Skip to content
Snippets Groups Projects
Commit 0c74b57f authored by Eike Cochu's avatar Eike Cochu
Browse files

added versioning

added maven buildnumber versioning
added version properties file and reader
updated info resource to return app information
parent 2225b4d1
Branches
No related tags found
No related merge requests found
Showing
with 261 additions and 4 deletions
...@@ -14,6 +14,8 @@ ...@@ -14,6 +14,8 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.target>1.8</maven.compiler.target> <maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.source>1.8</maven.compiler.source> <maven.compiler.source>1.8</maven.compiler.source>
<maven.build.timestamp.format>yyMMdd_HHmm</maven.build.timestamp.format>
<buildDate>${maven.build.timestamp}</buildDate>
<jerseyVersion>2.22.1</jerseyVersion> <jerseyVersion>2.22.1</jerseyVersion>
<jettyVersion>9.3.6.v20151106</jettyVersion> <jettyVersion>9.3.6.v20151106</jettyVersion>
<servletVersion>3.1.0</servletVersion> <servletVersion>3.1.0</servletVersion>
...@@ -21,6 +23,12 @@ ...@@ -21,6 +23,12 @@
<jacksonVersion>2.7.0</jacksonVersion> <jacksonVersion>2.7.0</jacksonVersion>
</properties> </properties>
<scm>
<connection>scm:git:https://git.cochu.io/master-thesis/ma-impl.git</connection>
<developerConnection>scm:git:https://git.cochu.io/master-thesis/ma-impl.git</developerConnection>
<url>https://git.cochu.io/master-thesis/ma-impl</url>
</scm>
<dependencies> <dependencies>
<!-- Jersey REST --> <!-- Jersey REST -->
<dependency> <dependency>
...@@ -113,6 +121,43 @@ ...@@ -113,6 +121,43 @@
<skipTests>true</skipTests> <skipTests>true</skipTests>
</configuration> </configuration>
</plugin> </plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.6</version>
<configuration>
<archive>
<manifest>
<addDefaultImplementationEntries>true</addDefaultImplementationEntries>
</manifest>
<manifestEntries>
<git-SHA-1>${buildNumber}</git-SHA-1>
</manifestEntries>
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>buildnumber-maven-plugin</artifactId>
<version>1.4</version>
<executions>
<execution>
<phase>validate</phase>
<goals>
<goal>create</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins> </plugins>
<resources>
<resource>
<directory>${basedir}/src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
</build> </build>
</project> </project>
package de.vipra.rest.resource; package de.vipra.rest.resource;
import java.lang.management.ManagementFactory;
import java.lang.management.RuntimeMXBean;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.UriInfo;
import de.vipra.rest.model.Wrapper;
import de.vipra.util.BuildInfo;
import de.vipra.util.NestedMap;
import de.vipra.util.StringUtils;
@Path("info")
public class InfoResource { public class InfoResource {
@Context
UriInfo uri;
private static final NestedMap info = new NestedMap();
static {
try {
RuntimeMXBean rb = ManagementFactory.getRuntimeMXBean();
Runtime rt = Runtime.getRuntime();
BuildInfo buildInfo = new BuildInfo();
// vm info
info.put("vm.starttime", rb.getStartTime());
info.put("vm.uptime", rb.getUptime());
info.put("vm.args", StringUtils.join(rb.getInputArguments()));
info.put("vm.java.vendor", System.getProperty("java.vendor"));
info.put("vm.java.version", System.getProperty("java.version"));
// host info
info.put("host.cores", rt.availableProcessors());
info.put("host.memory", rt.maxMemory());
info.put("host.os.name", System.getProperty("os.name"));
info.put("host.os.arch", System.getProperty("os.arch"));
info.put("host.os.version", System.getProperty("os.version"));
// app info
info.put("app.gitsha1", buildInfo.getGitSHA1());
info.put("app.version", buildInfo.getVersion());
info.put("app.builddate", buildInfo.getBuildDate());
} catch (Exception e) {
info.put("error", e.getMessage());
}
}
@GET
@Produces(MediaType.APPLICATION_JSON)
public Response getInfo() {
Wrapper<NestedMap> res = new Wrapper<>();
return res.ok(info);
}
} }
git-sha-1=${buildNumber}
version=${project.version}
builddate=${buildDate}
\ No newline at end of file
...@@ -22,5 +22,11 @@ ...@@ -22,5 +22,11 @@
<attribute name="maven.pomderived" value="true"/> <attribute name="maven.pomderived" value="true"/>
</attributes> </attributes>
</classpathentry> </classpathentry>
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="target/classes"/> <classpathentry kind="output" path="target/classes"/>
</classpath> </classpath>
...@@ -14,8 +14,16 @@ ...@@ -14,8 +14,16 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.target>1.8</maven.compiler.target> <maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.source>1.8</maven.compiler.source> <maven.compiler.source>1.8</maven.compiler.source>
<maven.build.timestamp.format>yyMMdd_HHmm</maven.build.timestamp.format>
<buildDate>${maven.build.timestamp}</buildDate>
</properties> </properties>
<scm>
<connection>scm:git:https://git.cochu.io/master-thesis/ma-impl.git</connection>
<developerConnection>scm:git:https://git.cochu.io/master-thesis/ma-impl.git</developerConnection>
<url>https://git.cochu.io/master-thesis/ma-impl</url>
</scm>
<dependencies> <dependencies>
<!-- Apache Commons --> <!-- Apache Commons -->
<dependency> <dependency>
...@@ -116,10 +124,35 @@ ...@@ -116,10 +124,35 @@
<addClasspath>true</addClasspath> <addClasspath>true</addClasspath>
<classpathPrefix>lib/</classpathPrefix> <classpathPrefix>lib/</classpathPrefix>
<mainClass>de.vipra.cmd.Main</mainClass> <mainClass>de.vipra.cmd.Main</mainClass>
<addDefaultImplementationEntries>true</addDefaultImplementationEntries>
</manifest> </manifest>
<manifestEntries>
<git-SHA-1>${buildNumber}</git-SHA-1>
</manifestEntries>
</archive> </archive>
</configuration> </configuration>
</plugin> </plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>buildnumber-maven-plugin</artifactId>
<version>1.4</version>
<executions>
<execution>
<phase>validate</phase>
<goals>
<goal>create</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins> </plugins>
<resources>
<resource>
<directory>${basedir}/src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
</build> </build>
</project> </project>
git-sha-1=${buildNumber}
version=${project.version}
builddate=${buildDate}
\ No newline at end of file
...@@ -6,6 +6,11 @@ ...@@ -6,6 +6,11 @@
<attribute name="maven.pomderived" value="true"/> <attribute name="maven.pomderived" value="true"/>
</attributes> </attributes>
</classpathentry> </classpathentry>
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER"> <classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
<attributes> <attributes>
<attribute name="maven.pomderived" value="true"/> <attribute name="maven.pomderived" value="true"/>
......
eclipse.preferences.version=1 eclipse.preferences.version=1
encoding//src/main/java=UTF-8 encoding//src/main/java=UTF-8
encoding//src/main/resources=UTF-8
encoding/<project>=UTF-8 encoding/<project>=UTF-8
<?xml version="1.0" encoding="UTF-8"?><project-modules id="moduleCoreId" project-version="1.5.0"> <?xml version="1.0" encoding="UTF-8"?><project-modules id="moduleCoreId" project-version="1.5.0">
<wb-module deploy-name="vipra-util"> <wb-module deploy-name="vipra-util">
<wb-resource deploy-path="/" source-path="/src/main/java"/> <wb-resource deploy-path="/" source-path="/src/main/java"/>
<wb-resource deploy-path="/" source-path="/src/main/resources"/>
</wb-module> </wb-module>
</project-modules> </project-modules>
...@@ -10,8 +10,16 @@ ...@@ -10,8 +10,16 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.target>1.8</maven.compiler.target> <maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.source>1.8</maven.compiler.source> <maven.compiler.source>1.8</maven.compiler.source>
<maven.build.timestamp.format>yyMMdd_HHmm</maven.build.timestamp.format>
<buildDate>${maven.build.timestamp}</buildDate>
</properties> </properties>
<scm>
<connection>scm:git:https://git.cochu.io/master-thesis/ma-impl.git</connection>
<developerConnection>scm:git:https://git.cochu.io/master-thesis/ma-impl.git</developerConnection>
<url>https://git.cochu.io/master-thesis/ma-impl</url>
</scm>
<dependencies> <dependencies>
<!-- Apache Commons --> <!-- Apache Commons -->
<dependency> <dependency>
...@@ -58,4 +66,29 @@ ...@@ -58,4 +66,29 @@
<version>2.1.0</version> <version>2.1.0</version>
</dependency> </dependency>
</dependencies> </dependencies>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>buildnumber-maven-plugin</artifactId>
<version>1.4</version>
<executions>
<execution>
<phase>validate</phase>
<goals>
<goal>create</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
<resources>
<resource>
<directory>${basedir}/src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
</build>
</project> </project>
\ No newline at end of file
package de.vipra.util;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
public class BuildInfo {
private static Properties properties;
private static Properties getProperties() {
if (properties == null) {
InputStream inputStream = FileUtils.getResource("buildNumber.properties");
properties = new Properties();
try {
properties.load(inputStream);
} catch (IOException e) {
throw new RuntimeException("Failed to read properties file", e);
} finally {
if (inputStream != null) {
try {
inputStream.close();
} catch (IOException e) {
// Ignore
}
}
}
}
return properties;
}
private final String gitSHA1;
private final String version;
private final String buildDate;
public BuildInfo() {
Properties props = getProperties();
this.gitSHA1 = props.getProperty("git-sha-1");
this.version = props.getProperty("version");
this.buildDate = props.getProperty("builddate");
}
public String getGitSHA1() {
return gitSHA1;
}
public String getVersion() {
return version;
}
public String getBuildDate() {
return buildDate;
}
}
\ No newline at end of file
...@@ -77,21 +77,32 @@ public class FileUtils extends org.apache.commons.io.FileUtils { ...@@ -77,21 +77,32 @@ public class FileUtils extends org.apache.commons.io.FileUtils {
* *
* @param name * @param name
* name of resource * name of resource
* @Param clazz class to use to retrieve resource
* @return resource or null * @return resource or null
*/ */
public static InputStream getResource(String name) { public static InputStream getResource(String name, Class<?> clazz) {
while (name.startsWith("/")) while (name.startsWith("/"))
name = name.substring(1); name = name.substring(1);
InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream(name); InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream(name);
if (is == null) { if (is == null) {
is = Config.class.getResourceAsStream(name); if (clazz != null)
is = clazz.getResourceAsStream(name);
else
is = Config.class.getResourceAsStream(name);
} }
if (isJAR && !name.startsWith("resources") && getResource("resources/") != null) if (isJAR && !name.startsWith("resources") && getResource("resources/", clazz) != null)
return getResource("resources/" + name); return getResource("resources/" + name, clazz);
else else
return is; return is;
} }
/**
* @see {@link FileUtils#getResource(String, Class)}
*/
public static InputStream getResource(String name) {
return getResource(name, null);
}
/** /**
* Counts the lines in a file * Counts the lines in a file
* *
......
git-sha-1=${buildNumber}
version=${project.version}
builddate=${buildDate}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment