EMMA Coverage Report (generated Mon Oct 17 05:41:20 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 * 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.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