You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by mm...@apache.org on 2018/05/30 18:33:39 UTC

[incubator-pulsar] branch master updated: Ship git info in jar and print at boot (#1850)

This is an automated email from the ASF dual-hosted git repository.

mmerli pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-pulsar.git


The following commit(s) were added to refs/heads/master by this push:
     new 92802e9  Ship git info in jar and print at boot (#1850)
92802e9 is described below

commit 92802e9efafc487c9c336fd9c99989cf8e5c390c
Author: Ivan Kelly <iv...@apache.org>
AuthorDate: Wed May 30 20:33:37 2018 +0200

    Ship git info in jar and print at boot (#1850)
    
    We currently print the version at boot. However, there's no guarantee
    that modifications haven't been made against that version without the
    version string being bumped. The only why to be sure is to have the
    git sha that the jar was built from.
    
    This patch packages the git information into a properties file, which
    is shipped in the jar. It requires git to be available on the PATH to
    work. If not, the file is not generated, but the build does not fail.
    
    The version printing on boot has been moved to the start of the
    PulsarService#start() method, and now prints the version as before,
    but also the git sha, the git user and email of the builder, the
    machine it was built on and the time it was built.
---
 pom.xml                                            | 29 ++++++++++++++++++++++
 .../org/apache/pulsar/broker/PulsarService.java    | 10 +++++---
 .../utils/PulsarBrokerVersionStringUtils.java      | 26 +++++++++++++++++++
 3 files changed, 62 insertions(+), 3 deletions(-)

diff --git a/pom.xml b/pom.xml
index d50d184..651b2b4 100644
--- a/pom.xml
+++ b/pom.xml
@@ -1045,6 +1045,30 @@ flexible messaging model and an intuitive client API.</description>
           </excludes>
         </configuration>
       </plugin>
+      <plugin>
+        <groupId>pl.project13.maven</groupId>
+        <artifactId>git-commit-id-plugin</artifactId>
+        <executions>
+          <execution>
+            <id>git-info</id>
+            <goals>
+              <goal>revision</goal>
+            </goals>
+          </execution>
+        </executions>
+        <configuration>
+          <useNativeGit>true</useNativeGit>
+          <prefix>git</prefix>
+          <verbose>true</verbose>
+          <generateGitPropertiesFile>true</generateGitPropertiesFile>
+          <generateGitPropertiesFilename>${project.build.outputDirectory}/${project.artifactId}-git.properties</generateGitPropertiesFilename>
+          <failOnUnableToExtractRepoInfo>false</failOnUnableToExtractRepoInfo>
+          <format>properties</format>
+          <gitDescribe>
+            <skip>true</skip>
+          </gitDescribe>
+        </configuration>
+      </plugin>
     </plugins>
 
     <pluginManagement>
@@ -1117,6 +1141,11 @@ flexible messaging model and an intuitive client API.</description>
             </lifecycleMappingMetadata>
           </configuration>
         </plugin>
+        <plugin>
+          <groupId>pl.project13.maven</groupId>
+          <artifactId>git-commit-id-plugin</artifactId>
+          <version>2.2.4</version>
+        </plugin>
       </plugins>
     </pluginManagement>
     <extensions>
diff --git a/pulsar-broker/src/main/java/org/apache/pulsar/broker/PulsarService.java b/pulsar-broker/src/main/java/org/apache/pulsar/broker/PulsarService.java
index bfc4ce5..484235f 100644
--- a/pulsar-broker/src/main/java/org/apache/pulsar/broker/PulsarService.java
+++ b/pulsar-broker/src/main/java/org/apache/pulsar/broker/PulsarService.java
@@ -308,6 +308,13 @@ public class PulsarService implements AutoCloseable {
     public void start() throws PulsarServerException {
         mutex.lock();
 
+        LOG.info("Starting Pulsar Broker service; version: '{}'", ( brokerVersion != null ? brokerVersion : "unknown" )  );
+        LOG.info("Git Revision {}", PulsarBrokerVersionStringUtils.getGitSha());
+        LOG.info("Built by {} on {} at {}",
+                 PulsarBrokerVersionStringUtils.getBuildUser(),
+                 PulsarBrokerVersionStringUtils.getBuildHost(),
+                 PulsarBrokerVersionStringUtils.getBuildTime());
+
         try {
             if (state != State.Init) {
                 throw new PulsarServerException("Cannot start the service once it was stopped");
@@ -336,7 +343,6 @@ public class PulsarService implements AutoCloseable {
 
             this.offloader = createManagedLedgerOffloader(this.getConfiguration());
 
-            LOG.info("Starting Pulsar Broker service; version: '{}'", ( brokerVersion != null ? brokerVersion : "unknown" )  );
             brokerService.start();
 
             this.webService = new WebService(this);
@@ -421,8 +427,6 @@ public class PulsarService implements AutoCloseable {
 
             leaderElectionService.start();
 
-            LOG.info("Starting Pulsar Broker service; version: '{}'", ( brokerVersion != null ? brokerVersion : "unknown" )  );
-
             webService.start();
 
             this.metricsGenerator = new MetricsGenerator(this);
diff --git a/pulsar-broker/src/main/java/org/apache/pulsar/utils/PulsarBrokerVersionStringUtils.java b/pulsar-broker/src/main/java/org/apache/pulsar/utils/PulsarBrokerVersionStringUtils.java
index fd4d7ed..96553f2 100644
--- a/pulsar-broker/src/main/java/org/apache/pulsar/utils/PulsarBrokerVersionStringUtils.java
+++ b/pulsar-broker/src/main/java/org/apache/pulsar/utils/PulsarBrokerVersionStringUtils.java
@@ -31,6 +31,8 @@ public class PulsarBrokerVersionStringUtils {
     private static final Logger LOG = LoggerFactory.getLogger(PulsarBrokerVersionStringUtils.class);
 
     private static final String RESOURCE_NAME = "pulsar-broker-version.properties";
+    private static final String GIT_RESOURCE_NAME = "pulsar-broker-git.properties";
+
     private static final Pattern majorMinorPatchPattern = Pattern.compile("([1-9]+[0-9]*)\\.([1-9]+[0-9]*)\\.([1-9]+[0-9]*)(.*)");
 
     // If the version string does not contain a patch version, add one so the
@@ -101,4 +103,28 @@ public class PulsarBrokerVersionStringUtils {
     public static String getNormalizedVersionString() {
         return fixVersionString(getPropertyFromResource(RESOURCE_NAME, "version"));
     }
+
+    public static String getGitSha() {
+        String commit = getPropertyFromResource(GIT_RESOURCE_NAME, "git.commit.id");
+        String dirtyString = getPropertyFromResource(GIT_RESOURCE_NAME, "git.dirty");
+        if (dirtyString == null || Boolean.valueOf(dirtyString)) {
+            return commit + "(dirty)";
+        } else {
+            return commit;
+        }
+    }
+
+    public static String getBuildUser() {
+        String email = getPropertyFromResource(GIT_RESOURCE_NAME, "git.build.user.email");
+        String name = getPropertyFromResource(GIT_RESOURCE_NAME, "git.build.user.name");
+        return String.format("%s <%s>", name, email);
+    }
+
+    public static String getBuildHost() {
+        return getPropertyFromResource(GIT_RESOURCE_NAME, "git.build.host");
+    }
+
+    public static String getBuildTime() {
+        return getPropertyFromResource(GIT_RESOURCE_NAME, "git.build.time");
+    }
 }

-- 
To stop receiving notification emails like this one, please contact
mmerli@apache.org.