You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tamaya.apache.org by pl...@apache.org on 2016/02/14 16:43:04 UTC

incubator-tamaya git commit: TAMAYA-139 Solution proposal. Version information are read from a properties file in the classpath once.

Repository: incubator-tamaya
Updated Branches:
  refs/heads/master f0146494b -> 9fd1cee1f


TAMAYA-139 Solution proposal. Version information are read from a properties file in the classpath once.


Project: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/commit/9fd1cee1
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/tree/9fd1cee1
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/diff/9fd1cee1

Branch: refs/heads/master
Commit: 9fd1cee1fa27fe70af0e34e66ef81f0ba243c67e
Parents: f014649
Author: Oliver B. Fischer <pl...@apache.org>
Authored: Sun Feb 14 16:42:05 2016 +0100
Committer: Oliver B. Fischer <pl...@apache.org>
Committed: Sun Feb 14 16:42:05 2016 +0100

----------------------------------------------------------------------
 modules/server/pom.xml                          | 30 +++++++++
 .../tamaya/server/ConfigurationResource.java    |  7 +-
 .../apache/tamaya/server/VersionProperties.java | 68 ++++++++++++++++++++
 .../META-INF/server-version.properties          | 22 +++++++
 .../server/src/main/resources/config-server.yml |  2 +
 .../main/resources/server-version.properties    | 22 +++++++
 .../tamaya/server/VersionPropertiesTest.java    | 46 +++++++++++++
 7 files changed, 195 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/9fd1cee1/modules/server/pom.xml
----------------------------------------------------------------------
diff --git a/modules/server/pom.xml b/modules/server/pom.xml
index 62fb139..f5b1e70 100644
--- a/modules/server/pom.xml
+++ b/modules/server/pom.xml
@@ -69,9 +69,39 @@ under the License.
             <groupId>junit</groupId>
             <artifactId>junit</artifactId>
         </dependency>
+        <dependency>
+            <groupId>org.hamcrest</groupId>
+            <artifactId>hamcrest-core</artifactId>
+            <version>${hamcrest.version}</version>
+            <scope>test</scope>
+        </dependency>
+
+        <dependency>
+            <groupId>org.hamcrest</groupId>
+            <artifactId>hamcrest-library</artifactId>
+            <version>${hamcrest.version}</version>
+            <scope>test</scope>
+        </dependency>
     </dependencies>
 
     <build>
+        <resources>
+            <resource>
+                <directory>${project.basedir}/src/main/resources</directory>
+                <filtering>true</filtering>
+                <includes>
+                    <include>META-INF/server-version.properties</include>
+                </includes>
+            </resource>
+            <resource>
+                <directory>${project.basedir}/src/main/resources</directory>
+                <filtering>false</filtering>
+                <excludes>
+                    <exclude>META-INF/server-version.properties</exclude>
+                </excludes>
+            </resource>
+
+        </resources>
         <plugins>
             <plugin>
                 <groupId>com.spotify</groupId>

http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/9fd1cee1/modules/server/src/main/java/org/apache/tamaya/server/ConfigurationResource.java
----------------------------------------------------------------------
diff --git a/modules/server/src/main/java/org/apache/tamaya/server/ConfigurationResource.java b/modules/server/src/main/java/org/apache/tamaya/server/ConfigurationResource.java
index ec01097..a9575fe 100644
--- a/modules/server/src/main/java/org/apache/tamaya/server/ConfigurationResource.java
+++ b/modules/server/src/main/java/org/apache/tamaya/server/ConfigurationResource.java
@@ -63,7 +63,10 @@ public class ConfigurationResource {
     @Path("/version")
     @Produces({MediaType.APPLICATION_JSON, MediaType.TEXT_PLAIN})
     public String version() {
-        return "{ \"version\" : \"Apache Tamaya: 0.2-incubating\" }";
+        String product = VersionProperties.getProduct().replace("\"", "\\\"");
+        String version = VersionProperties.getVersion().replace("\"", "\\\"");
+
+        return String.format("{ \"version\" : \"%s: %s\" }", product, version);
     }
 
     @GET
@@ -318,4 +321,4 @@ public class ConfigurationResource {
         }
     }
 
-}
\ No newline at end of file
+}

