From 5c0d335937dcc8448bc04003daa8a0ae0b0c2e9c Mon Sep 17 00:00:00 2001
From: Matthew Swift <matthew.swift@forgerock.com>
Date: Wed, 15 Jan 2014 15:05:23 +0000
Subject: [PATCH] Finish migrating DynamicConstants to ProductInformation class:
---
opendj-sdk/opendj-server/src/main/java/org/forgerock/opendj/server/core/ProductInformation.java | 293 ++++++++++++++++++++++++++++++++++++++++++++++--
opendj-sdk/opendj-server/src/test/java/org/forgerock/opendj/server/core/ProductInformationTest.java | 14 ++
opendj-sdk/opendj-server/pom.xml | 13 +-
opendj-sdk/opendj-server/src/main/resources/META-INF/product/opendj.properties | 15 +-
4 files changed, 306 insertions(+), 29 deletions(-)
diff --git a/opendj-sdk/opendj-server/pom.xml b/opendj-sdk/opendj-server/pom.xml
index 5acd4e1..007710c 100644
--- a/opendj-sdk/opendj-server/pom.xml
+++ b/opendj-sdk/opendj-server/pom.xml
@@ -39,14 +39,14 @@
</description>
<packaging>jar</packaging>
<properties>
- <!-- Product properties -->
+ <!-- Product information properties -->
<shortProductName>OpenDJ</shortProductName>
- <issuesFixIds></issuesFixIds>
+ <patchFixIds></patchFixIds>
<isDebugBuild>false</isDebugBuild>
- <docReferenceHome>http://opendj.forgerock.org/</docReferenceHome>
- <docReferenceWiki>http://opendj.forgerock.org/docs.html</docReferenceWiki>
- <docQuickRefGuide>http://opendj.forgerock.org/doc/admin-guide/index.html</docQuickRefGuide>
- <adminGuideUrl>http://opendj.forgerock.org/doc/admin-guide/index.html</adminGuideUrl>
+ <docHomepageUrl>http://opendj.forgerock.org/</docHomepageUrl>
+ <docWikiUrl>http://opendj.forgerock.org/docs.html</docWikiUrl>
+ <docGuideRefUrl>http://opendj.forgerock.org/doc/admin-guide/index.html</docGuideRefUrl>
+ <docGuideAdminUrl>http://opendj.forgerock.org/doc/admin-guide/index.html</docGuideAdminUrl>
</properties>
<dependencies>
<dependency>
@@ -125,6 +125,7 @@
<configuration>
<useLastCommittedRevision>true</useLastCommittedRevision>
<buildNumberPropertyName>buildRevision</buildNumberPropertyName>
+ <revisionOnScmFailure>-1</revisionOnScmFailure>
</configuration>
</execution>
<execution>
diff --git a/opendj-sdk/opendj-server/src/main/java/org/forgerock/opendj/server/core/ProductInformation.java b/opendj-sdk/opendj-server/src/main/java/org/forgerock/opendj/server/core/ProductInformation.java
index 31ba691..11a78ad 100644
--- a/opendj-sdk/opendj-server/src/main/java/org/forgerock/opendj/server/core/ProductInformation.java
+++ b/opendj-sdk/opendj-server/src/main/java/org/forgerock/opendj/server/core/ProductInformation.java
@@ -33,11 +33,11 @@
import java.util.Properties;
/**
- * Product information, including version information.
+ * OpenDJ product information, including version number, build information, and
+ * references to documentation.
*/
public final class ProductInformation {
private static final ProductInformation DEFAULT = new ProductInformation("opendj");
- private final Properties properties;
/**
* Returns the singleton product information instance.
@@ -48,10 +48,13 @@
return DEFAULT;
}
- private ProductInformation(String productName) {
- // Load the resource file.
- String resourceName = "/META-INF/product/" + productName + ".properties";
- InputStream stream = getClass().getResourceAsStream(resourceName);
+ private final Properties properties;
+ private final String versionFull;
+ private final String versionPrintable;
+
+ private ProductInformation(final String productName) {
+ final String resourceName = "/META-INF/product/" + productName + ".properties";
+ final InputStream stream = getClass().getResourceAsStream(resourceName);
if (stream == null) {
throw new MissingResourceException("Can't find product information " + resourceName,
@@ -61,14 +64,173 @@
properties = new Properties();
try {
properties.load(new BufferedInputStream(stream));
- } catch (IOException e) {
+ } catch (final IOException e) {
throw new MissingResourceException("Can't load product information " + resourceName
+ " due to IO exception: " + e.getMessage(), productName, "");
}
+
+ versionFull =
+ productName() + " " + version()
+ + (patchFixIds().length() > 0 ? "+" + patchFixIds() : "");
+ versionPrintable =
+ versionFull + System.getProperty("line.separator") + "Build " + buildId()
+ + System.getProperty("line.separator");
}
/**
- * Returns the short product name for the Directory Server.
+ * Returns the build ID for the generated build of the Directory Server.
+ *
+ * @return The build ID for the generated build of the Directory Server.
+ */
+ public String buildId() {
+ return properties.getProperty("build.id");
+ }
+
+ /**
+ * Returns {@code true} if this is a debug build of the Directory Server
+ * that may include additional debugging facilities not available in
+ * standard release versions.
+ *
+ * @return {@code true} if this is a debug build of the Directory Server
+ * that may include additional debugging facilities not available in
+ * standard release versions.
+ */
+ public boolean buildIsDebug() {
+ return Boolean.valueOf(properties.getProperty("build.isdebug"));
+ }
+
+ /**
+ * Returns the vendor for the Java version used to generate this build.
+ *
+ * @return The vendor for the Java version used to generate this build.
+ */
+ public String buildJavaVendor() {
+ return properties.getProperty("build.java.vendor");
+ }
+
+ /**
+ * Returns the Java version used to generate this build.
+ *
+ * @return The Java version used to generate this build.
+ */
+ public String buildJavaVersion() {
+ return properties.getProperty("build.java.version");
+ }
+
+ /**
+ * Returns the vendor for the JVM used to generate this build.
+ *
+ * @return The vendor for the JVM used to generate this build.
+ */
+ public String buildJvmVendor() {
+ return properties.getProperty("build.jvm.vendor");
+ }
+
+ /**
+ * Returns the JVM version used to generate this build.
+ *
+ * @return The JVM version used to generate this build.
+ */
+ public String buildJvmVersion() {
+ return properties.getProperty("build.jvm.version");
+ }
+
+ /**
+ * Returns the operating system on which this build was generated.
+ *
+ * @return The operating system on which this build was generated.
+ */
+ public String buildOs() {
+ return properties.getProperty("build.os");
+ }
+
+ /**
+ * Returns the username of the user that created this build.
+ *
+ * @return The username of the user that created this build.
+ */
+ public String buildUser() {
+ return properties.getProperty("build.user");
+ }
+
+ /**
+ * Returns the URL of the product WIKI page.
+ *
+ * @return The URL of the product WIKI page.
+ */
+ public String documentationAdminGuideUrl() {
+ return properties.getProperty("doc.guide.admin.url");
+ }
+
+ /**
+ * Returns the URL of the product home page.
+ *
+ * @return The URL of the product home page.
+ */
+ public String documentationHomePageUrl() {
+ return properties.getProperty("doc.homepage.url");
+ }
+
+ /**
+ * Returns the URL of the product WIKI page.
+ *
+ * @return The URL of the product WIKI page.
+ */
+ public String documentationReferenceGuideUrl() {
+ return properties.getProperty("doc.guide.ref.url");
+ }
+
+ /**
+ * Returns the URL of the product WIKI page.
+ *
+ * @return The URL of the product WIKI page.
+ */
+ public String documentationWikiUrl() {
+ return properties.getProperty("doc.wiki.url");
+ }
+
+ /**
+ * Returns the set of bug IDs for fixes included in this build of the
+ * Directory Server.
+ *
+ * @return The set of bug IDs for fixes included in this build of the
+ * Directory Server.
+ */
+ public String patchFixIds() {
+ return properties.getProperty("patch.fix.ids");
+ }
+
+ /**
+ * Returns the full product name for the Directory Server, which may contain
+ * white space.
+ *
+ * @return The full product name for the Directory Server.
+ */
+ public String productName() {
+ return properties.getProperty("product.name");
+ }
+
+ /**
+ * Returns the product publication date.
+ *
+ * @return The product publication date.
+ */
+ public String productPublicationDate() {
+ return properties.getProperty("product.publication.date");
+ }
+
+ /**
+ * Returns the product release date.
+ *
+ * @return The product release date.
+ */
+ public String productReleaseDate() {
+ return properties.getProperty("product.release.date");
+ }
+
+ /**
+ * Returns the short product name for the Directory Server, suitable for use
+ * in file names.
*
* @return The short product name for the Directory Server.
*/
@@ -77,12 +239,119 @@
}
/**
- * Returns the official full product name for the Directory Server.
+ * Returns the revision number of the source repository on which this build
+ * is based.
*
- * @return The official full product name for the Directory Server.
+ * @return The revision number of the source repository on which this build
+ * is based.
*/
- public String productName() {
- return properties.getProperty("product.name");
+ public String scmRevision() {
+ return properties.getProperty("scm.revision");
}
+ /**
+ * Returns the URL of the source repository location on which this build is
+ * based.
+ *
+ * @return The URL of the source repository location on which this build is
+ * based.
+ */
+ public String scmUrl() {
+ return properties.getProperty("scm.url");
+ }
+
+ /**
+ * Returns the version number for the Directory Server. The return string
+ * will have the format {@code major.minor.point[-qualifier]}.
+ *
+ * @return The version number for the Directory Server.
+ */
+ public String version() {
+ return properties.getProperty("version");
+ }
+
+ /**
+ * Returns the build number for the Directory Server.
+ *
+ * @return The build number for the Directory Server.
+ */
+ public int versionBuildNumber() {
+ return Integer.valueOf(properties.getProperty("version.build"));
+ }
+
+ /**
+ * Returns the compact version string for this product, suitable for use in
+ * path names and similar cases.
+ *
+ * @return The compact version string for this product, suitable for use in
+ * path names and similar cases.
+ */
+ public String versionCompact() {
+ return properties.getProperty("version.compact");
+ }
+
+ /**
+ * Returns the full version string for this product.
+ *
+ * @return The full version string for this product.
+ */
+ public String versionFull() {
+ return versionFull;
+ }
+
+ /**
+ * Returns the major version number for the Directory Server.
+ *
+ * @return The major version number for the Directory Server.
+ */
+ public int versionMajorNumber() {
+ return Integer.valueOf(properties.getProperty("version.major"));
+ }
+
+ /**
+ * Returns the minor version number for the Directory Server.
+ *
+ * @return The minor version number for the Directory Server.
+ */
+ public int versionMinorNumber() {
+ return Integer.valueOf(properties.getProperty("version.minor"));
+ }
+
+ /**
+ * Returns the point version number for the Directory Server.
+ *
+ * @return The point version number for the Directory Server.
+ */
+ public int versionPointNumber() {
+ return Integer.valueOf(properties.getProperty("version.point"));
+ }
+
+ /**
+ * Returns the printable version string for this product.
+ *
+ * @return The printable version string for this product.
+ */
+ public String versionPrintable() {
+ return versionPrintable;
+ }
+
+ /**
+ * Returns the version qualifier string for the Directory Server.
+ *
+ * @return The version qualifier string for the Directory Server.
+ */
+ public String versionQualifier() {
+ return properties.getProperty("version.qualifier");
+ }
+
+ /**
+ * Returns the revision number of the source repository on which this build
+ * is based.
+ *
+ * @return The revision number of the source repository on which this build
+ * is based.
+ */
+ public String versionRevision() {
+ return properties.getProperty("scm.revision");
+ }
}
diff --git a/opendj-sdk/opendj-server/src/main/resources/META-INF/product/opendj.properties b/opendj-sdk/opendj-server/src/main/resources/META-INF/product/opendj.properties
index b47d130..5918560 100644
--- a/opendj-sdk/opendj-server/src/main/resources/META-INF/product/opendj.properties
+++ b/opendj-sdk/opendj-server/src/main/resources/META-INF/product/opendj.properties
@@ -10,14 +10,11 @@
# Version.
version=${project.version}
version.compact=${shortProductName}-${project.version}
-version.full=${project.name} ${project.version} ${issuesFixIds}
-version.printable=${project.name} ${project.version} ${issuesFixIds}\nBuild ${buildDateTime}\n
version.major=${parsedVersion.majorVersion}
version.minor=${parsedVersion.minorVersion}
version.point=${parsedVersion.incrementalVersion}
version.qualifier=${parsedVersion.qualifier}
version.build=${parsedVersion.buildNumber}
-version.revision=${buildRevision}
# Additional build information.
build.id=${buildDateTime}
@@ -27,17 +24,17 @@
build.jvm.version=${java.vm.version}
build.jvm.vendor=${java.vm.vendor}
build.os=${os.name} ${os.version} ${os.arch}
-build.isDebug=${isDebugBuild}
+build.isdebug=${isDebugBuild}
# Patch bug fix IDs for this build.
-patch.fix.ids=${issuesFixIds}
+patch.fix.ids=${patchFixIds}
# Source version.
scm.url=${scm.url}
scm.revision=${buildRevision}
# Documentation.
-doc.home=${docReferenceHome}
-doc.wiki=${docReferenceWiki}
-doc.guide.ref=${docQuickRefGuide}
-doc.guide.admin=${adminGuideUrl}
+doc.homepage.url=${docHomepageUrl}
+doc.wiki.url=${docWikiUrl}
+doc.guide.ref.url=${docGuideRefUrl}
+doc.guide.admin.url=${docGuideAdminUrl}
diff --git a/opendj-sdk/opendj-server/src/test/java/org/forgerock/opendj/server/core/ProductInformationTest.java b/opendj-sdk/opendj-server/src/test/java/org/forgerock/opendj/server/core/ProductInformationTest.java
index 4db953f..a9c9472 100644
--- a/opendj-sdk/opendj-server/src/test/java/org/forgerock/opendj/server/core/ProductInformationTest.java
+++ b/opendj-sdk/opendj-server/src/test/java/org/forgerock/opendj/server/core/ProductInformationTest.java
@@ -34,14 +34,24 @@
@SuppressWarnings("javadoc")
@Test
public class ProductInformationTest extends ForgeRockTestCase {
+ /*
+ * This test class verifies that the product information has been generated
+ * and can be loaded at runtime. It does not attempt to exhaustively check
+ * all methods.
+ */
@Test
- public void testGetName() {
+ public void testProductName() {
assertThat(ProductInformation.getInstance().productName()).isNotNull();
}
@Test
- public void testGetShortName() {
+ public void testProductShortName() {
assertThat(ProductInformation.getInstance().productShortName()).isEqualTo("OpenDJ");
}
+
+ @Test
+ public void testVersionMajor() {
+ assertThat(ProductInformation.getInstance().versionMajorNumber()).isGreaterThanOrEqualTo(3);
+ }
}
--
Gitblit v1.10.0