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/05/05 13:11:23 UTC
[04/10] incubator-tamaya git commit: Removed unused dormant parts.
Moved usable dormant utils into new sandbox module. Fixed jqassistant issues
in simple metamodel module.
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/46ede97c/dormant/modules/metamodels/environment/src/main/java/org/apache/tamaya/metamodel/environment/internal/InitialEnvironmentProvider.java
----------------------------------------------------------------------
diff --git a/dormant/modules/metamodels/environment/src/main/java/org/apache/tamaya/metamodel/environment/internal/InitialEnvironmentProvider.java b/dormant/modules/metamodels/environment/src/main/java/org/apache/tamaya/metamodel/environment/internal/InitialEnvironmentProvider.java
deleted file mode 100644
index 9321539..0000000
--- a/dormant/modules/metamodels/environment/src/main/java/org/apache/tamaya/metamodel/environment/internal/InitialEnvironmentProvider.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.metamodel.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.Properties;
-import java.util.TimeZone;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
-import org.apache.tamaya.core.env.ConfiguredSystemProperties;
-import org.apache.tamaya.metamodel.environment.EnvironmentBuilder;
-import org.apache.tamaya.metamodel.environment.spi.EnvironmentProvider;
-
-/**
- * Default {@link org.apache.tamaya.metamodel.environment.Environment}.
- */
-public final class InitialEnvironmentProvider implements EnvironmentProvider{
-
- private Map<String,String> environmentData = new HashMap<>();
-
- public InitialEnvironmentProvider() {
- Properties props = System.getProperties();
- if(props instanceof ConfiguredSystemProperties){
- props = ((ConfiguredSystemProperties)props).getInitialProperties();
- }
- String stageValue = props.getProperty(EnvironmentBuilder.STAGE_PROP);
- environmentData.put(EnvironmentBuilder.STAGE_PROP, stageValue);
- environmentData.put("timezone", TimeZone.getDefault().getID());
- environmentData.put("locale", Locale.getDefault().toString());
- try {
- environmentData.put("host", InetAddress.getLocalHost().toString());
- } catch (Exception e) {
- Logger.getLogger(getClass().getName()).log(Level.WARNING, e, () -> "Failed to evaluate hostname.");
- }
- // Copy env properties....
- for (Entry<String, String> en : System.getenv().entrySet()) {
- environmentData.put(en.getKey(), en.getValue());
- }
- environmentData = Collections.unmodifiableMap(environmentData);
- }
-
- @Override
- public boolean isActive(){
- return true;
- }
-
- @Override
- public Map<String,String> getEnvironmentData() {
- return environmentData;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/46ede97c/dormant/modules/metamodels/environment/src/main/java/org/apache/tamaya/metamodel/environment/internal/SingleEnvironmentManager.java
----------------------------------------------------------------------
diff --git a/dormant/modules/metamodels/environment/src/main/java/org/apache/tamaya/metamodel/environment/internal/SingleEnvironmentManager.java b/dormant/modules/metamodels/environment/src/main/java/org/apache/tamaya/metamodel/environment/internal/SingleEnvironmentManager.java
deleted file mode 100644
index cbf177d..0000000
--- a/dormant/modules/metamodels/environment/src/main/java/org/apache/tamaya/metamodel/environment/internal/SingleEnvironmentManager.java
+++ /dev/null
@@ -1,70 +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.internal;
-
-
-import org.apache.tamaya.metamodel.environment.Environment;
-import org.apache.tamaya.metamodel.environment.EnvironmentBuilder;
-import org.apache.tamaya.metamodel.environment.spi.EnvironmentProvider;
-import org.apache.tamaya.metamodel.environment.spi.EnvironmentSpi;
-import org.apache.tamaya.spi.ServiceContext;
-
-import java.util.*;
-
-/**
- * Service for accessing {@link org.apache.tamaya.metamodel.environment.Environment}. 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 EnvironmentSpi {
-
- private final List<EnvironmentProvider> environmentProviders = loadEnvironmentProviders();
- private Environment rootEnvironment = getCurrentEnvironment();
-
- private List<EnvironmentProvider> loadEnvironmentProviders() {
- List<EnvironmentProvider> providerList = new ArrayList<>();
- for(EnvironmentProvider prov: ServiceContext.getInstance().getServices(EnvironmentProvider.class)){
- providerList.add(prov);
- }
- return providerList;
- }
-
- @Override
- public Environment getCurrentEnvironment(){
- EnvironmentBuilder b = EnvironmentBuilder.of();
- for(EnvironmentProvider prov: environmentProviders){
- if(prov.isActive()){
- if(prov.isActive()){
- b.setAll(prov.getEnvironmentData());
- }
- }
- }
- return b.build();
- }
-
- @Override
- public Environment getRootEnvironment(){
- return rootEnvironment;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/46ede97c/dormant/modules/metamodels/environment/src/main/java/org/apache/tamaya/metamodel/environment/internal/SystemClassLoaderEnvironmentProvider.java
----------------------------------------------------------------------
diff --git a/dormant/modules/metamodels/environment/src/main/java/org/apache/tamaya/metamodel/environment/internal/SystemClassLoaderEnvironmentProvider.java b/dormant/modules/metamodels/environment/src/main/java/org/apache/tamaya/metamodel/environment/internal/SystemClassLoaderEnvironmentProvider.java
deleted file mode 100644
index e943971..0000000
--- a/dormant/modules/metamodels/environment/src/main/java/org/apache/tamaya/metamodel/environment/internal/SystemClassLoaderEnvironmentProvider.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.metamodel.environment.internal;
-
-import org.apache.tamaya.core.config.ConfigurationFormats;
-import org.apache.tamaya.core.resource.Resource;
-import org.apache.tamaya.metamodel.environment.spi.EnvironmentProvider;
-import org.apache.tamaya.spi.ServiceContext;
-import org.apache.tamaya.core.properties.ConfigurationFormat;
-import org.apache.tamaya.core.resource.ResourceLoader;
-
-
-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}.
- */
-public class SystemClassLoaderEnvironmentProvider implements EnvironmentProvider {
-
- private static final Logger LOG = Logger.getLogger(SystemClassLoaderEnvironmentProvider.class.getName());
-
- private Map<String,String> data = new HashMap<>();
-
-
- public SystemClassLoaderEnvironmentProvider(){
- List<Resource> propertyResources = ServiceContext.getInstance().getSingleton(ResourceLoader.class).getResources(ClassLoader.getSystemClassLoader(),
- "classpath:META-INF/env/system.properties", "classpath:META-INF/env/system.xml", "classpath:META-INF/env/system.ini");
- for(Resource resource:propertyResources){
- try{
- ConfigurationFormat format = ConfigurationFormats.getFormat(resource);
- Map<String,String> data = format.readConfiguration(resource);
- data.putAll(data);
- }
- catch(Exception e){
- LOG.log(Level.INFO, e, () -> "Could not read environment data from " + resource);
- }
- }
- data.put("classloader.type", ClassLoader.getSystemClassLoader().getClass().getName());
- data.put("classloader.info", ClassLoader.getSystemClassLoader().toString());
- Set<Resource> resourceSet = new HashSet<>();
- resourceSet.addAll(propertyResources);
- data.put("environment.system.sources", resourceSet.toString());
- this.data = Collections.unmodifiableMap(data);
- }
- @Override
- public boolean isActive() {
- return true;
- }
-
- @Override
- public Map<String,String> getEnvironmentData() {
- return data;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/46ede97c/dormant/modules/metamodels/environment/src/main/java/org/apache/tamaya/metamodel/environment/spi/EnvironmentSpi.java
----------------------------------------------------------------------
diff --git a/dormant/modules/metamodels/environment/src/main/java/org/apache/tamaya/metamodel/environment/spi/EnvironmentSpi.java b/dormant/modules/metamodels/environment/src/main/java/org/apache/tamaya/metamodel/environment/spi/EnvironmentSpi.java
deleted file mode 100644
index dbf8f65..0000000
--- a/dormant/modules/metamodels/environment/src/main/java/org/apache/tamaya/metamodel/environment/spi/EnvironmentSpi.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.metamodel.environment.spi;
-
-
-import org.apache.tamaya.metamodel.environment.Environment;
-
-/**
- * Service for accessing {@link org.apache.tamaya.metamodel.environment.Environment}. 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 interface EnvironmentSpi {
-
- /**
- * Get the current environment current the given environment type.
- * @return the corresponding environment, never null.
- * @throws IllegalArgumentException if not such type is present or active.
- */
- Environment getCurrentEnvironment();
-
- /**
- * Get the current environment current the given environment type.
- * @return the corresponding environment, never null.
- * @throws IllegalArgumentException if not such type is present or active.
- */
- Environment getRootEnvironment();
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/46ede97c/dormant/modules/metamodels/environment/src/main/resources/META-INF/services/org.apache.tamaya.spi.EnvironmentSpi
----------------------------------------------------------------------
diff --git a/dormant/modules/metamodels/environment/src/main/resources/META-INF/services/org.apache.tamaya.spi.EnvironmentSpi b/dormant/modules/metamodels/environment/src/main/resources/META-INF/services/org.apache.tamaya.spi.EnvironmentSpi
deleted file mode 100644
index 4a5b828..0000000
--- a/dormant/modules/metamodels/environment/src/main/resources/META-INF/services/org.apache.tamaya.spi.EnvironmentSpi
+++ /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.metamodel.environment.TestEnvironmentManagerSingleton
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/46ede97c/dormant/modules/metamodels/environment/src/test/java/org/apache/tamaya/metamodel/environment/EnvironmentManagerTest.java
----------------------------------------------------------------------
diff --git a/dormant/modules/metamodels/environment/src/test/java/org/apache/tamaya/metamodel/environment/EnvironmentManagerTest.java b/dormant/modules/metamodels/environment/src/test/java/org/apache/tamaya/metamodel/environment/EnvironmentManagerTest.java
deleted file mode 100644
index e9ff31b..0000000
--- a/dormant/modules/metamodels/environment/src/test/java/org/apache/tamaya/metamodel/environment/EnvironmentManagerTest.java
+++ /dev/null
@@ -1,66 +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;
-import org.junit.Test;
-
-
-import static org.junit.Assert.*;
-
-/**
- * Tests for basic {@link org.apache.tamaya.EnvironmentManager} functionality.
- * Created by Anatole on 17.10.2014.
- */
-public class EnvironmentManagerTest {
-
- @Test
- public void testGetEnvironment(){
- Environment env = Environment.current();
- assertNotNull(env);
- Environment env2 = Environment.current();
- assertNotNull(env2);
- assertFalse("Current Environments requested in same context are not the same!", env==env2);
- }
-
- @Test
- public void testGetRootEnvironment(){
- Environment env = Environment.root();
- assertNotNull(env);
- Environment env2 = Environment.root();
- assertNotNull(env2);
- assertTrue("Root Environments requested in same context are not the same!", env==env2);
- }
-
- @Test
- public void testRootIsNotCurrentEnvironment(){
- Environment env1 = Environment.root();
- Environment env2 = Environment.current();
- assertNotNull(env1);
- assertNotNull(env2);
- // within this testdata environment these are always the same
- assertEquals(env1, env2);
- }
-
- @Test
- public void testEnvironmentOverride(){
- assertEquals(Environment.root().get("user.country").get(),System.getProperty("user.country"));
- assertEquals(Environment.current().get("user.country").get(), System.getProperty("user.country"));
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/46ede97c/dormant/modules/metamodels/environment/src/test/java/org/apache/tamaya/metamodel/environment/TestEnvironmentManagerSingleton.java
----------------------------------------------------------------------
diff --git a/dormant/modules/metamodels/environment/src/test/java/org/apache/tamaya/metamodel/environment/TestEnvironmentManagerSingleton.java b/dormant/modules/metamodels/environment/src/test/java/org/apache/tamaya/metamodel/environment/TestEnvironmentManagerSingleton.java
deleted file mode 100644
index 83a6056..0000000
--- a/dormant/modules/metamodels/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.metamodel.environment.spi.EnvironmentSpi;
-
-/**
- * Created by Anatole on 12.09.2014.
- */
-public class TestEnvironmentManagerSingleton implements EnvironmentSpi {
- @Override
- public Environment getCurrentEnvironment(){
- return null;
- }
-
- @Override
- public Environment getRootEnvironment(){
- return null;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/46ede97c/dormant/modules/metamodels/environment/src/test/java/org/apache/tamaya/metamodel/environment/TestEnvironmentProvider.java
----------------------------------------------------------------------
diff --git a/dormant/modules/metamodels/environment/src/test/java/org/apache/tamaya/metamodel/environment/TestEnvironmentProvider.java b/dormant/modules/metamodels/environment/src/test/java/org/apache/tamaya/metamodel/environment/TestEnvironmentProvider.java
deleted file mode 100644
index 7524a80..0000000
--- a/dormant/modules/metamodels/environment/src/test/java/org/apache/tamaya/metamodel/environment/TestEnvironmentProvider.java
+++ /dev/null
@@ -1,48 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tamaya.metamodel.environment;
-
-import org.apache.tamaya.core.spi.EnvironmentProvider;
-
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.Map;
-
-/**
- * Environment provider used by some tests.
- */
-public class TestEnvironmentProvider implements EnvironmentProvider {
- private Map<String, String> data = new HashMap<>();
-
- public TestEnvironmentProvider(){
- data.put("user.country", System.getProperty("user.country"));
- data.put("java.version", System.getProperty("java.version"));
- data = Collections.unmodifiableMap(data);
- }
-
- @Override
- public boolean isActive() {
- return true;
- }
-
- @Override
- public Map<String, String> getEnvironmentData() {
- return data;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/46ede97c/dormant/modules/metamodels/simple/src/main/resources/META-INF/services/old.ConfigurationProviderSpi
----------------------------------------------------------------------
diff --git a/dormant/modules/metamodels/simple/src/main/resources/META-INF/services/old.ConfigurationProviderSpi b/dormant/modules/metamodels/simple/src/main/resources/META-INF/services/old.ConfigurationProviderSpi
deleted file mode 100644
index b3a2634..0000000
--- a/dormant/modules/metamodels/simple/src/main/resources/META-INF/services/old.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.metamodel.simple.SimpleConfigProvider
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/46ede97c/dormant/pom.xml
----------------------------------------------------------------------
diff --git a/dormant/pom.xml b/dormant/pom.xml
deleted file mode 100644
index 434563e..0000000
--- a/dormant/pom.xml
+++ /dev/null
@@ -1,35 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
-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.
--->
-<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-all</artifactId>
- <version>0.1-SNAPSHOT</version>
- </parent>
-
- <artifactId>buildtools</artifactId>
- <name>Apache Tamaya - Build Tools</name>
-
-
-</project>
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/46ede97c/modules/metamodels/simple/src/main/resources/META-INF/services/org.apache.tamaya.spi.PropertySourceProvider
----------------------------------------------------------------------
diff --git a/modules/metamodels/simple/src/main/resources/META-INF/services/org.apache.tamaya.spi.PropertySourceProvider b/modules/metamodels/simple/src/main/resources/META-INF/services/org.apache.tamaya.spi.PropertySourceProvider
new file mode 100644
index 0000000..b3a2634
--- /dev/null
+++ b/modules/metamodels/simple/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.metamodel.simple.SimpleConfigProvider
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/46ede97c/sandbox/environment/pom.xml
----------------------------------------------------------------------
diff --git a/sandbox/environment/pom.xml b/sandbox/environment/pom.xml
new file mode 100644
index 0000000..7773c43
--- /dev/null
+++ b/sandbox/environment/pom.xml
@@ -0,0 +1,42 @@
+<!--
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements. See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership. The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License. You may obtain a copy current the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied. See the License for the
+specific language governing permissions and limitations
+under the License.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.apache.tamaya.ext</groupId>
+ <artifactId>tamaya-sandbox</artifactId>
+ <version>0.1-incubating-SNAPSHOT</version>
+ <relativePath>..</relativePath>
+ </parent>
+
+ <artifactId>tamaya-environment</artifactId>
+ <name>Apache Tamaya Modules - Environment Manager</name>
+ <packaging>jar</packaging>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.tamaya</groupId>
+ <artifactId>tamaya-api</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ </dependencies>
+
+</project>
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/46ede97c/sandbox/environment/src/main/java/org/apache/tamaya/environment/BuildableRuntimeContext.java
----------------------------------------------------------------------
diff --git a/sandbox/environment/src/main/java/org/apache/tamaya/environment/BuildableRuntimeContext.java b/sandbox/environment/src/main/java/org/apache/tamaya/environment/BuildableRuntimeContext.java
new file mode 100644
index 0000000..009b5e2
--- /dev/null
+++ b/sandbox/environment/src/main/java/org/apache/tamaya/environment/BuildableRuntimeContext.java
@@ -0,0 +1,113 @@
+/*
+ * 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 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 environment data.
+ */
+ private Map<String, String> context = new TreeMap<>();
+
+ /**
+ * Constructor.
+ *
+ * @param builder the builder, not null.
+ */
+ BuildableRuntimeContext(EnvironmentBuilder builder) {
+ Objects.requireNonNull(builder);
+ context.putAll(builder.contextData);
+ }
+
+ @Override
+ public Map<String, String> toMap() {
+ return context;
+ }
+
+ @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;
+
+ BuildableEnvironment that = (BuildableEnvironment) 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/blob/46ede97c/sandbox/environment/src/main/java/org/apache/tamaya/environment/RuntimeContext.java
----------------------------------------------------------------------
diff --git a/sandbox/environment/src/main/java/org/apache/tamaya/environment/RuntimeContext.java b/sandbox/environment/src/main/java/org/apache/tamaya/environment/RuntimeContext.java
new file mode 100644
index 0000000..48b0691
--- /dev/null
+++ b/sandbox/environment/src/main/java/org/apache/tamaya/environment/RuntimeContext.java
@@ -0,0 +1,83 @@
+/*
+ * 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.spi.ServiceContext;
+
+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();
+
+ /**
+ * Returns a full (and unique) context 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 getQualifiedContextId();
+
+ /**
+ * Access the parent context.
+ * @return the parent context for this instance, or null, if this is a root context.
+ */
+ RuntimeContext getParentContext();
+
+ /**
+ * 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/blob/46ede97c/sandbox/environment/src/main/java/org/apache/tamaya/environment/RuntimeContextBuilder.java
----------------------------------------------------------------------
diff --git a/sandbox/environment/src/main/java/org/apache/tamaya/environment/RuntimeContextBuilder.java b/sandbox/environment/src/main/java/org/apache/tamaya/environment/RuntimeContextBuilder.java
new file mode 100644
index 0000000..1aba76a
--- /dev/null
+++ b/sandbox/environment/src/main/java/org/apache/tamaya/environment/RuntimeContextBuilder.java
@@ -0,0 +1,75 @@
+/*
+ * 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 java.util.HashMap;
+import java.util.Map;
+import java.util.Objects;
+
+/**
+* Builder to create new {@link RuntimeContext instances.}
+*/
+public final class RuntimeContextBuilder {
+
+ /** THe environment data. */
+ Map<String,String> contextData = new HashMap<>();
+
+ /**
+ * Constructor.
+ */
+ private RuntimeContextBuilder() {
+ }
+
+ /**
+ * Creates a new buildr instance.
+ * @return the new builder instance.
+ */
+ public static final RuntimeContextBuilder of() {
+ return new RuntimeContextBuilder();
+ }
+
+ /**
+ * 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/blob/46ede97c/sandbox/environment/src/main/java/org/apache/tamaya/environment/RuntimeContextProvider.java
----------------------------------------------------------------------
diff --git a/sandbox/environment/src/main/java/org/apache/tamaya/environment/RuntimeContextProvider.java b/sandbox/environment/src/main/java/org/apache/tamaya/environment/RuntimeContextProvider.java
new file mode 100644
index 0000000..dcd6cf2
--- /dev/null
+++ b/sandbox/environment/src/main/java/org/apache/tamaya/environment/RuntimeContextProvider.java
@@ -0,0 +1,59 @@
+/*
+ * 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.spi.ServiceContext;
+
+import java.util.Map;
+
+/**
+ * Singleton accessor to the current {@link org.apache.tamaya.metamodel.environment.RuntimeContext}.
+ */
+public final class RuntimeContextProvider {
+
+ private static final ContextSpi contextSpi = loadSpi();
+
+ private static ContextSpi loadSpi(){
+ return ServiceContext.getInstance().getSingleton(org.apache.tamaya.environment.spi.ContextSpi.class);
+ }
+
+ /**
+ * 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();
+ }
+
+ /**
+ * 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 root(){
+ return contextSpi.getRootContext();
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/46ede97c/sandbox/environment/src/main/java/org/apache/tamaya/environment/internal/ClassLoaderDependentApplicationEnvironmentProvider.java
----------------------------------------------------------------------
diff --git a/sandbox/environment/src/main/java/org/apache/tamaya/environment/internal/ClassLoaderDependentApplicationEnvironmentProvider.java b/sandbox/environment/src/main/java/org/apache/tamaya/environment/internal/ClassLoaderDependentApplicationEnvironmentProvider.java
new file mode 100644
index 0000000..cc9034e
--- /dev/null
+++ b/sandbox/environment/src/main/java/org/apache/tamaya/environment/internal/ClassLoaderDependentApplicationEnvironmentProvider.java
@@ -0,0 +1,102 @@
+/*
+ * 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.internal;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import org.apache.tamaya.core.config.ConfigurationFormats;
+import org.apache.tamaya.core.resource.Resource;
+import org.apache.tamaya.core.resource.ResourceLoader;
+import org.apache.tamaya.core.properties.ConfigurationFormat;
+import org.apache.tamaya.environment.spi.ContextDataProvider;
+import org.apache.tamaya.metamodel.environment.spi.EnvironmentProvider;
+import org.apache.tamaya.spi.ServiceContext;
+
+/**
+ * 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.metamodel.environment.RuntimeContext} instance
+ * is created and attached.
+ */
+public class ClassLoaderDependentApplicationEnvironmentProvider implements ContextDataProvider {
+
+ private static final Logger LOG = Logger.getLogger(ClassLoaderDependentApplicationEnvironmentProvider.class.getName());
+
+ private Map<ClassLoader, Map<String,String>> contexts = new ConcurrentHashMap<>();
+ private Map<ClassLoader, Boolean> contextsAvailable = new ConcurrentHashMap<>();
+
+ @Override
+ public boolean isActive() {
+ ClassLoader cl = Thread.currentThread().getContextClassLoader();
+ if(cl==null){
+ return false;
+ }
+ Boolean available = this.contextsAvailable.get(cl);
+ if(available!=null && !available){
+ return false;
+ }
+ List<Resource> propertyUris = ServiceContext.getInstance().getSingleton(ResourceLoader.class).getResources(cl,
+ "classpath:META-INF/context/application.properties", "classpath:META-INF/context/application.xml", "classpath:META-INF/context/application.ini");
+ available = !propertyUris.isEmpty();
+ this.contextsAvailable.put(cl, available);
+ return available;
+ }
+
+ @Override
+ public Map<String,String> getEnvironmentData() {
+ ClassLoader cl = Thread.currentThread().getContextClassLoader();
+ if(cl==null){
+ return null;
+ }
+ Map<String,String> data = this.contexts.get(cl);
+ if(data!=null){
+ return data;
+ }
+ List<Resource> propertyUris = ServiceContext.getInstance().getSingleton(ResourceLoader.class).getResources(cl,
+ "classpath:META-INF/context/application.properties", "classpath:META-INF/context/application.xml", "classpath:META-INF/context/application.ini");
+ data = new HashMap<>();
+
+ for(Resource resource:propertyUris){
+ try{
+ ConfigurationFormat format = ConfigurationFormats.getFormat(resource);
+ data.putAll(format.readConfiguration(resource));
+ }
+ 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<Resource> uris = new HashSet<>();
+ uris.addAll(propertyUris);
+ data.put("context.sources", uris.toString());
+ data = Collections.unmodifiableMap(data);
+ this.contexts.put(cl, data);
+ return data;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/46ede97c/sandbox/environment/src/main/java/org/apache/tamaya/environment/internal/ClassLoaderDependentEarEnvironmentProvider.java
----------------------------------------------------------------------
diff --git a/sandbox/environment/src/main/java/org/apache/tamaya/environment/internal/ClassLoaderDependentEarEnvironmentProvider.java b/sandbox/environment/src/main/java/org/apache/tamaya/environment/internal/ClassLoaderDependentEarEnvironmentProvider.java
new file mode 100644
index 0000000..6b999cc
--- /dev/null
+++ b/sandbox/environment/src/main/java/org/apache/tamaya/environment/internal/ClassLoaderDependentEarEnvironmentProvider.java
@@ -0,0 +1,108 @@
+/*
+ * 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.internal;
+
+import org.apache.tamaya.core.config.ConfigurationFormats;
+import org.apache.tamaya.core.resource.Resource;
+import org.apache.tamaya.metamodel.environment.RuntimeContextBuilder;
+import org.apache.tamaya.metamodel.environment.spi.EnvironmentProvider;
+import org.apache.tamaya.spi.ServiceContext;
+import org.apache.tamaya.core.properties.ConfigurationFormat;
+import org.apache.tamaya.core.resource.ResourceLoader;
+
+
+import java.util.*;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * This class implements a {@link EnvironmentProvider} 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.metamodel.environment.RuntimeContext}
+ * is created and attached to the corresponding ear classloader.
+ */
+public class ClassLoaderDependentEarEnvironmentProvider implements EnvironmentProvider {
+
+ private static final Logger LOG = Logger.getLogger(ClassLoaderDependentEarEnvironmentProvider.class.getName());
+
+// private static final String EARID_PROP = "environment.earId";
+
+ private Map<ClassLoader, Map<String,String>> contexts = new ConcurrentHashMap<>();
+ private Map<ClassLoader, Boolean> contextsAvailable = new ConcurrentHashMap<>();
+
+ @Override
+ public boolean isActive() {
+ ClassLoader cl = Thread.currentThread().getContextClassLoader();
+ if(cl==null){
+ return false;
+ }
+ Boolean available = this.contextsAvailable.get(cl);
+ if(available!=null && !available){
+ return false;
+ }
+ List<Resource> propertyUris = ServiceContext.getInstance().getSingleton(ResourceLoader.class).getResources(cl,
+ "classpath:META-INF/context/ear.properties", "classpath:META-INF/context/ear.xml", "classpath:META-INF/context/ear.ini");
+ available = !propertyUris.isEmpty();
+ this.contextsAvailable.put(cl, available);
+ return available;
+ }
+
+ @Override
+ public Map<String,String> getEnvironmentData() {
+ ClassLoader cl = Thread.currentThread().getContextClassLoader();
+ if(cl==null){
+ return null;
+ }
+ Map<String,String> data = this.contexts.get(cl);
+ if(data!=null){
+ return data;
+ }
+ List<Resource> resources = ServiceContext.getInstance().getSingleton(ResourceLoader.class).getResources(cl,
+ "classpath:META-INF/context/ear.properties", "classpath:META-INF/context/ear.xml", "classpath:META-INF/context/ear.ini");
+ data = new HashMap<>();
+ for(Resource resource:resources){
+ try{
+ ConfigurationFormat format = ConfigurationFormats.getFormat(resource);
+ Map<String,String> read = format.readConfiguration(resource);
+ data.putAll(read);
+ }
+ catch(Exception e){
+ LOG.log(Level.SEVERE, e, () -> "Error reading ear context data fromMap " + resource);
+ }
+ }
+// String earId = data.getOrDefault(EARID_PROP, cl.toString());
+ String stageValue = data.get(RuntimeContextBuilder.STAGE_PROP);
+ if (stageValue != null) {
+ data.put(RuntimeContextBuilder.STAGE_PROP,stageValue);
+ }
+ data.put("classloader.type", cl.getClass().getName());
+ data.put("classloader.info", cl.toString());
+ Set<Resource> resourceSet = new HashSet<>();
+ resourceSet.addAll(resources);
+ data.put("context.sources", resourceSet.toString());
+ data = Collections.unmodifiableMap(data);
+ this.contexts.put(cl, data);
+ return data;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/46ede97c/sandbox/environment/src/main/java/org/apache/tamaya/environment/internal/InitialEnvironmentProvider.java
----------------------------------------------------------------------
diff --git a/sandbox/environment/src/main/java/org/apache/tamaya/environment/internal/InitialEnvironmentProvider.java b/sandbox/environment/src/main/java/org/apache/tamaya/environment/internal/InitialEnvironmentProvider.java
new file mode 100644
index 0000000..bf97d9c
--- /dev/null
+++ b/sandbox/environment/src/main/java/org/apache/tamaya/environment/internal/InitialEnvironmentProvider.java
@@ -0,0 +1,75 @@
+/*
+ * 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.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.Properties;
+import java.util.TimeZone;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import org.apache.tamaya.core.env.ConfiguredSystemProperties;
+import org.apache.tamaya.environment.spi.ContextDataProvider;
+import org.apache.tamaya.metamodel.environment.RuntimeContextBuilder;
+import org.apache.tamaya.metamodel.environment.spi.EnvironmentProvider;
+
+/**
+ * Default {@link org.apache.tamaya.metamodel.environment.RuntimeContext}.
+ */
+public final class InitialEnvironmentProvider implements ContextDataProvider{
+
+ private Map<String,String> contextData = new HashMap<>();
+
+ public InitialEnvironmentProvider() {
+ Properties props = System.getProperties();
+ if(props instanceof ConfiguredSystemProperties){
+ props = ((ConfiguredSystemProperties)props).getInitialProperties();
+ }
+ String stageValue = props.getProperty(RuntimeContextBuilder.STAGE_PROP);
+ contextData.put(RuntimeContextBuilder.STAGE_PROP, stageValue);
+ contextData.put("timezone", TimeZone.getDefault().getID());
+ contextData.put("locale", Locale.getDefault().toString());
+ try {
+ contextData.put("host", InetAddress.getLocalHost().toString());
+ } catch (Exception e) {
+ Logger.getLogger(getClass().getName()).log(Level.WARNING, e, () -> "Failed to evaluate hostname.");
+ }
+ // Copy env properties....
+ for (Entry<String, String> en : System.getenv().entrySet()) {
+ contextData.put(en.getKey(), en.getValue());
+ }
+ contextData = Collections.unmodifiableMap(contextData);
+ }
+
+ @Override
+ public boolean isActive(){
+ return true;
+ }
+
+ @Override
+ public Map<String,String> getContextData() {
+ return contextData;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/46ede97c/sandbox/environment/src/main/java/org/apache/tamaya/environment/internal/SingleEnvironmentManager.java
----------------------------------------------------------------------
diff --git a/sandbox/environment/src/main/java/org/apache/tamaya/environment/internal/SingleEnvironmentManager.java b/sandbox/environment/src/main/java/org/apache/tamaya/environment/internal/SingleEnvironmentManager.java
new file mode 100644
index 0000000..fb636c7
--- /dev/null
+++ b/sandbox/environment/src/main/java/org/apache/tamaya/environment/internal/SingleEnvironmentManager.java
@@ -0,0 +1,69 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tamaya.metamodel.environment.internal;
+
+
+import org.apache.tamaya.metamodel.environment.RuntimeContext;
+import org.apache.tamaya.metamodel.environment.RuntimeContextBuilder;
+import org.apache.tamaya.metamodel.environment.spi.EnvironmentProvider;
+import org.apache.tamaya.spi.ServiceContext;
+
+import java.util.*;
+
+/**
+ * Service for accessing {@link org.apache.tamaya.metamodel.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.metamodel.environment.spi.ContextSpi {
+
+ private final List<EnvironmentProvider> environmentProviders = loadEnvironmentProviders();
+ private RuntimeContext rootEnvironment = getCurrentEnvironment();
+
+ private List<EnvironmentProvider> loadEnvironmentProviders() {
+ List<EnvironmentProvider> providerList = new ArrayList<>();
+ for(EnvironmentProvider prov: ServiceContext.getInstance().getServices(EnvironmentProvider.class)){
+ providerList.add(prov);
+ }
+ return providerList;
+ }
+
+ @Override
+ public RuntimeContext getCurrentEnvironment(){
+ RuntimeContextBuilder b = RuntimeContextBuilder.of();
+ for(EnvironmentProvider prov: environmentProviders){
+ if(prov.isActive()){
+ if(prov.isActive()){
+ b.setAll(prov.getEnvironmentData());
+ }
+ }
+ }
+ return b.build();
+ }
+
+ @Override
+ public RuntimeContext getRootEnvironment(){
+ return rootEnvironment;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/46ede97c/sandbox/environment/src/main/java/org/apache/tamaya/environment/internal/SystemClassLoaderEnvironmentProvider.java
----------------------------------------------------------------------
diff --git a/sandbox/environment/src/main/java/org/apache/tamaya/environment/internal/SystemClassLoaderEnvironmentProvider.java b/sandbox/environment/src/main/java/org/apache/tamaya/environment/internal/SystemClassLoaderEnvironmentProvider.java
new file mode 100644
index 0000000..12019a0
--- /dev/null
+++ b/sandbox/environment/src/main/java/org/apache/tamaya/environment/internal/SystemClassLoaderEnvironmentProvider.java
@@ -0,0 +1,75 @@
+/*
+ * 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.internal;
+
+import org.apache.tamaya.core.config.ConfigurationFormats;
+import org.apache.tamaya.core.resource.Resource;
+import org.apache.tamaya.environment.spi.ContextDataProvider;
+import org.apache.tamaya.metamodel.environment.spi.EnvironmentProvider;
+import org.apache.tamaya.spi.ServiceContext;
+import org.apache.tamaya.core.properties.ConfigurationFormat;
+import org.apache.tamaya.core.resource.ResourceLoader;
+
+
+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}.
+ */
+public class SystemClassLoaderEnvironmentProvider implements ContextDataProvider {
+
+ private static final Logger LOG = Logger.getLogger(SystemClassLoaderEnvironmentProvider.class.getName());
+
+ private Map<String,String> data = new HashMap<>();
+
+
+ public SystemClassLoaderEnvironmentProvider(){
+ List<Resource> propertyResources = ServiceContext.getInstance().getSingleton(ResourceLoader.class).getResources(ClassLoader.getSystemClassLoader(),
+ "classpath:META-INF/env/system.properties", "classpath:META-INF/env/system.xml", "classpath:META-INF/env/system.ini");
+ for(Resource resource:propertyResources){
+ try{
+ ConfigurationFormat format = ConfigurationFormats.getFormat(resource);
+ Map<String,String> data = format.readConfiguration(resource);
+ data.putAll(data);
+ }
+ catch(Exception e){
+ LOG.log(Level.INFO, e, () -> "Could not read environment data from " + resource);
+ }
+ }
+ data.put("classloader.type", ClassLoader.getSystemClassLoader().getClass().getName());
+ data.put("classloader.info", ClassLoader.getSystemClassLoader().toString());
+ Set<Resource> resourceSet = new HashSet<>();
+ resourceSet.addAll(propertyResources);
+ data.put("environment.system.sources", resourceSet.toString());
+ this.data = Collections.unmodifiableMap(data);
+ }
+ @Override
+ public boolean isActive() {
+ return true;
+ }
+
+ @Override
+ public Map<String,String> getContextData() {
+ return data;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/46ede97c/sandbox/environment/src/main/java/org/apache/tamaya/environment/spi/ContextDataProvider.java
----------------------------------------------------------------------
diff --git a/sandbox/environment/src/main/java/org/apache/tamaya/environment/spi/ContextDataProvider.java b/sandbox/environment/src/main/java/org/apache/tamaya/environment/spi/ContextDataProvider.java
new file mode 100644
index 0000000..0c6c138
--- /dev/null
+++ b/sandbox/environment/src/main/java/org/apache/tamaya/environment/spi/ContextDataProvider.java
@@ -0,0 +1,7 @@
+package org.apache.tamaya.environment.spi;
+
+/**
+ * Created by Anatole on 04.05.2015.
+ */
+public interface ContextDataProvider {
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/46ede97c/sandbox/environment/src/main/java/org/apache/tamaya/environment/spi/ContextSpi.java
----------------------------------------------------------------------
diff --git a/sandbox/environment/src/main/java/org/apache/tamaya/environment/spi/ContextSpi.java b/sandbox/environment/src/main/java/org/apache/tamaya/environment/spi/ContextSpi.java
new file mode 100644
index 0000000..ef4519a
--- /dev/null
+++ b/sandbox/environment/src/main/java/org/apache/tamaya/environment/spi/ContextSpi.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.metamodel.environment.spi;
+
+
+/**
+ * Service for accessing the current ids that identify a runtime environment. 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 interface ContextSpi {
+
+ /**
+ * Get the current environment id.
+ * @return the corresponding environment id, never null.
+ */
+ RuntimeContext getCurrentContext();
+
+ /**
+ * Get the current root environment id.
+ * @return the corresponding root environment id, never null.
+ */
+ RuntimeContext getRootContext();
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/46ede97c/sandbox/environment/src/test/java/org/apache/tamaya/metamodel/environment/EnvironmentManagerTest.java
----------------------------------------------------------------------
diff --git a/sandbox/environment/src/test/java/org/apache/tamaya/metamodel/environment/EnvironmentManagerTest.java b/sandbox/environment/src/test/java/org/apache/tamaya/metamodel/environment/EnvironmentManagerTest.java
new file mode 100644
index 0000000..958ace6
--- /dev/null
+++ b/sandbox/environment/src/test/java/org/apache/tamaya/metamodel/environment/EnvironmentManagerTest.java
@@ -0,0 +1,66 @@
+/*
+ * 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;
+import org.junit.Test;
+
+
+import static org.junit.Assert.*;
+
+/**
+ * Tests for basic {@link org.apache.tamaya.EnvironmentManager} functionality.
+ * Created by Anatole on 17.10.2014.
+ */
+public class EnvironmentManagerTest {
+
+ @Test
+ public void testGetEnvironment(){
+ RuntimeContext env = RuntimeContext.current();
+ assertNotNull(env);
+ RuntimeContext env2 = RuntimeContext.current();
+ assertNotNull(env2);
+ assertFalse("Current Environments requested in same context are not the same!", env==env2);
+ }
+
+ @Test
+ public void testGetRootEnvironment(){
+ RuntimeContext env = RuntimeContext.root();
+ assertNotNull(env);
+ RuntimeContext env2 = RuntimeContext.root();
+ assertNotNull(env2);
+ assertTrue("Root Environments requested in same context are not the same!", env==env2);
+ }
+
+ @Test
+ public void testRootIsNotCurrentEnvironment(){
+ RuntimeContext env1 = RuntimeContext.root();
+ RuntimeContext env2 = RuntimeContext.current();
+ assertNotNull(env1);
+ assertNotNull(env2);
+ // within this testdata environment these are always the same
+ assertEquals(env1, env2);
+ }
+
+ @Test
+ public void testEnvironmentOverride(){
+ assertEquals(RuntimeContext.root().get("user.country").get(),System.getProperty("user.country"));
+ assertEquals(RuntimeContext.current().get("user.country").get(), System.getProperty("user.country"));
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/46ede97c/sandbox/environment/src/test/java/org/apache/tamaya/metamodel/environment/TestEnvironmentManagerSingleton.java
----------------------------------------------------------------------
diff --git a/sandbox/environment/src/test/java/org/apache/tamaya/metamodel/environment/TestEnvironmentManagerSingleton.java b/sandbox/environment/src/test/java/org/apache/tamaya/metamodel/environment/TestEnvironmentManagerSingleton.java
new file mode 100644
index 0000000..52227c9
--- /dev/null
+++ b/sandbox/environment/src/test/java/org/apache/tamaya/metamodel/environment/TestEnvironmentManagerSingleton.java
@@ -0,0 +1,35 @@
+/*
+ * 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;
+
+/**
+ * Created by Anatole on 12.09.2014.
+ */
+public class TestEnvironmentManagerSingleton implements org.apache.tamaya.metamodel.environment.spi.ContextSpi {
+ @Override
+ public RuntimeContext getCurrentEnvironment(){
+ return null;
+ }
+
+ @Override
+ public RuntimeContext getRootEnvironment(){
+ return null;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/46ede97c/sandbox/environment/src/test/java/org/apache/tamaya/metamodel/environment/TestEnvironmentProvider.java
----------------------------------------------------------------------
diff --git a/sandbox/environment/src/test/java/org/apache/tamaya/metamodel/environment/TestEnvironmentProvider.java b/sandbox/environment/src/test/java/org/apache/tamaya/metamodel/environment/TestEnvironmentProvider.java
new file mode 100644
index 0000000..7524a80
--- /dev/null
+++ b/sandbox/environment/src/test/java/org/apache/tamaya/metamodel/environment/TestEnvironmentProvider.java
@@ -0,0 +1,48 @@
+/*
+ * 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.core.spi.EnvironmentProvider;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * Environment provider used by some tests.
+ */
+public class TestEnvironmentProvider implements EnvironmentProvider {
+ private Map<String, String> data = new HashMap<>();
+
+ public TestEnvironmentProvider(){
+ data.put("user.country", System.getProperty("user.country"));
+ data.put("java.version", System.getProperty("java.version"));
+ data = Collections.unmodifiableMap(data);
+ }
+
+ @Override
+ public boolean isActive() {
+ return true;
+ }
+
+ @Override
+ public Map<String, String> getEnvironmentData() {
+ return data;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/46ede97c/sandbox/environment/src/test/resources/META-INF/services/org.apache.tamaya.environment.spi.ContextSpi
----------------------------------------------------------------------
diff --git a/sandbox/environment/src/test/resources/META-INF/services/org.apache.tamaya.environment.spi.ContextSpi b/sandbox/environment/src/test/resources/META-INF/services/org.apache.tamaya.environment.spi.ContextSpi
new file mode 100644
index 0000000..8915399
--- /dev/null
+++ b/sandbox/environment/src/test/resources/META-INF/services/org.apache.tamaya.environment.spi.ContextSpi
@@ -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.SingleEnvironmentManager
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/46ede97c/sandbox/functions/pom.xml
----------------------------------------------------------------------
diff --git a/sandbox/functions/pom.xml b/sandbox/functions/pom.xml
new file mode 100644
index 0000000..06dd0ed
--- /dev/null
+++ b/sandbox/functions/pom.xml
@@ -0,0 +1,52 @@
+<!--
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements. See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership. The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License. You may obtain a copy current the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied. See the License for the
+specific language governing permissions and limitations
+under the License.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.apache.tamaya.ext</groupId>
+ <artifactId>tamaya-sandbox</artifactId>
+ <version>0.1-incubating-SNAPSHOT</version>
+ <relativePath>..</relativePath>
+ </parent>
+ <artifactId>tamaya-functions</artifactId>
+ <name>Apache Tamaya Common Functional Extensions</name>
+ <packaging>jar</packaging>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.tamaya</groupId>
+ <artifactId>tamaya-api</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <!-- Test scope only, do not create a code dependency! -->
+ <dependency>
+ <groupId>org.apache.tamaya</groupId>
+ <artifactId>tamaya-core</artifactId>
+ <version>${project.version}</version>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ </dependency>
+ </dependencies>
+</project>
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/46ede97c/sandbox/functions/src/main/java/org/apache/tamaya/functions/ConfigurationFunctions.java
----------------------------------------------------------------------
diff --git a/sandbox/functions/src/main/java/org/apache/tamaya/functions/ConfigurationFunctions.java b/sandbox/functions/src/main/java/org/apache/tamaya/functions/ConfigurationFunctions.java
new file mode 100644
index 0000000..1f1c571
--- /dev/null
+++ b/sandbox/functions/src/main/java/org/apache/tamaya/functions/ConfigurationFunctions.java
@@ -0,0 +1,239 @@
+/*
+ * 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.functions;
+
+import org.apache.tamaya.ConfigOperator;
+import org.apache.tamaya.ConfigQuery;
+import org.apache.tamaya.Configuration;
+
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+import java.util.TreeSet;
+import java.util.function.BiPredicate;
+import java.util.function.Function;
+import java.util.function.Predicate;
+import java.util.stream.Collectors;
+
+/**
+ * Accessor that provides useful functions along with configuration.
+ */
+public final class ConfigurationFunctions {
+ /**
+ * Private singleton constructor.
+ */
+ private ConfigurationFunctions() {
+ }
+
+ /**
+ * Creates a ConfigOperator that creates a Configuration containing only keys
+ * that are contained in the given area (non recursive). Hereby
+ * the area key is stripped away fromMap the resulting key.
+ *
+ * @param filter the filter, not null
+ * @return the area configuration, with the areaKey stripped away.
+ */
+ public static ConfigOperator filter(BiPredicate<String, String> filter) {
+ return cfg -> new FilteredConfiguration(cfg, filter, null);
+ }
+
+ /**
+ * Creates a ConfigOperator that creates a Configuration with keys mapped as
+ * defined by the given keyMapper.
+ *
+ * @param keyMapper the keyMapper, not null
+ * @return the area configuration, with the areaKey stripped away.
+ */
+ public static ConfigOperator map(Function<String, String> keyMapper) {
+ return cfg -> new MappedConfiguration(cfg, keyMapper, null);
+ }
+
+
+ /**
+ * Creates a ConfigOperator that creates a Configuration containing only keys
+ * that are contained in the given area (non recursive). Hereby
+ * the area key is stripped away fromMap the resulting key.
+ *
+ * @param areaKey the area key, not null
+ * @return the area configuration, with the areaKey stripped away.
+ */
+ public static ConfigOperator area(String areaKey) {
+ return area(areaKey, true);
+ }
+
+ /**
+ * Creates a ConfigOperator that creates a Configuration containing only keys
+ * that are contained in the given area (non recursive).
+ *
+ * @param areaKey the area key, not null
+ * @param stripKeys if set to true, the area key is stripped away fromMap the resulting key.
+ * @return the area configuration, with the areaKey stripped away.
+ */
+ public static ConfigOperator area(String areaKey, boolean stripKeys) {
+ return config -> {
+ Configuration filtered = new FilteredConfiguration(config,
+ (k,v) -> isKeyInArea(k, areaKey), "area: " + areaKey);
+ if(stripKeys){
+ return new MappedConfiguration(filtered, k -> k.substring(areaKey.length() + 1), "stripped");
+ }
+ return filtered;
+ };
+ }
+
+ /**
+ * Calculates the current area key and compares it with the given key.
+ *
+ * @param key the fully qualified entry key, not null
+ * @param areaKey the area key, not null
+ * @return true, if the entry is exact in this area
+ */
+ public static boolean isKeyInArea(String key, String areaKey) {
+ int lastIndex = key.lastIndexOf('.');
+ String curAreaKey = lastIndex > 0 ? key.substring(0, lastIndex) : "";
+ return curAreaKey.equals(areaKey);
+ }
+
+ /**
+ * Calculates the current area key and compares it with the given area keys.
+ *
+ * @param key the fully qualified entry key, not null
+ * @param areaKeys the area keys, not null
+ * @return true, if the entry is exact in this area
+ */
+ public static boolean isKeyInAreas(String key, String... areaKeys) {
+ for(String areaKey:areaKeys){
+ if(isKeyInArea(key, areaKey)){
+ return true;
+ }
+ }
+ return false;
+ }
+
+ /**
+ * Return a query to evaluate the set with all fully qualifies area names. This method should return the areas as accurate as possible,
+ * but may not provide a complete set of areas that are finally accessible, especially when the underlying storage
+ * does not support key iteration.
+ *
+ * @return s set with all areas, never {@code null}.
+ */
+ public static ConfigQuery<Set<String>> areas() {
+ return config -> {
+ final Set<String> areas = new HashSet<>();
+ config.getProperties().keySet().forEach(s -> {
+ int index = s.lastIndexOf('.');
+ if (index > 0) {
+ areas.add(s.substring(0, index));
+ } else {
+ areas.add("<root>");
+ }
+ });
+ return areas;
+ };
+ }
+
+ /**
+ * Return a query to evaluate the set with all fully qualified area names, containing the transitive closure also including all
+ * subarea names, regardless if properties are accessible or not. This method should return the areas as accurate
+ * as possible, but may not provide a complete set of areas that are finally accessible, especially when the
+ * underlying storage does not support key iteration.
+ *
+ * @return s set with all transitive areas, never {@code null}.
+ */
+ public static ConfigQuery<Set<String>> transitiveAreas() {
+ return config -> {
+ final Set<String> transitiveAreas = new HashSet<>();
+ config.query(areas()).forEach(s -> {
+ int index = s.lastIndexOf('.');
+ if (index < 0) {
+ transitiveAreas.add("<root>");
+ } else {
+ while (index > 0) {
+ s = s.substring(0, index);
+ transitiveAreas.add(s);
+ index = s.lastIndexOf('.');
+ }
+ }
+ });
+ return transitiveAreas;
+ };
+ }
+
+ /**
+ * Return a query to evaluate the set with all fully qualified area names, containing only the
+ * areas that match the predicate and have properties attached. This method should return the areas as accurate as possible,
+ * but may not provide a complete set of areas that are finally accessible, especially when the underlying storage
+ * does not support key iteration.
+ *
+ * @param predicate A predicate to deternine, which areas should be returned, not {@code null}.
+ * @return s set with all areas, never {@code null}.
+ */
+ public static ConfigQuery<Set<String>> areas(final Predicate<String> predicate) {
+ return config ->
+ config.query(areas()).stream().filter(predicate).collect(Collectors.toCollection(TreeSet::new));
+ }
+
+ /**
+ * Return a query to evaluate the set with all fully qualified area names, containing the transitive closure also including all
+ * subarea names, regardless if properties are accessible or not. This method should return the areas as accurate as possible,
+ * but may not provide a complete set of areas that are finally accessible, especially when the underlying storage
+ * does not support key iteration.
+ *
+ * @param predicate A predicate to deternine, which areas should be returned, not {@code null}.
+ * @return s set with all transitive areas, never {@code null}.
+ */
+ public static ConfigQuery<Set<String>> transitiveAreas(Predicate<String> predicate) {
+ return config ->
+ config.query(transitiveAreas()).stream().filter(predicate).collect(Collectors.toCollection(TreeSet::new));
+ }
+
+
+ /**
+ * Creates a ConfigOperator that creates a Configuration containing only keys
+ * that are contained in the given area (recursive). Hereby
+ * the area key is stripped away fromMap the resulting key.
+ *
+ * @param areaKeys the area keys, not null
+ * @return the area configuration, with the areaKey stripped away.
+ */
+ public static ConfigOperator areasRecursive(String... areaKeys) {
+ return areaRecursive(true, areaKeys);
+ }
+
+ /**
+ * Creates a ConfigOperator that creates a Configuration containing only keys
+ * that are contained in the given area (recursive).
+ *
+ * @param areaKeys the area keys, not null
+ * @param stripKeys if set to true, the area key is stripped away fromMap the resulting key.
+ * @return the area configuration, with the areaKey stripped away.
+ */
+ public static ConfigOperator areaRecursive(boolean stripKeys, String... areaKeys) {
+ return config -> {
+ Configuration filtered = new FilteredConfiguration(config,
+ (k,v) -> isKeyInAreas(k, areaKeys), "areas: " + Arrays.toString(areaKeys));
+ if(stripKeys){
+ return new MappedConfiguration(filtered, PropertySourceFunctions::stripAreaKeys, "stripped");
+ }
+ return filtered;
+ };
+ }
+
+
+}