diff --git a/vipra-backend/pom.xml b/vipra-backend/pom.xml index 0b93290d0545b5c866769197ad14087ca68c3cc2..6bc93255b326a84642fbe3945b46005cf3e7d7d4 100644 --- a/vipra-backend/pom.xml +++ b/vipra-backend/pom.xml @@ -14,6 +14,8 @@ <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <maven.compiler.target>1.8</maven.compiler.target> <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> <jettyVersion>9.3.6.v20151106</jettyVersion> <servletVersion>3.1.0</servletVersion> @@ -21,6 +23,12 @@ <jacksonVersion>2.7.0</jacksonVersion> </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> <!-- Jersey REST --> <dependency> @@ -113,6 +121,43 @@ <skipTests>true</skipTests> </configuration> </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> + + <resources> + <resource> + <directory>${basedir}/src/main/resources</directory> + <filtering>true</filtering> + </resource> + </resources> </build> </project> diff --git a/vipra-backend/src/main/java/de/vipra/rest/resource/InfoResource.java b/vipra-backend/src/main/java/de/vipra/rest/resource/InfoResource.java index 18dde950fac14ac1fba9931fb718af5809580280..0b24151d7186f8cde568e6534b2f04b7bf94b8a1 100644 --- a/vipra-backend/src/main/java/de/vipra/rest/resource/InfoResource.java +++ b/vipra-backend/src/main/java/de/vipra/rest/resource/InfoResource.java @@ -1,5 +1,62 @@ 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 { + @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); + } } diff --git a/vipra-backend/src/main/resources/buildNumber.properties b/vipra-backend/src/main/resources/buildNumber.properties new file mode 100644 index 0000000000000000000000000000000000000000..e340aab1876a2301cbd747d057798e4db2c1a143 --- /dev/null +++ b/vipra-backend/src/main/resources/buildNumber.properties @@ -0,0 +1,3 @@ +git-sha-1=${buildNumber} +version=${project.version} +builddate=${buildDate} \ No newline at end of file diff --git a/vipra-cmd/.classpath b/vipra-cmd/.classpath index 24f51ca2c6aa22680ae5cbb790e66ec176e43965..4b6b27664bf27624189421ebc42d984b75d9e8d1 100644 --- a/vipra-cmd/.classpath +++ b/vipra-cmd/.classpath @@ -22,5 +22,11 @@ <attribute name="maven.pomderived" value="true"/> </attributes> </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"/> </classpath> diff --git a/vipra-cmd/pom.xml b/vipra-cmd/pom.xml index 64fc4cdfb9681c0914d1f6e12d67c6f4c751156d..ccacb04b64992fe250634dcba7b7686d246cfedc 100644 --- a/vipra-cmd/pom.xml +++ b/vipra-cmd/pom.xml @@ -14,8 +14,16 @@ <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <maven.compiler.target>1.8</maven.compiler.target> <maven.compiler.source>1.8</maven.compiler.source> + <maven.build.timestamp.format>yyMMdd_HHmm</maven.build.timestamp.format> + <buildDate>${maven.build.timestamp}</buildDate> </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> <!-- Apache Commons --> <dependency> @@ -116,10 +124,35 @@ <addClasspath>true</addClasspath> <classpathPrefix>lib/</classpathPrefix> <mainClass>de.vipra.cmd.Main</mainClass> + <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> + + <resources> + <resource> + <directory>${basedir}/src/main/resources</directory> + <filtering>true</filtering> + </resource> + </resources> </build> </project> diff --git a/vipra-cmd/src/main/resources/buildNumber.properties b/vipra-cmd/src/main/resources/buildNumber.properties new file mode 100644 index 0000000000000000000000000000000000000000..e340aab1876a2301cbd747d057798e4db2c1a143 --- /dev/null +++ b/vipra-cmd/src/main/resources/buildNumber.properties @@ -0,0 +1,3 @@ +git-sha-1=${buildNumber} +version=${project.version} +builddate=${buildDate} \ No newline at end of file diff --git a/vipra-util/.classpath b/vipra-util/.classpath index 332896b54e5e51f9182bf4cc67b19abb799ed950..bc4ecd839eae0f22d3fd040e98dbb33cdbdcc96b 100644 --- a/vipra-util/.classpath +++ b/vipra-util/.classpath @@ -6,6 +6,11 @@ <attribute name="maven.pomderived" value="true"/> </attributes> </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"> <attributes> <attribute name="maven.pomderived" value="true"/> diff --git a/vipra-util/.settings/org.eclipse.core.resources.prefs b/vipra-util/.settings/org.eclipse.core.resources.prefs index e9441bb123ec3e1ab029c7eac896bc45681d9a71..abdea9ac032d4655898933f93050f48bf9581d14 100644 --- a/vipra-util/.settings/org.eclipse.core.resources.prefs +++ b/vipra-util/.settings/org.eclipse.core.resources.prefs @@ -1,3 +1,4 @@ eclipse.preferences.version=1 encoding//src/main/java=UTF-8 +encoding//src/main/resources=UTF-8 encoding/<project>=UTF-8 diff --git a/vipra-util/.settings/org.eclipse.wst.common.component b/vipra-util/.settings/org.eclipse.wst.common.component index 98cb9759f376998c345804d1b8ac743309b0b3ae..217de769b1c939ce8569041d55e0227a3473b779 100644 --- a/vipra-util/.settings/org.eclipse.wst.common.component +++ b/vipra-util/.settings/org.eclipse.wst.common.component @@ -1,5 +1,6 @@ <?xml version="1.0" encoding="UTF-8"?><project-modules id="moduleCoreId" project-version="1.5.0"> <wb-module deploy-name="vipra-util"> <wb-resource deploy-path="/" source-path="/src/main/java"/> + <wb-resource deploy-path="/" source-path="/src/main/resources"/> </wb-module> </project-modules> diff --git a/vipra-util/pom.xml b/vipra-util/pom.xml index 5084145ae53e0c0e941984e53c59ce3e41268117..aa784ea6b69595efbbcc077bb504b5dafbceb5b6 100644 --- a/vipra-util/pom.xml +++ b/vipra-util/pom.xml @@ -10,8 +10,16 @@ <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <maven.compiler.target>1.8</maven.compiler.target> <maven.compiler.source>1.8</maven.compiler.source> + <maven.build.timestamp.format>yyMMdd_HHmm</maven.build.timestamp.format> + <buildDate>${maven.build.timestamp}</buildDate> </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> <!-- Apache Commons --> <dependency> @@ -58,4 +66,29 @@ <version>2.1.0</version> </dependency> </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> \ No newline at end of file diff --git a/vipra-util/src/main/java/de/vipra/util/BuildInfo.java b/vipra-util/src/main/java/de/vipra/util/BuildInfo.java new file mode 100644 index 0000000000000000000000000000000000000000..befee3124c23557728bdff9007d16c1ac111c13b --- /dev/null +++ b/vipra-util/src/main/java/de/vipra/util/BuildInfo.java @@ -0,0 +1,56 @@ +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 diff --git a/vipra-util/src/main/java/de/vipra/util/FileUtils.java b/vipra-util/src/main/java/de/vipra/util/FileUtils.java index 44aa7bce7584f406808b4ddc716a4031d3858e30..1b26ea291e01333846f40450c7bed53e970eda1d 100644 --- a/vipra-util/src/main/java/de/vipra/util/FileUtils.java +++ b/vipra-util/src/main/java/de/vipra/util/FileUtils.java @@ -77,21 +77,32 @@ public class FileUtils extends org.apache.commons.io.FileUtils { * * @param name * name of resource + * @Param clazz class to use to retrieve resource * @return resource or null */ - public static InputStream getResource(String name) { + public static InputStream getResource(String name, Class<?> clazz) { while (name.startsWith("/")) name = name.substring(1); InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream(name); 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) - return getResource("resources/" + name); + if (isJAR && !name.startsWith("resources") && getResource("resources/", clazz) != null) + return getResource("resources/" + name, clazz); else return is; } + /** + * @see {@link FileUtils#getResource(String, Class)} + */ + public static InputStream getResource(String name) { + return getResource(name, null); + } + /** * Counts the lines in a file * diff --git a/vipra-util/src/main/resources/buildNumber.properties b/vipra-util/src/main/resources/buildNumber.properties new file mode 100644 index 0000000000000000000000000000000000000000..e340aab1876a2301cbd747d057798e4db2c1a143 --- /dev/null +++ b/vipra-util/src/main/resources/buildNumber.properties @@ -0,0 +1,3 @@ +git-sha-1=${buildNumber} +version=${project.version} +builddate=${buildDate} \ No newline at end of file