You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tamaya.apache.org by an...@apache.org on 2017/03/11 22:37:10 UTC
[1/2] incubator-tamaya-sandbox git commit: TAMAYA-256: Fixed Java
version, tests and added documentation for Vertx support.
Repository: incubator-tamaya-sandbox
Updated Branches:
refs/heads/master 99e685002 -> 7efb64e80
TAMAYA-256: Fixed Java version, tests and added documentation for Vertx support.
Project: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/commit/204dc484
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/tree/204dc484
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/diff/204dc484
Branch: refs/heads/master
Commit: 204dc4844552a6d5bff4938ac8b5a36f1c4b3f76
Parents: 99e6850
Author: anatole <an...@apache.org>
Authored: Sat Mar 11 00:02:25 2017 +0100
Committer: anatole <an...@apache.org>
Committed: Sat Mar 11 00:02:25 2017 +0100
----------------------------------------------------------------------
vertx/bnd.bnd | 3 +
vertx/pom.xml | 113 ++++++++++++++++
.../vertx/AbstractConfiguredVerticle.java | 76 +++++++++++
.../org/apache/tamaya/vertx/ConfigVerticle.java | 88 +++++++++++++
.../apache/tamaya/vertx/ConfigVerticleTest.java | 129 +++++++++++++++++++
.../org/apache/tamaya/vertx/TestVerticle.java | 42 ++++++
6 files changed, 451 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/204dc484/vertx/bnd.bnd
----------------------------------------------------------------------
diff --git a/vertx/bnd.bnd b/vertx/bnd.bnd
new file mode 100644
index 0000000..115c2e4
--- /dev/null
+++ b/vertx/bnd.bnd
@@ -0,0 +1,3 @@
+Export-Package: \
+ org.apache.tamaya.vertx
+Bundle-SymbolicName: org.apache.tamaya.vertx
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/204dc484/vertx/pom.xml
----------------------------------------------------------------------
diff --git a/vertx/pom.xml b/vertx/pom.xml
new file mode 100644
index 0000000..058fbd3
--- /dev/null
+++ b/vertx/pom.xml
@@ -0,0 +1,113 @@
+<!--
+ ~ 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.
+ -->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.apache.tamaya.ext</groupId>
+ <artifactId>tamaya-sandbox</artifactId>
+ <version>0.3-incubating-SNAPSHOT</version>
+ <relativePath>..</relativePath>
+ </parent>
+
+ <artifactId>tamaya-vertx-alpha</artifactId>
+ <name>Apache Tamaya Modules - Vertx Support</name>
+ <description>This extension module provides functionality to integrate Tamaya configuration
+ with Vertx.
+ </description>
+ <packaging>jar</packaging>
+
+ <properties>
+ <jdkVersion>1.8</jdkVersion>
+ <maven.compile.sourceLevel>${jdkVersion}</maven.compile.sourceLevel>
+ <maven.compile.targetLevel>${jdkVersion}</maven.compile.targetLevel>
+ <vertx.version>3.3.0</vertx.version>
+ </properties>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.tamaya</groupId>
+ <artifactId>tamaya-api</artifactId>
+ <version>${project.parent.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.tamaya</groupId>
+ <artifactId>tamaya-core</artifactId>
+ <version>${project.parent.version}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>io.vertx</groupId>
+ <artifactId>vertx-core</artifactId>
+ <version>${vertx.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>io.vertx</groupId>
+ <artifactId>vertx-unit</artifactId>
+ <version>${vertx.version}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.tamaya.ext</groupId>
+ <artifactId>tamaya-injection-api</artifactId>
+ <version>${project.parent.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.tamaya.ext</groupId>
+ <artifactId>tamaya-events</artifactId>
+ <version>${project.parent.version}</version>
+ <scope>provided</scope>
+ <optional>true</optional>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.tamaya.ext</groupId>
+ <artifactId>tamaya-injection</artifactId>
+ <version>${project.parent.version}</version>
+ <scope>provided</scope>
+ <optional>true</optional>
+ </dependency>
+ <dependency>
+ <groupId>org.hamcrest</groupId>
+ <artifactId>java-hamcrest</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <version>3.5.1</version>
+ <configuration>
+ <debug>true</debug>
+ <optimize>${maven.compile.optimize}</optimize>
+ <source>${maven.compile.sourceLevel}</source>
+ <target>${maven.compile.targetLevel}</target>
+ <encoding>${project.build.sourceEncoding}</encoding>
+ <showDeprecation>${maven.compile.deprecation}</showDeprecation>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
+</project>
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/204dc484/vertx/src/main/java/org/apache/tamaya/vertx/AbstractConfiguredVerticle.java
----------------------------------------------------------------------
diff --git a/vertx/src/main/java/org/apache/tamaya/vertx/AbstractConfiguredVerticle.java b/vertx/src/main/java/org/apache/tamaya/vertx/AbstractConfiguredVerticle.java
new file mode 100644
index 0000000..495c62f
--- /dev/null
+++ b/vertx/src/main/java/org/apache/tamaya/vertx/AbstractConfiguredVerticle.java
@@ -0,0 +1,76 @@
+/*
+ * 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.vertx;
+
+import io.vertx.core.AbstractVerticle;
+import org.apache.tamaya.Configuration;
+import org.apache.tamaya.ConfigurationProvider;
+import org.apache.tamaya.inject.ConfigurationInjection;
+
+/**
+ * Base verticle class that adds some convenience methods for accessing configuration.
+ * The class also performs configuration injection using {@link ConfigurationInjection}.
+ */
+public abstract class AbstractConfiguredVerticle extends AbstractVerticle{
+
+ private Configuration configuration;
+
+ public AbstractConfiguredVerticle() {
+ configure();
+ }
+
+ public Configuration getConfiguration(){
+ if(configuration==null){
+ return ConfigurationProvider.getConfiguration();
+ }
+ return configuration;
+ }
+
+ public void setConfiguration(Configuration configuration){
+ this.configuration = configuration;
+ }
+
+ protected void configure(){
+ ConfigurationInjection.getConfigurationInjector().configure(this, getConfiguration());
+ }
+
+ protected final String getConfigProperty(String key){
+ return getConfiguration().get(key);
+ }
+
+ protected final String getConfigPropertyOrDefault(String key, String defaultValue){
+ String val = getConfiguration().get(key);
+ if(val==null){
+ return defaultValue;
+ }
+ return val;
+ }
+
+ protected final <T> T getConfigProperty(String key, Class<T> type){
+ return getConfiguration().get(key, type);
+ }
+
+ protected final <T> T getConfigPropertyOrDefault(String key, Class<T> type, T defaultValue){
+ T val = getConfiguration().get(key, type);
+ if(val==null){
+ return defaultValue;
+ }
+ return val;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/204dc484/vertx/src/main/java/org/apache/tamaya/vertx/ConfigVerticle.java
----------------------------------------------------------------------
diff --git a/vertx/src/main/java/org/apache/tamaya/vertx/ConfigVerticle.java b/vertx/src/main/java/org/apache/tamaya/vertx/ConfigVerticle.java
new file mode 100644
index 0000000..228aece
--- /dev/null
+++ b/vertx/src/main/java/org/apache/tamaya/vertx/ConfigVerticle.java
@@ -0,0 +1,88 @@
+/*
+ * 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.vertx;
+
+import io.vertx.core.Handler;
+import io.vertx.core.eventbus.Message;
+import io.vertx.core.eventbus.MessageConsumer;
+import io.vertx.core.json.Json;
+import org.apache.tamaya.Configuration;
+import org.apache.tamaya.ConfigurationProvider;
+import org.apache.tamaya.functions.ConfigurationFunctions;
+import org.apache.tamaya.functions.PropertyMatcher;
+import org.apache.tamaya.inject.api.Config;
+
+import java.util.Map;
+
+/**
+ * Small configured verticle for testing Tamaya's vertx support.
+ */
+public class ConfigVerticle extends AbstractConfiguredVerticle{
+
+ @Config(value = "tamaya.vertx.config.map", defaultValue = "CONFIG-MAP")
+ private String mapBusTarget;
+
+ @Config(value = "tamaya.vertx.config.value", defaultValue = "CONFIG-VAL")
+ private String valBusTarget;
+
+ private MessageConsumer<String> mapBusListener;
+ private MessageConsumer<String> valBusListener;
+
+ @Override
+ public void start()throws Exception{
+ mapBusListener = vertx.eventBus().consumer(mapBusTarget);
+ mapBusListener.handler(new Handler<Message<String>>(){
+ @Override
+ public void handle(final Message<String> message) {
+ Configuration config = ConfigurationProvider.getConfiguration();
+ Map<String,String> cfg = config.with(ConfigurationFunctions.filter(
+ new PropertyMatcher() {
+ @Override
+ public boolean test(String key, String value) {
+ return key.matches(message.body());
+ }
+ }
+ )).getProperties();
+ message.reply(Json.encodePrettily(cfg));
+ }
+ });
+ valBusListener = vertx.eventBus().consumer(valBusTarget);
+ valBusListener.handler(new Handler<Message<String>>(){
+ @Override
+ public void handle(final Message<String> message) {
+ Configuration config = ConfigurationProvider.getConfiguration();
+ message.reply(config.get(message.body()));
+ }
+ });
+ }
+
+ @Override
+ public void stop()throws Exception{
+ mapBusListener.unregister();
+ valBusListener.unregister();
+ }
+
+ @Override
+ public String toString() {
+ return "ConfigVerticle{" +
+ "mapBusTarget='" + mapBusTarget + '\'' +
+ ", valBusTarget='" + valBusTarget + '\'' +
+ '}';
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/204dc484/vertx/src/test/java/org/apache/tamaya/vertx/ConfigVerticleTest.java
----------------------------------------------------------------------
diff --git a/vertx/src/test/java/org/apache/tamaya/vertx/ConfigVerticleTest.java b/vertx/src/test/java/org/apache/tamaya/vertx/ConfigVerticleTest.java
new file mode 100644
index 0000000..734d27a
--- /dev/null
+++ b/vertx/src/test/java/org/apache/tamaya/vertx/ConfigVerticleTest.java
@@ -0,0 +1,129 @@
+/*
+ * 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.vertx;
+
+import io.vertx.core.AsyncResult;
+import io.vertx.core.Handler;
+import io.vertx.core.eventbus.Message;
+import io.vertx.core.json.Json;
+import io.vertx.ext.unit.Async;
+import io.vertx.ext.unit.TestContext;
+import io.vertx.ext.unit.junit.RunTestOnContext;
+import io.vertx.ext.unit.junit.VertxUnitRunner;
+import org.apache.tamaya.ConfigurationProvider;
+import org.apache.tamaya.functions.ConfigurationFunctions;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import java.math.BigDecimal;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+/**
+ * Tests the Tamaya Vertx configuration support.
+ * Created by atsticks on 08.03.17.
+ */
+@RunWith(VertxUnitRunner.class)
+public class ConfigVerticleTest {
+
+ @Rule
+ public RunTestOnContext vertxContext = new RunTestOnContext();
+
+ private TestVerticle testVerticle = new TestVerticle();
+
+ @Before
+ public void prepare(){
+ vertxContext.vertx().deployVerticle(testVerticle);
+ vertxContext.vertx().deployVerticle(new ConfigVerticle());
+ }
+
+ @Test
+ public void testSingle(final TestContext testContext){
+ final Async async = testContext.async();
+ vertxContext.vertx().eventBus().send("CONFIG-VAL",
+ "user.home", new Handler<AsyncResult<Message<String>>>() {
+ @Override
+ public void handle(AsyncResult<Message<String>> reply) {
+ testContext.assertEquals(
+ reply.result().body(),
+ System.getProperty("user.home"));
+ async.complete();
+ }
+ });
+ }
+
+ @Test
+ public void testMap(final TestContext testContext){
+ final Async async = testContext.async();
+ String selector = "user.";
+ vertxContext.vertx().eventBus().send("CONFIG-MAP",
+ selector, new Handler<AsyncResult<Message<String>>>() {
+ @Override
+ public void handle(AsyncResult<Message<String>> reply) {
+ testContext.assertNotNull(reply.result());
+ testContext.assertNotNull(reply.result().body());
+ Map<String,String> config = Json.decodeValue(reply.result().body(),
+ Map.class);
+ Map<String,String> compareTo = ConfigurationProvider.getConfiguration()
+ .with(ConfigurationFunctions.filter((k,v) -> {
+ return k.matches("user.");
+ })).getProperties();
+ testContext.assertEquals(config.size(), compareTo.size());
+ for(Map.Entry<String,String> en:compareTo.entrySet()){
+ testContext.assertEquals(
+ config.get(en.getKey()), en.getValue());
+ }
+ async.complete();
+ }
+ });
+ }
+
+ @Test
+ public void testConfigCalls(TestContext testContext){
+ testContext.assertNotNull(testVerticle.getConfiguration());
+ testContext.assertEquals(
+ testVerticle.getConfigProperty("user.home"),
+ System.getProperty("user.home"));
+ testContext.assertEquals(
+ testVerticle.getConfigPropertyOrDefault("foo.bar", "blabla"),
+ "blabla");
+ testContext.assertEquals(
+ testVerticle.getConfigPropertyOrDefault("foo.bar", BigDecimal.class, new BigDecimal("1.12345")),
+ new BigDecimal("1.12345"));
+ }
+
+ @Test
+ public void testInjection(TestContext testContext){
+ testContext.assertNotNull(testVerticle.userHome);
+ testContext.assertNotNull(testVerticle.userName);
+ testContext.assertNotNull(testVerticle.anyNumber);
+ testContext.assertEquals(
+ testVerticle.userHome,
+ System.getProperty("user.home"));
+ testContext.assertEquals(
+ testVerticle.userName,
+ System.getProperty("user.name"));
+ testContext.assertEquals(
+ testVerticle.anyNumber,
+ new BigDecimal("1.123456789"));
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/204dc484/vertx/src/test/java/org/apache/tamaya/vertx/TestVerticle.java
----------------------------------------------------------------------
diff --git a/vertx/src/test/java/org/apache/tamaya/vertx/TestVerticle.java b/vertx/src/test/java/org/apache/tamaya/vertx/TestVerticle.java
new file mode 100644
index 0000000..8ec90ec
--- /dev/null
+++ b/vertx/src/test/java/org/apache/tamaya/vertx/TestVerticle.java
@@ -0,0 +1,42 @@
+/*
+ * 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.vertx;
+
+import org.apache.tamaya.inject.api.Config;
+
+import java.math.BigDecimal;
+
+/**
+ * Small configured verticle for testing Tamaya's vertx support.
+ */
+public class TestVerticle extends AbstractConfiguredVerticle{
+
+ @Config("user.name")
+ String userName;
+
+ @Config("user.home")
+ String userHome;
+
+ @Config(value = "any.number.BD", defaultValue = "1.123456789")
+ BigDecimal anyNumber;
+
+ public TestVerticle(){
+ super();
+ }
+}
[2/2] incubator-tamaya-sandbox git commit: TAMAYA-238: Added explicit
bundle names.
Posted by an...@apache.org.
TAMAYA-238: Added explicit bundle names.
Project: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/commit/7efb64e8
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/tree/7efb64e8
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/diff/7efb64e8
Branch: refs/heads/master
Commit: 7efb64e8075de1b40bbe65a46b695f789b1465c2
Parents: 204dc48
Author: anatole <an...@apache.org>
Authored: Sat Mar 11 23:36:54 2017 +0100
Committer: anatole <an...@apache.org>
Committed: Sat Mar 11 23:36:54 2017 +0100
----------------------------------------------------------------------
pom.xml | 1 +
validation/pom.xml | 24 +-----------------------
2 files changed, 2 insertions(+), 23 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/7efb64e8/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index 4f27ff7..836b89a 100644
--- a/pom.xml
+++ b/pom.xml
@@ -755,6 +755,7 @@ under the License.
<module>management</module>
<module>metamodel</module>
<module>uom</module>
+ <!--<module>vertx</module>-->
</modules>
<profiles>
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/7efb64e8/validation/pom.xml
----------------------------------------------------------------------
diff --git a/validation/pom.xml b/validation/pom.xml
index 0547892..15bf254 100644
--- a/validation/pom.xml
+++ b/validation/pom.xml
@@ -30,7 +30,7 @@
<name>Apache Tamaya Modules - Validation</name>
<description>This extension module provides functionality to validate configuration.
</description>
- <packaging>bundle</packaging>
+ <packaging>jar</packaging>
<properties>
<jdkVersion>1.7</jdkVersion>
@@ -88,26 +88,4 @@
</dependency>
</dependencies>
- <build>
- <plugins>
- <plugin>
- <groupId>org.apache.felix</groupId>
- <artifactId>maven-bundle-plugin</artifactId>
- <version>3.2.0</version>
- <extensions>true</extensions>
- <configuration>
- <instructions>
- <Export-Package>
- org.apache.tamaya.model,
- org.apache.tamaya.model.spi
- </Export-Package>
- <Private-Package>
- org.apache.tamaya.model.internal
- </Private-Package>
- </instructions>
- </configuration>
- </plugin>
- </plugins>
- </build>
-
</project>