You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by rg...@apache.org on 2006/12/26 22:10:23 UTC

svn commit: r490373 - in /incubator/qpid/trunk/qpid/java: common/src/main/java/org/apache/qpid/common/QpidProperties.java pom.xml

Author: rgreig
Date: Tue Dec 26 13:10:20 2006
New Revision: 490373

URL: http://svn.apache.org/viewvc?view=rev&rev=490373
Log:
QPID-227 Renamed version.properties to qpidversion.properties due to clash with a dependency also using version.properties. Also improved robustness where properties file does not contain expected properties.

Modified:
    incubator/qpid/trunk/qpid/java/common/src/main/java/org/apache/qpid/common/QpidProperties.java
    incubator/qpid/trunk/qpid/java/pom.xml

Modified: incubator/qpid/trunk/qpid/java/common/src/main/java/org/apache/qpid/common/QpidProperties.java
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/java/common/src/main/java/org/apache/qpid/common/QpidProperties.java?view=diff&rev=490373&r1=490372&r2=490373
==============================================================================
--- incubator/qpid/trunk/qpid/java/common/src/main/java/org/apache/qpid/common/QpidProperties.java (original)
+++ incubator/qpid/trunk/qpid/java/common/src/main/java/org/apache/qpid/common/QpidProperties.java Tue Dec 26 13:10:20 2006
@@ -20,12 +20,18 @@
  */
 package org.apache.qpid.common;
 
+import org.apache.log4j.Logger;
+
 import java.util.Properties;
+import java.util.Map;
 import java.io.IOException;
+import java.io.InputStream;
 
 public class QpidProperties
 {
-    public static final String VERSION_RESOURCE = "version.properties";
+    private static final Logger _logger = Logger.getLogger(QpidProperties.class);
+    
+    public static final String VERSION_RESOURCE = "qpidversion.properties";
 
     public static final String PRODUCT_NAME_PROPERTY = "qpid.name";
     public static final String RELEASE_VERSION_PROPERTY = "qpid.version";
@@ -44,16 +50,34 @@
 
         try
         {
-            props.load(QpidProperties.class.getClassLoader().getResourceAsStream(VERSION_RESOURCE));
-
-            productName = props.getProperty(PRODUCT_NAME_PROPERTY);
-            releaseVersion = props.getProperty(RELEASE_VERSION_PROPERTY);
-            buildVersion = props.getProperty(BUILD_VERSION_PROPERTY);
+            InputStream propertyStream = QpidProperties.class.getClassLoader().getResourceAsStream(VERSION_RESOURCE);
+            if (propertyStream == null)
+            {
+                _logger.warn("Unable to find resource " + VERSION_RESOURCE + " from classloader");
+            }
+            else
+            {
+                props.load(propertyStream);
+
+                if (_logger.isDebugEnabled())
+                {
+                    _logger.debug("Dumping QpidProperties");
+                    for (Map.Entry<Object,Object> entry : props.entrySet())
+                    {
+                        _logger.debug("Property: " + entry.getKey() + " Value: "+ entry.getValue());
+                    }
+                    _logger.debug("End of property dump");
+                }
+
+                productName = readPropertyValue(props, PRODUCT_NAME_PROPERTY);
+                releaseVersion = readPropertyValue(props, RELEASE_VERSION_PROPERTY);
+                buildVersion = readPropertyValue(props, BUILD_VERSION_PROPERTY);                
+            }
         }
         catch (IOException e)
         {
             // Log a warning about this and leave the values initialized to unknown.
-            System.err.println("Could not load version.properties resource.");
+            _logger.error("Could not load version.properties resource: " + e, e);
         }
     }
 
@@ -75,6 +99,16 @@
     public static String getVersionString()
     {
         return getProductName() + " - " + getReleaseVersion() + " build: " + getBuildVersion();
+    }
+
+    private static String readPropertyValue(Properties props, String propertyName)
+    {
+        String retVal = (String) props.get(propertyName);
+        if (retVal == null)
+        {
+            retVal = DEFAULT;
+        }
+        return retVal;
     }
 
     public static void main(String[] args)

Modified: incubator/qpid/trunk/qpid/java/pom.xml
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/java/pom.xml?view=diff&rev=490373&r1=490372&r2=490373
==============================================================================
--- incubator/qpid/trunk/qpid/java/pom.xml (original)
+++ incubator/qpid/trunk/qpid/java/pom.xml Tue Dec 26 13:10:20 2006
@@ -186,11 +186,11 @@
                               time, during the 'package' phase to capture the version of any resources added to jar files.
                               This svnversion command is always run in the top directory to accurately reflect the svnversion range accross all modules 
                               at the time of the build.
-                              The properties are placed into a file 'version.properties' in the target/classes directory of any child module that runs 
+                              The properties are placed into a file 'qpidversion.properties' in the target/classes directory of any child module that runs 
                               this plugin.
-                              The 'version.properties' file is loaded by the org.apache.qpid.common.QpidProperties class.
+                              The 'qpidversion.properties' file is loaded by the org.apache.qpid.common.QpidProperties class.
                               Be carefull of the possibility that the 'common' module may run this antrun plugin and recieve its own set of 
-                              version.properties and then the client or broker being built against an older version of the common library ending up with
+                              qpidversion.properties and then the client or broker being built against an older version of the common library ending up with
                               the wrong version information. This is unlikely to happen because the client or broker should pick up its own properties
                               from the classpath first. If this happens it will be obvious because the productName property will be 
                               'Qpid Common Utilities'. If this is a problem then push this ant task down into the client and broker poms and remove it
@@ -208,7 +208,7 @@
                                </exec>
 
                                <!-- Write the version.properties out. -->
-                               <propertyfile file="target/classes/version.properties">
+                               <propertyfile file="target/classes/qpidversion.properties">
                                  <entry key="qpid.svnversion" value="${svnversion}"/>
                                  <entry key="qpid.name" value="${project.name}"/>
                                  <entry key="qpid.version" value="${project.version}"/>