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 <anat...@apache.org> Authored: Wed Dec 21 16:57:48 2016 +0100 Committer: anatole <anat...@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>