HTRACE-42. Automatically generate version.go (cmccabe)
diff --git a/.gitignore b/.gitignore
index 7238b01..f6c1807 100644
--- a/.gitignore
+++ b/.gitignore
@@ -14,3 +14,4 @@
 htrace-core/src/go/src/org/apache/htrace/resource
 htrace-core/src/go/src/github.com/
 htrace-core/src/go/src/gopkg.in/
+htrace-core/src/go/src/org/apache/htrace/common/version.go
diff --git a/htrace-core/pom.xml b/htrace-core/pom.xml
index bd0b65e..91d906c 100644
--- a/htrace-core/pom.xml
+++ b/htrace-core/pom.xml
@@ -85,6 +85,7 @@
                 <exec executable="./gobuild.sh" 
                       dir="${basedir}/src/go/"
                       failonerror="true"> 
+                  <env key="RELEASE_VERSION" value="${version}"/>
                 </exec>
               </tasks>
             </configuration>
diff --git a/htrace-core/src/go/generate_version.sh b/htrace-core/src/go/generate_version.sh
new file mode 100755
index 0000000..cece713
--- /dev/null
+++ b/htrace-core/src/go/generate_version.sh
@@ -0,0 +1,66 @@
+#!/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.
+#
+
+#
+# Generates the version.go file.
+#
+# ./generate_version.sh [release-version]      Generates the version.go file
+#
+
+die() {
+    echo $@
+    exit 1
+}
+
+[ $# -lt 1 ] && die "You must specify the release version."
+RELEASE_VERSION=$1
+
+SCRIPT_DIR="$(cd "$( dirname $0 )" && pwd)"
+cd "${SCRIPT_DIR}"
+GIT_VERSION=$(git rev-parse HEAD)
+[ $? -eq 0 ] || die "Failed to run 'git rev-parse HEAD'"
+cat <<EOF > "./src/org/apache/htrace/common/version.go"
+/*
+ * 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 IS GENERATED CODE.  DO NOT EDIT.
+
+package common
+
+const RELEASE_VERSION = "$RELEASE_VERSION"
+const GIT_VERSION = "$GIT_VERSION"
+EOF
diff --git a/htrace-core/src/go/gobuild.sh b/htrace-core/src/go/gobuild.sh
index d8a6b47..9e1efa8 100755
--- a/htrace-core/src/go/gobuild.sh
+++ b/htrace-core/src/go/gobuild.sh
@@ -44,6 +44,7 @@
     fi
     shift
 fi
+RELEASE_VERSION=${RELEASE_VERSION:-unknown}
 
 SCRIPT_DIR="$(cd "$( dirname $0 )" && pwd)"
 export GOPATH="$GOPATH:${SCRIPT_DIR}"
@@ -84,5 +85,6 @@
     go run "$SCRIPT_DIR/src/org/apache/htrace/bundler/bundler.go" \
         --src="$SCRIPT_DIR/../web/" --dst="$SCRIPT_DIR/src/org/apache/htrace/resource/" \
             || die "bundler failed"
+    ${SCRIPT_DIR}/generate_version.sh "${RELEASE_VERSION}"
 fi
 go "${ACTION}" -v org/apache/htrace/... "$@"
diff --git a/htrace-core/src/go/src/org/apache/htrace/common/rest.go b/htrace-core/src/go/src/org/apache/htrace/common/rest.go
index 1b1db03..eeb9568 100644
--- a/htrace-core/src/go/src/org/apache/htrace/common/rest.go
+++ b/htrace-core/src/go/src/org/apache/htrace/common/rest.go
@@ -22,5 +22,8 @@
 // Info returned by /serverInfo
 type ServerInfo struct {
 	// The server release version.
-	Version string
+	ReleaseVersion string
+
+	// The git hash that this software was built with.
+	GitVersion string
 }
diff --git a/htrace-core/src/go/src/org/apache/htrace/common/version.go b/htrace-core/src/go/src/org/apache/htrace/common/version.go
deleted file mode 100644
index c560c09..0000000
--- a/htrace-core/src/go/src/org/apache/htrace/common/version.go
+++ /dev/null
@@ -1,22 +0,0 @@
-/*
- * 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 common
-
-const RELEASE_VERSION = "3.1.0-SNAPSHOT"
diff --git a/htrace-core/src/go/src/org/apache/htrace/htrace/cmd.go b/htrace-core/src/go/src/org/apache/htrace/htrace/cmd.go
index 0437628..3b89c72 100644
--- a/htrace-core/src/go/src/org/apache/htrace/htrace/cmd.go
+++ b/htrace-core/src/go/src/org/apache/htrace/htrace/cmd.go
@@ -84,7 +84,7 @@
 			string(buf), err.Error())
 		return 1
 	}
-	fmt.Printf("HTraced server version %s\n", info.Version)
+	fmt.Printf("HTraced server version %s (%s)\n", info.ReleaseVersion, info.GitVersion)
 	return 0
 }
 
diff --git a/htrace-core/src/go/src/org/apache/htrace/htraced/rest.go b/htrace-core/src/go/src/org/apache/htrace/htraced/rest.go
index b704bd2..74018c0 100644
--- a/htrace-core/src/go/src/org/apache/htrace/htraced/rest.go
+++ b/htrace-core/src/go/src/org/apache/htrace/htraced/rest.go
@@ -34,7 +34,8 @@
 }
 
 func (handler *serverInfoHandler) ServeHTTP(w http.ResponseWriter, req *http.Request) {
-	version := common.ServerInfo{Version: common.RELEASE_VERSION}
+	version := common.ServerInfo{ReleaseVersion: common.RELEASE_VERSION,
+		GitVersion: common.GIT_VERSION}
 	buf, err := json.Marshal(&version)
 	if err != nil {
 		log.Printf("error marshalling ServerInfo: %s\n", err.Error())