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/09/25 21:23:49 UTC
[01/50] [abbrv] incubator-tamaya-sandbox git commit: TAMAYA-60
JavaDoc...
Repository: incubator-tamaya-sandbox
Updated Branches:
refs/heads/master 6392c952b -> 7acfa8070
TAMAYA-60 JavaDoc...
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/d7dd200a
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/tree/d7dd200a
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/diff/d7dd200a
Branch: refs/heads/master
Commit: d7dd200a14e82fed99a08f88447d80cfbe29d502
Parents: 158d589
Author: Oliver B. Fischer <pl...@apache.org>
Authored: Tue Mar 10 22:43:39 2015 +0100
Committer: Oliver B. Fischer <pl...@apache.org>
Committed: Tue Mar 10 22:43:39 2015 +0100
----------------------------------------------------------------------
.../modules/builder/ConfigurationBuilder.java | 63 ++++++++++++++++++--
1 file changed, 57 insertions(+), 6 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/d7dd200a/src/main/java/org/apache/tamaya/modules/builder/ConfigurationBuilder.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/tamaya/modules/builder/ConfigurationBuilder.java b/src/main/java/org/apache/tamaya/modules/builder/ConfigurationBuilder.java
index cd55a27..173117a 100644
--- a/src/main/java/org/apache/tamaya/modules/builder/ConfigurationBuilder.java
+++ b/src/main/java/org/apache/tamaya/modules/builder/ConfigurationBuilder.java
@@ -157,16 +157,16 @@ public class ConfigurationBuilder {
* <p>If a specific format is supported depends on the available
* {@link org.apache.tamaya.format.ConfigurationFormat} implementations.</p>
*
- *<pre>
- * URL first = new URL("file:/etc/service/config.json");
- * URL second = new URL(file:/etc/defaults/values.properties");
+ *<pre>{@code URL first = new URL("file:/etc/service/config.json");
+ * URL second = new URL("file:/etc/defaults/values.properties");
*
- * builder.addPropertySources(first, second);
+ * builder.addPropertySources(first, second);}
*</pre>
*
* @param url first resource with properties for the the configuration to be build.
* @param urls list additional of resources with properties for the configuration to be
* build.
+ *
* @return the builder instance currently used
*
* @see org.apache.tamaya.format.ConfigurationFormat
@@ -182,8 +182,26 @@ public class ConfigurationBuilder {
return this;
}
+
/**
+ * Adds one or more resources with properties in an arbitrary format
+ * to the configuration to be build.
+ *
+ * <p>If a specific format is supported depends on the available
+ * {@link org.apache.tamaya.format.ConfigurationFormat} implementations.</p>
+ *
+ *<pre>{@code builder.addPropertySources("file:/etc/service/config.json",
+ * "file:/etc/defaults/values.properties");}
+ *</pre>
+ *
+ * @param url first resource with properties for the the configuration to be build.
+ * @param urls list additional of resources with properties for the configuration to be
+ * build.
+ *
* @return the builder instance currently used
+ *
+ * @see org.apache.tamaya.format.ConfigurationFormat
+ * @see org.apache.tamaya.format.ConfigurationFormats#getFormats()
*/
public ConfigurationBuilder addPropertySource(String url, String... urls) {
Stream.of(Collections.singletonList(url), Arrays.asList(urls))
@@ -197,7 +215,20 @@ public class ConfigurationBuilder {
}
/**
+ * Adds one or more property source instances to the configuration to be build.
+ *
+ *<pre>{@code PropertySource first = new CustomPropertySource();
+ * PropertySource second = new YetAnotherPropertySource();
+ *
+ * builder.addPropertySources(first, second)};
+ *</pre>
+ *
+ * @param sources list of property source instances with properties for the
+ * configuration to be build.
+ *
* @return the builder instance currently used
+ *
+ * @see org.apache.tamaya.spi.PropertySource
*/
public ConfigurationBuilder addPropertySources(PropertySource... sources){
checkBuilderState();
@@ -213,10 +244,22 @@ public class ConfigurationBuilder {
}
/**
+ * Adds one or more property source provider instances to the configuration to be build.
+ *
+ * <pre>{@code PropertySourceProvider jc = new JavaConfigurationProvider();
+ *
+ * builder.addPropertySources(jc)};
+ * </pre>
+ *
+ * @param providers list of property source provider instances each providing a set
+ * of property source instances for the configuration to be build.
+ *
* @return the builder instance currently used
+ *
+ * @see org.apache.tamaya.spi.PropertySourceProvider
*/
- public ConfigurationBuilder addPropertySourceProviders(PropertySourceProvider... propertySourceProviders){
- contextBuilder.addPropertySourceProviders(propertySourceProviders);
+ public ConfigurationBuilder addPropertySourceProviders(PropertySourceProvider... providers){
+ contextBuilder.addPropertySourceProviders(providers);
return this;
}
@@ -332,6 +375,14 @@ public class ConfigurationBuilder {
}
/**
+ * Disables the loading of all {@link org.apache.tamaya.spi.PropertyFilter}
+ * service providers.
+ *
+ * @return the builder instance currently used
+ *
+ * @see org.apache.tamaya.spi.PropertyFilter
+ * @see #enabledProvidedPropertyFilters()
+ *
* @return the builder instance currently used
*/
public ConfigurationBuilder disableProvidedPropertyFilters() {
[41/50] [abbrv] incubator-tamaya-sandbox git commit:
[maven-release-plugin] prepare release tamaya-all-0.2-incubating
Posted by pl...@apache.org.
[maven-release-plugin] prepare release tamaya-all-0.2-incubating
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/3fb70b50
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/tree/3fb70b50
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/diff/3fb70b50
Branch: refs/heads/master
Commit: 3fb70b50451b35657781e0a782f7d7147657a7a3
Parents: fdeb76b
Author: anatole <an...@apache.org>
Authored: Wed Mar 16 16:20:07 2016 +0100
Committer: anatole <an...@apache.org>
Committed: Wed Mar 16 16:20:07 2016 +0100
----------------------------------------------------------------------
pom.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/3fb70b50/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index 32dc6b5..9202d80 100644
--- a/pom.xml
+++ b/pom.xml
@@ -23,7 +23,7 @@ under the License.
<parent>
<groupId>org.apache.tamaya.ext</groupId>
<artifactId>tamaya-extensions</artifactId>
- <version>0.2-incubating-SNAPSHOT</version>
+ <version>0.2-incubating</version>
</parent>
<artifactId>tamaya-builder</artifactId>
[40/50] [abbrv] incubator-tamaya-sandbox git commit: Fixed deprecated
calls, some javadoc issues.
Posted by pl...@apache.org.
Fixed deprecated calls, some javadoc issues.
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/fdeb76bc
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/tree/fdeb76bc
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/diff/fdeb76bc
Branch: refs/heads/master
Commit: fdeb76bc22bd0b81db8433591a11069ff92821b0
Parents: 3c667de
Author: anatole <an...@apache.org>
Authored: Tue Mar 15 08:39:07 2016 +0100
Committer: anatole <an...@apache.org>
Committed: Tue Mar 15 08:39:07 2016 +0100
----------------------------------------------------------------------
.../org/apache/tamaya/builder/ConfigurationBuilderTest.java | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/fdeb76bc/src/test/java/org/apache/tamaya/builder/ConfigurationBuilderTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/tamaya/builder/ConfigurationBuilderTest.java b/src/test/java/org/apache/tamaya/builder/ConfigurationBuilderTest.java
index 43196f7..07a72c5 100644
--- a/src/test/java/org/apache/tamaya/builder/ConfigurationBuilderTest.java
+++ b/src/test/java/org/apache/tamaya/builder/ConfigurationBuilderTest.java
@@ -370,8 +370,7 @@ public class ConfigurationBuilderTest {
@Test(expected = NullPointerException.class)
public void canNotAddNullAsPropertyFilter() {
ConfigurationBuilder builder = new ConfigurationBuilder();
-
- builder.addPropertyFilters(null);
+ builder.addPropertyFilters((PropertyFilter[])null);
}
@Test
@@ -505,7 +504,7 @@ public class ConfigurationBuilderTest {
@Test(expected = NullPointerException.class)
public void cannotAddNullAsPropertyProvider() {
- new ConfigurationBuilder().addPropertySourceProviders(null);
+ new ConfigurationBuilder().addPropertySourceProviders((PropertySourceProvider[])null);
}
@Test
[18/50] [abbrv] incubator-tamaya-sandbox git commit: Reset version
for rerunning release plugin.
Posted by pl...@apache.org.
Reset version for rerunning release plugin.
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/b656312a
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/tree/b656312a
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/diff/b656312a
Branch: refs/heads/master
Commit: b656312ac97c9a011ad05d72fdf3cba79c2c3dd1
Parents: 3106f95
Author: anatole <at...@gmail.com>
Authored: Tue Aug 4 11:22:59 2015 +0200
Committer: anatole <at...@gmail.com>
Committed: Tue Aug 4 11:22:59 2015 +0200
----------------------------------------------------------------------
pom.xml | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/b656312a/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index 4cabb38..0e0c034 100644
--- a/pom.xml
+++ b/pom.xml
@@ -17,8 +17,7 @@ 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"
+<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>
[16/50] [abbrv] incubator-tamaya-sandbox git commit: Added missing
scm sections (pom). Readded simpke model. Fixed compile issues.
Posted by pl...@apache.org.
Added missing scm sections (pom).
Readded simpke model.
Fixed compile issues.
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/0c039d5b
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/tree/0c039d5b
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/diff/0c039d5b
Branch: refs/heads/master
Commit: 0c039d5b912e16ef1eb4a55b37b7189a0686cd77
Parents: 66c6e8d
Author: anatole <at...@gmail.com>
Authored: Tue Jul 28 00:55:35 2015 +0200
Committer: anatole <at...@gmail.com>
Committed: Tue Jul 28 00:55:35 2015 +0200
----------------------------------------------------------------------
pom.xml | 13 +++++++++
.../tamaya/builder/SimplePropertySource.java | 30 ++++++++++++++++++++
2 files changed, 43 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/0c039d5b/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index 97d42b7..d203b01 100644
--- a/pom.xml
+++ b/pom.xml
@@ -33,12 +33,24 @@ under the License.
<inceptionYear>2015</inceptionYear>
+ <scm>
+ <connection>
+ scm:git://git.apache.org/incubator-tamaya.git
+ </connection>
+ <developerConnection>
+ scm:git://git.apache.org/incubator-tamaya.git
+ </developerConnection>
+ <url>
+ https://git-wip-us.apache.org/repos/asf?p=incubator-tamaya.git
+ </url>
+ </scm>
<dependencies>
<dependency>
<groupId>org.apache.tamaya</groupId>
<artifactId>tamaya-api</artifactId>
<version>${project.version}</version>
+ <scope>provided</scope>
</dependency>
<dependency>
@@ -51,6 +63,7 @@ under the License.
<groupId>org.apache.tamaya</groupId>
<artifactId>tamaya-core</artifactId>
<version>${project.version}</version>
+ <scope>provided</scope>
</dependency>
<dependency>
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/0c039d5b/src/main/java/org/apache/tamaya/builder/SimplePropertySource.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/tamaya/builder/SimplePropertySource.java b/src/main/java/org/apache/tamaya/builder/SimplePropertySource.java
index f343973..f39a0cc 100644
--- a/src/main/java/org/apache/tamaya/builder/SimplePropertySource.java
+++ b/src/main/java/org/apache/tamaya/builder/SimplePropertySource.java
@@ -23,6 +23,8 @@ import org.apache.tamaya.spi.PropertySource;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
+import java.util.logging.Level;
+import java.util.logging.Logger;
/**
* Simple property source implementation using a map.
@@ -39,16 +41,44 @@ public class SimplePropertySource implements PropertySource {
}
@Override
+ public int getOrdinal(){
+ String configuredOrdinal = get(TAMAYA_ORDINAL);
+ if(configuredOrdinal!=null){
+ try{
+ return Integer.parseInt(configuredOrdinal);
+ } catch(Exception e){
+ Logger.getLogger(getClass().getName()).log(Level.WARNING,
+ "Configured Ordinal is not an int number: " + configuredOrdinal, e);
+ }
+ }
+ return getDefaultOrdinal();
+ }
+
+ public int getDefaultOrdinal(){
+ return 0;
+ }
+
+ @Override
public String getName() {
return name;
}
@Override
+ public String get(String key) {
+ return null;
+ }
+
+ @Override
public Map<String, String> getProperties() {
return this.properties;
}
@Override
+ public boolean isScannable() {
+ return false;
+ }
+
+ @Override
public String toString(){
return "SimplePropertySource(name="+name+", numProps="+properties.size()+")";
}
[09/50] [abbrv] incubator-tamaya-sandbox git commit: Establishing
naming convention for property filters.
Posted by pl...@apache.org.
Establishing naming convention for property filters.
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/a63c28f7
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/tree/a63c28f7
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/diff/a63c28f7
Branch: refs/heads/master
Commit: a63c28f7f2b3133bf7ea5d857fb36ef132f47540
Parents: f34d77d
Author: Oliver B. Fischer <pl...@apache.org>
Authored: Tue Apr 14 08:42:56 2015 +0200
Committer: Oliver B. Fischer <pl...@apache.org>
Committed: Tue Apr 14 08:42:56 2015 +0200
----------------------------------------------------------------------
.../builder/ConfigurationBuilderTest.java | 16 ++++-----
.../builder/TestANonSPIPropertyFilter.java | 34 ++++++++++++++++++++
.../builder/TestBNonSPIPropertyFilter.java | 34 ++++++++++++++++++++
.../builder/TestNonSPIPropertyFilterA.java | 34 --------------------
.../builder/TestNonSPIPropertyFilterB.java | 34 --------------------
5 files changed, 76 insertions(+), 76 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/a63c28f7/src/test/java/org/apache/tamaya/builder/ConfigurationBuilderTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/tamaya/builder/ConfigurationBuilderTest.java b/src/test/java/org/apache/tamaya/builder/ConfigurationBuilderTest.java
index 5f33c24..e28f3ea 100644
--- a/src/test/java/org/apache/tamaya/builder/ConfigurationBuilderTest.java
+++ b/src/test/java/org/apache/tamaya/builder/ConfigurationBuilderTest.java
@@ -372,7 +372,7 @@ public class ConfigurationBuilderTest {
ConfigurationBuilder builder = new ConfigurationBuilder();
Configuration config = builder.addPropertySources(source)
- .addPropertyFilters(new TestNonSPIPropertyFilterA())
+ .addPropertyFilters(new TestANonSPIPropertyFilter())
.build();
String property = config.get("key");
@@ -391,8 +391,8 @@ public class ConfigurationBuilderTest {
ConfigurationBuilder builder = new ConfigurationBuilder();
Configuration config = builder.addPropertySources(source)
- .addPropertyFilters(new TestNonSPIPropertyFilterA())
- .addPropertyFilters(new TestNonSPIPropertyFilterB())
+ .addPropertyFilters(new TestANonSPIPropertyFilter())
+ .addPropertyFilters(new TestBNonSPIPropertyFilter())
.build();
String property = config.get("key");
@@ -412,9 +412,9 @@ public class ConfigurationBuilderTest {
ConfigurationBuilder builder = new ConfigurationBuilder();
Configuration config = builder.addPropertySources(source)
- .addPropertyFilters(new TestNonSPIPropertyFilterA(),
+ .addPropertyFilters(new TestANonSPIPropertyFilter(),
null,
- new TestNonSPIPropertyFilterB())
+ new TestBNonSPIPropertyFilter())
.build();
String property = config.get("key");
@@ -435,7 +435,7 @@ public class ConfigurationBuilderTest {
Configuration config = builder.addPropertySources(source)
.addPropertyFilters((PropertyFilter)null) // The cast is needed!
- .addPropertyFilters(new TestNonSPIPropertyFilterB())
+ .addPropertyFilters(new TestBNonSPIPropertyFilter())
.build();
String property = config.get("key");
@@ -454,8 +454,8 @@ public class ConfigurationBuilderTest {
ConfigurationBuilder builder = new ConfigurationBuilder();
Configuration config = builder.addPropertySources(source)
- .addPropertyFilters(new TestNonSPIPropertyFilterA(),
- new TestNonSPIPropertyFilterB())
+ .addPropertyFilters(new TestANonSPIPropertyFilter(),
+ new TestBNonSPIPropertyFilter())
.build();
String property = config.get("key");
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/a63c28f7/src/test/java/org/apache/tamaya/builder/TestANonSPIPropertyFilter.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/tamaya/builder/TestANonSPIPropertyFilter.java b/src/test/java/org/apache/tamaya/builder/TestANonSPIPropertyFilter.java
new file mode 100644
index 0000000..e113010
--- /dev/null
+++ b/src/test/java/org/apache/tamaya/builder/TestANonSPIPropertyFilter.java
@@ -0,0 +1,34 @@
+/*
+ * 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.builder;
+
+import org.apache.tamaya.spi.PropertyFilter;
+
+public class TestANonSPIPropertyFilter implements PropertyFilter {
+ @Override
+ public String filterProperty(String key, String value) {
+ String result = value;
+
+ if (!result.contains(("ABC"))) {
+ result = value + "ABC";
+ }
+
+ return result;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/a63c28f7/src/test/java/org/apache/tamaya/builder/TestBNonSPIPropertyFilter.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/tamaya/builder/TestBNonSPIPropertyFilter.java b/src/test/java/org/apache/tamaya/builder/TestBNonSPIPropertyFilter.java
new file mode 100644
index 0000000..2ce81fc
--- /dev/null
+++ b/src/test/java/org/apache/tamaya/builder/TestBNonSPIPropertyFilter.java
@@ -0,0 +1,34 @@
+/*
+ * 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.builder;
+
+import org.apache.tamaya.spi.PropertyFilter;
+
+public class TestBNonSPIPropertyFilter implements PropertyFilter {
+ @Override
+ public String filterProperty(String key, String value) {
+ String result = value;
+
+ if (!result.contains(("XYZ"))) {
+ result = value + "XYZ";
+ }
+
+ return result;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/a63c28f7/src/test/java/org/apache/tamaya/builder/TestNonSPIPropertyFilterA.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/tamaya/builder/TestNonSPIPropertyFilterA.java b/src/test/java/org/apache/tamaya/builder/TestNonSPIPropertyFilterA.java
deleted file mode 100644
index 4b9ae72..0000000
--- a/src/test/java/org/apache/tamaya/builder/TestNonSPIPropertyFilterA.java
+++ /dev/null
@@ -1,34 +0,0 @@
-/*
- * 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.builder;
-
-import org.apache.tamaya.spi.PropertyFilter;
-
-public class TestNonSPIPropertyFilterA implements PropertyFilter {
- @Override
- public String filterProperty(String key, String value) {
- String result = value;
-
- if (!result.contains(("ABC"))) {
- result = value + "ABC";
- }
-
- return result;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/a63c28f7/src/test/java/org/apache/tamaya/builder/TestNonSPIPropertyFilterB.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/tamaya/builder/TestNonSPIPropertyFilterB.java b/src/test/java/org/apache/tamaya/builder/TestNonSPIPropertyFilterB.java
deleted file mode 100644
index 95112b0..0000000
--- a/src/test/java/org/apache/tamaya/builder/TestNonSPIPropertyFilterB.java
+++ /dev/null
@@ -1,34 +0,0 @@
-/*
- * 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.builder;
-
-import org.apache.tamaya.spi.PropertyFilter;
-
-public class TestNonSPIPropertyFilterB implements PropertyFilter {
- @Override
- public String filterProperty(String key, String value) {
- String result = value;
-
- if (!result.contains(("XYZ"))) {
- result = value + "XYZ";
- }
-
- return result;
- }
-}
[37/50] [abbrv] incubator-tamaya-sandbox git commit:
[maven-release-plugin] prepare release 0.2-incubating-rc1
Posted by pl...@apache.org.
[maven-release-plugin] prepare release 0.2-incubating-rc1
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/69c1ec2b
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/tree/69c1ec2b
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/diff/69c1ec2b
Branch: refs/heads/master
Commit: 69c1ec2b1b323653a662f642c8d15b4d262c12bf
Parents: 4d40b2e
Author: anatole <an...@apache.org>
Authored: Tue Mar 8 20:39:05 2016 +0100
Committer: anatole <an...@apache.org>
Committed: Tue Mar 8 20:39:05 2016 +0100
----------------------------------------------------------------------
pom.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/69c1ec2b/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index 96f6244..9202d80 100644
--- a/pom.xml
+++ b/pom.xml
@@ -23,7 +23,7 @@ under the License.
<parent>
<groupId>org.apache.tamaya.ext</groupId>
<artifactId>tamaya-extensions</artifactId>
- <version>0.3-incubating-SNAPSHOT</version>
+ <version>0.2-incubating</version>
</parent>
<artifactId>tamaya-builder</artifactId>
[22/50] [abbrv] incubator-tamaya-sandbox git commit: Updated snapshot
version.
Posted by pl...@apache.org.
Updated snapshot version.
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/24bb6c61
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/tree/24bb6c61
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/diff/24bb6c61
Branch: refs/heads/master
Commit: 24bb6c6135bcc6b0754e8d20d2eb0984497a0cc4
Parents: daa8f22
Author: anatole <an...@apache.org>
Authored: Fri Aug 28 18:12:04 2015 +0200
Committer: anatole <an...@apache.org>
Committed: Fri Aug 28 18:12:04 2015 +0200
----------------------------------------------------------------------
pom.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/24bb6c61/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index 54d1ba0..5912c2c 100644
--- a/pom.xml
+++ b/pom.xml
@@ -23,7 +23,7 @@ under the License.
<parent>
<groupId>org.apache.tamaya.ext</groupId>
<artifactId>tamaya-extensions</artifactId>
- <version>0.1-incubating-SNAPSHOT</version>
+ <version>0.2-incubating-SNAPSHOT</version>
</parent>
<artifactId>tamaya-builder</artifactId>
[17/50] [abbrv] incubator-tamaya-sandbox git commit: Minor pom fixes
to clean up contents and reduce duplicated content.
Posted by pl...@apache.org.
Minor pom fixes to clean up contents and reduce duplicated content.
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/3106f951
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/tree/3106f951
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/diff/3106f951
Branch: refs/heads/master
Commit: 3106f95160247b74f46eaabb0273f10717ae6868
Parents: 0c039d5
Author: John D. Ament <jo...@apache.org>
Authored: Sat Aug 1 21:32:22 2015 -0400
Committer: John D. Ament <jo...@apache.org>
Committed: Sat Aug 1 21:32:22 2015 -0400
----------------------------------------------------------------------
pom.xml | 12 ------------
1 file changed, 12 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/3106f951/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index d203b01..4cabb38 100644
--- a/pom.xml
+++ b/pom.xml
@@ -33,18 +33,6 @@ under the License.
<inceptionYear>2015</inceptionYear>
- <scm>
- <connection>
- scm:git://git.apache.org/incubator-tamaya.git
- </connection>
- <developerConnection>
- scm:git://git.apache.org/incubator-tamaya.git
- </developerConnection>
- <url>
- https://git-wip-us.apache.org/repos/asf?p=incubator-tamaya.git
- </url>
- </scm>
-
<dependencies>
<dependency>
<groupId>org.apache.tamaya</groupId>
[48/50] [abbrv] incubator-tamaya-sandbox git commit: Moved the
builder to the directory builder
Posted by pl...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/f45a5bb5/builder/src/test/java/org/apache/tamaya/builder/ConfigurationBuilderTest.java
----------------------------------------------------------------------
diff --git a/builder/src/test/java/org/apache/tamaya/builder/ConfigurationBuilderTest.java b/builder/src/test/java/org/apache/tamaya/builder/ConfigurationBuilderTest.java
new file mode 100644
index 0000000..07a72c5
--- /dev/null
+++ b/builder/src/test/java/org/apache/tamaya/builder/ConfigurationBuilderTest.java
@@ -0,0 +1,907 @@
+/*
+ * 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.builder;
+
+import org.apache.tamaya.ConfigException;
+import org.apache.tamaya.Configuration;
+import org.apache.tamaya.TypeLiteral;
+import org.apache.tamaya.builder.util.types.CustomTypeA;
+import org.apache.tamaya.builder.util.types.CustomTypeB;
+import org.apache.tamaya.builder.util.types.CustomTypeC;
+import org.apache.tamaya.spi.*;
+import org.hamcrest.CoreMatchers;
+import org.hamcrest.Matchers;
+import org.junit.Ignore;
+import org.junit.Test;
+import org.mockito.Mockito;
+
+
+import java.io.IOException;
+import java.net.URL;
+
+import static java.util.Arrays.asList;
+import static org.apache.tamaya.builder.util.mockito.NotMockedAnswer.NOT_MOCKED_ANSWER;
+import static org.hamcrest.CoreMatchers.equalTo;
+import static org.hamcrest.CoreMatchers.nullValue;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.is;
+import static org.hamcrest.Matchers.notNullValue;
+import static org.mockito.Matchers.anyString;
+import static org.mockito.Mockito.CALLS_REAL_METHODS;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.doThrow;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+
+
+public class ConfigurationBuilderTest {
+
+ @Test
+ public void buildCanBuildEmptyConfiguration() {
+ ConfigurationBuilder builder = new ConfigurationBuilder();
+
+ Configuration config = builder.build();
+
+ assertThat(config, notNullValue());
+ }
+
+ @Test(expected = IllegalStateException.class)
+ public void buildCanBeCalledOnlyOnce() {
+ ConfigurationBuilder builder = new ConfigurationBuilder();
+
+ builder.build();
+ builder.build();
+ }
+
+ /*********************************************************************
+ * Tests for adding P r o p e r t y S o u r c e s
+ */
+
+ @Test(expected = NullPointerException.class)
+ public void addPropertySourcesDoesNotAcceptNullValue() {
+ ConfigurationBuilder builder = new ConfigurationBuilder();
+
+ builder.addPropertySources((PropertySource[])null);
+ }
+
+ @Test(expected = IllegalStateException.class)
+ public void propertySourceCanNotBeAddedAfterBuildingTheConfiguration() {
+ PropertySource first = mock(PropertySource.class, NOT_MOCKED_ANSWER);
+
+ doReturn("first").when(first).getName();
+ doReturn(100).when(first).getOrdinal();
+
+ ConfigurationBuilder builder = new ConfigurationBuilder().addPropertySources(first);
+
+ builder.build();
+
+ PropertySource second = mock(PropertySource.class, NOT_MOCKED_ANSWER);
+
+ doReturn("second").when(first).getName();
+
+ builder.addPropertySources(second);
+ }
+
+ @Test
+ public void singleAddedPropertySourceIsUsed() {
+ PropertySource source = mock(PropertySource.class, NOT_MOCKED_ANSWER);
+
+ doReturn("one").when(source).getName();
+ doReturn(PropertyValue.of("keyOfA","a", "test")).when(source).get("keyOfA");
+ doReturn(100).when(source).getOrdinal();
+
+ ConfigurationBuilder builder = new ConfigurationBuilder().addPropertySources(source);
+
+ Configuration config = builder.build();
+
+ String valueOfA = config.get("keyOfA");
+
+ assertThat(valueOfA, notNullValue());
+ assertThat(valueOfA, equalTo("a"));
+ }
+
+ @Test
+ public void twoAddedPropertySourcesAreUsed() {
+ PropertySource sourceOne = mock(PropertySource.class, NOT_MOCKED_ANSWER);
+
+ doReturn("one").when(sourceOne).getName();
+ doReturn(PropertyValue.of("keyOfA","b", "test")).when(sourceOne).get("keyOfA");
+ doReturn(10).when(sourceOne).getOrdinal();
+
+ PropertySource sourceTwo = mock(PropertySource.class, NOT_MOCKED_ANSWER);
+ doReturn("two").when(sourceTwo).getName();
+ doReturn(PropertyValue.of("keyOfA","a", "test")).when(sourceTwo).get("keyOfA");
+ doReturn(10).when(sourceTwo).getOrdinal();
+
+ ConfigurationBuilder builder = new ConfigurationBuilder().addPropertySources(sourceOne)
+ .addPropertySources(sourceTwo);
+
+ Configuration config = builder.build();
+
+ String valueOfA = config.get("keyOfA");
+
+ assertThat(valueOfA, notNullValue());
+ assertThat(valueOfA, equalTo("a"));
+ }
+
+ @Ignore
+ @Test(expected = ConfigException.class)
+ public void twoPropertySourcesSamePrioritySameKey() {
+ PropertySource sourceOne = mock(PropertySource.class, NOT_MOCKED_ANSWER);
+
+ doReturn("one").when(sourceOne).getName();
+ doReturn("b").when(sourceOne).get("keyOfA");
+ doReturn(20).when(sourceOne).getOrdinal();
+
+ PropertySource sourceTwo = mock(PropertySource.class, NOT_MOCKED_ANSWER);
+ doReturn("two").when(sourceTwo).getName();
+ doReturn("a").when(sourceTwo).get("keyOfA");
+ doReturn(20).when(sourceTwo).getOrdinal();
+
+ ConfigurationBuilder builder = new ConfigurationBuilder().addPropertySources(sourceOne)
+ .addPropertySources(sourceTwo);
+
+ Configuration config = builder.build();
+
+ config.get("keyOfA");
+ }
+
+ @Test
+ public void twoPropertySourcesDiffPrioritySameKeyLowerAddedFirst() {
+ PropertySource sourceOne = mock(PropertySource.class, NOT_MOCKED_ANSWER);
+
+ doReturn("one").when(sourceOne).getName();
+ doReturn(PropertyValue.of("keyOfA","b", "test")).when(sourceOne).get("keyOfA");
+ doReturn(10).when(sourceOne).getOrdinal();
+
+ PropertySource sourceTwo = mock(PropertySource.class, NOT_MOCKED_ANSWER);
+ doReturn("two").when(sourceTwo).getName();
+ doReturn(PropertyValue.of("keyOfA","a", "test")).when(sourceTwo).get("keyOfA");
+ doReturn(20).when(sourceTwo).getOrdinal();
+
+ ConfigurationBuilder builder = new ConfigurationBuilder().addPropertySources(sourceOne)
+ .addPropertySources(sourceTwo);
+
+ Configuration config = builder.build();
+
+ String valueOfA = config.get("keyOfA");
+
+ assertThat(valueOfA, notNullValue());
+ assertThat(valueOfA, equalTo("a"));
+ }
+
+ @Test
+ public void twoPropertySourcesDiffPrioritySameKeyHigherAddedFirst() {
+ PropertySource sourceOne = mock(PropertySource.class, NOT_MOCKED_ANSWER);
+
+ doReturn("one").when(sourceOne).getName();
+ doReturn(PropertyValue.of("keyOfA","b", "test")).when(sourceOne).get("keyOfA");
+ doReturn(30).when(sourceOne).getOrdinal();
+
+ PropertySource sourceTwo = mock(PropertySource.class, NOT_MOCKED_ANSWER);
+ doReturn("two").when(sourceTwo).getName();
+ doReturn(PropertyValue.of("keyOfA","a", "test")).when(sourceTwo).get("keyOfA");
+ doReturn(20).when(sourceTwo).getOrdinal();
+
+ ConfigurationBuilder builder = new ConfigurationBuilder().addPropertySources(sourceOne, sourceTwo);
+
+ Configuration config = builder.build();
+
+ String valueOfA = config.get("keyOfA");
+
+ assertThat(valueOfA, notNullValue());
+ assertThat(valueOfA, equalTo("b"));
+ }
+
+ @Test
+ public void consecutiveCallsToAddPropertySourceArePossible() {
+ PropertySource sourceOne = mock(PropertySource.class, NOT_MOCKED_ANSWER);
+
+ doReturn("one").when(sourceOne).getName();
+ doReturn(null).when(sourceOne).get(anyString());
+ doReturn(PropertyValue.of("b","b", "test")).when(sourceOne).get("b");
+ doReturn(30).when(sourceOne).getOrdinal();
+
+ PropertySource sourceTwo = mock(PropertySource.class, NOT_MOCKED_ANSWER);
+ doReturn("two").when(sourceTwo).getName();
+ doReturn(null).when(sourceTwo).get(anyString());
+ doReturn(PropertyValue.of("a","a", "test")).when(sourceTwo).get("a");
+ doReturn(30).when(sourceTwo).getOrdinal();
+
+ ConfigurationBuilder builder = new ConfigurationBuilder().addPropertySources(sourceOne)
+ .addPropertySources(sourceTwo);
+
+ Configuration config = builder.build();
+
+ assertThat(config.get("b"), equalTo("b"));
+ assertThat(config.get("a"), equalTo("a"));
+ }
+
+ @Test
+ public void addMultiplePropertySourcesWhereOneIsNull() {
+ PropertySource sourceOne = mock(PropertySource.class, NOT_MOCKED_ANSWER);
+
+ doReturn("one").when(sourceOne).getName();
+ doReturn(null).when(sourceOne).get(anyString());
+ doReturn(PropertyValue.of("b","b", "test")).when(sourceOne).get("b");
+ doReturn(30).when(sourceOne).getOrdinal();
+
+ PropertySource sourceTwo = mock(PropertySource.class, NOT_MOCKED_ANSWER);
+ doReturn("two").when(sourceTwo).getName();
+ doReturn(null).when(sourceTwo).get(anyString());
+ doReturn(PropertyValue.of("a","a", "test")).when(sourceTwo).get("a");
+ doReturn(30).when(sourceTwo).getOrdinal();
+
+ ConfigurationBuilder builder = new ConfigurationBuilder().addPropertySources(sourceOne, null, sourceTwo);
+
+ Configuration config = builder.build();
+
+ assertThat(config.get("b"), equalTo("b"));
+ assertThat(config.get("a"), equalTo("a"));
+ }
+
+ /**
+ * ******************************************************************
+ * Tests for adding P r o p e r t y C o n v e r t e r
+ */
+
+ @Test(expected = NullPointerException.class)
+ public void canNotAddNullPropertyConverter() {
+ ConfigurationBuilder builder = new ConfigurationBuilder();
+
+ builder.addPropertyConverter(TypeLiteral.of(CustomTypeA.class), null);
+ }
+
+ @Test(expected = NullPointerException.class)
+ public void canNotAddNullTypeLiteralButPropertyConverter() {
+ ConfigurationBuilder builder = new ConfigurationBuilder();
+ builder.addPropertyConverter((TypeLiteral)null,
+ new PropertyConverter() {
+ @Override
+ public CustomTypeA convert(final String prop, ConversionContext context) {
+ return new CustomTypeA(prop, prop);
+ }
+ });
+ }
+
+ @Test
+ public void addedPropertyConverterWithTypeLiteralIsUsedByConfiguration() {
+ PropertySource source = mock(PropertySource.class, NOT_MOCKED_ANSWER);
+
+ doReturn("source").when(source).getName();
+ doReturn(PropertyValue.of("key","A", "test")).when(source).get("key");
+ doReturn(100).when(source).getOrdinal();
+
+ ConfigurationBuilder builder = new ConfigurationBuilder();
+
+ builder.addPropertyConverter(TypeLiteral.of(CustomTypeA.class),
+ new PropertyConverter() {
+ @Override
+ public CustomTypeA convert(final String prop, ConversionContext context) {
+ return new CustomTypeA(prop, prop);
+ }
+ });
+ builder.addPropertySources(source);
+
+ Configuration config = builder.build();
+
+ Object resultRaw = config.get("key", CustomTypeA.class);
+
+ assertThat(resultRaw, CoreMatchers.notNullValue());
+
+ CustomTypeA result = (CustomTypeA)resultRaw;
+
+ assertThat(result.getName(), equalTo("AA"));
+ }
+
+ @Test
+ public void addedPropertyConverterWithClassIsUsedByConfiguration() {
+ PropertySource source = mock(PropertySource.class, NOT_MOCKED_ANSWER);
+
+ doReturn("source").when(source).getName();
+ doReturn(PropertyValue.of("key","A", "test")).when(source).get("key");
+ doReturn(100).when(source).getOrdinal();
+
+ ConfigurationBuilder builder = new ConfigurationBuilder();
+
+ builder.addPropertyConverter(TypeLiteral.of(CustomTypeA.class),
+ new PropertyConverter() {
+ @Override
+ public CustomTypeA convert(final String prop, ConversionContext context) {
+ return new CustomTypeA(prop, prop);
+ }
+ });
+ builder.addPropertySources(source);
+
+ Configuration config = builder.build();
+
+ Object resultRaw = config.get("key", CustomTypeA.class);
+
+ assertThat(resultRaw, CoreMatchers.notNullValue());
+
+ CustomTypeA result = (CustomTypeA)resultRaw;
+
+ assertThat(result.getName(), equalTo("AA"));
+ }
+
+ @Test
+ public void canGetAndConvertPropertyViaOfMethod() {
+ PropertySource source = mock(PropertySource.class, NOT_MOCKED_ANSWER);
+
+ doReturn("source").when(source).getName();
+ doReturn(PropertyValue.of("key","A", "test")).when(source).get("key");
+ doReturn(100).when(source).getOrdinal();
+
+ ConfigurationBuilder builder = new ConfigurationBuilder();
+
+ builder.addPropertySources(source);
+
+ Configuration config = builder.build();
+
+ Object resultRaw = config.get("key", CustomTypeB.class);
+
+ assertThat(resultRaw, CoreMatchers.notNullValue());
+
+ CustomTypeB result = (CustomTypeB)resultRaw;
+
+ assertThat(result.getName(), equalTo("A"));
+ }
+
+ /*********************************************************************
+ * Tests for adding P r o p e r t y F i l t e r
+ */
+
+ @Test(expected = NullPointerException.class)
+ public void canNotAddNullAsPropertyFilter() {
+ ConfigurationBuilder builder = new ConfigurationBuilder();
+ builder.addPropertyFilters((PropertyFilter[])null);
+ }
+
+ @Test
+ public void canAddNonSPIPropertyFilter() {
+ PropertySource source = mock(PropertySource.class, NOT_MOCKED_ANSWER);
+
+ doReturn(PropertyValue.of("key","M", "test")).when(source).get("key");
+ doReturn("source").when(source).getName();
+
+ ConfigurationBuilder builder = new ConfigurationBuilder();
+
+ Configuration config = builder.addPropertySources(source)
+ .addPropertyFilters(new TestANonSPIPropertyFilter())
+ .build();
+
+ String property = config.get("key");
+
+ assertThat(property, CoreMatchers.notNullValue());
+ assertThat(property, CoreMatchers.containsString("ABC"));
+ }
+
+ @Test
+ public void canAddNonSPIPropertyFiltersViaConsecutiveCalls() {
+ PropertySource source = mock(PropertySource.class, NOT_MOCKED_ANSWER);
+
+ doReturn(PropertyValue.of("key","M", "test")).when(source).get("key");
+ doReturn("source").when(source).getName();
+
+ ConfigurationBuilder builder = new ConfigurationBuilder();
+
+ Configuration config = builder.addPropertySources(source)
+ .addPropertyFilters(new TestANonSPIPropertyFilter())
+ .addPropertyFilters(new TestBNonSPIPropertyFilter())
+ .build();
+
+ String property = config.get("key");
+
+ assertThat(property, CoreMatchers.notNullValue());
+ assertThat(property, CoreMatchers.containsString("ABC"));
+ assertThat(property, CoreMatchers.containsString("XYZ"));
+ }
+
+ @Test
+ public void canAddMultipleNonSPIPropertyFiltersWhileOneIsNull() {
+ PropertySource source = mock(PropertySource.class, NOT_MOCKED_ANSWER);
+
+ doReturn(PropertyValue.of("key","M", "test")).when(source).get("key");
+ doReturn("source").when(source).getName();
+
+ ConfigurationBuilder builder = new ConfigurationBuilder();
+
+ Configuration config = builder.addPropertySources(source)
+ .addPropertyFilters(new TestANonSPIPropertyFilter(),
+ null,
+ new TestBNonSPIPropertyFilter())
+ .build();
+
+ String property = config.get("key");
+
+ assertThat(property, CoreMatchers.notNullValue());
+ assertThat(property, CoreMatchers.containsString("ABC"));
+ assertThat(property, CoreMatchers.containsString("XYZ"));
+ }
+
+ @Test
+ public void overhandedNullPropertyFilterIsSafelyHandled() {
+ PropertySource source = mock(PropertySource.class, NOT_MOCKED_ANSWER);
+
+ doReturn(PropertyValue.of("key","M", "test")).when(source).get("key");
+ doReturn("source").when(source).getName();
+
+ ConfigurationBuilder builder = new ConfigurationBuilder();
+
+ Configuration config = builder.addPropertySources(source)
+ .addPropertyFilters((PropertyFilter)null) // The cast is needed!
+ .addPropertyFilters(new TestBNonSPIPropertyFilter())
+ .build();
+
+ String property = config.get("key");
+
+ assertThat(property, CoreMatchers.notNullValue());
+ assertThat(property, CoreMatchers.containsString("XYZ"));
+ }
+
+ @Test
+ public void canAddMultipleNonSPIPropertyFilter() {
+ PropertySource source = mock(PropertySource.class, NOT_MOCKED_ANSWER);
+
+ doReturn(PropertyValue.of("key","M", "test")).when(source).get("key");
+ doReturn("source").when(source).getName();
+
+ ConfigurationBuilder builder = new ConfigurationBuilder();
+
+ Configuration config = builder.addPropertySources(source)
+ .addPropertyFilters(new TestANonSPIPropertyFilter(),
+ new TestBNonSPIPropertyFilter())
+ .build();
+
+ String property = config.get("key");
+
+ assertThat(property, CoreMatchers.notNullValue());
+ assertThat(property, CoreMatchers.containsString("ABC"));
+ assertThat(property, CoreMatchers.containsString("XYZ"));
+ }
+
+ /*********************************************************************
+ * Tests for adding
+ * P r o p e r t y S o u r c e P r o v i d e r s
+ */
+
+ @Test
+ public void handlesSafelyPropertyProviderReturningNullInsteadOfPropertySource() {
+ PropertySourceProvider nullReturning = mock(PropertySourceProvider.class, NOT_MOCKED_ANSWER);
+
+ doReturn(asList((PropertySource)null)).when(nullReturning).getPropertySources();
+
+ ConfigurationBuilder builder = new ConfigurationBuilder();
+
+ Configuration config = builder.addPropertySourceProviders(new TestPropertySourceProviderB(),
+ nullReturning,
+ new TestPropertySourceProvider())
+ .build();
+
+ assertThat(config.get("tpsp_a"), Matchers.equalTo("A"));
+ assertThat(config.get("tpsp_b"), Matchers.equalTo("B"));
+ assertThat(config.get("tpsp_x"), Matchers.equalTo("X"));
+ assertThat(config.get("tpsp_y"), Matchers.equalTo("Y"));
+
+ verify(nullReturning).getPropertySources();
+ }
+
+ @Test(expected = NullPointerException.class)
+ public void cannotAddNullAsPropertyProvider() {
+ new ConfigurationBuilder().addPropertySourceProviders((PropertySourceProvider[])null);
+ }
+
+ @Test
+ public void canAddMultipleNonSPIPropertySourceProviders() {
+ ConfigurationBuilder builder = new ConfigurationBuilder();
+
+ Configuration config = builder.addPropertySourceProviders(new TestPropertySourceProviderB(),
+ new TestPropertySourceProvider())
+ .build();
+
+ assertThat(config.get("tpsp_a"), Matchers.equalTo("A"));
+ assertThat(config.get("tpsp_b"), Matchers.equalTo("B"));
+ assertThat(config.get("tpsp_x"), Matchers.equalTo("X"));
+ assertThat(config.get("tpsp_y"), Matchers.equalTo("Y"));
+ }
+
+ @Test
+ public void canAddMultipleNonSPIPropertySourceProvidersWhileOfOfThemIsNull() {
+ ConfigurationBuilder builder = new ConfigurationBuilder();
+
+ Configuration config = builder.addPropertySourceProviders(new TestPropertySourceProviderB(), null,
+ new TestPropertySourceProvider())
+ .build();
+
+ assertThat(config.get("tpsp_a"), Matchers.equalTo("A"));
+ assertThat(config.get("tpsp_b"), Matchers.equalTo("B"));
+ assertThat(config.get("tpsp_x"), Matchers.equalTo("X"));
+ assertThat(config.get("tpsp_y"), Matchers.equalTo("Y"));
+ }
+
+
+ /*
+ * Tests for adding
+ * P r o p e r t y V a l u e C o m b i n a t i o n P o l i c y
+ */
+
+ // @todo TAYAMA-60 Write more tests
+
+ /*********************************************************************
+ * Tests for enabling and disabling of automatic loading of
+ * P r o p e r t y S o u r c e s
+ */
+
+ @Test
+ public void enablingOfProvidedPropertySourceServiceProvidersIsOk() {
+ ConfigurationBuilder builder = new ConfigurationBuilder();
+
+ builder.disableProvidedPropertyConverters()
+ .enableProvidedPropertyConverters();
+
+ assertThat(builder.isPropertyConverterLoadingEnabled(), is(true));
+ }
+
+ @Test
+ public void disablingOfProvidedPropertySourceServiceProvidersIsOk() {
+ ConfigurationBuilder builder = new ConfigurationBuilder();
+
+ builder.enableProvidedPropertyConverters()
+ .disableProvidedPropertyConverters();
+
+ assertThat(builder.isPropertyConverterLoadingEnabled(), is(false));
+ }
+
+ @Test(expected = ConfigException.class)
+ public void loadingOrPropertyConvertersCanBeDisabled() {
+ PropertySource source = mock(PropertySource.class, NOT_MOCKED_ANSWER);
+
+ doReturn("source").when(source).getName();
+ doReturn(PropertyValue.of("key","A", "test")).when(source).get("key");
+ doReturn(100).when(source).getOrdinal();
+
+ ConfigurationBuilder builder = new ConfigurationBuilder().addPropertySources(source)
+ .enableProvidedPropertyConverters()
+ .disableProvidedPropertyConverters();
+
+ Configuration config = builder.build();
+
+ config.get("key", CustomTypeC.class);
+ }
+
+ @Test
+ public void loadingOfPropertyConvertersCanBeEnabled() {
+ PropertySource source = mock(PropertySource.class, NOT_MOCKED_ANSWER);
+
+ doReturn("source").when(source).getName();
+ doReturn(PropertyValue.of("key","A", "test")).when(source).get("key");
+ doReturn(100).when(source).getOrdinal();
+
+ ConfigurationBuilder builder = new ConfigurationBuilder().addPropertySources(source)
+ .disableProvidedPropertyConverters()
+ .enableProvidedPropertyConverters();
+
+ Configuration config = builder.build();
+
+ CustomTypeC result = config.get("key", CustomTypeC.class);
+
+ assertThat(result, notNullValue());
+ assertThat(result.getValue(), equalTo("A"));
+ }
+
+ /*********************************************************************
+ * Tests for enabling and disabling of automatic loading of
+ * P r o p e r t y S o u r c e s
+ */
+
+ @Test
+ public void enablingOfPropertySourceLoadingIsOk() {
+ ConfigurationBuilder builder = new ConfigurationBuilder();
+
+ builder.disableProvidedPropertySources()
+ .enableProvidedPropertySources();
+
+ assertThat(builder.isPropertySourcesLoadingEnabled(), is(true));
+ }
+
+ @Test
+ public void disablingPropertySourceLoadingIsOk() {
+ ConfigurationBuilder builder = new ConfigurationBuilder();
+
+ builder.enableProvidedPropertySources()
+ .disableProvidedPropertySources();
+
+ assertThat(builder.isPropertySourcesLoadingEnabled(), is(false));
+ }
+
+ @Test
+ public void loadingOfPropertySourcesCanBeEnabled() {
+ ConfigurationBuilder builder = new ConfigurationBuilder();
+
+ Configuration config = builder.disableProvidedPropertySources()
+ .enableProvidedPropertySources()
+ .build();
+
+
+ assertThat(builder.isPropertySourcesLoadingEnabled(), is(true));
+ assertThat(config.get("tps_a"), Matchers.equalTo("A"));
+ }
+
+ @Test
+ public void loadingOfPropertySourcesCanBeDisabled() {
+ ConfigurationBuilder builder = new ConfigurationBuilder();
+
+ Configuration config = builder.enableProvidedPropertySources()
+ .disableProvidedPropertySources()
+ .build();
+
+
+ assertThat(builder.isPropertySourcesLoadingEnabled(), is(false));
+ assertThat(config.get("tps_c"), Matchers.nullValue());
+ }
+
+ /*********************************************************************
+ * Tests for enabling and disabling of automatic loading of
+ * P r o p e r t y F i l t e r s
+ */
+
+ @Test
+ public void enablingOfPropertyFiltersLoadingIsOk() {
+ PropertySource source = mock(PropertySource.class, NOT_MOCKED_ANSWER);
+
+ doReturn("source").when(source).getName();
+ doReturn(PropertyValue.of("key","A", "test")).when(source).get("key");
+ doReturn(100).when(source).getOrdinal();
+
+ ConfigurationBuilder builder = new ConfigurationBuilder();
+
+ Configuration config = builder.disableProvidedPropertyFilters()
+ .enabledProvidedPropertyFilters()
+ .addPropertySources(source)
+ .build();
+
+ String property = config.get("key");
+
+ assertThat(property, CoreMatchers.notNullValue());
+ assertThat(property, Matchers.equalTo("AinBerlin"));
+ }
+
+ @Test
+ public void disablingOfPropertyFiltersLoadingIsOk() {
+ ConfigurationBuilder builder = new ConfigurationBuilder();
+
+ builder.enabledProvidedPropertyFilters()
+ .disableProvidedPropertyFilters();
+
+ assertThat(builder.isPropertyFilterLoadingEnabled(), is(false));
+ }
+
+ @Test
+ public void loadingOfPropertyFiltersCanBeDisabled() {
+ ConfigurationBuilder builder = new ConfigurationBuilder();
+
+ builder.disableProvidedPropertyFilters()
+ .enabledProvidedPropertyFilters();
+
+ assertThat(builder.isPropertyFilterLoadingEnabled(), is(true));
+ }
+
+ @Test
+ public void loadingOfPropertyFiltersCanBeEnabled() {
+ PropertySource source = mock(PropertySource.class, NOT_MOCKED_ANSWER);
+
+ doReturn("source").when(source).getName();
+ doReturn(PropertyValue.of("key","A", "test")).when(source).get("key");
+ doReturn(100).when(source).getOrdinal();
+
+ ConfigurationBuilder builder = new ConfigurationBuilder();
+
+ Configuration config = builder.enabledProvidedPropertyFilters()
+ .disableProvidedPropertyFilters()
+ .addPropertySources(source)
+ .build();
+
+ String property = config.get("key");
+
+ assertThat(property, CoreMatchers.notNullValue());
+ assertThat(property, Matchers.equalTo("A"));
+ }
+
+ /*********************************************************************
+ * Tests for enabling and disabling of automatic loading of
+ * P r o p e r t y S o u r c e P r o v i d e r s
+ */
+
+ @Test
+ public void disablingOfPropertySourceProvidersIsOk() {
+ ConfigurationBuilder builder = new ConfigurationBuilder();
+
+ builder.enableProvidedPropertySourceProviders()
+ .disableProvidedPropertySourceProviders()
+ .build();
+
+ assertThat(builder.isPropertySourceProvidersLoadingEnabled(), is(false));
+ }
+
+ @Test
+ public void enablingOfPropertySourceProvidersIsOk() {
+
+ ConfigurationBuilder builder = new ConfigurationBuilder();
+
+ builder.disableProvidedPropertySourceProviders()
+ .enableProvidedPropertySourceProviders()
+ .build();
+
+ assertThat(builder.isPropertySourceProvidersLoadingEnabled(), is(true));
+ }
+
+ @Test
+ public void loadingOfPropertySourceProvidersCanBeEnabled() {
+ ConfigurationBuilder builder = new ConfigurationBuilder();
+
+ Configuration config = builder.disableProvidedPropertySourceProviders()
+ .enableProvidedPropertySourceProviders()
+ .build();
+
+ assertThat(builder.isPropertySourceProvidersLoadingEnabled(), is(true));
+ assertThat(config.get("tpsp_x"), Matchers.equalTo("X"));
+ assertThat(config.get("tpsp_y"), Matchers.equalTo("Y"));
+ }
+
+ @Test
+ public void loadingOfPropertySourceProvidersCanBeDisabled() {
+ ConfigurationBuilder builder = new ConfigurationBuilder();
+
+ Configuration config = builder.enableProvidedPropertySourceProviders()
+ .disableProvidedPropertySourceProviders()
+ .build();
+
+ assertThat(builder.isPropertySourceProvidersLoadingEnabled(), is(false));
+ assertThat(config.get("tpsp_x"), nullValue());
+ assertThat(config.get("tpsp_x"), nullValue());
+ }
+
+ @Test(expected = ConfigException.class)
+ public void ioExceptionIsTurnedInConfigExceptionWhenLoadingResourceViaURL() throws Exception {
+ URL resource = this.getClass().getResource("/configfiles/json/simple.json");
+
+ assertThat(resource, CoreMatchers.notNullValue());
+
+ ConfigurationBuilder builder = mock(ConfigurationBuilder.class, CALLS_REAL_METHODS);
+
+ doThrow(IOException.class).when(builder).getConfigurationDataFromURL(Mockito.eq(resource));
+
+ builder.addPropertySource(resource).build();
+ }
+
+ /*********************************************************************
+ * Tests for loading resources via URL (as String)
+ */
+
+ @Test(expected = ConfigException.class)
+ public void tryToLoadOneUnsupportedPropertySourceViaStringURL() {
+ URL resource = this.getClass().getResource("/configfiles/other/simple.oml");
+
+ assertThat(resource, CoreMatchers.notNullValue());
+
+ ConfigurationBuilder builder = new ConfigurationBuilder();
+
+ builder.addPropertySources(resource.toString()).build();
+ }
+
+ @Test
+ public void loadOneJSONPropertySourceViaStringURL() {
+ URL resource = this.getClass().getResource("/configfiles/json/simple.json");
+
+ assertThat(resource, CoreMatchers.notNullValue());
+
+ ConfigurationBuilder builder = new ConfigurationBuilder();
+
+ Configuration config = builder.addPropertySources(resource.toString())
+ .build();
+
+ assertThat(config, CoreMatchers.notNullValue());
+ assertThat(config.get("a"), equalTo("A"));
+ assertThat(config.get("b"), equalTo("B"));
+ }
+
+ @Test
+ public void loadMultipleJSONPropertySourceViaStringURL() {
+ URL first = this.getClass().getResource("/configfiles/json/first.json");
+ URL second = this.getClass().getResource("/configfiles/json/second.json");
+ URL third = this.getClass().getResource("/configfiles/json/third.json");
+
+ assertThat(first, CoreMatchers.notNullValue());
+ assertThat(second, CoreMatchers.notNullValue());
+ assertThat(third, CoreMatchers.notNullValue());
+
+ ConfigurationBuilder builder = new ConfigurationBuilder();
+
+ Configuration config = builder.addPropertySources(first.toString(), second.toString(),
+ null, third.toString())
+ .build();
+
+ assertThat(config, CoreMatchers.notNullValue());
+
+ // from first.json
+ assertThat(config.get("d"), equalTo("D"));
+ assertThat(config.get("e"), equalTo("E"));
+
+ // from second.json
+ assertThat(config.get("m"), equalTo("M"));
+ assertThat(config.get("n"), equalTo("N"));
+
+ // from thrid.json
+ assertThat(config.get("p"), equalTo("P"));
+ assertThat(config.get("q"), equalTo("Q"));
+ }
+
+ /**
+ * ******************************************************************
+ * Tests for loading resources via URL (as URL object)
+ */
+
+ @Test
+ public void loadOneJSONPropertySourceViaURL() {
+ URL resource = this.getClass().getResource("/configfiles/json/simple.json");
+
+ assertThat(resource, CoreMatchers.notNullValue());
+
+ ConfigurationBuilder builder = new ConfigurationBuilder();
+
+ Configuration config = builder.addPropertySource(resource)
+ .build();
+
+ assertThat(config, CoreMatchers.notNullValue());
+ assertThat(config.get("a"), equalTo("A"));
+ assertThat(config.get("b"), equalTo("B"));
+ }
+
+ @Test
+ public void loadMultipleJSONPropertySourceViaURL() {
+ URL first = this.getClass().getResource("/configfiles/json/first.json");
+ URL second = this.getClass().getResource("/configfiles/json/second.json");
+ URL third = this.getClass().getResource("/configfiles/json/third.json");
+
+ assertThat(first, CoreMatchers.notNullValue());
+ assertThat(second, CoreMatchers.notNullValue());
+ assertThat(third, CoreMatchers.notNullValue());
+
+ ConfigurationBuilder builder = new ConfigurationBuilder();
+
+ Configuration config = builder.addPropertySources(first, second,
+ null, third)
+ .build();
+
+ assertThat(config, CoreMatchers.notNullValue());
+
+ // from first.json
+ assertThat(config.get("d"), equalTo("D"));
+ assertThat(config.get("e"), equalTo("E"));
+
+ // from second.json
+ assertThat(config.get("m"), equalTo("M"));
+ assertThat(config.get("n"), equalTo("N"));
+
+ // from thrid.json
+ assertThat(config.get("p"), equalTo("P"));
+ assertThat(config.get("q"), equalTo("Q"));
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/f45a5bb5/builder/src/test/java/org/apache/tamaya/builder/TestANonSPIPropertyFilter.java
----------------------------------------------------------------------
diff --git a/builder/src/test/java/org/apache/tamaya/builder/TestANonSPIPropertyFilter.java b/builder/src/test/java/org/apache/tamaya/builder/TestANonSPIPropertyFilter.java
new file mode 100644
index 0000000..896e0bc
--- /dev/null
+++ b/builder/src/test/java/org/apache/tamaya/builder/TestANonSPIPropertyFilter.java
@@ -0,0 +1,35 @@
+/*
+ * 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.builder;
+
+import org.apache.tamaya.spi.FilterContext;
+import org.apache.tamaya.spi.PropertyFilter;
+
+public class TestANonSPIPropertyFilter implements PropertyFilter {
+ @Override
+ public String filterProperty(String value, FilterContext context) {
+ String result = value;
+
+ if (!result.contains(("ABC"))) {
+ result = value + "ABC";
+ }
+
+ return result;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/f45a5bb5/builder/src/test/java/org/apache/tamaya/builder/TestBNonSPIPropertyFilter.java
----------------------------------------------------------------------
diff --git a/builder/src/test/java/org/apache/tamaya/builder/TestBNonSPIPropertyFilter.java b/builder/src/test/java/org/apache/tamaya/builder/TestBNonSPIPropertyFilter.java
new file mode 100644
index 0000000..a9c0ac2
--- /dev/null
+++ b/builder/src/test/java/org/apache/tamaya/builder/TestBNonSPIPropertyFilter.java
@@ -0,0 +1,35 @@
+/*
+ * 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.builder;
+
+import org.apache.tamaya.spi.FilterContext;
+import org.apache.tamaya.spi.PropertyFilter;
+
+public class TestBNonSPIPropertyFilter implements PropertyFilter {
+ @Override
+ public String filterProperty(String value, FilterContext context) {
+ String result = value;
+
+ if (!result.contains(("XYZ"))) {
+ result = value + "XYZ";
+ }
+
+ return result;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/f45a5bb5/builder/src/test/java/org/apache/tamaya/builder/TestPropertyFilter.java
----------------------------------------------------------------------
diff --git a/builder/src/test/java/org/apache/tamaya/builder/TestPropertyFilter.java b/builder/src/test/java/org/apache/tamaya/builder/TestPropertyFilter.java
new file mode 100644
index 0000000..e22fca8
--- /dev/null
+++ b/builder/src/test/java/org/apache/tamaya/builder/TestPropertyFilter.java
@@ -0,0 +1,35 @@
+/*
+ * 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.builder;
+
+import org.apache.tamaya.spi.FilterContext;
+import org.apache.tamaya.spi.PropertyFilter;
+
+public class TestPropertyFilter implements PropertyFilter {
+ @Override
+ public String filterProperty(String value, FilterContext context) {
+ String result = value;
+
+ if (!result.contains(("inBerlin"))) {
+ result = value + "inBerlin";
+ }
+
+ return result;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/f45a5bb5/builder/src/test/java/org/apache/tamaya/builder/TestPropertySource.java
----------------------------------------------------------------------
diff --git a/builder/src/test/java/org/apache/tamaya/builder/TestPropertySource.java b/builder/src/test/java/org/apache/tamaya/builder/TestPropertySource.java
new file mode 100644
index 0000000..f1ebfea
--- /dev/null
+++ b/builder/src/test/java/org/apache/tamaya/builder/TestPropertySource.java
@@ -0,0 +1,59 @@
+/*
+ * 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.builder;
+
+import org.apache.tamaya.core.propertysource.BasePropertySource;
+import org.apache.tamaya.spi.PropertySource;
+import org.apache.tamaya.spi.PropertyValue;
+
+import java.util.Collections;
+import java.util.Hashtable;
+import java.util.Map;
+
+public class TestPropertySource extends BasePropertySource
+{
+ private Map<String, String> properties;
+
+ {
+ properties = new Hashtable<>(3);
+ properties.put("tps_a", "A");
+ properties.put("tps_b", "B");
+ properties.put("tps_c", "C");
+ }
+
+ @Override
+ public int getOrdinal() {
+ return 456;
+ }
+
+ @Override
+ public String getName() {
+ return "TestPropertySource";
+ }
+
+ @Override
+ public PropertyValue get(String key) {
+ return PropertyValue.of(key, getProperties().get(key), getName());
+ }
+
+ @Override
+ public Map<String, String> getProperties() {
+ return Collections.unmodifiableMap(properties);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/f45a5bb5/builder/src/test/java/org/apache/tamaya/builder/TestPropertySourceProvider.java
----------------------------------------------------------------------
diff --git a/builder/src/test/java/org/apache/tamaya/builder/TestPropertySourceProvider.java b/builder/src/test/java/org/apache/tamaya/builder/TestPropertySourceProvider.java
new file mode 100644
index 0000000..5a2f400
--- /dev/null
+++ b/builder/src/test/java/org/apache/tamaya/builder/TestPropertySourceProvider.java
@@ -0,0 +1,91 @@
+/*
+ * 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.builder;
+
+import org.apache.tamaya.core.propertysource.BasePropertySource;
+import org.apache.tamaya.spi.PropertySource;
+import org.apache.tamaya.spi.PropertySourceProvider;
+import org.apache.tamaya.spi.PropertyValue;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Map;
+
+public class TestPropertySourceProvider
+ implements PropertySourceProvider
+{
+ @Override
+ public Collection<PropertySource> getPropertySources() {
+ ArrayList<PropertySource> sources = new ArrayList<>(2);
+
+ sources.add(new XProvidingPropertySource());
+ sources.add(new YProvidingPropertySource());
+
+ return sources;
+ }
+
+ private class YProvidingPropertySource extends BasePropertySource {
+ private Map<String, String> props = Collections.singletonMap("tpsp_x", "X");
+
+ @Override
+ public int getOrdinal() {
+ return 100;
+ }
+
+ @Override
+ public String getName() {
+ return "YProvidingPropertySource";
+ }
+
+ @Override
+ public PropertyValue get(String key) {
+ return PropertyValue.of(key, getProperties().get(key), getName());
+ }
+
+ @Override
+ public Map<String, String> getProperties() {
+ return props;
+ }
+ }
+
+ private class XProvidingPropertySource extends BasePropertySource {
+ private Map<String, String> props = Collections.singletonMap("tpsp_y", "Y");
+
+ @Override
+ public Map<String, String> getProperties() {
+ return props;
+ }
+
+ @Override
+ public PropertyValue get(String key) {
+ return PropertyValue.of(key, getProperties().get(key), getName());
+ }
+
+ @Override
+ public int getOrdinal() {
+ return 100;
+ }
+
+ @Override
+ public String getName() {
+ return "XProvidingPropertySource";
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/f45a5bb5/builder/src/test/java/org/apache/tamaya/builder/TestPropertySourceProviderB.java
----------------------------------------------------------------------
diff --git a/builder/src/test/java/org/apache/tamaya/builder/TestPropertySourceProviderB.java b/builder/src/test/java/org/apache/tamaya/builder/TestPropertySourceProviderB.java
new file mode 100644
index 0000000..9cfe725
--- /dev/null
+++ b/builder/src/test/java/org/apache/tamaya/builder/TestPropertySourceProviderB.java
@@ -0,0 +1,91 @@
+/*
+ * 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.builder;
+
+import org.apache.tamaya.core.propertysource.BasePropertySource;
+import org.apache.tamaya.spi.PropertySource;
+import org.apache.tamaya.spi.PropertySourceProvider;
+import org.apache.tamaya.spi.PropertyValue;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Map;
+
+public class TestPropertySourceProviderB
+ implements PropertySourceProvider
+{
+ @Override
+ public Collection<PropertySource> getPropertySources() {
+ ArrayList<PropertySource> sources = new ArrayList<>(2);
+
+ sources.add(new AProvidingPropertySource());
+ sources.add(new BProvidingPropertySource());
+
+ return sources;
+ }
+
+ private class BProvidingPropertySource extends BasePropertySource {
+ private Map<String, String> props = Collections.singletonMap("tpsp_b", "B");
+
+ @Override
+ public int getOrdinal() {
+ return 100;
+ }
+
+ @Override
+ public String getName() {
+ return "BProvidingPropertySource";
+ }
+
+ @Override
+ public PropertyValue get(String key) {
+ return PropertyValue.of(key,getProperties().get(key), getName());
+ }
+
+ @Override
+ public Map<String, String> getProperties() {
+ return props;
+ }
+ }
+
+ private class AProvidingPropertySource extends BasePropertySource {
+ private Map<String, String> props = Collections.singletonMap("tpsp_a", "A");
+
+ @Override
+ public Map<String, String> getProperties() {
+ return props;
+ }
+
+ @Override
+ public PropertyValue get(String key) {
+ return PropertyValue.of(key, getProperties().get(key), getName());
+ }
+
+ @Override
+ public int getOrdinal() {
+ return 100;
+ }
+
+ @Override
+ public String getName() {
+ return "AProvidingPropertySource";
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/f45a5bb5/builder/src/test/java/org/apache/tamaya/builder/util/mockito/NotMockedAnswer.java
----------------------------------------------------------------------
diff --git a/builder/src/test/java/org/apache/tamaya/builder/util/mockito/NotMockedAnswer.java b/builder/src/test/java/org/apache/tamaya/builder/util/mockito/NotMockedAnswer.java
new file mode 100644
index 0000000..3188d85
--- /dev/null
+++ b/builder/src/test/java/org/apache/tamaya/builder/util/mockito/NotMockedAnswer.java
@@ -0,0 +1,57 @@
+/*
+ * 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.builder.util.mockito;
+
+import org.mockito.exceptions.base.MockitoException;
+import org.mockito.invocation.InvocationOnMock;
+import org.mockito.stubbing.Answer;
+
+import java.io.Serializable;
+
+// @todo This is a duplicated class
+public class NotMockedAnswer implements Answer<Object>, Serializable {
+ public final static NotMockedAnswer NOT_MOCKED_ANSWER = new NotMockedAnswer();
+
+ private NotMockedAnswer() {
+ }
+
+ @Override
+ public Object answer(InvocationOnMock invocation) throws Throwable {
+ if("toString".equals(invocation.getMethod().getName())){
+ return "Some "+invocation.getMethod().getDeclaringClass().getName();
+ }
+ StringBuilder msgBuilder = new StringBuilder();
+
+ msgBuilder.append("Invocation of method not mocked: ")
+ .append(invocation.getMethod().toGenericString());
+
+ if (invocation.getArguments().length > 0) {
+ msgBuilder.append(" Supplied arguments: ");
+
+ for (int i = 0; i < invocation.getArguments().length; i++) {
+ msgBuilder.append(invocation.getArguments()[i]);
+
+ if (i - 1 < invocation.getArguments().length) {
+ msgBuilder.append(", ");
+ }
+ }
+ }
+ throw new MockitoException(msgBuilder.toString());
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/f45a5bb5/builder/src/test/java/org/apache/tamaya/builder/util/types/CustomTypeA.java
----------------------------------------------------------------------
diff --git a/builder/src/test/java/org/apache/tamaya/builder/util/types/CustomTypeA.java b/builder/src/test/java/org/apache/tamaya/builder/util/types/CustomTypeA.java
new file mode 100644
index 0000000..89b2f5b
--- /dev/null
+++ b/builder/src/test/java/org/apache/tamaya/builder/util/types/CustomTypeA.java
@@ -0,0 +1,34 @@
+/*
+ * 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.builder.util.types;
+
+/**
+ * Custom type with two argument constructor.
+ */
+public class CustomTypeA {
+ private String name;
+
+ public CustomTypeA(String name, String other) {
+ this.name = name + other;
+ }
+
+ public String getName() {
+ return name;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/f45a5bb5/builder/src/test/java/org/apache/tamaya/builder/util/types/CustomTypeB.java
----------------------------------------------------------------------
diff --git a/builder/src/test/java/org/apache/tamaya/builder/util/types/CustomTypeB.java b/builder/src/test/java/org/apache/tamaya/builder/util/types/CustomTypeB.java
new file mode 100644
index 0000000..f7f4d99
--- /dev/null
+++ b/builder/src/test/java/org/apache/tamaya/builder/util/types/CustomTypeB.java
@@ -0,0 +1,39 @@
+/*
+ * 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.builder.util.types;
+
+/**
+ * Custom type with factory method
+ * {@link org.apache.tamaya.builder.util.types.CustomTypeB#of(String)}
+ */
+public class CustomTypeB {
+ private String name;
+
+ private CustomTypeB(String value) {
+ this.name = value;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public static CustomTypeB of(String source) {
+ return new CustomTypeB(source);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/f45a5bb5/builder/src/test/java/org/apache/tamaya/builder/util/types/CustomTypeC.java
----------------------------------------------------------------------
diff --git a/builder/src/test/java/org/apache/tamaya/builder/util/types/CustomTypeC.java b/builder/src/test/java/org/apache/tamaya/builder/util/types/CustomTypeC.java
new file mode 100644
index 0000000..da9ce56
--- /dev/null
+++ b/builder/src/test/java/org/apache/tamaya/builder/util/types/CustomTypeC.java
@@ -0,0 +1,36 @@
+/*
+ * 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.builder.util.types;
+
+public class CustomTypeC {
+ private String value;
+
+
+ public CustomTypeC(String in, @SuppressWarnings("unused") int iHideThisConstructorForTamaya) {
+ value = in;
+ }
+
+ public String getValue() {
+ return value;
+ }
+
+ public static CustomTypeC produceFrom(String in) {
+ return new CustomTypeC(in, -1);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/f45a5bb5/builder/src/test/java/org/apache/tamaya/builder/util/types/CustomTypeCPropertyConverter.java
----------------------------------------------------------------------
diff --git a/builder/src/test/java/org/apache/tamaya/builder/util/types/CustomTypeCPropertyConverter.java b/builder/src/test/java/org/apache/tamaya/builder/util/types/CustomTypeCPropertyConverter.java
new file mode 100644
index 0000000..9e56613
--- /dev/null
+++ b/builder/src/test/java/org/apache/tamaya/builder/util/types/CustomTypeCPropertyConverter.java
@@ -0,0 +1,29 @@
+/*
+ * 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.builder.util.types;
+
+import org.apache.tamaya.spi.ConversionContext;
+import org.apache.tamaya.spi.PropertyConverter;
+
+public class CustomTypeCPropertyConverter implements PropertyConverter<org.apache.tamaya.builder.util.types.CustomTypeC> {
+ @Override
+ public org.apache.tamaya.builder.util.types.CustomTypeC convert(String value, ConversionContext context) {
+ return org.apache.tamaya.builder.util.types.CustomTypeC.produceFrom(value);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/f45a5bb5/builder/src/test/resources/META-INF/services/org.apache.tamaya.spi.PropertyConverter
----------------------------------------------------------------------
diff --git a/builder/src/test/resources/META-INF/services/org.apache.tamaya.spi.PropertyConverter b/builder/src/test/resources/META-INF/services/org.apache.tamaya.spi.PropertyConverter
new file mode 100644
index 0000000..b9e0d44
--- /dev/null
+++ b/builder/src/test/resources/META-INF/services/org.apache.tamaya.spi.PropertyConverter
@@ -0,0 +1,19 @@
+#
+# 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.
+#
+org.apache.tamaya.builder.util.types.CustomTypeCPropertyConverter
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/f45a5bb5/builder/src/test/resources/META-INF/services/org.apache.tamaya.spi.PropertyFilter
----------------------------------------------------------------------
diff --git a/builder/src/test/resources/META-INF/services/org.apache.tamaya.spi.PropertyFilter b/builder/src/test/resources/META-INF/services/org.apache.tamaya.spi.PropertyFilter
new file mode 100644
index 0000000..f35e9c5
--- /dev/null
+++ b/builder/src/test/resources/META-INF/services/org.apache.tamaya.spi.PropertyFilter
@@ -0,0 +1,19 @@
+#
+# 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.
+#
+org.apache.tamaya.builder.TestPropertyFilter
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/f45a5bb5/builder/src/test/resources/META-INF/services/org.apache.tamaya.spi.PropertySource
----------------------------------------------------------------------
diff --git a/builder/src/test/resources/META-INF/services/org.apache.tamaya.spi.PropertySource b/builder/src/test/resources/META-INF/services/org.apache.tamaya.spi.PropertySource
new file mode 100644
index 0000000..8b07205
--- /dev/null
+++ b/builder/src/test/resources/META-INF/services/org.apache.tamaya.spi.PropertySource
@@ -0,0 +1,19 @@
+#
+# 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.
+#
+org.apache.tamaya.builder.TestPropertySource
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/f45a5bb5/builder/src/test/resources/META-INF/services/org.apache.tamaya.spi.PropertySourceProvider
----------------------------------------------------------------------
diff --git a/builder/src/test/resources/META-INF/services/org.apache.tamaya.spi.PropertySourceProvider b/builder/src/test/resources/META-INF/services/org.apache.tamaya.spi.PropertySourceProvider
new file mode 100644
index 0000000..9a19ea0
--- /dev/null
+++ b/builder/src/test/resources/META-INF/services/org.apache.tamaya.spi.PropertySourceProvider
@@ -0,0 +1,19 @@
+#
+# 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.
+#
+org.apache.tamaya.builder.TestPropertySourceProvider
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/f45a5bb5/builder/src/test/resources/configfiles/json/first.json
----------------------------------------------------------------------
diff --git a/builder/src/test/resources/configfiles/json/first.json b/builder/src/test/resources/configfiles/json/first.json
new file mode 100644
index 0000000..822cf6e
--- /dev/null
+++ b/builder/src/test/resources/configfiles/json/first.json
@@ -0,0 +1,4 @@
+{
+ "d": "D",
+ "e": "E"
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/f45a5bb5/builder/src/test/resources/configfiles/json/second.json
----------------------------------------------------------------------
diff --git a/builder/src/test/resources/configfiles/json/second.json b/builder/src/test/resources/configfiles/json/second.json
new file mode 100644
index 0000000..e2c7778
--- /dev/null
+++ b/builder/src/test/resources/configfiles/json/second.json
@@ -0,0 +1,4 @@
+{
+ "m": "M",
+ "n": "N"
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/f45a5bb5/builder/src/test/resources/configfiles/json/simple.json
----------------------------------------------------------------------
diff --git a/builder/src/test/resources/configfiles/json/simple.json b/builder/src/test/resources/configfiles/json/simple.json
new file mode 100644
index 0000000..0cab2ae
--- /dev/null
+++ b/builder/src/test/resources/configfiles/json/simple.json
@@ -0,0 +1,4 @@
+{
+ "a": "A",
+ "b": "B"
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/f45a5bb5/builder/src/test/resources/configfiles/json/third.json
----------------------------------------------------------------------
diff --git a/builder/src/test/resources/configfiles/json/third.json b/builder/src/test/resources/configfiles/json/third.json
new file mode 100644
index 0000000..6b62b96
--- /dev/null
+++ b/builder/src/test/resources/configfiles/json/third.json
@@ -0,0 +1,4 @@
+{
+ "p": "P",
+ "q": "Q"
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/f45a5bb5/builder/src/test/resources/configfiles/other/simple.oml
----------------------------------------------------------------------
diff --git a/builder/src/test/resources/configfiles/other/simple.oml b/builder/src/test/resources/configfiles/other/simple.oml
new file mode 100644
index 0000000..494dba3
--- /dev/null
+++ b/builder/src/test/resources/configfiles/other/simple.oml
@@ -0,0 +1,19 @@
+#
+# 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.
+#
+Key:=Value
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/f45a5bb5/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
deleted file mode 100644
index 96f6244..0000000
--- a/pom.xml
+++ /dev/null
@@ -1,104 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
-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.
--->
-<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-extensions</artifactId>
- <version>0.3-incubating-SNAPSHOT</version>
- </parent>
-
- <artifactId>tamaya-builder</artifactId>
- <name>Apache Tamaya Modules - Builder</name>
- <packaging>jar</packaging> <!-- bundle -->
-
- <inceptionYear>2015</inceptionYear>
-
- <dependencies>
- <dependency>
- <groupId>org.apache.tamaya</groupId>
- <artifactId>tamaya-api</artifactId>
- <version>${project.version}</version>
- <scope>provided</scope>
- </dependency>
-
- <dependency>
- <groupId>org.apache.tamaya.ext</groupId>
- <artifactId>tamaya-formats</artifactId>
- <version>${project.version}</version>
- </dependency>
-
- <dependency>
- <groupId>org.apache.tamaya</groupId>
- <artifactId>tamaya-core</artifactId>
- <version>${project.version}</version>
- <scope>test</scope>
- </dependency>
-
- <dependency>
- <groupId>org.apache.tamaya.ext</groupId>
- <artifactId>tamaya-spisupport</artifactId>
- <version>${project.version}</version>
- </dependency>
-
- <dependency>
- <groupId>org.apache.tamaya.ext</groupId>
- <artifactId>tamaya-json</artifactId>
- <version>${project.version}</version>
- <scope>test</scope>
- </dependency>
-
- <dependency>
- <groupId>org.hamcrest</groupId>
- <artifactId>java-hamcrest</artifactId>
- </dependency>
-
- <dependency>
- <groupId>org.mockito</groupId>
- <artifactId>mockito-core</artifactId>
- </dependency>
-
- <dependency>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
- </dependency>
-
-
- </dependencies>
-
- <!--build>
- <plugins>
- <plugin>
- <groupId>org.apache.felix</groupId>
- <artifactId>maven-bundle-plugin</artifactId>
- <extensions>true</extensions>
- <configuration>
- <instructions>
- <Export-Package>
- org.apache.tamaya.builder
- </Export-Package>
- </instructions>
- </configuration>
- </plugin>
- </plugins>
- </build -->
-
-</project>
[30/50] [abbrv] incubator-tamaya-sandbox git commit: Fixed further
issues from quality gates.
Posted by pl...@apache.org.
Fixed further issues from quality gates.
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/714305e7
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/tree/714305e7
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/diff/714305e7
Branch: refs/heads/master
Commit: 714305e795d3c0bb97f8512703139a2f29ce5f80
Parents: 528a07d
Author: anatole <an...@apache.org>
Authored: Sun Jan 10 02:14:41 2016 +0100
Committer: anatole <an...@apache.org>
Committed: Sun Jan 10 02:14:41 2016 +0100
----------------------------------------------------------------------
.../java/org/apache/tamaya/builder/ConfigurationBuilder.java | 5 ++---
.../tamaya/builder/ProgrammaticConfigurationContext.java | 8 ++++----
.../org/apache/tamaya/builder/PropertySourceBuilder.java | 4 ++--
.../java/org/apache/tamaya/builder/SimplePropertySource.java | 4 ++--
4 files changed, 10 insertions(+), 11 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/714305e7/src/main/java/org/apache/tamaya/builder/ConfigurationBuilder.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/tamaya/builder/ConfigurationBuilder.java b/src/main/java/org/apache/tamaya/builder/ConfigurationBuilder.java
index 5126cea..cd457a1 100644
--- a/src/main/java/org/apache/tamaya/builder/ConfigurationBuilder.java
+++ b/src/main/java/org/apache/tamaya/builder/ConfigurationBuilder.java
@@ -80,7 +80,7 @@ import static java.lang.String.format;
*/
public class ConfigurationBuilder {
/** Builder used to create new ConfigurationContext instances. */
- private ProgrammaticConfigurationContext.Builder contextBuilder = new ProgrammaticConfigurationContext.Builder();
+ private final ProgrammaticConfigurationContext.Builder contextBuilder = new ProgrammaticConfigurationContext.Builder();
/**
* Flag if the config has already been built.
@@ -113,6 +113,7 @@ public class ConfigurationBuilder {
* Allows to set configuration context during unit tests.
*/
ConfigurationBuilder setConfigurationContext(ConfigurationContext configurationContext) {
+ //noinspection deprecation
contextBuilder.setConfigurationContext(configurationContext);
return this;
}
@@ -487,8 +488,6 @@ public class ConfigurationBuilder {
* Disables the automatic loading of all {@link org.apache.tamaya.spi.PropertyFilter}
* service providers.
*
- * @return the builder instance currently used
- *
* @see org.apache.tamaya.spi.PropertyFilter
* @see #enabledProvidedPropertyFilters()
* @see #addPropertyFilters(org.apache.tamaya.spi.PropertyFilter...)
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/714305e7/src/main/java/org/apache/tamaya/builder/ProgrammaticConfigurationContext.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/tamaya/builder/ProgrammaticConfigurationContext.java b/src/main/java/org/apache/tamaya/builder/ProgrammaticConfigurationContext.java
index b3a1c3f..68e770d 100644
--- a/src/main/java/org/apache/tamaya/builder/ProgrammaticConfigurationContext.java
+++ b/src/main/java/org/apache/tamaya/builder/ProgrammaticConfigurationContext.java
@@ -76,7 +76,7 @@ class ProgrammaticConfigurationContext implements ConfigurationContext {
/**
* Lock for internal synchronization.
*/
- private ReadWriteLock propertySourceLock = new ReentrantReadWriteLock();
+ private final ReadWriteLock propertySourceLock = new ReentrantReadWriteLock();
/**
@@ -256,14 +256,14 @@ class ProgrammaticConfigurationContext implements ConfigurationContext {
/**
* The current unmodifiable list of loaded {@link org.apache.tamaya.spi.PropertySource} instances.
*/
- private List<PropertySource> propertySources = new ArrayList<>();
+ private final List<PropertySource> propertySources = new ArrayList<>();
/**
* The current unmodifiable list of loaded {@link org.apache.tamaya.spi.PropertyFilter} instances.
*/
- private List<PropertyFilter> propertyFilters = new ArrayList<>();
+ private final List<PropertyFilter> propertyFilters = new ArrayList<>();
- private Map<TypeLiteral<?>, List<PropertyConverter<?>>> propertyConverters = new HashMap<>();
+ private final Map<TypeLiteral<?>, List<PropertyConverter<?>>> propertyConverters = new HashMap<>();
/**
* The overriding policy used when combining PropertySources registered to evalute the final configuration
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/714305e7/src/main/java/org/apache/tamaya/builder/PropertySourceBuilder.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/tamaya/builder/PropertySourceBuilder.java b/src/main/java/org/apache/tamaya/builder/PropertySourceBuilder.java
index e298939..481a80c 100644
--- a/src/main/java/org/apache/tamaya/builder/PropertySourceBuilder.java
+++ b/src/main/java/org/apache/tamaya/builder/PropertySourceBuilder.java
@@ -31,9 +31,9 @@ public final class PropertySourceBuilder {
/** The ordinal to be used. */
private int ordinal;
/** The name to be used. */
- private String name;
+ private final String name;
/** The properties. */
- private Map<String,String> properties = new HashMap<>();
+ private final Map<String,String> properties = new HashMap<>();
/** private constructor. */
private PropertySourceBuilder(String name){
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/714305e7/src/main/java/org/apache/tamaya/builder/SimplePropertySource.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/tamaya/builder/SimplePropertySource.java b/src/main/java/org/apache/tamaya/builder/SimplePropertySource.java
index f39a0cc..0d5561e 100644
--- a/src/main/java/org/apache/tamaya/builder/SimplePropertySource.java
+++ b/src/main/java/org/apache/tamaya/builder/SimplePropertySource.java
@@ -31,9 +31,9 @@ import java.util.logging.Logger;
*/
public class SimplePropertySource implements PropertySource {
/** The properties. */
- private Map<String, String> properties;
+ private final Map<String, String> properties;
/** The source's name. */
- private String name;
+ private final String name;
public SimplePropertySource(String name, Map<String, String> properties){
this.properties = new HashMap<>(properties);
[13/50] [abbrv] incubator-tamaya-sandbox git commit: Added a new
constraint to ensure that a service configuration contains only existing
classes.
Posted by pl...@apache.org.
Added a new constraint to ensure that a service configuration contains only existing classes.
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/341697f5
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/tree/341697f5
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/diff/341697f5
Branch: refs/heads/master
Commit: 341697f59463f1098179982973dee4fdd00e5db1
Parents: d03d92d
Author: Oliver B. Fischer <pl...@apache.org>
Authored: Fri May 15 20:20:42 2015 +0200
Committer: Oliver B. Fischer <pl...@apache.org>
Committed: Fri May 15 19:52:47 2015 +0200
----------------------------------------------------------------------
.../META-INF/services/org.apache.tamaya.spi.PropertySource | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/341697f5/src/test/resources/META-INF/services/org.apache.tamaya.spi.PropertySource
----------------------------------------------------------------------
diff --git a/src/test/resources/META-INF/services/org.apache.tamaya.spi.PropertySource b/src/test/resources/META-INF/services/org.apache.tamaya.spi.PropertySource
index 64d1b0d..8b07205 100644
--- a/src/test/resources/META-INF/services/org.apache.tamaya.spi.PropertySource
+++ b/src/test/resources/META-INF/services/org.apache.tamaya.spi.PropertySource
@@ -16,4 +16,4 @@
# specific language governing permissions and limitations
# under the License.
#
-org.apache.tamaya.builder.TestPropertySource
+org.apache.tamaya.builder.TestPropertySource
\ No newline at end of file
[27/50] [abbrv] incubator-tamaya-sandbox git commit: TAMAYA-126:
Removed refs to Java 8.
Posted by pl...@apache.org.
TAMAYA-126: Removed refs to Java 8.
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/2b52e65a
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/tree/2b52e65a
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/diff/2b52e65a
Branch: refs/heads/master
Commit: 2b52e65a9570519d70f6748c58274e56d3fba335
Parents: decb12b
Author: Anatole Tresch <an...@apache.org>
Authored: Fri Oct 30 10:22:36 2015 +0100
Committer: Anatole Tresch <an...@apache.org>
Committed: Fri Oct 30 10:22:36 2015 +0100
----------------------------------------------------------------------
pom.xml | 4 ----
.../tamaya/builder/ProgrammaticConfigurationContext.java | 7 ++++---
2 files changed, 4 insertions(+), 7 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/2b52e65a/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index 746af5e..90b07e7 100644
--- a/pom.xml
+++ b/pom.xml
@@ -32,10 +32,6 @@ under the License.
<inceptionYear>2015</inceptionYear>
- <properties>
- <jdkVersion>1.8</jdkVersion>
- </properties>
-
<dependencies>
<dependency>
<groupId>org.apache.tamaya</groupId>
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/2b52e65a/src/main/java/org/apache/tamaya/builder/ProgrammaticConfigurationContext.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/tamaya/builder/ProgrammaticConfigurationContext.java b/src/main/java/org/apache/tamaya/builder/ProgrammaticConfigurationContext.java
index b67d18a..b3a1c3f 100644
--- a/src/main/java/org/apache/tamaya/builder/ProgrammaticConfigurationContext.java
+++ b/src/main/java/org/apache/tamaya/builder/ProgrammaticConfigurationContext.java
@@ -35,7 +35,8 @@ import org.apache.tamaya.spisupport.PropertySourceComparator;
import javax.annotation.Priority;
import java.util.*;
import java.util.concurrent.locks.Lock;
-import java.util.concurrent.locks.StampedLock;
+import java.util.concurrent.locks.ReadWriteLock;
+import java.util.concurrent.locks.ReentrantReadWriteLock;
import java.util.logging.Logger;
/**
@@ -75,7 +76,7 @@ class ProgrammaticConfigurationContext implements ConfigurationContext {
/**
* Lock for internal synchronization.
*/
- private StampedLock propertySourceLock = new StampedLock();
+ private ReadWriteLock propertySourceLock = new ReentrantReadWriteLock();
/**
@@ -149,7 +150,7 @@ class ProgrammaticConfigurationContext implements ConfigurationContext {
}
public void addPropertySources(PropertySource... propertySourcesToAdd) {
- Lock writeLock = propertySourceLock.asWriteLock();
+ Lock writeLock = propertySourceLock.writeLock();
try {
writeLock.lock();
List<PropertySource> provided = new ArrayList<>();
[10/50] [abbrv] incubator-tamaya-sandbox git commit: Moved
PropertyConverter into SPI package.
Posted by pl...@apache.org.
Moved PropertyConverter into SPI package.
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/1a7b54d3
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/tree/1a7b54d3
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/diff/1a7b54d3
Branch: refs/heads/master
Commit: 1a7b54d34f01cb40e25d939f2ce44fadf8c6ef66
Parents: a63c28f
Author: anatole <an...@apache.org>
Authored: Fri Apr 17 22:41:11 2015 +0200
Committer: anatole <an...@apache.org>
Committed: Fri Apr 17 22:41:11 2015 +0200
----------------------------------------------------------------------
.../tamaya/builder/ConfigurationBuilder.java | 20 ++++++++++----------
.../ProgrammaticConfigurationContext.java | 4 ++--
.../types/CustomTypeCPropertyConverter.java | 2 +-
.../org.apache.tamaya.PropertyConverter | 19 -------------------
.../org.apache.tamaya.spi.PropertyConverter | 19 +++++++++++++++++++
5 files changed, 32 insertions(+), 32 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/1a7b54d3/src/main/java/org/apache/tamaya/builder/ConfigurationBuilder.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/tamaya/builder/ConfigurationBuilder.java b/src/main/java/org/apache/tamaya/builder/ConfigurationBuilder.java
index 21d6cf7..dfe821b 100644
--- a/src/main/java/org/apache/tamaya/builder/ConfigurationBuilder.java
+++ b/src/main/java/org/apache/tamaya/builder/ConfigurationBuilder.java
@@ -20,7 +20,7 @@ package org.apache.tamaya.builder;
import org.apache.tamaya.ConfigException;
import org.apache.tamaya.Configuration;
-import org.apache.tamaya.PropertyConverter;
+import org.apache.tamaya.spi.PropertyConverter;
import org.apache.tamaya.TypeLiteral;
import org.apache.tamaya.core.internal.DefaultConfiguration;
import org.apache.tamaya.format.ConfigurationData;
@@ -326,7 +326,7 @@ public class ConfigurationBuilder {
*
* @return the builder instance currently used
*
- * @see org.apache.tamaya.PropertyConverter
+ * @see org.apache.tamaya.spi.PropertyConverter
* @see #enableProvidedPropertyConverters()
* @see #disableProvidedPropertyConverters()
*/
@@ -349,7 +349,7 @@ public class ConfigurationBuilder {
}
/**
- * Checks if the automatic loading of all {@link org.apache.tamaya.PropertyConverter
+ * Checks if the automatic loading of all {@link org.apache.tamaya.spi.PropertyConverter
* PropertyConverter} service providers is enabled or disabled.
*
* @return {@code true} if the automatic loading is enabled,
@@ -357,20 +357,20 @@ public class ConfigurationBuilder {
*
* @see #enableProvidedPropertyConverters()
* @see #disableProvidedPropertyConverters()
- * @see #addPropertyConverter(Class, org.apache.tamaya.PropertyConverter)
- * @see #addPropertyConverter(org.apache.tamaya.TypeLiteral, org.apache.tamaya.PropertyConverter)
+ * @see #addPropertyConverter(Class, org.apache.tamaya.spi.PropertyConverter)
+ * @see #addPropertyConverter(org.apache.tamaya.TypeLiteral, org.apache.tamaya.spi.PropertyConverter)
*/
public boolean isPropertyConverterLoadingEnabled() {
return loadProvidedPropertyConverters;
}
/**
- * Enables the loading of all {@link org.apache.tamaya.PropertyConverter}
+ * Enables the loading of all {@link org.apache.tamaya.spi.PropertyConverter}
* service providers.
*
* @return the builder instance currently used
*
- * @see org.apache.tamaya.PropertyConverter
+ * @see org.apache.tamaya.spi.PropertyConverter
* @see #disableProvidedPropertyConverters()
* @see #enableProvidedPropertyConverters()
*/
@@ -383,14 +383,14 @@ public class ConfigurationBuilder {
}
/**
- * Disables the automatic loading of all {@link org.apache.tamaya.PropertyConverter}
+ * Disables the automatic loading of all {@link org.apache.tamaya.spi.PropertyConverter}
* service providers.
*
* @return the builder instance currently used
*
- * @see org.apache.tamaya.PropertyConverter
+ * @see org.apache.tamaya.spi.PropertyConverter
* @see #enableProvidedPropertyConverters()
- * @see #addPropertyConverter(Class, org.apache.tamaya.PropertyConverter)
+ * @see #addPropertyConverter(Class, org.apache.tamaya.spi.PropertyConverter)
*/
public ConfigurationBuilder disableProvidedPropertyConverters() {
checkBuilderState();
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/1a7b54d3/src/main/java/org/apache/tamaya/builder/ProgrammaticConfigurationContext.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/tamaya/builder/ProgrammaticConfigurationContext.java b/src/main/java/org/apache/tamaya/builder/ProgrammaticConfigurationContext.java
index 6c7e845..d867c3e 100644
--- a/src/main/java/org/apache/tamaya/builder/ProgrammaticConfigurationContext.java
+++ b/src/main/java/org/apache/tamaya/builder/ProgrammaticConfigurationContext.java
@@ -19,7 +19,7 @@
package org.apache.tamaya.builder;
-import org.apache.tamaya.PropertyConverter;
+import org.apache.tamaya.spi.PropertyConverter;
import org.apache.tamaya.TypeLiteral;
import org.apache.tamaya.core.internal.PropertyConverterManager;
import org.apache.tamaya.spi.ConfigurationContext;
@@ -62,7 +62,7 @@ class ProgrammaticConfigurationContext implements ConfigurationContext {
*/
private final static Logger LOG = Logger.getLogger(ProgrammaticConfigurationContext.class.getName());
/**
- * Cubcomponent handling {@link org.apache.tamaya.PropertyConverter} instances.
+ * Cubcomponent handling {@link org.apache.tamaya.spi.PropertyConverter} instances.
*/
private PropertyConverterManager propertyConverterManager = new PropertyConverterManager();
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/1a7b54d3/src/test/java/org/apache/tamaya/builder/util/types/CustomTypeCPropertyConverter.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/tamaya/builder/util/types/CustomTypeCPropertyConverter.java b/src/test/java/org/apache/tamaya/builder/util/types/CustomTypeCPropertyConverter.java
index 1754b30..c7d1490 100644
--- a/src/test/java/org/apache/tamaya/builder/util/types/CustomTypeCPropertyConverter.java
+++ b/src/test/java/org/apache/tamaya/builder/util/types/CustomTypeCPropertyConverter.java
@@ -18,7 +18,7 @@
*/
package org.apache.tamaya.builder.util.types;
-import org.apache.tamaya.PropertyConverter;
+import org.apache.tamaya.spi.PropertyConverter;
public class CustomTypeCPropertyConverter implements PropertyConverter<org.apache.tamaya.builder.util.types.CustomTypeC> {
@Override
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/1a7b54d3/src/test/resources/META-INF/services/org.apache.tamaya.PropertyConverter
----------------------------------------------------------------------
diff --git a/src/test/resources/META-INF/services/org.apache.tamaya.PropertyConverter b/src/test/resources/META-INF/services/org.apache.tamaya.PropertyConverter
deleted file mode 100644
index b9e0d44..0000000
--- a/src/test/resources/META-INF/services/org.apache.tamaya.PropertyConverter
+++ /dev/null
@@ -1,19 +0,0 @@
-#
-# 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.
-#
-org.apache.tamaya.builder.util.types.CustomTypeCPropertyConverter
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/1a7b54d3/src/test/resources/META-INF/services/org.apache.tamaya.spi.PropertyConverter
----------------------------------------------------------------------
diff --git a/src/test/resources/META-INF/services/org.apache.tamaya.spi.PropertyConverter b/src/test/resources/META-INF/services/org.apache.tamaya.spi.PropertyConverter
new file mode 100644
index 0000000..b9e0d44
--- /dev/null
+++ b/src/test/resources/META-INF/services/org.apache.tamaya.spi.PropertyConverter
@@ -0,0 +1,19 @@
+#
+# 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.
+#
+org.apache.tamaya.builder.util.types.CustomTypeCPropertyConverter
\ No newline at end of file
[21/50] [abbrv] incubator-tamaya-sandbox git commit: Reset head to
previous master head version.
Posted by pl...@apache.org.
Reset head to previous master head version.
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/daa8f222
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/tree/daa8f222
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/diff/daa8f222
Branch: refs/heads/master
Commit: daa8f222685fcd8790b1f6b05e323ba7b7c782ff
Parents: b5232bb
Author: anatole <at...@gmail.com>
Authored: Tue Aug 4 22:42:56 2015 +0200
Committer: anatole <at...@gmail.com>
Committed: Tue Aug 4 22:42:56 2015 +0200
----------------------------------------------------------------------
pom.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/daa8f222/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index 5912c2c..54d1ba0 100644
--- a/pom.xml
+++ b/pom.xml
@@ -23,7 +23,7 @@ under the License.
<parent>
<groupId>org.apache.tamaya.ext</groupId>
<artifactId>tamaya-extensions</artifactId>
- <version>0.2-incubating-SNAPSHOT</version>
+ <version>0.1-incubating-SNAPSHOT</version>
</parent>
<artifactId>tamaya-builder</artifactId>
[42/50] [abbrv] incubator-tamaya-sandbox git commit:
[maven-release-plugin] prepare for next development iteration
Posted by pl...@apache.org.
[maven-release-plugin] prepare for next development iteration
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/93bcde78
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/tree/93bcde78
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/diff/93bcde78
Branch: refs/heads/master
Commit: 93bcde7881aa26a71de0ac9e35dc8f4582cc39e9
Parents: 3fb70b5
Author: anatole <an...@apache.org>
Authored: Wed Mar 16 16:20:17 2016 +0100
Committer: anatole <an...@apache.org>
Committed: Wed Mar 16 16:20:17 2016 +0100
----------------------------------------------------------------------
pom.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/93bcde78/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index 9202d80..96f6244 100644
--- a/pom.xml
+++ b/pom.xml
@@ -23,7 +23,7 @@ under the License.
<parent>
<groupId>org.apache.tamaya.ext</groupId>
<artifactId>tamaya-extensions</artifactId>
- <version>0.2-incubating</version>
+ <version>0.3-incubating-SNAPSHOT</version>
</parent>
<artifactId>tamaya-builder</artifactId>
[38/50] [abbrv] incubator-tamaya-sandbox git commit:
[maven-release-plugin] prepare for next development iteration
Posted by pl...@apache.org.
[maven-release-plugin] prepare for next development iteration
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/c28fbec8
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/tree/c28fbec8
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/diff/c28fbec8
Branch: refs/heads/master
Commit: c28fbec87aa36de21830709753f54b097e3ed0b3
Parents: 69c1ec2
Author: anatole <an...@apache.org>
Authored: Tue Mar 8 20:39:16 2016 +0100
Committer: anatole <an...@apache.org>
Committed: Tue Mar 8 20:39:16 2016 +0100
----------------------------------------------------------------------
pom.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/c28fbec8/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index 9202d80..96f6244 100644
--- a/pom.xml
+++ b/pom.xml
@@ -23,7 +23,7 @@ under the License.
<parent>
<groupId>org.apache.tamaya.ext</groupId>
<artifactId>tamaya-extensions</artifactId>
- <version>0.2-incubating</version>
+ <version>0.3-incubating-SNAPSHOT</version>
</parent>
<artifactId>tamaya-builder</artifactId>
[36/50] [abbrv] incubator-tamaya-sandbox git commit:
[maven-release-plugin] prepare for next development iteration
Posted by pl...@apache.org.
[maven-release-plugin] prepare for next development iteration
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/4d40b2e7
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/tree/4d40b2e7
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/diff/4d40b2e7
Branch: refs/heads/master
Commit: 4d40b2e72e17a4c0ee6b1e2a6d7ff17a8da5188d
Parents: da4748f
Author: anatole <an...@apache.org>
Authored: Tue Mar 8 17:40:05 2016 +0100
Committer: anatole <an...@apache.org>
Committed: Tue Mar 8 17:40:05 2016 +0100
----------------------------------------------------------------------
pom.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/4d40b2e7/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index 9202d80..96f6244 100644
--- a/pom.xml
+++ b/pom.xml
@@ -23,7 +23,7 @@ under the License.
<parent>
<groupId>org.apache.tamaya.ext</groupId>
<artifactId>tamaya-extensions</artifactId>
- <version>0.2-incubating</version>
+ <version>0.3-incubating-SNAPSHOT</version>
</parent>
<artifactId>tamaya-builder</artifactId>
[26/50] [abbrv] incubator-tamaya-sandbox git commit: TAMAYA-128:
Added ConversionContext for supporting more complex conversion cases.
Posted by pl...@apache.org.
TAMAYA-128: Added ConversionContext for supporting more complex conversion cases.
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/decb12ba
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/tree/decb12ba
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/diff/decb12ba
Branch: refs/heads/master
Commit: decb12bada358db088b8ea7073c3e82579e5839f
Parents: d44893c
Author: Anatole Tresch <an...@apache.org>
Authored: Thu Oct 29 11:40:27 2015 +0100
Committer: Anatole Tresch <an...@apache.org>
Committed: Thu Oct 29 11:40:27 2015 +0100
----------------------------------------------------------------------
pom.xml | 8 +-
.../tamaya/builder/ConfigurationBuilder.java | 48 ++---
.../ProgrammaticConfigurationContext.java | 205 +++++++++----------
.../builder/ConfigurationBuilderTest.java | 34 ++-
.../builder/util/mockito/NotMockedAnswer.java | 4 +-
.../types/CustomTypeCPropertyConverter.java | 3 +-
6 files changed, 151 insertions(+), 151 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/decb12ba/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index 710e5e7..746af5e 100644
--- a/pom.xml
+++ b/pom.xml
@@ -54,7 +54,13 @@ under the License.
<groupId>org.apache.tamaya</groupId>
<artifactId>tamaya-core</artifactId>
<version>${project.version}</version>
- <scope>provided</scope>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.tamaya.ext</groupId>
+ <artifactId>tamaya-spisupport</artifactId>
+ <version>${project.version}</version>
</dependency>
<dependency>
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/decb12ba/src/main/java/org/apache/tamaya/builder/ConfigurationBuilder.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/tamaya/builder/ConfigurationBuilder.java b/src/main/java/org/apache/tamaya/builder/ConfigurationBuilder.java
index 82eb3eb..ad92d51 100644
--- a/src/main/java/org/apache/tamaya/builder/ConfigurationBuilder.java
+++ b/src/main/java/org/apache/tamaya/builder/ConfigurationBuilder.java
@@ -22,7 +22,6 @@ import org.apache.tamaya.ConfigException;
import org.apache.tamaya.Configuration;
import org.apache.tamaya.spi.PropertyConverter;
import org.apache.tamaya.TypeLiteral;
-import org.apache.tamaya.core.internal.DefaultConfiguration;
import org.apache.tamaya.format.ConfigurationData;
import org.apache.tamaya.format.ConfigurationFormats;
import org.apache.tamaya.format.FlattenedDefaultPropertySource;
@@ -31,16 +30,13 @@ import org.apache.tamaya.spi.PropertyFilter;
import org.apache.tamaya.spi.PropertySource;
import org.apache.tamaya.spi.PropertySourceProvider;
import org.apache.tamaya.spi.PropertyValueCombinationPolicy;
+import org.apache.tamaya.spisupport.DefaultConfiguration;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
-import java.util.Arrays;
import java.util.Collection;
import java.util.Objects;
-import java.util.function.Function;
-import java.util.stream.Collectors;
-import java.util.stream.Stream;
import static java.lang.String.format;
@@ -187,12 +183,11 @@ public class ConfigurationBuilder {
* @see org.apache.tamaya.format.ConfigurationFormats#getFormats()
*/
public ConfigurationBuilder addPropertySources(URL... urls) {
- Stream.of(Arrays.asList(urls))
- .flatMap(Collection::stream)
- .filter(entry -> entry != null)
- .collect(Collectors.toList())
- .forEach(this::addPropertySource);
-
+ for(URL url:urls){
+ if(url!=null){
+ addPropertySource(url);
+ }
+ }
return this;
}
@@ -218,9 +213,11 @@ public class ConfigurationBuilder {
* @see org.apache.tamaya.format.ConfigurationFormats#getFormats()
*/
public ConfigurationBuilder addPropertySources(Collection<URL> urls) {
- urls.stream()
- .filter(entry -> entry != null)
- .forEach(this::addPropertySource);
+ for(URL url:urls) {
+ if (url != null) {
+ addPropertySource(url);
+ }
+ }
return this;
}
@@ -245,13 +242,15 @@ public class ConfigurationBuilder {
* @see org.apache.tamaya.format.ConfigurationFormats#getFormats()
*/
public ConfigurationBuilder addPropertySources(String... urls) {
- Stream.of(Arrays.asList(urls))
- .flatMap(Collection::stream)
- .filter(entry -> entry != null)
- .map(new StringToURLMapper())
- .collect(Collectors.toList())
- .forEach(this::addPropertySource);
-
+ for(String url:urls) {
+ if (url != null) {
+ try{
+ addPropertySource(new URL(url));
+ } catch(Exception e){
+ throw new ConfigException("Invalid URL: " + url);
+ }
+ }
+ }
return this;
}
@@ -360,8 +359,7 @@ public class ConfigurationBuilder {
public <T> ConfigurationBuilder addPropertyConverter(Class<T> type, PropertyConverter<T> converter) {
Objects.requireNonNull(type);
Objects.requireNonNull(converter);
-
- return addPropertyConverter(TypeLiteral.of(type), converter);
+ return addPropertyConverter(TypeLiteral.of(type), (PropertyConverter<Object>)converter);
}
/**
@@ -370,7 +368,6 @@ public class ConfigurationBuilder {
public <T> ConfigurationBuilder addPropertyConverter(TypeLiteral<T> type, PropertyConverter<T> propertyConverter){
Objects.requireNonNull(type);
Objects.requireNonNull(propertyConverter);
-
contextBuilder.addPropertyConverter(type, propertyConverter);
return this;
}
@@ -591,8 +588,7 @@ public class ConfigurationBuilder {
/**
* Mapper to map a URL given as string to an URL instance.
*/
- private static class StringToURLMapper implements Function<String, URL> {
- @Override
+ private static class StringToURLMapper {
public URL apply(String u) {
try {
return new URL(u);
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/decb12ba/src/main/java/org/apache/tamaya/builder/ProgrammaticConfigurationContext.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/tamaya/builder/ProgrammaticConfigurationContext.java b/src/main/java/org/apache/tamaya/builder/ProgrammaticConfigurationContext.java
index 9f675dc..b67d18a 100644
--- a/src/main/java/org/apache/tamaya/builder/ProgrammaticConfigurationContext.java
+++ b/src/main/java/org/apache/tamaya/builder/ProgrammaticConfigurationContext.java
@@ -21,7 +21,6 @@ package org.apache.tamaya.builder;
import org.apache.tamaya.spi.PropertyConverter;
import org.apache.tamaya.TypeLiteral;
-import org.apache.tamaya.core.internal.PropertyConverterManager;
import org.apache.tamaya.spi.ConfigurationContext;
import org.apache.tamaya.spi.ConfigurationContextBuilder;
import org.apache.tamaya.spi.PropertyFilter;
@@ -29,25 +28,15 @@ import org.apache.tamaya.spi.PropertySource;
import org.apache.tamaya.spi.PropertySourceProvider;
import org.apache.tamaya.spi.PropertyValueCombinationPolicy;
import org.apache.tamaya.spi.ServiceContextManager;
+import org.apache.tamaya.spisupport.PriorityServiceComparator;
+import org.apache.tamaya.spisupport.PropertyConverterManager;
+import org.apache.tamaya.spisupport.PropertySourceComparator;
import javax.annotation.Priority;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Objects;
+import java.util.*;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.StampedLock;
-import java.util.function.Function;
-import java.util.function.Predicate;
import java.util.logging.Logger;
-import java.util.stream.Collectors;
-import java.util.stream.Stream;
-
-import static java.util.stream.Collectors.toList;
/**
* Implementation of the {@link org.apache.tamaya.spi.ConfigurationContext}
@@ -56,6 +45,8 @@ import static java.util.stream.Collectors.toList;
*/
class ProgrammaticConfigurationContext implements ConfigurationContext {
+ private static final Comparator<PropertySource> PS_COMPARATOR = new PropertySourceComparator();
+ private static final Comparator<Object> COMP_COMPARATOR = new PriorityServiceComparator();
/**
* The logger used.
*/
@@ -96,75 +87,78 @@ class ProgrammaticConfigurationContext implements ConfigurationContext {
public ProgrammaticConfigurationContext(Builder builder) {
propertyConverterManager = new PropertyConverterManager(builder.loadProvidedPropertyConverters);
- immutablePropertySources = getAllPropertySources(builder).stream()
- .sorted(this::comparePropertySources)
- .collect(Collectors.toList());
+ List<PropertySource> sources = getAllPropertySources(builder);
+ Collections.sort(sources, PS_COMPARATOR);
+ immutablePropertySources = Collections.unmodifiableList(sources);
- immutablePropertyFilters = getPropertyFilters(builder).stream()
- .sorted(this::comparePropertyFilters)
- .collect(toList());
+ List<PropertyFilter> filters = getPropertyFilters(builder);
+ Collections.sort(filters, COMP_COMPARATOR);
+ immutablePropertyFilters = Collections.unmodifiableList(filters);
propertyValueCombinationPolicy = builder.propertyValueCombinationPolicy;
+ for(Map.Entry<TypeLiteral<?>, List<PropertyConverter<?>>> en: builder.propertyConverters.entrySet()){
+ if(en!=null){
+ for(PropertyConverter pv:en.getValue()) {
+ propertyConverterManager.register(en.getKey(), pv);
+ }
+ }
+ }
- builder.propertyConverters.forEach((literal, converters) -> {
- converters.stream().filter(c -> c != null)
- .forEach(c -> propertyConverterManager.register((TypeLiteral<Object>) literal,
- (PropertyConverter<Object>) c));
- });
-
- LOG.info(() -> "Using " + immutablePropertySources.size() + " property sources: " +
- createStringList(immutablePropertySources, ps -> ps.getName() + '[' + ps.getClass().getName() + ']'));
-
-
- LOG.info(() -> "Using " + immutablePropertyFilters.size() + " property filters: " +
- createStringList(immutablePropertyFilters, f -> f.getClass().getName()));
-
-
- LOG.info(() -> "Using PropertyValueCombinationPolicy: " + propertyValueCombinationPolicy);
+ LOG.info("Using " + immutablePropertySources.size() + " property sources: " + immutablePropertySources);
+ LOG.info("Using " + immutablePropertyFilters.size() + " property filters: " + immutablePropertyFilters);
+ LOG.info("Using PropertyValueCombinationPolicy: " + propertyValueCombinationPolicy);
}
private List<PropertyFilter> getPropertyFilters(Builder builder) {
- List<PropertyFilter> provided = builder.loadProvidedPropertyFilters
- ? ServiceContextManager.getServiceContext().getServices(PropertyFilter.class)
- : new ArrayList<>(0);
-
- List<PropertyFilter> configured = builder.propertyFilters;
-
- return Stream.of(provided, configured).flatMap(Collection::stream)
- .collect(toList());
+ List<PropertyFilter> provided = new ArrayList<>();
+ if(builder.loadProvidedPropertyFilters) {
+ provided.addAll(ServiceContextManager.getServiceContext().getServices(PropertyFilter.class));
+ }
+ for(PropertyFilter pf:builder.propertyFilters) {
+ if (pf != null) {
+ provided.add(pf);
+ }
+ }
+ return provided;
}
private List<PropertySource> getAllPropertySources(Builder builder) {
- List<PropertySource> provided = builder.loadProvidedPropertySources
- ? ServiceContextManager.getServiceContext().getServices(PropertySource.class)
- : new ArrayList<>(0);
-
+ List<PropertySource> provided = new ArrayList<>();
+ if(builder.loadProvidedPropertySources) {
+ provided.addAll(ServiceContextManager.getServiceContext().getServices(PropertySource.class));
+ }
+ for(PropertySource ps:builder.propertySources){
+ if(ps!=null){
+ provided.add(ps);
+ }
+ }
if (builder.loadProvidedPropertySourceProviders) {
List<PropertySourceProvider> providers = ServiceContextManager.getServiceContext()
.getServices(PropertySourceProvider.class);
for (PropertySourceProvider provider : providers) {
- Collection<PropertySource> sources = provider.getPropertySources();
- provided.addAll(sources);
+ for(PropertySource ps:provider.getPropertySources()) {
+ if(ps!=null) {
+ provided.addAll(provider.getPropertySources());
+ }
+ }
}
}
-
- List<PropertySource> configured = builder.propertySources;
-
- return Stream.of(provided, configured).flatMap(Collection::stream)
- .collect(toList());
+ return provided;
}
public void addPropertySources(PropertySource... propertySourcesToAdd) {
Lock writeLock = propertySourceLock.asWriteLock();
try {
writeLock.lock();
- List<PropertySource> newPropertySources = new ArrayList<>(this.immutablePropertySources);
- newPropertySources.addAll(Arrays.asList(propertySourcesToAdd));
- Collections.sort(newPropertySources, this::comparePropertySources);
-
- this.immutablePropertySources = Collections.unmodifiableList(newPropertySources);
+ List<PropertySource> provided = new ArrayList<>();
+ for(PropertySource ps:propertySourcesToAdd){
+ if(ps!=null){
+ provided.add(ps);
+ }
+ }
+ this.immutablePropertySources = Collections.unmodifiableList(provided);
} finally {
writeLock.unlock();
}
@@ -224,7 +218,7 @@ class ProgrammaticConfigurationContext implements ConfigurationContext {
public <T> void addPropertyConverter(TypeLiteral<T> typeToConvert, PropertyConverter<T> propertyConverter) {
propertyConverterManager.register(typeToConvert, propertyConverter);
- LOG.info(() -> "Added PropertyConverter: " + propertyConverter.getClass().getName());
+ LOG.info("Added PropertyConverter: " + propertyConverter.getClass().getName());
}
@Override
@@ -247,11 +241,6 @@ class ProgrammaticConfigurationContext implements ConfigurationContext {
return propertyValueCombinationPolicy;
}
- private <T> String createStringList(Collection<T> propertySources, Function<T, String> mapper) {
- StringBuilder joiner = new StringBuilder(", ");
- propertySources.forEach(t -> joiner.append(mapper.apply(t)));
- return joiner.toString();
- }
@Override
public ConfigurationContextBuilder toBuilder() {
@@ -259,11 +248,6 @@ class ProgrammaticConfigurationContext implements ConfigurationContext {
throw new RuntimeException("This method is currently not supported.");
}
- public Collection<PropertySource> getPropertySources(Predicate<PropertySource> selector) {
- // @todo Check if it could be useful to support this method, Oliver B. Fischer
- throw new RuntimeException("This method is currently not supported.");
- }
-
/**
* The Builder for {@link ProgrammaticConfigurationContext}
*/
@@ -298,56 +282,56 @@ class ProgrammaticConfigurationContext implements ConfigurationContext {
}
public Builder addPropertySources(PropertySource... propertySources) {
- List<PropertySource> filtered = Stream.of(propertySources).filter(this::isNotNull)
- .collect(toList());
-
- this.propertySources.addAll(filtered);
-
+ for (PropertySource ps : propertySources) {
+ if (ps != null) {
+ this.propertySources.add(ps);
+ }
+ }
return this;
}
public Builder addPropertySources(Collection<PropertySource> propertySources) {
- List<PropertySource> filtered = propertySources.stream().filter(this::isNotNull)
- .collect(toList());
-
- this.propertySources.addAll(filtered);
-
+ for (PropertySource ps : propertySources) {
+ if (ps != null) {
+ this.propertySources.add(ps);
+ }
+ }
return this;
}
public Builder addPropertySourceProviders(PropertySourceProvider... propertySourceProviders) {
- List<PropertySourceProvider> providers = Stream.of(propertySourceProviders).filter(this::isNotNull)
- .collect(toList());
-
- return addPropertySourceProviders(providers);
+ for (PropertySourceProvider ps : propertySourceProviders) {
+ if (ps != null) {
+ this.propertySources.addAll(ps.getPropertySources());
+ }
+ }
+ return this;
}
- public Builder addPropertySourceProviders(Collection<PropertySourceProvider> providers) {
- List<PropertySource> filtered = providers.stream().filter(this::isNotNull)
- .flatMap(p -> p.getPropertySources().stream())
- .filter(this::isNotNull)
- .collect(toList());
-
- this.propertySources.addAll(filtered);
-
+ public Builder addPropertySourceProviders(Collection<PropertySourceProvider> propertySourceProviders) {
+ for (PropertySourceProvider ps : propertySourceProviders) {
+ if (ps != null) {
+ this.propertySources.addAll(ps.getPropertySources());
+ }
+ }
return this;
}
- public Builder addPropertyFilters(PropertyFilter... propertySources) {
- List<PropertyFilter> sources = Stream.of(propertySources).filter(this::isNotNull)
- .collect(toList());
-
- this.propertyFilters.addAll(sources);
-
+ public Builder addPropertyFilters(PropertyFilter... propertyFIlter) {
+ for (PropertyFilter pf : propertyFIlter) {
+ if (pf != null) {
+ this.propertyFilters.add(pf);
+ }
+ }
return this;
}
- public Builder addPropertyFilters(Collection<PropertyFilter> propertySources) {
- List<PropertyFilter> sources = propertySources.stream().filter(this::isNotNull)
- .collect(toList());
-
- this.propertyFilters.addAll(sources);
-
+ public Builder addPropertyFilters(Collection<PropertyFilter> propertyFIlter) {
+ for (PropertyFilter pf : propertyFIlter) {
+ if (pf != null) {
+ this.propertyFilters.add(pf);
+ }
+ }
return this;
}
@@ -367,9 +351,11 @@ class ProgrammaticConfigurationContext implements ConfigurationContext {
//X TODO as overrides used first.
public <T> Builder addPropertyConverter(TypeLiteral<T> type, PropertyConverter<T> propertyConverter) {
- propertyConverters.computeIfAbsent(type, (t) -> new ArrayList<>())
- .add(propertyConverter);
-
+ if(!propertyConverters.containsKey(type)){
+ List<PropertyConverter<?>> convList = new ArrayList<>();
+ convList.add(propertyConverter);
+ propertyConverters.put(type, convList);
+ }
return this;
}
@@ -394,9 +380,6 @@ class ProgrammaticConfigurationContext implements ConfigurationContext {
loadProvidedPropertyFilters = state;
}
- private <T> boolean isNotNull(T item) {
- return null != item;
- }
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/decb12ba/src/test/java/org/apache/tamaya/builder/ConfigurationBuilderTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/tamaya/builder/ConfigurationBuilderTest.java b/src/test/java/org/apache/tamaya/builder/ConfigurationBuilderTest.java
index e5ec668..023fb27 100644
--- a/src/test/java/org/apache/tamaya/builder/ConfigurationBuilderTest.java
+++ b/src/test/java/org/apache/tamaya/builder/ConfigurationBuilderTest.java
@@ -24,9 +24,7 @@ import org.apache.tamaya.TypeLiteral;
import org.apache.tamaya.builder.util.types.CustomTypeA;
import org.apache.tamaya.builder.util.types.CustomTypeB;
import org.apache.tamaya.builder.util.types.CustomTypeC;
-import org.apache.tamaya.spi.PropertyFilter;
-import org.apache.tamaya.spi.PropertySource;
-import org.apache.tamaya.spi.PropertySourceProvider;
+import org.apache.tamaya.spi.*;
import org.hamcrest.CoreMatchers;
import org.hamcrest.Matchers;
import org.junit.Ignore;
@@ -273,9 +271,13 @@ public class ConfigurationBuilderTest {
@Test(expected = NullPointerException.class)
public void canNotAddNullTypeLiteralButPropertyConverter() {
ConfigurationBuilder builder = new ConfigurationBuilder();
-
- builder.addPropertyConverter((TypeLiteral<CustomTypeA>)null,
- prop -> new CustomTypeA(prop, prop));
+ builder.addPropertyConverter((TypeLiteral)null,
+ new PropertyConverter() {
+ @Override
+ public CustomTypeA convert(final String prop, ConversionContext context) {
+ return new CustomTypeA(prop, prop);
+ }
+ });
}
@Test
@@ -289,8 +291,13 @@ public class ConfigurationBuilderTest {
ConfigurationBuilder builder = new ConfigurationBuilder();
builder.addPropertyConverter(TypeLiteral.of(CustomTypeA.class),
- prop -> new CustomTypeA(prop, prop))
- .addPropertySources(source);
+ new PropertyConverter() {
+ @Override
+ public CustomTypeA convert(final String prop, ConversionContext context) {
+ return new CustomTypeA(prop, prop);
+ }
+ });
+ builder.addPropertySources(source);
Configuration config = builder.build();
@@ -313,9 +320,14 @@ public class ConfigurationBuilderTest {
ConfigurationBuilder builder = new ConfigurationBuilder();
- builder.addPropertyConverter(CustomTypeA.class,
- prop -> new CustomTypeA(prop, prop))
- .addPropertySources(source);
+ builder.addPropertyConverter(TypeLiteral.of(CustomTypeA.class),
+ new PropertyConverter() {
+ @Override
+ public CustomTypeA convert(final String prop, ConversionContext context) {
+ return new CustomTypeA(prop, prop);
+ }
+ });
+ builder.addPropertySources(source);
Configuration config = builder.build();
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/decb12ba/src/test/java/org/apache/tamaya/builder/util/mockito/NotMockedAnswer.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/tamaya/builder/util/mockito/NotMockedAnswer.java b/src/test/java/org/apache/tamaya/builder/util/mockito/NotMockedAnswer.java
index 10b3734..3188d85 100644
--- a/src/test/java/org/apache/tamaya/builder/util/mockito/NotMockedAnswer.java
+++ b/src/test/java/org/apache/tamaya/builder/util/mockito/NotMockedAnswer.java
@@ -33,6 +33,9 @@ public class NotMockedAnswer implements Answer<Object>, Serializable {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
+ if("toString".equals(invocation.getMethod().getName())){
+ return "Some "+invocation.getMethod().getDeclaringClass().getName();
+ }
StringBuilder msgBuilder = new StringBuilder();
msgBuilder.append("Invocation of method not mocked: ")
@@ -49,7 +52,6 @@ public class NotMockedAnswer implements Answer<Object>, Serializable {
}
}
}
-
throw new MockitoException(msgBuilder.toString());
}
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/decb12ba/src/test/java/org/apache/tamaya/builder/util/types/CustomTypeCPropertyConverter.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/tamaya/builder/util/types/CustomTypeCPropertyConverter.java b/src/test/java/org/apache/tamaya/builder/util/types/CustomTypeCPropertyConverter.java
index c7d1490..9e56613 100644
--- a/src/test/java/org/apache/tamaya/builder/util/types/CustomTypeCPropertyConverter.java
+++ b/src/test/java/org/apache/tamaya/builder/util/types/CustomTypeCPropertyConverter.java
@@ -18,11 +18,12 @@
*/
package org.apache.tamaya.builder.util.types;
+import org.apache.tamaya.spi.ConversionContext;
import org.apache.tamaya.spi.PropertyConverter;
public class CustomTypeCPropertyConverter implements PropertyConverter<org.apache.tamaya.builder.util.types.CustomTypeC> {
@Override
- public org.apache.tamaya.builder.util.types.CustomTypeC convert(String value) {
+ public org.apache.tamaya.builder.util.types.CustomTypeC convert(String value, ConversionContext context) {
return org.apache.tamaya.builder.util.types.CustomTypeC.produceFrom(value);
}
}
[44/50] [abbrv] incubator-tamaya-sandbox git commit:
[maven-release-plugin] prepare release vote02-tamaya-0.2-incubating
Posted by pl...@apache.org.
[maven-release-plugin] prepare release vote02-tamaya-0.2-incubating
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/6e573517
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/tree/6e573517
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/diff/6e573517
Branch: refs/heads/master
Commit: 6e573517e72b2067a343d371614577d8bdf4099c
Parents: 204d358
Author: anatole <an...@apache.org>
Authored: Tue Apr 5 18:56:54 2016 +0200
Committer: anatole <an...@apache.org>
Committed: Tue Apr 5 18:56:54 2016 +0200
----------------------------------------------------------------------
pom.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/6e573517/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index 32dc6b5..9202d80 100644
--- a/pom.xml
+++ b/pom.xml
@@ -23,7 +23,7 @@ under the License.
<parent>
<groupId>org.apache.tamaya.ext</groupId>
<artifactId>tamaya-extensions</artifactId>
- <version>0.2-incubating-SNAPSHOT</version>
+ <version>0.2-incubating</version>
</parent>
<artifactId>tamaya-builder</artifactId>
[19/50] [abbrv] incubator-tamaya-sandbox git commit:
[maven-release-plugin] prepare release tamaya-all-0.1-incubating
Posted by pl...@apache.org.
[maven-release-plugin] prepare release tamaya-all-0.1-incubating
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/0bace89c
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/tree/0bace89c
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/diff/0bace89c
Branch: refs/heads/master
Commit: 0bace89c1921fbd3399abfe70c25372cdf2f0633
Parents: b656312
Author: anatole <at...@gmail.com>
Authored: Tue Aug 4 11:53:34 2015 +0200
Committer: anatole <at...@gmail.com>
Committed: Tue Aug 4 11:53:34 2015 +0200
----------------------------------------------------------------------
pom.xml | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/0bace89c/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index 0e0c034..9cb03fd 100644
--- a/pom.xml
+++ b/pom.xml
@@ -17,14 +17,13 @@ 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">
+<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-extensions</artifactId>
- <version>0.1-incubating-SNAPSHOT</version>
+ <version>0.1-incubating</version>
</parent>
<artifactId>tamaya-builder</artifactId>
[03/50] [abbrv] incubator-tamaya-sandbox git commit: TAMAYA-60 Wrote
more JavaDoc.
Posted by pl...@apache.org.
TAMAYA-60 Wrote more JavaDoc.
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/51393bf4
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/tree/51393bf4
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/diff/51393bf4
Branch: refs/heads/master
Commit: 51393bf4a5e1c9488cac14c6328093a3db1b0653
Parents: 0c4fe5c
Author: Oliver B. Fischer <pl...@apache.org>
Authored: Wed Mar 11 06:36:10 2015 +0100
Committer: Oliver B. Fischer <pl...@apache.org>
Committed: Wed Mar 11 06:36:10 2015 +0100
----------------------------------------------------------------------
.../modules/builder/ConfigurationBuilder.java | 92 ++++++++++++++------
1 file changed, 66 insertions(+), 26 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/51393bf4/src/main/java/org/apache/tamaya/modules/builder/ConfigurationBuilder.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/tamaya/modules/builder/ConfigurationBuilder.java b/src/main/java/org/apache/tamaya/modules/builder/ConfigurationBuilder.java
index ce26aad..945eb2f 100644
--- a/src/main/java/org/apache/tamaya/modules/builder/ConfigurationBuilder.java
+++ b/src/main/java/org/apache/tamaya/modules/builder/ConfigurationBuilder.java
@@ -45,23 +45,6 @@ import java.util.stream.Stream;
import static java.lang.String.format;
-/* TODO LIST FOR TAMAYA-60
- *
- * - configurable loading of provided PropertyConverter DONE
- * - configurable loading of provided PropertySources DONE
- * - configurable loading of provided PropertySourceProviders DONE
- * - configurable loading of provided PropertyFilters DONE
- * - I can not overhand null in varargs
- * - Rethink the default behaviour for SPI loading
- * - Work on all TODOs for TAMAYA-60
- * - Write JavaDoc
- * - adding sources via URL DONE
- *
- *
- *
- *
- */
-
/**
* <p>Builder class used for building a configuration manually without relying
* only on the Service Provider Interface API.</p>
@@ -112,6 +95,11 @@ public class ConfigurationBuilder {
private boolean isLoadProvidedPropertyFilters = false;
+ /**
+ * Creates a new builder instance.
+ */
+ public ConfigurationBuilder() {
+ }
/**
* Allows to set configuration context during unit tests.
@@ -280,15 +268,31 @@ public class ConfigurationBuilder {
}
/**
+ * Adds one or more property filter instances to the configuration to be build.
+ *
+ * <pre>{@code PropertyFilter quoteReplacingFilter = new QuoteFilter();
+ * PropertyFilter commaRemovingFilter = new CommaFilter();
+ *
+ * builder.addPropertyFilters(commaRemovingFilter, quoteReplacingFilter)};
+ * </pre>
+ *
+ * @param filters list of property filter instances which should be applied
+ * to the properties of the configuration to be build.
+ *
* @return the builder instance currently used
+ *
+ * @see org.apache.tamaya.spi.PropertyFilter
+ * @see #disableProvidedPropertyFilters()
+ * @see #enabledProvidedPropertyFilters()
*/
- public ConfigurationBuilder addPropertyFilters(PropertyFilter... propertyFilters){
- Objects.requireNonNull(propertyFilters);
+ public ConfigurationBuilder addPropertyFilters(PropertyFilter... filters){
+ Objects.requireNonNull(filters);
- contextBuilder.addPropertyFilters(propertyFilters);
+ contextBuilder.addPropertyFilters(filters);
return this;
}
+
/**
* @return the builder instance currently used
*/
@@ -298,13 +302,29 @@ public class ConfigurationBuilder {
}
/**
+ * Adds a property converter for the a given type to the configuration to
+ * be build.
+ *
+ * <pre>{@code PropertyConverter<MyType> converter = value -> new MyType(value, 42);
+ *
+ * builder.addPropertyConverter(MyType.class, converter}
+ * </pre>
+ *
+ * @param type the required target type the converter should be applied to
+ * @param converter the converter to be used to convert the string property
+ * to the given target type.
+ *
* @return the builder instance currently used
+ *
+ * @see org.apache.tamaya.PropertyConverter
+ * @see #enableProvidedPropertyConverters()
+ * @see #disableProvidedPropertyConverters()
*/
- public <T> ConfigurationBuilder addPropertyConverter(Class<T> type, PropertyConverter<T> propertyConverter) {
+ public <T> ConfigurationBuilder addPropertyConverter(Class<T> type, PropertyConverter<T> converter) {
Objects.requireNonNull(type);
- Objects.requireNonNull(propertyConverter);
+ Objects.requireNonNull(converter);
- return addPropertyConverter(TypeLiteral.of(type), propertyConverter);
+ return addPropertyConverter(TypeLiteral.of(type), converter);
}
/**
@@ -318,7 +338,18 @@ public class ConfigurationBuilder {
return this;
}
-
+ /**
+ * Checks if the automatic loading of all {@link org.apache.tamaya.PropertyConverter
+ * PropertyConverter} service providers is enabled or disabled.
+ *
+ * @return {@code true} if the automatic loading is enabled,
+ * otherwise {@code false}.
+ *
+ * @see #enableProvidedPropertyConverters()
+ * @see #disableProvidedPropertyConverters()
+ * @see #addPropertyConverter(Class, org.apache.tamaya.PropertyConverter)
+ * @see #addPropertyConverter(org.apache.tamaya.TypeLiteral, org.apache.tamaya.PropertyConverter)
+ */
public boolean isPropertyConverterLoadingEnabled() {
return loadProvidedPropertyConverters;
}
@@ -331,6 +362,7 @@ public class ConfigurationBuilder {
*
* @see org.apache.tamaya.PropertyConverter
* @see #disableProvidedPropertyConverters()
+ * @see #enableProvidedPropertyConverters()
*/
public ConfigurationBuilder enableProvidedPropertyConverters() {
checkBuilderState();
@@ -348,6 +380,7 @@ public class ConfigurationBuilder {
*
* @see org.apache.tamaya.PropertyConverter
* @see #enableProvidedPropertyConverters()
+ * @see #addPropertyConverter(Class, org.apache.tamaya.PropertyConverter)
*/
public ConfigurationBuilder disableProvidedPropertyConverters() {
checkBuilderState();
@@ -392,15 +425,21 @@ public class ConfigurationBuilder {
* PropertyFilter} service providers is enabled or disabled.
*
* @return {@code true} if the automatic loading is enabled,
- * otherwise {@code false}.
+ * otherwise {@code false}.
*/
public boolean isPropertyFilterLoadingEnabled() {
return isLoadProvidedPropertyFilters;
}
-
/**
+ * Enables the automatic loading of all {@link org.apache.tamaya.spi.PropertyFilter}
+ * service providers.
+ *
* @return the builder instance currently used
+ *
+ * @see org.apache.tamaya.spi.PropertyFilter
+ * @see #disableProvidedPropertyFilters()
+ * @see #addPropertyFilters(org.apache.tamaya.spi.PropertyFilter...)
*/
public ConfigurationBuilder enabledProvidedPropertyFilters() {
checkBuilderState();
@@ -418,6 +457,7 @@ public class ConfigurationBuilder {
*
* @see org.apache.tamaya.spi.PropertyFilter
* @see #enabledProvidedPropertyFilters()
+ * @see #addPropertyFilters(org.apache.tamaya.spi.PropertyFilter...)
*
* @return the builder instance currently used
*/
[11/50] [abbrv] incubator-tamaya-sandbox git commit: Added collection
support.
Posted by pl...@apache.org.
Added collection 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/4ac2dd72
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/tree/4ac2dd72
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/diff/4ac2dd72
Branch: refs/heads/master
Commit: 4ac2dd723edbea5809cbe0042ecb0deadde315d4
Parents: 1a7b54d
Author: anatole <an...@apache.org>
Authored: Sat May 9 00:57:35 2015 +0200
Committer: anatole <an...@apache.org>
Committed: Sat May 9 00:57:35 2015 +0200
----------------------------------------------------------------------
.../tamaya/builder/ConfigurationBuilder.java | 33 ++++++++++++++++++--
1 file changed, 30 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/4ac2dd72/src/main/java/org/apache/tamaya/builder/ConfigurationBuilder.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/tamaya/builder/ConfigurationBuilder.java b/src/main/java/org/apache/tamaya/builder/ConfigurationBuilder.java
index dfe821b..799b114 100644
--- a/src/main/java/org/apache/tamaya/builder/ConfigurationBuilder.java
+++ b/src/main/java/org/apache/tamaya/builder/ConfigurationBuilder.java
@@ -149,7 +149,6 @@ public class ConfigurationBuilder {
} catch (IOException e) {
throw new ConfigException("Failed to read " + url.toString(), e);
}
-
return this;
}
@@ -187,7 +186,7 @@ public class ConfigurationBuilder {
* @see org.apache.tamaya.format.ConfigurationFormat
* @see org.apache.tamaya.format.ConfigurationFormats#getFormats()
*/
- public ConfigurationBuilder addPropertySource(URL... urls) {
+ public ConfigurationBuilder addPropertySources(URL... urls) {
Stream.of(Arrays.asList(urls))
.flatMap(Collection::stream)
.filter(entry -> entry != null)
@@ -197,6 +196,34 @@ public class ConfigurationBuilder {
return this;
}
+ /**
+ * Adds one or more resources with properties in an arbitrary format
+ * to the configuration to be build.
+ *
+ * <p>If a specific format is supported depends on the available
+ * {@link org.apache.tamaya.format.ConfigurationFormat} implementations.</p>
+ *
+ *<pre>{@code URL first = new URL("file:/etc/service/config.json");
+ * URL second = new URL("file:/etc/defaults/values.properties");
+ *
+ * builder.addPropertySources(first, second);}
+ *</pre>
+ *
+ * @param urls list of resources with properties for the configuration to be
+ * build.
+ *
+ * @return the builder instance currently used
+ *
+ * @see org.apache.tamaya.format.ConfigurationFormat
+ * @see org.apache.tamaya.format.ConfigurationFormats#getFormats()
+ */
+ public ConfigurationBuilder addPropertySources(Collection<URL> urls) {
+ urls.stream()
+ .filter(entry -> entry != null)
+ .forEach(this::addPropertySource);
+ return this;
+ }
+
/**
* Adds one or more resources with properties in an arbitrary format
@@ -217,7 +244,7 @@ public class ConfigurationBuilder {
* @see org.apache.tamaya.format.ConfigurationFormat
* @see org.apache.tamaya.format.ConfigurationFormats#getFormats()
*/
- public ConfigurationBuilder addPropertySource(String... urls) {
+ public ConfigurationBuilder addPropertySources(String... urls) {
Stream.of(Arrays.asList(urls))
.flatMap(Collection::stream)
.filter(entry -> entry != null)
[47/50] [abbrv] incubator-tamaya-sandbox git commit: Moved the
builder to the directory builder
Posted by pl...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/f45a5bb5/src/main/java/org/apache/tamaya/builder/ConfigurationBuilder.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/tamaya/builder/ConfigurationBuilder.java b/src/main/java/org/apache/tamaya/builder/ConfigurationBuilder.java
deleted file mode 100644
index afdc121..0000000
--- a/src/main/java/org/apache/tamaya/builder/ConfigurationBuilder.java
+++ /dev/null
@@ -1,605 +0,0 @@
-/*
- * 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.builder;
-
-import org.apache.tamaya.ConfigException;
-import org.apache.tamaya.Configuration;
-import org.apache.tamaya.spi.PropertyConverter;
-import org.apache.tamaya.TypeLiteral;
-import org.apache.tamaya.format.ConfigurationData;
-import org.apache.tamaya.format.ConfigurationFormats;
-import org.apache.tamaya.format.FlattenedDefaultPropertySource;
-import org.apache.tamaya.spi.ConfigurationContext;
-import org.apache.tamaya.spi.PropertyFilter;
-import org.apache.tamaya.spi.PropertySource;
-import org.apache.tamaya.spi.PropertySourceProvider;
-import org.apache.tamaya.spi.PropertyValueCombinationPolicy;
-import org.apache.tamaya.spisupport.DefaultConfiguration;
-
-import java.io.IOException;
-import java.net.MalformedURLException;
-import java.net.URL;
-import java.util.Collection;
-import java.util.Objects;
-
-import static java.lang.String.format;
-
-/**
- * <p>Builder class used for building a configuration manually without relying
- * only on the Service Provider Interface API.</p>
- *
- * <p><strong>Features of the builder</strong></p>
- *
- * <ol>
- * <li>Adding of property converters manually</li>
- * <li>Adding of property sources directly</li>
- * <li>Adding of property sources via URL</li>
- * <li>Adding of property source providers directly</li>
- * <li>Enabling and disabling of via SPI mechanism provided resources as converters,
- * property sources, etc.</li>
- * </ol>
- *
- * <p><strong>Example</strong></p>
- *
- * <pre>{@code ConfigurationBuilder builder = new ConfigurationBuilder();
- * builder.disableProvidedPropertySources() // Do not load provided property
- * .disableProvidedPropertySourceProviders() // sources and providers automatically
- * .addPropertySource("file:/etc/conf.properties"); // Load properties from conf.properties
- *
- * Configuration config = builder.build();
- * }</pre>
- *
- * <p><strong>Support for configuration formats</strong></p>
- *
- * The configuration builder allows you to put property resources
- * via a URL, as shown in the code example above, without implementing
- * a {@link org.apache.tamaya.spi.PropertySource PropertySource} or providing an
- * instance of a {@link org.apache.tamaya.spi.PropertySource PropertySource}.
- * If a property resource in
- * a specific format can be added to configuration builder or not depends
- * on the available implementations of
- * {@link org.apache.tamaya.format.ConfigurationFormat} in the classpath.
- * Which formats are available can be checked via
- * {@link org.apache.tamaya.format.ConfigurationFormats#getFormats()}.
- */
-public class ConfigurationBuilder {
- /** Builder used to create new ConfigurationContext instances. */
- private final ProgrammaticConfigurationContext.Builder contextBuilder = new ProgrammaticConfigurationContext.Builder();
-
- /**
- * Flag if the config has already been built.
- * Configuration can be built only once
- */
- private boolean built;
-
- /**
- * Flag if all existing property converter service providers
- * should be loaded if the configuration is build.
- */
- private boolean loadProvidedPropertyConverters = true;
-
- /**
- * Flag if all existing property source service providers
- * will be loaded if the configuration is build.
- */
- private boolean loadProvidedPropertySources = false;
- private boolean loadProvidedPropertySourceProviders = false;
-
- private boolean isLoadProvidedPropertyFilters = false;
-
- /**
- * Creates a new builder instance.
- */
- public ConfigurationBuilder() {
- }
-
- /**
- * Allows to set configuration context during unit tests.
- */
- ConfigurationBuilder setConfigurationContext(ConfigurationContext configurationContext) {
- //noinspection deprecation
- contextBuilder.setConfigurationContext(configurationContext);
- return this;
- }
-
- /**
- * Adds one resources with properties in an arbitrary format
- * to the configuration to be build.
- *
- * <p>If a specific format is supported depends on the available
- * {@link org.apache.tamaya.format.ConfigurationFormat} implementations.</p>
- *
- * <pre>{@code URL resource = new URL("file:/etc/service/config.json");
- *
- * builder.addPropertySources(resource);}
- * </pre>
- *
- * @param url resource with properties for the the configuration to be build.
- *
- * @return the builder instance currently used
- *
- * @see org.apache.tamaya.format.ConfigurationFormat
- * @see org.apache.tamaya.format.ConfigurationFormats#getFormats()
- */
- public ConfigurationBuilder addPropertySource(URL url) {
- try {
- ConfigurationData data = getConfigurationDataFromURL(url);
-
- FlattenedDefaultPropertySource propertySource = new FlattenedDefaultPropertySource(data);
- addPropertySources(propertySource);
- } catch (IOException e) {
- throw new ConfigException("Failed to read " + url.toString(), e);
- }
- return this;
- }
-
- protected ConfigurationData getConfigurationDataFromURL(URL url) throws IOException {
- ConfigurationData data = ConfigurationFormats.readConfigurationData(url);
-
- if (null == data) {
- String mesg = format("No configuration format found which is able " +
- "to read properties from %s.", url.toString());
-
- throw new ConfigException(mesg);
- }
-
- return data;
- }
-
- /**
- * Adds one or more resources with properties in an arbitrary format
- * to the configuration to be build.
- *
- * <p>If a specific format is supported depends on the available
- * {@link org.apache.tamaya.format.ConfigurationFormat} implementations.</p>
- *
- *<pre>{@code URL first = new URL("file:/etc/service/config.json");
- * URL second = new URL("file:/etc/defaults/values.properties");
- *
- * builder.addPropertySources(first, second);}
- *</pre>
- *
- * @param urls list of resources with properties for the configuration to be
- * build.
- *
- * @return the builder instance currently used
- *
- * @see org.apache.tamaya.format.ConfigurationFormat
- * @see org.apache.tamaya.format.ConfigurationFormats#getFormats()
- */
- public ConfigurationBuilder addPropertySources(URL... urls) {
- for(URL url:urls){
- if(url!=null){
- addPropertySource(url);
- }
- }
- return this;
- }
-
- /**
- * Adds one or more resources with properties in an arbitrary format
- * to the configuration to be build.
- *
- * <p>If a specific format is supported depends on the available
- * {@link org.apache.tamaya.format.ConfigurationFormat} implementations.</p>
- *
- *<pre>{@code URL first = new URL("file:/etc/service/config.json");
- * URL second = new URL("file:/etc/defaults/values.properties");
- *
- * builder.addPropertySources(first, second);}
- *</pre>
- *
- * @param urls list of resources with properties for the configuration to be
- * build.
- *
- * @return the builder instance currently used
- *
- * @see org.apache.tamaya.format.ConfigurationFormat
- * @see org.apache.tamaya.format.ConfigurationFormats#getFormats()
- */
- public ConfigurationBuilder addPropertySources(Collection<URL> urls) {
- for(URL url:urls) {
- if (url != null) {
- addPropertySource(url);
- }
- }
- return this;
- }
-
-
- /**
- * Adds one or more resources with properties in an arbitrary format
- * to the configuration to be build.
- *
- * <p>If a specific format is supported depends on the available
- * {@link org.apache.tamaya.format.ConfigurationFormat} implementations.</p>
- *
- *<pre>{@code builder.addPropertySources("file:/etc/service/config.json",
- * "file:/etc/defaults/values.properties");}
- *</pre>
- *
- * @param urls list of resources with properties for the configuration to be
- * build.
- *
- * @return the builder instance currently used
- *
- * @see org.apache.tamaya.format.ConfigurationFormat
- * @see org.apache.tamaya.format.ConfigurationFormats#getFormats()
- */
- public ConfigurationBuilder addPropertySources(String... urls) {
- for(String url:urls) {
- if (url != null) {
- try{
- addPropertySource(new URL(url));
- } catch(Exception e){
- throw new ConfigException("Invalid URL: " + url);
- }
- }
- }
- return this;
- }
-
- /**
- * Adds one or more property source instances to the configuration to be build.
- *
- *<pre>{@code PropertySource first = new CustomPropertySource();
- * PropertySource second = new YetAnotherPropertySource();
- *
- * builder.addPropertySources(first, second)};
- *</pre>
- *
- * @param sources list of property source instances with properties for the
- * configuration to be build.
- *
- * @return the builder instance currently used
- *
- * @see org.apache.tamaya.spi.PropertySource
- */
- public ConfigurationBuilder addPropertySources(PropertySource... sources){
- checkBuilderState();
-
- contextBuilder.addPropertySources(Objects.requireNonNull(sources));
- return this;
- }
-
- private void checkBuilderState() {
- if (built) {
- throw new IllegalStateException("Configuration has already been build.");
- }
- }
-
- /**
- * Adds one or more property source provider instances to the configuration to be build.
- *
- * <pre>{@code PropertySourceProvider jc = new JavaConfigurationProvider();
- *
- * builder.addPropertySources(jc)};
- * </pre>
- *
- * @param providers list of property source provider instances each providing a set
- * of property source instances for the configuration to be build.
- *
- * @return the builder instance currently used
- *
- * @see org.apache.tamaya.spi.PropertySourceProvider
- */
- public ConfigurationBuilder addPropertySourceProviders(PropertySourceProvider... providers){
- contextBuilder.addPropertySourceProviders(providers);
- return this;
- }
-
- /**
- * Adds one or more property filter instances to the configuration to be build.
- *
- * <pre>{@code PropertyFilter quoteReplacingFilter = new QuoteFilter();
- * PropertyFilter commaRemovingFilter = new CommaFilter();
- *
- * builder.addPropertyFilters(commaRemovingFilter, quoteReplacingFilter)};
- * </pre>
- *
- * @param filters list of property filter instances which should be applied
- * to the properties of the configuration to be build.
- *
- * @return the builder instance currently used
- *
- * @see org.apache.tamaya.spi.PropertyFilter
- * @see #disableProvidedPropertyFilters()
- * @see #enabledProvidedPropertyFilters()
- */
- public ConfigurationBuilder addPropertyFilters(PropertyFilter... filters){
- Objects.requireNonNull(filters);
-
- contextBuilder.addPropertyFilters(filters);
- return this;
- }
-
-
- /**
- * @param propertyValueCombinationPolicy combination policy to use for this builder.
- * @return the builder instance currently in use.
- */
- public ConfigurationBuilder setPropertyValueCombinationPolicy(PropertyValueCombinationPolicy propertyValueCombinationPolicy){
- contextBuilder.setPropertyValueCombinationPolicy(propertyValueCombinationPolicy);
- return this;
- }
-
- /**
- * Adds a property converter for the a given type to the configuration to
- * be build.
- *
- * <pre>{@code PropertyConverter<MyType> converter = value -> new MyType(value, 42);
- *
- * builder.addPropertyConverter(MyType.class, converter}
- * </pre>
- *
- * @param <T> the type of the configuration
- * @param type the required target type the converter should be applied to
- * @param converter the converter to be used to convert the string property
- * to the given target type.
- *
- * @return the builder instance currently used
- *
- * @see org.apache.tamaya.spi.PropertyConverter
- * @see #enableProvidedPropertyConverters()
- * @see #disableProvidedPropertyConverters()
- */
- public <T> ConfigurationBuilder addPropertyConverter(Class<T> type, PropertyConverter<T> converter) {
- Objects.requireNonNull(type);
- Objects.requireNonNull(converter);
- return addPropertyConverter(TypeLiteral.of(type), (PropertyConverter<Object>)converter);
- }
-
- /**
- * Adds a propertyConverter of a given type.
- *
- * @param <T> the type of the configuration
- * @param type type literal of this converter.
- * @param propertyConverter property converter.
- * @return the builder instance currently used
- */
- public <T> ConfigurationBuilder addPropertyConverter(TypeLiteral<T> type, PropertyConverter<T> propertyConverter){
- Objects.requireNonNull(type);
- Objects.requireNonNull(propertyConverter);
- contextBuilder.addPropertyConverter(type, propertyConverter);
- return this;
- }
-
- /**
- * Checks if the automatic loading of all {@link org.apache.tamaya.spi.PropertyConverter
- * PropertyConverter} service providers is enabled or disabled.
- *
- * @return {@code true} if the automatic loading is enabled,
- * otherwise {@code false}.
- *
- * @see #enableProvidedPropertyConverters()
- * @see #disableProvidedPropertyConverters()
- * @see #addPropertyConverter(Class, org.apache.tamaya.spi.PropertyConverter)
- * @see #addPropertyConverter(org.apache.tamaya.TypeLiteral, org.apache.tamaya.spi.PropertyConverter)
- */
- public boolean isPropertyConverterLoadingEnabled() {
- return loadProvidedPropertyConverters;
- }
-
- /**
- * Enables the loading of all {@link org.apache.tamaya.spi.PropertyConverter}
- * service providers.
- *
- * @return the builder instance currently used
- *
- * @see org.apache.tamaya.spi.PropertyConverter
- * @see #disableProvidedPropertyConverters()
- * @see #enableProvidedPropertyConverters()
- */
- public ConfigurationBuilder enableProvidedPropertyConverters() {
- checkBuilderState();
-
- loadProvidedPropertyConverters = true;
-
- return this;
- }
-
- /**
- * Disables the automatic loading of all {@link org.apache.tamaya.spi.PropertyConverter}
- * service providers.
- *
- * @return the builder instance currently used
- *
- * @see org.apache.tamaya.spi.PropertyConverter
- * @see #enableProvidedPropertyConverters()
- * @see #addPropertyConverter(Class, org.apache.tamaya.spi.PropertyConverter)
- */
- public ConfigurationBuilder disableProvidedPropertyConverters() {
- checkBuilderState();
-
- loadProvidedPropertyConverters = false;
-
- return this;
- }
-
-
- /**
- * Enables the automatic loading of all {@link org.apache.tamaya.spi.PropertySource}
- * service providers.
- *
- * @return the builder instance currently used
- *
- * @see org.apache.tamaya.spi.PropertySource
- * @see #disableProvidedPropertySources()
- */
- public ConfigurationBuilder enableProvidedPropertySources() {
- checkBuilderState();
-
- loadProvidedPropertySources = true;
-
- return this;
- }
-
- /**
- * Checks if the automatic loading of all {@link org.apache.tamaya.spi.PropertySource
- * PropertySource} service providers is enabled or disabled.
- *
- * @return {@code true} if the automatic loading is enabled,
- * otherwise {@code false}.
- */
- public boolean isPropertySourcesLoadingEnabled() {
- return loadProvidedPropertySources;
- }
-
-
- /**
- * Checks if the automatic loading of all {@link org.apache.tamaya.spi.PropertyFilter
- * PropertyFilter} service providers is enabled or disabled.
- *
- * @return {@code true} if the automatic loading is enabled,
- * otherwise {@code false}.
- */
- public boolean isPropertyFilterLoadingEnabled() {
- return isLoadProvidedPropertyFilters;
- }
-
- /**
- * Enables the automatic loading of all {@link org.apache.tamaya.spi.PropertyFilter}
- * service providers.
- *
- * @return the builder instance currently used
- *
- * @see org.apache.tamaya.spi.PropertyFilter
- * @see #disableProvidedPropertyFilters()
- * @see #addPropertyFilters(org.apache.tamaya.spi.PropertyFilter...)
- */
- public ConfigurationBuilder enabledProvidedPropertyFilters() {
- checkBuilderState();
-
- isLoadProvidedPropertyFilters = true;
-
- return this;
- }
-
- /**
- * Disables the automatic loading of all {@link org.apache.tamaya.spi.PropertyFilter}
- * service providers.
- *
- * @see org.apache.tamaya.spi.PropertyFilter
- * @see #enabledProvidedPropertyFilters()
- * @see #addPropertyFilters(org.apache.tamaya.spi.PropertyFilter...)
- *
- * @return the builder instance currently used
- */
- public ConfigurationBuilder disableProvidedPropertyFilters() {
- checkBuilderState();
-
- isLoadProvidedPropertyFilters = false;
-
- return this;
- }
-
- /**
- * Disables the automatic loading of all {@link org.apache.tamaya.spi.PropertySource}
- * service providers.
- *
- * @return the builder instance currently used
- *
- * @see org.apache.tamaya.spi.PropertySource
- * @see #enableProvidedPropertySources()
- */
- public ConfigurationBuilder disableProvidedPropertySources() {
- checkBuilderState();
-
- loadProvidedPropertySources = false;
-
- return this;
- }
-
- /**
- * Enables the automatic loading of {@link org.apache.tamaya.spi.PropertySourceProvider
- * property source providers} provided via the SPI API.
- *
- * @return the builder instance currently used
- *
- * @see org.apache.tamaya.spi.PropertySourceProvider
- */
- public ConfigurationBuilder enableProvidedPropertySourceProviders() {
- checkBuilderState();
-
- loadProvidedPropertySourceProviders = true;
-
- return this;
- }
-
- /**
- * Disables the automatic loading of {@link org.apache.tamaya.spi.PropertySourceProvider
- * property source providers} provided via the SPI API.
- *
- * @return the builder instance currently used
- */
- public ConfigurationBuilder disableProvidedPropertySourceProviders() {
- checkBuilderState();
-
- loadProvidedPropertySourceProviders = false;
-
- return this;
- }
-
- /**
- * Checks if the automatic loading of {@link org.apache.tamaya.spi.PropertySourceProvider
- * PropertySourceProviders} is enabled or disabled.
- *
- * @return {@code true} if the automatic loading is enabled,
- * otherwise {@code false}.
- */
- public boolean isPropertySourceProvidersLoadingEnabled() {
- return loadProvidedPropertySourceProviders;
- }
-
- //X TODO think on a functionality/API for using the default PropertyConverters and use the configured ones here
- //X TODO as overrides used first.
-
-
- /**
- * Builds a new configuration based on the configuration of this builder instance.
- *
- * @return a new {@link org.apache.tamaya.Configuration configuration instance},
- * never {@code null}.
- */
- public Configuration build() {
- checkBuilderState();
-
- built = true;
-
- contextBuilder.loadProvidedPropertyConverters(isPropertyConverterLoadingEnabled());
- contextBuilder.loadProvidedPropertySources(isPropertySourcesLoadingEnabled());
- contextBuilder.loadProvidedPropertySourceProviders(isPropertySourceProvidersLoadingEnabled());
- contextBuilder.loadProvidedPropertyFilters(isLoadProvidedPropertyFilters);
-
- return new DefaultConfiguration(contextBuilder.build());
- }
-
- /**
- * Mapper to map a URL given as string to an URL instance.
- */
- private static class StringToURLMapper {
- public URL apply(String u) {
- try {
- return new URL(u);
- } catch (MalformedURLException e) {
- throw new ConfigException(u + " is not a valid URL", e);
- }
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/f45a5bb5/src/main/java/org/apache/tamaya/builder/ProgrammaticConfigurationContext.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/tamaya/builder/ProgrammaticConfigurationContext.java b/src/main/java/org/apache/tamaya/builder/ProgrammaticConfigurationContext.java
deleted file mode 100644
index 68e770d..0000000
--- a/src/main/java/org/apache/tamaya/builder/ProgrammaticConfigurationContext.java
+++ /dev/null
@@ -1,388 +0,0 @@
-/*
- * 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.builder;
-
-
-import org.apache.tamaya.spi.PropertyConverter;
-import org.apache.tamaya.TypeLiteral;
-import org.apache.tamaya.spi.ConfigurationContext;
-import org.apache.tamaya.spi.ConfigurationContextBuilder;
-import org.apache.tamaya.spi.PropertyFilter;
-import org.apache.tamaya.spi.PropertySource;
-import org.apache.tamaya.spi.PropertySourceProvider;
-import org.apache.tamaya.spi.PropertyValueCombinationPolicy;
-import org.apache.tamaya.spi.ServiceContextManager;
-import org.apache.tamaya.spisupport.PriorityServiceComparator;
-import org.apache.tamaya.spisupport.PropertyConverterManager;
-import org.apache.tamaya.spisupport.PropertySourceComparator;
-
-import javax.annotation.Priority;
-import java.util.*;
-import java.util.concurrent.locks.Lock;
-import java.util.concurrent.locks.ReadWriteLock;
-import java.util.concurrent.locks.ReentrantReadWriteLock;
-import java.util.logging.Logger;
-
-/**
- * Implementation of the {@link org.apache.tamaya.spi.ConfigurationContext}
- * used by the {@link org.apache.tamaya.builder.ConfigurationBuilder}
- * internally.
- */
-class ProgrammaticConfigurationContext implements ConfigurationContext {
-
- private static final Comparator<PropertySource> PS_COMPARATOR = new PropertySourceComparator();
- private static final Comparator<Object> COMP_COMPARATOR = new PriorityServiceComparator();
- /**
- * The logger used.
- */
- private final static Logger LOG = Logger.getLogger(ProgrammaticConfigurationContext.class.getName());
- /**
- * Cubcomponent handling {@link org.apache.tamaya.spi.PropertyConverter} instances.
- */
- private PropertyConverterManager propertyConverterManager = new PropertyConverterManager();
-
- /**
- * The current unmodifiable list of loaded {@link org.apache.tamaya.spi.PropertySource} instances.
- */
- private List<PropertySource> immutablePropertySources = new ArrayList<>();
-
- /**
- * The current unmodifiable list of loaded {@link org.apache.tamaya.spi.PropertyFilter} instances.
- */
- private List<PropertyFilter> immutablePropertyFilters = new ArrayList<>();
-
- /**
- * The overriding policy used when combining PropertySources registered to evalute the final configuration
- * values.
- */
- private PropertyValueCombinationPolicy propertyValueCombinationPolicy;
-
- /**
- * Lock for internal synchronization.
- */
- private final ReadWriteLock propertySourceLock = new ReentrantReadWriteLock();
-
-
- /**
- * The first time the Configuration system gets invoked we do initialize
- * all our {@link org.apache.tamaya.spi.PropertySource}s and
- * {@link org.apache.tamaya.spi.PropertyFilter}s which are known at startup.
- */
- @SuppressWarnings("unchecked")
- public ProgrammaticConfigurationContext(Builder builder) {
- propertyConverterManager = new PropertyConverterManager(builder.loadProvidedPropertyConverters);
-
- List<PropertySource> sources = getAllPropertySources(builder);
- Collections.sort(sources, PS_COMPARATOR);
- immutablePropertySources = Collections.unmodifiableList(sources);
-
-
- List<PropertyFilter> filters = getPropertyFilters(builder);
- Collections.sort(filters, COMP_COMPARATOR);
- immutablePropertyFilters = Collections.unmodifiableList(filters);
-
-
- propertyValueCombinationPolicy = builder.propertyValueCombinationPolicy;
- for(Map.Entry<TypeLiteral<?>, List<PropertyConverter<?>>> en: builder.propertyConverters.entrySet()){
- if(en!=null){
- for(PropertyConverter pv:en.getValue()) {
- propertyConverterManager.register(en.getKey(), pv);
- }
- }
- }
-
- LOG.info("Using " + immutablePropertySources.size() + " property sources: " + immutablePropertySources);
- LOG.info("Using " + immutablePropertyFilters.size() + " property filters: " + immutablePropertyFilters);
- LOG.info("Using PropertyValueCombinationPolicy: " + propertyValueCombinationPolicy);
- }
-
- private List<PropertyFilter> getPropertyFilters(Builder builder) {
- List<PropertyFilter> provided = new ArrayList<>();
- if(builder.loadProvidedPropertyFilters) {
- provided.addAll(ServiceContextManager.getServiceContext().getServices(PropertyFilter.class));
- }
- for(PropertyFilter pf:builder.propertyFilters) {
- if (pf != null) {
- provided.add(pf);
- }
- }
- return provided;
- }
-
- private List<PropertySource> getAllPropertySources(Builder builder) {
- List<PropertySource> provided = new ArrayList<>();
- if(builder.loadProvidedPropertySources) {
- provided.addAll(ServiceContextManager.getServiceContext().getServices(PropertySource.class));
- }
- for(PropertySource ps:builder.propertySources){
- if(ps!=null){
- provided.add(ps);
- }
- }
- if (builder.loadProvidedPropertySourceProviders) {
- List<PropertySourceProvider> providers = ServiceContextManager.getServiceContext()
- .getServices(PropertySourceProvider.class);
- for (PropertySourceProvider provider : providers) {
- for(PropertySource ps:provider.getPropertySources()) {
- if(ps!=null) {
- provided.addAll(provider.getPropertySources());
- }
- }
- }
- }
- return provided;
- }
-
- public void addPropertySources(PropertySource... propertySourcesToAdd) {
- Lock writeLock = propertySourceLock.writeLock();
- try {
- writeLock.lock();
- List<PropertySource> provided = new ArrayList<>();
- for(PropertySource ps:propertySourcesToAdd){
- if(ps!=null){
- provided.add(ps);
- }
- }
- this.immutablePropertySources = Collections.unmodifiableList(provided);
- } finally {
- writeLock.unlock();
- }
- }
-
- /**
- * Order property source reversely, the most important come first.
- *
- * @param source1 the first PropertySource
- * @param source2 the second PropertySource
- * @return the comparison result.
- */
- private int comparePropertySources(PropertySource source1, PropertySource source2) {
-
- //X TODO this method duplicates org.apache.tamaya.core.internal.DefaultConfigurationContext.PropertySourceComparator.comparePropertySources()
- //X maybe we should extract the Comperator in an own class for real code-reuse (copy paste == bad code reuse)
-
- if (source1.getOrdinal() < source2.getOrdinal()) {
- return -1;
- } else if (source1.getOrdinal() > source2.getOrdinal()) {
- return 1;
- } else {
- return source1.getClass().getName().compareTo(source2.getClass().getName());
- }
- }
-
- /**
- * Compare 2 filters for ordering the filter chain.
- *
- * @param filter1 the first filter
- * @param filter2 the second filter
- * @return the comparison result
- */
- private int comparePropertyFilters(PropertyFilter filter1, PropertyFilter filter2) {
-
- //X TODO this method duplicates org.apache.tamaya.core.internal.DefaultConfigurationContext.PropertySourceComparator.comparePropertyFilters()
- //X maybe we should extract the Comperator in an own class for real code-reuse (copy paste == bad code reuse)
-
- Priority prio1 = filter1.getClass().getAnnotation(Priority.class);
- Priority prio2 = filter2.getClass().getAnnotation(Priority.class);
- int ord1 = prio1 != null ? prio1.value() : 0;
- int ord2 = prio2 != null ? prio2.value() : 0;
-
- if (ord1 < ord2) {
- return -1;
- } else if (ord1 > ord2) {
- return 1;
- } else {
- return filter1.getClass().getName().compareTo(filter2.getClass().getName());
- }
- }
-
- @Override
- public List<PropertySource> getPropertySources() {
- return immutablePropertySources;
- }
-
- public <T> void addPropertyConverter(TypeLiteral<T> typeToConvert, PropertyConverter<T> propertyConverter) {
- propertyConverterManager.register(typeToConvert, propertyConverter);
- LOG.info("Added PropertyConverter: " + propertyConverter.getClass().getName());
- }
-
- @Override
- public Map<TypeLiteral<?>, List<PropertyConverter<?>>> getPropertyConverters() {
- return propertyConverterManager.getPropertyConverters();
- }
-
- @Override
- public <T> List<PropertyConverter<T>> getPropertyConverters(TypeLiteral<T> targetType) {
- return propertyConverterManager.getPropertyConverters(targetType);
- }
-
- @Override
- public List<PropertyFilter> getPropertyFilters() {
- return immutablePropertyFilters;
- }
-
- @Override
- public PropertyValueCombinationPolicy getPropertyValueCombinationPolicy() {
- return propertyValueCombinationPolicy;
- }
-
-
- @Override
- public ConfigurationContextBuilder toBuilder() {
- // @todo Check if it could be useful to support this method, Oliver B. Fischer
- throw new RuntimeException("This method is currently not supported.");
- }
-
- /**
- * The Builder for {@link ProgrammaticConfigurationContext}
- */
- public final static class Builder {
- /**
- * The current unmodifiable list of loaded {@link org.apache.tamaya.spi.PropertySource} instances.
- */
- private final List<PropertySource> propertySources = new ArrayList<>();
-
- /**
- * The current unmodifiable list of loaded {@link org.apache.tamaya.spi.PropertyFilter} instances.
- */
- private final List<PropertyFilter> propertyFilters = new ArrayList<>();
-
- private final Map<TypeLiteral<?>, List<PropertyConverter<?>>> propertyConverters = new HashMap<>();
-
- /**
- * The overriding policy used when combining PropertySources registered to evalute the final configuration
- * values.
- */
- private PropertyValueCombinationPolicy propertyValueCombinationPolicy =
- PropertyValueCombinationPolicy.DEFAULT_OVERRIDING_COLLECTOR;
-
- private boolean loadProvidedPropertyConverters;
- private boolean loadProvidedPropertySources;
- private boolean loadProvidedPropertySourceProviders;
- private boolean loadProvidedPropertyFilters;
-
- public Builder setPropertyValueCombinationPolicy(PropertyValueCombinationPolicy policy) {
- this.propertyValueCombinationPolicy = Objects.requireNonNull(policy);
- return this;
- }
-
- public Builder addPropertySources(PropertySource... propertySources) {
- for (PropertySource ps : propertySources) {
- if (ps != null) {
- this.propertySources.add(ps);
- }
- }
- return this;
- }
-
- public Builder addPropertySources(Collection<PropertySource> propertySources) {
- for (PropertySource ps : propertySources) {
- if (ps != null) {
- this.propertySources.add(ps);
- }
- }
- return this;
- }
-
- public Builder addPropertySourceProviders(PropertySourceProvider... propertySourceProviders) {
- for (PropertySourceProvider ps : propertySourceProviders) {
- if (ps != null) {
- this.propertySources.addAll(ps.getPropertySources());
- }
- }
- return this;
- }
-
- public Builder addPropertySourceProviders(Collection<PropertySourceProvider> propertySourceProviders) {
- for (PropertySourceProvider ps : propertySourceProviders) {
- if (ps != null) {
- this.propertySources.addAll(ps.getPropertySources());
- }
- }
- return this;
- }
-
- public Builder addPropertyFilters(PropertyFilter... propertyFIlter) {
- for (PropertyFilter pf : propertyFIlter) {
- if (pf != null) {
- this.propertyFilters.add(pf);
- }
- }
- return this;
- }
-
- public Builder addPropertyFilters(Collection<PropertyFilter> propertyFIlter) {
- for (PropertyFilter pf : propertyFIlter) {
- if (pf != null) {
- this.propertyFilters.add(pf);
- }
- }
- return this;
- }
-
- /**
- * Should be never used.
- */
- @Deprecated
- public Builder setConfigurationContext(ConfigurationContext configurationContext) {
- this.addPropertySources(configurationContext.getPropertySources());
- this.addPropertyFilters(configurationContext.getPropertyFilters());
- this.propertyValueCombinationPolicy = Objects.requireNonNull(
- configurationContext.getPropertyValueCombinationPolicy());
- return this;
- }
-
- //X TODO think on a functonality/API for using the default PropertyConverters and use the configured ones here
- //X TODO as overrides used first.
-
- public <T> Builder addPropertyConverter(TypeLiteral<T> type, PropertyConverter<T> propertyConverter) {
- if(!propertyConverters.containsKey(type)){
- List<PropertyConverter<?>> convList = new ArrayList<>();
- convList.add(propertyConverter);
- propertyConverters.put(type, convList);
- }
- return this;
- }
-
- public ConfigurationContext build() {
- return new ProgrammaticConfigurationContext(this);
- }
-
-
- public void loadProvidedPropertyConverters(boolean state) {
- loadProvidedPropertyConverters = state;
- }
-
- public void loadProvidedPropertySources(boolean state) {
- loadProvidedPropertySources = state;
- }
-
- public void loadProvidedPropertySourceProviders(boolean state) {
- loadProvidedPropertySourceProviders = state;
- }
-
- public void loadProvidedPropertyFilters(boolean state) {
- loadProvidedPropertyFilters = state;
- }
-
- }
-
-
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/f45a5bb5/src/main/java/org/apache/tamaya/builder/PropertySourceBuilder.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/tamaya/builder/PropertySourceBuilder.java b/src/main/java/org/apache/tamaya/builder/PropertySourceBuilder.java
deleted file mode 100644
index 481a80c..0000000
--- a/src/main/java/org/apache/tamaya/builder/PropertySourceBuilder.java
+++ /dev/null
@@ -1,118 +0,0 @@
-/*
- * 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.builder;
-
-import org.apache.tamaya.spi.PropertySource;
-
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Objects;
-
-/**
- * Simple builder for building a {@link org.apache.tamaya.spi.PropertySource}.
- */
-public final class PropertySourceBuilder {
- /** The ordinal to be used. */
- private int ordinal;
- /** The name to be used. */
- private final String name;
- /** The properties. */
- private final Map<String,String> properties = new HashMap<>();
-
- /** private constructor. */
- private PropertySourceBuilder(String name){
- this.name = Objects.requireNonNull(name);
- }
-
- /**
- * Gets a new instance of a builder.
- * @param name The name of the property source, not null.
- * @return a new instance.
- */
- public static PropertySourceBuilder of(String name){
- return new PropertySourceBuilder(name);
- }
-
- /**
- * Gets a new instance of a builder.
- * @param name The name of the property source, not null.
- * @return a new instance.
- */
- public static PropertySourceBuilder from(String name){
- return new PropertySourceBuilder(name);
- }
-
- /**
- * Sets a new property key/value.
- * @param key the property key, not null.
- * @param value the property value, not null.
- * @return the bulder for chaining.
- */
- public PropertySourceBuilder put(String key, String value){
- this.properties.put(key, value);
- return this;
- }
-
- /**
- * Put all the given key, values.
- * @param values the new key/values, not null.
- * @return the bulder for chaining.
- */
- public PropertySourceBuilder putAll(Map<String, String> values){
- this.properties.putAll(values);
- return this;
- }
-
- /**
- * Sets the ordinal to be used explicitly (instead evaluating it using {@code tamaya.ordinal}.
- * @param ordinal the explicit ordinal to be used.
- * @return the bulder for chaining.
- */
- public PropertySourceBuilder withOrdinal(int ordinal){
- this.ordinal = ordinal;
- return this;
- }
-
- /**
- * Puts all values from the given property source.
- * @param propertySource the property source, not null.
- * @return the bulder for chaining.
- */
- public PropertySourceBuilder putAll(PropertySource propertySource){
- this.properties.putAll(propertySource.getProperties());
- return this;
- }
-
- /**
- * Creates a new immutable {@link org.apache.tamaya.spi.PropertySource} instance.
- * @return a new immutable {@link org.apache.tamaya.spi.PropertySource} instance, never null.
- */
- public PropertySource build(){
- return new SimplePropertySource(name, properties);
- }
-
- @Override
- public String toString() {
- return "PropertySourceBuilder{" +
- "ordinal=" + ordinal +
- ", name='" + name + '\'' +
- ", properties=" + properties +
- '}';
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/f45a5bb5/src/main/java/org/apache/tamaya/builder/SimplePropertySource.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/tamaya/builder/SimplePropertySource.java b/src/main/java/org/apache/tamaya/builder/SimplePropertySource.java
deleted file mode 100644
index 085bd9a..0000000
--- a/src/main/java/org/apache/tamaya/builder/SimplePropertySource.java
+++ /dev/null
@@ -1,86 +0,0 @@
-/*
- * 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.builder;
-
-import org.apache.tamaya.spi.PropertySource;
-import org.apache.tamaya.spi.PropertyValue;
-
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Objects;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
-/**
-* Simple property source implementation using a map.
-*/
-public class SimplePropertySource implements PropertySource {
- /** The properties. */
- private final Map<String, String> properties;
- /** The source's name. */
- private final String name;
-
- public SimplePropertySource(String name, Map<String, String> properties){
- this.properties = new HashMap<>(properties);
- this.name = Objects.requireNonNull(name);
- }
-
- @Override
- public int getOrdinal(){
- PropertyValue configuredOrdinal = get(TAMAYA_ORDINAL);
- if(configuredOrdinal!=null){
- try{
- return Integer.parseInt(configuredOrdinal.getValue());
- } catch(Exception e){
- Logger.getLogger(getClass().getName()).log(Level.WARNING,
- "Configured Ordinal is not an int number: " + configuredOrdinal, e);
- }
- }
- return getDefaultOrdinal();
- }
-
- public int getDefaultOrdinal(){
- return 0;
- }
-
- @Override
- public String getName() {
- return name;
- }
-
- @Override
- public PropertyValue get(String key) {
- return null;
- }
-
- @Override
- public Map<String, String> getProperties() {
- return this.properties;
- }
-
- @Override
- public boolean isScannable() {
- return false;
- }
-
- @Override
- public String toString(){
- return "SimplePropertySource(name="+name+", numProps="+properties.size()+")";
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/f45a5bb5/src/main/java/org/apache/tamaya/builder/package-info.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/tamaya/builder/package-info.java b/src/main/java/org/apache/tamaya/builder/package-info.java
deleted file mode 100644
index 24c86a9..0000000
--- a/src/main/java/org/apache/tamaya/builder/package-info.java
+++ /dev/null
@@ -1,28 +0,0 @@
-/*
- * 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.
- */
-/**
- * This package provides
- * {@link org.apache.tamaya.builder.ConfigurationBuilder a configuration
- * builder} that allows to build a configuration manually without
- * using exclusively on the Service Provider Interface API of Tamaya.
- *
- * @see org.apache.tamaya.builder.ConfigurationBuilder
- * @see org.apache.tamaya.Configuration
- */
-package org.apache.tamaya.builder;
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/f45a5bb5/src/test/java/org/apache/tamaya/builder/ConfigurationBuilderTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/tamaya/builder/ConfigurationBuilderTest.java b/src/test/java/org/apache/tamaya/builder/ConfigurationBuilderTest.java
deleted file mode 100644
index 07a72c5..0000000
--- a/src/test/java/org/apache/tamaya/builder/ConfigurationBuilderTest.java
+++ /dev/null
@@ -1,907 +0,0 @@
-/*
- * 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.builder;
-
-import org.apache.tamaya.ConfigException;
-import org.apache.tamaya.Configuration;
-import org.apache.tamaya.TypeLiteral;
-import org.apache.tamaya.builder.util.types.CustomTypeA;
-import org.apache.tamaya.builder.util.types.CustomTypeB;
-import org.apache.tamaya.builder.util.types.CustomTypeC;
-import org.apache.tamaya.spi.*;
-import org.hamcrest.CoreMatchers;
-import org.hamcrest.Matchers;
-import org.junit.Ignore;
-import org.junit.Test;
-import org.mockito.Mockito;
-
-
-import java.io.IOException;
-import java.net.URL;
-
-import static java.util.Arrays.asList;
-import static org.apache.tamaya.builder.util.mockito.NotMockedAnswer.NOT_MOCKED_ANSWER;
-import static org.hamcrest.CoreMatchers.equalTo;
-import static org.hamcrest.CoreMatchers.nullValue;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.Matchers.is;
-import static org.hamcrest.Matchers.notNullValue;
-import static org.mockito.Matchers.anyString;
-import static org.mockito.Mockito.CALLS_REAL_METHODS;
-import static org.mockito.Mockito.doReturn;
-import static org.mockito.Mockito.doThrow;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.verify;
-
-
-public class ConfigurationBuilderTest {
-
- @Test
- public void buildCanBuildEmptyConfiguration() {
- ConfigurationBuilder builder = new ConfigurationBuilder();
-
- Configuration config = builder.build();
-
- assertThat(config, notNullValue());
- }
-
- @Test(expected = IllegalStateException.class)
- public void buildCanBeCalledOnlyOnce() {
- ConfigurationBuilder builder = new ConfigurationBuilder();
-
- builder.build();
- builder.build();
- }
-
- /*********************************************************************
- * Tests for adding P r o p e r t y S o u r c e s
- */
-
- @Test(expected = NullPointerException.class)
- public void addPropertySourcesDoesNotAcceptNullValue() {
- ConfigurationBuilder builder = new ConfigurationBuilder();
-
- builder.addPropertySources((PropertySource[])null);
- }
-
- @Test(expected = IllegalStateException.class)
- public void propertySourceCanNotBeAddedAfterBuildingTheConfiguration() {
- PropertySource first = mock(PropertySource.class, NOT_MOCKED_ANSWER);
-
- doReturn("first").when(first).getName();
- doReturn(100).when(first).getOrdinal();
-
- ConfigurationBuilder builder = new ConfigurationBuilder().addPropertySources(first);
-
- builder.build();
-
- PropertySource second = mock(PropertySource.class, NOT_MOCKED_ANSWER);
-
- doReturn("second").when(first).getName();
-
- builder.addPropertySources(second);
- }
-
- @Test
- public void singleAddedPropertySourceIsUsed() {
- PropertySource source = mock(PropertySource.class, NOT_MOCKED_ANSWER);
-
- doReturn("one").when(source).getName();
- doReturn(PropertyValue.of("keyOfA","a", "test")).when(source).get("keyOfA");
- doReturn(100).when(source).getOrdinal();
-
- ConfigurationBuilder builder = new ConfigurationBuilder().addPropertySources(source);
-
- Configuration config = builder.build();
-
- String valueOfA = config.get("keyOfA");
-
- assertThat(valueOfA, notNullValue());
- assertThat(valueOfA, equalTo("a"));
- }
-
- @Test
- public void twoAddedPropertySourcesAreUsed() {
- PropertySource sourceOne = mock(PropertySource.class, NOT_MOCKED_ANSWER);
-
- doReturn("one").when(sourceOne).getName();
- doReturn(PropertyValue.of("keyOfA","b", "test")).when(sourceOne).get("keyOfA");
- doReturn(10).when(sourceOne).getOrdinal();
-
- PropertySource sourceTwo = mock(PropertySource.class, NOT_MOCKED_ANSWER);
- doReturn("two").when(sourceTwo).getName();
- doReturn(PropertyValue.of("keyOfA","a", "test")).when(sourceTwo).get("keyOfA");
- doReturn(10).when(sourceTwo).getOrdinal();
-
- ConfigurationBuilder builder = new ConfigurationBuilder().addPropertySources(sourceOne)
- .addPropertySources(sourceTwo);
-
- Configuration config = builder.build();
-
- String valueOfA = config.get("keyOfA");
-
- assertThat(valueOfA, notNullValue());
- assertThat(valueOfA, equalTo("a"));
- }
-
- @Ignore
- @Test(expected = ConfigException.class)
- public void twoPropertySourcesSamePrioritySameKey() {
- PropertySource sourceOne = mock(PropertySource.class, NOT_MOCKED_ANSWER);
-
- doReturn("one").when(sourceOne).getName();
- doReturn("b").when(sourceOne).get("keyOfA");
- doReturn(20).when(sourceOne).getOrdinal();
-
- PropertySource sourceTwo = mock(PropertySource.class, NOT_MOCKED_ANSWER);
- doReturn("two").when(sourceTwo).getName();
- doReturn("a").when(sourceTwo).get("keyOfA");
- doReturn(20).when(sourceTwo).getOrdinal();
-
- ConfigurationBuilder builder = new ConfigurationBuilder().addPropertySources(sourceOne)
- .addPropertySources(sourceTwo);
-
- Configuration config = builder.build();
-
- config.get("keyOfA");
- }
-
- @Test
- public void twoPropertySourcesDiffPrioritySameKeyLowerAddedFirst() {
- PropertySource sourceOne = mock(PropertySource.class, NOT_MOCKED_ANSWER);
-
- doReturn("one").when(sourceOne).getName();
- doReturn(PropertyValue.of("keyOfA","b", "test")).when(sourceOne).get("keyOfA");
- doReturn(10).when(sourceOne).getOrdinal();
-
- PropertySource sourceTwo = mock(PropertySource.class, NOT_MOCKED_ANSWER);
- doReturn("two").when(sourceTwo).getName();
- doReturn(PropertyValue.of("keyOfA","a", "test")).when(sourceTwo).get("keyOfA");
- doReturn(20).when(sourceTwo).getOrdinal();
-
- ConfigurationBuilder builder = new ConfigurationBuilder().addPropertySources(sourceOne)
- .addPropertySources(sourceTwo);
-
- Configuration config = builder.build();
-
- String valueOfA = config.get("keyOfA");
-
- assertThat(valueOfA, notNullValue());
- assertThat(valueOfA, equalTo("a"));
- }
-
- @Test
- public void twoPropertySourcesDiffPrioritySameKeyHigherAddedFirst() {
- PropertySource sourceOne = mock(PropertySource.class, NOT_MOCKED_ANSWER);
-
- doReturn("one").when(sourceOne).getName();
- doReturn(PropertyValue.of("keyOfA","b", "test")).when(sourceOne).get("keyOfA");
- doReturn(30).when(sourceOne).getOrdinal();
-
- PropertySource sourceTwo = mock(PropertySource.class, NOT_MOCKED_ANSWER);
- doReturn("two").when(sourceTwo).getName();
- doReturn(PropertyValue.of("keyOfA","a", "test")).when(sourceTwo).get("keyOfA");
- doReturn(20).when(sourceTwo).getOrdinal();
-
- ConfigurationBuilder builder = new ConfigurationBuilder().addPropertySources(sourceOne, sourceTwo);
-
- Configuration config = builder.build();
-
- String valueOfA = config.get("keyOfA");
-
- assertThat(valueOfA, notNullValue());
- assertThat(valueOfA, equalTo("b"));
- }
-
- @Test
- public void consecutiveCallsToAddPropertySourceArePossible() {
- PropertySource sourceOne = mock(PropertySource.class, NOT_MOCKED_ANSWER);
-
- doReturn("one").when(sourceOne).getName();
- doReturn(null).when(sourceOne).get(anyString());
- doReturn(PropertyValue.of("b","b", "test")).when(sourceOne).get("b");
- doReturn(30).when(sourceOne).getOrdinal();
-
- PropertySource sourceTwo = mock(PropertySource.class, NOT_MOCKED_ANSWER);
- doReturn("two").when(sourceTwo).getName();
- doReturn(null).when(sourceTwo).get(anyString());
- doReturn(PropertyValue.of("a","a", "test")).when(sourceTwo).get("a");
- doReturn(30).when(sourceTwo).getOrdinal();
-
- ConfigurationBuilder builder = new ConfigurationBuilder().addPropertySources(sourceOne)
- .addPropertySources(sourceTwo);
-
- Configuration config = builder.build();
-
- assertThat(config.get("b"), equalTo("b"));
- assertThat(config.get("a"), equalTo("a"));
- }
-
- @Test
- public void addMultiplePropertySourcesWhereOneIsNull() {
- PropertySource sourceOne = mock(PropertySource.class, NOT_MOCKED_ANSWER);
-
- doReturn("one").when(sourceOne).getName();
- doReturn(null).when(sourceOne).get(anyString());
- doReturn(PropertyValue.of("b","b", "test")).when(sourceOne).get("b");
- doReturn(30).when(sourceOne).getOrdinal();
-
- PropertySource sourceTwo = mock(PropertySource.class, NOT_MOCKED_ANSWER);
- doReturn("two").when(sourceTwo).getName();
- doReturn(null).when(sourceTwo).get(anyString());
- doReturn(PropertyValue.of("a","a", "test")).when(sourceTwo).get("a");
- doReturn(30).when(sourceTwo).getOrdinal();
-
- ConfigurationBuilder builder = new ConfigurationBuilder().addPropertySources(sourceOne, null, sourceTwo);
-
- Configuration config = builder.build();
-
- assertThat(config.get("b"), equalTo("b"));
- assertThat(config.get("a"), equalTo("a"));
- }
-
- /**
- * ******************************************************************
- * Tests for adding P r o p e r t y C o n v e r t e r
- */
-
- @Test(expected = NullPointerException.class)
- public void canNotAddNullPropertyConverter() {
- ConfigurationBuilder builder = new ConfigurationBuilder();
-
- builder.addPropertyConverter(TypeLiteral.of(CustomTypeA.class), null);
- }
-
- @Test(expected = NullPointerException.class)
- public void canNotAddNullTypeLiteralButPropertyConverter() {
- ConfigurationBuilder builder = new ConfigurationBuilder();
- builder.addPropertyConverter((TypeLiteral)null,
- new PropertyConverter() {
- @Override
- public CustomTypeA convert(final String prop, ConversionContext context) {
- return new CustomTypeA(prop, prop);
- }
- });
- }
-
- @Test
- public void addedPropertyConverterWithTypeLiteralIsUsedByConfiguration() {
- PropertySource source = mock(PropertySource.class, NOT_MOCKED_ANSWER);
-
- doReturn("source").when(source).getName();
- doReturn(PropertyValue.of("key","A", "test")).when(source).get("key");
- doReturn(100).when(source).getOrdinal();
-
- ConfigurationBuilder builder = new ConfigurationBuilder();
-
- builder.addPropertyConverter(TypeLiteral.of(CustomTypeA.class),
- new PropertyConverter() {
- @Override
- public CustomTypeA convert(final String prop, ConversionContext context) {
- return new CustomTypeA(prop, prop);
- }
- });
- builder.addPropertySources(source);
-
- Configuration config = builder.build();
-
- Object resultRaw = config.get("key", CustomTypeA.class);
-
- assertThat(resultRaw, CoreMatchers.notNullValue());
-
- CustomTypeA result = (CustomTypeA)resultRaw;
-
- assertThat(result.getName(), equalTo("AA"));
- }
-
- @Test
- public void addedPropertyConverterWithClassIsUsedByConfiguration() {
- PropertySource source = mock(PropertySource.class, NOT_MOCKED_ANSWER);
-
- doReturn("source").when(source).getName();
- doReturn(PropertyValue.of("key","A", "test")).when(source).get("key");
- doReturn(100).when(source).getOrdinal();
-
- ConfigurationBuilder builder = new ConfigurationBuilder();
-
- builder.addPropertyConverter(TypeLiteral.of(CustomTypeA.class),
- new PropertyConverter() {
- @Override
- public CustomTypeA convert(final String prop, ConversionContext context) {
- return new CustomTypeA(prop, prop);
- }
- });
- builder.addPropertySources(source);
-
- Configuration config = builder.build();
-
- Object resultRaw = config.get("key", CustomTypeA.class);
-
- assertThat(resultRaw, CoreMatchers.notNullValue());
-
- CustomTypeA result = (CustomTypeA)resultRaw;
-
- assertThat(result.getName(), equalTo("AA"));
- }
-
- @Test
- public void canGetAndConvertPropertyViaOfMethod() {
- PropertySource source = mock(PropertySource.class, NOT_MOCKED_ANSWER);
-
- doReturn("source").when(source).getName();
- doReturn(PropertyValue.of("key","A", "test")).when(source).get("key");
- doReturn(100).when(source).getOrdinal();
-
- ConfigurationBuilder builder = new ConfigurationBuilder();
-
- builder.addPropertySources(source);
-
- Configuration config = builder.build();
-
- Object resultRaw = config.get("key", CustomTypeB.class);
-
- assertThat(resultRaw, CoreMatchers.notNullValue());
-
- CustomTypeB result = (CustomTypeB)resultRaw;
-
- assertThat(result.getName(), equalTo("A"));
- }
-
- /*********************************************************************
- * Tests for adding P r o p e r t y F i l t e r
- */
-
- @Test(expected = NullPointerException.class)
- public void canNotAddNullAsPropertyFilter() {
- ConfigurationBuilder builder = new ConfigurationBuilder();
- builder.addPropertyFilters((PropertyFilter[])null);
- }
-
- @Test
- public void canAddNonSPIPropertyFilter() {
- PropertySource source = mock(PropertySource.class, NOT_MOCKED_ANSWER);
-
- doReturn(PropertyValue.of("key","M", "test")).when(source).get("key");
- doReturn("source").when(source).getName();
-
- ConfigurationBuilder builder = new ConfigurationBuilder();
-
- Configuration config = builder.addPropertySources(source)
- .addPropertyFilters(new TestANonSPIPropertyFilter())
- .build();
-
- String property = config.get("key");
-
- assertThat(property, CoreMatchers.notNullValue());
- assertThat(property, CoreMatchers.containsString("ABC"));
- }
-
- @Test
- public void canAddNonSPIPropertyFiltersViaConsecutiveCalls() {
- PropertySource source = mock(PropertySource.class, NOT_MOCKED_ANSWER);
-
- doReturn(PropertyValue.of("key","M", "test")).when(source).get("key");
- doReturn("source").when(source).getName();
-
- ConfigurationBuilder builder = new ConfigurationBuilder();
-
- Configuration config = builder.addPropertySources(source)
- .addPropertyFilters(new TestANonSPIPropertyFilter())
- .addPropertyFilters(new TestBNonSPIPropertyFilter())
- .build();
-
- String property = config.get("key");
-
- assertThat(property, CoreMatchers.notNullValue());
- assertThat(property, CoreMatchers.containsString("ABC"));
- assertThat(property, CoreMatchers.containsString("XYZ"));
- }
-
- @Test
- public void canAddMultipleNonSPIPropertyFiltersWhileOneIsNull() {
- PropertySource source = mock(PropertySource.class, NOT_MOCKED_ANSWER);
-
- doReturn(PropertyValue.of("key","M", "test")).when(source).get("key");
- doReturn("source").when(source).getName();
-
- ConfigurationBuilder builder = new ConfigurationBuilder();
-
- Configuration config = builder.addPropertySources(source)
- .addPropertyFilters(new TestANonSPIPropertyFilter(),
- null,
- new TestBNonSPIPropertyFilter())
- .build();
-
- String property = config.get("key");
-
- assertThat(property, CoreMatchers.notNullValue());
- assertThat(property, CoreMatchers.containsString("ABC"));
- assertThat(property, CoreMatchers.containsString("XYZ"));
- }
-
- @Test
- public void overhandedNullPropertyFilterIsSafelyHandled() {
- PropertySource source = mock(PropertySource.class, NOT_MOCKED_ANSWER);
-
- doReturn(PropertyValue.of("key","M", "test")).when(source).get("key");
- doReturn("source").when(source).getName();
-
- ConfigurationBuilder builder = new ConfigurationBuilder();
-
- Configuration config = builder.addPropertySources(source)
- .addPropertyFilters((PropertyFilter)null) // The cast is needed!
- .addPropertyFilters(new TestBNonSPIPropertyFilter())
- .build();
-
- String property = config.get("key");
-
- assertThat(property, CoreMatchers.notNullValue());
- assertThat(property, CoreMatchers.containsString("XYZ"));
- }
-
- @Test
- public void canAddMultipleNonSPIPropertyFilter() {
- PropertySource source = mock(PropertySource.class, NOT_MOCKED_ANSWER);
-
- doReturn(PropertyValue.of("key","M", "test")).when(source).get("key");
- doReturn("source").when(source).getName();
-
- ConfigurationBuilder builder = new ConfigurationBuilder();
-
- Configuration config = builder.addPropertySources(source)
- .addPropertyFilters(new TestANonSPIPropertyFilter(),
- new TestBNonSPIPropertyFilter())
- .build();
-
- String property = config.get("key");
-
- assertThat(property, CoreMatchers.notNullValue());
- assertThat(property, CoreMatchers.containsString("ABC"));
- assertThat(property, CoreMatchers.containsString("XYZ"));
- }
-
- /*********************************************************************
- * Tests for adding
- * P r o p e r t y S o u r c e P r o v i d e r s
- */
-
- @Test
- public void handlesSafelyPropertyProviderReturningNullInsteadOfPropertySource() {
- PropertySourceProvider nullReturning = mock(PropertySourceProvider.class, NOT_MOCKED_ANSWER);
-
- doReturn(asList((PropertySource)null)).when(nullReturning).getPropertySources();
-
- ConfigurationBuilder builder = new ConfigurationBuilder();
-
- Configuration config = builder.addPropertySourceProviders(new TestPropertySourceProviderB(),
- nullReturning,
- new TestPropertySourceProvider())
- .build();
-
- assertThat(config.get("tpsp_a"), Matchers.equalTo("A"));
- assertThat(config.get("tpsp_b"), Matchers.equalTo("B"));
- assertThat(config.get("tpsp_x"), Matchers.equalTo("X"));
- assertThat(config.get("tpsp_y"), Matchers.equalTo("Y"));
-
- verify(nullReturning).getPropertySources();
- }
-
- @Test(expected = NullPointerException.class)
- public void cannotAddNullAsPropertyProvider() {
- new ConfigurationBuilder().addPropertySourceProviders((PropertySourceProvider[])null);
- }
-
- @Test
- public void canAddMultipleNonSPIPropertySourceProviders() {
- ConfigurationBuilder builder = new ConfigurationBuilder();
-
- Configuration config = builder.addPropertySourceProviders(new TestPropertySourceProviderB(),
- new TestPropertySourceProvider())
- .build();
-
- assertThat(config.get("tpsp_a"), Matchers.equalTo("A"));
- assertThat(config.get("tpsp_b"), Matchers.equalTo("B"));
- assertThat(config.get("tpsp_x"), Matchers.equalTo("X"));
- assertThat(config.get("tpsp_y"), Matchers.equalTo("Y"));
- }
-
- @Test
- public void canAddMultipleNonSPIPropertySourceProvidersWhileOfOfThemIsNull() {
- ConfigurationBuilder builder = new ConfigurationBuilder();
-
- Configuration config = builder.addPropertySourceProviders(new TestPropertySourceProviderB(), null,
- new TestPropertySourceProvider())
- .build();
-
- assertThat(config.get("tpsp_a"), Matchers.equalTo("A"));
- assertThat(config.get("tpsp_b"), Matchers.equalTo("B"));
- assertThat(config.get("tpsp_x"), Matchers.equalTo("X"));
- assertThat(config.get("tpsp_y"), Matchers.equalTo("Y"));
- }
-
-
- /*
- * Tests for adding
- * P r o p e r t y V a l u e C o m b i n a t i o n P o l i c y
- */
-
- // @todo TAYAMA-60 Write more tests
-
- /*********************************************************************
- * Tests for enabling and disabling of automatic loading of
- * P r o p e r t y S o u r c e s
- */
-
- @Test
- public void enablingOfProvidedPropertySourceServiceProvidersIsOk() {
- ConfigurationBuilder builder = new ConfigurationBuilder();
-
- builder.disableProvidedPropertyConverters()
- .enableProvidedPropertyConverters();
-
- assertThat(builder.isPropertyConverterLoadingEnabled(), is(true));
- }
-
- @Test
- public void disablingOfProvidedPropertySourceServiceProvidersIsOk() {
- ConfigurationBuilder builder = new ConfigurationBuilder();
-
- builder.enableProvidedPropertyConverters()
- .disableProvidedPropertyConverters();
-
- assertThat(builder.isPropertyConverterLoadingEnabled(), is(false));
- }
-
- @Test(expected = ConfigException.class)
- public void loadingOrPropertyConvertersCanBeDisabled() {
- PropertySource source = mock(PropertySource.class, NOT_MOCKED_ANSWER);
-
- doReturn("source").when(source).getName();
- doReturn(PropertyValue.of("key","A", "test")).when(source).get("key");
- doReturn(100).when(source).getOrdinal();
-
- ConfigurationBuilder builder = new ConfigurationBuilder().addPropertySources(source)
- .enableProvidedPropertyConverters()
- .disableProvidedPropertyConverters();
-
- Configuration config = builder.build();
-
- config.get("key", CustomTypeC.class);
- }
-
- @Test
- public void loadingOfPropertyConvertersCanBeEnabled() {
- PropertySource source = mock(PropertySource.class, NOT_MOCKED_ANSWER);
-
- doReturn("source").when(source).getName();
- doReturn(PropertyValue.of("key","A", "test")).when(source).get("key");
- doReturn(100).when(source).getOrdinal();
-
- ConfigurationBuilder builder = new ConfigurationBuilder().addPropertySources(source)
- .disableProvidedPropertyConverters()
- .enableProvidedPropertyConverters();
-
- Configuration config = builder.build();
-
- CustomTypeC result = config.get("key", CustomTypeC.class);
-
- assertThat(result, notNullValue());
- assertThat(result.getValue(), equalTo("A"));
- }
-
- /*********************************************************************
- * Tests for enabling and disabling of automatic loading of
- * P r o p e r t y S o u r c e s
- */
-
- @Test
- public void enablingOfPropertySourceLoadingIsOk() {
- ConfigurationBuilder builder = new ConfigurationBuilder();
-
- builder.disableProvidedPropertySources()
- .enableProvidedPropertySources();
-
- assertThat(builder.isPropertySourcesLoadingEnabled(), is(true));
- }
-
- @Test
- public void disablingPropertySourceLoadingIsOk() {
- ConfigurationBuilder builder = new ConfigurationBuilder();
-
- builder.enableProvidedPropertySources()
- .disableProvidedPropertySources();
-
- assertThat(builder.isPropertySourcesLoadingEnabled(), is(false));
- }
-
- @Test
- public void loadingOfPropertySourcesCanBeEnabled() {
- ConfigurationBuilder builder = new ConfigurationBuilder();
-
- Configuration config = builder.disableProvidedPropertySources()
- .enableProvidedPropertySources()
- .build();
-
-
- assertThat(builder.isPropertySourcesLoadingEnabled(), is(true));
- assertThat(config.get("tps_a"), Matchers.equalTo("A"));
- }
-
- @Test
- public void loadingOfPropertySourcesCanBeDisabled() {
- ConfigurationBuilder builder = new ConfigurationBuilder();
-
- Configuration config = builder.enableProvidedPropertySources()
- .disableProvidedPropertySources()
- .build();
-
-
- assertThat(builder.isPropertySourcesLoadingEnabled(), is(false));
- assertThat(config.get("tps_c"), Matchers.nullValue());
- }
-
- /*********************************************************************
- * Tests for enabling and disabling of automatic loading of
- * P r o p e r t y F i l t e r s
- */
-
- @Test
- public void enablingOfPropertyFiltersLoadingIsOk() {
- PropertySource source = mock(PropertySource.class, NOT_MOCKED_ANSWER);
-
- doReturn("source").when(source).getName();
- doReturn(PropertyValue.of("key","A", "test")).when(source).get("key");
- doReturn(100).when(source).getOrdinal();
-
- ConfigurationBuilder builder = new ConfigurationBuilder();
-
- Configuration config = builder.disableProvidedPropertyFilters()
- .enabledProvidedPropertyFilters()
- .addPropertySources(source)
- .build();
-
- String property = config.get("key");
-
- assertThat(property, CoreMatchers.notNullValue());
- assertThat(property, Matchers.equalTo("AinBerlin"));
- }
-
- @Test
- public void disablingOfPropertyFiltersLoadingIsOk() {
- ConfigurationBuilder builder = new ConfigurationBuilder();
-
- builder.enabledProvidedPropertyFilters()
- .disableProvidedPropertyFilters();
-
- assertThat(builder.isPropertyFilterLoadingEnabled(), is(false));
- }
-
- @Test
- public void loadingOfPropertyFiltersCanBeDisabled() {
- ConfigurationBuilder builder = new ConfigurationBuilder();
-
- builder.disableProvidedPropertyFilters()
- .enabledProvidedPropertyFilters();
-
- assertThat(builder.isPropertyFilterLoadingEnabled(), is(true));
- }
-
- @Test
- public void loadingOfPropertyFiltersCanBeEnabled() {
- PropertySource source = mock(PropertySource.class, NOT_MOCKED_ANSWER);
-
- doReturn("source").when(source).getName();
- doReturn(PropertyValue.of("key","A", "test")).when(source).get("key");
- doReturn(100).when(source).getOrdinal();
-
- ConfigurationBuilder builder = new ConfigurationBuilder();
-
- Configuration config = builder.enabledProvidedPropertyFilters()
- .disableProvidedPropertyFilters()
- .addPropertySources(source)
- .build();
-
- String property = config.get("key");
-
- assertThat(property, CoreMatchers.notNullValue());
- assertThat(property, Matchers.equalTo("A"));
- }
-
- /*********************************************************************
- * Tests for enabling and disabling of automatic loading of
- * P r o p e r t y S o u r c e P r o v i d e r s
- */
-
- @Test
- public void disablingOfPropertySourceProvidersIsOk() {
- ConfigurationBuilder builder = new ConfigurationBuilder();
-
- builder.enableProvidedPropertySourceProviders()
- .disableProvidedPropertySourceProviders()
- .build();
-
- assertThat(builder.isPropertySourceProvidersLoadingEnabled(), is(false));
- }
-
- @Test
- public void enablingOfPropertySourceProvidersIsOk() {
-
- ConfigurationBuilder builder = new ConfigurationBuilder();
-
- builder.disableProvidedPropertySourceProviders()
- .enableProvidedPropertySourceProviders()
- .build();
-
- assertThat(builder.isPropertySourceProvidersLoadingEnabled(), is(true));
- }
-
- @Test
- public void loadingOfPropertySourceProvidersCanBeEnabled() {
- ConfigurationBuilder builder = new ConfigurationBuilder();
-
- Configuration config = builder.disableProvidedPropertySourceProviders()
- .enableProvidedPropertySourceProviders()
- .build();
-
- assertThat(builder.isPropertySourceProvidersLoadingEnabled(), is(true));
- assertThat(config.get("tpsp_x"), Matchers.equalTo("X"));
- assertThat(config.get("tpsp_y"), Matchers.equalTo("Y"));
- }
-
- @Test
- public void loadingOfPropertySourceProvidersCanBeDisabled() {
- ConfigurationBuilder builder = new ConfigurationBuilder();
-
- Configuration config = builder.enableProvidedPropertySourceProviders()
- .disableProvidedPropertySourceProviders()
- .build();
-
- assertThat(builder.isPropertySourceProvidersLoadingEnabled(), is(false));
- assertThat(config.get("tpsp_x"), nullValue());
- assertThat(config.get("tpsp_x"), nullValue());
- }
-
- @Test(expected = ConfigException.class)
- public void ioExceptionIsTurnedInConfigExceptionWhenLoadingResourceViaURL() throws Exception {
- URL resource = this.getClass().getResource("/configfiles/json/simple.json");
-
- assertThat(resource, CoreMatchers.notNullValue());
-
- ConfigurationBuilder builder = mock(ConfigurationBuilder.class, CALLS_REAL_METHODS);
-
- doThrow(IOException.class).when(builder).getConfigurationDataFromURL(Mockito.eq(resource));
-
- builder.addPropertySource(resource).build();
- }
-
- /*********************************************************************
- * Tests for loading resources via URL (as String)
- */
-
- @Test(expected = ConfigException.class)
- public void tryToLoadOneUnsupportedPropertySourceViaStringURL() {
- URL resource = this.getClass().getResource("/configfiles/other/simple.oml");
-
- assertThat(resource, CoreMatchers.notNullValue());
-
- ConfigurationBuilder builder = new ConfigurationBuilder();
-
- builder.addPropertySources(resource.toString()).build();
- }
-
- @Test
- public void loadOneJSONPropertySourceViaStringURL() {
- URL resource = this.getClass().getResource("/configfiles/json/simple.json");
-
- assertThat(resource, CoreMatchers.notNullValue());
-
- ConfigurationBuilder builder = new ConfigurationBuilder();
-
- Configuration config = builder.addPropertySources(resource.toString())
- .build();
-
- assertThat(config, CoreMatchers.notNullValue());
- assertThat(config.get("a"), equalTo("A"));
- assertThat(config.get("b"), equalTo("B"));
- }
-
- @Test
- public void loadMultipleJSONPropertySourceViaStringURL() {
- URL first = this.getClass().getResource("/configfiles/json/first.json");
- URL second = this.getClass().getResource("/configfiles/json/second.json");
- URL third = this.getClass().getResource("/configfiles/json/third.json");
-
- assertThat(first, CoreMatchers.notNullValue());
- assertThat(second, CoreMatchers.notNullValue());
- assertThat(third, CoreMatchers.notNullValue());
-
- ConfigurationBuilder builder = new ConfigurationBuilder();
-
- Configuration config = builder.addPropertySources(first.toString(), second.toString(),
- null, third.toString())
- .build();
-
- assertThat(config, CoreMatchers.notNullValue());
-
- // from first.json
- assertThat(config.get("d"), equalTo("D"));
- assertThat(config.get("e"), equalTo("E"));
-
- // from second.json
- assertThat(config.get("m"), equalTo("M"));
- assertThat(config.get("n"), equalTo("N"));
-
- // from thrid.json
- assertThat(config.get("p"), equalTo("P"));
- assertThat(config.get("q"), equalTo("Q"));
- }
-
- /**
- * ******************************************************************
- * Tests for loading resources via URL (as URL object)
- */
-
- @Test
- public void loadOneJSONPropertySourceViaURL() {
- URL resource = this.getClass().getResource("/configfiles/json/simple.json");
-
- assertThat(resource, CoreMatchers.notNullValue());
-
- ConfigurationBuilder builder = new ConfigurationBuilder();
-
- Configuration config = builder.addPropertySource(resource)
- .build();
-
- assertThat(config, CoreMatchers.notNullValue());
- assertThat(config.get("a"), equalTo("A"));
- assertThat(config.get("b"), equalTo("B"));
- }
-
- @Test
- public void loadMultipleJSONPropertySourceViaURL() {
- URL first = this.getClass().getResource("/configfiles/json/first.json");
- URL second = this.getClass().getResource("/configfiles/json/second.json");
- URL third = this.getClass().getResource("/configfiles/json/third.json");
-
- assertThat(first, CoreMatchers.notNullValue());
- assertThat(second, CoreMatchers.notNullValue());
- assertThat(third, CoreMatchers.notNullValue());
-
- ConfigurationBuilder builder = new ConfigurationBuilder();
-
- Configuration config = builder.addPropertySources(first, second,
- null, third)
- .build();
-
- assertThat(config, CoreMatchers.notNullValue());
-
- // from first.json
- assertThat(config.get("d"), equalTo("D"));
- assertThat(config.get("e"), equalTo("E"));
-
- // from second.json
- assertThat(config.get("m"), equalTo("M"));
- assertThat(config.get("n"), equalTo("N"));
-
- // from thrid.json
- assertThat(config.get("p"), equalTo("P"));
- assertThat(config.get("q"), equalTo("Q"));
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/f45a5bb5/src/test/java/org/apache/tamaya/builder/TestANonSPIPropertyFilter.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/tamaya/builder/TestANonSPIPropertyFilter.java b/src/test/java/org/apache/tamaya/builder/TestANonSPIPropertyFilter.java
deleted file mode 100644
index 896e0bc..0000000
--- a/src/test/java/org/apache/tamaya/builder/TestANonSPIPropertyFilter.java
+++ /dev/null
@@ -1,35 +0,0 @@
-/*
- * 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.builder;
-
-import org.apache.tamaya.spi.FilterContext;
-import org.apache.tamaya.spi.PropertyFilter;
-
-public class TestANonSPIPropertyFilter implements PropertyFilter {
- @Override
- public String filterProperty(String value, FilterContext context) {
- String result = value;
-
- if (!result.contains(("ABC"))) {
- result = value + "ABC";
- }
-
- return result;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/f45a5bb5/src/test/java/org/apache/tamaya/builder/TestBNonSPIPropertyFilter.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/tamaya/builder/TestBNonSPIPropertyFilter.java b/src/test/java/org/apache/tamaya/builder/TestBNonSPIPropertyFilter.java
deleted file mode 100644
index a9c0ac2..0000000
--- a/src/test/java/org/apache/tamaya/builder/TestBNonSPIPropertyFilter.java
+++ /dev/null
@@ -1,35 +0,0 @@
-/*
- * 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.builder;
-
-import org.apache.tamaya.spi.FilterContext;
-import org.apache.tamaya.spi.PropertyFilter;
-
-public class TestBNonSPIPropertyFilter implements PropertyFilter {
- @Override
- public String filterProperty(String value, FilterContext context) {
- String result = value;
-
- if (!result.contains(("XYZ"))) {
- result = value + "XYZ";
- }
-
- return result;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/f45a5bb5/src/test/java/org/apache/tamaya/builder/TestPropertyFilter.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/tamaya/builder/TestPropertyFilter.java b/src/test/java/org/apache/tamaya/builder/TestPropertyFilter.java
deleted file mode 100644
index e22fca8..0000000
--- a/src/test/java/org/apache/tamaya/builder/TestPropertyFilter.java
+++ /dev/null
@@ -1,35 +0,0 @@
-/*
- * 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.builder;
-
-import org.apache.tamaya.spi.FilterContext;
-import org.apache.tamaya.spi.PropertyFilter;
-
-public class TestPropertyFilter implements PropertyFilter {
- @Override
- public String filterProperty(String value, FilterContext context) {
- String result = value;
-
- if (!result.contains(("inBerlin"))) {
- result = value + "inBerlin";
- }
-
- return result;
- }
-}
[28/50] [abbrv] incubator-tamaya-sandbox git commit: Fixed dangling
Javadoc comments.
Posted by pl...@apache.org.
Fixed dangling Javadoc comments.
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/446ff2ae
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/tree/446ff2ae
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/diff/446ff2ae
Branch: refs/heads/master
Commit: 446ff2ae4f76adce82f2f013d33aebdc2b050b0f
Parents: 2b52e65
Author: Oliver B. Fischer <pl...@apache.org>
Authored: Tue Dec 22 09:39:38 2015 +0100
Committer: Oliver B. Fischer <pl...@apache.org>
Committed: Tue Dec 22 09:39:38 2015 +0100
----------------------------------------------------------------------
.../java/org/apache/tamaya/builder/ConfigurationBuilderTest.java | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/446ff2ae/src/test/java/org/apache/tamaya/builder/ConfigurationBuilderTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/tamaya/builder/ConfigurationBuilderTest.java b/src/test/java/org/apache/tamaya/builder/ConfigurationBuilderTest.java
index 023fb27..d48fe08 100644
--- a/src/test/java/org/apache/tamaya/builder/ConfigurationBuilderTest.java
+++ b/src/test/java/org/apache/tamaya/builder/ConfigurationBuilderTest.java
@@ -537,7 +537,7 @@ public class ConfigurationBuilderTest {
}
- /*********************************************************************
+ /*
* Tests for adding
* P r o p e r t y V a l u e C o m b i n a t i o n P o l i c y
*/
[34/50] [abbrv] incubator-tamaya-sandbox git commit: Update Hamcrest
(1.3 -> 2.0.0.0)
Posted by pl...@apache.org.
Update Hamcrest (1.3 -> 2.0.0.0)
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/d5a45e7f
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/tree/d5a45e7f
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/diff/d5a45e7f
Branch: refs/heads/master
Commit: d5a45e7f812a67dd7a815cfc0648bc263eafb4bb
Parents: 1f67dc5
Author: Oliver B. Fischer <pl...@apache.org>
Authored: Sun Feb 14 21:12:56 2016 +0100
Committer: Oliver B. Fischer <pl...@apache.org>
Committed: Sun Feb 14 21:12:56 2016 +0100
----------------------------------------------------------------------
pom.xml | 9 ++-------
1 file changed, 2 insertions(+), 7 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/d5a45e7f/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index c7da3f8..32dc6b5 100644
--- a/pom.xml
+++ b/pom.xml
@@ -66,14 +66,9 @@ under the License.
<scope>test</scope>
</dependency>
-
- <dependency>
- <groupId>org.hamcrest</groupId>
- <artifactId>hamcrest-library</artifactId>
- </dependency>
<dependency>
<groupId>org.hamcrest</groupId>
- <artifactId>hamcrest-core</artifactId>
+ <artifactId>java-hamcrest</artifactId>
</dependency>
<dependency>
@@ -106,4 +101,4 @@ under the License.
</plugins>
</build -->
-</project>
\ No newline at end of file
+</project>
[23/50] [abbrv] incubator-tamaya-sandbox git commit: TAMAYA-113:
Remove Java 8 related parts - added JDK8 flags where necessary,
fixed some tests/examples using Java8 APIs, checked built.
Posted by pl...@apache.org.
TAMAYA-113: Remove Java 8 related parts - added JDK8 flags where necessary, fixed some tests/examples using Java8 APIs, checked built.
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/89e97b11
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/tree/89e97b11
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/diff/89e97b11
Branch: refs/heads/master
Commit: 89e97b1192db3fba58d227faab1fa61ac6e7deca
Parents: 24bb6c6
Author: anatole <an...@apache.org>
Authored: Tue Sep 29 09:00:46 2015 +0200
Committer: anatole <an...@apache.org>
Committed: Tue Sep 29 09:00:46 2015 +0200
----------------------------------------------------------------------
pom.xml | 4 ++++
.../tamaya/builder/ProgrammaticConfigurationContext.java | 9 ++++-----
.../java/org/apache/tamaya/builder/TestPropertySource.java | 4 ++--
.../apache/tamaya/builder/TestPropertySourceProvider.java | 5 +++--
.../apache/tamaya/builder/TestPropertySourceProviderB.java | 5 +++--
5 files changed, 16 insertions(+), 11 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/89e97b11/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index 5912c2c..a078f79 100644
--- a/pom.xml
+++ b/pom.xml
@@ -31,6 +31,10 @@ under the License.
<inceptionYear>2015</inceptionYear>
+ <properties>
+ <jdkVersion>1.8</jdkVersion>
+ </properties>
+
<dependencies>
<dependency>
<groupId>org.apache.tamaya</groupId>
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/89e97b11/src/main/java/org/apache/tamaya/builder/ProgrammaticConfigurationContext.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/tamaya/builder/ProgrammaticConfigurationContext.java b/src/main/java/org/apache/tamaya/builder/ProgrammaticConfigurationContext.java
index d867c3e..b333986 100644
--- a/src/main/java/org/apache/tamaya/builder/ProgrammaticConfigurationContext.java
+++ b/src/main/java/org/apache/tamaya/builder/ProgrammaticConfigurationContext.java
@@ -28,7 +28,7 @@ import org.apache.tamaya.spi.PropertyFilter;
import org.apache.tamaya.spi.PropertySource;
import org.apache.tamaya.spi.PropertySourceProvider;
import org.apache.tamaya.spi.PropertyValueCombinationPolicy;
-import org.apache.tamaya.spi.ServiceContext;
+import org.apache.tamaya.spi.ServiceContextManager;
import javax.annotation.Priority;
import java.util.ArrayList;
@@ -128,7 +128,7 @@ class ProgrammaticConfigurationContext implements ConfigurationContext {
private List<PropertyFilter> getPropertyFilters(Builder builder) {
List<PropertyFilter> provided = builder.loadProvidedPropertyFilters
- ? ServiceContext.getInstance().getServices(PropertyFilter.class)
+ ? ServiceContextManager.getServiceContext().getServices(PropertyFilter.class)
: new ArrayList<>(0);
List<PropertyFilter> configured = builder.propertyFilters;
@@ -139,11 +139,11 @@ class ProgrammaticConfigurationContext implements ConfigurationContext {
private List<PropertySource> getAllPropertySources(Builder builder) {
List<PropertySource> provided = builder.loadProvidedPropertySources
- ? ServiceContext.getInstance().getServices(PropertySource.class)
+ ? ServiceContextManager.getServiceContext().getServices(PropertySource.class)
: new ArrayList<>(0);
if (builder.loadProvidedPropertySourceProviders) {
- List<PropertySourceProvider> providers = ServiceContext.getInstance()
+ List<PropertySourceProvider> providers = ServiceContextManager.getServiceContext()
.getServices(PropertySourceProvider.class);
for (PropertySourceProvider provider : providers) {
Collection<PropertySource> sources = provider.getPropertySources();
@@ -260,7 +260,6 @@ class ProgrammaticConfigurationContext implements ConfigurationContext {
throw new RuntimeException("This method is currently not supported.");
}
- @Override
public Collection<PropertySource> getPropertySources(Predicate<PropertySource> selector) {
// @todo Check if it could be useful to support this method, Oliver B. Fischer
throw new RuntimeException("This method is currently not supported.");
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/89e97b11/src/test/java/org/apache/tamaya/builder/TestPropertySource.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/tamaya/builder/TestPropertySource.java b/src/test/java/org/apache/tamaya/builder/TestPropertySource.java
index 54deca3..e30c244 100644
--- a/src/test/java/org/apache/tamaya/builder/TestPropertySource.java
+++ b/src/test/java/org/apache/tamaya/builder/TestPropertySource.java
@@ -18,14 +18,14 @@
*/
package org.apache.tamaya.builder;
+import org.apache.tamaya.core.propertysource.BasePropertySource;
import org.apache.tamaya.spi.PropertySource;
import java.util.Collections;
import java.util.Hashtable;
import java.util.Map;
-public class TestPropertySource
- implements PropertySource
+public class TestPropertySource extends BasePropertySource
{
private Map<String, String> properties;
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/89e97b11/src/test/java/org/apache/tamaya/builder/TestPropertySourceProvider.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/tamaya/builder/TestPropertySourceProvider.java b/src/test/java/org/apache/tamaya/builder/TestPropertySourceProvider.java
index 4e7db79..0dcd68c 100644
--- a/src/test/java/org/apache/tamaya/builder/TestPropertySourceProvider.java
+++ b/src/test/java/org/apache/tamaya/builder/TestPropertySourceProvider.java
@@ -18,6 +18,7 @@
*/
package org.apache.tamaya.builder;
+import org.apache.tamaya.core.propertysource.BasePropertySource;
import org.apache.tamaya.spi.PropertySource;
import org.apache.tamaya.spi.PropertySourceProvider;
@@ -39,7 +40,7 @@ public class TestPropertySourceProvider
return sources;
}
- private class YProvidingPropertySource implements PropertySource {
+ private class YProvidingPropertySource extends BasePropertySource {
private Map<String, String> props = Collections.singletonMap("tpsp_x", "X");
@Override
@@ -63,7 +64,7 @@ public class TestPropertySourceProvider
}
}
- private class XProvidingPropertySource implements PropertySource {
+ private class XProvidingPropertySource extends BasePropertySource {
private Map<String, String> props = Collections.singletonMap("tpsp_y", "Y");
@Override
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/89e97b11/src/test/java/org/apache/tamaya/builder/TestPropertySourceProviderB.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/tamaya/builder/TestPropertySourceProviderB.java b/src/test/java/org/apache/tamaya/builder/TestPropertySourceProviderB.java
index ddfb132..e06c75c 100644
--- a/src/test/java/org/apache/tamaya/builder/TestPropertySourceProviderB.java
+++ b/src/test/java/org/apache/tamaya/builder/TestPropertySourceProviderB.java
@@ -18,6 +18,7 @@
*/
package org.apache.tamaya.builder;
+import org.apache.tamaya.core.propertysource.BasePropertySource;
import org.apache.tamaya.spi.PropertySource;
import org.apache.tamaya.spi.PropertySourceProvider;
@@ -39,7 +40,7 @@ public class TestPropertySourceProviderB
return sources;
}
- private class BProvidingPropertySource implements PropertySource {
+ private class BProvidingPropertySource extends BasePropertySource {
private Map<String, String> props = Collections.singletonMap("tpsp_b", "B");
@Override
@@ -63,7 +64,7 @@ public class TestPropertySourceProviderB
}
}
- private class AProvidingPropertySource implements PropertySource {
+ private class AProvidingPropertySource extends BasePropertySource {
private Map<String, String> props = Collections.singletonMap("tpsp_a", "A");
@Override
[12/50] [abbrv] incubator-tamaya-sandbox git commit: Adapted tests.
Posted by pl...@apache.org.
Adapted tests.
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/d03d92d4
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/tree/d03d92d4
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/diff/d03d92d4
Branch: refs/heads/master
Commit: d03d92d4b41d2ba436f127554a6aa02709f37f94
Parents: 4ac2dd7
Author: anatole <an...@apache.org>
Authored: Sat May 9 01:13:12 2015 +0200
Committer: anatole <an...@apache.org>
Committed: Sat May 9 01:13:12 2015 +0200
----------------------------------------------------------------------
.../org/apache/tamaya/builder/ConfigurationBuilderTest.java | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/d03d92d4/src/test/java/org/apache/tamaya/builder/ConfigurationBuilderTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/tamaya/builder/ConfigurationBuilderTest.java b/src/test/java/org/apache/tamaya/builder/ConfigurationBuilderTest.java
index e28f3ea..e5ec668 100644
--- a/src/test/java/org/apache/tamaya/builder/ConfigurationBuilderTest.java
+++ b/src/test/java/org/apache/tamaya/builder/ConfigurationBuilderTest.java
@@ -791,7 +791,7 @@ public class ConfigurationBuilderTest {
ConfigurationBuilder builder = new ConfigurationBuilder();
- builder.addPropertySource(resource.toString()).build();
+ builder.addPropertySources(resource.toString()).build();
}
@Test
@@ -802,7 +802,7 @@ public class ConfigurationBuilderTest {
ConfigurationBuilder builder = new ConfigurationBuilder();
- Configuration config = builder.addPropertySource(resource.toString())
+ Configuration config = builder.addPropertySources(resource.toString())
.build();
assertThat(config, CoreMatchers.notNullValue());
@@ -822,7 +822,7 @@ public class ConfigurationBuilderTest {
ConfigurationBuilder builder = new ConfigurationBuilder();
- Configuration config = builder.addPropertySource(first.toString(), second.toString(),
+ Configuration config = builder.addPropertySources(first.toString(), second.toString(),
null, third.toString())
.build();
@@ -874,7 +874,7 @@ public class ConfigurationBuilderTest {
ConfigurationBuilder builder = new ConfigurationBuilder();
- Configuration config = builder.addPropertySource(first, second,
+ Configuration config = builder.addPropertySources(first, second,
null, third)
.build();
[33/50] [abbrv] incubator-tamaya-sandbox git commit: TAMAYA-136:
Adding PropertyValue for PropertySource SPI. All changes and test fixes in
all modules/examples relevant for release.
Posted by pl...@apache.org.
TAMAYA-136: Adding PropertyValue for PropertySource SPI. All changes and test fixes in all modules/examples relevant for release.
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/1f67dc56
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/tree/1f67dc56
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/diff/1f67dc56
Branch: refs/heads/master
Commit: 1f67dc565ca25e9cd8bbd0902c03a714b7932dfa
Parents: 19b7071
Author: anatole <an...@apache.org>
Authored: Tue Feb 2 17:15:53 2016 +0100
Committer: anatole <an...@apache.org>
Committed: Tue Feb 2 17:15:53 2016 +0100
----------------------------------------------------------------------
.../tamaya/builder/SimplePropertySource.java | 7 +--
.../builder/ConfigurationBuilderTest.java | 46 ++++++++++----------
.../builder/TestANonSPIPropertyFilter.java | 3 +-
.../builder/TestBNonSPIPropertyFilter.java | 3 +-
.../tamaya/builder/TestPropertyFilter.java | 3 +-
.../tamaya/builder/TestPropertySource.java | 5 ++-
.../builder/TestPropertySourceProvider.java | 9 ++--
.../builder/TestPropertySourceProviderB.java | 9 ++--
8 files changed, 46 insertions(+), 39 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/1f67dc56/src/main/java/org/apache/tamaya/builder/SimplePropertySource.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/tamaya/builder/SimplePropertySource.java b/src/main/java/org/apache/tamaya/builder/SimplePropertySource.java
index 0d5561e..085bd9a 100644
--- a/src/main/java/org/apache/tamaya/builder/SimplePropertySource.java
+++ b/src/main/java/org/apache/tamaya/builder/SimplePropertySource.java
@@ -19,6 +19,7 @@
package org.apache.tamaya.builder;
import org.apache.tamaya.spi.PropertySource;
+import org.apache.tamaya.spi.PropertyValue;
import java.util.HashMap;
import java.util.Map;
@@ -42,10 +43,10 @@ public class SimplePropertySource implements PropertySource {
@Override
public int getOrdinal(){
- String configuredOrdinal = get(TAMAYA_ORDINAL);
+ PropertyValue configuredOrdinal = get(TAMAYA_ORDINAL);
if(configuredOrdinal!=null){
try{
- return Integer.parseInt(configuredOrdinal);
+ return Integer.parseInt(configuredOrdinal.getValue());
} catch(Exception e){
Logger.getLogger(getClass().getName()).log(Level.WARNING,
"Configured Ordinal is not an int number: " + configuredOrdinal, e);
@@ -64,7 +65,7 @@ public class SimplePropertySource implements PropertySource {
}
@Override
- public String get(String key) {
+ public PropertyValue get(String key) {
return null;
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/1f67dc56/src/test/java/org/apache/tamaya/builder/ConfigurationBuilderTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/tamaya/builder/ConfigurationBuilderTest.java b/src/test/java/org/apache/tamaya/builder/ConfigurationBuilderTest.java
index d48fe08..43196f7 100644
--- a/src/test/java/org/apache/tamaya/builder/ConfigurationBuilderTest.java
+++ b/src/test/java/org/apache/tamaya/builder/ConfigurationBuilderTest.java
@@ -103,7 +103,7 @@ public class ConfigurationBuilderTest {
PropertySource source = mock(PropertySource.class, NOT_MOCKED_ANSWER);
doReturn("one").when(source).getName();
- doReturn("a").when(source).get("keyOfA");
+ doReturn(PropertyValue.of("keyOfA","a", "test")).when(source).get("keyOfA");
doReturn(100).when(source).getOrdinal();
ConfigurationBuilder builder = new ConfigurationBuilder().addPropertySources(source);
@@ -121,12 +121,12 @@ public class ConfigurationBuilderTest {
PropertySource sourceOne = mock(PropertySource.class, NOT_MOCKED_ANSWER);
doReturn("one").when(sourceOne).getName();
- doReturn("b").when(sourceOne).get("keyOfA");
+ doReturn(PropertyValue.of("keyOfA","b", "test")).when(sourceOne).get("keyOfA");
doReturn(10).when(sourceOne).getOrdinal();
PropertySource sourceTwo = mock(PropertySource.class, NOT_MOCKED_ANSWER);
doReturn("two").when(sourceTwo).getName();
- doReturn("a").when(sourceTwo).get("keyOfA");
+ doReturn(PropertyValue.of("keyOfA","a", "test")).when(sourceTwo).get("keyOfA");
doReturn(10).when(sourceTwo).getOrdinal();
ConfigurationBuilder builder = new ConfigurationBuilder().addPropertySources(sourceOne)
@@ -167,12 +167,12 @@ public class ConfigurationBuilderTest {
PropertySource sourceOne = mock(PropertySource.class, NOT_MOCKED_ANSWER);
doReturn("one").when(sourceOne).getName();
- doReturn("b").when(sourceOne).get("keyOfA");
+ doReturn(PropertyValue.of("keyOfA","b", "test")).when(sourceOne).get("keyOfA");
doReturn(10).when(sourceOne).getOrdinal();
PropertySource sourceTwo = mock(PropertySource.class, NOT_MOCKED_ANSWER);
doReturn("two").when(sourceTwo).getName();
- doReturn("a").when(sourceTwo).get("keyOfA");
+ doReturn(PropertyValue.of("keyOfA","a", "test")).when(sourceTwo).get("keyOfA");
doReturn(20).when(sourceTwo).getOrdinal();
ConfigurationBuilder builder = new ConfigurationBuilder().addPropertySources(sourceOne)
@@ -191,12 +191,12 @@ public class ConfigurationBuilderTest {
PropertySource sourceOne = mock(PropertySource.class, NOT_MOCKED_ANSWER);
doReturn("one").when(sourceOne).getName();
- doReturn("b").when(sourceOne).get("keyOfA");
+ doReturn(PropertyValue.of("keyOfA","b", "test")).when(sourceOne).get("keyOfA");
doReturn(30).when(sourceOne).getOrdinal();
PropertySource sourceTwo = mock(PropertySource.class, NOT_MOCKED_ANSWER);
doReturn("two").when(sourceTwo).getName();
- doReturn("a").when(sourceTwo).get("keyOfA");
+ doReturn(PropertyValue.of("keyOfA","a", "test")).when(sourceTwo).get("keyOfA");
doReturn(20).when(sourceTwo).getOrdinal();
ConfigurationBuilder builder = new ConfigurationBuilder().addPropertySources(sourceOne, sourceTwo);
@@ -215,13 +215,13 @@ public class ConfigurationBuilderTest {
doReturn("one").when(sourceOne).getName();
doReturn(null).when(sourceOne).get(anyString());
- doReturn("b").when(sourceOne).get("b");
+ doReturn(PropertyValue.of("b","b", "test")).when(sourceOne).get("b");
doReturn(30).when(sourceOne).getOrdinal();
PropertySource sourceTwo = mock(PropertySource.class, NOT_MOCKED_ANSWER);
doReturn("two").when(sourceTwo).getName();
doReturn(null).when(sourceTwo).get(anyString());
- doReturn("a").when(sourceTwo).get("a");
+ doReturn(PropertyValue.of("a","a", "test")).when(sourceTwo).get("a");
doReturn(30).when(sourceTwo).getOrdinal();
ConfigurationBuilder builder = new ConfigurationBuilder().addPropertySources(sourceOne)
@@ -239,13 +239,13 @@ public class ConfigurationBuilderTest {
doReturn("one").when(sourceOne).getName();
doReturn(null).when(sourceOne).get(anyString());
- doReturn("b").when(sourceOne).get("b");
+ doReturn(PropertyValue.of("b","b", "test")).when(sourceOne).get("b");
doReturn(30).when(sourceOne).getOrdinal();
PropertySource sourceTwo = mock(PropertySource.class, NOT_MOCKED_ANSWER);
doReturn("two").when(sourceTwo).getName();
doReturn(null).when(sourceTwo).get(anyString());
- doReturn("a").when(sourceTwo).get("a");
+ doReturn(PropertyValue.of("a","a", "test")).when(sourceTwo).get("a");
doReturn(30).when(sourceTwo).getOrdinal();
ConfigurationBuilder builder = new ConfigurationBuilder().addPropertySources(sourceOne, null, sourceTwo);
@@ -285,7 +285,7 @@ public class ConfigurationBuilderTest {
PropertySource source = mock(PropertySource.class, NOT_MOCKED_ANSWER);
doReturn("source").when(source).getName();
- doReturn("A").when(source).get("key");
+ doReturn(PropertyValue.of("key","A", "test")).when(source).get("key");
doReturn(100).when(source).getOrdinal();
ConfigurationBuilder builder = new ConfigurationBuilder();
@@ -315,7 +315,7 @@ public class ConfigurationBuilderTest {
PropertySource source = mock(PropertySource.class, NOT_MOCKED_ANSWER);
doReturn("source").when(source).getName();
- doReturn("A").when(source).get("key");
+ doReturn(PropertyValue.of("key","A", "test")).when(source).get("key");
doReturn(100).when(source).getOrdinal();
ConfigurationBuilder builder = new ConfigurationBuilder();
@@ -345,7 +345,7 @@ public class ConfigurationBuilderTest {
PropertySource source = mock(PropertySource.class, NOT_MOCKED_ANSWER);
doReturn("source").when(source).getName();
- doReturn("A").when(source).get("key");
+ doReturn(PropertyValue.of("key","A", "test")).when(source).get("key");
doReturn(100).when(source).getOrdinal();
ConfigurationBuilder builder = new ConfigurationBuilder();
@@ -378,7 +378,7 @@ public class ConfigurationBuilderTest {
public void canAddNonSPIPropertyFilter() {
PropertySource source = mock(PropertySource.class, NOT_MOCKED_ANSWER);
- doReturn("M").when(source).get("key");
+ doReturn(PropertyValue.of("key","M", "test")).when(source).get("key");
doReturn("source").when(source).getName();
ConfigurationBuilder builder = new ConfigurationBuilder();
@@ -397,7 +397,7 @@ public class ConfigurationBuilderTest {
public void canAddNonSPIPropertyFiltersViaConsecutiveCalls() {
PropertySource source = mock(PropertySource.class, NOT_MOCKED_ANSWER);
- doReturn("M").when(source).get("key");
+ doReturn(PropertyValue.of("key","M", "test")).when(source).get("key");
doReturn("source").when(source).getName();
ConfigurationBuilder builder = new ConfigurationBuilder();
@@ -418,7 +418,7 @@ public class ConfigurationBuilderTest {
public void canAddMultipleNonSPIPropertyFiltersWhileOneIsNull() {
PropertySource source = mock(PropertySource.class, NOT_MOCKED_ANSWER);
- doReturn("M").when(source).get("key");
+ doReturn(PropertyValue.of("key","M", "test")).when(source).get("key");
doReturn("source").when(source).getName();
ConfigurationBuilder builder = new ConfigurationBuilder();
@@ -440,7 +440,7 @@ public class ConfigurationBuilderTest {
public void overhandedNullPropertyFilterIsSafelyHandled() {
PropertySource source = mock(PropertySource.class, NOT_MOCKED_ANSWER);
- doReturn("M").when(source).get("key");
+ doReturn(PropertyValue.of("key","M", "test")).when(source).get("key");
doReturn("source").when(source).getName();
ConfigurationBuilder builder = new ConfigurationBuilder();
@@ -460,7 +460,7 @@ public class ConfigurationBuilderTest {
public void canAddMultipleNonSPIPropertyFilter() {
PropertySource source = mock(PropertySource.class, NOT_MOCKED_ANSWER);
- doReturn("M").when(source).get("key");
+ doReturn(PropertyValue.of("key","M", "test")).when(source).get("key");
doReturn("source").when(source).getName();
ConfigurationBuilder builder = new ConfigurationBuilder();
@@ -574,7 +574,7 @@ public class ConfigurationBuilderTest {
PropertySource source = mock(PropertySource.class, NOT_MOCKED_ANSWER);
doReturn("source").when(source).getName();
- doReturn("A").when(source).get("key");
+ doReturn(PropertyValue.of("key","A", "test")).when(source).get("key");
doReturn(100).when(source).getOrdinal();
ConfigurationBuilder builder = new ConfigurationBuilder().addPropertySources(source)
@@ -591,7 +591,7 @@ public class ConfigurationBuilderTest {
PropertySource source = mock(PropertySource.class, NOT_MOCKED_ANSWER);
doReturn("source").when(source).getName();
- doReturn("A").when(source).get("key");
+ doReturn(PropertyValue.of("key","A", "test")).when(source).get("key");
doReturn(100).when(source).getOrdinal();
ConfigurationBuilder builder = new ConfigurationBuilder().addPropertySources(source)
@@ -667,7 +667,7 @@ public class ConfigurationBuilderTest {
PropertySource source = mock(PropertySource.class, NOT_MOCKED_ANSWER);
doReturn("source").when(source).getName();
- doReturn("A").when(source).get("key");
+ doReturn(PropertyValue.of("key","A", "test")).when(source).get("key");
doReturn(100).when(source).getOrdinal();
ConfigurationBuilder builder = new ConfigurationBuilder();
@@ -708,7 +708,7 @@ public class ConfigurationBuilderTest {
PropertySource source = mock(PropertySource.class, NOT_MOCKED_ANSWER);
doReturn("source").when(source).getName();
- doReturn("A").when(source).get("key");
+ doReturn(PropertyValue.of("key","A", "test")).when(source).get("key");
doReturn(100).when(source).getOrdinal();
ConfigurationBuilder builder = new ConfigurationBuilder();
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/1f67dc56/src/test/java/org/apache/tamaya/builder/TestANonSPIPropertyFilter.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/tamaya/builder/TestANonSPIPropertyFilter.java b/src/test/java/org/apache/tamaya/builder/TestANonSPIPropertyFilter.java
index e113010..896e0bc 100644
--- a/src/test/java/org/apache/tamaya/builder/TestANonSPIPropertyFilter.java
+++ b/src/test/java/org/apache/tamaya/builder/TestANonSPIPropertyFilter.java
@@ -18,11 +18,12 @@
*/
package org.apache.tamaya.builder;
+import org.apache.tamaya.spi.FilterContext;
import org.apache.tamaya.spi.PropertyFilter;
public class TestANonSPIPropertyFilter implements PropertyFilter {
@Override
- public String filterProperty(String key, String value) {
+ public String filterProperty(String value, FilterContext context) {
String result = value;
if (!result.contains(("ABC"))) {
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/1f67dc56/src/test/java/org/apache/tamaya/builder/TestBNonSPIPropertyFilter.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/tamaya/builder/TestBNonSPIPropertyFilter.java b/src/test/java/org/apache/tamaya/builder/TestBNonSPIPropertyFilter.java
index 2ce81fc..a9c0ac2 100644
--- a/src/test/java/org/apache/tamaya/builder/TestBNonSPIPropertyFilter.java
+++ b/src/test/java/org/apache/tamaya/builder/TestBNonSPIPropertyFilter.java
@@ -18,11 +18,12 @@
*/
package org.apache.tamaya.builder;
+import org.apache.tamaya.spi.FilterContext;
import org.apache.tamaya.spi.PropertyFilter;
public class TestBNonSPIPropertyFilter implements PropertyFilter {
@Override
- public String filterProperty(String key, String value) {
+ public String filterProperty(String value, FilterContext context) {
String result = value;
if (!result.contains(("XYZ"))) {
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/1f67dc56/src/test/java/org/apache/tamaya/builder/TestPropertyFilter.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/tamaya/builder/TestPropertyFilter.java b/src/test/java/org/apache/tamaya/builder/TestPropertyFilter.java
index 80c4cb3..e22fca8 100644
--- a/src/test/java/org/apache/tamaya/builder/TestPropertyFilter.java
+++ b/src/test/java/org/apache/tamaya/builder/TestPropertyFilter.java
@@ -18,11 +18,12 @@
*/
package org.apache.tamaya.builder;
+import org.apache.tamaya.spi.FilterContext;
import org.apache.tamaya.spi.PropertyFilter;
public class TestPropertyFilter implements PropertyFilter {
@Override
- public String filterProperty(String key, String value) {
+ public String filterProperty(String value, FilterContext context) {
String result = value;
if (!result.contains(("inBerlin"))) {
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/1f67dc56/src/test/java/org/apache/tamaya/builder/TestPropertySource.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/tamaya/builder/TestPropertySource.java b/src/test/java/org/apache/tamaya/builder/TestPropertySource.java
index e30c244..f1ebfea 100644
--- a/src/test/java/org/apache/tamaya/builder/TestPropertySource.java
+++ b/src/test/java/org/apache/tamaya/builder/TestPropertySource.java
@@ -20,6 +20,7 @@ package org.apache.tamaya.builder;
import org.apache.tamaya.core.propertysource.BasePropertySource;
import org.apache.tamaya.spi.PropertySource;
+import org.apache.tamaya.spi.PropertyValue;
import java.util.Collections;
import java.util.Hashtable;
@@ -47,8 +48,8 @@ public class TestPropertySource extends BasePropertySource
}
@Override
- public String get(String key) {
- return getProperties().get(key);
+ public PropertyValue get(String key) {
+ return PropertyValue.of(key, getProperties().get(key), getName());
}
@Override
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/1f67dc56/src/test/java/org/apache/tamaya/builder/TestPropertySourceProvider.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/tamaya/builder/TestPropertySourceProvider.java b/src/test/java/org/apache/tamaya/builder/TestPropertySourceProvider.java
index 0dcd68c..5a2f400 100644
--- a/src/test/java/org/apache/tamaya/builder/TestPropertySourceProvider.java
+++ b/src/test/java/org/apache/tamaya/builder/TestPropertySourceProvider.java
@@ -21,6 +21,7 @@ package org.apache.tamaya.builder;
import org.apache.tamaya.core.propertysource.BasePropertySource;
import org.apache.tamaya.spi.PropertySource;
import org.apache.tamaya.spi.PropertySourceProvider;
+import org.apache.tamaya.spi.PropertyValue;
import java.util.ArrayList;
import java.util.Collection;
@@ -54,8 +55,8 @@ public class TestPropertySourceProvider
}
@Override
- public String get(String key) {
- return getProperties().get(key);
+ public PropertyValue get(String key) {
+ return PropertyValue.of(key, getProperties().get(key), getName());
}
@Override
@@ -73,8 +74,8 @@ public class TestPropertySourceProvider
}
@Override
- public String get(String key) {
- return getProperties().get(key);
+ public PropertyValue get(String key) {
+ return PropertyValue.of(key, getProperties().get(key), getName());
}
@Override
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/1f67dc56/src/test/java/org/apache/tamaya/builder/TestPropertySourceProviderB.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/tamaya/builder/TestPropertySourceProviderB.java b/src/test/java/org/apache/tamaya/builder/TestPropertySourceProviderB.java
index e06c75c..9cfe725 100644
--- a/src/test/java/org/apache/tamaya/builder/TestPropertySourceProviderB.java
+++ b/src/test/java/org/apache/tamaya/builder/TestPropertySourceProviderB.java
@@ -21,6 +21,7 @@ package org.apache.tamaya.builder;
import org.apache.tamaya.core.propertysource.BasePropertySource;
import org.apache.tamaya.spi.PropertySource;
import org.apache.tamaya.spi.PropertySourceProvider;
+import org.apache.tamaya.spi.PropertyValue;
import java.util.ArrayList;
import java.util.Collection;
@@ -54,8 +55,8 @@ public class TestPropertySourceProviderB
}
@Override
- public String get(String key) {
- return getProperties().get(key);
+ public PropertyValue get(String key) {
+ return PropertyValue.of(key,getProperties().get(key), getName());
}
@Override
@@ -73,8 +74,8 @@ public class TestPropertySourceProviderB
}
@Override
- public String get(String key) {
- return getProperties().get(key);
+ public PropertyValue get(String key) {
+ return PropertyValue.of(key, getProperties().get(key), getName());
}
@Override
[15/50] [abbrv] incubator-tamaya-sandbox git commit: Merge branch
'master' of https://git-wip-us.apache.org/repos/asf/incubator-tamaya
Posted by pl...@apache.org.
Merge branch 'master' of https://git-wip-us.apache.org/repos/asf/incubator-tamaya
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/66c6e8d3
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/tree/66c6e8d3
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/diff/66c6e8d3
Branch: refs/heads/master
Commit: 66c6e8d30ce11913e157dee7e58b501df45592a8
Parents: 8e555f4 341697f
Author: anatole <an...@apache.org>
Authored: Thu May 21 06:46:19 2015 +0200
Committer: anatole <an...@apache.org>
Committed: Thu May 21 06:46:19 2015 +0200
----------------------------------------------------------------------
.../META-INF/services/org.apache.tamaya.spi.PropertySource | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------
[49/50] [abbrv] incubator-tamaya-sandbox git commit: Moved the
builder to the directory builder
Posted by pl...@apache.org.
Moved the builder to the directory builder
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/f45a5bb5
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/tree/f45a5bb5
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/diff/f45a5bb5
Branch: refs/heads/master
Commit: f45a5bb5bc1f2bb439980fda4f0da7fae70c19d4
Parents: 09ab45b
Author: Oliver B. Fischer <pl...@apache.org>
Authored: Sun Sep 25 23:20:22 2016 +0200
Committer: Oliver B. Fischer <pl...@apache.org>
Committed: Sun Sep 25 23:20:22 2016 +0200
----------------------------------------------------------------------
builder/pom.xml | 104 +++
.../tamaya/builder/ConfigurationBuilder.java | 605 +++++++++++++
.../ProgrammaticConfigurationContext.java | 388 ++++++++
.../tamaya/builder/PropertySourceBuilder.java | 118 +++
.../tamaya/builder/SimplePropertySource.java | 86 ++
.../org/apache/tamaya/builder/package-info.java | 28 +
.../builder/ConfigurationBuilderTest.java | 907 +++++++++++++++++++
.../builder/TestANonSPIPropertyFilter.java | 35 +
.../builder/TestBNonSPIPropertyFilter.java | 35 +
.../tamaya/builder/TestPropertyFilter.java | 35 +
.../tamaya/builder/TestPropertySource.java | 59 ++
.../builder/TestPropertySourceProvider.java | 91 ++
.../builder/TestPropertySourceProviderB.java | 91 ++
.../builder/util/mockito/NotMockedAnswer.java | 57 ++
.../tamaya/builder/util/types/CustomTypeA.java | 34 +
.../tamaya/builder/util/types/CustomTypeB.java | 39 +
.../tamaya/builder/util/types/CustomTypeC.java | 36 +
.../types/CustomTypeCPropertyConverter.java | 29 +
.../org.apache.tamaya.spi.PropertyConverter | 19 +
.../org.apache.tamaya.spi.PropertyFilter | 19 +
.../org.apache.tamaya.spi.PropertySource | 19 +
...org.apache.tamaya.spi.PropertySourceProvider | 19 +
.../test/resources/configfiles/json/first.json | 4 +
.../test/resources/configfiles/json/second.json | 4 +
.../test/resources/configfiles/json/simple.json | 4 +
.../test/resources/configfiles/json/third.json | 4 +
.../test/resources/configfiles/other/simple.oml | 19 +
pom.xml | 104 ---
.../tamaya/builder/ConfigurationBuilder.java | 605 -------------
.../ProgrammaticConfigurationContext.java | 388 --------
.../tamaya/builder/PropertySourceBuilder.java | 118 ---
.../tamaya/builder/SimplePropertySource.java | 86 --
.../org/apache/tamaya/builder/package-info.java | 28 -
.../builder/ConfigurationBuilderTest.java | 907 -------------------
.../builder/TestANonSPIPropertyFilter.java | 35 -
.../builder/TestBNonSPIPropertyFilter.java | 35 -
.../tamaya/builder/TestPropertyFilter.java | 35 -
.../tamaya/builder/TestPropertySource.java | 59 --
.../builder/TestPropertySourceProvider.java | 91 --
.../builder/TestPropertySourceProviderB.java | 91 --
.../builder/util/mockito/NotMockedAnswer.java | 57 --
.../tamaya/builder/util/types/CustomTypeA.java | 34 -
.../tamaya/builder/util/types/CustomTypeB.java | 39 -
.../tamaya/builder/util/types/CustomTypeC.java | 36 -
.../types/CustomTypeCPropertyConverter.java | 29 -
.../org.apache.tamaya.spi.PropertyConverter | 19 -
.../org.apache.tamaya.spi.PropertyFilter | 19 -
.../org.apache.tamaya.spi.PropertySource | 19 -
...org.apache.tamaya.spi.PropertySourceProvider | 19 -
src/test/resources/configfiles/json/first.json | 4 -
src/test/resources/configfiles/json/second.json | 4 -
src/test/resources/configfiles/json/simple.json | 4 -
src/test/resources/configfiles/json/third.json | 4 -
src/test/resources/configfiles/other/simple.oml | 19 -
54 files changed, 2888 insertions(+), 2888 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/f45a5bb5/builder/pom.xml
----------------------------------------------------------------------
diff --git a/builder/pom.xml b/builder/pom.xml
new file mode 100644
index 0000000..96f6244
--- /dev/null
+++ b/builder/pom.xml
@@ -0,0 +1,104 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+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.
+-->
+<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-extensions</artifactId>
+ <version>0.3-incubating-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>tamaya-builder</artifactId>
+ <name>Apache Tamaya Modules - Builder</name>
+ <packaging>jar</packaging> <!-- bundle -->
+
+ <inceptionYear>2015</inceptionYear>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.tamaya</groupId>
+ <artifactId>tamaya-api</artifactId>
+ <version>${project.version}</version>
+ <scope>provided</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.tamaya.ext</groupId>
+ <artifactId>tamaya-formats</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.tamaya</groupId>
+ <artifactId>tamaya-core</artifactId>
+ <version>${project.version}</version>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.tamaya.ext</groupId>
+ <artifactId>tamaya-spisupport</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.tamaya.ext</groupId>
+ <artifactId>tamaya-json</artifactId>
+ <version>${project.version}</version>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.hamcrest</groupId>
+ <artifactId>java-hamcrest</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>org.mockito</groupId>
+ <artifactId>mockito-core</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ </dependency>
+
+
+ </dependencies>
+
+ <!--build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+ <extensions>true</extensions>
+ <configuration>
+ <instructions>
+ <Export-Package>
+ org.apache.tamaya.builder
+ </Export-Package>
+ </instructions>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build -->
+
+</project>
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/f45a5bb5/builder/src/main/java/org/apache/tamaya/builder/ConfigurationBuilder.java
----------------------------------------------------------------------
diff --git a/builder/src/main/java/org/apache/tamaya/builder/ConfigurationBuilder.java b/builder/src/main/java/org/apache/tamaya/builder/ConfigurationBuilder.java
new file mode 100644
index 0000000..afdc121
--- /dev/null
+++ b/builder/src/main/java/org/apache/tamaya/builder/ConfigurationBuilder.java
@@ -0,0 +1,605 @@
+/*
+ * 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.builder;
+
+import org.apache.tamaya.ConfigException;
+import org.apache.tamaya.Configuration;
+import org.apache.tamaya.spi.PropertyConverter;
+import org.apache.tamaya.TypeLiteral;
+import org.apache.tamaya.format.ConfigurationData;
+import org.apache.tamaya.format.ConfigurationFormats;
+import org.apache.tamaya.format.FlattenedDefaultPropertySource;
+import org.apache.tamaya.spi.ConfigurationContext;
+import org.apache.tamaya.spi.PropertyFilter;
+import org.apache.tamaya.spi.PropertySource;
+import org.apache.tamaya.spi.PropertySourceProvider;
+import org.apache.tamaya.spi.PropertyValueCombinationPolicy;
+import org.apache.tamaya.spisupport.DefaultConfiguration;
+
+import java.io.IOException;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.Collection;
+import java.util.Objects;
+
+import static java.lang.String.format;
+
+/**
+ * <p>Builder class used for building a configuration manually without relying
+ * only on the Service Provider Interface API.</p>
+ *
+ * <p><strong>Features of the builder</strong></p>
+ *
+ * <ol>
+ * <li>Adding of property converters manually</li>
+ * <li>Adding of property sources directly</li>
+ * <li>Adding of property sources via URL</li>
+ * <li>Adding of property source providers directly</li>
+ * <li>Enabling and disabling of via SPI mechanism provided resources as converters,
+ * property sources, etc.</li>
+ * </ol>
+ *
+ * <p><strong>Example</strong></p>
+ *
+ * <pre>{@code ConfigurationBuilder builder = new ConfigurationBuilder();
+ * builder.disableProvidedPropertySources() // Do not load provided property
+ * .disableProvidedPropertySourceProviders() // sources and providers automatically
+ * .addPropertySource("file:/etc/conf.properties"); // Load properties from conf.properties
+ *
+ * Configuration config = builder.build();
+ * }</pre>
+ *
+ * <p><strong>Support for configuration formats</strong></p>
+ *
+ * The configuration builder allows you to put property resources
+ * via a URL, as shown in the code example above, without implementing
+ * a {@link org.apache.tamaya.spi.PropertySource PropertySource} or providing an
+ * instance of a {@link org.apache.tamaya.spi.PropertySource PropertySource}.
+ * If a property resource in
+ * a specific format can be added to configuration builder or not depends
+ * on the available implementations of
+ * {@link org.apache.tamaya.format.ConfigurationFormat} in the classpath.
+ * Which formats are available can be checked via
+ * {@link org.apache.tamaya.format.ConfigurationFormats#getFormats()}.
+ */
+public class ConfigurationBuilder {
+ /** Builder used to create new ConfigurationContext instances. */
+ private final ProgrammaticConfigurationContext.Builder contextBuilder = new ProgrammaticConfigurationContext.Builder();
+
+ /**
+ * Flag if the config has already been built.
+ * Configuration can be built only once
+ */
+ private boolean built;
+
+ /**
+ * Flag if all existing property converter service providers
+ * should be loaded if the configuration is build.
+ */
+ private boolean loadProvidedPropertyConverters = true;
+
+ /**
+ * Flag if all existing property source service providers
+ * will be loaded if the configuration is build.
+ */
+ private boolean loadProvidedPropertySources = false;
+ private boolean loadProvidedPropertySourceProviders = false;
+
+ private boolean isLoadProvidedPropertyFilters = false;
+
+ /**
+ * Creates a new builder instance.
+ */
+ public ConfigurationBuilder() {
+ }
+
+ /**
+ * Allows to set configuration context during unit tests.
+ */
+ ConfigurationBuilder setConfigurationContext(ConfigurationContext configurationContext) {
+ //noinspection deprecation
+ contextBuilder.setConfigurationContext(configurationContext);
+ return this;
+ }
+
+ /**
+ * Adds one resources with properties in an arbitrary format
+ * to the configuration to be build.
+ *
+ * <p>If a specific format is supported depends on the available
+ * {@link org.apache.tamaya.format.ConfigurationFormat} implementations.</p>
+ *
+ * <pre>{@code URL resource = new URL("file:/etc/service/config.json");
+ *
+ * builder.addPropertySources(resource);}
+ * </pre>
+ *
+ * @param url resource with properties for the the configuration to be build.
+ *
+ * @return the builder instance currently used
+ *
+ * @see org.apache.tamaya.format.ConfigurationFormat
+ * @see org.apache.tamaya.format.ConfigurationFormats#getFormats()
+ */
+ public ConfigurationBuilder addPropertySource(URL url) {
+ try {
+ ConfigurationData data = getConfigurationDataFromURL(url);
+
+ FlattenedDefaultPropertySource propertySource = new FlattenedDefaultPropertySource(data);
+ addPropertySources(propertySource);
+ } catch (IOException e) {
+ throw new ConfigException("Failed to read " + url.toString(), e);
+ }
+ return this;
+ }
+
+ protected ConfigurationData getConfigurationDataFromURL(URL url) throws IOException {
+ ConfigurationData data = ConfigurationFormats.readConfigurationData(url);
+
+ if (null == data) {
+ String mesg = format("No configuration format found which is able " +
+ "to read properties from %s.", url.toString());
+
+ throw new ConfigException(mesg);
+ }
+
+ return data;
+ }
+
+ /**
+ * Adds one or more resources with properties in an arbitrary format
+ * to the configuration to be build.
+ *
+ * <p>If a specific format is supported depends on the available
+ * {@link org.apache.tamaya.format.ConfigurationFormat} implementations.</p>
+ *
+ *<pre>{@code URL first = new URL("file:/etc/service/config.json");
+ * URL second = new URL("file:/etc/defaults/values.properties");
+ *
+ * builder.addPropertySources(first, second);}
+ *</pre>
+ *
+ * @param urls list of resources with properties for the configuration to be
+ * build.
+ *
+ * @return the builder instance currently used
+ *
+ * @see org.apache.tamaya.format.ConfigurationFormat
+ * @see org.apache.tamaya.format.ConfigurationFormats#getFormats()
+ */
+ public ConfigurationBuilder addPropertySources(URL... urls) {
+ for(URL url:urls){
+ if(url!=null){
+ addPropertySource(url);
+ }
+ }
+ return this;
+ }
+
+ /**
+ * Adds one or more resources with properties in an arbitrary format
+ * to the configuration to be build.
+ *
+ * <p>If a specific format is supported depends on the available
+ * {@link org.apache.tamaya.format.ConfigurationFormat} implementations.</p>
+ *
+ *<pre>{@code URL first = new URL("file:/etc/service/config.json");
+ * URL second = new URL("file:/etc/defaults/values.properties");
+ *
+ * builder.addPropertySources(first, second);}
+ *</pre>
+ *
+ * @param urls list of resources with properties for the configuration to be
+ * build.
+ *
+ * @return the builder instance currently used
+ *
+ * @see org.apache.tamaya.format.ConfigurationFormat
+ * @see org.apache.tamaya.format.ConfigurationFormats#getFormats()
+ */
+ public ConfigurationBuilder addPropertySources(Collection<URL> urls) {
+ for(URL url:urls) {
+ if (url != null) {
+ addPropertySource(url);
+ }
+ }
+ return this;
+ }
+
+
+ /**
+ * Adds one or more resources with properties in an arbitrary format
+ * to the configuration to be build.
+ *
+ * <p>If a specific format is supported depends on the available
+ * {@link org.apache.tamaya.format.ConfigurationFormat} implementations.</p>
+ *
+ *<pre>{@code builder.addPropertySources("file:/etc/service/config.json",
+ * "file:/etc/defaults/values.properties");}
+ *</pre>
+ *
+ * @param urls list of resources with properties for the configuration to be
+ * build.
+ *
+ * @return the builder instance currently used
+ *
+ * @see org.apache.tamaya.format.ConfigurationFormat
+ * @see org.apache.tamaya.format.ConfigurationFormats#getFormats()
+ */
+ public ConfigurationBuilder addPropertySources(String... urls) {
+ for(String url:urls) {
+ if (url != null) {
+ try{
+ addPropertySource(new URL(url));
+ } catch(Exception e){
+ throw new ConfigException("Invalid URL: " + url);
+ }
+ }
+ }
+ return this;
+ }
+
+ /**
+ * Adds one or more property source instances to the configuration to be build.
+ *
+ *<pre>{@code PropertySource first = new CustomPropertySource();
+ * PropertySource second = new YetAnotherPropertySource();
+ *
+ * builder.addPropertySources(first, second)};
+ *</pre>
+ *
+ * @param sources list of property source instances with properties for the
+ * configuration to be build.
+ *
+ * @return the builder instance currently used
+ *
+ * @see org.apache.tamaya.spi.PropertySource
+ */
+ public ConfigurationBuilder addPropertySources(PropertySource... sources){
+ checkBuilderState();
+
+ contextBuilder.addPropertySources(Objects.requireNonNull(sources));
+ return this;
+ }
+
+ private void checkBuilderState() {
+ if (built) {
+ throw new IllegalStateException("Configuration has already been build.");
+ }
+ }
+
+ /**
+ * Adds one or more property source provider instances to the configuration to be build.
+ *
+ * <pre>{@code PropertySourceProvider jc = new JavaConfigurationProvider();
+ *
+ * builder.addPropertySources(jc)};
+ * </pre>
+ *
+ * @param providers list of property source provider instances each providing a set
+ * of property source instances for the configuration to be build.
+ *
+ * @return the builder instance currently used
+ *
+ * @see org.apache.tamaya.spi.PropertySourceProvider
+ */
+ public ConfigurationBuilder addPropertySourceProviders(PropertySourceProvider... providers){
+ contextBuilder.addPropertySourceProviders(providers);
+ return this;
+ }
+
+ /**
+ * Adds one or more property filter instances to the configuration to be build.
+ *
+ * <pre>{@code PropertyFilter quoteReplacingFilter = new QuoteFilter();
+ * PropertyFilter commaRemovingFilter = new CommaFilter();
+ *
+ * builder.addPropertyFilters(commaRemovingFilter, quoteReplacingFilter)};
+ * </pre>
+ *
+ * @param filters list of property filter instances which should be applied
+ * to the properties of the configuration to be build.
+ *
+ * @return the builder instance currently used
+ *
+ * @see org.apache.tamaya.spi.PropertyFilter
+ * @see #disableProvidedPropertyFilters()
+ * @see #enabledProvidedPropertyFilters()
+ */
+ public ConfigurationBuilder addPropertyFilters(PropertyFilter... filters){
+ Objects.requireNonNull(filters);
+
+ contextBuilder.addPropertyFilters(filters);
+ return this;
+ }
+
+
+ /**
+ * @param propertyValueCombinationPolicy combination policy to use for this builder.
+ * @return the builder instance currently in use.
+ */
+ public ConfigurationBuilder setPropertyValueCombinationPolicy(PropertyValueCombinationPolicy propertyValueCombinationPolicy){
+ contextBuilder.setPropertyValueCombinationPolicy(propertyValueCombinationPolicy);
+ return this;
+ }
+
+ /**
+ * Adds a property converter for the a given type to the configuration to
+ * be build.
+ *
+ * <pre>{@code PropertyConverter<MyType> converter = value -> new MyType(value, 42);
+ *
+ * builder.addPropertyConverter(MyType.class, converter}
+ * </pre>
+ *
+ * @param <T> the type of the configuration
+ * @param type the required target type the converter should be applied to
+ * @param converter the converter to be used to convert the string property
+ * to the given target type.
+ *
+ * @return the builder instance currently used
+ *
+ * @see org.apache.tamaya.spi.PropertyConverter
+ * @see #enableProvidedPropertyConverters()
+ * @see #disableProvidedPropertyConverters()
+ */
+ public <T> ConfigurationBuilder addPropertyConverter(Class<T> type, PropertyConverter<T> converter) {
+ Objects.requireNonNull(type);
+ Objects.requireNonNull(converter);
+ return addPropertyConverter(TypeLiteral.of(type), (PropertyConverter<Object>)converter);
+ }
+
+ /**
+ * Adds a propertyConverter of a given type.
+ *
+ * @param <T> the type of the configuration
+ * @param type type literal of this converter.
+ * @param propertyConverter property converter.
+ * @return the builder instance currently used
+ */
+ public <T> ConfigurationBuilder addPropertyConverter(TypeLiteral<T> type, PropertyConverter<T> propertyConverter){
+ Objects.requireNonNull(type);
+ Objects.requireNonNull(propertyConverter);
+ contextBuilder.addPropertyConverter(type, propertyConverter);
+ return this;
+ }
+
+ /**
+ * Checks if the automatic loading of all {@link org.apache.tamaya.spi.PropertyConverter
+ * PropertyConverter} service providers is enabled or disabled.
+ *
+ * @return {@code true} if the automatic loading is enabled,
+ * otherwise {@code false}.
+ *
+ * @see #enableProvidedPropertyConverters()
+ * @see #disableProvidedPropertyConverters()
+ * @see #addPropertyConverter(Class, org.apache.tamaya.spi.PropertyConverter)
+ * @see #addPropertyConverter(org.apache.tamaya.TypeLiteral, org.apache.tamaya.spi.PropertyConverter)
+ */
+ public boolean isPropertyConverterLoadingEnabled() {
+ return loadProvidedPropertyConverters;
+ }
+
+ /**
+ * Enables the loading of all {@link org.apache.tamaya.spi.PropertyConverter}
+ * service providers.
+ *
+ * @return the builder instance currently used
+ *
+ * @see org.apache.tamaya.spi.PropertyConverter
+ * @see #disableProvidedPropertyConverters()
+ * @see #enableProvidedPropertyConverters()
+ */
+ public ConfigurationBuilder enableProvidedPropertyConverters() {
+ checkBuilderState();
+
+ loadProvidedPropertyConverters = true;
+
+ return this;
+ }
+
+ /**
+ * Disables the automatic loading of all {@link org.apache.tamaya.spi.PropertyConverter}
+ * service providers.
+ *
+ * @return the builder instance currently used
+ *
+ * @see org.apache.tamaya.spi.PropertyConverter
+ * @see #enableProvidedPropertyConverters()
+ * @see #addPropertyConverter(Class, org.apache.tamaya.spi.PropertyConverter)
+ */
+ public ConfigurationBuilder disableProvidedPropertyConverters() {
+ checkBuilderState();
+
+ loadProvidedPropertyConverters = false;
+
+ return this;
+ }
+
+
+ /**
+ * Enables the automatic loading of all {@link org.apache.tamaya.spi.PropertySource}
+ * service providers.
+ *
+ * @return the builder instance currently used
+ *
+ * @see org.apache.tamaya.spi.PropertySource
+ * @see #disableProvidedPropertySources()
+ */
+ public ConfigurationBuilder enableProvidedPropertySources() {
+ checkBuilderState();
+
+ loadProvidedPropertySources = true;
+
+ return this;
+ }
+
+ /**
+ * Checks if the automatic loading of all {@link org.apache.tamaya.spi.PropertySource
+ * PropertySource} service providers is enabled or disabled.
+ *
+ * @return {@code true} if the automatic loading is enabled,
+ * otherwise {@code false}.
+ */
+ public boolean isPropertySourcesLoadingEnabled() {
+ return loadProvidedPropertySources;
+ }
+
+
+ /**
+ * Checks if the automatic loading of all {@link org.apache.tamaya.spi.PropertyFilter
+ * PropertyFilter} service providers is enabled or disabled.
+ *
+ * @return {@code true} if the automatic loading is enabled,
+ * otherwise {@code false}.
+ */
+ public boolean isPropertyFilterLoadingEnabled() {
+ return isLoadProvidedPropertyFilters;
+ }
+
+ /**
+ * Enables the automatic loading of all {@link org.apache.tamaya.spi.PropertyFilter}
+ * service providers.
+ *
+ * @return the builder instance currently used
+ *
+ * @see org.apache.tamaya.spi.PropertyFilter
+ * @see #disableProvidedPropertyFilters()
+ * @see #addPropertyFilters(org.apache.tamaya.spi.PropertyFilter...)
+ */
+ public ConfigurationBuilder enabledProvidedPropertyFilters() {
+ checkBuilderState();
+
+ isLoadProvidedPropertyFilters = true;
+
+ return this;
+ }
+
+ /**
+ * Disables the automatic loading of all {@link org.apache.tamaya.spi.PropertyFilter}
+ * service providers.
+ *
+ * @see org.apache.tamaya.spi.PropertyFilter
+ * @see #enabledProvidedPropertyFilters()
+ * @see #addPropertyFilters(org.apache.tamaya.spi.PropertyFilter...)
+ *
+ * @return the builder instance currently used
+ */
+ public ConfigurationBuilder disableProvidedPropertyFilters() {
+ checkBuilderState();
+
+ isLoadProvidedPropertyFilters = false;
+
+ return this;
+ }
+
+ /**
+ * Disables the automatic loading of all {@link org.apache.tamaya.spi.PropertySource}
+ * service providers.
+ *
+ * @return the builder instance currently used
+ *
+ * @see org.apache.tamaya.spi.PropertySource
+ * @see #enableProvidedPropertySources()
+ */
+ public ConfigurationBuilder disableProvidedPropertySources() {
+ checkBuilderState();
+
+ loadProvidedPropertySources = false;
+
+ return this;
+ }
+
+ /**
+ * Enables the automatic loading of {@link org.apache.tamaya.spi.PropertySourceProvider
+ * property source providers} provided via the SPI API.
+ *
+ * @return the builder instance currently used
+ *
+ * @see org.apache.tamaya.spi.PropertySourceProvider
+ */
+ public ConfigurationBuilder enableProvidedPropertySourceProviders() {
+ checkBuilderState();
+
+ loadProvidedPropertySourceProviders = true;
+
+ return this;
+ }
+
+ /**
+ * Disables the automatic loading of {@link org.apache.tamaya.spi.PropertySourceProvider
+ * property source providers} provided via the SPI API.
+ *
+ * @return the builder instance currently used
+ */
+ public ConfigurationBuilder disableProvidedPropertySourceProviders() {
+ checkBuilderState();
+
+ loadProvidedPropertySourceProviders = false;
+
+ return this;
+ }
+
+ /**
+ * Checks if the automatic loading of {@link org.apache.tamaya.spi.PropertySourceProvider
+ * PropertySourceProviders} is enabled or disabled.
+ *
+ * @return {@code true} if the automatic loading is enabled,
+ * otherwise {@code false}.
+ */
+ public boolean isPropertySourceProvidersLoadingEnabled() {
+ return loadProvidedPropertySourceProviders;
+ }
+
+ //X TODO think on a functionality/API for using the default PropertyConverters and use the configured ones here
+ //X TODO as overrides used first.
+
+
+ /**
+ * Builds a new configuration based on the configuration of this builder instance.
+ *
+ * @return a new {@link org.apache.tamaya.Configuration configuration instance},
+ * never {@code null}.
+ */
+ public Configuration build() {
+ checkBuilderState();
+
+ built = true;
+
+ contextBuilder.loadProvidedPropertyConverters(isPropertyConverterLoadingEnabled());
+ contextBuilder.loadProvidedPropertySources(isPropertySourcesLoadingEnabled());
+ contextBuilder.loadProvidedPropertySourceProviders(isPropertySourceProvidersLoadingEnabled());
+ contextBuilder.loadProvidedPropertyFilters(isLoadProvidedPropertyFilters);
+
+ return new DefaultConfiguration(contextBuilder.build());
+ }
+
+ /**
+ * Mapper to map a URL given as string to an URL instance.
+ */
+ private static class StringToURLMapper {
+ public URL apply(String u) {
+ try {
+ return new URL(u);
+ } catch (MalformedURLException e) {
+ throw new ConfigException(u + " is not a valid URL", e);
+ }
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/f45a5bb5/builder/src/main/java/org/apache/tamaya/builder/ProgrammaticConfigurationContext.java
----------------------------------------------------------------------
diff --git a/builder/src/main/java/org/apache/tamaya/builder/ProgrammaticConfigurationContext.java b/builder/src/main/java/org/apache/tamaya/builder/ProgrammaticConfigurationContext.java
new file mode 100644
index 0000000..68e770d
--- /dev/null
+++ b/builder/src/main/java/org/apache/tamaya/builder/ProgrammaticConfigurationContext.java
@@ -0,0 +1,388 @@
+/*
+ * 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.builder;
+
+
+import org.apache.tamaya.spi.PropertyConverter;
+import org.apache.tamaya.TypeLiteral;
+import org.apache.tamaya.spi.ConfigurationContext;
+import org.apache.tamaya.spi.ConfigurationContextBuilder;
+import org.apache.tamaya.spi.PropertyFilter;
+import org.apache.tamaya.spi.PropertySource;
+import org.apache.tamaya.spi.PropertySourceProvider;
+import org.apache.tamaya.spi.PropertyValueCombinationPolicy;
+import org.apache.tamaya.spi.ServiceContextManager;
+import org.apache.tamaya.spisupport.PriorityServiceComparator;
+import org.apache.tamaya.spisupport.PropertyConverterManager;
+import org.apache.tamaya.spisupport.PropertySourceComparator;
+
+import javax.annotation.Priority;
+import java.util.*;
+import java.util.concurrent.locks.Lock;
+import java.util.concurrent.locks.ReadWriteLock;
+import java.util.concurrent.locks.ReentrantReadWriteLock;
+import java.util.logging.Logger;
+
+/**
+ * Implementation of the {@link org.apache.tamaya.spi.ConfigurationContext}
+ * used by the {@link org.apache.tamaya.builder.ConfigurationBuilder}
+ * internally.
+ */
+class ProgrammaticConfigurationContext implements ConfigurationContext {
+
+ private static final Comparator<PropertySource> PS_COMPARATOR = new PropertySourceComparator();
+ private static final Comparator<Object> COMP_COMPARATOR = new PriorityServiceComparator();
+ /**
+ * The logger used.
+ */
+ private final static Logger LOG = Logger.getLogger(ProgrammaticConfigurationContext.class.getName());
+ /**
+ * Cubcomponent handling {@link org.apache.tamaya.spi.PropertyConverter} instances.
+ */
+ private PropertyConverterManager propertyConverterManager = new PropertyConverterManager();
+
+ /**
+ * The current unmodifiable list of loaded {@link org.apache.tamaya.spi.PropertySource} instances.
+ */
+ private List<PropertySource> immutablePropertySources = new ArrayList<>();
+
+ /**
+ * The current unmodifiable list of loaded {@link org.apache.tamaya.spi.PropertyFilter} instances.
+ */
+ private List<PropertyFilter> immutablePropertyFilters = new ArrayList<>();
+
+ /**
+ * The overriding policy used when combining PropertySources registered to evalute the final configuration
+ * values.
+ */
+ private PropertyValueCombinationPolicy propertyValueCombinationPolicy;
+
+ /**
+ * Lock for internal synchronization.
+ */
+ private final ReadWriteLock propertySourceLock = new ReentrantReadWriteLock();
+
+
+ /**
+ * The first time the Configuration system gets invoked we do initialize
+ * all our {@link org.apache.tamaya.spi.PropertySource}s and
+ * {@link org.apache.tamaya.spi.PropertyFilter}s which are known at startup.
+ */
+ @SuppressWarnings("unchecked")
+ public ProgrammaticConfigurationContext(Builder builder) {
+ propertyConverterManager = new PropertyConverterManager(builder.loadProvidedPropertyConverters);
+
+ List<PropertySource> sources = getAllPropertySources(builder);
+ Collections.sort(sources, PS_COMPARATOR);
+ immutablePropertySources = Collections.unmodifiableList(sources);
+
+
+ List<PropertyFilter> filters = getPropertyFilters(builder);
+ Collections.sort(filters, COMP_COMPARATOR);
+ immutablePropertyFilters = Collections.unmodifiableList(filters);
+
+
+ propertyValueCombinationPolicy = builder.propertyValueCombinationPolicy;
+ for(Map.Entry<TypeLiteral<?>, List<PropertyConverter<?>>> en: builder.propertyConverters.entrySet()){
+ if(en!=null){
+ for(PropertyConverter pv:en.getValue()) {
+ propertyConverterManager.register(en.getKey(), pv);
+ }
+ }
+ }
+
+ LOG.info("Using " + immutablePropertySources.size() + " property sources: " + immutablePropertySources);
+ LOG.info("Using " + immutablePropertyFilters.size() + " property filters: " + immutablePropertyFilters);
+ LOG.info("Using PropertyValueCombinationPolicy: " + propertyValueCombinationPolicy);
+ }
+
+ private List<PropertyFilter> getPropertyFilters(Builder builder) {
+ List<PropertyFilter> provided = new ArrayList<>();
+ if(builder.loadProvidedPropertyFilters) {
+ provided.addAll(ServiceContextManager.getServiceContext().getServices(PropertyFilter.class));
+ }
+ for(PropertyFilter pf:builder.propertyFilters) {
+ if (pf != null) {
+ provided.add(pf);
+ }
+ }
+ return provided;
+ }
+
+ private List<PropertySource> getAllPropertySources(Builder builder) {
+ List<PropertySource> provided = new ArrayList<>();
+ if(builder.loadProvidedPropertySources) {
+ provided.addAll(ServiceContextManager.getServiceContext().getServices(PropertySource.class));
+ }
+ for(PropertySource ps:builder.propertySources){
+ if(ps!=null){
+ provided.add(ps);
+ }
+ }
+ if (builder.loadProvidedPropertySourceProviders) {
+ List<PropertySourceProvider> providers = ServiceContextManager.getServiceContext()
+ .getServices(PropertySourceProvider.class);
+ for (PropertySourceProvider provider : providers) {
+ for(PropertySource ps:provider.getPropertySources()) {
+ if(ps!=null) {
+ provided.addAll(provider.getPropertySources());
+ }
+ }
+ }
+ }
+ return provided;
+ }
+
+ public void addPropertySources(PropertySource... propertySourcesToAdd) {
+ Lock writeLock = propertySourceLock.writeLock();
+ try {
+ writeLock.lock();
+ List<PropertySource> provided = new ArrayList<>();
+ for(PropertySource ps:propertySourcesToAdd){
+ if(ps!=null){
+ provided.add(ps);
+ }
+ }
+ this.immutablePropertySources = Collections.unmodifiableList(provided);
+ } finally {
+ writeLock.unlock();
+ }
+ }
+
+ /**
+ * Order property source reversely, the most important come first.
+ *
+ * @param source1 the first PropertySource
+ * @param source2 the second PropertySource
+ * @return the comparison result.
+ */
+ private int comparePropertySources(PropertySource source1, PropertySource source2) {
+
+ //X TODO this method duplicates org.apache.tamaya.core.internal.DefaultConfigurationContext.PropertySourceComparator.comparePropertySources()
+ //X maybe we should extract the Comperator in an own class for real code-reuse (copy paste == bad code reuse)
+
+ if (source1.getOrdinal() < source2.getOrdinal()) {
+ return -1;
+ } else if (source1.getOrdinal() > source2.getOrdinal()) {
+ return 1;
+ } else {
+ return source1.getClass().getName().compareTo(source2.getClass().getName());
+ }
+ }
+
+ /**
+ * Compare 2 filters for ordering the filter chain.
+ *
+ * @param filter1 the first filter
+ * @param filter2 the second filter
+ * @return the comparison result
+ */
+ private int comparePropertyFilters(PropertyFilter filter1, PropertyFilter filter2) {
+
+ //X TODO this method duplicates org.apache.tamaya.core.internal.DefaultConfigurationContext.PropertySourceComparator.comparePropertyFilters()
+ //X maybe we should extract the Comperator in an own class for real code-reuse (copy paste == bad code reuse)
+
+ Priority prio1 = filter1.getClass().getAnnotation(Priority.class);
+ Priority prio2 = filter2.getClass().getAnnotation(Priority.class);
+ int ord1 = prio1 != null ? prio1.value() : 0;
+ int ord2 = prio2 != null ? prio2.value() : 0;
+
+ if (ord1 < ord2) {
+ return -1;
+ } else if (ord1 > ord2) {
+ return 1;
+ } else {
+ return filter1.getClass().getName().compareTo(filter2.getClass().getName());
+ }
+ }
+
+ @Override
+ public List<PropertySource> getPropertySources() {
+ return immutablePropertySources;
+ }
+
+ public <T> void addPropertyConverter(TypeLiteral<T> typeToConvert, PropertyConverter<T> propertyConverter) {
+ propertyConverterManager.register(typeToConvert, propertyConverter);
+ LOG.info("Added PropertyConverter: " + propertyConverter.getClass().getName());
+ }
+
+ @Override
+ public Map<TypeLiteral<?>, List<PropertyConverter<?>>> getPropertyConverters() {
+ return propertyConverterManager.getPropertyConverters();
+ }
+
+ @Override
+ public <T> List<PropertyConverter<T>> getPropertyConverters(TypeLiteral<T> targetType) {
+ return propertyConverterManager.getPropertyConverters(targetType);
+ }
+
+ @Override
+ public List<PropertyFilter> getPropertyFilters() {
+ return immutablePropertyFilters;
+ }
+
+ @Override
+ public PropertyValueCombinationPolicy getPropertyValueCombinationPolicy() {
+ return propertyValueCombinationPolicy;
+ }
+
+
+ @Override
+ public ConfigurationContextBuilder toBuilder() {
+ // @todo Check if it could be useful to support this method, Oliver B. Fischer
+ throw new RuntimeException("This method is currently not supported.");
+ }
+
+ /**
+ * The Builder for {@link ProgrammaticConfigurationContext}
+ */
+ public final static class Builder {
+ /**
+ * The current unmodifiable list of loaded {@link org.apache.tamaya.spi.PropertySource} instances.
+ */
+ private final List<PropertySource> propertySources = new ArrayList<>();
+
+ /**
+ * The current unmodifiable list of loaded {@link org.apache.tamaya.spi.PropertyFilter} instances.
+ */
+ private final List<PropertyFilter> propertyFilters = new ArrayList<>();
+
+ private final Map<TypeLiteral<?>, List<PropertyConverter<?>>> propertyConverters = new HashMap<>();
+
+ /**
+ * The overriding policy used when combining PropertySources registered to evalute the final configuration
+ * values.
+ */
+ private PropertyValueCombinationPolicy propertyValueCombinationPolicy =
+ PropertyValueCombinationPolicy.DEFAULT_OVERRIDING_COLLECTOR;
+
+ private boolean loadProvidedPropertyConverters;
+ private boolean loadProvidedPropertySources;
+ private boolean loadProvidedPropertySourceProviders;
+ private boolean loadProvidedPropertyFilters;
+
+ public Builder setPropertyValueCombinationPolicy(PropertyValueCombinationPolicy policy) {
+ this.propertyValueCombinationPolicy = Objects.requireNonNull(policy);
+ return this;
+ }
+
+ public Builder addPropertySources(PropertySource... propertySources) {
+ for (PropertySource ps : propertySources) {
+ if (ps != null) {
+ this.propertySources.add(ps);
+ }
+ }
+ return this;
+ }
+
+ public Builder addPropertySources(Collection<PropertySource> propertySources) {
+ for (PropertySource ps : propertySources) {
+ if (ps != null) {
+ this.propertySources.add(ps);
+ }
+ }
+ return this;
+ }
+
+ public Builder addPropertySourceProviders(PropertySourceProvider... propertySourceProviders) {
+ for (PropertySourceProvider ps : propertySourceProviders) {
+ if (ps != null) {
+ this.propertySources.addAll(ps.getPropertySources());
+ }
+ }
+ return this;
+ }
+
+ public Builder addPropertySourceProviders(Collection<PropertySourceProvider> propertySourceProviders) {
+ for (PropertySourceProvider ps : propertySourceProviders) {
+ if (ps != null) {
+ this.propertySources.addAll(ps.getPropertySources());
+ }
+ }
+ return this;
+ }
+
+ public Builder addPropertyFilters(PropertyFilter... propertyFIlter) {
+ for (PropertyFilter pf : propertyFIlter) {
+ if (pf != null) {
+ this.propertyFilters.add(pf);
+ }
+ }
+ return this;
+ }
+
+ public Builder addPropertyFilters(Collection<PropertyFilter> propertyFIlter) {
+ for (PropertyFilter pf : propertyFIlter) {
+ if (pf != null) {
+ this.propertyFilters.add(pf);
+ }
+ }
+ return this;
+ }
+
+ /**
+ * Should be never used.
+ */
+ @Deprecated
+ public Builder setConfigurationContext(ConfigurationContext configurationContext) {
+ this.addPropertySources(configurationContext.getPropertySources());
+ this.addPropertyFilters(configurationContext.getPropertyFilters());
+ this.propertyValueCombinationPolicy = Objects.requireNonNull(
+ configurationContext.getPropertyValueCombinationPolicy());
+ return this;
+ }
+
+ //X TODO think on a functonality/API for using the default PropertyConverters and use the configured ones here
+ //X TODO as overrides used first.
+
+ public <T> Builder addPropertyConverter(TypeLiteral<T> type, PropertyConverter<T> propertyConverter) {
+ if(!propertyConverters.containsKey(type)){
+ List<PropertyConverter<?>> convList = new ArrayList<>();
+ convList.add(propertyConverter);
+ propertyConverters.put(type, convList);
+ }
+ return this;
+ }
+
+ public ConfigurationContext build() {
+ return new ProgrammaticConfigurationContext(this);
+ }
+
+
+ public void loadProvidedPropertyConverters(boolean state) {
+ loadProvidedPropertyConverters = state;
+ }
+
+ public void loadProvidedPropertySources(boolean state) {
+ loadProvidedPropertySources = state;
+ }
+
+ public void loadProvidedPropertySourceProviders(boolean state) {
+ loadProvidedPropertySourceProviders = state;
+ }
+
+ public void loadProvidedPropertyFilters(boolean state) {
+ loadProvidedPropertyFilters = state;
+ }
+
+ }
+
+
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/f45a5bb5/builder/src/main/java/org/apache/tamaya/builder/PropertySourceBuilder.java
----------------------------------------------------------------------
diff --git a/builder/src/main/java/org/apache/tamaya/builder/PropertySourceBuilder.java b/builder/src/main/java/org/apache/tamaya/builder/PropertySourceBuilder.java
new file mode 100644
index 0000000..481a80c
--- /dev/null
+++ b/builder/src/main/java/org/apache/tamaya/builder/PropertySourceBuilder.java
@@ -0,0 +1,118 @@
+/*
+ * 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.builder;
+
+import org.apache.tamaya.spi.PropertySource;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Objects;
+
+/**
+ * Simple builder for building a {@link org.apache.tamaya.spi.PropertySource}.
+ */
+public final class PropertySourceBuilder {
+ /** The ordinal to be used. */
+ private int ordinal;
+ /** The name to be used. */
+ private final String name;
+ /** The properties. */
+ private final Map<String,String> properties = new HashMap<>();
+
+ /** private constructor. */
+ private PropertySourceBuilder(String name){
+ this.name = Objects.requireNonNull(name);
+ }
+
+ /**
+ * Gets a new instance of a builder.
+ * @param name The name of the property source, not null.
+ * @return a new instance.
+ */
+ public static PropertySourceBuilder of(String name){
+ return new PropertySourceBuilder(name);
+ }
+
+ /**
+ * Gets a new instance of a builder.
+ * @param name The name of the property source, not null.
+ * @return a new instance.
+ */
+ public static PropertySourceBuilder from(String name){
+ return new PropertySourceBuilder(name);
+ }
+
+ /**
+ * Sets a new property key/value.
+ * @param key the property key, not null.
+ * @param value the property value, not null.
+ * @return the bulder for chaining.
+ */
+ public PropertySourceBuilder put(String key, String value){
+ this.properties.put(key, value);
+ return this;
+ }
+
+ /**
+ * Put all the given key, values.
+ * @param values the new key/values, not null.
+ * @return the bulder for chaining.
+ */
+ public PropertySourceBuilder putAll(Map<String, String> values){
+ this.properties.putAll(values);
+ return this;
+ }
+
+ /**
+ * Sets the ordinal to be used explicitly (instead evaluating it using {@code tamaya.ordinal}.
+ * @param ordinal the explicit ordinal to be used.
+ * @return the bulder for chaining.
+ */
+ public PropertySourceBuilder withOrdinal(int ordinal){
+ this.ordinal = ordinal;
+ return this;
+ }
+
+ /**
+ * Puts all values from the given property source.
+ * @param propertySource the property source, not null.
+ * @return the bulder for chaining.
+ */
+ public PropertySourceBuilder putAll(PropertySource propertySource){
+ this.properties.putAll(propertySource.getProperties());
+ return this;
+ }
+
+ /**
+ * Creates a new immutable {@link org.apache.tamaya.spi.PropertySource} instance.
+ * @return a new immutable {@link org.apache.tamaya.spi.PropertySource} instance, never null.
+ */
+ public PropertySource build(){
+ return new SimplePropertySource(name, properties);
+ }
+
+ @Override
+ public String toString() {
+ return "PropertySourceBuilder{" +
+ "ordinal=" + ordinal +
+ ", name='" + name + '\'' +
+ ", properties=" + properties +
+ '}';
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/f45a5bb5/builder/src/main/java/org/apache/tamaya/builder/SimplePropertySource.java
----------------------------------------------------------------------
diff --git a/builder/src/main/java/org/apache/tamaya/builder/SimplePropertySource.java b/builder/src/main/java/org/apache/tamaya/builder/SimplePropertySource.java
new file mode 100644
index 0000000..085bd9a
--- /dev/null
+++ b/builder/src/main/java/org/apache/tamaya/builder/SimplePropertySource.java
@@ -0,0 +1,86 @@
+/*
+ * 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.builder;
+
+import org.apache.tamaya.spi.PropertySource;
+import org.apache.tamaya.spi.PropertyValue;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Objects;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+* Simple property source implementation using a map.
+*/
+public class SimplePropertySource implements PropertySource {
+ /** The properties. */
+ private final Map<String, String> properties;
+ /** The source's name. */
+ private final String name;
+
+ public SimplePropertySource(String name, Map<String, String> properties){
+ this.properties = new HashMap<>(properties);
+ this.name = Objects.requireNonNull(name);
+ }
+
+ @Override
+ public int getOrdinal(){
+ PropertyValue configuredOrdinal = get(TAMAYA_ORDINAL);
+ if(configuredOrdinal!=null){
+ try{
+ return Integer.parseInt(configuredOrdinal.getValue());
+ } catch(Exception e){
+ Logger.getLogger(getClass().getName()).log(Level.WARNING,
+ "Configured Ordinal is not an int number: " + configuredOrdinal, e);
+ }
+ }
+ return getDefaultOrdinal();
+ }
+
+ public int getDefaultOrdinal(){
+ return 0;
+ }
+
+ @Override
+ public String getName() {
+ return name;
+ }
+
+ @Override
+ public PropertyValue get(String key) {
+ return null;
+ }
+
+ @Override
+ public Map<String, String> getProperties() {
+ return this.properties;
+ }
+
+ @Override
+ public boolean isScannable() {
+ return false;
+ }
+
+ @Override
+ public String toString(){
+ return "SimplePropertySource(name="+name+", numProps="+properties.size()+")";
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/f45a5bb5/builder/src/main/java/org/apache/tamaya/builder/package-info.java
----------------------------------------------------------------------
diff --git a/builder/src/main/java/org/apache/tamaya/builder/package-info.java b/builder/src/main/java/org/apache/tamaya/builder/package-info.java
new file mode 100644
index 0000000..24c86a9
--- /dev/null
+++ b/builder/src/main/java/org/apache/tamaya/builder/package-info.java
@@ -0,0 +1,28 @@
+/*
+ * 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.
+ */
+/**
+ * This package provides
+ * {@link org.apache.tamaya.builder.ConfigurationBuilder a configuration
+ * builder} that allows to build a configuration manually without
+ * using exclusively on the Service Provider Interface API of Tamaya.
+ *
+ * @see org.apache.tamaya.builder.ConfigurationBuilder
+ * @see org.apache.tamaya.Configuration
+ */
+package org.apache.tamaya.builder;
\ No newline at end of file
[45/50] [abbrv] incubator-tamaya-sandbox git commit: Set new
development version.
Posted by pl...@apache.org.
Set new development version.
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/09ab45b0
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/tree/09ab45b0
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/diff/09ab45b0
Branch: refs/heads/master
Commit: 09ab45b0196e563ea0252ced67c5d402b984b1d1
Parents: 6e57351
Author: anatole <an...@apache.org>
Authored: Thu Apr 14 00:47:11 2016 +0200
Committer: anatole <an...@apache.org>
Committed: Thu Apr 14 00:47:11 2016 +0200
----------------------------------------------------------------------
pom.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/09ab45b0/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index 9202d80..96f6244 100644
--- a/pom.xml
+++ b/pom.xml
@@ -23,7 +23,7 @@ under the License.
<parent>
<groupId>org.apache.tamaya.ext</groupId>
<artifactId>tamaya-extensions</artifactId>
- <version>0.2-incubating</version>
+ <version>0.3-incubating-SNAPSHOT</version>
</parent>
<artifactId>tamaya-builder</artifactId>
[31/50] [abbrv] incubator-tamaya-sandbox git commit: Unified module
name in poms.
Posted by pl...@apache.org.
Unified module name in poms.
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/25d8ce13
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/tree/25d8ce13
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/diff/25d8ce13
Branch: refs/heads/master
Commit: 25d8ce1356b163651d1fe8f6536dbc9747b1bc65
Parents: 714305e
Author: anatole <an...@apache.org>
Authored: Sat Jan 16 07:40:08 2016 +0100
Committer: anatole <an...@apache.org>
Committed: Sat Jan 16 07:40:08 2016 +0100
----------------------------------------------------------------------
pom.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/25d8ce13/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index 90b07e7..c7da3f8 100644
--- a/pom.xml
+++ b/pom.xml
@@ -27,7 +27,7 @@ under the License.
</parent>
<artifactId>tamaya-builder</artifactId>
- <name>Apache Tamaya Builder</name>
+ <name>Apache Tamaya Modules - Builder</name>
<packaging>jar</packaging> <!-- bundle -->
<inceptionYear>2015</inceptionYear>
[02/50] [abbrv] incubator-tamaya-sandbox git commit: TAMAYA-60
JavaDoc..
Posted by pl...@apache.org.
TAMAYA-60 JavaDoc..
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/0c4fe5c7
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/tree/0c4fe5c7
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/diff/0c4fe5c7
Branch: refs/heads/master
Commit: 0c4fe5c73ac2aae9100894c994840dad1819ae09
Parents: d7dd200
Author: Oliver B. Fischer <pl...@apache.org>
Authored: Tue Mar 10 22:57:55 2015 +0100
Committer: Oliver B. Fischer <pl...@apache.org>
Committed: Tue Mar 10 22:57:55 2015 +0100
----------------------------------------------------------------------
.../modules/builder/ConfigurationBuilder.java | 52 ++++++++++++++++++--
1 file changed, 49 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/0c4fe5c7/src/main/java/org/apache/tamaya/modules/builder/ConfigurationBuilder.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/tamaya/modules/builder/ConfigurationBuilder.java b/src/main/java/org/apache/tamaya/modules/builder/ConfigurationBuilder.java
index 173117a..ce26aad 100644
--- a/src/main/java/org/apache/tamaya/modules/builder/ConfigurationBuilder.java
+++ b/src/main/java/org/apache/tamaya/modules/builder/ConfigurationBuilder.java
@@ -122,7 +122,23 @@ public class ConfigurationBuilder {
}
/**
+ * Adds one resources with properties in an arbitrary format
+ * to the configuration to be build.
+ *
+ * <p>If a specific format is supported depends on the available
+ * {@link org.apache.tamaya.format.ConfigurationFormat} implementations.</p>
+ *
+ * <pre>{@code URL resource = new URL("file:/etc/service/config.json");
+ *
+ * builder.addPropertySources(resource);}
+ * </pre>
+ *
+ * @param url resource with properties for the the configuration to be build.
+ *
* @return the builder instance currently used
+ *
+ * @see org.apache.tamaya.format.ConfigurationFormat
+ * @see org.apache.tamaya.format.ConfigurationFormats#getFormats()
*/
public ConfigurationBuilder addPropertySource(URL url) {
try {
@@ -325,7 +341,7 @@ public class ConfigurationBuilder {
}
/**
- * Disables the loading of all {@link org.apache.tamaya.PropertyConverter}
+ * Disables the automatic loading of all {@link org.apache.tamaya.PropertyConverter}
* service providers.
*
* @return the builder instance currently used
@@ -343,7 +359,13 @@ public class ConfigurationBuilder {
/**
+ * Enables the automatic loading of all {@link org.apache.tamaya.spi.PropertySource}
+ * service providers.
+ *
* @return the builder instance currently used
+ *
+ * @see org.apache.tamaya.spi.PropertySource
+ * @see #disableProvidedPropertySources()
*/
public ConfigurationBuilder enableProvidedPropertySources() {
checkBuilderState();
@@ -353,11 +375,25 @@ public class ConfigurationBuilder {
return this;
}
+ /**
+ * Checks if the automatic loading of all {@link org.apache.tamaya.spi.PropertySource
+ * PropertySource} service providers is enabled or disabled.
+ *
+ * @return {@code true} if the automatic loading is enabled,
+ * otherwise {@code false}.
+ */
public boolean isPropertySourcesLoadingEnabled() {
return loadProvidedPropertySources;
}
+ /**
+ * Checks if the automatic loading of all {@link org.apache.tamaya.spi.PropertyFilter
+ * PropertyFilter} service providers is enabled or disabled.
+ *
+ * @return {@code true} if the automatic loading is enabled,
+ * otherwise {@code false}.
+ */
public boolean isPropertyFilterLoadingEnabled() {
return isLoadProvidedPropertyFilters;
}
@@ -375,7 +411,7 @@ public class ConfigurationBuilder {
}
/**
- * Disables the loading of all {@link org.apache.tamaya.spi.PropertyFilter}
+ * Disables the automatic loading of all {@link org.apache.tamaya.spi.PropertyFilter}
* service providers.
*
* @return the builder instance currently used
@@ -394,7 +430,13 @@ public class ConfigurationBuilder {
}
/**
+ * Disables the automatic loading of all {@link org.apache.tamaya.spi.PropertySource}
+ * service providers.
+ *
* @return the builder instance currently used
+ *
+ * @see org.apache.tamaya.spi.PropertySource
+ * @see #enableProvidedPropertySources()
*/
public ConfigurationBuilder disableProvidedPropertySources() {
checkBuilderState();
@@ -405,9 +447,13 @@ public class ConfigurationBuilder {
}
/**
- *
+ * Enables the automatic loading of {@link org.apache.tamaya.spi.PropertySourceProvider
+ * property source providers} provided via the SPI API.
*
* @return the builder instance currently used
+ *
+ * @see org.apache.tamaya.spi.PropertySourceProvider
+ * @see
*/
public ConfigurationBuilder enableProvidedPropertySourceProviders() {
checkBuilderState();
[06/50] [abbrv] incubator-tamaya-sandbox git commit: TAMAYA-60
Removed the modules package for the package hierarchy.
Posted by pl...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/f78f6a11/src/test/java/org/apache/tamaya/builder/ConfigurationBuilderTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/tamaya/builder/ConfigurationBuilderTest.java b/src/test/java/org/apache/tamaya/builder/ConfigurationBuilderTest.java
new file mode 100644
index 0000000..5f33c24
--- /dev/null
+++ b/src/test/java/org/apache/tamaya/builder/ConfigurationBuilderTest.java
@@ -0,0 +1,896 @@
+/*
+ * 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.builder;
+
+import org.apache.tamaya.ConfigException;
+import org.apache.tamaya.Configuration;
+import org.apache.tamaya.TypeLiteral;
+import org.apache.tamaya.builder.util.types.CustomTypeA;
+import org.apache.tamaya.builder.util.types.CustomTypeB;
+import org.apache.tamaya.builder.util.types.CustomTypeC;
+import org.apache.tamaya.spi.PropertyFilter;
+import org.apache.tamaya.spi.PropertySource;
+import org.apache.tamaya.spi.PropertySourceProvider;
+import org.hamcrest.CoreMatchers;
+import org.hamcrest.Matchers;
+import org.junit.Ignore;
+import org.junit.Test;
+import org.mockito.Mockito;
+
+
+import java.io.IOException;
+import java.net.URL;
+
+import static java.util.Arrays.asList;
+import static org.apache.tamaya.builder.util.mockito.NotMockedAnswer.NOT_MOCKED_ANSWER;
+import static org.hamcrest.CoreMatchers.equalTo;
+import static org.hamcrest.CoreMatchers.nullValue;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.is;
+import static org.hamcrest.Matchers.notNullValue;
+import static org.mockito.Matchers.anyString;
+import static org.mockito.Mockito.CALLS_REAL_METHODS;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.doThrow;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+
+
+public class ConfigurationBuilderTest {
+
+ @Test
+ public void buildCanBuildEmptyConfiguration() {
+ ConfigurationBuilder builder = new ConfigurationBuilder();
+
+ Configuration config = builder.build();
+
+ assertThat(config, notNullValue());
+ }
+
+ @Test(expected = IllegalStateException.class)
+ public void buildCanBeCalledOnlyOnce() {
+ ConfigurationBuilder builder = new ConfigurationBuilder();
+
+ builder.build();
+ builder.build();
+ }
+
+ /*********************************************************************
+ * Tests for adding P r o p e r t y S o u r c e s
+ */
+
+ @Test(expected = NullPointerException.class)
+ public void addPropertySourcesDoesNotAcceptNullValue() {
+ ConfigurationBuilder builder = new ConfigurationBuilder();
+
+ builder.addPropertySources((PropertySource[])null);
+ }
+
+ @Test(expected = IllegalStateException.class)
+ public void propertySourceCanNotBeAddedAfterBuildingTheConfiguration() {
+ PropertySource first = mock(PropertySource.class, NOT_MOCKED_ANSWER);
+
+ doReturn("first").when(first).getName();
+ doReturn(100).when(first).getOrdinal();
+
+ ConfigurationBuilder builder = new ConfigurationBuilder().addPropertySources(first);
+
+ builder.build();
+
+ PropertySource second = mock(PropertySource.class, NOT_MOCKED_ANSWER);
+
+ doReturn("second").when(first).getName();
+
+ builder.addPropertySources(second);
+ }
+
+ @Test
+ public void singleAddedPropertySourceIsUsed() {
+ PropertySource source = mock(PropertySource.class, NOT_MOCKED_ANSWER);
+
+ doReturn("one").when(source).getName();
+ doReturn("a").when(source).get("keyOfA");
+ doReturn(100).when(source).getOrdinal();
+
+ ConfigurationBuilder builder = new ConfigurationBuilder().addPropertySources(source);
+
+ Configuration config = builder.build();
+
+ String valueOfA = config.get("keyOfA");
+
+ assertThat(valueOfA, notNullValue());
+ assertThat(valueOfA, equalTo("a"));
+ }
+
+ @Test
+ public void twoAddedPropertySourcesAreUsed() {
+ PropertySource sourceOne = mock(PropertySource.class, NOT_MOCKED_ANSWER);
+
+ doReturn("one").when(sourceOne).getName();
+ doReturn("b").when(sourceOne).get("keyOfA");
+ doReturn(10).when(sourceOne).getOrdinal();
+
+ PropertySource sourceTwo = mock(PropertySource.class, NOT_MOCKED_ANSWER);
+ doReturn("two").when(sourceTwo).getName();
+ doReturn("a").when(sourceTwo).get("keyOfA");
+ doReturn(10).when(sourceTwo).getOrdinal();
+
+ ConfigurationBuilder builder = new ConfigurationBuilder().addPropertySources(sourceOne)
+ .addPropertySources(sourceTwo);
+
+ Configuration config = builder.build();
+
+ String valueOfA = config.get("keyOfA");
+
+ assertThat(valueOfA, notNullValue());
+ assertThat(valueOfA, equalTo("a"));
+ }
+
+ @Ignore
+ @Test(expected = ConfigException.class)
+ public void twoPropertySourcesSamePrioritySameKey() {
+ PropertySource sourceOne = mock(PropertySource.class, NOT_MOCKED_ANSWER);
+
+ doReturn("one").when(sourceOne).getName();
+ doReturn("b").when(sourceOne).get("keyOfA");
+ doReturn(20).when(sourceOne).getOrdinal();
+
+ PropertySource sourceTwo = mock(PropertySource.class, NOT_MOCKED_ANSWER);
+ doReturn("two").when(sourceTwo).getName();
+ doReturn("a").when(sourceTwo).get("keyOfA");
+ doReturn(20).when(sourceTwo).getOrdinal();
+
+ ConfigurationBuilder builder = new ConfigurationBuilder().addPropertySources(sourceOne)
+ .addPropertySources(sourceTwo);
+
+ Configuration config = builder.build();
+
+ config.get("keyOfA");
+ }
+
+ @Test
+ public void twoPropertySourcesDiffPrioritySameKeyLowerAddedFirst() {
+ PropertySource sourceOne = mock(PropertySource.class, NOT_MOCKED_ANSWER);
+
+ doReturn("one").when(sourceOne).getName();
+ doReturn("b").when(sourceOne).get("keyOfA");
+ doReturn(10).when(sourceOne).getOrdinal();
+
+ PropertySource sourceTwo = mock(PropertySource.class, NOT_MOCKED_ANSWER);
+ doReturn("two").when(sourceTwo).getName();
+ doReturn("a").when(sourceTwo).get("keyOfA");
+ doReturn(20).when(sourceTwo).getOrdinal();
+
+ ConfigurationBuilder builder = new ConfigurationBuilder().addPropertySources(sourceOne)
+ .addPropertySources(sourceTwo);
+
+ Configuration config = builder.build();
+
+ String valueOfA = config.get("keyOfA");
+
+ assertThat(valueOfA, notNullValue());
+ assertThat(valueOfA, equalTo("a"));
+ }
+
+ @Test
+ public void twoPropertySourcesDiffPrioritySameKeyHigherAddedFirst() {
+ PropertySource sourceOne = mock(PropertySource.class, NOT_MOCKED_ANSWER);
+
+ doReturn("one").when(sourceOne).getName();
+ doReturn("b").when(sourceOne).get("keyOfA");
+ doReturn(30).when(sourceOne).getOrdinal();
+
+ PropertySource sourceTwo = mock(PropertySource.class, NOT_MOCKED_ANSWER);
+ doReturn("two").when(sourceTwo).getName();
+ doReturn("a").when(sourceTwo).get("keyOfA");
+ doReturn(20).when(sourceTwo).getOrdinal();
+
+ ConfigurationBuilder builder = new ConfigurationBuilder().addPropertySources(sourceOne, sourceTwo);
+
+ Configuration config = builder.build();
+
+ String valueOfA = config.get("keyOfA");
+
+ assertThat(valueOfA, notNullValue());
+ assertThat(valueOfA, equalTo("b"));
+ }
+
+ @Test
+ public void consecutiveCallsToAddPropertySourceArePossible() {
+ PropertySource sourceOne = mock(PropertySource.class, NOT_MOCKED_ANSWER);
+
+ doReturn("one").when(sourceOne).getName();
+ doReturn(null).when(sourceOne).get(anyString());
+ doReturn("b").when(sourceOne).get("b");
+ doReturn(30).when(sourceOne).getOrdinal();
+
+ PropertySource sourceTwo = mock(PropertySource.class, NOT_MOCKED_ANSWER);
+ doReturn("two").when(sourceTwo).getName();
+ doReturn(null).when(sourceTwo).get(anyString());
+ doReturn("a").when(sourceTwo).get("a");
+ doReturn(30).when(sourceTwo).getOrdinal();
+
+ ConfigurationBuilder builder = new ConfigurationBuilder().addPropertySources(sourceOne)
+ .addPropertySources(sourceTwo);
+
+ Configuration config = builder.build();
+
+ assertThat(config.get("b"), equalTo("b"));
+ assertThat(config.get("a"), equalTo("a"));
+ }
+
+ @Test
+ public void addMultiplePropertySourcesWhereOneIsNull() {
+ PropertySource sourceOne = mock(PropertySource.class, NOT_MOCKED_ANSWER);
+
+ doReturn("one").when(sourceOne).getName();
+ doReturn(null).when(sourceOne).get(anyString());
+ doReturn("b").when(sourceOne).get("b");
+ doReturn(30).when(sourceOne).getOrdinal();
+
+ PropertySource sourceTwo = mock(PropertySource.class, NOT_MOCKED_ANSWER);
+ doReturn("two").when(sourceTwo).getName();
+ doReturn(null).when(sourceTwo).get(anyString());
+ doReturn("a").when(sourceTwo).get("a");
+ doReturn(30).when(sourceTwo).getOrdinal();
+
+ ConfigurationBuilder builder = new ConfigurationBuilder().addPropertySources(sourceOne, null, sourceTwo);
+
+ Configuration config = builder.build();
+
+ assertThat(config.get("b"), equalTo("b"));
+ assertThat(config.get("a"), equalTo("a"));
+ }
+
+ /**
+ * ******************************************************************
+ * Tests for adding P r o p e r t y C o n v e r t e r
+ */
+
+ @Test(expected = NullPointerException.class)
+ public void canNotAddNullPropertyConverter() {
+ ConfigurationBuilder builder = new ConfigurationBuilder();
+
+ builder.addPropertyConverter(TypeLiteral.of(CustomTypeA.class), null);
+ }
+
+ @Test(expected = NullPointerException.class)
+ public void canNotAddNullTypeLiteralButPropertyConverter() {
+ ConfigurationBuilder builder = new ConfigurationBuilder();
+
+ builder.addPropertyConverter((TypeLiteral<CustomTypeA>)null,
+ prop -> new CustomTypeA(prop, prop));
+ }
+
+ @Test
+ public void addedPropertyConverterWithTypeLiteralIsUsedByConfiguration() {
+ PropertySource source = mock(PropertySource.class, NOT_MOCKED_ANSWER);
+
+ doReturn("source").when(source).getName();
+ doReturn("A").when(source).get("key");
+ doReturn(100).when(source).getOrdinal();
+
+ ConfigurationBuilder builder = new ConfigurationBuilder();
+
+ builder.addPropertyConverter(TypeLiteral.of(CustomTypeA.class),
+ prop -> new CustomTypeA(prop, prop))
+ .addPropertySources(source);
+
+ Configuration config = builder.build();
+
+ Object resultRaw = config.get("key", CustomTypeA.class);
+
+ assertThat(resultRaw, CoreMatchers.notNullValue());
+
+ CustomTypeA result = (CustomTypeA)resultRaw;
+
+ assertThat(result.getName(), equalTo("AA"));
+ }
+
+ @Test
+ public void addedPropertyConverterWithClassIsUsedByConfiguration() {
+ PropertySource source = mock(PropertySource.class, NOT_MOCKED_ANSWER);
+
+ doReturn("source").when(source).getName();
+ doReturn("A").when(source).get("key");
+ doReturn(100).when(source).getOrdinal();
+
+ ConfigurationBuilder builder = new ConfigurationBuilder();
+
+ builder.addPropertyConverter(CustomTypeA.class,
+ prop -> new CustomTypeA(prop, prop))
+ .addPropertySources(source);
+
+ Configuration config = builder.build();
+
+ Object resultRaw = config.get("key", CustomTypeA.class);
+
+ assertThat(resultRaw, CoreMatchers.notNullValue());
+
+ CustomTypeA result = (CustomTypeA)resultRaw;
+
+ assertThat(result.getName(), equalTo("AA"));
+ }
+
+ @Test
+ public void canGetAndConvertPropertyViaOfMethod() {
+ PropertySource source = mock(PropertySource.class, NOT_MOCKED_ANSWER);
+
+ doReturn("source").when(source).getName();
+ doReturn("A").when(source).get("key");
+ doReturn(100).when(source).getOrdinal();
+
+ ConfigurationBuilder builder = new ConfigurationBuilder();
+
+ builder.addPropertySources(source);
+
+ Configuration config = builder.build();
+
+ Object resultRaw = config.get("key", CustomTypeB.class);
+
+ assertThat(resultRaw, CoreMatchers.notNullValue());
+
+ CustomTypeB result = (CustomTypeB)resultRaw;
+
+ assertThat(result.getName(), equalTo("A"));
+ }
+
+ /*********************************************************************
+ * Tests for adding P r o p e r t y F i l t e r
+ */
+
+ @Test(expected = NullPointerException.class)
+ public void canNotAddNullAsPropertyFilter() {
+ ConfigurationBuilder builder = new ConfigurationBuilder();
+
+ builder.addPropertyFilters(null);
+ }
+
+ @Test
+ public void canAddNonSPIPropertyFilter() {
+ PropertySource source = mock(PropertySource.class, NOT_MOCKED_ANSWER);
+
+ doReturn("M").when(source).get("key");
+ doReturn("source").when(source).getName();
+
+ ConfigurationBuilder builder = new ConfigurationBuilder();
+
+ Configuration config = builder.addPropertySources(source)
+ .addPropertyFilters(new TestNonSPIPropertyFilterA())
+ .build();
+
+ String property = config.get("key");
+
+ assertThat(property, CoreMatchers.notNullValue());
+ assertThat(property, CoreMatchers.containsString("ABC"));
+ }
+
+ @Test
+ public void canAddNonSPIPropertyFiltersViaConsecutiveCalls() {
+ PropertySource source = mock(PropertySource.class, NOT_MOCKED_ANSWER);
+
+ doReturn("M").when(source).get("key");
+ doReturn("source").when(source).getName();
+
+ ConfigurationBuilder builder = new ConfigurationBuilder();
+
+ Configuration config = builder.addPropertySources(source)
+ .addPropertyFilters(new TestNonSPIPropertyFilterA())
+ .addPropertyFilters(new TestNonSPIPropertyFilterB())
+ .build();
+
+ String property = config.get("key");
+
+ assertThat(property, CoreMatchers.notNullValue());
+ assertThat(property, CoreMatchers.containsString("ABC"));
+ assertThat(property, CoreMatchers.containsString("XYZ"));
+ }
+
+ @Test
+ public void canAddMultipleNonSPIPropertyFiltersWhileOneIsNull() {
+ PropertySource source = mock(PropertySource.class, NOT_MOCKED_ANSWER);
+
+ doReturn("M").when(source).get("key");
+ doReturn("source").when(source).getName();
+
+ ConfigurationBuilder builder = new ConfigurationBuilder();
+
+ Configuration config = builder.addPropertySources(source)
+ .addPropertyFilters(new TestNonSPIPropertyFilterA(),
+ null,
+ new TestNonSPIPropertyFilterB())
+ .build();
+
+ String property = config.get("key");
+
+ assertThat(property, CoreMatchers.notNullValue());
+ assertThat(property, CoreMatchers.containsString("ABC"));
+ assertThat(property, CoreMatchers.containsString("XYZ"));
+ }
+
+ @Test
+ public void overhandedNullPropertyFilterIsSafelyHandled() {
+ PropertySource source = mock(PropertySource.class, NOT_MOCKED_ANSWER);
+
+ doReturn("M").when(source).get("key");
+ doReturn("source").when(source).getName();
+
+ ConfigurationBuilder builder = new ConfigurationBuilder();
+
+ Configuration config = builder.addPropertySources(source)
+ .addPropertyFilters((PropertyFilter)null) // The cast is needed!
+ .addPropertyFilters(new TestNonSPIPropertyFilterB())
+ .build();
+
+ String property = config.get("key");
+
+ assertThat(property, CoreMatchers.notNullValue());
+ assertThat(property, CoreMatchers.containsString("XYZ"));
+ }
+
+ @Test
+ public void canAddMultipleNonSPIPropertyFilter() {
+ PropertySource source = mock(PropertySource.class, NOT_MOCKED_ANSWER);
+
+ doReturn("M").when(source).get("key");
+ doReturn("source").when(source).getName();
+
+ ConfigurationBuilder builder = new ConfigurationBuilder();
+
+ Configuration config = builder.addPropertySources(source)
+ .addPropertyFilters(new TestNonSPIPropertyFilterA(),
+ new TestNonSPIPropertyFilterB())
+ .build();
+
+ String property = config.get("key");
+
+ assertThat(property, CoreMatchers.notNullValue());
+ assertThat(property, CoreMatchers.containsString("ABC"));
+ assertThat(property, CoreMatchers.containsString("XYZ"));
+ }
+
+ /*********************************************************************
+ * Tests for adding
+ * P r o p e r t y S o u r c e P r o v i d e r s
+ */
+
+ @Test
+ public void handlesSafelyPropertyProviderReturningNullInsteadOfPropertySource() {
+ PropertySourceProvider nullReturning = mock(PropertySourceProvider.class, NOT_MOCKED_ANSWER);
+
+ doReturn(asList((PropertySource)null)).when(nullReturning).getPropertySources();
+
+ ConfigurationBuilder builder = new ConfigurationBuilder();
+
+ Configuration config = builder.addPropertySourceProviders(new TestPropertySourceProviderB(),
+ nullReturning,
+ new TestPropertySourceProvider())
+ .build();
+
+ assertThat(config.get("tpsp_a"), Matchers.equalTo("A"));
+ assertThat(config.get("tpsp_b"), Matchers.equalTo("B"));
+ assertThat(config.get("tpsp_x"), Matchers.equalTo("X"));
+ assertThat(config.get("tpsp_y"), Matchers.equalTo("Y"));
+
+ verify(nullReturning).getPropertySources();
+ }
+
+ @Test(expected = NullPointerException.class)
+ public void cannotAddNullAsPropertyProvider() {
+ new ConfigurationBuilder().addPropertySourceProviders(null);
+ }
+
+ @Test
+ public void canAddMultipleNonSPIPropertySourceProviders() {
+ ConfigurationBuilder builder = new ConfigurationBuilder();
+
+ Configuration config = builder.addPropertySourceProviders(new TestPropertySourceProviderB(),
+ new TestPropertySourceProvider())
+ .build();
+
+ assertThat(config.get("tpsp_a"), Matchers.equalTo("A"));
+ assertThat(config.get("tpsp_b"), Matchers.equalTo("B"));
+ assertThat(config.get("tpsp_x"), Matchers.equalTo("X"));
+ assertThat(config.get("tpsp_y"), Matchers.equalTo("Y"));
+ }
+
+ @Test
+ public void canAddMultipleNonSPIPropertySourceProvidersWhileOfOfThemIsNull() {
+ ConfigurationBuilder builder = new ConfigurationBuilder();
+
+ Configuration config = builder.addPropertySourceProviders(new TestPropertySourceProviderB(), null,
+ new TestPropertySourceProvider())
+ .build();
+
+ assertThat(config.get("tpsp_a"), Matchers.equalTo("A"));
+ assertThat(config.get("tpsp_b"), Matchers.equalTo("B"));
+ assertThat(config.get("tpsp_x"), Matchers.equalTo("X"));
+ assertThat(config.get("tpsp_y"), Matchers.equalTo("Y"));
+ }
+
+
+ /*********************************************************************
+ * Tests for adding
+ * P r o p e r t y V a l u e C o m b i n a t i o n P o l i c y
+ */
+
+ // @todo TAYAMA-60 Write more tests
+
+ /*********************************************************************
+ * Tests for enabling and disabling of automatic loading of
+ * P r o p e r t y S o u r c e s
+ */
+
+ @Test
+ public void enablingOfProvidedPropertySourceServiceProvidersIsOk() {
+ ConfigurationBuilder builder = new ConfigurationBuilder();
+
+ builder.disableProvidedPropertyConverters()
+ .enableProvidedPropertyConverters();
+
+ assertThat(builder.isPropertyConverterLoadingEnabled(), is(true));
+ }
+
+ @Test
+ public void disablingOfProvidedPropertySourceServiceProvidersIsOk() {
+ ConfigurationBuilder builder = new ConfigurationBuilder();
+
+ builder.enableProvidedPropertyConverters()
+ .disableProvidedPropertyConverters();
+
+ assertThat(builder.isPropertyConverterLoadingEnabled(), is(false));
+ }
+
+ @Test(expected = ConfigException.class)
+ public void loadingOrPropertyConvertersCanBeDisabled() {
+ PropertySource source = mock(PropertySource.class, NOT_MOCKED_ANSWER);
+
+ doReturn("source").when(source).getName();
+ doReturn("A").when(source).get("key");
+ doReturn(100).when(source).getOrdinal();
+
+ ConfigurationBuilder builder = new ConfigurationBuilder().addPropertySources(source)
+ .enableProvidedPropertyConverters()
+ .disableProvidedPropertyConverters();
+
+ Configuration config = builder.build();
+
+ config.get("key", CustomTypeC.class);
+ }
+
+ @Test
+ public void loadingOfPropertyConvertersCanBeEnabled() {
+ PropertySource source = mock(PropertySource.class, NOT_MOCKED_ANSWER);
+
+ doReturn("source").when(source).getName();
+ doReturn("A").when(source).get("key");
+ doReturn(100).when(source).getOrdinal();
+
+ ConfigurationBuilder builder = new ConfigurationBuilder().addPropertySources(source)
+ .disableProvidedPropertyConverters()
+ .enableProvidedPropertyConverters();
+
+ Configuration config = builder.build();
+
+ CustomTypeC result = config.get("key", CustomTypeC.class);
+
+ assertThat(result, notNullValue());
+ assertThat(result.getValue(), equalTo("A"));
+ }
+
+ /*********************************************************************
+ * Tests for enabling and disabling of automatic loading of
+ * P r o p e r t y S o u r c e s
+ */
+
+ @Test
+ public void enablingOfPropertySourceLoadingIsOk() {
+ ConfigurationBuilder builder = new ConfigurationBuilder();
+
+ builder.disableProvidedPropertySources()
+ .enableProvidedPropertySources();
+
+ assertThat(builder.isPropertySourcesLoadingEnabled(), is(true));
+ }
+
+ @Test
+ public void disablingPropertySourceLoadingIsOk() {
+ ConfigurationBuilder builder = new ConfigurationBuilder();
+
+ builder.enableProvidedPropertySources()
+ .disableProvidedPropertySources();
+
+ assertThat(builder.isPropertySourcesLoadingEnabled(), is(false));
+ }
+
+ @Test
+ public void loadingOfPropertySourcesCanBeEnabled() {
+ ConfigurationBuilder builder = new ConfigurationBuilder();
+
+ Configuration config = builder.disableProvidedPropertySources()
+ .enableProvidedPropertySources()
+ .build();
+
+
+ assertThat(builder.isPropertySourcesLoadingEnabled(), is(true));
+ assertThat(config.get("tps_a"), Matchers.equalTo("A"));
+ }
+
+ @Test
+ public void loadingOfPropertySourcesCanBeDisabled() {
+ ConfigurationBuilder builder = new ConfigurationBuilder();
+
+ Configuration config = builder.enableProvidedPropertySources()
+ .disableProvidedPropertySources()
+ .build();
+
+
+ assertThat(builder.isPropertySourcesLoadingEnabled(), is(false));
+ assertThat(config.get("tps_c"), Matchers.nullValue());
+ }
+
+ /*********************************************************************
+ * Tests for enabling and disabling of automatic loading of
+ * P r o p e r t y F i l t e r s
+ */
+
+ @Test
+ public void enablingOfPropertyFiltersLoadingIsOk() {
+ PropertySource source = mock(PropertySource.class, NOT_MOCKED_ANSWER);
+
+ doReturn("source").when(source).getName();
+ doReturn("A").when(source).get("key");
+ doReturn(100).when(source).getOrdinal();
+
+ ConfigurationBuilder builder = new ConfigurationBuilder();
+
+ Configuration config = builder.disableProvidedPropertyFilters()
+ .enabledProvidedPropertyFilters()
+ .addPropertySources(source)
+ .build();
+
+ String property = config.get("key");
+
+ assertThat(property, CoreMatchers.notNullValue());
+ assertThat(property, Matchers.equalTo("AinBerlin"));
+ }
+
+ @Test
+ public void disablingOfPropertyFiltersLoadingIsOk() {
+ ConfigurationBuilder builder = new ConfigurationBuilder();
+
+ builder.enabledProvidedPropertyFilters()
+ .disableProvidedPropertyFilters();
+
+ assertThat(builder.isPropertyFilterLoadingEnabled(), is(false));
+ }
+
+ @Test
+ public void loadingOfPropertyFiltersCanBeDisabled() {
+ ConfigurationBuilder builder = new ConfigurationBuilder();
+
+ builder.disableProvidedPropertyFilters()
+ .enabledProvidedPropertyFilters();
+
+ assertThat(builder.isPropertyFilterLoadingEnabled(), is(true));
+ }
+
+ @Test
+ public void loadingOfPropertyFiltersCanBeEnabled() {
+ PropertySource source = mock(PropertySource.class, NOT_MOCKED_ANSWER);
+
+ doReturn("source").when(source).getName();
+ doReturn("A").when(source).get("key");
+ doReturn(100).when(source).getOrdinal();
+
+ ConfigurationBuilder builder = new ConfigurationBuilder();
+
+ Configuration config = builder.enabledProvidedPropertyFilters()
+ .disableProvidedPropertyFilters()
+ .addPropertySources(source)
+ .build();
+
+ String property = config.get("key");
+
+ assertThat(property, CoreMatchers.notNullValue());
+ assertThat(property, Matchers.equalTo("A"));
+ }
+
+ /*********************************************************************
+ * Tests for enabling and disabling of automatic loading of
+ * P r o p e r t y S o u r c e P r o v i d e r s
+ */
+
+ @Test
+ public void disablingOfPropertySourceProvidersIsOk() {
+ ConfigurationBuilder builder = new ConfigurationBuilder();
+
+ builder.enableProvidedPropertySourceProviders()
+ .disableProvidedPropertySourceProviders()
+ .build();
+
+ assertThat(builder.isPropertySourceProvidersLoadingEnabled(), is(false));
+ }
+
+ @Test
+ public void enablingOfPropertySourceProvidersIsOk() {
+
+ ConfigurationBuilder builder = new ConfigurationBuilder();
+
+ builder.disableProvidedPropertySourceProviders()
+ .enableProvidedPropertySourceProviders()
+ .build();
+
+ assertThat(builder.isPropertySourceProvidersLoadingEnabled(), is(true));
+ }
+
+ @Test
+ public void loadingOfPropertySourceProvidersCanBeEnabled() {
+ ConfigurationBuilder builder = new ConfigurationBuilder();
+
+ Configuration config = builder.disableProvidedPropertySourceProviders()
+ .enableProvidedPropertySourceProviders()
+ .build();
+
+ assertThat(builder.isPropertySourceProvidersLoadingEnabled(), is(true));
+ assertThat(config.get("tpsp_x"), Matchers.equalTo("X"));
+ assertThat(config.get("tpsp_y"), Matchers.equalTo("Y"));
+ }
+
+ @Test
+ public void loadingOfPropertySourceProvidersCanBeDisabled() {
+ ConfigurationBuilder builder = new ConfigurationBuilder();
+
+ Configuration config = builder.enableProvidedPropertySourceProviders()
+ .disableProvidedPropertySourceProviders()
+ .build();
+
+ assertThat(builder.isPropertySourceProvidersLoadingEnabled(), is(false));
+ assertThat(config.get("tpsp_x"), nullValue());
+ assertThat(config.get("tpsp_x"), nullValue());
+ }
+
+ @Test(expected = ConfigException.class)
+ public void ioExceptionIsTurnedInConfigExceptionWhenLoadingResourceViaURL() throws Exception {
+ URL resource = this.getClass().getResource("/configfiles/json/simple.json");
+
+ assertThat(resource, CoreMatchers.notNullValue());
+
+ ConfigurationBuilder builder = mock(ConfigurationBuilder.class, CALLS_REAL_METHODS);
+
+ doThrow(IOException.class).when(builder).getConfigurationDataFromURL(Mockito.eq(resource));
+
+ builder.addPropertySource(resource).build();
+ }
+
+ /*********************************************************************
+ * Tests for loading resources via URL (as String)
+ */
+
+ @Test(expected = ConfigException.class)
+ public void tryToLoadOneUnsupportedPropertySourceViaStringURL() {
+ URL resource = this.getClass().getResource("/configfiles/other/simple.oml");
+
+ assertThat(resource, CoreMatchers.notNullValue());
+
+ ConfigurationBuilder builder = new ConfigurationBuilder();
+
+ builder.addPropertySource(resource.toString()).build();
+ }
+
+ @Test
+ public void loadOneJSONPropertySourceViaStringURL() {
+ URL resource = this.getClass().getResource("/configfiles/json/simple.json");
+
+ assertThat(resource, CoreMatchers.notNullValue());
+
+ ConfigurationBuilder builder = new ConfigurationBuilder();
+
+ Configuration config = builder.addPropertySource(resource.toString())
+ .build();
+
+ assertThat(config, CoreMatchers.notNullValue());
+ assertThat(config.get("a"), equalTo("A"));
+ assertThat(config.get("b"), equalTo("B"));
+ }
+
+ @Test
+ public void loadMultipleJSONPropertySourceViaStringURL() {
+ URL first = this.getClass().getResource("/configfiles/json/first.json");
+ URL second = this.getClass().getResource("/configfiles/json/second.json");
+ URL third = this.getClass().getResource("/configfiles/json/third.json");
+
+ assertThat(first, CoreMatchers.notNullValue());
+ assertThat(second, CoreMatchers.notNullValue());
+ assertThat(third, CoreMatchers.notNullValue());
+
+ ConfigurationBuilder builder = new ConfigurationBuilder();
+
+ Configuration config = builder.addPropertySource(first.toString(), second.toString(),
+ null, third.toString())
+ .build();
+
+ assertThat(config, CoreMatchers.notNullValue());
+
+ // from first.json
+ assertThat(config.get("d"), equalTo("D"));
+ assertThat(config.get("e"), equalTo("E"));
+
+ // from second.json
+ assertThat(config.get("m"), equalTo("M"));
+ assertThat(config.get("n"), equalTo("N"));
+
+ // from thrid.json
+ assertThat(config.get("p"), equalTo("P"));
+ assertThat(config.get("q"), equalTo("Q"));
+ }
+
+ /**
+ * ******************************************************************
+ * Tests for loading resources via URL (as URL object)
+ */
+
+ @Test
+ public void loadOneJSONPropertySourceViaURL() {
+ URL resource = this.getClass().getResource("/configfiles/json/simple.json");
+
+ assertThat(resource, CoreMatchers.notNullValue());
+
+ ConfigurationBuilder builder = new ConfigurationBuilder();
+
+ Configuration config = builder.addPropertySource(resource)
+ .build();
+
+ assertThat(config, CoreMatchers.notNullValue());
+ assertThat(config.get("a"), equalTo("A"));
+ assertThat(config.get("b"), equalTo("B"));
+ }
+
+ @Test
+ public void loadMultipleJSONPropertySourceViaURL() {
+ URL first = this.getClass().getResource("/configfiles/json/first.json");
+ URL second = this.getClass().getResource("/configfiles/json/second.json");
+ URL third = this.getClass().getResource("/configfiles/json/third.json");
+
+ assertThat(first, CoreMatchers.notNullValue());
+ assertThat(second, CoreMatchers.notNullValue());
+ assertThat(third, CoreMatchers.notNullValue());
+
+ ConfigurationBuilder builder = new ConfigurationBuilder();
+
+ Configuration config = builder.addPropertySource(first, second,
+ null, third)
+ .build();
+
+ assertThat(config, CoreMatchers.notNullValue());
+
+ // from first.json
+ assertThat(config.get("d"), equalTo("D"));
+ assertThat(config.get("e"), equalTo("E"));
+
+ // from second.json
+ assertThat(config.get("m"), equalTo("M"));
+ assertThat(config.get("n"), equalTo("N"));
+
+ // from thrid.json
+ assertThat(config.get("p"), equalTo("P"));
+ assertThat(config.get("q"), equalTo("Q"));
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/f78f6a11/src/test/java/org/apache/tamaya/builder/TestNonSPIPropertyFilterA.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/tamaya/builder/TestNonSPIPropertyFilterA.java b/src/test/java/org/apache/tamaya/builder/TestNonSPIPropertyFilterA.java
new file mode 100644
index 0000000..4b9ae72
--- /dev/null
+++ b/src/test/java/org/apache/tamaya/builder/TestNonSPIPropertyFilterA.java
@@ -0,0 +1,34 @@
+/*
+ * 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.builder;
+
+import org.apache.tamaya.spi.PropertyFilter;
+
+public class TestNonSPIPropertyFilterA implements PropertyFilter {
+ @Override
+ public String filterProperty(String key, String value) {
+ String result = value;
+
+ if (!result.contains(("ABC"))) {
+ result = value + "ABC";
+ }
+
+ return result;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/f78f6a11/src/test/java/org/apache/tamaya/builder/TestNonSPIPropertyFilterB.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/tamaya/builder/TestNonSPIPropertyFilterB.java b/src/test/java/org/apache/tamaya/builder/TestNonSPIPropertyFilterB.java
new file mode 100644
index 0000000..95112b0
--- /dev/null
+++ b/src/test/java/org/apache/tamaya/builder/TestNonSPIPropertyFilterB.java
@@ -0,0 +1,34 @@
+/*
+ * 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.builder;
+
+import org.apache.tamaya.spi.PropertyFilter;
+
+public class TestNonSPIPropertyFilterB implements PropertyFilter {
+ @Override
+ public String filterProperty(String key, String value) {
+ String result = value;
+
+ if (!result.contains(("XYZ"))) {
+ result = value + "XYZ";
+ }
+
+ return result;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/f78f6a11/src/test/java/org/apache/tamaya/builder/TestPropertyFilter.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/tamaya/builder/TestPropertyFilter.java b/src/test/java/org/apache/tamaya/builder/TestPropertyFilter.java
new file mode 100644
index 0000000..80c4cb3
--- /dev/null
+++ b/src/test/java/org/apache/tamaya/builder/TestPropertyFilter.java
@@ -0,0 +1,34 @@
+/*
+ * 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.builder;
+
+import org.apache.tamaya.spi.PropertyFilter;
+
+public class TestPropertyFilter implements PropertyFilter {
+ @Override
+ public String filterProperty(String key, String value) {
+ String result = value;
+
+ if (!result.contains(("inBerlin"))) {
+ result = value + "inBerlin";
+ }
+
+ return result;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/f78f6a11/src/test/java/org/apache/tamaya/builder/TestPropertySource.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/tamaya/builder/TestPropertySource.java b/src/test/java/org/apache/tamaya/builder/TestPropertySource.java
new file mode 100644
index 0000000..54deca3
--- /dev/null
+++ b/src/test/java/org/apache/tamaya/builder/TestPropertySource.java
@@ -0,0 +1,58 @@
+/*
+ * 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.builder;
+
+import org.apache.tamaya.spi.PropertySource;
+
+import java.util.Collections;
+import java.util.Hashtable;
+import java.util.Map;
+
+public class TestPropertySource
+ implements PropertySource
+{
+ private Map<String, String> properties;
+
+ {
+ properties = new Hashtable<>(3);
+ properties.put("tps_a", "A");
+ properties.put("tps_b", "B");
+ properties.put("tps_c", "C");
+ }
+
+ @Override
+ public int getOrdinal() {
+ return 456;
+ }
+
+ @Override
+ public String getName() {
+ return "TestPropertySource";
+ }
+
+ @Override
+ public String get(String key) {
+ return getProperties().get(key);
+ }
+
+ @Override
+ public Map<String, String> getProperties() {
+ return Collections.unmodifiableMap(properties);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/f78f6a11/src/test/java/org/apache/tamaya/builder/TestPropertySourceProvider.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/tamaya/builder/TestPropertySourceProvider.java b/src/test/java/org/apache/tamaya/builder/TestPropertySourceProvider.java
new file mode 100644
index 0000000..4e7db79
--- /dev/null
+++ b/src/test/java/org/apache/tamaya/builder/TestPropertySourceProvider.java
@@ -0,0 +1,89 @@
+/*
+ * 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.builder;
+
+import org.apache.tamaya.spi.PropertySource;
+import org.apache.tamaya.spi.PropertySourceProvider;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Map;
+
+public class TestPropertySourceProvider
+ implements PropertySourceProvider
+{
+ @Override
+ public Collection<PropertySource> getPropertySources() {
+ ArrayList<PropertySource> sources = new ArrayList<>(2);
+
+ sources.add(new XProvidingPropertySource());
+ sources.add(new YProvidingPropertySource());
+
+ return sources;
+ }
+
+ private class YProvidingPropertySource implements PropertySource {
+ private Map<String, String> props = Collections.singletonMap("tpsp_x", "X");
+
+ @Override
+ public int getOrdinal() {
+ return 100;
+ }
+
+ @Override
+ public String getName() {
+ return "YProvidingPropertySource";
+ }
+
+ @Override
+ public String get(String key) {
+ return getProperties().get(key);
+ }
+
+ @Override
+ public Map<String, String> getProperties() {
+ return props;
+ }
+ }
+
+ private class XProvidingPropertySource implements PropertySource {
+ private Map<String, String> props = Collections.singletonMap("tpsp_y", "Y");
+
+ @Override
+ public Map<String, String> getProperties() {
+ return props;
+ }
+
+ @Override
+ public String get(String key) {
+ return getProperties().get(key);
+ }
+
+ @Override
+ public int getOrdinal() {
+ return 100;
+ }
+
+ @Override
+ public String getName() {
+ return "XProvidingPropertySource";
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/f78f6a11/src/test/java/org/apache/tamaya/builder/TestPropertySourceProviderB.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/tamaya/builder/TestPropertySourceProviderB.java b/src/test/java/org/apache/tamaya/builder/TestPropertySourceProviderB.java
new file mode 100644
index 0000000..ddfb132
--- /dev/null
+++ b/src/test/java/org/apache/tamaya/builder/TestPropertySourceProviderB.java
@@ -0,0 +1,89 @@
+/*
+ * 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.builder;
+
+import org.apache.tamaya.spi.PropertySource;
+import org.apache.tamaya.spi.PropertySourceProvider;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Map;
+
+public class TestPropertySourceProviderB
+ implements PropertySourceProvider
+{
+ @Override
+ public Collection<PropertySource> getPropertySources() {
+ ArrayList<PropertySource> sources = new ArrayList<>(2);
+
+ sources.add(new AProvidingPropertySource());
+ sources.add(new BProvidingPropertySource());
+
+ return sources;
+ }
+
+ private class BProvidingPropertySource implements PropertySource {
+ private Map<String, String> props = Collections.singletonMap("tpsp_b", "B");
+
+ @Override
+ public int getOrdinal() {
+ return 100;
+ }
+
+ @Override
+ public String getName() {
+ return "BProvidingPropertySource";
+ }
+
+ @Override
+ public String get(String key) {
+ return getProperties().get(key);
+ }
+
+ @Override
+ public Map<String, String> getProperties() {
+ return props;
+ }
+ }
+
+ private class AProvidingPropertySource implements PropertySource {
+ private Map<String, String> props = Collections.singletonMap("tpsp_a", "A");
+
+ @Override
+ public Map<String, String> getProperties() {
+ return props;
+ }
+
+ @Override
+ public String get(String key) {
+ return getProperties().get(key);
+ }
+
+ @Override
+ public int getOrdinal() {
+ return 100;
+ }
+
+ @Override
+ public String getName() {
+ return "AProvidingPropertySource";
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/f78f6a11/src/test/java/org/apache/tamaya/builder/util/mockito/NotMockedAnswer.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/tamaya/builder/util/mockito/NotMockedAnswer.java b/src/test/java/org/apache/tamaya/builder/util/mockito/NotMockedAnswer.java
new file mode 100644
index 0000000..10b3734
--- /dev/null
+++ b/src/test/java/org/apache/tamaya/builder/util/mockito/NotMockedAnswer.java
@@ -0,0 +1,55 @@
+/*
+ * 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.builder.util.mockito;
+
+import org.mockito.exceptions.base.MockitoException;
+import org.mockito.invocation.InvocationOnMock;
+import org.mockito.stubbing.Answer;
+
+import java.io.Serializable;
+
+// @todo This is a duplicated class
+public class NotMockedAnswer implements Answer<Object>, Serializable {
+ public final static NotMockedAnswer NOT_MOCKED_ANSWER = new NotMockedAnswer();
+
+ private NotMockedAnswer() {
+ }
+
+ @Override
+ public Object answer(InvocationOnMock invocation) throws Throwable {
+ StringBuilder msgBuilder = new StringBuilder();
+
+ msgBuilder.append("Invocation of method not mocked: ")
+ .append(invocation.getMethod().toGenericString());
+
+ if (invocation.getArguments().length > 0) {
+ msgBuilder.append(" Supplied arguments: ");
+
+ for (int i = 0; i < invocation.getArguments().length; i++) {
+ msgBuilder.append(invocation.getArguments()[i]);
+
+ if (i - 1 < invocation.getArguments().length) {
+ msgBuilder.append(", ");
+ }
+ }
+ }
+
+ throw new MockitoException(msgBuilder.toString());
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/f78f6a11/src/test/java/org/apache/tamaya/builder/util/types/CustomTypeA.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/tamaya/builder/util/types/CustomTypeA.java b/src/test/java/org/apache/tamaya/builder/util/types/CustomTypeA.java
new file mode 100644
index 0000000..89b2f5b
--- /dev/null
+++ b/src/test/java/org/apache/tamaya/builder/util/types/CustomTypeA.java
@@ -0,0 +1,34 @@
+/*
+ * 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.builder.util.types;
+
+/**
+ * Custom type with two argument constructor.
+ */
+public class CustomTypeA {
+ private String name;
+
+ public CustomTypeA(String name, String other) {
+ this.name = name + other;
+ }
+
+ public String getName() {
+ return name;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/f78f6a11/src/test/java/org/apache/tamaya/builder/util/types/CustomTypeB.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/tamaya/builder/util/types/CustomTypeB.java b/src/test/java/org/apache/tamaya/builder/util/types/CustomTypeB.java
new file mode 100644
index 0000000..f7f4d99
--- /dev/null
+++ b/src/test/java/org/apache/tamaya/builder/util/types/CustomTypeB.java
@@ -0,0 +1,39 @@
+/*
+ * 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.builder.util.types;
+
+/**
+ * Custom type with factory method
+ * {@link org.apache.tamaya.builder.util.types.CustomTypeB#of(String)}
+ */
+public class CustomTypeB {
+ private String name;
+
+ private CustomTypeB(String value) {
+ this.name = value;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public static CustomTypeB of(String source) {
+ return new CustomTypeB(source);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/f78f6a11/src/test/java/org/apache/tamaya/builder/util/types/CustomTypeC.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/tamaya/builder/util/types/CustomTypeC.java b/src/test/java/org/apache/tamaya/builder/util/types/CustomTypeC.java
new file mode 100644
index 0000000..da9ce56
--- /dev/null
+++ b/src/test/java/org/apache/tamaya/builder/util/types/CustomTypeC.java
@@ -0,0 +1,36 @@
+/*
+ * 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.builder.util.types;
+
+public class CustomTypeC {
+ private String value;
+
+
+ public CustomTypeC(String in, @SuppressWarnings("unused") int iHideThisConstructorForTamaya) {
+ value = in;
+ }
+
+ public String getValue() {
+ return value;
+ }
+
+ public static CustomTypeC produceFrom(String in) {
+ return new CustomTypeC(in, -1);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/f78f6a11/src/test/java/org/apache/tamaya/builder/util/types/CustomTypeCPropertyConverter.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/tamaya/builder/util/types/CustomTypeCPropertyConverter.java b/src/test/java/org/apache/tamaya/builder/util/types/CustomTypeCPropertyConverter.java
new file mode 100644
index 0000000..1754b30
--- /dev/null
+++ b/src/test/java/org/apache/tamaya/builder/util/types/CustomTypeCPropertyConverter.java
@@ -0,0 +1,28 @@
+/*
+ * 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.builder.util.types;
+
+import org.apache.tamaya.PropertyConverter;
+
+public class CustomTypeCPropertyConverter implements PropertyConverter<org.apache.tamaya.builder.util.types.CustomTypeC> {
+ @Override
+ public org.apache.tamaya.builder.util.types.CustomTypeC convert(String value) {
+ return org.apache.tamaya.builder.util.types.CustomTypeC.produceFrom(value);
+ }
+}
[20/50] [abbrv] incubator-tamaya-sandbox git commit:
[maven-release-plugin] prepare for next development iteration
Posted by pl...@apache.org.
[maven-release-plugin] prepare for next development iteration
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/b5232bb2
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/tree/b5232bb2
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/diff/b5232bb2
Branch: refs/heads/master
Commit: b5232bb269c67d1881856baa0584a033c2cb4fd9
Parents: 0bace89
Author: anatole <at...@gmail.com>
Authored: Tue Aug 4 11:53:44 2015 +0200
Committer: anatole <at...@gmail.com>
Committed: Tue Aug 4 11:53:44 2015 +0200
----------------------------------------------------------------------
pom.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/b5232bb2/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index 9cb03fd..5912c2c 100644
--- a/pom.xml
+++ b/pom.xml
@@ -23,7 +23,7 @@ under the License.
<parent>
<groupId>org.apache.tamaya.ext</groupId>
<artifactId>tamaya-extensions</artifactId>
- <version>0.1-incubating</version>
+ <version>0.2-incubating-SNAPSHOT</version>
</parent>
<artifactId>tamaya-builder</artifactId>
[25/50] [abbrv] incubator-tamaya-sandbox git commit: TAMAYA-126:
Removed refs to StringJoiner.
Posted by pl...@apache.org.
TAMAYA-126: Removed refs to StringJoiner.
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/d44893c5
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/tree/d44893c5
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/diff/d44893c5
Branch: refs/heads/master
Commit: d44893c5fd59c9b91eb8747cc6229896e86400ff
Parents: 61de41d
Author: anatole <an...@apache.org>
Authored: Sat Oct 17 23:12:04 2015 +0200
Committer: anatole <an...@apache.org>
Committed: Sat Oct 17 23:12:04 2015 +0200
----------------------------------------------------------------------
.../apache/tamaya/builder/ProgrammaticConfigurationContext.java | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/d44893c5/src/main/java/org/apache/tamaya/builder/ProgrammaticConfigurationContext.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/tamaya/builder/ProgrammaticConfigurationContext.java b/src/main/java/org/apache/tamaya/builder/ProgrammaticConfigurationContext.java
index b333986..9f675dc 100644
--- a/src/main/java/org/apache/tamaya/builder/ProgrammaticConfigurationContext.java
+++ b/src/main/java/org/apache/tamaya/builder/ProgrammaticConfigurationContext.java
@@ -39,7 +39,6 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
-import java.util.StringJoiner;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.StampedLock;
import java.util.function.Function;
@@ -249,8 +248,8 @@ class ProgrammaticConfigurationContext implements ConfigurationContext {
}
private <T> String createStringList(Collection<T> propertySources, Function<T, String> mapper) {
- StringJoiner joiner = new StringJoiner(", ");
- propertySources.forEach(t -> joiner.add(mapper.apply(t)));
+ StringBuilder joiner = new StringBuilder(", ");
+ propertySources.forEach(t -> joiner.append(mapper.apply(t)));
return joiner.toString();
}
[46/50] [abbrv] incubator-tamaya-sandbox git commit: Moved the
builder to the directory builder
Posted by pl...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/f45a5bb5/src/test/java/org/apache/tamaya/builder/TestPropertySource.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/tamaya/builder/TestPropertySource.java b/src/test/java/org/apache/tamaya/builder/TestPropertySource.java
deleted file mode 100644
index f1ebfea..0000000
--- a/src/test/java/org/apache/tamaya/builder/TestPropertySource.java
+++ /dev/null
@@ -1,59 +0,0 @@
-/*
- * 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.builder;
-
-import org.apache.tamaya.core.propertysource.BasePropertySource;
-import org.apache.tamaya.spi.PropertySource;
-import org.apache.tamaya.spi.PropertyValue;
-
-import java.util.Collections;
-import java.util.Hashtable;
-import java.util.Map;
-
-public class TestPropertySource extends BasePropertySource
-{
- private Map<String, String> properties;
-
- {
- properties = new Hashtable<>(3);
- properties.put("tps_a", "A");
- properties.put("tps_b", "B");
- properties.put("tps_c", "C");
- }
-
- @Override
- public int getOrdinal() {
- return 456;
- }
-
- @Override
- public String getName() {
- return "TestPropertySource";
- }
-
- @Override
- public PropertyValue get(String key) {
- return PropertyValue.of(key, getProperties().get(key), getName());
- }
-
- @Override
- public Map<String, String> getProperties() {
- return Collections.unmodifiableMap(properties);
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/f45a5bb5/src/test/java/org/apache/tamaya/builder/TestPropertySourceProvider.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/tamaya/builder/TestPropertySourceProvider.java b/src/test/java/org/apache/tamaya/builder/TestPropertySourceProvider.java
deleted file mode 100644
index 5a2f400..0000000
--- a/src/test/java/org/apache/tamaya/builder/TestPropertySourceProvider.java
+++ /dev/null
@@ -1,91 +0,0 @@
-/*
- * 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.builder;
-
-import org.apache.tamaya.core.propertysource.BasePropertySource;
-import org.apache.tamaya.spi.PropertySource;
-import org.apache.tamaya.spi.PropertySourceProvider;
-import org.apache.tamaya.spi.PropertyValue;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.Map;
-
-public class TestPropertySourceProvider
- implements PropertySourceProvider
-{
- @Override
- public Collection<PropertySource> getPropertySources() {
- ArrayList<PropertySource> sources = new ArrayList<>(2);
-
- sources.add(new XProvidingPropertySource());
- sources.add(new YProvidingPropertySource());
-
- return sources;
- }
-
- private class YProvidingPropertySource extends BasePropertySource {
- private Map<String, String> props = Collections.singletonMap("tpsp_x", "X");
-
- @Override
- public int getOrdinal() {
- return 100;
- }
-
- @Override
- public String getName() {
- return "YProvidingPropertySource";
- }
-
- @Override
- public PropertyValue get(String key) {
- return PropertyValue.of(key, getProperties().get(key), getName());
- }
-
- @Override
- public Map<String, String> getProperties() {
- return props;
- }
- }
-
- private class XProvidingPropertySource extends BasePropertySource {
- private Map<String, String> props = Collections.singletonMap("tpsp_y", "Y");
-
- @Override
- public Map<String, String> getProperties() {
- return props;
- }
-
- @Override
- public PropertyValue get(String key) {
- return PropertyValue.of(key, getProperties().get(key), getName());
- }
-
- @Override
- public int getOrdinal() {
- return 100;
- }
-
- @Override
- public String getName() {
- return "XProvidingPropertySource";
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/f45a5bb5/src/test/java/org/apache/tamaya/builder/TestPropertySourceProviderB.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/tamaya/builder/TestPropertySourceProviderB.java b/src/test/java/org/apache/tamaya/builder/TestPropertySourceProviderB.java
deleted file mode 100644
index 9cfe725..0000000
--- a/src/test/java/org/apache/tamaya/builder/TestPropertySourceProviderB.java
+++ /dev/null
@@ -1,91 +0,0 @@
-/*
- * 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.builder;
-
-import org.apache.tamaya.core.propertysource.BasePropertySource;
-import org.apache.tamaya.spi.PropertySource;
-import org.apache.tamaya.spi.PropertySourceProvider;
-import org.apache.tamaya.spi.PropertyValue;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.Map;
-
-public class TestPropertySourceProviderB
- implements PropertySourceProvider
-{
- @Override
- public Collection<PropertySource> getPropertySources() {
- ArrayList<PropertySource> sources = new ArrayList<>(2);
-
- sources.add(new AProvidingPropertySource());
- sources.add(new BProvidingPropertySource());
-
- return sources;
- }
-
- private class BProvidingPropertySource extends BasePropertySource {
- private Map<String, String> props = Collections.singletonMap("tpsp_b", "B");
-
- @Override
- public int getOrdinal() {
- return 100;
- }
-
- @Override
- public String getName() {
- return "BProvidingPropertySource";
- }
-
- @Override
- public PropertyValue get(String key) {
- return PropertyValue.of(key,getProperties().get(key), getName());
- }
-
- @Override
- public Map<String, String> getProperties() {
- return props;
- }
- }
-
- private class AProvidingPropertySource extends BasePropertySource {
- private Map<String, String> props = Collections.singletonMap("tpsp_a", "A");
-
- @Override
- public Map<String, String> getProperties() {
- return props;
- }
-
- @Override
- public PropertyValue get(String key) {
- return PropertyValue.of(key, getProperties().get(key), getName());
- }
-
- @Override
- public int getOrdinal() {
- return 100;
- }
-
- @Override
- public String getName() {
- return "AProvidingPropertySource";
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/f45a5bb5/src/test/java/org/apache/tamaya/builder/util/mockito/NotMockedAnswer.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/tamaya/builder/util/mockito/NotMockedAnswer.java b/src/test/java/org/apache/tamaya/builder/util/mockito/NotMockedAnswer.java
deleted file mode 100644
index 3188d85..0000000
--- a/src/test/java/org/apache/tamaya/builder/util/mockito/NotMockedAnswer.java
+++ /dev/null
@@ -1,57 +0,0 @@
-/*
- * 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.builder.util.mockito;
-
-import org.mockito.exceptions.base.MockitoException;
-import org.mockito.invocation.InvocationOnMock;
-import org.mockito.stubbing.Answer;
-
-import java.io.Serializable;
-
-// @todo This is a duplicated class
-public class NotMockedAnswer implements Answer<Object>, Serializable {
- public final static NotMockedAnswer NOT_MOCKED_ANSWER = new NotMockedAnswer();
-
- private NotMockedAnswer() {
- }
-
- @Override
- public Object answer(InvocationOnMock invocation) throws Throwable {
- if("toString".equals(invocation.getMethod().getName())){
- return "Some "+invocation.getMethod().getDeclaringClass().getName();
- }
- StringBuilder msgBuilder = new StringBuilder();
-
- msgBuilder.append("Invocation of method not mocked: ")
- .append(invocation.getMethod().toGenericString());
-
- if (invocation.getArguments().length > 0) {
- msgBuilder.append(" Supplied arguments: ");
-
- for (int i = 0; i < invocation.getArguments().length; i++) {
- msgBuilder.append(invocation.getArguments()[i]);
-
- if (i - 1 < invocation.getArguments().length) {
- msgBuilder.append(", ");
- }
- }
- }
- throw new MockitoException(msgBuilder.toString());
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/f45a5bb5/src/test/java/org/apache/tamaya/builder/util/types/CustomTypeA.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/tamaya/builder/util/types/CustomTypeA.java b/src/test/java/org/apache/tamaya/builder/util/types/CustomTypeA.java
deleted file mode 100644
index 89b2f5b..0000000
--- a/src/test/java/org/apache/tamaya/builder/util/types/CustomTypeA.java
+++ /dev/null
@@ -1,34 +0,0 @@
-/*
- * 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.builder.util.types;
-
-/**
- * Custom type with two argument constructor.
- */
-public class CustomTypeA {
- private String name;
-
- public CustomTypeA(String name, String other) {
- this.name = name + other;
- }
-
- public String getName() {
- return name;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/f45a5bb5/src/test/java/org/apache/tamaya/builder/util/types/CustomTypeB.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/tamaya/builder/util/types/CustomTypeB.java b/src/test/java/org/apache/tamaya/builder/util/types/CustomTypeB.java
deleted file mode 100644
index f7f4d99..0000000
--- a/src/test/java/org/apache/tamaya/builder/util/types/CustomTypeB.java
+++ /dev/null
@@ -1,39 +0,0 @@
-/*
- * 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.builder.util.types;
-
-/**
- * Custom type with factory method
- * {@link org.apache.tamaya.builder.util.types.CustomTypeB#of(String)}
- */
-public class CustomTypeB {
- private String name;
-
- private CustomTypeB(String value) {
- this.name = value;
- }
-
- public String getName() {
- return name;
- }
-
- public static CustomTypeB of(String source) {
- return new CustomTypeB(source);
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/f45a5bb5/src/test/java/org/apache/tamaya/builder/util/types/CustomTypeC.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/tamaya/builder/util/types/CustomTypeC.java b/src/test/java/org/apache/tamaya/builder/util/types/CustomTypeC.java
deleted file mode 100644
index da9ce56..0000000
--- a/src/test/java/org/apache/tamaya/builder/util/types/CustomTypeC.java
+++ /dev/null
@@ -1,36 +0,0 @@
-/*
- * 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.builder.util.types;
-
-public class CustomTypeC {
- private String value;
-
-
- public CustomTypeC(String in, @SuppressWarnings("unused") int iHideThisConstructorForTamaya) {
- value = in;
- }
-
- public String getValue() {
- return value;
- }
-
- public static CustomTypeC produceFrom(String in) {
- return new CustomTypeC(in, -1);
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/f45a5bb5/src/test/java/org/apache/tamaya/builder/util/types/CustomTypeCPropertyConverter.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/tamaya/builder/util/types/CustomTypeCPropertyConverter.java b/src/test/java/org/apache/tamaya/builder/util/types/CustomTypeCPropertyConverter.java
deleted file mode 100644
index 9e56613..0000000
--- a/src/test/java/org/apache/tamaya/builder/util/types/CustomTypeCPropertyConverter.java
+++ /dev/null
@@ -1,29 +0,0 @@
-/*
- * 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.builder.util.types;
-
-import org.apache.tamaya.spi.ConversionContext;
-import org.apache.tamaya.spi.PropertyConverter;
-
-public class CustomTypeCPropertyConverter implements PropertyConverter<org.apache.tamaya.builder.util.types.CustomTypeC> {
- @Override
- public org.apache.tamaya.builder.util.types.CustomTypeC convert(String value, ConversionContext context) {
- return org.apache.tamaya.builder.util.types.CustomTypeC.produceFrom(value);
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/f45a5bb5/src/test/resources/META-INF/services/org.apache.tamaya.spi.PropertyConverter
----------------------------------------------------------------------
diff --git a/src/test/resources/META-INF/services/org.apache.tamaya.spi.PropertyConverter b/src/test/resources/META-INF/services/org.apache.tamaya.spi.PropertyConverter
deleted file mode 100644
index b9e0d44..0000000
--- a/src/test/resources/META-INF/services/org.apache.tamaya.spi.PropertyConverter
+++ /dev/null
@@ -1,19 +0,0 @@
-#
-# 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.
-#
-org.apache.tamaya.builder.util.types.CustomTypeCPropertyConverter
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/f45a5bb5/src/test/resources/META-INF/services/org.apache.tamaya.spi.PropertyFilter
----------------------------------------------------------------------
diff --git a/src/test/resources/META-INF/services/org.apache.tamaya.spi.PropertyFilter b/src/test/resources/META-INF/services/org.apache.tamaya.spi.PropertyFilter
deleted file mode 100644
index f35e9c5..0000000
--- a/src/test/resources/META-INF/services/org.apache.tamaya.spi.PropertyFilter
+++ /dev/null
@@ -1,19 +0,0 @@
-#
-# 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.
-#
-org.apache.tamaya.builder.TestPropertyFilter
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/f45a5bb5/src/test/resources/META-INF/services/org.apache.tamaya.spi.PropertySource
----------------------------------------------------------------------
diff --git a/src/test/resources/META-INF/services/org.apache.tamaya.spi.PropertySource b/src/test/resources/META-INF/services/org.apache.tamaya.spi.PropertySource
deleted file mode 100644
index 8b07205..0000000
--- a/src/test/resources/META-INF/services/org.apache.tamaya.spi.PropertySource
+++ /dev/null
@@ -1,19 +0,0 @@
-#
-# 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.
-#
-org.apache.tamaya.builder.TestPropertySource
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/f45a5bb5/src/test/resources/META-INF/services/org.apache.tamaya.spi.PropertySourceProvider
----------------------------------------------------------------------
diff --git a/src/test/resources/META-INF/services/org.apache.tamaya.spi.PropertySourceProvider b/src/test/resources/META-INF/services/org.apache.tamaya.spi.PropertySourceProvider
deleted file mode 100644
index 9a19ea0..0000000
--- a/src/test/resources/META-INF/services/org.apache.tamaya.spi.PropertySourceProvider
+++ /dev/null
@@ -1,19 +0,0 @@
-#
-# 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.
-#
-org.apache.tamaya.builder.TestPropertySourceProvider
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/f45a5bb5/src/test/resources/configfiles/json/first.json
----------------------------------------------------------------------
diff --git a/src/test/resources/configfiles/json/first.json b/src/test/resources/configfiles/json/first.json
deleted file mode 100644
index 822cf6e..0000000
--- a/src/test/resources/configfiles/json/first.json
+++ /dev/null
@@ -1,4 +0,0 @@
-{
- "d": "D",
- "e": "E"
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/f45a5bb5/src/test/resources/configfiles/json/second.json
----------------------------------------------------------------------
diff --git a/src/test/resources/configfiles/json/second.json b/src/test/resources/configfiles/json/second.json
deleted file mode 100644
index e2c7778..0000000
--- a/src/test/resources/configfiles/json/second.json
+++ /dev/null
@@ -1,4 +0,0 @@
-{
- "m": "M",
- "n": "N"
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/f45a5bb5/src/test/resources/configfiles/json/simple.json
----------------------------------------------------------------------
diff --git a/src/test/resources/configfiles/json/simple.json b/src/test/resources/configfiles/json/simple.json
deleted file mode 100644
index 0cab2ae..0000000
--- a/src/test/resources/configfiles/json/simple.json
+++ /dev/null
@@ -1,4 +0,0 @@
-{
- "a": "A",
- "b": "B"
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/f45a5bb5/src/test/resources/configfiles/json/third.json
----------------------------------------------------------------------
diff --git a/src/test/resources/configfiles/json/third.json b/src/test/resources/configfiles/json/third.json
deleted file mode 100644
index 6b62b96..0000000
--- a/src/test/resources/configfiles/json/third.json
+++ /dev/null
@@ -1,4 +0,0 @@
-{
- "p": "P",
- "q": "Q"
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/f45a5bb5/src/test/resources/configfiles/other/simple.oml
----------------------------------------------------------------------
diff --git a/src/test/resources/configfiles/other/simple.oml b/src/test/resources/configfiles/other/simple.oml
deleted file mode 100644
index 494dba3..0000000
--- a/src/test/resources/configfiles/other/simple.oml
+++ /dev/null
@@ -1,19 +0,0 @@
-#
-# 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.
-#
-Key:=Value
[43/50] [abbrv] incubator-tamaya-sandbox git commit: Reset version,
integrated docs into site.
Posted by pl...@apache.org.
Reset version, integrated docs into site.
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/204d358f
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/tree/204d358f
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/diff/204d358f
Branch: refs/heads/master
Commit: 204d358f20b5be3550f95fd2a73aa47ad7985e83
Parents: 93bcde7
Author: anatole <an...@apache.org>
Authored: Wed Mar 16 21:54:18 2016 +0100
Committer: anatole <an...@apache.org>
Committed: Wed Mar 16 21:54:18 2016 +0100
----------------------------------------------------------------------
pom.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/204d358f/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index 96f6244..32dc6b5 100644
--- a/pom.xml
+++ b/pom.xml
@@ -23,7 +23,7 @@ under the License.
<parent>
<groupId>org.apache.tamaya.ext</groupId>
<artifactId>tamaya-extensions</artifactId>
- <version>0.3-incubating-SNAPSHOT</version>
+ <version>0.2-incubating-SNAPSHOT</version>
</parent>
<artifactId>tamaya-builder</artifactId>
[07/50] [abbrv] incubator-tamaya-sandbox git commit: TAMAYA-60
Removed the modules package for the package hierarchy.
Posted by pl...@apache.org.
TAMAYA-60 Removed the modules package for the package hierarchy.
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/f78f6a11
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/tree/f78f6a11
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/diff/f78f6a11
Branch: refs/heads/master
Commit: f78f6a1171277b015374a3f979ebe4781c4b64ef
Parents: da8f601
Author: Oliver B. Fischer <pl...@apache.org>
Authored: Sat Mar 14 00:56:48 2015 +0100
Committer: Oliver B. Fischer <pl...@apache.org>
Committed: Sat Mar 14 00:56:48 2015 +0100
----------------------------------------------------------------------
.../tamaya/builder/ConfigurationBuilder.java | 580 ++++++++++++
.../ProgrammaticConfigurationContext.java | 406 +++++++++
.../org/apache/tamaya/builder/package-info.java | 28 +
.../modules/builder/ConfigurationBuilder.java | 580 ------------
.../ProgrammaticConfigurationContext.java | 406 ---------
.../tamaya/modules/builder/package-info.java | 28 -
.../builder/ConfigurationBuilderTest.java | 896 +++++++++++++++++++
.../builder/TestNonSPIPropertyFilterA.java | 34 +
.../builder/TestNonSPIPropertyFilterB.java | 34 +
.../tamaya/builder/TestPropertyFilter.java | 34 +
.../tamaya/builder/TestPropertySource.java | 58 ++
.../builder/TestPropertySourceProvider.java | 89 ++
.../builder/TestPropertySourceProviderB.java | 89 ++
.../builder/util/mockito/NotMockedAnswer.java | 55 ++
.../tamaya/builder/util/types/CustomTypeA.java | 34 +
.../tamaya/builder/util/types/CustomTypeB.java | 39 +
.../tamaya/builder/util/types/CustomTypeC.java | 36 +
.../types/CustomTypeCPropertyConverter.java | 28 +
.../builder/ConfigurationBuilderTest.java | 896 -------------------
.../builder/TestNonSPIPropertyFilterA.java | 34 -
.../builder/TestNonSPIPropertyFilterB.java | 34 -
.../modules/builder/TestPropertyFilter.java | 34 -
.../modules/builder/TestPropertySource.java | 58 --
.../builder/TestPropertySourceProvider.java | 89 --
.../builder/TestPropertySourceProviderB.java | 89 --
.../builder/util/mockito/NotMockedAnswer.java | 55 --
.../modules/builder/util/types/CustomTypeA.java | 34 -
.../modules/builder/util/types/CustomTypeB.java | 39 -
.../modules/builder/util/types/CustomTypeC.java | 36 -
.../types/CustomTypeCPropertyConverter.java | 28 -
.../org.apache.tamaya.PropertyConverter | 2 +-
.../org.apache.tamaya.spi.PropertyFilter | 2 +-
.../org.apache.tamaya.spi.PropertySource | 2 +-
...org.apache.tamaya.spi.PropertySourceProvider | 2 +-
34 files changed, 2444 insertions(+), 2444 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/f78f6a11/src/main/java/org/apache/tamaya/builder/ConfigurationBuilder.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/tamaya/builder/ConfigurationBuilder.java b/src/main/java/org/apache/tamaya/builder/ConfigurationBuilder.java
new file mode 100644
index 0000000..51abbcf
--- /dev/null
+++ b/src/main/java/org/apache/tamaya/builder/ConfigurationBuilder.java
@@ -0,0 +1,580 @@
+/*
+ * 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.builder;
+
+import org.apache.tamaya.ConfigException;
+import org.apache.tamaya.Configuration;
+import org.apache.tamaya.PropertyConverter;
+import org.apache.tamaya.TypeLiteral;
+import org.apache.tamaya.core.internal.DefaultConfiguration;
+import org.apache.tamaya.format.ConfigurationData;
+import org.apache.tamaya.format.ConfigurationFormats;
+import org.apache.tamaya.format.FlattenedDefaultPropertySource;
+import org.apache.tamaya.spi.ConfigurationContext;
+import org.apache.tamaya.spi.PropertyFilter;
+import org.apache.tamaya.spi.PropertySource;
+import org.apache.tamaya.spi.PropertySourceProvider;
+import org.apache.tamaya.spi.PropertyValueCombinationPolicy;
+
+import java.io.IOException;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Objects;
+import java.util.function.Function;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+
+import static java.lang.String.format;
+
+/**
+ * <p>Builder class used for building a configuration manually without relying
+ * only on the Service Provider Interface API.</p>
+ *
+ * <p><strong>Features of the builder</strong></p>
+ *
+ * <ol>
+ * <li>Adding of property converters manually</li>
+ * <li>Adding of property sources directly</li>
+ * <li>Adding of property sources via URL</li>
+ * <li>Adding of property source providers directly</li>
+ * <li>Enabling and disabling of via SPI mechanism provided resources as converters,
+ * property sources, etc.</li>
+ * </ol>
+ *
+ * <p><strong>Example</strong></p>
+ *
+ * <pre>{@code ConfigurationBuilder builder = new ConfigurationBuilder();
+ * builder.disableProvidedPropertySources() // Do not load provided property
+ * .disableProvidedPropertySourceProviders() // sources and providers automatically
+ * .addPropertySource("file:/etc/conf.properties"); // Load properties from conf.properties
+ *
+ * Configuration config = builder.build();
+ * }</pre>
+ *
+ * <p><strong>Support for configuration formats</strong></p>
+ *
+ * The configuration builder allows you to add property resources
+ * via a URL, as shown in the code example above, without implementing
+ * a {@link org.apache.tamaya.spi.PropertySource PropertySource} or providing an
+ * instance of a {@link org.apache.tamaya.spi.PropertySource PropertySource}.
+ * If a property resource in
+ * a specific format can be added to configuration builder or not depends
+ * on the available implementations of
+ * {@link org.apache.tamaya.format.ConfigurationFormat} in the classpath.
+ * Which formats are available can be checked via
+ * {@link org.apache.tamaya.format.ConfigurationFormats#getFormats()}.
+ */
+public class ConfigurationBuilder {
+ /** Builder used to create new ConfigurationContext instances. */
+ private ProgrammaticConfigurationContext.Builder contextBuilder = new ProgrammaticConfigurationContext.Builder();
+
+ /**
+ * Flag if the config has already been built.
+ * Configuration can be built only once
+ */
+ private boolean built;
+
+ /**
+ * Flag if all existing property converter service providers
+ * should be loaded if the configuration is build.
+ */
+ private boolean loadProvidedPropertyConverters = true;
+
+ /**
+ * Flag if all existing property source service providers
+ * will be loaded if the configuration is build.
+ */
+ private boolean loadProvidedPropertySources = false;
+ private boolean loadProvidedPropertySourceProviders = false;
+
+ private boolean isLoadProvidedPropertyFilters = false;
+
+ /**
+ * Creates a new builder instance.
+ */
+ public ConfigurationBuilder() {
+ }
+
+ /**
+ * Allows to set configuration context during unit tests.
+ */
+ ConfigurationBuilder setConfigurationContext(ConfigurationContext configurationContext) {
+ contextBuilder.setConfigurationContext(configurationContext);
+ return this;
+ }
+
+ /**
+ * Adds one resources with properties in an arbitrary format
+ * to the configuration to be build.
+ *
+ * <p>If a specific format is supported depends on the available
+ * {@link org.apache.tamaya.format.ConfigurationFormat} implementations.</p>
+ *
+ * <pre>{@code URL resource = new URL("file:/etc/service/config.json");
+ *
+ * builder.addPropertySources(resource);}
+ * </pre>
+ *
+ * @param url resource with properties for the the configuration to be build.
+ *
+ * @return the builder instance currently used
+ *
+ * @see org.apache.tamaya.format.ConfigurationFormat
+ * @see org.apache.tamaya.format.ConfigurationFormats#getFormats()
+ */
+ public ConfigurationBuilder addPropertySource(URL url) {
+ try {
+ ConfigurationData data = getConfigurationDataFromURL(url);
+
+ FlattenedDefaultPropertySource propertySource = new FlattenedDefaultPropertySource(data);
+ addPropertySources(propertySource);
+ } catch (IOException e) {
+ throw new ConfigException("Failed to read " + url.toString(), e);
+ }
+
+ return this;
+ }
+
+ protected ConfigurationData getConfigurationDataFromURL(URL url) throws IOException {
+ ConfigurationData data = ConfigurationFormats.readConfigurationData(url);
+
+ if (null == data) {
+ String mesg = format("No configuration format found which is able " +
+ "to read properties from %s.", url.toString());
+
+ throw new ConfigException(mesg);
+ }
+
+ return data;
+ }
+
+ /**
+ * Adds one or more resources with properties in an arbitrary format
+ * to the configuration to be build.
+ *
+ * <p>If a specific format is supported depends on the available
+ * {@link org.apache.tamaya.format.ConfigurationFormat} implementations.</p>
+ *
+ *<pre>{@code URL first = new URL("file:/etc/service/config.json");
+ * URL second = new URL("file:/etc/defaults/values.properties");
+ *
+ * builder.addPropertySources(first, second);}
+ *</pre>
+ *
+ * @param url first resource with properties for the the configuration to be build.
+ * @param urls list additional of resources with properties for the configuration to be
+ * build.
+ *
+ * @return the builder instance currently used
+ *
+ * @see org.apache.tamaya.format.ConfigurationFormat
+ * @see org.apache.tamaya.format.ConfigurationFormats#getFormats()
+ */
+ public ConfigurationBuilder addPropertySource(URL url, URL... urls) {
+ Stream.of(Collections.singletonList(url), Arrays.asList(urls))
+ .flatMap(Collection::stream)
+ .filter(entry -> entry != null)
+ .collect(Collectors.toList())
+ .forEach(this::addPropertySource);
+
+ return this;
+ }
+
+
+ /**
+ * Adds one or more resources with properties in an arbitrary format
+ * to the configuration to be build.
+ *
+ * <p>If a specific format is supported depends on the available
+ * {@link org.apache.tamaya.format.ConfigurationFormat} implementations.</p>
+ *
+ *<pre>{@code builder.addPropertySources("file:/etc/service/config.json",
+ * "file:/etc/defaults/values.properties");}
+ *</pre>
+ *
+ * @param url first resource with properties for the the configuration to be build.
+ * @param urls list additional of resources with properties for the configuration to be
+ * build.
+ *
+ * @return the builder instance currently used
+ *
+ * @see org.apache.tamaya.format.ConfigurationFormat
+ * @see org.apache.tamaya.format.ConfigurationFormats#getFormats()
+ */
+ public ConfigurationBuilder addPropertySource(String url, String... urls) {
+ Stream.of(Collections.singletonList(url), Arrays.asList(urls))
+ .flatMap(Collection::stream)
+ .filter(entry -> entry != null)
+ .map(new StringToURLMapper())
+ .collect(Collectors.toList())
+ .forEach(this::addPropertySource);
+
+ return this;
+ }
+
+ /**
+ * Adds one or more property source instances to the configuration to be build.
+ *
+ *<pre>{@code PropertySource first = new CustomPropertySource();
+ * PropertySource second = new YetAnotherPropertySource();
+ *
+ * builder.addPropertySources(first, second)};
+ *</pre>
+ *
+ * @param sources list of property source instances with properties for the
+ * configuration to be build.
+ *
+ * @return the builder instance currently used
+ *
+ * @see org.apache.tamaya.spi.PropertySource
+ */
+ public ConfigurationBuilder addPropertySources(PropertySource... sources){
+ checkBuilderState();
+
+ contextBuilder.addPropertySources(Objects.requireNonNull(sources));
+ return this;
+ }
+
+ private void checkBuilderState() {
+ if (built) {
+ throw new IllegalStateException("Configuration has already been build.");
+ }
+ }
+
+ /**
+ * Adds one or more property source provider instances to the configuration to be build.
+ *
+ * <pre>{@code PropertySourceProvider jc = new JavaConfigurationProvider();
+ *
+ * builder.addPropertySources(jc)};
+ * </pre>
+ *
+ * @param providers list of property source provider instances each providing a set
+ * of property source instances for the configuration to be build.
+ *
+ * @return the builder instance currently used
+ *
+ * @see org.apache.tamaya.spi.PropertySourceProvider
+ */
+ public ConfigurationBuilder addPropertySourceProviders(PropertySourceProvider... providers){
+ contextBuilder.addPropertySourceProviders(providers);
+ return this;
+ }
+
+ /**
+ * Adds one or more property filter instances to the configuration to be build.
+ *
+ * <pre>{@code PropertyFilter quoteReplacingFilter = new QuoteFilter();
+ * PropertyFilter commaRemovingFilter = new CommaFilter();
+ *
+ * builder.addPropertyFilters(commaRemovingFilter, quoteReplacingFilter)};
+ * </pre>
+ *
+ * @param filters list of property filter instances which should be applied
+ * to the properties of the configuration to be build.
+ *
+ * @return the builder instance currently used
+ *
+ * @see org.apache.tamaya.spi.PropertyFilter
+ * @see #disableProvidedPropertyFilters()
+ * @see #enabledProvidedPropertyFilters()
+ */
+ public ConfigurationBuilder addPropertyFilters(PropertyFilter... filters){
+ Objects.requireNonNull(filters);
+
+ contextBuilder.addPropertyFilters(filters);
+ return this;
+ }
+
+
+ /**
+ * @return the builder instance currently used
+ */
+ public ConfigurationBuilder setPropertyValueCombinationPolicy(PropertyValueCombinationPolicy propertyValueCombinationPolicy){
+ contextBuilder.setPropertyValueCombinationPolicy(propertyValueCombinationPolicy);
+ return this;
+ }
+
+ /**
+ * Adds a property converter for the a given type to the configuration to
+ * be build.
+ *
+ * <pre>{@code PropertyConverter<MyType> converter = value -> new MyType(value, 42);
+ *
+ * builder.addPropertyConverter(MyType.class, converter}
+ * </pre>
+ *
+ * @param type the required target type the converter should be applied to
+ * @param converter the converter to be used to convert the string property
+ * to the given target type.
+ *
+ * @return the builder instance currently used
+ *
+ * @see org.apache.tamaya.PropertyConverter
+ * @see #enableProvidedPropertyConverters()
+ * @see #disableProvidedPropertyConverters()
+ */
+ public <T> ConfigurationBuilder addPropertyConverter(Class<T> type, PropertyConverter<T> converter) {
+ Objects.requireNonNull(type);
+ Objects.requireNonNull(converter);
+
+ return addPropertyConverter(TypeLiteral.of(type), converter);
+ }
+
+ /**
+ * @return the builder instance currently used
+ */
+ public <T> ConfigurationBuilder addPropertyConverter(TypeLiteral<T> type, PropertyConverter<T> propertyConverter){
+ Objects.requireNonNull(type);
+ Objects.requireNonNull(propertyConverter);
+
+ contextBuilder.addPropertyConverter(type, propertyConverter);
+ return this;
+ }
+
+ /**
+ * Checks if the automatic loading of all {@link org.apache.tamaya.PropertyConverter
+ * PropertyConverter} service providers is enabled or disabled.
+ *
+ * @return {@code true} if the automatic loading is enabled,
+ * otherwise {@code false}.
+ *
+ * @see #enableProvidedPropertyConverters()
+ * @see #disableProvidedPropertyConverters()
+ * @see #addPropertyConverter(Class, org.apache.tamaya.PropertyConverter)
+ * @see #addPropertyConverter(org.apache.tamaya.TypeLiteral, org.apache.tamaya.PropertyConverter)
+ */
+ public boolean isPropertyConverterLoadingEnabled() {
+ return loadProvidedPropertyConverters;
+ }
+
+ /**
+ * Enables the loading of all {@link org.apache.tamaya.PropertyConverter}
+ * service providers.
+ *
+ * @return the builder instance currently used
+ *
+ * @see org.apache.tamaya.PropertyConverter
+ * @see #disableProvidedPropertyConverters()
+ * @see #enableProvidedPropertyConverters()
+ */
+ public ConfigurationBuilder enableProvidedPropertyConverters() {
+ checkBuilderState();
+
+ loadProvidedPropertyConverters = true;
+
+ return this;
+ }
+
+ /**
+ * Disables the automatic loading of all {@link org.apache.tamaya.PropertyConverter}
+ * service providers.
+ *
+ * @return the builder instance currently used
+ *
+ * @see org.apache.tamaya.PropertyConverter
+ * @see #enableProvidedPropertyConverters()
+ * @see #addPropertyConverter(Class, org.apache.tamaya.PropertyConverter)
+ */
+ public ConfigurationBuilder disableProvidedPropertyConverters() {
+ checkBuilderState();
+
+ loadProvidedPropertyConverters = false;
+
+ return this;
+ }
+
+
+ /**
+ * Enables the automatic loading of all {@link org.apache.tamaya.spi.PropertySource}
+ * service providers.
+ *
+ * @return the builder instance currently used
+ *
+ * @see org.apache.tamaya.spi.PropertySource
+ * @see #disableProvidedPropertySources()
+ */
+ public ConfigurationBuilder enableProvidedPropertySources() {
+ checkBuilderState();
+
+ loadProvidedPropertySources = true;
+
+ return this;
+ }
+
+ /**
+ * Checks if the automatic loading of all {@link org.apache.tamaya.spi.PropertySource
+ * PropertySource} service providers is enabled or disabled.
+ *
+ * @return {@code true} if the automatic loading is enabled,
+ * otherwise {@code false}.
+ */
+ public boolean isPropertySourcesLoadingEnabled() {
+ return loadProvidedPropertySources;
+ }
+
+
+ /**
+ * Checks if the automatic loading of all {@link org.apache.tamaya.spi.PropertyFilter
+ * PropertyFilter} service providers is enabled or disabled.
+ *
+ * @return {@code true} if the automatic loading is enabled,
+ * otherwise {@code false}.
+ */
+ public boolean isPropertyFilterLoadingEnabled() {
+ return isLoadProvidedPropertyFilters;
+ }
+
+ /**
+ * Enables the automatic loading of all {@link org.apache.tamaya.spi.PropertyFilter}
+ * service providers.
+ *
+ * @return the builder instance currently used
+ *
+ * @see org.apache.tamaya.spi.PropertyFilter
+ * @see #disableProvidedPropertyFilters()
+ * @see #addPropertyFilters(org.apache.tamaya.spi.PropertyFilter...)
+ */
+ public ConfigurationBuilder enabledProvidedPropertyFilters() {
+ checkBuilderState();
+
+ isLoadProvidedPropertyFilters = true;
+
+ return this;
+ }
+
+ /**
+ * Disables the automatic loading of all {@link org.apache.tamaya.spi.PropertyFilter}
+ * service providers.
+ *
+ * @return the builder instance currently used
+ *
+ * @see org.apache.tamaya.spi.PropertyFilter
+ * @see #enabledProvidedPropertyFilters()
+ * @see #addPropertyFilters(org.apache.tamaya.spi.PropertyFilter...)
+ *
+ * @return the builder instance currently used
+ */
+ public ConfigurationBuilder disableProvidedPropertyFilters() {
+ checkBuilderState();
+
+ isLoadProvidedPropertyFilters = false;
+
+ return this;
+ }
+
+ /**
+ * Disables the automatic loading of all {@link org.apache.tamaya.spi.PropertySource}
+ * service providers.
+ *
+ * @return the builder instance currently used
+ *
+ * @see org.apache.tamaya.spi.PropertySource
+ * @see #enableProvidedPropertySources()
+ */
+ public ConfigurationBuilder disableProvidedPropertySources() {
+ checkBuilderState();
+
+ loadProvidedPropertySources = false;
+
+ return this;
+ }
+
+ /**
+ * Enables the automatic loading of {@link org.apache.tamaya.spi.PropertySourceProvider
+ * property source providers} provided via the SPI API.
+ *
+ * @return the builder instance currently used
+ *
+ * @see org.apache.tamaya.spi.PropertySourceProvider
+ * @see
+ */
+ public ConfigurationBuilder enableProvidedPropertySourceProviders() {
+ checkBuilderState();
+
+ loadProvidedPropertySourceProviders = true;
+
+ return this;
+ }
+
+ /**
+ * Disables the automatic loading of {@link org.apache.tamaya.spi.PropertySourceProvider
+ * property source providers} provided via the SPI API.
+ *
+ * @return the builder instance currently used
+ */
+ public ConfigurationBuilder disableProvidedPropertySourceProviders() {
+ checkBuilderState();
+
+ loadProvidedPropertySourceProviders = false;
+
+ return this;
+ }
+
+ /**
+ * Checks if the automatic loading of {@link org.apache.tamaya.spi.PropertySourceProvider
+ * PropertySourceProviders} is enabled or disabled.
+ *
+ * @return {@code true} if the automatic loading is enabled,
+ * otherwise {@code false}.
+ */
+ public boolean isPropertySourceProvidersLoadingEnabled() {
+ return loadProvidedPropertySourceProviders;
+ }
+
+ //X TODO think on a functonality/API for using the default PropertyConverters and use the configured ones here
+ //X TODO as overrides used first.
+
+
+ /**
+ * Builds a new configuration based on the configuration of this builder instance.
+ *
+ * @return a new {@link org.apache.tamaya.Configuration configuration instance},
+ * never {@code null}.
+ */
+ public Configuration build() {
+ checkBuilderState();
+
+ built = true;
+
+ contextBuilder.loadProvidedPropertyConverters(isPropertyConverterLoadingEnabled());
+ contextBuilder.loadProvidedPropertySources(isPropertySourcesLoadingEnabled());
+ contextBuilder.loadProvidedPropertySourceProviders(isPropertySourceProvidersLoadingEnabled());
+ contextBuilder.loadProvidedPropertyFilters(isLoadProvidedPropertyFilters);
+
+ return new DefaultConfiguration(contextBuilder.build());
+ }
+
+ /**
+ * Mapper to map a URL given as string to an URL instance.
+ */
+ private static class StringToURLMapper implements Function<String, URL> {
+ @Override
+ public URL apply(String u) {
+ try {
+ return new URL(u);
+ } catch (MalformedURLException e) {
+ throw new ConfigException(u + " is not a valid URL", e);
+ }
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/f78f6a11/src/main/java/org/apache/tamaya/builder/ProgrammaticConfigurationContext.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/tamaya/builder/ProgrammaticConfigurationContext.java b/src/main/java/org/apache/tamaya/builder/ProgrammaticConfigurationContext.java
new file mode 100644
index 0000000..6c7e845
--- /dev/null
+++ b/src/main/java/org/apache/tamaya/builder/ProgrammaticConfigurationContext.java
@@ -0,0 +1,406 @@
+/*
+ * 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.builder;
+
+
+import org.apache.tamaya.PropertyConverter;
+import org.apache.tamaya.TypeLiteral;
+import org.apache.tamaya.core.internal.PropertyConverterManager;
+import org.apache.tamaya.spi.ConfigurationContext;
+import org.apache.tamaya.spi.ConfigurationContextBuilder;
+import org.apache.tamaya.spi.PropertyFilter;
+import org.apache.tamaya.spi.PropertySource;
+import org.apache.tamaya.spi.PropertySourceProvider;
+import org.apache.tamaya.spi.PropertyValueCombinationPolicy;
+import org.apache.tamaya.spi.ServiceContext;
+
+import javax.annotation.Priority;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import java.util.StringJoiner;
+import java.util.concurrent.locks.Lock;
+import java.util.concurrent.locks.StampedLock;
+import java.util.function.Function;
+import java.util.function.Predicate;
+import java.util.logging.Logger;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+
+import static java.util.stream.Collectors.toList;
+
+/**
+ * Implementation of the {@link org.apache.tamaya.spi.ConfigurationContext}
+ * used by the {@link org.apache.tamaya.builder.ConfigurationBuilder}
+ * internally.
+ */
+class ProgrammaticConfigurationContext implements ConfigurationContext {
+
+ /**
+ * The logger used.
+ */
+ private final static Logger LOG = Logger.getLogger(ProgrammaticConfigurationContext.class.getName());
+ /**
+ * Cubcomponent handling {@link org.apache.tamaya.PropertyConverter} instances.
+ */
+ private PropertyConverterManager propertyConverterManager = new PropertyConverterManager();
+
+ /**
+ * The current unmodifiable list of loaded {@link org.apache.tamaya.spi.PropertySource} instances.
+ */
+ private List<PropertySource> immutablePropertySources = new ArrayList<>();
+
+ /**
+ * The current unmodifiable list of loaded {@link org.apache.tamaya.spi.PropertyFilter} instances.
+ */
+ private List<PropertyFilter> immutablePropertyFilters = new ArrayList<>();
+
+ /**
+ * The overriding policy used when combining PropertySources registered to evalute the final configuration
+ * values.
+ */
+ private PropertyValueCombinationPolicy propertyValueCombinationPolicy;
+
+ /**
+ * Lock for internal synchronization.
+ */
+ private StampedLock propertySourceLock = new StampedLock();
+
+
+ /**
+ * The first time the Configuration system gets invoked we do initialize
+ * all our {@link org.apache.tamaya.spi.PropertySource}s and
+ * {@link org.apache.tamaya.spi.PropertyFilter}s which are known at startup.
+ */
+ @SuppressWarnings("unchecked")
+ public ProgrammaticConfigurationContext(Builder builder) {
+ propertyConverterManager = new PropertyConverterManager(builder.loadProvidedPropertyConverters);
+
+ immutablePropertySources = getAllPropertySources(builder).stream()
+ .sorted(this::comparePropertySources)
+ .collect(Collectors.toList());
+
+
+ immutablePropertyFilters = getPropertyFilters(builder).stream()
+ .sorted(this::comparePropertyFilters)
+ .collect(toList());
+
+
+ propertyValueCombinationPolicy = builder.propertyValueCombinationPolicy;
+
+ builder.propertyConverters.forEach((literal, converters) -> {
+ converters.stream().filter(c -> c != null)
+ .forEach(c -> propertyConverterManager.register((TypeLiteral<Object>) literal,
+ (PropertyConverter<Object>) c));
+ });
+
+ LOG.info(() -> "Using " + immutablePropertySources.size() + " property sources: " +
+ createStringList(immutablePropertySources, ps -> ps.getName() + '[' + ps.getClass().getName() + ']'));
+
+
+ LOG.info(() -> "Using " + immutablePropertyFilters.size() + " property filters: " +
+ createStringList(immutablePropertyFilters, f -> f.getClass().getName()));
+
+
+ LOG.info(() -> "Using PropertyValueCombinationPolicy: " + propertyValueCombinationPolicy);
+ }
+
+ private List<PropertyFilter> getPropertyFilters(Builder builder) {
+ List<PropertyFilter> provided = builder.loadProvidedPropertyFilters
+ ? ServiceContext.getInstance().getServices(PropertyFilter.class)
+ : new ArrayList<>(0);
+
+ List<PropertyFilter> configured = builder.propertyFilters;
+
+ return Stream.of(provided, configured).flatMap(Collection::stream)
+ .collect(toList());
+ }
+
+ private List<PropertySource> getAllPropertySources(Builder builder) {
+ List<PropertySource> provided = builder.loadProvidedPropertySources
+ ? ServiceContext.getInstance().getServices(PropertySource.class)
+ : new ArrayList<>(0);
+
+ if (builder.loadProvidedPropertySourceProviders) {
+ List<PropertySourceProvider> providers = ServiceContext.getInstance()
+ .getServices(PropertySourceProvider.class);
+ for (PropertySourceProvider provider : providers) {
+ Collection<PropertySource> sources = provider.getPropertySources();
+ provided.addAll(sources);
+ }
+ }
+
+ List<PropertySource> configured = builder.propertySources;
+
+ return Stream.of(provided, configured).flatMap(Collection::stream)
+ .collect(toList());
+ }
+
+ public void addPropertySources(PropertySource... propertySourcesToAdd) {
+ Lock writeLock = propertySourceLock.asWriteLock();
+ try {
+ writeLock.lock();
+ List<PropertySource> newPropertySources = new ArrayList<>(this.immutablePropertySources);
+ newPropertySources.addAll(Arrays.asList(propertySourcesToAdd));
+ Collections.sort(newPropertySources, this::comparePropertySources);
+
+ this.immutablePropertySources = Collections.unmodifiableList(newPropertySources);
+ } finally {
+ writeLock.unlock();
+ }
+ }
+
+ /**
+ * Order property source reversely, the most important come first.
+ *
+ * @param source1 the first PropertySource
+ * @param source2 the second PropertySource
+ * @return the comparison result.
+ */
+ private int comparePropertySources(PropertySource source1, PropertySource source2) {
+
+ //X TODO this method duplicates org.apache.tamaya.core.internal.DefaultConfigurationContext.PropertySourceComparator.comparePropertySources()
+ //X maybe we should extract the Comperator in an own class for real code-reuse (copy paste == bad code reuse)
+
+ if (source1.getOrdinal() < source2.getOrdinal()) {
+ return -1;
+ } else if (source1.getOrdinal() > source2.getOrdinal()) {
+ return 1;
+ } else {
+ return source1.getClass().getName().compareTo(source2.getClass().getName());
+ }
+ }
+
+ /**
+ * Compare 2 filters for ordering the filter chain.
+ *
+ * @param filter1 the first filter
+ * @param filter2 the second filter
+ * @return the comparison result
+ */
+ private int comparePropertyFilters(PropertyFilter filter1, PropertyFilter filter2) {
+
+ //X TODO this method duplicates org.apache.tamaya.core.internal.DefaultConfigurationContext.PropertySourceComparator.comparePropertyFilters()
+ //X maybe we should extract the Comperator in an own class for real code-reuse (copy paste == bad code reuse)
+
+ Priority prio1 = filter1.getClass().getAnnotation(Priority.class);
+ Priority prio2 = filter2.getClass().getAnnotation(Priority.class);
+ int ord1 = prio1 != null ? prio1.value() : 0;
+ int ord2 = prio2 != null ? prio2.value() : 0;
+
+ if (ord1 < ord2) {
+ return -1;
+ } else if (ord1 > ord2) {
+ return 1;
+ } else {
+ return filter1.getClass().getName().compareTo(filter2.getClass().getName());
+ }
+ }
+
+ @Override
+ public List<PropertySource> getPropertySources() {
+ return immutablePropertySources;
+ }
+
+ public <T> void addPropertyConverter(TypeLiteral<T> typeToConvert, PropertyConverter<T> propertyConverter) {
+ propertyConverterManager.register(typeToConvert, propertyConverter);
+ LOG.info(() -> "Added PropertyConverter: " + propertyConverter.getClass().getName());
+ }
+
+ @Override
+ public Map<TypeLiteral<?>, List<PropertyConverter<?>>> getPropertyConverters() {
+ return propertyConverterManager.getPropertyConverters();
+ }
+
+ @Override
+ public <T> List<PropertyConverter<T>> getPropertyConverters(TypeLiteral<T> targetType) {
+ return propertyConverterManager.getPropertyConverters(targetType);
+ }
+
+ @Override
+ public List<PropertyFilter> getPropertyFilters() {
+ return immutablePropertyFilters;
+ }
+
+ @Override
+ public PropertyValueCombinationPolicy getPropertyValueCombinationPolicy() {
+ return propertyValueCombinationPolicy;
+ }
+
+ private <T> String createStringList(Collection<T> propertySources, Function<T, String> mapper) {
+ StringJoiner joiner = new StringJoiner(", ");
+ propertySources.forEach(t -> joiner.add(mapper.apply(t)));
+ return joiner.toString();
+ }
+
+ @Override
+ public ConfigurationContextBuilder toBuilder() {
+ // @todo Check if it could be useful to support this method, Oliver B. Fischer
+ throw new RuntimeException("This method is currently not supported.");
+ }
+
+ @Override
+ public Collection<PropertySource> getPropertySources(Predicate<PropertySource> selector) {
+ // @todo Check if it could be useful to support this method, Oliver B. Fischer
+ throw new RuntimeException("This method is currently not supported.");
+ }
+
+ /**
+ * The Builder for {@link ProgrammaticConfigurationContext}
+ */
+ public final static class Builder {
+ /**
+ * The current unmodifiable list of loaded {@link org.apache.tamaya.spi.PropertySource} instances.
+ */
+ private List<PropertySource> propertySources = new ArrayList<>();
+
+ /**
+ * The current unmodifiable list of loaded {@link org.apache.tamaya.spi.PropertyFilter} instances.
+ */
+ private List<PropertyFilter> propertyFilters = new ArrayList<>();
+
+ private Map<TypeLiteral<?>, List<PropertyConverter<?>>> propertyConverters = new HashMap<>();
+
+ /**
+ * The overriding policy used when combining PropertySources registered to evalute the final configuration
+ * values.
+ */
+ private PropertyValueCombinationPolicy propertyValueCombinationPolicy =
+ PropertyValueCombinationPolicy.DEFAULT_OVERRIDING_COLLECTOR;
+
+ private boolean loadProvidedPropertyConverters;
+ private boolean loadProvidedPropertySources;
+ private boolean loadProvidedPropertySourceProviders;
+ private boolean loadProvidedPropertyFilters;
+
+ public Builder setPropertyValueCombinationPolicy(PropertyValueCombinationPolicy policy) {
+ this.propertyValueCombinationPolicy = Objects.requireNonNull(policy);
+ return this;
+ }
+
+ public Builder addPropertySources(PropertySource... propertySources) {
+ List<PropertySource> filtered = Stream.of(propertySources).filter(this::isNotNull)
+ .collect(toList());
+
+ this.propertySources.addAll(filtered);
+
+ return this;
+ }
+
+ public Builder addPropertySources(Collection<PropertySource> propertySources) {
+ List<PropertySource> filtered = propertySources.stream().filter(this::isNotNull)
+ .collect(toList());
+
+ this.propertySources.addAll(filtered);
+
+ return this;
+ }
+
+ public Builder addPropertySourceProviders(PropertySourceProvider... propertySourceProviders) {
+ List<PropertySourceProvider> providers = Stream.of(propertySourceProviders).filter(this::isNotNull)
+ .collect(toList());
+
+ return addPropertySourceProviders(providers);
+ }
+
+ public Builder addPropertySourceProviders(Collection<PropertySourceProvider> providers) {
+ List<PropertySource> filtered = providers.stream().filter(this::isNotNull)
+ .flatMap(p -> p.getPropertySources().stream())
+ .filter(this::isNotNull)
+ .collect(toList());
+
+ this.propertySources.addAll(filtered);
+
+ return this;
+ }
+
+ public Builder addPropertyFilters(PropertyFilter... propertySources) {
+ List<PropertyFilter> sources = Stream.of(propertySources).filter(this::isNotNull)
+ .collect(toList());
+
+ this.propertyFilters.addAll(sources);
+
+ return this;
+ }
+
+ public Builder addPropertyFilters(Collection<PropertyFilter> propertySources) {
+ List<PropertyFilter> sources = propertySources.stream().filter(this::isNotNull)
+ .collect(toList());
+
+ this.propertyFilters.addAll(sources);
+
+ return this;
+ }
+
+ /**
+ * Should be never used.
+ */
+ @Deprecated
+ public Builder setConfigurationContext(ConfigurationContext configurationContext) {
+ this.addPropertySources(configurationContext.getPropertySources());
+ this.addPropertyFilters(configurationContext.getPropertyFilters());
+ this.propertyValueCombinationPolicy = Objects.requireNonNull(
+ configurationContext.getPropertyValueCombinationPolicy());
+ return this;
+ }
+
+ //X TODO think on a functonality/API for using the default PropertyConverters and use the configured ones here
+ //X TODO as overrides used first.
+
+ public <T> Builder addPropertyConverter(TypeLiteral<T> type, PropertyConverter<T> propertyConverter) {
+ propertyConverters.computeIfAbsent(type, (t) -> new ArrayList<>())
+ .add(propertyConverter);
+
+ return this;
+ }
+
+ public ConfigurationContext build() {
+ return new ProgrammaticConfigurationContext(this);
+ }
+
+
+ public void loadProvidedPropertyConverters(boolean state) {
+ loadProvidedPropertyConverters = state;
+ }
+
+ public void loadProvidedPropertySources(boolean state) {
+ loadProvidedPropertySources = state;
+ }
+
+ public void loadProvidedPropertySourceProviders(boolean state) {
+ loadProvidedPropertySourceProviders = state;
+ }
+
+ public void loadProvidedPropertyFilters(boolean state) {
+ loadProvidedPropertyFilters = state;
+ }
+
+ private <T> boolean isNotNull(T item) {
+ return null != item;
+ }
+ }
+
+
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/f78f6a11/src/main/java/org/apache/tamaya/builder/package-info.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/tamaya/builder/package-info.java b/src/main/java/org/apache/tamaya/builder/package-info.java
new file mode 100644
index 0000000..24c86a9
--- /dev/null
+++ b/src/main/java/org/apache/tamaya/builder/package-info.java
@@ -0,0 +1,28 @@
+/*
+ * 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.
+ */
+/**
+ * This package provides
+ * {@link org.apache.tamaya.builder.ConfigurationBuilder a configuration
+ * builder} that allows to build a configuration manually without
+ * using exclusively on the Service Provider Interface API of Tamaya.
+ *
+ * @see org.apache.tamaya.builder.ConfigurationBuilder
+ * @see org.apache.tamaya.Configuration
+ */
+package org.apache.tamaya.builder;
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/f78f6a11/src/main/java/org/apache/tamaya/modules/builder/ConfigurationBuilder.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/tamaya/modules/builder/ConfigurationBuilder.java b/src/main/java/org/apache/tamaya/modules/builder/ConfigurationBuilder.java
deleted file mode 100644
index 2d7ccac..0000000
--- a/src/main/java/org/apache/tamaya/modules/builder/ConfigurationBuilder.java
+++ /dev/null
@@ -1,580 +0,0 @@
-/*
- * 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.modules.builder;
-
-import org.apache.tamaya.ConfigException;
-import org.apache.tamaya.Configuration;
-import org.apache.tamaya.PropertyConverter;
-import org.apache.tamaya.TypeLiteral;
-import org.apache.tamaya.core.internal.DefaultConfiguration;
-import org.apache.tamaya.format.ConfigurationData;
-import org.apache.tamaya.format.ConfigurationFormats;
-import org.apache.tamaya.format.FlattenedDefaultPropertySource;
-import org.apache.tamaya.spi.ConfigurationContext;
-import org.apache.tamaya.spi.PropertyFilter;
-import org.apache.tamaya.spi.PropertySource;
-import org.apache.tamaya.spi.PropertySourceProvider;
-import org.apache.tamaya.spi.PropertyValueCombinationPolicy;
-
-import java.io.IOException;
-import java.net.MalformedURLException;
-import java.net.URL;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.Objects;
-import java.util.function.Function;
-import java.util.stream.Collectors;
-import java.util.stream.Stream;
-
-import static java.lang.String.format;
-
-/**
- * <p>Builder class used for building a configuration manually without relying
- * only on the Service Provider Interface API.</p>
- *
- * <p><strong>Features of the builder</strong></p>
- *
- * <ol>
- * <li>Adding of property converters manually</li>
- * <li>Adding of property sources directly</li>
- * <li>Adding of property sources via URL</li>
- * <li>Adding of property source providers directly</li>
- * <li>Enabling and disabling of via SPI mechanism provided resources as converters,
- * property sources, etc.</li>
- * </ol>
- *
- * <p><strong>Example</strong></p>
- *
- * <pre>{@code ConfigurationBuilder builder = new ConfigurationBuilder();
- * builder.disableProvidedPropertySources() // Do not load provided property
- * .disableProvidedPropertySourceProviders() // sources and providers automatically
- * .addPropertySource("file:/etc/conf.properties"); // Load properties from conf.properties
- *
- * Configuration config = builder.build();
- * }</pre>
- *
- * <p><strong>Support for configuration formats</strong></p>
- *
- * The configuration builder allows you to add property resources
- * via a URL, as shown in the code example above, without implementing
- * a {@link org.apache.tamaya.spi.PropertySource PropertySource} or providing an
- * instance of a {@link org.apache.tamaya.spi.PropertySource PropertySource}.
- * If a property resource in
- * a specific format can be added to configuration builder or not depends
- * on the available implementations of
- * {@link org.apache.tamaya.format.ConfigurationFormat} in the classpath.
- * Which formats are available can be checked via
- * {@link org.apache.tamaya.format.ConfigurationFormats#getFormats()}.
- */
-public class ConfigurationBuilder {
- /** Builder used to create new ConfigurationContext instances. */
- private ProgrammaticConfigurationContext.Builder contextBuilder = new ProgrammaticConfigurationContext.Builder();
-
- /**
- * Flag if the config has already been built.
- * Configuration can be built only once
- */
- private boolean built;
-
- /**
- * Flag if all existing property converter service providers
- * should be loaded if the configuration is build.
- */
- private boolean loadProvidedPropertyConverters = true;
-
- /**
- * Flag if all existing property source service providers
- * will be loaded if the configuration is build.
- */
- private boolean loadProvidedPropertySources = false;
- private boolean loadProvidedPropertySourceProviders = false;
-
- private boolean isLoadProvidedPropertyFilters = false;
-
- /**
- * Creates a new builder instance.
- */
- public ConfigurationBuilder() {
- }
-
- /**
- * Allows to set configuration context during unit tests.
- */
- ConfigurationBuilder setConfigurationContext(ConfigurationContext configurationContext) {
- contextBuilder.setConfigurationContext(configurationContext);
- return this;
- }
-
- /**
- * Adds one resources with properties in an arbitrary format
- * to the configuration to be build.
- *
- * <p>If a specific format is supported depends on the available
- * {@link org.apache.tamaya.format.ConfigurationFormat} implementations.</p>
- *
- * <pre>{@code URL resource = new URL("file:/etc/service/config.json");
- *
- * builder.addPropertySources(resource);}
- * </pre>
- *
- * @param url resource with properties for the the configuration to be build.
- *
- * @return the builder instance currently used
- *
- * @see org.apache.tamaya.format.ConfigurationFormat
- * @see org.apache.tamaya.format.ConfigurationFormats#getFormats()
- */
- public ConfigurationBuilder addPropertySource(URL url) {
- try {
- ConfigurationData data = getConfigurationDataFromURL(url);
-
- FlattenedDefaultPropertySource propertySource = new FlattenedDefaultPropertySource(data);
- addPropertySources(propertySource);
- } catch (IOException e) {
- throw new ConfigException("Failed to read " + url.toString(), e);
- }
-
- return this;
- }
-
- protected ConfigurationData getConfigurationDataFromURL(URL url) throws IOException {
- ConfigurationData data = ConfigurationFormats.readConfigurationData(url);
-
- if (null == data) {
- String mesg = format("No configuration format found which is able " +
- "to read properties from %s.", url.toString());
-
- throw new ConfigException(mesg);
- }
-
- return data;
- }
-
- /**
- * Adds one or more resources with properties in an arbitrary format
- * to the configuration to be build.
- *
- * <p>If a specific format is supported depends on the available
- * {@link org.apache.tamaya.format.ConfigurationFormat} implementations.</p>
- *
- *<pre>{@code URL first = new URL("file:/etc/service/config.json");
- * URL second = new URL("file:/etc/defaults/values.properties");
- *
- * builder.addPropertySources(first, second);}
- *</pre>
- *
- * @param url first resource with properties for the the configuration to be build.
- * @param urls list additional of resources with properties for the configuration to be
- * build.
- *
- * @return the builder instance currently used
- *
- * @see org.apache.tamaya.format.ConfigurationFormat
- * @see org.apache.tamaya.format.ConfigurationFormats#getFormats()
- */
- public ConfigurationBuilder addPropertySource(URL url, URL... urls) {
- Stream.of(Collections.singletonList(url), Arrays.asList(urls))
- .flatMap(Collection::stream)
- .filter(entry -> entry != null)
- .collect(Collectors.toList())
- .forEach(this::addPropertySource);
-
- return this;
- }
-
-
- /**
- * Adds one or more resources with properties in an arbitrary format
- * to the configuration to be build.
- *
- * <p>If a specific format is supported depends on the available
- * {@link org.apache.tamaya.format.ConfigurationFormat} implementations.</p>
- *
- *<pre>{@code builder.addPropertySources("file:/etc/service/config.json",
- * "file:/etc/defaults/values.properties");}
- *</pre>
- *
- * @param url first resource with properties for the the configuration to be build.
- * @param urls list additional of resources with properties for the configuration to be
- * build.
- *
- * @return the builder instance currently used
- *
- * @see org.apache.tamaya.format.ConfigurationFormat
- * @see org.apache.tamaya.format.ConfigurationFormats#getFormats()
- */
- public ConfigurationBuilder addPropertySource(String url, String... urls) {
- Stream.of(Collections.singletonList(url), Arrays.asList(urls))
- .flatMap(Collection::stream)
- .filter(entry -> entry != null)
- .map(new StringToURLMapper())
- .collect(Collectors.toList())
- .forEach(this::addPropertySource);
-
- return this;
- }
-
- /**
- * Adds one or more property source instances to the configuration to be build.
- *
- *<pre>{@code PropertySource first = new CustomPropertySource();
- * PropertySource second = new YetAnotherPropertySource();
- *
- * builder.addPropertySources(first, second)};
- *</pre>
- *
- * @param sources list of property source instances with properties for the
- * configuration to be build.
- *
- * @return the builder instance currently used
- *
- * @see org.apache.tamaya.spi.PropertySource
- */
- public ConfigurationBuilder addPropertySources(PropertySource... sources){
- checkBuilderState();
-
- contextBuilder.addPropertySources(Objects.requireNonNull(sources));
- return this;
- }
-
- private void checkBuilderState() {
- if (built) {
- throw new IllegalStateException("Configuration has already been build.");
- }
- }
-
- /**
- * Adds one or more property source provider instances to the configuration to be build.
- *
- * <pre>{@code PropertySourceProvider jc = new JavaConfigurationProvider();
- *
- * builder.addPropertySources(jc)};
- * </pre>
- *
- * @param providers list of property source provider instances each providing a set
- * of property source instances for the configuration to be build.
- *
- * @return the builder instance currently used
- *
- * @see org.apache.tamaya.spi.PropertySourceProvider
- */
- public ConfigurationBuilder addPropertySourceProviders(PropertySourceProvider... providers){
- contextBuilder.addPropertySourceProviders(providers);
- return this;
- }
-
- /**
- * Adds one or more property filter instances to the configuration to be build.
- *
- * <pre>{@code PropertyFilter quoteReplacingFilter = new QuoteFilter();
- * PropertyFilter commaRemovingFilter = new CommaFilter();
- *
- * builder.addPropertyFilters(commaRemovingFilter, quoteReplacingFilter)};
- * </pre>
- *
- * @param filters list of property filter instances which should be applied
- * to the properties of the configuration to be build.
- *
- * @return the builder instance currently used
- *
- * @see org.apache.tamaya.spi.PropertyFilter
- * @see #disableProvidedPropertyFilters()
- * @see #enabledProvidedPropertyFilters()
- */
- public ConfigurationBuilder addPropertyFilters(PropertyFilter... filters){
- Objects.requireNonNull(filters);
-
- contextBuilder.addPropertyFilters(filters);
- return this;
- }
-
-
- /**
- * @return the builder instance currently used
- */
- public ConfigurationBuilder setPropertyValueCombinationPolicy(PropertyValueCombinationPolicy propertyValueCombinationPolicy){
- contextBuilder.setPropertyValueCombinationPolicy(propertyValueCombinationPolicy);
- return this;
- }
-
- /**
- * Adds a property converter for the a given type to the configuration to
- * be build.
- *
- * <pre>{@code PropertyConverter<MyType> converter = value -> new MyType(value, 42);
- *
- * builder.addPropertyConverter(MyType.class, converter}
- * </pre>
- *
- * @param type the required target type the converter should be applied to
- * @param converter the converter to be used to convert the string property
- * to the given target type.
- *
- * @return the builder instance currently used
- *
- * @see org.apache.tamaya.PropertyConverter
- * @see #enableProvidedPropertyConverters()
- * @see #disableProvidedPropertyConverters()
- */
- public <T> ConfigurationBuilder addPropertyConverter(Class<T> type, PropertyConverter<T> converter) {
- Objects.requireNonNull(type);
- Objects.requireNonNull(converter);
-
- return addPropertyConverter(TypeLiteral.of(type), converter);
- }
-
- /**
- * @return the builder instance currently used
- */
- public <T> ConfigurationBuilder addPropertyConverter(TypeLiteral<T> type, PropertyConverter<T> propertyConverter){
- Objects.requireNonNull(type);
- Objects.requireNonNull(propertyConverter);
-
- contextBuilder.addPropertyConverter(type, propertyConverter);
- return this;
- }
-
- /**
- * Checks if the automatic loading of all {@link org.apache.tamaya.PropertyConverter
- * PropertyConverter} service providers is enabled or disabled.
- *
- * @return {@code true} if the automatic loading is enabled,
- * otherwise {@code false}.
- *
- * @see #enableProvidedPropertyConverters()
- * @see #disableProvidedPropertyConverters()
- * @see #addPropertyConverter(Class, org.apache.tamaya.PropertyConverter)
- * @see #addPropertyConverter(org.apache.tamaya.TypeLiteral, org.apache.tamaya.PropertyConverter)
- */
- public boolean isPropertyConverterLoadingEnabled() {
- return loadProvidedPropertyConverters;
- }
-
- /**
- * Enables the loading of all {@link org.apache.tamaya.PropertyConverter}
- * service providers.
- *
- * @return the builder instance currently used
- *
- * @see org.apache.tamaya.PropertyConverter
- * @see #disableProvidedPropertyConverters()
- * @see #enableProvidedPropertyConverters()
- */
- public ConfigurationBuilder enableProvidedPropertyConverters() {
- checkBuilderState();
-
- loadProvidedPropertyConverters = true;
-
- return this;
- }
-
- /**
- * Disables the automatic loading of all {@link org.apache.tamaya.PropertyConverter}
- * service providers.
- *
- * @return the builder instance currently used
- *
- * @see org.apache.tamaya.PropertyConverter
- * @see #enableProvidedPropertyConverters()
- * @see #addPropertyConverter(Class, org.apache.tamaya.PropertyConverter)
- */
- public ConfigurationBuilder disableProvidedPropertyConverters() {
- checkBuilderState();
-
- loadProvidedPropertyConverters = false;
-
- return this;
- }
-
-
- /**
- * Enables the automatic loading of all {@link org.apache.tamaya.spi.PropertySource}
- * service providers.
- *
- * @return the builder instance currently used
- *
- * @see org.apache.tamaya.spi.PropertySource
- * @see #disableProvidedPropertySources()
- */
- public ConfigurationBuilder enableProvidedPropertySources() {
- checkBuilderState();
-
- loadProvidedPropertySources = true;
-
- return this;
- }
-
- /**
- * Checks if the automatic loading of all {@link org.apache.tamaya.spi.PropertySource
- * PropertySource} service providers is enabled or disabled.
- *
- * @return {@code true} if the automatic loading is enabled,
- * otherwise {@code false}.
- */
- public boolean isPropertySourcesLoadingEnabled() {
- return loadProvidedPropertySources;
- }
-
-
- /**
- * Checks if the automatic loading of all {@link org.apache.tamaya.spi.PropertyFilter
- * PropertyFilter} service providers is enabled or disabled.
- *
- * @return {@code true} if the automatic loading is enabled,
- * otherwise {@code false}.
- */
- public boolean isPropertyFilterLoadingEnabled() {
- return isLoadProvidedPropertyFilters;
- }
-
- /**
- * Enables the automatic loading of all {@link org.apache.tamaya.spi.PropertyFilter}
- * service providers.
- *
- * @return the builder instance currently used
- *
- * @see org.apache.tamaya.spi.PropertyFilter
- * @see #disableProvidedPropertyFilters()
- * @see #addPropertyFilters(org.apache.tamaya.spi.PropertyFilter...)
- */
- public ConfigurationBuilder enabledProvidedPropertyFilters() {
- checkBuilderState();
-
- isLoadProvidedPropertyFilters = true;
-
- return this;
- }
-
- /**
- * Disables the automatic loading of all {@link org.apache.tamaya.spi.PropertyFilter}
- * service providers.
- *
- * @return the builder instance currently used
- *
- * @see org.apache.tamaya.spi.PropertyFilter
- * @see #enabledProvidedPropertyFilters()
- * @see #addPropertyFilters(org.apache.tamaya.spi.PropertyFilter...)
- *
- * @return the builder instance currently used
- */
- public ConfigurationBuilder disableProvidedPropertyFilters() {
- checkBuilderState();
-
- isLoadProvidedPropertyFilters = false;
-
- return this;
- }
-
- /**
- * Disables the automatic loading of all {@link org.apache.tamaya.spi.PropertySource}
- * service providers.
- *
- * @return the builder instance currently used
- *
- * @see org.apache.tamaya.spi.PropertySource
- * @see #enableProvidedPropertySources()
- */
- public ConfigurationBuilder disableProvidedPropertySources() {
- checkBuilderState();
-
- loadProvidedPropertySources = false;
-
- return this;
- }
-
- /**
- * Enables the automatic loading of {@link org.apache.tamaya.spi.PropertySourceProvider
- * property source providers} provided via the SPI API.
- *
- * @return the builder instance currently used
- *
- * @see org.apache.tamaya.spi.PropertySourceProvider
- * @see
- */
- public ConfigurationBuilder enableProvidedPropertySourceProviders() {
- checkBuilderState();
-
- loadProvidedPropertySourceProviders = true;
-
- return this;
- }
-
- /**
- * Disables the automatic loading of {@link org.apache.tamaya.spi.PropertySourceProvider
- * property source providers} provided via the SPI API.
- *
- * @return the builder instance currently used
- */
- public ConfigurationBuilder disableProvidedPropertySourceProviders() {
- checkBuilderState();
-
- loadProvidedPropertySourceProviders = false;
-
- return this;
- }
-
- /**
- * Checks if the automatic loading of {@link org.apache.tamaya.spi.PropertySourceProvider
- * PropertySourceProviders} is enabled or disabled.
- *
- * @return {@code true} if the automatic loading is enabled,
- * otherwise {@code false}.
- */
- public boolean isPropertySourceProvidersLoadingEnabled() {
- return loadProvidedPropertySourceProviders;
- }
-
- //X TODO think on a functonality/API for using the default PropertyConverters and use the configured ones here
- //X TODO as overrides used first.
-
-
- /**
- * Builds a new configuration based on the configuration of this builder instance.
- *
- * @return a new {@link org.apache.tamaya.Configuration configuration instance},
- * never {@code null}.
- */
- public Configuration build() {
- checkBuilderState();
-
- built = true;
-
- contextBuilder.loadProvidedPropertyConverters(isPropertyConverterLoadingEnabled());
- contextBuilder.loadProvidedPropertySources(isPropertySourcesLoadingEnabled());
- contextBuilder.loadProvidedPropertySourceProviders(isPropertySourceProvidersLoadingEnabled());
- contextBuilder.loadProvidedPropertyFilters(isLoadProvidedPropertyFilters);
-
- return new DefaultConfiguration(contextBuilder.build());
- }
-
- /**
- * Mapper to map a URL given as string to an URL instance.
- */
- private static class StringToURLMapper implements Function<String, URL> {
- @Override
- public URL apply(String u) {
- try {
- return new URL(u);
- } catch (MalformedURLException e) {
- throw new ConfigException(u + " is not a valid URL", e);
- }
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/f78f6a11/src/main/java/org/apache/tamaya/modules/builder/ProgrammaticConfigurationContext.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/tamaya/modules/builder/ProgrammaticConfigurationContext.java b/src/main/java/org/apache/tamaya/modules/builder/ProgrammaticConfigurationContext.java
deleted file mode 100644
index e748eaa..0000000
--- a/src/main/java/org/apache/tamaya/modules/builder/ProgrammaticConfigurationContext.java
+++ /dev/null
@@ -1,406 +0,0 @@
-/*
- * 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.modules.builder;
-
-
-import org.apache.tamaya.PropertyConverter;
-import org.apache.tamaya.TypeLiteral;
-import org.apache.tamaya.core.internal.PropertyConverterManager;
-import org.apache.tamaya.spi.ConfigurationContext;
-import org.apache.tamaya.spi.ConfigurationContextBuilder;
-import org.apache.tamaya.spi.PropertyFilter;
-import org.apache.tamaya.spi.PropertySource;
-import org.apache.tamaya.spi.PropertySourceProvider;
-import org.apache.tamaya.spi.PropertyValueCombinationPolicy;
-import org.apache.tamaya.spi.ServiceContext;
-
-import javax.annotation.Priority;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Objects;
-import java.util.StringJoiner;
-import java.util.concurrent.locks.Lock;
-import java.util.concurrent.locks.StampedLock;
-import java.util.function.Function;
-import java.util.function.Predicate;
-import java.util.logging.Logger;
-import java.util.stream.Collectors;
-import java.util.stream.Stream;
-
-import static java.util.stream.Collectors.toList;
-
-/**
- * Implementation of the {@link org.apache.tamaya.spi.ConfigurationContext}
- * used by the {@link org.apache.tamaya.modules.builder.ConfigurationBuilder}
- * internally.
- */
-class ProgrammaticConfigurationContext implements ConfigurationContext {
-
- /**
- * The logger used.
- */
- private final static Logger LOG = Logger.getLogger(ProgrammaticConfigurationContext.class.getName());
- /**
- * Cubcomponent handling {@link org.apache.tamaya.PropertyConverter} instances.
- */
- private PropertyConverterManager propertyConverterManager = new PropertyConverterManager();
-
- /**
- * The current unmodifiable list of loaded {@link org.apache.tamaya.spi.PropertySource} instances.
- */
- private List<PropertySource> immutablePropertySources = new ArrayList<>();
-
- /**
- * The current unmodifiable list of loaded {@link org.apache.tamaya.spi.PropertyFilter} instances.
- */
- private List<PropertyFilter> immutablePropertyFilters = new ArrayList<>();
-
- /**
- * The overriding policy used when combining PropertySources registered to evalute the final configuration
- * values.
- */
- private PropertyValueCombinationPolicy propertyValueCombinationPolicy;
-
- /**
- * Lock for internal synchronization.
- */
- private StampedLock propertySourceLock = new StampedLock();
-
-
- /**
- * The first time the Configuration system gets invoked we do initialize
- * all our {@link org.apache.tamaya.spi.PropertySource}s and
- * {@link org.apache.tamaya.spi.PropertyFilter}s which are known at startup.
- */
- @SuppressWarnings("unchecked")
- public ProgrammaticConfigurationContext(Builder builder) {
- propertyConverterManager = new PropertyConverterManager(builder.loadProvidedPropertyConverters);
-
- immutablePropertySources = getAllPropertySources(builder).stream()
- .sorted(this::comparePropertySources)
- .collect(Collectors.toList());
-
-
- immutablePropertyFilters = getPropertyFilters(builder).stream()
- .sorted(this::comparePropertyFilters)
- .collect(toList());
-
-
- propertyValueCombinationPolicy = builder.propertyValueCombinationPolicy;
-
- builder.propertyConverters.forEach((literal, converters) -> {
- converters.stream().filter(c -> c != null)
- .forEach(c -> propertyConverterManager.register((TypeLiteral<Object>) literal,
- (PropertyConverter<Object>) c));
- });
-
- LOG.info(() -> "Using " + immutablePropertySources.size() + " property sources: " +
- createStringList(immutablePropertySources, ps -> ps.getName() + '[' + ps.getClass().getName() + ']'));
-
-
- LOG.info(() -> "Using " + immutablePropertyFilters.size() + " property filters: " +
- createStringList(immutablePropertyFilters, f -> f.getClass().getName()));
-
-
- LOG.info(() -> "Using PropertyValueCombinationPolicy: " + propertyValueCombinationPolicy);
- }
-
- private List<PropertyFilter> getPropertyFilters(Builder builder) {
- List<PropertyFilter> provided = builder.loadProvidedPropertyFilters
- ? ServiceContext.getInstance().getServices(PropertyFilter.class)
- : new ArrayList<>(0);
-
- List<PropertyFilter> configured = builder.propertyFilters;
-
- return Stream.of(provided, configured).flatMap(Collection::stream)
- .collect(toList());
- }
-
- private List<PropertySource> getAllPropertySources(Builder builder) {
- List<PropertySource> provided = builder.loadProvidedPropertySources
- ? ServiceContext.getInstance().getServices(PropertySource.class)
- : new ArrayList<>(0);
-
- if (builder.loadProvidedPropertySourceProviders) {
- List<PropertySourceProvider> providers = ServiceContext.getInstance()
- .getServices(PropertySourceProvider.class);
- for (PropertySourceProvider provider : providers) {
- Collection<PropertySource> sources = provider.getPropertySources();
- provided.addAll(sources);
- }
- }
-
- List<PropertySource> configured = builder.propertySources;
-
- return Stream.of(provided, configured).flatMap(Collection::stream)
- .collect(toList());
- }
-
- public void addPropertySources(PropertySource... propertySourcesToAdd) {
- Lock writeLock = propertySourceLock.asWriteLock();
- try {
- writeLock.lock();
- List<PropertySource> newPropertySources = new ArrayList<>(this.immutablePropertySources);
- newPropertySources.addAll(Arrays.asList(propertySourcesToAdd));
- Collections.sort(newPropertySources, this::comparePropertySources);
-
- this.immutablePropertySources = Collections.unmodifiableList(newPropertySources);
- } finally {
- writeLock.unlock();
- }
- }
-
- /**
- * Order property source reversely, the most important come first.
- *
- * @param source1 the first PropertySource
- * @param source2 the second PropertySource
- * @return the comparison result.
- */
- private int comparePropertySources(PropertySource source1, PropertySource source2) {
-
- //X TODO this method duplicates org.apache.tamaya.core.internal.DefaultConfigurationContext.PropertySourceComparator.comparePropertySources()
- //X maybe we should extract the Comperator in an own class for real code-reuse (copy paste == bad code reuse)
-
- if (source1.getOrdinal() < source2.getOrdinal()) {
- return -1;
- } else if (source1.getOrdinal() > source2.getOrdinal()) {
- return 1;
- } else {
- return source1.getClass().getName().compareTo(source2.getClass().getName());
- }
- }
-
- /**
- * Compare 2 filters for ordering the filter chain.
- *
- * @param filter1 the first filter
- * @param filter2 the second filter
- * @return the comparison result
- */
- private int comparePropertyFilters(PropertyFilter filter1, PropertyFilter filter2) {
-
- //X TODO this method duplicates org.apache.tamaya.core.internal.DefaultConfigurationContext.PropertySourceComparator.comparePropertyFilters()
- //X maybe we should extract the Comperator in an own class for real code-reuse (copy paste == bad code reuse)
-
- Priority prio1 = filter1.getClass().getAnnotation(Priority.class);
- Priority prio2 = filter2.getClass().getAnnotation(Priority.class);
- int ord1 = prio1 != null ? prio1.value() : 0;
- int ord2 = prio2 != null ? prio2.value() : 0;
-
- if (ord1 < ord2) {
- return -1;
- } else if (ord1 > ord2) {
- return 1;
- } else {
- return filter1.getClass().getName().compareTo(filter2.getClass().getName());
- }
- }
-
- @Override
- public List<PropertySource> getPropertySources() {
- return immutablePropertySources;
- }
-
- public <T> void addPropertyConverter(TypeLiteral<T> typeToConvert, PropertyConverter<T> propertyConverter) {
- propertyConverterManager.register(typeToConvert, propertyConverter);
- LOG.info(() -> "Added PropertyConverter: " + propertyConverter.getClass().getName());
- }
-
- @Override
- public Map<TypeLiteral<?>, List<PropertyConverter<?>>> getPropertyConverters() {
- return propertyConverterManager.getPropertyConverters();
- }
-
- @Override
- public <T> List<PropertyConverter<T>> getPropertyConverters(TypeLiteral<T> targetType) {
- return propertyConverterManager.getPropertyConverters(targetType);
- }
-
- @Override
- public List<PropertyFilter> getPropertyFilters() {
- return immutablePropertyFilters;
- }
-
- @Override
- public PropertyValueCombinationPolicy getPropertyValueCombinationPolicy() {
- return propertyValueCombinationPolicy;
- }
-
- private <T> String createStringList(Collection<T> propertySources, Function<T, String> mapper) {
- StringJoiner joiner = new StringJoiner(", ");
- propertySources.forEach(t -> joiner.add(mapper.apply(t)));
- return joiner.toString();
- }
-
- @Override
- public ConfigurationContextBuilder toBuilder() {
- // @todo Check if it could be useful to support this method, Oliver B. Fischer
- throw new RuntimeException("This method is currently not supported.");
- }
-
- @Override
- public Collection<PropertySource> getPropertySources(Predicate<PropertySource> selector) {
- // @todo Check if it could be useful to support this method, Oliver B. Fischer
- throw new RuntimeException("This method is currently not supported.");
- }
-
- /**
- * The Builder for {@link ProgrammaticConfigurationContext}
- */
- public final static class Builder {
- /**
- * The current unmodifiable list of loaded {@link org.apache.tamaya.spi.PropertySource} instances.
- */
- private List<PropertySource> propertySources = new ArrayList<>();
-
- /**
- * The current unmodifiable list of loaded {@link org.apache.tamaya.spi.PropertyFilter} instances.
- */
- private List<PropertyFilter> propertyFilters = new ArrayList<>();
-
- private Map<TypeLiteral<?>, List<PropertyConverter<?>>> propertyConverters = new HashMap<>();
-
- /**
- * The overriding policy used when combining PropertySources registered to evalute the final configuration
- * values.
- */
- private PropertyValueCombinationPolicy propertyValueCombinationPolicy =
- PropertyValueCombinationPolicy.DEFAULT_OVERRIDING_COLLECTOR;
-
- private boolean loadProvidedPropertyConverters;
- private boolean loadProvidedPropertySources;
- private boolean loadProvidedPropertySourceProviders;
- private boolean loadProvidedPropertyFilters;
-
- public Builder setPropertyValueCombinationPolicy(PropertyValueCombinationPolicy policy) {
- this.propertyValueCombinationPolicy = Objects.requireNonNull(policy);
- return this;
- }
-
- public Builder addPropertySources(PropertySource... propertySources) {
- List<PropertySource> filtered = Stream.of(propertySources).filter(this::isNotNull)
- .collect(toList());
-
- this.propertySources.addAll(filtered);
-
- return this;
- }
-
- public Builder addPropertySources(Collection<PropertySource> propertySources) {
- List<PropertySource> filtered = propertySources.stream().filter(this::isNotNull)
- .collect(toList());
-
- this.propertySources.addAll(filtered);
-
- return this;
- }
-
- public Builder addPropertySourceProviders(PropertySourceProvider... propertySourceProviders) {
- List<PropertySourceProvider> providers = Stream.of(propertySourceProviders).filter(this::isNotNull)
- .collect(toList());
-
- return addPropertySourceProviders(providers);
- }
-
- public Builder addPropertySourceProviders(Collection<PropertySourceProvider> providers) {
- List<PropertySource> filtered = providers.stream().filter(this::isNotNull)
- .flatMap(p -> p.getPropertySources().stream())
- .filter(this::isNotNull)
- .collect(toList());
-
- this.propertySources.addAll(filtered);
-
- return this;
- }
-
- public Builder addPropertyFilters(PropertyFilter... propertySources) {
- List<PropertyFilter> sources = Stream.of(propertySources).filter(this::isNotNull)
- .collect(toList());
-
- this.propertyFilters.addAll(sources);
-
- return this;
- }
-
- public Builder addPropertyFilters(Collection<PropertyFilter> propertySources) {
- List<PropertyFilter> sources = propertySources.stream().filter(this::isNotNull)
- .collect(toList());
-
- this.propertyFilters.addAll(sources);
-
- return this;
- }
-
- /**
- * Should be never used.
- */
- @Deprecated
- public Builder setConfigurationContext(ConfigurationContext configurationContext) {
- this.addPropertySources(configurationContext.getPropertySources());
- this.addPropertyFilters(configurationContext.getPropertyFilters());
- this.propertyValueCombinationPolicy = Objects.requireNonNull(
- configurationContext.getPropertyValueCombinationPolicy());
- return this;
- }
-
- //X TODO think on a functonality/API for using the default PropertyConverters and use the configured ones here
- //X TODO as overrides used first.
-
- public <T> Builder addPropertyConverter(TypeLiteral<T> type, PropertyConverter<T> propertyConverter) {
- propertyConverters.computeIfAbsent(type, (t) -> new ArrayList<>())
- .add(propertyConverter);
-
- return this;
- }
-
- public ConfigurationContext build() {
- return new ProgrammaticConfigurationContext(this);
- }
-
-
- public void loadProvidedPropertyConverters(boolean state) {
- loadProvidedPropertyConverters = state;
- }
-
- public void loadProvidedPropertySources(boolean state) {
- loadProvidedPropertySources = state;
- }
-
- public void loadProvidedPropertySourceProviders(boolean state) {
- loadProvidedPropertySourceProviders = state;
- }
-
- public void loadProvidedPropertyFilters(boolean state) {
- loadProvidedPropertyFilters = state;
- }
-
- private <T> boolean isNotNull(T item) {
- return null != item;
- }
- }
-
-
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/f78f6a11/src/main/java/org/apache/tamaya/modules/builder/package-info.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/tamaya/modules/builder/package-info.java b/src/main/java/org/apache/tamaya/modules/builder/package-info.java
deleted file mode 100644
index dacba73..0000000
--- a/src/main/java/org/apache/tamaya/modules/builder/package-info.java
+++ /dev/null
@@ -1,28 +0,0 @@
-/*
- * 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.
- */
-/**
- * This package provides
- * {@link org.apache.tamaya.modules.builder.ConfigurationBuilder a configuration
- * builder} that allows to build a configuration manually without
- * using exclusively on the Service Provider Interface API of Tamaya.
- *
- * @see org.apache.tamaya.modules.builder.ConfigurationBuilder
- * @see org.apache.tamaya.Configuration
- */
-package org.apache.tamaya.modules.builder;
\ No newline at end of file
[05/50] [abbrv] incubator-tamaya-sandbox git commit: TAMAYA-60
Removed the modules package for the package hierarchy.
Posted by pl...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/f78f6a11/src/test/java/org/apache/tamaya/modules/builder/ConfigurationBuilderTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/tamaya/modules/builder/ConfigurationBuilderTest.java b/src/test/java/org/apache/tamaya/modules/builder/ConfigurationBuilderTest.java
deleted file mode 100644
index a5062bd..0000000
--- a/src/test/java/org/apache/tamaya/modules/builder/ConfigurationBuilderTest.java
+++ /dev/null
@@ -1,896 +0,0 @@
-/*
- * 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.modules.builder;
-
-import org.apache.tamaya.ConfigException;
-import org.apache.tamaya.Configuration;
-import org.apache.tamaya.TypeLiteral;
-import org.apache.tamaya.modules.builder.util.types.CustomTypeA;
-import org.apache.tamaya.modules.builder.util.types.CustomTypeB;
-import org.apache.tamaya.modules.builder.util.types.CustomTypeC;
-import org.apache.tamaya.spi.PropertyFilter;
-import org.apache.tamaya.spi.PropertySource;
-import org.apache.tamaya.spi.PropertySourceProvider;
-import org.hamcrest.CoreMatchers;
-import org.hamcrest.Matchers;
-import org.junit.Ignore;
-import org.junit.Test;
-import org.mockito.Mockito;
-
-
-import java.io.IOException;
-import java.net.URL;
-
-import static java.util.Arrays.asList;
-import static org.apache.tamaya.modules.builder.util.mockito.NotMockedAnswer.NOT_MOCKED_ANSWER;
-import static org.hamcrest.CoreMatchers.equalTo;
-import static org.hamcrest.CoreMatchers.nullValue;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.Matchers.is;
-import static org.hamcrest.Matchers.notNullValue;
-import static org.mockito.Matchers.anyString;
-import static org.mockito.Mockito.CALLS_REAL_METHODS;
-import static org.mockito.Mockito.doReturn;
-import static org.mockito.Mockito.doThrow;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.verify;
-
-
-public class ConfigurationBuilderTest {
-
- @Test
- public void buildCanBuildEmptyConfiguration() {
- ConfigurationBuilder builder = new ConfigurationBuilder();
-
- Configuration config = builder.build();
-
- assertThat(config, notNullValue());
- }
-
- @Test(expected = IllegalStateException.class)
- public void buildCanBeCalledOnlyOnce() {
- ConfigurationBuilder builder = new ConfigurationBuilder();
-
- builder.build();
- builder.build();
- }
-
- /*********************************************************************
- * Tests for adding P r o p e r t y S o u r c e s
- */
-
- @Test(expected = NullPointerException.class)
- public void addPropertySourcesDoesNotAcceptNullValue() {
- ConfigurationBuilder builder = new ConfigurationBuilder();
-
- builder.addPropertySources((PropertySource[])null);
- }
-
- @Test(expected = IllegalStateException.class)
- public void propertySourceCanNotBeAddedAfterBuildingTheConfiguration() {
- PropertySource first = mock(PropertySource.class, NOT_MOCKED_ANSWER);
-
- doReturn("first").when(first).getName();
- doReturn(100).when(first).getOrdinal();
-
- ConfigurationBuilder builder = new ConfigurationBuilder().addPropertySources(first);
-
- builder.build();
-
- PropertySource second = mock(PropertySource.class, NOT_MOCKED_ANSWER);
-
- doReturn("second").when(first).getName();
-
- builder.addPropertySources(second);
- }
-
- @Test
- public void singleAddedPropertySourceIsUsed() {
- PropertySource source = mock(PropertySource.class, NOT_MOCKED_ANSWER);
-
- doReturn("one").when(source).getName();
- doReturn("a").when(source).get("keyOfA");
- doReturn(100).when(source).getOrdinal();
-
- ConfigurationBuilder builder = new ConfigurationBuilder().addPropertySources(source);
-
- Configuration config = builder.build();
-
- String valueOfA = config.get("keyOfA");
-
- assertThat(valueOfA, notNullValue());
- assertThat(valueOfA, equalTo("a"));
- }
-
- @Test
- public void twoAddedPropertySourcesAreUsed() {
- PropertySource sourceOne = mock(PropertySource.class, NOT_MOCKED_ANSWER);
-
- doReturn("one").when(sourceOne).getName();
- doReturn("b").when(sourceOne).get("keyOfA");
- doReturn(10).when(sourceOne).getOrdinal();
-
- PropertySource sourceTwo = mock(PropertySource.class, NOT_MOCKED_ANSWER);
- doReturn("two").when(sourceTwo).getName();
- doReturn("a").when(sourceTwo).get("keyOfA");
- doReturn(10).when(sourceTwo).getOrdinal();
-
- ConfigurationBuilder builder = new ConfigurationBuilder().addPropertySources(sourceOne)
- .addPropertySources(sourceTwo);
-
- Configuration config = builder.build();
-
- String valueOfA = config.get("keyOfA");
-
- assertThat(valueOfA, notNullValue());
- assertThat(valueOfA, equalTo("a"));
- }
-
- @Ignore
- @Test(expected = ConfigException.class)
- public void twoPropertySourcesSamePrioritySameKey() {
- PropertySource sourceOne = mock(PropertySource.class, NOT_MOCKED_ANSWER);
-
- doReturn("one").when(sourceOne).getName();
- doReturn("b").when(sourceOne).get("keyOfA");
- doReturn(20).when(sourceOne).getOrdinal();
-
- PropertySource sourceTwo = mock(PropertySource.class, NOT_MOCKED_ANSWER);
- doReturn("two").when(sourceTwo).getName();
- doReturn("a").when(sourceTwo).get("keyOfA");
- doReturn(20).when(sourceTwo).getOrdinal();
-
- ConfigurationBuilder builder = new ConfigurationBuilder().addPropertySources(sourceOne)
- .addPropertySources(sourceTwo);
-
- Configuration config = builder.build();
-
- config.get("keyOfA");
- }
-
- @Test
- public void twoPropertySourcesDiffPrioritySameKeyLowerAddedFirst() {
- PropertySource sourceOne = mock(PropertySource.class, NOT_MOCKED_ANSWER);
-
- doReturn("one").when(sourceOne).getName();
- doReturn("b").when(sourceOne).get("keyOfA");
- doReturn(10).when(sourceOne).getOrdinal();
-
- PropertySource sourceTwo = mock(PropertySource.class, NOT_MOCKED_ANSWER);
- doReturn("two").when(sourceTwo).getName();
- doReturn("a").when(sourceTwo).get("keyOfA");
- doReturn(20).when(sourceTwo).getOrdinal();
-
- ConfigurationBuilder builder = new ConfigurationBuilder().addPropertySources(sourceOne)
- .addPropertySources(sourceTwo);
-
- Configuration config = builder.build();
-
- String valueOfA = config.get("keyOfA");
-
- assertThat(valueOfA, notNullValue());
- assertThat(valueOfA, equalTo("a"));
- }
-
- @Test
- public void twoPropertySourcesDiffPrioritySameKeyHigherAddedFirst() {
- PropertySource sourceOne = mock(PropertySource.class, NOT_MOCKED_ANSWER);
-
- doReturn("one").when(sourceOne).getName();
- doReturn("b").when(sourceOne).get("keyOfA");
- doReturn(30).when(sourceOne).getOrdinal();
-
- PropertySource sourceTwo = mock(PropertySource.class, NOT_MOCKED_ANSWER);
- doReturn("two").when(sourceTwo).getName();
- doReturn("a").when(sourceTwo).get("keyOfA");
- doReturn(20).when(sourceTwo).getOrdinal();
-
- ConfigurationBuilder builder = new ConfigurationBuilder().addPropertySources(sourceOne, sourceTwo);
-
- Configuration config = builder.build();
-
- String valueOfA = config.get("keyOfA");
-
- assertThat(valueOfA, notNullValue());
- assertThat(valueOfA, equalTo("b"));
- }
-
- @Test
- public void consecutiveCallsToAddPropertySourceArePossible() {
- PropertySource sourceOne = mock(PropertySource.class, NOT_MOCKED_ANSWER);
-
- doReturn("one").when(sourceOne).getName();
- doReturn(null).when(sourceOne).get(anyString());
- doReturn("b").when(sourceOne).get("b");
- doReturn(30).when(sourceOne).getOrdinal();
-
- PropertySource sourceTwo = mock(PropertySource.class, NOT_MOCKED_ANSWER);
- doReturn("two").when(sourceTwo).getName();
- doReturn(null).when(sourceTwo).get(anyString());
- doReturn("a").when(sourceTwo).get("a");
- doReturn(30).when(sourceTwo).getOrdinal();
-
- ConfigurationBuilder builder = new ConfigurationBuilder().addPropertySources(sourceOne)
- .addPropertySources(sourceTwo);
-
- Configuration config = builder.build();
-
- assertThat(config.get("b"), equalTo("b"));
- assertThat(config.get("a"), equalTo("a"));
- }
-
- @Test
- public void addMultiplePropertySourcesWhereOneIsNull() {
- PropertySource sourceOne = mock(PropertySource.class, NOT_MOCKED_ANSWER);
-
- doReturn("one").when(sourceOne).getName();
- doReturn(null).when(sourceOne).get(anyString());
- doReturn("b").when(sourceOne).get("b");
- doReturn(30).when(sourceOne).getOrdinal();
-
- PropertySource sourceTwo = mock(PropertySource.class, NOT_MOCKED_ANSWER);
- doReturn("two").when(sourceTwo).getName();
- doReturn(null).when(sourceTwo).get(anyString());
- doReturn("a").when(sourceTwo).get("a");
- doReturn(30).when(sourceTwo).getOrdinal();
-
- ConfigurationBuilder builder = new ConfigurationBuilder().addPropertySources(sourceOne, null, sourceTwo);
-
- Configuration config = builder.build();
-
- assertThat(config.get("b"), equalTo("b"));
- assertThat(config.get("a"), equalTo("a"));
- }
-
- /**
- * ******************************************************************
- * Tests for adding P r o p e r t y C o n v e r t e r
- */
-
- @Test(expected = NullPointerException.class)
- public void canNotAddNullPropertyConverter() {
- ConfigurationBuilder builder = new ConfigurationBuilder();
-
- builder.addPropertyConverter(TypeLiteral.of(CustomTypeA.class), null);
- }
-
- @Test(expected = NullPointerException.class)
- public void canNotAddNullTypeLiteralButPropertyConverter() {
- ConfigurationBuilder builder = new ConfigurationBuilder();
-
- builder.addPropertyConverter((TypeLiteral<CustomTypeA>)null,
- prop -> new CustomTypeA(prop, prop));
- }
-
- @Test
- public void addedPropertyConverterWithTypeLiteralIsUsedByConfiguration() {
- PropertySource source = mock(PropertySource.class, NOT_MOCKED_ANSWER);
-
- doReturn("source").when(source).getName();
- doReturn("A").when(source).get("key");
- doReturn(100).when(source).getOrdinal();
-
- ConfigurationBuilder builder = new ConfigurationBuilder();
-
- builder.addPropertyConverter(TypeLiteral.of(CustomTypeA.class),
- prop -> new CustomTypeA(prop, prop))
- .addPropertySources(source);
-
- Configuration config = builder.build();
-
- Object resultRaw = config.get("key", CustomTypeA.class);
-
- assertThat(resultRaw, CoreMatchers.notNullValue());
-
- CustomTypeA result = (CustomTypeA)resultRaw;
-
- assertThat(result.getName(), equalTo("AA"));
- }
-
- @Test
- public void addedPropertyConverterWithClassIsUsedByConfiguration() {
- PropertySource source = mock(PropertySource.class, NOT_MOCKED_ANSWER);
-
- doReturn("source").when(source).getName();
- doReturn("A").when(source).get("key");
- doReturn(100).when(source).getOrdinal();
-
- ConfigurationBuilder builder = new ConfigurationBuilder();
-
- builder.addPropertyConverter(CustomTypeA.class,
- prop -> new CustomTypeA(prop, prop))
- .addPropertySources(source);
-
- Configuration config = builder.build();
-
- Object resultRaw = config.get("key", CustomTypeA.class);
-
- assertThat(resultRaw, CoreMatchers.notNullValue());
-
- CustomTypeA result = (CustomTypeA)resultRaw;
-
- assertThat(result.getName(), equalTo("AA"));
- }
-
- @Test
- public void canGetAndConvertPropertyViaOfMethod() {
- PropertySource source = mock(PropertySource.class, NOT_MOCKED_ANSWER);
-
- doReturn("source").when(source).getName();
- doReturn("A").when(source).get("key");
- doReturn(100).when(source).getOrdinal();
-
- ConfigurationBuilder builder = new ConfigurationBuilder();
-
- builder.addPropertySources(source);
-
- Configuration config = builder.build();
-
- Object resultRaw = config.get("key", CustomTypeB.class);
-
- assertThat(resultRaw, CoreMatchers.notNullValue());
-
- CustomTypeB result = (CustomTypeB)resultRaw;
-
- assertThat(result.getName(), equalTo("A"));
- }
-
- /*********************************************************************
- * Tests for adding P r o p e r t y F i l t e r
- */
-
- @Test(expected = NullPointerException.class)
- public void canNotAddNullAsPropertyFilter() {
- ConfigurationBuilder builder = new ConfigurationBuilder();
-
- builder.addPropertyFilters(null);
- }
-
- @Test
- public void canAddNonSPIPropertyFilter() {
- PropertySource source = mock(PropertySource.class, NOT_MOCKED_ANSWER);
-
- doReturn("M").when(source).get("key");
- doReturn("source").when(source).getName();
-
- ConfigurationBuilder builder = new ConfigurationBuilder();
-
- Configuration config = builder.addPropertySources(source)
- .addPropertyFilters(new TestNonSPIPropertyFilterA())
- .build();
-
- String property = config.get("key");
-
- assertThat(property, CoreMatchers.notNullValue());
- assertThat(property, CoreMatchers.containsString("ABC"));
- }
-
- @Test
- public void canAddNonSPIPropertyFiltersViaConsecutiveCalls() {
- PropertySource source = mock(PropertySource.class, NOT_MOCKED_ANSWER);
-
- doReturn("M").when(source).get("key");
- doReturn("source").when(source).getName();
-
- ConfigurationBuilder builder = new ConfigurationBuilder();
-
- Configuration config = builder.addPropertySources(source)
- .addPropertyFilters(new TestNonSPIPropertyFilterA())
- .addPropertyFilters(new TestNonSPIPropertyFilterB())
- .build();
-
- String property = config.get("key");
-
- assertThat(property, CoreMatchers.notNullValue());
- assertThat(property, CoreMatchers.containsString("ABC"));
- assertThat(property, CoreMatchers.containsString("XYZ"));
- }
-
- @Test
- public void canAddMultipleNonSPIPropertyFiltersWhileOneIsNull() {
- PropertySource source = mock(PropertySource.class, NOT_MOCKED_ANSWER);
-
- doReturn("M").when(source).get("key");
- doReturn("source").when(source).getName();
-
- ConfigurationBuilder builder = new ConfigurationBuilder();
-
- Configuration config = builder.addPropertySources(source)
- .addPropertyFilters(new TestNonSPIPropertyFilterA(),
- null,
- new TestNonSPIPropertyFilterB())
- .build();
-
- String property = config.get("key");
-
- assertThat(property, CoreMatchers.notNullValue());
- assertThat(property, CoreMatchers.containsString("ABC"));
- assertThat(property, CoreMatchers.containsString("XYZ"));
- }
-
- @Test
- public void overhandedNullPropertyFilterIsSafelyHandled() {
- PropertySource source = mock(PropertySource.class, NOT_MOCKED_ANSWER);
-
- doReturn("M").when(source).get("key");
- doReturn("source").when(source).getName();
-
- ConfigurationBuilder builder = new ConfigurationBuilder();
-
- Configuration config = builder.addPropertySources(source)
- .addPropertyFilters((PropertyFilter)null) // The cast is needed!
- .addPropertyFilters(new TestNonSPIPropertyFilterB())
- .build();
-
- String property = config.get("key");
-
- assertThat(property, CoreMatchers.notNullValue());
- assertThat(property, CoreMatchers.containsString("XYZ"));
- }
-
- @Test
- public void canAddMultipleNonSPIPropertyFilter() {
- PropertySource source = mock(PropertySource.class, NOT_MOCKED_ANSWER);
-
- doReturn("M").when(source).get("key");
- doReturn("source").when(source).getName();
-
- ConfigurationBuilder builder = new ConfigurationBuilder();
-
- Configuration config = builder.addPropertySources(source)
- .addPropertyFilters(new TestNonSPIPropertyFilterA(),
- new TestNonSPIPropertyFilterB())
- .build();
-
- String property = config.get("key");
-
- assertThat(property, CoreMatchers.notNullValue());
- assertThat(property, CoreMatchers.containsString("ABC"));
- assertThat(property, CoreMatchers.containsString("XYZ"));
- }
-
- /*********************************************************************
- * Tests for adding
- * P r o p e r t y S o u r c e P r o v i d e r s
- */
-
- @Test
- public void handlesSafelyPropertyProviderReturningNullInsteadOfPropertySource() {
- PropertySourceProvider nullReturning = mock(PropertySourceProvider.class, NOT_MOCKED_ANSWER);
-
- doReturn(asList((PropertySource)null)).when(nullReturning).getPropertySources();
-
- ConfigurationBuilder builder = new ConfigurationBuilder();
-
- Configuration config = builder.addPropertySourceProviders(new TestPropertySourceProviderB(),
- nullReturning,
- new TestPropertySourceProvider())
- .build();
-
- assertThat(config.get("tpsp_a"), Matchers.equalTo("A"));
- assertThat(config.get("tpsp_b"), Matchers.equalTo("B"));
- assertThat(config.get("tpsp_x"), Matchers.equalTo("X"));
- assertThat(config.get("tpsp_y"), Matchers.equalTo("Y"));
-
- verify(nullReturning).getPropertySources();
- }
-
- @Test(expected = NullPointerException.class)
- public void cannotAddNullAsPropertyProvider() {
- new ConfigurationBuilder().addPropertySourceProviders(null);
- }
-
- @Test
- public void canAddMultipleNonSPIPropertySourceProviders() {
- ConfigurationBuilder builder = new ConfigurationBuilder();
-
- Configuration config = builder.addPropertySourceProviders(new TestPropertySourceProviderB(),
- new TestPropertySourceProvider())
- .build();
-
- assertThat(config.get("tpsp_a"), Matchers.equalTo("A"));
- assertThat(config.get("tpsp_b"), Matchers.equalTo("B"));
- assertThat(config.get("tpsp_x"), Matchers.equalTo("X"));
- assertThat(config.get("tpsp_y"), Matchers.equalTo("Y"));
- }
-
- @Test
- public void canAddMultipleNonSPIPropertySourceProvidersWhileOfOfThemIsNull() {
- ConfigurationBuilder builder = new ConfigurationBuilder();
-
- Configuration config = builder.addPropertySourceProviders(new TestPropertySourceProviderB(), null,
- new TestPropertySourceProvider())
- .build();
-
- assertThat(config.get("tpsp_a"), Matchers.equalTo("A"));
- assertThat(config.get("tpsp_b"), Matchers.equalTo("B"));
- assertThat(config.get("tpsp_x"), Matchers.equalTo("X"));
- assertThat(config.get("tpsp_y"), Matchers.equalTo("Y"));
- }
-
-
- /*********************************************************************
- * Tests for adding
- * P r o p e r t y V a l u e C o m b i n a t i o n P o l i c y
- */
-
- // @todo TAYAMA-60 Write more tests
-
- /*********************************************************************
- * Tests for enabling and disabling of automatic loading of
- * P r o p e r t y S o u r c e s
- */
-
- @Test
- public void enablingOfProvidedPropertySourceServiceProvidersIsOk() {
- ConfigurationBuilder builder = new ConfigurationBuilder();
-
- builder.disableProvidedPropertyConverters()
- .enableProvidedPropertyConverters();
-
- assertThat(builder.isPropertyConverterLoadingEnabled(), is(true));
- }
-
- @Test
- public void disablingOfProvidedPropertySourceServiceProvidersIsOk() {
- ConfigurationBuilder builder = new ConfigurationBuilder();
-
- builder.enableProvidedPropertyConverters()
- .disableProvidedPropertyConverters();
-
- assertThat(builder.isPropertyConverterLoadingEnabled(), is(false));
- }
-
- @Test(expected = ConfigException.class)
- public void loadingOrPropertyConvertersCanBeDisabled() {
- PropertySource source = mock(PropertySource.class, NOT_MOCKED_ANSWER);
-
- doReturn("source").when(source).getName();
- doReturn("A").when(source).get("key");
- doReturn(100).when(source).getOrdinal();
-
- ConfigurationBuilder builder = new ConfigurationBuilder().addPropertySources(source)
- .enableProvidedPropertyConverters()
- .disableProvidedPropertyConverters();
-
- Configuration config = builder.build();
-
- config.get("key", CustomTypeC.class);
- }
-
- @Test
- public void loadingOfPropertyConvertersCanBeEnabled() {
- PropertySource source = mock(PropertySource.class, NOT_MOCKED_ANSWER);
-
- doReturn("source").when(source).getName();
- doReturn("A").when(source).get("key");
- doReturn(100).when(source).getOrdinal();
-
- ConfigurationBuilder builder = new ConfigurationBuilder().addPropertySources(source)
- .disableProvidedPropertyConverters()
- .enableProvidedPropertyConverters();
-
- Configuration config = builder.build();
-
- CustomTypeC result = config.get("key", CustomTypeC.class);
-
- assertThat(result, notNullValue());
- assertThat(result.getValue(), equalTo("A"));
- }
-
- /*********************************************************************
- * Tests for enabling and disabling of automatic loading of
- * P r o p e r t y S o u r c e s
- */
-
- @Test
- public void enablingOfPropertySourceLoadingIsOk() {
- ConfigurationBuilder builder = new ConfigurationBuilder();
-
- builder.disableProvidedPropertySources()
- .enableProvidedPropertySources();
-
- assertThat(builder.isPropertySourcesLoadingEnabled(), is(true));
- }
-
- @Test
- public void disablingPropertySourceLoadingIsOk() {
- ConfigurationBuilder builder = new ConfigurationBuilder();
-
- builder.enableProvidedPropertySources()
- .disableProvidedPropertySources();
-
- assertThat(builder.isPropertySourcesLoadingEnabled(), is(false));
- }
-
- @Test
- public void loadingOfPropertySourcesCanBeEnabled() {
- ConfigurationBuilder builder = new ConfigurationBuilder();
-
- Configuration config = builder.disableProvidedPropertySources()
- .enableProvidedPropertySources()
- .build();
-
-
- assertThat(builder.isPropertySourcesLoadingEnabled(), is(true));
- assertThat(config.get("tps_a"), Matchers.equalTo("A"));
- }
-
- @Test
- public void loadingOfPropertySourcesCanBeDisabled() {
- ConfigurationBuilder builder = new ConfigurationBuilder();
-
- Configuration config = builder.enableProvidedPropertySources()
- .disableProvidedPropertySources()
- .build();
-
-
- assertThat(builder.isPropertySourcesLoadingEnabled(), is(false));
- assertThat(config.get("tps_c"), Matchers.nullValue());
- }
-
- /*********************************************************************
- * Tests for enabling and disabling of automatic loading of
- * P r o p e r t y F i l t e r s
- */
-
- @Test
- public void enablingOfPropertyFiltersLoadingIsOk() {
- PropertySource source = mock(PropertySource.class, NOT_MOCKED_ANSWER);
-
- doReturn("source").when(source).getName();
- doReturn("A").when(source).get("key");
- doReturn(100).when(source).getOrdinal();
-
- ConfigurationBuilder builder = new ConfigurationBuilder();
-
- Configuration config = builder.disableProvidedPropertyFilters()
- .enabledProvidedPropertyFilters()
- .addPropertySources(source)
- .build();
-
- String property = config.get("key");
-
- assertThat(property, CoreMatchers.notNullValue());
- assertThat(property, Matchers.equalTo("AinBerlin"));
- }
-
- @Test
- public void disablingOfPropertyFiltersLoadingIsOk() {
- ConfigurationBuilder builder = new ConfigurationBuilder();
-
- builder.enabledProvidedPropertyFilters()
- .disableProvidedPropertyFilters();
-
- assertThat(builder.isPropertyFilterLoadingEnabled(), is(false));
- }
-
- @Test
- public void loadingOfPropertyFiltersCanBeDisabled() {
- ConfigurationBuilder builder = new ConfigurationBuilder();
-
- builder.disableProvidedPropertyFilters()
- .enabledProvidedPropertyFilters();
-
- assertThat(builder.isPropertyFilterLoadingEnabled(), is(true));
- }
-
- @Test
- public void loadingOfPropertyFiltersCanBeEnabled() {
- PropertySource source = mock(PropertySource.class, NOT_MOCKED_ANSWER);
-
- doReturn("source").when(source).getName();
- doReturn("A").when(source).get("key");
- doReturn(100).when(source).getOrdinal();
-
- ConfigurationBuilder builder = new ConfigurationBuilder();
-
- Configuration config = builder.enabledProvidedPropertyFilters()
- .disableProvidedPropertyFilters()
- .addPropertySources(source)
- .build();
-
- String property = config.get("key");
-
- assertThat(property, CoreMatchers.notNullValue());
- assertThat(property, Matchers.equalTo("A"));
- }
-
- /*********************************************************************
- * Tests for enabling and disabling of automatic loading of
- * P r o p e r t y S o u r c e P r o v i d e r s
- */
-
- @Test
- public void disablingOfPropertySourceProvidersIsOk() {
- ConfigurationBuilder builder = new ConfigurationBuilder();
-
- builder.enableProvidedPropertySourceProviders()
- .disableProvidedPropertySourceProviders()
- .build();
-
- assertThat(builder.isPropertySourceProvidersLoadingEnabled(), is(false));
- }
-
- @Test
- public void enablingOfPropertySourceProvidersIsOk() {
-
- ConfigurationBuilder builder = new ConfigurationBuilder();
-
- builder.disableProvidedPropertySourceProviders()
- .enableProvidedPropertySourceProviders()
- .build();
-
- assertThat(builder.isPropertySourceProvidersLoadingEnabled(), is(true));
- }
-
- @Test
- public void loadingOfPropertySourceProvidersCanBeEnabled() {
- ConfigurationBuilder builder = new ConfigurationBuilder();
-
- Configuration config = builder.disableProvidedPropertySourceProviders()
- .enableProvidedPropertySourceProviders()
- .build();
-
- assertThat(builder.isPropertySourceProvidersLoadingEnabled(), is(true));
- assertThat(config.get("tpsp_x"), Matchers.equalTo("X"));
- assertThat(config.get("tpsp_y"), Matchers.equalTo("Y"));
- }
-
- @Test
- public void loadingOfPropertySourceProvidersCanBeDisabled() {
- ConfigurationBuilder builder = new ConfigurationBuilder();
-
- Configuration config = builder.enableProvidedPropertySourceProviders()
- .disableProvidedPropertySourceProviders()
- .build();
-
- assertThat(builder.isPropertySourceProvidersLoadingEnabled(), is(false));
- assertThat(config.get("tpsp_x"), nullValue());
- assertThat(config.get("tpsp_x"), nullValue());
- }
-
- @Test(expected = ConfigException.class)
- public void ioExceptionIsTurnedInConfigExceptionWhenLoadingResourceViaURL() throws Exception {
- URL resource = this.getClass().getResource("/configfiles/json/simple.json");
-
- assertThat(resource, CoreMatchers.notNullValue());
-
- ConfigurationBuilder builder = mock(ConfigurationBuilder.class, CALLS_REAL_METHODS);
-
- doThrow(IOException.class).when(builder).getConfigurationDataFromURL(Mockito.eq(resource));
-
- builder.addPropertySource(resource).build();
- }
-
- /*********************************************************************
- * Tests for loading resources via URL (as String)
- */
-
- @Test(expected = ConfigException.class)
- public void tryToLoadOneUnsupportedPropertySourceViaStringURL() {
- URL resource = this.getClass().getResource("/configfiles/other/simple.oml");
-
- assertThat(resource, CoreMatchers.notNullValue());
-
- ConfigurationBuilder builder = new ConfigurationBuilder();
-
- builder.addPropertySource(resource.toString()).build();
- }
-
- @Test
- public void loadOneJSONPropertySourceViaStringURL() {
- URL resource = this.getClass().getResource("/configfiles/json/simple.json");
-
- assertThat(resource, CoreMatchers.notNullValue());
-
- ConfigurationBuilder builder = new ConfigurationBuilder();
-
- Configuration config = builder.addPropertySource(resource.toString())
- .build();
-
- assertThat(config, CoreMatchers.notNullValue());
- assertThat(config.get("a"), equalTo("A"));
- assertThat(config.get("b"), equalTo("B"));
- }
-
- @Test
- public void loadMultipleJSONPropertySourceViaStringURL() {
- URL first = this.getClass().getResource("/configfiles/json/first.json");
- URL second = this.getClass().getResource("/configfiles/json/second.json");
- URL third = this.getClass().getResource("/configfiles/json/third.json");
-
- assertThat(first, CoreMatchers.notNullValue());
- assertThat(second, CoreMatchers.notNullValue());
- assertThat(third, CoreMatchers.notNullValue());
-
- ConfigurationBuilder builder = new ConfigurationBuilder();
-
- Configuration config = builder.addPropertySource(first.toString(), second.toString(),
- null, third.toString())
- .build();
-
- assertThat(config, CoreMatchers.notNullValue());
-
- // from first.json
- assertThat(config.get("d"), equalTo("D"));
- assertThat(config.get("e"), equalTo("E"));
-
- // from second.json
- assertThat(config.get("m"), equalTo("M"));
- assertThat(config.get("n"), equalTo("N"));
-
- // from thrid.json
- assertThat(config.get("p"), equalTo("P"));
- assertThat(config.get("q"), equalTo("Q"));
- }
-
- /**
- * ******************************************************************
- * Tests for loading resources via URL (as URL object)
- */
-
- @Test
- public void loadOneJSONPropertySourceViaURL() {
- URL resource = this.getClass().getResource("/configfiles/json/simple.json");
-
- assertThat(resource, CoreMatchers.notNullValue());
-
- ConfigurationBuilder builder = new ConfigurationBuilder();
-
- Configuration config = builder.addPropertySource(resource)
- .build();
-
- assertThat(config, CoreMatchers.notNullValue());
- assertThat(config.get("a"), equalTo("A"));
- assertThat(config.get("b"), equalTo("B"));
- }
-
- @Test
- public void loadMultipleJSONPropertySourceViaURL() {
- URL first = this.getClass().getResource("/configfiles/json/first.json");
- URL second = this.getClass().getResource("/configfiles/json/second.json");
- URL third = this.getClass().getResource("/configfiles/json/third.json");
-
- assertThat(first, CoreMatchers.notNullValue());
- assertThat(second, CoreMatchers.notNullValue());
- assertThat(third, CoreMatchers.notNullValue());
-
- ConfigurationBuilder builder = new ConfigurationBuilder();
-
- Configuration config = builder.addPropertySource(first, second,
- null, third)
- .build();
-
- assertThat(config, CoreMatchers.notNullValue());
-
- // from first.json
- assertThat(config.get("d"), equalTo("D"));
- assertThat(config.get("e"), equalTo("E"));
-
- // from second.json
- assertThat(config.get("m"), equalTo("M"));
- assertThat(config.get("n"), equalTo("N"));
-
- // from thrid.json
- assertThat(config.get("p"), equalTo("P"));
- assertThat(config.get("q"), equalTo("Q"));
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/f78f6a11/src/test/java/org/apache/tamaya/modules/builder/TestNonSPIPropertyFilterA.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/tamaya/modules/builder/TestNonSPIPropertyFilterA.java b/src/test/java/org/apache/tamaya/modules/builder/TestNonSPIPropertyFilterA.java
deleted file mode 100644
index 7d899dc..0000000
--- a/src/test/java/org/apache/tamaya/modules/builder/TestNonSPIPropertyFilterA.java
+++ /dev/null
@@ -1,34 +0,0 @@
-/*
- * 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.modules.builder;
-
-import org.apache.tamaya.spi.PropertyFilter;
-
-public class TestNonSPIPropertyFilterA implements PropertyFilter {
- @Override
- public String filterProperty(String key, String value) {
- String result = value;
-
- if (!result.contains(("ABC"))) {
- result = value + "ABC";
- }
-
- return result;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/f78f6a11/src/test/java/org/apache/tamaya/modules/builder/TestNonSPIPropertyFilterB.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/tamaya/modules/builder/TestNonSPIPropertyFilterB.java b/src/test/java/org/apache/tamaya/modules/builder/TestNonSPIPropertyFilterB.java
deleted file mode 100644
index d7f7a40..0000000
--- a/src/test/java/org/apache/tamaya/modules/builder/TestNonSPIPropertyFilterB.java
+++ /dev/null
@@ -1,34 +0,0 @@
-/*
- * 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.modules.builder;
-
-import org.apache.tamaya.spi.PropertyFilter;
-
-public class TestNonSPIPropertyFilterB implements PropertyFilter {
- @Override
- public String filterProperty(String key, String value) {
- String result = value;
-
- if (!result.contains(("XYZ"))) {
- result = value + "XYZ";
- }
-
- return result;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/f78f6a11/src/test/java/org/apache/tamaya/modules/builder/TestPropertyFilter.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/tamaya/modules/builder/TestPropertyFilter.java b/src/test/java/org/apache/tamaya/modules/builder/TestPropertyFilter.java
deleted file mode 100644
index 6e9f5ae..0000000
--- a/src/test/java/org/apache/tamaya/modules/builder/TestPropertyFilter.java
+++ /dev/null
@@ -1,34 +0,0 @@
-/*
- * 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.modules.builder;
-
-import org.apache.tamaya.spi.PropertyFilter;
-
-public class TestPropertyFilter implements PropertyFilter {
- @Override
- public String filterProperty(String key, String value) {
- String result = value;
-
- if (!result.contains(("inBerlin"))) {
- result = value + "inBerlin";
- }
-
- return result;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/f78f6a11/src/test/java/org/apache/tamaya/modules/builder/TestPropertySource.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/tamaya/modules/builder/TestPropertySource.java b/src/test/java/org/apache/tamaya/modules/builder/TestPropertySource.java
deleted file mode 100644
index 8c9fc00..0000000
--- a/src/test/java/org/apache/tamaya/modules/builder/TestPropertySource.java
+++ /dev/null
@@ -1,58 +0,0 @@
-/*
- * 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.modules.builder;
-
-import org.apache.tamaya.spi.PropertySource;
-
-import java.util.Collections;
-import java.util.Hashtable;
-import java.util.Map;
-
-public class TestPropertySource
- implements PropertySource
-{
- private Map<String, String> properties;
-
- {
- properties = new Hashtable<>(3);
- properties.put("tps_a", "A");
- properties.put("tps_b", "B");
- properties.put("tps_c", "C");
- }
-
- @Override
- public int getOrdinal() {
- return 456;
- }
-
- @Override
- public String getName() {
- return "TestPropertySource";
- }
-
- @Override
- public String get(String key) {
- return getProperties().get(key);
- }
-
- @Override
- public Map<String, String> getProperties() {
- return Collections.unmodifiableMap(properties);
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/f78f6a11/src/test/java/org/apache/tamaya/modules/builder/TestPropertySourceProvider.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/tamaya/modules/builder/TestPropertySourceProvider.java b/src/test/java/org/apache/tamaya/modules/builder/TestPropertySourceProvider.java
deleted file mode 100644
index a753c25..0000000
--- a/src/test/java/org/apache/tamaya/modules/builder/TestPropertySourceProvider.java
+++ /dev/null
@@ -1,89 +0,0 @@
-/*
- * 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.modules.builder;
-
-import org.apache.tamaya.spi.PropertySource;
-import org.apache.tamaya.spi.PropertySourceProvider;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.Map;
-
-public class TestPropertySourceProvider
- implements PropertySourceProvider
-{
- @Override
- public Collection<PropertySource> getPropertySources() {
- ArrayList<PropertySource> sources = new ArrayList<>(2);
-
- sources.add(new XProvidingPropertySource());
- sources.add(new YProvidingPropertySource());
-
- return sources;
- }
-
- private class YProvidingPropertySource implements PropertySource {
- private Map<String, String> props = Collections.singletonMap("tpsp_x", "X");
-
- @Override
- public int getOrdinal() {
- return 100;
- }
-
- @Override
- public String getName() {
- return "YProvidingPropertySource";
- }
-
- @Override
- public String get(String key) {
- return getProperties().get(key);
- }
-
- @Override
- public Map<String, String> getProperties() {
- return props;
- }
- }
-
- private class XProvidingPropertySource implements PropertySource {
- private Map<String, String> props = Collections.singletonMap("tpsp_y", "Y");
-
- @Override
- public Map<String, String> getProperties() {
- return props;
- }
-
- @Override
- public String get(String key) {
- return getProperties().get(key);
- }
-
- @Override
- public int getOrdinal() {
- return 100;
- }
-
- @Override
- public String getName() {
- return "XProvidingPropertySource";
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/f78f6a11/src/test/java/org/apache/tamaya/modules/builder/TestPropertySourceProviderB.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/tamaya/modules/builder/TestPropertySourceProviderB.java b/src/test/java/org/apache/tamaya/modules/builder/TestPropertySourceProviderB.java
deleted file mode 100644
index 890b166..0000000
--- a/src/test/java/org/apache/tamaya/modules/builder/TestPropertySourceProviderB.java
+++ /dev/null
@@ -1,89 +0,0 @@
-/*
- * 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.modules.builder;
-
-import org.apache.tamaya.spi.PropertySource;
-import org.apache.tamaya.spi.PropertySourceProvider;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.Map;
-
-public class TestPropertySourceProviderB
- implements PropertySourceProvider
-{
- @Override
- public Collection<PropertySource> getPropertySources() {
- ArrayList<PropertySource> sources = new ArrayList<>(2);
-
- sources.add(new AProvidingPropertySource());
- sources.add(new BProvidingPropertySource());
-
- return sources;
- }
-
- private class BProvidingPropertySource implements PropertySource {
- private Map<String, String> props = Collections.singletonMap("tpsp_b", "B");
-
- @Override
- public int getOrdinal() {
- return 100;
- }
-
- @Override
- public String getName() {
- return "BProvidingPropertySource";
- }
-
- @Override
- public String get(String key) {
- return getProperties().get(key);
- }
-
- @Override
- public Map<String, String> getProperties() {
- return props;
- }
- }
-
- private class AProvidingPropertySource implements PropertySource {
- private Map<String, String> props = Collections.singletonMap("tpsp_a", "A");
-
- @Override
- public Map<String, String> getProperties() {
- return props;
- }
-
- @Override
- public String get(String key) {
- return getProperties().get(key);
- }
-
- @Override
- public int getOrdinal() {
- return 100;
- }
-
- @Override
- public String getName() {
- return "AProvidingPropertySource";
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/f78f6a11/src/test/java/org/apache/tamaya/modules/builder/util/mockito/NotMockedAnswer.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/tamaya/modules/builder/util/mockito/NotMockedAnswer.java b/src/test/java/org/apache/tamaya/modules/builder/util/mockito/NotMockedAnswer.java
deleted file mode 100644
index d754305..0000000
--- a/src/test/java/org/apache/tamaya/modules/builder/util/mockito/NotMockedAnswer.java
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
- * 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.modules.builder.util.mockito;
-
-import org.mockito.exceptions.base.MockitoException;
-import org.mockito.invocation.InvocationOnMock;
-import org.mockito.stubbing.Answer;
-
-import java.io.Serializable;
-
-// @todo This is a duplicated class
-public class NotMockedAnswer implements Answer<Object>, Serializable {
- public final static NotMockedAnswer NOT_MOCKED_ANSWER = new NotMockedAnswer();
-
- private NotMockedAnswer() {
- }
-
- @Override
- public Object answer(InvocationOnMock invocation) throws Throwable {
- StringBuilder msgBuilder = new StringBuilder();
-
- msgBuilder.append("Invocation of method not mocked: ")
- .append(invocation.getMethod().toGenericString());
-
- if (invocation.getArguments().length > 0) {
- msgBuilder.append(" Supplied arguments: ");
-
- for (int i = 0; i < invocation.getArguments().length; i++) {
- msgBuilder.append(invocation.getArguments()[i]);
-
- if (i - 1 < invocation.getArguments().length) {
- msgBuilder.append(", ");
- }
- }
- }
-
- throw new MockitoException(msgBuilder.toString());
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/f78f6a11/src/test/java/org/apache/tamaya/modules/builder/util/types/CustomTypeA.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/tamaya/modules/builder/util/types/CustomTypeA.java b/src/test/java/org/apache/tamaya/modules/builder/util/types/CustomTypeA.java
deleted file mode 100644
index 378a131..0000000
--- a/src/test/java/org/apache/tamaya/modules/builder/util/types/CustomTypeA.java
+++ /dev/null
@@ -1,34 +0,0 @@
-/*
- * 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.modules.builder.util.types;
-
-/**
- * Custom type with two argument constructor.
- */
-public class CustomTypeA {
- private String name;
-
- public CustomTypeA(String name, String other) {
- this.name = name + other;
- }
-
- public String getName() {
- return name;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/f78f6a11/src/test/java/org/apache/tamaya/modules/builder/util/types/CustomTypeB.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/tamaya/modules/builder/util/types/CustomTypeB.java b/src/test/java/org/apache/tamaya/modules/builder/util/types/CustomTypeB.java
deleted file mode 100644
index a00abda..0000000
--- a/src/test/java/org/apache/tamaya/modules/builder/util/types/CustomTypeB.java
+++ /dev/null
@@ -1,39 +0,0 @@
-/*
- * 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.modules.builder.util.types;
-
-/**
- * Custom type with factory method
- * {@link org.apache.tamaya.builder.util.types.CustomTypeB#of(String)}
- */
-public class CustomTypeB {
- private String name;
-
- private CustomTypeB(String value) {
- this.name = value;
- }
-
- public String getName() {
- return name;
- }
-
- public static CustomTypeB of(String source) {
- return new CustomTypeB(source);
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/f78f6a11/src/test/java/org/apache/tamaya/modules/builder/util/types/CustomTypeC.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/tamaya/modules/builder/util/types/CustomTypeC.java b/src/test/java/org/apache/tamaya/modules/builder/util/types/CustomTypeC.java
deleted file mode 100644
index a75af2b..0000000
--- a/src/test/java/org/apache/tamaya/modules/builder/util/types/CustomTypeC.java
+++ /dev/null
@@ -1,36 +0,0 @@
-/*
- * 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.modules.builder.util.types;
-
-public class CustomTypeC {
- private String value;
-
-
- public CustomTypeC(String in, @SuppressWarnings("unused") int iHideThisConstructorForTamaya) {
- value = in;
- }
-
- public String getValue() {
- return value;
- }
-
- public static CustomTypeC produceFrom(String in) {
- return new CustomTypeC(in, -1);
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/f78f6a11/src/test/java/org/apache/tamaya/modules/builder/util/types/CustomTypeCPropertyConverter.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/tamaya/modules/builder/util/types/CustomTypeCPropertyConverter.java b/src/test/java/org/apache/tamaya/modules/builder/util/types/CustomTypeCPropertyConverter.java
deleted file mode 100644
index ede9fda..0000000
--- a/src/test/java/org/apache/tamaya/modules/builder/util/types/CustomTypeCPropertyConverter.java
+++ /dev/null
@@ -1,28 +0,0 @@
-/*
- * 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.modules.builder.util.types;
-
-import org.apache.tamaya.PropertyConverter;
-
-public class CustomTypeCPropertyConverter implements PropertyConverter<org.apache.tamaya.modules.builder.util.types.CustomTypeC> {
- @Override
- public org.apache.tamaya.modules.builder.util.types.CustomTypeC convert(String value) {
- return org.apache.tamaya.modules.builder.util.types.CustomTypeC.produceFrom(value);
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/f78f6a11/src/test/resources/META-INF/services/org.apache.tamaya.PropertyConverter
----------------------------------------------------------------------
diff --git a/src/test/resources/META-INF/services/org.apache.tamaya.PropertyConverter b/src/test/resources/META-INF/services/org.apache.tamaya.PropertyConverter
index 9510492..b9e0d44 100644
--- a/src/test/resources/META-INF/services/org.apache.tamaya.PropertyConverter
+++ b/src/test/resources/META-INF/services/org.apache.tamaya.PropertyConverter
@@ -16,4 +16,4 @@
# specific language governing permissions and limitations
# under the License.
#
-org.apache.tamaya.modules.builder.util.types.CustomTypeCPropertyConverter
\ No newline at end of file
+org.apache.tamaya.builder.util.types.CustomTypeCPropertyConverter
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/f78f6a11/src/test/resources/META-INF/services/org.apache.tamaya.spi.PropertyFilter
----------------------------------------------------------------------
diff --git a/src/test/resources/META-INF/services/org.apache.tamaya.spi.PropertyFilter b/src/test/resources/META-INF/services/org.apache.tamaya.spi.PropertyFilter
index d69635f..f35e9c5 100644
--- a/src/test/resources/META-INF/services/org.apache.tamaya.spi.PropertyFilter
+++ b/src/test/resources/META-INF/services/org.apache.tamaya.spi.PropertyFilter
@@ -16,4 +16,4 @@
# specific language governing permissions and limitations
# under the License.
#
-org.apache.tamaya.modules.builder.TestPropertyFilter
+org.apache.tamaya.builder.TestPropertyFilter
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/f78f6a11/src/test/resources/META-INF/services/org.apache.tamaya.spi.PropertySource
----------------------------------------------------------------------
diff --git a/src/test/resources/META-INF/services/org.apache.tamaya.spi.PropertySource b/src/test/resources/META-INF/services/org.apache.tamaya.spi.PropertySource
index c0cc7f7..64d1b0d 100644
--- a/src/test/resources/META-INF/services/org.apache.tamaya.spi.PropertySource
+++ b/src/test/resources/META-INF/services/org.apache.tamaya.spi.PropertySource
@@ -16,4 +16,4 @@
# specific language governing permissions and limitations
# under the License.
#
-org.apache.tamaya.modules.builder.TestPropertySource
+org.apache.tamaya.builder.TestPropertySource
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/f78f6a11/src/test/resources/META-INF/services/org.apache.tamaya.spi.PropertySourceProvider
----------------------------------------------------------------------
diff --git a/src/test/resources/META-INF/services/org.apache.tamaya.spi.PropertySourceProvider b/src/test/resources/META-INF/services/org.apache.tamaya.spi.PropertySourceProvider
index 12aa505..9a19ea0 100644
--- a/src/test/resources/META-INF/services/org.apache.tamaya.spi.PropertySourceProvider
+++ b/src/test/resources/META-INF/services/org.apache.tamaya.spi.PropertySourceProvider
@@ -16,4 +16,4 @@
# specific language governing permissions and limitations
# under the License.
#
-org.apache.tamaya.modules.builder.TestPropertySourceProvider
+org.apache.tamaya.builder.TestPropertySourceProvider
[08/50] [abbrv] incubator-tamaya-sandbox git commit: TAMAYA-60
Changed method signatures.
Posted by pl...@apache.org.
TAMAYA-60 Changed method signatures.
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/f34d77dc
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/tree/f34d77dc
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/diff/f34d77dc
Branch: refs/heads/master
Commit: f34d77dc195f7956626c8150e0145aa79107e5ea
Parents: f78f6a1
Author: Oliver B. Fischer <pl...@apache.org>
Authored: Tue Mar 24 08:24:38 2015 +0100
Committer: Oliver B. Fischer <pl...@apache.org>
Committed: Tue Mar 24 08:24:38 2015 +0100
----------------------------------------------------------------------
.../apache/tamaya/builder/ConfigurationBuilder.java | 15 ++++++---------
1 file changed, 6 insertions(+), 9 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/f34d77dc/src/main/java/org/apache/tamaya/builder/ConfigurationBuilder.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/tamaya/builder/ConfigurationBuilder.java b/src/main/java/org/apache/tamaya/builder/ConfigurationBuilder.java
index 51abbcf..21d6cf7 100644
--- a/src/main/java/org/apache/tamaya/builder/ConfigurationBuilder.java
+++ b/src/main/java/org/apache/tamaya/builder/ConfigurationBuilder.java
@@ -37,7 +37,6 @@ import java.net.MalformedURLException;
import java.net.URL;
import java.util.Arrays;
import java.util.Collection;
-import java.util.Collections;
import java.util.Objects;
import java.util.function.Function;
import java.util.stream.Collectors;
@@ -180,8 +179,7 @@ public class ConfigurationBuilder {
* builder.addPropertySources(first, second);}
*</pre>
*
- * @param url first resource with properties for the the configuration to be build.
- * @param urls list additional of resources with properties for the configuration to be
+ * @param urls list of resources with properties for the configuration to be
* build.
*
* @return the builder instance currently used
@@ -189,8 +187,8 @@ public class ConfigurationBuilder {
* @see org.apache.tamaya.format.ConfigurationFormat
* @see org.apache.tamaya.format.ConfigurationFormats#getFormats()
*/
- public ConfigurationBuilder addPropertySource(URL url, URL... urls) {
- Stream.of(Collections.singletonList(url), Arrays.asList(urls))
+ public ConfigurationBuilder addPropertySource(URL... urls) {
+ Stream.of(Arrays.asList(urls))
.flatMap(Collection::stream)
.filter(entry -> entry != null)
.collect(Collectors.toList())
@@ -211,8 +209,7 @@ public class ConfigurationBuilder {
* "file:/etc/defaults/values.properties");}
*</pre>
*
- * @param url first resource with properties for the the configuration to be build.
- * @param urls list additional of resources with properties for the configuration to be
+ * @param urls list of resources with properties for the configuration to be
* build.
*
* @return the builder instance currently used
@@ -220,8 +217,8 @@ public class ConfigurationBuilder {
* @see org.apache.tamaya.format.ConfigurationFormat
* @see org.apache.tamaya.format.ConfigurationFormats#getFormats()
*/
- public ConfigurationBuilder addPropertySource(String url, String... urls) {
- Stream.of(Collections.singletonList(url), Arrays.asList(urls))
+ public ConfigurationBuilder addPropertySource(String... urls) {
+ Stream.of(Arrays.asList(urls))
.flatMap(Collection::stream)
.filter(entry -> entry != null)
.map(new StringToURLMapper())
[32/50] [abbrv] incubator-tamaya-sandbox git commit: TAMAYA-134:
Gitignore improvements and second batch of Javadoc fixes done by Philipp
Ottlinger.
Posted by pl...@apache.org.
TAMAYA-134: Gitignore improvements and second batch of
Javadoc fixes done by Philipp Ottlinger.
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/19b7071d
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/tree/19b7071d
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/diff/19b7071d
Branch: refs/heads/master
Commit: 19b7071ddd8a48402a91a47b4cd275dd12b3f596
Parents: 25d8ce1
Author: anatole <an...@apache.org>
Authored: Tue Jan 19 01:11:27 2016 +0100
Committer: anatole <an...@apache.org>
Committed: Tue Jan 19 01:11:27 2016 +0100
----------------------------------------------------------------------
.../org/apache/tamaya/builder/ConfigurationBuilder.java | 11 +++++++++--
1 file changed, 9 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/19b7071d/src/main/java/org/apache/tamaya/builder/ConfigurationBuilder.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/tamaya/builder/ConfigurationBuilder.java b/src/main/java/org/apache/tamaya/builder/ConfigurationBuilder.java
index cd457a1..afdc121 100644
--- a/src/main/java/org/apache/tamaya/builder/ConfigurationBuilder.java
+++ b/src/main/java/org/apache/tamaya/builder/ConfigurationBuilder.java
@@ -331,7 +331,8 @@ public class ConfigurationBuilder {
/**
- * @return the builder instance currently used
+ * @param propertyValueCombinationPolicy combination policy to use for this builder.
+ * @return the builder instance currently in use.
*/
public ConfigurationBuilder setPropertyValueCombinationPolicy(PropertyValueCombinationPolicy propertyValueCombinationPolicy){
contextBuilder.setPropertyValueCombinationPolicy(propertyValueCombinationPolicy);
@@ -347,6 +348,7 @@ public class ConfigurationBuilder {
* builder.addPropertyConverter(MyType.class, converter}
* </pre>
*
+ * @param <T> the type of the configuration
* @param type the required target type the converter should be applied to
* @param converter the converter to be used to convert the string property
* to the given target type.
@@ -364,6 +366,11 @@ public class ConfigurationBuilder {
}
/**
+ * Adds a propertyConverter of a given type.
+ *
+ * @param <T> the type of the configuration
+ * @param type type literal of this converter.
+ * @param propertyConverter property converter.
* @return the builder instance currently used
*/
public <T> ConfigurationBuilder addPropertyConverter(TypeLiteral<T> type, PropertyConverter<T> propertyConverter){
@@ -560,7 +567,7 @@ public class ConfigurationBuilder {
return loadProvidedPropertySourceProviders;
}
- //X TODO think on a functonality/API for using the default PropertyConverters and use the configured ones here
+ //X TODO think on a functionality/API for using the default PropertyConverters and use the configured ones here
//X TODO as overrides used first.
[50/50] [abbrv] incubator-tamaya-sandbox git commit: Import of the
builder module into the sandbox. We decided to move this module not to the
extension project. Merge branch 'master' of
/Users/obf/tamaya-splitted/tamaya-backup
Posted by pl...@apache.org.
Import of the builder module into the sandbox. We decided to move this module not to the extension project.
Merge branch 'master' of /Users/obf/tamaya-splitted/tamaya-backup
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/7acfa807
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/tree/7acfa807
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/diff/7acfa807
Branch: refs/heads/master
Commit: 7acfa8070cf1a94ff0fdebac7708751bb9eb5b0f
Parents: 6392c95 f45a5bb
Author: Oliver B. Fischer <pl...@apache.org>
Authored: Sun Sep 25 23:21:05 2016 +0200
Committer: Oliver B. Fischer <pl...@apache.org>
Committed: Sun Sep 25 23:21:05 2016 +0200
----------------------------------------------------------------------
builder/pom.xml | 104 +++
.../tamaya/builder/ConfigurationBuilder.java | 605 +++++++++++++
.../ProgrammaticConfigurationContext.java | 388 ++++++++
.../tamaya/builder/PropertySourceBuilder.java | 118 +++
.../tamaya/builder/SimplePropertySource.java | 86 ++
.../org/apache/tamaya/builder/package-info.java | 28 +
.../builder/ConfigurationBuilderTest.java | 907 +++++++++++++++++++
.../builder/TestANonSPIPropertyFilter.java | 35 +
.../builder/TestBNonSPIPropertyFilter.java | 35 +
.../tamaya/builder/TestPropertyFilter.java | 35 +
.../tamaya/builder/TestPropertySource.java | 59 ++
.../builder/TestPropertySourceProvider.java | 91 ++
.../builder/TestPropertySourceProviderB.java | 91 ++
.../builder/util/mockito/NotMockedAnswer.java | 57 ++
.../tamaya/builder/util/types/CustomTypeA.java | 34 +
.../tamaya/builder/util/types/CustomTypeB.java | 39 +
.../tamaya/builder/util/types/CustomTypeC.java | 36 +
.../types/CustomTypeCPropertyConverter.java | 29 +
.../org.apache.tamaya.spi.PropertyConverter | 19 +
.../org.apache.tamaya.spi.PropertyFilter | 19 +
.../org.apache.tamaya.spi.PropertySource | 19 +
...org.apache.tamaya.spi.PropertySourceProvider | 19 +
.../test/resources/configfiles/json/first.json | 4 +
.../test/resources/configfiles/json/second.json | 4 +
.../test/resources/configfiles/json/simple.json | 4 +
.../test/resources/configfiles/json/third.json | 4 +
.../test/resources/configfiles/other/simple.oml | 19 +
27 files changed, 2888 insertions(+)
----------------------------------------------------------------------
[24/50] [abbrv] incubator-tamaya-sandbox git commit: TAMAYA-123:
Adding OSGI Support.
Posted by pl...@apache.org.
TAMAYA-123: Adding OSGI 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/61de41de
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/tree/61de41de
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/diff/61de41de
Branch: refs/heads/master
Commit: 61de41defc580137487625c203b1ad6c07dc0c78
Parents: 89e97b1
Author: anatole <an...@apache.org>
Authored: Fri Oct 16 19:15:21 2015 +0200
Committer: anatole <an...@apache.org>
Committed: Fri Oct 16 19:15:21 2015 +0200
----------------------------------------------------------------------
pom.xml | 17 +++++++++++++++++
1 file changed, 17 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/61de41de/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index a078f79..710e5e7 100644
--- a/pom.xml
+++ b/pom.xml
@@ -28,6 +28,7 @@ under the License.
<artifactId>tamaya-builder</artifactId>
<name>Apache Tamaya Builder</name>
+ <packaging>jar</packaging> <!-- bundle -->
<inceptionYear>2015</inceptionYear>
@@ -86,5 +87,21 @@ under the License.
</dependencies>
+ <!--build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+ <extensions>true</extensions>
+ <configuration>
+ <instructions>
+ <Export-Package>
+ org.apache.tamaya.builder
+ </Export-Package>
+ </instructions>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build -->
</project>
\ No newline at end of file
[39/50] [abbrv] incubator-tamaya-sandbox git commit: Reset version
for new release run.
Posted by pl...@apache.org.
Reset version for new release run.
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/3c667deb
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/tree/3c667deb
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/diff/3c667deb
Branch: refs/heads/master
Commit: 3c667debb76063550e73f3efaaabf38c4c1e754f
Parents: c28fbec
Author: anatole <an...@apache.org>
Authored: Wed Mar 9 14:09:25 2016 +0100
Committer: anatole <an...@apache.org>
Committed: Wed Mar 9 14:09:25 2016 +0100
----------------------------------------------------------------------
pom.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/3c667deb/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index 96f6244..32dc6b5 100644
--- a/pom.xml
+++ b/pom.xml
@@ -23,7 +23,7 @@ under the License.
<parent>
<groupId>org.apache.tamaya.ext</groupId>
<artifactId>tamaya-extensions</artifactId>
- <version>0.3-incubating-SNAPSHOT</version>
+ <version>0.2-incubating-SNAPSHOT</version>
</parent>
<artifactId>tamaya-builder</artifactId>
[14/50] [abbrv] incubator-tamaya-sandbox git commit: Moved
PropertySourceBuilder from resource module to builder module. Minor Javadoc
change.
Posted by pl...@apache.org.
Moved PropertySourceBuilder from resource module to builder module.
Minor Javadoc change.
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/8e555f4d
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/tree/8e555f4d
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/diff/8e555f4d
Branch: refs/heads/master
Commit: 8e555f4dc9658afd2204262df7f3010daf71b15b
Parents: d03d92d
Author: anatole <an...@apache.org>
Authored: Thu May 21 06:28:44 2015 +0200
Committer: anatole <an...@apache.org>
Committed: Thu May 21 06:28:44 2015 +0200
----------------------------------------------------------------------
.../tamaya/builder/ConfigurationBuilder.java | 2 +-
.../tamaya/builder/PropertySourceBuilder.java | 118 +++++++++++++++++++
.../tamaya/builder/SimplePropertySource.java | 55 +++++++++
3 files changed, 174 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/8e555f4d/src/main/java/org/apache/tamaya/builder/ConfigurationBuilder.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/tamaya/builder/ConfigurationBuilder.java b/src/main/java/org/apache/tamaya/builder/ConfigurationBuilder.java
index 799b114..82eb3eb 100644
--- a/src/main/java/org/apache/tamaya/builder/ConfigurationBuilder.java
+++ b/src/main/java/org/apache/tamaya/builder/ConfigurationBuilder.java
@@ -71,7 +71,7 @@ import static java.lang.String.format;
*
* <p><strong>Support for configuration formats</strong></p>
*
- * The configuration builder allows you to add property resources
+ * The configuration builder allows you to put property resources
* via a URL, as shown in the code example above, without implementing
* a {@link org.apache.tamaya.spi.PropertySource PropertySource} or providing an
* instance of a {@link org.apache.tamaya.spi.PropertySource PropertySource}.
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/8e555f4d/src/main/java/org/apache/tamaya/builder/PropertySourceBuilder.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/tamaya/builder/PropertySourceBuilder.java b/src/main/java/org/apache/tamaya/builder/PropertySourceBuilder.java
new file mode 100644
index 0000000..e298939
--- /dev/null
+++ b/src/main/java/org/apache/tamaya/builder/PropertySourceBuilder.java
@@ -0,0 +1,118 @@
+/*
+ * 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.builder;
+
+import org.apache.tamaya.spi.PropertySource;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Objects;
+
+/**
+ * Simple builder for building a {@link org.apache.tamaya.spi.PropertySource}.
+ */
+public final class PropertySourceBuilder {
+ /** The ordinal to be used. */
+ private int ordinal;
+ /** The name to be used. */
+ private String name;
+ /** The properties. */
+ private Map<String,String> properties = new HashMap<>();
+
+ /** private constructor. */
+ private PropertySourceBuilder(String name){
+ this.name = Objects.requireNonNull(name);
+ }
+
+ /**
+ * Gets a new instance of a builder.
+ * @param name The name of the property source, not null.
+ * @return a new instance.
+ */
+ public static PropertySourceBuilder of(String name){
+ return new PropertySourceBuilder(name);
+ }
+
+ /**
+ * Gets a new instance of a builder.
+ * @param name The name of the property source, not null.
+ * @return a new instance.
+ */
+ public static PropertySourceBuilder from(String name){
+ return new PropertySourceBuilder(name);
+ }
+
+ /**
+ * Sets a new property key/value.
+ * @param key the property key, not null.
+ * @param value the property value, not null.
+ * @return the bulder for chaining.
+ */
+ public PropertySourceBuilder put(String key, String value){
+ this.properties.put(key, value);
+ return this;
+ }
+
+ /**
+ * Put all the given key, values.
+ * @param values the new key/values, not null.
+ * @return the bulder for chaining.
+ */
+ public PropertySourceBuilder putAll(Map<String, String> values){
+ this.properties.putAll(values);
+ return this;
+ }
+
+ /**
+ * Sets the ordinal to be used explicitly (instead evaluating it using {@code tamaya.ordinal}.
+ * @param ordinal the explicit ordinal to be used.
+ * @return the bulder for chaining.
+ */
+ public PropertySourceBuilder withOrdinal(int ordinal){
+ this.ordinal = ordinal;
+ return this;
+ }
+
+ /**
+ * Puts all values from the given property source.
+ * @param propertySource the property source, not null.
+ * @return the bulder for chaining.
+ */
+ public PropertySourceBuilder putAll(PropertySource propertySource){
+ this.properties.putAll(propertySource.getProperties());
+ return this;
+ }
+
+ /**
+ * Creates a new immutable {@link org.apache.tamaya.spi.PropertySource} instance.
+ * @return a new immutable {@link org.apache.tamaya.spi.PropertySource} instance, never null.
+ */
+ public PropertySource build(){
+ return new SimplePropertySource(name, properties);
+ }
+
+ @Override
+ public String toString() {
+ return "PropertySourceBuilder{" +
+ "ordinal=" + ordinal +
+ ", name='" + name + '\'' +
+ ", properties=" + properties +
+ '}';
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/8e555f4d/src/main/java/org/apache/tamaya/builder/SimplePropertySource.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/tamaya/builder/SimplePropertySource.java b/src/main/java/org/apache/tamaya/builder/SimplePropertySource.java
new file mode 100644
index 0000000..f343973
--- /dev/null
+++ b/src/main/java/org/apache/tamaya/builder/SimplePropertySource.java
@@ -0,0 +1,55 @@
+/*
+ * 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.builder;
+
+import org.apache.tamaya.spi.PropertySource;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Objects;
+
+/**
+* Simple property source implementation using a map.
+*/
+public class SimplePropertySource implements PropertySource {
+ /** The properties. */
+ private Map<String, String> properties;
+ /** The source's name. */
+ private String name;
+
+ public SimplePropertySource(String name, Map<String, String> properties){
+ this.properties = new HashMap<>(properties);
+ this.name = Objects.requireNonNull(name);
+ }
+
+ @Override
+ public String getName() {
+ return name;
+ }
+
+ @Override
+ public Map<String, String> getProperties() {
+ return this.properties;
+ }
+
+ @Override
+ public String toString(){
+ return "SimplePropertySource(name="+name+", numProps="+properties.size()+")";
+ }
+}
[04/50] [abbrv] incubator-tamaya-sandbox git commit: TAMAYA-60
Completed the JavaDoc for now.
Posted by pl...@apache.org.
TAMAYA-60 Completed the JavaDoc for now.
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/da8f6017
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/tree/da8f6017
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/diff/da8f6017
Branch: refs/heads/master
Commit: da8f60178746c14ea7a24e711147594f5a6dbc39
Parents: 51393bf
Author: Oliver B. Fischer <pl...@apache.org>
Authored: Thu Mar 12 07:42:08 2015 +0100
Committer: Oliver B. Fischer <pl...@apache.org>
Committed: Thu Mar 12 07:42:08 2015 +0100
----------------------------------------------------------------------
.../tamaya/modules/builder/ConfigurationBuilder.java | 13 +++++++++++++
1 file changed, 13 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/da8f6017/src/main/java/org/apache/tamaya/modules/builder/ConfigurationBuilder.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/tamaya/modules/builder/ConfigurationBuilder.java b/src/main/java/org/apache/tamaya/modules/builder/ConfigurationBuilder.java
index 945eb2f..2d7ccac 100644
--- a/src/main/java/org/apache/tamaya/modules/builder/ConfigurationBuilder.java
+++ b/src/main/java/org/apache/tamaya/modules/builder/ConfigurationBuilder.java
@@ -69,6 +69,19 @@ import static java.lang.String.format;
*
* Configuration config = builder.build();
* }</pre>
+ *
+ * <p><strong>Support for configuration formats</strong></p>
+ *
+ * The configuration builder allows you to add property resources
+ * via a URL, as shown in the code example above, without implementing
+ * a {@link org.apache.tamaya.spi.PropertySource PropertySource} or providing an
+ * instance of a {@link org.apache.tamaya.spi.PropertySource PropertySource}.
+ * If a property resource in
+ * a specific format can be added to configuration builder or not depends
+ * on the available implementations of
+ * {@link org.apache.tamaya.format.ConfigurationFormat} in the classpath.
+ * Which formats are available can be checked via
+ * {@link org.apache.tamaya.format.ConfigurationFormats#getFormats()}.
*/
public class ConfigurationBuilder {
/** Builder used to create new ConfigurationContext instances. */
[29/50] [abbrv] incubator-tamaya-sandbox git commit: Fixed all
Javadoc problems for now...
Posted by pl...@apache.org.
Fixed all Javadoc problems for now...
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/528a07d5
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/tree/528a07d5
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/diff/528a07d5
Branch: refs/heads/master
Commit: 528a07d5a60d89e71ed8dadc45d3bfe7b234322f
Parents: 446ff2a
Author: Oliver B. Fischer <pl...@apache.org>
Authored: Fri Jan 1 23:58:57 2016 +0100
Committer: Oliver B. Fischer <pl...@apache.org>
Committed: Fri Jan 1 23:58:57 2016 +0100
----------------------------------------------------------------------
src/main/java/org/apache/tamaya/builder/ConfigurationBuilder.java | 1 -
1 file changed, 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/528a07d5/src/main/java/org/apache/tamaya/builder/ConfigurationBuilder.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/tamaya/builder/ConfigurationBuilder.java b/src/main/java/org/apache/tamaya/builder/ConfigurationBuilder.java
index ad92d51..5126cea 100644
--- a/src/main/java/org/apache/tamaya/builder/ConfigurationBuilder.java
+++ b/src/main/java/org/apache/tamaya/builder/ConfigurationBuilder.java
@@ -527,7 +527,6 @@ public class ConfigurationBuilder {
* @return the builder instance currently used
*
* @see org.apache.tamaya.spi.PropertySourceProvider
- * @see
*/
public ConfigurationBuilder enableProvidedPropertySourceProviders() {
checkBuilderState();
[35/50] [abbrv] incubator-tamaya-sandbox git commit:
[maven-release-plugin] prepare release 0.2-incubating
Posted by pl...@apache.org.
[maven-release-plugin] prepare release 0.2-incubating
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/da4748f4
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/tree/da4748f4
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/diff/da4748f4
Branch: refs/heads/master
Commit: da4748f47ab995da3f91cd7c0174d8cdd87694e6
Parents: d5a45e7
Author: anatole <an...@apache.org>
Authored: Tue Mar 8 17:39:55 2016 +0100
Committer: anatole <an...@apache.org>
Committed: Tue Mar 8 17:39:55 2016 +0100
----------------------------------------------------------------------
pom.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/da4748f4/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index 32dc6b5..9202d80 100644
--- a/pom.xml
+++ b/pom.xml
@@ -23,7 +23,7 @@ under the License.
<parent>
<groupId>org.apache.tamaya.ext</groupId>
<artifactId>tamaya-extensions</artifactId>
- <version>0.2-incubating-SNAPSHOT</version>
+ <version>0.2-incubating</version>
</parent>
<artifactId>tamaya-builder</artifactId>