EMMA Coverage Report (generated Mon Oct 17 05:41:20 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 * 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.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   // ex. Centos-5.6-20110917 pub
57   public static final Pattern PATTERN = Pattern.compile("([^ -]+)[^0-9]([0-9.]+)[ -].*");
58 
59   @Override
60   public OsFamilyVersion64Bit apply(String input) {
61      boolean is64Bit = and(not(containsPattern("32bit")),
62               or(containsPattern("64bit"), not(containsPattern("Windows")))).apply(input);
63      if (input.contains("Windows")) {
64         String version = null;
65         Matcher matcher = Pattern.compile(".*(20[01][0-9] R[1-9]).*").matcher(input);
66         if (matcher.find()) {
67            version = matcher.group(1);
68         } else {
69            matcher = Pattern.compile(".*(20[01][0-9]).*").matcher(input);
70            if (matcher.find())
71               version = matcher.group(1);
72         }
73         return new OsFamilyVersion64Bit(OsFamily.WINDOWS, osVersionMap.get(OsFamily.WINDOWS).get(version), is64Bit);
74      } else {
75         Matcher matcher = PATTERN.matcher(input);
76         if (matcher.find()) {
77            OsFamily fam = OsFamily.fromValue(matcher.group(1).toLowerCase());
78            switch (fam) {
79               case UNRECOGNIZED:
80                  return new OsFamilyVersion64Bit(OsFamily.UNRECOGNIZED, null, is64Bit);
81            }
82            return new OsFamilyVersion64Bit(fam, ComputeServiceUtils.parseVersionOrReturnEmptyString(fam, matcher
83                     .group(2), osVersionMap), is64Bit);
84         } else {
85            return new OsFamilyVersion64Bit(OsFamily.UNRECOGNIZED, null, is64Bit);
86         }
87      }
88   }
89}

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