Coverage report

  %line %branch
net.sf.infrared.agent.util.AgentHelper
61% 
78% 

 1  
 /* 
 2  
  * Copyright 2005 Tavant Technologies and Contributors
 3  
  * 
 4  
  * Licensed under the Apache License, Version 2.0 (the "License")
 5  
  * you may not use this file except in compliance with the License.
 6  
  * You may obtain a copy of the License at
 7  
  *
 8  
  *     http://www.apache.org/licenses/LICENSE-2.0
 9  
  *
 10  
  * Unless required by applicable law or agreed to in writing, software
 11  
  * distributed under the License is distributed on an "AS IS" BASIS,
 12  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 13  
  * See the License for the specific language governing permissions and
 14  
  * limitations under the License.
 15  
  * 
 16  
  *
 17  
  *
 18  
  * Original Author:  binil.thomas (Tavant Technologies)
 19  
  * Contributor(s):   -
 20  
  *
 21  
  */
 22  
 package net.sf.infrared.agent.util;
 23  
 
 24  
 import java.io.InputStream;
 25  
 import java.net.InetAddress;
 26  
 import java.util.Properties;
 27  
 
 28  
 import net.sf.infrared.base.util.LoggingFactory;
 29  
 
 30  
 import org.apache.log4j.Logger;
 31  
 
 32  
 /**
 33  
  * Helper methods which are used throughout agent module
 34  
  * 
 35  
  * @author binil
 36  
  */
 37  0
 public class AgentHelper {
 38  
     public static final String VERSION_FILE = "version.txt";
 39  
     
 40  4
     private static Logger log = LoggingFactory.getLogger(AgentHelper.class);
 41  
     
 42  
     private static String hostName;
 43  
     private static String version;
 44  
     
 45  
     public static String getLocalHostName() {
 46  2
         if (hostName !=  null) {
 47  0
             return hostName;
 48  
         }
 49  
         
 50  
         try {
 51  2
             hostName = InetAddress.getLocalHost().getHostName();
 52  0
         } catch (Throwable th) {
 53  0
             log.error("Failed to figure out host name, using default " + hostName, th);            
 54  0
             th.printStackTrace();
 55  0
             hostName = "unknwon-host";
 56  2
         }
 57  2
         return hostName;
 58  
     }
 59  
     
 60  
     public static String getVersion() {
 61  2
         if (version !=  null) {
 62  0
             return version;
 63  
         }
 64  
         
 65  
         try {
 66  2
             InputStream versionUrl = 
 67  
                 Thread.currentThread().getContextClassLoader().getResourceAsStream(VERSION_FILE);
 68  2
             Properties props = new Properties();
 69  2
             if (versionUrl != null) {
 70  2
                 props.load(versionUrl);
 71  2
                 version = props.getProperty("infrared-version");
 72  
             }
 73  0
         } catch (Throwable th) {
 74  
             // swallow this and go with unknown version!
 75  2
         }
 76  2
         if ( (version == null) || (version.trim().equals("")) ) {
 77  0
             version = "unknwon";
 78  
         }
 79  
         
 80  2
         return version;
 81  
     }
 82  
 }

This report is generated by jcoverage, Maven and Maven JCoverage Plugin.