You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@reef.apache.org by yu...@apache.org on 2014/11/19 17:58:56 UTC

incubator-reef git commit: [REEF-43]: Get version number from pom

Repository: incubator-reef
Updated Branches:
  refs/heads/master e9eb00fbe -> 57d3e3e12


[REEF-43]: Get version number from pom

The REEF interface defines a method getVersion(), and a hard-coded
variable REEF_VERSION, set to "0.6-SNAPSHOT".
However, it has been out of date and is not a viable solution indeed.
This PR defines an injectable class Version to get the version number
from pom (via a properties file).

JIRA:
[REEF-43] https://issues.apache.org/jira/browse/REEF-43

Author: chobrian <ch...@apache.org>

Closes #19


Project: http://git-wip-us.apache.org/repos/asf/incubator-reef/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-reef/commit/57d3e3e1
Tree: http://git-wip-us.apache.org/repos/asf/incubator-reef/tree/57d3e3e1
Diff: http://git-wip-us.apache.org/repos/asf/incubator-reef/diff/57d3e3e1

Branch: refs/heads/master
Commit: 57d3e3e12ff6b460911099027db9b983dc26161e
Parents: e9eb00f
Author: chobrian <ch...@apache.org>
Authored: Tue Nov 18 16:03:55 2014 +0900
Committer: Yunseong Lee <yu...@apache.org>
Committed: Thu Nov 20 01:47:40 2014 +0900

----------------------------------------------------------------------
 reef-common/pom.xml                             | 16 +++++
 .../main/java/org/apache/reef/client/REEF.java  |  2 -
 .../common/client/JobSubmissionHelper.java      |  9 ++-
 .../java/org/apache/reef/util/REEFVersion.java  | 68 ++++++++++++++++++++
 .../src/main/resources/version.properties       | 18 ++++++
 5 files changed, 108 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/57d3e3e1/reef-common/pom.xml
----------------------------------------------------------------------
diff --git a/reef-common/pom.xml b/reef-common/pom.xml
index eb9549d..abc56f0 100644
--- a/reef-common/pom.xml
+++ b/reef-common/pom.xml
@@ -79,6 +79,22 @@ under the License.
                 </executions>
             </plugin>
         </plugins>
