qpid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From oru...@apache.org
Subject qpid-broker-j git commit: QPID-8227: Replace qpidbrokerversion.properties with jar metadata
Date Wed, 08 Aug 2018 15:32:59 GMT
Repository: qpid-broker-j
Updated Branches:
  refs/heads/master c7b3d189f -> 6c96879f6


QPID-8227: Replace qpidbrokerversion.properties with jar metadata


Project: http://git-wip-us.apache.org/repos/asf/qpid-broker-j/repo
Commit: http://git-wip-us.apache.org/repos/asf/qpid-broker-j/commit/6c96879f
Tree: http://git-wip-us.apache.org/repos/asf/qpid-broker-j/tree/6c96879f
Diff: http://git-wip-us.apache.org/repos/asf/qpid-broker-j/diff/6c96879f

Branch: refs/heads/master
Commit: 6c96879f6e724ea593da0aa15ebb504d4943405d
Parents: c7b3d18
Author: Keith Wall <kwall@apache.org>
Authored: Sun May 20 22:17:53 2018 +0100
Committer: Alex Rudyy <orudyy@apache.org>
Committed: Wed Aug 8 16:32:39 2018 +0100

----------------------------------------------------------------------
 broker-core/pom.xml                             |  22 +---
 .../server/configuration/CommonProperties.java  | 116 +++++++++----------
 .../server/configuration/fallback-version.txt   |   1 +
 .../main/resources/qpidbrokerversion.properties |  23 ----
 pom.xml                                         |  37 +++++-
 5 files changed, 97 insertions(+), 102 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/qpid-broker-j/blob/6c96879f/broker-core/pom.xml
----------------------------------------------------------------------
diff --git a/broker-core/pom.xml b/broker-core/pom.xml
index b3ce59c..959d41a 100644
--- a/broker-core/pom.xml
+++ b/broker-core/pom.xml
@@ -30,10 +30,7 @@
 
   <properties>
     <generated-logmessages-dir>${basedir}/src/main/java</generated-logmessages-dir>
-    <qpid.name>qpid</qpid.name>
     <qpid.version>${project.version}</qpid.version>
-    <qpid.version.suffix />
-    <buildNumber>Unversioned directory</buildNumber>
   </properties>
 
   <dependencies>
@@ -109,6 +106,7 @@
         <filtering>true</filtering>
         <includes>
           <include>**/*.properties</include>
+          <include>**/fallback-version.txt</include>
         </includes>
       </resource>
       <resource>
@@ -142,23 +140,6 @@
 
     <plugins>
       <plugin>
-        <groupId>org.codehaus.mojo</groupId>
-        <artifactId>buildnumber-maven-plugin</artifactId>
-        <version>1.3</version>
-        <executions>
-          <execution>
-            <phase>validate</phase>
-            <goals>
-              <goal>create</goal>
-            </goals>
-          </execution>
-        </executions>
-        <configuration>
-          <doCheck>false</doCheck>
-          <doUpdate>false</doUpdate>
-        </configuration>
-      </plugin>
-      <plugin>
         <groupId>org.apache.maven.plugins</groupId>
         <artifactId>maven-jar-plugin</artifactId>
         <!--version specified in parent pluginManagement -->
@@ -186,6 +167,7 @@
         <configuration>
           <excludes>
             <exclude>src/test/resources/ssl/**</exclude>
+            <exclude>src/main/resources/org/apache/qpid/server/configuration/fallback-version.txt</exclude>
           </excludes>
         </configuration>
       </plugin>

http://git-wip-us.apache.org/repos/asf/qpid-broker-j/blob/6c96879f/broker-core/src/main/java/org/apache/qpid/server/configuration/CommonProperties.java
----------------------------------------------------------------------
diff --git a/broker-core/src/main/java/org/apache/qpid/server/configuration/CommonProperties.java
b/broker-core/src/main/java/org/apache/qpid/server/configuration/CommonProperties.java
index b45d67d..eab1400 100644
--- a/broker-core/src/main/java/org/apache/qpid/server/configuration/CommonProperties.java
+++ b/broker-core/src/main/java/org/apache/qpid/server/configuration/CommonProperties.java
@@ -20,16 +20,19 @@
  */
 package org.apache.qpid.server.configuration;
 
+import java.io.BufferedReader;
 import java.io.File;
 import java.io.IOException;
 import java.io.InputStream;
+import java.io.InputStreamReader;
 import java.net.MalformedURLException;
 import java.net.URL;
+import java.nio.charset.StandardCharsets;
 import java.util.HashSet;
 import java.util.Properties;
 import java.util.Set;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
+import java.util.jar.Attributes;
+import java.util.jar.Manifest;
 
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -61,20 +64,10 @@ public class CommonProperties
     public static final String QPID_SECURITY_TLS_CIPHER_SUITE_BLACK_LIST = "qpid.security.tls.cipherSuiteBlackList";
     public static final String QPID_SECURITY_TLS_CIPHER_SUITE_BLACK_LIST_DEFAULT = "";
 
