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 2015/01/24 21:06:37 UTC

[7/9] incubator-tamaya git commit: TAMAYA-63: Bugfixes and alignment with latest Java 8 version.

TAMAYA-63: Bugfixes and alignment with latest  Java 8 version.


Project: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/commit/a8c1a9c0
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/tree/a8c1a9c0
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/diff/a8c1a9c0

Branch: refs/heads/master
Commit: a8c1a9c0840c928a5fe74fcfb8d8bbb89a748e4b
Parents: bc62f71
Author: anatole <an...@apache.org>
Authored: Sat Jan 24 19:40:32 2015 +0100
Committer: anatole <an...@apache.org>
Committed: Sat Jan 24 21:06:17 2015 +0100

----------------------------------------------------------------------
 .../apache/tamaya/ConfigurationProvider.java    | 31 +++++++++++++-
 .../tamaya/spi/ConfigurationProviderSpi.java    | 45 ++++++++++++++++++++
 .../tamaya/TestConfigurationProvider.java       | 41 ++++++++++++++++++
 .../services/org.apache.tamaya.Configuration    | 19 ---------
 ...g.apache.tamaya.spi.ConfigurationProviderSpi | 19 +++++++++
 .../core/internal/DefaultConfiguration.java     | 11 ++++-
 .../internal/DefaultConfigurationProvider.java  | 45 ++++++++++++++++++++
 .../org.apache.tamaya.spi.ConfigurationContext  | 19 ---------
 ...g.apache.tamaya.spi.ConfigurationProviderSpi | 19 +++++++++
 .../apache/tamaya/core/ConfigurationTest.java   |  3 +-
 .../internal/DefaultServiceContextTest.java     |  8 ++--
 11 files changed, 215 insertions(+), 45 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a8c1a9c0/java7/api/src/main/java/org/apache/tamaya/ConfigurationProvider.java
----------------------------------------------------------------------
diff --git a/java7/api/src/main/java/org/apache/tamaya/ConfigurationProvider.java b/java7/api/src/main/java/org/apache/tamaya/ConfigurationProvider.java
index 1293f49..69045b5 100644
--- a/java7/api/src/main/java/org/apache/tamaya/ConfigurationProvider.java
+++ b/java7/api/src/main/java/org/apache/tamaya/ConfigurationProvider.java
@@ -16,17 +16,46 @@
  */
 package org.apache.tamaya;
 
+import org.apache.tamaya.spi.ConfigurationContext;
+import org.apache.tamaya.spi.ConfigurationProviderSpi;
 import org.apache.tamaya.spi.ServiceContextManager;
 
 /**
  * Static access to the {@link Configuration} for the very application.
  */
 public final class ConfigurationProvider {
+
+    private static final ConfigurationProviderSpi PROVIDER_SPI = loadSpi();
+
+    private static ConfigurationProviderSpi loadSpi() {
+        ConfigurationProviderSpi spi = ServiceContextManager.getServiceContext()
+                .getService(ConfigurationProviderSpi.class);
+        if(spi==null){
+            throw new IllegalStateException("ConfigurationProviderSpi not available.");
+        }
+        return spi;
+    }
+
     private ConfigurationProvider() {
         // just to prevent initialisation
     }
 
+    /**
+     * Access the current configuration.
+     *
+     * @return the corresponding Configuration instance, never null.
+     */
     public static Configuration getConfiguration() {
-        return ServiceContextManager.getServiceContext().getService(Configuration.class);
+        return PROVIDER_SPI.getConfiguration();
     }
+
+    /**
+     * Get access to the current ConfigurationContext.
+     *
+     * @return the current ConfigurationContext, never null.
+     */
+    public static ConfigurationContext getConfigurationContext(){
+        return PROVIDER_SPI.getConfigurationContext();
+    }
+
 }

