From 2bf96640d8f1f75f2163c85daf36e3d20508f0f6 Mon Sep 17 00:00:00 2001
From: Mark Struberg
Date: Wed, 20 Jul 2016 09:36:15 +0200
Subject: [PATCH 01/37] remove isScannable
---
api/src/main/java/javx/config/Config.java | 2 --
api/src/main/java/javx/config/spi/ConfigSource.java | 9 ---------
.../main/java/org/apache/geronimo/config/ConfigImpl.java | 4 +---
.../geronimo/config/configsource/BaseConfigSource.java | 4 ----
.../config/tck/configsources/CustomDbConfigSource.java | 5 -----
.../config/tck/configsources/SampleYamlConfigSource.java | 4 ----
6 files changed, 1 insertion(+), 27 deletions(-)
diff --git a/api/src/main/java/javx/config/Config.java b/api/src/main/java/javx/config/Config.java
index 080c437..f172b59 100644
--- a/api/src/main/java/javx/config/Config.java
+++ b/api/src/main/java/javx/config/Config.java
@@ -49,8 +49,6 @@ public interface Config {
* Returns a Map of all properties from all scannable config sources. The values of the properties reflect the
* values that would be obtained by a call to {@link #getValue(java.lang.String)}, that is, the value of the
* property from the ConfigSource with the highest ordinal.
- *
- * @see ConfigSource#isScannable()
*/
Map getAllProperties();
diff --git a/api/src/main/java/javx/config/spi/ConfigSource.java b/api/src/main/java/javx/config/spi/ConfigSource.java
index 8b00018..525df12 100644
--- a/api/src/main/java/javx/config/spi/ConfigSource.java
+++ b/api/src/main/java/javx/config/spi/ConfigSource.java
@@ -94,13 +94,4 @@ public interface ConfigSource {
*/
String getConfigName();
- /**
- * Determines if this config source should be scanned for its list of properties.
- *
- * Generally, slow ConfigSources should return {@code false} here.
- *
- * @return {@code true} if this ConfigSource should be scanned for its list of properties,
- * {@code false} if it should not be scanned.
- */
- boolean isScannable();
}
diff --git a/impl/src/main/java/org/apache/geronimo/config/ConfigImpl.java b/impl/src/main/java/org/apache/geronimo/config/ConfigImpl.java
index e501664..a585968 100644
--- a/impl/src/main/java/org/apache/geronimo/config/ConfigImpl.java
+++ b/impl/src/main/java/org/apache/geronimo/config/ConfigImpl.java
@@ -62,9 +62,7 @@ public Map getAllProperties() {
for (int i = configSources.length; i > 0; i--) {
ConfigSource configSource = configSources[i];
- if (configSource.isScannable()) {
- result.putAll(configSource.getProperties());
- }
+ result.putAll(configSource.getProperties());
}
// now filter them
diff --git a/impl/src/main/java/org/apache/geronimo/config/configsource/BaseConfigSource.java b/impl/src/main/java/org/apache/geronimo/config/configsource/BaseConfigSource.java
index c8c8da1..1f41c5f 100644
--- a/impl/src/main/java/org/apache/geronimo/config/configsource/BaseConfigSource.java
+++ b/impl/src/main/java/org/apache/geronimo/config/configsource/BaseConfigSource.java
@@ -63,8 +63,4 @@ protected void initOrdinal(int defaultOrdinal) {
}
}
- @Override
- public boolean isScannable() {
- return true;
- }
}
diff --git a/tck/src/main/java/org/apache/geronimo/config/tck/configsources/CustomDbConfigSource.java b/tck/src/main/java/org/apache/geronimo/config/tck/configsources/CustomDbConfigSource.java
index bd19640..9e2ec10 100644
--- a/tck/src/main/java/org/apache/geronimo/config/tck/configsources/CustomDbConfigSource.java
+++ b/tck/src/main/java/org/apache/geronimo/config/tck/configsources/CustomDbConfigSource.java
@@ -53,11 +53,6 @@ public String getConfigName() {
return "customDbConfig";
}
- @Override
- public boolean isScannable() {
- return true;
- }
-
private Map readPropertiesFromDb() {
return configValues;
}
diff --git a/tck/src/main/java/org/apache/geronimo/config/tck/configsources/SampleYamlConfigSource.java b/tck/src/main/java/org/apache/geronimo/config/tck/configsources/SampleYamlConfigSource.java
index 80fbf4a..34a196d 100644
--- a/tck/src/main/java/org/apache/geronimo/config/tck/configsources/SampleYamlConfigSource.java
+++ b/tck/src/main/java/org/apache/geronimo/config/tck/configsources/SampleYamlConfigSource.java
@@ -52,8 +52,4 @@ public String getConfigName() {
return null;
}
- @Override
- public boolean isScannable() {
- return false;
- }
}
From 90795e4ba314a727c17cf8b6d8f3c489eb8bdf57 Mon Sep 17 00:00:00 2001
From: Matt Benson
Date: Fri, 22 Jul 2016 10:08:50 -0500
Subject: [PATCH 02/37] Wording, punctuation, grammar recommendations
---
spec/src/main/asciidoc/architecture.asciidoc | 24 +++++------
spec/src/main/asciidoc/configfilters.asciidoc | 13 +++---
spec/src/main/asciidoc/configsources.asciidoc | 40 +++++++++----------
3 files changed, 37 insertions(+), 40 deletions(-)
diff --git a/spec/src/main/asciidoc/architecture.asciidoc b/spec/src/main/asciidoc/architecture.asciidoc
index cc1a15f..2f0af02 100644
--- a/spec/src/main/asciidoc/architecture.asciidoc
+++ b/spec/src/main/asciidoc/architecture.asciidoc
@@ -1,23 +1,23 @@
[[architecture]]
== Architecture
-This specification defines a easy to use and flexible system for application configuration.
+This specification defines an easy to use and flexible system for application configuration.
It also defines a way to extend the configuration mechanism itself via a SPI (Service Provider Interface).
=== Rational
-Released binaries often contain classes which need to behave slightly different depending on the deployment.
-This might be different REST endpoints to talk with depending on the customer at which a WAR gets deployed.
-Or it might even be different features which need to be switched on and off depending on the installation.
+Released binaries often contain classes which need to behave slightly differently depending on the deployment.
+This might be different REST endpoints to talk with depending on the customer for whom a WAR is deployed
+or might even be different features which need to be switched on and off depending on the installation.
All this must be possible without the need to re-package the whole application binary.
Java-config provides a way to achieve this goal by allowing the application to bundle default configuration within the application.
-But it also allows to overwrite them from outside, e.g. via an environment variable, a Java system property or even a database entry.
+It also allows to override the defaults from outside, e.g. via an environment variable, a Java system property or even a database entry.
=== Accessing a certain Configuration
The `ConfigProvider` is the central class to access a configuration.
-It must allow access to different configurations based on the application it gets used in.
+It must allow access to different configurations based on the application in which it is used.
We distinguish 3 different ways to resolve a `Config` instance:
* A factory method `ConfigProvider#getConfig()` to create a `Config` object based on automatically picked up `ConfigSource` s from the current Thread Context ClassLoader classpath.
@@ -28,15 +28,15 @@ We distinguish 3 different ways to resolve a `Config` instance:
E.g. if you need the Config for a class in a shared EAR lib folder.
Subsequent calls to this method for a certain ClassLoader will return the same `Config` instance.
-* A factory method `ConfigProvider#newConfig()` to to create an empty `Config` object which can be filled manually.
+* A factory method `ConfigProvider#newConfig()` to create an empty `Config` object which can be filled manually.
No automatic `ConfigSource` and `ConfigFilter` lookup will be performed.
This configuration instance will not be shared by the `ConfigProvider`.
- This method is intended be used if a IoT container or any other external Factory can be used to give access to a manualy created shared `Config`.
+ This method is intended be used if a IoT container or any other external Factory can be used to give access to a manually created shared `Config`.
All methods in the `ConfigProvider` and `Config` implementations are thread safe and reentrant.
-If a `Config` is bound to a ClassLoader ist must be made sure that it gets properly removed if the ClassLoader gets destroyed.
-It must not create any mem leaks in that case.
+If a `Config` is bound to a ClassLoader it must be made sure that it gets properly removed if the ClassLoader gets destroyed.
+It must not create any memory leaks in that case.
=== Configuration Lookup Mechanism Example
@@ -67,11 +67,11 @@ public class ConfigUsageSample {
}
----
-If you like to access a different server then you can e.g. change the configuration via a `-D` system property:
+If you need to access a different server then you can e.g. change the configuration via a `-D` system property:
[source, text]
----
$> java -jar some.jar -Dcom.acme.myproject.someserver.url=http://other.server/other/endpoint
----
-Note that the way to inject this configuration into the application can be extended by providing custom `ConfigSource` s.
\ No newline at end of file
+Note that the way to inject this configuration into the application can be extended by providing custom `ConfigSource` s.
diff --git a/spec/src/main/asciidoc/configfilters.asciidoc b/spec/src/main/asciidoc/configfilters.asciidoc
index f3dbde7..eb80c56 100644
--- a/spec/src/main/asciidoc/configfilters.asciidoc
+++ b/spec/src/main/asciidoc/configfilters.asciidoc
@@ -1,14 +1,13 @@
[[configfilters]]
== ConfigFilters
-A `ConfigFilter` allows to act as a valve which is able to modify the configured values before they get handed out to the caller.
+A `ConfigFilter` acts as a valve which is able to modify the configured values before they are returned to the caller.
-The spec does not require the implementations to ship with any `ConfigFilters` enabled by default.
+An implementation of the specification is not required to ship with any `ConfigFilters` enabled by default.
-A custom `ConfigFilter` must implement the interface `javx.config.spi.ConfigFilter`.
-You have to register your implementation in a file `/META-INF/services/javx.config.spi.ConfigFilter` by writing the fully qualified class name of the custom implementation into it.
+A custom `ConfigFilter` must implement the interface `javx.config.spi.ConfigFilter` and is typically registered in a classpath resource `/META-INF/services/javx.config.spi.ConfigFilter` by including the fully-qualified class name of the custom implementation (well-known Java SE `java.util.ServiceLoader` mechanism).
-Alternative to that a user can register a `ConfigFilter` manually via `void Config#addConfigFilter(ConfigFilter configFilterToAdd)`.
+Alternatively a user can register a `ConfigFilter` manually via `void Config#addConfigFilter(ConfigFilter configFilterToAdd)`.
=== Filtering a value for Usage
@@ -35,7 +34,7 @@ public class PasswordDecryptionConfigFilter implements ConfigFilter {
=== Filtering a value for Logging
-To prevent passwords and other secret information to be printed out or logged away, a `ConfigFilter` can be used to mask out those values.
+To prevent passwords and other secret information from being printed out or logged, a `ConfigFilter` can be used to mask those values.
[source, java]
----
@@ -56,4 +55,4 @@ public class PasswordConfigFilter implements ConfigFilter {
}
}
-----
\ No newline at end of file
+----
diff --git a/spec/src/main/asciidoc/configsources.asciidoc b/spec/src/main/asciidoc/configsources.asciidoc
index 1a283df..6adb9a8 100644
--- a/spec/src/main/asciidoc/configsources.asciidoc
+++ b/spec/src/main/asciidoc/configsources.asciidoc
@@ -2,18 +2,17 @@
== ConfigSources
A `ConfigSource` is exactly what its name says: a source for configured values.
-The `Config` uses all configured implementations of `ConfigSource` to lookup the property in question.
+The `Config` uses all configured implementations of `ConfigSource` to look up the property in question.
=== ConfigSource Ordering
-Each `ConfigSource` has a specified `ordinal`.
-This ordinal get’s used to determine the importance of the values taken from the very `ConfigSource`.
-A higher ordinal means that the values taken from this ConfigSource will override values from less important ConfigSources.
-This is the trick which allows to amend configuration from outside a binary - given those outside ConfigSources have a higher `ordinal` than the ones who pickup the values from within the release binaries.
+Each `ConfigSource` has a specified `ordinal`, which is used to determine the importance of the values taken from the associated `ConfigSource`.
+A higher `ordinal` means that the values taken from this `ConfigSource` will override values from lower-priority `ConfigSource` s.
+This allows a configuration to be customized from outside a binary, assuming that external `ConfigSource` s have higher `ordinal` values than the ones whose values originate within the release binaries.
It can also be used to implement a drop-in configuration approach.
-Simply create a jar containing a `ConfigSource` with a higher ordinal and overwrite configuration values in it.
-If the jar gets added to the classpath then it will overwrite the configuration from `ConfigSource` s with lower ordinal.
+Simply create a jar containing a `ConfigSource` with a higher ordinal and override configuration values in it.
+If the jar is present on the classpath then it will override configuration values from `ConfigSource` s with lower `ordinal` values.
The ordinal for property file based `ConfigSource` s can be configured using the key `config_ordinal` inside the property file.
@@ -29,13 +28,13 @@ A Java-config implementation must provide `ConfigSource` s for the following dat
* System properties (ordinal=400)
* Environment properties (ordinal=300)
-* An own `ConfigSource` for each property file `META-INF/java-config.properties` found on the classpath. (default ordinal = 100)
+* A `ConfigSource` for each property file `META-INF/java-config.properties` found on the classpath. (default ordinal = 100)
=== Custom ConfigSources
-ConfigSources are picked up using the `java.util.ServiceLoader` mechanism.
+`ConfigSource` s are discovered using the `java.util.ServiceLoader` mechanism.
-To add a custom `ConfigSource`, you have to implement the interface `javx.config.spi.ConfigSource`.
+To add a custom `ConfigSource`, implement the interface `javx.config.spi.ConfigSource`.
[source, java]
----
@@ -71,19 +70,19 @@ public class CustomDbConfigSource implements ConfigSource {
----
-Then register your implementation in a file `/META-INF/services/javx.config.spi.ConfigSource` by writing the fully qualified class name of the custom implementation into it.
+Then register your implementation in a resource file `/META-INF/services/javx.config.spi.ConfigSource` by including the fully-qualified class name of the custom implementation in the file.
=== Custom ConfigSources via ConfigSourceProvider
-If you need dynamic ConfigSources you can also register a `ConfigSourceProvider` in a similar way.
-This is useful if you like to dynamically pick up multiple `ConfigSource` s of the same kind.
-For example, if you like to pick up all myproject.properties files from all the JARs in your classpath.
+If you need dynamic `ConfigSource` s you can also register a `ConfigSourceProvider` in a similar manner.
+This is useful if you are required to dynamically pick up multiple `ConfigSource` s of the same kind;
+for example, to pick up all `myproject.properties` resources from all the JARs in your classpath.
-A custom `ConfigSourceProvider` needs to implement the interface `javx.config.spi.ConfigSourceProvider`.
-Register your implementation in a file `/META-INF/services/javx.config.spi.ConfigSourceProvider` by writing the fully qualified class name of the custom implementation/s into it.
+A custom `ConfigSourceProvider` must implement the interface `javx.config.spi.ConfigSourceProvider`.
+Register your implementation in a resource file `/META-INF/services/javx.config.spi.ConfigSourceProvider` by including the fully-qualified class name of the custom implementation/s in the file.
-An example which registers all yaml files with the name `exampleconfig.yaml`:
+An example which registers all YAML files with the name `exampleconfig.yaml`:
[source, java]
----
@@ -126,13 +125,13 @@ public class CustomPropertyFileConfig implements PropertyFileConfig {
}
----
-Register your implementation in a file `/META-INF/services/javx.config.spi.PropertyFileConfig` by writing the fully qualified class name of your `PropertyFileConfig` into it.
+Register your implementation in a resource file `/META-INF/services/javx.config.spi.PropertyFileConfig` by including the fully-qualified class name of your `PropertyFileConfig` in the file.
=== ConfigSource and Mutable Data
A `Config` instance provides no caching but iterates over all `ConfigSources` for each `getValue(String)` operation.
-A ConfigSource is allowed to cache the underlying values itself.
+A `ConfigSource` is allowed to cache the underlying values itself.
=== Manually adding ConfigSources
@@ -140,5 +139,4 @@ A ConfigSource is allowed to cache the underlying values itself.
A user can manually register `ConfigSource` s by using the method `void addConfigSources(List configSourcesToAdd)`.
This will add the given list to the already registered `ConfigSources` of the current `Config` instance.
-The order in which the `ConfigSources` get evaluates when using `Config#getValue(String key)` is independent from the order in which they got added to the `Config`.
-It is only depending on the `ordinal` of the `ConfigSources`.
\ No newline at end of file
+The order in which the `ConfigSources` are evaluated when using `Config#getValue(String key)` is independent of the order in which they were added to the `Config`; this depends only on the `ordinal` values of the available `ConfigSources`.
From cabad1d99640c6e4f1aab6126442a44fee39d3f4 Mon Sep 17 00:00:00 2001
From: Mark Struberg
Date: Mon, 25 Jul 2016 07:48:31 +0200
Subject: [PATCH 03/37] enable travisCi on github
---
.travis.yml | 1 +
1 file changed, 1 insertion(+)
create mode 100644 .travis.yml
diff --git a/.travis.yml b/.travis.yml
new file mode 100644
index 0000000..dff5f3a
--- /dev/null
+++ b/.travis.yml
@@ -0,0 +1 @@
+language: java
From 879a084b91d86524b1b88126b6bc69ff36592e18 Mon Sep 17 00:00:00 2001
From: Mark Struberg
Date: Mon, 25 Jul 2016 15:24:22 +0200
Subject: [PATCH 04/37] remove PropertyFileConfigSource
because it can be implemented easily in userland anyway.
---
.../javx/config/spi/PropertyFileConfig.java | 67 -------------------
.../config/DefaultConfigProvider.java | 12 ----
spec/src/main/asciidoc/configsources.asciidoc | 23 -------
.../tck/PropertyFileConfigSourceTest.java | 39 -----------
.../CustomPropertyFileConfig.java | 34 ----------
.../javx.config.spi.PropertyFileConfig | 1 -
tck/src/main/resources/some/custom.properties | 7 --
7 files changed, 183 deletions(-)
delete mode 100644 api/src/main/java/javx/config/spi/PropertyFileConfig.java
delete mode 100644 tck/src/main/java/org/apache/geronimo/config/tck/PropertyFileConfigSourceTest.java
delete mode 100644 tck/src/main/java/org/apache/geronimo/config/tck/configsources/CustomPropertyFileConfig.java
delete mode 100644 tck/src/main/resources/META-INF/services/javx.config.spi.PropertyFileConfig
delete mode 100644 tck/src/main/resources/some/custom.properties
diff --git a/api/src/main/java/javx/config/spi/PropertyFileConfig.java b/api/src/main/java/javx/config/spi/PropertyFileConfig.java
deleted file mode 100644
index 2fdf996..0000000
--- a/api/src/main/java/javx/config/spi/PropertyFileConfig.java
+++ /dev/null
@@ -1,67 +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 javx.config.spi;
-
-/**
- *
- * If you implement this interface, the property files with the given file name will be registered as
- * {@link ConfigSource}s.
- *
- **
- *
Automatic pickup via {@code java.util.ServiceLoader} mechanism
- *
You need to register the PropertyFileConfig via the {@code java.util.ServiceLoader} mechanism.
- *
- *
The {@code ServiceLoader} mechanism requires to have a file
- *
- *
- */
-public interface PropertyFileConfig
-{
- /**
- * All the property files on the classpath which have this name will get picked up and registered as
- * {@link ConfigSource}s.
- *
- * @return the full file name (including path) of the property files to pick up.
- */
- String getPropertyFileName();
-
- /**
- * @return true if the file is optional, false if the specified file has to be in place.
- */
- boolean isOptional();
-}
diff --git a/impl/src/main/java/org/apache/geronimo/config/DefaultConfigProvider.java b/impl/src/main/java/org/apache/geronimo/config/DefaultConfigProvider.java
index bd4a5cd..42227bf 100644
--- a/impl/src/main/java/org/apache/geronimo/config/DefaultConfigProvider.java
+++ b/impl/src/main/java/org/apache/geronimo/config/DefaultConfigProvider.java
@@ -30,7 +30,6 @@
import javx.config.spi.ConfigFilter;
import javx.config.spi.ConfigSource;
import javx.config.spi.ConfigSourceProvider;
-import javx.config.spi.PropertyFileConfig;
import org.apache.geronimo.config.configsource.PropertyFileConfigSourceProvider;
import org.apache.geronimo.config.configsource.SystemEnvConfigSource;
@@ -110,17 +109,6 @@ protected Collection extends ConfigSource> getBuiltInConfigSources(ClassLoader
configSources.add(new SystemEnvConfigSource());
configSources.add(new SystemPropertyConfigSource());
configSources.addAll(new PropertyFileConfigSourceProvider("META-INF/java-config.properties", true, forClassLoader).getConfigSources(forClassLoader));
- configSources.addAll(getCustomPropertyFiles(forClassLoader));
-
- return configSources;
- }
-
- private Collection extends ConfigSource> getCustomPropertyFiles(ClassLoader forClassLoader) {
- List configSources = new ArrayList<>();
- ServiceLoader propertyFileConfigLoader = ServiceLoader.load(PropertyFileConfig.class);
- for (PropertyFileConfig propConfig : propertyFileConfigLoader) {
- configSources.addAll(new PropertyFileConfigSourceProvider(propConfig.getPropertyFileName(), propConfig.isOptional(), forClassLoader).getConfigSources(forClassLoader));
- }
return configSources;
}
diff --git a/spec/src/main/asciidoc/configsources.asciidoc b/spec/src/main/asciidoc/configsources.asciidoc
index 6adb9a8..32a849c 100644
--- a/spec/src/main/asciidoc/configsources.asciidoc
+++ b/spec/src/main/asciidoc/configsources.asciidoc
@@ -105,29 +105,6 @@ public class ExampleYamlConfigSourceProvider
Please note that a single `ConfigSource` should be either registered directly or via a `ConfigSourceProvider`, but never both ways.
-=== PropertyFileConfig
-
-You can also make Java-config pick up property files with a custom name as `ConfigSource` s.
-The following example will pick up all property files with the name `some/custom.properties` from the classpath.
-
-[source, java]
-----
-public class CustomPropertyFileConfig implements PropertyFileConfig {
- @Override
- public String getPropertyFileName() {
- return "some/custom.properties";
- }
-
- @Override
- public boolean isOptional() {
- return false;
- }
-}
-----
-
-Register your implementation in a resource file `/META-INF/services/javx.config.spi.PropertyFileConfig` by including the fully-qualified class name of your `PropertyFileConfig` in the file.
-
-
=== ConfigSource and Mutable Data
A `Config` instance provides no caching but iterates over all `ConfigSources` for each `getValue(String)` operation.
diff --git a/tck/src/main/java/org/apache/geronimo/config/tck/PropertyFileConfigSourceTest.java b/tck/src/main/java/org/apache/geronimo/config/tck/PropertyFileConfigSourceTest.java
deleted file mode 100644
index 229e42b..0000000
--- a/tck/src/main/java/org/apache/geronimo/config/tck/PropertyFileConfigSourceTest.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.geronimo.config.tck;
-
-import javx.config.Config;
-import javx.config.ConfigProvider;
-import org.testng.Assert;
-import org.testng.annotations.Test;
-
-/**
- * @author Mark Struberg
- */
-public class PropertyFileConfigSourceTest {
- @Test
- public void testCustomPropertyFilesConfigSource() {
- Config config = ConfigProvider.getConfig();
- Assert.assertEquals(config.getValue("tck.config.test.propertyfileconfig.custom.key1"), "value1");
- }
-
- @Test
- public void testPropertyOverwrite() {
- Config config = ConfigProvider.getConfig();
- Assert.assertEquals(config.getValue("tck.config.test.overwritten.in.custompropertyfile.key1"), "value from some/custom.properties");
- }
-}
\ No newline at end of file
diff --git a/tck/src/main/java/org/apache/geronimo/config/tck/configsources/CustomPropertyFileConfig.java b/tck/src/main/java/org/apache/geronimo/config/tck/configsources/CustomPropertyFileConfig.java
deleted file mode 100644
index f7589ad..0000000
--- a/tck/src/main/java/org/apache/geronimo/config/tck/configsources/CustomPropertyFileConfig.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.geronimo.config.tck.configsources;
-
-import javx.config.spi.PropertyFileConfig;
-
-/**
- * @author Mark Struberg
- */
-public class CustomPropertyFileConfig implements PropertyFileConfig {
- @Override
- public String getPropertyFileName() {
- return "some/custom.properties";
- }
-
- @Override
- public boolean isOptional() {
- return false;
- }
-}
diff --git a/tck/src/main/resources/META-INF/services/javx.config.spi.PropertyFileConfig b/tck/src/main/resources/META-INF/services/javx.config.spi.PropertyFileConfig
deleted file mode 100644
index 20aa208..0000000
--- a/tck/src/main/resources/META-INF/services/javx.config.spi.PropertyFileConfig
+++ /dev/null
@@ -1 +0,0 @@
-org.apache.geronimo.config.tck.configsources.CustomPropertyFileConfig
\ No newline at end of file
diff --git a/tck/src/main/resources/some/custom.properties b/tck/src/main/resources/some/custom.properties
deleted file mode 100644
index 739ec20..0000000
--- a/tck/src/main/resources/some/custom.properties
+++ /dev/null
@@ -1,7 +0,0 @@
-# a bit higher than the default, to guarantee overwriting values from java-config.properties
-config_ordinal = 110
-
-tck.config.test.propertyfileconfig.custom.key1=value1
-
-
-tck.config.test.overwritten.in.custompropertyfile.key1=value from some/custom.properties
\ No newline at end of file
From c8525998a43fe798f367bcdba9006fc8984f4cb9 Mon Sep 17 00:00:00 2001
From: Mark Struberg
Date: Wed, 27 Jul 2016 10:44:23 +0200
Subject: [PATCH 05/37] incorporate ConfigBuilder idea from rmannibucau
Manually merged over from branch romain-proposal.
---
api/src/main/java/javx/config/Config.java | 18 ---
.../main/java/javx/config/ConfigProvider.java | 18 ++-
.../apache/geronimo/config/ConfigImpl.java | 2 -
.../geronimo/config/DefaultConfigBuilder.java | 115 ++++++++++++++++++
.../config/DefaultConfigProvider.java | 67 +++-------
spec/pom.xml | 2 +-
...spec.asciidoc => javaconfig-spec.asciidoc} | 0
.../config/tck/ConfigProviderTest.java | 15 +++
8 files changed, 163 insertions(+), 74 deletions(-)
create mode 100644 impl/src/main/java/org/apache/geronimo/config/DefaultConfigBuilder.java
rename spec/src/main/asciidoc/{config-spec.asciidoc => javaconfig-spec.asciidoc} (100%)
diff --git a/api/src/main/java/javx/config/Config.java b/api/src/main/java/javx/config/Config.java
index f172b59..3ecf33d 100644
--- a/api/src/main/java/javx/config/Config.java
+++ b/api/src/main/java/javx/config/Config.java
@@ -16,10 +16,8 @@
*/
package javx.config;
-import java.util.List;
import java.util.Map;
-import javx.config.spi.ConfigFilter;
import javx.config.spi.ConfigSource;
import javx.config.spi.ConfigSourceProvider;
@@ -71,20 +69,4 @@ public interface Config {
*/
ConfigSource[] getConfigSources();
-
- /**
- * This method can be used for programmatically adding {@link ConfigSource}s
- * to this very Config.
- * It is not needed for normal 'usage' by end users, but only for Extension Developers!
- *
- * @param configSourcesToAdd the ConfigSources to add
- */
- void addConfigSources(List configSourcesToAdd);
-
- /**
- * Add a {@link ConfigFilter} to this very Config
- *
- * It is not needed for normal 'usage' by end users, but only for Extension Developers!
- */
- void addConfigFilter(ConfigFilter configFilterToAdd);
}
diff --git a/api/src/main/java/javx/config/ConfigProvider.java b/api/src/main/java/javx/config/ConfigProvider.java
index 9962096..22aaeca 100644
--- a/api/src/main/java/javx/config/ConfigProvider.java
+++ b/api/src/main/java/javx/config/ConfigProvider.java
@@ -43,6 +43,7 @@
* from a database table./p>
*
* @author Mark Struberg
+ * @author Romain Manni-Bucau
*/
public class ConfigProvider {
@@ -76,7 +77,7 @@ public static Config getConfig(ClassLoader forClassLoader) {
*
* The ConfigProvider will not manage the Config instance internally
*/
- public static Config newConfig() {
+ public static ConfigBuilder newConfig() {
return instance.newConfig();
}
@@ -89,6 +90,19 @@ public static void releaseConfig(Config config) {
}
+ /**
+ * Builder for manually creating an instance of a {@code Config}.
+ *
+ * @see ConfigProvider#newConfig()
+ */
+ public interface ConfigBuilder {
+ ConfigBuilder ignoreDefaultSources();
+ ConfigBuilder forClassLoader(ClassLoader loader);
+ ConfigBuilder withSources(ConfigSource... sources);
+ ConfigBuilder withFilters(ConfigFilter... filters);
+ Config build();
+ }
+
/**
* This interface gets implemented internally by the Config library.
* The implementation registers itself via {@link java.util.ServiceLoader} mechanism.
@@ -96,7 +110,7 @@ public static void releaseConfig(Config config) {
public interface SPI {
Config getConfig();
Config getConfig(ClassLoader forClassLoader);
- Config newConfig();
+ ConfigBuilder newConfig();
void releaseConfig(Config config);
}
diff --git a/impl/src/main/java/org/apache/geronimo/config/ConfigImpl.java b/impl/src/main/java/org/apache/geronimo/config/ConfigImpl.java
index a585968..c9b78f4 100644
--- a/impl/src/main/java/org/apache/geronimo/config/ConfigImpl.java
+++ b/impl/src/main/java/org/apache/geronimo/config/ConfigImpl.java
@@ -99,7 +99,6 @@ public ConfigSource[] getConfigSources() {
return configSources;
}
- @Override
public synchronized void addConfigSources(List configSourcesToAdd) {
List allConfigSources = new ArrayList<>(Arrays.asList(configSources));
allConfigSources.addAll(configSourcesToAdd);
@@ -108,7 +107,6 @@ public synchronized void addConfigSources(List configSourcesToAdd)
configSources = sortDescending(allConfigSources);
}
- @Override
public synchronized void addConfigFilter(ConfigFilter configFilter) {
configFilters.add(configFilter);
diff --git a/impl/src/main/java/org/apache/geronimo/config/DefaultConfigBuilder.java b/impl/src/main/java/org/apache/geronimo/config/DefaultConfigBuilder.java
new file mode 100644
index 0000000..e70c59b
--- /dev/null
+++ b/impl/src/main/java/org/apache/geronimo/config/DefaultConfigBuilder.java
@@ -0,0 +1,115 @@
+/*
+ * 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.geronimo.config;
+
+import javx.config.Config;
+import javx.config.ConfigProvider;
+import javx.config.spi.ConfigFilter;
+import javx.config.spi.ConfigSource;
+import javx.config.spi.ConfigSourceProvider;
+import org.apache.geronimo.config.configsource.PropertyFileConfigSourceProvider;
+import org.apache.geronimo.config.configsource.SystemEnvConfigSource;
+import org.apache.geronimo.config.configsource.SystemPropertyConfigSource;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+import java.util.ServiceLoader;
+
+import static java.util.Arrays.asList;
+
+/**
+ * @author Romain Manni-Bucau
+ * @author Mark Struberg
+ */
+public class DefaultConfigBuilder implements ConfigProvider.ConfigBuilder {
+ private ClassLoader forClassLoader;
+ private final List sources = new ArrayList<>();
+ private final List filters = new ArrayList<>();
+ private boolean ignoreDefaultSources = false;
+
+ @Override
+ public ConfigProvider.ConfigBuilder ignoreDefaultSources() {
+ this.ignoreDefaultSources = true;
+ return this;
+ }
+
+ @Override
+ public ConfigProvider.ConfigBuilder forClassLoader(final ClassLoader loader) {
+ this.forClassLoader = loader;
+ return this;
+ }
+
+ @Override
+ public ConfigProvider.ConfigBuilder withSources(final ConfigSource... sources) {
+ this.sources.addAll(asList(sources));
+ return this;
+ }
+
+ @Override
+ public ConfigProvider.ConfigBuilder withFilters(final ConfigFilter... filters) {
+ this.filters.addAll(asList(filters));
+ return this;
+ }
+
+ @Override
+ public Config build() {
+ List configSources = new ArrayList<>();
+
+ configSources.addAll(getBuiltInConfigSources(forClassLoader));
+ configSources.addAll(sources);
+
+ if (!ignoreDefaultSources) {
+ // load all ConfigSource services
+ ServiceLoader configSourceLoader = ServiceLoader.load(ConfigSource.class, forClassLoader);
+ for (ConfigSource configSource : configSourceLoader) {
+ configSources.add(configSource);
+ }
+
+ // load all ConfigSources from ConfigSourceProviders
+ ServiceLoader configSourceProviderLoader = ServiceLoader.load(ConfigSourceProvider.class, forClassLoader);
+ for (ConfigSourceProvider configSourceProvider : configSourceProviderLoader) {
+ configSources.addAll(configSourceProvider.getConfigSources(forClassLoader));
+ }
+ }
+
+ ConfigImpl config = new ConfigImpl();
+ config.addConfigSources(configSources);
+
+ // also register all ConfigFilters
+ ServiceLoader configFilterLoader = ServiceLoader.load(ConfigFilter.class, forClassLoader);
+ for (ConfigFilter configFilter : configFilterLoader) {
+ config.addConfigFilter(configFilter);
+ }
+
+ for (ConfigFilter filter : filters) {
+ config.addConfigFilter(filter);
+ }
+
+ return config;
+ }
+
+ protected Collection extends ConfigSource> getBuiltInConfigSources(ClassLoader forClassLoader) {
+ List configSources = new ArrayList<>();
+
+ configSources.add(new SystemEnvConfigSource());
+ configSources.add(new SystemPropertyConfigSource());
+ configSources.addAll(new PropertyFileConfigSourceProvider("META-INF/java-config.properties", true, forClassLoader).getConfigSources(forClassLoader));
+
+ return configSources;
+ }
+}
diff --git a/impl/src/main/java/org/apache/geronimo/config/DefaultConfigProvider.java b/impl/src/main/java/org/apache/geronimo/config/DefaultConfigProvider.java
index 42227bf..388624e 100644
--- a/impl/src/main/java/org/apache/geronimo/config/DefaultConfigProvider.java
+++ b/impl/src/main/java/org/apache/geronimo/config/DefaultConfigProvider.java
@@ -17,23 +17,12 @@
package org.apache.geronimo.config;
import java.lang.ref.WeakReference;
-import java.util.ArrayList;
-import java.util.Collection;
import java.util.Collections;
-import java.util.List;
+import java.util.Iterator;
import java.util.Map;
-import java.util.ServiceLoader;
import java.util.WeakHashMap;
-
import javx.config.Config;
import javx.config.ConfigProvider;
-import javx.config.spi.ConfigFilter;
-import javx.config.spi.ConfigSource;
-import javx.config.spi.ConfigSourceProvider;
-
-import org.apache.geronimo.config.configsource.PropertyFileConfigSourceProvider;
-import org.apache.geronimo.config.configsource.SystemEnvConfigSource;
-import org.apache.geronimo.config.configsource.SystemPropertyConfigSource;
/**
@@ -75,42 +64,7 @@ private Config existingConfig(ClassLoader forClassLoader) {
}
protected Config createConfig(ClassLoader forClassLoader) {
- List configSources = new ArrayList<>();
-
- configSources.addAll(getBuiltInConfigSources(forClassLoader));
-
- // load all ConfigSource services
- ServiceLoader configSourceLoader = ServiceLoader.load(ConfigSource.class, forClassLoader);
- for (ConfigSource configSource : configSourceLoader) {
- configSources.add(configSource);
- }
-
- // load all ConfigSources from ConfigSourceProviders
- ServiceLoader configSourceProviderLoader = ServiceLoader.load(ConfigSourceProvider.class, forClassLoader);
- for (ConfigSourceProvider configSourceProvider : configSourceProviderLoader) {
- configSources.addAll(configSourceProvider.getConfigSources(forClassLoader));
- }
-
- ConfigImpl config = new ConfigImpl();
- config.addConfigSources(configSources);
-
- // also register all ConfigFilters
- ServiceLoader configFilterLoader = ServiceLoader.load(ConfigFilter.class, forClassLoader);
- for (ConfigFilter configFilter : configFilterLoader) {
- config.addConfigFilter(configFilter);
- }
-
- return config;
- }
-
- protected Collection extends ConfigSource> getBuiltInConfigSources(ClassLoader forClassLoader) {
- List configSources = new ArrayList<>();
-
- configSources.add(new SystemEnvConfigSource());
- configSources.add(new SystemPropertyConfigSource());
- configSources.addAll(new PropertyFileConfigSourceProvider("META-INF/java-config.properties", true, forClassLoader).getConfigSources(forClassLoader));
-
- return configSources;
+ return newConfig().forClassLoader(forClassLoader).build();
}
private void registerConfig(Config config, ClassLoader forClassLoader) {
@@ -120,12 +74,23 @@ private void registerConfig(Config config, ClassLoader forClassLoader) {
}
@Override
- public Config newConfig() {
- return new ConfigImpl();
+ public ConfigProvider.ConfigBuilder newConfig() {
+ return new DefaultConfigBuilder();
}
@Override
public void releaseConfig(Config config) {
-
+ if (config != null) {
+ synchronized (DefaultConfigProvider.class) {
+ Iterator>> it = configs.entrySet().iterator();
+ while (it.hasNext()) {
+ Map.Entry> entry = it.next();
+ if (entry.getValue().get() != null && entry.getValue().get() == config) {
+ it.remove();
+ break;
+ }
+ }
+ }
+ }
}
}
diff --git a/spec/pom.xml b/spec/pom.xml
index b8a8c17..0a08c75 100644
--- a/spec/pom.xml
+++ b/spec/pom.xml
@@ -77,7 +77,7 @@
- config-spec.asciidoc
+ javaconfig-spec.asciidoccoderayApache License v2.0
diff --git a/spec/src/main/asciidoc/config-spec.asciidoc b/spec/src/main/asciidoc/javaconfig-spec.asciidoc
similarity index 100%
rename from spec/src/main/asciidoc/config-spec.asciidoc
rename to spec/src/main/asciidoc/javaconfig-spec.asciidoc
diff --git a/tck/src/main/java/org/apache/geronimo/config/tck/ConfigProviderTest.java b/tck/src/main/java/org/apache/geronimo/config/tck/ConfigProviderTest.java
index 7e21402..ec99dfe 100644
--- a/tck/src/main/java/org/apache/geronimo/config/tck/ConfigProviderTest.java
+++ b/tck/src/main/java/org/apache/geronimo/config/tck/ConfigProviderTest.java
@@ -90,4 +90,19 @@ public void testNonExistingConfigKey() {
Config config = ConfigProvider.getConfig();
Assert.assertNull(config.getValue("tck.config.test.keydoesnotexist"));
}
+
+
+ @Test
+ public void testConfigProviderRelease() {
+ Config config1 = ConfigProvider.getConfig();
+ Config config2 = ConfigProvider.getConfig();
+
+ Assert.assertEquals(config2, config1);
+
+ ConfigProvider.releaseConfig(config2);
+
+ Config config3 = ConfigProvider.getConfig();
+
+ Assert.assertNotEquals(config1, config3);
+ }
}
From cccc42b6c097fa5cb79a77aaee219ca4ea031da1 Mon Sep 17 00:00:00 2001
From: Mark Struberg
Date: Thu, 28 Jul 2016 17:09:46 +0200
Subject: [PATCH 06/37] add samples and cross references to JavaDocs
---
api/src/main/java/javx/config/Config.java | 3 +++
api/src/main/java/javx/config/ConfigProvider.java | 9 +++++++++
2 files changed, 12 insertions(+)
diff --git a/api/src/main/java/javx/config/Config.java b/api/src/main/java/javx/config/Config.java
index ab444ec..0f4380e 100644
--- a/api/src/main/java/javx/config/Config.java
+++ b/api/src/main/java/javx/config/Config.java
@@ -29,6 +29,9 @@
*
You can provide your own lookup paths by implementing and registering additional
* {@link ConfigSource}s and {@link ConfigSourceProvider} implementations.
*
+ *
+ * @see ConfigProvider to resolve the current configuration.
+ *
* @author Mark Struberg
*/
public interface Config {
diff --git a/api/src/main/java/javx/config/ConfigProvider.java b/api/src/main/java/javx/config/ConfigProvider.java
index 22aaeca..b3caf0c 100644
--- a/api/src/main/java/javx/config/ConfigProvider.java
+++ b/api/src/main/java/javx/config/ConfigProvider.java
@@ -42,6 +42,15 @@
* flexibly extend the configuration mechanism. An example would be to pick up configuration values
* from a database table./p>
*
+ *
+ *
+ *
+ *
* @author Mark Struberg
* @author Romain Manni-Bucau
*/
From 2c6ad25515bf42a10f3c69e9b9f723773e02af8c Mon Sep 17 00:00:00 2001
From: Mark Struberg
Date: Sat, 30 Jul 2016 23:22:32 +0200
Subject: [PATCH 07/37] add missing ASF headers + enhance spec wording
---
README.adoc | 17 +++++++++++
.../main/java/javx/config/spi/Converter.java | 18 +++++++++++
.../services/javx.config.ConfigProvider$SPI | 19 ++++++++++++
pom.xml | 21 ++++++++++++-
spec/pom.xml | 2 +-
spec/src/main/asciidoc/architecture.asciidoc | 30 +++++++++++++++----
spec/src/main/asciidoc/configfilters.asciidoc | 17 +++++++++++
spec/src/main/asciidoc/configsources.asciidoc | 17 +++++++++++
spec/src/main/asciidoc/converters.asciidoc | 17 +++++++++++
.../main/asciidoc/javaconfig-spec.asciidoc | 17 +++++++++++
spec/src/main/asciidoc/license-alv2.asciidoc | 17 +++++++++++
.../geronimo/config/tck/ConfigFilterTest.java | 16 ++++++++++
.../config/tck/ConfigSourceProviderTest.java | 16 ++++++++++
.../config/tck/CustomConfigSourceTest.java | 16 ++++++++++
.../resources/META-INF/java-config.properties | 20 +++++++++++++
.../services/javx.config.spi.ConfigFilter | 19 ++++++++++++
.../services/javx.config.spi.ConfigSource | 19 ++++++++++++
.../javx.config.spi.ConfigSourceProvider | 19 ++++++++++++
tck/src/main/resources/sampleconfig.yaml | 18 +++++++++++
19 files changed, 328 insertions(+), 7 deletions(-)
diff --git a/README.adoc b/README.adoc
index 30bd075..7d48664 100644
--- a/README.adoc
+++ b/README.adoc
@@ -1,3 +1,20 @@
+//
+// 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.
+//
+
# Configuration for Java SE and EE JSR
## Status
diff --git a/api/src/main/java/javx/config/spi/Converter.java b/api/src/main/java/javx/config/spi/Converter.java
index 9bac50c..07a86a5 100644
--- a/api/src/main/java/javx/config/spi/Converter.java
+++ b/api/src/main/java/javx/config/spi/Converter.java
@@ -1,3 +1,21 @@
+/*
+ * 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 javx.config.spi;
/**
diff --git a/impl/src/main/resources/META-INF/services/javx.config.ConfigProvider$SPI b/impl/src/main/resources/META-INF/services/javx.config.ConfigProvider$SPI
index c22654d..b3580b9 100644
--- a/impl/src/main/resources/META-INF/services/javx.config.ConfigProvider$SPI
+++ b/impl/src/main/resources/META-INF/services/javx.config.ConfigProvider$SPI
@@ -1 +1,20 @@
+#
+# 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.geronimo.config.DefaultConfigProvider
\ No newline at end of file
diff --git a/pom.xml b/pom.xml
index 63b79ce..51bc47d 100644
--- a/pom.xml
+++ b/pom.xml
@@ -23,7 +23,7 @@
org.apacheapache
- 17
+ 18org.apache.geronimo.config
@@ -46,4 +46,23 @@
implspec
+
+
+
+
+ org.apache.rat
+ apache-rat-plugin
+ 0.12
+
+
+ rat-check
+ check
+
+
+
+ .travis.yml
+
+
+
+
diff --git a/spec/pom.xml b/spec/pom.xml
index 0a08c75..756115a 100644
--- a/spec/pom.xml
+++ b/spec/pom.xml
@@ -35,7 +35,7 @@
1.5.31.5.0-alpha.10.1
- asl2
+ ALv2MMMM dd, yyyy${maven.build.timestamp}
diff --git a/spec/src/main/asciidoc/architecture.asciidoc b/spec/src/main/asciidoc/architecture.asciidoc
index 2f0af02..2f7cb7c 100644
--- a/spec/src/main/asciidoc/architecture.asciidoc
+++ b/spec/src/main/asciidoc/architecture.asciidoc
@@ -1,3 +1,20 @@
+//
+// 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.
+//
+
[[architecture]]
== Architecture
@@ -6,13 +23,15 @@ It also defines a way to extend the configuration mechanism itself via a SPI (Se
=== Rational
-Released binaries often contain classes which need to behave slightly differently depending on the deployment.
-This might be different REST endpoints to talk with depending on the customer for whom a WAR is deployed
-or might even be different features which need to be switched on and off depending on the installation.
+Released binaries often contain functionality which need to behave slightly differently depending on the deployment.
+This might be different REST endpoints to talk with (e.g. depending on the customer for whom a WAR is deployed).
+Or it might even be different features which need to be switched on and off depending on the installation.
All this must be possible without the need to re-package the whole application binary.
-Java-config provides a way to achieve this goal by allowing the application to bundle default configuration within the application.
-It also allows to override the defaults from outside, e.g. via an environment variable, a Java system property or even a database entry.
+Java-config provides a way to achieve this goal by aggregating configuration from many different sources and presents a single merged view to the user.
+This allows the application to bundle default configuration within the application.
+It also allows to override the defaults from outside, e.g. via an environment variable a Java system property.
+Java-config also allows to extend these configuration sources in a portable way, e.g. reading configuration values from a shared database in an application cluster.
=== Accessing a certain Configuration
@@ -41,6 +60,7 @@ It must not create any memory leaks in that case.
=== Configuration Lookup Mechanism Example
Java-config is a String/String based mechanism.
+Type-safety is provided by using the proper `Converter` before handing the value out to the caller.
The configuration key might use dot-separated namespaces similar to Java package namespacing:
diff --git a/spec/src/main/asciidoc/configfilters.asciidoc b/spec/src/main/asciidoc/configfilters.asciidoc
index eb80c56..631f618 100644
--- a/spec/src/main/asciidoc/configfilters.asciidoc
+++ b/spec/src/main/asciidoc/configfilters.asciidoc
@@ -1,3 +1,20 @@
+//
+// 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.
+//
+
[[configfilters]]
== ConfigFilters
diff --git a/spec/src/main/asciidoc/configsources.asciidoc b/spec/src/main/asciidoc/configsources.asciidoc
index 32a849c..cfc13db 100644
--- a/spec/src/main/asciidoc/configsources.asciidoc
+++ b/spec/src/main/asciidoc/configsources.asciidoc
@@ -1,3 +1,20 @@
+//
+// 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.
+//
+
[[configsources]]
== ConfigSources
diff --git a/spec/src/main/asciidoc/converters.asciidoc b/spec/src/main/asciidoc/converters.asciidoc
index 46317ab..e8e1010 100644
--- a/spec/src/main/asciidoc/converters.asciidoc
+++ b/spec/src/main/asciidoc/converters.asciidoc
@@ -1,3 +1,20 @@
+//
+// 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.
+//
+
[[converters]]
== Converters
diff --git a/spec/src/main/asciidoc/javaconfig-spec.asciidoc b/spec/src/main/asciidoc/javaconfig-spec.asciidoc
index 9640d3f..e2cb17a 100644
--- a/spec/src/main/asciidoc/javaconfig-spec.asciidoc
+++ b/spec/src/main/asciidoc/javaconfig-spec.asciidoc
@@ -1,3 +1,20 @@
+//
+// 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.
+//
+
= JSR XXX: Configuration for Java
:author: Mark Struberg
:email: struberg@apache.org
diff --git a/spec/src/main/asciidoc/license-alv2.asciidoc b/spec/src/main/asciidoc/license-alv2.asciidoc
index 1461ae1..9876e47 100644
--- a/spec/src/main/asciidoc/license-alv2.asciidoc
+++ b/spec/src/main/asciidoc/license-alv2.asciidoc
@@ -1,3 +1,20 @@
+//
+// 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.
+//
+
[subs="normal"]
....
diff --git a/tck/src/main/java/org/apache/geronimo/config/tck/ConfigFilterTest.java b/tck/src/main/java/org/apache/geronimo/config/tck/ConfigFilterTest.java
index 3bb7fc8..1c826b2 100644
--- a/tck/src/main/java/org/apache/geronimo/config/tck/ConfigFilterTest.java
+++ b/tck/src/main/java/org/apache/geronimo/config/tck/ConfigFilterTest.java
@@ -1,3 +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 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.geronimo.config.tck;
import javx.config.Config;
diff --git a/tck/src/main/java/org/apache/geronimo/config/tck/ConfigSourceProviderTest.java b/tck/src/main/java/org/apache/geronimo/config/tck/ConfigSourceProviderTest.java
index bf90fe8..f95dca2 100644
--- a/tck/src/main/java/org/apache/geronimo/config/tck/ConfigSourceProviderTest.java
+++ b/tck/src/main/java/org/apache/geronimo/config/tck/ConfigSourceProviderTest.java
@@ -1,3 +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 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.geronimo.config.tck;
import javx.config.Config;
diff --git a/tck/src/main/java/org/apache/geronimo/config/tck/CustomConfigSourceTest.java b/tck/src/main/java/org/apache/geronimo/config/tck/CustomConfigSourceTest.java
index abcb2a1..99e89a6 100644
--- a/tck/src/main/java/org/apache/geronimo/config/tck/CustomConfigSourceTest.java
+++ b/tck/src/main/java/org/apache/geronimo/config/tck/CustomConfigSourceTest.java
@@ -1,3 +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 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.geronimo.config.tck;
import javx.config.Config;
diff --git a/tck/src/main/resources/META-INF/java-config.properties b/tck/src/main/resources/META-INF/java-config.properties
index 02d6826..879c8ee 100644
--- a/tck/src/main/resources/META-INF/java-config.properties
+++ b/tck/src/main/resources/META-INF/java-config.properties
@@ -1,3 +1,23 @@
+#
+# 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.
+#
+
+
tck.config.test.javaconfig.properties.key1=VALue1
diff --git a/tck/src/main/resources/META-INF/services/javx.config.spi.ConfigFilter b/tck/src/main/resources/META-INF/services/javx.config.spi.ConfigFilter
index 7c75d4e..6aff602 100644
--- a/tck/src/main/resources/META-INF/services/javx.config.spi.ConfigFilter
+++ b/tck/src/main/resources/META-INF/services/javx.config.spi.ConfigFilter
@@ -1 +1,20 @@
+#
+# 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.geronimo.config.tck.configfilters.PasswordConfigFilter
\ No newline at end of file
diff --git a/tck/src/main/resources/META-INF/services/javx.config.spi.ConfigSource b/tck/src/main/resources/META-INF/services/javx.config.spi.ConfigSource
index 60f1da5..16d2f7b 100644
--- a/tck/src/main/resources/META-INF/services/javx.config.spi.ConfigSource
+++ b/tck/src/main/resources/META-INF/services/javx.config.spi.ConfigSource
@@ -1 +1,20 @@
+#
+# 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.geronimo.config.tck.configsources.CustomDbConfigSource
\ No newline at end of file
diff --git a/tck/src/main/resources/META-INF/services/javx.config.spi.ConfigSourceProvider b/tck/src/main/resources/META-INF/services/javx.config.spi.ConfigSourceProvider
index a3c6d8a..d2fc399 100644
--- a/tck/src/main/resources/META-INF/services/javx.config.spi.ConfigSourceProvider
+++ b/tck/src/main/resources/META-INF/services/javx.config.spi.ConfigSourceProvider
@@ -1 +1,20 @@
+#
+# 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.geronimo.config.tck.configsources.CustomConfigSourceProvider
\ No newline at end of file
diff --git a/tck/src/main/resources/sampleconfig.yaml b/tck/src/main/resources/sampleconfig.yaml
index 7769f0c..ee228a4 100644
--- a/tck/src/main/resources/sampleconfig.yaml
+++ b/tck/src/main/resources/sampleconfig.yaml
@@ -1,2 +1,20 @@
+#
+# 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.
+#
# just needed as a trigger for the ConfigSource pickup.
# Content is hardcoded in SampleYamlConfigSource
\ No newline at end of file
From cd42023ac5bfff5083b086524680815716087a1b Mon Sep 17 00:00:00 2001
From: Mark Struberg
Date: Sat, 30 Jul 2016 23:54:31 +0200
Subject: [PATCH 08/37] improve architecture overview
---
pom.xml | 4 ++-
spec/src/main/asciidoc/architecture.asciidoc | 25 ++++++++++++-------
spec/src/main/asciidoc/configsources.asciidoc | 5 ----
3 files changed, 19 insertions(+), 15 deletions(-)
diff --git a/pom.xml b/pom.xml
index 51bc47d..1ac5b48 100644
--- a/pom.xml
+++ b/pom.xml
@@ -60,7 +60,9 @@
- .travis.yml
+
+ .travis.yml
+
diff --git a/spec/src/main/asciidoc/architecture.asciidoc b/spec/src/main/asciidoc/architecture.asciidoc
index 2f7cb7c..e73dd3d 100644
--- a/spec/src/main/asciidoc/architecture.asciidoc
+++ b/spec/src/main/asciidoc/architecture.asciidoc
@@ -19,7 +19,7 @@
== Architecture
This specification defines an easy to use and flexible system for application configuration.
-It also defines a way to extend the configuration mechanism itself via a SPI (Service Provider Interface).
+It also defines a way to extend the configuration mechanism itself via a SPI (Service Provider Interface) in a portable way.
=== Rational
@@ -30,13 +30,13 @@ All this must be possible without the need to re-package the whole application b
Java-config provides a way to achieve this goal by aggregating configuration from many different sources and presents a single merged view to the user.
This allows the application to bundle default configuration within the application.
-It also allows to override the defaults from outside, e.g. via an environment variable a Java system property.
-Java-config also allows to extend these configuration sources in a portable way, e.g. reading configuration values from a shared database in an application cluster.
+It also allows to override the defaults from outside, e.g. via an environment variable a Java system property or via Docker.
+Java-config also allows to implement and register own configuration sources in a portable way, e.g. for reading configuration values from a shared database in an application cluster.
=== Accessing a certain Configuration
The `ConfigProvider` is the central class to access a configuration.
-It must allow access to different configurations based on the application in which it is used.
+It allows access to different configurations (represented by a `Config` instance) based on the application in which it is used.
We distinguish 3 different ways to resolve a `Config` instance:
* A factory method `ConfigProvider#getConfig()` to create a `Config` object based on automatically picked up `ConfigSource` s from the current Thread Context ClassLoader classpath.
@@ -47,8 +47,7 @@ We distinguish 3 different ways to resolve a `Config` instance:
E.g. if you need the Config for a class in a shared EAR lib folder.
Subsequent calls to this method for a certain ClassLoader will return the same `Config` instance.
-* A factory method `ConfigProvider#newConfig()` to create an empty `Config` object which can be filled manually.
- No automatic `ConfigSource` and `ConfigFilter` lookup will be performed.
+* A factory method `ConfigProvider#newConfig()` to create an empty `Config` object which can be filled manually via a builder.
This configuration instance will not be shared by the `ConfigProvider`.
This method is intended be used if a IoT container or any other external Factory can be used to give access to a manually created shared `Config`.
@@ -57,16 +56,22 @@ All methods in the `ConfigProvider` and `Config` implementations are thread safe
If a `Config` is bound to a ClassLoader it must be made sure that it gets properly removed if the ClassLoader gets destroyed.
It must not create any memory leaks in that case.
+A `Config` can be release by calling `ConfigProvider#release(Config)`.
+ConfigSources which implement the `java.io.Closeable` interface will be properly destroyed.
+Any subsequent call to `ConfigProvider#getConfig()` or `ConfigProvider#getConfig(ClassLoader forClassLoader)` will result in a new `Config` instance.
+
+
=== Configuration Lookup Mechanism Example
-Java-config is a String/String based mechanism.
-Type-safety is provided by using the proper `Converter` before handing the value out to the caller.
+The core Java-config mechanism is purely String/String based.
+Type-safety is only provided on top of that by using the proper `Converter` before handing the value out to the caller.
The configuration key might use dot-separated namespaces similar to Java package namespacing:
[source, text]
----
com.acme.myproject.someserver.url = http://some.server/some/endpoint
+com.acme.myproject.someserver.port = 9085
com.acme.myproject.someserver.active = true
com.acme.other.stuff.name = Karl
----
@@ -81,8 +86,10 @@ public class ConfigUsageSample {
// get access to the Config instance
Config config = ConfigProvider.getConfig();
String serverUrl = config.getValue("com.acme.myproject.someserver.url");
+ Integer serverPort = config.getValue("com.acme.myproject.someserver.port",
+ Integer.class);
- callToServer(serverUrl);
+ callToServer(serverUrl, serverPort);
}
}
----
diff --git a/spec/src/main/asciidoc/configsources.asciidoc b/spec/src/main/asciidoc/configsources.asciidoc
index cfc13db..f4f008e 100644
--- a/spec/src/main/asciidoc/configsources.asciidoc
+++ b/spec/src/main/asciidoc/configsources.asciidoc
@@ -77,11 +77,6 @@ public class CustomDbConfigSource implements ConfigSource {
return "customDbConfig";
}
- @Override
- public boolean isScannable() {
- return true;
- }
-
// + methods to read from the DB
}
From 7151304c6fe81593789a07d9f074371c41f3eaaa Mon Sep 17 00:00:00 2001
From: Mark Struberg
Date: Wed, 3 Aug 2016 22:59:13 +0200
Subject: [PATCH 09/37] adopt for microprofile
---
README.adoc | 7 ++++---
.../{javx => io/microprofile}/config/Config.java | 11 ++++++-----
.../microprofile}/config/ConfigProvider.java | 6 +++---
.../microprofile}/config/spi/ConfigFilter.java | 4 ++--
.../microprofile}/config/spi/ConfigSource.java | 2 +-
.../config/spi/ConfigSourceProvider.java | 2 +-
.../microprofile}/config/spi/Converter.java | 2 +-
.../java/org/apache/geronimo/config/ConfigImpl.java | 8 ++++----
.../apache/geronimo/config/DefaultConfigBuilder.java | 10 +++++-----
.../geronimo/config/DefaultConfigProvider.java | 4 ++--
.../config/configsource/BaseConfigSource.java | 2 +-
.../PropertyFileConfigSourceProvider.java | 4 ++--
.../config/configsource/SystemEnvConfigSource.java | 2 +-
.../configsource/SystemPropertyConfigSource.java | 2 +-
.../geronimo/config/converters/BooleanConverter.java | 2 +-
.../geronimo/config/converters/DoubleConverter.java | 2 +-
.../geronimo/config/converters/FloatConverter.java | 2 +-
.../geronimo/config/converters/IntegerConverter.java | 2 +-
.../geronimo/config/converters/LongConverter.java | 2 +-
...SPI => io.microprofile.config.ConfigProvider$SPI} | 0
spec/pom.xml | 2 +-
spec/src/main/asciidoc/architecture.asciidoc | 6 +++---
spec/src/main/asciidoc/configfilters.asciidoc | 2 +-
spec/src/main/asciidoc/configsources.asciidoc | 12 ++++++------
spec/src/main/asciidoc/converters.asciidoc | 8 +++++---
...ec.asciidoc => microprofile-config-spec.asciidoc} | 2 +-
.../apache/geronimo/config/tck/ConfigFilterTest.java | 4 ++--
.../geronimo/config/tck/ConfigProviderTest.java | 4 ++--
.../config/tck/ConfigSourceProviderTest.java | 4 ++--
.../apache/geronimo/config/tck/ConverterTest.java | 4 ++--
.../geronimo/config/tck/CustomConfigSourceTest.java | 4 ++--
.../tck/configfilters/PasswordConfigFilter.java | 2 +-
.../configsources/CustomConfigSourceProvider.java | 4 ++--
.../tck/configsources/CustomDbConfigSource.java | 2 +-
.../tck/configsources/SampleYamlConfigSource.java | 2 +-
.../config/tck/converters/DuckConverter.java | 2 +-
...ilter => io.microprofile.config.spi.ConfigFilter} | 0
...ource => io.microprofile.config.spi.ConfigSource} | 0
... io.microprofile.config.spi.ConfigSourceProvider} | 0
39 files changed, 72 insertions(+), 68 deletions(-)
rename api/src/main/java/{javx => io/microprofile}/config/Config.java (92%)
rename api/src/main/java/{javx => io/microprofile}/config/ConfigProvider.java (97%)
rename api/src/main/java/{javx => io/microprofile}/config/spi/ConfigFilter.java (96%)
rename api/src/main/java/{javx => io/microprofile}/config/spi/ConfigSource.java (99%)
rename api/src/main/java/{javx => io/microprofile}/config/spi/ConfigSourceProvider.java (98%)
rename api/src/main/java/{javx => io/microprofile}/config/spi/Converter.java (98%)
rename impl/src/main/resources/META-INF/services/{javx.config.ConfigProvider$SPI => io.microprofile.config.ConfigProvider$SPI} (100%)
rename spec/src/main/asciidoc/{javaconfig-spec.asciidoc => microprofile-config-spec.asciidoc} (97%)
rename tck/src/main/resources/META-INF/services/{javx.config.spi.ConfigFilter => io.microprofile.config.spi.ConfigFilter} (100%)
rename tck/src/main/resources/META-INF/services/{javx.config.spi.ConfigSource => io.microprofile.config.spi.ConfigSource} (100%)
rename tck/src/main/resources/META-INF/services/{javx.config.spi.ConfigSourceProvider => io.microprofile.config.spi.ConfigSourceProvider} (100%)
diff --git a/README.adoc b/README.adoc
index 7d48664..63fb9be 100644
--- a/README.adoc
+++ b/README.adoc
@@ -15,11 +15,11 @@
// limitations under the License.
//
-# Configuration for Java SE and EE JSR
+# Configuration for Java SE and EE
## Status
-JSR proposal!
+Microprofile proposal!
== Rational
@@ -35,6 +35,7 @@ But be able to overwrite those default values from external.
This very configuration approach has it's roots in the Apache OpenWebBeans internal SPI configuration.
In 2010 it got moved over to the Apache MyFaces CODI project and enhanced to also fit the need of customer projects by Gerhard Petracek and Mark Struberg.
In 2012 we further enhanced it while moving CODI to the Apache DeltaSpike project.
+Romain Manni-Bucau (Apache/Tomitribe), Ron Smeral (JBoss) and Anatole Tresch also gave appreciated input in the last years.
== How it works
@@ -60,4 +61,4 @@ An example would be a ConfigSource which gets the configured values from a share
`$> mvn clean install`
-After that the specification PDF can be found in `spec/target/generated-docs/config-spec.pdf`
\ No newline at end of file
+After that the specification PDF can be found in `spec/target/generated-docs/microprofile-config-spec.pdf`
\ No newline at end of file
diff --git a/api/src/main/java/javx/config/Config.java b/api/src/main/java/io/microprofile/config/Config.java
similarity index 92%
rename from api/src/main/java/javx/config/Config.java
rename to api/src/main/java/io/microprofile/config/Config.java
index 0f4380e..f7b0b1f 100644
--- a/api/src/main/java/javx/config/Config.java
+++ b/api/src/main/java/io/microprofile/config/Config.java
@@ -14,12 +14,13 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package javx.config;
+package io.microprofile.config;
import java.util.Map;
-import javx.config.spi.ConfigSource;
-import javx.config.spi.ConfigSourceProvider;
+import io.microprofile.config.spi.ConfigSourceProvider;
+import io.microprofile.config.spi.Converter;
+import io.microprofile.config.spi.ConfigSource;
/**
*
Resolves configured values of properties by going through the list
@@ -53,14 +54,14 @@ public interface Config {
* @param asType Also support parameterized Types?
* @param
* @return
- * @throws UnsupportedOperationException if there is no {@link javx.config.spi.Converter} registered for asType
+ * @throws UnsupportedOperationException if there is no {@link Converter} registered for asType
*/
T getValue(String key, Class asType);
/**
* Apply the
* @return the String converted
- * @throws UnsupportedOperationException if there is no {@link javx.config.spi.Converter} registered for asType
+ * @throws UnsupportedOperationException if there is no {@link Converter} registered for asType
*/
T convert(String value, Class asType);
diff --git a/api/src/main/java/javx/config/ConfigProvider.java b/api/src/main/java/io/microprofile/config/ConfigProvider.java
similarity index 97%
rename from api/src/main/java/javx/config/ConfigProvider.java
rename to api/src/main/java/io/microprofile/config/ConfigProvider.java
index b3caf0c..d693a06 100644
--- a/api/src/main/java/javx/config/ConfigProvider.java
+++ b/api/src/main/java/io/microprofile/config/ConfigProvider.java
@@ -14,13 +14,13 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package javx.config;
+package io.microprofile.config;
import java.util.ServiceLoader;
import java.util.logging.Logger;
-import javx.config.spi.ConfigFilter;
-import javx.config.spi.ConfigSource;
+import io.microprofile.config.spi.ConfigFilter;
+import io.microprofile.config.spi.ConfigSource;
/**
*
This is the central class to access a {@link Config}.
diff --git a/api/src/main/java/javx/config/spi/ConfigFilter.java b/api/src/main/java/io/microprofile/config/spi/ConfigFilter.java
similarity index 96%
rename from api/src/main/java/javx/config/spi/ConfigFilter.java
rename to api/src/main/java/io/microprofile/config/spi/ConfigFilter.java
index 0e01b51..f327778 100644
--- a/api/src/main/java/javx/config/spi/ConfigFilter.java
+++ b/api/src/main/java/io/microprofile/config/spi/ConfigFilter.java
@@ -16,9 +16,9 @@
* specific language governing permissions and limitations
* under the License.
*/
-package javx.config.spi;
+package io.microprofile.config.spi;
-import javx.config.Config;
+import io.microprofile.config.Config;
/**
*
A filter which can be added to the
diff --git a/api/src/main/java/javx/config/spi/ConfigSource.java b/api/src/main/java/io/microprofile/config/spi/ConfigSource.java
similarity index 99%
rename from api/src/main/java/javx/config/spi/ConfigSource.java
rename to api/src/main/java/io/microprofile/config/spi/ConfigSource.java
index f66f552..5b0f06b 100644
--- a/api/src/main/java/javx/config/spi/ConfigSource.java
+++ b/api/src/main/java/io/microprofile/config/spi/ConfigSource.java
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package javx.config.spi;
+package io.microprofile.config.spi;
import java.util.Map;
diff --git a/api/src/main/java/javx/config/spi/ConfigSourceProvider.java b/api/src/main/java/io/microprofile/config/spi/ConfigSourceProvider.java
similarity index 98%
rename from api/src/main/java/javx/config/spi/ConfigSourceProvider.java
rename to api/src/main/java/io/microprofile/config/spi/ConfigSourceProvider.java
index b3f3a46..8b9b4f8 100644
--- a/api/src/main/java/javx/config/spi/ConfigSourceProvider.java
+++ b/api/src/main/java/io/microprofile/config/spi/ConfigSourceProvider.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package javx.config.spi;
+package io.microprofile.config.spi;
import java.util.List;
diff --git a/api/src/main/java/javx/config/spi/Converter.java b/api/src/main/java/io/microprofile/config/spi/Converter.java
similarity index 98%
rename from api/src/main/java/javx/config/spi/Converter.java
rename to api/src/main/java/io/microprofile/config/spi/Converter.java
index 07a86a5..0d655d6 100644
--- a/api/src/main/java/javx/config/spi/Converter.java
+++ b/api/src/main/java/io/microprofile/config/spi/Converter.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package javx.config.spi;
+package io.microprofile.config.spi;
/**
*
A very simple interface for conversion of configuration values from String to any Java type.
diff --git a/impl/src/main/java/org/apache/geronimo/config/ConfigImpl.java b/impl/src/main/java/org/apache/geronimo/config/ConfigImpl.java
index 44eb254..6aa702c 100644
--- a/impl/src/main/java/org/apache/geronimo/config/ConfigImpl.java
+++ b/impl/src/main/java/org/apache/geronimo/config/ConfigImpl.java
@@ -28,10 +28,10 @@
import java.util.logging.Level;
import java.util.logging.Logger;
-import javx.config.Config;
-import javx.config.spi.ConfigFilter;
-import javx.config.spi.ConfigSource;
-import javx.config.spi.Converter;
+import io.microprofile.config.Config;
+import io.microprofile.config.spi.ConfigFilter;
+import io.microprofile.config.spi.ConfigSource;
+import io.microprofile.config.spi.Converter;
import org.apache.geronimo.config.converters.BooleanConverter;
import org.apache.geronimo.config.converters.DoubleConverter;
import org.apache.geronimo.config.converters.FloatConverter;
diff --git a/impl/src/main/java/org/apache/geronimo/config/DefaultConfigBuilder.java b/impl/src/main/java/org/apache/geronimo/config/DefaultConfigBuilder.java
index e70c59b..bd9afa2 100644
--- a/impl/src/main/java/org/apache/geronimo/config/DefaultConfigBuilder.java
+++ b/impl/src/main/java/org/apache/geronimo/config/DefaultConfigBuilder.java
@@ -16,11 +16,11 @@
*/
package org.apache.geronimo.config;
-import javx.config.Config;
-import javx.config.ConfigProvider;
-import javx.config.spi.ConfigFilter;
-import javx.config.spi.ConfigSource;
-import javx.config.spi.ConfigSourceProvider;
+import io.microprofile.config.Config;
+import io.microprofile.config.ConfigProvider;
+import io.microprofile.config.spi.ConfigFilter;
+import io.microprofile.config.spi.ConfigSource;
+import io.microprofile.config.spi.ConfigSourceProvider;
import org.apache.geronimo.config.configsource.PropertyFileConfigSourceProvider;
import org.apache.geronimo.config.configsource.SystemEnvConfigSource;
import org.apache.geronimo.config.configsource.SystemPropertyConfigSource;
diff --git a/impl/src/main/java/org/apache/geronimo/config/DefaultConfigProvider.java b/impl/src/main/java/org/apache/geronimo/config/DefaultConfigProvider.java
index 388624e..07605f9 100644
--- a/impl/src/main/java/org/apache/geronimo/config/DefaultConfigProvider.java
+++ b/impl/src/main/java/org/apache/geronimo/config/DefaultConfigProvider.java
@@ -21,8 +21,8 @@
import java.util.Iterator;
import java.util.Map;
import java.util.WeakHashMap;
-import javx.config.Config;
-import javx.config.ConfigProvider;
+import io.microprofile.config.Config;
+import io.microprofile.config.ConfigProvider;
/**
diff --git a/impl/src/main/java/org/apache/geronimo/config/configsource/BaseConfigSource.java b/impl/src/main/java/org/apache/geronimo/config/configsource/BaseConfigSource.java
index 1f41c5f..9ffbc10 100644
--- a/impl/src/main/java/org/apache/geronimo/config/configsource/BaseConfigSource.java
+++ b/impl/src/main/java/org/apache/geronimo/config/configsource/BaseConfigSource.java
@@ -21,7 +21,7 @@
import java.util.logging.Level;
import java.util.logging.Logger;
-import javx.config.spi.ConfigSource;
+import io.microprofile.config.spi.ConfigSource;
/**
diff --git a/impl/src/main/java/org/apache/geronimo/config/configsource/PropertyFileConfigSourceProvider.java b/impl/src/main/java/org/apache/geronimo/config/configsource/PropertyFileConfigSourceProvider.java
index 9d6e218..6404f92 100644
--- a/impl/src/main/java/org/apache/geronimo/config/configsource/PropertyFileConfigSourceProvider.java
+++ b/impl/src/main/java/org/apache/geronimo/config/configsource/PropertyFileConfigSourceProvider.java
@@ -26,8 +26,8 @@
import java.util.logging.Level;
import java.util.logging.Logger;
-import javx.config.spi.ConfigSource;
-import javx.config.spi.ConfigSourceProvider;
+import io.microprofile.config.spi.ConfigSource;
+import io.microprofile.config.spi.ConfigSourceProvider;
/**
diff --git a/impl/src/main/java/org/apache/geronimo/config/configsource/SystemEnvConfigSource.java b/impl/src/main/java/org/apache/geronimo/config/configsource/SystemEnvConfigSource.java
index c45a47d..bf5e171 100644
--- a/impl/src/main/java/org/apache/geronimo/config/configsource/SystemEnvConfigSource.java
+++ b/impl/src/main/java/org/apache/geronimo/config/configsource/SystemEnvConfigSource.java
@@ -21,7 +21,7 @@
import java.util.Map;
-import javx.config.spi.ConfigSource;
+import io.microprofile.config.spi.ConfigSource;
/**
* {@link ConfigSource} which uses {@link System#getenv()}
diff --git a/impl/src/main/java/org/apache/geronimo/config/configsource/SystemPropertyConfigSource.java b/impl/src/main/java/org/apache/geronimo/config/configsource/SystemPropertyConfigSource.java
index f29cf23..73ce7f1 100644
--- a/impl/src/main/java/org/apache/geronimo/config/configsource/SystemPropertyConfigSource.java
+++ b/impl/src/main/java/org/apache/geronimo/config/configsource/SystemPropertyConfigSource.java
@@ -20,7 +20,7 @@
import java.util.Map;
-import javx.config.spi.ConfigSource;
+import io.microprofile.config.spi.ConfigSource;
/**
* {@link ConfigSource} which uses {@link System#getProperties()}
diff --git a/impl/src/main/java/org/apache/geronimo/config/converters/BooleanConverter.java b/impl/src/main/java/org/apache/geronimo/config/converters/BooleanConverter.java
index 5df76ee..72e03b4 100644
--- a/impl/src/main/java/org/apache/geronimo/config/converters/BooleanConverter.java
+++ b/impl/src/main/java/org/apache/geronimo/config/converters/BooleanConverter.java
@@ -16,7 +16,7 @@
*/
package org.apache.geronimo.config.converters;
-import javx.config.spi.Converter;
+import io.microprofile.config.spi.Converter;
import javax.annotation.Priority;
diff --git a/impl/src/main/java/org/apache/geronimo/config/converters/DoubleConverter.java b/impl/src/main/java/org/apache/geronimo/config/converters/DoubleConverter.java
index 99b0add..c32860f 100644
--- a/impl/src/main/java/org/apache/geronimo/config/converters/DoubleConverter.java
+++ b/impl/src/main/java/org/apache/geronimo/config/converters/DoubleConverter.java
@@ -16,7 +16,7 @@
*/
package org.apache.geronimo.config.converters;
-import javx.config.spi.Converter;
+import io.microprofile.config.spi.Converter;
import javax.annotation.Priority;
diff --git a/impl/src/main/java/org/apache/geronimo/config/converters/FloatConverter.java b/impl/src/main/java/org/apache/geronimo/config/converters/FloatConverter.java
index c8d5806..fa7372a 100644
--- a/impl/src/main/java/org/apache/geronimo/config/converters/FloatConverter.java
+++ b/impl/src/main/java/org/apache/geronimo/config/converters/FloatConverter.java
@@ -18,7 +18,7 @@
import javax.annotation.Priority;
-import javx.config.spi.Converter;
+import io.microprofile.config.spi.Converter;
/**
* @author Mark Struberg
diff --git a/impl/src/main/java/org/apache/geronimo/config/converters/IntegerConverter.java b/impl/src/main/java/org/apache/geronimo/config/converters/IntegerConverter.java
index e3c7e0d..cb76c63 100644
--- a/impl/src/main/java/org/apache/geronimo/config/converters/IntegerConverter.java
+++ b/impl/src/main/java/org/apache/geronimo/config/converters/IntegerConverter.java
@@ -18,7 +18,7 @@
import javax.annotation.Priority;
-import javx.config.spi.Converter;
+import io.microprofile.config.spi.Converter;
/**
* @author Mark Struberg
diff --git a/impl/src/main/java/org/apache/geronimo/config/converters/LongConverter.java b/impl/src/main/java/org/apache/geronimo/config/converters/LongConverter.java
index 2d9eff6..4df6eaa 100644
--- a/impl/src/main/java/org/apache/geronimo/config/converters/LongConverter.java
+++ b/impl/src/main/java/org/apache/geronimo/config/converters/LongConverter.java
@@ -16,7 +16,7 @@
*/
package org.apache.geronimo.config.converters;
-import javx.config.spi.Converter;
+import io.microprofile.config.spi.Converter;
import javax.annotation.Priority;
diff --git a/impl/src/main/resources/META-INF/services/javx.config.ConfigProvider$SPI b/impl/src/main/resources/META-INF/services/io.microprofile.config.ConfigProvider$SPI
similarity index 100%
rename from impl/src/main/resources/META-INF/services/javx.config.ConfigProvider$SPI
rename to impl/src/main/resources/META-INF/services/io.microprofile.config.ConfigProvider$SPI
diff --git a/spec/pom.xml b/spec/pom.xml
index 756115a..416f9c5 100644
--- a/spec/pom.xml
+++ b/spec/pom.xml
@@ -77,7 +77,7 @@
- javaconfig-spec.asciidoc
+ microprofile-config-spec.asciidoccoderayApache License v2.0
diff --git a/spec/src/main/asciidoc/architecture.asciidoc b/spec/src/main/asciidoc/architecture.asciidoc
index e73dd3d..11af860 100644
--- a/spec/src/main/asciidoc/architecture.asciidoc
+++ b/spec/src/main/asciidoc/architecture.asciidoc
@@ -28,10 +28,10 @@ This might be different REST endpoints to talk with (e.g. depending on the custo
Or it might even be different features which need to be switched on and off depending on the installation.
All this must be possible without the need to re-package the whole application binary.
-Java-config provides a way to achieve this goal by aggregating configuration from many different sources and presents a single merged view to the user.
+Microprofile-Config provides a way to achieve this goal by aggregating configuration from many different sources and presents a single merged view to the user.
This allows the application to bundle default configuration within the application.
It also allows to override the defaults from outside, e.g. via an environment variable a Java system property or via Docker.
-Java-config also allows to implement and register own configuration sources in a portable way, e.g. for reading configuration values from a shared database in an application cluster.
+Microprofile-Config also allows to implement and register own configuration sources in a portable way, e.g. for reading configuration values from a shared database in an application cluster.
=== Accessing a certain Configuration
@@ -63,7 +63,7 @@ Any subsequent call to `ConfigProvider#getConfig()` or `ConfigProvider#getConfig
=== Configuration Lookup Mechanism Example
-The core Java-config mechanism is purely String/String based.
+The core Microprofile-Config mechanism is purely String/String based.
Type-safety is only provided on top of that by using the proper `Converter` before handing the value out to the caller.
The configuration key might use dot-separated namespaces similar to Java package namespacing:
diff --git a/spec/src/main/asciidoc/configfilters.asciidoc b/spec/src/main/asciidoc/configfilters.asciidoc
index 631f618..b32eb96 100644
--- a/spec/src/main/asciidoc/configfilters.asciidoc
+++ b/spec/src/main/asciidoc/configfilters.asciidoc
@@ -22,7 +22,7 @@ A `ConfigFilter` acts as a valve which is able to modify the configured values b
An implementation of the specification is not required to ship with any `ConfigFilters` enabled by default.
-A custom `ConfigFilter` must implement the interface `javx.config.spi.ConfigFilter` and is typically registered in a classpath resource `/META-INF/services/javx.config.spi.ConfigFilter` by including the fully-qualified class name of the custom implementation (well-known Java SE `java.util.ServiceLoader` mechanism).
+A custom `ConfigFilter` must implement the interface `io.microprofile.config.spi.ConfigFilter` and is typically registered in a classpath resource `/META-INF/services/io.microprofile.config.spi.ConfigFilter` by including the fully-qualified class name of the custom implementation (well-known Java SE `java.util.ServiceLoader` mechanism).
Alternatively a user can register a `ConfigFilter` manually via `void Config#addConfigFilter(ConfigFilter configFilterToAdd)`.
diff --git a/spec/src/main/asciidoc/configsources.asciidoc b/spec/src/main/asciidoc/configsources.asciidoc
index f4f008e..74b9dd8 100644
--- a/spec/src/main/asciidoc/configsources.asciidoc
+++ b/spec/src/main/asciidoc/configsources.asciidoc
@@ -41,7 +41,7 @@ com.acme.myproject.someserver.url = http://more_important.server/some/endpoint
=== Default ConfigSources
-A Java-config implementation must provide `ConfigSource` s for the following data out of the box:
+A Microprofile-Config implementation must provide `ConfigSource` s for the following data out of the box:
* System properties (ordinal=400)
* Environment properties (ordinal=300)
@@ -51,7 +51,7 @@ A Java-config implementation must provide `ConfigSource` s for the following dat
`ConfigSource` s are discovered using the `java.util.ServiceLoader` mechanism.
-To add a custom `ConfigSource`, implement the interface `javx.config.spi.ConfigSource`.
+To add a custom `ConfigSource`, implement the interface `io.microprofile.config.spi.ConfigSource`.
[source, java]
----
@@ -82,7 +82,7 @@ public class CustomDbConfigSource implements ConfigSource {
----
-Then register your implementation in a resource file `/META-INF/services/javx.config.spi.ConfigSource` by including the fully-qualified class name of the custom implementation in the file.
+Then register your implementation in a resource file `/META-INF/services/io.microprofile.config.spi.ConfigSource` by including the fully-qualified class name of the custom implementation in the file.
=== Custom ConfigSources via ConfigSourceProvider
@@ -91,15 +91,15 @@ If you need dynamic `ConfigSource` s you can also register a `ConfigSourceProvid
This is useful if you are required to dynamically pick up multiple `ConfigSource` s of the same kind;
for example, to pick up all `myproject.properties` resources from all the JARs in your classpath.
-A custom `ConfigSourceProvider` must implement the interface `javx.config.spi.ConfigSourceProvider`.
-Register your implementation in a resource file `/META-INF/services/javx.config.spi.ConfigSourceProvider` by including the fully-qualified class name of the custom implementation/s in the file.
+A custom `ConfigSourceProvider` must implement the interface `io.microprofile.config.spi.ConfigSourceProvider`.
+Register your implementation in a resource file `/META-INF/services/io.microprofile.config.spi.ConfigSourceProvider` by including the fully-qualified class name of the custom implementation/s in the file.
An example which registers all YAML files with the name `exampleconfig.yaml`:
[source, java]
----
public class ExampleYamlConfigSourceProvider
- implements javx.config.spi.ConfigSourceProvider {
+ implements io.microprofile.config.spi.ConfigSourceProvider {
@Override
public List getConfigSources(ClassLoader forClassLoader) {
List configSources = new ArrayList<>();
diff --git a/spec/src/main/asciidoc/converters.asciidoc b/spec/src/main/asciidoc/converters.asciidoc
index e8e1010..589891b 100644
--- a/spec/src/main/asciidoc/converters.asciidoc
+++ b/spec/src/main/asciidoc/converters.asciidoc
@@ -23,7 +23,7 @@ This happens by providing `Converter` s in the `Config`.
=== Built-in Converters
-The following `Converter` s are provided by Java-config by default:
+The following `Converter` s are provided by Microprofile-Config by default:
* `Boolean` , values for `true` (case insensitive) "true", "1", "YES", "Y" "JA" "J", "OUI".
Any other value will be interpreted as `false`
@@ -31,13 +31,15 @@ The following `Converter` s are provided by Java-config by default:
* `Long`
* `Float` , a dot '.' is used to separate the fractional digits
* `Double` , a dot '.' is used to separate the fractional digits
+* `java.util.Date` in ISO-8601 format (https://www.ietf.org/rfc/rfc3339.txt), e.g. YYYY-MM-DD. Remaining fractions are set to 0.
+* Java8 `LocalDate` and `LocalDateTime`in ISO-8601 format
=== Adding custom Converters
-A custom `Converter` must implement the generic interface `javx.config.spi.Converter`.
+A custom `Converter` must implement the generic interface `io.microprofile.config.spi.Converter`.
The TypedParameter of the interface is the target type the String is converted to
-You have to register your implementation in a file `/META-INF/services/javx.config.spi.Converter` by writing the fully qualified class name of the custom implementation into it.
+You have to register your implementation in a file `/META-INF/services/io.microprofile.config.spi.Converter` by writing the fully qualified class name of the custom implementation into it.
A custom `Converter` can define a priority with the `@javax.annotation.Priority` annotation.
If a Priority annotation isn't applied, a default priority of 100 is assumed.
diff --git a/spec/src/main/asciidoc/javaconfig-spec.asciidoc b/spec/src/main/asciidoc/microprofile-config-spec.asciidoc
similarity index 97%
rename from spec/src/main/asciidoc/javaconfig-spec.asciidoc
rename to spec/src/main/asciidoc/microprofile-config-spec.asciidoc
index e2cb17a..92686df 100644
--- a/spec/src/main/asciidoc/javaconfig-spec.asciidoc
+++ b/spec/src/main/asciidoc/microprofile-config-spec.asciidoc
@@ -15,7 +15,7 @@
// limitations under the License.
//
-= JSR XXX: Configuration for Java
+= Configuration for Microprofile
:author: Mark Struberg
:email: struberg@apache.org
:revnumber: 0.1
diff --git a/tck/src/main/java/org/apache/geronimo/config/tck/ConfigFilterTest.java b/tck/src/main/java/org/apache/geronimo/config/tck/ConfigFilterTest.java
index 1c826b2..683b3a7 100644
--- a/tck/src/main/java/org/apache/geronimo/config/tck/ConfigFilterTest.java
+++ b/tck/src/main/java/org/apache/geronimo/config/tck/ConfigFilterTest.java
@@ -16,8 +16,8 @@
*/
package org.apache.geronimo.config.tck;
-import javx.config.Config;
-import javx.config.ConfigProvider;
+import io.microprofile.config.Config;
+import io.microprofile.config.ConfigProvider;
import org.testng.Assert;
import org.testng.annotations.Test;
diff --git a/tck/src/main/java/org/apache/geronimo/config/tck/ConfigProviderTest.java b/tck/src/main/java/org/apache/geronimo/config/tck/ConfigProviderTest.java
index ec99dfe..aafa3f5 100644
--- a/tck/src/main/java/org/apache/geronimo/config/tck/ConfigProviderTest.java
+++ b/tck/src/main/java/org/apache/geronimo/config/tck/ConfigProviderTest.java
@@ -21,8 +21,8 @@
import java.util.Map;
import java.util.Properties;
-import javx.config.Config;
-import javx.config.ConfigProvider;
+import io.microprofile.config.Config;
+import io.microprofile.config.ConfigProvider;
import org.testng.Assert;
import org.testng.annotations.Test;
diff --git a/tck/src/main/java/org/apache/geronimo/config/tck/ConfigSourceProviderTest.java b/tck/src/main/java/org/apache/geronimo/config/tck/ConfigSourceProviderTest.java
index f95dca2..664d27d 100644
--- a/tck/src/main/java/org/apache/geronimo/config/tck/ConfigSourceProviderTest.java
+++ b/tck/src/main/java/org/apache/geronimo/config/tck/ConfigSourceProviderTest.java
@@ -16,8 +16,8 @@
*/
package org.apache.geronimo.config.tck;
-import javx.config.Config;
-import javx.config.ConfigProvider;
+import io.microprofile.config.Config;
+import io.microprofile.config.ConfigProvider;
import org.testng.Assert;
import org.testng.annotations.Test;
diff --git a/tck/src/main/java/org/apache/geronimo/config/tck/ConverterTest.java b/tck/src/main/java/org/apache/geronimo/config/tck/ConverterTest.java
index da3558f..dfa8e0b 100644
--- a/tck/src/main/java/org/apache/geronimo/config/tck/ConverterTest.java
+++ b/tck/src/main/java/org/apache/geronimo/config/tck/ConverterTest.java
@@ -16,8 +16,8 @@
*/
package org.apache.geronimo.config.tck;
-import javx.config.Config;
-import javx.config.ConfigProvider;
+import io.microprofile.config.Config;
+import io.microprofile.config.ConfigProvider;
import org.testng.Assert;
import org.testng.annotations.Test;
diff --git a/tck/src/main/java/org/apache/geronimo/config/tck/CustomConfigSourceTest.java b/tck/src/main/java/org/apache/geronimo/config/tck/CustomConfigSourceTest.java
index 99e89a6..83b0758 100644
--- a/tck/src/main/java/org/apache/geronimo/config/tck/CustomConfigSourceTest.java
+++ b/tck/src/main/java/org/apache/geronimo/config/tck/CustomConfigSourceTest.java
@@ -16,8 +16,8 @@
*/
package org.apache.geronimo.config.tck;
-import javx.config.Config;
-import javx.config.ConfigProvider;
+import io.microprofile.config.Config;
+import io.microprofile.config.ConfigProvider;
import org.testng.Assert;
import org.testng.annotations.Test;
diff --git a/tck/src/main/java/org/apache/geronimo/config/tck/configfilters/PasswordConfigFilter.java b/tck/src/main/java/org/apache/geronimo/config/tck/configfilters/PasswordConfigFilter.java
index 1d472e8..4186b86 100644
--- a/tck/src/main/java/org/apache/geronimo/config/tck/configfilters/PasswordConfigFilter.java
+++ b/tck/src/main/java/org/apache/geronimo/config/tck/configfilters/PasswordConfigFilter.java
@@ -16,7 +16,7 @@
*/
package org.apache.geronimo.config.tck.configfilters;
-import javx.config.spi.ConfigFilter;
+import io.microprofile.config.spi.ConfigFilter;
/**
* @author Mark Struberg
diff --git a/tck/src/main/java/org/apache/geronimo/config/tck/configsources/CustomConfigSourceProvider.java b/tck/src/main/java/org/apache/geronimo/config/tck/configsources/CustomConfigSourceProvider.java
index d14bbb9..33691d0 100644
--- a/tck/src/main/java/org/apache/geronimo/config/tck/configsources/CustomConfigSourceProvider.java
+++ b/tck/src/main/java/org/apache/geronimo/config/tck/configsources/CustomConfigSourceProvider.java
@@ -22,8 +22,8 @@
import java.util.Enumeration;
import java.util.List;
-import javx.config.spi.ConfigSource;
-import javx.config.spi.ConfigSourceProvider;
+import io.microprofile.config.spi.ConfigSource;
+import io.microprofile.config.spi.ConfigSourceProvider;
/**
* @author Mark Struberg
diff --git a/tck/src/main/java/org/apache/geronimo/config/tck/configsources/CustomDbConfigSource.java b/tck/src/main/java/org/apache/geronimo/config/tck/configsources/CustomDbConfigSource.java
index c9ebfdf..a5741d5 100644
--- a/tck/src/main/java/org/apache/geronimo/config/tck/configsources/CustomDbConfigSource.java
+++ b/tck/src/main/java/org/apache/geronimo/config/tck/configsources/CustomDbConfigSource.java
@@ -19,7 +19,7 @@
import java.util.HashMap;
import java.util.Map;
-import javx.config.spi.ConfigSource;
+import io.microprofile.config.spi.ConfigSource;
/**
* @author Mark Struberg
diff --git a/tck/src/main/java/org/apache/geronimo/config/tck/configsources/SampleYamlConfigSource.java b/tck/src/main/java/org/apache/geronimo/config/tck/configsources/SampleYamlConfigSource.java
index 896a668..2ea346b 100644
--- a/tck/src/main/java/org/apache/geronimo/config/tck/configsources/SampleYamlConfigSource.java
+++ b/tck/src/main/java/org/apache/geronimo/config/tck/configsources/SampleYamlConfigSource.java
@@ -20,7 +20,7 @@
import java.util.HashMap;
import java.util.Map;
-import javx.config.spi.ConfigSource;
+import io.microprofile.config.spi.ConfigSource;
/**
* @author Mark Struberg
diff --git a/tck/src/main/java/org/apache/geronimo/config/tck/converters/DuckConverter.java b/tck/src/main/java/org/apache/geronimo/config/tck/converters/DuckConverter.java
index f8337bd..fe51b8d 100644
--- a/tck/src/main/java/org/apache/geronimo/config/tck/converters/DuckConverter.java
+++ b/tck/src/main/java/org/apache/geronimo/config/tck/converters/DuckConverter.java
@@ -16,7 +16,7 @@
*/
package org.apache.geronimo.config.tck.converters;
-import javx.config.spi.Converter;
+import io.microprofile.config.spi.Converter;
/**
* @author Mark Struberg
diff --git a/tck/src/main/resources/META-INF/services/javx.config.spi.ConfigFilter b/tck/src/main/resources/META-INF/services/io.microprofile.config.spi.ConfigFilter
similarity index 100%
rename from tck/src/main/resources/META-INF/services/javx.config.spi.ConfigFilter
rename to tck/src/main/resources/META-INF/services/io.microprofile.config.spi.ConfigFilter
diff --git a/tck/src/main/resources/META-INF/services/javx.config.spi.ConfigSource b/tck/src/main/resources/META-INF/services/io.microprofile.config.spi.ConfigSource
similarity index 100%
rename from tck/src/main/resources/META-INF/services/javx.config.spi.ConfigSource
rename to tck/src/main/resources/META-INF/services/io.microprofile.config.spi.ConfigSource
diff --git a/tck/src/main/resources/META-INF/services/javx.config.spi.ConfigSourceProvider b/tck/src/main/resources/META-INF/services/io.microprofile.config.spi.ConfigSourceProvider
similarity index 100%
rename from tck/src/main/resources/META-INF/services/javx.config.spi.ConfigSourceProvider
rename to tck/src/main/resources/META-INF/services/io.microprofile.config.spi.ConfigSourceProvider
From 6ae692627723c44d9bdb36b5371d2dacb428c6ae Mon Sep 17 00:00:00 2001
From: Mark Struberg
Date: Fri, 5 Aug 2016 09:34:25 +0200
Subject: [PATCH 10/37] fix licensing header for the spec docs
---
spec/src/main/asciidoc/configsources.asciidoc | 4 ++--
spec/src/main/asciidoc/license-alv2.asciidoc | 5 ++++-
2 files changed, 6 insertions(+), 3 deletions(-)
diff --git a/spec/src/main/asciidoc/configsources.asciidoc b/spec/src/main/asciidoc/configsources.asciidoc
index 74b9dd8..beeb73e 100644
--- a/spec/src/main/asciidoc/configsources.asciidoc
+++ b/spec/src/main/asciidoc/configsources.asciidoc
@@ -104,8 +104,8 @@ public class ExampleYamlConfigSourceProvider
public List getConfigSources(ClassLoader forClassLoader) {
List configSources = new ArrayList<>();
- Enumeration yamlFiles = null;
- yamlFiles = forClassLoader.getResources("sampleconfig.yaml");
+ Enumeration yamlFiles
+ = forClassLoader.getResources("sampleconfig.yaml");
while (yamlFiles.hasMoreElements()) {
configSources.add(new SampleYamlConfigSource(yamlFiles.nextElement()));
}
diff --git a/spec/src/main/asciidoc/license-alv2.asciidoc b/spec/src/main/asciidoc/license-alv2.asciidoc
index 9876e47..ddbfded 100644
--- a/spec/src/main/asciidoc/license-alv2.asciidoc
+++ b/spec/src/main/asciidoc/license-alv2.asciidoc
@@ -28,7 +28,10 @@ Specification Lead: Mark Struberg
Release: {revdate}
-Copyright 2016 Apache Software Foundation
+Copyright 2016 Original Authors,
+Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements.
+Licensed to the Microprofile.io community.
+
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
From a066efe1a587a92086220992ac226dd864f6d435 Mon Sep 17 00:00:00 2001
From: Mark Struberg
Date: Sun, 17 Jul 2016 13:11:11 +0200
Subject: [PATCH 11/37] add an access layer on top of the minimal configuration
API
---
.../java/io/microprofile/config/Config.java | 7 +
.../io/microprofile/config/ConfigValue.java | 130 +++++++++++
.../apache/geronimo/config/ConfigImpl.java | 5 +
.../geronimo/config/ConfigValueImpl.java | 219 ++++++++++++++++++
.../config/DefaultConfigProvider.java | 5 +-
.../geronimo/config/tck/ConfigValueTest.java | 132 +++++++++++
6 files changed, 496 insertions(+), 2 deletions(-)
create mode 100644 api/src/main/java/io/microprofile/config/ConfigValue.java
create mode 100644 impl/src/main/java/org/apache/geronimo/config/ConfigValueImpl.java
create mode 100644 tck/src/main/java/org/apache/geronimo/config/tck/ConfigValueTest.java
diff --git a/api/src/main/java/io/microprofile/config/Config.java b/api/src/main/java/io/microprofile/config/Config.java
index f7b0b1f..332f670 100644
--- a/api/src/main/java/io/microprofile/config/Config.java
+++ b/api/src/main/java/io/microprofile/config/Config.java
@@ -37,6 +37,13 @@
*/
public interface Config {
+ /**
+ * Create a {@link ConfigValue} to access the underlying configuration.
+ *
+ * @param key the property key
+ */
+ ConfigValue access(String key);
+
/**
* Resolves the value configured for the given key.
*
diff --git a/api/src/main/java/io/microprofile/config/ConfigValue.java b/api/src/main/java/io/microprofile/config/ConfigValue.java
new file mode 100644
index 0000000..9231821
--- /dev/null
+++ b/api/src/main/java/io/microprofile/config/ConfigValue.java
@@ -0,0 +1,130 @@
+/*
+ * 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 io.microprofile.config;
+
+
+import java.util.concurrent.TimeUnit;
+
+/**
+ * Accessor to a configured value.
+ * It follows a builder pattern.
+ *
+ * Accessing the configured value is finally done via {@link #getValue()}
+ *
+ * @author Mark Struberg
+ * @author Gerhard Petracek
+ * @author Ron Smeral
+ */
+public interface ConfigValue {
+
+ /**
+ * Sets the type of the configuration entry to the given class and returns this builder.
+ * The default type of a ConfigValue is {@code String}.
+ *
+ * @param clazz The target type
+ * @param The target type
+ * @return This builder as a typed ConfigValue
+ */
+ ConfigValue as(Class clazz);
+
+ /**
+ * Sets the default value to use in case the resolution returns null.
+ * @param value the default value
+ * @return This builder
+ */
+ ConfigValue withDefault(T value);
+
+ /**
+ * Sets the default value to use in case the resolution returns null. Converts the given String to the type of
+ * this resolver using the same method as used for the configuration entries.
+ * @param value string value to be converted and used as default
+ * @return This builder
+ */
+ ConfigValue withStringDefault(String value);
+
+ /**
+ * Specify that a resolved value will get cached for a certain amount of time.
+ * After the time expires the next {@link #getValue()} will again resolve the value
+ * from the underlying {@link Config}.
+ *
+ * @param value the amount of the TimeUnit to wait
+ * @param timeUnit the TimeUnit for the value
+ *
+ * @return This builder
+ */
+ ConfigValue cacheFor(long value, TimeUnit timeUnit);
+
+ /**
+ * Whether to evaluate variables in configured values.
+ * A variable starts with '${' and ends with '}', e.g.
+ *
+ * If 'evaluateVariables' is enabled, the result for the above key
+ * {@code "mycompany.some.url"} would be:
+ * {@code "http://localhost:8081/some/path"}
+ * @param evaluateVariables whether to evaluate variables in values or not
+ * @return This builder
+ */
+ ConfigValue evaluateVariables(boolean evaluateVariables);
+
+ /**
+ * Appends the resolved value of the given property to the key of this builder.
+ * TODO further explain.
+ * @return This builder
+ */
+ ConfigValue withLookupChain(String... postfixNames);
+
+ /**
+ * Whether to log picking up any value changes as INFO.
+ *
+ * @return This builder
+ */
+ ConfigValue logChanges(boolean logChanges);
+
+ /**
+ * Returns the converted resolved filtered value.
+ * @return the resolved value
+ */
+ T getValue();
+
+ /**
+ * Returns the key given in {@link Config#access(String)}.
+ * @return the original key
+ */
+ String getKey();
+
+ /**
+ * Returns the actual key which led to successful resolution and corresponds to the resolved value. This applies
+ * only when {@link #withLookupChain(String...)} is used.
+ * Otherwise the resolved key should always be equal to the original key.
+ * This method is provided for cases, when arameterized resolution is
+ * requested but the value for such appended key is not found and some of the fallback keys is used.
+ *
+ * This should be called only after calling {@link #getValue()} otherwise the value is undefined (but likely
+ * null).
+ */
+ String getResolvedKey();
+
+ /**
+ * Returns the default value provided by {@link #withDefault(Object)} or {@link #withStringDefault(String)}.
+ * Returns null if no default was provided.
+ * @return the default value or {@code null}
+ */
+ T getDefaultValue();
+}
diff --git a/impl/src/main/java/org/apache/geronimo/config/ConfigImpl.java b/impl/src/main/java/org/apache/geronimo/config/ConfigImpl.java
index 6aa702c..bab3494 100644
--- a/impl/src/main/java/org/apache/geronimo/config/ConfigImpl.java
+++ b/impl/src/main/java/org/apache/geronimo/config/ConfigImpl.java
@@ -29,6 +29,7 @@
import java.util.logging.Logger;
import io.microprofile.config.Config;
+import io.microprofile.config.ConfigValue;
import io.microprofile.config.spi.ConfigFilter;
import io.microprofile.config.spi.ConfigSource;
import io.microprofile.config.spi.Converter;
@@ -104,6 +105,10 @@ private Converter getConverter(Class asType) {
return converter;
}
+ public ConfigValue access(String key) {
+ return new ConfigValueImpl<>(this, key);
+ }
+
@Override
public Map getAllProperties() {
Map result = new HashMap();
diff --git a/impl/src/main/java/org/apache/geronimo/config/ConfigValueImpl.java b/impl/src/main/java/org/apache/geronimo/config/ConfigValueImpl.java
new file mode 100644
index 0000000..623390c
--- /dev/null
+++ b/impl/src/main/java/org/apache/geronimo/config/ConfigValueImpl.java
@@ -0,0 +1,219 @@
+/*
+ * 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.geronimo.config;
+
+import io.microprofile.config.ConfigValue;
+import io.microprofile.config.spi.Converter;
+
+import java.util.concurrent.TimeUnit;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * @author Mark Struberg
+ */
+public class ConfigValueImpl implements ConfigValue {
+ private static final Logger logger = Logger.getLogger(ConfigValueImpl.class.getName());
+
+ private final ConfigImpl config;
+
+ private String keyOriginal;
+
+ private String keyResolved;
+
+ private Class> configEntryType = String.class;
+
+ private String[] lookupChain;
+
+ private boolean withDefault = false;
+ private T defaultValue;
+
+
+ private Converter> converter;
+
+ private boolean evaluateVariables = false;
+
+ private boolean logChanges = false;
+
+ private long cacheTimeMs = -1;
+ private volatile long reloadAfter = -1;
+ private T lastValue = null;
+
+ public ConfigValueImpl(ConfigImpl config, String key) {
+ this.config = config;
+ this.keyOriginal = key;
+ }
+
+ @Override
+ public ConfigValue as(Class clazz) {
+ configEntryType = clazz;
+ this.converter = null;
+ return (ConfigValue) this;
+ }
+
+ @Override
+ public ConfigValue withDefault(T value) {
+ defaultValue = value;
+ withDefault = true;
+ return this;
+ }
+
+ @Override
+ public ConfigValue withStringDefault(String value) {
+ if (value == null || value.isEmpty())
+ {
+ throw new RuntimeException("Empty String or null supplied as string-default value for property "
+ + keyOriginal);
+ }
+
+ defaultValue = convert(value);
+ withDefault = true;
+ return this;
+ }
+
+ @Override
+ public ConfigValue cacheFor(long value, TimeUnit timeUnit) {
+ this.cacheTimeMs = timeUnit.toMillis(value);
+ return this;
+ }
+
+ @Override
+ public ConfigValue evaluateVariables(boolean evaluateVariables) {
+ this.evaluateVariables = evaluateVariables;
+ return this;
+ }
+
+ @Override
+ public ConfigValue withLookupChain(String... postfixNames) {
+ this.lookupChain = postfixNames;
+ return this;
+ }
+
+ @Override
+ public ConfigValue logChanges(boolean logChanges) {
+ this.logChanges = logChanges;
+ return this;
+ }
+
+ @Override
+ public T getValue() {
+ long now = -1;
+ if (cacheTimeMs > 0)
+ {
+ now = System.currentTimeMillis();
+ if (now <= reloadAfter)
+ {
+ return lastValue;
+ }
+ }
+
+ String valueStr = resolveStringValue();
+ T value = convert(valueStr);
+
+ if (withDefault)
+ {
+ value = fallbackToDefaultIfEmpty(keyResolved, value, defaultValue);
+ }
+
+ if (logChanges && (value != null && !value.equals(lastValue) || (value == null && lastValue != null)) )
+ {
+ logger.log(Level.INFO, "New value {0} for key {1}.",
+ new Object[]{config.filterConfigValueForLog(keyOriginal, valueStr), keyOriginal});
+ }
+
+ lastValue = value;
+
+ if (cacheTimeMs > 0)
+ {
+ reloadAfter = now + cacheTimeMs;
+ }
+
+ return value;
+ }
+
+ private String resolveStringValue() {
+ //X TODO implement lookupChain
+
+ String value = config.getValue(keyOriginal);
+ if (evaluateVariables)
+ {
+ // recursively resolve any ${varName} in the value
+ int startVar = 0;
+ while ((startVar = value.indexOf("${", startVar)) >= 0)
+ {
+ int endVar = value.indexOf("}", startVar);
+ if (endVar <= 0)
+ {
+ break;
+ }
+ String varName = value.substring(startVar + 2, endVar);
+ if (varName.isEmpty())
+ {
+ break;
+ }
+ String variableValue = config.access(varName).evaluateVariables(true).withLookupChain(lookupChain).getValue();
+ if (variableValue != null)
+ {
+ value = value.replace("${" + varName + "}", variableValue);
+ }
+ startVar++;
+ }
+ }
+ return value;
+ }
+
+ @Override
+ public String getKey() {
+ return keyOriginal;
+ }
+
+ @Override
+ public String getResolvedKey() {
+ return keyResolved;
+ }
+
+ @Override
+ public T getDefaultValue() {
+ return defaultValue;
+ }
+
+ private T convert(String value) {
+ if (String.class == configEntryType) {
+ return (T) value;
+ }
+
+ Converter converter = config.getConverters().get(configEntryType);
+ if (converter == null) {
+ throw new IllegalStateException("No Converter for type " + configEntryType);
+ }
+
+ return (T) converter.convert(value);
+ }
+
+ private T fallbackToDefaultIfEmpty(String key, T value, T defaultValue) {
+ if (value == null || (value instanceof String && ((String)value).isEmpty()))
+ {
+ logger.log(Level.FINE, "no configured value found for key {0}, using default value {1}.",
+ new Object[]{key, defaultValue});
+
+ return defaultValue;
+ }
+
+ return value;
+ }
+
+}
diff --git a/impl/src/main/java/org/apache/geronimo/config/DefaultConfigProvider.java b/impl/src/main/java/org/apache/geronimo/config/DefaultConfigProvider.java
index 07605f9..c7be82a 100644
--- a/impl/src/main/java/org/apache/geronimo/config/DefaultConfigProvider.java
+++ b/impl/src/main/java/org/apache/geronimo/config/DefaultConfigProvider.java
@@ -30,7 +30,8 @@
*/
public class DefaultConfigProvider implements ConfigProvider.SPI {
- protected static Map> configs = Collections.synchronizedMap(new WeakHashMap>());
+ protected static Map> configs
+ = Collections.synchronizedMap(new WeakHashMap>());
@Override
@@ -69,7 +70,7 @@ protected Config createConfig(ClassLoader forClassLoader) {
private void registerConfig(Config config, ClassLoader forClassLoader) {
synchronized (DefaultConfigProvider.class) {
- configs.put(forClassLoader, new WeakReference(config));
+ configs.put(forClassLoader, new WeakReference<>(config));
}
}
diff --git a/tck/src/main/java/org/apache/geronimo/config/tck/ConfigValueTest.java b/tck/src/main/java/org/apache/geronimo/config/tck/ConfigValueTest.java
new file mode 100644
index 0000000..568650d
--- /dev/null
+++ b/tck/src/main/java/org/apache/geronimo/config/tck/ConfigValueTest.java
@@ -0,0 +1,132 @@
+/*
+ * 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.geronimo.config.tck;
+
+import io.microprofile.config.Config;
+import io.microprofile.config.ConfigProvider;
+import io.microprofile.config.ConfigValue;
+import org.testng.Assert;
+import org.testng.annotations.Test;
+
+import java.util.concurrent.TimeUnit;
+
+/**
+ * @author Mark Struberg
+ */
+public class ConfigValueTest {
+
+ private Config config = ConfigProvider.getConfig();
+
+ @Test
+ public void testGetValue() {
+ Assert.assertEquals(config.access("tck.config.test.javaconfig.configvalue.key1").getValue(), "value1");
+ }
+
+ @Test
+ public void testGetValueWithDefault() {
+ ConfigValue cfga = config.access("tck.config.test.javaconfig.configvalue.withdefault.notexisting")
+ .as(Integer.class)
+ .withDefault(Integer.valueOf(1234));
+
+ Assert.assertEquals(cfga.getValue(), Integer.valueOf(1234));
+ }
+
+ @Test
+ public void testGetValueWithStringDefault() {
+ ConfigValue cfga = config.access("tck.config.test.javaconfig.configvalue.withdefault.notexisting")
+ .as(Integer.class)
+ .withStringDefault("1234");
+
+ Assert.assertEquals(cfga.getValue(), Integer.valueOf(1234));
+ }
+
+ @Test
+ public void testIntegerConverter() {
+ Assert.assertEquals(config.access("tck.config.test.javaconfig.configvalue.integer").as(Integer.class).getValue(), Integer.valueOf(1234));
+ }
+
+ @Test
+ public void testLongConverter() {
+ Assert.assertEquals(config.access("tck.config.test.javaconfig.configvalue.long").as(Long.class).getValue(), Long.valueOf(1234567890123456L));
+ }
+
+ @Test
+ public void testFloatConverter() {
+ Assert.assertEquals(config.access("tck.config.test.javaconfig.configvalue.float").as(Float.class).getValue(), Float.valueOf(12.34f));
+ }
+
+ @Test
+ public void testDoubleonverter() {
+ Assert.assertEquals(config.access("tck.config.test.javaconfig.configvalue.double").as(Double.class).getValue(), Double.valueOf(12.34567890123456));
+ }
+
+ @Test
+ public void testBooleanConverter() {
+ Assert.assertEquals(config.access("tck.config.test.javaconfig.configvalue.boolean.true").as(Boolean.class).getValue(), Boolean.TRUE);
+ Assert.assertEquals(config.access("tck.config.test.javaconfig.configvalue.boolean.true_uppercase").as(Boolean.class).getValue(), Boolean.TRUE);
+ Assert.assertEquals(config.access("tck.config.test.javaconfig.configvalue.boolean.true_mixedcase").as(Boolean.class).getValue(), Boolean.TRUE);
+ Assert.assertEquals(config.access("tck.config.test.javaconfig.configvalue.boolean.false").as(Boolean.class).getValue(), Boolean.FALSE);
+
+ Assert.assertEquals(config.access("tck.config.test.javaconfig.configvalue.boolean.one").as(Boolean.class).getValue(), Boolean.TRUE);
+ Assert.assertEquals(config.access("tck.config.test.javaconfig.configvalue.boolean.zero").as(Boolean.class).getValue(), Boolean.FALSE);
+ Assert.assertEquals(config.access("tck.config.test.javaconfig.configvalue.boolean.seventeen").as(Boolean.class).getValue(), Boolean.FALSE);
+
+ Assert.assertEquals(config.access("tck.config.test.javaconfig.configvalue.boolean.yes").as(Boolean.class).getValue(), Boolean.TRUE);
+ Assert.assertEquals(config.access("tck.config.test.javaconfig.configvalue.boolean.yes_uppercase").as(Boolean.class).getValue(), Boolean.TRUE);
+ Assert.assertEquals(config.access("tck.config.test.javaconfig.configvalue.boolean.yes_mixedcase").as(Boolean.class).getValue(), Boolean.TRUE);
+
+ Assert.assertEquals(config.access("tck.config.test.javaconfig.configvalue.boolean.y").as(Boolean.class).getValue(), Boolean.TRUE);
+ Assert.assertEquals(config.access("tck.config.test.javaconfig.configvalue.boolean.y_uppercase").as(Boolean.class).getValue(), Boolean.TRUE);
+
+ Assert.assertEquals(config.access("tck.config.test.javaconfig.configvalue.boolean.ja").as(Boolean.class).getValue(), Boolean.TRUE);
+ Assert.assertEquals(config.access("tck.config.test.javaconfig.configvalue.boolean.ja_uppercase").as(Boolean.class).getValue(), Boolean.TRUE);
+ Assert.assertEquals(config.access("tck.config.test.javaconfig.configvalue.boolean.ja_mixedcase").as(Boolean.class).getValue(), Boolean.TRUE);
+ Assert.assertEquals(config.access("tck.config.test.javaconfig.configvalue.boolean.no_mixedcase").as(Boolean.class).getValue(), Boolean.FALSE);
+
+ Assert.assertEquals(config.access("tck.config.test.javaconfig.configvalue.boolean.j").as(Boolean.class).getValue(), Boolean.TRUE);
+ Assert.assertEquals(config.access("tck.config.test.javaconfig.configvalue.boolean.j_uppercase").as(Boolean.class).getValue(), Boolean.TRUE);
+ Assert.assertEquals(config.access("tck.config.test.javaconfig.configvalue.boolean.n_uppercase").as(Boolean.class).getValue(), Boolean.FALSE);
+
+ Assert.assertEquals(config.access("tck.config.test.javaconfig.configvalue.boolean.oui").as(Boolean.class).getValue(), Boolean.TRUE);
+ Assert.assertEquals(config.access("tck.config.test.javaconfig.configvalue.boolean.oui_uppercase").as(Boolean.class).getValue(), Boolean.TRUE);
+ Assert.assertEquals(config.access("tck.config.test.javaconfig.configvalue.boolean.oui_mixedcase").as(Boolean.class).getValue(), Boolean.TRUE);
+ }
+
+ @Test
+ public void testCacheFor() throws Exception {
+ String key = "tck.config.cachefor.key";
+ System.setProperty(key, "firstvalue");
+ ConfigValue val = config.access(key).cacheFor(30, TimeUnit.MILLISECONDS);
+ Assert.assertEquals(val.getValue(), "firstvalue");
+
+ // immediately change the value
+ System.setProperty(key, "secondvalue");
+
+ // we should still see the first value, because it is cached!
+ Assert.assertEquals(val.getValue(), "firstvalue");
+
+ // but now let's wait a bit
+ Thread.sleep(40);
+ Assert.assertEquals(val.getValue(), "secondvalue");
+ }
+
+ @Test
+ public void testWithVariable() throws Exception {
+ ConfigValue val = config.access("tck.config.test.javaconfig.configvalue.withvariable.key").evaluateVariables(true);
+ Assert.assertEquals(val.getValue(), "This key needs the perfect value!");
+ }
+}
From 993542f53e72dc879bd5e472d0f263f97ab848ce Mon Sep 17 00:00:00 2001
From: Mark Struberg
Date: Tue, 15 Nov 2016 11:01:09 +0100
Subject: [PATCH 12/37] adding Converter to ConfigBuilder
---
.../java/io/microprofile/config/ConfigProvider.java | 2 ++
.../apache/geronimo/config/DefaultConfigBuilder.java | 12 ++++++++++++
2 files changed, 14 insertions(+)
diff --git a/api/src/main/java/io/microprofile/config/ConfigProvider.java b/api/src/main/java/io/microprofile/config/ConfigProvider.java
index d693a06..e679c15 100644
--- a/api/src/main/java/io/microprofile/config/ConfigProvider.java
+++ b/api/src/main/java/io/microprofile/config/ConfigProvider.java
@@ -21,6 +21,7 @@
import io.microprofile.config.spi.ConfigFilter;
import io.microprofile.config.spi.ConfigSource;
+import io.microprofile.config.spi.Converter;
/**
*
This is the central class to access a {@link Config}.
@@ -109,6 +110,7 @@ public interface ConfigBuilder {
ConfigBuilder forClassLoader(ClassLoader loader);
ConfigBuilder withSources(ConfigSource... sources);
ConfigBuilder withFilters(ConfigFilter... filters);
+ ConfigBuilder withConverters(Converter>... filters);
Config build();
}
diff --git a/impl/src/main/java/org/apache/geronimo/config/DefaultConfigBuilder.java b/impl/src/main/java/org/apache/geronimo/config/DefaultConfigBuilder.java
index bd9afa2..3988375 100644
--- a/impl/src/main/java/org/apache/geronimo/config/DefaultConfigBuilder.java
+++ b/impl/src/main/java/org/apache/geronimo/config/DefaultConfigBuilder.java
@@ -21,6 +21,7 @@
import io.microprofile.config.spi.ConfigFilter;
import io.microprofile.config.spi.ConfigSource;
import io.microprofile.config.spi.ConfigSourceProvider;
+import io.microprofile.config.spi.Converter;
import org.apache.geronimo.config.configsource.PropertyFileConfigSourceProvider;
import org.apache.geronimo.config.configsource.SystemEnvConfigSource;
import org.apache.geronimo.config.configsource.SystemPropertyConfigSource;
@@ -40,6 +41,7 @@ public class DefaultConfigBuilder implements ConfigProvider.ConfigBuilder {
private ClassLoader forClassLoader;
private final List sources = new ArrayList<>();
private final List filters = new ArrayList<>();
+ private final List> converters = new ArrayList<>();
private boolean ignoreDefaultSources = false;
@Override
@@ -66,6 +68,12 @@ public ConfigProvider.ConfigBuilder withFilters(final ConfigFilter... filters) {
return this;
}
+ @Override
+ public ConfigProvider.ConfigBuilder withConverters(Converter>... converters) {
+ this.converters.addAll(asList(converters));
+ return this;
+ }
+
@Override
public Config build() {
List configSources = new ArrayList<>();
@@ -100,6 +108,10 @@ public Config build() {
config.addConfigFilter(filter);
}
+ for (Converter> converter : converters) {
+ config.addConverter(converter);
+ }
+
return config;
}
From be0ae251b3b5461e4f8a8901a4ee3dfe8c3f826d Mon Sep 17 00:00:00 2001
From: Mark Struberg
Date: Sun, 15 Jan 2017 20:35:17 +0100
Subject: [PATCH 13/37] improve JavaDoc
---
.../main/java/io/microprofile/config/ConfigProvider.java | 7 ++++---
pom.xml | 4 ++++
spec/pom.xml | 2 +-
3 files changed, 9 insertions(+), 4 deletions(-)
diff --git a/api/src/main/java/io/microprofile/config/ConfigProvider.java b/api/src/main/java/io/microprofile/config/ConfigProvider.java
index e679c15..7e8c035 100644
--- a/api/src/main/java/io/microprofile/config/ConfigProvider.java
+++ b/api/src/main/java/io/microprofile/config/ConfigProvider.java
@@ -63,7 +63,7 @@ public class ConfigProvider {
* Provide a {@link Config} based on all {@link ConfigSource}s
* of the current Thread Context ClassLoader (TCCL)
*
- *
There is exactly a single Config instance per ClassLoader
+ *
There is exactly a single Config instance per Application
*/
public static Config getConfig() {
return instance.getConfig();
@@ -73,7 +73,7 @@ public static Config getConfig() {
* Provide a {@link Config} based on all {@link ConfigSource}s
* of the given ClassLoader.
*
- *
There is exactly a single Config instance per ClassLoader
+ *
There is exactly a single Config instance per Application. The Application get's identified via a ClassLoader
*/
public static Config getConfig(ClassLoader forClassLoader) {
return instance.getConfig(forClassLoader);
@@ -85,7 +85,8 @@ public static Config getConfig(ClassLoader forClassLoader) {
* {@link ConfigSource} nor any {@link ConfigFilter}.
* Those have to be added manually.
*
- * The ConfigProvider will not manage the Config instance internally
+ * The ConfigProvider will not manage the Config instance internally.
+ * That means that {@link #getConfig()} does not pick up a Config created that way.
*/
public static ConfigBuilder newConfig() {
return instance.newConfig();
diff --git a/pom.xml b/pom.xml
index 1ac5b48..8721e88 100644
--- a/pom.xml
+++ b/pom.xml
@@ -31,6 +31,10 @@
0.1-SNAPSHOTpom
+
+ Apache License v 2.0
+
+
3.1.0
diff --git a/spec/pom.xml b/spec/pom.xml
index 416f9c5..7faf60c 100644
--- a/spec/pom.xml
+++ b/spec/pom.xml
@@ -35,7 +35,7 @@
1.5.31.5.0-alpha.10.1
- ALv2
+ Apache License v 2.0MMMM dd, yyyy${maven.build.timestamp}
From b82524b838236297b52c23ae91919a8600176979 Mon Sep 17 00:00:00 2001
From: Mark Struberg
Date: Sun, 15 Jan 2017 20:54:00 +0100
Subject: [PATCH 14/37] adopt License for microprofile usage
---
NOTICE | 5 ++---
api/pom.xml | 22 +++++++++++++------
.../java/io/microprofile/config/Config.java | 8 +++----
.../microprofile/config/ConfigProvider.java | 8 +++----
.../io/microprofile/config/ConfigValue.java | 8 +++----
.../microprofile/config/spi/ConfigFilter.java | 13 +++++------
.../microprofile/config/spi/ConfigSource.java | 8 +++----
.../config/spi/ConfigSourceProvider.java | 13 +++++------
.../io/microprofile/config/spi/Converter.java | 13 +++++------
pom.xml | 7 +++++-
spec/pom.xml | 22 +++++++++++++------
spec/src/main/asciidoc/architecture.asciidoc | 8 +++----
spec/src/main/asciidoc/configfilters.asciidoc | 8 +++----
spec/src/main/asciidoc/configsources.asciidoc | 8 +++----
spec/src/main/asciidoc/converters.asciidoc | 8 +++----
spec/src/main/asciidoc/license-alv2.asciidoc | 8 +++----
.../microprofile-config-spec.asciidoc | 13 +++++------
tck/pom.xml | 22 +++++++++++++------
18 files changed, 113 insertions(+), 89 deletions(-)
diff --git a/NOTICE b/NOTICE
index 27e30dd..451c174 100644
--- a/NOTICE
+++ b/NOTICE
@@ -1,5 +1,4 @@
-Apache Geronimo Configuration
-Copyright 2016 The Apache Software Foundation
+Copyright 2016-2017 original author and authors
This product includes software developed at
-The Apache Software Foundation (http://www.apache.org/).
+The Apache Software Foundation (http://www.apache.org/).
\ No newline at end of file
diff --git a/api/pom.xml b/api/pom.xml
index 7411717..5a5765b 100644
--- a/api/pom.xml
+++ b/api/pom.xml
@@ -1,12 +1,11 @@
-
+
diff --git a/impl/src/main/java/org/apache/geronimo/config/DefaultConfigBuilder.java b/impl/src/main/java/org/apache/geronimo/config/DefaultConfigBuilder.java
index 3988375..a84ac00 100644
--- a/impl/src/main/java/org/apache/geronimo/config/DefaultConfigBuilder.java
+++ b/impl/src/main/java/org/apache/geronimo/config/DefaultConfigBuilder.java
@@ -38,7 +38,7 @@
* @author Mark Struberg
*/
public class DefaultConfigBuilder implements ConfigProvider.ConfigBuilder {
- private ClassLoader forClassLoader;
+ protected ClassLoader forClassLoader;
private final List sources = new ArrayList<>();
private final List filters = new ArrayList<>();
private final List> converters = new ArrayList<>();
@@ -78,7 +78,9 @@ public ConfigProvider.ConfigBuilder withConverters(Converter>... converters) {
public Config build() {
List configSources = new ArrayList<>();
- configSources.addAll(getBuiltInConfigSources(forClassLoader));
+ if (!ignoreDefaultSources) {
+ configSources.addAll(getBuiltInConfigSources(forClassLoader));
+ }
configSources.addAll(sources);
if (!ignoreDefaultSources) {
diff --git a/impl/src/main/java/org/apache/geronimo/config/DefaultConfigProvider.java b/impl/src/main/java/org/apache/geronimo/config/DefaultConfigProvider.java
index c7be82a..03adbff 100644
--- a/impl/src/main/java/org/apache/geronimo/config/DefaultConfigProvider.java
+++ b/impl/src/main/java/org/apache/geronimo/config/DefaultConfigProvider.java
@@ -59,7 +59,7 @@ public Config getConfig(ClassLoader forClassLoader) {
return config;
}
- private Config existingConfig(ClassLoader forClassLoader) {
+ Config existingConfig(ClassLoader forClassLoader) {
WeakReference configRef = configs.get(forClassLoader);
return configRef != null ? configRef.get() : null;
}
@@ -68,7 +68,7 @@ protected Config createConfig(ClassLoader forClassLoader) {
return newConfig().forClassLoader(forClassLoader).build();
}
- private void registerConfig(Config config, ClassLoader forClassLoader) {
+ void registerConfig(Config config, ClassLoader forClassLoader) {
synchronized (DefaultConfigProvider.class) {
configs.put(forClassLoader, new WeakReference<>(config));
}
@@ -79,6 +79,11 @@ public ConfigProvider.ConfigBuilder newConfig() {
return new DefaultConfigBuilder();
}
+ @Override
+ public ConfigProvider.ConfigBuilder registerConfig() {
+ return new ManualApplicationConfigBuilder(this);
+ }
+
@Override
public void releaseConfig(Config config) {
if (config != null) {
diff --git a/impl/src/main/java/org/apache/geronimo/config/ManualApplicationConfigBuilder.java b/impl/src/main/java/org/apache/geronimo/config/ManualApplicationConfigBuilder.java
new file mode 100644
index 0000000..9b91edf
--- /dev/null
+++ b/impl/src/main/java/org/apache/geronimo/config/ManualApplicationConfigBuilder.java
@@ -0,0 +1,49 @@
+/*
+ * 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.geronimo.config;
+
+import io.microprofile.config.Config;
+import io.microprofile.config.ConfigProvider;
+
+/**
+ * @author Mark Struberg
+ */
+public class ManualApplicationConfigBuilder extends DefaultConfigBuilder {
+ private DefaultConfigProvider configProvider;
+
+ public ManualApplicationConfigBuilder(DefaultConfigProvider configProvider) {
+ this.configProvider = configProvider;
+ }
+
+ @Override
+ public synchronized Config build() {
+ Config config = super.build();
+ ClassLoader cl = forClassLoader;
+ if (cl == null) {
+ cl = Thread.currentThread().getContextClassLoader();
+ if (cl == null) {
+ cl = ConfigProvider.SPI.class.getClassLoader();
+ }
+ }
+ Config oldConfig = configProvider.existingConfig(cl);
+ if (oldConfig != null) {
+ throw new IllegalStateException("This Application already has a registered Configuration!");
+ }
+ configProvider.registerConfig(config, cl);
+ return config;
+ }
+}
diff --git a/tck/src/main/java/org/apache/geronimo/config/tck/ConfigProviderTest.java b/tck/src/main/java/org/apache/geronimo/config/tck/ConfigProviderTest.java
index aafa3f5..09a9514 100644
--- a/tck/src/main/java/org/apache/geronimo/config/tck/ConfigProviderTest.java
+++ b/tck/src/main/java/org/apache/geronimo/config/tck/ConfigProviderTest.java
@@ -24,6 +24,7 @@
import io.microprofile.config.Config;
import io.microprofile.config.ConfigProvider;
+import org.apache.geronimo.config.tck.configsources.SampleYamlConfigSource;
import org.testng.Assert;
import org.testng.annotations.Test;
@@ -91,6 +92,45 @@ public void testNonExistingConfigKey() {
Assert.assertNull(config.getValue("tck.config.test.keydoesnotexist"));
}
+ @Test
+ public void testRegisterManualConfig() {
+ // make sure we get a clean config
+ ConfigProvider.releaseConfig(ConfigProvider.getConfig());
+
+ ConfigProvider.registerConfig()
+ .ignoreDefaultSources()
+ .withSources(new SampleYamlConfigSource(null))
+ .build();
+
+ Config config = ConfigProvider.getConfig();
+ Assert.assertNotNull(config);
+ Assert.assertNotNull(config.getConfigSources());
+ Assert.assertEquals(1, config.getConfigSources().length);
+ Assert.assertEquals(SampleYamlConfigSource.class, config.getConfigSources()[0].getClass());
+
+ Assert.assertEquals("yamlvalue1", config.getValue("tck.config.test.sampleyaml.key1"));
+
+ Assert.assertNull(config.getValue("tck.config.test.javaconfig.properties.key1"));
+
+ {
+ // try it again, Sam
+ // this time we should fail as we already have a Config registered for this application
+ try {
+ ConfigProvider.registerConfig()
+ .ignoreDefaultSources()
+ .withSources(new SampleYamlConfigSource(null))
+ .build();
+
+ Assert.fail("We fail because subsequently registering another Config for the application is not allowed");
+ }
+ catch (IllegalStateException ise) {
+ // all fine
+ }
+ }
+
+ // clean up the dirt afterwards
+ ConfigProvider.releaseConfig(ConfigProvider.getConfig());
+ }
@Test
public void testConfigProviderRelease() {
From 0ee61e3578e277701cbd6f3028a3ebdedf5efe7c Mon Sep 17 00:00:00 2001
From: Mark Struberg
Date: Sun, 15 Jan 2017 22:02:54 +0100
Subject: [PATCH 16/37] rename package to io.microprofile
---
impl/debug-suite.xml | 2 +-
.../microprofile}/config/tck/ConfigFilterTest.java | 2 +-
.../microprofile}/config/tck/ConfigProviderTest.java | 4 ++--
.../microprofile}/config/tck/ConfigSourceProviderTest.java | 2 +-
.../microprofile}/config/tck/ConfigValueTest.java | 2 +-
.../microprofile}/config/tck/ConverterTest.java | 2 +-
.../microprofile}/config/tck/CustomConfigSourceTest.java | 2 +-
.../config/tck/configfilters/PasswordConfigFilter.java | 2 +-
.../config/tck/configsources/CustomConfigSourceProvider.java | 2 +-
.../config/tck/configsources/CustomDbConfigSource.java | 2 +-
.../config/tck/configsources/SampleYamlConfigSource.java | 2 +-
.../microprofile}/config/tck/converters/Duck.java | 2 +-
.../microprofile}/config/tck/converters/DuckConverter.java | 2 +-
.../META-INF/services/io.microprofile.config.spi.ConfigFilter | 2 +-
.../META-INF/services/io.microprofile.config.spi.ConfigSource | 2 +-
.../services/io.microprofile.config.spi.ConfigSourceProvider | 2 +-
16 files changed, 17 insertions(+), 17 deletions(-)
rename tck/src/main/java/{org/apache/geronimo => io/microprofile}/config/tck/ConfigFilterTest.java (97%)
rename tck/src/main/java/{org/apache/geronimo => io/microprofile}/config/tck/ConfigProviderTest.java (97%)
rename tck/src/main/java/{org/apache/geronimo => io/microprofile}/config/tck/ConfigSourceProviderTest.java (96%)
rename tck/src/main/java/{org/apache/geronimo => io/microprofile}/config/tck/ConfigValueTest.java (99%)
rename tck/src/main/java/{org/apache/geronimo => io/microprofile}/config/tck/ConverterTest.java (97%)
rename tck/src/main/java/{org/apache/geronimo => io/microprofile}/config/tck/CustomConfigSourceTest.java (96%)
rename tck/src/main/java/{org/apache/geronimo => io/microprofile}/config/tck/configfilters/PasswordConfigFilter.java (96%)
rename tck/src/main/java/{org/apache/geronimo => io/microprofile}/config/tck/configsources/CustomConfigSourceProvider.java (97%)
rename tck/src/main/java/{org/apache/geronimo => io/microprofile}/config/tck/configsources/CustomDbConfigSource.java (97%)
rename tck/src/main/java/{org/apache/geronimo => io/microprofile}/config/tck/configsources/SampleYamlConfigSource.java (96%)
rename tck/src/main/java/{org/apache/geronimo => io/microprofile}/config/tck/converters/Duck.java (95%)
rename tck/src/main/java/{org/apache/geronimo => io/microprofile}/config/tck/converters/DuckConverter.java (95%)
diff --git a/impl/debug-suite.xml b/impl/debug-suite.xml
index 1164b05..10e8976 100644
--- a/impl/debug-suite.xml
+++ b/impl/debug-suite.xml
@@ -24,7 +24,7 @@
-
+
diff --git a/tck/src/main/java/org/apache/geronimo/config/tck/ConfigFilterTest.java b/tck/src/main/java/io/microprofile/config/tck/ConfigFilterTest.java
similarity index 97%
rename from tck/src/main/java/org/apache/geronimo/config/tck/ConfigFilterTest.java
rename to tck/src/main/java/io/microprofile/config/tck/ConfigFilterTest.java
index 683b3a7..d41b07d 100644
--- a/tck/src/main/java/org/apache/geronimo/config/tck/ConfigFilterTest.java
+++ b/tck/src/main/java/io/microprofile/config/tck/ConfigFilterTest.java
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.geronimo.config.tck;
+package io.microprofile.config.tck;
import io.microprofile.config.Config;
import io.microprofile.config.ConfigProvider;
diff --git a/tck/src/main/java/org/apache/geronimo/config/tck/ConfigProviderTest.java b/tck/src/main/java/io/microprofile/config/tck/ConfigProviderTest.java
similarity index 97%
rename from tck/src/main/java/org/apache/geronimo/config/tck/ConfigProviderTest.java
rename to tck/src/main/java/io/microprofile/config/tck/ConfigProviderTest.java
index 09a9514..6b9a4b0 100644
--- a/tck/src/main/java/org/apache/geronimo/config/tck/ConfigProviderTest.java
+++ b/tck/src/main/java/io/microprofile/config/tck/ConfigProviderTest.java
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.geronimo.config.tck;
+package io.microprofile.config.tck;
import java.net.URL;
import java.net.URLClassLoader;
@@ -24,7 +24,7 @@
import io.microprofile.config.Config;
import io.microprofile.config.ConfigProvider;
-import org.apache.geronimo.config.tck.configsources.SampleYamlConfigSource;
+import io.microprofile.config.tck.configsources.SampleYamlConfigSource;
import org.testng.Assert;
import org.testng.annotations.Test;
diff --git a/tck/src/main/java/org/apache/geronimo/config/tck/ConfigSourceProviderTest.java b/tck/src/main/java/io/microprofile/config/tck/ConfigSourceProviderTest.java
similarity index 96%
rename from tck/src/main/java/org/apache/geronimo/config/tck/ConfigSourceProviderTest.java
rename to tck/src/main/java/io/microprofile/config/tck/ConfigSourceProviderTest.java
index 664d27d..28a65a9 100644
--- a/tck/src/main/java/org/apache/geronimo/config/tck/ConfigSourceProviderTest.java
+++ b/tck/src/main/java/io/microprofile/config/tck/ConfigSourceProviderTest.java
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.geronimo.config.tck;
+package io.microprofile.config.tck;
import io.microprofile.config.Config;
import io.microprofile.config.ConfigProvider;
diff --git a/tck/src/main/java/org/apache/geronimo/config/tck/ConfigValueTest.java b/tck/src/main/java/io/microprofile/config/tck/ConfigValueTest.java
similarity index 99%
rename from tck/src/main/java/org/apache/geronimo/config/tck/ConfigValueTest.java
rename to tck/src/main/java/io/microprofile/config/tck/ConfigValueTest.java
index 568650d..575f00a 100644
--- a/tck/src/main/java/org/apache/geronimo/config/tck/ConfigValueTest.java
+++ b/tck/src/main/java/io/microprofile/config/tck/ConfigValueTest.java
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.geronimo.config.tck;
+package io.microprofile.config.tck;
import io.microprofile.config.Config;
import io.microprofile.config.ConfigProvider;
diff --git a/tck/src/main/java/org/apache/geronimo/config/tck/ConverterTest.java b/tck/src/main/java/io/microprofile/config/tck/ConverterTest.java
similarity index 97%
rename from tck/src/main/java/org/apache/geronimo/config/tck/ConverterTest.java
rename to tck/src/main/java/io/microprofile/config/tck/ConverterTest.java
index dfa8e0b..bbb0419 100644
--- a/tck/src/main/java/org/apache/geronimo/config/tck/ConverterTest.java
+++ b/tck/src/main/java/io/microprofile/config/tck/ConverterTest.java
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.geronimo.config.tck;
+package io.microprofile.config.tck;
import io.microprofile.config.Config;
import io.microprofile.config.ConfigProvider;
diff --git a/tck/src/main/java/org/apache/geronimo/config/tck/CustomConfigSourceTest.java b/tck/src/main/java/io/microprofile/config/tck/CustomConfigSourceTest.java
similarity index 96%
rename from tck/src/main/java/org/apache/geronimo/config/tck/CustomConfigSourceTest.java
rename to tck/src/main/java/io/microprofile/config/tck/CustomConfigSourceTest.java
index 83b0758..5a8d80d 100644
--- a/tck/src/main/java/org/apache/geronimo/config/tck/CustomConfigSourceTest.java
+++ b/tck/src/main/java/io/microprofile/config/tck/CustomConfigSourceTest.java
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.geronimo.config.tck;
+package io.microprofile.config.tck;
import io.microprofile.config.Config;
import io.microprofile.config.ConfigProvider;
diff --git a/tck/src/main/java/org/apache/geronimo/config/tck/configfilters/PasswordConfigFilter.java b/tck/src/main/java/io/microprofile/config/tck/configfilters/PasswordConfigFilter.java
similarity index 96%
rename from tck/src/main/java/org/apache/geronimo/config/tck/configfilters/PasswordConfigFilter.java
rename to tck/src/main/java/io/microprofile/config/tck/configfilters/PasswordConfigFilter.java
index 4186b86..ef733cf 100644
--- a/tck/src/main/java/org/apache/geronimo/config/tck/configfilters/PasswordConfigFilter.java
+++ b/tck/src/main/java/io/microprofile/config/tck/configfilters/PasswordConfigFilter.java
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.geronimo.config.tck.configfilters;
+package io.microprofile.config.tck.configfilters;
import io.microprofile.config.spi.ConfigFilter;
diff --git a/tck/src/main/java/org/apache/geronimo/config/tck/configsources/CustomConfigSourceProvider.java b/tck/src/main/java/io/microprofile/config/tck/configsources/CustomConfigSourceProvider.java
similarity index 97%
rename from tck/src/main/java/org/apache/geronimo/config/tck/configsources/CustomConfigSourceProvider.java
rename to tck/src/main/java/io/microprofile/config/tck/configsources/CustomConfigSourceProvider.java
index 33691d0..2f2d0c4 100644
--- a/tck/src/main/java/org/apache/geronimo/config/tck/configsources/CustomConfigSourceProvider.java
+++ b/tck/src/main/java/io/microprofile/config/tck/configsources/CustomConfigSourceProvider.java
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.geronimo.config.tck.configsources;
+package io.microprofile.config.tck.configsources;
import java.io.IOException;
import java.net.URL;
diff --git a/tck/src/main/java/org/apache/geronimo/config/tck/configsources/CustomDbConfigSource.java b/tck/src/main/java/io/microprofile/config/tck/configsources/CustomDbConfigSource.java
similarity index 97%
rename from tck/src/main/java/org/apache/geronimo/config/tck/configsources/CustomDbConfigSource.java
rename to tck/src/main/java/io/microprofile/config/tck/configsources/CustomDbConfigSource.java
index a5741d5..83e27a1 100644
--- a/tck/src/main/java/org/apache/geronimo/config/tck/configsources/CustomDbConfigSource.java
+++ b/tck/src/main/java/io/microprofile/config/tck/configsources/CustomDbConfigSource.java
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.geronimo.config.tck.configsources;
+package io.microprofile.config.tck.configsources;
import java.util.HashMap;
import java.util.Map;
diff --git a/tck/src/main/java/org/apache/geronimo/config/tck/configsources/SampleYamlConfigSource.java b/tck/src/main/java/io/microprofile/config/tck/configsources/SampleYamlConfigSource.java
similarity index 96%
rename from tck/src/main/java/org/apache/geronimo/config/tck/configsources/SampleYamlConfigSource.java
rename to tck/src/main/java/io/microprofile/config/tck/configsources/SampleYamlConfigSource.java
index 2ea346b..4e7c4bb 100644
--- a/tck/src/main/java/org/apache/geronimo/config/tck/configsources/SampleYamlConfigSource.java
+++ b/tck/src/main/java/io/microprofile/config/tck/configsources/SampleYamlConfigSource.java
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.geronimo.config.tck.configsources;
+package io.microprofile.config.tck.configsources;
import java.net.URL;
import java.util.HashMap;
diff --git a/tck/src/main/java/org/apache/geronimo/config/tck/converters/Duck.java b/tck/src/main/java/io/microprofile/config/tck/converters/Duck.java
similarity index 95%
rename from tck/src/main/java/org/apache/geronimo/config/tck/converters/Duck.java
rename to tck/src/main/java/io/microprofile/config/tck/converters/Duck.java
index 18d0fb0..23a0542 100644
--- a/tck/src/main/java/org/apache/geronimo/config/tck/converters/Duck.java
+++ b/tck/src/main/java/io/microprofile/config/tck/converters/Duck.java
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.geronimo.config.tck.converters;
+package io.microprofile.config.tck.converters;
/**
* @author Mark Struberg
diff --git a/tck/src/main/java/org/apache/geronimo/config/tck/converters/DuckConverter.java b/tck/src/main/java/io/microprofile/config/tck/converters/DuckConverter.java
similarity index 95%
rename from tck/src/main/java/org/apache/geronimo/config/tck/converters/DuckConverter.java
rename to tck/src/main/java/io/microprofile/config/tck/converters/DuckConverter.java
index fe51b8d..b653fc1 100644
--- a/tck/src/main/java/org/apache/geronimo/config/tck/converters/DuckConverter.java
+++ b/tck/src/main/java/io/microprofile/config/tck/converters/DuckConverter.java
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.geronimo.config.tck.converters;
+package io.microprofile.config.tck.converters;
import io.microprofile.config.spi.Converter;
diff --git a/tck/src/main/resources/META-INF/services/io.microprofile.config.spi.ConfigFilter b/tck/src/main/resources/META-INF/services/io.microprofile.config.spi.ConfigFilter
index 6aff602..81487b7 100644
--- a/tck/src/main/resources/META-INF/services/io.microprofile.config.spi.ConfigFilter
+++ b/tck/src/main/resources/META-INF/services/io.microprofile.config.spi.ConfigFilter
@@ -17,4 +17,4 @@
# under the License.
#
-org.apache.geronimo.config.tck.configfilters.PasswordConfigFilter
\ No newline at end of file
+io.microprofile.config.tck.configfilters.PasswordConfigFilter
\ No newline at end of file
diff --git a/tck/src/main/resources/META-INF/services/io.microprofile.config.spi.ConfigSource b/tck/src/main/resources/META-INF/services/io.microprofile.config.spi.ConfigSource
index 16d2f7b..677a9fb 100644
--- a/tck/src/main/resources/META-INF/services/io.microprofile.config.spi.ConfigSource
+++ b/tck/src/main/resources/META-INF/services/io.microprofile.config.spi.ConfigSource
@@ -17,4 +17,4 @@
# under the License.
#
-org.apache.geronimo.config.tck.configsources.CustomDbConfigSource
\ No newline at end of file
+io.microprofile.config.tck.configsources.CustomDbConfigSource
\ No newline at end of file
diff --git a/tck/src/main/resources/META-INF/services/io.microprofile.config.spi.ConfigSourceProvider b/tck/src/main/resources/META-INF/services/io.microprofile.config.spi.ConfigSourceProvider
index d2fc399..bbcd7a0 100644
--- a/tck/src/main/resources/META-INF/services/io.microprofile.config.spi.ConfigSourceProvider
+++ b/tck/src/main/resources/META-INF/services/io.microprofile.config.spi.ConfigSourceProvider
@@ -17,4 +17,4 @@
# under the License.
#
-org.apache.geronimo.config.tck.configsources.CustomConfigSourceProvider
\ No newline at end of file
+io.microprofile.config.tck.configsources.CustomConfigSourceProvider
\ No newline at end of file
From 1d9491361ec39a50a107ffb252f5b41ec0e6080f Mon Sep 17 00:00:00 2001
From: Mark Struberg
Date: Sun, 15 Jan 2017 22:30:04 +0100
Subject: [PATCH 17/37] remove ConfigFilter as any secrets will be handled in
an own proposal
---
README.adoc | 2 +-
.../java/io/microprofile/config/Config.java | 14 ----
.../microprofile/config/ConfigProvider.java | 2 -
.../microprofile/config/spi/ConfigFilter.java | 52 -------------
.../apache/geronimo/config/ConfigImpl.java | 35 +--------
.../geronimo/config/ConfigValueImpl.java | 2 +-
.../geronimo/config/DefaultConfigBuilder.java | 18 -----
spec/src/main/asciidoc/configfilters.asciidoc | 75 -------------------
.../microprofile-config-spec.asciidoc | 2 -
.../config/tck/ConfigFilterTest.java | 48 ------------
.../configfilters/PasswordConfigFilter.java | 47 ------------
.../resources/META-INF/java-config.properties | 3 -
.../io.microprofile.config.spi.ConfigFilter | 20 -----
13 files changed, 4 insertions(+), 316 deletions(-)
delete mode 100644 api/src/main/java/io/microprofile/config/spi/ConfigFilter.java
delete mode 100644 spec/src/main/asciidoc/configfilters.asciidoc
delete mode 100644 tck/src/main/java/io/microprofile/config/tck/ConfigFilterTest.java
delete mode 100644 tck/src/main/java/io/microprofile/config/tck/configfilters/PasswordConfigFilter.java
delete mode 100644 tck/src/main/resources/META-INF/services/io.microprofile.config.spi.ConfigFilter
diff --git a/README.adoc b/README.adoc
index 63fb9be..5f6c584 100644
--- a/README.adoc
+++ b/README.adoc
@@ -34,7 +34,7 @@ But be able to overwrite those default values from external.
This very configuration approach has it's roots in the Apache OpenWebBeans internal SPI configuration.
In 2010 it got moved over to the Apache MyFaces CODI project and enhanced to also fit the need of customer projects by Gerhard Petracek and Mark Struberg.
-In 2012 we further enhanced it while moving CODI to the Apache DeltaSpike project.
+In 2011 we further enhanced it while moving CODI to the Apache DeltaSpike project.
Romain Manni-Bucau (Apache/Tomitribe), Ron Smeral (JBoss) and Anatole Tresch also gave appreciated input in the last years.
== How it works
diff --git a/api/src/main/java/io/microprofile/config/Config.java b/api/src/main/java/io/microprofile/config/Config.java
index 628de45..76e2e55 100644
--- a/api/src/main/java/io/microprofile/config/Config.java
+++ b/api/src/main/java/io/microprofile/config/Config.java
@@ -79,20 +79,6 @@ public interface Config {
*/
Map getAllProperties();
- /**
- * Filter the configured value.
- * This can e.g. be used for decryption.
- * @return the filtered value
- */
- String filterConfigValue(String key, String value);
-
- /**
- * Filter the configured value for logging.
- * This can e.g. be used for displaying ***** instead of a real password.
- * @return the filtered value
- */
- String filterConfigValueForLog(String key, String value);
-
/**
* @return all currently registered {@link ConfigSource}s
*/
diff --git a/api/src/main/java/io/microprofile/config/ConfigProvider.java b/api/src/main/java/io/microprofile/config/ConfigProvider.java
index 4cbf7ce..ae0f690 100644
--- a/api/src/main/java/io/microprofile/config/ConfigProvider.java
+++ b/api/src/main/java/io/microprofile/config/ConfigProvider.java
@@ -19,7 +19,6 @@
import java.util.ServiceLoader;
import java.util.logging.Logger;
-import io.microprofile.config.spi.ConfigFilter;
import io.microprofile.config.spi.ConfigSource;
import io.microprofile.config.spi.Converter;
@@ -122,7 +121,6 @@ public interface ConfigBuilder {
ConfigBuilder ignoreDefaultSources();
ConfigBuilder forClassLoader(ClassLoader loader);
ConfigBuilder withSources(ConfigSource... sources);
- ConfigBuilder withFilters(ConfigFilter... filters);
ConfigBuilder withConverters(Converter>... filters);
Config build();
}
diff --git a/api/src/main/java/io/microprofile/config/spi/ConfigFilter.java b/api/src/main/java/io/microprofile/config/spi/ConfigFilter.java
deleted file mode 100644
index 15a130b..0000000
--- a/api/src/main/java/io/microprofile/config/spi/ConfigFilter.java
+++ /dev/null
@@ -1,52 +0,0 @@
-/*
- * Licensed under the Apache License, Version 2.0 (the "License");
- * See the NOTICE file distributed with this work for additional information
- * regarding copyright ownership.
- * The author 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 io.microprofile.config.spi;
-
-import io.microprofile.config.Config;
-
-/**
- *
A filter which can be added to the
- * {@link Config}.
- * The filter can be used to decrypt config values or prepare
- * values for logging.
- *
- *
Registering a {@code ConfigFilter} can either be done via the
- * {@code java.util.ServiceLoader} pattern or by manually adding it via
- * {@link Config#addConfigFilter(ConfigFilter)}.
- *
- * @author Mark Struberg
- */
-public interface ConfigFilter
-{
- /**
- * Filter the given configuration value
- * @param key
- * @param value
- * @return the filtered value or the original input String if no filter shall be applied
- */
- String filterValue(String key, String value);
-
- /**
- * Filter the given configuration value for usage in logs.
- * This might be used to mask out passwords, etc.
- * @param key
- * @param value
- * @return the filtered value or the original input String if no filter shall be applied
- */
- String filterValueForLog(String key, String value);
-}
diff --git a/impl/src/main/java/org/apache/geronimo/config/ConfigImpl.java b/impl/src/main/java/org/apache/geronimo/config/ConfigImpl.java
index bab3494..a9feb00 100644
--- a/impl/src/main/java/org/apache/geronimo/config/ConfigImpl.java
+++ b/impl/src/main/java/org/apache/geronimo/config/ConfigImpl.java
@@ -30,7 +30,6 @@
import io.microprofile.config.Config;
import io.microprofile.config.ConfigValue;
-import io.microprofile.config.spi.ConfigFilter;
import io.microprofile.config.spi.ConfigSource;
import io.microprofile.config.spi.Converter;
import org.apache.geronimo.config.converters.BooleanConverter;
@@ -48,7 +47,6 @@ public class ConfigImpl implements Config {
protected Logger logger = Logger.getLogger(ConfigImpl.class.getName());
protected ConfigSource[] configSources = new ConfigSource[0];
- protected List configFilters = new ArrayList<>();
protected Map converters = new HashMap<>();
@@ -72,10 +70,10 @@ public String getValue(String key) {
if (value != null) {
if (logger.isLoggable(Level.FINE)) {
logger.log(Level.FINE, "found value {0} for key {1} in ConfigSource {2}.",
- new Object[]{filterConfigValueForLog(key, value), key, configSource.getConfigName()});
+ new Object[]{value, key, configSource.getConfigName()});
}
- return filterConfigValue(key, value);
+ return value;
}
}
return null;
@@ -118,34 +116,9 @@ public Map getAllProperties() {
result.putAll(configSource.getProperties());
}
- // now filter them
- for (Map.Entry entries : result.entrySet()) {
- entries.setValue(filterConfigValue(entries.getKey(), entries.getValue()));
- }
-
return Collections.unmodifiableMap(result);
}
- @Override
- public String filterConfigValue(String key, String value) {
- String filteredValue = value;
-
- for (ConfigFilter filter : configFilters) {
- filteredValue = filter.filterValue(key, filteredValue);
- }
- return filteredValue;
- }
-
- @Override
- public String filterConfigValueForLog(String key, String value) {
- String logValue = value;
-
- for (ConfigFilter filter : configFilters) {
- logValue = filter.filterValueForLog(key, logValue);
- }
-
- return logValue;
- }
@Override
public ConfigSource[] getConfigSources() {
@@ -160,10 +133,6 @@ public synchronized void addConfigSources(List configSourcesToAdd)
configSources = sortDescending(allConfigSources);
}
- public synchronized void addConfigFilter(ConfigFilter configFilter) {
- configFilters.add(configFilter);
-
- }
public synchronized void addConverter(Converter> converter) {
if (converter == null) {
diff --git a/impl/src/main/java/org/apache/geronimo/config/ConfigValueImpl.java b/impl/src/main/java/org/apache/geronimo/config/ConfigValueImpl.java
index 623390c..b552493 100644
--- a/impl/src/main/java/org/apache/geronimo/config/ConfigValueImpl.java
+++ b/impl/src/main/java/org/apache/geronimo/config/ConfigValueImpl.java
@@ -132,7 +132,7 @@ public T getValue() {
if (logChanges && (value != null && !value.equals(lastValue) || (value == null && lastValue != null)) )
{
logger.log(Level.INFO, "New value {0} for key {1}.",
- new Object[]{config.filterConfigValueForLog(keyOriginal, valueStr), keyOriginal});
+ new Object[]{valueStr, keyOriginal});
}
lastValue = value;
diff --git a/impl/src/main/java/org/apache/geronimo/config/DefaultConfigBuilder.java b/impl/src/main/java/org/apache/geronimo/config/DefaultConfigBuilder.java
index a84ac00..2d504d3 100644
--- a/impl/src/main/java/org/apache/geronimo/config/DefaultConfigBuilder.java
+++ b/impl/src/main/java/org/apache/geronimo/config/DefaultConfigBuilder.java
@@ -18,7 +18,6 @@
import io.microprofile.config.Config;
import io.microprofile.config.ConfigProvider;
-import io.microprofile.config.spi.ConfigFilter;
import io.microprofile.config.spi.ConfigSource;
import io.microprofile.config.spi.ConfigSourceProvider;
import io.microprofile.config.spi.Converter;
@@ -40,7 +39,6 @@
public class DefaultConfigBuilder implements ConfigProvider.ConfigBuilder {
protected ClassLoader forClassLoader;
private final List sources = new ArrayList<>();
- private final List filters = new ArrayList<>();
private final List> converters = new ArrayList<>();
private boolean ignoreDefaultSources = false;
@@ -62,12 +60,6 @@ public ConfigProvider.ConfigBuilder withSources(final ConfigSource... sources) {
return this;
}
- @Override
- public ConfigProvider.ConfigBuilder withFilters(final ConfigFilter... filters) {
- this.filters.addAll(asList(filters));
- return this;
- }
-
@Override
public ConfigProvider.ConfigBuilder withConverters(Converter>... converters) {
this.converters.addAll(asList(converters));
@@ -100,16 +92,6 @@ public Config build() {
ConfigImpl config = new ConfigImpl();
config.addConfigSources(configSources);
- // also register all ConfigFilters
- ServiceLoader configFilterLoader = ServiceLoader.load(ConfigFilter.class, forClassLoader);
- for (ConfigFilter configFilter : configFilterLoader) {
- config.addConfigFilter(configFilter);
- }
-
- for (ConfigFilter filter : filters) {
- config.addConfigFilter(filter);
- }
-
for (Converter> converter : converters) {
config.addConverter(converter);
}
diff --git a/spec/src/main/asciidoc/configfilters.asciidoc b/spec/src/main/asciidoc/configfilters.asciidoc
deleted file mode 100644
index b11f4e3..0000000
--- a/spec/src/main/asciidoc/configfilters.asciidoc
+++ /dev/null
@@ -1,75 +0,0 @@
-//
-// Licensed under the Apache License, Version 2.0 (the "License").
-// See the NOTICE file distributed with this work
-// for additional information regarding copyright ownership.
-// The author 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.
-//
-
-[[configfilters]]
-== ConfigFilters
-
-A `ConfigFilter` acts as a valve which is able to modify the configured values before they are returned to the caller.
-
-An implementation of the specification is not required to ship with any `ConfigFilters` enabled by default.
-
-A custom `ConfigFilter` must implement the interface `io.microprofile.config.spi.ConfigFilter` and is typically registered in a classpath resource `/META-INF/services/io.microprofile.config.spi.ConfigFilter` by including the fully-qualified class name of the custom implementation (well-known Java SE `java.util.ServiceLoader` mechanism).
-
-Alternatively a user can register a `ConfigFilter` manually via `void Config#addConfigFilter(ConfigFilter configFilterToAdd)`.
-
-=== Filtering a value for Usage
-
-A `ConfigFilter` can e.g. be used to decrypt a stored password on the fly:
-
-[source, java]
-----
-public class PasswordDecryptionConfigFilter implements ConfigFilter {
- @Override
- public String filterValue(String key, String value) {
- if (value != null && key.endsWith(".password")) {
- return decrypt(value);
- }
- return value;
- }
-
- @Override
- public String filterValueForLog(String key, String value) {
- // do nothing
- return value;
- }
-}
-----
-
-=== Filtering a value for Logging
-
-To prevent passwords and other secret information from being printed out or logged, a `ConfigFilter` can be used to mask those values.
-
-[source, java]
-----
-public class PasswordConfigFilter implements ConfigFilter {
- @Override
- public String filterValue(String key, String value) {
- // do nothing
- return value;
- }
-
- @Override
- public String filterValueForLog(String key, String value) {
- if (value != null &&
- (key.contains("password") || key.contains("secret"))) {
- return "*******"; // simply star-out the password
- }
- return value;
- }
-}
-
-----
diff --git a/spec/src/main/asciidoc/microprofile-config-spec.asciidoc b/spec/src/main/asciidoc/microprofile-config-spec.asciidoc
index f01ac12..187c9a5 100644
--- a/spec/src/main/asciidoc/microprofile-config-spec.asciidoc
+++ b/spec/src/main/asciidoc/microprofile-config-spec.asciidoc
@@ -39,6 +39,4 @@ include::architecture.asciidoc[]
include::configsources.asciidoc[]
-include::configfilters.asciidoc[]
-
include::converters.asciidoc[]
diff --git a/tck/src/main/java/io/microprofile/config/tck/ConfigFilterTest.java b/tck/src/main/java/io/microprofile/config/tck/ConfigFilterTest.java
deleted file mode 100644
index d41b07d..0000000
--- a/tck/src/main/java/io/microprofile/config/tck/ConfigFilterTest.java
+++ /dev/null
@@ -1,48 +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 io.microprofile.config.tck;
-
-import io.microprofile.config.Config;
-import io.microprofile.config.ConfigProvider;
-import org.testng.Assert;
-import org.testng.annotations.Test;
-
-/**
- * @author Mark Struberg
- */
-public class ConfigFilterTest {
-
- @Test
- public void testConfigFiltering() {
- Config config = ConfigProvider.getConfig();
-
- // unfiltered
- Assert.assertEquals(config.getValue("tck.config.test.javaconfig.configfilter.my.secret"), "SOME_SECRET");
-
- // filtered
- Assert.assertEquals(config.getValue("tck.config.test.javaconfig.configfilter.my.password"), "some_password");
- }
-
- @Test
- public void testConfigFiltering_ForLogging() {
- Config config = ConfigProvider.getConfig();
-
- Assert.assertEquals(
- config.filterConfigValueForLog("tck.config.test.javaconfig.configfilter.my.password",
- config.getValue("tck.config.test.javaconfig.configfilter.my.password")), "*******");
- }
-}
diff --git a/tck/src/main/java/io/microprofile/config/tck/configfilters/PasswordConfigFilter.java b/tck/src/main/java/io/microprofile/config/tck/configfilters/PasswordConfigFilter.java
deleted file mode 100644
index ef733cf..0000000
--- a/tck/src/main/java/io/microprofile/config/tck/configfilters/PasswordConfigFilter.java
+++ /dev/null
@@ -1,47 +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 io.microprofile.config.tck.configfilters;
-
-import io.microprofile.config.spi.ConfigFilter;
-
-/**
- * @author Mark Struberg
- */
-public class PasswordConfigFilter implements ConfigFilter {
- @Override
- public String filterValue(String key, String value) {
- if (value != null && key.endsWith(".password")) {
- return decrypt(value);
- }
- return value;
- }
-
- @Override
- public String filterValueForLog(String key, String value) {
- if (value != null &&
- (key.contains("password") || key.contains("secret"))) {
- return "*******"; // simply star-out the password
- }
- return value;
- }
-
- private String decrypt(String value) {
- // Just to modify the string.
- // In reality the 'encryption' should be a bit stronger ;)
- return value.toLowerCase();
- }
-}
diff --git a/tck/src/main/resources/META-INF/java-config.properties b/tck/src/main/resources/META-INF/java-config.properties
index 879c8ee..8d478f9 100644
--- a/tck/src/main/resources/META-INF/java-config.properties
+++ b/tck/src/main/resources/META-INF/java-config.properties
@@ -24,9 +24,6 @@ tck.config.test.javaconfig.properties.key1=VALue1
tck.config.test.overwritten.in.custompropertyfile.key1=value from java-config.properties
-tck.config.test.javaconfig.configfilter.my.secret = SOME_SECRET
-tck.config.test.javaconfig.configfilter.my.password = SOME_PASSWORD
-
tck.config.test.javaconfig.converter.integervalue = 1234
tck.config.test.javaconfig.converter.floatvalue = 12.34
diff --git a/tck/src/main/resources/META-INF/services/io.microprofile.config.spi.ConfigFilter b/tck/src/main/resources/META-INF/services/io.microprofile.config.spi.ConfigFilter
deleted file mode 100644
index 81487b7..0000000
--- a/tck/src/main/resources/META-INF/services/io.microprofile.config.spi.ConfigFilter
+++ /dev/null
@@ -1,20 +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.
-#
-
-io.microprofile.config.tck.configfilters.PasswordConfigFilter
\ No newline at end of file
From ca43fd814f144d670deee1ce2f478804fecc1150 Mon Sep 17 00:00:00 2001
From: Mark Struberg
Date: Tue, 17 Jan 2017 08:40:59 +0100
Subject: [PATCH 18/37] tweak spec wording to say 'Application based on
ClassLoader'
---
spec/src/main/asciidoc/architecture.asciidoc | 21 +++++++++++++-------
spec/src/main/asciidoc/license-alv2.asciidoc | 6 +-----
2 files changed, 15 insertions(+), 12 deletions(-)
diff --git a/spec/src/main/asciidoc/architecture.asciidoc b/spec/src/main/asciidoc/architecture.asciidoc
index dfd96ed..13dd764 100644
--- a/spec/src/main/asciidoc/architecture.asciidoc
+++ b/spec/src/main/asciidoc/architecture.asciidoc
@@ -39,24 +39,31 @@ The `ConfigProvider` is the central class to access a configuration.
It allows access to different configurations (represented by a `Config` instance) based on the application in which it is used.
We distinguish 3 different ways to resolve a `Config` instance:
-* A factory method `ConfigProvider#getConfig()` to create a `Config` object based on automatically picked up `ConfigSource` s from the current Thread Context ClassLoader classpath.
- Subsequent calls to this method for a certain ClassLoader will return the same `Config` instance.
+* A factory method `ConfigProvider#getConfig()` to create a `Config` object based on automatically picked up `ConfigSources`
+ of the Application identified by the current Thread Context ClassLoader classpath.
+ Subsequent calls to this method for a certain Application will return the same `Config` instance.
-* A factory method `ConfigProvider#getConfig(ClassLoader forClassLoader)` to create a `Config` object based on automatically picked up `ConfigSource` s from a given ClassLoader.
+* A factory method `ConfigProvider#getConfig(ClassLoader forClassLoader)` to create a `Config` object based on automatically picked up `ConfigSources`
+ of the Application identified by the given ClassLoader.
This can be used if the Thread Context ClassLoader does not represent the correct layer.
E.g. if you need the Config for a class in a shared EAR lib folder.
- Subsequent calls to this method for a certain ClassLoader will return the same `Config` instance.
+ Subsequent calls to this method for a certain Application will return the same `Config` instance.
* A factory method `ConfigProvider#newConfig()` to create an empty `Config` object which can be filled manually via a builder.
This configuration instance will not be shared by the `ConfigProvider`.
This method is intended be used if a IoT container or any other external Factory can be used to give access to a manually created shared `Config`.
+* A factory method `ConfigProvider#registerConfig()` to create an empty `Config` object which can be filled manually via a builder.
+ This configuration instance *will* be shared by the `ConfigProvider`.
+ Any subsequent call to `ConfigProvider#getConfig()` will return the registered `Config` instance.
+
+
All methods in the `ConfigProvider` and `Config` implementations are thread safe and reentrant.
-If a `Config` is bound to a ClassLoader it must be made sure that it gets properly removed if the ClassLoader gets destroyed.
-It must not create any memory leaks in that case.
+If a `Config` is bound to an Application it is ensured that it gets properly removed if the Application gets destroyed.
+The Config system deos not create any memory leaks in that case.
-A `Config` can be release by calling `ConfigProvider#release(Config)`.
+A `Config` can be release manually by calling `ConfigProvider#release(Config)`.
ConfigSources which implement the `java.io.Closeable` interface will be properly destroyed.
Any subsequent call to `ConfigProvider#getConfig()` or `ConfigProvider#getConfig(ClassLoader forClassLoader)` will result in a new `Config` instance.
diff --git a/spec/src/main/asciidoc/license-alv2.asciidoc b/spec/src/main/asciidoc/license-alv2.asciidoc
index 9dab241..ff9d5f6 100644
--- a/spec/src/main/asciidoc/license-alv2.asciidoc
+++ b/spec/src/main/asciidoc/license-alv2.asciidoc
@@ -28,11 +28,7 @@ Specification Lead: Mark Struberg
Release: {revdate}
-Copyright 2016 Original Authors,
-Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements.
-Licensed to the Microprofile.io community.
-
-
+Copyright 2016-2017 Original Authors,
Licensed 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
From f880b0d523f0a86746086c5297bc355c86cc3afd Mon Sep 17 00:00:00 2001
From: Mark Struberg
Date: Tue, 17 Jan 2017 09:52:33 +0100
Subject: [PATCH 19/37] rework spec.
Also add Emily as she seems to be the designated feature leader within microprofile
---
spec/src/main/asciidoc/architecture.asciidoc | 70 ++--------------
.../src/main/asciidoc/configexamples.asciidoc | 84 +++++++++++++++++++
.../src/main/asciidoc/configprovider.asciidoc | 53 ++++++++++++
spec/src/main/asciidoc/configsources.asciidoc | 12 ++-
spec/src/main/asciidoc/converters.asciidoc | 4 +-
spec/src/main/asciidoc/license-alv2.asciidoc | 2 +-
.../microprofile-config-spec.asciidoc | 4 +
7 files changed, 158 insertions(+), 71 deletions(-)
create mode 100644 spec/src/main/asciidoc/configexamples.asciidoc
create mode 100644 spec/src/main/asciidoc/configprovider.asciidoc
diff --git a/spec/src/main/asciidoc/architecture.asciidoc b/spec/src/main/asciidoc/architecture.asciidoc
index 13dd764..b715436 100644
--- a/spec/src/main/asciidoc/architecture.asciidoc
+++ b/spec/src/main/asciidoc/architecture.asciidoc
@@ -24,54 +24,18 @@ It also defines a way to extend the configuration mechanism itself via a SPI (Se
=== Rational
Released binaries often contain functionality which need to behave slightly differently depending on the deployment.
-This might be different REST endpoints to talk with (e.g. depending on the customer for whom a WAR is deployed).
+This might be different REST endpoints to talk to (e.g. depending on the customer for whom a WAR is deployed).
Or it might even be different features which need to be switched on and off depending on the installation.
All this must be possible without the need to re-package the whole application binary.
-Microprofile-Config provides a way to achieve this goal by aggregating configuration from many different sources and presents a single merged view to the user.
+Microprofile-Config provides a way to achieve this goal by aggregating configuration from many different <> and presents a single merged view to the user.
This allows the application to bundle default configuration within the application.
It also allows to override the defaults from outside, e.g. via an environment variable a Java system property or via Docker.
Microprofile-Config also allows to implement and register own configuration sources in a portable way, e.g. for reading configuration values from a shared database in an application cluster.
-=== Accessing a certain Configuration
-
-The `ConfigProvider` is the central class to access a configuration.
-It allows access to different configurations (represented by a `Config` instance) based on the application in which it is used.
-We distinguish 3 different ways to resolve a `Config` instance:
-
-* A factory method `ConfigProvider#getConfig()` to create a `Config` object based on automatically picked up `ConfigSources`
- of the Application identified by the current Thread Context ClassLoader classpath.
- Subsequent calls to this method for a certain Application will return the same `Config` instance.
-
-* A factory method `ConfigProvider#getConfig(ClassLoader forClassLoader)` to create a `Config` object based on automatically picked up `ConfigSources`
- of the Application identified by the given ClassLoader.
- This can be used if the Thread Context ClassLoader does not represent the correct layer.
- E.g. if you need the Config for a class in a shared EAR lib folder.
- Subsequent calls to this method for a certain Application will return the same `Config` instance.
-
-* A factory method `ConfigProvider#newConfig()` to create an empty `Config` object which can be filled manually via a builder.
- This configuration instance will not be shared by the `ConfigProvider`.
- This method is intended be used if a IoT container or any other external Factory can be used to give access to a manually created shared `Config`.
-
-* A factory method `ConfigProvider#registerConfig()` to create an empty `Config` object which can be filled manually via a builder.
- This configuration instance *will* be shared by the `ConfigProvider`.
- Any subsequent call to `ConfigProvider#getConfig()` will return the registered `Config` instance.
-
-
-All methods in the `ConfigProvider` and `Config` implementations are thread safe and reentrant.
-
-If a `Config` is bound to an Application it is ensured that it gets properly removed if the Application gets destroyed.
-The Config system deos not create any memory leaks in that case.
-
-A `Config` can be release manually by calling `ConfigProvider#release(Config)`.
-ConfigSources which implement the `java.io.Closeable` interface will be properly destroyed.
-Any subsequent call to `ConfigProvider#getConfig()` or `ConfigProvider#getConfig(ClassLoader forClassLoader)` will result in a new `Config` instance.
-
-
-=== Configuration Lookup Mechanism Example
The core Microprofile-Config mechanism is purely String/String based.
-Type-safety is only provided on top of that by using the proper `Converter` before handing the value out to the caller.
+Type-safety is only provided on top of that by using the proper <> before handing the value out to the caller.
The configuration key might use dot-separated namespaces similar to Java package namespacing:
@@ -81,31 +45,7 @@ com.acme.myproject.someserver.url = http://some.server/some/endpoint
com.acme.myproject.someserver.port = 9085
com.acme.myproject.someserver.active = true
com.acme.other.stuff.name = Karl
+com.acme.myproject.notify.onerror=karl@mycompany,sue@mcompany
----
-An application can access this configuration via a `Config` instance.
-
-[source, java]
-----
-public class ConfigUsageSample {
-
- public void useTheConfig() {
- // get access to the Config instance
- Config config = ConfigProvider.getConfig();
- String serverUrl = config.getValue("com.acme.myproject.someserver.url");
- Integer serverPort = config.getValue("com.acme.myproject.someserver.port",
- Integer.class);
-
- callToServer(serverUrl, serverPort);
- }
-}
-----
-
-If you need to access a different server then you can e.g. change the configuration via a `-D` system property:
-
-[source, text]
-----
-$> java -jar some.jar -Dcom.acme.myproject.someserver.url=http://other.server/other/endpoint
-----
-
-Note that the way to inject this configuration into the application can be extended by providing custom `ConfigSource` s.
+Config keys are usually case sensitive.
diff --git a/spec/src/main/asciidoc/configexamples.asciidoc b/spec/src/main/asciidoc/configexamples.asciidoc
new file mode 100644
index 0000000..ab1a817
--- /dev/null
+++ b/spec/src/main/asciidoc/configexamples.asciidoc
@@ -0,0 +1,84 @@
+//
+// Licensed under the Apache License, Version 2.0 (the "License").
+// See the NOTICE file distributed with this work
+// for additional information regarding copyright ownership.
+// The author 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.
+//
+
+[[configexamples]]
+== Configuration Usage Examples
+
+An application can access it's configured values via a `Config` instance.
+Use the `ConfigProvider` to access the `Config` of an application.
+
+=== Simple Example
+
+[source, java]
+----
+public class ConfigUsageSample {
+
+ public void useTheConfig() {
+ // get access to the Config instance
+ Config config = ConfigProvider.getConfig();
+
+ String serverUrl = config.getValue("com.acme.myproject.someserver.url");
+ Integer serverPort = config.getValue("com.acme.myproject.someserver.port",
+ Integer.class);
+
+ callToServer(serverUrl, serverPort);
+ }
+}
+----
+
+If you need to access a different server then you can e.g. change the configuration via a `-D` system property:
+
+[source, text]
+----
+$> java -jar some.jar -Dcom.acme.myproject.someserver.url=http://other.server/other/endpoint
+----
+
+Note that the way to inject this configuration into the application can be extended by providing custom `ConfigSource` s.
+
+
+=== Some advanced features
+
+It is also possible to dynamically pick up values which might change at runtime.
+For example if the configured values get picked up from a custom <> which picks up it's values from a Database.
+
+[source, java]
+----
+public class DynamicConfigUsageSample {
+
+ private ConfigValue urlConfigCfg
+ = ConfigProvider.getConfig.access("com.acme.myproject.someserver.url")
+ .cacheFor(5, TimeUnit.MINUTES)
+ .logChanges(true)
+ .evaluateVariables(true);
+
+ private ConfigValue urlPortCfg
+ = ConfigProvider.getConfig.access("com.acme.myproject.someserver.url")
+ .as(Integer.class)
+ .cacheFor(5, TimeUnit.MINUTES)
+ .logChanges(true)
+ .evaluateVariables(true)
+ .withDefault(8080);
+
+ public void useTheConfig() {
+ callToServer(serverUrlCfg.getValue(), serverPortCfg.getValue());
+ }
+}
+----
+
+The `cacheFor(5, TimeUnit.MINUTES)` will have the `ConfigValue` behave like a local cache and thus reduce load on the configuration system.
+5 minutes after `getValue()` got called the last time any fresh value will get picked up.
+If `logChanges(true)` is set then any value change will get logged.
\ No newline at end of file
diff --git a/spec/src/main/asciidoc/configprovider.asciidoc b/spec/src/main/asciidoc/configprovider.asciidoc
new file mode 100644
index 0000000..77c7285
--- /dev/null
+++ b/spec/src/main/asciidoc/configprovider.asciidoc
@@ -0,0 +1,53 @@
+//
+// Licensed under the Apache License, Version 2.0 (the "License").
+// See the NOTICE file distributed with this work
+// for additional information regarding copyright ownership.
+// The author 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.
+//
+
+[[configprovider]]
+== Accessing or Creating a certain Configuration
+
+The `ConfigProvider` is the central class to access a configuration.
+It allows access to different configurations (represented by a `Config` instance) based on the application in which it is used.
+We distinguish 3 different ways to resolve a `Config` instance:
+
+* A factory method `ConfigProvider#getConfig()` to create a `Config` object based on automatically picked up `ConfigSources`
+ of the Application identified by the current Thread Context ClassLoader classpath.
+ Subsequent calls to this method for a certain Application will return the same `Config` instance.
+
+* A factory method `ConfigProvider#getConfig(ClassLoader forClassLoader)` to create a `Config` object based on automatically picked up `ConfigSources`
+ of the Application identified by the given ClassLoader.
+ This can be used if the Thread Context ClassLoader does not represent the correct layer.
+ E.g. if you need the Config for a class in a shared EAR lib folder.
+ Subsequent calls to this method for a certain Application will return the same `Config` instance.
+
+* A factory method `ConfigProvider#newConfig()` to create an empty `Config` object which can be filled manually via a builder.
+ This configuration instance will not be shared by the `ConfigProvider`.
+ This method is intended be used if a IoT container or any other external Factory can be used to give access to a manually created shared `Config`.
+
+* A factory method `ConfigProvider#registerConfig()` to create an empty `Config` object which can be filled manually via a builder.
+ This configuration instance *will* be shared by the `ConfigProvider`.
+ Any subsequent call to `ConfigProvider#getConfig()` will return the registered `Config` instance.
+
+
+All methods in the `ConfigProvider` and `Config` implementations are thread safe and reentrant.
+
+If a `Config` is bound to an Application it is ensured that it gets properly removed if the Application gets destroyed.
+The Config system deos not create any memory leaks in that case.
+
+A `Config` can be release manually by calling `ConfigProvider#release(Config)`.
+ConfigSources which implement the `java.io.Closeable` interface will be properly destroyed.
+Any subsequent call to `ConfigProvider#getConfig()` or `ConfigProvider#getConfig(ClassLoader forClassLoader)` will result in a new `Config` instance.
+
+<<<
\ No newline at end of file
diff --git a/spec/src/main/asciidoc/configsources.asciidoc b/spec/src/main/asciidoc/configsources.asciidoc
index f7f562d..22e5d85 100644
--- a/spec/src/main/asciidoc/configsources.asciidoc
+++ b/spec/src/main/asciidoc/configsources.asciidoc
@@ -15,8 +15,8 @@
// limitations under the License.
//
-[[configsources]]
-== ConfigSources
+[[configsource]]
+== ConfigSource
A `ConfigSource` is exactly what its name says: a source for configured values.
The `Config` uses all configured implementations of `ConfigSource` to look up the property in question.
@@ -39,12 +39,15 @@ config_ordinal = 120
com.acme.myproject.someserver.url = http://more_important.server/some/endpoint
----
+[[default_configsources]]
=== Default ConfigSources
A Microprofile-Config implementation must provide `ConfigSource` s for the following data out of the box:
* System properties (ordinal=400)
-* Environment properties (ordinal=300)
+* Environment properties (ordinal=300).
+ The built in `ConfigSource` for the environment provides an all upper-case fallback lookup where dots are replaced with underlines.
+ An environment setting `ACME_MYKEY=bla` machtches a lookup for `config.getValue("acme.mykey")`.
* A `ConfigSource` for each property file `META-INF/java-config.properties` found on the classpath. (default ordinal = 100)
=== Custom ConfigSources
@@ -122,6 +125,8 @@ Please note that a single `ConfigSource` should be either registered directly or
A `Config` instance provides no caching but iterates over all `ConfigSources` for each `getValue(String)` operation.
A `ConfigSource` is allowed to cache the underlying values itself.
+Users might use the `cacheFor(long, TimeUnit)` method of a `ConfigValue` to pick up values which might change at runtime without penetrating the configuration system.
+
=== Manually adding ConfigSources
@@ -129,3 +134,4 @@ A user can manually register `ConfigSource` s by using the method `void addConfi
This will add the given list to the already registered `ConfigSources` of the current `Config` instance.
The order in which the `ConfigSources` are evaluated when using `Config#getValue(String key)` is independent of the order in which they were added to the `Config`; this depends only on the `ordinal` values of the available `ConfigSources`.
+
diff --git a/spec/src/main/asciidoc/converters.asciidoc b/spec/src/main/asciidoc/converters.asciidoc
index fc0a642..0131c39 100644
--- a/spec/src/main/asciidoc/converters.asciidoc
+++ b/spec/src/main/asciidoc/converters.asciidoc
@@ -15,8 +15,8 @@
// limitations under the License.
//
-[[converters]]
-== Converters
+[[converter]]
+== Converter
For providing typeseafe configuration we need to convert from the configured Strings into target types.
This happens by providing `Converter` s in the `Config`.
diff --git a/spec/src/main/asciidoc/license-alv2.asciidoc b/spec/src/main/asciidoc/license-alv2.asciidoc
index ff9d5f6..276af0a 100644
--- a/spec/src/main/asciidoc/license-alv2.asciidoc
+++ b/spec/src/main/asciidoc/license-alv2.asciidoc
@@ -24,7 +24,7 @@ Version: {revnumber}
Status: {revremark}
-Specification Lead: Mark Struberg
+Specification Lead: Mark Struberg, Emily Jiang
Release: {revdate}
diff --git a/spec/src/main/asciidoc/microprofile-config-spec.asciidoc b/spec/src/main/asciidoc/microprofile-config-spec.asciidoc
index 187c9a5..eca5e96 100644
--- a/spec/src/main/asciidoc/microprofile-config-spec.asciidoc
+++ b/spec/src/main/asciidoc/microprofile-config-spec.asciidoc
@@ -37,6 +37,10 @@ include::license-alv2.asciidoc[]
include::architecture.asciidoc[]
+include::configexamples.asciidoc[]
+
+include::configprovider.asciidoc[]
+
include::configsources.asciidoc[]
include::converters.asciidoc[]
From bc854934f47f48efc2cc990da46e3270ad0ecb47 Mon Sep 17 00:00:00 2001
From: Mark Struberg
Date: Tue, 17 Jan 2017 10:40:29 +0100
Subject: [PATCH 20/37] add missing ()
txs to rmannibucau for the report!
---
spec/src/main/asciidoc/configexamples.asciidoc | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/spec/src/main/asciidoc/configexamples.asciidoc b/spec/src/main/asciidoc/configexamples.asciidoc
index ab1a817..3740cb1 100644
--- a/spec/src/main/asciidoc/configexamples.asciidoc
+++ b/spec/src/main/asciidoc/configexamples.asciidoc
@@ -60,13 +60,13 @@ For example if the configured values get picked up from a custom <
public class DynamicConfigUsageSample {
private ConfigValue urlConfigCfg
- = ConfigProvider.getConfig.access("com.acme.myproject.someserver.url")
+ = ConfigProvider.getConfig().access("com.acme.myproject.someserver.url")
.cacheFor(5, TimeUnit.MINUTES)
.logChanges(true)
.evaluateVariables(true);
private ConfigValue urlPortCfg
- = ConfigProvider.getConfig.access("com.acme.myproject.someserver.url")
+ = ConfigProvider.getConfig().access("com.acme.myproject.someserver.url")
.as(Integer.class)
.cacheFor(5, TimeUnit.MINUTES)
.logChanges(true)
From 210d6c7f49b2a0c96c5d5e2ed3fdd703f91273f8 Mon Sep 17 00:00:00 2001
From: Mark Struberg
Date: Tue, 17 Jan 2017 11:55:55 +0100
Subject: [PATCH 21/37] add @Inject for Config and fix sample
---
.../src/main/asciidoc/configexamples.asciidoc | 20 +++++++++++++------
.../src/main/asciidoc/configprovider.asciidoc | 8 ++++++--
2 files changed, 20 insertions(+), 8 deletions(-)
diff --git a/spec/src/main/asciidoc/configexamples.asciidoc b/spec/src/main/asciidoc/configexamples.asciidoc
index 3740cb1..4799e11 100644
--- a/spec/src/main/asciidoc/configexamples.asciidoc
+++ b/spec/src/main/asciidoc/configexamples.asciidoc
@@ -19,13 +19,13 @@
== Configuration Usage Examples
An application can access it's configured values via a `Config` instance.
-Use the `ConfigProvider` to access the `Config` of an application.
+A user can use the `ConfigProvider` to access the `Config` of an application or simply use `@Inject Config` within CDI managed components.
=== Simple Example
[source, java]
----
-public class ConfigUsageSample {
+ppublic class ConfigUsageSample {
public void useTheConfig() {
// get access to the Config instance
@@ -50,6 +50,7 @@ $> java -jar some.jar -Dcom.acme.myproject.someserver.url=http://other.server/ot
Note that the way to inject this configuration into the application can be extended by providing custom `ConfigSource` s.
+
=== Some advanced features
It is also possible to dynamically pick up values which might change at runtime.
@@ -57,21 +58,28 @@ For example if the configured values get picked up from a custom <
[source, java]
----
+@ApplicationScoped
public class DynamicConfigUsageSample {
- private ConfigValue urlConfigCfg
- = ConfigProvider.getConfig().access("com.acme.myproject.someserver.url")
+ private @Inject Config config;
+
+ private ConfigValue serverUrlCfg;
+ private ConfigValue serverPortCfg
+
+ @PostConstruct
+ private void init() {
+ serverUrlCfg= config.access("com.acme.myproject.someserver.url")
.cacheFor(5, TimeUnit.MINUTES)
.logChanges(true)
.evaluateVariables(true);
- private ConfigValue urlPortCfg
- = ConfigProvider.getConfig().access("com.acme.myproject.someserver.url")
+ serverPortCfg = config.access("com.acme.myproject.someserver.port")
.as(Integer.class)
.cacheFor(5, TimeUnit.MINUTES)
.logChanges(true)
.evaluateVariables(true)
.withDefault(8080);
+ }
public void useTheConfig() {
callToServer(serverUrlCfg.getValue(), serverPortCfg.getValue());
diff --git a/spec/src/main/asciidoc/configprovider.asciidoc b/spec/src/main/asciidoc/configprovider.asciidoc
index 77c7285..ce39eb4 100644
--- a/spec/src/main/asciidoc/configprovider.asciidoc
+++ b/spec/src/main/asciidoc/configprovider.asciidoc
@@ -18,9 +18,13 @@
[[configprovider]]
== Accessing or Creating a certain Configuration
-The `ConfigProvider` is the central class to access a configuration.
+
+For manually accessing the `ConfigProvider` is the central class to access a configuration.
It allows access to different configurations (represented by a `Config` instance) based on the application in which it is used.
-We distinguish 3 different ways to resolve a `Config` instance:
+We distinguish 5 different ways to create or `Config` instance:
+
+* In CDI manged components a user can use `@Inject` to access the current application configuration.
+ If no configuration is registered the automatic discovery of <> will be performed.
* A factory method `ConfigProvider#getConfig()` to create a `Config` object based on automatically picked up `ConfigSources`
of the Application identified by the current Thread Context ClassLoader classpath.
From d322b3a35589bb73ec9bbe95e89be3f8341b1d88 Mon Sep 17 00:00:00 2001
From: Mark Struberg
Date: Thu, 26 Jan 2017 08:40:50 +0100
Subject: [PATCH 22/37] add list handling
---
api/pom.xml | 1 +
.../main/java/io/microprofile/config/ConfigValue.java | 9 +++++++++
.../config/tck/configsources/SampleYamlConfigSource.java | 2 +-
3 files changed, 11 insertions(+), 1 deletion(-)
diff --git a/api/pom.xml b/api/pom.xml
index 5a5765b..3a68c25 100644
--- a/api/pom.xml
+++ b/api/pom.xml
@@ -39,4 +39,5 @@
+
diff --git a/api/src/main/java/io/microprofile/config/ConfigValue.java b/api/src/main/java/io/microprofile/config/ConfigValue.java
index ddf0d91..d93b95b 100644
--- a/api/src/main/java/io/microprofile/config/ConfigValue.java
+++ b/api/src/main/java/io/microprofile/config/ConfigValue.java
@@ -103,6 +103,15 @@ public interface ConfigValue {
*/
T getValue();
+ /**
+ * Resolves the value and split it on each comma (',') character.
+ * If a comma is contained in the values it must get escaped with a preceding backslash ("\,").
+ * Any backslash needs to get escaped via double-backslash ("\\").
+ *
+ * @return the list of configured comma separated values or an empty Iterable if no
+ */
+ Iterable getValueList();
+
/**
* Returns the key given in {@link Config#access(String)}.
* @return the original key
diff --git a/tck/src/main/java/io/microprofile/config/tck/configsources/SampleYamlConfigSource.java b/tck/src/main/java/io/microprofile/config/tck/configsources/SampleYamlConfigSource.java
index 4e7c4bb..1d64de5 100644
--- a/tck/src/main/java/io/microprofile/config/tck/configsources/SampleYamlConfigSource.java
+++ b/tck/src/main/java/io/microprofile/config/tck/configsources/SampleYamlConfigSource.java
@@ -34,7 +34,7 @@ public SampleYamlConfigSource(URL url) {
@Override
public int getOrdinal() {
- return 110;
+ return config.get("ordinal") != null ? Integer.valueOf(config.get("ordinal")) : 110;
}
@Override
From b8f480d11472d83603030ab765df424814d536cb Mon Sep 17 00:00:00 2001
From: Mark Struberg
Date: Fri, 10 Mar 2017 00:14:04 +0100
Subject: [PATCH 23/37] adopt to microprofile API + fix a few things
---
api/pom.xml | 43 ----
.../java/io/microprofile/config/Config.java | 87 --------
.../microprofile/config/ConfigProvider.java | 198 ------------------
.../io/microprofile/config/ConfigValue.java | 139 ------------
.../microprofile/config/spi/ConfigSource.java | 99 ---------
.../config/spi/ConfigSourceProvider.java | 46 ----
.../io/microprofile/config/spi/Converter.java | 51 -----
impl/pom.xml | 12 +-
.../apache/geronimo/config/ConfigImpl.java | 36 ++--
.../geronimo/config/ConfigValueImpl.java | 133 ++++++------
.../geronimo/config/DefaultConfigBuilder.java | 36 ++--
.../config/DefaultConfigProvider.java | 20 +-
.../ManualApplicationConfigBuilder.java | 6 +-
.../config/configsource/BaseConfigSource.java | 7 +-
.../PropertyFileConfigSource.java | 6 +-
.../PropertyFileConfigSourceProvider.java | 4 +-
.../configsource/SystemEnvConfigSource.java | 6 +-
.../SystemPropertyConfigSource.java | 6 +-
.../config/converters/BooleanConverter.java | 2 +-
.../config/converters/DoubleConverter.java | 2 +-
.../config/converters/FloatConverter.java | 2 +-
.../config/converters/IntegerConverter.java | 2 +-
.../config/converters/LongConverter.java | 2 +-
...profile.config.spi.ConfigProviderResolver} | 0
impl/tck-suite.xml | 2 +-
pom.xml | 7 +-
spec/pom.xml | 98 ---------
spec/src/main/asciidoc/architecture.asciidoc | 51 -----
.../src/main/asciidoc/configexamples.asciidoc | 92 --------
.../src/main/asciidoc/configprovider.asciidoc | 57 -----
spec/src/main/asciidoc/configsources.asciidoc | 137 ------------
spec/src/main/asciidoc/converters.asciidoc | 48 -----
spec/src/main/asciidoc/license-alv2.asciidoc | 44 ----
.../microprofile-config-spec.asciidoc | 46 ----
tck/pom.xml | 55 -----
.../config/tck/ConfigProviderTest.java | 148 -------------
.../config/tck/ConfigSourceProviderTest.java | 35 ----
.../config/tck/ConfigValueTest.java | 132 ------------
.../config/tck/ConverterTest.java | 46 ----
.../config/tck/CustomConfigSourceTest.java | 35 ----
.../CustomConfigSourceProvider.java | 47 -----
.../configsources/CustomDbConfigSource.java | 63 ------
.../configsources/SampleYamlConfigSource.java | 55 -----
.../config/tck/converters/Duck.java | 33 ---
.../config/tck/converters/DuckConverter.java | 30 ---
.../resources/META-INF/java-config.properties | 73 -------
.../io.microprofile.config.spi.ConfigSource | 20 --
...croprofile.config.spi.ConfigSourceProvider | 20 --
tck/src/main/resources/sampleconfig.yaml | 20 --
49 files changed, 151 insertions(+), 2188 deletions(-)
delete mode 100644 api/pom.xml
delete mode 100644 api/src/main/java/io/microprofile/config/Config.java
delete mode 100644 api/src/main/java/io/microprofile/config/ConfigProvider.java
delete mode 100644 api/src/main/java/io/microprofile/config/ConfigValue.java
delete mode 100644 api/src/main/java/io/microprofile/config/spi/ConfigSource.java
delete mode 100644 api/src/main/java/io/microprofile/config/spi/ConfigSourceProvider.java
delete mode 100644 api/src/main/java/io/microprofile/config/spi/Converter.java
rename impl/src/main/resources/META-INF/services/{io.microprofile.config.ConfigProvider$SPI => org.eclipse.microprofile.config.spi.ConfigProviderResolver} (100%)
delete mode 100644 spec/pom.xml
delete mode 100644 spec/src/main/asciidoc/architecture.asciidoc
delete mode 100644 spec/src/main/asciidoc/configexamples.asciidoc
delete mode 100644 spec/src/main/asciidoc/configprovider.asciidoc
delete mode 100644 spec/src/main/asciidoc/configsources.asciidoc
delete mode 100644 spec/src/main/asciidoc/converters.asciidoc
delete mode 100644 spec/src/main/asciidoc/license-alv2.asciidoc
delete mode 100644 spec/src/main/asciidoc/microprofile-config-spec.asciidoc
delete mode 100644 tck/pom.xml
delete mode 100644 tck/src/main/java/io/microprofile/config/tck/ConfigProviderTest.java
delete mode 100644 tck/src/main/java/io/microprofile/config/tck/ConfigSourceProviderTest.java
delete mode 100644 tck/src/main/java/io/microprofile/config/tck/ConfigValueTest.java
delete mode 100644 tck/src/main/java/io/microprofile/config/tck/ConverterTest.java
delete mode 100644 tck/src/main/java/io/microprofile/config/tck/CustomConfigSourceTest.java
delete mode 100644 tck/src/main/java/io/microprofile/config/tck/configsources/CustomConfigSourceProvider.java
delete mode 100644 tck/src/main/java/io/microprofile/config/tck/configsources/CustomDbConfigSource.java
delete mode 100644 tck/src/main/java/io/microprofile/config/tck/configsources/SampleYamlConfigSource.java
delete mode 100644 tck/src/main/java/io/microprofile/config/tck/converters/Duck.java
delete mode 100644 tck/src/main/java/io/microprofile/config/tck/converters/DuckConverter.java
delete mode 100644 tck/src/main/resources/META-INF/java-config.properties
delete mode 100644 tck/src/main/resources/META-INF/services/io.microprofile.config.spi.ConfigSource
delete mode 100644 tck/src/main/resources/META-INF/services/io.microprofile.config.spi.ConfigSourceProvider
delete mode 100644 tck/src/main/resources/sampleconfig.yaml
diff --git a/api/pom.xml b/api/pom.xml
deleted file mode 100644
index 3a68c25..0000000
--- a/api/pom.xml
+++ /dev/null
@@ -1,43 +0,0 @@
-
-
-
- 4.0.0
-
-
-
- org.apache.geronimo.config
- config-parent
- 0.1-SNAPSHOT
-
-
- org.apache.geronimo.config
- config-api
-
-
-
- Apache License, Version 2.0
- https://www.apache.org/licenses/LICENSE-2.0.txt
- repo
- A business-friendly OSS license
-
-
-
-
-
diff --git a/api/src/main/java/io/microprofile/config/Config.java b/api/src/main/java/io/microprofile/config/Config.java
deleted file mode 100644
index 76e2e55..0000000
--- a/api/src/main/java/io/microprofile/config/Config.java
+++ /dev/null
@@ -1,87 +0,0 @@
-/*
- * Licensed under the Apache License, Version 2.0 (the "License");
- * See the NOTICE file distributed with this work for additional information
- * regarding copyright ownership.
- * The author 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 io.microprofile.config;
-
-import java.util.Map;
-
-import io.microprofile.config.spi.ConfigSourceProvider;
-import io.microprofile.config.spi.Converter;
-import io.microprofile.config.spi.ConfigSource;
-
-/**
- *
Resolves configured values of properties by going through the list
- * of configured {@link ConfigSource}s and using the one with the highest ordinal.
- * If multiple {@link ConfigSource}s have the same ordinal, their order is undefined.
- *
- *
You can provide your own lookup paths by implementing and registering additional
- * {@link ConfigSource}s and {@link ConfigSourceProvider} implementations.
- *
- *
- * @see ConfigProvider to resolve the current configuration.
- *
- * @author Mark Struberg
- */
-public interface Config {
-
- /**
- * Create a {@link ConfigValue} to access the underlying configuration.
- *
- * @param key the property key
- */
- ConfigValue access(String key);
-
- /**
- * Resolves the value configured for the given key.
- *
- * @param key the property key
- *
- * @return the configured property value from the {@link ConfigSource} with the highest ordinal
- * or {@code null} if there is no configured value for it
- */
- String getValue(String key);
-
- /**
- * Resolves the value configured for the given key and convert it to the required asType.
- *
- * @param key
- * @param asType Also support parameterized Types?
- * @param
- * @return
- * @throws UnsupportedOperationException if there is no {@link Converter} registered for asType
- */
- T getValue(String key, Class asType);
-
- /**
- * Apply the
- * @return the String converted
- * @throws UnsupportedOperationException if there is no {@link Converter} registered for asType
- */
- T convert(String value, Class asType);
-
- /**
- * Returns a Map of all properties from all scannable config sources. The values of the properties reflect the
- * values that would be obtained by a call to {@link #getValue(java.lang.String)}, that is, the value of the
- * property from the ConfigSource with the highest ordinal.
- */
- Map getAllProperties();
-
- /**
- * @return all currently registered {@link ConfigSource}s
- */
- ConfigSource[] getConfigSources();
-
-}
diff --git a/api/src/main/java/io/microprofile/config/ConfigProvider.java b/api/src/main/java/io/microprofile/config/ConfigProvider.java
deleted file mode 100644
index ae0f690..0000000
--- a/api/src/main/java/io/microprofile/config/ConfigProvider.java
+++ /dev/null
@@ -1,198 +0,0 @@
-/*
- * Licensed under the Apache License, Version 2.0 (the "License");
- * See the NOTICE file distributed with this work for additional information
- * regarding copyright ownership.
- * The author 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 io.microprofile.config;
-
-import java.util.ServiceLoader;
-import java.util.logging.Logger;
-
-import io.microprofile.config.spi.ConfigSource;
-import io.microprofile.config.spi.Converter;
-
-/**
- *
This is the central class to access a {@link Config}.
- *
- *
A {@link Config} contains the configuration for a certain
- * situation. That might be the configuration found in a certain ClassLoader
- * or even a manually created Configuration
- *
- *
The default usage is to use {@link #getConfig()} to automatically
- * pick up the 'Configuration' for the Thread Context ClassLoader
- * (See {@link Thread#getContextClassLoader()}).
- *
- *
A 'Configuration' consists of the information collected from the registered
- * {@link ConfigSource}s. These {@link ConfigSource}s
- * get sorted according to their ordinal defined via {@link ConfigSource#getOrdinal()}.
- * That way it is possible to overwrite configuration with lower importance from outside.
- *
- *
It is also possible to register custom {@link ConfigSource}s to
- * flexibly extend the configuration mechanism. An example would be to pick up configuration values
- * from a database table./p>
- *
- *
- *
- * @author Mark Struberg
- * @author Romain Manni-Bucau
- */
-public class ConfigProvider {
-
- private static volatile SPI instance;
-
- /**
- * Provide a {@link Config} based on all {@link ConfigSource}s
- * of the current Thread Context ClassLoader (TCCL)
- *
- *
There is exactly a single Config instance per Application
- */
- public static Config getConfig() {
- return loadSpi().getConfig();
- }
-
- /**
- * Provide a {@link Config} based on all {@link ConfigSource}s
- * of the given ClassLoader.
- *
- *
There is exactly a single Config instance per Application. The Application get's identified via a ClassLoader
- */
- public static Config getConfig(ClassLoader forClassLoader) {
- return instance.getConfig(forClassLoader);
- }
-
- /**
- * Create a {@link ConfigBuilder} for providing a fresh {@link Config} instance.
- *
- * The ConfigProvider will not manage the Config instance internally.
- * That means that {@link #getConfig()} does not pick up a Config created that way.
- */
- public static ConfigBuilder newConfig() {
- return instance.newConfig();
- }
-
- /**
- * Create a {@link ConfigBuilder} for register a {@link Config} instance to a certain Application.
- * Invoking {@link ConfigBuilder#build()} will effectively register the Config.
- * Use {@link ConfigBuilder#forClassLoader(ClassLoader)} to define the application the Config should be for,
- * otherwise the current ThreadContextClassLoader will be used.
- *
- * A {@link Config} registered that way will get picked up on any subsequent call to {@link ConfigProvider#getConfig()}.
- *
- * @throws IllegalStateException if a {@link Config} has already been associated for the Application.
- */
- public static ConfigBuilder registerConfig() {
- return instance.registerConfig();
- }
-
-
- /**
- * A {@link Config} normally gets released if the ClassLoader it represents gets destroyed.
- * Invoke this method if you like to destroy the Config prematurely.
- */
- public static void releaseConfig(Config config) {
- instance.releaseConfig(config);
- }
-
-
- /**
- * Builder for manually creating an instance of a {@code Config}.
- *
- * @see ConfigProvider#newConfig()
- */
- public interface ConfigBuilder {
- ConfigBuilder ignoreDefaultSources();
- ConfigBuilder forClassLoader(ClassLoader loader);
- ConfigBuilder withSources(ConfigSource... sources);
- ConfigBuilder withConverters(Converter>... filters);
- Config build();
- }
-
- /**
- * This interface gets implemented internally by the Config library.
- * The implementation registers itself via {@link java.util.ServiceLoader} mechanism.
- * In an OSGi environment
- */
- public interface SPI {
- Config getConfig();
- Config getConfig(ClassLoader forClassLoader);
- ConfigBuilder newConfig();
- ConfigBuilder registerConfig();
- void releaseConfig(Config config);
- }
-
- /**
- * Attention, handle with care!
- * This method is not intended to be used from a user.
- * It is for integration with e.g. OSGi from within a BundleActivator.
- * TODO probably remove this and add native OSGi support later.
- */
- public static synchronized void setSPI(SPI newInstance) {
- instance = newInstance;
- }
-
- private static SPI loadSpi() {
- if (instance == null) {
- synchronized (SPI.class) {
- if (instance != null) {
- return instance;
- }
- ClassLoader cl = Thread.currentThread().getContextClassLoader();
- if (cl == null) {
- cl = SPI.class.getClassLoader();
- }
-
- SPI newInstance = loadSpi(cl);
-
- if (newInstance == null) {
- throw new IllegalStateException("No ConfigResolver SPI implementation found!");
- }
-
- instance = newInstance;
- }
- }
-
- return instance;
- }
-
- private static SPI loadSpi(ClassLoader cl) {
- if (cl == null) {
- return null;
- }
-
- // start from the root CL and go back down to the TCCL
- SPI instance = loadSpi(cl.getParent());
-
- if (instance == null) {
- ServiceLoader sl = ServiceLoader.load(SPI.class, cl);
- for (SPI spi : sl) {
- if (instance != null) {
- Logger.getLogger(ConfigProvider.class.getName())
- .warning("Multiple ConfigResolver SPIs found. Ignoring " + spi.getClass().getName());
- } else {
- instance = spi;
- }
- }
- }
- return instance;
- }
-
-
-}
diff --git a/api/src/main/java/io/microprofile/config/ConfigValue.java b/api/src/main/java/io/microprofile/config/ConfigValue.java
deleted file mode 100644
index d93b95b..0000000
--- a/api/src/main/java/io/microprofile/config/ConfigValue.java
+++ /dev/null
@@ -1,139 +0,0 @@
-/*
- * Licensed under the Apache License, Version 2.0 (the "License");
- * See the NOTICE file distributed with this work for additional information
- * regarding copyright ownership.
- * The author 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 io.microprofile.config;
-
-
-import java.util.concurrent.TimeUnit;
-
-/**
- * Accessor to a configured value.
- * It follows a builder pattern.
- *
- * Accessing the configured value is finally done via {@link #getValue()}
- *
- * @author Mark Struberg
- * @author Gerhard Petracek
- * @author Ron Smeral
- */
-public interface ConfigValue {
-
- /**
- * Sets the type of the configuration entry to the given class and returns this builder.
- * The default type of a ConfigValue is {@code String}.
- *
- * @param clazz The target type
- * @param The target type
- * @return This builder as a typed ConfigValue
- */
- ConfigValue as(Class clazz);
-
- /**
- * Sets the default value to use in case the resolution returns null.
- * @param value the default value
- * @return This builder
- */
- ConfigValue withDefault(T value);
-
- /**
- * Sets the default value to use in case the resolution returns null. Converts the given String to the type of
- * this resolver using the same method as used for the configuration entries.
- * @param value string value to be converted and used as default
- * @return This builder
- */
- ConfigValue withStringDefault(String value);
-
- /**
- * Specify that a resolved value will get cached for a certain amount of time.
- * After the time expires the next {@link #getValue()} will again resolve the value
- * from the underlying {@link Config}.
- *
- * @param value the amount of the TimeUnit to wait
- * @param timeUnit the TimeUnit for the value
- *
- * @return This builder
- */
- ConfigValue cacheFor(long value, TimeUnit timeUnit);
-
- /**
- * Whether to evaluate variables in configured values.
- * A variable starts with '${' and ends with '}', e.g.
- *
- * If 'evaluateVariables' is enabled, the result for the above key
- * {@code "mycompany.some.url"} would be:
- * {@code "http://localhost:8081/some/path"}
- * @param evaluateVariables whether to evaluate variables in values or not
- * @return This builder
- */
- ConfigValue evaluateVariables(boolean evaluateVariables);
-
- /**
- * Appends the resolved value of the given property to the key of this builder.
- * TODO further explain.
- * @return This builder
- */
- ConfigValue withLookupChain(String... postfixNames);
-
- /**
- * Whether to log picking up any value changes as INFO.
- *
- * @return This builder
- */
- ConfigValue logChanges(boolean logChanges);
-
- /**
- * Returns the converted resolved filtered value.
- * @return the resolved value
- */
- T getValue();
-
- /**
- * Resolves the value and split it on each comma (',') character.
- * If a comma is contained in the values it must get escaped with a preceding backslash ("\,").
- * Any backslash needs to get escaped via double-backslash ("\\").
- *
- * @return the list of configured comma separated values or an empty Iterable if no
- */
- Iterable getValueList();
-
- /**
- * Returns the key given in {@link Config#access(String)}.
- * @return the original key
- */
- String getKey();
-
- /**
- * Returns the actual key which led to successful resolution and corresponds to the resolved value. This applies
- * only when {@link #withLookupChain(String...)} is used.
- * Otherwise the resolved key should always be equal to the original key.
- * This method is provided for cases, when arameterized resolution is
- * requested but the value for such appended key is not found and some of the fallback keys is used.
- *
- * This should be called only after calling {@link #getValue()} otherwise the value is undefined (but likely
- * null).
- */
- String getResolvedKey();
-
- /**
- * Returns the default value provided by {@link #withDefault(Object)} or {@link #withStringDefault(String)}.
- * Returns null if no default was provided.
- * @return the default value or {@code null}
- */
- T getDefaultValue();
-}
diff --git a/api/src/main/java/io/microprofile/config/spi/ConfigSource.java b/api/src/main/java/io/microprofile/config/spi/ConfigSource.java
deleted file mode 100644
index 6340aea..0000000
--- a/api/src/main/java/io/microprofile/config/spi/ConfigSource.java
+++ /dev/null
@@ -1,99 +0,0 @@
-/*
- * Licensed under the Apache License, Version 2.0 (the "License");
- * See the NOTICE file distributed with this work for additional information
- * regarding copyright ownership.
- * The author 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 io.microprofile.config.spi;
-
-import java.util.Map;
-
-/**
- *
Implement this interfaces to provide a ConfigSource.
- * A ConfigSource provides properties from a specific place, like
- * JNDI configuration, a properties file, etc.
- * A ConfigSource is always read-only, any potential updates of the
- * configured values must be handled directly inside each ConfigSource.
- *
- *
The custom implementation can be 'registered' using a
- * {@link ConfigSourceProvider} or via the
- * {@link java.util.ServiceLoader} mechanism. In the later case
- * it must get registered via creating a
- * META-INF/services/javax.config.spi.ConfigSource
- * file and adding the fully qualified class name of your ConfigSource
- * implementation into it.
- *
- * @author Mark Struberg
- * @author Gerhard Petracek
- */
-public interface ConfigSource {
- /**
- * The default name for the ordinal field.
- * Any ConfigSource might use it's own though or even return a hardcoded
- * in {@link #getOrdinal()}.
- */
- String CONFIG_ORDINAL = "config_ordinal";
-
-
- /**
- * Lookup order:
- *
- *
- *
- * If a custom implementation should be invoked before the default implementations, use a value > 400
- *
- *
- * If a custom implementation should be invoked after the default implementations, use a value < 100
- *
- *
- *
- *
- *
- *
- *
Reordering of the default order of the config-sources:
- *
Example: If the properties file/s should be used before the other implementations,
- * you have to configure an ordinal > 400. That means, you have to add e.g. config_ordinal=401 to
- * /META-INF/java-config.properties . Hint: In case of property files every file is handled as independent
- * config-source, but all of them have ordinal 400 by default (and can be reordered in a fine-grained manner.
- *
- * @return the 'importance' aka ordinal of the configured values. The higher, the more important.
- */
- int getOrdinal();
-
- /**
- * Return properties contained in this config source.
- * @return Properties available in this config source.
- */
- Map getProperties();
-
- /**
- * @param key for the property
- * @return configured value or null if this ConfigSource doesn't provide any value for the given key.
- */
- String getPropertyValue(String key);
-
- /**
- * The name of the config might be used for logging or analysis of configured values.
- *
- * @return the 'name' of the configuration source, e.g. 'property-file mylocation/myproperty.properties'
- */
- String getConfigName();
-
-}
diff --git a/api/src/main/java/io/microprofile/config/spi/ConfigSourceProvider.java b/api/src/main/java/io/microprofile/config/spi/ConfigSourceProvider.java
deleted file mode 100644
index ca4e04c..0000000
--- a/api/src/main/java/io/microprofile/config/spi/ConfigSourceProvider.java
+++ /dev/null
@@ -1,46 +0,0 @@
-/*
- * Licensed under the Apache License, Version 2.0 (the "License");
- * See the NOTICE file distributed with this work for additional information
- * regarding copyright ownership.
- * The author 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 io.microprofile.config.spi;
-
-import java.util.List;
-
-/**
- *
Implement this interfaces to provide a ConfigSource provider which
- * is able to maintain multiple ConfigSources. This is e.g. needed if
- * there are multiple property files of a given name.
- *
- *
If a ConfigSource like JNDI only exists once, then there is no need
- * to implement it via the ConfigSourceProvider but should directly
- * expose a {@link ConfigSource}.
- *
- *
A ConfigSourceProvider will get picked up via the
- * {@link java.util.ServiceLoader} mechanism and must get registered via
- * META-INF/services/javax.config.spi.ConfigSourceProvider
- *
- * @author Mark Struberg
- */
-public interface ConfigSourceProvider
-{
-
- /**
- * @param forClassLoader the classloader which should be used if any is needed
- *
- * @return For each e.g. property file, we return a single ConfigSource or an empty list if no ConfigSource exists.
- */
- List getConfigSources(ClassLoader forClassLoader);
-}
diff --git a/api/src/main/java/io/microprofile/config/spi/Converter.java b/api/src/main/java/io/microprofile/config/spi/Converter.java
deleted file mode 100644
index b6565b5..0000000
--- a/api/src/main/java/io/microprofile/config/spi/Converter.java
+++ /dev/null
@@ -1,51 +0,0 @@
-/*
- * Licensed under the Apache License, Version 2.0 (the "License");
- * See the NOTICE file distributed with this work for additional information
- * regarding copyright ownership.
- * The author 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 io.microprofile.config.spi;
-
-/**
- *
A very simple interface for conversion of configuration values from String to any Java type.
- *
- *
A Converter can specify a {@link javax.annotation.Priority}.
- * If no priority is explicitly assigned, the value of 100 is assumed.
- *
- *
If multiple Converter get found the one with the highest priority will be used.
- *
- *
The Converter for the following types are automatically enabled:
- *
Float, a dot '.' is used to separate the fractional digits
- *
Double, a dot '.' is used to separate the fractional digits>
- *
- *
- *
- *
- * @author Mark Struberg
- * @author Ron Smeral
- * @author Gerhard Petracek
- */
-public interface Converter {
- /**
- * Returns the converted value of the configuration entry.
- * @param value The String property value to convert
- * @return Converted value
- */
- T convert(String value);
-
-}
diff --git a/impl/pom.xml b/impl/pom.xml
index 69d8a7c..618a423 100644
--- a/impl/pom.xml
+++ b/impl/pom.xml
@@ -32,15 +32,15 @@
- org.apache.geronimo.config
- config-api
- 0.1-SNAPSHOT
+ org.eclipse.microprofile.config.api
+ microprofile-config-api
+ 1.0-SNAPSHOT
- org.apache.geronimo.config
- config-tck
- 0.1-SNAPSHOT
+ org.eclipse.microprofile.config.tck
+ microprofile-config-tck
+ 1.0-SNAPSHOTtest
diff --git a/impl/src/main/java/org/apache/geronimo/config/ConfigImpl.java b/impl/src/main/java/org/apache/geronimo/config/ConfigImpl.java
index a9feb00..89bf067 100644
--- a/impl/src/main/java/org/apache/geronimo/config/ConfigImpl.java
+++ b/impl/src/main/java/org/apache/geronimo/config/ConfigImpl.java
@@ -23,15 +23,18 @@
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
+import java.util.HashSet;
import java.util.List;
import java.util.Map;
+import java.util.Optional;
+import java.util.Set;
import java.util.logging.Level;
import java.util.logging.Logger;
-import io.microprofile.config.Config;
-import io.microprofile.config.ConfigValue;
-import io.microprofile.config.spi.ConfigSource;
-import io.microprofile.config.spi.Converter;
+import org.eclipse.microprofile.config.Config;
+import org.eclipse.microprofile.config.ConfigValue;
+import org.eclipse.microprofile.config.spi.ConfigSource;
+import org.eclipse.microprofile.config.spi.Converter;
import org.apache.geronimo.config.converters.BooleanConverter;
import org.apache.geronimo.config.converters.DoubleConverter;
import org.apache.geronimo.config.converters.FloatConverter;
@@ -63,14 +66,18 @@ private void registerDefaultConverter() {
}
@Override
+ public Optional getString(String key) {
+ return Optional.ofNullable(getValue(key));
+ }
+
public String getValue(String key) {
for (ConfigSource configSource : configSources) {
- String value = configSource.getPropertyValue(key);
+ String value = configSource.getValue(key);
if (value != null) {
if (logger.isLoggable(Level.FINE)) {
logger.log(Level.FINE, "found value {0} for key {1} in ConfigSource {2}.",
- new Object[]{value, key, configSource.getConfigName()});
+ new Object[]{value, key, configSource.getName()});
}
return value;
@@ -80,12 +87,11 @@ public String getValue(String key) {
}
@Override
- public T getValue(String key, Class asType) {
+ public Optional getValue(String key, Class asType) {
String value = getValue(key);
- return convert(value, asType);
+ return Optional.ofNullable(convert(value, asType));
}
- @Override
public T convert(String value, Class asType) {
Converter converter = getConverter(asType);
if (value != null) {
@@ -104,22 +110,22 @@ private Converter getConverter(Class asType) {
}
public ConfigValue access(String key) {
- return new ConfigValueImpl<>(this, key);
+ return new ConfigValueImpl(this, key);
}
@Override
- public Map getAllProperties() {
- Map result = new HashMap();
+ public Iterable getPropertyNames() {
+ Set result = new HashSet<>();
for (int i = configSources.length; i > 0; i--) {
ConfigSource configSource = configSources[i];
- result.putAll(configSource.getProperties());
+ result.addAll(configSource.getProperties().keySet());
}
-
- return Collections.unmodifiableMap(result);
+ return result;
}
+
@Override
public ConfigSource[] getConfigSources() {
return configSources;
diff --git a/impl/src/main/java/org/apache/geronimo/config/ConfigValueImpl.java b/impl/src/main/java/org/apache/geronimo/config/ConfigValueImpl.java
index b552493..90f8884 100644
--- a/impl/src/main/java/org/apache/geronimo/config/ConfigValueImpl.java
+++ b/impl/src/main/java/org/apache/geronimo/config/ConfigValueImpl.java
@@ -16,17 +16,20 @@
*/
package org.apache.geronimo.config;
-import io.microprofile.config.ConfigValue;
-import io.microprofile.config.spi.Converter;
+import org.eclipse.microprofile.config.ConfigValue;
+import org.eclipse.microprofile.config.spi.Converter;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.NoSuchElementException;
+import java.util.Optional;
import java.util.concurrent.TimeUnit;
-import java.util.logging.Level;
import java.util.logging.Logger;
/**
* @author Mark Struberg
*/
-public class ConfigValueImpl implements ConfigValue {
+public class ConfigValueImpl implements ConfigValue {
private static final Logger logger = Logger.getLogger(ConfigValueImpl.class.getName());
private final ConfigImpl config;
@@ -39,19 +42,12 @@ public class ConfigValueImpl implements ConfigValue {
private String[] lookupChain;
- private boolean withDefault = false;
- private T defaultValue;
-
-
- private Converter> converter;
-
private boolean evaluateVariables = false;
- private boolean logChanges = false;
-
private long cacheTimeMs = -1;
private volatile long reloadAfter = -1;
private T lastValue = null;
+ private ConfigChanged valueChangeListener;
public ConfigValueImpl(ConfigImpl config, String key) {
this.config = config;
@@ -61,29 +57,9 @@ public ConfigValueImpl(ConfigImpl config, String key) {
@Override
public ConfigValue as(Class clazz) {
configEntryType = clazz;
- this.converter = null;
return (ConfigValue) this;
}
- @Override
- public ConfigValue withDefault(T value) {
- defaultValue = value;
- withDefault = true;
- return this;
- }
-
- @Override
- public ConfigValue withStringDefault(String value) {
- if (value == null || value.isEmpty())
- {
- throw new RuntimeException("Empty String or null supplied as string-default value for property "
- + keyOriginal);
- }
-
- defaultValue = convert(value);
- withDefault = true;
- return this;
- }
@Override
public ConfigValue cacheFor(long value, TimeUnit timeUnit) {
@@ -97,20 +73,76 @@ public ConfigValue evaluateVariables(boolean evaluateVariables) {
return this;
}
- @Override
public ConfigValue withLookupChain(String... postfixNames) {
this.lookupChain = postfixNames;
return this;
}
@Override
- public ConfigValue logChanges(boolean logChanges) {
- this.logChanges = logChanges;
+ public T get() {
+ T val = getValue();
+ if (val == null) {
+ throw new NoSuchElementException("No config value present for key " + keyOriginal);
+ }
+ return val;
+ }
+
+ @Override
+ public Optional getOptional() {
+ return Optional.ofNullable(getValue());
+ }
+
+ @Override
+ public ConfigValue onChange(ConfigChanged valueChangeListener) {
+ this.valueChangeListener = valueChangeListener;
return this;
}
@Override
+ public List getValueList() {
+ String rawList = (String) getValue(false);
+ List values = new ArrayList();
+ StringBuilder sb = new StringBuilder(64);
+ for (int i= 0; i < rawList.length(); i++) {
+ char c = rawList.charAt(i);
+ if ('\\' == c) {
+ if (i == rawList.length()) {
+ throw new IllegalStateException("incorrect escaping of key " + keyOriginal + " value: " + rawList);
+ }
+ char nextChar = rawList.charAt(i+1);
+ if (nextChar == '\\') {
+ sb.append('\\');
+ }
+ else if (nextChar == ',') {
+ sb.append(',');
+ }
+ i++;
+ }
+ else if (',' == c) {
+ addListValue(values, sb);
+ }
+ else {
+ sb.append(c);
+ }
+ }
+ addListValue(values, sb);
+
+ return values;
+ }
+
+ private void addListValue(List values, StringBuilder sb) {
+ String val = sb.toString().trim();
+ if (!val.isEmpty()) {
+ values.add(convert(val));
+ }
+ sb.setLength(0);
+ }
+
public T getValue() {
+ return getValue(true);
+ }
+
+ private T getValue(boolean convert) {
long now = -1;
if (cacheTimeMs > 0)
{
@@ -122,17 +154,11 @@ public T getValue() {
}
String valueStr = resolveStringValue();
- T value = convert(valueStr);
+ T value = convert ? convert(valueStr) : (T) valueStr;
- if (withDefault)
+ if (valueChangeListener != null && (value != null && !value.equals(lastValue) || (value == null && lastValue != null)) )
{
- value = fallbackToDefaultIfEmpty(keyResolved, value, defaultValue);
- }
-
- if (logChanges && (value != null && !value.equals(lastValue) || (value == null && lastValue != null)) )
- {
- logger.log(Level.INFO, "New value {0} for key {1}.",
- new Object[]{valueStr, keyOriginal});
+ valueChangeListener.onValueChange(keyOriginal, lastValue, value);
}
lastValue = value;
@@ -165,7 +191,7 @@ private String resolveStringValue() {
{
break;
}
- String variableValue = config.access(varName).evaluateVariables(true).withLookupChain(lookupChain).getValue();
+ String variableValue = config.access(varName).evaluateVariables(true).get();
if (variableValue != null)
{
value = value.replace("${" + varName + "}", variableValue);
@@ -186,11 +212,6 @@ public String getResolvedKey() {
return keyResolved;
}
- @Override
- public T getDefaultValue() {
- return defaultValue;
- }
-
private T convert(String value) {
if (String.class == configEntryType) {
return (T) value;
@@ -204,16 +225,4 @@ private T convert(String value) {
return (T) converter.convert(value);
}
- private T fallbackToDefaultIfEmpty(String key, T value, T defaultValue) {
- if (value == null || (value instanceof String && ((String)value).isEmpty()))
- {
- logger.log(Level.FINE, "no configured value found for key {0}, using default value {1}.",
- new Object[]{key, defaultValue});
-
- return defaultValue;
- }
-
- return value;
- }
-
}
diff --git a/impl/src/main/java/org/apache/geronimo/config/DefaultConfigBuilder.java b/impl/src/main/java/org/apache/geronimo/config/DefaultConfigBuilder.java
index 2d504d3..49fbad0 100644
--- a/impl/src/main/java/org/apache/geronimo/config/DefaultConfigBuilder.java
+++ b/impl/src/main/java/org/apache/geronimo/config/DefaultConfigBuilder.java
@@ -16,11 +16,11 @@
*/
package org.apache.geronimo.config;
-import io.microprofile.config.Config;
-import io.microprofile.config.ConfigProvider;
-import io.microprofile.config.spi.ConfigSource;
-import io.microprofile.config.spi.ConfigSourceProvider;
-import io.microprofile.config.spi.Converter;
+import org.eclipse.microprofile.config.Config;
+import org.eclipse.microprofile.config.spi.ConfigBuilder;
+import org.eclipse.microprofile.config.spi.ConfigSource;
+import org.eclipse.microprofile.config.spi.ConfigSourceProvider;
+import org.eclipse.microprofile.config.spi.Converter;
import org.apache.geronimo.config.configsource.PropertyFileConfigSourceProvider;
import org.apache.geronimo.config.configsource.SystemEnvConfigSource;
import org.apache.geronimo.config.configsource.SystemPropertyConfigSource;
@@ -36,32 +36,32 @@
* @author Romain Manni-Bucau
* @author Mark Struberg
*/
-public class DefaultConfigBuilder implements ConfigProvider.ConfigBuilder {
+public class DefaultConfigBuilder implements ConfigBuilder {
protected ClassLoader forClassLoader;
private final List sources = new ArrayList<>();
private final List> converters = new ArrayList<>();
- private boolean ignoreDefaultSources = false;
+ private boolean ignoreDefaultSources = true;
@Override
- public ConfigProvider.ConfigBuilder ignoreDefaultSources() {
- this.ignoreDefaultSources = true;
+ public ConfigBuilder addDefaultSources() {
+ this.ignoreDefaultSources = false;
return this;
}
@Override
- public ConfigProvider.ConfigBuilder forClassLoader(final ClassLoader loader) {
+ public ConfigBuilder forClassLoader(final ClassLoader loader) {
this.forClassLoader = loader;
return this;
}
@Override
- public ConfigProvider.ConfigBuilder withSources(final ConfigSource... sources) {
+ public ConfigBuilder withSources(final ConfigSource... sources) {
this.sources.addAll(asList(sources));
return this;
}
@Override
- public ConfigProvider.ConfigBuilder withConverters(Converter>... converters) {
+ public ConfigBuilder withConverters(Converter>... converters) {
this.converters.addAll(asList(converters));
return this;
}
@@ -78,15 +78,13 @@ public Config build() {
if (!ignoreDefaultSources) {
// load all ConfigSource services
ServiceLoader configSourceLoader = ServiceLoader.load(ConfigSource.class, forClassLoader);
- for (ConfigSource configSource : configSourceLoader) {
- configSources.add(configSource);
- }
+ configSourceLoader.forEach(configSource -> configSources.add(configSource));
// load all ConfigSources from ConfigSourceProviders
ServiceLoader configSourceProviderLoader = ServiceLoader.load(ConfigSourceProvider.class, forClassLoader);
- for (ConfigSourceProvider configSourceProvider : configSourceProviderLoader) {
- configSources.addAll(configSourceProvider.getConfigSources(forClassLoader));
- }
+ configSourceProviderLoader.forEach(configSourceProvider ->
+ configSourceProvider.getConfigSources(forClassLoader)
+ .forEach(configSource -> configSources.add(configSource)));
}
ConfigImpl config = new ConfigImpl();
@@ -104,7 +102,7 @@ protected Collection extends ConfigSource> getBuiltInConfigSources(ClassLoader
configSources.add(new SystemEnvConfigSource());
configSources.add(new SystemPropertyConfigSource());
- configSources.addAll(new PropertyFileConfigSourceProvider("META-INF/java-config.properties", true, forClassLoader).getConfigSources(forClassLoader));
+ configSources.addAll(new PropertyFileConfigSourceProvider("META-INF/microprofile-config.properties", true, forClassLoader).getConfigSources(forClassLoader));
return configSources;
}
diff --git a/impl/src/main/java/org/apache/geronimo/config/DefaultConfigProvider.java b/impl/src/main/java/org/apache/geronimo/config/DefaultConfigProvider.java
index 03adbff..0d280ed 100644
--- a/impl/src/main/java/org/apache/geronimo/config/DefaultConfigProvider.java
+++ b/impl/src/main/java/org/apache/geronimo/config/DefaultConfigProvider.java
@@ -21,16 +21,17 @@
import java.util.Iterator;
import java.util.Map;
import java.util.WeakHashMap;
-import io.microprofile.config.Config;
-import io.microprofile.config.ConfigProvider;
+import org.eclipse.microprofile.config.Config;
+import org.eclipse.microprofile.config.spi.ConfigBuilder;
+import org.eclipse.microprofile.config.spi.ConfigProviderResolver;
/**
* @author Mark Struberg
*/
-public class DefaultConfigProvider implements ConfigProvider.SPI {
+public class DefaultConfigProvider extends ConfigProviderResolver {
- protected static Map> configs
+ private static Map> configs
= Collections.synchronizedMap(new WeakHashMap>());
@@ -51,7 +52,7 @@ public Config getConfig(ClassLoader forClassLoader) {
synchronized (DefaultConfigProvider.class) {
config = existingConfig(forClassLoader);
if (config == null) {
- config = createConfig(forClassLoader);
+ config = getBuilder().forClassLoader(forClassLoader).addDefaultSources().build();
registerConfig(config, forClassLoader);
}
}
@@ -64,9 +65,6 @@ Config existingConfig(ClassLoader forClassLoader) {
return configRef != null ? configRef.get() : null;
}
- protected Config createConfig(ClassLoader forClassLoader) {
- return newConfig().forClassLoader(forClassLoader).build();
- }
void registerConfig(Config config, ClassLoader forClassLoader) {
synchronized (DefaultConfigProvider.class) {
@@ -75,13 +73,13 @@ void registerConfig(Config config, ClassLoader forClassLoader) {
}
@Override
- public ConfigProvider.ConfigBuilder newConfig() {
+ public ConfigBuilder getBuilder() {
return new DefaultConfigBuilder();
}
@Override
- public ConfigProvider.ConfigBuilder registerConfig() {
- return new ManualApplicationConfigBuilder(this);
+ public void setConfig(Config config, ClassLoader classLoader) {
+ registerConfig(config, classLoader);
}
@Override
diff --git a/impl/src/main/java/org/apache/geronimo/config/ManualApplicationConfigBuilder.java b/impl/src/main/java/org/apache/geronimo/config/ManualApplicationConfigBuilder.java
index 9b91edf..01ee075 100644
--- a/impl/src/main/java/org/apache/geronimo/config/ManualApplicationConfigBuilder.java
+++ b/impl/src/main/java/org/apache/geronimo/config/ManualApplicationConfigBuilder.java
@@ -16,8 +16,8 @@
*/
package org.apache.geronimo.config;
-import io.microprofile.config.Config;
-import io.microprofile.config.ConfigProvider;
+import org.eclipse.microprofile.config.Config;
+import org.eclipse.microprofile.config.spi.ConfigProviderResolver;
/**
* @author Mark Struberg
@@ -36,7 +36,7 @@ public synchronized Config build() {
if (cl == null) {
cl = Thread.currentThread().getContextClassLoader();
if (cl == null) {
- cl = ConfigProvider.SPI.class.getClassLoader();
+ cl = ConfigProviderResolver.class.getClassLoader();
}
}
Config oldConfig = configProvider.existingConfig(cl);
diff --git a/impl/src/main/java/org/apache/geronimo/config/configsource/BaseConfigSource.java b/impl/src/main/java/org/apache/geronimo/config/configsource/BaseConfigSource.java
index 9ffbc10..d7117be 100644
--- a/impl/src/main/java/org/apache/geronimo/config/configsource/BaseConfigSource.java
+++ b/impl/src/main/java/org/apache/geronimo/config/configsource/BaseConfigSource.java
@@ -21,7 +21,7 @@
import java.util.logging.Level;
import java.util.logging.Logger;
-import io.microprofile.config.spi.ConfigSource;
+import org.eclipse.microprofile.config.spi.ConfigSource;
/**
@@ -31,6 +31,9 @@
* @author Gerhard Petracek
*/
public abstract class BaseConfigSource implements ConfigSource {
+
+ public final static String CONFIG_ORDINAL = "config_ordinal";
+
protected Logger log = Logger.getLogger(getClass().getName());
private int ordinal = 1000; // default
@@ -50,7 +53,7 @@ public int getOrdinal() {
protected void initOrdinal(int defaultOrdinal) {
ordinal = defaultOrdinal;
- String configuredOrdinalString = getPropertyValue(ConfigSource.CONFIG_ORDINAL);
+ String configuredOrdinalString = getValue(CONFIG_ORDINAL);
try {
if (configuredOrdinalString != null) {
diff --git a/impl/src/main/java/org/apache/geronimo/config/configsource/PropertyFileConfigSource.java b/impl/src/main/java/org/apache/geronimo/config/configsource/PropertyFileConfigSource.java
index d98826d..7d86394 100644
--- a/impl/src/main/java/org/apache/geronimo/config/configsource/PropertyFileConfigSource.java
+++ b/impl/src/main/java/org/apache/geronimo/config/configsource/PropertyFileConfigSource.java
@@ -42,12 +42,12 @@ public PropertyFileConfigSource(URL propertyFileUrl) {
* @return value for the given key or null if there is no configured value
*/
@Override
- public String getPropertyValue(String key) {
- return (String) properties.get(key);
+ public String getValue(String key) {
+ return properties.get(key);
}
@Override
- public String getConfigName() {
+ public String getName() {
return fileName;
}
diff --git a/impl/src/main/java/org/apache/geronimo/config/configsource/PropertyFileConfigSourceProvider.java b/impl/src/main/java/org/apache/geronimo/config/configsource/PropertyFileConfigSourceProvider.java
index 6404f92..f4be5fa 100644
--- a/impl/src/main/java/org/apache/geronimo/config/configsource/PropertyFileConfigSourceProvider.java
+++ b/impl/src/main/java/org/apache/geronimo/config/configsource/PropertyFileConfigSourceProvider.java
@@ -26,8 +26,8 @@
import java.util.logging.Level;
import java.util.logging.Logger;
-import io.microprofile.config.spi.ConfigSource;
-import io.microprofile.config.spi.ConfigSourceProvider;
+import org.eclipse.microprofile.config.spi.ConfigSource;
+import org.eclipse.microprofile.config.spi.ConfigSourceProvider;
/**
diff --git a/impl/src/main/java/org/apache/geronimo/config/configsource/SystemEnvConfigSource.java b/impl/src/main/java/org/apache/geronimo/config/configsource/SystemEnvConfigSource.java
index bf5e171..1c31cc6 100644
--- a/impl/src/main/java/org/apache/geronimo/config/configsource/SystemEnvConfigSource.java
+++ b/impl/src/main/java/org/apache/geronimo/config/configsource/SystemEnvConfigSource.java
@@ -21,7 +21,7 @@
import java.util.Map;
-import io.microprofile.config.spi.ConfigSource;
+import org.eclipse.microprofile.config.spi.ConfigSource;
/**
* {@link ConfigSource} which uses {@link System#getenv()}
@@ -40,7 +40,7 @@ public SystemEnvConfigSource() {
}
@Override
- public String getConfigName() {
+ public String getName() {
return "system_env";
}
@@ -50,7 +50,7 @@ public Map getProperties() {
}
@Override
- public String getPropertyValue(String key) {
+ public String getValue(String key) {
String val = configValues.get(key);
if (val == null || val.isEmpty()) {
val = configValues.get(key.replace('.', '_'));
diff --git a/impl/src/main/java/org/apache/geronimo/config/configsource/SystemPropertyConfigSource.java b/impl/src/main/java/org/apache/geronimo/config/configsource/SystemPropertyConfigSource.java
index 73ce7f1..f5f8ea1 100644
--- a/impl/src/main/java/org/apache/geronimo/config/configsource/SystemPropertyConfigSource.java
+++ b/impl/src/main/java/org/apache/geronimo/config/configsource/SystemPropertyConfigSource.java
@@ -20,7 +20,7 @@
import java.util.Map;
-import io.microprofile.config.spi.ConfigSource;
+import org.eclipse.microprofile.config.spi.ConfigSource;
/**
* {@link ConfigSource} which uses {@link System#getProperties()}
@@ -38,12 +38,12 @@ public Map getProperties() {
}
@Override
- public String getPropertyValue(String key) {
+ public String getValue(String key) {
return System.getProperty(key);
}
@Override
- public String getConfigName() {
+ public String getName() {
return "system-properties";
}
}
diff --git a/impl/src/main/java/org/apache/geronimo/config/converters/BooleanConverter.java b/impl/src/main/java/org/apache/geronimo/config/converters/BooleanConverter.java
index 72e03b4..e2b5d3c 100644
--- a/impl/src/main/java/org/apache/geronimo/config/converters/BooleanConverter.java
+++ b/impl/src/main/java/org/apache/geronimo/config/converters/BooleanConverter.java
@@ -16,7 +16,7 @@
*/
package org.apache.geronimo.config.converters;
-import io.microprofile.config.spi.Converter;
+import org.eclipse.microprofile.config.spi.Converter;
import javax.annotation.Priority;
diff --git a/impl/src/main/java/org/apache/geronimo/config/converters/DoubleConverter.java b/impl/src/main/java/org/apache/geronimo/config/converters/DoubleConverter.java
index c32860f..c1eb6fb 100644
--- a/impl/src/main/java/org/apache/geronimo/config/converters/DoubleConverter.java
+++ b/impl/src/main/java/org/apache/geronimo/config/converters/DoubleConverter.java
@@ -16,7 +16,7 @@
*/
package org.apache.geronimo.config.converters;
-import io.microprofile.config.spi.Converter;
+import org.eclipse.microprofile.config.spi.Converter;
import javax.annotation.Priority;
diff --git a/impl/src/main/java/org/apache/geronimo/config/converters/FloatConverter.java b/impl/src/main/java/org/apache/geronimo/config/converters/FloatConverter.java
index fa7372a..1a4eaac 100644
--- a/impl/src/main/java/org/apache/geronimo/config/converters/FloatConverter.java
+++ b/impl/src/main/java/org/apache/geronimo/config/converters/FloatConverter.java
@@ -18,7 +18,7 @@
import javax.annotation.Priority;
-import io.microprofile.config.spi.Converter;
+import org.eclipse.microprofile.config.spi.Converter;
/**
* @author Mark Struberg
diff --git a/impl/src/main/java/org/apache/geronimo/config/converters/IntegerConverter.java b/impl/src/main/java/org/apache/geronimo/config/converters/IntegerConverter.java
index cb76c63..be32e8a 100644
--- a/impl/src/main/java/org/apache/geronimo/config/converters/IntegerConverter.java
+++ b/impl/src/main/java/org/apache/geronimo/config/converters/IntegerConverter.java
@@ -18,7 +18,7 @@
import javax.annotation.Priority;
-import io.microprofile.config.spi.Converter;
+import org.eclipse.microprofile.config.spi.Converter;
/**
* @author Mark Struberg
diff --git a/impl/src/main/java/org/apache/geronimo/config/converters/LongConverter.java b/impl/src/main/java/org/apache/geronimo/config/converters/LongConverter.java
index 4df6eaa..dc63f5a 100644
--- a/impl/src/main/java/org/apache/geronimo/config/converters/LongConverter.java
+++ b/impl/src/main/java/org/apache/geronimo/config/converters/LongConverter.java
@@ -16,7 +16,7 @@
*/
package org.apache.geronimo.config.converters;
-import io.microprofile.config.spi.Converter;
+import org.eclipse.microprofile.config.spi.Converter;
import javax.annotation.Priority;
diff --git a/impl/src/main/resources/META-INF/services/io.microprofile.config.ConfigProvider$SPI b/impl/src/main/resources/META-INF/services/org.eclipse.microprofile.config.spi.ConfigProviderResolver
similarity index 100%
rename from impl/src/main/resources/META-INF/services/io.microprofile.config.ConfigProvider$SPI
rename to impl/src/main/resources/META-INF/services/org.eclipse.microprofile.config.spi.ConfigProviderResolver
diff --git a/impl/tck-suite.xml b/impl/tck-suite.xml
index ab445be..eff3f62 100644
--- a/impl/tck-suite.xml
+++ b/impl/tck-suite.xml
@@ -22,7 +22,7 @@
-
+
diff --git a/pom.xml b/pom.xml
index cf08594..487e84b 100644
--- a/pom.xml
+++ b/pom.xml
@@ -45,15 +45,12 @@
- 1.7
- 1.7
+ 1.8
+ 1.8
- api
- tckimpl
- spec
diff --git a/spec/pom.xml b/spec/pom.xml
deleted file mode 100644
index 6389337..0000000
--- a/spec/pom.xml
+++ /dev/null
@@ -1,98 +0,0 @@
-
-
-
- 4.0.0
-
-
-
- org.apache.geronimo.config
- config-parent
- 0.1-SNAPSHOT
-
-
- org.apache.geronimo.config
- config-spec
- pom
-
-
-
- Apache License, Version 2.0
- https://www.apache.org/licenses/LICENSE-2.0.txt
- repo
- A business-friendly OSS license
-
-
-
-
- 1.5.3
- 1.5.0-alpha.10.1
- Apache License v 2.0
- MMMM dd, yyyy
- ${maven.build.timestamp}
-
-
-
- clean package
-
-
- org.asciidoctor
- asciidoctor-maven-plugin
- ${asciidoctor-maven.version}
-
-
- org.asciidoctor
- asciidoctorj-pdf
- ${asciidoctorj-pdf.version}
-
-
-
-
- generate-pdf-doc
- generate-resources
-
- process-asciidoc
-
-
- pdf
-
-
-
- output-html
- generate-resources
-
- process-asciidoc
-
-
- html5
-
-
-
-
- microprofile-config-spec.asciidoc
- coderay
-
- Apache License v2.0
-
-
-
-
-
-
-
diff --git a/spec/src/main/asciidoc/architecture.asciidoc b/spec/src/main/asciidoc/architecture.asciidoc
deleted file mode 100644
index b715436..0000000
--- a/spec/src/main/asciidoc/architecture.asciidoc
+++ /dev/null
@@ -1,51 +0,0 @@
-//
-// Licensed under the Apache License, Version 2.0 (the "License").
-// See the NOTICE file distributed with this work
-// for additional information regarding copyright ownership.
-// The author 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.
-//
-
-[[architecture]]
-== Architecture
-
-This specification defines an easy to use and flexible system for application configuration.
-It also defines a way to extend the configuration mechanism itself via a SPI (Service Provider Interface) in a portable way.
-
-=== Rational
-
-Released binaries often contain functionality which need to behave slightly differently depending on the deployment.
-This might be different REST endpoints to talk to (e.g. depending on the customer for whom a WAR is deployed).
-Or it might even be different features which need to be switched on and off depending on the installation.
-All this must be possible without the need to re-package the whole application binary.
-
-Microprofile-Config provides a way to achieve this goal by aggregating configuration from many different <> and presents a single merged view to the user.
-This allows the application to bundle default configuration within the application.
-It also allows to override the defaults from outside, e.g. via an environment variable a Java system property or via Docker.
-Microprofile-Config also allows to implement and register own configuration sources in a portable way, e.g. for reading configuration values from a shared database in an application cluster.
-
-
-The core Microprofile-Config mechanism is purely String/String based.
-Type-safety is only provided on top of that by using the proper <> before handing the value out to the caller.
-
-The configuration key might use dot-separated namespaces similar to Java package namespacing:
-
-[source, text]
-----
-com.acme.myproject.someserver.url = http://some.server/some/endpoint
-com.acme.myproject.someserver.port = 9085
-com.acme.myproject.someserver.active = true
-com.acme.other.stuff.name = Karl
-com.acme.myproject.notify.onerror=karl@mycompany,sue@mcompany
-----
-
-Config keys are usually case sensitive.
diff --git a/spec/src/main/asciidoc/configexamples.asciidoc b/spec/src/main/asciidoc/configexamples.asciidoc
deleted file mode 100644
index 4799e11..0000000
--- a/spec/src/main/asciidoc/configexamples.asciidoc
+++ /dev/null
@@ -1,92 +0,0 @@
-//
-// Licensed under the Apache License, Version 2.0 (the "License").
-// See the NOTICE file distributed with this work
-// for additional information regarding copyright ownership.
-// The author 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.
-//
-
-[[configexamples]]
-== Configuration Usage Examples
-
-An application can access it's configured values via a `Config` instance.
-A user can use the `ConfigProvider` to access the `Config` of an application or simply use `@Inject Config` within CDI managed components.
-
-=== Simple Example
-
-[source, java]
-----
-ppublic class ConfigUsageSample {
-
- public void useTheConfig() {
- // get access to the Config instance
- Config config = ConfigProvider.getConfig();
-
- String serverUrl = config.getValue("com.acme.myproject.someserver.url");
- Integer serverPort = config.getValue("com.acme.myproject.someserver.port",
- Integer.class);
-
- callToServer(serverUrl, serverPort);
- }
-}
-----
-
-If you need to access a different server then you can e.g. change the configuration via a `-D` system property:
-
-[source, text]
-----
-$> java -jar some.jar -Dcom.acme.myproject.someserver.url=http://other.server/other/endpoint
-----
-
-Note that the way to inject this configuration into the application can be extended by providing custom `ConfigSource` s.
-
-
-
-=== Some advanced features
-
-It is also possible to dynamically pick up values which might change at runtime.
-For example if the configured values get picked up from a custom <> which picks up it's values from a Database.
-
-[source, java]
-----
-@ApplicationScoped
-public class DynamicConfigUsageSample {
-
- private @Inject Config config;
-
- private ConfigValue serverUrlCfg;
- private ConfigValue serverPortCfg
-
- @PostConstruct
- private void init() {
- serverUrlCfg= config.access("com.acme.myproject.someserver.url")
- .cacheFor(5, TimeUnit.MINUTES)
- .logChanges(true)
- .evaluateVariables(true);
-
- serverPortCfg = config.access("com.acme.myproject.someserver.port")
- .as(Integer.class)
- .cacheFor(5, TimeUnit.MINUTES)
- .logChanges(true)
- .evaluateVariables(true)
- .withDefault(8080);
- }
-
- public void useTheConfig() {
- callToServer(serverUrlCfg.getValue(), serverPortCfg.getValue());
- }
-}
-----
-
-The `cacheFor(5, TimeUnit.MINUTES)` will have the `ConfigValue` behave like a local cache and thus reduce load on the configuration system.
-5 minutes after `getValue()` got called the last time any fresh value will get picked up.
-If `logChanges(true)` is set then any value change will get logged.
\ No newline at end of file
diff --git a/spec/src/main/asciidoc/configprovider.asciidoc b/spec/src/main/asciidoc/configprovider.asciidoc
deleted file mode 100644
index ce39eb4..0000000
--- a/spec/src/main/asciidoc/configprovider.asciidoc
+++ /dev/null
@@ -1,57 +0,0 @@
-//
-// Licensed under the Apache License, Version 2.0 (the "License").
-// See the NOTICE file distributed with this work
-// for additional information regarding copyright ownership.
-// The author 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.
-//
-
-[[configprovider]]
-== Accessing or Creating a certain Configuration
-
-
-For manually accessing the `ConfigProvider` is the central class to access a configuration.
-It allows access to different configurations (represented by a `Config` instance) based on the application in which it is used.
-We distinguish 5 different ways to create or `Config` instance:
-
-* In CDI manged components a user can use `@Inject` to access the current application configuration.
- If no configuration is registered the automatic discovery of <> will be performed.
-
-* A factory method `ConfigProvider#getConfig()` to create a `Config` object based on automatically picked up `ConfigSources`
- of the Application identified by the current Thread Context ClassLoader classpath.
- Subsequent calls to this method for a certain Application will return the same `Config` instance.
-
-* A factory method `ConfigProvider#getConfig(ClassLoader forClassLoader)` to create a `Config` object based on automatically picked up `ConfigSources`
- of the Application identified by the given ClassLoader.
- This can be used if the Thread Context ClassLoader does not represent the correct layer.
- E.g. if you need the Config for a class in a shared EAR lib folder.
- Subsequent calls to this method for a certain Application will return the same `Config` instance.
-
-* A factory method `ConfigProvider#newConfig()` to create an empty `Config` object which can be filled manually via a builder.
- This configuration instance will not be shared by the `ConfigProvider`.
- This method is intended be used if a IoT container or any other external Factory can be used to give access to a manually created shared `Config`.
-
-* A factory method `ConfigProvider#registerConfig()` to create an empty `Config` object which can be filled manually via a builder.
- This configuration instance *will* be shared by the `ConfigProvider`.
- Any subsequent call to `ConfigProvider#getConfig()` will return the registered `Config` instance.
-
-
-All methods in the `ConfigProvider` and `Config` implementations are thread safe and reentrant.
-
-If a `Config` is bound to an Application it is ensured that it gets properly removed if the Application gets destroyed.
-The Config system deos not create any memory leaks in that case.
-
-A `Config` can be release manually by calling `ConfigProvider#release(Config)`.
-ConfigSources which implement the `java.io.Closeable` interface will be properly destroyed.
-Any subsequent call to `ConfigProvider#getConfig()` or `ConfigProvider#getConfig(ClassLoader forClassLoader)` will result in a new `Config` instance.
-
-<<<
\ No newline at end of file
diff --git a/spec/src/main/asciidoc/configsources.asciidoc b/spec/src/main/asciidoc/configsources.asciidoc
deleted file mode 100644
index 22e5d85..0000000
--- a/spec/src/main/asciidoc/configsources.asciidoc
+++ /dev/null
@@ -1,137 +0,0 @@
-//
-// Licensed under the Apache License, Version 2.0 (the "License").
-// See the NOTICE file distributed with this work
-// for additional information regarding copyright ownership.
-// The author 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.
-//
-
-[[configsource]]
-== ConfigSource
-
-A `ConfigSource` is exactly what its name says: a source for configured values.
-The `Config` uses all configured implementations of `ConfigSource` to look up the property in question.
-
-=== ConfigSource Ordering
-
-Each `ConfigSource` has a specified `ordinal`, which is used to determine the importance of the values taken from the associated `ConfigSource`.
-A higher `ordinal` means that the values taken from this `ConfigSource` will override values from lower-priority `ConfigSource` s.
-This allows a configuration to be customized from outside a binary, assuming that external `ConfigSource` s have higher `ordinal` values than the ones whose values originate within the release binaries.
-
-It can also be used to implement a drop-in configuration approach.
-Simply create a jar containing a `ConfigSource` with a higher ordinal and override configuration values in it.
-If the jar is present on the classpath then it will override configuration values from `ConfigSource` s with lower `ordinal` values.
-
-The ordinal for property file based `ConfigSource` s can be configured using the key `config_ordinal` inside the property file.
-
-[source, text]
-----
-config_ordinal = 120
-com.acme.myproject.someserver.url = http://more_important.server/some/endpoint
-----
-
-[[default_configsources]]
-=== Default ConfigSources
-
-A Microprofile-Config implementation must provide `ConfigSource` s for the following data out of the box:
-
-* System properties (ordinal=400)
-* Environment properties (ordinal=300).
- The built in `ConfigSource` for the environment provides an all upper-case fallback lookup where dots are replaced with underlines.
- An environment setting `ACME_MYKEY=bla` machtches a lookup for `config.getValue("acme.mykey")`.
-* A `ConfigSource` for each property file `META-INF/java-config.properties` found on the classpath. (default ordinal = 100)
-
-=== Custom ConfigSources
-
-`ConfigSource` s are discovered using the `java.util.ServiceLoader` mechanism.
-
-To add a custom `ConfigSource`, implement the interface `io.microprofile.config.spi.ConfigSource`.
-
-[source, java]
-----
-public class CustomDbConfigSource implements ConfigSource {
-
- @Override
- public int getOrdinal() {
- return 112;
- }
-
- @Override
- public Map getProperties() {
- return readPropertiesFromDb();
- }
-
- @Override
- public String getPropertyValue(String key) {
- return readPropertyFromDb(key);
- }
-
- @Override
- public String getConfigName() {
- return "customDbConfig";
- }
-
- // + methods to read from the DB
-}
-
-----
-
-Then register your implementation in a resource file `/META-INF/services/io.microprofile.config.spi.ConfigSource` by including the fully-qualified class name of the custom implementation in the file.
-
-
-=== Custom ConfigSources via ConfigSourceProvider
-
-If you need dynamic `ConfigSource` s you can also register a `ConfigSourceProvider` in a similar manner.
-This is useful if you are required to dynamically pick up multiple `ConfigSource` s of the same kind;
-for example, to pick up all `myproject.properties` resources from all the JARs in your classpath.
-
-A custom `ConfigSourceProvider` must implement the interface `io.microprofile.config.spi.ConfigSourceProvider`.
-Register your implementation in a resource file `/META-INF/services/io.microprofile.config.spi.ConfigSourceProvider` by including the fully-qualified class name of the custom implementation/s in the file.
-
-An example which registers all YAML files with the name `exampleconfig.yaml`:
-
-[source, java]
-----
-public class ExampleYamlConfigSourceProvider
- implements io.microprofile.config.spi.ConfigSourceProvider {
- @Override
- public List getConfigSources(ClassLoader forClassLoader) {
- List configSources = new ArrayList<>();
-
- Enumeration yamlFiles
- = forClassLoader.getResources("sampleconfig.yaml");
- while (yamlFiles.hasMoreElements()) {
- configSources.add(new SampleYamlConfigSource(yamlFiles.nextElement()));
- }
- return configSources;
- }
-}
-----
-
-Please note that a single `ConfigSource` should be either registered directly or via a `ConfigSourceProvider`, but never both ways.
-
-
-=== ConfigSource and Mutable Data
-
-A `Config` instance provides no caching but iterates over all `ConfigSources` for each `getValue(String)` operation.
-A `ConfigSource` is allowed to cache the underlying values itself.
-
-Users might use the `cacheFor(long, TimeUnit)` method of a `ConfigValue` to pick up values which might change at runtime without penetrating the configuration system.
-
-
-=== Manually adding ConfigSources
-
-A user can manually register `ConfigSource` s by using the method `void addConfigSources(List configSourcesToAdd)`.
-This will add the given list to the already registered `ConfigSources` of the current `Config` instance.
-
-The order in which the `ConfigSources` are evaluated when using `Config#getValue(String key)` is independent of the order in which they were added to the `Config`; this depends only on the `ordinal` values of the available `ConfigSources`.
-
diff --git a/spec/src/main/asciidoc/converters.asciidoc b/spec/src/main/asciidoc/converters.asciidoc
deleted file mode 100644
index 0131c39..0000000
--- a/spec/src/main/asciidoc/converters.asciidoc
+++ /dev/null
@@ -1,48 +0,0 @@
-//
-// Licensed under the Apache License, Version 2.0 (the "License").
-// See the NOTICE file distributed with this work
-// for additional information regarding copyright ownership.
-// The author 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.
-//
-
-[[converter]]
-== Converter
-
-For providing typeseafe configuration we need to convert from the configured Strings into target types.
-This happens by providing `Converter` s in the `Config`.
-
-=== Built-in Converters
-
-The following `Converter` s are provided by Microprofile-Config by default:
-
-* `Boolean` , values for `true` (case insensitive) "true", "1", "YES", "Y" "JA" "J", "OUI".
- Any other value will be interpreted as `false`
-* `Integer`
-* `Long`
-* `Float` , a dot '.' is used to separate the fractional digits
-* `Double` , a dot '.' is used to separate the fractional digits
-* `java.util.Date` in ISO-8601 format (https://www.ietf.org/rfc/rfc3339.txt), e.g. YYYY-MM-DD. Remaining fractions are set to 0.
-* Java8 `LocalDate` and `LocalDateTime`in ISO-8601 format
-
-
-=== Adding custom Converters
-
-A custom `Converter` must implement the generic interface `io.microprofile.config.spi.Converter`.
-The TypedParameter of the interface is the target type the String is converted to
-You have to register your implementation in a file `/META-INF/services/io.microprofile.config.spi.Converter` by writing the fully qualified class name of the custom implementation into it.
-
-A custom `Converter` can define a priority with the `@javax.annotation.Priority` annotation.
-If a Priority annotation isn't applied, a default priority of 100 is assumed.
-The `Config` will use the `Converter` with the highest `Priority` for each target type.
-
-A custom `Converter` for a target type of any of the built-in Converters will overwrite the default Converter.
diff --git a/spec/src/main/asciidoc/license-alv2.asciidoc b/spec/src/main/asciidoc/license-alv2.asciidoc
deleted file mode 100644
index 276af0a..0000000
--- a/spec/src/main/asciidoc/license-alv2.asciidoc
+++ /dev/null
@@ -1,44 +0,0 @@
-//
-// Licensed under the Apache License, Version 2.0 (the "License").
-// See the NOTICE file distributed with this work
-// for additional information regarding copyright ownership.
-// The author 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.
-//
-
-[subs="normal"]
-....
-
-Specification: {doctitle}
-
-Version: {revnumber}
-
-Status: {revremark}
-
-Specification Lead: Mark Struberg, Emily Jiang
-
-Release: {revdate}
-
-Copyright 2016-2017 Original Authors,
-Licensed 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.
-
-....
diff --git a/spec/src/main/asciidoc/microprofile-config-spec.asciidoc b/spec/src/main/asciidoc/microprofile-config-spec.asciidoc
deleted file mode 100644
index eca5e96..0000000
--- a/spec/src/main/asciidoc/microprofile-config-spec.asciidoc
+++ /dev/null
@@ -1,46 +0,0 @@
-//
-// Licensed under the Apache License, Version 2.0 (the "License").
-// See the NOTICE file distributed with this work
-// for additional information regarding copyright ownership.
-// The author 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.
-//
-
-= Configuration for Microprofile
-:author: Mark Struberg
-:email: struberg@apache.org
-:revnumber: 0.2
-:revdate: 2017-01-15
-:revremark: Proposal
-:version-label!:
-:sectanchors:
-:doctype: book
-:license: Apache License v2.0
-:source-highlighter: coderay
-:toc: left
-:toclevels: 4
-:sectnumlevels: 4
-ifdef::backend-pdf[]
-:pagenums:
-endif::[]
-
-include::license-alv2.asciidoc[]
-
-include::architecture.asciidoc[]
-
-include::configexamples.asciidoc[]
-
-include::configprovider.asciidoc[]
-
-include::configsources.asciidoc[]
-
-include::converters.asciidoc[]
diff --git a/tck/pom.xml b/tck/pom.xml
deleted file mode 100644
index cff61bd..0000000
--- a/tck/pom.xml
+++ /dev/null
@@ -1,55 +0,0 @@
-
-
-
- 4.0.0
-
-
- org.apache.geronimo.config
- config-parent
- 0.1-SNAPSHOT
-
-
- org.apache.geronimo.config
- config-tck
-
-
-
- Apache License, Version 2.0
- https://www.apache.org/licenses/LICENSE-2.0.txt
- repo
- A business-friendly OSS license
-
-
-
-
-
- org.apache.geronimo.config
- config-api
- 0.1-SNAPSHOT
-
-
-
- org.testng
- testng
- 6.9.9
- compile
-
-
-
diff --git a/tck/src/main/java/io/microprofile/config/tck/ConfigProviderTest.java b/tck/src/main/java/io/microprofile/config/tck/ConfigProviderTest.java
deleted file mode 100644
index 6b9a4b0..0000000
--- a/tck/src/main/java/io/microprofile/config/tck/ConfigProviderTest.java
+++ /dev/null
@@ -1,148 +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 io.microprofile.config.tck;
-
-import java.net.URL;
-import java.net.URLClassLoader;
-import java.util.Map;
-import java.util.Properties;
-
-import io.microprofile.config.Config;
-import io.microprofile.config.ConfigProvider;
-
-import io.microprofile.config.tck.configsources.SampleYamlConfigSource;
-import org.testng.Assert;
-import org.testng.annotations.Test;
-
-/**
- * @author Mark Struberg
- */
-public class ConfigProviderTest {
-
- @Test
- public void testConfigProviderWithDefaultTCCL() {
- ClassLoader oldTccl = Thread.currentThread().getContextClassLoader();
- try {
- ClassLoader tempCl = new URLClassLoader(new URL[0], this.getClass().getClassLoader());
- Thread.currentThread().setContextClassLoader(tempCl);
- Config config = ConfigProvider.getConfig();
- Assert.assertNotNull(config);
-
- Config config2 = ConfigProvider.getConfig(tempCl);
- Assert.assertNotNull(config2);
- Assert.assertEquals(config, config2);
- }
- finally {
- Thread.currentThread().setContextClassLoader(oldTccl);
- }
- }
-
- @Test
- public void testEnvironmentConfigSource() {
- Map env = System.getenv();
- Config config = ConfigProvider.getConfig();
- for (Map.Entry envEntry : env.entrySet()) {
- Assert.assertEquals(envEntry.getValue(), config.getValue(envEntry.getKey()));
- }
- }
-
- @Test
- public void testPropertyConfigSource() {
- Properties properties = System.getProperties();
- Config config = ConfigProvider.getConfig();
-
- for (Map.Entry