HCATALOG-619 Update HCatalog test/release script with post-release improvements


git-svn-id: https://svn.apache.org/repos/asf/incubator/hcatalog/trunk@1459078 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/CHANGES.txt b/CHANGES.txt
index bde6c03..b1f96c1 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -26,6 +26,8 @@
 
   IMPROVEMENTS
 
+  HCAT-619 Update HCatalog test/release script with post-release improvements (traviscrawford via gates)
+
   OPTIMIZATIONS
 
   BUG FIXES
diff --git a/build-support/scripts/release.py b/build-support/scripts/release.py
new file mode 100644
index 0000000..a270cc9
--- /dev/null
+++ b/build-support/scripts/release.py
@@ -0,0 +1,117 @@
+#!/usr/bin/env python
+
+# 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.
+
+import os
+import os.path
+import subprocess
+import sys
+
+from optparse import OptionParser
+
+def get_snapshot_version():
+  with open('build.properties') as f:
+    for line in f.readlines():
+      if line.startswith('hcatalog.version='):
+        return line.strip().split('=')[1]
+
+def update_poms(release_version):
+  snapshot_version = get_snapshot_version()
+  for root, dirs, files in os.walk(os.getcwd()):
+    for filename in files:
+      if filename in ['build.properties', 'pom.xml']:
+        abs_filename = os.path.join(root, filename)
+        lines = []
+        with open(abs_filename) as f:
+          for line in f:
+            lines.append(line.replace(snapshot_version, release_version))
+        with open(abs_filename, 'w') as f:
+          f.write(''.join(lines))
+
+def main():
+  parser = OptionParser(usage=('usage: %prog [options])\n\n'
+      'This tool automates HCatalog release-releated tasks, providing '
+      'flexibility around the build and deploy process (useful for '
+      'site-specific customization). For more information, see '
+      'https://cwiki.apache.org/confluence/display/HCATALOG/HowToRelease'))
+  parser.add_option('--dry-run',
+      dest='dry_run',
+      default=False,
+      action='store_true',
+      help=('Perform a release dry run, which appends `dryrun` to the version '
+            'and does not publish artifacts to Maven. (default: %default)'))
+  parser.add_option('--release-version',
+    dest='release_version',
+    default=None,
+    help='HCatalog release version. (default: %default)')
+  parser.add_option('--forrest-home',
+    dest='forrest_home',
+    default='/usr/local/apache-forrest-0.9',
+    help='Path to the Apache Forrest home. (default: %default)')
+  parser.add_option('--mvn-deploy-repo-id',
+    dest='mvn_deploy_repo_id',
+    default='apache.releases.https',
+    help=('Maven repo id to publish to. This id must exist in your '
+          'settings.xml, along with your username/password to publish '
+          'artifacts. For more information, see '
+          'http://maven.apache.org/settings.html#Servers (default: %default)'))
+  parser.add_option('--mvn-deploy-repo-url',
+    dest='mvn_deploy_repo_url',
+    default='https://repository.apache.org/service/local/staging/deploy/maven2',
+    help='Maven repo URL to publish to. (default: %default)')
+  parser.add_option('--ant-args',
+    dest='ant_args',
+    default=None,
+    help=('Extra args for ant, such as overriding something from '
+          '`build.properties`. (default: %default)'))
+  (options, args) = parser.parse_args()
+
+  if len(sys.argv) == 0:
+    parser.print_help()
+    sys.exit(-1)
+
+  if options.release_version is None:
+    print('Required option --release-version not set!')
+    parser.print_help()
+    sys.exit(-1)
+
+  ant_args = []
+  if os.environ.has_key('ANT_ARGS'):
+    ant_args.append(os.environ['ANT_ARGS'])
+  if options.ant_args is not None:
+    ant_args.append(options.ant_args)
+
+  if options.dry_run:
+    options.release_version = '%s-dryrun' % options.release_version
+  else:
+    ant_args.extend([
+      '-Dmvn.deploy.repo.id=%s' % options.mvn_deploy_repo_id,
+      '-Dmvn.deploy.repo.url=%s' % options.mvn_deploy_repo_url,
+    ])
+    os.environ['HCAT_MVN_DEPLOY'] = 'true'
+
+  os.environ['FORREST_HOME'] = options.forrest_home
+  os.environ['ANT_ARGS'] = ' '.join(ant_args)
+
+  update_poms(options.release_version)
+
+  subprocess.Popen(os.path.join(os.path.dirname(__file__), 'test.sh'),
+      env=os.environ, stdout=sys.stdout, stderr=sys.stderr).communicate()
+
+if __name__ == '__main__':
+  main()
diff --git a/build-support/scripts/release.sh b/build-support/scripts/release.sh
deleted file mode 100755
index 2e0ea1a..0000000
--- a/build-support/scripts/release.sh
+++ /dev/null
@@ -1,40 +0,0 @@
-#!/bin/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.
-
-# HCatalog uses maven for resolving dependencies and publishing artifacts.
-# Maven requires project version numbers be hard-coded in pom.xml files,
-# rather than being typical variables. Tooling in provided by maven to ease
-# managing these version numbers, however, as our build is ant-based
-# we cannot use that tooling. This release script is a workaround to
-# update pom.xml version numbers to properly build release artifacts.
-
-if [ "${HCAT_RELEASE_VERSION}" == "" ]; then
-  echo "Required environment variable HCAT_RELEASE_VERSION not set."
-  exit -1
-fi
-
-snapshot_version=$(awk -F= '/hcatalog.version=/ { print $2 }' build.properties)
-
-find . -name pom.xml -exec sed -i '' "s/${snapshot_version}/${HCAT_RELEASE_VERSION}/" {} \;
-sed -i '' "s/${snapshot_version}/${HCAT_RELEASE_VERSION}/" build.properties
-
-# useful to pass in "-Dtestcase=Foo" to bypass tests when troubleshooting builds
-export ANT_ARGS="${ANT_ARGS}"
-
-./build-support/scripts/test.sh
diff --git a/build-support/scripts/test.sh b/build-support/scripts/test.sh
index 528d2f6..ea15634 100755
--- a/build-support/scripts/test.sh
+++ b/build-support/scripts/test.sh
@@ -55,8 +55,10 @@
 
 # Build and run tests with hadoop20. This must happen afterwards so test results
 # are available for CI to publish.