http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a8c1a9c0/java7/api/src/main/java/org/apache/tamaya/spi/ConfigurationProviderSpi.java
----------------------------------------------------------------------
diff --git a/java7/api/src/main/java/org/apache/tamaya/spi/ConfigurationProviderSpi.java b/java7/api/src/main/java/org/apache/tamaya/spi/ConfigurationProviderSpi.java
new file mode 100644
index 0000000..3e96abd
--- /dev/null
+++ b/java7/api/src/main/java/org/apache/tamaya/spi/ConfigurationProviderSpi.java
@@ -0,0 +1,45 @@
+/*
+ * 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.apache.tamaya.Configuration;
+
+/**
+ * SPI that must be implemented to provide the component that manages all {@link org.apache.tamaya.Configuration}
+ * instances in a system. In SE this may be a true singleton containing exact one {@link org.apache.tamaya.Configuration}
+ * instance, whereas in Java EE and other more complex environments instances may be returned depending the current
+ * runtime context.
+ */
+public interface ConfigurationProviderSpi {
+
+    /**
+     * Access the current {@link org.apache.tamaya.Configuration}.
+     *
+     * @return the current {@link org.apache.tamaya.Configuration} instance, never null.
+     */
+    Configuration getConfiguration();
+
+    /**
+     * Get access to the current {@link ConfigurationContext}.
+     *
+     * @return the current {@link ConfigurationContext}, never null.
+     */
+    ConfigurationContext getConfigurationContext();
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a8c1a9c0/java7/api/src/test/java/org/apache/tamaya/TestConfigurationProvider.java
----------------------------------------------------------------------
diff --git a/java7/api/src/test/java/org/apache/tamaya/TestConfigurationProvider.java b/java7/api/src/test/java/org/apache/tamaya/TestConfigurationProvider.java
new file mode 100644
index 0000000..7c356c8
--- /dev/null
+++ b/java7/api/src/test/java/org/apache/tamaya/TestConfigurationProvider.java
@@ -0,0 +1,41 @@
+/*
+ * 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.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;
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a8c1a9c0/java7/api/src/test/resources/META-INF/services/org.apache.tamaya.Configuration
----------------------------------------------------------------------
diff --git a/java7/api/src/test/resources/META-INF/services/org.apache.tamaya.Configuration b/java7/api/src/test/resources/META-INF/services/org.apache.tamaya.Configuration
deleted file mode 100644
index 1f42438..0000000
--- a/java7/api/src/test/resources/META-INF/services/org.apache.tamaya.Configuration
+++ /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.TestConfiguration
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a8c1a9c0/java7/api/src/test/resources/META-INF/services/org.apache.tamaya.spi.ConfigurationProviderSpi
----------------------------------------------------------------------
diff --git a/java7/api/src/test/resources/META-INF/services/org.apache.tamaya.spi.ConfigurationProviderSpi b/java7/api/src/test/resources/META-INF/services/org.apache.tamaya.spi.ConfigurationProviderSpi
new file mode 100644
index 0000000..b9c5ba5
--- /dev/null
+++ b/java7/api/src/test/resources/META-INF/services/org.apache.tamaya.spi.ConfigurationProviderSpi
@@ -0,0 +1,19 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy current the License at
+#
+#    http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+org.apache.tamaya.TestConfigurationProvider

http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a8c1a9c0/java7/core/src/main/java/org/apache/tamaya/core/internal/DefaultConfiguration.java
----------------------------------------------------------------------
diff --git a/java7/core/src/main/java/org/apache/tamaya/core/internal/DefaultConfiguration.java b/java7/core/src/main/java/org/apache/tamaya/core/internal/DefaultConfiguration.java
index 720efe0..4215a73 100644
--- a/java7/core/src/main/java/org/apache/tamaya/core/internal/DefaultConfiguration.java
+++ b/java7/core/src/main/java/org/apache/tamaya/core/internal/DefaultConfiguration.java
@@ -33,6 +33,7 @@ import java.util.Collections;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.Objects;
 import java.util.concurrent.atomic.AtomicInteger;
 import java.util.logging.Level;
 import java.util.logging.Logger;
@@ -55,7 +56,15 @@ public class DefaultConfiguration implements Configuration {
     /**
      * The current {@link org.apache.tamaya.spi.ConfigurationContext} of the current instance.
      */
-    private final ConfigurationContext configurationContext = ServiceContextManager.getServiceContext().getService(ConfigurationContext.class);
+    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

http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a8c1a9c0/java7/core/src/main/java/org/apache/tamaya/core/internal/DefaultConfigurationProvider.java
----------------------------------------------------------------------
diff --git a/java7/core/src/main/java/org/apache/tamaya/core/internal/DefaultConfigurationProvider.java b/java7/core/src/main/java/org/apache/tamaya/core/internal/DefaultConfigurationProvider.java
new file mode 100644
index 0000000..c06755d
--- /dev/null
+++ b/java7/core/src/main/java/org/apache/tamaya/core/internal/DefaultConfigurationProvider.java
@@ -0,0 +1,45 @@
+/*
+ * 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.ConfigurationProviderSpi;
+
+/**
+ * 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;
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a8c1a9c0/java7/core/src/main/resources/META-INF/services/org.apache.tamaya.spi.ConfigurationContext
----------------------------------------------------------------------
diff --git a/java7/core/src/main/resources/META-INF/services/org.apache.tamaya.spi.ConfigurationContext b/java7/core/src/main/resources/META-INF/services/org.apache.tamaya.spi.ConfigurationContext
deleted file mode 100644
index 2f0f44e..0000000
--- a/java7/core/src/main/resources/META-INF/services/org.apache.tamaya.spi.ConfigurationContext
+++ /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.core.internal.DefaultConfigurationContext

http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a8c1a9c0/java7/core/src/main/resources/META-INF/services/org.apache.tamaya.spi.ConfigurationProviderSpi
----------------------------------------------------------------------
diff --git a/java7/core/src/main/resources/META-INF/services/org.apache.tamaya.spi.ConfigurationProviderSpi b/java7/core/src/main/resources/META-INF/services/org.apache.tamaya.spi.ConfigurationProviderSpi
new file mode 100644
index 0000000..7c0e249
--- /dev/null
+++ b/java7/core/src/main/resources/META-INF/services/org.apache.tamaya.spi.ConfigurationProviderSpi
@@ -0,0 +1,19 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy current the License at
+#
+#    http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+org.apache.tamaya.core.internal.DefaultConfigurationProvider

http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a8c1a9c0/java7/core/src/test/java/org/apache/tamaya/core/ConfigurationTest.java
----------------------------------------------------------------------
diff --git a/java7/core/src/test/java/org/apache/tamaya/core/ConfigurationTest.java b/java7/core/src/test/java/org/apache/tamaya/core/ConfigurationTest.java
index 4c0e813..0eb2181 100644
--- a/java7/core/src/test/java/org/apache/tamaya/core/ConfigurationTest.java
+++ b/java7/core/src/test/java/org/apache/tamaya/core/ConfigurationTest.java
@@ -19,6 +19,7 @@
 package org.apache.tamaya.core;
 
 import org.apache.tamaya.Configuration;
+import org.apache.tamaya.ConfigurationProvider;
 import org.apache.tamaya.core.internal.DefaultConfiguration;
 import org.apache.tamaya.spi.ServiceContext;
 import org.apache.tamaya.spi.ServiceContextManager;
@@ -42,7 +43,7 @@ public class ConfigurationTest {
     }
 
     private Configuration current() {
-        return ServiceContextManager.getServiceContext().getService(Configuration.class);
+        return ConfigurationProvider.getConfiguration();
     }
 
     @Test

http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a8c1a9c0/java7/core/src/test/java/org/apache/tamaya/core/internal/DefaultServiceContextTest.java
----------------------------------------------------------------------
diff --git a/java7/core/src/test/java/org/apache/tamaya/core/internal/DefaultServiceContextTest.java b/java7/core/src/test/java/org/apache/tamaya/core/internal/DefaultServiceContextTest.java
index 4f4079a..795c80f 100644
--- a/java7/core/src/test/java/org/apache/tamaya/core/internal/DefaultServiceContextTest.java
+++ b/java7/core/src/test/java/org/apache/tamaya/core/internal/DefaultServiceContextTest.java
@@ -20,6 +20,7 @@ package org.apache.tamaya.core.internal;
 
 import org.apache.tamaya.ConfigException;
 import org.apache.tamaya.spi.ConfigurationContext;
+import org.apache.tamaya.spi.ConfigurationProviderSpi;
 import org.junit.Assert;
 import org.junit.Test;
 
@@ -37,10 +38,9 @@ public class DefaultServiceContextTest {
 
     @Test
     public void testGetService() {
-        ConfigurationContext configurationContext = context.getService(ConfigurationContext.class);
-
-        Assert.assertNotNull(configurationContext);
-        Assert.assertTrue(configurationContext instanceof DefaultConfigurationContext);
+        ConfigurationProviderSpi providerSpi = context.getService(ConfigurationProviderSpi.class);
+        Assert.assertNotNull(providerSpi);
+        Assert.assertTrue(providerSpi instanceof DefaultConfigurationProvider);
     }
 
     @Test(expected = ConfigException.class)