You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tamaya.apache.org by an...@apache.org on 2018/01/03 00:09:09 UTC
[13/18] incubator-tamaya-extensions git commit: Rewrite/adaptation
based on JSR API.
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/cfb364cd/modules/jndi/src/main/resources/META-INF/services/org.apache.tamaya.spi.PropertySource
----------------------------------------------------------------------
diff --git a/modules/jndi/src/main/resources/META-INF/services/org.apache.tamaya.spi.PropertySource b/modules/jndi/src/main/resources/META-INF/services/org.apache.tamaya.spi.PropertySource
index b587cf7..1b036f1 100644
--- a/modules/jndi/src/main/resources/META-INF/services/org.apache.tamaya.spi.PropertySource
+++ b/modules/jndi/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.jndi.JNDIPropertySource
\ No newline at end of file
+org.apache.tamaya.jndi.JNDIConfigSource
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/cfb364cd/modules/jndi/src/test/java/org/apache/tamaya/jndi/JNDIConfigSourceTest.java
----------------------------------------------------------------------
diff --git a/modules/jndi/src/test/java/org/apache/tamaya/jndi/JNDIConfigSourceTest.java b/modules/jndi/src/test/java/org/apache/tamaya/jndi/JNDIConfigSourceTest.java
new file mode 100644
index 0000000..bb00dd5
--- /dev/null
+++ b/modules/jndi/src/test/java/org/apache/tamaya/jndi/JNDIConfigSourceTest.java
@@ -0,0 +1,72 @@
+/*
+ * 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.jndi;
+
+import org.junit.Test;
+
+import javax.naming.Context;
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
+import java.io.File;
+import java.net.MalformedURLException;
+import java.util.Hashtable;
+import java.util.Map;
+
+import static junit.framework.TestCase.assertNotNull;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+public class JNDIConfigSourceTest {
+
+ private InitialContext createFSContext() throws NamingException, MalformedURLException {
+ Hashtable<String, String> env = new Hashtable<String, String>();
+ env.put (Context.INITIAL_CONTEXT_FACTORY,
+ "com.sun.jndi.fscontext.RefFSContextFactory");
+ return new InitialContext(env);
+ }
+
+ private Context getTestDirContext(InitialContext ctx) throws NamingException {
+ return (Context)ctx.lookup(new File("./src/test/jndi-dir").getAbsolutePath());
+ }
+
+ @Test
+ public void testCreateWithContext() throws NamingException, MalformedURLException {
+ new JNDIConfigSource("jndi-test", createFSContext());
+ }
+
+ @Test
+ public void testScanContext() throws NamingException, MalformedURLException {
+ JNDIConfigSource ps = new JNDIConfigSource("jndi-test", getTestDirContext(createFSContext()));
+ Map<String,String> props = ps.getProperties();
+ assertNotNull(props);
+ assertTrue(props.isEmpty());
+ ps.setScannable(true);
+ props = ps.getProperties();
+ assertNotNull(props);
+ assertFalse(props.isEmpty());
+ assertEquals(props.size(), 5);
+ assertNotNull(props.get("c.c1.test5"));
+ assertNotNull(props.get("c.test3"));
+ assertNotNull(props.get("c.test4"));
+ assertNotNull(props.get("b.test2"));
+ assertNotNull(props.get("a.test1"));
+ }
+
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/cfb364cd/modules/jndi/src/test/java/org/apache/tamaya/jndi/JNDIPropertySourceTest.java
----------------------------------------------------------------------
diff --git a/modules/jndi/src/test/java/org/apache/tamaya/jndi/JNDIPropertySourceTest.java b/modules/jndi/src/test/java/org/apache/tamaya/jndi/JNDIPropertySourceTest.java
deleted file mode 100644
index 1f06855..0000000
--- a/modules/jndi/src/test/java/org/apache/tamaya/jndi/JNDIPropertySourceTest.java
+++ /dev/null
@@ -1,75 +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.jndi;
-
-import org.apache.tamaya.spi.PropertyValue;
-import org.junit.Test;
-
-import javax.naming.Context;
-import javax.naming.InitialContext;
-import javax.naming.NamingException;
-import java.io.File;
-import java.net.MalformedURLException;
-import java.util.Hashtable;
-import java.util.Map;
-
-import static junit.framework.TestCase.assertNotNull;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
-
-public class JNDIPropertySourceTest{
-
- private InitialContext createFSContext() throws NamingException, MalformedURLException {
- Hashtable<String, String> env = new Hashtable<String, String>();
- env.put (Context.INITIAL_CONTEXT_FACTORY,
- "com.sun.jndi.fscontext.RefFSContextFactory");
- return new InitialContext(env);
- }
-
- private Context getTestDirContext(InitialContext ctx) throws NamingException {
- return (Context)ctx.lookup(new File("./src/test/jndi-dir").getAbsolutePath());
- }
-
- @Test
- public void testCreateWithContext() throws NamingException, MalformedURLException {
- new JNDIPropertySource("jndi-test", createFSContext());
- }
-
- @Test
- public void testScanContext() throws NamingException, MalformedURLException {
- JNDIPropertySource ps = new JNDIPropertySource("jndi-test", getTestDirContext(createFSContext()));
- assertFalse(ps.isScannable());
- Map<String,PropertyValue> props = ps.getProperties();
- assertNotNull(props);
- assertTrue(props.isEmpty());
- ps.setScannable(true);
- assertTrue(ps.isScannable());
- props = ps.getProperties();
- assertNotNull(props);
- assertFalse(props.isEmpty());
- assertEquals(props.size(), 5);
- assertNotNull(props.get("c.c1.test5"));
- assertNotNull(props.get("c.test3"));
- assertNotNull(props.get("c.test4"));
- assertNotNull(props.get("b.test2"));
- assertNotNull(props.get("a.test1"));
- }
-
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/cfb364cd/modules/microprofile/bnd.bnd
----------------------------------------------------------------------
diff --git a/modules/microprofile/bnd.bnd b/modules/microprofile/bnd.bnd
deleted file mode 100644
index da67308..0000000
--- a/modules/microprofile/bnd.bnd
+++ /dev/null
@@ -1,34 +0,0 @@
--buildpath: \
- osgi.annotation; version=6.0.0,\
- osgi.core; version=6.0,\
- osgi.cmpn; version=6.0
-
--testpath: \
- ${junit}
-
-javac.source: 1.8
-javac.target: 1.8
-
-Bundle-Version: ${version}.${tstamp}
-Bundle-Name: Apache Tamaya - Microprofile
-Bundle-SymbolicName: org.apache.tamaya.microprofile
-Bundle-Description: Apacha Tamaya Config - Microprofile Implementation
-Bundle-Category: Implementation
-Bundle-Copyright: (C) Apache Foundation
-Bundle-License: Apache Licence version 2
-Bundle-Vendor: Apache Software Foundation
-Bundle-ContactAddress: dev-tamaya@incubator.apache.org
-Bundle-DocURL: http://tamaya.apache.org
-Export-Package: \
- org.apache.tamaya.microprofile,\
- org.apache.tamaya.microprofile.cdi,\
- org.apache.tamaya.microprofile.converter
-Import-Package: \
- org.apache.tamaya,\
- org.apache.tamaya.spi,\
- org.eclipse.microprofile.config
-Export-Service: \
- org.apache.tamaya.spi.PropertyConverter,\
- org.apache.tamaya.spi.ProperySource,\
- org.eclipse.microprofile.config.spi.ConfigProviderResolver,\
- javax.enterprise.inject.spi.Extension
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/cfb364cd/modules/microprofile/pom.xml
----------------------------------------------------------------------
diff --git a/modules/microprofile/pom.xml b/modules/microprofile/pom.xml
deleted file mode 100644
index 86b6889..0000000
--- a/modules/microprofile/pom.xml
+++ /dev/null
@@ -1,166 +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.
--->
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
- <modelVersion>4.0.0</modelVersion>
-
- <parent>
- <groupId>org.apache.tamaya.ext</groupId>
- <artifactId>tamaya-extensions</artifactId>
- <version>0.4-incubating-SNAPSHOT</version>
- </parent>
-
- <artifactId>tamaya-microprofile</artifactId>
- <name>Apache Tamaya Modules - Microprofile API</name>
- <packaging>jar</packaging>
-
- <properties>
- <maven.compile.sourceLevel>1.8</maven.compile.sourceLevel>
- <maven.compile.targetLevel>1.8</maven.compile.targetLevel>
- <microprofile.config.version>1.1</microprofile.config.version>
- <geronimo-atinject-1.0-spec.version>1.0</geronimo-atinject-1.0-spec.version>
- <geronimo-jcdi-1.1-spec.version>1.0</geronimo-jcdi-1.1-spec.version>
- <version.shrinkwrap.resolvers>2.2.6</version.shrinkwrap.resolvers>
- <tamaya-version>0.4-incubating-SNAPSHOT</tamaya-version>
- <arquillian.version>1.1.13.Final</arquillian.version>
- <arquillian-weld-embedded.version>2.0.0.Beta5</arquillian-weld-embedded.version>
- <cdi-api.version>2.0</cdi-api.version>
- <weld.version>3.0.1.Final</weld.version>
- <deltaspike.version>1.1.0</deltaspike.version>
- <openejb.version>4.7.1</openejb.version>
- </properties>
-
- <dependencies>
- <dependency>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.hamcrest</groupId>
- <artifactId>java-hamcrest</artifactId>
- <scope>test</scope>
- </dependency>
-
- <dependency>
- <groupId>org.apache.tamaya</groupId>
- <artifactId>tamaya-core</artifactId>
- <version>${tamaya-version}</version>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.apache.tamaya</groupId>
- <artifactId>tamaya-api</artifactId>
- <version>${tamaya-version}</version>
- </dependency>
- <dependency>
- <groupId>org.apache.tamaya.ext</groupId>
- <artifactId>tamaya-functions</artifactId>
- <version>${tamaya-version}</version>
- </dependency>
- <dependency>
- <groupId>org.apache.tamaya.ext</groupId>
- <artifactId>tamaya-events</artifactId>
- <version>${tamaya-version}</version>
- </dependency>
- <dependency>
- <groupId>org.assertj</groupId>
- <artifactId>assertj-core</artifactId>
- </dependency>
- <dependency>
- <groupId>org.eclipse.microprofile.config</groupId>
- <artifactId>microprofile-config-api</artifactId>
- <version>${microprofile.config.version}</version>
- </dependency>
- <dependency>
- <groupId>org.mockito</groupId>
- <artifactId>mockito-core</artifactId>
- </dependency>
- <dependency>
- <groupId>javax.enterprise</groupId>
- <artifactId>cdi-api</artifactId>
- <version>${cdi-api.version}</version>
- <scope>provided</scope>
- </dependency>
- <dependency>
- <groupId>org.jboss.weld.se</groupId>
- <artifactId>weld-se-shaded</artifactId>
- <version>${weld.version}</version>
- <scope>test</scope>
- </dependency>
- <!-- Microprofile TCK support only -->
- <dependency>
- <groupId>org.jboss.arquillian.testng</groupId>
- <artifactId>arquillian-testng-container</artifactId>
- <version>${arquillian.version}</version>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.testng</groupId>
- <artifactId>testng</artifactId>
- <version>6.9.9</version>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.jboss.shrinkwrap.resolver</groupId>
- <artifactId>shrinkwrap-resolver-depchain</artifactId>
- <version>${version.shrinkwrap.resolvers}</version>
- <scope>test</scope>
- <type>pom</type>
- </dependency>
- </dependencies>
-
- <profiles>
- <profile>
- <id>TCK</id>
- <activation>
- <activeByDefault>false</activeByDefault>
- </activation>
- <dependencies>
- <dependency>
- <groupId>org.eclipse.microprofile.config</groupId>
- <artifactId>microprofile-config-tck</artifactId>
- <version>${microprofile.config.version}</version>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.jboss.arquillian.container</groupId>
- <artifactId>arquillian-weld-embedded</artifactId>
- <version>${arquillian-weld-embedded.version}</version>
- <scope>test</scope>
- </dependency>
- </dependencies>
-
- <build>
- <plugins>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-surefire-plugin</artifactId>
- <version>2.20.1</version>
- <configuration>
- <suiteXmlFiles>
- <suiteXmlFile>src/test/tck-suite.xml</suiteXmlFile>
- </suiteXmlFiles>
- </configuration>
- </plugin>
- </plugins>
- </build>
- </profile>
- </profiles>
-
-</project>
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/cfb364cd/modules/microprofile/src/main/java/org/apache/tamaya/microprofile/MicroprofileAdapter.java
----------------------------------------------------------------------
diff --git a/modules/microprofile/src/main/java/org/apache/tamaya/microprofile/MicroprofileAdapter.java b/modules/microprofile/src/main/java/org/apache/tamaya/microprofile/MicroprofileAdapter.java
deleted file mode 100644
index 8f5002c..0000000
--- a/modules/microprofile/src/main/java/org/apache/tamaya/microprofile/MicroprofileAdapter.java
+++ /dev/null
@@ -1,185 +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.microprofile;
-
-
-import org.apache.tamaya.*;
-import org.apache.tamaya.spi.ConfigurationContextBuilder;
-import org.apache.tamaya.spi.PropertyConverter;
-import org.apache.tamaya.spi.PropertySource;
-import org.apache.tamaya.spi.PropertyValue;
-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.Converter;
-
-import java.util.*;
-
-/**
- * Utility class for adapting microprofile artifacts into Tamaya artifacts and vice versa.
- */
-public final class MicroprofileAdapter{
-
- /**
- * Singleton constructor.
- */
- private MicroprofileAdapter(){}
-
- /**
- * Converts a Tamaya {@link Configuration} into a Microprofile.io {@link Config}.
- * @param config the Tamaya {@link Configuration} instance, not null.
- * @return the corresponding Microprofile.io {@link Config} instance, never null.
- */
- public static Config toConfig(Configuration config){
- if(config instanceof TamayaConfiguration){
- return ((TamayaConfiguration)config).getConfig();
- }
- return new MicroprofileConfig(config);
- }
-
- /**
- * Converts a Microprofile {@link Config}s into Tamaya {@link Configuration}s.
- * @param config the Microprofile {@link Config} instance, not null.
- * @return the corresponding Tamaya {@link Configuration} instance, never null.
- */
- public static Configuration toConfiguration(Config config){
- if(config instanceof MicroprofileConfig){
- return ((MicroprofileConfig)config).getConfiguration();
- }
- return new TamayaConfiguration(config);
- }
-
- /**
- * Converts a Tamaya {@link PropertySource}s into a Microprofile.io {@link ConfigSource}.
- * @param propertySources the Tamaya {@link PropertySource} instances, not null.
- * @return the corresponding Microprofile.io {@link ConfigSource} instance, never null.
- */
- public static List<ConfigSource> toConfigSources(Iterable<PropertySource> propertySources) {
- List<ConfigSource> configSources = new ArrayList<>();
- for(PropertySource ps:propertySources){
- configSources.add(toConfigSource(ps));
- }
- Collections.reverse(configSources);
- return configSources;
- }
-
- /**
- * Converts a Microprofile {@link ConfigSource}s into Tamaya {@link PropertySource}s.
- * @param configSources the Microprofile {@link ConfigSource} instances, not null.
- * @return the corresponding Tamaya {@link PropertySource} instances, never null.
- */
- public static List<PropertySource> toPropertySources(Iterable<ConfigSource> configSources) {
- List<PropertySource> propertySources = new ArrayList<>();
- for(ConfigSource cs:configSources){
- propertySources.add(toPropertySource(cs));
- }
- return propertySources;
- }
-
- /**
- * Converts a Tamaya {@link PropertySource} into a Microprofile.io {@link ConfigSource}.
- * @param propertySource the Tamaya {@link PropertySource} instance, not null.
- * @return the corresponding Microprofile.io {@link ConfigSource} instance, never null.
- */
- public static ConfigSource toConfigSource(PropertySource propertySource) {
- if(propertySource instanceof TamayaPropertySource){
- return ((TamayaPropertySource)propertySource).getConfigSource();
- }
- return new MicroprofileConfigSource(propertySource);
- }
-
- /**
- * Converts a Microprofile {@link ConfigSource} into a Tamaya {@link PropertySource}.
- * @param configSource the Microprofile {@link ConfigSource} instance, not null.
- * @return the corresponding Tamaya {@link PropertySource} instance, never null.
- */
- public static PropertySource toPropertySource(ConfigSource configSource) {
- if(configSource instanceof MicroprofileConfigSource){
- return ((MicroprofileConfigSource)configSource).getPropertySource();
- }
- return new TamayaPropertySource(configSource);
- }
-
- /**
- * Converts a Microprofile {@link Converter} into a Tamaya {@link PropertyConverter}.
- * @param converter the Microprofile {@link Converter} instance, not null.
- * @param <T> the target type
- * @return the corresponding Tamaya {@link PropertyConverter} instance, never null.
- */
- public static <T> PropertyConverter<T> toPropertyConverter(Converter<T> converter) {
- if(converter instanceof MicroprofileConverter){
- return ((MicroprofileConverter)converter).getPropertyConverter();
- }
- return new TamayaPropertyConverter(converter);
- }
-
- /**
- * Converts a Tamaya {@link PropertyConverter} into a Microprofile.io {@link Converter}.
- * @param converter the Tamaya {@link PropertyConverter} instance, not null.
- * @param <T> the target type
- * @return the corresponding Microprofile.io {@link Converter} instance, never null.
- */
- public static <T> Converter<T> toConverter(PropertyConverter<T> converter) {
- if(converter instanceof TamayaPropertyConverter){
- return ((TamayaPropertyConverter)converter).getConverter();
- }
- return new MicroprofileConverter(converter);
- }
-
- /**
- * Converts a Tamaya {@link ConfigurationContextBuilder} into a Microprofile.io {@link ConfigBuilder}.
- * @param builder the Tamaya {@link ConfigurationContextBuilder} instance, not null.
- * @return the corresponding Microprofile.io {@link ConfigBuilder} instance, never null.
- */
- public static ConfigBuilder toConfigBuilder(ConfigurationContextBuilder builder) {
- return new MicroprofileConfigBuilder(builder);
- }
-
- /**
- * Converts the given Tamaya key, value map into a corresponding String based map, hereby
- * omitting all meta-entries.
- * @param properties the Tamaya key, value map, not null.
- * @return the corresponding String based map, never null.
- */
- public static Map<String, String> toStringMap(Map<String, PropertyValue> properties) {
- Map<String, String> valueMap = new HashMap<>(properties.size());
- for(Map.Entry<String,PropertyValue> en:properties.entrySet()){
- if(en.getValue().getValue()!=null) {
- valueMap.put(en.getKey(), en.getValue().getValue());
- }
- }
- return valueMap;
- }
-
- /**
- * Converts the given String based key, value map into a corresponding String,PropertyValue
- * based map.
- * @param properties the String based key, value map, not null.
- * @param source the source of the entries, not null.
- * @return the corresponding String,PropertyValue based map, never null.
- */
- public static Map<String, PropertyValue> toPropertyValueMap(Map<String, String> properties, String source) {
- 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(), source));
- }
- return valueMap;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/cfb364cd/modules/microprofile/src/main/java/org/apache/tamaya/microprofile/MicroprofileConfig.java
----------------------------------------------------------------------
diff --git a/modules/microprofile/src/main/java/org/apache/tamaya/microprofile/MicroprofileConfig.java b/modules/microprofile/src/main/java/org/apache/tamaya/microprofile/MicroprofileConfig.java
deleted file mode 100644
index 61c3cdc..0000000
--- a/modules/microprofile/src/main/java/org/apache/tamaya/microprofile/MicroprofileConfig.java
+++ /dev/null
@@ -1,100 +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.microprofile;
-
-import org.apache.tamaya.ConfigException;
-import org.apache.tamaya.Configuration;
-import org.apache.tamaya.events.FrozenConfiguration;
-import org.apache.tamaya.spi.PropertySource;
-import org.eclipse.microprofile.config.Config;
-import org.eclipse.microprofile.config.spi.ConfigSource;
-
-import java.io.IOException;
-import java.io.ObjectInputStream;
-import java.io.ObjectOutputStream;
-import java.io.Serializable;
-import java.util.*;
-
-/**
- * Microprofile {@link ConfigSource} implementation that wraps a {@link PropertySource} instance.
- */
-public class MicroprofileConfig implements Config, Serializable {
-
- private Configuration delegate;
-
- public MicroprofileConfig(Configuration delegate){
- this.delegate = Objects.requireNonNull(delegate);
- }
-
- public Configuration getConfiguration(){
- return this.delegate;
- }
-
-
- @Override
- public <T> T getValue(String propertyName, Class<T> propertyType) {
- T value = null;
- try{
- value = delegate.get(propertyName, propertyType);
- }catch(ConfigException e){
- if(e.toString().contains("Unparseable")){
- throw new IllegalArgumentException("Invalid type: " + propertyType.getName());
- }
- }
- if(value == null){
- throw new NoSuchElementException("No such config property: " + propertyName);
- }
- return value;
- }
-
- @Override
- public <T> Optional<T> getOptionalValue(String propertyName, Class<T> propertyType) {
- return Optional.ofNullable(delegate.get(propertyName, propertyType));
- }
-
- @Override
- public Iterable<String> getPropertyNames() {
- return delegate.getProperties().keySet();
- }
-
- @Override
- public Iterable<ConfigSource> getConfigSources() {
- return MicroprofileAdapter.toConfigSources(delegate.getContext().getPropertySources());
- }
-
- @Override
- public String toString() {
- return "MicroprofileConfig{" +
- "delegate=" + delegate +
- '}';
- }
-
- private void writeObject(ObjectOutputStream out) throws IOException{
- if(!(this.delegate instanceof Serializable)){
- out.writeObject(FrozenConfiguration.of(this.delegate));
- }else {
- out.writeObject(this.delegate);
- }
- }
-
- private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException{
- this.delegate = (Configuration)in.readObject();
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/cfb364cd/modules/microprofile/src/main/java/org/apache/tamaya/microprofile/MicroprofileConfigBuilder.java
----------------------------------------------------------------------
diff --git a/modules/microprofile/src/main/java/org/apache/tamaya/microprofile/MicroprofileConfigBuilder.java b/modules/microprofile/src/main/java/org/apache/tamaya/microprofile/MicroprofileConfigBuilder.java
deleted file mode 100644
index 82209c3..0000000
--- a/modules/microprofile/src/main/java/org/apache/tamaya/microprofile/MicroprofileConfigBuilder.java
+++ /dev/null
@@ -1,140 +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.microprofile;
-
-import org.apache.tamaya.ConfigurationProvider;
-import org.apache.tamaya.TypeLiteral;
-import org.apache.tamaya.spi.ConfigurationContextBuilder;
-import org.apache.tamaya.spi.ServiceContextManager;
-import org.apache.tamaya.spisupport.propertysource.EnvironmentPropertySource;
-import org.apache.tamaya.spisupport.PropertySourceComparator;
-import org.apache.tamaya.spisupport.propertysource.SystemPropertySource;
-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 java.util.Objects;
-
-/**
- * Created by atsticks on 23.03.17.
- */
-final class MicroprofileConfigBuilder implements ConfigBuilder{
-
- private ConfigurationContextBuilder contextBuilder;
- private ClassLoader classLoader;
-
- MicroprofileConfigBuilder(ConfigurationContextBuilder contextBuilder){
- this.contextBuilder = Objects.requireNonNull(contextBuilder);
- contextBuilder.addDefaultPropertyConverters();
- }
-
- public ConfigurationContextBuilder getConfigurationContextBuilder(){
- return contextBuilder;
- }
-
- /**
- * Add the default config sources appearing on the builder's classpath
- * including:
- * <ol>
- * <li>System properties</li>
- * <li>Environment properties</li>
- * <li>/META-INF/microprofile-config.properties</li>
- * </ol>
- *
- * @return the ConfigBuilder with the default config sources
- */
- @Override
- public ConfigBuilder addDefaultSources() {
- contextBuilder.addPropertySources(
- new SystemPropertySource(400),
- new EnvironmentPropertySource(300),
- new MicroprofileDefaultProperties());
- contextBuilder.sortPropertySources(PropertySourceComparator.getInstance());
- return this;
- }
-
- /**
- * Add ConfigSources registered using the ServiceLoader.
- * @return the ConfigBuilder with the added config sources
- */
- @Override
- public ConfigBuilder addDiscoveredSources() {
- for(ConfigSource configSource: ServiceContextManager.getServiceContext().getServices(ConfigSource.class)){
- contextBuilder.addPropertySources(MicroprofileAdapter.toPropertySource(configSource));
- }
- for(ConfigSourceProvider configSourceProvider: ServiceContextManager.getServiceContext().getServices(ConfigSourceProvider.class)){
- contextBuilder.addPropertySources(MicroprofileAdapter.toPropertySources(configSourceProvider.getConfigSources(
- Thread.currentThread().getContextClassLoader()
- )));
- }
- contextBuilder.sortPropertySources(PropertySourceComparator.getInstance());
- return this;
- }
-
- /**
- * Add Converters registered using the ServiceLoader.
- * @return the ConfigBuilder with the added config converters
- */
- @Override
- public ConfigBuilder addDiscoveredConverters() {
- for(Converter<?> converter: ServiceContextManager.getServiceContext().getServices(Converter.class)){
- TypeLiteral targetType = TypeLiteral.of(
- TypeLiteral.getGenericInterfaceTypeParameters(converter.getClass(),Converter.class)[0]);
- contextBuilder.addPropertyConverters(targetType,
- MicroprofileAdapter.toPropertyConverter(converter));
- }
- return this;
- }
-
- @Override
- public ConfigBuilder forClassLoader(ClassLoader loader) {
- this.classLoader = loader;
- return this;
- }
-
- @Override
- public ConfigBuilder withSources(ConfigSource... sources) {
- for(ConfigSource source:sources){
- contextBuilder.addPropertySources(MicroprofileAdapter.toPropertySource(source));
- }
- return this;
- }
-
- @Override
- public ConfigBuilder withConverters(Converter<?>... converters) {
- for(Converter<?> converter:converters){
- TypeLiteral lit = TypeLiteral.of(converter.getClass());
- TypeLiteral target = TypeLiteral.of(lit.getType());
- contextBuilder.removePropertyConverters(target);
- contextBuilder.addPropertyConverters(
- target,
- MicroprofileAdapter.toPropertyConverter(converter));
- }
- return this;
- }
-
- @Override
- public Config build() {
- return MicroprofileAdapter.toConfig(ConfigurationProvider.createConfiguration(
- contextBuilder.build()
- ));
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/cfb364cd/modules/microprofile/src/main/java/org/apache/tamaya/microprofile/MicroprofileConfigProviderResolver.java
----------------------------------------------------------------------
diff --git a/modules/microprofile/src/main/java/org/apache/tamaya/microprofile/MicroprofileConfigProviderResolver.java b/modules/microprofile/src/main/java/org/apache/tamaya/microprofile/MicroprofileConfigProviderResolver.java
deleted file mode 100644
index 92a928a..0000000
--- a/modules/microprofile/src/main/java/org/apache/tamaya/microprofile/MicroprofileConfigProviderResolver.java
+++ /dev/null
@@ -1,82 +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.microprofile;
-
-import org.apache.tamaya.ConfigurationProvider;
-import org.apache.tamaya.spi.ConfigurationContextBuilder;
-import org.eclipse.microprofile.config.Config;
-import org.eclipse.microprofile.config.spi.ConfigBuilder;
-import org.eclipse.microprofile.config.spi.ConfigProviderResolver;
-
-import java.util.Map;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.logging.Logger;
-
-/**
- * Created by atsticks on 23.03.17.
- */
-public class MicroprofileConfigProviderResolver extends ConfigProviderResolver {
-
- private Map<ClassLoader, Config> configs = new ConcurrentHashMap<>();
-
- @Override
- public Config getConfig() {
- return getConfig(Thread.currentThread().getContextClassLoader());
- }
-
- @Override
- public Config getConfig(ClassLoader loader) {
- Config config = this.configs.get(loader);
- if(config==null){
- ConfigurationContextBuilder builder = ConfigurationProvider.getConfigurationContextBuilder();
- builder.addDefaultPropertyConverters();
- MicroprofileConfigBuilder microConfigBuilder = new MicroprofileConfigBuilder(builder);
- microConfigBuilder.addDefaultSources();
- microConfigBuilder.addDiscoveredSources();
- config = microConfigBuilder.build();
- this.configs.put(loader, config);
- }
- return config;
- }
-
- @Override
- public ConfigBuilder getBuilder() {
- return new MicroprofileConfigBuilder(ConfigurationProvider.getConfigurationContextBuilder());
- }
-
- @Override
- public void registerConfig(Config config, ClassLoader classLoader) {
- if(configs.containsKey(classLoader)){
- Logger.getLogger(getClass().getName())
- .warning("Replacing existing config for classloader: " + classLoader);
-// throw new IllegalArgumentException("Already a config registered with classloader: " + classLoader);
- }
- this.configs.put(classLoader, config);
- }
-
- @Override
- public void releaseConfig(Config config) {
- for(Map.Entry<ClassLoader, Config> en: this.configs.entrySet()){
- if(en.getValue().equals(config)){
- this.configs.remove(en.getKey());
- return;
- }
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/cfb364cd/modules/microprofile/src/main/java/org/apache/tamaya/microprofile/MicroprofileConfigSource.java
----------------------------------------------------------------------
diff --git a/modules/microprofile/src/main/java/org/apache/tamaya/microprofile/MicroprofileConfigSource.java b/modules/microprofile/src/main/java/org/apache/tamaya/microprofile/MicroprofileConfigSource.java
deleted file mode 100644
index 39ca119..0000000
--- a/modules/microprofile/src/main/java/org/apache/tamaya/microprofile/MicroprofileConfigSource.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.microprofile;
-
-import org.apache.tamaya.spi.PropertySource;
-import org.apache.tamaya.spi.PropertyValue;
-import org.eclipse.microprofile.config.spi.ConfigSource;
-
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Objects;
-
-/**
- * Microprofile {@link ConfigSource} implementation that wraps a {@link PropertySource} instance.
- */
-public class MicroprofileConfigSource implements ConfigSource{
-
- private PropertySource delegate;
-
- public MicroprofileConfigSource(PropertySource propertySource){
- this.delegate = Objects.requireNonNull(propertySource);
- }
-
- public PropertySource getPropertySource(){
- return this.delegate;
- }
-
- @Override
- public int getOrdinal() {
- return delegate.getOrdinal();
- }
-
- @Override
- public String getName() {
- return delegate.getName();
- }
-
- @Override
- public String getValue(String key) {
- PropertyValue value = delegate.get(key);
- if(value!=null){
- return value.getValue();
- }
- return null;
- }
-
- @Override
- public Map<String, String> getProperties() {
- return toMap(delegate.getProperties());
- }
-
- private Map<String, String> toMap(Map<String, PropertyValue> properties) {
- Map<String, String> valueMap = new HashMap<>(properties.size());
- for(Map.Entry<String,PropertyValue> en:properties.entrySet()){
- if(en.getValue().getValue()!=null) {
- valueMap.put(en.getKey(), en.getValue().getValue());
- }
- }
- return valueMap;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/cfb364cd/modules/microprofile/src/main/java/org/apache/tamaya/microprofile/MicroprofileConfigSourceProvider.java
----------------------------------------------------------------------
diff --git a/modules/microprofile/src/main/java/org/apache/tamaya/microprofile/MicroprofileConfigSourceProvider.java b/modules/microprofile/src/main/java/org/apache/tamaya/microprofile/MicroprofileConfigSourceProvider.java
deleted file mode 100644
index 5176940..0000000
--- a/modules/microprofile/src/main/java/org/apache/tamaya/microprofile/MicroprofileConfigSourceProvider.java
+++ /dev/null
@@ -1,64 +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.microprofile;
-
-import org.apache.tamaya.spi.PropertySource;
-import org.apache.tamaya.spi.PropertySourceProvider;
-import org.apache.tamaya.spi.PropertyValue;
-import org.eclipse.microprofile.config.spi.ConfigSource;
-import org.eclipse.microprofile.config.spi.ConfigSourceProvider;
-
-import java.util.*;
-
-/**
- * Microprofile {@link ConfigSource} implementation that wraps a {@link PropertySource} instance.
- */
-public class MicroprofileConfigSourceProvider implements ConfigSourceProvider{
-
- private PropertySourceProvider delegate;
-
- public MicroprofileConfigSourceProvider(PropertySourceProvider propertySourceProvider){
- this.delegate = Objects.requireNonNull(propertySourceProvider);
- }
-
- public PropertySourceProvider getPropertySourceProvider(){
- return this.delegate;
- }
-
-
- private Map<String, String> toMap(Map<String, PropertyValue> properties) {
- Map<String, String> valueMap = new HashMap<>(properties.size());
- for(Map.Entry<String,PropertyValue> en:properties.entrySet()){
- if(en.getValue().getValue()!=null) {
- valueMap.put(en.getKey(), en.getValue().getValue());
- }
- }
- return valueMap;
- }
-
- @Override
- public Iterable<ConfigSource> getConfigSources(ClassLoader forClassLoader) {
- if(delegate instanceof TamayaPropertySourceProvider){
- return ((TamayaPropertySourceProvider)delegate).getConfigSourceProvider()
- .getConfigSources(forClassLoader);
- }else {
- return MicroprofileAdapter.toConfigSources(delegate.getPropertySources());
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/cfb364cd/modules/microprofile/src/main/java/org/apache/tamaya/microprofile/MicroprofileConverter.java
----------------------------------------------------------------------
diff --git a/modules/microprofile/src/main/java/org/apache/tamaya/microprofile/MicroprofileConverter.java b/modules/microprofile/src/main/java/org/apache/tamaya/microprofile/MicroprofileConverter.java
deleted file mode 100644
index cb6aab2..0000000
--- a/modules/microprofile/src/main/java/org/apache/tamaya/microprofile/MicroprofileConverter.java
+++ /dev/null
@@ -1,50 +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.microprofile;
-
-
-import org.apache.tamaya.TypeLiteral;
-import org.apache.tamaya.spi.ConversionContext;
-import org.apache.tamaya.spi.PropertyConverter;
-import org.eclipse.microprofile.config.spi.ConfigSource;
-import org.eclipse.microprofile.config.spi.Converter;
-
-import java.util.Objects;
-
-/**
- * Property source implementation that wraps a Microprofile {@link ConfigSource} instance.
- */
-public class MicroprofileConverter<T> implements Converter<T> {
-
- private PropertyConverter<T> delegate;
-
- public MicroprofileConverter(PropertyConverter<T> delegate){
- this.delegate = Objects.requireNonNull(delegate);
- }
-
- public PropertyConverter<T> getPropertyConverter(){
- return this.delegate;
- }
-
- @Override
- public T convert(String value) {
- return delegate.convert(value, new ConversionContext.Builder("microprofile:no-key", TypeLiteral.of(
- TypeLiteral.of(getClass()).getType())).build());
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/cfb364cd/modules/microprofile/src/main/java/org/apache/tamaya/microprofile/MicroprofileDefaultProperties.java
----------------------------------------------------------------------
diff --git a/modules/microprofile/src/main/java/org/apache/tamaya/microprofile/MicroprofileDefaultProperties.java b/modules/microprofile/src/main/java/org/apache/tamaya/microprofile/MicroprofileDefaultProperties.java
deleted file mode 100644
index b20dc8f..0000000
--- a/modules/microprofile/src/main/java/org/apache/tamaya/microprofile/MicroprofileDefaultProperties.java
+++ /dev/null
@@ -1,33 +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.microprofile;
-
-import org.apache.tamaya.spisupport.propertysource.PropertiesResourcePropertySource;
-
-
-/**
- * Default property source for config properties in the classpath.
- */
-public class MicroprofileDefaultProperties extends PropertiesResourcePropertySource{
-
- public MicroprofileDefaultProperties() {
- super("META-INF/microprofile-config.properties", null);
- setDefaultOrdinal(100);
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/cfb364cd/modules/microprofile/src/main/java/org/apache/tamaya/microprofile/TamayaConfiguration.java
----------------------------------------------------------------------
diff --git a/modules/microprofile/src/main/java/org/apache/tamaya/microprofile/TamayaConfiguration.java b/modules/microprofile/src/main/java/org/apache/tamaya/microprofile/TamayaConfiguration.java
deleted file mode 100644
index 0f27821..0000000
--- a/modules/microprofile/src/main/java/org/apache/tamaya/microprofile/TamayaConfiguration.java
+++ /dev/null
@@ -1,93 +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.microprofile;
-
-import org.apache.tamaya.*;
-import org.apache.tamaya.spi.ConfigurationContext;
-import org.eclipse.microprofile.config.Config;
-
-import java.util.*;
-
-/**
- * Created by atsticks on 23.03.17.
- */
-public class TamayaConfiguration implements Configuration{
-
- private Config delegate;
-
- public TamayaConfiguration(Config config){
- this.delegate = Objects.requireNonNull(config);
- }
-
- public Config getConfig(){
- return delegate;
- }
-
- @Override
- public String get(String key) {
- return this.delegate.getOptionalValue(key, String.class).orElse(null);
- }
-
- @Override
- public String getOrDefault(String key, String defaultValue) {
- return this.delegate.getOptionalValue(key, String.class).orElse(defaultValue);
- }
-
- @Override
- public <T> T getOrDefault(String key, Class<T> type, T defaultValue) {
- return this.delegate.getOptionalValue(key, type).orElse(defaultValue);
- }
-
- @Override
- public <T> T get(String key, Class<T> type) {
- return this.delegate.getOptionalValue(key, type).orElseThrow(
- () -> new NoSuchElementException("Missing key: " + key));
- }
-
- @Override
- public <T> T get(String key, TypeLiteral<T> type) {
- return this.delegate.getOptionalValue(key, type.getRawType()).orElseThrow(
- () -> new NoSuchElementException("Missing key: " + key));
- }
-
- @Override
- public <T> T getOrDefault(String key, TypeLiteral<T> type, T defaultValue) {
- return null;
- }
-
- @Override
- public Map<String, String> getProperties() {
- return null;
- }
-
- @Override
- public Configuration with(ConfigOperator operator) {
- return operator.operate(this);
- }
-
- @Override
- public <T> T query(ConfigQuery<T> query) {
- return query.query(this);
- }
-
- @Override
- public ConfigurationContext getContext() {
- return null;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/cfb364cd/modules/microprofile/src/main/java/org/apache/tamaya/microprofile/TamayaPropertyConverter.java
----------------------------------------------------------------------
diff --git a/modules/microprofile/src/main/java/org/apache/tamaya/microprofile/TamayaPropertyConverter.java b/modules/microprofile/src/main/java/org/apache/tamaya/microprofile/TamayaPropertyConverter.java
deleted file mode 100644
index a83008a..0000000
--- a/modules/microprofile/src/main/java/org/apache/tamaya/microprofile/TamayaPropertyConverter.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 org.apache.tamaya.microprofile;
-
-
-import org.apache.tamaya.spi.ConversionContext;
-import org.apache.tamaya.spi.PropertyConverter;
-import org.eclipse.microprofile.config.spi.ConfigSource;
-import org.eclipse.microprofile.config.spi.Converter;
-
-import java.util.Objects;
-
-/**
- * Property source implementation that wraps a Microprofile {@link ConfigSource} 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-extensions/blob/cfb364cd/modules/microprofile/src/main/java/org/apache/tamaya/microprofile/TamayaPropertySource.java
----------------------------------------------------------------------
diff --git a/modules/microprofile/src/main/java/org/apache/tamaya/microprofile/TamayaPropertySource.java b/modules/microprofile/src/main/java/org/apache/tamaya/microprofile/TamayaPropertySource.java
deleted file mode 100644
index 0511e32..0000000
--- a/modules/microprofile/src/main/java/org/apache/tamaya/microprofile/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.microprofile;
-
-import org.apache.tamaya.spi.PropertySource;
-import org.apache.tamaya.spi.PropertyValue;
-import org.eclipse.microprofile.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 Microprofile {@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-extensions/blob/cfb364cd/modules/microprofile/src/main/java/org/apache/tamaya/microprofile/TamayaPropertySourceProvider.java
----------------------------------------------------------------------
diff --git a/modules/microprofile/src/main/java/org/apache/tamaya/microprofile/TamayaPropertySourceProvider.java b/modules/microprofile/src/main/java/org/apache/tamaya/microprofile/TamayaPropertySourceProvider.java
deleted file mode 100644
index 5b0bcf7..0000000
--- a/modules/microprofile/src/main/java/org/apache/tamaya/microprofile/TamayaPropertySourceProvider.java
+++ /dev/null
@@ -1,56 +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.microprofile;
-
-
-import org.apache.tamaya.spi.PropertySource;
-import org.apache.tamaya.spi.PropertySourceProvider;
-import org.eclipse.microprofile.config.spi.ConfigSource;
-import org.eclipse.microprofile.config.spi.ConfigSourceProvider;
-
-import java.util.*;
-
-/**
- * Microprofile {@link ConfigSource} implementation that wraps a {@link PropertySource} 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 MicroprofileConfigSourceProvider){
- return ((MicroprofileConfigSourceProvider)delegate).getPropertySourceProvider()
- .getPropertySources();
- }else {
- return MicroprofileAdapter.toPropertySources(
- delegate.getConfigSources(Thread.currentThread().getContextClassLoader()));
- }
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/cfb364cd/modules/microprofile/src/main/java/org/apache/tamaya/microprofile/cdi/BridgingConfigBean.java
----------------------------------------------------------------------
diff --git a/modules/microprofile/src/main/java/org/apache/tamaya/microprofile/cdi/BridgingConfigBean.java b/modules/microprofile/src/main/java/org/apache/tamaya/microprofile/cdi/BridgingConfigBean.java
deleted file mode 100644
index a08f76f..0000000
--- a/modules/microprofile/src/main/java/org/apache/tamaya/microprofile/cdi/BridgingConfigBean.java
+++ /dev/null
@@ -1,95 +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.microprofile.cdi;
-
-import javax.enterprise.context.spi.CreationalContext;
-import javax.enterprise.inject.spi.Bean;
-import javax.enterprise.inject.spi.InjectionPoint;
-import java.lang.annotation.Annotation;
-import java.lang.reflect.Type;
-import java.util.Objects;
-import java.util.Set;
-
-/**
- * Internally used conversion bean.
- */
-final class BridgingConfigBean implements Bean<Object> {
-
- private final Bean<Object> delegate;
- private final Set<Type> types;
-
- public BridgingConfigBean(final Bean delegate, final Set<Type> types) {
- this.types = types;
- this.delegate = Objects.requireNonNull(delegate);
- }
-
- @Override
- public Set<Type> getTypes() {
- return types;
- }
-
- @Override
- public Class<?> getBeanClass() {
- return delegate.getBeanClass();
- }
-
- @Override
- public Set<InjectionPoint> getInjectionPoints() {
- return delegate.getInjectionPoints();
- }
-
- @Override
- public String getName() {
- return delegate.getName();
- }
-
- @Override
- public Set<Annotation> getQualifiers() {
- return delegate.getQualifiers();
- }
-
- @Override
- public Class<? extends Annotation> getScope() {
- return delegate.getScope();
- }
-
- @Override
- public Set<Class<? extends Annotation>> getStereotypes() {
- return delegate.getStereotypes();
- }
-
- @Override
- public boolean isAlternative() {
- return delegate.isAlternative();
- }
-
- @Override
- public boolean isNullable() {
- return false;
- // delegate.isNullable();
- }
-
- @Override
- public Object create(CreationalContext<Object> creationalContext) {
- return this.delegate.create(creationalContext);
- }
-
- @Override
- public void destroy(Object instance, CreationalContext<Object> creationalContext) {
- delegate.destroy(instance, creationalContext);
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/cfb364cd/modules/microprofile/src/main/java/org/apache/tamaya/microprofile/cdi/ConfiguredField.java
----------------------------------------------------------------------
diff --git a/modules/microprofile/src/main/java/org/apache/tamaya/microprofile/cdi/ConfiguredField.java b/modules/microprofile/src/main/java/org/apache/tamaya/microprofile/cdi/ConfiguredField.java
deleted file mode 100644
index 29d7122..0000000
--- a/modules/microprofile/src/main/java/org/apache/tamaya/microprofile/cdi/ConfiguredField.java
+++ /dev/null
@@ -1,65 +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.microprofile.cdi;
-
-import org.apache.tamaya.Configuration;
-
-import javax.enterprise.inject.spi.InjectionPoint;
-import java.lang.reflect.Field;
-
-/**
- * CDI implementation for event publishing of configured instances.
- */
-public final class ConfiguredField {
-
- private final Field field;
- private String key;
-
- ConfiguredField(InjectionPoint injectionPoint, String key){
- this.field = (Field)injectionPoint.getMember();
- this.key = key;
- }
-
- public Class<?> getType() {
- return field.getType();
- }
-
- public String getKey() {
- return key;
- }
-
- public Field getAnnotatedField() {
- return field;
- }
-
- public String getName() {
- return field.getName();
- }
-
- public String getSignature() {
- return getName()+':'+field.getType().getName();
- }
-
- public void configure(Object instance, Configuration config) {
- throw new UnsupportedOperationException("Use CDI annotations for configuration injection.");
- }
-
- @Override
- public String toString() {
- return "CDIConfiguredField["+getSignature()+']';
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/cfb364cd/modules/microprofile/src/main/java/org/apache/tamaya/microprofile/cdi/ConfiguredMethod.java
----------------------------------------------------------------------
diff --git a/modules/microprofile/src/main/java/org/apache/tamaya/microprofile/cdi/ConfiguredMethod.java b/modules/microprofile/src/main/java/org/apache/tamaya/microprofile/cdi/ConfiguredMethod.java
deleted file mode 100644
index 90204fe..0000000
--- a/modules/microprofile/src/main/java/org/apache/tamaya/microprofile/cdi/ConfiguredMethod.java
+++ /dev/null
@@ -1,65 +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.microprofile.cdi;
-
-import org.apache.tamaya.Configuration;
-
-import javax.enterprise.inject.spi.InjectionPoint;
-import java.lang.reflect.Method;
-
-/**
- * Implementation of a configured methods for CDI module.
- */
-public final class ConfiguredMethod {
-
- private final Method method;
- private String key;
-
- ConfiguredMethod(InjectionPoint injectionPoint, String key){
- this.method = (Method)injectionPoint.getMember();
- this.key = key;
- }
-
- public String getKey() {
- return key;
- }
-
- public Class<?>[] getParameterTypes() {
- return method.getParameterTypes();
- }
-
- public Method getAnnotatedMethod() {
- return method;
- }
-
- public String getName() {
- return method.getName();
- }
-
- public String getSignature() {
- return null;
- }
-
- public void configure(Object instance, Configuration config) {
- throw new UnsupportedOperationException("Use CDI annotations for configuration injection.");
- }
-
- @Override
- public String toString() {
- return "CDIConfiguredMethod["+getSignature()+']';
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/cfb364cd/modules/microprofile/src/main/java/org/apache/tamaya/microprofile/cdi/ConfiguredType.java
----------------------------------------------------------------------
diff --git a/modules/microprofile/src/main/java/org/apache/tamaya/microprofile/cdi/ConfiguredType.java b/modules/microprofile/src/main/java/org/apache/tamaya/microprofile/cdi/ConfiguredType.java
deleted file mode 100644
index 535a556..0000000
--- a/modules/microprofile/src/main/java/org/apache/tamaya/microprofile/cdi/ConfiguredType.java
+++ /dev/null
@@ -1,86 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.tamaya.microprofile.cdi;
-
-import org.apache.tamaya.Configuration;
-
-import javax.enterprise.inject.spi.InjectionPoint;
-import java.lang.reflect.Field;
-import java.lang.reflect.Member;
-import java.lang.reflect.Method;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.List;
-import java.util.Objects;
-
-/**
- * Event published for items configured by CDI extensions. This is for example used by the documentation module
- * to automatically track the configuration endpoints for documentation.
- */
-public final class ConfiguredType {
-
- private final Class<?> type;
- private final List<ConfiguredMethod> methods = new ArrayList<>();
- private final List<ConfiguredField> fields = new ArrayList<>();
-
- public ConfiguredType(Class<?> type){
- this.type = Objects.requireNonNull(type);
- }
-
- public Class getType() {
- return type;
- }
-
- public String getName() {
- return type.getName();
- }
-
- public Collection<ConfiguredField> getConfiguredFields() {
- return null;
- }
-
- public Collection<ConfiguredMethod> getConfiguredMethods() {
- return null;
- }
-
- public void configure(Object instance, Configuration config) {
- throw new UnsupportedOperationException("Use CDI annotations for configuration injection.");
- }
-
- /**
- * Used to build up during injection point processing.
- * @param injectionPoint the CDI injection point, not null.
- * @param key the possible config key, not null.
- */
- void addConfiguredMember(InjectionPoint injectionPoint, String key) {
- Member member = injectionPoint.getMember();
- if(member instanceof Field){
- this.fields.add(new ConfiguredField(injectionPoint, key));
- } else if(member instanceof Method){
- this.methods.add(new ConfiguredMethod(injectionPoint, key));
- }
- }
-
- @Override
- public String toString() {
- return "CDIConfiguredType{" +
- "type=" + type +
- ", methods=" + methods +
- ", fields=" + fields +
- '}';
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/cfb364cd/modules/microprofile/src/main/java/org/apache/tamaya/microprofile/cdi/MicroprofileCDIExtension.java
----------------------------------------------------------------------
diff --git a/modules/microprofile/src/main/java/org/apache/tamaya/microprofile/cdi/MicroprofileCDIExtension.java b/modules/microprofile/src/main/java/org/apache/tamaya/microprofile/cdi/MicroprofileCDIExtension.java
deleted file mode 100644
index 0be929b..0000000
--- a/modules/microprofile/src/main/java/org/apache/tamaya/microprofile/cdi/MicroprofileCDIExtension.java
+++ /dev/null
@@ -1,127 +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.microprofile.cdi;
-
-import org.eclipse.microprofile.config.inject.ConfigProperty;
-
-import javax.enterprise.event.Observes;
-import javax.enterprise.inject.Instance;
-import javax.enterprise.inject.spi.AfterBeanDiscovery;
-import javax.enterprise.inject.spi.Bean;
-import javax.enterprise.inject.spi.BeanManager;
-import javax.enterprise.inject.spi.Extension;
-import javax.enterprise.inject.spi.InjectionPoint;
-import javax.enterprise.inject.spi.ProcessBean;
-import javax.enterprise.inject.spi.ProcessProducerMethod;
-import javax.inject.Provider;
-import java.lang.reflect.AnnotatedType;
-import java.lang.reflect.Method;
-import java.lang.reflect.ParameterizedType;
-import java.lang.reflect.Type;
-import java.util.HashSet;
-import java.util.Set;
-import java.util.logging.Logger;
-
-
-/**
- * CDI Extension module that adds injection mechanism for configuration.
- *
- * @see org.eclipse.microprofile.config.Config
- * @see org.eclipse.microprofile.config.inject.ConfigProperty
- */
-public class MicroprofileCDIExtension implements Extension {
-
- private static final Logger LOG = Logger.getLogger(MicroprofileCDIExtension.class.getName());
-
- private final Set<Type> types = new HashSet<>();
- private Bean<?> convBean;
-
- /**
- * Constructor for loading logging its load.
- */
- public MicroprofileCDIExtension(){
- LOG.finest("Loading Tamaya Microprofile Support...");
- }
-
- /**
- * Method that checks the configuration injection points during deployment for available configuration.
- * @param pb the bean to process.
- * @param beanManager the bean manager to notify about new injections.
- */
- public void retrieveTypes(@Observes final ProcessBean<?> pb, BeanManager beanManager) {
-
- final Set<InjectionPoint> ips = pb.getBean().getInjectionPoints();
- ConfiguredType configuredType = new ConfiguredType(pb.getBean().getBeanClass());
-
- boolean configured = false;
- for (InjectionPoint injectionPoint : ips) {
- if (injectionPoint.getAnnotated().isAnnotationPresent(ConfigProperty.class)) {
- LOG.fine("Configuring: " + injectionPoint);
- final ConfigProperty annotation = injectionPoint.getAnnotated().getAnnotation(ConfigProperty.class);
- String key = !annotation.name().isEmpty()?annotation.name():MicroprofileConfigurationProducer.getDefaultKey(injectionPoint);
- configuredType.addConfiguredMember(injectionPoint, key);
- Type originalType = injectionPoint.getType();
- Type convertedType = unwrapType(originalType);
- types.add(convertedType);
- configured = true;
- LOG.finest(() -> "Enabling Tamaya Microprofile Configuration on bean: " + configuredType.getName());
- }else if(injectionPoint.getMember() instanceof Method){
- Method method = (Method)injectionPoint.getMember();
- for(AnnotatedType paramType: method.getAnnotatedParameterTypes()){
- if(paramType.isAnnotationPresent(ConfigProperty.class)) {
- LOG.fine("Configuring method: " + injectionPoint);
- final ConfigProperty annotation = paramType.getAnnotation(ConfigProperty.class);
- String key = !annotation.name().isEmpty() ? annotation.name() : MicroprofileConfigurationProducer.getDefaultKey(injectionPoint);
- configuredType.addConfiguredMember(injectionPoint, key);
- Type originalType = paramType.getType();
- Type convertedType = unwrapType(originalType);
- types.add(convertedType);
- configured = true;
- LOG.finest(() -> "Enabling Tamaya Microprofile Configuration on bean: " + configuredType.getName());
- }
- }
- }
- }
- if(configured) {
- beanManager.fireEvent(configuredType);
- }
- }
-
-
- public void captureConvertBean(@Observes final ProcessProducerMethod<?, ?> ppm) {
- if (ppm.getAnnotated().isAnnotationPresent(ConfigProperty.class)) {
- convBean = ppm.getBean();
- }
- }
-
- public void addConverter(@Observes final AfterBeanDiscovery abd, final BeanManager bm) {
- if(!types.isEmpty() && convBean!=null) {
- abd.addBean(new BridgingConfigBean(convBean, types));
- }
- }
-
- private Type unwrapType(Type type) {
- if(type instanceof ParameterizedType) {
- Type rawType = ((ParameterizedType) type).getRawType();
- if(rawType == Provider.class || rawType == Instance.class) {
- return ((ParameterizedType) type).getActualTypeArguments()[0];
- }
- }
- return type;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/cfb364cd/modules/microprofile/src/main/java/org/apache/tamaya/microprofile/cdi/MicroprofileConfigurationProducer.java
----------------------------------------------------------------------
diff --git a/modules/microprofile/src/main/java/org/apache/tamaya/microprofile/cdi/MicroprofileConfigurationProducer.java b/modules/microprofile/src/main/java/org/apache/tamaya/microprofile/cdi/MicroprofileConfigurationProducer.java
deleted file mode 100644
index bae7287..0000000
--- a/modules/microprofile/src/main/java/org/apache/tamaya/microprofile/cdi/MicroprofileConfigurationProducer.java
+++ /dev/null
@@ -1,156 +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.microprofile.cdi;
-
-import org.apache.tamaya.ConfigException;
-import org.apache.tamaya.Configuration;
-import org.apache.tamaya.ConfigurationProvider;
-import org.apache.tamaya.TypeLiteral;
-import org.apache.tamaya.spi.ConversionContext;
-import org.apache.tamaya.spi.PropertyConverter;
-import org.eclipse.microprofile.config.Config;
-import org.eclipse.microprofile.config.ConfigProvider;
-import org.eclipse.microprofile.config.inject.ConfigProperty;
-import org.eclipse.microprofile.config.spi.ConfigBuilder;
-import org.eclipse.microprofile.config.spi.ConfigProviderResolver;
-
-import javax.enterprise.context.ApplicationScoped;
-import javax.enterprise.inject.Produces;
-import javax.enterprise.inject.spi.Annotated;
-import javax.enterprise.inject.spi.AnnotatedField;
-import javax.enterprise.inject.spi.AnnotatedType;
-import javax.enterprise.inject.spi.InjectionPoint;
-import javax.inject.Provider;
-import java.lang.reflect.AnnotatedElement;
-import java.lang.reflect.Method;
-import java.lang.reflect.ParameterizedType;
-import java.lang.reflect.Type;
-import java.util.List;
-import java.util.Optional;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
-/**
- * Producer bean for configuration properties.
- */
-@ApplicationScoped
-public class MicroprofileConfigurationProducer {
-
- private static final Logger LOGGER = Logger.getLogger(MicroprofileConfigurationProducer.class.getName());
-
- @Produces
- @ConfigProperty
- public Object resolveAndConvert(final InjectionPoint injectionPoint) {
- LOGGER.finest( () -> "Inject: " + injectionPoint);
- final ConfigProperty annotation = injectionPoint.getAnnotated().getAnnotation(ConfigProperty.class);
- String key = annotation.name();
- if(key.isEmpty()){
- key = getDefaultKey(injectionPoint);
- }
-
- // unless the extension is not installed, this should never happen because the extension
- // enforces the resolvability of the config
-
- String defaultTextValue = annotation.defaultValue().equals(ConfigProperty.UNCONFIGURED_VALUE) ? null : annotation.defaultValue();
- ConversionContext conversionContext = createConversionContext(key, injectionPoint);
- Object value = resolveValue(defaultTextValue, conversionContext, injectionPoint);
- if (value == null) {
- throw new ConfigException(String.format(
- "Can't resolve any of the possible config keys: %s to the required target type: %s, supported formats: %s",
- key, conversionContext.getTargetType(), conversionContext.getSupportedFormats().toString()));
- }
- LOGGER.finest(String.format("Injecting %s for key %s in class %s", key, value.toString(), injectionPoint.toString()));
- return value;
- }
-
- static String getDefaultKey(InjectionPoint injectionPoint) {
- Class declaringType = injectionPoint.getMember().getDeclaringClass();
- return declaringType.getCanonicalName() + "." + injectionPoint.getMember().getName();
- }
-
- static ConversionContext createConversionContext(String key, InjectionPoint injectionPoint) {
- final Type targetType = injectionPoint.getAnnotated().getBaseType();
- Configuration config = ConfigurationProvider.getConfiguration();
- ConversionContext.Builder builder = new ConversionContext.Builder(config,
- ConfigurationProvider.getConfiguration().getContext(), key, TypeLiteral.of(targetType));
- if(targetType instanceof ParameterizedType){
- ParameterizedType pt = (ParameterizedType)targetType;
- if(pt.getRawType().equals(Provider.class)) {
- builder = new ConversionContext.Builder(config,
- ConfigurationProvider.getConfiguration().getContext(), key,
- TypeLiteral.of(pt.getActualTypeArguments()[0]));
- }
- }
- if (injectionPoint.getMember() instanceof AnnotatedElement) {
- AnnotatedElement annotated = (AnnotatedElement)injectionPoint.getMember();
- if(annotated.isAnnotationPresent(ConfigProperty.class)) {
- builder.setAnnotatedElement(annotated);
- }
- }else if(injectionPoint.getMember() instanceof Method){
- Method method = (Method)injectionPoint.getMember();
- for(Type type:method.getParameterTypes()){
- if(type instanceof AnnotatedElement){
- AnnotatedElement annotated = (AnnotatedElement)type;
- if(annotated.isAnnotationPresent(ConfigProperty.class)) {
- builder.setAnnotatedElement(annotated);
- }
- }
- }
- }
- return builder.build();
- }
-
- static Object resolveValue(String defaultTextValue, ConversionContext context, InjectionPoint injectionPoint) {
- Config config = ConfigProviderResolver.instance().getConfig();
- String textValue = config.getOptionalValue(context.getKey(), String.class).orElse(defaultTextValue);
- if(String.class.equals(context.getTargetType().getRawType())){
- return textValue;
- }
- Object value = null;
- if (textValue != null || Optional.class.equals(context.getTargetType().getRawType())) {
- LOGGER.log(Level.FINEST, () -> "Converting KEY: " + context.getKey() + "("+context.getTargetType()+"), textValue: " + textValue);
- List<PropertyConverter> converters = ConfigurationProvider.getConfiguration().getContext()
- .getPropertyConverters((TypeLiteral)context.getTargetType());
- for (PropertyConverter<Object> converter : converters) {
- try {
- value = converter.convert(textValue, context);
- if (value != null) {
- LOGGER.log(Level.FINEST, "Parsed default value from '" + textValue + "' into " +
- injectionPoint);
- break;
- }
- } catch (Exception e) {
- LOGGER.log(Level.FINEST, "Failed to convert value '" + textValue + "' for " +
- injectionPoint, e);
- }
- }
- }
- return value;
- }
-
- @Produces
- public Config getConfiguration(){
- return ConfigProvider.getConfig();
- }
-
- @Produces
- public ConfigBuilder getConfigBuilder(){
- return ConfigProviderResolver.instance().getBuilder();
- }
-
-
-}