-cmd='ant -Dtest.junit.output.format=xml clean releaseaudit package test'
+cmd="ant -Dtest.junit.output.format=xml -Dforrest.home=${FORREST_HOME} clean releaseaudit package test"
 if [ "${HUDSON_URL}" == "https://builds.apache.org/" ]; then
   cmd="${cmd} mvn-deploy"
+elif [ "${HCAT_MVN_DEPLOY}" == "true" ]; then
+  cmd="${cmd} mvn-deploy-signed"
 fi
 run_cmd
diff --git a/build.properties b/build.properties
index 7695db1..a335e39 100644
--- a/build.properties
+++ b/build.properties
@@ -15,7 +15,7 @@
 # specific language governing permissions and limitations
 # under the License.
 
-hcatalog.version=0.6.0-SNAPSHOT
+hcatalog.version=1.0-gates
 jar.name=${ant.project.name}-${hcatalog.version}.jar
 hcatalog.jar=${ant.project.name}-${hcatalog.version}.jar
 hcatalog.core.jar=${ant.project.name}-core-${hcatalog.version}.jar
diff --git a/core/pom.xml b/core/pom.xml
index 7ee60f1..4cbbbf6 100644
--- a/core/pom.xml
+++ b/core/pom.xml
@@ -24,7 +24,7 @@
     <parent>
         <groupId>org.apache.hcatalog</groupId>
         <artifactId>hcatalog</artifactId>
-        <version>0.6.0-SNAPSHOT</version>
+        <version>1.0-gates</version>
         <relativePath>../pom.xml</relativePath>
     </parent>
 
@@ -32,7 +32,7 @@
     <groupId>org.apache.hcatalog</groupId>
     <artifactId>hcatalog-core</artifactId>
     <packaging>jar</packaging>
-    <version>0.6.0-SNAPSHOT</version>
+    <version>1.0-gates</version>
     <name>hcatalog-core</name>
     <url>http://maven.apache.org</url>
 
diff --git a/hcatalog-pig-adapter/pom.xml b/hcatalog-pig-adapter/pom.xml
index c294b31..fa2eea5 100644
--- a/hcatalog-pig-adapter/pom.xml
+++ b/hcatalog-pig-adapter/pom.xml
@@ -24,7 +24,7 @@
     <parent>
         <groupId>org.apache.hcatalog</groupId>
         <artifactId>hcatalog</artifactId>
-        <version>0.6.0-SNAPSHOT</version>
+        <version>1.0-gates</version>
         <relativePath>../pom.xml</relativePath>
     </parent>
 
