diff --git a/.gitignore b/.gitignore index 0e2b0a7bfd7600af76263f2b37c5f40f188a608e..afc5c326e2982d289666eade6c1b2e7e4329fc5c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ /.settings /.classpath /target +src/main/resources/git.properties diff --git a/pom.xml b/pom.xml index dd503231e829f2efd8ee0213908caf70103550a0..02b0524436c90210a0444dbbe56f097515984ad0 100644 --- a/pom.xml +++ b/pom.xml @@ -257,6 +257,27 @@ </plugins> </pluginManagement> <plugins> + <plugin> + <groupId>pl.project13.maven</groupId> + <artifactId>git-commit-id-plugin</artifactId> + <version>2.1.5</version> + <executions> + <execution> + <goals> + <goal>revision</goal> + </goals> + </execution> + </executions> + <configuration> + <verbose>true</verbose> + <dateFormat>yyyy-MM-dd HH:mm:ss</dateFormat> + <generateGitPropertiesFile>true</generateGitPropertiesFile> + <gitDescribe> + <tags>true</tags> + <dirty>-dev</dirty> + </gitDescribe> + </configuration> + </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> diff --git a/src/main/java/info/textgrid/services/aggregator/Version.java b/src/main/java/info/textgrid/services/aggregator/Version.java index 745d07d01b70fe2482aff91bb5855488171f571e..134cc961e5effe32c88278f414dc430268d478e5 100644 --- a/src/main/java/info/textgrid/services/aggregator/Version.java +++ b/src/main/java/info/textgrid/services/aggregator/Version.java @@ -1,8 +1,10 @@ package info.textgrid.services.aggregator; import java.io.IOException; +import java.io.InputStream; import java.io.OutputStream; import java.io.PrintStream; +import java.util.Properties; import javax.ws.rs.GET; import javax.ws.rs.Path; @@ -14,16 +16,33 @@ @Path("/version") public class Version { - - + private final ITextGridRep repository; private final String version; + private Properties gitInfo; public Version(final ITextGridRep repository, final String version) { this.repository = repository; this.version = version; } - + + private Properties loadGitInfo() { + if (gitInfo == null) { + gitInfo = new Properties(); + final InputStream inputStream = getClass().getResourceAsStream( + "/git.properties"); + if (inputStream != null) { + try { + gitInfo.load(inputStream); + } catch (final IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + } + return gitInfo; + } + @GET // @Path("/") @Produces("text/html") @@ -32,19 +51,29 @@ public StreamingOutput get() { @Override public void write(final OutputStream outputStream) - throws IOException, - WebApplicationException { + throws IOException, WebApplicationException { final PrintStream out = new PrintStream(outputStream, true); out.println("<!DOCTYPE html><html><head><meta charset='utf-8'/><title>Aggregator Version Report</title></head><body>"); - out.printf("<h1>TextGrid Aggregator Version %s</h1>\n", version); - out.printf("<p>TextGridRep Configuration Endpoint: <a href='%1$s'>%1$s</a></p>\n\n", + out.printf("<h1>TextGrid Aggregator</h1>\n", version); + final Properties info = loadGitInfo(); + out.printf( + "<p style='border: 1px solid #ccf; padding: 6px;'>Version: <em>%s</em> (<strong>%s</strong>) from branch <em>%s</em> as of <em>%s</em>, built on <em>%s</em>.</p>", + version, + info.getProperty("git.commit.id.describe", "?"), + info.getProperty("git.branch", "?"), + info.getProperty("git.commit.time", "?"), + info.getProperty("git.build.time", "?")); + + out.printf( + "<p>TextGridRep Configuration Endpoint: <a href='%1$s'>%1$s</a></p>\n\n", repository.getCONF_ENDPOINT()); out.print("<h3>Repository Configuration:</h3>\n<table><tr><td>"); - out.print(Joiner.on("</td></tr>\n<tr><td>").withKeyValueSeparator("</td><td>") + out.print(Joiner.on("</td></tr>\n<tr><td>") + .withKeyValueSeparator("</td><td>") .join(repository.getConfig())); out.println("</td></tr></table>"); - out.printf("<p>Using TG-crud version: <strong>%s</strong>\n", repository - .getCRUDService().getVersion()); + out.printf("<p>Using TG-crud version: <strong>%s</strong>\n", + repository.getCRUDService().getVersion()); out.println("</body></html>"); out.close(); @@ -52,6 +81,5 @@ public void write(final OutputStream outputStream) } }; } - }