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/21 09:40:30 UTC
[12/15] incubator-tamaya git commit: Made experimental modules
compilable. Moved code from former dormant parts (which is removed now).
Made experimental modules compilable.
Moved code from former dormant parts (which is removed now).
Project: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/commit/9af32c09
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/tree/9af32c09
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/diff/9af32c09
Branch: refs/heads/master
Commit: 9af32c09292ed7331c4373c6f704ee6831a628c8
Parents: 324151d
Author: anatole <an...@apache.org>
Authored: Thu May 21 06:37:47 2015 +0200
Committer: anatole <an...@apache.org>
Committed: Thu May 21 06:37:47 2015 +0200
----------------------------------------------------------------------
.../internal/InitialEnvironmentProvider.java | 44 ++++++++++----------
.../internal/SingleEnvironmentManager.java | 11 +++--
.../tamaya/environment/spi/ContextSpi.java | 4 +-
.../functions/ConfigurationFunctions.java | 1 -
.../tamaya/functions/FilteredConfiguration.java | 18 ++++++++
.../tamaya/functions/MappedConfiguration.java | 18 ++++++++
.../tamaya/functions/MappedPropertySource.java | 28 +++++++++----
.../functions/MetaEnrichedPropertySource.java | 18 ++++++++
.../functions/ValueFilteredPropertySource.java | 28 +++++++++++--
9 files changed, 127 insertions(+), 43 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/9af32c09/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
index bf97d9c..062becc 100644
--- 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
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.apache.tamaya.metamodel.environment.internal;
+package org.apache.tamaya.environment.internal;
import java.net.InetAddress;
import java.util.Collections;
@@ -29,47 +29,45 @@ 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.RuntimeContext;
import org.apache.tamaya.environment.spi.ContextDataProvider;
-import org.apache.tamaya.metamodel.environment.RuntimeContextBuilder;
-import org.apache.tamaya.metamodel.environment.spi.EnvironmentProvider;
+import org.apache.tamaya.environment.RuntimeContextBuilder;
/**
- * Default {@link org.apache.tamaya.metamodel.environment.RuntimeContext}.
+ * Default {@link org.apache.tamaya.environment.RuntimeContext}.
*/
public final class InitialEnvironmentProvider implements ContextDataProvider{
- private Map<String,String> contextData = new HashMap<>();
+ private static final String STAGE_PROP = "env.STAGE";
+ 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....
+ 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 boolean isActive(){
- return true;
- }
@Override
- public Map<String,String> getContextData() {
- return contextData;
- }
-
+ public RuntimeContext getContext(RuntimeContext currentContext) {
+ return RuntimeContextBuilder.of("root").withParentContext(currentContext)
+ .setAll(contextData).build();
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/9af32c09/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
index fb636c7..7ed63b8 100644
--- 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
@@ -16,18 +16,17 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.apache.tamaya.metamodel.environment.internal;
+package org.apache.tamaya.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.environment.RuntimeContext;
+import org.apache.tamaya.environment.RuntimeContextBuilder;
import org.apache.tamaya.spi.ServiceContext;
import java.util.*;
/**
- * Service for accessing {@link org.apache.tamaya.metamodel.environment.RuntimeContext}. Environments are used to
+ * 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>
@@ -35,7 +34,7 @@ import java.util.*;
* <li>and behaves contextual.
* </ul>
*/
-public class SingleEnvironmentManager implements org.apache.tamaya.metamodel.environment.spi.ContextSpi {
+public class SingleEnvironmentManager implements org.apache.tamaya.environment.spi.ContextSpi{
private final List<EnvironmentProvider> environmentProviders = loadEnvironmentProviders();
private RuntimeContext rootEnvironment = getCurrentEnvironment();
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/9af32c09/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
index ef4519a..1651aaa 100644
--- 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
@@ -16,9 +16,11 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.apache.tamaya.metamodel.environment.spi;
+package org.apache.tamaya.environment.spi;
+import org.apache.tamaya.environment.RuntimeContext;
+
/**
* Service for accessing the current ids that identify a runtime environment. Environments are used to
* access/determine configurations.<br/>
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/9af32c09/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
index 1f1c571..9a588fc 100644
--- a/sandbox/functions/src/main/java/org/apache/tamaya/functions/ConfigurationFunctions.java
+++ b/sandbox/functions/src/main/java/org/apache/tamaya/functions/ConfigurationFunctions.java
@@ -24,7 +24,6 @@ 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;
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/9af32c09/sandbox/functions/src/main/java/org/apache/tamaya/functions/FilteredConfiguration.java
----------------------------------------------------------------------
diff --git a/sandbox/functions/src/main/java/org/apache/tamaya/functions/FilteredConfiguration.java b/sandbox/functions/src/main/java/org/apache/tamaya/functions/FilteredConfiguration.java
index 1b731c1..2f92331 100644
--- a/sandbox/functions/src/main/java/org/apache/tamaya/functions/FilteredConfiguration.java
+++ b/sandbox/functions/src/main/java/org/apache/tamaya/functions/FilteredConfiguration.java
@@ -1,3 +1,21 @@
+/*
+ * 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.Configuration;
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/9af32c09/sandbox/functions/src/main/java/org/apache/tamaya/functions/MappedConfiguration.java
----------------------------------------------------------------------
diff --git a/sandbox/functions/src/main/java/org/apache/tamaya/functions/MappedConfiguration.java b/sandbox/functions/src/main/java/org/apache/tamaya/functions/MappedConfiguration.java
index a7af911..df1f43c 100644
--- a/sandbox/functions/src/main/java/org/apache/tamaya/functions/MappedConfiguration.java
+++ b/sandbox/functions/src/main/java/org/apache/tamaya/functions/MappedConfiguration.java
@@ -1,3 +1,21 @@
+/*
+ * 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.Configuration;
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/9af32c09/sandbox/functions/src/main/java/org/apache/tamaya/functions/MappedPropertySource.java
----------------------------------------------------------------------
diff --git a/sandbox/functions/src/main/java/org/apache/tamaya/functions/MappedPropertySource.java b/sandbox/functions/src/main/java/org/apache/tamaya/functions/MappedPropertySource.java
index ae37168..8491fa6 100644
--- a/sandbox/functions/src/main/java/org/apache/tamaya/functions/MappedPropertySource.java
+++ b/sandbox/functions/src/main/java/org/apache/tamaya/functions/MappedPropertySource.java
@@ -1,3 +1,21 @@
+/*
+ * 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.spi.PropertySource;
@@ -5,7 +23,6 @@ import org.apache.tamaya.spi.PropertySource;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
-import java.util.Optional;
import java.util.function.UnaryOperator;
/**
@@ -54,13 +71,8 @@ class MappedPropertySource implements PropertySource {
}
@Override
- public Optional<String> get(String key){
- return Optional.of(getProperties().get(key));
- }
-
- @Override
- public boolean isEmpty() {
- return this.propertySource.isEmpty();
+ public String get(String key){
+ return getProperties().get(key);
}
}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/9af32c09/sandbox/functions/src/main/java/org/apache/tamaya/functions/MetaEnrichedPropertySource.java
----------------------------------------------------------------------
diff --git a/sandbox/functions/src/main/java/org/apache/tamaya/functions/MetaEnrichedPropertySource.java b/sandbox/functions/src/main/java/org/apache/tamaya/functions/MetaEnrichedPropertySource.java
index f43d65e..6ef32c3 100644
--- a/sandbox/functions/src/main/java/org/apache/tamaya/functions/MetaEnrichedPropertySource.java
+++ b/sandbox/functions/src/main/java/org/apache/tamaya/functions/MetaEnrichedPropertySource.java
@@ -1,3 +1,21 @@
+/*
+ * 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.spi.PropertySource;
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/9af32c09/sandbox/functions/src/main/java/org/apache/tamaya/functions/ValueFilteredPropertySource.java
----------------------------------------------------------------------
diff --git a/sandbox/functions/src/main/java/org/apache/tamaya/functions/ValueFilteredPropertySource.java b/sandbox/functions/src/main/java/org/apache/tamaya/functions/ValueFilteredPropertySource.java
index 23a5434..3180b0c 100644
--- a/sandbox/functions/src/main/java/org/apache/tamaya/functions/ValueFilteredPropertySource.java
+++ b/sandbox/functions/src/main/java/org/apache/tamaya/functions/ValueFilteredPropertySource.java
@@ -1,3 +1,21 @@
+/*
+ * 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.spi.PropertySource;
@@ -31,10 +49,12 @@ class ValueFilteredPropertySource implements PropertySource{
}
@Override
- public Optional<String> get(String key) {
- String value = this.source.get(key).orElse(null);
- value = valueFilter.apply(key, value);
- return Optional.ofNullable(value);
+ public String get(String key) {
+ String value = this.source.get(key);
+ if(value!=null) {
+ return valueFilter.apply(key, value);
+ }
+ return null;
}
@Override