+        <resources>
+            <resource>
+                <directory>${basedir}/src/main/resources</directory>
+                <includes>
+                    <include>version.properties</include>
+                </includes>
+                <filtering>true</filtering>
+            </resource>
+            <resource>
+                <directory>${basedir}/src/main/resources</directory>
+                <excludes>
+                    <exclude>version.properties</exclude>
+                </excludes>
+                <filtering>false</filtering>
+            </resource>
+        </resources>
     </build>
 
     <dependencies>

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/57d3e3e1/reef-common/src/main/java/org/apache/reef/client/REEF.java
----------------------------------------------------------------------
diff --git a/reef-common/src/main/java/org/apache/reef/client/REEF.java b/reef-common/src/main/java/org/apache/reef/client/REEF.java
index c0f908e..9020035 100644
--- a/reef-common/src/main/java/org/apache/reef/client/REEF.java
+++ b/reef-common/src/main/java/org/apache/reef/client/REEF.java
@@ -37,8 +37,6 @@ import org.apache.reef.tang.annotations.DefaultImplementation;
 @DefaultImplementation(REEFImplementation.class)
 public interface REEF extends AutoCloseable {
 
-  static final String REEF_VERSION = "0.6-SNAPSHOT";
-
   /**
    * Close the resourcemanager connection.
    */

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/57d3e3e1/reef-common/src/main/java/org/apache/reef/runtime/common/client/JobSubmissionHelper.java
----------------------------------------------------------------------
diff --git a/reef-common/src/main/java/org/apache/reef/runtime/common/client/JobSubmissionHelper.java b/reef-common/src/main/java/org/apache/reef/runtime/common/client/JobSubmissionHelper.java
index d48ef60..fa06be5 100644
--- a/reef-common/src/main/java/org/apache/reef/runtime/common/client/JobSubmissionHelper.java
+++ b/reef-common/src/main/java/org/apache/reef/runtime/common/client/JobSubmissionHelper.java
@@ -18,7 +18,6 @@
  */
 package org.apache.reef.runtime.common.client;
 
-import org.apache.reef.client.REEF;
 import org.apache.reef.driver.parameters.*;
 import org.apache.reef.proto.ClientRuntimeProtocol;
 import org.apache.reef.proto.ReefServiceProtos;
@@ -28,6 +27,7 @@ import org.apache.reef.tang.Tang;
 import org.apache.reef.tang.exceptions.InjectionException;
 import org.apache.reef.tang.formats.ConfigurationSerializer;
 import org.apache.reef.util.JARFileMaker;
+import org.apache.reef.util.REEFVersion;
 
 import javax.inject.Inject;
 import java.io.File;
@@ -58,10 +58,13 @@ final class JobSubmissionHelper {
   private static final Logger LOG = Logger.getLogger(JobSubmissionHelper.class.getName());
 
   private final ConfigurationSerializer configurationSerializer;
+  private final REEFVersion version;
 
   @Inject
-  JobSubmissionHelper(ConfigurationSerializer configurationSerializer) {
+  JobSubmissionHelper(final ConfigurationSerializer configurationSerializer,
+                      final REEFVersion version) {
     this.configurationSerializer = configurationSerializer;
+    this.version = version;
   }
 
   /**
@@ -165,6 +168,6 @@ final class JobSubmissionHelper {
    * @return the version string for REEF.
    */
   String getVersion() {
-    return REEF.REEF_VERSION;
+    return version.getVersion();
   }
 }

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/57d3e3e1/reef-common/src/main/java/org/apache/reef/util/REEFVersion.java
----------------------------------------------------------------------
diff --git a/reef-common/src/main/java/org/apache/reef/util/REEFVersion.java b/reef-common/src/main/java/org/apache/reef/util/REEFVersion.java
new file mode 100644
index 0000000..dd77bbc
--- /dev/null
+++ b/reef-common/src/main/java/org/apache/reef/util/REEFVersion.java
@@ -0,0 +1,68 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.reef.util;
+
+import javax.inject.Inject;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Properties;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * Version information, retrieved from the pom (via a properties file reference)
+ */
+public final class REEFVersion {
+
+  private final static Logger LOG = Logger.getLogger(REEFVersion.class.getName());
+
+  private final static String FILENAME = "version.properties";
+  private final static String VERSION_KEY = "version";
+  private final static String VERSION_DEFAULT = "unknown";
+
+  private final String version;
+
+  @Inject
+  public REEFVersion() {
+    this.version = loadVersion();
+  }
+
+  private static String loadVersion() {
+    String version;
+    try (final InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream(FILENAME)) {
+      if (is == null) {
+        throw new IOException(FILENAME + " not found");
+      }
+      final Properties properties = new Properties();
+      properties.load(is);
+      version = properties.getProperty(VERSION_KEY, VERSION_DEFAULT);
+    } catch (IOException e) {
+      LOG.log(Level.WARNING, "Could not find REEF version");
+      version = VERSION_DEFAULT;
+    }
+    return version;
+  }
+
+  /**
+   * @return the version string for REEF.
+   */
+  public String getVersion() {
+    return version;
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/57d3e3e1/reef-common/src/main/resources/version.properties
----------------------------------------------------------------------
diff --git a/reef-common/src/main/resources/version.properties b/reef-common/src/main/resources/version.properties
new file mode 100644
index 0000000..846f2a0
--- /dev/null
+++ b/reef-common/src/main/resources/version.properties
@@ -0,0 +1,18 @@
+ # Licensed to the Apache Software Foundation (ASF) under one
+ # or more contributor license agreements.  See the NOTICE file
+ # distributed with this work for additional information
+ # regarding copyright ownership.  The ASF licenses this file
+ # to you under the Apache License, Version 2.0 (the
+ # "License"); you may not use this file except in compliance
+ # with the License.  You may obtain a copy of the License at
+ #
+ #   http://www.apache.org/licenses/LICENSE-2.0
+ #
+ # Unless required by applicable law or agreed to in writing,
+ # software distributed under the License is distributed on an
+ # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ # KIND, either express or implied.  See the License for the
+ # specific language governing permissions and limitations
+ # under the License.
+
+version=${pom.version}