You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@storm.apache.org by bo...@apache.org on 2015/01/22 22:00:17 UTC

[03/25] storm git commit: STORM-243, Record version and revision information in builds

STORM-243,Record version and revision information in builds


Project: http://git-wip-us.apache.org/repos/asf/storm/repo
Commit: http://git-wip-us.apache.org/repos/asf/storm/commit/fd03e16f
Tree: http://git-wip-us.apache.org/repos/asf/storm/tree/fd03e16f
Diff: http://git-wip-us.apache.org/repos/asf/storm/diff/fd03e16f

Branch: refs/heads/master
Commit: fd03e16f1a11bafb352dbda74f4b179ddf569bef
Parents: fa38335
Author: caofangkun <ca...@gmail.com>
Authored: Thu Oct 16 09:57:48 2014 +0800
Committer: caofangkun <ca...@gmail.com>
Committed: Thu Oct 16 09:57:48 2014 +0800

----------------------------------------------------------------------
 bin/storm                                       | 10 ++--
 storm-core/pom.xml                              | 23 ++++++++
 storm-core/src/clj/backtype/storm/ui/core.clj   | 10 +---
 .../backtype/storm/utils/VersionAnnotation.java | 20 +++++++
 .../jvm/backtype/storm/utils/VersionInfo.java   | 57 ++++++++++++++++++++
 storm-core/src/saveVersion.sh                   | 42 +++++++++++++++
 storm-dist/binary/src/main/assembly/binary.xml  |  7 ---
 7 files changed, 149 insertions(+), 20 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/storm/blob/fd03e16f/bin/storm
----------------------------------------------------------------------
diff --git a/bin/storm b/bin/storm
index fee548a..5eadb89 100755
--- a/bin/storm
+++ b/bin/storm
@@ -415,11 +415,11 @@ def version():
   
   Prints the version number of this Storm release.  
   """
-  releasefile = STORM_DIR + "/RELEASE"
-  if os.path.exists(releasefile):
-    print(open(releasefile).readline().strip())
-  else:
-    print("Unknown")
+  cppaths = [CLUSTER_CONF_DIR]
+  exec_storm_class(
+       "backtype.storm.utils.VersionInfo",
+       jvmtype=" ",
+       extrajars=[CLUSTER_CONF_DIR])
 
 def print_classpath():
     """Syntax: [storm classpath]

http://git-wip-us.apache.org/repos/asf/storm/blob/fd03e16f/storm-core/pom.xml
----------------------------------------------------------------------
diff --git a/storm-core/pom.xml b/storm-core/pom.xml
index d2938e3..514f39d 100644
--- a/storm-core/pom.xml
+++ b/storm-core/pom.xml
@@ -361,6 +361,29 @@
                     </dependency>
                 </dependencies>
             </plugin>
+            <plugin>
+                <groupId>org.codehaus.mojo</groupId>
+                <artifactId>exec-maven-plugin</artifactId>
+                <version>1.2.1</version>
+                <inherited>false</inherited>
+                <executions>
+                   <execution>
+                      <id>Version Calculation</id>
+                      <phase>generate-sources</phase>
+                      <goals>
+                          <goal>exec</goal>
+                      </goals>
+                      <configuration>
+                         <executable>sh</executable>
+                           <arguments>
+                              <argument>${basedir}/src/saveVersion.sh</argument>
+                              <argument>${project.version}</argument>
+                              <argument>${basedir}/src/jvm</argument>
+                           </arguments>
+                     </configuration>
+                  </execution>
+               </executions>
+          </plugin>
 
         </plugins>
     </build>

http://git-wip-us.apache.org/repos/asf/storm/blob/fd03e16f/storm-core/src/clj/backtype/storm/ui/core.clj
----------------------------------------------------------------------
diff --git a/storm-core/src/clj/backtype/storm/ui/core.clj b/storm-core/src/clj/backtype/storm/ui/core.clj
index 969b514..8c2541f 100644
--- a/storm-core/src/clj/backtype/storm/ui/core.clj
+++ b/storm-core/src/clj/backtype/storm/ui/core.clj
@@ -52,15 +52,9 @@
        (map #(.get_stats ^ExecutorSummary %))
        (filter not-nil?)))
 
