Coverage Report - ca.uhn.hl7v2.hoh.util.VersionLogger
 
Classes in this File Line Coverage Branch Coverage Complexity
VersionLogger
82%
14/17
100%
2/2
1.667
 
 1  
 package ca.uhn.hl7v2.hoh.util;
 2  
 
 3  
 import java.io.InputStream;
 4  
 import java.util.Properties;
 5  
 
 6  
 import org.slf4j.Logger;
 7  
 import org.slf4j.LoggerFactory;
 8  
 
 9  
 /**
 10  
  * Class to log the HAPI version when HAPI is first used (mostly for troubleshooting purposes)
 11  
  */
 12  
 public class VersionLogger {
 13  
 
 14  5
     private static final Logger LOG = LoggerFactory.getLogger(VersionLogger.class);
 15  5
         private static boolean ourInitialized = false;
 16  
     private static String ourVersion; 
 17  
     /**
 18  
      * Non-instantiable
 19  
      */
 20  0
     private VersionLogger() {
 21  
         // nothing
 22  0
     }
 23  
 
 24  
     /**
 25  
          * @return Returns the current version of HAPI
 26  
          */
 27  
         public static String getVersion() {
 28  395
                 init();
 29  395
                 return ourVersion;
 30  
         }
 31  
 
 32  
         /**
 33  
      * Logs the HAPI version on the first time this method is invoked, does nothing afterwards
 34  
      */
 35  
     public static void init() {
 36  415
         if (!ourInitialized) {
 37  
             try {
 38  5
                 InputStream is = VersionLogger.class.getResourceAsStream("/ca/uhn/hl7v2/hoh/hoh-version.properties");
 39  5
                 Properties p = new Properties();
 40  5
                 p.load(is);
 41  5
                 ourVersion = p.getProperty("version");
 42  5
                 String build = p.getProperty("build");
 43  5
                                 LOG.info("HL7 over HTTP (HAPI) library version " + ourVersion + " - Build " + build);
 44  0
             } catch (Exception e) {
 45  
                 // ignore
 46  5
             }
 47  5
             ourInitialized = true;
 48  
         }
 49  415
     }
 50  
     
 51  
 }