tools/release.sh: Simplify our release build process

Rather than having 3 commands for a human to type in by hand,
lets wrap it all up into a tiny shell script.

Change-Id: I967416266e7cde3a2a5ae567bdc4524c874b4a34
Signed-off-by: Shawn O. Pearce <sop@google.com>
diff --git a/Documentation/dev-readme.txt b/Documentation/dev-readme.txt
index 1433981..5856439 100644
--- a/Documentation/dev-readme.txt
+++ b/Documentation/dev-readme.txt
@@ -129,24 +129,9 @@
 through the download site:
 
 ----
-  ./tools/version.sh --release
-  mvn clean package
-  git reset --hard
+  ./tools/release.sh
 ----
 
-The first script, 'tools/version.sh' updates the pom.xml files with
-the current build number from Git, so the version appears in the
-embedded JAR file names, and in the final WAR file name.
-
-A clean build is necesary to ensure different versions of the
-same dependency don't wind up in the output WAR.  If a dependency
-changes versions, Maven often leaves the old version in the WAR,
-and also includes the new version, resulting in an ambiguous class
-loading order at runtime.
-
-The final command replaces all modified files with their last
-committed revisions, undoing the edits made by 'tools/version.sh'.
-
 
 Client-Server RPC
 -----------------
diff --git a/tools/release.sh b/tools/release.sh
new file mode 100755
index 0000000..14d7fc8
--- /dev/null
+++ b/tools/release.sh
@@ -0,0 +1,24 @@
+#!/bin/sh
+
+git update-index -q --refresh
+
+if test -n "$(git diff-index --name-only HEAD --)" \
+|| test -n "$(git ls-files --others --exclude-standard)"
+then
+	echo >&2 "error: working directory is dirty, refusing to build"
+	exit 1
+fi
+
+./tools/version.sh --release &&
+mvn clean package
+rc=$?
+./tools/version.sh --reset
+
+if test 0 = $rc
+then
+	echo
+	echo Built Gerrit Code Review `git describe`:
+	ls gerrit-war/target/gerrit-*.war
+	echo
+fi
+exit $rc
diff --git a/tools/version.sh b/tools/version.sh
index a4c09cb..c3d9417 100755
--- a/tools/version.sh
+++ b/tools/version.sh
@@ -6,6 +6,8 @@
 # Java based Maven plugin so its fully portable.
 #
 
+POM_FILES=$(git ls-files | grep pom.xml)
+
 case "$1" in
 --snapshot=*)
 	V=$(echo "$1" | perl -pe 's/^--snapshot=//')
@@ -24,8 +26,13 @@
 	V=$(git describe HEAD) || exit
 	;;
 
+--reset)
+	git checkout HEAD -- $POM_FILES
+	exit $?
+	;;
+
 *)
-	echo >&2 "usage: $0 {--snapshot=0.n.0 | --release}"
+	echo >&2 "usage: $0 {--snapshot=2.n | --release}"
 	exit 1
 esac
 
@@ -40,8 +47,6 @@
 	}
 	if (!$seen_version) {
 		$seen_version = 1 if
-		s{(<version>).*(</version>)}{${1}'"$POM_V"'${2}};
+		s{(<version>).*(</version>)}{${1}'"$V"'${2}};
 	}
-	' $(git ls-files | grep pom.xml)
-
-git diff
+	' $POM_FILES