[Lada-commits] [PATCH 1 of 2] Get version from pom.xml instead of hard coded

Wald Commits scm-commit at wald.intevation.org
Tue Jun 7 12:12:46 CEST 2016


# HG changeset patch
# User Tom Gottfried <tom at intevation.de>
# Date 1465293816 -7200
# Node ID ad8c859cfdca1275c5d836149bbb5c745b4ab12a
# Parent  3a2ed18fe13c4b9865a463ae0f58ad58bef6aac1
Get version from pom.xml instead of hard coded.

diff -r 3a2ed18fe13c -r ad8c859cfdca pom.xml
--- a/pom.xml	Mon Jun 06 15:15:12 2016 +0200
+++ b/pom.xml	Tue Jun 07 12:03:36 2016 +0200
@@ -169,6 +169,12 @@
                 <activeByDefault>true</activeByDefault>
             </activation>
             <build>
+                <resources>
+                    <resource>
+                        <directory>src/main/resources</directory>
+                        <filtering>true</filtering>
+                    </resource>
+                </resources>
                 <plugins>
                     <plugin>
                         <artifactId>maven-surefire-plugin</artifactId>
diff -r 3a2ed18fe13c -r ad8c859cfdca src/main/java/de/intevation/lada/rest/VersionService.java
--- a/src/main/java/de/intevation/lada/rest/VersionService.java	Mon Jun 06 15:15:12 2016 +0200
+++ b/src/main/java/de/intevation/lada/rest/VersionService.java	Tue Jun 07 12:03:36 2016 +0200
@@ -7,6 +7,10 @@
  */
 package de.intevation.lada.rest;
 
+import java.util.ResourceBundle;
+import java.util.MissingResourceException;
+
+import javax.inject.Inject;
 import javax.enterprise.context.RequestScoped;
 import javax.servlet.http.HttpServletRequest;
 import javax.ws.rs.GET;
@@ -17,6 +21,8 @@
 import javax.ws.rs.core.MediaType;
 import javax.ws.rs.core.UriInfo;
 
+import org.apache.log4j.Logger;
+
 import de.intevation.lada.util.rest.Response;
 
 /**
@@ -46,7 +52,8 @@
 @RequestScoped
 public class VersionService {
 
-    private static final String VERSION = "2.2.0";
+    @Inject
+    private Logger logger;
 
     /**
      * Get server Version.
@@ -63,6 +70,14 @@
         @Context HttpServletRequest request,
         @Context UriInfo info
     ) {
-        return new Response(true, 200, VERSION);
+        String version = "unknown";
+        try {
+            version = ResourceBundle.getBundle("lada").getString("version");
+            return new Response(true, 200, version);
+        }
+        catch (MissingResourceException mre) {
+            logger.error(mre);
+        }
+        return new Response(false, 200, version);
     }
 }
diff -r 3a2ed18fe13c -r ad8c859cfdca src/main/resources/lada.properties
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/main/resources/lada.properties	Tue Jun 07 12:03:36 2016 +0200
@@ -0,0 +1,1 @@
+version=${project.version}


More information about the Lada-commits mailing list