http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/9fd1cee1/modules/server/src/main/java/org/apache/tamaya/server/VersionProperties.java
----------------------------------------------------------------------
diff --git a/modules/server/src/main/java/org/apache/tamaya/server/VersionProperties.java b/modules/server/src/main/java/org/apache/tamaya/server/VersionProperties.java
new file mode 100644
index 0000000..1e04e8b
--- /dev/null
+++ b/modules/server/src/main/java/org/apache/tamaya/server/VersionProperties.java
@@ -0,0 +1,68 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tamaya.server;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Properties;
+
+/**
+ * <p>This class gives access to the current name and the current version information
+ * at runtime.</p>
+ *
+ * <p>All information offered by this is loaded from a properties file at
+ * {@value #VERSION_PROPERTY_FILE}.</p>
+ */
+public class VersionProperties {
+    private static final String VERSION_PROPERTY_FILE = "/META-INF/server-version.properties";
+
+    static {
+        try (InputStream resource = VersionProperties.class.getResourceAsStream(VERSION_PROPERTY_FILE)) {
+            if (null == resource) {
+                throw new ExceptionInInitializerError("Failed to version information resource. " +
+                                                       VERSION_PROPERTY_FILE + " not found.");
+            }
+
+            Properties properties = new Properties();
+            properties.load(resource);
+
+            product = properties.getProperty("server.product", "n/a");
+            version = properties.getProperty("server.version", "n/a");
+
+        } catch (IOException e) {
+            throw new ExceptionInInitializerError(e);
+        }
+    }
+
+    private static String product;
+    private static String version;
+
+    private VersionProperties() {
+    }
+
+    public static String getProduct() {
+        return product;
+    }
+
+    public static String getVersion() {
+        return version;
+    }
+
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/9fd1cee1/modules/server/src/main/resources/META-INF/server-version.properties
----------------------------------------------------------------------
diff --git a/modules/server/src/main/resources/META-INF/server-version.properties b/modules/server/src/main/resources/META-INF/server-version.properties
new file mode 100644
index 0000000..ef0ca70
--- /dev/null
+++ b/modules/server/src/main/resources/META-INF/server-version.properties
@@ -0,0 +1,22 @@
+
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy current the License at
+#
+#    http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+
+server.product=Apache Tamaya
+server.version=${project.version}

http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/9fd1cee1/modules/server/src/main/resources/config-server.yml
----------------------------------------------------------------------
diff --git a/modules/server/src/main/resources/config-server.yml b/modules/server/src/main/resources/config-server.yml
index 7d3dbe8..2e210a6 100644
--- a/modules/server/src/main/resources/config-server.yml
+++ b/modules/server/src/main/resources/config-server.yml
@@ -27,3 +27,5 @@ server:
   - type: http
     port: 4099
 
+   # ${project.version}
+

http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/9fd1cee1/modules/server/src/main/resources/server-version.properties
----------------------------------------------------------------------
diff --git a/modules/server/src/main/resources/server-version.properties b/modules/server/src/main/resources/server-version.properties
new file mode 100644
index 0000000..ef0ca70
--- /dev/null
+++ b/modules/server/src/main/resources/server-version.properties
@@ -0,0 +1,22 @@
+
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy current the License at
+#
+#    http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+
+server.product=Apache Tamaya
+server.version=${project.version}

http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/9fd1cee1/modules/server/src/test/java/org/apache/tamaya/server/VersionPropertiesTest.java
----------------------------------------------------------------------
diff --git a/modules/server/src/test/java/org/apache/tamaya/server/VersionPropertiesTest.java b/modules/server/src/test/java/org/apache/tamaya/server/VersionPropertiesTest.java
new file mode 100644
index 0000000..8e1b79d
--- /dev/null
+++ b/modules/server/src/test/java/org/apache/tamaya/server/VersionPropertiesTest.java
@@ -0,0 +1,46 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tamaya.server;
+
+import org.hamcrest.Matchers;
+import org.junit.Test;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Properties;
+
+import static org.hamcrest.Matchers.not;
+import static org.hamcrest.core.IsEqual.equalTo;
+import static org.junit.Assert.*;
+
+public class VersionPropertiesTest {
+
+    @Test
+    public void correctVersionPropertiesAreReadAndSet() throws IOException {
+        InputStream resource = VersionProperties.class.getResourceAsStream("/META-INF/server-version.properties");
+
+        Properties properties = new Properties();
+        properties.load(resource);
+
+        assertThat(VersionProperties.getVersion(), not(Matchers.isEmptyOrNullString()));
+        assertThat(VersionProperties.getVersion(), equalTo(properties.get("server.version")));
+        assertThat(VersionProperties.getProduct(), not(Matchers.isEmptyOrNullString()));
+        assertThat(VersionProperties.getProduct(), equalTo(properties.get("server.product")));
+    }
+}