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/12 16:13:05 UTC
[2/5] incubator-tamaya-sandbox git commit: Added tests and bugfixes
for Tamaya OSGI support.
Added tests and bugfixes for Tamaya OSGI support.
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/f0dfa86d
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/tree/f0dfa86d
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/diff/f0dfa86d
Branch: refs/heads/master
Commit: f0dfa86dea30790ecc0d2e31f2ac62880f90a705
Parents: ff8e47c
Author: anatole <an...@apache.org>
Authored: Mon Dec 12 16:05:29 2016 +0100
Committer: anatole <an...@apache.org>
Committed: Mon Dec 12 16:05:29 2016 +0100
----------------------------------------------------------------------
osgi/common/pom.xml | 164 ++++++++++++++++
.../java/org/apache/tamaya/osgi/Activator.java | 130 ++++++++++++
.../tamaya/osgi/OSGIConfigRootMapper.java | 36 ++++
.../tamaya/osgi/OSGIEnhancedConfiguration.java | 117 +++++++++++
.../tamaya/osgi/TamayaConfigAdminImpl.java | 176 +++++++++++++++++
.../tamaya/osgi/TamayaOSGIConfiguration.java | 139 +++++++++++++
.../org/apache/tamaya/osgi/OSGIKarafTest.java | 115 +++++++++++
.../tamaya/osgi/TamayaConfigAdminImplTest.java | 75 +++++++
.../META-INF/javaconfiguration.properties | 21 ++
osgi/common/src/test/resources/arquillian.xml | 27 +++
osgi/common/src/test/resources/felix.properties | 23 +++
.../test/resources/org.ops4j.pax.logging.cfg | 48 +++++
osgi/features/pom.xml | 84 ++++++++
osgi/features/src/main/features/features.xml | 24 +++
osgi/pom.xml | 75 ++-----
.../java/org/apache/tamaya/osgi/Activator.java | 129 ------------
.../tamaya/osgi/OSGIConfigRootMapper.java | 36 ----
.../tamaya/osgi/OSGIEnhancedConfiguration.java | 117 -----------
.../tamaya/osgi/TamayaConfigAdminImpl.java | 196 -------------------
.../tamaya/osgi/TamayaConfigurationImpl.java | 127 ------------
.../META-INF/javaconfiguration.properties | 18 --
osgi/src/test/resources/arquillian.xml | 27 ---
osgi/src/test/resources/felix.properties | 23 ---
23 files changed, 1192 insertions(+), 735 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/f0dfa86d/osgi/common/pom.xml
----------------------------------------------------------------------
diff --git a/osgi/common/pom.xml b/osgi/common/pom.xml
new file mode 100644
index 0000000..c10de13
--- /dev/null
+++ b/osgi/common/pom.xml
@@ -0,0 +1,164 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<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">
+
+ <!--
+
+ 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.
+ -->
+
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.apache.tamaya.ext</groupId>
+ <artifactId>tamaya-osgi-all</artifactId>
+ <version>0.3-incubating-SNAPSHOT</version>
+ <relativePath>..</relativePath>
+ </parent>
+
+ <artifactId>tamaya-osgi</artifactId>
+ <packaging>jar</packaging>
+ <name>Apache Tamaya :: OSGi Integration :: ConfigAdmin</name>
+ <description>Tamaya Based OSGI Implementation of ConfigAdmin and Config Injection</description>
+
+ <properties>
+ <karaf.version>4.0.7</karaf.version>
+ <osgi.version>6.0.0</osgi.version>
+ <pax.exam.version>4.5.0</pax.exam.version>
+ </properties>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>biz.aQute.bnd</groupId>
+ <artifactId>bnd-maven-plugin</artifactId>
+ <version>3.3.0</version>
+ <executions>
+ <execution>
+ <goals>
+ <goal>bnd-process</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.osgi</groupId>
+ <artifactId>org.osgi.service.cm</artifactId>
+ <version>1.5.0</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.karaf.features</groupId>
+ <artifactId>framework</artifactId>
+ <version>${karaf.version}</version>
+ <type>kar</type>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.karaf.features</groupId>
+ <artifactId>standard</artifactId>
+ <version>${karaf.version}</version>
+ <classifier>features</classifier>
+ <type>xml</type>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.karaf.features</groupId>
+ <artifactId>enterprise</artifactId>
+ <version>${karaf.version}</version>
+ <classifier>features</classifier>
+ <type>xml</type>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.osgi</groupId>
+ <artifactId>org.osgi.core</artifactId>
+ <version>${osgi.version}</version>
+ </dependency>
+
+ <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>
+ <dependency>
+ <groupId>org.apache.tamaya.ext</groupId>
+ <artifactId>tamaya-osgi-features</artifactId>
+ <version>${project.version}</version>
+ <type>pom</type>
+ <scope>test</scope>
+ </dependency>
+
+ <!-- Testing -->
+
+ <!--<dependency>-->
+ <!--<groupId>org.apache.tamaya.ext</groupId>-->
+ <!--<artifactId>tamaya-injection</artifactId>-->
+ <!--<version>${project.version}</version>-->
+ <!--</dependency>-->
+ <dependency>
+ <groupId>org.hamcrest</groupId>
+ <artifactId>java-hamcrest</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.ops4j.pax.exam</groupId>
+ <artifactId>pax-exam-container-karaf</artifactId>
+ <version>${pax.exam.version}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.ops4j.pax.exam</groupId>
+ <artifactId>pax-exam-junit4</artifactId>
+ <version>${pax.exam.version}</version>
+ <scope>test</scope>
+ </dependency>
+ <!-- https://mvnrepository.com/artifact/org.ops4j.pax.url/pax-url-mvn -->
+ <dependency>
+ <groupId>org.ops4j.pax.url</groupId>
+ <artifactId>pax-url-mvn</artifactId>
+ <version>1.3.7</version>
+ </dependency>
+
+ </dependencies>
+
+</project>
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/f0dfa86d/osgi/common/src/main/java/org/apache/tamaya/osgi/Activator.java
----------------------------------------------------------------------
diff --git a/osgi/common/src/main/java/org/apache/tamaya/osgi/Activator.java b/osgi/common/src/main/java/org/apache/tamaya/osgi/Activator.java
new file mode 100644
index 0000000..1fe445c
--- /dev/null
+++ b/osgi/common/src/main/java/org/apache/tamaya/osgi/Activator.java
@@ -0,0 +1,130 @@
+/*
+ * 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.osgi.framework.BundleActivator;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.Constants;
+import org.osgi.framework.ServiceRegistration;
+import org.osgi.service.cm.ConfigurationAdmin;
+import org.osgi.util.tracker.ServiceTracker;
+
+import java.util.Dictionary;
+import java.util.Hashtable;
+import java.util.logging.Logger;
+
+/**
+ * Activator that registers the Tamaya based Service Class for {@link ConfigurationAdmin},
+ * using a default service priority of {@code 0}. This behaviour is configurable based on OSGI properties:
+ * <ul>
+ * <li><p><b>org.tamaya.integration.osgi.cm.ranking, type: int</b> allows to configure the OSGI service ranking for
+ * Tamaya based ConfigurationAdmin instance. The default ranking used is 10.</p></li>
+ * <li><p><b>org.tamaya.integration.osgi.cm.override, type: boolean</b> allows to configure if Tamaya should
+ * register its ConfigAdmin service. Default is true.</p></li>
+ * </ul>
+ */
+public class Activator implements BundleActivator {
+
+ private static final String SERVICE_RANKING_PROP = "org.apache.tamaya.osgi.cm.ranking";
+
+// private static final String SERVICE_OVERRIDE_PROP = "org.apache.tamaya.osgi.cm.override";
+
+ private static final Integer DEFAULT_RANKING = 10;
+
+ private static final Logger LOG = Logger.getLogger(Activator.class.getName());
+
+ private ServiceRegistration<ConfigurationAdmin> registration;
+
+// private ServiceTracker<Object, Object> injectionTracker;
+
+ @Override
+ public void start(BundleContext context) throws Exception {
+ Dictionary<String, Object> props = new Hashtable<>();
+ String ranking = context.getProperty(SERVICE_RANKING_PROP);
+ if (ranking == null) {
+ ranking = System.getProperty(SERVICE_RANKING_PROP);
+ }
+ if (ranking == null) {
+ props.put(Constants.SERVICE_RANKING, DEFAULT_RANKING);
+ LOG.fine("Using default ranking for Tamaya OSGI ConfigAdmin service: " + DEFAULT_RANKING);
+ } else {
+ props.put(Constants.SERVICE_RANKING, Integer.valueOf(ranking));
+ LOG.fine("Using custom ranking for Tamaya OSGI ConfigAdmin service: " + ranking);
+ }
+ TamayaConfigAdminImpl cm = new TamayaConfigAdminImpl(context);
+ registration = context.registerService(ConfigurationAdmin.class, cm, props);
+ LOG.info("Registered Tamaya OSGI ConfigAdmin service-");
+
+ // register injection mechanisms, if not configured otherwise
+// val = context.getProperty(SERVICE_INJECT_PROP);
+// if(val == null || Boolean.parseBoolean(val)){
+// injectionTracker = new ServiceTracker<Object, Object>(context, Object.class, null) {
+// @Override
+// public Object addingService(ServiceReference<Object> reference) {
+// Object service = context.getService(reference);
+// Object pidObj = reference.getProperty(Constants.SERVICE_PID);
+// if (pidObj instanceof String) {
+// String pid = (String) pidObj;
+// ConfigurationAdmin configAdmin = null;
+// ServiceReference<ConfigurationAdmin> adminRef =
+// context.getServiceReference(ConfigurationAdmin.class);
+// if(adminRef!=null){
+// configAdmin = context.getService(adminRef);
+// }
+// try {
+// Configuration targetConfig = null;
+// if(configAdmin != null){
+// org.osgi.service.cm.Configuration osgiConfig = configAdmin.getConfiguration(pid);
+// if(osgiConfig!=null){
+// targetConfig = new OSGIEnhancedConfiguration(osgiConfig);
+// }
+// }
+// if(targetConfig==null){
+// targetConfig = ConfigurationProvider.getConfiguration();
+// }
+// ConfigurationInjection.getConfigurationInjector().configure(service, targetConfig);
+// } catch (Exception e) {
+// LOG.log(Level.WARNING, "Error configuring Service: " + service, e);
+// }
+// } else {
+// LOG.log(Level.SEVERE, "Unsupported pid: " + pidObj);
+// }
+// return service;
+// }
+//
+// @Override
+// public void removedService(ServiceReference<Object> reference, Object service) {
+// context.ungetService(reference);
+// }
+// };
+// injectionTracker.open();
+// }
+ }
+
+ @Override
+ public void stop(BundleContext context) throws Exception {
+ if (registration != null) {
+ registration.unregister();
+ }
+// if(injectionTracker!=null){
+// injectionTracker.close();
+// }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/f0dfa86d/osgi/common/src/main/java/org/apache/tamaya/osgi/OSGIConfigRootMapper.java
----------------------------------------------------------------------
diff --git a/osgi/common/src/main/java/org/apache/tamaya/osgi/OSGIConfigRootMapper.java b/osgi/common/src/main/java/org/apache/tamaya/osgi/OSGIConfigRootMapper.java
new file mode 100644
index 0000000..79cc387
--- /dev/null
+++ b/osgi/common/src/main/java/org/apache/tamaya/osgi/OSGIConfigRootMapper.java
@@ -0,0 +1,36 @@
+/*
+ * 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;
+
+/**
+ * Mapping function for mapping Tamaya configuration sections to OSGI pids.
+ */
+public interface OSGIConfigRootMapper {
+
+ /**
+ * Map the given OSGI pid to a corresponding configuration section in Tamaya. Es an example (and this is also the
+ * default implemented) a configuration mapping for {@code pid/factoryPid==myBundle} could be {@code [bundle:myBundle]}.
+ * This mapping is used as a prefix when collecting the corresponding entries for the OSGI configuration.
+ * @param pid the OSGI pid, or null
+ * @param factoryPid the OSGI factoryPid, or null
+ * @return return the corresponding config root section. For ommitting any root section simply return an empty
+ * String.
+ */
+ String getTamayaConfigRoot(String pid, String factoryPid);
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/f0dfa86d/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
new file mode 100644
index 0000000..117ae1b
--- /dev/null
+++ b/osgi/common/src/main/java/org/apache/tamaya/osgi/OSGIEnhancedConfiguration.java
@@ -0,0 +1,117 @@
+///*
+// * 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/f0dfa86d/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
new file mode 100644
index 0000000..047cfb3
--- /dev/null
+++ b/osgi/common/src/main/java/org/apache/tamaya/osgi/TamayaConfigAdminImpl.java
@@ -0,0 +1,176 @@
+/*
+ * 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 java.io.IOException;
+import java.util.*;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.Filter;
+import org.osgi.framework.InvalidSyntaxException;
+import org.osgi.framework.ServiceReference;
+import org.osgi.service.cm.Configuration;
+import org.osgi.service.cm.ConfigurationAdmin;
+
+/**
+ * Tamaya based implementation of an OSGI {@link ConfigurationAdmin}.
+ */
+public class TamayaConfigAdminImpl implements ConfigurationAdmin {
+ /** the logger. */
+ private static final Logger LOG = Logger.getLogger(TamayaConfigAdminImpl.class.getName());
+
+ /** The OSGI context. */
+ private final BundleContext context;
+ /** THe optional OSGI parent service. */
+ private ConfigurationAdmin parent;
+ /** The cached configurations. */
+ private Map<String,Configuration> configs = new WeakHashMap<>();
+ /** The configuration section mapper. */
+ private OSGIConfigRootMapper configRootMapper;
+
+ /**
+ * Create a new config.
+ * @param context the OSGI context
+ */
+ TamayaConfigAdminImpl(BundleContext context) {
+ this.context = context;
+ this.configRootMapper = loadConfigRootMapper();
+ }
+
+ @Override
+ public Configuration createFactoryConfiguration(String factoryPid) throws IOException {
+ return createFactoryConfiguration(factoryPid, null);
+ }
+
+ @Override
+ public Configuration createFactoryConfiguration(String factoryPid, String location) throws IOException {
+ String key = "factory:"+factoryPid;
+ if(location!=null){
+ key += "::"+location;
+ }
+ Configuration config = this.configs.get(key);
+ if(config==null) {
+ Dictionary<String, Object> parentConfig = getParentConfig(null, factoryPid, location);
+ config = new TamayaOSGIConfiguration(null, factoryPid, configRootMapper, parentConfig);
+ this.configs.put(key, config);
+ }
+ return config;
+ }
+
+ @Override
+ public Configuration getConfiguration(String pid, String location) throws IOException {
+ String key = "config:"+pid;
+ if(location!=null){
+ key += "::"+location;
+ }
+ 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);
+ }
+ return config;
+ }
+
+ @Override
+ public Configuration getConfiguration(String pid) throws IOException {
+ return getConfiguration(pid, null);
+ }
+
+ private Dictionary<String, Object> getParentConfig(String pid, String factoryPid, String location) {
+ Dictionary<String, Object> parentConfig = null;
+ if (context != null) {
+ try {
+ ServiceReference[] refs = context.getAllServiceReferences(ConfigurationAdmin.class.getName(), null);
+ for (ServiceReference<ConfigurationAdmin> ref : refs) {
+ ConfigurationAdmin parentCand = context.getService(ref);
+ if (parentCand != null && !(parentCand instanceof TamayaConfigAdminImpl)) {
+ try {
+ parentConfig = parentCand.getConfiguration(pid, factoryPid).getProperties();
+ } catch (IOException e) {
+ LOG.log(Level.WARNING, "Error reading parent OSGI config.", e);
+ }
+ }
+ }
+ } catch (Exception e) {
+ LOG.log(Level.SEVERE, "Cannot not evaluate parent/base OSGI config.", e);
+ }
+ }
+ return parentConfig;
+ }
+
+ @Override
+ public Configuration[] listConfigurations(String filter) throws IOException, InvalidSyntaxException {
+ Collection<Configuration> result;
+ if (filter == null) {
+ result = this.configs.values();
+ } else {
+ result = new ArrayList<>();
+ if(context==null){
+ for (Configuration config : this.configs.values()) {
+ 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[configs.size()]);
+ }
+
+ /**
+ * Loads the configuration toor mapper using the OSGIConfigRootMapper OSGI service resolving mechanism. If no
+ * such service is available it loads the default mapper.
+ * @return the mapper to be used, bever null.
+ */
+ private OSGIConfigRootMapper loadConfigRootMapper() {
+ OSGIConfigRootMapper mapper = null;
+ if(context!=null) {
+ ServiceReference<OSGIConfigRootMapper> ref = context.getServiceReference(OSGIConfigRootMapper.class);
+ if (ref != null) {
+ mapper = context.getService(ref);
+ }
+ }
+ if(mapper==null){
+ mapper = new OSGIConfigRootMapper() {
+ @Override
+ public String getTamayaConfigRoot(String pid, String factoryPid) {
+ if(pid!=null) {
+ return "[" + pid +']';
+ } else{
+ return "[" + factoryPid +']';
+ }
+ }
+ @Override
+ public String toString(){
+ return "Default OSGIConfigRootMapper(pid -> [bundle:pid], factoryPid -> [bundle:factoryPid]";
+ }
+ };
+ }
+ return mapper;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/f0dfa86d/osgi/common/src/main/java/org/apache/tamaya/osgi/TamayaOSGIConfiguration.java
----------------------------------------------------------------------
diff --git a/osgi/common/src/main/java/org/apache/tamaya/osgi/TamayaOSGIConfiguration.java b/osgi/common/src/main/java/org/apache/tamaya/osgi/TamayaOSGIConfiguration.java
new file mode 100644
index 0000000..962cc38
--- /dev/null
+++ b/osgi/common/src/main/java/org/apache/tamaya/osgi/TamayaOSGIConfiguration.java
@@ -0,0 +1,139 @@
+/*
+ * 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 java.io.IOException;
+import java.util.*;
+import java.util.logging.Logger;
+
+import org.apache.tamaya.ConfigurationProvider;
+import org.apache.tamaya.functions.ConfigurationFunctions;
+import org.osgi.service.cm.Configuration;
+
+/**
+ * Tamaya based implementation of an OSGI {@link Configuration}.
+ */
+public class TamayaOSGIConfiguration implements Configuration {
+ private static final Logger LOG = Logger.getLogger(TamayaOSGIConfiguration.class.getName());
+ private final Dictionary<String, Object> parentConfig;
+ private final String pid;
+ private final String factoryPid;
+ private OSGIConfigRootMapper rootMapper;
+ private boolean overriding = true;
+ private String bundleLocation;
+
+ /**
+ * Constructor.
+ * @param confPid the OSGI pid
+ * @param factoryPid the factory pid
+ * @param configRootMapper the mapper that maps the pids to a tamaya root section.
+ * @param parentConfig the OSGI config for the given context, may be null..
+ */
+ TamayaOSGIConfiguration(String confPid, String factoryPid, OSGIConfigRootMapper configRootMapper,
+ Dictionary<String, Object> parentConfig) {
+ this.pid = confPid;
+ this.factoryPid = factoryPid;
+ this.parentConfig = parentConfig;
+ this.rootMapper = Objects.requireNonNull(configRootMapper);
+ }
+
+ public boolean isOverriding() {
+ return overriding;
+ }
+
+ public void setOverriding(boolean overriding){
+ this.overriding = overriding;
+ }
+
+ @Override
+ public String getPid() {
+ return pid;
+ }
+
+ @Override
+ public Dictionary<String, Object> getProperties() {
+ Dictionary<String, Object> properties = new Hashtable<>();
+
+ final String rootKey = this.rootMapper.getTamayaConfigRoot(pid, factoryPid);
+ LOG.info("Configuration: Evaluating Tamaya configuration for '" + rootKey + "'.");
+ org.apache.tamaya.Configuration tamayConfig = ConfigurationProvider.getConfiguration();
+ if(overriding){
+ if(parentConfig!=null) {
+ putAll(properties, parentConfig);
+ }
+ putAll(properties, tamayConfig.with(ConfigurationFunctions.section(rootKey, true)).getProperties());
+ }else{
+ putAll(properties, tamayConfig.with(ConfigurationFunctions.section(rootKey, true)).getProperties());
+ if(parentConfig!=null) {
+ putAll(properties, parentConfig);
+ }
+ }
+ return properties;
+ }
+
+ private void putAll(Dictionary<String, Object> target, Dictionary<String, Object> data) {
+ Enumeration<String> keys = data.keys();
+ while(keys.hasMoreElements()){
+ String key = keys.nextElement();
+ target.put(key, data.get(key));
+ }
+ }
+
+ private void putAll(Dictionary<String, Object> target, Map<String, String> data) {
+ for(Map.Entry<String,String> en:data.entrySet()){
+ target.put(en.getKey(), en.getValue());
+ }
+ }
+
+ @Override
+ public void update(Dictionary<String, ?> properties) throws IOException {
+ throw new UnsupportedOperationException("Mutability is not supported.");
+ }
+
+ @Override
+ public void delete() throws IOException {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public String getFactoryPid() {
+ return factoryPid;
+ }
+
+ @Override
+ public void update() throws IOException {
+ // Nothing to do since, we load everything dynamically.
+ }
+
+ @Override
+ public void setBundleLocation(String location) {
+ this.bundleLocation = location;
+ }
+
+ @Override
+ public String getBundleLocation() {
+ return this.bundleLocation;
+ }
+
+ @Override
+ public long getChangeCount() {
+ return 0;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/f0dfa86d/osgi/common/src/test/java/org/apache/tamaya/osgi/OSGIKarafTest.java
----------------------------------------------------------------------
diff --git a/osgi/common/src/test/java/org/apache/tamaya/osgi/OSGIKarafTest.java b/osgi/common/src/test/java/org/apache/tamaya/osgi/OSGIKarafTest.java
new file mode 100644
index 0000000..d1014ef
--- /dev/null
+++ b/osgi/common/src/test/java/org/apache/tamaya/osgi/OSGIKarafTest.java
@@ -0,0 +1,115 @@
+/*
+ * 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.junit.Ignore;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.ops4j.pax.exam.Configuration;
+import org.ops4j.pax.exam.CoreOptions;
+import org.ops4j.pax.exam.Option;
+import org.ops4j.pax.exam.junit.PaxExam;
+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.PerMethod;
+import org.osgi.service.cm.ConfigurationAdmin;
+
+import javax.inject.Inject;
+import java.io.File;
+
+import static org.junit.Assert.*;
+import static org.junit.Assert.assertEquals;
+import static org.ops4j.pax.exam.CoreOptions.*;
+
+@RunWith(PaxExam.class)
+@ExamReactorStrategy(PerMethod.class)
+public class OSGIKarafTest {
+
+ @Inject
+ private ConfigurationAdmin configAdmin;
+
+ @Configuration
+ public Option[] config() {
+ return options(
+ // distribution to test: Karaf 3.0.3
+ KarafDistributionOption.karafDistributionConfiguration()
+ .frameworkUrl(CoreOptions.maven()
+ .groupId("org.apache.karaf")
+ .artifactId("apache-karaf")
+ .type("zip")
+ .version(getKarafVersion()))
+ .karafVersion(getKarafVersion())
+ .name("ApacheKaraf")
+ .useDeployFolder(false)
+ .unpackDirectory(new File("target/karaf")),
+ // no local and remote consoles
+// KarafDistributionOption.debugConfiguration("5005", true),
+ KarafDistributionOption.configureConsole().startLocalConsole(),
+ KarafDistributionOption.configureConsole().ignoreRemoteShell(),
+ // keep runtime folder allowing analysing results
+ KarafDistributionOption.keepRuntimeFolder(),
+ // use custom logging configuration file with a custom appender
+ KarafDistributionOption.replaceConfigurationFile("etc/org.ops4j.pax.logging.cfg", new File(
+ "src/test/resources/org.ops4j.pax.logging.cfg")),
+
+ mavenBundle("org.apache.geronimo.specs", "geronimo-annotation_1.2_spec", "1.0-alpha-1"),
+ mavenBundle("org.apache.tamaya", "tamaya-api", "0.3-incubating-SNAPSHOT"),
+ mavenBundle("org.apache.tamaya", "tamaya-core", "0.3-incubating-SNAPSHOT"),
+ mavenBundle("org.apache.tamaya.ext", "tamaya-spisupport", "0.3-incubating-SNAPSHOT"),
+ mavenBundle("org.apache.tamaya.ext", "tamaya-functions", "0.3-incubating-SNAPSHOT"),
+ mavenBundle("org.apache.tamaya.ext", "tamaya-osgi", "0.3-incubating-SNAPSHOT"),
+ KarafDistributionOption.features(
+ maven().groupId("org.apache.karaf.features").artifactId("standard").type("xml")
+ .classifier("features").version(getKarafVersion()), "aries-blueprint"),
+// KarafDistributionOption.features(
+// "mvn:org.apache.karaf.features/standard/4.0.7/xml/features",
+// "aries-blueprint"),
+// bundle("reference:file:target/test-classes"),
+ junitBundles()
+ );
+ }
+
+ private String getKarafVersion() {
+ return "4.0.7";
+ }
+
+
+ @Test
+ @Ignore
+ public void ensureEnvironmentIsWorkingAndTamayaIsActive() {
+ assertNotNull(configAdmin);
+ assertTrue(configAdmin instanceof TamayaConfigAdminImpl);
+ }
+
+ @Test
+ @Ignore
+ public void getConfiguration() throws Exception {
+ org.osgi.service.cm.Configuration config = configAdmin.getConfiguration("tamaya");
+ assertNotNull(config);
+ assertFalse(config.getProperties().isEmpty());
+ assertEquals(config.getProperties().size(), 4);
+ assertEquals(config.getProperties().get("my.testProperty1"), "success1");
+ assertEquals(config.getProperties().get("my.testProperty2"), "success2");
+ assertEquals(config.getProperties().get("my.testProperty3"), "success3");
+ assertEquals(config.getProperties().get("my.testProperty4"), "success4");
+ }
+
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/f0dfa86d/osgi/common/src/test/java/org/apache/tamaya/osgi/TamayaConfigAdminImplTest.java
----------------------------------------------------------------------
diff --git a/osgi/common/src/test/java/org/apache/tamaya/osgi/TamayaConfigAdminImplTest.java b/osgi/common/src/test/java/org/apache/tamaya/osgi/TamayaConfigAdminImplTest.java
new file mode 100644
index 0000000..93f98d0
--- /dev/null
+++ b/osgi/common/src/test/java/org/apache/tamaya/osgi/TamayaConfigAdminImplTest.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.osgi;
+
+import org.junit.Test;
+import org.osgi.service.cm.Configuration;
+
+import static org.junit.Assert.*;
+
+/**
+ * Created by atsticks on 10.12.16.
+ */
+public class TamayaConfigAdminImplTest {
+
+ private TamayaConfigAdminImpl configAdmin = new TamayaConfigAdminImpl(null);
+
+ @Test
+ public void createFactoryConfiguration() throws Exception {
+ Configuration config = configAdmin.createFactoryConfiguration("tamaya");
+ assertNotNull(config);
+ assertFalse(config.getProperties().isEmpty());
+ assertEquals(config.getProperties().size(), 4);
+ assertEquals(config.getProperties().get("my.testProperty1"), "success1");
+ }
+
+ @Test
+ public void createFactoryConfigurationWithLocation() throws Exception {
+ Configuration config = configAdmin.createFactoryConfiguration("tamaya", "location");
+ assertNotNull(config);
+ assertFalse(config.getProperties().isEmpty());
+ assertEquals(config.getProperties().size(), 4);
+ assertEquals(config.getProperties().get("my.testProperty2"), "success2");
+ }
+
+ @Test
+ public void getConfiguration() throws Exception {
+ Configuration config = configAdmin.getConfiguration("tamaya");
+ assertNotNull(config);
+ assertFalse(config.getProperties().isEmpty());
+ assertEquals(config.getProperties().size(), 4);
+ assertEquals(config.getProperties().get("my.testProperty3"), "success3");
+ }
+
+ @Test
+ public void getConfigurationWithLocation() throws Exception {
+ Configuration config = configAdmin.getConfiguration("tamaya", "location");
+ assertNotNull(config);
+ assertFalse(config.getProperties().isEmpty());
+ assertEquals(config.getProperties().size(), 4);
+ assertEquals(config.getProperties().get("my.testProperty4"), "success4");
+ }
+
+ @Test
+ public void listConfigurations() throws Exception {
+ Configuration[] configs = configAdmin.listConfigurations(".*");
+ assertNotNull(configs);
+ }
+
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/f0dfa86d/osgi/common/src/test/resources/META-INF/javaconfiguration.properties
----------------------------------------------------------------------
diff --git a/osgi/common/src/test/resources/META-INF/javaconfiguration.properties b/osgi/common/src/test/resources/META-INF/javaconfiguration.properties
new file mode 100644
index 0000000..f2879a0
--- /dev/null
+++ b/osgi/common/src/test/resources/META-INF/javaconfiguration.properties
@@ -0,0 +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.
+#
+[tamaya]my.testProperty1=success1
+[tamaya]my.testProperty2=success2
+[tamaya]my.testProperty3=success3
+[tamaya]my.testProperty4=success4
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/f0dfa86d/osgi/common/src/test/resources/arquillian.xml
----------------------------------------------------------------------
diff --git a/osgi/common/src/test/resources/arquillian.xml b/osgi/common/src/test/resources/arquillian.xml
new file mode 100644
index 0000000..a4c885a
--- /dev/null
+++ b/osgi/common/src/test/resources/arquillian.xml
@@ -0,0 +1,27 @@
+<!--
+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.
+-->
+<arquillian xmlns="http://jboss.org/schema/arquillian" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://jboss.org/schema/arquillian http://jboss.org/schema/arquillian/arquillian_1_0.xsd">
+
+ <container qualifier="osgi" default="true">
+ <configuration>
+ <property name="frameworkProperties">src/test/resources/felix.properties</property>
+ </configuration>
+ </container>
+</arquillian>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/f0dfa86d/osgi/common/src/test/resources/felix.properties
----------------------------------------------------------------------
diff --git a/osgi/common/src/test/resources/felix.properties b/osgi/common/src/test/resources/felix.properties
new file mode 100644
index 0000000..4630fa2
--- /dev/null
+++ b/osgi/common/src/test/resources/felix.properties
@@ -0,0 +1,23 @@
+# 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.
+#
+# org.osgi.service.cm;org.apache.felix.cm;org.apache.tamaya;org.apache.tamaya.spi;
+org.osgi.framework.bootdelegation=org.apache.tamaya,org.apache.tamaya.osgi,org.apache.tamaya.osgi.test
+felix.log.level=4 #debug logging
+# felix.auto.deploy.dir=../test-bundles
+org.osgi.framework.storage=target/felix-cache
+felix.fileinstall.dir=./test-bundles
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/f0dfa86d/osgi/common/src/test/resources/org.ops4j.pax.logging.cfg
----------------------------------------------------------------------
diff --git a/osgi/common/src/test/resources/org.ops4j.pax.logging.cfg b/osgi/common/src/test/resources/org.ops4j.pax.logging.cfg
new file mode 100644
index 0000000..6683438
--- /dev/null
+++ b/osgi/common/src/test/resources/org.ops4j.pax.logging.cfg
@@ -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.
+#
+#updated by pax-exam
+#Sun Nov 27 20:55:11 CET 2016
+log4j.appender.stdout=org.apache.log4j.ConsoleAppender
+log4j.appender.sift.appender.append=true
+log4j.appender.out.maxFileSize=1MB
+log4j.appender.audit.layout.ConversionPattern=%d{ISO8601} | %-5.5p | %-16.16t | %-32.32c{1} | %X{bundle.id} - %X{bundle.name} - %X{bundle.version} | %m%n
+log4j.appender.sift.appender.file=${karaf.data}/log/$\\{bundle.name\\}.log
+log4j.appender.sift.appender.layout=org.apache.log4j.PatternLayout
+log4j.appender.out.append=true
+log4j.appender.sift.appender=org.apache.log4j.FileAppender
+log4j.appender.out.layout=org.apache.log4j.PatternLayout
+log4j.appender.out=org.apache.log4j.RollingFileAppender
+log4j.appender.stdout.layout.ConversionPattern=%d{ISO8601} | %-5.5p | %-16.16t | %-32.32c{1} | %X{bundle.id} - %X{bundle.name} - %X{bundle.version} | %m%n
+log4j.throwableRenderer=org.apache.log4j.OsgiThrowableRenderer
+log4j.appender.out.file=${karaf.data}/log/karaf.log
+log4j.appender.sift=org.apache.log4j.sift.MDCSiftingAppender
+log4j.appender.audit.append=true
+log4j.appender.audit.maxBackupIndex=10
+log4j.appender.audit.layout=org.apache.log4j.PatternLayout
+log4j.appender.sift.key=bundle.name
+log4j.appender.audit.maxFileSize=1MB
+log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
+log4j.additivity.org.apache.karaf.jaas.modules.audit=false
+log4j.logger.org.apache.karaf.jaas.modules.audit=INFO, audit
+log4j.appender.audit.file=${karaf.data}/security/audit.log
+log4j.appender.sift.default=karaf
+log4j.appender.sift.appender.layout.ConversionPattern=%d{ISO8601} | %-5.5p | %-16.16t | %-32.32c{1} | %m%n
+log4j.appender.out.maxBackupIndex=10
+log4j.appender.audit=org.apache.log4j.RollingFileAppender
+log4j.rootLogger=WARN, out, stdout, osgi\:*
+log4j.appender.out.layout.ConversionPattern=%d{ISO8601} | %-5.5p | %-16.16t | %-32.32c{1} | %X{bundle.id} - %X{bundle.name} - %X{bundle.version} | %m%n
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/f0dfa86d/osgi/features/pom.xml
----------------------------------------------------------------------
diff --git a/osgi/features/pom.xml b/osgi/features/pom.xml
new file mode 100644
index 0000000..e7ea3eb
--- /dev/null
+++ b/osgi/features/pom.xml
@@ -0,0 +1,84 @@
+<?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/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.apache.tamaya.ext</groupId>
+ <artifactId>tamaya-sandbox</artifactId>
+ <version>0.3-incubating-SNAPSHOT</version>
+ <relativePath>..</relativePath>
+ </parent>
+
+ <artifactId>tamaya-osgi-features</artifactId>
+ <packaging>pom</packaging>
+ <name>Apache Tamaya :: OSGI Integration :: Features</name>
+
+ <build>
+ <plugins>
+
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-resources-plugin</artifactId>
+ <executions>
+ <execution>
+ <id>features</id>
+ <phase>generate-resources</phase>
+ <goals>
+ <goal>copy-resources</goal>
+ </goals>
+ <configuration>
+ <resources>
+ <resource>
+ <directory>src/main/features</directory>
+ <filtering>true</filtering>
+ </resource>
+ </resources>
+ <outputDirectory>target/features</outputDirectory>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+
+ <plugin>
+ <groupId>org.codehaus.mojo</groupId>
+ <artifactId>build-helper-maven-plugin</artifactId>
+ <executions>
+ <execution>
+ <id>attach-artifacts</id>
+ <phase>package</phase>
+ <goals>
+ <goal>attach-artifact</goal>
+ </goals>
+ <configuration>
+ <artifacts>
+ <artifact>
+ <file>target/features/features.xml</file>
+ <type>xml</type>
+ <classifier>features</classifier>
+ </artifact>
+ </artifacts>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+</project>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/f0dfa86d/osgi/features/src/main/features/features.xml
----------------------------------------------------------------------
diff --git a/osgi/features/src/main/features/features.xml b/osgi/features/src/main/features/features.xml
new file mode 100644
index 0000000..0655d30
--- /dev/null
+++ b/osgi/features/src/main/features/features.xml
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Copyright 2013 David Valeri.
+ Licensed 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.
+ -->
+<features name="org-apache-tamaya-${project.version}">
+ <feature name="org-apache-tamaya" version="${project.version}">
+ <feature>org-apache-tamaya</feature>
+ <bundle>mvn:${project.groupId}/tamaya-osgi/${project.version}/jar</bundle>
+ <bundle>mvn:${project.groupId}/tamaya-functions/${project.version}/jar</bundle>
+ <bundle>mvn:${project.groupId}/tamaya-spi-support/${project.version}/jar</bundle>
+ <bundle>mvn:org.apache.tamaya/tamaya-api/${project.version}/jar</bundle>
+ <bundle>mvn:org.apache.tamaya/tamaya-core/${project.version}/jar</bundle>
+ <bundle>mvn:org.apache.geronimo.specs/geronimo-annotation_1.2_spec/1.0-alpha-1/jar</bundle>
+ </feature>
+</features>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/f0dfa86d/osgi/pom.xml
----------------------------------------------------------------------
diff --git a/osgi/pom.xml b/osgi/pom.xml
index 193abca..1578a16 100644
--- a/osgi/pom.xml
+++ b/osgi/pom.xml
@@ -28,10 +28,10 @@
<relativePath>..</relativePath>
</parent>
- <artifactId>tamaya-osgi</artifactId>
- <packaging>jar</packaging>
- <name>Apache Tamaya Integration - OSGi Services :: Tamaya Config</name>
- <description>Tamaya Based OSGI Implementation of ConfigAdmin and Config Injection</description>
+ <artifactId>tamaya-osgi-all</artifactId>
+ <packaging>pom</packaging>
+ <name>Apache Tamaya :: OSGi Integration :: ALL</name>
+ <description>Tamaya OSGI Integration</description>
<properties>
<karaf.version>4.0.7</karaf.version>
@@ -40,29 +40,19 @@
</properties>
<dependencies>
- <!--<dependency>-->
- <!--<groupId>org.apache.felix</groupId>-->
- <!--<artifactId>org.apache.felix.configadmin</artifactId>-->
- <!--<version>1.8.8</version>-->
- <!--</dependency>-->
- <dependency>
- <groupId>org.osgi</groupId>
- <artifactId>org.osgi.service.cm</artifactId>
- <version>1.5.0</version>
- </dependency>
<dependency>
<groupId>org.apache.geronimo.specs</groupId>
<artifactId>geronimo-atinject_1.0_spec</artifactId>
<version>1.0</version>
</dependency>
<dependency>
- <groupId>org.osgi</groupId>
- <artifactId>org.osgi.core</artifactId>
- <version>${osgi.version}</version>
+ <groupId>org.apache.tamaya</groupId>
+ <artifactId>tamaya-api</artifactId>
+ <version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.apache.tamaya</groupId>
- <artifactId>tamaya-api</artifactId>
+ <artifactId>tamaya-core</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
@@ -75,50 +65,11 @@
<artifactId>tamaya-spisupport</artifactId>
<version>${project.version}</version>
</dependency>
-
- <!-- Testing -->
-
- <!--<dependency>-->
- <!--<groupId>org.apache.tamaya.ext</groupId>-->
- <!--<artifactId>tamaya-injection</artifactId>-->
- <!--<version>${project.version}</version>-->
- <!--</dependency>-->
- <dependency>
- <groupId>org.hamcrest</groupId>
- <artifactId>java-hamcrest</artifactId>
- </dependency>
- <dependency>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
- </dependency>
- <dependency>
- <groupId>org.ops4j.pax.exam</groupId>
- <artifactId>pax-exam-container-karaf</artifactId>
- <version>${pax.exam.version}</version>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.ops4j.pax.exam</groupId>
- <artifactId>pax-exam-junit4</artifactId>
- <version>${pax.exam.version}</version>
- <scope>test</scope>
- </dependency>
- <!-- https://mvnrepository.com/artifact/org.ops4j.pax.url/pax-url-mvn -->
- <dependency>
- <groupId>org.ops4j.pax.url</groupId>
- <artifactId>pax-url-mvn</artifactId>
- <version>1.3.7</version>
- </dependency>
-
-
- <!--<dependency>-->
- <!--<groupId>org.apache.karaf</groupId>-->
- <!--<artifactId>apache-karaf</artifactId>-->
- <!--<version>${karaf.version}</version>-->
- <!--<type>zip</type>-->
- <!--<scope>test</scope>-->
- <!--</dependency>-->
-
</dependencies>
+ <modules>
+ <module>features</module>
+ <module>common</module>
+ </modules>
+
</project>
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/f0dfa86d/osgi/src/main/java/org/apache/tamaya/osgi/Activator.java
----------------------------------------------------------------------
diff --git a/osgi/src/main/java/org/apache/tamaya/osgi/Activator.java b/osgi/src/main/java/org/apache/tamaya/osgi/Activator.java
deleted file mode 100644
index 73820f5..0000000
--- a/osgi/src/main/java/org/apache/tamaya/osgi/Activator.java
+++ /dev/null
@@ -1,129 +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.osgi.framework.BundleActivator;
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.Constants;
-import org.osgi.framework.ServiceRegistration;
-import org.osgi.service.cm.ConfigurationAdmin;
-import org.osgi.util.tracker.ServiceTracker;
-
-import java.util.Dictionary;
-import java.util.Hashtable;
-import java.util.logging.Logger;
-
-/**
- * Activator that registers the Tamaya based Service Class for {@link ConfigurationAdmin},
- * using a default service priority of {@code 0}. This behaviour is configurable based on OSGI properties:
- * <ul>
- * <li><p><b>org.tamaya.integration.osgi.cm.ranking, type: int</b> allows to configure the OSGI service ranking for
- * Tamaya based ConfigurationAdmin instance. The default ranking used is 10.</p></li>
- * <li><p><b>org.tamaya.integration.osgi.cm.override, type: boolean</b> allows to configure if Tamaya should
- * register its ConfigAdmin service. Default is true.</p></li>
- * </ul>
- */
-public class Activator implements BundleActivator {
-
- private static final String SERVICE_RANKING_PROP = "org.tamaya.integration.osgi.cm.ranking";
-
- private static final String SERVICE_OVERRIDE_PROP = "org.tamaya.integration.osgi.cm.override";
-
- private static final String SERVICE_INJECT_PROP = "org.tamaya.integration.osgi.cm.inject";
-
- private static final Integer DEFAULT_RANKING = 10;
-
- private static final Logger LOG = Logger.getLogger(Activator.class.getName());
-
- private ServiceRegistration<ConfigurationAdmin> registration;
-
- private ServiceTracker<Object, Object> injectionTracker;
-
- @Override
- public void start(BundleContext context) throws Exception {
- String val = context.getProperty(SERVICE_OVERRIDE_PROP);
- if(val == null || Boolean.parseBoolean(val)){
- Dictionary<String, Object> props = new Hashtable<>();
- String ranking = context.getProperty(SERVICE_RANKING_PROP);
- if (ranking == null) {
- props.put(Constants.SERVICE_RANKING, DEFAULT_RANKING);
- } else {
- props.put(Constants.SERVICE_RANKING, Integer.valueOf(ranking));
- }
- TamayaConfigAdminImpl cm = new TamayaConfigAdminImpl(context);
- registration = context.registerService(ConfigurationAdmin.class, cm, props);
- }
-
- // register injection mechanisms, if not configured otherwise
-// val = context.getProperty(SERVICE_INJECT_PROP);
-// if(val == null || Boolean.parseBoolean(val)){
-// injectionTracker = new ServiceTracker<Object, Object>(context, Object.class, null) {
-// @Override
-// public Object addingService(ServiceReference<Object> reference) {
-// Object service = context.getService(reference);
-// Object pidObj = reference.getProperty(Constants.SERVICE_PID);
-// if (pidObj instanceof String) {
-// String pid = (String) pidObj;
-// ConfigurationAdmin configAdmin = null;
-// ServiceReference<ConfigurationAdmin> adminRef =
-// context.getServiceReference(ConfigurationAdmin.class);
-// if(adminRef!=null){
-// configAdmin = context.getService(adminRef);
-// }
-// try {
-// Configuration targetConfig = null;
-// if(configAdmin != null){
-// org.osgi.service.cm.Configuration osgiConfig = configAdmin.getConfiguration(pid);
-// if(osgiConfig!=null){
-// targetConfig = new OSGIEnhancedConfiguration(osgiConfig);
-// }
-// }
-// if(targetConfig==null){
-// targetConfig = ConfigurationProvider.getConfiguration();
-// }
-// ConfigurationInjection.getConfigurationInjector().configure(service, targetConfig);
-// } catch (Exception e) {
-// LOG.log(Level.WARNING, "Error configuring Service: " + service, e);
-// }
-// } else {
-// LOG.log(Level.SEVERE, "Unsupported pid: " + pidObj);
-// }
-// return service;
-// }
-//
-// @Override
-// public void removedService(ServiceReference<Object> reference, Object service) {
-// context.ungetService(reference);
-// }
-// };
-// injectionTracker.open();
-// }
- }
-
- @Override
- public void stop(BundleContext context) throws Exception {
- if (registration != null) {
- registration.unregister();
- }
- if(injectionTracker!=null){
- injectionTracker.close();
- }
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/f0dfa86d/osgi/src/main/java/org/apache/tamaya/osgi/OSGIConfigRootMapper.java
----------------------------------------------------------------------
diff --git a/osgi/src/main/java/org/apache/tamaya/osgi/OSGIConfigRootMapper.java b/osgi/src/main/java/org/apache/tamaya/osgi/OSGIConfigRootMapper.java
deleted file mode 100644
index 79cc387..0000000
--- a/osgi/src/main/java/org/apache/tamaya/osgi/OSGIConfigRootMapper.java
+++ /dev/null
@@ -1,36 +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;
-
-/**
- * Mapping function for mapping Tamaya configuration sections to OSGI pids.
- */
-public interface OSGIConfigRootMapper {
-
- /**
- * Map the given OSGI pid to a corresponding configuration section in Tamaya. Es an example (and this is also the
- * default implemented) a configuration mapping for {@code pid/factoryPid==myBundle} could be {@code [bundle:myBundle]}.
- * This mapping is used as a prefix when collecting the corresponding entries for the OSGI configuration.
- * @param pid the OSGI pid, or null
- * @param factoryPid the OSGI factoryPid, or null
- * @return return the corresponding config root section. For ommitting any root section simply return an empty
- * String.
- */
- String getTamayaConfigRoot(String pid, String factoryPid);
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/f0dfa86d/osgi/src/main/java/org/apache/tamaya/osgi/OSGIEnhancedConfiguration.java
----------------------------------------------------------------------
diff --git a/osgi/src/main/java/org/apache/tamaya/osgi/OSGIEnhancedConfiguration.java b/osgi/src/main/java/org/apache/tamaya/osgi/OSGIEnhancedConfiguration.java
deleted file mode 100644
index 66f9b1c..0000000
--- a/osgi/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/f0dfa86d/osgi/src/main/java/org/apache/tamaya/osgi/TamayaConfigAdminImpl.java
----------------------------------------------------------------------
diff --git a/osgi/src/main/java/org/apache/tamaya/osgi/TamayaConfigAdminImpl.java b/osgi/src/main/java/org/apache/tamaya/osgi/TamayaConfigAdminImpl.java
deleted file mode 100644
index 35c55e7..0000000
--- a/osgi/src/main/java/org/apache/tamaya/osgi/TamayaConfigAdminImpl.java
+++ /dev/null
@@ -1,196 +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 java.io.IOException;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Map;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.Constants;
-import org.osgi.framework.Filter;
-import org.osgi.framework.InvalidSyntaxException;
-import org.osgi.framework.ServiceFactory;
-import org.osgi.framework.ServiceReference;
-import org.osgi.service.cm.Configuration;
-import org.osgi.service.cm.ConfigurationAdmin;
-import org.osgi.service.cm.ManagedService;
-import org.osgi.service.cm.ManagedServiceFactory;
-import org.osgi.util.tracker.ServiceTracker;
-
-/**
- * Tamaya based implementation of an OSGI {@link ConfigurationAdmin}.
- */
-public class TamayaConfigAdminImpl implements ConfigurationAdmin {
- /** the logger. */
- private static final Logger LOG = Logger.getLogger(TamayaConfigAdminImpl.class.getName());
-
- /** The OSGI context. */
- private final BundleContext context;
- /** THe optional OSGI parent service. */
- private ConfigurationAdmin parent;
- /** The cached configurations. */
- private Map<String,Configuration> configs = new ConcurrentHashMap<>();
- /** The configuration section mapper. */
- private OSGIConfigRootMapper configRootMapper;
-
- /**
- * Create a new config.
- * @param context the OSGI context
- */
- TamayaConfigAdminImpl(BundleContext context) {
- this.context = context;
- this.configRootMapper = loadConfigRootMapper();
- ServiceReference<ConfigurationAdmin> ref = context.getServiceReference(ConfigurationAdmin.class);
- this.parent = ref!=null?context.getService(ref):null;
- ServiceTracker<ManagedService, ManagedService> serviceTracker = new ServiceTracker<ManagedService,
- ManagedService>(context, ManagedService.class, null) {
- @Override
- public ManagedService addingService(ServiceReference<ManagedService> reference) {
- ManagedService service = context.getService(reference);
- Object pidObj = reference.getProperty(Constants.SERVICE_PID);
- if (pidObj instanceof String) {
- String pid = (String) pidObj;
- try {
- Configuration config = getConfiguration(pid);
- if(config==null){
- service.updated(null);
- } else{
- service.updated(config.getProperties());
- }
- } catch (Exception e) {
- LOG.log(Level.WARNING, "Error configuring ManagedService: " + service, e);
- }
- } else {
- LOG.log(Level.SEVERE, "Unsupported pid: " + pidObj);
- }
- return service;
- }
-
- @Override
- public void removedService(ServiceReference<ManagedService> reference, ManagedService service) {
- context.ungetService(reference);
- }
- };
- serviceTracker.open();
-
- ServiceTracker<ServiceFactory, ServiceFactory> factoryTracker
- = new ServiceTracker<ServiceFactory, ServiceFactory>(context, ServiceFactory.class, null) {
- @Override
- public ServiceFactory addingService(ServiceReference<ServiceFactory> reference) {
- ServiceFactory factory = context.getService(reference);
- if(factory instanceof ManagedServiceFactory) {
- Object pidObj = reference.getProperty(Constants.SERVICE_PID);
- if (pidObj instanceof String) {
- String pid = (String) pidObj;
- try {
- Configuration config = getConfiguration(pid);
- if (config != null) {
- ((ManagedServiceFactory) factory).updated(config.getFactoryPid(), config.getProperties());
- }
- } catch (Exception e) {
- LOG.log(Level.WARNING, "Error configuring ManagedServiceFactory: " + factory, e);
- }
- } else {
- LOG.log(Level.SEVERE, "Unsupported pid: " + pidObj);
- }
- }
- return factory;
- }
-
- @Override
- public void removedService(ServiceReference<ServiceFactory> reference, ServiceFactory service) {
- super.removedService(reference, service);
- }
- };
- factoryTracker.open();
- }
-
- @Override
- public Configuration createFactoryConfiguration(String factoryPid) throws IOException {
- return createFactoryConfiguration(factoryPid, null);
- }
-
- @Override
- public Configuration createFactoryConfiguration(String factoryPid, String location) throws IOException {
- return new TamayaConfigurationImpl(factoryPid, null, configRootMapper, this.parent);
- }
-
- @Override
- public Configuration getConfiguration(String pid, String location) throws IOException {
- return getConfiguration(pid);
- }
-
- @Override
- public Configuration getConfiguration(String pid) throws IOException {
- return new TamayaConfigurationImpl(pid, null, configRootMapper, this.parent);
- }
-
- @Override
- public Configuration[] listConfigurations(String filter) throws IOException, InvalidSyntaxException {
- Collection<Configuration> result;
- if (filter == null) {
- result = this.configs.values();
- } else {
- result = new ArrayList<>();
- Filter flt = context.createFilter(filter);
- for (Configuration config : this.configs.values()) {
- if (flt.match(config.getProperties())) {
- result.add(config);
- }
- }
- }
- return result.isEmpty() ? null : result.toArray(new Configuration[configs.size()]);
- }
-
- /**
- * Loads the configuration toor mapper using the OSGIConfigRootMapper OSGI service resolving mechanism. If no
- * such service is available it loads the default mapper.
- * @return the mapper to be used, bever null.
- */
- private OSGIConfigRootMapper loadConfigRootMapper() {
- OSGIConfigRootMapper mapper = null;
- ServiceReference<OSGIConfigRootMapper> ref = context.getServiceReference(OSGIConfigRootMapper.class);
- if(ref!=null){
- mapper = context.getService(ref);
- }
- if(mapper==null){
- mapper = new OSGIConfigRootMapper() {
- @Override
- public String getTamayaConfigRoot(String pid, String factoryPid) {
- if(pid!=null) {
- return "[bundle:" + pid +']';
- } else{
- return "[bundle:" + factoryPid +']';
- }
- }
- @Override
- public String toString(){
- return "Default OSGIConfigRootMapper(pid -> [bundle:pid], factoryPid -> [bundle:factoryPid]";
- }
- };
- }
- return mapper;
- }
-
-}