-    /** The name of the version properties file to load from the class path. */
-    public static final String VERSION_RESOURCE = "qpidbrokerversion.properties";
-
-    /** Defines the name of the product property. */
-    public static final String PRODUCT_NAME_PROPERTY = "qpid.name";
-
-    /** Defines the name of the version property. */
-    public static final String RELEASE_VERSION_PROPERTY = "qpid.version";
+    private static final String MANIFEST_HEADER_IMPLEMENTATION_BUILD = "Implementation-Build";
 
     /** Defines the name of the version suffix property. */
-    public static final String RELEASE_VERSION_SUFFIX = "qpid.version.suffix";
-
-    /** Defines the name of the source code revision property. */
-    public static final String BUILD_VERSION_PROPERTY = "qpid.svnversion";
+    private static final String RELEASE_VERSION_SUFFIX = "qpid.version.suffix";
 
     /** Defines the default value for all properties that cannot be loaded. */
     private static final String DEFAULT = "unknown";
@@ -85,40 +78,22 @@ public class CommonProperties
     /** Holds the product version. */
     private static final String releaseVersion;
 
-    /** Holds the product major version - derived from the releaseVersion */
-    private static final int releaseVersionMajor;
-
-    /** Holds the product minor version - derived from the releaseVersion */
-    private static final int releaseVersionMinor;
-
     /** Holds the source code revision. */
     private static final String buildVersion;
 
     private static final Properties properties = new Properties();
 
