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 2016/12/22 21:19:31 UTC
[1/4] incubator-tamaya-sandbox git commit: TAMAYA-210: Added
additional resource location logic. Tested and implemented especially with
OSGI. TAMAYA-148: Further tests with OSGI/Karaf.
Repository: incubator-tamaya-sandbox
Updated Branches:
refs/heads/master 6aa6bb751 -> 9e1cd74c9
TAMAYA-210: Added additional resource location logic. Tested and implemented especially with OSGI.
TAMAYA-148: Further tests with OSGI/Karaf.
Project: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/commit/7b9971d8
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/tree/7b9971d8
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/diff/7b9971d8
Branch: refs/heads/master
Commit: 7b9971d81f98c486fb356bff28eacb23af122706
Parents: 6aa6bb7
Author: anatole <an...@apache.org>
Authored: Wed Dec 21 16:57:48 2016 +0100
Committer: anatole <an...@apache.org>
Committed: Wed Dec 21 16:57:48 2016 +0100
----------------------------------------------------------------------
.../tamaya/osgi/OSGIEnhancedConfiguration.java | 117 -------------------
.../tamaya/osgi/TamayaConfigAdminImpl.java | 30 ++---
.../org/apache/tamaya/osgi/OSGIKarafTest.java | 8 +-
.../src/test/resources/META-INF/OSGIResource | 17 +++
osgi/pom.xml | 28 -----
5 files changed, 32 insertions(+), 168 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/7b9971d8/osgi/common/src/main/java/org/apache/tamaya/osgi/OSGIEnhancedConfiguration.java
----------------------------------------------------------------------
diff --git a/osgi/common/src/main/java/org/apache/tamaya/osgi/OSGIEnhancedConfiguration.java b/osgi/common/src/main/java/org/apache/tamaya/osgi/OSGIEnhancedConfiguration.java
deleted file mode 100644
index 117ae1b..0000000
--- a/osgi/common/src/main/java/org/apache/tamaya/osgi/OSGIEnhancedConfiguration.java
+++ /dev/null
@@ -1,117 +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.osgi;
-//
-//import org.apache.tamaya.spi.PropertySource;
-//import org.apache.tamaya.spisupport.BasePropertySource;
-//import org.apache.tamaya.spisupport.DefaultConfiguration;
-//import org.apache.tamaya.spisupport.DefaultConfigurationContext;
-//
-//import java.util.Dictionary;
-//import java.util.Enumeration;
-//import java.util.HashMap;
-//import java.util.List;
-//import java.util.Map;
-//import java.util.Objects;
-//
-///**
-// * Configuration object that also reflects the values provided by the OSGI ConfigAdmin Configuration.
-// * Similar to other tamaya areas adding a tamaya.ordinal into the corresponding OSGI configuration for
-// * a pif/factoryPid allows to control the ordinal/priority of the OSGI configuration related to other
-// * configured Tamaya Property Sources. Overall the configuration evaluation for Tamaya follows the
-// * same rules, with the difference that each bunldle owns its own ConfigAdmin based part. From
-// * Tamaya, the granularity depends on the implementation of the ConfigurationProviderSpi. By default
-// * Tamaya configuration is managed as a global resource/config tree, wheres bundle specific sections are
-// * selected only.
-// */
-//public class OSGIEnhancedConfiguration extends DefaultConfiguration{
-// /** The default ordinal used for the OSGI config, */
-// private static final int OSGI_DEFAULT_ORDINAL = 0;
-//
-// /**
-// * Constructor.
-// *
-// * @param osgiConfiguration The OSGI configuration found.
-// */
-// public OSGIEnhancedConfiguration(org.osgi.service.cm.Configuration osgiConfiguration) {
-// super(new OSGIConfigurationContext(osgiConfiguration));
-// }
-//
-// /**
-// * Class that models a Tamaya ConfigurationContext, which implicitly contains the bundle specific
-// * Configuration wrapped into a Tamaya PropertySource.
-// */
-// private static final class OSGIConfigurationContext extends DefaultConfigurationContext{
-// private OSGIPropertySource osgiPropertySource;
-//
-// public OSGIConfigurationContext(org.osgi.service.cm.Configuration osgiConfiguration){
-// if(osgiConfiguration!=null) {
-// this.osgiPropertySource = new OSGIPropertySource(osgiConfiguration);
-// }
-// }
-//
-// @Override
-// public List<PropertySource> getPropertySources() {
-// List<PropertySource> sources = super.getPropertySources();
-// if(osgiPropertySource!=null){
-// sources.add(osgiPropertySource);
-// }
-// return sources;
-// }
-// }
-//
-// /**
-// * Tamaya PropertySource providing the values from an OSGI Configuration.
-// */
-// private static final class OSGIPropertySource extends BasePropertySource{
-//
-// private final org.osgi.service.cm.Configuration osgiConfiguration;
-//
-// public OSGIPropertySource(org.osgi.service.cm.Configuration osgiConfiguration){
-// this.osgiConfiguration = Objects.requireNonNull(osgiConfiguration);
-// }
-//
-// @Override
-// public int getDefaultOrdinal() {
-// String val = System.getProperty("osgi.defaultOrdinal");
-// if(val!=null){
-// return Integer.parseInt(val.trim());
-// }
-// return OSGI_DEFAULT_ORDINAL;
-// }
-//
-// @Override
-// public String getName() {
-// return "OSGIConfig:pid="+
-// (osgiConfiguration.getPid()!=null?osgiConfiguration.getPid():osgiConfiguration.getFactoryPid());
-// }
-//
-// @Override
-// public Map<String, String> getProperties() {
-// Map<String, String> map = new HashMap<>();
-// Dictionary<String,Object> dict = osgiConfiguration.getProperties();
-// Enumeration<String> keys = dict.keys();
-// while(keys.hasMoreElements()){
-// String key = keys.nextElement();
-// map.put(key,String.valueOf(dict.get(key)));
-// }
-// return map;
-// }
-// }
-//}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/7b9971d8/osgi/common/src/main/java/org/apache/tamaya/osgi/TamayaConfigAdminImpl.java
----------------------------------------------------------------------
diff --git a/osgi/common/src/main/java/org/apache/tamaya/osgi/TamayaConfigAdminImpl.java b/osgi/common/src/main/java/org/apache/tamaya/osgi/TamayaConfigAdminImpl.java
index 047cfb3..d9ba1bf 100644
--- a/osgi/common/src/main/java/org/apache/tamaya/osgi/TamayaConfigAdminImpl.java
+++ b/osgi/common/src/main/java/org/apache/tamaya/osgi/TamayaConfigAdminImpl.java
@@ -19,6 +19,7 @@
package org.apache.tamaya.osgi;
import java.io.IOException;
+import java.lang.ref.WeakReference;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.logging.Level;
@@ -43,7 +44,7 @@ public class TamayaConfigAdminImpl implements ConfigurationAdmin {
/** THe optional OSGI parent service. */
private ConfigurationAdmin parent;
/** The cached configurations. */
- private Map<String,Configuration> configs = new WeakHashMap<>();
+ private Map<String,Configuration> configs = new ConcurrentHashMap<>();
/** The configuration section mapper. */
private OSGIConfigRootMapper configRootMapper;
@@ -68,7 +69,7 @@ public class TamayaConfigAdminImpl implements ConfigurationAdmin {
key += "::"+location;
}
Configuration config = this.configs.get(key);
- if(config==null) {
+ if (config == null) {
Dictionary<String, Object> parentConfig = getParentConfig(null, factoryPid, location);
config = new TamayaOSGIConfiguration(null, factoryPid, configRootMapper, parentConfig);
this.configs.put(key, config);
@@ -82,8 +83,8 @@ public class TamayaConfigAdminImpl implements ConfigurationAdmin {
if(location!=null){
key += "::"+location;
}
- Configuration config = this.configs.get(key);
- if(config==null) {
+ Configuration config = this.configs.get(key);
+ if (config == null) {
Dictionary<String, Object> parentConfig = getParentConfig(pid, null, location);
config = new TamayaOSGIConfiguration(pid, null, configRootMapper, parentConfig);
this.configs.put(key, config);
@@ -120,25 +121,18 @@ public class TamayaConfigAdminImpl implements ConfigurationAdmin {
@Override
public Configuration[] listConfigurations(String filter) throws IOException, InvalidSyntaxException {
- Collection<Configuration> result;
- if (filter == null) {
- result = this.configs.values();
+ List<Configuration> result = new ArrayList<>();
+ if (filter == null || context == null) {
+ return this.configs.values().toArray(new Configuration[this.configs.size()]);
} else {
- result = new ArrayList<>();
- if(context==null){
- for (Configuration config : this.configs.values()) {
+ Filter flt = context.createFilter(filter);
+ for(Configuration config:this.configs.values()) {
+ if (flt.match(config.getProperties())) {
result.add(config);
}
- }else {
- Filter flt = context.createFilter(filter);
- for (Configuration config : this.configs.values()) {
- if (flt.match(config.getProperties())) {
- result.add(config);
- }
- }
}
+ return result.toArray(new Configuration[result.size()]);
}
- return result.toArray(new Configuration[configs.size()]);
}
/**
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/7b9971d8/osgi/features/src/test/java/org/apache/tamaya/osgi/OSGIKarafTest.java
----------------------------------------------------------------------
diff --git a/osgi/features/src/test/java/org/apache/tamaya/osgi/OSGIKarafTest.java b/osgi/features/src/test/java/org/apache/tamaya/osgi/OSGIKarafTest.java
index 28936ea..c0c3880 100644
--- a/osgi/features/src/test/java/org/apache/tamaya/osgi/OSGIKarafTest.java
+++ b/osgi/features/src/test/java/org/apache/tamaya/osgi/OSGIKarafTest.java
@@ -74,7 +74,6 @@ public class OSGIKarafTest {
.classifier("features")
.version("0.3-incubating-SNAPSHOT");
return options(
- // distribution to test: Karaf 3.0.3
KarafDistributionOption.karafDistributionConfiguration()
.frameworkUrl(CoreOptions.maven()
.groupId("org.apache.karaf")
@@ -85,8 +84,9 @@ public class OSGIKarafTest {
.name("ApacheKaraf")
.useDeployFolder(false)
.unpackDirectory(new File("target/karaf")),
- // no local and remote consoles
-// KarafDistributionOption.debugConfiguration("5005", true),
+ // if activated, the remote karaf instance will stop and wait for
+ // debugger to connect to.
+// KarafDistributionOption.debugConfiguration("5006", true),
KarafDistributionOption.configureConsole().ignoreLocalConsole(),
KarafDistributionOption.configureConsole().ignoreRemoteShell(),
// keep runtime folder allowing analysing results
@@ -105,7 +105,6 @@ public class OSGIKarafTest {
karafStandardRepo, "scr"),
KarafDistributionOption.features(
tamayaRepo, "tamaya-osgi-features/0.3.0.incubating-SNAPSHOT"),
-// bundle("reference:file:target/test-classes"),
junitBundles()
);
}
@@ -140,7 +139,6 @@ public class OSGIKarafTest {
}
@Test
- @Ignore
public void getConfiguration() throws Exception {
ConfigurationAdmin configAdmin = getConfigAdmin();
org.osgi.service.cm.Configuration config = configAdmin.getConfiguration("tamaya");
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/7b9971d8/osgi/features/src/test/resources/META-INF/OSGIResource
----------------------------------------------------------------------
diff --git a/osgi/features/src/test/resources/META-INF/OSGIResource b/osgi/features/src/test/resources/META-INF/OSGIResource
new file mode 100644
index 0000000..20989a6
--- /dev/null
+++ b/osgi/features/src/test/resources/META-INF/OSGIResource
@@ -0,0 +1,17 @@
+# 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.
+#
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/7b9971d8/osgi/pom.xml
----------------------------------------------------------------------
diff --git a/osgi/pom.xml b/osgi/pom.xml
index 0d3f859..9070c5b 100644
--- a/osgi/pom.xml
+++ b/osgi/pom.xml
@@ -39,34 +39,6 @@
<pax.exam.version>4.5.0</pax.exam.version>
</properties>
- <dependencies>
- <dependency>
- <groupId>org.apache.geronimo.specs</groupId>
- <artifactId>geronimo-atinject_1.0_spec</artifactId>
- <version>1.0</version>
- </dependency>
- <dependency>
- <groupId>org.apache.tamaya</groupId>
- <artifactId>tamaya-api</artifactId>
- <version>${project.version}</version>
- </dependency>
- <dependency>
- <groupId>org.apache.tamaya</groupId>
- <artifactId>tamaya-core</artifactId>
- <version>${project.version}</version>
- </dependency>
- <dependency>
- <groupId>org.apache.tamaya.ext</groupId>
- <artifactId>tamaya-functions</artifactId>
- <version>${project.version}</version>
- </dependency>
- <dependency>
- <groupId>org.apache.tamaya.ext</groupId>
- <artifactId>tamaya-spisupport</artifactId>
- <version>${project.version}</version>
- </dependency>
- </dependencies>
-
<modules>
<module>common</module>
<module>features</module>
[4/4] incubator-tamaya-sandbox git commit: TAMAYA-212: Rendered
default comparators into singletons.
Posted by an...@apache.org.
TAMAYA-212: Rendered default comparators into singletons.
Project: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/commit/9e1cd74c
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/tree/9e1cd74c
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/diff/9e1cd74c
Branch: refs/heads/master
Commit: 9e1cd74c93eec37eddb25d492e6a471853e8ff20
Parents: a144252
Author: anatole <an...@apache.org>
Authored: Thu Dec 22 22:18:27 2016 +0100
Committer: anatole <an...@apache.org>
Committed: Thu Dec 22 22:18:27 2016 +0100
----------------------------------------------------------------------
.../internal/DSLLoadingConfigurationProviderSpi.java | 14 ++++++++------
1 file changed, 8 insertions(+), 6 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/9e1cd74c/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/DSLLoadingConfigurationProviderSpi.java
----------------------------------------------------------------------
diff --git a/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/DSLLoadingConfigurationProviderSpi.java b/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/DSLLoadingConfigurationProviderSpi.java
index 47ce7f0..b6247c5 100644
--- a/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/DSLLoadingConfigurationProviderSpi.java
+++ b/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/DSLLoadingConfigurationProviderSpi.java
@@ -19,13 +19,17 @@
package org.apache.tamaya.metamodel.internal;
import org.apache.tamaya.metamodel.MetaConfiguration;
-import org.apache.tamaya.spi.*;
import org.apache.tamaya.Configuration;
+import org.apache.tamaya.spi.ConfigurationContext;
+import org.apache.tamaya.spi.ConfigurationContextBuilder;
+import org.apache.tamaya.spi.ConfigurationProviderSpi;
+import org.apache.tamaya.spi.ServiceContextManager;
import org.apache.tamaya.spisupport.DefaultConfiguration;
import org.apache.tamaya.spisupport.DefaultConfigurationContextBuilder;
+import org.apache.tamaya.spisupport.PropertyFilterComparator;
+import org.apache.tamaya.spisupport.PropertySourceComparator;
import javax.annotation.Priority;
-import java.util.Comparator;
import java.util.Objects;
/**
@@ -93,10 +97,8 @@ public class DSLLoadingConfigurationProviderSpi implements ConfigurationProvider
.addDefaultPropertyConverters()
.addDefaultPropertyFilters()
.addDefaultPropertySources()
- .sortPropertyFilter(
- (Comparator<PropertyFilter>)
- DefaultConfigurationContextBuilder.DEFAULT_PROPERTYFILTER_COMPARATOR)
- .sortPropertySources(DefaultConfigurationContextBuilder.DEFAULT_PROPERTYSOURCE_COMPARATOR)
+ .sortPropertyFilter(PropertyFilterComparator.getInstance())
+ .sortPropertySources(PropertySourceComparator.getInstance())
.build());
}
}
[3/4] incubator-tamaya-sandbox git commit: TAMAYA-145: Fixed tests
for basic OSGI support of the core functionality.
Posted by an...@apache.org.
TAMAYA-145: Fixed tests for basic OSGI support of the core functionality.
Project: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/commit/a144252f
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/tree/a144252f
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/diff/a144252f
Branch: refs/heads/master
Commit: a144252f06417ce34e31f90f799d7b86e3e01a99
Parents: 20c558d
Author: anatole <an...@apache.org>
Authored: Thu Dec 22 22:02:46 2016 +0100
Committer: anatole <an...@apache.org>
Committed: Thu Dec 22 22:02:46 2016 +0100
----------------------------------------------------------------------
.../org/apache/tamaya/osgi/OSGIKarafTest.java | 23 +++++++++++++++++++-
1 file changed, 22 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/a144252f/osgi/features/src/test/java/org/apache/tamaya/osgi/OSGIKarafTest.java
----------------------------------------------------------------------
diff --git a/osgi/features/src/test/java/org/apache/tamaya/osgi/OSGIKarafTest.java b/osgi/features/src/test/java/org/apache/tamaya/osgi/OSGIKarafTest.java
index c0c3880..236913c 100644
--- a/osgi/features/src/test/java/org/apache/tamaya/osgi/OSGIKarafTest.java
+++ b/osgi/features/src/test/java/org/apache/tamaya/osgi/OSGIKarafTest.java
@@ -20,6 +20,7 @@ package org.apache.tamaya.osgi;
import org.apache.karaf.features.Feature;
import org.apache.karaf.features.FeaturesService;
+import org.apache.tamaya.spi.ServiceContextManager;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
@@ -33,6 +34,7 @@ import org.ops4j.pax.exam.karaf.options.KarafDistributionOption;
import org.ops4j.pax.exam.options.BootClasspathLibraryOption;
import org.ops4j.pax.exam.options.MavenUrlReference;
import org.ops4j.pax.exam.spi.reactors.ExamReactorStrategy;
+import org.ops4j.pax.exam.spi.reactors.PerClass;
import org.ops4j.pax.exam.spi.reactors.PerMethod;
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceReference;
@@ -43,6 +45,9 @@ import javax.inject.Inject;
import javax.swing.*;
import java.awt.*;
import java.io.File;
+import java.io.IOException;
+import java.net.URL;
+import java.util.Enumeration;
import static org.junit.Assert.*;
import static org.junit.Assert.assertEquals;
@@ -152,7 +157,7 @@ public class OSGIKarafTest {
assertEquals(config.getProperties().get("my.testProperty4"), "success4");
StringBuilder b = new StringBuilder();
b.append("Print all configs....\n\n");
- org.osgi.service.cm.Configuration[] configs = configAdmin.listConfigurations("*");
+ org.osgi.service.cm.Configuration[] configs = configAdmin.listConfigurations(null);
for (org.osgi.service.cm.Configuration cfg : configs) {
b.append("\nConfiguration found in Karaf OSGI Container: " + cfg);
b.append("\n-------------------------------------------------");
@@ -160,6 +165,22 @@ public class OSGIKarafTest {
System.out.println(b.toString());
}
+ @Test
+ public void testResourceIsVisible(){
+ assertNotNull(ServiceContextManager.getServiceContext()
+ .getResource("META-INF/javaconfiguration.properties", null));
+ }
+
+ @Test
+ public void testResourcesAreVisible() throws IOException {
+ Enumeration<URL> urls = ServiceContextManager.getServiceContext()
+ .getResources("META-INF/javaconfiguration.properties", null);
+ assertNotNull(urls);
+ assertTrue(urls.hasMoreElements());
+ URL url = urls.nextElement();
+ assertNotNull(url);
+ }
+
public ConfigurationAdmin getConfigAdmin() {
return bundleContext.getService(bundleContext.getServiceReference(ConfigurationAdmin.class));
}
[2/4] incubator-tamaya-sandbox git commit: TAMAYA-145: Added support
for Refreshable and property source level filtering.
Posted by an...@apache.org.
TAMAYA-145: Added support for Refreshable and property source level filtering.
Project: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/commit/20c558d0
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/tree/20c558d0
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/diff/20c558d0
Branch: refs/heads/master
Commit: 20c558d0771a07da54fe26a9a8f28b80cb06014e
Parents: 7b9971d
Author: anatole <an...@apache.org>
Authored: Wed Dec 21 16:58:40 2016 +0100
Committer: anatole <an...@apache.org>
Committed: Wed Dec 21 16:58:40 2016 +0100
----------------------------------------------------------------------
.../org/apache/tamaya/metamodel/Enabled.java | 37 +++++
.../tamaya/metamodel/EnabledPropertySource.java | 135 +++++++++++++++++++
.../EnabledPropertySourceProvider.java | 112 +++++++++++++++
.../apache/tamaya/metamodel/MetaContext.java | 10 ++
.../metamodel/internal/ContextReader.java | 4 +-
.../DSLLoadingConfigurationProviderSpi.java | 10 +-
.../internal/PropertySourceReader.java | 78 +++++++++++
7 files changed, 375 insertions(+), 11 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/20c558d0/metamodel/src/main/java/org/apache/tamaya/metamodel/Enabled.java
----------------------------------------------------------------------
diff --git a/metamodel/src/main/java/org/apache/tamaya/metamodel/Enabled.java b/metamodel/src/main/java/org/apache/tamaya/metamodel/Enabled.java
new file mode 100644
index 0000000..b3051d3
--- /dev/null
+++ b/metamodel/src/main/java/org/apache/tamaya/metamodel/Enabled.java
@@ -0,0 +1,37 @@
+/*
+ * 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;
+
+/**
+ * Common interface for items that can be enabled or disabled.
+ */
+public interface Enabled {
+
+ /**
+ * Returns the enabled property.
+ * @return the enabled value.
+ */
+ boolean isEnabled();
+
+ /**
+ * Enables/disables this property source.
+ * @param enabled the enabled value.
+ */
+ void setEnabled(boolean enabled);
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/20c558d0/metamodel/src/main/java/org/apache/tamaya/metamodel/EnabledPropertySource.java
----------------------------------------------------------------------
diff --git a/metamodel/src/main/java/org/apache/tamaya/metamodel/EnabledPropertySource.java b/metamodel/src/main/java/org/apache/tamaya/metamodel/EnabledPropertySource.java
new file mode 100644
index 0000000..e231930
--- /dev/null
+++ b/metamodel/src/main/java/org/apache/tamaya/metamodel/EnabledPropertySource.java
@@ -0,0 +1,135 @@
+/*
+ * 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;
+
+import org.apache.tamaya.spi.PropertySource;
+import org.apache.tamaya.spi.PropertyValue;
+
+import javax.script.ScriptEngine;
+import javax.script.ScriptEngineManager;
+import javax.script.ScriptException;
+import java.util.Collections;
+import java.util.Map;
+import java.util.Objects;
+import java.util.logging.Logger;
+
+
+/**
+ * Wrapped property source that allows enabling a property source using an
+ * {@code enabled} expression.
+ */
+public final class EnabledPropertySource
+ implements PropertySource, Enabled {
+
+ private static final Logger LOG = Logger.getLogger(EnabledPropertySource.class.getName());
+ private String enabledExpression;
+ private PropertySource wrapped;
+ private boolean enabled;
+
+ public EnabledPropertySource(PropertySource wrapped, Map<String,String> context, String expression) {
+ this.enabledExpression = Objects.requireNonNull(expression);
+ this.wrapped = Objects.requireNonNull(wrapped);
+ this.enabled = calculateEnabled(context);
+ }
+
+ protected boolean calculateEnabled(Map<String, String> context) {
+ try {
+ ScriptEngineManager manager = new ScriptEngineManager();
+ ScriptEngine engine = manager.getEngineByName("nashorn");
+ if(engine==null){
+ engine = manager.getEngineByName("rhino");
+ }
+ // init script engine
+ for(Map.Entry<String,String> entry: context.entrySet()) {
+ engine.put(entry.getKey(), entry.getValue());
+ }
+ Object o = engine.eval(enabledExpression);
+ if(!(o instanceof Boolean)){
+ LOG.severe("Enabled expression must evaluate to Boolean: '"
+ +enabledExpression+"', but was " + o +
+ ", property source will be disabled: " +
+ wrapped.getName());
+ return false;
+ }
+ return (Boolean)o;
+ } catch (ScriptException e) {
+ LOG.severe("Invalid Boolean expression: '"
+ +enabledExpression+"': " + e + ", property source will be disabled: " +
+ wrapped.getName());
+ }
+ return false;
+ }
+
+ /**
+ * Returns the enabled property.
+ * @return the enabled value.
+ */
+ @Override
+ public boolean isEnabled(){
+ return enabled;
+ }
+
+ /**
+ * Enables/disables this property source.
+ * @param enabled the enabled value.
+ */
+ @Override
+ public void setEnabled(boolean enabled){
+ this.enabled = enabled;
+ }
+
+ @Override
+ public int getOrdinal() {
+ return this.wrapped.getOrdinal();
+ }
+
+ @Override
+ public String getName() {
+ return this.wrapped.getName();
+ }
+
+ @Override
+ public PropertyValue get(String key) {
+ if(!isEnabled()){
+ return null;
+ }
+ return this.wrapped.get(key);
+ }
+
+ @Override
+ public Map<String, String> getProperties() {
+ if(!isEnabled()){
+ return Collections.emptyMap();
+ }
+ return this.wrapped.getProperties();
+ }
+
+ @Override
+ public boolean isScannable() {
+ return this.wrapped.isScannable();
+ }
+
+ @Override
+ public String toString() {
+ return "DynamicPropertySource{" +
+ "\n enabled=" + enabledExpression +
+ "\n wrapped=" + wrapped +
+ '}';
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/20c558d0/metamodel/src/main/java/org/apache/tamaya/metamodel/EnabledPropertySourceProvider.java
----------------------------------------------------------------------
diff --git a/metamodel/src/main/java/org/apache/tamaya/metamodel/EnabledPropertySourceProvider.java b/metamodel/src/main/java/org/apache/tamaya/metamodel/EnabledPropertySourceProvider.java
new file mode 100644
index 0000000..5dfed10
--- /dev/null
+++ b/metamodel/src/main/java/org/apache/tamaya/metamodel/EnabledPropertySourceProvider.java
@@ -0,0 +1,112 @@
+/*
+ * 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;
+
+import org.apache.tamaya.spi.PropertySource;
+import org.apache.tamaya.spi.PropertySourceProvider;
+
+import javax.script.ScriptEngine;
+import javax.script.ScriptEngineManager;
+import javax.script.ScriptException;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Map;
+import java.util.Objects;
+import java.util.logging.Logger;
+
+/**
+ * Wrapped property source provider that allows enabling a property source using an
+ * {@code enabled} expression.
+ */
+public final class EnabledPropertySourceProvider
+ implements PropertySourceProvider, Enabled {
+
+ private static final Logger LOG = Logger.getLogger(EnabledPropertySourceProvider.class.getName());
+ private String enabledExpression;
+ private PropertySourceProvider wrapped;
+ private boolean enabled;
+
+ public EnabledPropertySourceProvider(PropertySourceProvider wrapped, Map<String,String> context, String expression) {
+ this.enabledExpression = Objects.requireNonNull(expression);
+ this.wrapped = Objects.requireNonNull(wrapped);
+ this.enabled = calculateEnabled(context);
+ }
+
+ protected boolean calculateEnabled(Map<String, String> context) {
+ try {
+ ScriptEngineManager manager = new ScriptEngineManager();
+ ScriptEngine engine = manager.getEngineByName("nashorn");
+ if(engine==null){
+ engine = manager.getEngineByName("rhino");
+ }
+ // init script engine
+ for(Map.Entry<String,String> entry: context.entrySet()) {
+ engine.put(entry.getKey(), entry.getValue());
+ }
+ Object o = engine.eval(enabledExpression);
+ if(!(o instanceof Boolean)){
+ LOG.severe("Enabled expression must evaluate to Boolean: '"
+ +enabledExpression+"', but was " + o +
+ ", property source provider will be disabled: " +
+ wrapped.getClass().getName());
+ return false;
+ }
+ return (Boolean)o;
+ } catch (ScriptException e) {
+ LOG.severe("Invalid Boolean expression: '"
+ +enabledExpression+"': " + e + ", property source provider will be disabled: " +
+ wrapped.getClass().getName());
+ }
+ return false;
+ }
+
+ /**
+ * Returns the enabled property.
+ * @return the enabled value.
+ */
+ @Override
+ public boolean isEnabled(){
+ return enabled;
+ }
+
+ /**
+ * Enables/disables this property source.
+ * @param enabled the enabled value.
+ */
+ @Override
+ public void setEnabled(boolean enabled){
+ this.enabled = enabled;
+ }
+
+ @Override
+ public Collection<PropertySource> getPropertySources() {
+ if(!isEnabled()){
+ return Collections.emptySet();
+ }
+ return this.wrapped.getPropertySources();
+ }
+
+ @Override
+ public String toString() {
+ return "DynamicPropertySourceProvider{" +
+ "\n enabled=" + enabledExpression +
+ "\n wrapped=" + wrapped +
+ '}';
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/20c558d0/metamodel/src/main/java/org/apache/tamaya/metamodel/MetaContext.java
----------------------------------------------------------------------
diff --git a/metamodel/src/main/java/org/apache/tamaya/metamodel/MetaContext.java b/metamodel/src/main/java/org/apache/tamaya/metamodel/MetaContext.java
index 4032c03..c4fa25a 100644
--- a/metamodel/src/main/java/org/apache/tamaya/metamodel/MetaContext.java
+++ b/metamodel/src/main/java/org/apache/tamaya/metamodel/MetaContext.java
@@ -52,6 +52,7 @@ public final class MetaContext {
return new MetaContext();
}
};
+ public static final String DEFAULT_CONTEXT_NAME = "<DEFAULT>";
private String id;
@@ -72,6 +73,15 @@ public final class MetaContext {
}
/**
+ * Access the default context. Contexts are managed as weak references in this class. If no
+ * such context exists, a new instance is created.
+ * @return the context instance, never null.
+ */
+ public static MetaContext getDefaultInstance(){
+ return getInstance(DEFAULT_CONTEXT_NAME);
+ }
+
+ /**
* Access a context by name. Contexts are managed as weak references in this class. If no
* such valid context exists, a new instance is created, using the given {@code validSupplier}.
* @param contextName the context name, not null.
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/20c558d0/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/ContextReader.java
----------------------------------------------------------------------
diff --git a/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/ContextReader.java b/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/ContextReader.java
index 5754e4f..db72f13 100644
--- a/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/ContextReader.java
+++ b/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/ContextReader.java
@@ -39,7 +39,7 @@ public class ContextReader implements MetaConfigurationReader {
@Override
public void read(Document document, ConfigurationContextBuilder contextBuilder) {
NodeList nodeList = document.getDocumentElement().getElementsByTagName("context");
- String contextName = "DEFAULT";
+ String contextName = null;
LOG.finer("Reading " + nodeList.getLength() + " meta context entries...");
for(int i=0;i<nodeList.getLength();i++){
Node node = nodeList.item(i);
@@ -48,7 +48,7 @@ public class ContextReader implements MetaConfigurationReader {
if(nameNode!=null){
contextName = nameNode.getTextContent();
}
- MetaContext context = MetaContext.getInstance(contextName);
+ MetaContext context = contextName!=null?MetaContext.getInstance(contextName):MetaContext.getDefaultInstance();
NodeList entryNodes = node.getChildNodes();
for(int c=0;c<entryNodes.getLength();c++){
Node entryNode = entryNodes.item(c);
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/20c558d0/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/DSLLoadingConfigurationProviderSpi.java
----------------------------------------------------------------------
diff --git a/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/DSLLoadingConfigurationProviderSpi.java b/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/DSLLoadingConfigurationProviderSpi.java
index 266ed5a..47ce7f0 100644
--- a/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/DSLLoadingConfigurationProviderSpi.java
+++ b/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/DSLLoadingConfigurationProviderSpi.java
@@ -23,18 +23,10 @@ import org.apache.tamaya.spi.*;
import org.apache.tamaya.Configuration;
import org.apache.tamaya.spisupport.DefaultConfiguration;
import org.apache.tamaya.spisupport.DefaultConfigurationContextBuilder;
-import org.w3c.dom.Document;
-import org.xml.sax.InputSource;
import javax.annotation.Priority;
-import javax.xml.parsers.DocumentBuilderFactory;
-import java.io.File;
-import java.net.MalformedURLException;
-import java.net.URL;
import java.util.Comparator;
import java.util.Objects;
-import java.util.logging.Level;
-import java.util.logging.Logger;
/**
* ConfigurationContext that uses {@link MetaConfiguration} to configure the
@@ -48,7 +40,7 @@ public class DSLLoadingConfigurationProviderSpi implements ConfigurationProvider
@Override
public ConfigurationContextBuilder getConfigurationContextBuilder() {
- return ServiceContextManager.getServiceContext().getService(ConfigurationContextBuilder.class);
+ return ServiceContextManager.getServiceContext().create(ConfigurationContextBuilder.class);
}
@Override
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/20c558d0/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/PropertySourceReader.java
----------------------------------------------------------------------
diff --git a/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/PropertySourceReader.java b/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/PropertySourceReader.java
index 8f42a3b..b3f107c 100644
--- a/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/PropertySourceReader.java
+++ b/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/PropertySourceReader.java
@@ -18,10 +18,12 @@
*/
package org.apache.tamaya.metamodel.internal;
+import org.apache.tamaya.metamodel.*;
import org.apache.tamaya.metamodel.spi.ItemFactory;
import org.apache.tamaya.metamodel.spi.ItemFactoryManager;
import org.apache.tamaya.metamodel.spi.MetaConfigurationReader;
import org.apache.tamaya.spi.ConfigurationContextBuilder;
+import org.apache.tamaya.spi.PropertyFilter;
import org.apache.tamaya.spi.PropertySource;
import org.apache.tamaya.spi.PropertySourceProvider;
import org.w3c.dom.Document;
@@ -66,6 +68,7 @@ public class PropertySourceReader implements MetaConfigurationReader{
PropertySource ps = sourceFactory.create(params);
if(ps!=null) {
ComponentConfigurator.configure(ps, params);
+ ps = decoratePropertySource(ps, contextBuilder, node, params);
LOG.finer("Adding configured property source: " + ps.getName());
contextBuilder.addPropertySources(ps);
}
@@ -84,6 +87,7 @@ public class PropertySourceReader implements MetaConfigurationReader{
PropertySourceProvider prov = providerFactory.create(params);
if(prov!=null) {
ComponentConfigurator.configure(prov, node);
+ prov = decoratePropertySourceProvider(prov, contextBuilder, node, params);
LOG.finer("Adding configured property source provider: " + prov.getClass().getName());
contextBuilder.addPropertySources(prov.getPropertySources());
}
@@ -100,4 +104,78 @@ public class PropertySourceReader implements MetaConfigurationReader{
}
}
+ /**
+ * Decorates a property source to be refreshable or filtered.
+ * @param ps the wrapped property source
+ * @param contextBuilder
+ *@param configNode the XML config node
+ * @param params the extracted parameter list @return the property source to be added to the context.
+ */
+ private PropertySource decoratePropertySource(PropertySource ps, ConfigurationContextBuilder contextBuilder, Node configNode, Map<String, String> params){
+ Node refreshableVal = configNode.getAttributes().getNamedItem("refreshable");
+ if(refreshableVal!=null && Boolean.parseBoolean(refreshableVal.getNodeValue())){
+ if(!(ps instanceof Refreshable)){
+ ps = RefreshablePropertySource.of(params, ps);
+ }
+ }
+ NodeList childNodes = configNode.getChildNodes();
+ for(int i=0;i<childNodes.getLength();i++){
+ Node node = childNodes.item(i);
+ if("filter".equals(node.getNodeName())) {
+ ps = FilteredPropertySource.of(ps);
+ configureFilter((FilteredPropertySource) ps, node);
+ }
+ }
+ Node enabledVal = configNode.getAttributes().getNamedItem("enabled");
+ if(enabledVal!=null){
+ ps = new EnabledPropertySource(ps,
+ MetaContext.getDefaultInstance().getProperties(),
+ enabledVal.getNodeValue());
+ }
+ return ps;
+ }
+
+ private void configureFilter(FilteredPropertySource ps, Node filterNode) {
+ try {
+ String type = filterNode.getAttributes().getNamedItem("type").getNodeValue();
+ ItemFactory<PropertyFilter> filterFactory = ItemFactoryManager.getInstance().getFactory(PropertyFilter.class, type);
+ if(filterFactory==null){
+ LOG.severe("No such property filter: " + type);
+ return;
+ }
+ Map<String,String> params = ComponentConfigurator.extractParameters(filterNode);
+ PropertyFilter filter = filterFactory.create(params);
+ if(filter!=null) {
+ ComponentConfigurator.configure(filter, params);
+ LOG.finer("Adding configured property filter: " + filter.getClass().getName());
+ ps.addPropertyFilter(filter);
+ }
+ }catch(Exception e){
+ LOG.log(Level.SEVERE, "Failed to read property filter configuration: " + filterNode, e);
+ }
+ }
+
+ /**
+ * Decorates a property source provider to be refreshable or filtered.
+ * @param prov the property source provider to be wrapped.
+ * @param contextBuilder
+ *@param configNode the XML config node
+ * @param params the extracted parameter list @return the property source provider to be added to the context.
+ */
+ private PropertySourceProvider decoratePropertySourceProvider(PropertySourceProvider prov, ConfigurationContextBuilder contextBuilder, Node configNode, Map<String, String> params){
+ Node refreshableVal = configNode.getAttributes().getNamedItem("refreshable");
+ if(refreshableVal!=null && Boolean.parseBoolean(refreshableVal.getNodeValue())){
+ if(!(prov instanceof Refreshable)){
+ prov = RefreshablePropertySourceProvider.of(params, prov);
+ }
+ }
+ Node enabledVal = configNode.getAttributes().getNamedItem("enabled");
+ if(enabledVal!=null){
+ prov = new EnabledPropertySourceProvider(prov,
+ MetaContext.getDefaultInstance().getProperties(),
+ enabledVal.getNodeValue());
+ }
+ return prov;
+ }
+
}