EMMA Coverage Report (generated Mon Dec 09 15:12:29 EST 2013)
[all classes][org.jclouds.glesys.compute.functions]

COVERAGE SUMMARY FOR SOURCE FILE [ParseOsFamilyVersion64BitFromImageName.java]

nameclass, %method, %block, %line, %
ParseOsFamilyVersion64BitFromImageName.java100% (1/1)100% (3/3)94%  (115/122)96%  (25/26)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class ParseOsFamilyVersion64BitFromImageName100% (1/1)100% (3/3)94%  (115/122)96%  (25/26)
apply (String): OsFamilyVersion64Bit 100% (1/1)94%  (102/109)95%  (20/21)
<static initializer> 100% (1/1)100% (7/7)100% (2/2)
ParseOsFamilyVersion64BitFromImageName (Map): void 100% (1/1)100% (6/6)100% (3/3)

1/*
2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements.  See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The ASF licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License.  You may obtain a copy of the License at
8 *
9 *     http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17package org.jclouds.glesys.compute.functions;
18 
19import static com.google.common.base.Predicates.containsPattern;
20 
21import java.util.Map;
22import java.util.regex.Matcher;
23import java.util.regex.Pattern;
24 
25import javax.inject.Inject;
26import javax.inject.Singleton;
27 
28import org.jclouds.compute.domain.OsFamily;
29import org.jclouds.compute.domain.OsFamilyVersion64Bit;
30import org.jclouds.compute.util.ComputeServiceUtils;
31 
32import com.google.common.base.Function;
33 
34/**
35 * Defaults to version null and 64bit, if the operating system is unrecognized
36 * and the pattern "32bit" isn't in the string.
37 * 
38 * @author Adrian Cole
39 * 
40 */
41@Singleton
42public class ParseOsFamilyVersion64BitFromImageName implements Function<String, OsFamilyVersion64Bit> {
43   private final Map<OsFamily, Map<String, String>> osVersionMap;
44 
45   @Inject
46   public ParseOsFamilyVersion64BitFromImageName(Map<OsFamily, Map<String, String>> osVersionMap) {
47      this.osVersionMap = osVersionMap;
48   }
49 
50   // ex Debian 6.0 64-bit
51   // ex. Ubuntu 10.04 LTS 32-bit
52   public static final Pattern OSFAMILY_VERSION = Pattern
53         .compile("([^ ]+).*[ -]([0-9.]+)( LTS)?( [36][24]-bit)?( x[68][46])?$");
54   public static final Pattern OSFAMILY = Pattern.compile("([^ ]+).*$");
55 
56   @Override
57   public OsFamilyVersion64Bit apply(String input) {
58      boolean is64Bit = containsPattern("64").apply(input);
59      String version = "";
60 
61      if (input.indexOf("Windows") != -1) {
62         Matcher matcher = Pattern.compile(".*(20[01][0-9] R[1-9]).*").matcher(input);
63         if (matcher.find()) {
64            version = matcher.group(1);
65         } else {
66            matcher = Pattern.compile(".*(20[01][0-9]).*").matcher(input);
67            if (matcher.find())
68               version = matcher.group(1);
69         }
70         return new OsFamilyVersion64Bit(OsFamily.WINDOWS, osVersionMap.get(OsFamily.WINDOWS).get(version), is64Bit);
71      }
72      Matcher osFamilyVersionMatcher = OSFAMILY_VERSION.matcher(input);
73      if (osFamilyVersionMatcher.find()) {
74         OsFamily fam = OsFamily.fromValue(osFamilyVersionMatcher.group(1).toLowerCase());
75         if (fam == OsFamily.UNRECOGNIZED ) {
76            return new OsFamilyVersion64Bit(OsFamily.UNRECOGNIZED, version, is64Bit);
77         }
78         return new OsFamilyVersion64Bit(fam, ComputeServiceUtils.parseVersionOrReturnEmptyString(fam,
79               osFamilyVersionMatcher.group(2), osVersionMap), is64Bit);
80      } else {
81         Matcher osFamilyMatcher = OSFAMILY.matcher(input);
82         OsFamily fam = OsFamily.UNRECOGNIZED;
83         if (osFamilyMatcher.find()) {
84            fam = OsFamily.fromValue(osFamilyMatcher.group(1).toLowerCase());
85         }
86         return new OsFamilyVersion64Bit(fam, version, is64Bit);
87      }
88 
89   }
90}

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