Author: [log in to unmask]
Date: Tue Apr 14 15:23:24 2015
New Revision: 2697
Log:
Print out HPS Java project properties when running command line job. HPSJAVA-487
Added:
java/trunk/distribution/src/main/java/org/hps/HPSJavaProperties.java
java/trunk/distribution/src/main/resources/
java/trunk/distribution/src/main/resources/org/
java/trunk/distribution/src/main/resources/org/hps/
java/trunk/distribution/src/main/resources/org/hps/hps-java.properties
Modified:
java/trunk/distribution/pom.xml
java/trunk/record-util/src/main/java/org/hps/job/JobManager.java
Modified: java/trunk/distribution/pom.xml
=============================================================================
--- java/trunk/distribution/pom.xml (original)
+++ java/trunk/distribution/pom.xml Tue Apr 14 15:23:24 2015
@@ -6,6 +6,8 @@
<description>module for creating a standalone runnable bin jar for HPS Java</description>
<properties>
<maven.javadoc.skip>true</maven.javadoc.skip>
+ <timestamp>${maven.build.timestamp}</timestamp>
+ <maven.build.timestamp.format>yyyy-MM-dd HH:mm</maven.build.timestamp.format>
</properties>
<parent>
<groupId>org.hps</groupId>
@@ -18,7 +20,13 @@
<connection>scm:svn:svn://svn.freehep.org/hps/java/trunk/distribution/</connection>
<developerConnection>scm:svn:svn://svn.freehep.org/hps/java/trunk/distribution/</developerConnection>
</scm>
- <build>
+ <build>
+ <resources>
+ <resource>
+ <directory>src/main/resources</directory>
+ <filtering>true</filtering>
+ </resource>
+ </resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
Added: java/trunk/distribution/src/main/java/org/hps/HPSJavaProperties.java
=============================================================================
--- java/trunk/distribution/src/main/java/org/hps/HPSJavaProperties.java (added)
+++ java/trunk/distribution/src/main/java/org/hps/HPSJavaProperties.java Tue Apr 14 15:23:24 2015
@@ -0,0 +1,97 @@
+package org.hps;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Properties;
+
+/**
+ * This class provides information about the HPS Java build environment for the current distribution jar that is being
+ * executed.
+ *
+ * @author <a href="mailto:[log in to unmask]">Jeremy McCormick</a>
+ */
+public final class HPSJavaProperties {
+
+ /**
+ * Properties file containing properties with values inserted from Maven resource filtering.
+ */
+ Properties properties = new Properties();
+
+ /**
+ * Class constructor.
+ *
+ * @throws IOException if there is problem loading the properties
+ */
+ public HPSJavaProperties() throws IOException {
+ final InputStream is = getClass().getResourceAsStream("/org/hps/hps-java.properties");
+ this.properties.load(is);
+ is.close();
+ }
+
+ /**
+ * Get the Java home from the build environment.
+ *
+ * @return the Java home directory
+ */
+ public String getJavaVersion() {
+ return this.properties.getProperty("java.version");
+ }
+
+ /**
+ * Get the LCSim version string.
+ *
+ * @return the LCSim version string
+ */
+ public String getLCSimVersion() {
+ return this.properties.getProperty("lcsimVersion");
+ }
+
+ /**
+ * Get the project name.
+ *
+ * @return the project name
+ */
+ public String getProjectArtifactId() {
+ return this.properties.getProperty("project.artifactId");
+ }
+
+ /**
+ * Get the local build directory.
+ *
+ * @return the local build directory
+ */
+ public String getProjectBuildDirectory() {
+ return this.properties.getProperty("project.build.directory");
+ }
+
+ /**
+ * Get the project version.
+ *
+ * @return the project version
+ */
+ public String getProjectVersion() {
+ return this.properties.getProperty("project.version");
+ }
+
+ /**
+ * Get the Maven build timestamp.
+ *
+ * @return the Maven build timestamp
+ */
+ public String getTimestamp() {
+ return this.properties.getProperty("timestamp");
+ }
+
+ @Override
+ public String toString() {
+ final StringBuffer sb = new StringBuffer();
+ sb.append("HPS Java properties" + '\n');
+ sb.append("project.artifactId: " + getProjectArtifactId() + '\n');
+ sb.append("project.version: " + getProjectVersion() + '\n');
+ sb.append("lcsimVersion: " + getLCSimVersion() + '\n');
+ sb.append("java.version: " + getJavaVersion() + '\n');
+ sb.append("project.build.directory: " + getProjectBuildDirectory() + '\n');
+ sb.append("timestamp: " + getTimestamp() + '\n');
+ return sb.toString();
+ }
+}
Added: java/trunk/distribution/src/main/resources/org/hps/hps-java.properties
=============================================================================
--- java/trunk/distribution/src/main/resources/org/hps/hps-java.properties (added)
+++ java/trunk/distribution/src/main/resources/org/hps/hps-java.properties Tue Apr 14 15:23:24 2015
@@ -0,0 +1,7 @@
+project.artifactId: ${project.artifactId}
+project.version: ${project.version}
+timestamp: ${timestamp}
+lcsimVersion: ${lcsimVersion}
+project.build.directory: ${project.build.directory}
+java.version: ${java.version}
+project.attachedArtifact: ${project.attachedArtifact[0]}
Modified: java/trunk/record-util/src/main/java/org/hps/job/JobManager.java
=============================================================================
--- java/trunk/record-util/src/main/java/org/hps/job/JobManager.java (original)
+++ java/trunk/record-util/src/main/java/org/hps/job/JobManager.java Tue Apr 14 15:23:24 2015
@@ -27,6 +27,15 @@
* Class constructor.
*/
public JobManager() {
+
+ try {
+ // Since this is packaged with the distribution, the class is not directly accessible.
+ final Object hpsJavaProperties = Class.forName("org.hps.HPSJavaProperties").newInstance();
+ logger.info(hpsJavaProperties.toString());
+ } catch (InstantiationException | IllegalAccessException | ClassNotFoundException e) {
+ // Just don't print info if not accessible (running in test case?).
+ }
+
// Always want to reset conditions system before starting the job.
DatabaseConditionsManager.resetInstance();
}
|