You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tamaya.apache.org by pl...@apache.org on 2016/09/15 17:29:22 UTC
[5/6] incubator-tamaya git commit: Removed the attic
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/ccc0842b/attic/java8/api/src/test/java/org/apache/tamaya/ConfigurationTest.java
----------------------------------------------------------------------
diff --git a/attic/java8/api/src/test/java/org/apache/tamaya/ConfigurationTest.java b/attic/java8/api/src/test/java/org/apache/tamaya/ConfigurationTest.java
deleted file mode 100644
index 8490455..0000000
--- a/attic/java8/api/src/test/java/org/apache/tamaya/ConfigurationTest.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;
-
-import org.junit.Test;
-
-import static org.junit.Assert.*;
-
-/**
- * Test class that tests the default methods implemented on {@link org.apache.tamaya.Configuration}. The provided
- * {@link org.apache.tamaya.TestConfiguration} is implemented with maximal use of the default methods.
- */
-public class ConfigurationTest {
-
- @Test
- public void testget() throws Exception {
- assertEquals(Boolean.TRUE, ConfigurationProvider.getConfiguration().getOptional("booleanTrue", Boolean.class).get());
- assertEquals(Boolean.FALSE, ConfigurationProvider.getConfiguration().getOptional("booleanFalse", Boolean.class).get());
- assertEquals((int) Byte.MAX_VALUE, (int) ConfigurationProvider.getConfiguration().getOptional("byte", Byte.class).get());
- assertEquals((int) Integer.MAX_VALUE, (int) ConfigurationProvider.getConfiguration().getOptional("int", Integer.class).get());
- assertEquals((long) Long.MAX_VALUE, (long) ConfigurationProvider.getConfiguration().getOptional("long", Long.class).get());
- assertEquals((double) Float.MAX_VALUE, (double) ConfigurationProvider.getConfiguration().getOptional("float", Float.class).get(), 0.0d);
- assertEquals((double) Double.MAX_VALUE, (double) ConfigurationProvider.getConfiguration().getOptional("double", Double.class).get(), 0.0d);
- }
-
- @Test
- public void testGetBoolean() throws Exception {
- assertTrue(ConfigurationProvider.getConfiguration().getBoolean("booleanTrue").isPresent());
- assertTrue(ConfigurationProvider.getConfiguration().getBoolean("booleanFalse").isPresent());
- assertFalse(ConfigurationProvider.getConfiguration().getBoolean("booleanFalse").get());
- assertTrue(ConfigurationProvider.getConfiguration().getBoolean("booleanTrue").get());
- assertFalse(ConfigurationProvider.getConfiguration().getBoolean("fooBar").isPresent());
- }
-
- @Test
- public void testGetInteger() throws Exception {
- assertEquals(Integer.MAX_VALUE, ConfigurationProvider.getConfiguration().getInteger("int").getAsInt());
- }
-
- @Test
- public void testGetLong() throws Exception {
- assertEquals(Long.MAX_VALUE, ConfigurationProvider.getConfiguration().getLong("long").getAsLong());
- }
-
- @Test
- public void testGetDouble() throws Exception {
- assertEquals(Double.MAX_VALUE, ConfigurationProvider.getConfiguration().getDouble("double").getAsDouble(), 0.0d);
- }
-
- @Test
- public void testWith() throws Exception {
- assertEquals(ConfigurationProvider.getConfiguration(), ConfigurationProvider.getConfiguration().with(c -> c));
- }
-
- @Test
- public void testQuery() throws Exception {
- assertEquals("myFooResult", ConfigurationProvider.getConfiguration().query(c -> "myFooResult"));
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/ccc0842b/attic/java8/api/src/test/java/org/apache/tamaya/TestConfiguration.java
----------------------------------------------------------------------
diff --git a/attic/java8/api/src/test/java/org/apache/tamaya/TestConfiguration.java b/attic/java8/api/src/test/java/org/apache/tamaya/TestConfiguration.java
deleted file mode 100644
index ef7cccf..0000000
--- a/attic/java8/api/src/test/java/org/apache/tamaya/TestConfiguration.java
+++ /dev/null
@@ -1,80 +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;
-
-import java.util.HashMap;
-import java.util.Map;
-
-/**
- * Test Configuration class, that is used to testdata the default methods provided by the API.
- */
-public class TestConfiguration implements Configuration {
-
- private static final Map<String, String> VALUES;
-
- static {
- VALUES = new HashMap<String, String>();
- VALUES.put("long", String.valueOf(Long.MAX_VALUE));
- VALUES.put("int", String.valueOf(Integer.MAX_VALUE));
- VALUES.put("double", String.valueOf(Double.MAX_VALUE));
- VALUES.put("float", String.valueOf(Float.MAX_VALUE));
- VALUES.put("short", String.valueOf(Short.MAX_VALUE));
- VALUES.put("byte", String.valueOf(Byte.MAX_VALUE));
- VALUES.put("booleanTrue", "true");
- VALUES.put("booleanFalse", "false");
- VALUES.put("String", "aStringValue");
- }
-
- @Override
- public String get(String key) {
- return VALUES.get(key);
- }
-
- @Override
- public <T> T get(String key, TypeLiteral<T> type) {
- if (type.getType().equals(Long.class)) {
- return (T) (Object) Long.MAX_VALUE;
- } else if (type.getType().equals(Integer.class)) {
- return (T) (Object) Integer.MAX_VALUE;
- } else if (type.getType().equals(Double.class)) {
- return (T) (Object) Double.MAX_VALUE;
- } else if (type.getType().equals(Float.class)) {
- return (T) (Object) Float.MAX_VALUE;
- } else if (type.getType().equals(Short.class)) {
- return (T) (Object) Short.MAX_VALUE;
- } else if (type.getType().equals(Byte.class)) {
- return (T) (Object) Byte.MAX_VALUE;
- } else if (type.getType().equals(Boolean.class)) {
- if ("booleanTrue".equals(key)) {
- return (T) (Object) Boolean.TRUE;
- } else if ("booleanFalse".equals(key)) {
- return (T) (Object) Boolean.FALSE;
- }
- } else if (type.getType().equals(String.class)) {
- return (T) (Object) "aStringValue";
- }
- return null;
- }
-
- @Override
- public Map<String, String> getProperties() {
- return null;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/ccc0842b/attic/java8/api/src/test/java/org/apache/tamaya/TestConfigurationProvider.java
----------------------------------------------------------------------
diff --git a/attic/java8/api/src/test/java/org/apache/tamaya/TestConfigurationProvider.java b/attic/java8/api/src/test/java/org/apache/tamaya/TestConfigurationProvider.java
deleted file mode 100644
index 98820ca..0000000
--- a/attic/java8/api/src/test/java/org/apache/tamaya/TestConfigurationProvider.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;
-
-import org.apache.tamaya.spi.ConfigurationContext;
-import org.apache.tamaya.spi.ConfigurationContextBuilder;
-import org.apache.tamaya.spi.ConfigurationProviderSpi;
-
-/**
- * Test Configuration class, that is used to testdata the default methods provided by the API.
- */
-public class TestConfigurationProvider implements ConfigurationProviderSpi {
-
- private static final Configuration config = new TestConfiguration();
-
-
- @Override
- public Configuration getConfiguration() {
- return config;
- }
-
- @Override
- public ConfigurationContext getConfigurationContext() {
- return null;
- }
-
- @Override
- public ConfigurationContextBuilder getConfigurationContextBuilder() {
- return null;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/ccc0842b/attic/java8/api/src/test/java/org/apache/tamaya/TypeLiteralTest.java
----------------------------------------------------------------------
diff --git a/attic/java8/api/src/test/java/org/apache/tamaya/TypeLiteralTest.java b/attic/java8/api/src/test/java/org/apache/tamaya/TypeLiteralTest.java
deleted file mode 100644
index 79f6257..0000000
--- a/attic/java8/api/src/test/java/org/apache/tamaya/TypeLiteralTest.java
+++ /dev/null
@@ -1,61 +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;
-
-import org.junit.Test;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import static org.junit.Assert.assertEquals;
-
-/**
- * Tests for the {@link org.apache.tamaya.TypeLiteral} class.
- */
-public class TypeLiteralTest {
-
- @Test
- public void test_constrcutor(){
- TypeLiteral<List<String>> listTypeLiteral = new TypeLiteral<List<String>>(){};
- assertEquals(List.class, listTypeLiteral.getRawType());
- assertEquals(String.class, TypeLiteral.getTypeParameters(listTypeLiteral.getType())[0]);
- }
-
- @Test
- public void test_of(){
- class MyListClass extends ArrayList<String>{};
- TypeLiteral<MyListClass> listTypeLiteral = TypeLiteral.of(MyListClass.class);
- assertEquals(MyListClass.class, listTypeLiteral.getRawType());
- assertEquals(MyListClass.class, listTypeLiteral.getType());
- }
-
- @Test
- public void test_getTypeParameter(){
- TypeLiteral<List<String>> listTypeLiteral = new TypeLiteral<List<String>>(){};
- assertEquals(List.class, listTypeLiteral.getRawType());
- assertEquals(String.class, TypeLiteral.getTypeParameters(listTypeLiteral.getType())[0]);
- }
-
- @Test
- public void test_getGenericInterfaceTypeParameter(){
- class MyListClass extends ArrayList<String> implements List<String>{};
- assertEquals(String.class, TypeLiteral.getGenericInterfaceTypeParameters(MyListClass.class, List.class)[0]);
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/ccc0842b/attic/java8/api/src/test/java/org/apache/tamaya/spi/ServiceContextManagerTest.java
----------------------------------------------------------------------
diff --git a/attic/java8/api/src/test/java/org/apache/tamaya/spi/ServiceContextManagerTest.java b/attic/java8/api/src/test/java/org/apache/tamaya/spi/ServiceContextManagerTest.java
deleted file mode 100644
index 949170d..0000000
--- a/attic/java8/api/src/test/java/org/apache/tamaya/spi/ServiceContextManagerTest.java
+++ /dev/null
@@ -1,131 +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.spi;
-
-import org.junit.AfterClass;
-import org.junit.Assert;
-import org.junit.BeforeClass;
-import org.junit.Test;
-
-import java.io.IOException;
-import java.lang.reflect.Field;
-import java.net.URL;
-import java.net.URLClassLoader;
-import java.util.Collections;
-import java.util.Enumeration;
-import java.util.List;
-
-import static org.junit.Assert.assertTrue;
-
-public class ServiceContextManagerTest {
-
- private static URLClassLoader classLoader;
- private static Field delegateField;
-
- @BeforeClass
- public static void init() throws Exception {
-
- // setup the environment for our ugly hacks
-
- // replace classloader with our own
- classLoader = (URLClassLoader) Thread.currentThread().getContextClassLoader();
- Thread.currentThread().setContextClassLoader(new UglyHackClassLoader(classLoader));
-
- // clear the caching field
- delegateField = ServiceContextManager.class.getDeclaredField("serviceContextProviderDelegate");
- delegateField.setAccessible(true);
-
- delegateField.set(null, null);
- }
-
- @AfterClass
- public static void clean() throws Exception {
-
- // clean our hacks
-
- delegateField.set(null, null);
- Thread.currentThread().setContextClassLoader(classLoader);
- }
-
- @Test
- public void testGetServiceContext() {
-
- ServiceContext context = ServiceContextManager.getServiceContext();
- Assert.assertEquals(1, context.ordinal());
-
- }
-
- @Test
- public void testSetServiceContext(){
- ServiceContext ctx = new ServiceContext() {
- @Override
- public <T> T getService(Class<T> serviceType) {
- return null;
- }
-
- @Override
- public <T> List<T> getServices(Class<T> serviceType) {
- return Collections.emptyList();
- }
- };
- ServiceContext prevContext = ServiceContextManager.set(ctx);
- if(prevContext!=null) {
- ServiceContextManager.set(prevContext);
- assertTrue(ServiceContextManager.getServiceContext() == prevContext);
- }
- }
-
-
- // has to be public because ServiceLoader won't find it otherwise
- public static class ServiceContextWithOrdinal implements ServiceContext {
-
- @Override
- public int ordinal() {
- return 100;
- }
-
- @Override
- public <T> T getService(Class<T> serviceType) {
- return null;
- }
-
- @Override
- public <T> List<T> getServices(Class<T> serviceType) {
- return null;
- }
- }
-
- // to override the getResources method to use our own 'ServiceLoader'-file we have to this ugly hack
- private static class UglyHackClassLoader extends URLClassLoader {
-
- private UglyHackClassLoader(URLClassLoader urlClassLoader) {
- super(urlClassLoader.getURLs());
- }
-
-
- @Override
- public Enumeration<URL> getResources(String name) throws IOException {
- if ("META-INF/services/org.apache.tamaya.spi.ServiceContext".equals(name)) {
- return super.getResources("ServiceContextWithOrdinal");
- }
-
- return super.getResources(name);
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/ccc0842b/attic/java8/api/src/test/java/org/apache/tamaya/spi/ServiceContextTest.java
----------------------------------------------------------------------
diff --git a/attic/java8/api/src/test/java/org/apache/tamaya/spi/ServiceContextTest.java b/attic/java8/api/src/test/java/org/apache/tamaya/spi/ServiceContextTest.java
deleted file mode 100644
index 28d9fac..0000000
--- a/attic/java8/api/src/test/java/org/apache/tamaya/spi/ServiceContextTest.java
+++ /dev/null
@@ -1,91 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tamaya.spi;
-
-import org.junit.Test;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.List;
-import java.util.Optional;
-
-import static org.junit.Assert.*;
-
-public class ServiceContextTest {
-
- private ServiceContext serviceContext = new ServiceContext() {
-
- @Override
- public <T> T getService(Class<T> serviceType) {
- if (String.class.equals(serviceType)) {
- return serviceType.cast("ServiceContextTest");
- }
- return null;
- }
-
- @Override
- public <T> List<T> getServices(Class<T> serviceType) {
- if (String.class.equals(serviceType)) {
- List<String> list = new ArrayList<>();
- list.add("ServiceContextTest");
- return List.class.cast(list);
- }
- return Collections.EMPTY_LIST;
- }
- };
-
- @Test
- public void testOrdinal() throws Exception {
- assertEquals(1, serviceContext.ordinal());
- }
-
- @Test
- public void testgetService() throws Exception {
- assertEquals("ServiceContextTest", serviceContext.getService(String.class));
- assertTrue(serviceContext.getService(Integer.class)==null);
- }
-
- @Test
- public void testGetService() throws Exception {
- String service = serviceContext.getService(String.class);
- assertNotNull(service);
- assertTrue(service!=null);
- assertEquals("ServiceContextTest", service);
- Integer intService = serviceContext.getService(Integer.class);
- assertNull(intService);
- }
-
- @Test
- public void testGetServices() throws Exception {
- Collection<String> services = serviceContext.getServices(String.class);
- assertNotNull(services);
- assertFalse(services.isEmpty());
- assertEquals("ServiceContextTest", services.iterator().next());
- List<Integer> intServices = serviceContext.getServices(Integer.class);
- assertNotNull(intServices);
- assertTrue(intServices.isEmpty());
- }
-
- @Test
- public void testGetInstance() throws Exception {
- assertNotNull(ServiceContext.getInstance());
- }
-
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/ccc0842b/attic/java8/api/src/test/java/org/apache/tamaya/spi/TestServiceContext.java
----------------------------------------------------------------------
diff --git a/attic/java8/api/src/test/java/org/apache/tamaya/spi/TestServiceContext.java b/attic/java8/api/src/test/java/org/apache/tamaya/spi/TestServiceContext.java
deleted file mode 100644
index 720a5c4..0000000
--- a/attic/java8/api/src/test/java/org/apache/tamaya/spi/TestServiceContext.java
+++ /dev/null
@@ -1,83 +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.spi;
-
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
-import java.util.Map;
-import java.util.ServiceLoader;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
-/**
- * This class implements the (default) {@link org.apache.tamaya.spi.ServiceContext} interface and hereby uses the JDK
- * {@link java.util.ServiceLoader} to load the services required.
- */
-public final class TestServiceContext implements ServiceContext {
- /**
- * List current services loaded, per class.
- */
- private final ConcurrentHashMap<Class<?>, List<Object>> servicesLoaded = new ConcurrentHashMap<>();
- /**
- * Singletons.
- */
- private final Map<Class<?>, Object> singletons = new ConcurrentHashMap<>();
-
- @Override
- public <T> T getService(Class<T> serviceType) {
- T cached = serviceType.cast(singletons.get(serviceType));
- if (cached == null) {
- List<? extends T> services = getServices(serviceType);
- if (services.isEmpty()) {
- cached = null;
- } else {
- cached = services.get(0);
- }
- singletons.put(serviceType, cached);
- }
- return cached;
- }
-
- /**
- * Loads and registers services.
- *
- * @param serviceType The service type.
- * @param <T> the concrete type.
- * @return the items found, never {@code null}.
- */
- @Override
- public <T> List<T> getServices(Class<T> serviceType) {
- try {
- List<T> services = new ArrayList<>();
- for (T t : ServiceLoader.load(serviceType)) {
- services.add(t);
- }
- services = Collections.unmodifiableList(services);
- final List<T> previousServices = List.class.cast(servicesLoaded.putIfAbsent(serviceType, (List<Object>) services));
- return previousServices != null ? previousServices : services;
- } catch (Exception e) {
- Logger.getLogger(TestServiceContext.class.getName()).log(Level.WARNING,
- "Error loading services current type " + serviceType, e);
- return Collections.emptyList();
- }
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/ccc0842b/attic/java8/api/src/test/resources/META-INF/services/org.apache.tamaya.spi.ConfigurationProviderSpi
----------------------------------------------------------------------
diff --git a/attic/java8/api/src/test/resources/META-INF/services/org.apache.tamaya.spi.ConfigurationProviderSpi b/attic/java8/api/src/test/resources/META-INF/services/org.apache.tamaya.spi.ConfigurationProviderSpi
deleted file mode 100644
index b9c5ba5..0000000
--- a/attic/java8/api/src/test/resources/META-INF/services/org.apache.tamaya.spi.ConfigurationProviderSpi
+++ /dev/null
@@ -1,19 +0,0 @@
-#
-# Licensed to the Apache Software Foundation (ASF) under one
-# or more contributor license agreements. See the NOTICE file
-# distributed with this work for additional information
-# regarding copyright ownership. The ASF licenses this file
-# to you under the Apache License, Version 2.0 (the
-# "License"); you may not use this file except in compliance
-# with the License. You may obtain a copy current the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing,
-# software distributed under the License is distributed on an
-# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-# KIND, either express or implied. See the License for the
-# specific language governing permissions and limitations
-# under the License.
-#
-org.apache.tamaya.TestConfigurationProvider
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/ccc0842b/attic/java8/api/src/test/resources/META-INF/services/org.apache.tamaya.spi.ServiceContext
----------------------------------------------------------------------
diff --git a/attic/java8/api/src/test/resources/META-INF/services/org.apache.tamaya.spi.ServiceContext b/attic/java8/api/src/test/resources/META-INF/services/org.apache.tamaya.spi.ServiceContext
deleted file mode 100644
index 199956f..0000000
--- a/attic/java8/api/src/test/resources/META-INF/services/org.apache.tamaya.spi.ServiceContext
+++ /dev/null
@@ -1,19 +0,0 @@
-#
-# Licensed to the Apache Software Foundation (ASF) under one
-# or more contributor license agreements. See the NOTICE file
-# distributed with this work for additional information
-# regarding copyright ownership. The ASF licenses this file
-# to you under the Apache License, Version 2.0 (the
-# "License"); you may not use this file except in compliance
-# with the License. You may obtain a copy current the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing,
-# software distributed under the License is distributed on an
-# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-# KIND, either express or implied. See the License for the
-# specific language governing permissions and limitations
-# under the License.
-#
-org.apache.tamaya.spi.TestServiceContext
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/ccc0842b/attic/java8/api/src/test/resources/ServiceContextWithOrdinal
----------------------------------------------------------------------
diff --git a/attic/java8/api/src/test/resources/ServiceContextWithOrdinal b/attic/java8/api/src/test/resources/ServiceContextWithOrdinal
deleted file mode 100644
index 4112c18..0000000
--- a/attic/java8/api/src/test/resources/ServiceContextWithOrdinal
+++ /dev/null
@@ -1,25 +0,0 @@
-# Licensed to the Apache Software Foundation (ASF) under one
-# or more contributor license agreements. See the NOTICE file
-# distributed with this work for additional information
-# regarding copyright ownership. The ASF licenses this file
-# to you under the Apache License, Version 2.0 (the
-# "License"); you may not use this file except in compliance
-# with the License. You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing,
-# software distributed under the License is distributed on an
-# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-# KIND, either express or implied. See the License for the
-# specific language governing permissions and limitations
-# under the License.
-
-# this is just an ugly hack to test the loading of ServiceContexts
-# if we have more than one
-
-# this one is without overriding ordinal so it shall take the default
-org.apache.tamaya.spi.TestServiceContext
-
-# this one has a higher ordinal (100)
-org.apache.tamaya.spi.ServiceContextManagerTest$ServiceContextWithOrdinal
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/ccc0842b/attic/java8/core/pom.xml
----------------------------------------------------------------------
diff --git a/attic/java8/core/pom.xml b/attic/java8/core/pom.xml
deleted file mode 100644
index 08860b6..0000000
--- a/attic/java8/core/pom.xml
+++ /dev/null
@@ -1,87 +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</groupId>
- <artifactId>tamaya-java8</artifactId>
- <version>0.2-incubating-SNAPSHOT</version>
- <relativePath>../pom.xml</relativePath>
- </parent>
-
- <artifactId>tamaya-core</artifactId>
- <name>Apache Tamaya Java 8 Core</name>
-
- <dependencies>
- <dependency>
- <groupId>org.apache.tamaya</groupId>
- <artifactId>tamaya-api</artifactId>
- <version>${project.version}</version>
- </dependency>
- <dependency>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
- </dependency>
- <dependency>
- <groupId>org.mockito</groupId>
- <artifactId>mockito-core</artifactId>
- </dependency>
- <dependency>
- <groupId>org.hamcrest</groupId>
- <artifactId>hamcrest-library</artifactId>
- </dependency>
- <dependency>
- <groupId>org.hamcrest</groupId>
- <artifactId>hamcrest-core</artifactId>
- </dependency>
- </dependencies>
-
- <build>
- <plugins>
- <plugin>
- <artifactId>maven-dependency-plugin</artifactId>
- <executions>
- <execution>
- <id>copyMain</id>
- <phase>process-test-classes</phase>
- <goals>
- <goal>copy</goal>
- </goals>
- <configuration>
- <outputDirectory>${project.build.directory}</outputDirectory>
- <overWriteReleases>false</overWriteReleases>
- <overWriteSnapshots>false</overWriteSnapshots>
- <overWriteIfNewer>true</overWriteIfNewer>
- <stripVersion>true</stripVersion>
- <artifactItems>
- <artifactItem>
- <groupId>org.jboss.arquillian.daemon</groupId>
- <artifactId>arquillian-daemon-main</artifactId>
- </artifactItem>
- </artifactItems>
- </configuration>
- </execution>
- </executions>
- </plugin>
- </plugins>
- </build>
-
-
-</project>
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/ccc0842b/attic/java8/core/src/main/java/org/apache/tamaya/core/internal/DefaultConfiguration.java
----------------------------------------------------------------------
diff --git a/attic/java8/core/src/main/java/org/apache/tamaya/core/internal/DefaultConfiguration.java b/attic/java8/core/src/main/java/org/apache/tamaya/core/internal/DefaultConfiguration.java
deleted file mode 100644
index 8eaa5cd..0000000
--- a/attic/java8/core/src/main/java/org/apache/tamaya/core/internal/DefaultConfiguration.java
+++ /dev/null
@@ -1,235 +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.core.internal;
-
-import org.apache.tamaya.ConfigException;
-import org.apache.tamaya.Configuration;
-import org.apache.tamaya.TypeLiteral;
-import org.apache.tamaya.spi.ConfigurationContext;
-import org.apache.tamaya.spi.PropertyConverter;
-import org.apache.tamaya.spi.PropertyFilter;
-import org.apache.tamaya.spi.PropertySource;
-import org.apache.tamaya.spi.PropertyValueCombinationPolicy;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Objects;
-import java.util.Optional;
-import java.util.concurrent.atomic.AtomicInteger;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-import java.util.stream.Collectors;
-
-/**
- * Implementation of the Configuration API. This class uses the current {@link ConfigurationContext} to evaluate the
- * chain of {@link org.apache.tamaya.spi.PropertySource} and {@link org.apache.tamaya.spi.PropertyFilter}
- * instance to evaluate the current Configuration.
- */
-public class DefaultConfiguration implements Configuration {
- /**
- * The logger.
- */
- private static final Logger LOG = Logger.getLogger(DefaultConfiguration.class.getName());
- /**
- * The maximal number of filter cycles performed before aborting.
- */
- private static final int MAX_FILTER_LOOPS = 10;
-
- /**
- * The current {@link org.apache.tamaya.spi.ConfigurationContext} of the current instance.
- */
- private final ConfigurationContext configurationContext;
-
- /**
- * Constructor.
- * @param configurationContext The configuration Context to be used.
- */
- public DefaultConfiguration(ConfigurationContext configurationContext){
- this.configurationContext = Objects.requireNonNull(configurationContext);
- }
-
- /**
- * This method evaluates the given configuration key. Hereby if goes down the chain or PropertySource instances
- * provided by the current {@link org.apache.tamaya.spi.ConfigurationContext}. The first non-null-value returned
- * is taken as an intermediate value. Finally the value is filtered through the
- * {@link org.apache.tamaya.spi.PropertyFilter} instances installed, before it is returned as the final result of
- * this method.
- *
- * @param key the property's key, not null.
- * @return the optional configuration value, never null.
- */
- @Override
- public String get(String key) {
- List<PropertySource> propertySources = configurationContext.getPropertySources();
- String unfilteredValue = null;
- PropertyValueCombinationPolicy combinationPolicy = this.configurationContext
- .getPropertyValueCombinationPolicy();
- for (PropertySource propertySource : propertySources) {
- unfilteredValue = combinationPolicy.collect(unfilteredValue, key, propertySource);
- }
- return applyFilter(key, unfilteredValue);
- }
-
- /**
- * Apply filters to a single property value.
- *
- * @param key the key, used for logging, not null.
- * @param unfilteredValue the unfiltered property value.
- * @return the filtered value, or null.
- */
- private String applyFilter(String key, String unfilteredValue) {
- // Apply filters to values, prevent values filtered to null!
- for (int i = 0; i < MAX_FILTER_LOOPS; i++) {
- boolean changed = false;
- // Apply filters to values, prevent values filtered to null!
- for (PropertyFilter filter : configurationContext.getPropertyFilters()) {
- String newValue = filter.filterProperty(key, unfilteredValue);
- if (newValue != null && !newValue.equals(unfilteredValue)) {
- changed = true;
- if (LOG.isLoggable(Level.FINEST)) {
- LOG.finest("Filter - " + key + ": " + unfilteredValue + " -> " + newValue + " by " + filter);
- }
- } else if (unfilteredValue != null && !unfilteredValue.equals(newValue)) {
- changed = true;
- if (LOG.isLoggable(Level.FINEST)) {
- LOG.finest("Filter - " + key + ": " + unfilteredValue + " -> " + newValue + " by " + filter);
- }
- }
- unfilteredValue = newValue;
- }
- if (!changed) {
- LOG.finest(() -> "Finishing filter loop, no changes detected.");
- break;
- } else {
- if (i == (MAX_FILTER_LOOPS - 1)) {
- if (LOG.isLoggable(Level.WARNING)) {
- LOG.warning("Maximal filter loop count reached, aborting filter evaluation after cycles: " + i);
- }
- } else {
- LOG.finest(() -> "Repeating filter loop, changes detected.");
- }
- }
- }
- return unfilteredValue;
- }
-
- /**
- * Get the current properties, composed by the loaded {@link org.apache.tamaya.spi.PropertySource} and filtered
- * by registered {@link org.apache.tamaya.spi.PropertyFilter}.
- *
- * @return the final properties.
- */
- @Override
- public Map<String, String> getProperties() {
- List<PropertySource> propertySources = new ArrayList<>(configurationContext.getPropertySources());
- Map<String, String> result = new HashMap<>();
- for (PropertySource propertySource : propertySources) {
- try {
- int origSize = result.size();
- Map<String, String> otherMap = propertySource.getProperties();
- LOG.log(Level.FINEST, null, () -> "Overriding with properties from " + propertySource.getName());
- result.putAll(otherMap);
- LOG.log(Level.FINEST, null, () -> "Handled properties from " + propertySource.getName() + "(new: " +
- (result.size() - origSize) + ", overrides: " + origSize + ", total: " + result.size());
- } catch (Exception e) {
- LOG.log(Level.SEVERE, "Error adding properties from PropertySource: " + propertySource + ", ignoring PropertySource.", e);
- }
- }
- return applyFilters(result);
- }
-
- /**
- * Filter a full configuration property map.
- *
- * @param inputMap the unfiltered map
- * @return the filtered map.
- */
- private Map<String, String> applyFilters(Map<String, String> inputMap) {
- // Apply filters to values, prevent values filtered to null!
- for (int i = 0; i < MAX_FILTER_LOOPS; i++) {
- AtomicInteger changes = new AtomicInteger();
- for (PropertyFilter filter : configurationContext.getPropertyFilters()) {
- inputMap.replaceAll((k, v) -> {
- String newValue = filter.filterProperty(k, v);
- if (newValue != null && !newValue.equals(v)) {
- changes.incrementAndGet();
- LOG.finest(() -> "Filter - " + k + ": " + v + " -> " + newValue + " by " + filter);
- } else if (v != null && !v.equals(newValue)) {
- changes.incrementAndGet();
- LOG.finest(() -> "Filter - " + k + ": " + v + " -> " + newValue + " by " + filter);
- }
- return newValue;
- });
- }
- if (changes.get() == 0) {
- LOG.finest(() -> "Finishing filter loop, no changes detected.");
- break;
- } else {
- if (i == (MAX_FILTER_LOOPS - 1)) {
- if (LOG.isLoggable(Level.WARNING)) {
- LOG.warning("Maximal filter loop count reached, aborting filter evaluation after cycles: " + i);
- }
- } else {
- LOG.finest(() -> "Repeating filter loop, changes detected: " + changes.get());
- }
- changes.set(0);
- }
- }
- // Remove null values
- return inputMap.entrySet().parallelStream().filter((e) -> e.getValue() != null).collect(
- Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
- }
-
- /**
- * Accesses the current String value for the given key (see {@link #getOptional(String)}) and tries to convert it
- * using the {@link org.apache.tamaya.spi.PropertyConverter} instances provided by the current
- * {@link org.apache.tamaya.spi.ConfigurationContext}.
- *
- * @param key the property's absolute, or relative path, e.g. @code
- * a/b/c/d.myProperty}.
- * @param type The target type required, not null.
- * @param <T> the value type
- * @return the converted value, never null.
- */
- @Override
- public <T> T get(String key, TypeLiteral<T> type) {
- Optional<String> value = getOptional(key);
- if (value.isPresent()) {
- List<PropertyConverter<T>> converters = configurationContext.getPropertyConverters(type);
- for (PropertyConverter<T> converter : converters) {
- try {
- T t = converter.convert(value.get());
- if (t != null) {
- return t;
- }
- } catch (Exception e) {
- LOG.log(Level.FINEST, e, () -> "PropertyConverter: " + converter +
- " failed to convert value: " + value.get());
- }
- }
-
- throw new ConfigException("Unable to convert config value for key " +
- key + " in type " + type.getType());
- }
- return null;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/ccc0842b/attic/java8/core/src/main/java/org/apache/tamaya/core/internal/DefaultConfigurationContext.java
----------------------------------------------------------------------
diff --git a/attic/java8/core/src/main/java/org/apache/tamaya/core/internal/DefaultConfigurationContext.java b/attic/java8/core/src/main/java/org/apache/tamaya/core/internal/DefaultConfigurationContext.java
deleted file mode 100644
index 96d5909..0000000
--- a/attic/java8/core/src/main/java/org/apache/tamaya/core/internal/DefaultConfigurationContext.java
+++ /dev/null
@@ -1,239 +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.core.internal;
-
-import org.apache.tamaya.TypeLiteral;
-import org.apache.tamaya.spi.ConfigurationContext;
-import org.apache.tamaya.spi.PropertyConverter;
-import org.apache.tamaya.spi.ConfigurationContextBuilder;
-import org.apache.tamaya.spi.PropertyFilter;
-import org.apache.tamaya.spi.PropertySource;
-import org.apache.tamaya.spi.PropertySourceProvider;
-import org.apache.tamaya.spi.PropertyValueCombinationPolicy;
-import org.apache.tamaya.spi.ServiceContext;
-import org.apache.tamaya.spi.ServiceContextManager;
-
-import javax.annotation.Priority;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.List;
-import java.util.Map;
-import java.util.function.Function;
-import java.util.logging.Logger;
-
-/**
- * Default Implementation of a simple ConfigurationContext.
- */
-public class DefaultConfigurationContext implements ConfigurationContext {
- /** The logger used. */
- private final static Logger LOG = Logger.getLogger(DefaultConfigurationContext.class.getName());
- /**
- * Cubcomponent handling {@link org.apache.tamaya.spi.PropertyConverter} instances.
- */
- private PropertyConverterManager propertyConverterManager = new PropertyConverterManager();
-
- /**
- * The current unmodifiable list of loaded {@link org.apache.tamaya.spi.PropertySource} instances.
- */
- private List<PropertySource> immutablePropertySources;
-
- /**
- * The current unmodifiable list of loaded {@link org.apache.tamaya.spi.PropertyFilter} instances.
- */
- private List<PropertyFilter> immutablePropertyFilters;
-
- /**
- * The overriding policy used when combining PropertySources registered to evalute the final configuration
- * values.
- */
- private PropertyValueCombinationPolicy propertyValueCombinationPolicy;
-
- /**
- * The first time the Configuration system gets invoked we do initialize
- * all our {@link org.apache.tamaya.spi.PropertySource}s and
- * {@link org.apache.tamaya.spi.PropertyFilter}s which are known at startup.
- */
- public DefaultConfigurationContext() {
- List<PropertySource> propertySources = new ArrayList<>();
-
- // first we load all PropertySources which got registered via java.util.ServiceLoader
- propertySources.addAll(ServiceContext.getInstance().getServices(PropertySource.class));
-
- // after that we add all PropertySources which get dynamically registered via their PropertySourceProviders
- propertySources.addAll(evaluatePropertySourcesFromProviders());
-
- // now sort them according to their ordinal values
- Collections.sort(propertySources, this::comparePropertySources);
- immutablePropertySources = Collections.unmodifiableList(propertySources);
- LOG.info(() -> "Registered " + immutablePropertySources.size() + " property sources: " +
- createStringList(immutablePropertySources,ps -> ps.getName() + '[' + ps.getClass().getName()+']'));
-
- // as next step we pick up the PropertyFilters pretty much the same way
- List<PropertyFilter> propertyFilters = new ArrayList<>();
- propertyFilters.addAll(ServiceContext.getInstance().getServices(PropertyFilter.class));
- Collections.sort(propertyFilters, this::comparePropertyFilters);
- immutablePropertyFilters = Collections.unmodifiableList(propertyFilters);
- LOG.info(() -> "Registered " + immutablePropertyFilters.size() + " property filters: " +
- createStringList(immutablePropertyFilters,f -> f.getClass().getName()));
-
- propertyValueCombinationPolicy = ServiceContext.getInstance().getService(PropertyValueCombinationPolicy.class);
- if(propertyValueCombinationPolicy==null) {
- propertyValueCombinationPolicy = PropertyValueCombinationPolicy.DEFAULT_OVERRIDING_COLLECTOR;
- }
- LOG.info(() -> "Using PropertyValueCombinationPolicy: " + propertyValueCombinationPolicy);
- }
-
- DefaultConfigurationContext(DefaultConfigurationContextBuilder builder) {
- List<PropertySource> propertySources = new ArrayList<>();
- // first we load all PropertySources which got registered via java.util.ServiceLoader
- propertySources.addAll(builder.propertySources);
- // now sort them according to their ordinal values
- Collections.sort(propertySources, this::comparePropertySources);
- immutablePropertySources = Collections.unmodifiableList(propertySources);
- LOG.info(() -> "Registered " + immutablePropertySources.size() + " property sources: " +
- createStringList(immutablePropertySources,ps -> ps.getName() + '[' + ps.getClass().getName()+']'));
-
- // as next step we pick up the PropertyFilters pretty much the same way
- List<PropertyFilter> propertyFilters = new ArrayList<>();
- propertyFilters.addAll(ServiceContext.getInstance().getServices(PropertyFilter.class));
- Collections.sort(propertyFilters, this::comparePropertyFilters);
- immutablePropertyFilters = Collections.unmodifiableList(propertyFilters);
- LOG.info(() -> "Registered " + immutablePropertyFilters.size() + " property filters: " +
- createStringList(immutablePropertyFilters,f -> f.getClass().getName()));
-
- propertyValueCombinationPolicy = ServiceContext.getInstance().getService(PropertyValueCombinationPolicy.class);
- if(propertyValueCombinationPolicy==null){
- propertyValueCombinationPolicy = PropertyValueCombinationPolicy.DEFAULT_OVERRIDING_COLLECTOR;
- }
- LOG.info(() -> "Using PropertyValueCombinationPolicy: " + propertyValueCombinationPolicy);
- }
-
- /**
- * Pick up all {@link org.apache.tamaya.spi.PropertySourceProvider}s and return all the
- * {@link org.apache.tamaya.spi.PropertySource}s they like to register.
- */
- private Collection<? extends PropertySource> evaluatePropertySourcesFromProviders() {
- List<PropertySource> propertySources = new ArrayList<>();
- Collection<PropertySourceProvider> propertySourceProviders = ServiceContext.getInstance().getServices(PropertySourceProvider.class);
- for (PropertySourceProvider propertySourceProvider : propertySourceProviders) {
- Collection<PropertySource> sources = propertySourceProvider.getPropertySources();
- LOG.finer(() -> "PropertySourceProvider " + propertySourceProvider.getClass().getName() +
- " provided the following property sources: " +
- createStringList(sources,ps -> ps.getName() + '[' + ps.getClass().getName()+']'));
- propertySources.addAll(sources);
- }
- return propertySources;
- }
-
-// @Override
-// public void addPropertySources(PropertySource... propertySourcesToAdd) {
-// Lock writeLock = propertySourceLock.asWriteLock();
-// try {
-// writeLock.lock();
-// List<PropertySource> newPropertySources = new ArrayList<>(this.immutablePropertySources);
-// newPropertySources.addAll(Arrays.asList(propertySourcesToAdd));
-// Collections.sort(newPropertySources, this::comparePropertySources);
-//
-// this.immutablePropertySources = Collections.unmodifiableList(newPropertySources);
-// } finally {
-// writeLock.unlock();
-// }
-// }
-
- /**
- * Order property source reversely, the most important come first.
- *
- * @param source1 the first PropertySource
- * @param source2 the second PropertySource
- * @return the comparison result.
- */
- private int comparePropertySources(PropertySource source1, PropertySource source2) {
- if (source1.getOrdinal() < source2.getOrdinal()) {
- return -1;
- } else if (source1.getOrdinal() > source2.getOrdinal()) {
- return 1;
- } else {
- return source1.getClass().getName().compareTo(source2.getClass().getName());
- }
- }
-
- /**
- * Compare 2 filters for ordering the filter chain.
- *
- * @param filter1 the first filter
- * @param filter2 the second filter
- * @return the comparison result
- */
- private int comparePropertyFilters(PropertyFilter filter1, PropertyFilter filter2) {
- Priority prio1 = filter1.getClass().getAnnotation(Priority.class);
- Priority prio2 = filter2.getClass().getAnnotation(Priority.class);
- int ord1 = prio1 != null ? prio1.value() : 0;
- int ord2 = prio2 != null ? prio2.value() : 0;
-
- if (ord1 < ord2) {
- return -1;
- } else if (ord1 > ord2) {
- return 1;
- } else {
- return filter1.getClass().getName().compareTo(filter2.getClass().getName());
- }
- }
-
- @Override
- public List<PropertySource> getPropertySources() {
- return immutablePropertySources;
- }
-
- @Override
- public Map<TypeLiteral<?>, List<PropertyConverter<?>>> getPropertyConverters() {
- return propertyConverterManager.getPropertyConverters();
- }
-
- @Override
- public <T> List<PropertyConverter<T>> getPropertyConverters(TypeLiteral<T> targetType) {
- return propertyConverterManager.getPropertyConverters(targetType);
- }
-
- @Override
- public List<PropertyFilter> getPropertyFilters() {
- return immutablePropertyFilters;
- }
-
- @Override
- public PropertyValueCombinationPolicy getPropertyValueCombinationPolicy(){
- return propertyValueCombinationPolicy;
- }
-
- @Override
- public ConfigurationContextBuilder toBuilder() {
- ServiceContext serviceContext = ServiceContextManager.getServiceContext();
- ConfigurationContextBuilder service = serviceContext.getService(ConfigurationContextBuilder.class);
-
- service.setContext(this);
-
- return service;
- }
-
- private <T> String createStringList(Collection<T> propertySources, Function<T,String> mapper){
- StringBuilder joiner = new StringBuilder(", ");
- propertySources.forEach(t -> joiner.append(mapper.apply(t)));
- return joiner.toString();
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/ccc0842b/attic/java8/core/src/main/java/org/apache/tamaya/core/internal/DefaultConfigurationContextBuilder.java
----------------------------------------------------------------------
diff --git a/attic/java8/core/src/main/java/org/apache/tamaya/core/internal/DefaultConfigurationContextBuilder.java b/attic/java8/core/src/main/java/org/apache/tamaya/core/internal/DefaultConfigurationContextBuilder.java
deleted file mode 100644
index c181373..0000000
--- a/attic/java8/core/src/main/java/org/apache/tamaya/core/internal/DefaultConfigurationContextBuilder.java
+++ /dev/null
@@ -1,145 +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.core.internal;
-
-import org.apache.tamaya.ConfigException;
-import org.apache.tamaya.spi.PropertyConverter;
-import org.apache.tamaya.TypeLiteral;
-import org.apache.tamaya.spi.ConfigurationContext;
-import org.apache.tamaya.spi.ConfigurationContextBuilder;
-import org.apache.tamaya.spi.PropertyFilter;
-import org.apache.tamaya.spi.PropertySource;
-import org.apache.tamaya.spi.PropertyValueCombinationPolicy;
-
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Objects;
-import java.util.Set;
-import java.util.function.Predicate;
-import java.util.stream.Collectors;
-
-/**
- * Default implementation of {@link org.apache.tamaya.spi.ConfigurationContextBuilder}.
- */
-public class DefaultConfigurationContextBuilder implements ConfigurationContextBuilder {
-
- List<PropertySource> propertySources = new ArrayList<>();
- List<PropertyFilter> propertyFilters = new ArrayList<>();
- Map<TypeLiteral<?>, List<PropertyConverter<?>>> propertyConverters = new HashMap<>();
- PropertyValueCombinationPolicy combinationPolicy;
-
- public DefaultConfigurationContextBuilder(){
- }
-
- @Override
- public ConfigurationContextBuilder setContext(ConfigurationContext context) {
- this.propertySources.clear();
- this.propertySources.addAll(context.getPropertySources());
- this.propertyFilters.clear();
- this.propertyFilters.addAll(context.getPropertyFilters());
- this.propertyConverters.clear();
- this.propertyConverters.putAll(context.getPropertyConverters());
- this.combinationPolicy = context.getPropertyValueCombinationPolicy();
- return this;
- }
-
- @Override
- public ConfigurationContextBuilder addPropertySources(Collection<PropertySource> propertySourcesToAdd) {
- Set<String> names = this.propertySources.stream().map(ps -> ps.getName()).collect(Collectors.toSet());
- for(PropertySource ps:propertySourcesToAdd){
- if(names.contains(ps.getName())){
- throw new ConfigException("Duplicate PropertySource: " + ps.getName());
- }
- }
- this.propertySources.addAll(propertySourcesToAdd);
- return this;
- }
-
- @Override
- public ConfigurationContextBuilder removePropertySources(Collection<String> propertySourcesToRemove) {
- this.propertySources = this.propertySources.stream().filter(ps -> !propertySourcesToRemove
- .contains(ps.getName())).collect(Collectors.toList());
- return this;
- }
-
- @Override
- public ConfigurationContextBuilder addPropertyFilters(Collection<PropertyFilter> filters) {
- this.propertyFilters.addAll(filters);
- return this;
- }
-
- @Override
- public ConfigurationContextBuilder removePropertyFilters(Predicate<PropertyFilter> selector) {
- Collection<PropertyFilter> filtersToRemove = this.propertyFilters.stream().filter(selector)
- .collect(Collectors.toList());
- this.propertyFilters.removeAll(filtersToRemove);
- return this;
- }
-
- @Override
- public ConfigurationContextBuilder removePropertyFilters(Collection<PropertyFilter> filters) {
- this.propertyFilters.removeAll(filters);
- return this;
- }
-
- @Override
- public ConfigurationContextBuilder removePropertySources(Predicate<PropertySource> selector) {
- Collection<PropertySource> sourcesToRemove = this.propertySources.stream().filter(selector)
- .collect(Collectors.toList());
- this.propertySources.removeAll(sourcesToRemove);
- return this;
- }
-
- @Override
- public <T> ConfigurationContextBuilder addPropertyConverter(TypeLiteral<T> typeToConvert, PropertyConverter<T> propertyConverter) {
- List<PropertyConverter<?>> converters = this.propertyConverters.computeIfAbsent(typeToConvert, (k) -> new ArrayList<>());
- converters.add(propertyConverter);
- return this;
- }
-
- @Override
- public ConfigurationContextBuilder removePropertyConverters(TypeLiteral<?> typeToConvert, PropertyConverter<?>... converters) {
- return removePropertyConverters(typeToConvert, Arrays.asList(converters));
- }
-
- @Override
- public ConfigurationContextBuilder removePropertyConverters(TypeLiteral<?> typeToConvert, Collection<PropertyConverter<?>> converters) {
- List<PropertyConverter<?>> existing = this.propertyConverters.get(typeToConvert);
- if(existing!=null) {
- existing.removeAll(converters);
- }
- return this;
- }
-
- @Override
- public ConfigurationContextBuilder setPropertyValueCombinationPolicy(PropertyValueCombinationPolicy policy) {
- this.combinationPolicy = Objects.requireNonNull(policy);
- return this;
- }
-
- @Override
- public ConfigurationContext build() {
- return new DefaultConfigurationContext(this);
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/ccc0842b/attic/java8/core/src/main/java/org/apache/tamaya/core/internal/DefaultConfigurationProvider.java
----------------------------------------------------------------------
diff --git a/attic/java8/core/src/main/java/org/apache/tamaya/core/internal/DefaultConfigurationProvider.java b/attic/java8/core/src/main/java/org/apache/tamaya/core/internal/DefaultConfigurationProvider.java
deleted file mode 100644
index 8b3d4bc..0000000
--- a/attic/java8/core/src/main/java/org/apache/tamaya/core/internal/DefaultConfigurationProvider.java
+++ /dev/null
@@ -1,62 +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.core.internal;
-
-import org.apache.tamaya.Configuration;
-import org.apache.tamaya.spi.ConfigurationContext;
-import org.apache.tamaya.spi.ConfigurationContextBuilder;
-import org.apache.tamaya.spi.ConfigurationProviderSpi;
-import org.apache.tamaya.spi.ServiceContext;
-import org.apache.tamaya.spi.ServiceContextManager;
-
-
-/**
- * Implementation of the Configuration API. This class uses the current {@link org.apache.tamaya.spi.ConfigurationContext} to evaluate the
- * chain of {@link org.apache.tamaya.spi.PropertySource} and {@link org.apache.tamaya.spi.PropertyFilter}
- * instance to evaluate the current Configuration.
- */
-public class DefaultConfigurationProvider implements ConfigurationProviderSpi {
-
- private ConfigurationContext context = new DefaultConfigurationContext();
- private Configuration config = new DefaultConfiguration(context);
-
- @Override
- public Configuration getConfiguration() {
- return config;
- }
-
- @Override
- public ConfigurationContext getConfigurationContext() {
- return context;
- }
-
- @Override
- public ConfigurationContextBuilder getConfigurationContextBuilder() {
- ServiceContext serviceContext = ServiceContextManager.getServiceContext();
- ConfigurationContextBuilder service = serviceContext.getService(ConfigurationContextBuilder.class);
-
- return service;
- }
-
- @Override
- public void setConfigurationContext(ConfigurationContext context){
- this.config = new DefaultConfiguration(context);
- this.context = context;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/ccc0842b/attic/java8/core/src/main/java/org/apache/tamaya/core/internal/DefaultServiceContext.java
----------------------------------------------------------------------
diff --git a/attic/java8/core/src/main/java/org/apache/tamaya/core/internal/DefaultServiceContext.java b/attic/java8/core/src/main/java/org/apache/tamaya/core/internal/DefaultServiceContext.java
deleted file mode 100644
index 8f37244..0000000
--- a/attic/java8/core/src/main/java/org/apache/tamaya/core/internal/DefaultServiceContext.java
+++ /dev/null
@@ -1,148 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tamaya.core.internal;
-
-import org.apache.tamaya.ConfigException;
-import org.apache.tamaya.spi.ServiceContext;
-
-import javax.annotation.Priority;
-import java.text.MessageFormat;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
-import java.util.Map;
-import java.util.ServiceLoader;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
-/**
- * This class implements the (default) {@link org.apache.tamaya.spi.ServiceContext} interface and hereby uses the JDK
- * {@link java.util.ServiceLoader} to load the services required.
- */
-public final class DefaultServiceContext implements ServiceContext {
- /**
- * List current services loaded, per class.
- */
- private final ConcurrentHashMap<Class<?>, List<Object>> servicesLoaded = new ConcurrentHashMap<>();
- /**
- * Singletons.
- */
- private final Map<Class<?>, Object> singletons = new ConcurrentHashMap<>();
-
- @Override
- public <T> T getService(Class<T> serviceType) {
- T cached = serviceType.cast(singletons.get(serviceType));
- if (cached == null) {
- List<? extends T> services = getServices(serviceType);
- if (!services.isEmpty()) {
- cached = getServiceWithHighestPriority(services, serviceType);
- }
- if(cached!=null){
- singletons.put(serviceType, cached);
- }
- }
- return cached;
- }
-
- /**
- * Loads and registers services.
- *
- * @param serviceType The service type.
- * @param <T> the concrete type.
- * @return the items found, never {@code null}.
- */
- @Override
- public <T> List<T> getServices(final Class<T> serviceType) {
- List<T> found = List.class.cast(servicesLoaded.get(serviceType));
- if (found != null) {
- return found;
- }
- List<T> services = new ArrayList<>();
- try {
- for (T t : ServiceLoader.load(serviceType)) {
- services.add(t);
- }
- services = Collections.unmodifiableList(services);
- } catch (Exception e) {
- Logger.getLogger(DefaultServiceContext.class.getName()).log(Level.WARNING,
- "Error loading services current type " + serviceType, e);
- }
- final List<T> previousServices = List.class.cast(servicesLoaded.putIfAbsent(serviceType, (List<Object>) services));
- return previousServices != null ? previousServices : services;
- }
-
- /**
- * Checks the given instance for a @Priority annotation. If present the annotation's value s evaluated. If no such
- * annotation is present, a default priority is returned (1);
- * @param o the instance, not null.
- * @return a priority, by default 1.
- */
- public static int getPriority(Object o){
- int prio = 1; //X TODO discuss default priority
- Priority priority = o.getClass().getAnnotation(Priority.class);
- if (priority != null) {
- prio = priority.value();
- }
- return prio;
- }
-
- /**
- * @param services to scan
- * @param <T> type of the service
- *
- * @return the service with the highest {@link javax.annotation.Priority#value()}
- *
- * @throws ConfigException if there are multiple service implementations with the maximum priority
- */
- private <T> T getServiceWithHighestPriority(List<? extends T> services, Class<T> serviceType) {
-
- // we do not need the priority stuff if the list contains only one element
- if (services.size() == 1) {
- return services.get(0);
- }
-
- Integer highestPriority = null;
- int highestPriorityServiceCount = 0;
- T highestService = null;
-
- for (T service : services) {
- int prio = getPriority(service);
-
- if (highestPriority == null || highestPriority < prio) {
- highestService = service;
- highestPriorityServiceCount = 1;
- highestPriority = prio;
- } else if (highestPriority == prio) {
- highestPriorityServiceCount++;
- }
- }
-
- if (highestPriorityServiceCount > 1) {
- throw new ConfigException(MessageFormat.format("Found {0} implementations for Service {1} with Priority {2}: {3}",
- highestPriorityServiceCount,
- serviceType.getName(),
- highestPriority,
- services));
- }
-
- return highestService;
- }
-
-}