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

COVERAGE SUMMARY FOR SOURCE FILE [SupplyFromProviderURIOrNodesProperty.java]

nameclass, %method, %block, %line, %
SupplyFromProviderURIOrNodesProperty.java100% (1/1)75%  (3/4)58%  (42/72)67%  (10/15)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class SupplyFromProviderURIOrNodesProperty100% (1/1)75%  (3/4)58%  (42/72)67%  (10/15)
toString (): String 0%   (0/1)0%   (0/12)0%   (0/1)
apply (URI): InputStream 100% (1/1)50%  (18/36)43%  (3/7)
SupplyFromProviderURIOrNodesProperty (URI): void 100% (1/1)100% (12/12)100% (4/4)
get (): InputStream 100% (1/1)100% (12/12)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.byon.suppliers;
20 
21import static com.google.common.base.Preconditions.checkNotNull;
22 
23import java.io.IOException;
24import java.io.InputStream;
25import java.net.URI;
26 
27import javax.annotation.Resource;
28 
29import org.jclouds.location.Provider;
30import org.jclouds.logging.Logger;
31import org.jclouds.util.Strings2;
32 
33import com.google.common.annotations.VisibleForTesting;
34import com.google.common.base.Function;
35import com.google.common.base.Supplier;
36import com.google.common.base.Throwables;
37import com.google.inject.Inject;
38import com.google.inject.name.Named;
39 
40/**
41 * @author Adrian Cole
42 */
43public class SupplyFromProviderURIOrNodesProperty implements Supplier<InputStream>, Function<URI, InputStream> {
44   @Resource
45   protected Logger logger = Logger.NULL;
46   private final URI url;
47 
48   @Inject(optional = true)
49   @Named("byon.nodes")
50   @VisibleForTesting
51   String nodes;
52 
53   @Inject
54   public SupplyFromProviderURIOrNodesProperty(@Provider URI url) {
55      this.url = checkNotNull(url, "url");
56   }
57 
58   @Override
59   public InputStream get() {
60      if (nodes != null)
61         return Strings2.toInputStream(nodes);
62      return apply(url);
63   }
64 
65   @Override
66   public String toString() {
67      return "[url=" + url + "]";
68   }
69 
70   @Override
71   public InputStream apply(URI input) {
72      try {
73         if (input.getScheme() != null && input.getScheme().equals("classpath"))
74            return getClass().getResourceAsStream(input.getPath());
75         return input.toURL().openStream();
76      } catch (IOException e) {
77         logger.error(e, "URI could not be read: %s", url);
78         Throwables.propagate(e);
79         return null;
80      }
81   }
82 
83}

[all classes][org.jclouds.byon.suppliers]
EMMA 2.0.5312 (C) Vladimir Roubtsov