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/06 17:18:03 UTC
[07/50] [abbrv] incubator-tamaya-sandbox git commit: Implemented
multi classpath environment PropertySourceProvider,
with relocation capability.
Implemented multi classpath environment PropertySourceProvider, with relocation capability.
Project: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/commit/5f2b6e3e
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/tree/5f2b6e3e
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/diff/5f2b6e3e
Branch: refs/heads/master
Commit: 5f2b6e3e065f30e1becdaedd03b9669e70ef50e1
Parents: 47eb7a5
Author: anatole <an...@apache.org>
Authored: Tue Oct 6 09:51:36 2015 +0200
Committer: anatole <an...@apache.org>
Committed: Tue Oct 6 09:56:11 2015 +0200
----------------------------------------------------------------------
environment/pom.xml | 10 +-
.../environment/BuildableRuntimeContext.java | 121 --------------
.../tamaya/environment/RuntimeContext.java | 67 --------
.../environment/RuntimeContextBuilder.java | 89 ----------
.../environment/RuntimeContextProvider.java | 49 ------
...ctClassLoaderDependentRuntimeContextSpi.java | 115 -------------
...ssLoaderDependentAppEnvironmentProvider.java | 40 -----
...ssLoaderDependentEarEnvironmentProvider.java | 40 -----
.../ClasspathPropertiesEnvironmentProvider.java | 167 +++++++++++++++++++
.../internal/InitialEnvironmentProviderSpi.java | 74 --------
.../internal/SingleEnvironmentManager.java | 61 -------
...SystemClassLoaderEnvironmentProviderSpi.java | 88 ----------
.../environment/internal/package-info.java | 2 +-
.../BaseEnvironmentPropertySourceProvider.java | 119 +++++++++++++
.../environment/spi/ContextProviderSpi.java | 45 -----
.../tamaya/environment/spi/package-info.java | 5 +-
...org.apache.tamaya.spi.PropertySourceProvider | 19 +++
.../RuntimeContextProviderSpiTest.java | 57 -------
.../TestEnvironmentManagerSingleton.java | 37 ----
.../environment/TestEnvironmentProvider.java | 47 ------
.../src/test/resources/GLOBAL.properties | 19 +++
...he.tamaya.environment.spi.ContextProviderSpi | 23 ---
22 files changed, 336 insertions(+), 958 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/5f2b6e3e/environment/pom.xml
----------------------------------------------------------------------
diff --git a/environment/pom.xml b/environment/pom.xml
index bd5ab5c..c2e1745 100644
--- a/environment/pom.xml
+++ b/environment/pom.xml
@@ -42,15 +42,21 @@ under the License.
<groupId>org.apache.tamaya</groupId>
<artifactId>tamaya-api</artifactId>
<version>${project.version}</version>
+ <scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.tamaya.ext</groupId>
- <artifactId>tamaya-formats</artifactId>
+ <artifactId>tamaya-functions</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.apache.tamaya.ext</groupId>
- <artifactId>tamaya-resource</artifactId>
+ <artifactId>tamaya-spisupport</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.tamaya.ext</groupId>
+ <artifactId>tamaya-resources</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/5f2b6e3e/environment/src/main/java/org/apache/tamaya/environment/BuildableRuntimeContext.java
----------------------------------------------------------------------
diff --git a/environment/src/main/java/org/apache/tamaya/environment/BuildableRuntimeContext.java b/environment/src/main/java/org/apache/tamaya/environment/BuildableRuntimeContext.java
deleted file mode 100644
index f7675bb..0000000
--- a/environment/src/main/java/org/apache/tamaya/environment/BuildableRuntimeContext.java
+++ /dev/null
@@ -1,121 +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.environment;
-
-import java.util.Map;
-import java.util.Objects;
-import java.util.TreeMap;
-
-/**
- * Environment class that is used by the {@link org.apache.tamaya.environment.RuntimeContextBuilder}.
- */
-class BuildableRuntimeContext implements RuntimeContext {
- /** The context id, never null or empty. */
- private String contextId;
-
- /**
- * The environment data.
- */
- private Map<String, String> context = new TreeMap<>();
-
- /**
- * Constructor.
- *
- * @param builder the builder, not null.
- */
- BuildableRuntimeContext(RuntimeContextBuilder builder) {
- Objects.requireNonNull(builder);
- this.contextId = builder.contextId;
- context.putAll(builder.contextData);
- }
-
- @Override
- public Map<String, String> toMap() {
- return context;
- }
-
- @Override
- public String getContextId() {
- return contextId;
- }
-
- @Override
- public String get(String key) {
- return context.get(key);
- }
-
- @Override
- public String get(String key, String defaultValue) {
- return context.getOrDefault(key, defaultValue);
- }
-
- @Override
- public boolean equals(Object o) {
- if (this == o) return true;
- if (o == null || getClass() != o.getClass()) return false;
-
- BuildableRuntimeContext that = (BuildableRuntimeContext) o;
- return context.equals(that.context);
- }
-
- @Override
- public int hashCode() {
- return context.hashCode();
- }
-
- /*
- * (non-Javadoc)
- *
- * @see java.lang.Object#toString()
- */
- @Override
- public String toString() {
- return "RuntimeContext: " + getContextId();
- }
-
- /**
- * Get the delta.
- *
- * @return
- */
- private String getData() {
- StringBuilder b = new StringBuilder();
- for (Map.Entry<String, String> en : this.context.entrySet()) {
- b.append(" ").append(en.getKey()).append('=').append(escape(en.getValue())).append('\n');
- }
- if (b.length() > 0) {
- b.setLength(b.length() - 1);
- }
- return b.toString();
- }
-
- /**
- * Escapes several characters.
- *
- * @param value
- * @return
- */
- private String escape(String value) {
- if (value == null) {
- return null;
- }
- return value.replaceAll("\n", "\\\\n").replaceAll("\r", "\\\\r").replaceAll("\t", "\\\\t")
- .replaceAll("=", "\\\\=");
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/5f2b6e3e/environment/src/main/java/org/apache/tamaya/environment/RuntimeContext.java
----------------------------------------------------------------------
diff --git a/environment/src/main/java/org/apache/tamaya/environment/RuntimeContext.java b/environment/src/main/java/org/apache/tamaya/environment/RuntimeContext.java
deleted file mode 100644
index ca98432..0000000
--- a/environment/src/main/java/org/apache/tamaya/environment/RuntimeContext.java
+++ /dev/null
@@ -1,67 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tamaya.environment;
-
-import java.util.Map;
-
-/**
- * Models a runtime context. Instances current this class are used to
- * evaluate the correct configuration artifacts or other
- * context dependent functionality.<br/>
- * <h3>Implementation Requirements</h3>
- * <p>
- * Implementations current this interface must be
- * <ul>
- * <li>Thread safe,
- * <li>Immutable,
- * <li>Serializable.
- * </ul>
- */
-public interface RuntimeContext {
-
- /**
- * Returns an id that identifies the current context. Depending on the environment isolation this
- * can be always the same key (e.g. in a SE use case) or a varying key depending on the current classloader
- * visible (OSGI, EE environment).
- * @return the context id, never null.
- */
- String getContextId();
-
- /**
- * Access a runtime context variable.
- * @param key the key
- * @return the corresponding value.
- */
- String get(String key);
-
- /**
- * Access a runtime context variable.
- * @param key the key
- * @param defaultValue the default value, returned if no value is present.
- * @return the corresponding value, or the defaultValue (including null).
- */
- String get(String key, String defaultValue);
-
- /**
- * Access the context as Map.
- * @return the Map instance containing the context properties, never null.
- */
- Map<String,String> toMap();
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/5f2b6e3e/environment/src/main/java/org/apache/tamaya/environment/RuntimeContextBuilder.java
----------------------------------------------------------------------
diff --git a/environment/src/main/java/org/apache/tamaya/environment/RuntimeContextBuilder.java b/environment/src/main/java/org/apache/tamaya/environment/RuntimeContextBuilder.java
deleted file mode 100644
index 4fb3f02..0000000
--- a/environment/src/main/java/org/apache/tamaya/environment/RuntimeContextBuilder.java
+++ /dev/null
@@ -1,89 +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.environment;
-
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Objects;
-
-/**
-* Builder to create new {@link RuntimeContext instances.}
-*/
-public final class RuntimeContextBuilder {
-
- /** The context id, never null or empty. */
- String contextId;
-
- /** THe environment data. */
- Map<String,String> contextData = new HashMap<>();
-
- /**
- * Constructor.
- */
- private RuntimeContextBuilder(String contextId) {
- this.contextId = Objects.requireNonNull(contextId);
- }
-
- /**
- * Creates a new buildr instance.
- * @return the new builder instance.
- */
- public static RuntimeContextBuilder of(String contextId) {
- return new RuntimeContextBuilder(contextId);
- }
-
- /**
- * Sets the environment contextId.
- * @param contextId the contextId, not null.
- * @return the builder for chaining
- */
- public RuntimeContextBuilder setContextId(String contextId){
- this.contextId = Objects.requireNonNull(contextId);
- return this;
- }
-
- /**
- * Sets a new environment property.
- * @param key the key, not null.
- * @param value the keys, not null.
- * @return the builder for chaining
- */
- public RuntimeContextBuilder set(String key, String value){
- this.contextData.put(key, value);
- return this;
- }
-
- /**
- * Sets new environment properties.
- * @param values the key/values, not null.
- * @return the builder for chaining
- */
- public RuntimeContextBuilder setAll(Map<String,String> values){
- this.contextData.putAll(values);
- return this;
- }
-
- /**
- * Builds a new Environment.
- * @return a new Environment, never null.
- */
- public RuntimeContext build() {
- return new BuildableRuntimeContext(this);
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/5f2b6e3e/environment/src/main/java/org/apache/tamaya/environment/RuntimeContextProvider.java
----------------------------------------------------------------------
diff --git a/environment/src/main/java/org/apache/tamaya/environment/RuntimeContextProvider.java b/environment/src/main/java/org/apache/tamaya/environment/RuntimeContextProvider.java
deleted file mode 100644
index 565b255..0000000
--- a/environment/src/main/java/org/apache/tamaya/environment/RuntimeContextProvider.java
+++ /dev/null
@@ -1,49 +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.environment;
-
-import org.apache.tamaya.environment.spi.ContextSpi;
-import org.apache.tamaya.spi.ServiceContext;
-
-/**
- * Singleton accessor to the current {@link org.apache.tamaya.environment.RuntimeContext}.
- */
-public final class RuntimeContextProvider {
-
- private static final ContextSpi contextSpi = loadSpi();
-
- private static ContextSpi loadSpi(){
- return ServiceContext.getInstance().getService(ContextSpi.class).get();
- }
-
- /**
- * Singleton constructor.
- */
- private RuntimeContextProvider(){}
-
- /**
- * Get the current {@link org.apache.tamaya.environment.RuntimeContextProvider}. The environment is used to determine the current runtime state, which
- * is important for returning the correct configuration.
- * @return the current Environment, never null.
- */
- public static RuntimeContext current(){
- return contextSpi.getCurrentContext();
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/5f2b6e3e/environment/src/main/java/org/apache/tamaya/environment/internal/AbstractClassLoaderDependentRuntimeContextSpi.java
----------------------------------------------------------------------
diff --git a/environment/src/main/java/org/apache/tamaya/environment/internal/AbstractClassLoaderDependentRuntimeContextSpi.java b/environment/src/main/java/org/apache/tamaya/environment/internal/AbstractClassLoaderDependentRuntimeContextSpi.java
deleted file mode 100644
index de92e78..0000000
--- a/environment/src/main/java/org/apache/tamaya/environment/internal/AbstractClassLoaderDependentRuntimeContextSpi.java
+++ /dev/null
@@ -1,115 +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.environment.internal;
-
-import org.apache.tamaya.environment.RuntimeContext;
-import org.apache.tamaya.environment.RuntimeContextBuilder;
-import org.apache.tamaya.environment.spi.ContextProviderSpi;
-import org.apache.tamaya.format.ConfigurationFormat;
-import org.apache.tamaya.format.ConfigurationFormats;
-import org.apache.tamaya.resource.ConfigResources;
-
-import java.io.InputStream;
-import java.net.URL;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Objects;
-import java.util.Set;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
-/**
- * Application environment provider that is dependent on the current context classloader and tries to
- * evaluate {@code META-INF/env/application.properties, META-INF/env/application.xml and META-INF/env/application.ini}.
- * Only if a property named {@code org.apache.tamaya.env.applicationId} is found, it will
- * be used as the {@code environmentId} and a corresponding {@link org.apache.tamaya.environment.RuntimeContext} instance
- * is created and attached.
- */
-public abstract class AbstractClassLoaderDependentRuntimeContextSpi implements ContextProviderSpi {
-
- private static final Logger LOG = Logger.getLogger(AbstractClassLoaderDependentRuntimeContextSpi.class.getName());
-
- private String contextId;
- private Map<ClassLoader, Map<String, String>> contexts = new ConcurrentHashMap<>();
- private Map<ClassLoader, Boolean> contextsAvailable = new ConcurrentHashMap<>();
-
- protected AbstractClassLoaderDependentRuntimeContextSpi(String contextId) {
- this.contextId = Objects.requireNonNull(contextId);
- }
-
- private boolean isActive() {
- ClassLoader cl = Thread.currentThread().getContextClassLoader();
- if (cl == null) {
- return false;
- }
- Boolean available = this.contextsAvailable.get(cl);
- if (available != null) {
- return available;
- }
- return true;
- }
-
- protected Collection<URL> getConfigLocations() {
- return ConfigResources.getResourceResolver().getResources(Thread.currentThread().getContextClassLoader(),
- "classpath:META-INF/context/" + contextId + ".properties", "classpath:META-INF/context/\"+contextId+\".xml", "classpath:META-INF/context/\"+contextId+\".ini");
- }
-
- protected List<ConfigurationFormat> getConfigFormats(URL url) {
- return ConfigurationFormats.getFormats(url);
- }
-
- @Override
- public void setupContext(RuntimeContextBuilder contextBuilder) {
- if (isActive()) {
- ClassLoader cl = Thread.currentThread().getContextClassLoader();
- if (cl == null) {
- return;
- }
- Map<String, String> data = this.contexts.get(cl);
- if (data == null) {
- Collection<URL> propertyUris = getConfigLocations();
- data = new HashMap<>();
- for (URL resource : propertyUris) {
- for (ConfigurationFormat format : getConfigFormats(resource)) {
- try (InputStream is = resource.openStream()) {
- data.putAll(format.readConfiguration(resource.toExternalForm(), is).getDefaultSection());
- } catch (Exception e) {
- LOG.log(Level.SEVERE, e, () -> "Error reading application context data fromMap " + resource);
- }
- }
- }
- data.put("classloader.type", cl.getClass().getName());
- data.put("classloader.info", cl.toString());
- Set<URL> uris = new HashSet<>();
- uris.addAll(propertyUris);
- data.put("context.sources", uris.toString());
- data = Collections.unmodifiableMap(data);
- contextBuilder.setContextId(contextId);
- this.contexts.put(cl, data);
- }
- contextBuilder.setAll(data);
- }
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/5f2b6e3e/environment/src/main/java/org/apache/tamaya/environment/internal/ClassLoaderDependentAppEnvironmentProvider.java
----------------------------------------------------------------------
diff --git a/environment/src/main/java/org/apache/tamaya/environment/internal/ClassLoaderDependentAppEnvironmentProvider.java b/environment/src/main/java/org/apache/tamaya/environment/internal/ClassLoaderDependentAppEnvironmentProvider.java
deleted file mode 100644
index 7268f5e..0000000
--- a/environment/src/main/java/org/apache/tamaya/environment/internal/ClassLoaderDependentAppEnvironmentProvider.java
+++ /dev/null
@@ -1,40 +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.environment.internal;
-
-
-import javax.annotation.Priority;
-
-/**
- * This class implements a {@link org.apache.tamaya.environment.RuntimeContextProvider} that tries
- * to read configuration for an ear deployment located under {@code META-INF/env/ear.properties,
- * META-INF/env/ear.xml or META-INF/env/ear.ini}. The environment id hereby is defined by a
- * configuration entry named {@code org.apache.tamaya.core.env.earId}.
- *
- * Only if such a configuration with such an {@code earId} is found an {@link org.apache.tamaya.environment.RuntimeContext}
- * is created and attached to the corresponding ear classloader.
- */
-@Priority(3000)
-public class ClassLoaderDependentAppEnvironmentProvider extends AbstractClassLoaderDependentRuntimeContextSpi{
-
- public ClassLoaderDependentAppEnvironmentProvider(){
- super("app");
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/5f2b6e3e/environment/src/main/java/org/apache/tamaya/environment/internal/ClassLoaderDependentEarEnvironmentProvider.java
----------------------------------------------------------------------
diff --git a/environment/src/main/java/org/apache/tamaya/environment/internal/ClassLoaderDependentEarEnvironmentProvider.java b/environment/src/main/java/org/apache/tamaya/environment/internal/ClassLoaderDependentEarEnvironmentProvider.java
deleted file mode 100644
index 688fc8c..0000000
--- a/environment/src/main/java/org/apache/tamaya/environment/internal/ClassLoaderDependentEarEnvironmentProvider.java
+++ /dev/null
@@ -1,40 +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.environment.internal;
-
-
-import javax.annotation.Priority;
-
-/**
- * This class implements a {@link org.apache.tamaya.environment.RuntimeContextProvider} that tries
- * to read configuration for an ear deployment located under {@code META-INF/env/ear.properties,
- * META-INF/env/ear.xml or META-INF/env/ear.ini}. The environment id hereby is defined by a
- * configuration entry named {@code org.apache.tamaya.core.env.earId}.
- *
- * Only if such a configuration with such an {@code earId} is found an {@link org.apache.tamaya.environment.RuntimeContext}
- * is created and attached to the corresponding ear classloader.
- */
-@Priority(2000)
-public class ClassLoaderDependentEarEnvironmentProvider extends AbstractClassLoaderDependentRuntimeContextSpi{
-
- public ClassLoaderDependentEarEnvironmentProvider(){
- super("ear");
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/5f2b6e3e/environment/src/main/java/org/apache/tamaya/environment/internal/ClasspathPropertiesEnvironmentProvider.java
----------------------------------------------------------------------
diff --git a/environment/src/main/java/org/apache/tamaya/environment/internal/ClasspathPropertiesEnvironmentProvider.java b/environment/src/main/java/org/apache/tamaya/environment/internal/ClasspathPropertiesEnvironmentProvider.java
new file mode 100644
index 0000000..d9767e5
--- /dev/null
+++ b/environment/src/main/java/org/apache/tamaya/environment/internal/ClasspathPropertiesEnvironmentProvider.java
@@ -0,0 +1,167 @@
+/*
+ * 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.environment.internal;
+
+
+import org.apache.tamaya.environment.spi.BaseEnvironmentPropertySourceProvider;
+import org.apache.tamaya.spisupport.SimplePropertiesPropertySource;
+import org.apache.tamaya.resource.ConfigResources;
+import org.apache.tamaya.spi.PropertySource;
+import org.apache.tamaya.spisupport.BasePropertySource;
+
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.logging.Logger;
+
+/**
+ * Configuration provider that resolves to a location in the classpath.
+ * Hereby the following system properties can be set to configure the provider
+ * (all entries are optional):
+ * <pre>
+ * env.STAGE : ordered list of configs to be loaded, e.g. GLOBAL,TEST,DEV
+ * env.ROOT : root context of the environment, by default ENV
+ * </pre>
+ * Adding {@code System.getenv()} as stage maps the current environment properties using
+ * the priority to be aliged with the context ordering, defined by {@code env.STAGE}.
+ */
+public class ClasspathPropertiesEnvironmentProvider extends BaseEnvironmentPropertySourceProvider {
+
+ private static final String STAGE_PROP = "env.STAGE";
+
+ private static final String ROOT_PROP = "env.ROOT";
+
+ private static final Logger LOGGER = Logger.getLogger(ClasspathPropertiesEnvironmentProvider.class.getName());
+
+ private String rootLocation;
+
+ private static final String DEFAULT_ENV = "System.getenv()";
+
+
+ public ClasspathPropertiesEnvironmentProvider(){
+ super(evaluateRoot(), evaluateStages());
+ }
+
+ private static String evaluateRoot() {
+ String value = System.getProperty(ROOT_PROP);
+ if(value==null) {
+ value = System.getenv(ROOT_PROP);
+ }
+ if(value==null){
+ value = "ENV";
+ }
+ return value;
+ }
+
+ private static String[] evaluateStages() {
+ String value = System.getProperty(STAGE_PROP);
+ if(value==null) {
+ value = System.getenv(STAGE_PROP);
+ }
+ if(value==null){
+ value = "System.getenv(),GLOBAL,DEVELOPMENT";
+ }
+ return value.split(",");
+ }
+
+ @Override
+ protected Collection<PropertySource> loadEnvProperties(
+ String environmentRootContext, String contextId, int priority) {
+ List<PropertySource> result = new ArrayList<>();
+ if (DEFAULT_ENV.equals(contextId)){
+ result.add(new EnvPropertiesPropertySource(environmentRootContext, priority));
+ }
+ else{
+ loadProperties(environmentRootContext, contextId, priority, result);
+ }
+ return result;
+ }
+
+ private void loadProperties(String environmentRootContext, String contextId, int priority, List<PropertySource> result) {
+ String cpExp = getBaseResourcePath()+'/' +contextId+".properties";
+ if(cpExp.startsWith("/")){
+ cpExp = cpExp.substring(1);
+ }
+ for(URL url: ConfigResources.getResourceResolver().getResources(cpExp)){
+ result.add(new SimplePropertiesPropertySource(environmentRootContext, url, priority));
+ }
+ }
+
+ /**
+ * Get the basic resource path used for lookup of properties files.
+ * @return the basic resource path, never null.
+ */
+ protected String getBaseResourcePath() {
+ return "";
+ }
+
+ private static final class EnvPropertiesPropertySource extends BasePropertySource{
+
+ private final int priority;
+
+ private Map<String, String> envProps = new HashMap<>();
+
+ public EnvPropertiesPropertySource(int priority) {
+ this(null, priority);
+ }
+
+ public EnvPropertiesPropertySource(String environmentRootContext, int priority){
+ this.priority = priority;
+ if(environmentRootContext==null){
+ envProps.putAll(System.getenv());
+ }
+ else{
+ for(Map.Entry<String,String> en: System.getenv().entrySet()){
+ String prefix = environmentRootContext;
+ if(!prefix.endsWith(".")){
+ prefix += ".";
+ }
+ envProps.put(prefix+en.getKey(), en.getValue());
+ }
+ }
+ this.envProps = Collections.unmodifiableMap(envProps);
+ }
+
+ @Override
+ public String getName() {
+ return "System.getenv()";
+ }
+
+ @Override
+ public Map<String, String> getProperties() {
+ return this.envProps;
+ }
+
+ @Override
+ public int getOrdinal(){
+ return priority;
+ }
+
+ @Override
+ public String toString() {
+ return "EnvPropertiesPropertySource{" +
+ "priority=" + priority +
+ '}';
+ }
+ }
+
+
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/5f2b6e3e/environment/src/main/java/org/apache/tamaya/environment/internal/InitialEnvironmentProviderSpi.java
----------------------------------------------------------------------
diff --git a/environment/src/main/java/org/apache/tamaya/environment/internal/InitialEnvironmentProviderSpi.java b/environment/src/main/java/org/apache/tamaya/environment/internal/InitialEnvironmentProviderSpi.java
deleted file mode 100644
index c1b1001..0000000
--- a/environment/src/main/java/org/apache/tamaya/environment/internal/InitialEnvironmentProviderSpi.java
+++ /dev/null
@@ -1,74 +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.environment.internal;
-
-import java.net.InetAddress;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.Locale;
-import java.util.Map;
-import java.util.Map.Entry;
-import java.util.TimeZone;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
-import org.apache.tamaya.environment.RuntimeContext;
-import org.apache.tamaya.environment.spi.ContextProviderSpi;
-import org.apache.tamaya.environment.RuntimeContextBuilder;
-
-import javax.annotation.Priority;
-
-/**
- * Default {@link org.apache.tamaya.environment.RuntimeContext}.
- */
-@Priority(0)
-public final class InitialEnvironmentProviderSpi implements ContextProviderSpi {
-
- private static final String STAGE_PROP = "env.STAGE";
- private Map<String,String> contextData = new HashMap<>();
-
- public InitialEnvironmentProviderSpi() {
- try {
- contextData.put("host", InetAddress.getLocalHost().toString());
- } catch (Exception e) {
- Logger.getLogger(getClass().getName()).log(Level.WARNING, e, () -> "Failed to evaluate hostname.");
- }
- contextData.put("timezone", TimeZone.getDefault().getID());
- contextData.put("locale", Locale.getDefault().toString());
- // Copy all env properties....
- for (Entry<String, String> en : System.getenv().entrySet()) {
- contextData.put(en.getKey(), en.getValue());
- }
- String value = System.getProperty(STAGE_PROP);
- if(value==null) {
- value = System.getenv(STAGE_PROP);
- }
- if(value==null){
- value = "DEVELOPMENT";
- }
- contextData.put(STAGE_PROP, value);
- contextData = Collections.unmodifiableMap(contextData);
- }
-
- @Override
- public void setupContext(RuntimeContextBuilder contextBuilder) {
- contextBuilder.setAll(contextData);
- contextBuilder.setContextId("root");
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/5f2b6e3e/environment/src/main/java/org/apache/tamaya/environment/internal/SingleEnvironmentManager.java
----------------------------------------------------------------------
diff --git a/environment/src/main/java/org/apache/tamaya/environment/internal/SingleEnvironmentManager.java b/environment/src/main/java/org/apache/tamaya/environment/internal/SingleEnvironmentManager.java
deleted file mode 100644
index d81b8bb..0000000
--- a/environment/src/main/java/org/apache/tamaya/environment/internal/SingleEnvironmentManager.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.environment.internal;
-
-
-import org.apache.tamaya.ConfigException;
-import org.apache.tamaya.environment.RuntimeContext;
-import org.apache.tamaya.environment.RuntimeContextBuilder;
-import org.apache.tamaya.environment.spi.ContextProviderSpi;
-import org.apache.tamaya.spi.ServiceContext;
-
-import java.util.ArrayList;
-import java.util.List;
-
-/**
- * Service for accessing {@link org.apache.tamaya.environment.RuntimeContext}. Environments are used to
- * access/determine configurations.<br/>
- * <h3>Implementation PropertyMapSpec</h3> This class is
- * <ul>
- * <li>thread safe,
- * <li>and behaves contextual.
- * </ul>
- */
-public class SingleEnvironmentManager implements org.apache.tamaya.environment.spi.ContextSpi {
-
- private final List<ContextProviderSpi> environmentProviders = loadEnvironmentProviders();
-
- private List<ContextProviderSpi> loadEnvironmentProviders() {
- List<ContextProviderSpi> providerList = new ArrayList<>();
- for (ContextProviderSpi prov : ServiceContext.getInstance().getServices(ContextProviderSpi.class)) {
- providerList.add(prov);
- }
- return providerList;
- }
-
- @Override
- public RuntimeContext getCurrentContext() {
- RuntimeContextBuilder builder = RuntimeContextBuilder.of("unknown");
- for (ContextProviderSpi prov : environmentProviders) {
- prov.setupContext(builder);
- }
- return builder.build();
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/5f2b6e3e/environment/src/main/java/org/apache/tamaya/environment/internal/SystemClassLoaderEnvironmentProviderSpi.java
----------------------------------------------------------------------
diff --git a/environment/src/main/java/org/apache/tamaya/environment/internal/SystemClassLoaderEnvironmentProviderSpi.java b/environment/src/main/java/org/apache/tamaya/environment/internal/SystemClassLoaderEnvironmentProviderSpi.java
deleted file mode 100644
index 7eb9cd1..0000000
--- a/environment/src/main/java/org/apache/tamaya/environment/internal/SystemClassLoaderEnvironmentProviderSpi.java
+++ /dev/null
@@ -1,88 +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.environment.internal;
-
-import org.apache.tamaya.environment.RuntimeContextBuilder;
-import org.apache.tamaya.environment.spi.ContextProviderSpi;
-import org.apache.tamaya.format.ConfigurationFormat;
-import org.apache.tamaya.format.ConfigurationFormats;
-import org.apache.tamaya.resource.ConfigResources;
-
-import javax.annotation.Priority;
-import java.io.InputStream;
-import java.net.URL;
-import java.util.*;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
-/**
- * System environment provider (loaded only once using the system class loader) that loads additional environment properties fromMap the classpath evaluating
- * {@code META-INF/env/system.properties, META-INF/env/system.xml and META-INF/env/system.ini}.
- */
-@Priority(1000)
-public class SystemClassLoaderEnvironmentProviderSpi implements ContextProviderSpi {
-
- private static final Logger LOG = Logger.getLogger(SystemClassLoaderEnvironmentProviderSpi.class.getName());
-
-
- private Map<String,String> data = new HashMap<>();
-
- public SystemClassLoaderEnvironmentProviderSpi(){
- if (data == null) {
- Collection<URL> propertyUris = getConfigLocations();
- data = new HashMap<>();
- for (URL resource : propertyUris) {
- for (ConfigurationFormat format : getConfigFormats(resource)) {
- try (InputStream is = resource.openStream()) {
- data.putAll(format.readConfiguration(resource.toExternalForm(), is).getDefaultSection());
- } catch (Exception e) {
- LOG.log(Level.SEVERE, e, () -> "Error reading application context data from " + resource);
- }
- }
- }
- data.put("classloader.type", ClassLoader.getSystemClassLoader().getClass().getName());
- data.put("classloader.info", "System-Classloader");
- Set<URL> uris = new HashSet<>();
- uris.addAll(propertyUris);
- data.put("context.sources", uris.toString());
- data = Collections.unmodifiableMap(data);
- this.data = Collections.unmodifiableMap(data);
- }
- }
-
- protected List<ConfigurationFormat> getConfigFormats(URL url) {
- return ConfigurationFormats.getFormats(url);
- }
-
- protected Collection<URL> getConfigLocations() {
- return ConfigResources.getResourceResolver().getResources(ClassLoader.getSystemClassLoader(),
- "classpath:META-INF/context/system.properties", "classpath:META-INF/context/system.xml",
- "classpath:META-INF/context/system.ini");
- }
-
-
- @Override
- public void setupContext(RuntimeContextBuilder contextBuilder) {
- if (!data.isEmpty()) {
- contextBuilder.setAll(data).build();
- contextBuilder.setContextId("system");
- }
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/5f2b6e3e/environment/src/main/java/org/apache/tamaya/environment/internal/package-info.java
----------------------------------------------------------------------
diff --git a/environment/src/main/java/org/apache/tamaya/environment/internal/package-info.java b/environment/src/main/java/org/apache/tamaya/environment/internal/package-info.java
index 3d5075e..3f5b53f 100644
--- a/environment/src/main/java/org/apache/tamaya/environment/internal/package-info.java
+++ b/environment/src/main/java/org/apache/tamaya/environment/internal/package-info.java
@@ -19,4 +19,4 @@
/**
* Contains the provided implementation classes for the environment module.
*/
-package org.apache.tamaya.resource.internal;
\ No newline at end of file
+package org.apache.tamaya.environment.internal;
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/5f2b6e3e/environment/src/main/java/org/apache/tamaya/environment/spi/BaseEnvironmentPropertySourceProvider.java
----------------------------------------------------------------------
diff --git a/environment/src/main/java/org/apache/tamaya/environment/spi/BaseEnvironmentPropertySourceProvider.java b/environment/src/main/java/org/apache/tamaya/environment/spi/BaseEnvironmentPropertySourceProvider.java
new file mode 100644
index 0000000..5924640
--- /dev/null
+++ b/environment/src/main/java/org/apache/tamaya/environment/spi/BaseEnvironmentPropertySourceProvider.java
@@ -0,0 +1,119 @@
+/*
+ * 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.environment.spi;
+
+
+import org.apache.tamaya.ConfigException;
+import org.apache.tamaya.spi.PropertySource;
+import org.apache.tamaya.spi.PropertySourceProvider;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.List;
+import java.util.logging.Logger;
+
+/**
+ * Implements a base property source that defines a multilayered environment setup.
+ */
+public abstract class BaseEnvironmentPropertySourceProvider implements PropertySourceProvider {
+
+ private static final Logger LOGGER = Logger.getLogger(BaseEnvironmentPropertySourceProvider.class.getName());
+
+ private int basePriority;
+
+ private int priorityIncrease;
+
+ private List<String> environmentIds = new ArrayList<>();
+
+ private String environmentRootContext;
+
+ private List<PropertySource> propertySources = new ArrayList<>();
+
+
+ /**
+ * Creates a new Environment provider, hereby using 10 for basePriority and priorityIncrease.
+ * @param environmentRootContext the environment target root context, e.g. ENV. or null
+ * for not remapping the environment properties.
+ * @param environmentIds the context ids, that build up the environment.
+ */
+ public BaseEnvironmentPropertySourceProvider(String environmentRootContext,
+ String... environmentIds) {
+ this(environmentRootContext, 10,10,environmentIds);
+ }
+ /**
+ * Creates a new Environment provider.
+ * @param environmentRootContext the environment target root context, e.g. ENV. or null
+ * for not remapping the environment properties.
+ * @param basePriority the base priority used for the weakest environment properties set.
+ * @param priorityIncrease the value the property source's priority should be increased with each
+ * environment context level added.
+ * @param environmentIds the context ids, that build up the environment.
+ */
+ public BaseEnvironmentPropertySourceProvider(String environmentRootContext, int basePriority, int priorityIncrease,
+ String... environmentIds) {
+ this.basePriority = basePriority;
+ this.priorityIncrease = priorityIncrease;
+ if (environmentIds.length == 0) {
+ throw new ConfigException("At least one environment context id must be defined.");
+ }
+ if (environmentRootContext == null) {
+ LOGGER.finest("No environment mapping is applied.");
+ }
+ this.environmentRootContext = environmentRootContext;
+ this.environmentIds.addAll(Arrays.asList(environmentIds));
+ int priority = basePriority;
+ for (String contextId : environmentIds) {
+ propertySources.addAll(loadEnvProperties(environmentRootContext, contextId, priority));
+ priority += priorityIncrease;
+ }
+ }
+
+ /**
+ * Method that loads the environment properties for the given contextId.
+ * @param environmentRootContext the root context, where entries should be mapped to.
+ * @param contextId the contextId.
+ * @param priority the target priority the created PropertySource should have. This priority is important, since it reflects the
+ * environment context overriding rules for the environment part created.
+ * @return the corresponding PrioritySources to be added, never null.
+ */
+ protected abstract Collection<PropertySource> loadEnvProperties(
+ String environmentRootContext, String contextId, int priority);
+
+ /**
+ * Get the environment context ids that define how this environment configuration
+ * is setup, in order of priority increasing.
+ * @return the ordered list of context ids.
+ */
+ public List<String> getEnvironmentIds() {
+ return environmentIds;
+ }
+
+ @Override
+ public String toString() {
+ return "EnvironmentPropertySourceProvider{" +
+ "environmentIds=" + environmentIds +
+ ", environmentRootContext='" + environmentRootContext + '\'' +
+ '}';
+ }
+
+ @Override
+ public Collection<PropertySource> getPropertySources() {
+ return propertySources;
+ }
+
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/5f2b6e3e/environment/src/main/java/org/apache/tamaya/environment/spi/ContextProviderSpi.java
----------------------------------------------------------------------
diff --git a/environment/src/main/java/org/apache/tamaya/environment/spi/ContextProviderSpi.java b/environment/src/main/java/org/apache/tamaya/environment/spi/ContextProviderSpi.java
deleted file mode 100644
index d0a8b3e..0000000
--- a/environment/src/main/java/org/apache/tamaya/environment/spi/ContextProviderSpi.java
+++ /dev/null
@@ -1,45 +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.environment.spi;
-
-
-import org.apache.tamaya.environment.RuntimeContext;
-import org.apache.tamaya.environment.RuntimeContextBuilder;
-
-
-/**
- * SPI component for evaluating the current runtime context. All registered providers hereby are
- * organized by default depending on their (optional) {@code @Priority} annotation's value. (the
- * effective ordering depends on the current {@link org.apache.tamaya.spi.ServiceContext} implementation
- * active).
- */
-public interface ContextProviderSpi {
-
- public static final String ENVIRONMENT_TYPE = "environment-type";
-
- /**
- * If a data providers identifies a new runtime context level, it should build a new
- * {@link org.apache.tamaya.environment.RuntimeContext} with all the related data to be added to this
- * context, otherwise it should simply return null.
- *
- * @param contextBuilder the current context builder.
- * @return the new current context for the current runtime state, or null.
- */
- void setupContext(RuntimeContextBuilder contextBuilder);
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/5f2b6e3e/environment/src/main/java/org/apache/tamaya/environment/spi/package-info.java
----------------------------------------------------------------------
diff --git a/environment/src/main/java/org/apache/tamaya/environment/spi/package-info.java b/environment/src/main/java/org/apache/tamaya/environment/spi/package-info.java
index 23d6b15..9037c2b 100644
--- a/environment/src/main/java/org/apache/tamaya/environment/spi/package-info.java
+++ b/environment/src/main/java/org/apache/tamaya/environment/spi/package-info.java
@@ -17,6 +17,7 @@
* under the License.
*/
/**
- * Defines the SPI of the environment module.
+ * Main API of the environment module, containing the base class for implementing adapted
+ * environment parts in your configuration.
*/
-package org.apache.tamaya.resource.internal;
\ No newline at end of file
+package org.apache.tamaya.environment.spi;
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/5f2b6e3e/environment/src/main/resources/META-INF/services/org.apache.tamaya.spi.PropertySourceProvider
----------------------------------------------------------------------
diff --git a/environment/src/main/resources/META-INF/services/org.apache.tamaya.spi.PropertySourceProvider b/environment/src/main/resources/META-INF/services/org.apache.tamaya.spi.PropertySourceProvider
new file mode 100644
index 0000000..233448a
--- /dev/null
+++ b/environment/src/main/resources/META-INF/services/org.apache.tamaya.spi.PropertySourceProvider
@@ -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.environment.internal.ClasspathPropertiesEnvironmentProvider
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/5f2b6e3e/environment/src/test/java/org/apache/tamaya/metamodel/environment/RuntimeContextProviderSpiTest.java
----------------------------------------------------------------------
diff --git a/environment/src/test/java/org/apache/tamaya/metamodel/environment/RuntimeContextProviderSpiTest.java b/environment/src/test/java/org/apache/tamaya/metamodel/environment/RuntimeContextProviderSpiTest.java
deleted file mode 100644
index 88b1692..0000000
--- a/environment/src/test/java/org/apache/tamaya/metamodel/environment/RuntimeContextProviderSpiTest.java
+++ /dev/null
@@ -1,57 +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.metamodel.environment;
-
-import org.apache.tamaya.environment.RuntimeContext;
-import org.apache.tamaya.environment.RuntimeContextProvider;
-import org.junit.Test;
-
-
-import static org.junit.Assert.*;
-
-/**
- * Tests for basic {@link RuntimeContextProvider} functionality.
- * Created by Anatole on 17.10.2014.
- */
-public class RuntimeContextProviderSpiTest {
-
- @Test
- public void testGetEnvironment(){
- RuntimeContext env = RuntimeContextProvider.current();
- assertNotNull(env);
- RuntimeContext env2 = RuntimeContextProvider.current();
- assertNotNull(env2);
- assertFalse("Current Environments requested in same context are not the same!", env==env2);
- }
-
- @Test
- public void testRootIsNotCurrentEnvironment(){
- RuntimeContext env1 = RuntimeContextProvider.current();
- assertNotNull(env1);
- RuntimeContext env2 = RuntimeContextProvider.current();
- assertNotNull(env2);
- // within this testdata environment these are always the same
- assertEquals(env1, env2);
- }
-
- @Test
- public void testEnvironmentOverride(){
- assertEquals(RuntimeContextProvider.current().get("env.STAGE"), "MyStage");
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/5f2b6e3e/environment/src/test/java/org/apache/tamaya/metamodel/environment/TestEnvironmentManagerSingleton.java
----------------------------------------------------------------------
diff --git a/environment/src/test/java/org/apache/tamaya/metamodel/environment/TestEnvironmentManagerSingleton.java b/environment/src/test/java/org/apache/tamaya/metamodel/environment/TestEnvironmentManagerSingleton.java
deleted file mode 100644
index 393775f..0000000
--- a/environment/src/test/java/org/apache/tamaya/metamodel/environment/TestEnvironmentManagerSingleton.java
+++ /dev/null
@@ -1,37 +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.metamodel.environment;
-
-import org.apache.tamaya.environment.RuntimeContext;
-import org.apache.tamaya.environment.spi.ContextSpi;
-
-/**
- * Created by Anatole on 12.09.2014.
- */
-public class TestEnvironmentManagerSingleton implements ContextSpi {
-
- public RuntimeContext getCurrentContext(){
- return null;
- }
-
- public RuntimeContext getRootContext(){
- return null;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/5f2b6e3e/environment/src/test/java/org/apache/tamaya/metamodel/environment/TestEnvironmentProvider.java
----------------------------------------------------------------------
diff --git a/environment/src/test/java/org/apache/tamaya/metamodel/environment/TestEnvironmentProvider.java b/environment/src/test/java/org/apache/tamaya/metamodel/environment/TestEnvironmentProvider.java
deleted file mode 100644
index 11760b9..0000000
--- a/environment/src/test/java/org/apache/tamaya/metamodel/environment/TestEnvironmentProvider.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.metamodel.environment;
-
-import org.apache.tamaya.environment.RuntimeContextBuilder;
-import org.apache.tamaya.environment.spi.ContextProviderSpi;
-
-import javax.annotation.Priority;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.Map;
-
-/**
- * Environment provider used by some tests.
- */
-@Priority(2000)
-public class TestEnvironmentProvider implements ContextProviderSpi {
- private Map<String, String> data = new HashMap<>();
-
- public TestEnvironmentProvider(){
- data.put("env.STAGE", "MyStage");
- data.put("java.version", System.getProperty("java.version"));
- data = Collections.unmodifiableMap(data);
- }
-
-
- @Override
- public void setupContext(RuntimeContextBuilder contextBuilder){
- contextBuilder.setAll(data);
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/5f2b6e3e/environment/src/test/resources/GLOBAL.properties
----------------------------------------------------------------------
diff --git a/environment/src/test/resources/GLOBAL.properties b/environment/src/test/resources/GLOBAL.properties
new file mode 100644
index 0000000..9f39f75
--- /dev/null
+++ b/environment/src/test/resources/GLOBAL.properties
@@ -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.
+#
+aKey=aValue.GLOBAL
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/5f2b6e3e/environment/src/test/resources/META-INF/services/org.apache.tamaya.environment.spi.ContextProviderSpi
----------------------------------------------------------------------
diff --git a/environment/src/test/resources/META-INF/services/org.apache.tamaya.environment.spi.ContextProviderSpi b/environment/src/test/resources/META-INF/services/org.apache.tamaya.environment.spi.ContextProviderSpi
deleted file mode 100644
index 7f71c15..0000000
--- a/environment/src/test/resources/META-INF/services/org.apache.tamaya.environment.spi.ContextProviderSpi
+++ /dev/null
@@ -1,23 +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.environment.internal.ClassLoaderDependentAppEnvironmentProvider
-org.apache.tamaya.environment.internal.ClassLoaderDependentEarEnvironmentProvider
-org.apache.tamaya.environment.internal.InitialEnvironmentProviderSpi
-org.apache.tamaya.environment.internal.SystemClassLoaderEnvironmentProviderSpi
-org.apache.tamaya.metamodel.environment.TestEnvironmentProvider
\ No newline at end of file