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

COVERAGE SUMMARY FOR SOURCE FILE [ParseVAppTemplateDescriptionToGetDefaultLoginCredentials.java]

nameclass, %method, %block, %line, %
ParseVAppTemplateDescriptionToGetDefaultLoginCredentials.java100% (1/1)100% (3/3)71%  (54/76)85%  (11.9/14)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class ParseVAppTemplateDescriptionToGetDefaultLoginCredentials100% (1/1)100% (3/3)71%  (54/76)85%  (11.9/14)
execute (Object): Credentials 100% (1/1)67%  (44/66)81%  (8.9/11)
<static initializer> 100% (1/1)100% (4/4)100% (1/1)
ParseVAppTemplateDescriptionToGetDefaultLoginCredentials (): void 100% (1/1)100% (6/6)100% (2/2)

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.trmk.vcloud_0_8.compute.strategy;
20 
21import static com.google.common.base.Preconditions.checkArgument;
22import static com.google.common.base.Preconditions.checkNotNull;
23 
24import java.util.regex.Matcher;
25import java.util.regex.Pattern;
26 
27import javax.annotation.Resource;
28import javax.inject.Named;
29import javax.inject.Singleton;
30 
31import org.jclouds.compute.reference.ComputeServiceConstants;
32import org.jclouds.compute.strategy.PopulateDefaultLoginCredentialsForImageStrategy;
33import org.jclouds.domain.Credentials;
34import org.jclouds.logging.Logger;
35import org.jclouds.trmk.vcloud_0_8.domain.VAppTemplate;
36 
37/**
38 * @author Adrian Cole
39 */
40@Singleton
41public class ParseVAppTemplateDescriptionToGetDefaultLoginCredentials implements
42         PopulateDefaultLoginCredentialsForImageStrategy {
43 
44   @Resource
45   @Named(ComputeServiceConstants.COMPUTE_LOGGER)
46   protected Logger logger = Logger.NULL;
47   
48   public static final Pattern USER_PASSWORD_PATTERN = Pattern
49            .compile(".*[Uu]sername: ([a-z]+) ?.*\n[Pp]assword: ([^ \n\r]+) ?\r?\n.*");
50 
51   @Override
52   public Credentials execute(Object resourceToAuthenticate) {
53      checkNotNull(resourceToAuthenticate);
54      checkArgument(resourceToAuthenticate instanceof VAppTemplate,
55               "Resource must be an VAppTemplate (for Terremark)");
56      VAppTemplate template = (VAppTemplate) resourceToAuthenticate;
57      String search = template.getDescription() != null ? template.getDescription() : template.getName();
58      if (search.indexOf("Windows") >= 0) {
59         return new Credentials("Administrator", null);
60      } else {
61         Matcher matcher = USER_PASSWORD_PATTERN.matcher(search);
62         if (matcher.find()) {
63            return new Credentials(matcher.group(1), matcher.group(2));
64         } else {
65            logger.warn("could not parse username/password for image: " + template.getHref() + "\n"
66                     + search);
67            return null;
68         }
69      }
70   }
71}

[all classes][org.jclouds.trmk.vcloud_0_8.compute.strategy]
EMMA 2.0.5312 (C) Vladimir Roubtsov