-(defn read-storm-version
+(def read-storm-version
   "Returns a string containing the Storm version or 'Unknown'."
-  []
-  (let [storm-home (System/getProperty "storm.home")
-        release-path (format "%s/RELEASE" storm-home)
-        release-file (File. release-path)]
-    (if (and (.exists release-file) (.isFile release-file))
-      (trim (slurp release-path))
-      "Unknown")))
+  (str VersionInfo/getVersion)) 
 
 (defn component-type
   "Returns the component type (either :bolt or :spout) for a given

http://git-wip-us.apache.org/repos/asf/storm/blob/fd03e16f/storm-core/src/jvm/backtype/storm/utils/VersionAnnotation.java
----------------------------------------------------------------------
diff --git a/storm-core/src/jvm/backtype/storm/utils/VersionAnnotation.java b/storm-core/src/jvm/backtype/storm/utils/VersionAnnotation.java
new file mode 100644
index 0000000..684e8ae
--- /dev/null
+++ b/storm-core/src/jvm/backtype/storm/utils/VersionAnnotation.java
@@ -0,0 +1,20 @@
+package backtype.storm.utils;
+import java.lang.annotation.*;
+
+@Retention(RetentionPolicy.RUNTIME)
+@Target(ElementType.PACKAGE)
+public @interface VersionAnnotation {
+  String version();
+
+  String user();
+
+  String date();
+
+  String url();
+
+  String revision();
+
+  String branch();
+
+  String srcChecksum();
+}

http://git-wip-us.apache.org/repos/asf/storm/blob/fd03e16f/storm-core/src/jvm/backtype/storm/utils/VersionInfo.java
----------------------------------------------------------------------
diff --git a/storm-core/src/jvm/backtype/storm/utils/VersionInfo.java b/storm-core/src/jvm/backtype/storm/utils/VersionInfo.java
new file mode 100644
index 0000000..d19a5d1
--- /dev/null
+++ b/storm-core/src/jvm/backtype/storm/utils/VersionInfo.java
@@ -0,0 +1,57 @@
+package backtype.storm.utils;
+
+public class VersionInfo {
+  private static Package myPackage;
+  private static VersionAnnotation version;
+
+  static {
+    myPackage = VersionAnnotation.class.getPackage();
+    version = myPackage.getAnnotation(VersionAnnotation.class);
+  }
+  
+  static Package getPackage() {
+    return myPackage;
+  }
+
+  public static String getVersion() {
+    return version != null ? version.version() : "Unknown";
+  }
+
+  public static String getRevision() {
+    return version != null ? version.revision() : "Unknown";
+  }
+
+  public static String getBranch() {
+    return version != null ? version.branch() : "Unknown";
+  }
+
+  public static String getDate() {
+    return version != null ? version.date() : "Unknown";
+  }
+
+  public static String getUser() {
+    return version != null ? version.user() : "Unknown";
+  }
+
+  public static String getUrl() {
+    return version != null ? version.url() : "Unknown";
+  }
+
+  public static String getSrcChecksum() {
+    return version != null ? version.srcChecksum() : "Unknown";
+  }
+
+  public static String getBuildVersion() {
+    return VersionInfo.getVersion() + " from " + VersionInfo.getRevision()
+        + " by " + VersionInfo.getUser() + " source checksum "
+        + VersionInfo.getSrcChecksum();
+  }
+
+  public static void main(String[] args) {
+    System.out.println("Storm " + getVersion());
+    System.out.println("Subversion " + getUrl() + " -r " + getRevision());
+    System.out.println("Compiled by " + getUser() + " on " + getDate());
+    System.out.println("From source with checksum " + getSrcChecksum());
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/storm/blob/fd03e16f/storm-core/src/saveVersion.sh
----------------------------------------------------------------------
diff --git a/storm-core/src/saveVersion.sh b/storm-core/src/saveVersion.sh
new file mode 100755
index 0000000..6475418
--- /dev/null
+++ b/storm-core/src/saveVersion.sh
@@ -0,0 +1,42 @@
+s file is used to generate the package-info.java class that
+# records the version, revision, branch, user, timestamp, and url
+unset LANG
+unset LC_CTYPE
+unset LC_TIME
+version=$1
+build_dir=$2
+user=`whoami`
+date=`date`
+cwd=`pwd`
+if [ -d .git ]; then
+  revision=`git log -1 --pretty=format:"%H"`
+  hostname=`hostname`
+  branch=`git branch | sed -n -e 's/^* //p'`
+  url="git://${hostname}${cwd}"
+elif [ -d .svn ]; then
+  revision=`svn info | sed -n -e 's/Last Changed Rev: \(.*\)/\1/p'`
+  url=`svn info | sed -n -e 's/URL: \(.*\)/\1/p'`
+  # Get canonical branch (branches/X, tags/X, or trunk)
+  branch=`echo $url | sed -n -e 's,.*\(branches/.*\)$,\1,p' \
+                             -e 's,.*\(tags/.*\)$,\1,p' \
+                             -e 's,.*trunk$,trunk,p'`
+else
+  revision="Unknown"
+  branch="Unknown"
+  url="file://$cwd"
+fi
+srcChecksum=`find src -name '*.java' | LC_ALL=C sort | xargs md5sum | md5sum | cut -d ' ' -f 1`
+
+mkdir -p $build_dir/backtype/storm/utils
+cat << EOF | \
+  sed -e "s/VERSION/$version/" -e "s/USER/$user/" -e "s/DATE/$date/" \
+      -e "s|URL|$url|" -e "s/REV/$revision/" \
+      -e "s|BRANCH|$branch|" -e "s/SRCCHECKSUM/$srcChecksum/" \
+      > $build_dir/backtype/storm/package-info.java
+/*
+ * Generated by saveVersion.sh
+ */
+@VersionAnnotation(version="VERSION", revision="REV", branch="BRANCH",
+                         user="USER", date="DATE", url="URL",
+                         srcChecksum="SRCCHECKSUM")
+package backtype.storm.utils;

http://git-wip-us.apache.org/repos/asf/storm/blob/fd03e16f/storm-dist/binary/src/main/assembly/binary.xml
----------------------------------------------------------------------
diff --git a/storm-dist/binary/src/main/assembly/binary.xml b/storm-dist/binary/src/main/assembly/binary.xml
index fdaee1d..bf87c50 100644
--- a/storm-dist/binary/src/main/assembly/binary.xml
+++ b/storm-dist/binary/src/main/assembly/binary.xml
@@ -131,13 +131,6 @@
         </file>
         <!-- TODO this should be a generated file from "target" -->
         <file>
-            <source>${project.basedir}/../../VERSION</source>
-            <outputDirectory>/</outputDirectory>
-            <destName>RELEASE</destName>
-            <filtered>true</filtered>
-        </file>
-
-        <file>
             <source>${project.basedir}/../../logback/cluster.xml</source>
             <outputDirectory>/logback</outputDirectory>
         </file>