Repository: incubator-ranger Updated Branches: refs/heads/master 8e786fa68 -> 4dd804138
RANGER-319 : Replace setVersion.sh bash script with platform independent python script Signed-off-by: sneethiraj <[email protected]> Project: http://git-wip-us.apache.org/repos/asf/incubator-ranger/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-ranger/commit/4dd80413 Tree: http://git-wip-us.apache.org/repos/asf/incubator-ranger/tree/4dd80413 Diff: http://git-wip-us.apache.org/repos/asf/incubator-ranger/diff/4dd80413 Branch: refs/heads/master Commit: 4dd804138a772ccfb30e66bd3e8672ab09642272 Parents: 8e786fa Author: Gautam Borad <[email protected]> Authored: Thu Mar 19 23:35:43 2015 +0530 Committer: sneethiraj <[email protected]> Committed: Tue Mar 24 16:29:34 2015 -0400 ---------------------------------------------------------------------- pom.xml | 1 + ranger-util/pom.xml | 8 +- ranger-util/src/scripts/saveVersion.py | 141 ++++++++++++++++++++++++++++ ranger-util/src/scripts/saveVersion.sh | 109 --------------------- 4 files changed, 146 insertions(+), 113 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/4dd80413/pom.xml ---------------------------------------------------------------------- diff --git a/pom.xml b/pom.xml index 0f9ccfb..00c63e9 100644 --- a/pom.xml +++ b/pom.xml @@ -93,6 +93,7 @@ <module>ugsync</module> <module>unixauthclient</module> <module>unixauthservice</module> + <module>ranger-util</module> </modules> <properties> <javac.source.version>1.7</javac.source.version> http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/4dd80413/ranger-util/pom.xml ---------------------------------------------------------------------- diff --git a/ranger-util/pom.xml b/ranger-util/pom.xml index bc9ec58..e09253b 100644 --- a/ranger-util/pom.xml +++ b/ranger-util/pom.xml @@ -26,7 +26,7 @@ <version>0.5.0</version> </parent> <artifactId>ranger-util</artifactId> - <name>ranger-util</name> + <name>Ranger Util</name> <description>Common Utilities of Ranger</description> <dependencies> <dependency> @@ -96,11 +96,11 @@ <phase>generate-sources</phase> <configuration> <target> - <exec executable="bash" failonerror="true"> - <arg value="${project.basedir}/src/scripts/saveVersion.sh" /> + <exec executable="python" failonerror="true"> + <arg value="${project.basedir}/src/scripts/saveVersion.py" /> <arg value="${project.version}" /> <arg value="${ranger.version.shortname}" /> - <arg value="${project.basedir}/src" /> + <arg value="${project.basedir}" /> </exec> </target> </configuration> http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/4dd80413/ranger-util/src/scripts/saveVersion.py ---------------------------------------------------------------------- diff --git a/ranger-util/src/scripts/saveVersion.py b/ranger-util/src/scripts/saveVersion.py new file mode 100644 index 0000000..fd8df94 --- /dev/null +++ b/ranger-util/src/scripts/saveVersion.py @@ -0,0 +1,141 @@ +# 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 + +import os +import re +import sys +import errno +import shlex +import hashlib +from os import listdir +import locale +import datetime +import getpass +import socket +import subprocess +from subprocess import Popen,PIPE +from time import gmtime, strftime + +def check_output(query): + p = subprocess.Popen(query, stdout=subprocess.PIPE) + output = p.communicate ()[0] + return output + +def hashfile(afile, hasher, blocksize=65536): + buf = afile.read(blocksize) + while len(buf) > 0: + hasher.update(buf) + buf = afile.read(blocksize) + return hasher.hexdigest() + +def main(): + LANG=None + LC_CTYPE=None + LC_TIME=None + version = sys.argv[1] + shortversion = sys.argv[2] + src_dir = os.path.join(sys.argv[3]) + revision = "" + user = getpass.getuser() + date = datetime.datetime.now().strftime("%I:%M%p on %B %d, %Y") + dir = os.getcwd() + cwd = dir.strip('scripts') + cwd = os.path.join(cwd, "src") + if revision == "" : + query = (["git","rev-parse","HEAD"]) + output = check_output(query) + if output != "" : + revision = output + hostname = socket.gethostname() + arr = (["git","rev-parse", "--abbrev-ref", "HEAD"]) + branch = check_output(arr) + branch = branch.strip("* ") + url = "git://%s/%s" % (hostname,cwd) + else: + revision="Unknown" + branch="Unknown" + url="file://cwd" + + if branch == "": + branch="Unknown" + if url == "": + url="file://cwd" + + c = [] + fileList = [] + sortedList = [] + for (dir, _, files) in os.walk(src_dir): + for f in files: + path = os.path.join(dir, f) + if path.endswith(".java"): + if os.path.exists(path): + fileList.append(path) + else: + pass + + sortedList = sorted(fileList, key = lambda x: x[:-4]) + for i, val in enumerate(sortedList): + m = hashfile(open(val,'rb'), hashlib.md5()) + f = m +" "+ val + "\n" + c.append(f); + + srcChecksum = hashlib.md5(''.join(c)).hexdigest() + + dir = os.path.join(src_dir,"gen","org","apache","ranger","common") + if not os.path.exists(dir): + os.makedirs(dir) + + # In Windows, all the following string ends with \r, need to get rid of them + branch = branch.strip('\n\r') + user = user.strip('\n\r') + date = date.strip('\n\r') + url = url.strip('\n\r') + revision = revision.strip('\n\r') + srcChecksum = srcChecksum.strip('\n\r') + + content = """/* + * 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. + */ + /* + * Generated by saveVersion.py + */ + @RangerVersionAnnotation(version="{VERSION}", shortVersion="{SHORTVERSION}",revision="{REV}",branch="{BRANCH}", user="{USER}",date="{DATE}", url="{URL}",srcChecksum="{SRCCHECKSUM}") + package org.apache.ranger.common;""" + + content = content.format(VERSION=version,SHORTVERSION=shortversion,USER=user,DATE=date,URL=url,REV=revision,BRANCH=branch,SRCCHECKSUM=srcChecksum) + des = os.path.join(dir, "package-info.java") + f = open(des , 'wb') + f.write(content) + f.close() + +main() http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/4dd80413/ranger-util/src/scripts/saveVersion.sh ---------------------------------------------------------------------- diff --git a/ranger-util/src/scripts/saveVersion.sh b/ranger-util/src/scripts/saveVersion.sh deleted file mode 100755 index 33c8820..0000000 --- a/ranger-util/src/scripts/saveVersion.sh +++ /dev/null @@ -1,109 +0,0 @@ -#!/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 -shortversion=$2 -src_dir=$3 -revision=$4 -branch=$5 -url=$6 -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/ranger/common - -# 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/SHORTVERSION/$shortversion/" \ - -e "s/USER/$user/" -e "s/DATE/$date/" \ - -e "s|URL|$url|" -e "s/REV/$revision/" \ - -e "s|BRANCH|$branch|" -e "s/SRCCHECKSUM/$srcChecksum/" \ - > $src_dir/gen/org/apache/ranger/common/package-info.java -/* - * 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. - */ - -/* - * Generated by saveVersion.sh - */ -@RangerVersionAnnotation(version="VERSION", shortVersion="SHORTVERSION", - revision="REV", branch="BRANCH", - user="USER", date="DATE", url="URL", - srcChecksum="SRCCHECKSUM") -package org.apache.ranger.common; -EOF