-    // Loads the values from the version properties file and common properties file.
     static
     {
+        Manifest jarManifest = getJarManifestFor(CommonProperties.class);
+        Attributes mainAttributes = jarManifest.getMainAttributes();
 
-        loadProperties(properties, VERSION_RESOURCE, false);
+        Package p = CommonProperties.class.getPackage();
 
-        buildVersion =  properties.getProperty(BUILD_VERSION_PROPERTY, DEFAULT);
-        productName = properties.getProperty(PRODUCT_NAME_PROPERTY, DEFAULT);
+        buildVersion = mainAttributes.getValue(MANIFEST_HEADER_IMPLEMENTATION_BUILD) != null
? mainAttributes.getValue(MANIFEST_HEADER_IMPLEMENTATION_BUILD) : DEFAULT;
+        productName = p.getImplementationTitle() != null ? p.getImplementationTitle() : DEFAULT;
 
-        String version = properties.getProperty(RELEASE_VERSION_PROPERTY, DEFAULT);
-        Pattern pattern = Pattern.compile("(\\d+)\\.(\\d+).*");
-        Matcher m = pattern.matcher(version);
-        if (m.matches())
-        {
-            releaseVersionMajor = Integer.parseInt(m.group(1));
-            releaseVersionMinor = Integer.parseInt(m.group(2));
-        }
-        else
-        {
-            LOGGER.warn("Failed to parse major and minor release number from '{}')", version);
-            releaseVersionMajor = -1;
-            releaseVersionMinor = -1;
-        }
+        String version = getImplementationVersion(p);
 
         boolean loadFromFile = true;
         String initialProperties = System.getProperty("qpid.common_properties_file");
@@ -173,26 +148,6 @@ public class CommonProperties
     }
 
     /**
-     * Gets the product major version.
-     *
-     * @return The product major version.
-     */
-    public static int getReleaseVersionMajor()
-    {
-        return releaseVersionMajor;
-    }
-
-    /**
-     * Gets the product minor version.
-     *
-     * @return The product version.
-     */
-    public static int getReleaseVersionMinor()
-    {
-        return releaseVersionMinor;
-    }
-
-    /**
      * Gets the source code revision.
      *
      * @return The source code revision.
@@ -252,5 +207,50 @@ public class CommonProperties
         }
     }
 
+    private static String getImplementationVersion(final Package p)
+    {
+        String version = p.getImplementationVersion();
+        if (version == null)
+        {
+            version = DEFAULT;
+            final String path = CommonProperties.class.getPackage().getName().replace(".",
"/");
+            final String fallbackPath = "/" + path + "/fallback-version.txt";
+            final InputStream in = CommonProperties.class.getResourceAsStream(fallbackPath);
+            if (in != null)
+            {
+                try(BufferedReader reader = new BufferedReader(new InputStreamReader(in,
StandardCharsets.US_ASCII)))
+                {
+                    version = reader.readLine();
+                }
+                catch (Exception e)
+                {
+                    LOGGER.trace("Problem reading version from fallback resource : {} ",
fallbackPath, e);
+                }
+            }
+        }
+        return version;
+    }
+
+    private static Manifest getJarManifestFor(final Class<?> clazz)
+    {
+        final Manifest emptyManifest = new Manifest();
+        String className = clazz.getSimpleName() + ".class";
+        String classPath = clazz.getResource(className).toString();
+        if (!classPath.startsWith("jar"))
+        {
+            return emptyManifest;
+        }
 
+        String manifestPath = classPath.substring(0, classPath.lastIndexOf("!") + 1) +
+                              "/META-INF/MANIFEST.MF";
+        try (InputStream is = new URL(manifestPath).openStream())
+        {
+            return new Manifest(is);
+        }
+        catch (IOException e)
+        {
+            // Ignore
+        }
+        return emptyManifest;
+    }
 }

http://git-wip-us.apache.org/repos/asf/qpid-broker-j/blob/6c96879f/broker-core/src/main/resources/org/apache/qpid/server/configuration/fallback-version.txt
----------------------------------------------------------------------
diff --git a/broker-core/src/main/resources/org/apache/qpid/server/configuration/fallback-version.txt
b/broker-core/src/main/resources/org/apache/qpid/server/configuration/fallback-version.txt
new file mode 100644
index 0000000..f2ab45c
--- /dev/null
+++ b/broker-core/src/main/resources/org/apache/qpid/server/configuration/fallback-version.txt
@@ -0,0 +1 @@
+${project.version}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/qpid-broker-j/blob/6c96879f/broker-core/src/main/resources/qpidbrokerversion.properties
----------------------------------------------------------------------
diff --git a/broker-core/src/main/resources/qpidbrokerversion.properties b/broker-core/src/main/resources/qpidbrokerversion.properties
deleted file mode 100644
index 1fc5753..0000000
--- a/broker-core/src/main/resources/qpidbrokerversion.properties
+++ /dev/null
@@ -1,23 +0,0 @@
-#
-# Licensed to the Apache Software Foundation (ASF) under one
-# or more contributor license agreements.  See the NOTICE file
-# distributed with this work for additional information
-# regarding copyright ownership.  The ASF licenses this file
-# to you under the Apache License, Version 2.0 (the
-# "License"); you may not use this file except in compliance
-# with the License.  You may obtain a copy of the License at
-#
-#   http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing,
-# software distributed under the License is distributed on an
-# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-# KIND, either express or implied.  See the License for the
-# specific language governing permissions and limitations
-# under the License.
-#
-
-qpid.name=${qpid.name}
-qpid.version=${qpid.version}
-qpid.version.suffix=${qpid.version.suffix}
-qpid.svnversion=${buildNumber}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/qpid-broker-j/blob/6c96879f/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index 7062c05..b30f366 100644
--- a/pom.xml
+++ b/pom.xml
@@ -148,6 +148,8 @@
     <apache-rat-plugin-version>0.11</apache-rat-plugin-version>
     <maven-docbx-plugin-version>2.0.15</maven-docbx-plugin-version>
     <maven-docbook-xml-plugin-version>5.0-all</maven-docbook-xml-plugin-version>
+    <buildnumber-maven-plugin-version>1.3</buildnumber-maven-plugin-version>
+    <maven-jar-plugin-version>3.0.0</maven-jar-plugin-version>
   </properties>
 
   <modules>
@@ -703,6 +705,11 @@
           <version>${jacoco-plugin-version}</version>
         </plugin>
         <plugin>
+          <groupId>org.apache.maven.plugins</groupId>
+          <artifactId>maven-jar-plugin</artifactId>
+          <version>${maven-jar-plugin-version}</version>
+        </plugin>
+        <plugin>
           <groupId>org.codehaus.mojo</groupId>
           <artifactId>license-maven-plugin</artifactId>
           <version>${license-maven-plugin-version}</version>
@@ -741,9 +748,37 @@
         </plugin>
       </plugins>
     </pluginManagement>
-
     <plugins>
       <plugin>
+        <groupId>org.codehaus.mojo</groupId>
+        <artifactId>buildnumber-maven-plugin</artifactId>
+        <version>${buildnumber-maven-plugin-version}</version>
+        <executions>
+          <execution>
+            <phase>validate</phase>
+            <goals>
+              <goal>create</goal>
+            </goals>
+          </execution>
+        </executions>
+        <configuration>
+          <doCheck>false</doCheck>
+          <doUpdate>false</doUpdate>
+        </configuration>
+      </plugin>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-jar-plugin</artifactId>
+        <version>${maven-jar-plugin-version}</version>
+        <configuration>
+          <archive>
+            <manifestEntries>
+              <Implementation-Build>${buildNumber}</Implementation-Build>
+            </manifestEntries>
+          </archive>
+        </configuration>
+      </plugin>
+      <plugin>
         <groupId>org.apache.maven.plugins</groupId>
         <artifactId>maven-antrun-plugin</artifactId>
         <executions>


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org


Mime
View raw message