Build Version as part of common, and add tests

Previously, the Version resource used by Version.java was compiled
directly into the war, rather than being included in the java_library
alongside the class that used it. The intended effect was to produce a
version of "(dev)" when running from Eclipse, and an accurate version
when running from the war. However, it made the build graph a little
confusing, and moreover made it impossible to write a test that tests
the actual format of the "git describe" output.

Rearrange the build rules to include Version in the common:server
library. This actually still results in "(dev)" when run from Eclipse,
because there is no jar for this library in the Eclipse classpath, so
looking up the resource will still fail as expected.

Change-Id: I26e38a8c37aef9e1872faed1ab40d003e6dea946
This commit is contained in:
Dave Borowitz
2017-11-03 09:13:15 -04:00
parent af5696a32d
commit 62f2d09aea
6 changed files with 106 additions and 24 deletions

View File

@@ -17,6 +17,7 @@ package com.google.gerrit.common;
import static java.nio.charset.StandardCharsets.UTF_8;
import com.google.common.annotations.GwtIncompatible;
import com.google.common.annotations.VisibleForTesting;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
@@ -27,20 +28,23 @@ import org.slf4j.LoggerFactory;
@GwtIncompatible("Unemulated com.google.gerrit.common.Version")
public class Version {
private static final Logger log = LoggerFactory.getLogger(Version.class);
private static final String version;
@VisibleForTesting static final String DEV = "(dev)";
private static final String VERSION;
public static String getVersion() {
return version;
return VERSION;
}
static {
version = loadVersion();
VERSION = loadVersion();
}
private static String loadVersion() {
try (InputStream in = Version.class.getResourceAsStream("Version")) {
if (in == null) {
return "(dev)";
return DEV;
}
try (BufferedReader r = new BufferedReader(new InputStreamReader(in, UTF_8))) {
String vs = r.readLine();