http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/8ad95aa9/configjsr/src/main/java/org/apache/tamaya/jsr382/TamayaPropertyConverter.java ---------------------------------------------------------------------- diff --git a/configjsr/src/main/java/org/apache/tamaya/jsr382/TamayaPropertyConverter.java b/configjsr/src/main/java/org/apache/tamaya/jsr382/TamayaPropertyConverter.java deleted file mode 100644 index e220eab..0000000 --- a/configjsr/src/main/java/org/apache/tamaya/jsr382/TamayaPropertyConverter.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 org.apache.tamaya.jsr382; - - -import org.apache.tamaya.spi.ConversionContext; -import org.apache.tamaya.spi.PropertyConverter; - -import javax.config.spi.Converter; -import java.util.Objects; - -/** - * Converter implementation that wraps a Javaconfig {@link Converter} instance. - */ -public class TamayaPropertyConverter<T> implements PropertyConverter<T> { - - private Converter<T> delegate; - - public TamayaPropertyConverter(Converter<T> delegate){ - this.delegate = Objects.requireNonNull(delegate); - } - - public Converter<T> getConverter(){ - return this.delegate; - } - - @Override - public T convert(String value, ConversionContext context) { - return delegate.convert(value); - } -}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/8ad95aa9/configjsr/src/main/java/org/apache/tamaya/jsr382/TamayaPropertyConverterAdapter.java ---------------------------------------------------------------------- diff --git a/configjsr/src/main/java/org/apache/tamaya/jsr382/TamayaPropertyConverterAdapter.java b/configjsr/src/main/java/org/apache/tamaya/jsr382/TamayaPropertyConverterAdapter.java new file mode 100644 index 0000000..b38bcbd --- /dev/null +++ b/configjsr/src/main/java/org/apache/tamaya/jsr382/TamayaPropertyConverterAdapter.java @@ -0,0 +1,62 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tamaya.jsr382; + + +import org.apache.tamaya.spi.ConversionContext; +import org.apache.tamaya.spi.PropertyConverter; + +import javax.config.spi.Converter; +import java.util.Objects; + +/** + * Converter implementation that wraps a Javaconfig {@link Converter} instance. + */ +final class TamayaPropertyConverterAdapter<T> implements PropertyConverter<T> { + + private Converter<T> delegate; + + /** + * Creates a new adapter instance. + * @param delegate the delegate, not null. + */ + public TamayaPropertyConverterAdapter(Converter<T> delegate){ + this.delegate = Objects.requireNonNull(delegate); + } + + /** + * Access the underlying converter instance. + * @return the underlying converter, not null. + */ + public Converter<T> getConverter(){ + return this.delegate; + } + + @Override + public T convert(String value, ConversionContext context) { + return delegate.convert(value); + } + + @Override + public String toString() { + return "TamayaPropertyConverterAdapter{" + + "delegate=" + delegate + + '}'; + } +} http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/8ad95aa9/configjsr/src/main/java/org/apache/tamaya/jsr382/TamayaPropertySource.java ---------------------------------------------------------------------- diff --git a/configjsr/src/main/java/org/apache/tamaya/jsr382/TamayaPropertySource.java b/configjsr/src/main/java/org/apache/tamaya/jsr382/TamayaPropertySource.java deleted file mode 100644 index a551b59..0000000 --- a/configjsr/src/main/java/org/apache/tamaya/jsr382/TamayaPropertySource.java +++ /dev/null @@ -1,78 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tamaya.jsr382; - -import org.apache.tamaya.spi.PropertySource; -import org.apache.tamaya.spi.PropertyValue; - -import javax.config.spi.ConfigSource; -import java.util.HashMap; -import java.util.Map; -import java.util.Objects; -import java.util.Optional; - -/** - * Property source implementation that wraps a Javaconfig {@link ConfigSource} instance. - */ -public class TamayaPropertySource implements PropertySource { - - private ConfigSource delegate; - - public TamayaPropertySource(ConfigSource configSource){ - this.delegate = Objects.requireNonNull(configSource); - } - - public ConfigSource getConfigSource(){ - return this.delegate; - } - - @Override - public int getOrdinal() { - return delegate.getOrdinal(); - } - - @Override - public String getName() { - return Optional.ofNullable(delegate.getName()) - .orElse(delegate.toString()); - } - - @Override - public PropertyValue get(String key) { - return PropertyValue.of(key, delegate.getValue(key),getName()); - } - - @Override - public Map<String, PropertyValue> getProperties() { - return toValueMap(delegate.getProperties()); - } - - private Map<String, PropertyValue> toValueMap(Map<String, String> properties) { - Map<String, PropertyValue> valueMap = new HashMap<>(properties.size()); - for(Map.Entry<String,String> en:properties.entrySet()){ - valueMap.put(en.getKey(), PropertyValue.of(en.getKey(), en.getValue(), getName())); - } - return valueMap; - } - - @Override - public boolean isScannable() { - return true; - } -} http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/8ad95aa9/configjsr/src/main/java/org/apache/tamaya/jsr382/TamayaPropertySourceAdapter.java ---------------------------------------------------------------------- diff --git a/configjsr/src/main/java/org/apache/tamaya/jsr382/TamayaPropertySourceAdapter.java b/configjsr/src/main/java/org/apache/tamaya/jsr382/TamayaPropertySourceAdapter.java new file mode 100644 index 0000000..126d68d --- /dev/null +++ b/configjsr/src/main/java/org/apache/tamaya/jsr382/TamayaPropertySourceAdapter.java @@ -0,0 +1,88 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tamaya.jsr382; + +import org.apache.tamaya.spi.PropertySource; +import org.apache.tamaya.spi.PropertyValue; + +import javax.config.spi.ConfigSource; +import java.util.HashMap; +import java.util.Map; +import java.util.Objects; +import java.util.Optional; + +/** + * Property source implementation that wraps a Javaconfig {@link ConfigSource} instance. + */ +class TamayaPropertySourceAdapter implements PropertySource { + + private ConfigSource delegate; + + /** + * Creates a new instance. + * @param configSource the underlying config source, not null. + */ + public TamayaPropertySourceAdapter(ConfigSource configSource){ + this.delegate = Objects.requireNonNull(configSource); + } + + /** + * Access the underlying config source. + * @return the underlying config source, not null. + */ + public ConfigSource getConfigSource(){ + return this.delegate; + } + + @Override + public int getOrdinal() { + return delegate.getOrdinal(); + } + + @Override + public String getName() { + return Optional.ofNullable(delegate.getName()) + .orElse(delegate.toString()); + } + + @Override + public PropertyValue get(String key) { + return PropertyValue.of(key, delegate.getValue(key),getName()); + } + + @Override + public Map<String, PropertyValue> getProperties() { + return toValueMap(delegate.getProperties()); + } + + private Map<String, PropertyValue> toValueMap(Map<String, String> properties) { + Map<String, PropertyValue> valueMap = new HashMap<>(properties.size()); + for(Map.Entry<String,String> en:properties.entrySet()){ + valueMap.put(en.getKey(), PropertyValue.of(en.getKey(), en.getValue(), getName())); + } + return valueMap; + } + + @Override + public String toString() { + return "TamayaPropertySourceAdapter{" + + "delegate=" + delegate + + '}'; + } +} http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/8ad95aa9/configjsr/src/main/java/org/apache/tamaya/jsr382/TamayaPropertySourceProvider.java ---------------------------------------------------------------------- diff --git a/configjsr/src/main/java/org/apache/tamaya/jsr382/TamayaPropertySourceProvider.java b/configjsr/src/main/java/org/apache/tamaya/jsr382/TamayaPropertySourceProvider.java deleted file mode 100644 index f5b48cd..0000000 --- a/configjsr/src/main/java/org/apache/tamaya/jsr382/TamayaPropertySourceProvider.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tamaya.jsr382; - - -import org.apache.tamaya.spi.PropertySource; -import org.apache.tamaya.spi.PropertySourceProvider; - -import javax.config.spi.ConfigSourceProvider; -import java.util.*; - -/** - * Tamaya {@link PropertySourceProvider} implementation that wraps a {@link ConfigSourceProvider} instance. - */ -public class TamayaPropertySourceProvider implements PropertySourceProvider{ - - private ConfigSourceProvider delegate; - - public TamayaPropertySourceProvider(ConfigSourceProvider configSourceProvider){ - this.delegate = Objects.requireNonNull(configSourceProvider); - } - - public ConfigSourceProvider getConfigSourceProvider(){ - return this.delegate; - } - - - @Override - public Collection<PropertySource> getPropertySources() { - if(delegate instanceof JavaConfigSourceProvider){ - return ((JavaConfigSourceProvider)delegate).getPropertySourceProvider() - .getPropertySources(); - }else { - return JavaConfigAdapter.toPropertySources( - delegate.getConfigSources(Thread.currentThread().getContextClassLoader())); - } - } - -} http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/8ad95aa9/configjsr/src/main/java/org/apache/tamaya/jsr382/TamayaPropertySourceProviderAdapter.java ---------------------------------------------------------------------- diff --git a/configjsr/src/main/java/org/apache/tamaya/jsr382/TamayaPropertySourceProviderAdapter.java b/configjsr/src/main/java/org/apache/tamaya/jsr382/TamayaPropertySourceProviderAdapter.java new file mode 100644 index 0000000..9040c48 --- /dev/null +++ b/configjsr/src/main/java/org/apache/tamaya/jsr382/TamayaPropertySourceProviderAdapter.java @@ -0,0 +1,69 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tamaya.jsr382; + + +import org.apache.tamaya.spi.PropertySource; +import org.apache.tamaya.spi.PropertySourceProvider; + +import javax.config.spi.ConfigSourceProvider; +import java.util.*; + +/** + * Tamaya {@link PropertySourceProvider} implementation that wraps a {@link ConfigSourceProvider} instance. + */ +class TamayaPropertySourceProviderAdapter implements PropertySourceProvider{ + + private ConfigSourceProvider delegate; + + /** + * Creates a new instance. + * @param configSourceProvider the provider, not null. + */ + public TamayaPropertySourceProviderAdapter(ConfigSourceProvider configSourceProvider){ + this.delegate = Objects.requireNonNull(configSourceProvider); + } + + /** + * Access the underlying provider. + * @return the provider, not null. + */ + public ConfigSourceProvider getConfigSourceProvider(){ + return this.delegate; + } + + + @Override + public Collection<PropertySource> getPropertySources() { + if(delegate instanceof JavaConfigSourceProvider){ + return ((JavaConfigSourceProvider)delegate).getPropertySourceProvider() + .getPropertySources(); + }else { + return JavaConfigAdapterFactory.toPropertySources( + delegate.getConfigSources(Thread.currentThread().getContextClassLoader())); + } + } + + @Override + public String toString() { + return "TamayaPropertySourceProviderAdapter{" + + "delegate=" + delegate + + '}'; + } +} http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/8ad95aa9/configjsr/src/main/java/org/apache/tamaya/jsr382/cdi/JavaConfigConfigurationProducer.java ---------------------------------------------------------------------- diff --git a/configjsr/src/main/java/org/apache/tamaya/jsr382/cdi/JavaConfigConfigurationProducer.java b/configjsr/src/main/java/org/apache/tamaya/jsr382/cdi/JavaConfigConfigurationProducer.java index 01893c8..e685824 100644 --- a/configjsr/src/main/java/org/apache/tamaya/jsr382/cdi/JavaConfigConfigurationProducer.java +++ b/configjsr/src/main/java/org/apache/tamaya/jsr382/cdi/JavaConfigConfigurationProducer.java @@ -83,13 +83,12 @@ public class JavaConfigConfigurationProducer { final Type targetType = injectionPoint.getAnnotated().getBaseType(); Configuration config = Configuration.current(); ConversionContext.Builder builder = new ConversionContext.Builder(config, - Configuration.current().getContext(), key, TypeLiteral.of(targetType)); + key, TypeLiteral.of(targetType)); if(targetType instanceof ParameterizedType){ ParameterizedType pt = (ParameterizedType)targetType; if(pt.getRawType().equals(Provider.class)) { builder = new ConversionContext.Builder(config, - Configuration.current().getContext(), key, - TypeLiteral.of(pt.getActualTypeArguments()[0])); + key, TypeLiteral.of(pt.getActualTypeArguments()[0])); } } if (injectionPoint.getMember() instanceof AnnotatedElement) { @@ -141,7 +140,7 @@ public class JavaConfigConfigurationProducer { @Produces public Config getConfiguration(){ - return Configuration.current(); + return ConfigProvider.getConfig(); } @Produces http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/8ad95aa9/configjsr/src/main/java/org/apache/tamaya/jsr382/converter/ProviderConverter.java ---------------------------------------------------------------------- diff --git a/configjsr/src/main/java/org/apache/tamaya/jsr382/converter/ProviderConverter.java b/configjsr/src/main/java/org/apache/tamaya/jsr382/converter/ProviderConverter.java index 432d05d..893e0f3 100644 --- a/configjsr/src/main/java/org/apache/tamaya/jsr382/converter/ProviderConverter.java +++ b/configjsr/src/main/java/org/apache/tamaya/jsr382/converter/ProviderConverter.java @@ -77,7 +77,7 @@ public class ProviderConverter implements PropertyConverter<Provider> { @Override public T query(Configuration config) { List<PropertyConverter<T>> converters = config.getContext().getPropertyConverters(type); - ConversionContext context = new ConversionContext.Builder(type).setConfigurationContext(config.getContext()) + ConversionContext context = new ConversionContext.Builder(type).setConfiguration(config) .setConfiguration(config).setKey(ConvertQuery.class.getName()).build(); for(PropertyConverter<?> conv: converters) { try{ http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/8ad95aa9/configjsr/src/main/resources/META-INF/services/javax.config.spi.ConfigProviderResolver ---------------------------------------------------------------------- diff --git a/configjsr/src/main/resources/META-INF/services/javax.config.spi.ConfigProviderResolver b/configjsr/src/main/resources/META-INF/services/javax.config.spi.ConfigProviderResolver index 4a9b29e..d48b8c9 100644 --- a/configjsr/src/main/resources/META-INF/services/javax.config.spi.ConfigProviderResolver +++ b/configjsr/src/main/resources/META-INF/services/javax.config.spi.ConfigProviderResolver @@ -16,4 +16,4 @@ # specific language governing permissions and limitations # under the License. # -org.apache.tamaya.jsr382.JavaConfigProviderResolver \ No newline at end of file +org.apache.tamaya.jsr382.TamayaConfigProviderResolver \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/8ad95aa9/configjsr/src/main/resources/META-INF/services/org.apache.tamaya.spi.PropertySource ---------------------------------------------------------------------- diff --git a/configjsr/src/main/resources/META-INF/services/org.apache.tamaya.spi.PropertySource b/configjsr/src/main/resources/META-INF/services/org.apache.tamaya.spi.PropertySource index 7840983..3cd92c5 100644 --- a/configjsr/src/main/resources/META-INF/services/org.apache.tamaya.spi.PropertySource +++ b/configjsr/src/main/resources/META-INF/services/org.apache.tamaya.spi.PropertySource @@ -16,4 +16,4 @@ # specific language governing permissions and limitations # under the License. # -org.apache.tamaya.jsr382.JavaConfigDefaultProperties \ No newline at end of file +org.apache.tamaya.jsr382.JavaConfigDefaultPropertiesPropertySource \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/8ad95aa9/configjsr/src/test/java/org/apache/tamaya/jsr382/JavaConfigAdapterTest.java ---------------------------------------------------------------------- diff --git a/configjsr/src/test/java/org/apache/tamaya/jsr382/JavaConfigAdapterTest.java b/configjsr/src/test/java/org/apache/tamaya/jsr382/JavaConfigAdapterTest.java index 60533da..c00949e 100644 --- a/configjsr/src/test/java/org/apache/tamaya/jsr382/JavaConfigAdapterTest.java +++ b/configjsr/src/test/java/org/apache/tamaya/jsr382/JavaConfigAdapterTest.java @@ -28,7 +28,9 @@ import org.assertj.core.api.Assertions; import org.junit.Test; import javax.config.Config; +import javax.config.ConfigAccessor; import javax.config.ConfigProvider; +import javax.config.ConfigSnapshot; import javax.config.spi.ConfigBuilder; import javax.config.spi.ConfigSource; import javax.config.spi.Converter; @@ -40,7 +42,7 @@ public class JavaConfigAdapterTest { @Test public void toConfig() throws Exception { Configuration config = Configuration.current(); - Config mpConfig = JavaConfigAdapter.toConfig(config); + Config mpConfig = JavaConfigAdapterFactory.toConfig(config); assertNotNull(mpConfig); assertEquals(config.getProperties().keySet(), mpConfig.getPropertyNames()); } @@ -48,20 +50,20 @@ public class JavaConfigAdapterTest { @Test public void toConfigWithTamayaConfiguration() throws Exception { Configuration configuration = new MyConfiguration(); - JavaConfig config = new JavaConfig(configuration); - TamayaConfiguration tamayaConfiguration = new TamayaConfiguration(config); + JavaConfigAdapter config = new JavaConfigAdapter(configuration); + TamayaConfigurationAdapter tamayaConfiguration = new TamayaConfigurationAdapter(config); - Config result = JavaConfigAdapter.toConfig(tamayaConfiguration); + Config result = JavaConfigAdapterFactory.toConfig(tamayaConfiguration); Assertions.assertThat(result).isNotNull() - .isInstanceOf(JavaConfig.class) + .isInstanceOf(JavaConfigAdapter.class) .isSameAs(config); } @Test public void toConfiguration() throws Exception { - Config mpConfig = Configuration.current(); - Configuration config = JavaConfigAdapter.toConfiguration(mpConfig); + Config mpConfig = ConfigProvider.getConfig(); + Configuration config = JavaConfigAdapterFactory.toConfiguration(mpConfig); assertNotNull(config); assertEquals(mpConfig.getPropertyNames(), config.getProperties().keySet()); } @@ -69,10 +71,10 @@ public class JavaConfigAdapterTest { @Test public void toConfigurationWithNoneJavaConfigConfig() throws Exception { Config config = new MyConfig(); - Configuration result = JavaConfigAdapter.toConfiguration(config); + Configuration result = JavaConfigAdapterFactory.toConfiguration(config); Assertions.assertThat(result).isNotNull() - .isInstanceOf(TamayaConfiguration.class); + .isInstanceOf(TamayaConfigurationAdapter.class); } @Test @@ -84,7 +86,7 @@ public class JavaConfigAdapterTest { .build(); List<PropertySource> tamayaSources = new ArrayList<>(); tamayaSources.add(testPropertySource); - List<ConfigSource> configSources = JavaConfigAdapter.toConfigSources(tamayaSources); + List<ConfigSource> configSources = JavaConfigAdapterFactory.toConfigSources(tamayaSources); assertNotNull(configSources); assertEquals(tamayaSources.size(), configSources.size()); compare(testPropertySource, configSources.get(0)); @@ -108,7 +110,7 @@ public class JavaConfigAdapterTest { .build(); List<ConfigSource> configSources = new ArrayList<>(); configSources.add(configSource); - List<PropertySource> propertySources = JavaConfigAdapter.toPropertySources(configSources); + List<PropertySource> propertySources = JavaConfigAdapterFactory.toPropertySources(configSources); assertNotNull(propertySources); assertEquals(propertySources.size(), configSources.size()); compare(propertySources.get(0), configSource); @@ -121,7 +123,7 @@ public class JavaConfigAdapterTest { .withSimpleProperty("string0", "value0") .withSimpleProperty("int0", "0") .build(); - ConfigSource configSource = JavaConfigAdapter.toConfigSource(tamayaSource); + ConfigSource configSource = JavaConfigAdapterFactory.toConfigSource(tamayaSource); assertNotNull(configSource); compare(tamayaSource, configSource); } @@ -133,28 +135,28 @@ public class JavaConfigAdapterTest { .withProperty("string0", "value0") .withProperty("int0", "0") .build(); - PropertySource tamayaSource = JavaConfigAdapter.toPropertySource(configSource); + PropertySource tamayaSource = JavaConfigAdapterFactory.toPropertySource(configSource); assertNotNull(configSource); compare(tamayaSource, configSource); } @Test public void toPropertyConverter() throws Exception { - PropertyConverter<String> tamayaConverter = JavaConfigAdapter.toPropertyConverter(new UppercaseConverter()); + PropertyConverter<String> tamayaConverter = JavaConfigAdapterFactory.toPropertyConverter(new UppercaseConverter()); assertNotNull(tamayaConverter); assertEquals("ABC", tamayaConverter.convert("aBC", null)); } @Test public void toConverter() throws Exception { - Converter<String> mpConverter = JavaConfigAdapter.toConverter(new UppercasePropertyConverter()); + Converter<String> mpConverter = JavaConfigAdapterFactory.toConverter(new UppercasePropertyConverter()); assertNotNull(mpConverter); assertEquals("ABC", mpConverter.convert("aBC")); } @Test public void toConfigBuilder() throws Exception { - ConfigBuilder builder = JavaConfigAdapter.toConfigBuilder(ConfigurationProvider.getConfigurationBuilder()); + ConfigBuilder builder = JavaConfigAdapterFactory.toConfigBuilder(ConfigurationProvider.getConfigurationBuilder()); assertNotNull(builder); } @@ -162,7 +164,7 @@ public class JavaConfigAdapterTest { public void toStringMap() throws Exception { Map<String,PropertyValue> props = new HashMap<>(); props.put("a", PropertyValue.of("a","b", "toStringMap")); - Map<String, String> mpProps = JavaConfigAdapter.toStringMap(props); + Map<String, String> mpProps = JavaConfigAdapterFactory.toStringMap(props); assertNotNull(mpProps); assertEquals(props.keySet(), mpProps.keySet()); assertEquals(mpProps.get("a"), "b"); @@ -172,7 +174,7 @@ public class JavaConfigAdapterTest { public void toPropertyValueMap() throws Exception { Map<String,String> props = new HashMap<>(); props.put("a", "b"); - Map<String, PropertyValue> tamayaProps = JavaConfigAdapter.toPropertyValueMap(props, "toPropertyValueMap"); + Map<String, PropertyValue> tamayaProps = JavaConfigAdapterFactory.toPropertyValueMap(props, "toPropertyValueMap"); assertNotNull(tamayaProps); assertEquals(tamayaProps.keySet(), props.keySet()); assertEquals(tamayaProps.get("a").getValue(), "b"); @@ -191,13 +193,23 @@ public class JavaConfigAdapterTest { } @Override + public ConfigAccessor<String> access(String propertyName) { + throw new RuntimeException("Not implemented yet!"); + } + + @Override + public ConfigSnapshot snapshotFor(ConfigAccessor<?>... configValues) { + return null; + } + + @Override public Iterable<String> getPropertyNames() { throw new RuntimeException("Not implemented yet!"); } @Override public Iterable<ConfigSource> getConfigSources() { - throw new RuntimeException("Not implemented yet!"); + return Collections.emptyList(); } } @@ -239,6 +251,11 @@ public class JavaConfigAdapterTest { @Override public ConfigurationContext getContext() { + return ConfigurationContext.EMPTY; + } + + @Override + public ConfigurationSnapshot getSnapshot(Iterable<String> keys) { throw new RuntimeException("Not implemented yet!"); } } http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/8ad95aa9/configjsr/src/test/java/org/apache/tamaya/jsr382/JavaConfigConfigProviderTest.java ---------------------------------------------------------------------- diff --git a/configjsr/src/test/java/org/apache/tamaya/jsr382/JavaConfigConfigProviderTest.java b/configjsr/src/test/java/org/apache/tamaya/jsr382/JavaConfigConfigProviderTest.java index bde67bf..c69af54 100644 --- a/configjsr/src/test/java/org/apache/tamaya/jsr382/JavaConfigConfigProviderTest.java +++ b/configjsr/src/test/java/org/apache/tamaya/jsr382/JavaConfigConfigProviderTest.java @@ -34,7 +34,7 @@ public class JavaConfigConfigProviderTest { @Test public void testDefaultConfigAccess(){ - Config config = Configuration.current(); + Config config = ConfigProvider.getConfig(); assertNotNull(config); Iterable<String> names = config.getPropertyNames(); assertNotNull(names); @@ -43,12 +43,16 @@ public class JavaConfigConfigProviderTest { count++; System.out.println(count + ": " +name); } - assertTrue(Configuration.current().getProperties().size() <= count); + int cfgCount = 0; + for(String s:ConfigProvider.getConfig().getPropertyNames()){ + cfgCount++; + } + assertTrue(cfgCount <= count); } @Test public void testClassloaderAccess(){ - Config config = Configuration.current(Thread.currentThread().getContextClassLoader()); + Config config = ConfigProvider.getConfig(Thread.currentThread().getContextClassLoader()); assertNotNull(config); Iterable<String> names = config.getPropertyNames(); assertNotNull(names); http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/8ad95aa9/configjsr/src/test/java/org/apache/tamaya/jsr382/JavaConfigConfigTest.java ---------------------------------------------------------------------- diff --git a/configjsr/src/test/java/org/apache/tamaya/jsr382/JavaConfigConfigTest.java b/configjsr/src/test/java/org/apache/tamaya/jsr382/JavaConfigConfigTest.java index 69cba64..06685e1 100644 --- a/configjsr/src/test/java/org/apache/tamaya/jsr382/JavaConfigConfigTest.java +++ b/configjsr/src/test/java/org/apache/tamaya/jsr382/JavaConfigConfigTest.java @@ -35,7 +35,7 @@ public class JavaConfigConfigTest { @Test public void testDefaultConfigAccess() { - Config config = Configuration.current(); + Config config = ConfigProvider.getConfig(); Iterable<ConfigSource> sources = config.getConfigSources(); int count = 0; for (ConfigSource cs : sources) { @@ -46,7 +46,7 @@ public class JavaConfigConfigTest { @Test public void testOptionalAccess(){ - Config config = Configuration.current(); + Config config = ConfigProvider.getConfig(); int count = 0; for(String key:config.getPropertyNames()){ Optional<String> val = config.getOptionalValue(key, String.class); @@ -59,7 +59,7 @@ public class JavaConfigConfigTest { @Test public void testGetValue(){ - Config config = Configuration.current(); + Config config = ConfigProvider.getConfig(); int count = 0; for(String key:config.getPropertyNames()){ String val = config.getValue(key, String.class); @@ -69,26 +69,26 @@ public class JavaConfigConfigTest { @Test(expected = NoSuchElementException.class) public void testGetValue_NoValue(){ - Config config = Configuration.current(); + Config config = ConfigProvider.getConfig(); config.getValue("fooBar", String.class); } @Test(expected = IllegalArgumentException.class) public void testGetValue_InvalidType(){ - Config config = Configuration.current(); + Config config = ConfigProvider.getConfig(); config.getValue("java.version", Integer.class); } @Test public void testEmptySystemProperty(){ System.setProperty("my.empty.property", ""); - Config config = Configuration.current(); + Config config = ConfigProvider.getConfig(); assertEquals("", config.getValue("my.empty.property", String.class)); } @Test public void testEmptyConfigProperty(){ - Config config = Configuration.current(); + Config config = ConfigProvider.getConfig(); assertEquals("", config.getValue("my.empty.property.in.config.file", String.class)); } http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/8ad95aa9/configjsr/src/test/java/org/apache/tamaya/jsr382/JavaConfigConverterTest.java ---------------------------------------------------------------------- diff --git a/configjsr/src/test/java/org/apache/tamaya/jsr382/JavaConfigConverterTest.java b/configjsr/src/test/java/org/apache/tamaya/jsr382/JavaConfigConverterTest.java index 9b9aba5..099d78f 100644 --- a/configjsr/src/test/java/org/apache/tamaya/jsr382/JavaConfigConverterTest.java +++ b/configjsr/src/test/java/org/apache/tamaya/jsr382/JavaConfigConverterTest.java @@ -34,7 +34,7 @@ public class JavaConfigConverterTest { @Test public void returnedPropertyConverterIsTheOneOfTheDelegate() throws Exception { - JavaConfigConverter<String> mpConverter = new JavaConfigConverter<>(converter); + JavaConfigConverterAdapter<String> mpConverter = new JavaConfigConverterAdapter<>(converter); assertThat(mpConverter.getPropertyConverter()).isSameAs(converter); } http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/8ad95aa9/configjsr/src/test/java/org/apache/tamaya/jsr382/JavaConfigDefaultPropertiesTest.java ---------------------------------------------------------------------- diff --git a/configjsr/src/test/java/org/apache/tamaya/jsr382/JavaConfigDefaultPropertiesTest.java b/configjsr/src/test/java/org/apache/tamaya/jsr382/JavaConfigDefaultPropertiesTest.java index 744fe63..1efdb68 100644 --- a/configjsr/src/test/java/org/apache/tamaya/jsr382/JavaConfigDefaultPropertiesTest.java +++ b/configjsr/src/test/java/org/apache/tamaya/jsr382/JavaConfigDefaultPropertiesTest.java @@ -25,7 +25,7 @@ import org.junit.Test; public class JavaConfigDefaultPropertiesTest { @Test public void hasOrdinalOf100() throws Exception { - JavaConfigDefaultProperties properties = new JavaConfigDefaultProperties(); + JavaConfigDefaultPropertiesPropertySource properties = new JavaConfigDefaultPropertiesPropertySource(); Assertions.assertThat(properties.getOrdinal()).isEqualTo(100); } } \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/8ad95aa9/configjsr/src/test/java/org/apache/tamaya/jsr382/SmokeExamples.java ---------------------------------------------------------------------- diff --git a/configjsr/src/test/java/org/apache/tamaya/jsr382/SmokeExamples.java b/configjsr/src/test/java/org/apache/tamaya/jsr382/SmokeExamples.java new file mode 100644 index 0000000..f7e0001 --- /dev/null +++ b/configjsr/src/test/java/org/apache/tamaya/jsr382/SmokeExamples.java @@ -0,0 +1,147 @@ +///* +// * Licensed to the Apache Software Foundation (ASF) under one +// * or more contributor license agreements. See the NOTICE file +// * distributed with this work for additional information +// * regarding copyright ownership. The ASF licenses this file +// * to you under the Apache License, Version 2.0 (the +// * "License"); you may not use this file except in compliance +// * with the License. You may obtain a copy of the License at +// * +// * http://www.apache.org/licenses/LICENSE-2.0 +// * +// * Unless required by applicable law or agreed to in writing, +// * software distributed under the License is distributed on an +// * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// * KIND, either express or implied. See the License for the +// * specific language governing permissions and limitations +// * under the License. +// */ +//package org.apache.tamaya.jsr382; +// +//import org.apache.tamaya.Configuration; +//import org.apache.tamaya.ConfigurationSnapshot; +// +//import javax.config.Config; +//import javax.config.ConfigAccessor; +//import javax.config.ConfigProvider; +//import javax.config.ConfigSnapshot; +//import java.util.Arrays; +//import java.util.Optional; +// +///** +// * Simple smoke example to use the JDK 382 API. +// */ +//public class SmokeExamples { +// +// +// static Server defaultServer; +// +// public static void main(String[] args) { +// } +// +// +// public void jsr382(){ +// +// Config config = ConfigProvider.getConfig(); +// +// String textValue = config.getValue("foo.bar.property", String.class); +// int intValue = config.getValue("foo.bar.property", int.class); +// Server serverValue = config.getValue("foo.bar.property", Server.class); +// } +// +// public void apacheTamaya(){ +// +// Configuration cfg = Configuration.current(); +// +// String textValue = cfg.get("foo.bar.property"); +// int intValue = cfg.get("foo.bar.property", int.class); +// Server serverValue = cfg.get("foo.bar.property", Server.class); +// } +// +// public void jsr382_Optional(){ +// +// Config config = ConfigProvider.getConfig(); +// +// Optional<String> textValue = config.getOptionalValue("foo.bar.property", String.class); +// Optional<Integer> intValue = config.getOptionalValue("foo.bar.property", Integer.class); +// Optional<Server> serverValue = config.getOptionalValue("foo.bar.property", Server.class); +// } +// +// public void apacheTamaya_Optional(){ +// +// Configuration cfg = Configuration.current(); +// +// Optional<String> textValue = cfg.getOptional("foo.bar.property"); +// Optional<Integer> intValue = cfg.getOptional("foo.bar.property", Integer.class); +// Optional<Server> serverValue = cfg.getOptional("foo.bar.property", Server.class); +// } +// +// public void jsr382_Defaults(){ +// +// Config config = ConfigProvider.getConfig(); +// +// String textValue = config.getOptionalValue("foo.bar.property", String.class).orElse("anyDefault"); +// Integer intValue = config.getOptionalValue("foo.bar.property", Integer.class).orElse(1234); +// Server serverValue = config.getOptionalValue("foo.bar.property", Server.class).orElse(defaultServer); +// } +// +// public void apacheTamaya_Defaults(){ +// +// Configuration cfg = Configuration.current(); +// +// String textValue = cfg.getOrDefault("foo.bar.property", "anyDefault"); +// Integer intValue = cfg.getOrDefault("foo.bar.property", Integer.class, 1234); +// Server serverValue = cfg.getOrDefault("foo.bar.property", Server.class, defaultServer); +// } +// +// public void jsr382_multiKeyLookup(){ +// +// Config config = ConfigProvider.getConfig(); +// +// ConfigAccessor<String> accessor = config.access("foo.bar.property"); +// accessor = accessor.addLookupSuffix("DEV").addLookupSuffix("server01"); +// accessor = accessor.withDefault("anyDefault"); +// String textValue = accessor.getValue(); +// } +// +// public void apacheTamaya_multiKeyLookup(){ +// +// Configuration config = Configuration.current(); +// +// String textValue = config.getOrDefault( +// Arrays.asList( +// "foo.bar.property.DEV.server1", +// "foo.bar.property.server1", +// "foo.bar.property.DEV", +// "foo.bar.property"), +// "anyDefault"); +// } +// +// public void jsr382_snapshot(){ +// +// Config config = ConfigProvider.getConfig(); +// +// ConfigAccessor<String> accessor = config.access("foo.bar.property"); +// accessor = accessor.addLookupSuffix("DEV"); +// accessor = accessor.withDefault("anyDefault"); +// ConfigAccessor<Integer> accessor2 = config.access("foo.bar.property2").as(Integer.class); +// accessor = accessor.withDefault("1234"); +// ConfigSnapshot snapshot = config.snapshotFor(accessor, accessor2); +// +// String property1 = accessor.getValue(snapshot); +// Integer property2 = accessor2.getValue(snapshot); +// } +// +// public void apacheTamaya_snapshot(){ +// +// ConfigurationSnapshot config = Configuration.current().getSnapshot( +// "foo.bar.property", "foo.bar.property.DEV", "foo.bar.property2"); +// +// String property1 = config.getOrDefault( +// Arrays.asList("foo.bar.property.DEV", "foo.bar.property"), +// "anyDefault"); +// Integer property2 = config.getOrDefault( +// "foo.bar.property2", Integer.class, 1234); +// } +// +//} http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/8ad95aa9/configjsr/src/test/java/org/apache/tamaya/jsr382/TamayaPropertySourceTest.java ---------------------------------------------------------------------- diff --git a/configjsr/src/test/java/org/apache/tamaya/jsr382/TamayaPropertySourceTest.java b/configjsr/src/test/java/org/apache/tamaya/jsr382/TamayaPropertySourceTest.java index e035a33..ee2447a 100644 --- a/configjsr/src/test/java/org/apache/tamaya/jsr382/TamayaPropertySourceTest.java +++ b/configjsr/src/test/java/org/apache/tamaya/jsr382/TamayaPropertySourceTest.java @@ -35,7 +35,7 @@ public class TamayaPropertySourceTest { @Test public void isScannable() throws Exception { - TamayaPropertySource source = new TamayaPropertySource(configSource); + TamayaPropertySourceAdapter source = new TamayaPropertySourceAdapter(configSource); assertThat(source.isScannable()).isTrue(); } @@ -44,7 +44,7 @@ public class TamayaPropertySourceTest { public void ordinalIsTheSameAsOfTheConfigSource() throws Exception { when(configSource.getOrdinal()).thenReturn(44); - TamayaPropertySource source = new TamayaPropertySource(configSource); + TamayaPropertySourceAdapter source = new TamayaPropertySourceAdapter(configSource); assertThat(source.getOrdinal()).isEqualTo(44); } http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/8ad95aa9/configjsr/src/test/java/org/apache/tamaya/jsr382/tck/TamayaConfigArchiveProcessor.java ---------------------------------------------------------------------- diff --git a/configjsr/src/test/java/org/apache/tamaya/jsr382/tck/TamayaConfigArchiveProcessor.java b/configjsr/src/test/java/org/apache/tamaya/jsr382/tck/TamayaConfigArchiveProcessor.java index fe2bea8..e6ba806 100644 --- a/configjsr/src/test/java/org/apache/tamaya/jsr382/tck/TamayaConfigArchiveProcessor.java +++ b/configjsr/src/test/java/org/apache/tamaya/jsr382/tck/TamayaConfigArchiveProcessor.java @@ -19,8 +19,8 @@ package org.apache.tamaya.jsr382.tck; import org.apache.tamaya.core.internal.converters.OptionalConverter; -import org.apache.tamaya.jsr382.JavaConfigAdapter; -import org.apache.tamaya.jsr382.JavaConfigProviderResolver; +import org.apache.tamaya.jsr382.JavaConfigAdapterFactory; +import org.apache.tamaya.jsr382.TamayaConfigProviderResolver; import org.apache.tamaya.jsr382.cdi.JavaConfigCDIExtension; import org.apache.tamaya.jsr382.converter.BooleanAsIntegerConverterFix; import org.apache.tamaya.spi.PropertyConverter; @@ -61,11 +61,11 @@ public class TamayaConfigArchiveProcessor implements ApplicationArchiveProcessor JavaArchive configJar = ShrinkWrap .create(JavaArchive.class, "tamaya-config-impl.jar") - .addPackage(JavaConfigAdapter.class.getPackage()) + .addPackage(JavaConfigAdapterFactory.class.getPackage()) .addPackage(JavaConfigCDIExtension.class.getPackage()) .addPackage(BooleanAsIntegerConverterFix.class.getPackage()) .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml") - .addAsServiceProvider(ConfigProviderResolver.class, JavaConfigProviderResolver.class) + .addAsServiceProvider(ConfigProviderResolver.class, TamayaConfigProviderResolver.class) .addAsServiceProvider(PropertyConverter.class, BooleanAsIntegerConverterFix.class) .addAsServiceProvider(PropertyConverter.class, OptionalConverter.class) .addAsServiceProvider(Extension.class, JavaConfigCDIExtension.class); http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/8ad95aa9/pom.xml ---------------------------------------------------------------------- diff --git a/pom.xml b/pom.xml index 8c80215..715ca1d 100644 --- a/pom.xml +++ b/pom.xml @@ -808,6 +808,7 @@ under the License. <module>metamodel</module> <module>uom</module> <module>vertx</module> + <module>configjsr</module> <!-- Once the API is officially available ... --> <!-- module>configjsr</module--> </modules>
