EMMA Coverage Report (generated Mon Oct 17 05:41:20 EDT 2011)
[all classes][org.jclouds.slicehost.compute.functions]

COVERAGE SUMMARY FOR SOURCE FILE [SlicehostImageToOperatingSystem.java]

nameclass, %method, %block, %line, %
SlicehostImageToOperatingSystem.java100% (1/1)100% (3/3)66%  (87/131)68%  (21/31)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class SlicehostImageToOperatingSystem100% (1/1)100% (3/3)66%  (87/131)68%  (21/31)
apply (Image): OperatingSystem 100% (1/1)62%  (71/115)60%  (15/25)
<static initializer> 100% (1/1)100% (7/7)100% (2/2)
SlicehostImageToOperatingSystem (Map): void 100% (1/1)100% (9/9)100% (4/4)

1/**
2 * Licensed to jclouds, Inc. (jclouds) under one or more
3 * contributor license agreements.  See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership.  jclouds licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License.  You may obtain a copy of the License at
9 *
10 *   http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied.  See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
19package org.jclouds.slicehost.compute.functions;
20 
21import java.util.Map;
22import java.util.regex.Matcher;
23import java.util.regex.Pattern;
24 
25import javax.annotation.Resource;
26import javax.inject.Inject;
27import javax.inject.Named;
28import javax.inject.Singleton;
29 
30import org.jclouds.compute.domain.OperatingSystem;
31import org.jclouds.compute.domain.OsFamily;
32import org.jclouds.compute.reference.ComputeServiceConstants;
33import org.jclouds.compute.util.ComputeServiceUtils;
34import org.jclouds.logging.Logger;
35 
36import com.google.common.base.Function;
37 
38/**
39 * 
40 * @author Adrian Cole
41 */
42@Singleton
43public class SlicehostImageToOperatingSystem implements Function<org.jclouds.slicehost.domain.Image, OperatingSystem> {
44   public static final Pattern DEFAULT_PATTERN = Pattern.compile("(([^ ]*) ([0-9.]+) ?.*)");
45   // Windows Server 2008 R2 x64
46   public static final Pattern WINDOWS_PATTERN = Pattern.compile("Windows (.*) (x[86][64])");
47 
48   @Resource
49   @Named(ComputeServiceConstants.COMPUTE_LOGGER)
50   protected Logger logger = Logger.NULL;
51 
52   private final Map<OsFamily, Map<String, String>> osVersionMap;
53 
54   @Inject
55   public SlicehostImageToOperatingSystem(Map<OsFamily, Map<String, String>> osVersionMap) {
56      this.osVersionMap = osVersionMap;
57   }
58 
59   public OperatingSystem apply(final org.jclouds.slicehost.domain.Image from) {
60      OsFamily osFamily = null;
61      String osName = null;
62      String osArch = null;
63      String osVersion = null;
64      String osDescription = from.getName();
65      boolean is64Bit = !from.getName().endsWith("32-bit");
66      if (from.getName().indexOf("Red Hat EL") != -1) {
67         osFamily = OsFamily.RHEL;
68      } else if (from.getName().indexOf("Oracle EL") != -1) {
69         osFamily = OsFamily.OEL;
70      } else if (from.getName().indexOf("Windows") != -1) {
71         osFamily = OsFamily.WINDOWS;
72         Matcher matcher = WINDOWS_PATTERN.matcher(from.getName());
73         if (matcher.find()) {
74            osVersion = ComputeServiceUtils.parseVersionOrReturnEmptyString(osFamily, matcher.group(1), osVersionMap);
75            is64Bit = matcher.group(2).equals("x64");
76         }
77      } else {
78         Matcher matcher = DEFAULT_PATTERN.matcher(from.getName());
79         if (matcher.find()) {
80            try {
81               osFamily = OsFamily.fromValue(matcher.group(2).toLowerCase());
82            } catch (IllegalArgumentException e) {
83               logger.debug("<< didn't match os(%s)", matcher.group(2));
84            }
85            osVersion = ComputeServiceUtils.parseVersionOrReturnEmptyString(osFamily, matcher.group(3), osVersionMap);
86         }
87      }
88      return new OperatingSystem(osFamily, osName, osVersion, osArch, osDescription, is64Bit);
89   }
90}

[all classes][org.jclouds.slicehost.compute.functions]
EMMA 2.0.5312 (C) Vladimir Roubtsov