EMMA Coverage Report (generated Fri Aug 26 14:14:05 EDT 2011)
[all classes][org.jclouds.cloudsigma.compute.functions]

COVERAGE SUMMARY FOR SOURCE FILE [ParseOsFamilyVersion64BitFromImageName.java]

nameclass, %method, %block, %line, %
ParseOsFamilyVersion64BitFromImageName.java100% (2/2)100% (4/4)94%  (117/125)95%  (20/21)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class ParseOsFamilyVersion64BitFromImageName$1100% (1/1)100% (1/1)92%  (11/12)91%  (0.9/1)
<static initializer> 100% (1/1)92%  (11/12)91%  (0.9/1)
     
class ParseOsFamilyVersion64BitFromImageName100% (1/1)100% (3/3)94%  (106/113)95%  (20/21)
apply (String): OsFamilyVersion64Bit 100% (1/1)93%  (96/103)94%  (16/17)
<static initializer> 100% (1/1)100% (4/4)100% (1/1)
ParseOsFamilyVersion64BitFromImageName (Map): void 100% (1/1)100% (6/6)100% (3/3)

1/**
2 *
3 * Copyright (C) 2011 Cloud Conscious, LLC. <info@cloudconscious.com>
4 *
5 * ====================================================================
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * 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, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 * ====================================================================
18 */
19package org.jclouds.cloudsigma.compute.functions;
20 
21import static com.google.common.base.Predicates.and;
22import static com.google.common.base.Predicates.containsPattern;
23import static com.google.common.base.Predicates.not;
24import static com.google.common.base.Predicates.or;
25 
26import java.util.Map;
27import java.util.regex.Matcher;
28import java.util.regex.Pattern;
29 
30import javax.inject.Inject;
31import javax.inject.Singleton;
32 
33import org.jclouds.compute.domain.OsFamily;
34import org.jclouds.compute.domain.OsFamilyVersion64Bit;
35import org.jclouds.compute.util.ComputeServiceUtils;
36 
37import com.google.common.base.Function;
38 
39/**
40 * Defaults to version null and 64bit, if the operating system is unrecognized and the pattern
41 * "32bit" isn't in the string.
42 * 
43 * @author Adrian Cole
44 * 
45 */
46@Singleton
47public class ParseOsFamilyVersion64BitFromImageName implements Function<String, OsFamilyVersion64Bit> {
48   private final Map<OsFamily, Map<String, String>> osVersionMap;
49 
50   @Inject
51   public ParseOsFamilyVersion64BitFromImageName(Map<OsFamily, Map<String, String>> osVersionMap) {
52      this.osVersionMap = osVersionMap;
53   }
54 
55   // ex CentOS 5.5 Linux 64bit Preinstalled System with AppFirst Monitoring
56   public static final Pattern PATTERN = Pattern.compile("([^ ]+)[^0-9]([0-9.]+) .*");
57 
58   @Override
59   public OsFamilyVersion64Bit apply(String input) {
60      boolean is64Bit = and(not(containsPattern("32bit")),
61               or(containsPattern("64bit"), not(containsPattern("Windows")))).apply(input);
62      if (input.contains("Windows")) {
63         String version = null;
64         Matcher matcher = Pattern.compile(".*(20[01][0-9] R[1-9]).*").matcher(input);
65         if (matcher.find()) {
66            version = matcher.group(1);
67         } else {
68            matcher = Pattern.compile(".*(20[01][0-9]).*").matcher(input);
69            if (matcher.find())
70               version = matcher.group(1);
71         }
72         return new OsFamilyVersion64Bit(OsFamily.WINDOWS, osVersionMap.get(OsFamily.WINDOWS).get(version), is64Bit);
73      } else {
74         Matcher matcher = PATTERN.matcher(input);
75         if (matcher.find()) {
76            OsFamily fam = OsFamily.fromValue(matcher.group(1).toLowerCase());
77            switch (fam) {
78               case UNRECOGNIZED:
79                  return new OsFamilyVersion64Bit(OsFamily.UNRECOGNIZED, null, is64Bit);
80            }
81            return new OsFamilyVersion64Bit(fam, ComputeServiceUtils.parseVersionOrReturnEmptyString(fam, matcher
82                     .group(2), osVersionMap), is64Bit);
83         } else {
84            return new OsFamilyVersion64Bit(OsFamily.UNRECOGNIZED, null, is64Bit);
85         }
86      }
87   }
88}

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