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

COVERAGE SUMMARY FOR SOURCE FILE [DeltacloudImageToOperatingSystem.java]

nameclass, %method, %block, %line, %
DeltacloudImageToOperatingSystem.java0%   (0/1)0%   (0/3)0%   (0/124)0%   (0/31)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class DeltacloudImageToOperatingSystem0%   (0/1)0%   (0/3)0%   (0/124)0%   (0/31)
<static initializer> 0%   (0/1)0%   (0/7)0%   (0/2)
DeltacloudImageToOperatingSystem (Map): void 0%   (0/1)0%   (0/9)0%   (0/4)
apply (Image): OperatingSystem 0%   (0/1)0%   (0/108)0%   (0/25)

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.deltacloud.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 * @author Adrian Cole
40 */
41@Singleton
42public class DeltacloudImageToOperatingSystem implements Function<org.jclouds.deltacloud.domain.Image, OperatingSystem> {
43   public static final Pattern DEFAULT_PATTERN = Pattern.compile("(([^ ]*) ([0-9.]+) ?.*)");
44   // Windows Server 2008 R2 x64
45   public static final Pattern WINDOWS_PATTERN = Pattern.compile("Windows (.*) (x[86][64])");
46 
47   @Resource
48   @Named(ComputeServiceConstants.COMPUTE_LOGGER)
49   protected Logger logger = Logger.NULL;
50 
51   private final Map<OsFamily, Map<String, String>> osVersionMap;
52 
53   @Inject
54   public DeltacloudImageToOperatingSystem(Map<OsFamily, Map<String, String>> osVersionMap) {
55      this.osVersionMap = osVersionMap;
56   }
57 
58   public OperatingSystem apply(org.jclouds.deltacloud.domain.Image from) {
59      OsFamily osFamily = null;
60      String osName = null;
61      String osArch = null;
62      String osVersion = null;
63      String osDescription = from.getName();
64      boolean is64Bit = true;
65      if (from.getName().indexOf("Red Hat EL") != -1) {
66         osFamily = OsFamily.RHEL;
67      } else if (from.getName().indexOf("Oracle EL") != -1) {
68         osFamily = OsFamily.OEL;
69      } else if (from.getName().indexOf("Windows") != -1) {
70         osFamily = OsFamily.WINDOWS;
71         Matcher matcher = WINDOWS_PATTERN.matcher(from.getName());
72         if (matcher.find()) {
73            osVersion = ComputeServiceUtils.parseVersionOrReturnEmptyString(osFamily, matcher.group(1), osVersionMap);
74            is64Bit = matcher.group(2).equals("x64");
75         }
76      } else {
77         Matcher matcher = DEFAULT_PATTERN.matcher(from.getName());
78         if (matcher.find()) {
79            try {
80               osFamily = OsFamily.fromValue(matcher.group(2).toLowerCase());
81            } catch (IllegalArgumentException e) {
82               logger.debug("<< didn't match os(%s)", matcher.group(2));
83            }
84            osVersion = ComputeServiceUtils.parseVersionOrReturnEmptyString(osFamily, matcher.group(3), osVersionMap);
85         }
86      }
87      return new OperatingSystem(osFamily, osName, osVersion, osArch, osDescription, is64Bit);
88   }
89}

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