feat(gateway-core) Capture Git information during build and make available at runtime. Display git info in Version when SNAPSHOT build.
MODIFY
gateway/engine/core/src/main/java/io/apiman/gateway/engine/Version.java
gateway/engine/core/src/main/java/io/apiman/gateway/engine/Version.java
@@ -21,8 +21,6 @@ import java.net.URL;
import java.util.Date;
import java.util.Properties;
-import org.apache.commons.io.IOUtils;
-
/**
* Accessor - used to get the current version of the engine.
*
@@ -35,8 +33,10 @@ public class Version {
return instance;
}
+ private Properties allProperties;
private String versionString;
private String versionDate;
+ private String vcsDescribe;
/**
* Constructor.
@@ -48,23 +48,21 @@ public class Version {
/**
* Loads the version info from version.properties.
*/
+ @SuppressWarnings("nls")
private void load() {
- URL url = Version.class.getResource("version.properties"); //$NON-NLS-1$
+ URL url = Version.class.getResource("version.properties");
if (url == null) {
- this.versionString = "Unknown"; //$NON-NLS-1$
+ this.versionString = "Unknown";
this.versionDate = new Date().toString();
} else {
- InputStream is = null;
- Properties props = new Properties();
- try {
- is = url.openStream();
- props.load(is);
- this.versionString = props.getProperty("version", "Unknown"); //$NON-NLS-1$ //$NON-NLS-2$
- this.versionDate = props.getProperty("date", new Date().toString()); //$NON-NLS-1$
+ allProperties = new Properties();
+ try(InputStream is = url.openStream()){
+ allProperties.load(is);
+ this.versionString = allProperties.getProperty("version", "Unknown");
+ this.versionDate = allProperties.getProperty("date", new Date().toString());
+ this.vcsDescribe = allProperties.getProperty("git.commit.id.describe", "Non-Git Build");
} catch (IOException e) {
throw new RuntimeException(e);
- } finally {
- IOUtils.closeQuietly(is);
}
}
}
@@ -83,4 +81,21 @@ public class Version {
return versionDate;
}
+ /**
+ * @return the verbose version output
+ */
+ public String getVerbose() {
+ return allProperties.toString();
+ }
+
+ /**
+ * The version control system (VCS) commit description. Particularly useful for identifying which
+ * code point a SNAPSHOT was using. Presently git.
+ *
+ * @return the VCS commit description
+ */
+ public String getVcsCommitDescription() {
+ return vcsDescribe;
+ }
+
}

MODIFY
gateway/engine/core/src/main/resources-filtered/io/apiman/gateway/engine/version.properties
gateway/engine/core/src/main/resources-filtered/io/apiman/gateway/engine/version.properties
version=${project.version}
date=${timestamp}
+git.tags=${git.tags}
+git.branch=${git.branch}
+git.dirty=${git.dirty}
+git.remote.origin.url=${git.remote.origin.url}
+git.commit.id=${git.commit.id}
+git.commit.id.abbrev=${git.commit.id.abbrev}
+git.commit.id.describe=${git.commit.id.describe}
+git.commit.id.describe-short=${git.commit.id.describe-short}
+git.commit.user.name=${git.commit.user.name}
+git.commit.user.email=${git.commit.user.email}
+git.commit.message.full=${git.commit.message.full}
+git.commit.message.short=${git.commit.message.short}
+git.commit.time=${git.commit.time}
+git.closest.tag.name=${git.closest.tag.name}
+git.closest.tag.commit.count=${git.closest.tag.commit.count}
+git.build.user.name=${git.build.user.name}
+git.build.user.email=${git.build.user.email}
+git.build.time=${git.build.time}
+git.build.host=${git.build.host}
+git.build.version=${git.build.version}

MODIFY
gateway/platforms/vertx3/vertx3/src/main/java/io/apiman/gateway/platforms/vertx3/ApimanVersionCommand.java
gateway/platforms/vertx3/vertx3/src/main/java/io/apiman/gateway/platforms/vertx3/ApimanVersionCommand.java
@@ -41,7 +41,7 @@ public class ApimanVersionCommand extends DefaultCommand {
public static String getApimanVersion() {
if (Version.get().getVersionString().contains("SNAPSHOT")) {
- return Version.get().getVersionString() + " @ " + Version.get().getVersionDate();
+ return Version.get().getVersionString() + " " + Version.get().getVcsCommitDescription() + Version.get().getVersionDate();
} else {
return Version.get().getVersionString();
}

MODIFY
pom.xml
pom.xml
<configuration>
<fail>true</fail>
<rules>
- <illegalTransitiveDependencyCheck
- implementation="de.is24.maven.enforcer.rules.IllegalTransitiveDependencyCheck">
+ <illegalTransitiveDependencyCheck implementation="de.is24.maven.enforcer.rules.IllegalTransitiveDependencyCheck">
<reportOnly>false</reportOnly>
<regexIgnoredClasses>
<regexIgnoredClass>javax\..+</regexIgnoredClass>
</plugins>
</pluginManagement>
<plugins>
+ <plugin>
+ <groupId>pl.project13.maven</groupId>
+ <artifactId>git-commit-id-plugin</artifactId>
+ <version>2.2.1</version>
+ <executions>
+ <execution>
+ <id>get-the-git-infos</id>
+ <goals>
+ <goal>revision</goal>
+ </goals>
+ </execution>
+ </executions>
+ <configuration>
+ <dotGitDirectory>${project.basedir}/.git</dotGitDirectory>
+ <dateFormat>yyyy-MM-dd'T'HH:mm:ss'Z'</dateFormat>
+ <dateFormatTimeZone>UTC</dateFormatTimeZone>
+ <verbose>false</verbose>
+ <generateGitPropertiesFile>false</generateGitPropertiesFile>
+ <skipPoms>true</skipPoms>
+ <injectAllReactorProjects>false</injectAllReactorProjects>
+ <failOnNoGitDirectory>true</failOnNoGitDirectory>
+ <failOnUnableToExtractRepoInfo>true</failOnUnableToExtractRepoInfo>
+ <useNativeGit>false</useNativeGit>
+ <abbrevLength>7</abbrevLength>
+ <commitIdGenerationMode>flat</commitIdGenerationMode>
+ <gitDescribe>
+ <always>false</always>
+ <!-- Chars to displayed as the commit object id? 7 is git's default -->
+ <abbrev>7</abbrev>
+ <!-- When the build is triggered while the repo is in "dirty state", append this suffix -->
+ <dirty>-dirty</dirty>
+ <!-- Only consider tags matching the given pattern. This can be used to avoid leaking private tags from the repository. -->
+ <match>*</match>
+ <!-- When you run git-describe it only looks only for *annotated tags* by default -->
+ <tags>false</tags>
+ <!--
+ always print using the "tag-commits_from_tag-g_commit_id-maybe_dirty" format, even if "on" a tag.
+ The distance will always be 0 if you're "on" the tag.
+ -->
+ <forceLongFormat>false</forceLongFormat>
+ </gitDescribe>
+ </configuration>
+ </plugin>
<!-- Enforcer-related stuff -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>

feat(gateway-core) Capture Git information during build and make available at runtime. Display git info in Version when SNAPSHOT build.