Coverage Report - org.apache.giraph.utils.GiraphDepVersions
 
Classes in this File Line Coverage Branch Coverage Complexity
GiraphDepVersions
0%
0/25
0%
0/4
1.6
 
 1  
 /*
 2  
  * Licensed to the Apache Software Foundation (ASF) under one
 3  
  * or more contributor license agreements.  See the NOTICE file
 4  
  * distributed with this work for additional information
 5  
  * regarding copyright ownership.  The ASF 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, 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  
 package org.apache.giraph.utils;
 19  
 
 20  
 import org.apache.log4j.Logger;
 21  
 
 22  
 import com.google.common.collect.Maps;
 23  
 import com.google.common.io.Resources;
 24  
 
 25  
 import java.io.IOException;
 26  
 import java.net.URL;
 27  
 import java.util.Map;
 28  
 import java.util.Properties;
 29  
 
 30  
 /**
 31  
  * Versions of Giraph dependencies. This pulls version information from a known
 32  
  * properties file. That file is created by maven when building the jar and
 33  
  * populated with versions from the pom. We put the properties file in a known
 34  
  * resources folder so that it is easy to pick up.
 35  
  *
 36  
  * See http://bit.ly/19LQyrK for more information.
 37  
  */
 38  
 public class GiraphDepVersions {
 39  
   /** Logger */
 40  0
   private static final Logger LOG = Logger.getLogger(GiraphDepVersions.class);
 41  
 
 42  
   /** Path to resource */
 43  
   private static final String RESOURCE_NAME =
 44  
       "org/apache/giraph/versions.properties";
 45  
 
 46  
   /** Singleton */
 47  0
   private static final GiraphDepVersions INSTANCE = new GiraphDepVersions();
 48  
 
 49  
   /** The properties read */
 50  
   private final Properties properties;
 51  
 
 52  
   /** Constructor */
 53  0
   private GiraphDepVersions() {
 54  0
     URL url = Resources.getResource(RESOURCE_NAME);
 55  0
     properties = new Properties();
 56  
     try {
 57  0
       properties.load(url.openStream());
 58  0
     } catch (IOException e) {
 59  0
       LOG.error("Could not read giraph versions from file " + RESOURCE_NAME);
 60  0
     }
 61  0
   }
 62  
 
 63  
   /**
 64  
    * Get singleton instance
 65  
    *
 66  
    * @return singleton
 67  
    */
 68  
   public static GiraphDepVersions get() {
 69  0
     return INSTANCE;
 70  
   }
 71  
 
 72  
   public Properties getProperties() {
 73  0
     return properties;
 74  
   }
 75  
 
 76  
   /**
 77  
    * Get version of the named dependency, or null if not found
 78  
    *
 79  
    * @param name dependency name
 80  
    * @return version, or null
 81  
    */
 82  
   public String versionOf(String name) {
 83  0
     return properties.getProperty(name);
 84  
   }
 85  
 
 86  
   /** Log the dependency versions we're using */
 87  
   public void logVersionsUsed() {
 88  0
     Map<String, String> sortedVersions = Maps.newTreeMap();
 89  0
     for (Map.Entry<Object, Object> entry : properties.entrySet()) {
 90  0
       sortedVersions.put(entry.getKey().toString(),
 91  0
           entry.getValue().toString());
 92  0
     }
 93  0
     StringBuilder sb = new StringBuilder(sortedVersions.size() * 20);
 94  0
     for (Map.Entry<String, String> entry : sortedVersions.entrySet()) {
 95  0
       sb.append("  ").append(entry.getKey()).append(": ").
 96  0
           append(entry.getValue()).append("\n");
 97  0
     }
 98  0
     LOG.info("Versions of Giraph dependencies =>\n" + sb);
 99  0
   }
 100  
 }