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

[GitHub] merlimat closed pull request #1850: Ship git info in jar and print at boot

merlimat closed pull request #1850: Ship git info in jar and print at boot
URL: https://github.com/apache/incubator-pulsar/pull/1850
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/pom.xml b/pom.xml
index a63515a740..73ed8cf049 100644
--- a/pom.xml
+++ b/pom.xml
@@ -1039,6 +1039,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>
@@ -1111,6 +1135,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 bfc4ce51b4..484235fe27 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 ServiceConfiguration getConfiguration() {
     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 void start() throws PulsarServerException {
 
             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 synchronized void brokerIsAFollowerNow() {
 
             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 fd4d7ed9cf..96553f26a9 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 @@
     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 @@ private static String getPropertyFromResource(String resource, String propertyNa
     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");
+    }
 }


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services