@@ -32,7 +32,7 @@
     <groupId>org.apache.hcatalog</groupId>
     <artifactId>hcatalog-pig-adapter</artifactId>
     <packaging>jar</packaging>
-    <version>0.6.0-SNAPSHOT</version>
+    <version>1.0-gates</version>
     <name>hcatalog-pig-adapter</name>
     <url>http://maven.apache.org</url>
 
diff --git a/pom.xml b/pom.xml
index 12433d4..f818451 100644
--- a/pom.xml
+++ b/pom.xml
@@ -51,7 +51,7 @@
   <modelVersion>4.0.0</modelVersion>
   <groupId>org.apache.hcatalog</groupId>
   <artifactId>hcatalog</artifactId>
-  <version>0.6.0-SNAPSHOT</version>
+  <version>1.0-gates</version>
   <packaging>pom</packaging>
 
   <build>
diff --git a/server-extensions/pom.xml b/server-extensions/pom.xml
index aab7553..3a26b63 100644
--- a/server-extensions/pom.xml
+++ b/server-extensions/pom.xml
@@ -24,7 +24,7 @@
     <parent>
         <groupId>org.apache.hcatalog</groupId>
         <artifactId>hcatalog</artifactId>
-        <version>0.6.0-SNAPSHOT</version>
+        <version>1.0-gates</version>
         <relativePath>../pom.xml</relativePath>
     </parent>
 
@@ -32,7 +32,7 @@
     <groupId>org.apache.hcatalog</groupId>
     <artifactId>hcatalog-server-extensions</artifactId>
     <packaging>jar</packaging>
-    <version>0.6.0-SNAPSHOT</version>
+    <version>1.0-gates</version>
     <name>server-extensions</name>
     <url>http://maven.apache.org</url>
 
diff --git a/storage-handlers/hbase/pom.xml b/storage-handlers/hbase/pom.xml
index 3fce57d..6298c08 100644
--- a/storage-handlers/hbase/pom.xml
+++ b/storage-handlers/hbase/pom.xml
@@ -24,7 +24,7 @@
   <parent>
     <groupId>org.apache.hcatalog</groupId>
     <artifactId>hcatalog</artifactId>
-    <version>0.6.0-SNAPSHOT</version>
+    <version>1.0-gates</version>
     <relativePath>../../pom.xml</relativePath>
   </parent>
 
@@ -32,7 +32,7 @@
   <groupId>org.apache.hcatalog</groupId>
   <artifactId>hbase-storage-handler</artifactId>
   <packaging>jar</packaging>
-  <version>0.6.0-SNAPSHOT</version>
+  <version>1.0-gates</version>
   <name>hbase-storage-handler</name>
   <url>http://maven.apache.org</url>
 
diff --git a/webhcat/java-client/pom.xml b/webhcat/java-client/pom.xml
index e545221..b1b732c 100644
--- a/webhcat/java-client/pom.xml
+++ b/webhcat/java-client/pom.xml
@@ -24,7 +24,7 @@
     <parent>
         <groupId>org.apache.hcatalog</groupId>
         <artifactId>hcatalog</artifactId>
-        <version>0.6.0-SNAPSHOT</version>
+        <version>1.0-gates</version>
         <relativePath>../../pom.xml</relativePath>
     </parent>
 
@@ -32,7 +32,7 @@
     <groupId>org.apache.hcatalog</groupId>
     <artifactId>webhcat-java-client</artifactId>
     <packaging>jar</packaging>
-    <version>0.6.0-SNAPSHOT</version>
+    <version>1.0-gates</version>
     <name>webhcat-java-client</name>
     <url>http://maven.apache.org</url>
 
diff --git a/webhcat/svr/pom.xml b/webhcat/svr/pom.xml
index bd270ed..a0dc59e 100644
--- a/webhcat/svr/pom.xml
+++ b/webhcat/svr/pom.xml
@@ -24,7 +24,7 @@
     <parent>
         <groupId>org.apache.hcatalog</groupId>
         <artifactId>hcatalog</artifactId>
-        <version>0.6.0-SNAPSHOT</version>
+        <version>1.0-gates</version>
         <relativePath>../../pom.xml</relativePath>
     </parent>
 
@@ -32,7 +32,7 @@
     <groupId>org.apache.hcatalog</groupId>
     <artifactId>webhcat</artifactId>
     <packaging>jar</packaging>
-    <version>0.6.0-SNAPSHOT</version>
+    <version>1.0-gates</version>
     <name>webhcat</name>
     <url>http://maven.apache.org</url>