You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sentry.apache.org by pr...@apache.org on 2014/09/12 08:40:00 UTC
git commit: SENTRY-412: Sentry script should support an option to
print product version (Prasad Mujumdar reviewed by Sravya Tirukkovalur and
Arun Suresh)
Repository: incubator-sentry
Updated Branches:
refs/heads/master 67f84187c -> 14a86ba9b
SENTRY-412: Sentry script should support an option to print product version (Prasad Mujumdar reviewed by Sravya Tirukkovalur and Arun Suresh)
Project: http://git-wip-us.apache.org/repos/asf/incubator-sentry/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-sentry/commit/14a86ba9
Tree: http://git-wip-us.apache.org/repos/asf/incubator-sentry/tree/14a86ba9
Diff: http://git-wip-us.apache.org/repos/asf/incubator-sentry/diff/14a86ba9
Branch: refs/heads/master
Commit: 14a86ba9b623ebe4b6c2428c03e033f5ec6eddac
Parents: 67f8418
Author: Prasad Mujumdar <pr...@cloudera.com>
Authored: Thu Sep 11 22:38:50 2014 -0700
Committer: Prasad Mujumdar <pr...@cloudera.com>
Committed: Thu Sep 11 22:38:50 2014 -0700
----------------------------------------------------------------------
.gitignore | 1 +
sentry-core/sentry-core-common/pom.xml | 44 ++++++++
.../main/java/org/apache/sentry/SentryMain.java | 13 +++
.../apache/sentry/SentryVersionAnnotation.java | 75 +++++++++++++
.../org/apache/sentry/SentryVersionInfo.java | 109 +++++++++++++++++++
.../src/scripts/saveVersion.sh | 89 +++++++++++++++
6 files changed, 331 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/14a86ba9/.gitignore
----------------------------------------------------------------------
diff --git a/.gitignore b/.gitignore
index 6a39d39..91ad75b 100644
--- a/.gitignore
+++ b/.gitignore
@@ -8,6 +8,7 @@ target/
*.iml
derby.log
datanucleus.log
+sentry-core/sentry-core-common/src/gen
**/TempStatsStore/
# Package Files #
*.jar
http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/14a86ba9/sentry-core/sentry-core-common/pom.xml
----------------------------------------------------------------------
diff --git a/sentry-core/sentry-core-common/pom.xml b/sentry-core/sentry-core-common/pom.xml
index e12469a..5c0fe43 100644
--- a/sentry-core/sentry-core-common/pom.xml
+++ b/sentry-core/sentry-core-common/pom.xml
@@ -59,4 +59,48 @@ limitations under the License.
</dependency>
</dependencies>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-antrun-plugin</artifactId>
+ <executions>
+ <execution>
+ <id>generate-version-annotation</id>
+ <phase>generate-sources</phase>
+ <configuration>
+ <target>
+ <exec executable="bash" failonerror="true">
+ <arg value="${basedir}/src/scripts/saveVersion.sh"/>
+ <arg value="${project.version}"/>
+ <arg value="${basedir}/src"/>
+ </exec>
+ </target>
+ </configuration>
+ <goals>
+ <goal>run</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ <plugin>
+ <groupId>org.codehaus.mojo</groupId>
+ <artifactId>build-helper-maven-plugin</artifactId>
+ <executions>
+ <execution>
+ <id>add-source</id>
+ <phase>generate-sources</phase>
+ <goals>
+ <goal>add-source</goal>
+ </goals>
+ <configuration>
+ <sources>
+ <source>src/gen</source>
+ </sources>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
</project>
http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/14a86ba9/sentry-core/sentry-core-common/src/main/java/org/apache/sentry/SentryMain.java
----------------------------------------------------------------------
diff --git a/sentry-core/sentry-core-common/src/main/java/org/apache/sentry/SentryMain.java b/sentry-core/sentry-core-common/src/main/java/org/apache/sentry/SentryMain.java
index 497c8a4..7b1b6ac 100644
--- a/sentry-core/sentry-core-common/src/main/java/org/apache/sentry/SentryMain.java
+++ b/sentry-core/sentry-core-common/src/main/java/org/apache/sentry/SentryMain.java
@@ -31,6 +31,8 @@ import com.google.common.collect.ImmutableMap;
public class SentryMain {
private static final String HELP_SHORT = "h";
private static final String HELP_LONG = "help";
+ private static final String VERSION_SHORT = "v";
+ private static final String VERSION_LONG = "version";
private static final String COMMAND = "command";
private static final String HIVE_CONF = "hiveconf";
private static final String LOG4J_CONF = "log4jConf";
@@ -46,6 +48,8 @@ public class SentryMain {
CommandLineParser parser = new GnuParser();
Options options = new Options();
options.addOption(HELP_SHORT, HELP_LONG, false, "Print this help text");
+ options.addOption(VERSION_SHORT, VERSION_LONG, false,
+ "Print Sentry version");
options.addOption(HIVE_CONF, true, "Set hive configuration variables");
options.addOption(null, COMMAND, true, "Command to run. Options: " + COMMANDS.keySet());
options.addOption(null, LOG4J_CONF, true, "Location of log4j properties file");
@@ -66,6 +70,9 @@ public class SentryMain {
if (commandName == null && (commandLine.hasOption(HELP_SHORT) ||
commandLine.hasOption(HELP_LONG))) {
printHelp(options, null);
+ } else if (commandLine.hasOption(VERSION_SHORT) ||
+ commandLine.hasOption(VERSION_LONG)) {
+ printVersion();
}
String commandClazz = COMMANDS.get(commandName);
@@ -86,6 +93,12 @@ public class SentryMain {
}
((Command)command).run(commandLine.getArgs());
}
+
+ private static void printVersion() {
+ System.out.println(SentryVersionInfo.getBuildVersion());
+ System.exit(0);
+ }
+
private static void printHelp(Options options, String msg) {
String sentry = "sentry";
if(msg != null)
http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/14a86ba9/sentry-core/sentry-core-common/src/main/java/org/apache/sentry/SentryVersionAnnotation.java
----------------------------------------------------------------------
diff --git a/sentry-core/sentry-core-common/src/main/java/org/apache/sentry/SentryVersionAnnotation.java b/sentry-core/sentry-core-common/src/main/java/org/apache/sentry/SentryVersionAnnotation.java
new file mode 100644
index 0000000..e64693a
--- /dev/null
+++ b/sentry-core/sentry-core-common/src/main/java/org/apache/sentry/SentryVersionAnnotation.java
@@ -0,0 +1,75 @@
+/**
+ * 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.sentry;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+ * SentryVersionAnnotation.
+ *
+ */
+@Retention(RetentionPolicy.RUNTIME)
+@Target(ElementType.PACKAGE)
+public @interface SentryVersionAnnotation {
+
+ /**
+ * Get the Sentry version
+ * @return the version string "0.6.3-dev"
+ */
+ String version();
+
+ /**
+ * Get the username that compiled Sentry.
+ */
+ String user();
+
+ /**
+ * Get the date when Sentry was compiled.
+ * @return the date in unix 'date' format
+ */
+ String date();
+
+ /**
+ * Get the url for the source repository.
+ */
+ String url();
+
+ /**
+ * Get the commit hash.
+ * @return the revision number as a string (eg. "451451")
+ */
+ String commitHash();
+
+ /**
+ * Get the branch from which this was compiled.
+ * @return The branch name, e.g. "trunk" or "branches/branch-0.20"
+ */
+ String branch();
+
+ /**
+ * Get a checksum of the source files from which
+ * Sentry was compiled.
+ * @return a string that uniquely identifies the source
+ **/
+ String srcChecksum();
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/14a86ba9/sentry-core/sentry-core-common/src/main/java/org/apache/sentry/SentryVersionInfo.java
----------------------------------------------------------------------
diff --git a/sentry-core/sentry-core-common/src/main/java/org/apache/sentry/SentryVersionInfo.java b/sentry-core/sentry-core-common/src/main/java/org/apache/sentry/SentryVersionInfo.java
new file mode 100644
index 0000000..53fe3af
--- /dev/null
+++ b/sentry-core/sentry-core-common/src/main/java/org/apache/sentry/SentryVersionInfo.java
@@ -0,0 +1,109 @@
+/**
+ * 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.sentry;
+
+public class SentryVersionInfo {
+ private static Package myPackage;
+ private static SentryVersionAnnotation version;
+
+ static {
+ myPackage = SentryVersionAnnotation.class.getPackage();
+ version = myPackage.getAnnotation(SentryVersionAnnotation.class);
+ }
+
+ /**
+ * Get the meta-data for the Sentry package.
+ * @return
+ */
+ static Package getPackage() {
+ return myPackage;
+ }
+
+ /**
+ * Get the Sentry version.
+ * @return the Sentry version string, eg. "1.4.0-SNAPSHOT"
+ */
+ public static String getVersion() {
+ return version != null ? version.version() : "Unknown";
+ }
+
+ /**
+ * Get the subversion revision number for the root directory
+ * @return the revision number, eg. "451451"
+ */
+ public static String getCommitHash() {
+ return version != null ? version.commitHash() : "Unknown";
+ }
+
+ /**
+ * Get the branch on which this originated.
+ * @return The branch name, e.g. "master" or "branches/branch-1.4.0"
+ */
+ public static String getBranch() {
+ return version != null ? version.branch() : "Unknown";
+ }
+
+ /**
+ * The date that Sentry was compiled.
+ * @return the compilation date in unix date format
+ */
+ public static String getDate() {
+ return version != null ? version.date() : "Unknown";
+ }
+
+ /**
+ * The user that compiled Sentry.
+ * @return the username of the user
+ */
+ public static String getUser() {
+ return version != null ? version.user() : "Unknown";
+ }
+
+ /**
+ * Get the subversion URL for the root Sentry directory.
+ */
+ public static String getUrl() {
+ return version != null ? version.url() : "Unknown";
+ }
+
+ /**
+ * Get the checksum of the source files from which Sentry was built.
+ **/
+ public static String getSrcChecksum() {
+ return version != null ? version.srcChecksum() : "Unknown";
+ }
+
+ /**
+ * Returns the buildVersion which includes version, revision, user and date.
+ */
+ public static String getBuildVersion() {
+ return "Apache Sentry " + SentryVersionInfo.getVersion()
+ + " ,built from commit#" + SentryVersionInfo.getCommitHash()
+ + " ,compiled by " + SentryVersionInfo.getUser()
+ + " with source checksum "
+ + SentryVersionInfo.getSrcChecksum();
+ }
+
+ public static void main(String[] args) {
+ System.out.println("Sentry " + getVersion());
+ System.out.println("Git " + getUrl());
+ System.out.println("Commit# " + getCommitHash());
+ System.out.println("Compiled by " + getUser() + " on " + getDate());
+ System.out.println("From source with checksum " + getSrcChecksum());
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/14a86ba9/sentry-core/sentry-core-common/src/scripts/saveVersion.sh
----------------------------------------------------------------------
diff --git a/sentry-core/sentry-core-common/src/scripts/saveVersion.sh b/sentry-core/sentry-core-common/src/scripts/saveVersion.sh
new file mode 100755
index 0000000..235443c
--- /dev/null
+++ b/sentry-core/sentry-core-common/src/scripts/saveVersion.sh
@@ -0,0 +1,89 @@
+#!/usr/bin/env bash
+
+# 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.
+
+
+# This 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
+src_dir=$2
+revision=$3
+branch=$4
+url=$5
+user=`whoami`
+date=`date`
+dir=`pwd`
+cwd=`dirname $dir`
+if [ "$revision" = "" ]; then
+ if git rev-parse HEAD 2>/dev/null > /dev/null ; 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
+fi
+if [ "$branch" = "" ]; then
+ branch="Unknown"
+fi
+if [ "$url" = "" ]; then
+ url="file://$cwd"
+fi
+
+if [ -x /sbin/md5 ]; then
+ md5="/sbin/md5"
+else
+ md5="md5sum"
+fi
+
+srcChecksum=`find ../ -name '*.java' | grep -v generated-sources | LC_ALL=C sort | xargs $md5 | $md5 | cut -d ' ' -f 1`
+
+mkdir -p $src_dir/gen/org/apache/sentry
+
+# In Windows, all the following string ends with \r, need to get rid of them
+branch=`echo $branch | tr -d '\r'`
+user=`echo $user | tr -d '\r'`
+date=`echo $date | tr -d '\r'`
+url=`echo $url | tr -d '\r'`
+srcChecksum=`echo $srcChecksum | tr -d '\r'`
+
+cat << EOF | \
+ sed -e "s/VERSION/$version/" \
+ -e "s/USER/$user/" -e "s/DATE/$date/" \
+ -e "s|URL|$url|" -e "s/COMMIT/$revision/" \
+ -e "s|BRANCH|$branch|" -e "s/SRCCHECKSUM/$srcChecksum/" \
+ > $src_dir/gen/org/apache/sentry/package-info.java
+/*
+ * Generated by saveVersion.sh
+ */
+@SentryVersionAnnotation(version="VERSION", commitHash="COMMIT", branch="BRANCH",
+ user="USER", date="DATE", url="URL",
+ srcChecksum="SRCCHECKSUM")
+package org.apache.sentry;
+EOF