You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@karaf.apache.org by gn...@apache.org on 2014/03/24 17:31:59 UTC
[01/24] git commit: [KARAF-2833] Make instance/core independent of
blueprint
Repository: karaf
Updated Branches:
refs/heads/master b509da2b5 -> e30e660b5
[KARAF-2833] Make instance/core independent of blueprint
Project: http://git-wip-us.apache.org/repos/asf/karaf/repo
Commit: http://git-wip-us.apache.org/repos/asf/karaf/commit/64e73109
Tree: http://git-wip-us.apache.org/repos/asf/karaf/tree/64e73109
Diff: http://git-wip-us.apache.org/repos/asf/karaf/diff/64e73109
Branch: refs/heads/master
Commit: 64e731099ce2700912f954ecd6be73c775d461c4
Parents: 5db77eb
Author: Guillaume Nodet <gn...@gmail.com>
Authored: Fri Mar 21 18:18:59 2014 +0100
Committer: Guillaume Nodet <gn...@gmail.com>
Committed: Mon Mar 24 17:30:12 2014 +0100
----------------------------------------------------------------------
.../standard/src/main/feature/feature.xml | 1 -
instance/core/pom.xml | 4 +
.../instance/core/internal/osgi/Activator.java | 80 ++++++++++++++++++++
.../OSGI-INF/blueprint/instance-core.xml | 41 ----------
4 files changed, 84 insertions(+), 42 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/karaf/blob/64e73109/assemblies/features/standard/src/main/feature/feature.xml
----------------------------------------------------------------------
diff --git a/assemblies/features/standard/src/main/feature/feature.xml b/assemblies/features/standard/src/main/feature/feature.xml
index 8656d87..fc42bbd 100644
--- a/assemblies/features/standard/src/main/feature/feature.xml
+++ b/assemblies/features/standard/src/main/feature/feature.xml
@@ -141,7 +141,6 @@
</feature>
<feature name="instance" description="Provide Instance support" version="${project.version}">
- <feature version="${project.version}">aries-blueprint</feature>
<bundle start-level="30" start="true">mvn:org.apache.karaf.instance/org.apache.karaf.instance.core/${project.version}</bundle>
<bundle start-level="30" start="true">mvn:org.apache.karaf.instance/org.apache.karaf.instance.command/${project.version}</bundle>
</feature>
http://git-wip-us.apache.org/repos/asf/karaf/blob/64e73109/instance/core/pom.xml
----------------------------------------------------------------------
diff --git a/instance/core/pom.xml b/instance/core/pom.xml
index 742b1e0..c9ecd1e 100644
--- a/instance/core/pom.xml
+++ b/instance/core/pom.xml
@@ -152,9 +152,13 @@
org.apache.karaf.jpm,
org.apache.karaf.jpm.impl,
org.apache.karaf.instance.core.internal,
+ org.apache.karaf.instance.core.internal.osgi,
org.apache.felix.utils.properties;-split-package:=merge-first,
org.apache.karaf.util.locks
</Private-Package>
+ <Bundle-Activator>
+ org.apache.karaf.instance.core.internal.osgi.Activator
+ </Bundle-Activator>
</instructions>
</configuration>
</plugin>
http://git-wip-us.apache.org/repos/asf/karaf/blob/64e73109/instance/core/src/main/java/org/apache/karaf/instance/core/internal/osgi/Activator.java
----------------------------------------------------------------------
diff --git a/instance/core/src/main/java/org/apache/karaf/instance/core/internal/osgi/Activator.java b/instance/core/src/main/java/org/apache/karaf/instance/core/internal/osgi/Activator.java
new file mode 100644
index 0000000..6e8344a
--- /dev/null
+++ b/instance/core/src/main/java/org/apache/karaf/instance/core/internal/osgi/Activator.java
@@ -0,0 +1,80 @@
+/*
+ * 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.karaf.instance.core.internal.osgi;
+
+import java.util.ArrayList;
+import java.util.Hashtable;
+import java.util.List;
+
+import javax.management.NotCompliantMBeanException;
+
+import org.apache.karaf.instance.core.InstanceService;
+import org.apache.karaf.instance.core.internal.InstanceServiceImpl;
+import org.apache.karaf.instance.core.internal.InstancesMBeanImpl;
+import org.osgi.framework.BundleActivator;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceRegistration;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class Activator implements BundleActivator {
+
+ private static final Logger LOGGER = LoggerFactory.getLogger(Activator.class);
+
+ private ServiceRegistration<InstanceService> serviceRegistration;
+ private ServiceRegistration mbeanRegistration;
+
+ @Override
+ public void start(BundleContext context) throws Exception {
+ InstanceService instanceService = new InstanceServiceImpl();
+ serviceRegistration = context.registerService(InstanceService.class, instanceService, null);
+ try {
+ InstancesMBeanImpl mbean = new InstancesMBeanImpl(instanceService);
+ Hashtable<String, Object> props = new Hashtable<String, Object>();
+ props.put("jmx.objectname", "org.apache.karaf:type=instance,name=" + System.getProperty("karaf.name"));
+ mbeanRegistration = context.registerService(
+ getInterfaceNames(mbean),
+ mbean,
+ props
+ );
+ } catch (NotCompliantMBeanException e) {
+ LOGGER.warn("Error creating ConfigRepository mbean", e);
+ }
+ }
+
+ @Override
+ public void stop(BundleContext context) throws Exception {
+ mbeanRegistration.unregister();
+ serviceRegistration.unregister();
+ }
+
+ private String[] getInterfaceNames(Object object) {
+ List<String> names = new ArrayList<String>();
+ for (Class cl = object.getClass(); cl != Object.class; cl = cl.getSuperclass()) {
+ addSuperInterfaces(names, cl);
+ }
+ return names.toArray(new String[names.size()]);
+ }
+
+ private void addSuperInterfaces(List<String> names, Class clazz) {
+ for (Class cl : clazz.getInterfaces()) {
+ names.add(cl.getName());
+ addSuperInterfaces(names, cl);
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/karaf/blob/64e73109/instance/core/src/main/resources/OSGI-INF/blueprint/instance-core.xml
----------------------------------------------------------------------
diff --git a/instance/core/src/main/resources/OSGI-INF/blueprint/instance-core.xml b/instance/core/src/main/resources/OSGI-INF/blueprint/instance-core.xml
deleted file mode 100644
index 6634349..0000000
--- a/instance/core/src/main/resources/OSGI-INF/blueprint/instance-core.xml
+++ /dev/null
@@ -1,41 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
-
- Licensed to the Apache Software Foundation (ASF) under one or more
- contributor license agreements. See the NOTICE file distributed with
- this work for additional information regarding copyright ownership.
- The ASF licenses this file to You under the Apache License, Version 2.0
- (the "License"); you may not use this file except in compliance with
- the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
-
--->
-<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
- xmlns:ext="http://aries.apache.org/blueprint/xmlns/blueprint-ext/v1.0.0">
-
- <ext:property-placeholder />
-
- <bean id="instanceService" class="org.apache.karaf.instance.core.internal.InstanceServiceImpl">
- <property name="storageLocation" value="${karaf.instances}" />
- </bean>
-
- <service ref="instanceService" interface="org.apache.karaf.instance.core.InstanceService"/>
-
- <bean id="instancesMBean" class="org.apache.karaf.instance.core.internal.InstancesMBeanImpl">
- <argument ref="instanceService" />
- </bean>
-
- <service ref="instancesMBean" auto-export="interfaces">
- <service-properties>
- <entry key="jmx.objectname" value="org.apache.karaf:type=instance,name=${karaf.name}"/>
- </service-properties>
- </service>
-
-</blueprint>
[05/24] git commit: [KARAF-2845] Move SingleServiceTracker to util
Posted by gn...@apache.org.
[KARAF-2845] Move SingleServiceTracker to util
Project: http://git-wip-us.apache.org/repos/asf/karaf/repo
Commit: http://git-wip-us.apache.org/repos/asf/karaf/commit/e7f67746
Tree: http://git-wip-us.apache.org/repos/asf/karaf/tree/e7f67746
Diff: http://git-wip-us.apache.org/repos/asf/karaf/diff/e7f67746
Branch: refs/heads/master
Commit: e7f677469bec4cf253a82ef7756ed551a68e85c9
Parents: a0f482c
Author: Guillaume Nodet <gn...@gmail.com>
Authored: Fri Mar 21 17:55:29 2014 +0100
Committer: Guillaume Nodet <gn...@gmail.com>
Committed: Mon Mar 24 17:30:12 2014 +0100
----------------------------------------------------------------------
region/persist/pom.xml | 15 +-
.../region/persist/internal/Activator.java | 2 +-
.../internal/util/SingleServiceTracker.java | 171 -------------------
shell/core/pom.xml | 1 +
.../osgi/secured/SecuredSessionFactoryImpl.java | 1 +
.../osgi/secured/SingleServiceTracker.java | 171 -------------------
shell/ssh/pom.xml | 3 +-
.../org/apache/karaf/shell/ssh/Activator.java | 2 +-
.../shell/ssh/util/SingleServiceTracker.java | 171 -------------------
.../util/tracker/SingleServiceTracker.java | 171 +++++++++++++++++++
10 files changed, 190 insertions(+), 518 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/karaf/blob/e7f67746/region/persist/pom.xml
----------------------------------------------------------------------
diff --git a/region/persist/pom.xml b/region/persist/pom.xml
index 1ae0793..6eaf68b 100644
--- a/region/persist/pom.xml
+++ b/region/persist/pom.xml
@@ -56,6 +56,12 @@
</dependency>
<dependency>
+ <groupId>org.apache.karaf</groupId>
+ <artifactId>org.apache.karaf.util</artifactId>
+ <scope>provided</scope>
+ </dependency>
+
+ <dependency>
<groupId>org.osgi</groupId>
<artifactId>org.osgi.compendium</artifactId>
<scope>provided</scope>
@@ -107,8 +113,13 @@
<artifactId>maven-bundle-plugin</artifactId>
<configuration>
<instructions>
- <Bundle-Activator>org.apache.karaf.region.persist.internal.Activator</Bundle-Activator>
- <Export-Package>org.apache.karaf.region.persist;version=${project.version};-split-package:=merge-first</Export-Package>
+ <Bundle-Activator>
+ org.apache.karaf.region.persist.internal.Activator
+ </Bundle-Activator>
+ <Private-Package>
+ org.apache.karaf.region.persist.internal.*,
+ org.apache.karaf.util.tracker
+ </Private-Package>
</instructions>
</configuration>
</plugin>
http://git-wip-us.apache.org/repos/asf/karaf/blob/e7f67746/region/persist/src/main/java/org/apache/karaf/region/persist/internal/Activator.java
----------------------------------------------------------------------
diff --git a/region/persist/src/main/java/org/apache/karaf/region/persist/internal/Activator.java b/region/persist/src/main/java/org/apache/karaf/region/persist/internal/Activator.java
index e6ab85b..4705818 100644
--- a/region/persist/src/main/java/org/apache/karaf/region/persist/internal/Activator.java
+++ b/region/persist/src/main/java/org/apache/karaf/region/persist/internal/Activator.java
@@ -23,7 +23,7 @@ package org.apache.karaf.region.persist.internal;
import java.util.concurrent.atomic.AtomicReference;
import org.apache.karaf.region.persist.RegionsPersistence;
-import org.apache.karaf.region.persist.internal.util.SingleServiceTracker;
+import org.apache.karaf.util.tracker.SingleServiceTracker;
import org.eclipse.equinox.region.RegionDigraph;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleActivator;
http://git-wip-us.apache.org/repos/asf/karaf/blob/e7f67746/region/persist/src/main/java/org/apache/karaf/region/persist/internal/util/SingleServiceTracker.java
----------------------------------------------------------------------
diff --git a/region/persist/src/main/java/org/apache/karaf/region/persist/internal/util/SingleServiceTracker.java b/region/persist/src/main/java/org/apache/karaf/region/persist/internal/util/SingleServiceTracker.java
deleted file mode 100644
index 16f554f..0000000
--- a/region/persist/src/main/java/org/apache/karaf/region/persist/internal/util/SingleServiceTracker.java
+++ /dev/null
@@ -1,171 +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.karaf.region.persist.internal.util;
-
-import java.util.concurrent.atomic.AtomicBoolean;
-import java.util.concurrent.atomic.AtomicReference;
-
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.Constants;
-import org.osgi.framework.Filter;
-import org.osgi.framework.InvalidSyntaxException;
-import org.osgi.framework.ServiceEvent;
-import org.osgi.framework.ServiceListener;
-import org.osgi.framework.ServiceReference;
-
-//This is from aries util
-public final class SingleServiceTracker<T> {
- public static interface SingleServiceListener {
- public void serviceFound();
-
- public void serviceLost();
-
- public void serviceReplaced();
- }
-
- private final BundleContext ctx;
- private final String className;
- private final AtomicReference<T> service = new AtomicReference<T>();
- private final AtomicReference<ServiceReference> ref = new AtomicReference<ServiceReference>();
- private final AtomicBoolean open = new AtomicBoolean(false);
- private final SingleServiceListener serviceListener;
- private String filterString;
- private Filter filter;
-
- private final ServiceListener listener = new ServiceListener() {
- public void serviceChanged(ServiceEvent event) {
- if (open.get()) {
- if (event.getType() == ServiceEvent.UNREGISTERING) {
- ServiceReference deadRef = event.getServiceReference();
- if (deadRef.equals(ref.get())) {
- findMatchingReference(deadRef);
- }
- } else if (event.getType() == ServiceEvent.REGISTERED && ref.get() == null) {
- findMatchingReference(null);
- }
- }
- }
- };
-
- public SingleServiceTracker(BundleContext context, Class<T> clazz, SingleServiceListener sl) {
- ctx = context;
- this.className = clazz.getName();
- serviceListener = sl;
- }
-
- public SingleServiceTracker(BundleContext context, Class<T> clazz, String filterString, SingleServiceListener sl) throws InvalidSyntaxException {
- this(context, clazz, sl);
- this.filterString = filterString;
- if (filterString != null) filter = context.createFilter(filterString);
- }
-
- public T getService() {
- return service.get();
- }
-
- public ServiceReference getServiceReference() {
- return ref.get();
- }
-
- public void open() {
- if (open.compareAndSet(false, true)) {
- try {
- String filterString = '(' + Constants.OBJECTCLASS + '=' + className + ')';
- if (filter != null) filterString = "(&" + filterString + filter + ')';
- ctx.addServiceListener(listener, filterString);
- findMatchingReference(null);
- } catch (InvalidSyntaxException e) {
- // this can never happen. (famous last words :)
- }
- }
- }
-
- private void findMatchingReference(ServiceReference original) {
- boolean clear = true;
- ServiceReference ref = ctx.getServiceReference(className);
- if (ref != null && (filter == null || filter.match(ref))) {
- @SuppressWarnings("unchecked")
- T service = (T) ctx.getService(ref);
- if (service != null) {
- clear = false;
-
- // We do the unget out of the lock so we don't exit this class while holding a lock.
- if (!!!update(original, ref, service)) {
- ctx.ungetService(ref);
- }
- }
- } else if (original == null) {
- clear = false;
- }
-
- if (clear) {
- update(original, null, null);
- }
- }
-
- private boolean update(ServiceReference deadRef, ServiceReference newRef, T service) {
- boolean result = false;
- int foundLostReplaced = -1;
-
- // Make sure we don't try to get a lock on null
- Object lock;
-
- // we have to choose our lock.
- if (newRef != null) lock = newRef;
- else if (deadRef != null) lock = deadRef;
- else lock = this;
-
- // This lock is here to ensure that no two threads can set the ref and service
- // at the same time.
- synchronized (lock) {
- if (open.get()) {
- result = this.ref.compareAndSet(deadRef, newRef);
- if (result) {
- this.service.set(service);
-
- if (deadRef == null && newRef != null) foundLostReplaced = 0;
- if (deadRef != null && newRef == null) foundLostReplaced = 1;
- if (deadRef != null && newRef != null) foundLostReplaced = 2;
- }
- }
- }
-
- if (serviceListener != null) {
- if (foundLostReplaced == 0) serviceListener.serviceFound();
- else if (foundLostReplaced == 1) serviceListener.serviceLost();
- else if (foundLostReplaced == 2) serviceListener.serviceReplaced();
- }
-
- return result;
- }
-
- public void close() {
- if (open.compareAndSet(true, false)) {
- ctx.removeServiceListener(listener);
-
- synchronized (this) {
- ServiceReference deadRef = ref.getAndSet(null);
- service.set(null);
- if (deadRef != null) ctx.ungetService(deadRef);
- }
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/karaf/blob/e7f67746/shell/core/pom.xml
----------------------------------------------------------------------
diff --git a/shell/core/pom.xml b/shell/core/pom.xml
index 47c1d34..c45f473 100644
--- a/shell/core/pom.xml
+++ b/shell/core/pom.xml
@@ -154,6 +154,7 @@
<Private-Package>
org.apache.karaf.service.guard.tools,
org.apache.karaf.shell.impl.*,
+ org.apache.karaf.util.tracker,
org.apache.felix.utils.properties,
org.apache.felix.utils.extender,
org.apache.felix.utils.manifest,
http://git-wip-us.apache.org/repos/asf/karaf/blob/e7f67746/shell/core/src/main/java/org/apache/karaf/shell/impl/console/osgi/secured/SecuredSessionFactoryImpl.java
----------------------------------------------------------------------
diff --git a/shell/core/src/main/java/org/apache/karaf/shell/impl/console/osgi/secured/SecuredSessionFactoryImpl.java b/shell/core/src/main/java/org/apache/karaf/shell/impl/console/osgi/secured/SecuredSessionFactoryImpl.java
index 567575d..6c4048a 100644
--- a/shell/core/src/main/java/org/apache/karaf/shell/impl/console/osgi/secured/SecuredSessionFactoryImpl.java
+++ b/shell/core/src/main/java/org/apache/karaf/shell/impl/console/osgi/secured/SecuredSessionFactoryImpl.java
@@ -37,6 +37,7 @@ import org.apache.karaf.service.guard.tools.ACLConfigurationParser;
import org.apache.karaf.shell.api.console.Command;
import org.apache.karaf.shell.api.console.Session;
import org.apache.karaf.shell.impl.console.SessionFactoryImpl;
+import org.apache.karaf.util.tracker.SingleServiceTracker;
import org.osgi.framework.BundleContext;
import org.osgi.framework.Constants;
import org.osgi.framework.ServiceRegistration;
http://git-wip-us.apache.org/repos/asf/karaf/blob/e7f67746/shell/core/src/main/java/org/apache/karaf/shell/impl/console/osgi/secured/SingleServiceTracker.java
----------------------------------------------------------------------
diff --git a/shell/core/src/main/java/org/apache/karaf/shell/impl/console/osgi/secured/SingleServiceTracker.java b/shell/core/src/main/java/org/apache/karaf/shell/impl/console/osgi/secured/SingleServiceTracker.java
deleted file mode 100644
index fb57ee1..0000000
--- a/shell/core/src/main/java/org/apache/karaf/shell/impl/console/osgi/secured/SingleServiceTracker.java
+++ /dev/null
@@ -1,171 +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.karaf.shell.impl.console.osgi.secured;
-
-import java.util.concurrent.atomic.AtomicBoolean;
-import java.util.concurrent.atomic.AtomicReference;
-
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.Constants;
-import org.osgi.framework.Filter;
-import org.osgi.framework.InvalidSyntaxException;
-import org.osgi.framework.ServiceEvent;
-import org.osgi.framework.ServiceListener;
-import org.osgi.framework.ServiceReference;
-
-//This is from aries util
-public final class SingleServiceTracker<T> {
- public static interface SingleServiceListener {
- public void serviceFound();
-
- public void serviceLost();
-
- public void serviceReplaced();
- }
-
- private final BundleContext ctx;
- private final String className;
- private final AtomicReference<T> service = new AtomicReference<T>();
- private final AtomicReference<ServiceReference> ref = new AtomicReference<ServiceReference>();
- private final AtomicBoolean open = new AtomicBoolean(false);
- private final SingleServiceListener serviceListener;
- private String filterString;
- private Filter filter;
-
- private final ServiceListener listener = new ServiceListener() {
- public void serviceChanged(ServiceEvent event) {
- if (open.get()) {
- if (event.getType() == ServiceEvent.UNREGISTERING) {
- ServiceReference deadRef = event.getServiceReference();
- if (deadRef.equals(ref.get())) {
- findMatchingReference(deadRef);
- }
- } else if (event.getType() == ServiceEvent.REGISTERED && ref.get() == null) {
- findMatchingReference(null);
- }
- }
- }
- };
-
- public SingleServiceTracker(BundleContext context, Class<T> clazz, SingleServiceListener sl) {
- ctx = context;
- this.className = clazz.getName();
- serviceListener = sl;
- }
-
- public SingleServiceTracker(BundleContext context, Class<T> clazz, String filterString, SingleServiceListener sl) throws InvalidSyntaxException {
- this(context, clazz, sl);
- this.filterString = filterString;
- if (filterString != null) filter = context.createFilter(filterString);
- }
-
- public T getService() {
- return service.get();
- }
-
- public ServiceReference getServiceReference() {
- return ref.get();
- }
-
- public void open() {
- if (open.compareAndSet(false, true)) {
- try {
- String filterString = '(' + Constants.OBJECTCLASS + '=' + className + ')';
- if (filter != null) filterString = "(&" + filterString + filter + ')';
- ctx.addServiceListener(listener, filterString);
- findMatchingReference(null);
- } catch (InvalidSyntaxException e) {
- // this can never happen. (famous last words :)
- }
- }
- }
-
- private void findMatchingReference(ServiceReference original) {
- boolean clear = true;
- ServiceReference ref = ctx.getServiceReference(className);
- if (ref != null && (filter == null || filter.match(ref))) {
- @SuppressWarnings("unchecked")
- T service = (T) ctx.getService(ref);
- if (service != null) {
- clear = false;
-
- // We do the unget out of the lock so we don't exit this class while holding a lock.
- if (!!!update(original, ref, service)) {
- ctx.ungetService(ref);
- }
- }
- } else if (original == null) {
- clear = false;
- }
-
- if (clear) {
- update(original, null, null);
- }
- }
-
- private boolean update(ServiceReference deadRef, ServiceReference newRef, T service) {
- boolean result = false;
- int foundLostReplaced = -1;
-
- // Make sure we don't try to get a lock on null
- Object lock;
-
- // we have to choose our lock.
- if (newRef != null) lock = newRef;
- else if (deadRef != null) lock = deadRef;
- else lock = this;
-
- // This lock is here to ensure that no two threads can set the ref and service
- // at the same time.
- synchronized (lock) {
- if (open.get()) {
- result = this.ref.compareAndSet(deadRef, newRef);
- if (result) {
- this.service.set(service);
-
- if (deadRef == null && newRef != null) foundLostReplaced = 0;
- if (deadRef != null && newRef == null) foundLostReplaced = 1;
- if (deadRef != null && newRef != null) foundLostReplaced = 2;
- }
- }
- }
-
- if (serviceListener != null) {
- if (foundLostReplaced == 0) serviceListener.serviceFound();
- else if (foundLostReplaced == 1) serviceListener.serviceLost();
- else if (foundLostReplaced == 2) serviceListener.serviceReplaced();
- }
-
- return result;
- }
-
- public void close() {
- if (open.compareAndSet(true, false)) {
- ctx.removeServiceListener(listener);
-
- synchronized (this) {
- ServiceReference deadRef = ref.getAndSet(null);
- service.set(null);
- if (deadRef != null) ctx.ungetService(deadRef);
- }
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/karaf/blob/e7f67746/shell/ssh/pom.xml
----------------------------------------------------------------------
diff --git a/shell/ssh/pom.xml b/shell/ssh/pom.xml
index 84135eb..cffaa0b 100644
--- a/shell/ssh/pom.xml
+++ b/shell/ssh/pom.xml
@@ -104,7 +104,8 @@
*
</Import-Package>
<Private-Package>
- org.apache.karaf.util
+ org.apache.karaf.util,
+ org.apache.karaf.util.tracker
</Private-Package>
<Bundle-Activator>org.apache.karaf.shell.ssh.Activator</Bundle-Activator>
</instructions>
http://git-wip-us.apache.org/repos/asf/karaf/blob/e7f67746/shell/ssh/src/main/java/org/apache/karaf/shell/ssh/Activator.java
----------------------------------------------------------------------
diff --git a/shell/ssh/src/main/java/org/apache/karaf/shell/ssh/Activator.java b/shell/ssh/src/main/java/org/apache/karaf/shell/ssh/Activator.java
index 575c871..af5fd54 100644
--- a/shell/ssh/src/main/java/org/apache/karaf/shell/ssh/Activator.java
+++ b/shell/ssh/src/main/java/org/apache/karaf/shell/ssh/Activator.java
@@ -29,9 +29,9 @@ import java.util.concurrent.Callable;
import java.util.concurrent.CopyOnWriteArrayList;
import org.apache.karaf.shell.api.action.lifecycle.Manager;
-import org.apache.karaf.shell.ssh.util.SingleServiceTracker;
import org.apache.karaf.shell.api.console.Session;
import org.apache.karaf.shell.api.console.SessionFactory;
+import org.apache.karaf.util.tracker.SingleServiceTracker;
import org.apache.sshd.SshServer;
import org.apache.sshd.common.NamedFactory;
import org.apache.sshd.server.command.ScpCommandFactory;
http://git-wip-us.apache.org/repos/asf/karaf/blob/e7f67746/shell/ssh/src/main/java/org/apache/karaf/shell/ssh/util/SingleServiceTracker.java
----------------------------------------------------------------------
diff --git a/shell/ssh/src/main/java/org/apache/karaf/shell/ssh/util/SingleServiceTracker.java b/shell/ssh/src/main/java/org/apache/karaf/shell/ssh/util/SingleServiceTracker.java
deleted file mode 100644
index c883dc0..0000000
--- a/shell/ssh/src/main/java/org/apache/karaf/shell/ssh/util/SingleServiceTracker.java
+++ /dev/null
@@ -1,171 +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.karaf.shell.ssh.util;
-
-import java.util.concurrent.atomic.AtomicBoolean;
-import java.util.concurrent.atomic.AtomicReference;
-
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.Constants;
-import org.osgi.framework.Filter;
-import org.osgi.framework.InvalidSyntaxException;
-import org.osgi.framework.ServiceEvent;
-import org.osgi.framework.ServiceListener;
-import org.osgi.framework.ServiceReference;
-
-//This is from aries util
-public final class SingleServiceTracker<T> {
- public static interface SingleServiceListener {
- public void serviceFound();
-
- public void serviceLost();
-
- public void serviceReplaced();
- }
-
- private final BundleContext ctx;
- private final String className;
- private final AtomicReference<T> service = new AtomicReference<T>();
- private final AtomicReference<ServiceReference> ref = new AtomicReference<ServiceReference>();
- private final AtomicBoolean open = new AtomicBoolean(false);
- private final SingleServiceListener serviceListener;
- private String filterString;
- private Filter filter;
-
- private final ServiceListener listener = new ServiceListener() {
- public void serviceChanged(ServiceEvent event) {
- if (open.get()) {
- if (event.getType() == ServiceEvent.UNREGISTERING) {
- ServiceReference deadRef = event.getServiceReference();
- if (deadRef.equals(ref.get())) {
- findMatchingReference(deadRef);
- }
- } else if (event.getType() == ServiceEvent.REGISTERED && ref.get() == null) {
- findMatchingReference(null);
- }
- }
- }
- };
-
- public SingleServiceTracker(BundleContext context, Class<T> clazz, SingleServiceListener sl) {
- ctx = context;
- this.className = clazz.getName();
- serviceListener = sl;
- }
-
- public SingleServiceTracker(BundleContext context, Class<T> clazz, String filterString, SingleServiceListener sl) throws InvalidSyntaxException {
- this(context, clazz, sl);
- this.filterString = filterString;
- if (filterString != null) filter = context.createFilter(filterString);
- }
-
- public T getService() {
- return service.get();
- }
-
- public ServiceReference getServiceReference() {
- return ref.get();
- }
-
- public void open() {
- if (open.compareAndSet(false, true)) {
- try {
- String filterString = '(' + Constants.OBJECTCLASS + '=' + className + ')';
- if (filter != null) filterString = "(&" + filterString + filter + ')';
- ctx.addServiceListener(listener, filterString);
- findMatchingReference(null);
- } catch (InvalidSyntaxException e) {
- // this can never happen. (famous last words :)
- }
- }
- }
-
- private void findMatchingReference(ServiceReference original) {
- boolean clear = true;
- ServiceReference ref = ctx.getServiceReference(className);
- if (ref != null && (filter == null || filter.match(ref))) {
- @SuppressWarnings("unchecked")
- T service = (T) ctx.getService(ref);
- if (service != null) {
- clear = false;
-
- // We do the unget out of the lock so we don't exit this class while holding a lock.
- if (!!!update(original, ref, service)) {
- ctx.ungetService(ref);
- }
- }
- } else if (original == null) {
- clear = false;
- }
-
- if (clear) {
- update(original, null, null);
- }
- }
-
- private boolean update(ServiceReference deadRef, ServiceReference newRef, T service) {
- boolean result = false;
- int foundLostReplaced = -1;
-
- // Make sure we don't try to get a lock on null
- Object lock;
-
- // we have to choose our lock.
- if (newRef != null) lock = newRef;
- else if (deadRef != null) lock = deadRef;
- else lock = this;
-
- // This lock is here to ensure that no two threads can set the ref and service
- // at the same time.
- synchronized (lock) {
- if (open.get()) {
- result = this.ref.compareAndSet(deadRef, newRef);
- if (result) {
- this.service.set(service);
-
- if (deadRef == null && newRef != null) foundLostReplaced = 0;
- if (deadRef != null && newRef == null) foundLostReplaced = 1;
- if (deadRef != null && newRef != null) foundLostReplaced = 2;
- }
- }
- }
-
- if (serviceListener != null) {
- if (foundLostReplaced == 0) serviceListener.serviceFound();
- else if (foundLostReplaced == 1) serviceListener.serviceLost();
- else if (foundLostReplaced == 2) serviceListener.serviceReplaced();
- }
-
- return result;
- }
-
- public void close() {
- if (open.compareAndSet(true, false)) {
- ctx.removeServiceListener(listener);
-
- synchronized (this) {
- ServiceReference deadRef = ref.getAndSet(null);
- service.set(null);
- if (deadRef != null) ctx.ungetService(deadRef);
- }
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/karaf/blob/e7f67746/util/src/main/java/org/apache/karaf/util/tracker/SingleServiceTracker.java
----------------------------------------------------------------------
diff --git a/util/src/main/java/org/apache/karaf/util/tracker/SingleServiceTracker.java b/util/src/main/java/org/apache/karaf/util/tracker/SingleServiceTracker.java
new file mode 100644
index 0000000..c96e73a
--- /dev/null
+++ b/util/src/main/java/org/apache/karaf/util/tracker/SingleServiceTracker.java
@@ -0,0 +1,171 @@
+/*
+ * 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.karaf.util.tracker;
+
+import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.concurrent.atomic.AtomicReference;
+
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.Constants;
+import org.osgi.framework.Filter;
+import org.osgi.framework.InvalidSyntaxException;
+import org.osgi.framework.ServiceEvent;
+import org.osgi.framework.ServiceListener;
+import org.osgi.framework.ServiceReference;
+
+//This is from aries util
+public final class SingleServiceTracker<T> {
+ public static interface SingleServiceListener {
+ public void serviceFound();
+
+ public void serviceLost();
+
+ public void serviceReplaced();
+ }
+
+ private final BundleContext ctx;
+ private final String className;
+ private final AtomicReference<T> service = new AtomicReference<T>();
+ private final AtomicReference<ServiceReference> ref = new AtomicReference<ServiceReference>();
+ private final AtomicBoolean open = new AtomicBoolean(false);
+ private final SingleServiceListener serviceListener;
+ private String filterString;
+ private Filter filter;
+
+ private final ServiceListener listener = new ServiceListener() {
+ public void serviceChanged(ServiceEvent event) {
+ if (open.get()) {
+ if (event.getType() == ServiceEvent.UNREGISTERING) {
+ ServiceReference deadRef = event.getServiceReference();
+ if (deadRef.equals(ref.get())) {
+ findMatchingReference(deadRef);
+ }
+ } else if (event.getType() == ServiceEvent.REGISTERED && ref.get() == null) {
+ findMatchingReference(null);
+ }
+ }
+ }
+ };
+
+ public SingleServiceTracker(BundleContext context, Class<T> clazz, SingleServiceListener sl) {
+ ctx = context;
+ this.className = clazz.getName();
+ serviceListener = sl;
+ }
+
+ public SingleServiceTracker(BundleContext context, Class<T> clazz, String filterString, SingleServiceListener sl) throws InvalidSyntaxException {
+ this(context, clazz, sl);
+ this.filterString = filterString;
+ if (filterString != null) filter = context.createFilter(filterString);
+ }
+
+ public T getService() {
+ return service.get();
+ }
+
+ public ServiceReference getServiceReference() {
+ return ref.get();
+ }
+
+ public void open() {
+ if (open.compareAndSet(false, true)) {
+ try {
+ String filterString = '(' + Constants.OBJECTCLASS + '=' + className + ')';
+ if (filter != null) filterString = "(&" + filterString + filter + ')';
+ ctx.addServiceListener(listener, filterString);
+ findMatchingReference(null);
+ } catch (InvalidSyntaxException e) {
+ // this can never happen. (famous last words :)
+ }
+ }
+ }
+
+ private void findMatchingReference(ServiceReference original) {
+ boolean clear = true;
+ ServiceReference ref = ctx.getServiceReference(className);
+ if (ref != null && (filter == null || filter.match(ref))) {
+ @SuppressWarnings("unchecked")
+ T service = (T) ctx.getService(ref);
+ if (service != null) {
+ clear = false;
+
+ // We do the unget out of the lock so we don't exit this class while holding a lock.
+ if (!!!update(original, ref, service)) {
+ ctx.ungetService(ref);
+ }
+ }
+ } else if (original == null) {
+ clear = false;
+ }
+
+ if (clear) {
+ update(original, null, null);
+ }
+ }
+
+ private boolean update(ServiceReference deadRef, ServiceReference newRef, T service) {
+ boolean result = false;
+ int foundLostReplaced = -1;
+
+ // Make sure we don't try to get a lock on null
+ Object lock;
+
+ // we have to choose our lock.
+ if (newRef != null) lock = newRef;
+ else if (deadRef != null) lock = deadRef;
+ else lock = this;
+
+ // This lock is here to ensure that no two threads can set the ref and service
+ // at the same time.
+ synchronized (lock) {
+ if (open.get()) {
+ result = this.ref.compareAndSet(deadRef, newRef);
+ if (result) {
+ this.service.set(service);
+
+ if (deadRef == null && newRef != null) foundLostReplaced = 0;
+ if (deadRef != null && newRef == null) foundLostReplaced = 1;
+ if (deadRef != null && newRef != null) foundLostReplaced = 2;
+ }
+ }
+ }
+
+ if (serviceListener != null) {
+ if (foundLostReplaced == 0) serviceListener.serviceFound();
+ else if (foundLostReplaced == 1) serviceListener.serviceLost();
+ else if (foundLostReplaced == 2) serviceListener.serviceReplaced();
+ }
+
+ return result;
+ }
+
+ public void close() {
+ if (open.compareAndSet(true, false)) {
+ ctx.removeServiceListener(listener);
+
+ synchronized (this) {
+ ServiceReference deadRef = ref.getAndSet(null);
+ service.set(null);
+ if (deadRef != null) ctx.ungetService(deadRef);
+ }
+ }
+ }
+}
[03/24] git commit: Fix concurrency issues in shell/core
Posted by gn...@apache.org.
Fix concurrency issues in shell/core
Project: http://git-wip-us.apache.org/repos/asf/karaf/repo
Commit: http://git-wip-us.apache.org/repos/asf/karaf/commit/9483e506
Tree: http://git-wip-us.apache.org/repos/asf/karaf/tree/9483e506
Diff: http://git-wip-us.apache.org/repos/asf/karaf/diff/9483e506
Branch: refs/heads/master
Commit: 9483e50620e379ae05e6d63fd6fbb3a528e48656
Parents: b509da2
Author: Guillaume Nodet <gn...@gmail.com>
Authored: Mon Mar 24 13:17:48 2014 +0100
Committer: Guillaume Nodet <gn...@gmail.com>
Committed: Mon Mar 24 17:30:12 2014 +0100
----------------------------------------------------------------------
.../karaf/shell/impl/console/RegistryImpl.java | 4 +-
.../shell/impl/console/SessionFactoryImpl.java | 54 +++++++++++---------
2 files changed, 31 insertions(+), 27 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/karaf/blob/9483e506/shell/core/src/main/java/org/apache/karaf/shell/impl/console/RegistryImpl.java
----------------------------------------------------------------------
diff --git a/shell/core/src/main/java/org/apache/karaf/shell/impl/console/RegistryImpl.java b/shell/core/src/main/java/org/apache/karaf/shell/impl/console/RegistryImpl.java
index 43ed27e..b607c5e 100644
--- a/shell/core/src/main/java/org/apache/karaf/shell/impl/console/RegistryImpl.java
+++ b/shell/core/src/main/java/org/apache/karaf/shell/impl/console/RegistryImpl.java
@@ -29,8 +29,8 @@ import org.apache.karaf.shell.api.console.Registry;
public class RegistryImpl implements Registry {
- private final Registry parent;
- private final Map<Object, Object> services = new LinkedHashMap<Object, Object>();
+ protected final Registry parent;
+ protected final Map<Object, Object> services = new LinkedHashMap<Object, Object>();
public RegistryImpl(Registry parent) {
this.parent = parent;
http://git-wip-us.apache.org/repos/asf/karaf/blob/9483e506/shell/core/src/main/java/org/apache/karaf/shell/impl/console/SessionFactoryImpl.java
----------------------------------------------------------------------
diff --git a/shell/core/src/main/java/org/apache/karaf/shell/impl/console/SessionFactoryImpl.java b/shell/core/src/main/java/org/apache/karaf/shell/impl/console/SessionFactoryImpl.java
index be7aaea..1a72e33 100644
--- a/shell/core/src/main/java/org/apache/karaf/shell/impl/console/SessionFactoryImpl.java
+++ b/shell/core/src/main/java/org/apache/karaf/shell/impl/console/SessionFactoryImpl.java
@@ -64,21 +64,23 @@ public class SessionFactoryImpl extends RegistryImpl implements SessionFactory,
@Override
public void register(Object service) {
- if (service instanceof Command) {
- Command command = (Command) service;
- String scope = command.getScope();
- String name = command.getName();
- if (!Session.SCOPE_GLOBAL.equals(scope)) {
- if (!subshells.containsKey(scope)) {
- SubShellCommand subShell = new SubShellCommand(scope);
- subshells.put(scope, subShell);
- register(subShell);
+ synchronized (services) {
+ if (service instanceof Command) {
+ Command command = (Command) service;
+ String scope = command.getScope();
+ String name = command.getName();
+ if (!Session.SCOPE_GLOBAL.equals(scope)) {
+ if (!subshells.containsKey(scope)) {
+ SubShellCommand subShell = new SubShellCommand(scope);
+ subshells.put(scope, subShell);
+ register(subShell);
+ }
+ subshells.get(scope).increment();
}
- subshells.get(scope).increment();
+ commandProcessor.addCommand(scope, wrap(command), name);
}
- commandProcessor.addCommand(scope, wrap(command), name);
+ super.register(service);
}
- super.register(service);
}
protected Function wrap(Command command) {
@@ -87,16 +89,18 @@ public class SessionFactoryImpl extends RegistryImpl implements SessionFactory,
@Override
public void unregister(Object service) {
- super.unregister(service);
- if (service instanceof Command) {
- Command command = (Command) service;
- String scope = command.getScope();
- String name = command.getName();
- commandProcessor.removeCommand(scope, name);
- if (!Session.SCOPE_GLOBAL.equals(scope)) {
- if (subshells.get(scope).decrement() == 0) {
- SubShellCommand subShell = subshells.remove(scope);
- unregister(subShell);
+ synchronized (services) {
+ super.unregister(service);
+ if (service instanceof Command) {
+ Command command = (Command) service;
+ String scope = command.getScope();
+ String name = command.getName();
+ commandProcessor.removeCommand(scope, name);
+ if (!Session.SCOPE_GLOBAL.equals(scope)) {
+ if (subshells.get(scope).decrement() == 0) {
+ SubShellCommand subShell = subshells.remove(scope);
+ unregister(subShell);
+ }
}
}
}
@@ -104,7 +108,7 @@ public class SessionFactoryImpl extends RegistryImpl implements SessionFactory,
@Override
public Session create(InputStream in, PrintStream out, PrintStream err, Terminal term, String encoding, Runnable closeCallback) {
- synchronized (this) {
+ synchronized (sessions) {
if (closed) {
throw new IllegalStateException("SessionFactory has been closed");
}
@@ -116,7 +120,7 @@ public class SessionFactoryImpl extends RegistryImpl implements SessionFactory,
@Override
public Session create(InputStream in, PrintStream out, PrintStream err) {
- synchronized (this) {
+ synchronized (sessions) {
if (closed) {
throw new IllegalStateException("SessionFactory has been closed");
}
@@ -127,7 +131,7 @@ public class SessionFactoryImpl extends RegistryImpl implements SessionFactory,
}
public void stop() {
- synchronized (this) {
+ synchronized (sessions) {
closed = true;
for (Session session : sessions) {
session.close();
[19/24] git commit: [KARAF-2833] Make package/core independent of
blueprint
Posted by gn...@apache.org.
[KARAF-2833] Make package/core independent of blueprint
Project: http://git-wip-us.apache.org/repos/asf/karaf/repo
Commit: http://git-wip-us.apache.org/repos/asf/karaf/commit/b355415e
Tree: http://git-wip-us.apache.org/repos/asf/karaf/tree/b355415e
Diff: http://git-wip-us.apache.org/repos/asf/karaf/diff/b355415e
Branch: refs/heads/master
Commit: b355415ec400623154cf872e5ecf0688cb78708e
Parents: 3091414
Author: Guillaume Nodet <gn...@gmail.com>
Authored: Sat Mar 22 16:22:59 2014 +0100
Committer: Guillaume Nodet <gn...@gmail.com>
Committed: Mon Mar 24 17:30:13 2014 +0100
----------------------------------------------------------------------
.../standard/src/main/feature/feature.xml | 1 -
package/core/pom.xml | 4 +
.../packages/core/internal/osgi/Activator.java | 80 ++++++++++++++++++++
.../resources/OSGI-INF/blueprint/blueprint.xml | 40 ----------
4 files changed, 84 insertions(+), 41 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/karaf/blob/b355415e/assemblies/features/standard/src/main/feature/feature.xml
----------------------------------------------------------------------
diff --git a/assemblies/features/standard/src/main/feature/feature.xml b/assemblies/features/standard/src/main/feature/feature.xml
index e6e6f3f..80c14f8 100644
--- a/assemblies/features/standard/src/main/feature/feature.xml
+++ b/assemblies/features/standard/src/main/feature/feature.xml
@@ -168,7 +168,6 @@
</feature>
<feature name="package" version="${project.version}" resolver="(obr)" description="Package commands and mbeans">
- <feature version="${project.version}">aries-blueprint</feature>
<bundle start-level="30">mvn:org.apache.karaf.package/org.apache.karaf.package.core/${project.version}</bundle>
<bundle start-level="30">mvn:org.apache.karaf.package/org.apache.karaf.package.command/${project.version}</bundle>
</feature>
http://git-wip-us.apache.org/repos/asf/karaf/blob/b355415e/package/core/pom.xml
----------------------------------------------------------------------
diff --git a/package/core/pom.xml b/package/core/pom.xml
index 90349a0..6814ee6 100644
--- a/package/core/pom.xml
+++ b/package/core/pom.xml
@@ -96,9 +96,13 @@
</Export-Package>
<Private-Package>
org.apache.karaf.packages.core.internal,
+ org.apache.karaf.packages.core.internal.osgi,
org.apache.felix.utils.version,
org.apache.felix.utils.manifest
</Private-Package>
+ <Bundle-Activator>
+ org.apache.karaf.packages.core.internal.osgi.Activator
+ </Bundle-Activator>
</instructions>
</configuration>
</plugin>
http://git-wip-us.apache.org/repos/asf/karaf/blob/b355415e/package/core/src/main/java/org/apache/karaf/packages/core/internal/osgi/Activator.java
----------------------------------------------------------------------
diff --git a/package/core/src/main/java/org/apache/karaf/packages/core/internal/osgi/Activator.java b/package/core/src/main/java/org/apache/karaf/packages/core/internal/osgi/Activator.java
new file mode 100644
index 0000000..bf906cc
--- /dev/null
+++ b/package/core/src/main/java/org/apache/karaf/packages/core/internal/osgi/Activator.java
@@ -0,0 +1,80 @@
+/*
+ * 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.karaf.packages.core.internal.osgi;
+
+import java.util.ArrayList;
+import java.util.Hashtable;
+import java.util.List;
+
+import javax.management.NotCompliantMBeanException;
+
+import org.apache.karaf.packages.core.PackageService;
+import org.apache.karaf.packages.core.internal.PackageServiceImpl;
+import org.apache.karaf.packages.core.internal.PackagesMBeanImpl;
+import org.osgi.framework.BundleActivator;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceRegistration;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class Activator implements BundleActivator {
+
+ private static final Logger LOGGER = LoggerFactory.getLogger(Activator.class);
+
+ private ServiceRegistration<PackageService> serviceRegistration;
+ private ServiceRegistration mbeanRegistration;
+
+ @Override
+ public void start(BundleContext context) throws Exception {
+ PackageService packageService = new PackageServiceImpl(context);
+ serviceRegistration = context.registerService(PackageService.class, packageService, null);
+ try {
+ PackagesMBeanImpl mbean = new PackagesMBeanImpl(packageService);
+ Hashtable<String, Object> props = new Hashtable<String, Object>();
+ props.put("jmx.objectname", "org.apache.karaf:type=package,name=" + System.getProperty("karaf.name"));
+ mbeanRegistration = context.registerService(
+ getInterfaceNames(mbean),
+ mbean,
+ props
+ );
+ } catch (NotCompliantMBeanException e) {
+ LOGGER.warn("Error creating Packages mbean", e);
+ }
+ }
+
+ @Override
+ public void stop(BundleContext context) throws Exception {
+ mbeanRegistration.unregister();
+ serviceRegistration.unregister();
+ }
+
+ private String[] getInterfaceNames(Object object) {
+ List<String> names = new ArrayList<String>();
+ for (Class cl = object.getClass(); cl != Object.class; cl = cl.getSuperclass()) {
+ addSuperInterfaces(names, cl);
+ }
+ return names.toArray(new String[names.size()]);
+ }
+
+ private void addSuperInterfaces(List<String> names, Class clazz) {
+ for (Class cl : clazz.getInterfaces()) {
+ names.add(cl.getName());
+ addSuperInterfaces(names, cl);
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/karaf/blob/b355415e/package/core/src/main/resources/OSGI-INF/blueprint/blueprint.xml
----------------------------------------------------------------------
diff --git a/package/core/src/main/resources/OSGI-INF/blueprint/blueprint.xml b/package/core/src/main/resources/OSGI-INF/blueprint/blueprint.xml
deleted file mode 100644
index dd4d6f7..0000000
--- a/package/core/src/main/resources/OSGI-INF/blueprint/blueprint.xml
+++ /dev/null
@@ -1,40 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
-
- Licensed to the Apache Software Foundation (ASF) under one or more
- contributor license agreements. See the NOTICE file distributed with
- this work for additional information regarding copyright ownership.
- The ASF licenses this file to You under the Apache License, Version 2.0
- (the "License"); you may not use this file except in compliance with
- the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
-
--->
-<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
- xmlns:ext="http://aries.apache.org/blueprint/xmlns/blueprint-ext/v1.0.0">
-
- <ext:property-placeholder/>
-
- <bean id="packageService" class="org.apache.karaf.packages.core.internal.PackageServiceImpl">
- <argument ref="blueprintBundleContext"/>
- </bean>
- <service interface="org.apache.karaf.packages.core.PackageService" ref="packageService"/>
-
- <bean id="packageMBean" class="org.apache.karaf.packages.core.internal.PackagesMBeanImpl">
- <argument ref="packageService" />
- </bean>
-
- <service ref="packageMBean" auto-export="interfaces">
- <service-properties>
- <entry key="jmx.objectname" value="org.apache.karaf:type=package,name=${karaf.name}"/>
- </service-properties>
- </service>
-
-</blueprint>
[10/24] git commit: [KARAF-2833] Make feature/core independant of
blueprint
Posted by gn...@apache.org.
[KARAF-2833] Make feature/core independant of blueprint
Project: http://git-wip-us.apache.org/repos/asf/karaf/repo
Commit: http://git-wip-us.apache.org/repos/asf/karaf/commit/42ce5d7d
Tree: http://git-wip-us.apache.org/repos/asf/karaf/tree/42ce5d7d
Diff: http://git-wip-us.apache.org/repos/asf/karaf/diff/42ce5d7d
Branch: refs/heads/master
Commit: 42ce5d7d81d9cba6a6d949eae314a9c4087eea92
Parents: 3cf38e7
Author: Guillaume Nodet <gn...@gmail.com>
Authored: Thu Mar 20 10:48:09 2014 +0100
Committer: Guillaume Nodet <gn...@gmail.com>
Committed: Mon Mar 24 17:30:12 2014 +0100
----------------------------------------------------------------------
features/core/pom.xml | 14 +-
.../internal/BootFeaturesInstaller.java | 2 +-
.../features/internal/FeaturesServiceImpl.java | 12 +-
.../karaf/features/internal/osgi/Activator.java | 255 +++++++++++++++++++
.../resources/OSGI-INF/blueprint/blueprint.xml | 107 --------
5 files changed, 274 insertions(+), 116 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/karaf/blob/42ce5d7d/features/core/pom.xml
----------------------------------------------------------------------
diff --git a/features/core/pom.xml b/features/core/pom.xml
index a076786..89d49b8 100644
--- a/features/core/pom.xml
+++ b/features/core/pom.xml
@@ -107,9 +107,10 @@
<configuration>
<instructions>
<Export-Package>
- org.apache.karaf.features,
- org.apache.karaf.features.management,
- org.apache.karaf.features.management.codec
+ org.apache.karaf.features;
+ org.apache.karaf.features.management;
+ org.apache.karaf.features.management.codec;
+ -noimport:=true
</Export-Package>
<Import-Package>
*
@@ -117,11 +118,16 @@
<Private-Package>
org.apache.karaf.features.internal,
org.apache.karaf.features.internal.model,
+ org.apache.karaf.features.internal.osgi,
org.apache.karaf.features.management.internal,
org.apache.felix.utils.version,
org.apache.felix.utils.manifest,
- org.apache.karaf.util.collections
+ org.apache.karaf.util.collections,
+ org.apache.karaf.util.tracker
</Private-Package>
+ <Bundle-Activator>
+ org.apache.karaf.features.internal.osgi.Activator
+ </Bundle-Activator>
</instructions>
</configuration>
</plugin>
http://git-wip-us.apache.org/repos/asf/karaf/blob/42ce5d7d/features/core/src/main/java/org/apache/karaf/features/internal/BootFeaturesInstaller.java
----------------------------------------------------------------------
diff --git a/features/core/src/main/java/org/apache/karaf/features/internal/BootFeaturesInstaller.java b/features/core/src/main/java/org/apache/karaf/features/internal/BootFeaturesInstaller.java
index 531f1b0..1b4fa9d 100644
--- a/features/core/src/main/java/org/apache/karaf/features/internal/BootFeaturesInstaller.java
+++ b/features/core/src/main/java/org/apache/karaf/features/internal/BootFeaturesInstaller.java
@@ -63,7 +63,7 @@ public class BootFeaturesInstaller {
* Install boot features
* @throws Exception
*/
- public void start() throws Exception {
+ public void start() {
if (boot != null) {
if (bootAsynchronous) {
new Thread() {
http://git-wip-us.apache.org/repos/asf/karaf/blob/42ce5d7d/features/core/src/main/java/org/apache/karaf/features/internal/FeaturesServiceImpl.java
----------------------------------------------------------------------
diff --git a/features/core/src/main/java/org/apache/karaf/features/internal/FeaturesServiceImpl.java b/features/core/src/main/java/org/apache/karaf/features/internal/FeaturesServiceImpl.java
index 381ac4c..909a963 100644
--- a/features/core/src/main/java/org/apache/karaf/features/internal/FeaturesServiceImpl.java
+++ b/features/core/src/main/java/org/apache/karaf/features/internal/FeaturesServiceImpl.java
@@ -154,13 +154,17 @@ public class FeaturesServiceImpl implements FeaturesService {
listeners.remove(listener);
}
- public void setUrls(String uris) throws URISyntaxException {
+ public void setUrls(String uris) {
String[] s = uris.split(",");
this.uris = new HashSet<URI>();
for (String value : s) {
value = value.trim();
if (!value.isEmpty()) {
- this.uris.add(new URI(value));
+ try {
+ this.uris.add(new URI(value));
+ } catch (URISyntaxException e) {
+ LOGGER.warn("Invalid features repository URI: " + value);
+ }
}
}
}
@@ -878,12 +882,12 @@ public class FeaturesServiceImpl implements FeaturesService {
}
}
- public void start() throws Exception {
+ public void start() {
this.eventAdminListener = bundleManager.createAndRegisterEventAdminListener();
initState();
}
- public void stop() throws Exception {
+ public void stop() {
stopped.set(true);
uris = new HashSet<URI>(repositories.keySet());
while (!repositories.isEmpty()) {
http://git-wip-us.apache.org/repos/asf/karaf/blob/42ce5d7d/features/core/src/main/java/org/apache/karaf/features/internal/osgi/Activator.java
----------------------------------------------------------------------
diff --git a/features/core/src/main/java/org/apache/karaf/features/internal/osgi/Activator.java b/features/core/src/main/java/org/apache/karaf/features/internal/osgi/Activator.java
new file mode 100644
index 0000000..c6abdb4
--- /dev/null
+++ b/features/core/src/main/java/org/apache/karaf/features/internal/osgi/Activator.java
@@ -0,0 +1,255 @@
+/*
+ * 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.karaf.features.internal.osgi;
+
+import java.io.File;
+import java.io.FileReader;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Hashtable;
+import java.util.List;
+import java.util.Properties;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.TimeUnit;
+
+import javax.management.NotCompliantMBeanException;
+
+import org.apache.karaf.features.FeaturesListener;
+import org.apache.karaf.features.FeaturesService;
+import org.apache.karaf.features.internal.BootFeaturesInstaller;
+import org.apache.karaf.features.internal.BundleManager;
+import org.apache.karaf.features.internal.FeatureConfigInstaller;
+import org.apache.karaf.features.internal.FeatureFinder;
+import org.apache.karaf.features.internal.FeaturesServiceImpl;
+import org.apache.karaf.features.management.internal.FeaturesServiceMBeanImpl;
+import org.apache.karaf.region.persist.RegionsPersistence;
+import org.apache.karaf.util.tracker.SingleServiceTracker;
+import org.osgi.framework.BundleActivator;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.Constants;
+import org.osgi.framework.ServiceReference;
+import org.osgi.framework.ServiceRegistration;
+import org.osgi.service.cm.ConfigurationAdmin;
+import org.osgi.service.cm.ManagedService;
+import org.osgi.service.url.URLStreamHandlerService;
+import org.osgi.util.tracker.ServiceTracker;
+import org.osgi.util.tracker.ServiceTrackerCustomizer;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class Activator implements BundleActivator, SingleServiceTracker.SingleServiceListener {
+
+ private static final Logger LOGGER = LoggerFactory.getLogger(Activator.class);
+
+ private ExecutorService executor = Executors.newSingleThreadExecutor();
+ private BundleContext bundleContext;
+ private SingleServiceTracker<RegionsPersistence> regionsPersistenceTracker;
+ private SingleServiceTracker<URLStreamHandlerService> mvnUrlHandlerTracker;
+ private SingleServiceTracker<ConfigurationAdmin> configurationAdminTracker;
+ private ServiceTracker<FeaturesListener, FeaturesListener> featuresListenerTracker;
+
+ private FeaturesServiceImpl featuresService;
+ private ServiceRegistration<ManagedService> featureFinderRegistration;
+ private ServiceRegistration<FeaturesService> featuresServiceRegistration;
+ private ServiceRegistration featuresServiceMBeanRegistration;
+
+ @Override
+ public void start(BundleContext context) throws Exception {
+ bundleContext = context;
+ regionsPersistenceTracker = new SingleServiceTracker<RegionsPersistence>(
+ bundleContext, RegionsPersistence.class, this
+ );
+ mvnUrlHandlerTracker = new SingleServiceTracker<URLStreamHandlerService>(
+ bundleContext, URLStreamHandlerService.class, "(url.handler.protocol=mvn)", this
+ );
+ configurationAdminTracker = new SingleServiceTracker<ConfigurationAdmin>(
+ bundleContext, ConfigurationAdmin.class, this
+ );
+ regionsPersistenceTracker.open();
+ mvnUrlHandlerTracker.open();
+ configurationAdminTracker.open();
+ }
+
+ @Override
+ public void stop(BundleContext context) throws Exception {
+ configurationAdminTracker.close();
+ mvnUrlHandlerTracker.close();
+ regionsPersistenceTracker.close();
+ executor.shutdown();
+ executor.awaitTermination(30, TimeUnit.SECONDS);
+ }
+
+ protected void doStart() {
+ ConfigurationAdmin configurationAdmin = configurationAdminTracker.getService();
+ RegionsPersistence regionsPersistence = regionsPersistenceTracker.getService();
+ URLStreamHandlerService mvnUrlHandler = mvnUrlHandlerTracker.getService();
+
+ if (configurationAdmin == null || mvnUrlHandler == null) {
+ return;
+ }
+
+ Properties configuration = new Properties();
+ File configFile = new File(System.getProperty("karaf.etc"), "org.apache.karaf.features.cfg");
+ if (configFile.isFile() && configFile.canRead()) {
+ try {
+ configuration.load(new FileReader(configFile));
+ } catch (IOException e) {
+ LOGGER.warn("Error reading configuration file " + configFile.toString(), e);
+ }
+ }
+
+ FeatureFinder featureFinder = new FeatureFinder();
+ Hashtable<String, Object> props = new Hashtable<String, Object>();
+ props.put(Constants.SERVICE_PID, "org.apache.karaf.features.repos");
+ featureFinderRegistration = bundleContext.registerService(ManagedService.class, featureFinder, props);
+
+ BundleManager bundleManager = new BundleManager(bundleContext, regionsPersistence);
+ FeatureConfigInstaller configInstaller = new FeatureConfigInstaller(configurationAdmin);
+ String featuresRepositories = getString(configuration, "featuresRepositories", "");
+ boolean respectStartLvlDuringFeatureStartup = getBoolean(configuration, "respectStartLvlDuringFeatureStartup", true);
+ boolean respectStartLvlDuringFeatureUninstall = getBoolean(configuration, "respectStartLvlDuringFeatureUninstall", true);
+ long resolverTimeout = getLong(configuration, "resolverTimeout", 5000);
+ String overrides = getString(configuration, "overrides", new File(System.getProperty("karaf.etc"), "overrides.properties").toString());
+ featuresService = new FeaturesServiceImpl(bundleManager, configInstaller);
+ featuresService.setUrls(featuresRepositories);
+ featuresService.setRespectStartLvlDuringFeatureStartup(respectStartLvlDuringFeatureStartup);
+ featuresService.setRespectStartLvlDuringFeatureUninstall(respectStartLvlDuringFeatureUninstall);
+ featuresService.setResolverTimeout(resolverTimeout);
+ featuresService.setOverrides(overrides);
+ featuresService.setFeatureFinder(featureFinder);
+ featuresService.start();
+ featuresServiceRegistration = bundleContext.registerService(FeaturesService.class, featuresService, null);
+
+ featuresListenerTracker = new ServiceTracker<FeaturesListener, FeaturesListener>(
+ bundleContext, FeaturesListener.class, new ServiceTrackerCustomizer<FeaturesListener, FeaturesListener>() {
+ @Override
+ public FeaturesListener addingService(ServiceReference<FeaturesListener> reference) {
+ FeaturesListener service = bundleContext.getService(reference);
+ featuresService.registerListener(service);
+ return service;
+ }
+ @Override
+ public void modifiedService(ServiceReference<FeaturesListener> reference, FeaturesListener service) {
+ }
+ @Override
+ public void removedService(ServiceReference<FeaturesListener> reference, FeaturesListener service) {
+ featuresService.unregisterListener(service);
+ bundleContext.ungetService(reference);
+ }
+ }
+ );
+ featuresListenerTracker.open();
+
+ String featuresBoot = getString(configuration, "featuresBoot", "");
+ boolean featuresBootAsynchronous = getBoolean(configuration, "featuresBootAsynchronous", false);
+ BootFeaturesInstaller bootFeaturesInstaller = new BootFeaturesInstaller(bundleContext, featuresService, featuresBoot, featuresBootAsynchronous);
+ bootFeaturesInstaller.start();
+
+ try {
+ FeaturesServiceMBeanImpl featuresServiceMBean = new FeaturesServiceMBeanImpl();
+ featuresServiceMBean.setBundleContext(bundleContext);
+ featuresServiceMBean.setFeaturesService(featuresService);
+ props = new Hashtable<String, Object>();
+ props.put("jmx.objectname", "org.apache.karaf:type=feature,name=" + System.getProperty("karaf.name"));
+ featuresServiceMBeanRegistration = bundleContext.registerService(
+ getInterfaceNames(featuresServiceMBean),
+ featuresServiceMBean,
+ props
+ );
+ } catch (NotCompliantMBeanException e) {
+ LOGGER.warn("Error creating FeaturesService mbean", e);
+ }
+ }
+
+ protected void doStop() {
+ if (featuresListenerTracker != null) {
+ featuresListenerTracker.close();
+ featuresListenerTracker = null;
+ }
+ if (featureFinderRegistration != null) {
+ featureFinderRegistration.unregister();
+ featureFinderRegistration = null;
+ }
+ if (featuresServiceRegistration != null) {
+ featuresServiceRegistration.unregister();
+ featuresServiceRegistration = null;
+ }
+ if (featuresServiceMBeanRegistration != null) {
+ featuresServiceMBeanRegistration.unregister();
+ featuresServiceMBeanRegistration = null;
+ }
+ if (featuresService != null) {
+ featuresService.stop();
+ featuresService = null;
+ }
+ }
+
+ @Override
+ public void serviceFound() {
+ executor.submit(new Runnable() {
+ @Override
+ public void run() {
+ doStop();
+ try {
+ doStart();
+ } catch (Exception e) {
+ LOGGER.warn("Error starting FeaturesService", e);
+ doStop();
+ }
+ }
+ });
+ }
+
+ @Override
+ public void serviceLost() {
+ serviceFound();
+ }
+
+ @Override
+ public void serviceReplaced() {
+ serviceFound();
+ }
+
+ private String[] getInterfaceNames(Object object) {
+ List<String> names = new ArrayList<String>();
+ for (Class cl = object.getClass(); cl != Object.class; cl = cl.getSuperclass()) {
+ addSuperInterfaces(names, cl);
+ }
+ return names.toArray(new String[names.size()]);
+ }
+
+ private void addSuperInterfaces(List<String> names, Class clazz) {
+ for (Class cl : clazz.getInterfaces()) {
+ names.add(cl.getName());
+ addSuperInterfaces(names, cl);
+ }
+ }
+
+ private String getString(Properties configuration, String key, String value) {
+ return configuration.getProperty(key, value);
+ }
+
+ private boolean getBoolean(Properties configuration, String key, boolean value) {
+ return Boolean.parseBoolean(getString(configuration, key, Boolean.toString(value)));
+ }
+
+ private long getLong(Properties configuration, String key, long value) {
+ return Long.parseLong(getString(configuration, key, Long.toString(value)));
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/karaf/blob/42ce5d7d/features/core/src/main/resources/OSGI-INF/blueprint/blueprint.xml
----------------------------------------------------------------------
diff --git a/features/core/src/main/resources/OSGI-INF/blueprint/blueprint.xml b/features/core/src/main/resources/OSGI-INF/blueprint/blueprint.xml
deleted file mode 100644
index 38391be..0000000
--- a/features/core/src/main/resources/OSGI-INF/blueprint/blueprint.xml
+++ /dev/null
@@ -1,107 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
-
- Licensed to the Apache Software Foundation (ASF) under one or more
- contributor license agreements. See the NOTICE file distributed with
- this work for additional information regarding copyright ownership.
- The ASF licenses this file to You under the Apache License, Version 2.0
- (the "License"); you may not use this file except in compliance with
- the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
-
--->
-<blueprint
- xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
- xmlns:ext="http://aries.apache.org/blueprint/xmlns/blueprint-ext/v1.0.0"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="
- http://www.osgi.org/xmlns/blueprint/v1.0.0 http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd
- http://aries.apache.org/blueprint/xmlns/blueprint-ext/v1.0.0 http://aries.apache.org/schemas/blueprint-ext/blueprint-ext.xsd">
-
- <ext:property-placeholder placeholder-prefix="$(" placeholder-suffix=")"/>
-
- <ext:property-placeholder placeholder-prefix="$[" placeholder-suffix="]" ignore-missing-locations="true">
- <ext:default-properties>
- <ext:property name="featuresRepositories" value=""/>
- <ext:property name="featuresBoot" value=""/>
- <ext:property name="resolverTimeout" value="5000"/>
- <ext:property name="respectStartLvlDuringFeatureStartup" value="true"/>
- <ext:property name="respectStartLvlDuringFeatureUninstall" value="true"/>
- <ext:property name="featuresBootAsynchronous" value="false"/>
- <ext:property name="overrides" value="file:$(karaf.etc)/overrides.properties"/>
- </ext:default-properties>
- <ext:location>file:$(karaf.etc)/org.apache.karaf.features.cfg</ext:location>
- </ext:property-placeholder>
-
- <reference-list id="featuresListeners" interface="org.apache.karaf.features.FeaturesListener"
- availability="optional">
-
- <reference-listener ref="featuresService"
- bind-method="registerListener"
- unbind-method="unregisterListener"/>
- </reference-list>
-
- <reference id="configAdmin" interface="org.osgi.service.cm.ConfigurationAdmin"/>
-
- <reference id="mvnUrlHandler" interface="org.osgi.service.url.URLStreamHandlerService"
- filter="(url.handler.protocol=mvn)"/>
-
- <reference id="regionsPersistence" availability="optional"
- interface="org.apache.karaf.region.persist.RegionsPersistence"/>
-
- <bean id="bundleManager" class="org.apache.karaf.features.internal.BundleManager">
- <argument ref="blueprintBundleContext"/>
- <argument ref="regionsPersistence"/>
- </bean>
- <bean id="configInstaller" class="org.apache.karaf.features.internal.FeatureConfigInstaller">
- <argument ref="configAdmin"/>
- </bean>
- <bean id="featuresService" class="org.apache.karaf.features.internal.FeaturesServiceImpl" init-method="start"
- destroy-method="stop">
- <argument ref="bundleManager"/>
- <argument ref="configInstaller"/>
- <property name="urls" value="$[featuresRepositories]"/>
- <property name="respectStartLvlDuringFeatureStartup" value="$[respectStartLvlDuringFeatureStartup]"/>
- <property name="respectStartLvlDuringFeatureUninstall" value="$[respectStartLvlDuringFeatureUninstall]"/>
- <property name="resolverTimeout" value="$[resolverTimeout]"/>
- <property name="overrides" value="$[overrides]"/>
- <property name="featureFinder" ref="featureFinder" />
- </bean>
-
-
- <bean id="featureFinder" class="org.apache.karaf.features.internal.FeatureFinder"/>
- <service ref="featureFinder" interface="org.osgi.service.cm.ManagedService" >
- <service-properties>
- <entry key="service.pid" value="org.apache.karaf.features.repos" />
- </service-properties>
- </service>
-
- <bean id="bootFeaturesInstaller" class="org.apache.karaf.features.internal.BootFeaturesInstaller"
- init-method="start">
- <argument ref="blueprintBundleContext"/>
- <argument ref="featuresService"/>
- <argument value="$[featuresBoot]"/>
- <argument value="$[featuresBootAsynchronous]"/>
- </bean>
-
- <bean id="featuresServiceMBean" class="org.apache.karaf.features.management.internal.FeaturesServiceMBeanImpl">
- <property name="bundleContext" ref="blueprintBundleContext"/>
- <property name="featuresService" ref="featuresService"/>
- </bean>
-
- <service ref="featuresService" interface="org.apache.karaf.features.FeaturesService"/>
-
- <service ref="featuresServiceMBean" auto-export="interfaces">
- <service-properties>
- <entry key="jmx.objectname" value="org.apache.karaf:type=feature,name=$(karaf.name)"/>
- </service-properties>
- </service>
-
-</blueprint>
[07/24] git commit: [KARAF-2834] Create features for aries proxy /
blueprint and various karaf services
Posted by gn...@apache.org.
[KARAF-2834] Create features for aries proxy / blueprint and various karaf services
Project: http://git-wip-us.apache.org/repos/asf/karaf/repo
Commit: http://git-wip-us.apache.org/repos/asf/karaf/commit/a0f482c2
Tree: http://git-wip-us.apache.org/repos/asf/karaf/tree/a0f482c2
Diff: http://git-wip-us.apache.org/repos/asf/karaf/diff/a0f482c2
Branch: refs/heads/master
Commit: a0f482c228bfef1729654ba810ee5949a41db25a
Parents: f652fab
Author: Guillaume Nodet <gn...@gmail.com>
Authored: Thu Mar 20 14:28:36 2014 +0100
Committer: Guillaume Nodet <gn...@gmail.com>
Committed: Mon Mar 24 17:30:12 2014 +0100
----------------------------------------------------------------------
assemblies/features/standard/pom.xml | 10 ++
.../standard/src/main/feature/feature.xml | 134 ++++++++++++++++---
2 files changed, 126 insertions(+), 18 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/karaf/blob/a0f482c2/assemblies/features/standard/pom.xml
----------------------------------------------------------------------
diff --git a/assemblies/features/standard/pom.xml b/assemblies/features/standard/pom.xml
index 458d51c..e27450a 100644
--- a/assemblies/features/standard/pom.xml
+++ b/assemblies/features/standard/pom.xml
@@ -110,6 +110,16 @@
<artifactId>org.apache.karaf.service.command</artifactId>
<scope>provided</scope>
</dependency>
+ <dependency>
+ <groupId>org.apache.karaf.shell</groupId>
+ <artifactId>org.apache.karaf.shell.core</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.karaf.shell</groupId>
+ <artifactId>org.apache.karaf.shell.commands</artifactId>
+ <scope>provided</scope>
+ </dependency>
<!-- aries-annotation deps -->
<dependency>
http://git-wip-us.apache.org/repos/asf/karaf/blob/a0f482c2/assemblies/features/standard/src/main/feature/feature.xml
----------------------------------------------------------------------
diff --git a/assemblies/features/standard/src/main/feature/feature.xml b/assemblies/features/standard/src/main/feature/feature.xml
index 7b7ccbe..b334606 100644
--- a/assemblies/features/standard/src/main/feature/feature.xml
+++ b/assemblies/features/standard/src/main/feature/feature.xml
@@ -22,23 +22,23 @@
<feature version="${project.version}" description="OSGi Security for Karaf" name="framework-security">
<bundle start="false" start-level="1">mvn:org.apache.felix/org.apache.felix.framework.security/${felix.framework.security.version}</bundle>
+ <bundle start="true" start-level="10">mvn:org.apache.karaf.service/org.apache.karaf.service.guard/${project.version}</bundle>
</feature>
<feature name="standard" description="Karaf standard feature" version="${project.version}">
- <bundle start-level="30">mvn:org.apache.karaf.shell/org.apache.karaf.shell.console/${project.version}</bundle>
- <bundle start-level="30">mvn:org.apache.karaf.features/org.apache.karaf.features.core/${project.version}</bundle>
- <bundle start-level="30">mvn:org.apache.karaf.features/org.apache.karaf.features.command/${project.version}</bundle>
- <bundle start-level="30">mvn:org.apache.karaf.instance/org.apache.karaf.instance.core/${project.version}</bundle>
- <bundle start-level="30">mvn:org.apache.karaf.instance/org.apache.karaf.instance.command/${project.version}</bundle>
- <bundle start-level="30">mvn:org.apache.karaf.jaas/org.apache.karaf.jaas.modules/${project.version}</bundle>
- <bundle start-level="30">mvn:org.apache.karaf.jaas/org.apache.karaf.jaas.config/${project.version}</bundle>
- <bundle start-level="30">mvn:org.apache.karaf.jaas/org.apache.karaf.jaas.command/${project.version}</bundle>
- <bundle start-level="30">mvn:org.apache.karaf.diagnostic/org.apache.karaf.diagnostic.core/${project.version}</bundle>
- <bundle start-level="30">mvn:org.apache.karaf.diagnostic/org.apache.karaf.diagnostic.command/${project.version}</bundle>
- <bundle start-level="30">mvn:org.apache.karaf.log/org.apache.karaf.log.core/${project.version}</bundle>
- <bundle start-level="30">mvn:org.apache.karaf.log/org.apache.karaf.log.command/${project.version}</bundle>
- <bundle start-level="30">mvn:org.apache.karaf.service/org.apache.karaf.service.core/${project.version}</bundle>
- <bundle start-level="30">mvn:org.apache.karaf.service/org.apache.karaf.service.command/${project.version}</bundle>
+ <feature>aries-blueprint</feature>
+ <feature>jaas</feature>
+ <feature>ssh</feature>
+ <feature>shell-compat</feature>
+ <feature>bundle</feature>
+ <feature>config</feature>
+ <feature>deployer</feature>
+ <feature>diagnostic</feature>
+ <feature>instance</feature>
+ <feature>log</feature>
+ <feature>service</feature>
+ <feature>system</feature>
+ <feature>package</feature>
<conditional>
<condition>webconsole</condition>
<bundle start-level="30">mvn:org.apache.karaf.webconsole/org.apache.karaf.webconsole.instance/${project.version}</bundle>
@@ -48,7 +48,23 @@
</conditional>
</feature>
+ <feature name="aries-proxy" description="Aries Proxy" version="${project.version}">
+ <bundle dependency="true" start-level="20">mvn:org.ow2.asm/asm-all/${asm.version}</bundle>
+ <bundle dependency="true" start-level="20">mvn:org.apache.aries/org.apache.aries.util/${aries.util.version}</bundle>
+ <bundle start-level="20">mvn:org.apache.aries.proxy/org.apache.aries.proxy.api/${aries.proxy.api.version}</bundle>
+ <bundle start-level="20">mvn:org.apache.aries.proxy/org.apache.aries.proxy.impl/${aries.proxy.version}</bundle>
+ </feature>
+
+ <feature name="aries-blueprint" description="Aries Blueprint" version="${project.version}">
+ <feature version="${project.version}">aries-proxy</feature>
+ <bundle start-level="20">mvn:org.apache.aries.blueprint/org.apache.aries.blueprint.api/${aries.blueprint.api.version}</bundle>
+ <bundle start-level="20">mvn:org.apache.aries.blueprint/org.apache.aries.blueprint.cm/${aries.blueprint.cm.version}</bundle>
+ <bundle start-level="20">mvn:org.apache.aries.blueprint/org.apache.aries.blueprint.core.compatibility/${aries.blueprint.core.compatibility.version}</bundle>
+ <bundle start-level="20">mvn:org.apache.aries.blueprint/org.apache.aries.blueprint.core/${aries.blueprint.core.version}</bundle>
+ </feature>
+
<feature name="aries-annotation" description="Aries Annotations" version="${project.version}">
+ <feature version="${project.version}">aries-blueprint</feature>
<bundle dependency="true" start-level="20">mvn:org.apache.commons/commons-jexl/${commons-jexl.version}</bundle>
<bundle dependency="true" start-level="20">mvn:org.ow2.asm/asm-all/${asm.version}</bundle>
<bundle dependency="true" start-level="20">mvn:org.apache.xbean/xbean-bundleutils/${xbean.version}</bundle>
@@ -60,9 +76,33 @@
<bundle start-level="20">mvn:org.apache.aries.blueprint/org.apache.aries.blueprint.jexl.evaluator/${aries.blueprint.jexl.evaluator.version}</bundle>
</feature>
+ <feature name="shell" description="Karaf Shell" version="${project.version}">
+ <bundle dependency="true" start-level="30">mvn:jline/jline/${jline.version}</bundle>
+ <bundle dependency="true" start-level="30">mvn:org.jledit/core/${jledit.version}</bundle>
+ <bundle start-level="30">mvn:org.apache.karaf.shell/org.apache.karaf.shell.core/${project.version}</bundle>
+ <bundle start-level="30">mvn:org.apache.karaf.shell/org.apache.karaf.shell.commands/${project.version}</bundle>
+ <bundle start-level="30">mvn:org.apache.karaf.features/org.apache.karaf.features.command/${project.version}</bundle>
+ </feature>
+
+ <feature name="shell-compat" description="Karaf Shell Compatibility" version="${project.version}">
+ <feature version="${project.version}">aries-blueprint</feature>
+ <feature version="${project.version}">shell</feature>
+ <bundle start-level="30">mvn:org.apache.karaf.shell/org.apache.karaf.shell.console/${project.version}</bundle>
+ <bundle start-level="30">mvn:org.apache.karaf.shell/org.apache.karaf.shell.table/${project.version}</bundle>
+ </feature>
+
+ <feature name="deployer" description="Karaf Deployer" version="${project.version}">
+ <feature version="${project.version}">aries-blueprint</feature>
+ <bundle start="true" start-level="24">mvn:org.apache.karaf.deployer/org.apache.karaf.deployer.spring/${project.version}</bundle>
+ <bundle start="true" start-level="24">mvn:org.apache.karaf.deployer/org.apache.karaf.deployer.blueprint/${project.version}</bundle>
+ <bundle start="true" start-level="24">mvn:org.apache.karaf.deployer/org.apache.karaf.deployer.wrap/${project.version}</bundle>
+ <bundle start="true" start-level="26">mvn:org.apache.karaf.deployer/org.apache.karaf.deployer.features/${project.version}</bundle>
+ </feature>
+
<!-- NB: this file is not the one really used. This file is used by the karaf-maven-plugin to define the start-level of bundles in the generated feature.xml -->
<feature name="wrapper" description="Provide OS integration" version="${project.version}">
+ <feature version="${project.version}">aries-blueprint</feature>
<bundle start-level="30">mvn:org.apache.karaf.wrapper/org.apache.karaf.wrapper.core/${project.version}</bundle>
<bundle start-level="30">mvn:org.apache.karaf.wrapper/org.apache.karaf.wrapper.command/${project.version}</bundle>
</feature>
@@ -71,6 +111,7 @@
</feature>
<feature name="obr" description="Provide OSGi Bundle Repository (OBR) support" version="${project.version}">
+ <feature version="${project.version}">aries-blueprint</feature>
<bundle start-level="30">mvn:org.apache.felix/org.osgi.service.obr/${felix.obr.version}</bundle>
<bundle start-level="30">mvn:org.apache.felix/org.apache.felix.bundlerepository/${felix.bundlerepository.version}</bundle>
<bundle start-level="30">mvn:org.apache.karaf.obr/org.apache.karaf.obr.core/${project.version}</bundle>
@@ -79,11 +120,43 @@
<bundle start-level="31">mvn:org.apache.karaf.features/org.apache.karaf.features.obr/${project.version}</bundle>
</feature>
+ <feature name="bundle" description="Provide Bundle support" version="${project.version}">
+ <feature version="${project.version}">aries-blueprint</feature>
+ <bundle start-level="30" start="true">mvn:org.apache.karaf.bundle/org.apache.karaf.bundle.core/${project.version}</bundle>
+ <bundle start-level="30" start="true">mvn:org.apache.karaf.bundle/org.apache.karaf.bundle.command/${project.version}</bundle>
+ </feature>
+
<feature name="config" description="Provide OSGi ConfigAdmin support" version="${project.version}">
+ <feature version="${project.version}">aries-blueprint</feature>
<bundle start-level="30" start="true">mvn:org.apache.karaf.config/org.apache.karaf.config.core/${project.version}</bundle>
<bundle start-level="30" start="true">mvn:org.apache.karaf.config/org.apache.karaf.config.command/${project.version}</bundle>
</feature>
+ <feature name="diagnostic" description="Provide Diagnostic support" version="${project.version}">
+ <feature version="${project.version}">aries-blueprint</feature>
+ <bundle start-level="30" start="true">mvn:org.apache.karaf.diagnostic/org.apache.karaf.diagnostic.core/${project.version}</bundle>
+ <bundle start-level="30" start="true">mvn:org.apache.karaf.diagnostic/org.apache.karaf.diagnostic.command/${project.version}</bundle>
+ </feature>
+
+ <feature name="instance" description="Provide Instance support" version="${project.version}">
+ <feature version="${project.version}">aries-blueprint</feature>
+ <bundle start-level="30" start="true">mvn:org.apache.karaf.instance/org.apache.karaf.instance.core/${project.version}</bundle>
+ <bundle start-level="30" start="true">mvn:org.apache.karaf.instance/org.apache.karaf.instance.command/${project.version}</bundle>
+ </feature>
+
+ <feature name="jaas" description="Provide JAAS support" version="${project.version}">
+ <feature version="${project.version}">aries-blueprint</feature>
+ <bundle start-level="30" start="true">mvn:org.apache.karaf.jaas/org.apache.karaf.jaas.config/${project.version}</bundle>
+ <bundle start-level="30" start="true">mvn:org.apache.karaf.jaas/org.apache.karaf.jaas.modules/${project.version}</bundle>
+ <bundle start-level="30" start="true">mvn:org.apache.karaf.jaas/org.apache.karaf.jaas.command/${project.version}</bundle>
+ </feature>
+
+ <feature name="log" description="Provide Log support" version="${project.version}">
+ <feature version="${project.version}">aries-blueprint</feature>
+ <bundle start-level="30" start="true">mvn:org.apache.karaf.log/org.apache.karaf.log.core/${project.version}</bundle>
+ <bundle start-level="30" start="true">mvn:org.apache.karaf.log/org.apache.karaf.log.command/${project.version}</bundle>
+ </feature>
+
<feature name="region" description="Provide Region Support" version="${project.version}">
<bundle start-level="30">mvn:org.eclipse.equinox/region/${equinox.region.version}</bundle>
<bundle start-level="30">mvn:org.apache.karaf.region/org.apache.karaf.region.persist/${project.version}</bundle>
@@ -91,10 +164,23 @@
</feature>
<feature name="package" version="${project.version}" resolver="(obr)" description="Package commands and mbeans">
+ <feature version="${project.version}">aries-blueprint</feature>
<bundle start-level="30">mvn:org.apache.karaf.package/org.apache.karaf.package.core/${project.version}</bundle>
<bundle start-level="30">mvn:org.apache.karaf.package/org.apache.karaf.package.command/${project.version}</bundle>
</feature>
+ <feature name="service" description="Provide Service support" version="${project.version}">
+ <feature version="${project.version}">aries-blueprint</feature>
+ <bundle start-level="30" start="true">mvn:org.apache.karaf.service/org.apache.karaf.service.core/${project.version}</bundle>
+ <bundle start-level="30" start="true">mvn:org.apache.karaf.service/org.apache.karaf.service.command/${project.version}</bundle>
+ </feature>
+
+ <feature name="system" description="Provide System support" version="${project.version}">
+ <feature version="${project.version}">aries-blueprint</feature>
+ <bundle start-level="30" start="true">mvn:org.apache.karaf.system/org.apache.karaf.system.core/${project.version}</bundle>
+ <bundle start-level="30" start="true">mvn:org.apache.karaf.system/org.apache.karaf.system.command/${project.version}</bundle>
+ </feature>
+
<feature name="http" version="${project.version}" resolver="(obr)" description="Implementation of the OSGI HTTP Service">
<feature version="${pax.web.version}">pax-http</feature>
<bundle start-level="30">mvn:org.apache.karaf.http/org.apache.karaf.http.core/${project.version}</bundle>
@@ -107,7 +193,7 @@
</feature>
<feature name="war" description="Turn Karaf as a full WebContainer" version="${project.version}" resolver="(obr)">
- <feature>http</feature>
+ <feature version="${project.version}">http</feature>
<feature version="${pax.web.version}">pax-war</feature>
<bundle start-level="30">mvn:org.apache.karaf.web/org.apache.karaf.web.core/${project.version}</bundle>
<bundle start-level="30">mvn:org.apache.karaf.web/org.apache.karaf.web.command/${project.version}</bundle>
@@ -118,9 +204,13 @@
</feature>
<feature name="kar" description="Provide KAR (KARaf archive) support" version="${project.version}" resolver="(obr)">
+ <feature version="${project.version}">aries-blueprint</feature>
<bundle start-level="30">mvn:org.apache.karaf.kar/org.apache.karaf.kar.core/${project.version}</bundle>
<bundle start-level="30">mvn:org.apache.karaf.kar/org.apache.karaf.kar.command/${project.version}</bundle>
- <bundle start-level="30">mvn:org.apache.karaf.deployer/org.apache.karaf.deployer.kar/${project.version}</bundle>
+ <conditional>
+ <condition>deployer</condition>
+ <bundle start-level="30">mvn:org.apache.karaf.deployer/org.apache.karaf.deployer.kar/${project.version}</bundle>
+ </conditional>
</feature>
<feature name="webconsole" description="Base support of the Karaf WebConsole" version="${project.version}" resolver="(obr)">
@@ -148,18 +238,26 @@
sshRealm=karaf
hostKey=${karaf.etc}/host.key
</config>
+ <feature version="${project.version}">shell</feature>
+ <feature version="${project.version}">jaas</feature>
<bundle start="true" start-level="30">mvn:org.apache.mina/mina-core/${mina.version}</bundle>
<bundle start="true" start-level="30">mvn:org.apache.sshd/sshd-core/${sshd.version}</bundle>
<bundle start="true" start-level="30">mvn:org.apache.karaf.shell/org.apache.karaf.shell.ssh/${project.version}</bundle>
</feature>
<feature name="management" description="Provide a JMX MBeanServer and a set of MBeans in Karaf" version="${project.version}">
+ <feature version="${project.version}">jaas</feature>
+ <feature version="${project.version}">aries-blueprint</feature>
+ <bundle dependency="true" start-level="20">mvn:org.apache.aries/org.apache.aries.util/${aries.util.version}</bundle>
<bundle start-level="30">mvn:org.apache.karaf.management/org.apache.karaf.management.server/${project.version}</bundle>
<bundle start-level="30">mvn:org.apache.aries.jmx/org.apache.aries.jmx.api/${aries.jmx.api.version}</bundle>
<bundle start-level="30">mvn:org.apache.aries.jmx/org.apache.aries.jmx.core/${aries.jmx.core.version}</bundle>
- <bundle start-level="30">mvn:org.apache.aries.jmx/org.apache.aries.jmx.blueprint.api/${aries.jmx.blueprint.api.version}</bundle>
- <bundle start-level="30">mvn:org.apache.aries.jmx/org.apache.aries.jmx.blueprint.core/${aries.jmx.blueprint.core.version}</bundle>
<bundle start-level="30">mvn:org.apache.aries.jmx/org.apache.aries.jmx.whiteboard/${aries.jmx.whiteboard.version}</bundle>
+ <conditional>
+ <condition>aries-blueprint</condition>
+ <bundle start-level="30">mvn:org.apache.aries.jmx/org.apache.aries.jmx.blueprint.api/${aries.jmx.blueprint.api.version}</bundle>
+ <bundle start-level="30">mvn:org.apache.aries.jmx/org.apache.aries.jmx.blueprint.core/${aries.jmx.blueprint.core.version}</bundle>
+ </conditional>
</feature>
<feature name="scheduler" description="Provide a scheduler service in Karaf to fire events" version="${project.version}" resolver="(obr)">
[11/24] git commit: [KARAF-2833] Make deployer/* independent of
blueprint
Posted by gn...@apache.org.
[KARAF-2833] Make deployer/* independent of blueprint
Project: http://git-wip-us.apache.org/repos/asf/karaf/repo
Commit: http://git-wip-us.apache.org/repos/asf/karaf/commit/7373515e
Tree: http://git-wip-us.apache.org/repos/asf/karaf/tree/7373515e
Diff: http://git-wip-us.apache.org/repos/asf/karaf/diff/7373515e
Branch: refs/heads/master
Commit: 7373515e77fc9ab19e32526dcb7c545af471c5d6
Parents: 60c0f82
Author: Guillaume Nodet <gn...@gmail.com>
Authored: Sun Mar 23 15:50:16 2014 +0100
Committer: Guillaume Nodet <gn...@gmail.com>
Committed: Mon Mar 24 17:30:13 2014 +0100
----------------------------------------------------------------------
.../standard/src/main/feature/feature.xml | 19 ++-
deployer/blueprint/pom.xml | 7 +-
.../deployer/blueprint/osgi/Activator.java | 59 ++++++++
.../OSGI-INF/blueprint/blueprint-deployer.xml | 40 -----
deployer/features/pom.xml | 10 +-
.../features/FeatureDeploymentListener.java | 2 +-
.../karaf/deployer/features/osgi/Activator.java | 147 +++++++++++++++++++
.../OSGI-INF/blueprint/features-deployer.xml | 47 ------
deployer/kar/pom.xml | 18 ++-
.../karaf/deployer/kar/osgi/Activator.java | 81 ++++++++++
.../OSGI-INF/blueprint/kar-deployer.xml | 34 -----
deployer/spring/pom.xml | 7 +-
.../karaf/deployer/spring/osgi/Activator.java | 59 ++++++++
.../OSGI-INF/blueprint/spring-deployer.xml | 40 -----
deployer/wrap/pom.xml | 8 +-
.../karaf/deployer/wrap/osgi/Activator.java | 74 ++++++++++
.../OSGI-INF/blueprint/wrap-deployer.xml | 30 ----
.../util/tracker/SingleServiceTracker.java | 40 +++--
18 files changed, 491 insertions(+), 231 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/karaf/blob/7373515e/assemblies/features/standard/src/main/feature/feature.xml
----------------------------------------------------------------------
diff --git a/assemblies/features/standard/src/main/feature/feature.xml b/assemblies/features/standard/src/main/feature/feature.xml
index 8979b32..4d49c44 100644
--- a/assemblies/features/standard/src/main/feature/feature.xml
+++ b/assemblies/features/standard/src/main/feature/feature.xml
@@ -96,11 +96,20 @@
</feature>
<feature name="deployer" description="Karaf Deployer" version="${project.version}">
- <feature version="${project.version}">aries-blueprint</feature>
- <bundle start="true" start-level="24">mvn:org.apache.karaf.deployer/org.apache.karaf.deployer.spring/${project.version}</bundle>
- <bundle start="true" start-level="24">mvn:org.apache.karaf.deployer/org.apache.karaf.deployer.blueprint/${project.version}</bundle>
<bundle start="true" start-level="24">mvn:org.apache.karaf.deployer/org.apache.karaf.deployer.wrap/${project.version}</bundle>
<bundle start="true" start-level="26">mvn:org.apache.karaf.deployer/org.apache.karaf.deployer.features/${project.version}</bundle>
+ <conditional>
+ <condition>aries-blueprint</condition>
+ <bundle start="true" start-level="24">mvn:org.apache.karaf.deployer/org.apache.karaf.deployer.blueprint/${project.version}</bundle>
+ </conditional>
+ <conditional>
+ <condition>spring</condition>
+ <bundle start="true" start-level="24">mvn:org.apache.karaf.deployer/org.apache.karaf.deployer.spring/${project.version}</bundle>
+ </conditional>
+ <conditional>
+ <condition>kar</condition>
+ <bundle start="true" start-level="24">mvn:org.apache.karaf.deployer/org.apache.karaf.deployer.kar/${project.version}</bundle>
+ </conditional>
</feature>
<!-- NB: this file is not the one really used. This file is used by the karaf-maven-plugin to define the start-level of bundles in the generated feature.xml -->
@@ -205,10 +214,6 @@
<feature name="kar" description="Provide KAR (KARaf archive) support" version="${project.version}" resolver="(obr)">
<bundle start-level="30">mvn:org.apache.karaf.kar/org.apache.karaf.kar.core/${project.version}</bundle>
<bundle start-level="30">mvn:org.apache.karaf.kar/org.apache.karaf.kar.command/${project.version}</bundle>
- <conditional>
- <condition>deployer</condition>
- <bundle start-level="30">mvn:org.apache.karaf.deployer/org.apache.karaf.deployer.kar/${project.version}</bundle>
- </conditional>
</feature>
<feature name="webconsole" description="Base support of the Karaf WebConsole" version="${project.version}" resolver="(obr)">
http://git-wip-us.apache.org/repos/asf/karaf/blob/7373515e/deployer/blueprint/pom.xml
----------------------------------------------------------------------
diff --git a/deployer/blueprint/pom.xml b/deployer/blueprint/pom.xml
index ef21812..c04c571 100644
--- a/deployer/blueprint/pom.xml
+++ b/deployer/blueprint/pom.xml
@@ -88,14 +88,15 @@
<artifactId>maven-bundle-plugin</artifactId>
<configuration>
<instructions>
- <!-- Set the blueprint.graceperiod flag to false to allow the bundle to start
- See the blueprint config file -->
- <Bundle-SymbolicName>${project.artifactId};blueprint.graceperiod:=false</Bundle-SymbolicName>
<Export-Package />
<Private-Package>
org.apache.karaf.deployer.blueprint,
+ org.apache.karaf.deployer.blueprint.osgi,
org.apache.karaf.util
</Private-Package>
+ <Bundle-Activator>
+ org.apache.karaf.deployer.blueprint.osgi.Activator
+ </Bundle-Activator>
</instructions>
</configuration>
</plugin>
http://git-wip-us.apache.org/repos/asf/karaf/blob/7373515e/deployer/blueprint/src/main/java/org/apache/karaf/deployer/blueprint/osgi/Activator.java
----------------------------------------------------------------------
diff --git a/deployer/blueprint/src/main/java/org/apache/karaf/deployer/blueprint/osgi/Activator.java b/deployer/blueprint/src/main/java/org/apache/karaf/deployer/blueprint/osgi/Activator.java
new file mode 100644
index 0000000..96057bb
--- /dev/null
+++ b/deployer/blueprint/src/main/java/org/apache/karaf/deployer/blueprint/osgi/Activator.java
@@ -0,0 +1,59 @@
+/**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.karaf.deployer.blueprint.osgi;
+
+import java.util.Hashtable;
+
+import org.apache.felix.fileinstall.ArtifactListener;
+import org.apache.felix.fileinstall.ArtifactUrlTransformer;
+import org.apache.karaf.deployer.blueprint.BlueprintDeploymentListener;
+import org.apache.karaf.deployer.blueprint.BlueprintURLHandler;
+import org.osgi.framework.BundleActivator;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceRegistration;
+import org.osgi.service.url.URLStreamHandlerService;
+
+public class Activator implements BundleActivator {
+
+ private ServiceRegistration urlHandlerRegistration;
+ private ServiceRegistration urlTransformerRegistration;
+
+ @Override
+ public void start(BundleContext context) throws Exception {
+ Hashtable<String, Object> props = new Hashtable<String, Object>();
+ props.put("url.handler.protocol", "blueprint");
+ urlHandlerRegistration = context.registerService(
+ URLStreamHandlerService.class,
+ new BlueprintURLHandler(),
+ props);
+
+ urlTransformerRegistration = context.registerService(
+ new String[] {
+ ArtifactUrlTransformer.class.getName(),
+ ArtifactListener.class.getName()
+ },
+ new BlueprintDeploymentListener(),
+ null);
+ }
+
+ @Override
+ public void stop(BundleContext context) throws Exception {
+ urlTransformerRegistration.unregister();
+ urlHandlerRegistration.unregister();
+ }
+}
http://git-wip-us.apache.org/repos/asf/karaf/blob/7373515e/deployer/blueprint/src/main/resources/OSGI-INF/blueprint/blueprint-deployer.xml
----------------------------------------------------------------------
diff --git a/deployer/blueprint/src/main/resources/OSGI-INF/blueprint/blueprint-deployer.xml b/deployer/blueprint/src/main/resources/OSGI-INF/blueprint/blueprint-deployer.xml
deleted file mode 100644
index 8f94e4c..0000000
--- a/deployer/blueprint/src/main/resources/OSGI-INF/blueprint/blueprint-deployer.xml
+++ /dev/null
@@ -1,40 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
-
- Licensed to the Apache Software Foundation (ASF) under one or more
- contributor license agreements. See the NOTICE file distributed with
- this work for additional information regarding copyright ownership.
- The ASF licenses this file to You under the Apache License, Version 2.0
- (the "License"); you may not use this file except in compliance with
- the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
-
--->
-<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0" default-activation="lazy">
-
- <service id="blueprintUrlHandler" interface="org.osgi.service.url.URLStreamHandlerService">
- <service-properties>
- <entry key="url.handler.protocol" value="blueprint"/>
- </service-properties>
- <bean class="org.apache.karaf.deployer.blueprint.BlueprintURLHandler"/>
- </service>
-
- <bean id="blueprintDeploymentListener" class="org.apache.karaf.deployer.blueprint.BlueprintDeploymentListener"/>
-
- <!-- Force a reference to the url handler above from the bundles registry to (try to) make sure
- the url handler is registered inside the framework. Else we can run into timing issues
- where fileinstall will use the featureDeploymentListener before the url can be actually
- used. In order to not block the bundle, the blueprint.graceperiod=false flag must be
- set on the SymbolicName bundles header -->
- <reference id="blueprintUrlHandlerRef" interface="org.osgi.service.url.URLStreamHandlerService" filter="url.handler.protocol=blueprint" />
-
- <service ref="blueprintDeploymentListener" auto-export="interfaces" depends-on="blueprintDeploymentListener" />
-
-</blueprint>
http://git-wip-us.apache.org/repos/asf/karaf/blob/7373515e/deployer/features/pom.xml
----------------------------------------------------------------------
diff --git a/deployer/features/pom.xml b/deployer/features/pom.xml
index ebcbed1..93cb36a 100644
--- a/deployer/features/pom.xml
+++ b/deployer/features/pom.xml
@@ -91,14 +91,16 @@
<artifactId>maven-bundle-plugin</artifactId>
<configuration>
<instructions>
- <!-- Set the blueprint.graceperiod flag to false to allow the bundle to start
- See the blueprint config file -->
- <Bundle-SymbolicName>${project.artifactId};blueprint.graceperiod:=false</Bundle-SymbolicName>
<Export-Package />
<Private-Package>
org.apache.karaf.deployer.features,
- org.apache.karaf.util
+ org.apache.karaf.deployer.features.osgi,
+ org.apache.karaf.util,
+ org.apache.karaf.util.tracker
</Private-Package>
+ <Bundle-Activator>
+ org.apache.karaf.deployer.features.osgi.Activator
+ </Bundle-Activator>
</instructions>
</configuration>
</plugin>
http://git-wip-us.apache.org/repos/asf/karaf/blob/7373515e/deployer/features/src/main/java/org/apache/karaf/deployer/features/FeatureDeploymentListener.java
----------------------------------------------------------------------
diff --git a/deployer/features/src/main/java/org/apache/karaf/deployer/features/FeatureDeploymentListener.java b/deployer/features/src/main/java/org/apache/karaf/deployer/features/FeatureDeploymentListener.java
index 1ef86c3..5f95daa 100644
--- a/deployer/features/src/main/java/org/apache/karaf/deployer/features/FeatureDeploymentListener.java
+++ b/deployer/features/src/main/java/org/apache/karaf/deployer/features/FeatureDeploymentListener.java
@@ -98,7 +98,7 @@ public class FeatureDeploymentListener implements ArtifactUrlTransformer, Bundle
}
}
- public void destroy() throws Exception {
+ public void destroy() {
bundleContext.removeBundleListener(this);
}
http://git-wip-us.apache.org/repos/asf/karaf/blob/7373515e/deployer/features/src/main/java/org/apache/karaf/deployer/features/osgi/Activator.java
----------------------------------------------------------------------
diff --git a/deployer/features/src/main/java/org/apache/karaf/deployer/features/osgi/Activator.java b/deployer/features/src/main/java/org/apache/karaf/deployer/features/osgi/Activator.java
new file mode 100644
index 0000000..51f9725
--- /dev/null
+++ b/deployer/features/src/main/java/org/apache/karaf/deployer/features/osgi/Activator.java
@@ -0,0 +1,147 @@
+/**
+ *
+ * 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.karaf.deployer.features.osgi;
+
+import java.util.Hashtable;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicBoolean;
+
+import org.apache.felix.fileinstall.ArtifactListener;
+import org.apache.felix.fileinstall.ArtifactUrlTransformer;
+import org.apache.karaf.deployer.features.FeatureDeploymentListener;
+import org.apache.karaf.deployer.features.FeatureURLHandler;
+import org.apache.karaf.features.FeaturesService;
+import org.apache.karaf.util.tracker.SingleServiceTracker;
+import org.osgi.framework.BundleActivator;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceRegistration;
+import org.osgi.service.url.URLStreamHandlerService;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class Activator implements BundleActivator, SingleServiceTracker.SingleServiceListener {
+
+ private static final Logger LOGGER = LoggerFactory.getLogger(Activator.class);
+
+ private ExecutorService executor = Executors.newSingleThreadExecutor();
+ private AtomicBoolean scheduled = new AtomicBoolean();
+ private BundleContext bundleContext;
+ private ServiceRegistration urlHandlerRegistration;
+ private ServiceRegistration urlTransformerRegistration;
+ private SingleServiceTracker<FeaturesService> featuresServiceTracker;
+ private FeatureDeploymentListener listener;
+
+ @Override
+ public void start(BundleContext context) throws Exception {
+ bundleContext = context;
+ scheduled.set(true);
+
+ featuresServiceTracker = new SingleServiceTracker<FeaturesService>(
+ context, FeaturesService.class, this);
+ featuresServiceTracker.open();
+
+ scheduled.set(false);
+ reconfigure();
+ }
+
+ @Override
+ public void stop(BundleContext context) throws Exception {
+ featuresServiceTracker.close();
+ executor.shutdown();
+ executor.awaitTermination(30, TimeUnit.SECONDS);
+ }
+
+ @Override
+ public void serviceFound() {
+ reconfigure();
+ }
+
+ @Override
+ public void serviceLost() {
+ reconfigure();
+ }
+
+ @Override
+ public void serviceReplaced() {
+ reconfigure();
+ }
+
+ protected void reconfigure() {
+ if (scheduled.compareAndSet(false, true)) {
+ executor.submit(new Runnable() {
+ @Override
+ public void run() {
+ scheduled.set(false);
+ doStop();
+ try {
+ doStart();
+ } catch (Exception e) {
+ LOGGER.warn("Error starting features deployer", e);
+ doStop();
+ }
+ }
+ });
+ }
+ }
+
+ protected void doStart() throws Exception {
+ FeaturesService service = featuresServiceTracker.getService();
+ if (service == null) {
+ return;
+ }
+
+ Hashtable<String, Object> props = new Hashtable<String, Object>();
+ props.put("url.handler.protocol", "feature");
+ FeatureURLHandler handler = new FeatureURLHandler();
+ urlHandlerRegistration = bundleContext.registerService(
+ URLStreamHandlerService.class,
+ handler,
+ props);
+
+ listener = new FeatureDeploymentListener();
+ listener.setFeaturesService(service);
+ listener.setBundleContext(bundleContext);
+ listener.init();
+
+ urlTransformerRegistration = bundleContext.registerService(
+ new String[] {
+ ArtifactUrlTransformer.class.getName(),
+ ArtifactListener.class.getName()
+ },
+ listener,
+ null);
+ }
+
+ protected void doStop() {
+ if (urlTransformerRegistration != null) {
+ urlTransformerRegistration.unregister();
+ urlTransformerRegistration = null;
+ }
+ if (urlHandlerRegistration != null) {
+ urlHandlerRegistration.unregister();
+ urlHandlerRegistration = null;
+ }
+ if (listener != null) {
+ listener.destroy();
+ listener = null;
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/karaf/blob/7373515e/deployer/features/src/main/resources/OSGI-INF/blueprint/features-deployer.xml
----------------------------------------------------------------------
diff --git a/deployer/features/src/main/resources/OSGI-INF/blueprint/features-deployer.xml b/deployer/features/src/main/resources/OSGI-INF/blueprint/features-deployer.xml
deleted file mode 100644
index 40585cc..0000000
--- a/deployer/features/src/main/resources/OSGI-INF/blueprint/features-deployer.xml
+++ /dev/null
@@ -1,47 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
-
- Licensed to the Apache Software Foundation (ASF) under one or more
- contributor license agreements. See the NOTICE file distributed with
- this work for additional information regarding copyright ownership.
- The ASF licenses this file to You under the Apache License, Version 2.0
- (the "License"); you may not use this file except in compliance with
- the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
-
--->
-<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
- default-activation="lazy">
-
- <service id="featureUrlHandler" interface="org.osgi.service.url.URLStreamHandlerService">
- <service-properties>
- <entry key="url.handler.protocol" value="feature"/>
- </service-properties>
- <bean class="org.apache.karaf.deployer.features.FeatureURLHandler"/>
- </service>
-
- <bean id="featureDeploymentListener" class="org.apache.karaf.deployer.features.FeatureDeploymentListener"
- init-method="init" destroy-method="destroy" activation="lazy">
- <property name="bundleContext" ref="blueprintBundleContext"/>
- <property name="featuresService">
- <reference interface="org.apache.karaf.features.FeaturesService"/>
- </property>
- </bean>
-
- <!-- Force a reference to the url handler above from the bundles registry to (try to) make sure
- the url handler is registered inside the framework. Else we can run into timing issues
- where fileinstall will use the featureDeploymentListener before the url can be actually
- used. In order to not block the bundle, the blueprint.graceperiod=false flag must be
- set on the SymbolicName bundles header -->
- <reference id="featureUrlHandlerRef" interface="org.osgi.service.url.URLStreamHandlerService" filter="url.handler.protocol=feature" />
-
- <service ref="featureDeploymentListener" auto-export="interfaces" depends-on="featureUrlHandlerRef"/>
-
-</blueprint>
http://git-wip-us.apache.org/repos/asf/karaf/blob/7373515e/deployer/kar/pom.xml
----------------------------------------------------------------------
diff --git a/deployer/kar/pom.xml b/deployer/kar/pom.xml
index 607a89b..7b6d26b 100644
--- a/deployer/kar/pom.xml
+++ b/deployer/kar/pom.xml
@@ -60,6 +60,12 @@
</dependency>
<dependency>
+ <groupId>org.apache.karaf</groupId>
+ <artifactId>org.apache.karaf.util</artifactId>
+ <scope>provided</scope>
+ </dependency>
+
+ <dependency>
<groupId>org.apache.felix</groupId>
<artifactId>org.apache.felix.fileinstall</artifactId>
<scope>provided</scope>
@@ -88,11 +94,15 @@
<artifactId>maven-bundle-plugin</artifactId>
<configuration>
<instructions>
- <!-- Set the blueprint.graceperiod flag to false to allow the bundle to start
- See the blueprint config file -->
- <Bundle-SymbolicName>${project.artifactId};blueprint.graceperiod:=false</Bundle-SymbolicName>
<Export-Package />
- <Private-Package>org.apache.karaf.deployer.kar</Private-Package>
+ <Private-Package>
+ org.apache.karaf.deployer.kar,
+ org.apache.karaf.deployer.kar.osgi,
+ org.apache.karaf.util.tracker
+ </Private-Package>
+ <Bundle-Activator>
+ org.apache.karaf.deployer.kar.osgi.Activator
+ </Bundle-Activator>
</instructions>
</configuration>
</plugin>
http://git-wip-us.apache.org/repos/asf/karaf/blob/7373515e/deployer/kar/src/main/java/org/apache/karaf/deployer/kar/osgi/Activator.java
----------------------------------------------------------------------
diff --git a/deployer/kar/src/main/java/org/apache/karaf/deployer/kar/osgi/Activator.java b/deployer/kar/src/main/java/org/apache/karaf/deployer/kar/osgi/Activator.java
new file mode 100644
index 0000000..1b5038f
--- /dev/null
+++ b/deployer/kar/src/main/java/org/apache/karaf/deployer/kar/osgi/Activator.java
@@ -0,0 +1,81 @@
+/**
+ *
+ * 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.karaf.deployer.kar.osgi;
+
+import java.util.Hashtable;
+
+import org.apache.felix.fileinstall.ArtifactInstaller;
+import org.apache.felix.fileinstall.ArtifactListener;
+import org.apache.karaf.deployer.kar.KarArtifactInstaller;
+import org.apache.karaf.kar.KarService;
+import org.apache.karaf.util.tracker.SingleServiceTracker;
+import org.osgi.framework.BundleActivator;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceRegistration;
+
+public class Activator implements BundleActivator, SingleServiceTracker.SingleServiceListener {
+
+ private BundleContext bundleContext;
+ private ServiceRegistration urlTransformerRegistration;
+ private SingleServiceTracker<KarService> karServiceTracker;
+
+ @Override
+ public void start(BundleContext context) throws Exception {
+ bundleContext = context;
+ karServiceTracker = new SingleServiceTracker<KarService>(
+ context, KarService.class, this);
+ karServiceTracker.open();
+ }
+
+ @Override
+ public void stop(BundleContext context) throws Exception {
+ karServiceTracker.close();
+ }
+
+ @Override
+ public void serviceFound() {
+ KarService service = karServiceTracker.getService();
+ if (urlTransformerRegistration == null && service != null) {
+ KarArtifactInstaller installer = new KarArtifactInstaller();
+ installer.setKarService(service);
+ Hashtable<String, Object> props = new Hashtable<String, Object>();
+ urlTransformerRegistration = bundleContext.registerService(
+ new String[] {
+ ArtifactInstaller.class.getName(),
+ ArtifactListener.class.getName()
+ },
+ installer,
+ null);
+ }
+ }
+
+ @Override
+ public void serviceLost() {
+ if (urlTransformerRegistration != null) {
+ urlTransformerRegistration.unregister();
+ urlTransformerRegistration = null;
+ }
+ }
+
+ @Override
+ public void serviceReplaced() {
+ serviceLost();
+ serviceFound();
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/karaf/blob/7373515e/deployer/kar/src/main/resources/OSGI-INF/blueprint/kar-deployer.xml
----------------------------------------------------------------------
diff --git a/deployer/kar/src/main/resources/OSGI-INF/blueprint/kar-deployer.xml b/deployer/kar/src/main/resources/OSGI-INF/blueprint/kar-deployer.xml
deleted file mode 100644
index 7095a31..0000000
--- a/deployer/kar/src/main/resources/OSGI-INF/blueprint/kar-deployer.xml
+++ /dev/null
@@ -1,34 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
- <!--
-
- Licensed to the Apache Software Foundation (ASF) under one or more
- contributor license agreements. See the NOTICE file distributed with
- this work for additional information regarding copyright ownership.
- The ASF licenses this file to You under the Apache License, Version
- 2.0 (the "License"); you may not use this file except in compliance
- with the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0 Unless required by
- applicable law or agreed to in writing, software distributed under the
- License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
- CONDITIONS OF ANY KIND, either express or implied. See the License for
- the specific language governing permissions and limitations under the
- License.
- -->
-<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
- xmlns:ext="http://aries.apache.org/blueprint/xmlns/blueprint-ext/v1.0.0"
- default-activation="lazy">
-
- <ext:property-placeholder placeholder-prefix="$[" placeholder-suffix="]" />
-
- <bean id="karArtifactInstaller" class="org.apache.karaf.deployer.kar.KarArtifactInstaller" activation="lazy">
- <property name="karService">
- <reference interface="org.apache.karaf.kar.KarService"/>
- </property>
- </bean>
-
- <service id="karArtifactInstallerService"
- ref="karArtifactInstaller"
- auto-export="interfaces"/>
-
-</blueprint>
http://git-wip-us.apache.org/repos/asf/karaf/blob/7373515e/deployer/spring/pom.xml
----------------------------------------------------------------------
diff --git a/deployer/spring/pom.xml b/deployer/spring/pom.xml
index 8f73714..f5427b8 100644
--- a/deployer/spring/pom.xml
+++ b/deployer/spring/pom.xml
@@ -92,14 +92,15 @@
<artifactId>maven-bundle-plugin</artifactId>
<configuration>
<instructions>
- <!-- Set the blueprint.graceperiod flag to false to allow the bundle to start
- See the blueprint config file -->
- <Bundle-SymbolicName>${project.artifactId};blueprint.graceperiod:=false</Bundle-SymbolicName>
<Export-Package />
<Private-Package>
org.apache.karaf.deployer.spring,
+ org.apache.karaf.deployer.spring.osgi,
org.apache.karaf.util
</Private-Package>
+ <Bundle-Activator>
+ org.apache.karaf.deployer.spring.osgi.Activator
+ </Bundle-Activator>
</instructions>
</configuration>
</plugin>
http://git-wip-us.apache.org/repos/asf/karaf/blob/7373515e/deployer/spring/src/main/java/org/apache/karaf/deployer/spring/osgi/Activator.java
----------------------------------------------------------------------
diff --git a/deployer/spring/src/main/java/org/apache/karaf/deployer/spring/osgi/Activator.java b/deployer/spring/src/main/java/org/apache/karaf/deployer/spring/osgi/Activator.java
new file mode 100644
index 0000000..146928b
--- /dev/null
+++ b/deployer/spring/src/main/java/org/apache/karaf/deployer/spring/osgi/Activator.java
@@ -0,0 +1,59 @@
+/**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.karaf.deployer.spring.osgi;
+
+import java.util.Hashtable;
+
+import org.apache.felix.fileinstall.ArtifactListener;
+import org.apache.felix.fileinstall.ArtifactUrlTransformer;
+import org.apache.karaf.deployer.spring.SpringDeploymentListener;
+import org.apache.karaf.deployer.spring.SpringURLHandler;
+import org.osgi.framework.BundleActivator;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceRegistration;
+import org.osgi.service.url.URLStreamHandlerService;
+
+public class Activator implements BundleActivator {
+
+ private ServiceRegistration urlHandlerRegistration;
+ private ServiceRegistration urlTransformerRegistration;
+
+ @Override
+ public void start(BundleContext context) throws Exception {
+ Hashtable<String, Object> props = new Hashtable<String, Object>();
+ props.put("url.handler.protocol", "spring");
+ urlHandlerRegistration = context.registerService(
+ URLStreamHandlerService.class,
+ new SpringURLHandler(),
+ props);
+
+ urlTransformerRegistration = context.registerService(
+ new String[] {
+ ArtifactUrlTransformer.class.getName(),
+ ArtifactListener.class.getName()
+ },
+ new SpringDeploymentListener(),
+ null);
+ }
+
+ @Override
+ public void stop(BundleContext context) throws Exception {
+ urlTransformerRegistration.unregister();
+ urlHandlerRegistration.unregister();
+ }
+}
http://git-wip-us.apache.org/repos/asf/karaf/blob/7373515e/deployer/spring/src/main/resources/OSGI-INF/blueprint/spring-deployer.xml
----------------------------------------------------------------------
diff --git a/deployer/spring/src/main/resources/OSGI-INF/blueprint/spring-deployer.xml b/deployer/spring/src/main/resources/OSGI-INF/blueprint/spring-deployer.xml
deleted file mode 100644
index e8fa854..0000000
--- a/deployer/spring/src/main/resources/OSGI-INF/blueprint/spring-deployer.xml
+++ /dev/null
@@ -1,40 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
-
- Licensed to the Apache Software Foundation (ASF) under one or more
- contributor license agreements. See the NOTICE file distributed with
- this work for additional information regarding copyright ownership.
- The ASF licenses this file to You under the Apache License, Version 2.0
- (the "License"); you may not use this file except in compliance with
- the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
-
--->
-<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0" default-activation="lazy">
-
- <service id="springUrlHandler" interface="org.osgi.service.url.URLStreamHandlerService">
- <service-properties>
- <entry key="url.handler.protocol" value="spring"/>
- </service-properties>
- <bean class="org.apache.karaf.deployer.spring.SpringURLHandler"/>
- </service>
-
- <bean id="springDeploymentListener" class="org.apache.karaf.deployer.spring.SpringDeploymentListener"/>
-
- <!-- Force a reference to the url handler above from the bundles registry to (try to) make sure
- the url handler is registered inside the framework. Else we can run into timing issues
- where fileinstall will use the featureDeploymentListener before the url can be actually
- used. In order to not block the bundle, the blueprint.graceperiod=false flag must be
- set on the SymbolicName bundles header -->
- <reference id="springUrlHandlerRef" interface="org.osgi.service.url.URLStreamHandlerService" filter="url.handler.protocol=spring" />
-
- <service ref="springDeploymentListener" auto-export="interfaces" depends-on="springDeploymentListener" />
-
-</blueprint>
http://git-wip-us.apache.org/repos/asf/karaf/blob/7373515e/deployer/wrap/pom.xml
----------------------------------------------------------------------
diff --git a/deployer/wrap/pom.xml b/deployer/wrap/pom.xml
index 5cf0343..6777f2b 100644
--- a/deployer/wrap/pom.xml
+++ b/deployer/wrap/pom.xml
@@ -77,12 +77,16 @@
<artifactId>maven-bundle-plugin</artifactId>
<configuration>
<instructions>
- <Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName>
<Export-Package />
<Private-Package>
org.apache.karaf.deployer.wrap,
- org.apache.karaf.util
+ org.apache.karaf.deployer.wrap.osgi,
+ org.apache.karaf.util,
+ org.apache.karaf.util.tracker
</Private-Package>
+ <Bundle-Activator>
+ org.apache.karaf.deployer.wrap.osgi.Activator
+ </Bundle-Activator>
<_versionpolicy>${bnd.version.policy}</_versionpolicy>
</instructions>
</configuration>
http://git-wip-us.apache.org/repos/asf/karaf/blob/7373515e/deployer/wrap/src/main/java/org/apache/karaf/deployer/wrap/osgi/Activator.java
----------------------------------------------------------------------
diff --git a/deployer/wrap/src/main/java/org/apache/karaf/deployer/wrap/osgi/Activator.java b/deployer/wrap/src/main/java/org/apache/karaf/deployer/wrap/osgi/Activator.java
new file mode 100644
index 0000000..4f4001b
--- /dev/null
+++ b/deployer/wrap/src/main/java/org/apache/karaf/deployer/wrap/osgi/Activator.java
@@ -0,0 +1,74 @@
+/**
+ *
+ * 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.karaf.deployer.wrap.osgi;
+
+import java.util.Hashtable;
+
+import org.apache.felix.fileinstall.ArtifactUrlTransformer;
+import org.apache.karaf.deployer.wrap.WrapDeploymentListener;
+import org.apache.karaf.util.tracker.SingleServiceTracker;
+import org.osgi.framework.BundleActivator;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceRegistration;
+import org.osgi.service.url.URLStreamHandlerService;
+
+public class Activator implements BundleActivator, SingleServiceTracker.SingleServiceListener {
+
+ private BundleContext bundleContext;
+ private ServiceRegistration<ArtifactUrlTransformer> urlTransformerRegistration;
+ private SingleServiceTracker<URLStreamHandlerService> urlHandlerTracker;
+
+ @Override
+ public void start(BundleContext context) throws Exception {
+ bundleContext = context;
+ urlHandlerTracker = new SingleServiceTracker<URLStreamHandlerService>(
+ context, URLStreamHandlerService.class,
+ "(url.handler.protocol=wrap)", this);
+ urlHandlerTracker.open();
+ }
+
+ @Override
+ public void stop(BundleContext context) throws Exception {
+ urlHandlerTracker.close();
+ }
+
+ @Override
+ public void serviceFound() {
+ if (urlTransformerRegistration == null) {
+ Hashtable<String, Object> props = new Hashtable<String, Object>();
+ props.put("service.ranking", -1);
+ urlTransformerRegistration = bundleContext.registerService(
+ ArtifactUrlTransformer.class,
+ new WrapDeploymentListener(),
+ props);
+ }
+ }
+
+ @Override
+ public void serviceLost() {
+ if (urlTransformerRegistration != null) {
+ urlTransformerRegistration.unregister();
+ urlTransformerRegistration = null;
+ }
+ }
+
+ @Override
+ public void serviceReplaced() {
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/karaf/blob/7373515e/deployer/wrap/src/main/resources/OSGI-INF/blueprint/wrap-deployer.xml
----------------------------------------------------------------------
diff --git a/deployer/wrap/src/main/resources/OSGI-INF/blueprint/wrap-deployer.xml b/deployer/wrap/src/main/resources/OSGI-INF/blueprint/wrap-deployer.xml
deleted file mode 100644
index c5295a5..0000000
--- a/deployer/wrap/src/main/resources/OSGI-INF/blueprint/wrap-deployer.xml
+++ /dev/null
@@ -1,30 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
-
- Licensed to the Apache Software Foundation (ASF) under one or more
- contributor license agreements. See the NOTICE file distributed with
- this work for additional information regarding copyright ownership.
- The ASF licenses this file to You under the Apache License, Version 2.0
- (the "License"); you may not use this file except in compliance with
- the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
-
--->
-<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
- default-activation="lazy">
-
- <bean id="wrapDeploymentListener" class="org.apache.karaf.deployer.wrap.WrapDeploymentListener"/>
-
- <reference id="wrapUrlHandlerRef" interface="org.osgi.service.url.URLStreamHandlerService" filter="url.handler.protocol=wrap"/>
-
- <service ref="wrapDeploymentListener" auto-export="interfaces" depends-on="wrapDeploymentListener" ranking="-1"/>
-
-
-</blueprint>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/karaf/blob/7373515e/util/src/main/java/org/apache/karaf/util/tracker/SingleServiceTracker.java
----------------------------------------------------------------------
diff --git a/util/src/main/java/org/apache/karaf/util/tracker/SingleServiceTracker.java b/util/src/main/java/org/apache/karaf/util/tracker/SingleServiceTracker.java
index a946c48..85c6caa 100644
--- a/util/src/main/java/org/apache/karaf/util/tracker/SingleServiceTracker.java
+++ b/util/src/main/java/org/apache/karaf/util/tracker/SingleServiceTracker.java
@@ -20,6 +20,7 @@
package org.apache.karaf.util.tracker;
+import java.util.Arrays;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicReference;
@@ -99,25 +100,32 @@ public final class SingleServiceTracker<T> {
}
private void findMatchingReference(ServiceReference original) {
- boolean clear = true;
- ServiceReference ref = ctx.getServiceReference(className);
- if (ref != null && (filter == null || filter.match(ref))) {
- @SuppressWarnings("unchecked")
- T service = (T) ctx.getService(ref);
- if (service != null) {
- clear = false;
-
- // We do the unget out of the lock so we don't exit this class while holding a lock.
- if (!!!update(original, ref, service)) {
- ctx.ungetService(ref);
+ try {
+ boolean clear = true;
+ ServiceReference[] refs = ctx.getServiceReferences(className, filterString);
+ if (refs != null && refs.length > 0) {
+ if (refs.length > 1) {
+ Arrays.sort(refs);
+ }
+ @SuppressWarnings("unchecked")
+ T service = (T) ctx.getService(refs[0]);
+ if (service != null) {
+ clear = false;
+
+ // We do the unget out of the lock so we don't exit this class while holding a lock.
+ if (!!!update(original, refs[0], service)) {
+ ctx.ungetService(refs[0]);
+ }
}
+ } else if (original == null) {
+ clear = false;
}
- } else if (original == null) {
- clear = false;
- }
- if (clear) {
- update(original, null, null);
+ if (clear) {
+ update(original, null, null);
+ }
+ } catch (InvalidSyntaxException e) {
+ // this can never happen. (famous last words :)
}
}
[17/24] git commit: [KARAF-2833] Make system/core independent of
blueprint
Posted by gn...@apache.org.
[KARAF-2833] Make system/core independent of blueprint
Project: http://git-wip-us.apache.org/repos/asf/karaf/repo
Commit: http://git-wip-us.apache.org/repos/asf/karaf/commit/42b676bb
Tree: http://git-wip-us.apache.org/repos/asf/karaf/tree/42b676bb
Diff: http://git-wip-us.apache.org/repos/asf/karaf/diff/42b676bb
Branch: refs/heads/master
Commit: 42b676bb5408810a571276166bebee8c0e02f1c6
Parents: 8e129bf
Author: Guillaume Nodet <gn...@gmail.com>
Authored: Sat Mar 22 11:58:34 2014 +0100
Committer: Guillaume Nodet <gn...@gmail.com>
Committed: Mon Mar 24 17:30:13 2014 +0100
----------------------------------------------------------------------
.../standard/src/main/feature/feature.xml | 1 -
system/core/pom.xml | 4 +
.../karaf/system/internal/osgi/Activator.java | 83 ++++++++++++++++++++
.../OSGI-INF/blueprint/system-core.xml | 42 ----------
4 files changed, 87 insertions(+), 43 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/karaf/blob/42b676bb/assemblies/features/standard/src/main/feature/feature.xml
----------------------------------------------------------------------
diff --git a/assemblies/features/standard/src/main/feature/feature.xml b/assemblies/features/standard/src/main/feature/feature.xml
index 6a71520..2b0f6c4 100644
--- a/assemblies/features/standard/src/main/feature/feature.xml
+++ b/assemblies/features/standard/src/main/feature/feature.xml
@@ -180,7 +180,6 @@
</feature>
<feature name="system" description="Provide System support" version="${project.version}">
- <feature version="${project.version}">aries-blueprint</feature>
<bundle start-level="30" start="true">mvn:org.apache.karaf.system/org.apache.karaf.system.core/${project.version}</bundle>
<bundle start-level="30" start="true">mvn:org.apache.karaf.system/org.apache.karaf.system.command/${project.version}</bundle>
</feature>
http://git-wip-us.apache.org/repos/asf/karaf/blob/42b676bb/system/core/pom.xml
----------------------------------------------------------------------
diff --git a/system/core/pom.xml b/system/core/pom.xml
index cfe46bf..f5a9507 100644
--- a/system/core/pom.xml
+++ b/system/core/pom.xml
@@ -85,9 +85,13 @@
</Export-Package>
<Private-Package>
org.apache.karaf.system.internal,
+ org.apache.karaf.system.internal.osgi,
org.apache.karaf.system.management.internal,
org.apache.felix.utils.properties
</Private-Package>
+ <Bundle-Activator>
+ org.apache.karaf.system.internal.osgi.Activator
+ </Bundle-Activator>
</instructions>
</configuration>
</plugin>
http://git-wip-us.apache.org/repos/asf/karaf/blob/42b676bb/system/core/src/main/java/org/apache/karaf/system/internal/osgi/Activator.java
----------------------------------------------------------------------
diff --git a/system/core/src/main/java/org/apache/karaf/system/internal/osgi/Activator.java b/system/core/src/main/java/org/apache/karaf/system/internal/osgi/Activator.java
new file mode 100644
index 0000000..b734253
--- /dev/null
+++ b/system/core/src/main/java/org/apache/karaf/system/internal/osgi/Activator.java
@@ -0,0 +1,83 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.karaf.system.internal.osgi;
+
+import java.util.ArrayList;
+import java.util.Hashtable;
+import java.util.List;
+
+import javax.management.NotCompliantMBeanException;
+
+import org.apache.karaf.system.SystemService;
+import org.apache.karaf.system.internal.SystemServiceImpl;
+import org.apache.karaf.system.management.internal.SystemMBeanImpl;
+import org.osgi.framework.BundleActivator;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceRegistration;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class Activator implements BundleActivator {
+
+ private static final Logger LOGGER = LoggerFactory.getLogger(Activator.class);
+
+ private ServiceRegistration<SystemService> serviceRegistration;
+ private ServiceRegistration mbeanRegistration;
+
+ @Override
+ public void start(BundleContext context) throws Exception {
+ SystemServiceImpl systemService = new SystemServiceImpl();
+ systemService.setBundleContext(context);
+ serviceRegistration = context.registerService(SystemService.class, systemService, null);
+ try {
+ SystemMBeanImpl mbean = new SystemMBeanImpl();
+ mbean.setBundleContext(context);
+ mbean.setSystemService(systemService);
+ Hashtable<String, Object> props = new Hashtable<String, Object>();
+ props.put("jmx.objectname", "org.apache.karaf:type=system,name=" + System.getProperty("karaf.name"));
+ mbeanRegistration = context.registerService(
+ getInterfaceNames(mbean),
+ mbean,
+ props
+ );
+ } catch (NotCompliantMBeanException e) {
+ LOGGER.warn("Error creating System mbean", e);
+ }
+ }
+
+ @Override
+ public void stop(BundleContext context) throws Exception {
+ mbeanRegistration.unregister();
+ serviceRegistration.unregister();
+ }
+
+ private String[] getInterfaceNames(Object object) {
+ List<String> names = new ArrayList<String>();
+ for (Class cl = object.getClass(); cl != Object.class; cl = cl.getSuperclass()) {
+ addSuperInterfaces(names, cl);
+ }
+ return names.toArray(new String[names.size()]);
+ }
+
+ private void addSuperInterfaces(List<String> names, Class clazz) {
+ for (Class cl : clazz.getInterfaces()) {
+ names.add(cl.getName());
+ addSuperInterfaces(names, cl);
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/karaf/blob/42b676bb/system/core/src/main/resources/OSGI-INF/blueprint/system-core.xml
----------------------------------------------------------------------
diff --git a/system/core/src/main/resources/OSGI-INF/blueprint/system-core.xml b/system/core/src/main/resources/OSGI-INF/blueprint/system-core.xml
deleted file mode 100644
index f96a08f..0000000
--- a/system/core/src/main/resources/OSGI-INF/blueprint/system-core.xml
+++ /dev/null
@@ -1,42 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
-
- Licensed to the Apache Software Foundation (ASF) under one or more
- contributor license agreements. See the NOTICE file distributed with
- this work for additional information regarding copyright ownership.
- The ASF licenses this file to You under the Apache License, Version 2.0
- (the "License"); you may not use this file except in compliance with
- the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
-
--->
-<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
- xmlns:ext="http://aries.apache.org/blueprint/xmlns/blueprint-ext/v1.0.0">
-
- <ext:property-placeholder />
-
- <bean id="systemService" class="org.apache.karaf.system.internal.SystemServiceImpl">
- <property name="bundleContext" ref="blueprintBundleContext"/>
- </bean>
-
- <service ref="systemService" interface="org.apache.karaf.system.SystemService"/>
-
- <bean id="systemMBean" class="org.apache.karaf.system.management.internal.SystemMBeanImpl">
- <property name="systemService" ref="systemService" />
- <property name="bundleContext" ref="blueprintBundleContext"/>
- </bean>
-
- <service ref="systemMBean" auto-export="interfaces">
- <service-properties>
- <entry key="jmx.objectname" value="org.apache.karaf:type=system,name=${karaf.name}"/>
- </service-properties>
- </service>
-
-</blueprint>
\ No newline at end of file
[12/24] git commit: [KARAF-2833] Make kar/core independent of
blueprint
Posted by gn...@apache.org.
[KARAF-2833] Make kar/core independent of blueprint
Project: http://git-wip-us.apache.org/repos/asf/karaf/repo
Commit: http://git-wip-us.apache.org/repos/asf/karaf/commit/04593bdc
Tree: http://git-wip-us.apache.org/repos/asf/karaf/tree/04593bdc
Diff: http://git-wip-us.apache.org/repos/asf/karaf/diff/04593bdc
Branch: refs/heads/master
Commit: 04593bdc393094c6da5321d0a0ca64e86e5feb79
Parents: 2a1815d
Author: Guillaume Nodet <gn...@gmail.com>
Authored: Sun Mar 23 14:45:11 2014 +0100
Committer: Guillaume Nodet <gn...@gmail.com>
Committed: Mon Mar 24 17:30:13 2014 +0100
----------------------------------------------------------------------
.../standard/src/main/feature/feature.xml | 1 -
kar/core/pom.xml | 5 +
.../karaf/kar/internal/osgi/Activator.java | 190 +++++++++++++++++++
.../resources/OSGI-INF/blueprint/kar-core.xml | 53 ------
4 files changed, 195 insertions(+), 54 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/karaf/blob/04593bdc/assemblies/features/standard/src/main/feature/feature.xml
----------------------------------------------------------------------
diff --git a/assemblies/features/standard/src/main/feature/feature.xml b/assemblies/features/standard/src/main/feature/feature.xml
index 9064d05..dff6bb2 100644
--- a/assemblies/features/standard/src/main/feature/feature.xml
+++ b/assemblies/features/standard/src/main/feature/feature.xml
@@ -204,7 +204,6 @@
</feature>
<feature name="kar" description="Provide KAR (KARaf archive) support" version="${project.version}" resolver="(obr)">
- <feature version="${project.version}">aries-blueprint</feature>
<bundle start-level="30">mvn:org.apache.karaf.kar/org.apache.karaf.kar.core/${project.version}</bundle>
<bundle start-level="30">mvn:org.apache.karaf.kar/org.apache.karaf.kar.command/${project.version}</bundle>
<conditional>
http://git-wip-us.apache.org/repos/asf/karaf/blob/04593bdc/kar/core/pom.xml
----------------------------------------------------------------------
diff --git a/kar/core/pom.xml b/kar/core/pom.xml
index 2c43d38..c9d6e4e 100644
--- a/kar/core/pom.xml
+++ b/kar/core/pom.xml
@@ -101,9 +101,14 @@
</Export-Package>
<Private-Package>
org.apache.karaf.kar.internal,
+ org.apache.karaf.kar.internal.osgi,
org.apache.karaf.util.maven,
+ org.apache.karaf.util.tracker,
org.apache.felix.utils.properties
</Private-Package>
+ <Bundle-Activator>
+ org.apache.karaf.kar.internal.osgi.Activator
+ </Bundle-Activator>
</instructions>
</configuration>
</plugin>
http://git-wip-us.apache.org/repos/asf/karaf/blob/04593bdc/kar/core/src/main/java/org/apache/karaf/kar/internal/osgi/Activator.java
----------------------------------------------------------------------
diff --git a/kar/core/src/main/java/org/apache/karaf/kar/internal/osgi/Activator.java b/kar/core/src/main/java/org/apache/karaf/kar/internal/osgi/Activator.java
new file mode 100644
index 0000000..f0418cf
--- /dev/null
+++ b/kar/core/src/main/java/org/apache/karaf/kar/internal/osgi/Activator.java
@@ -0,0 +1,190 @@
+/*
+ * 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.karaf.kar.internal.osgi;
+
+import java.util.ArrayList;
+import java.util.Dictionary;
+import java.util.Hashtable;
+import java.util.List;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicBoolean;
+
+import javax.management.NotCompliantMBeanException;
+
+import org.apache.karaf.features.FeaturesService;
+import org.apache.karaf.kar.KarService;
+import org.apache.karaf.kar.internal.KarServiceImpl;
+import org.apache.karaf.kar.internal.KarsMBeanImpl;
+import org.apache.karaf.util.tracker.SingleServiceTracker;
+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.ConfigurationException;
+import org.osgi.service.cm.ManagedService;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class Activator implements BundleActivator, ManagedService, SingleServiceTracker.SingleServiceListener {
+
+ private static final Logger LOGGER = LoggerFactory.getLogger(Activator.class);
+
+ private ExecutorService executor = Executors.newSingleThreadExecutor();
+ private AtomicBoolean scheduled = new AtomicBoolean();
+ private BundleContext bundleContext;
+ private Dictionary<String, ?> configuration;
+ private ServiceRegistration<KarService> registration;
+ private ServiceRegistration mbeanRegistration;
+ private ServiceRegistration<ManagedService> managedServiceRegistration;
+ private SingleServiceTracker<FeaturesService> featuresServiceTracker;
+
+ @Override
+ public void start(BundleContext context) throws Exception {
+ bundleContext = context;
+ scheduled.set(true);
+
+ Hashtable<String, Object> props = new Hashtable<String, Object>();
+ props.put(Constants.SERVICE_PID, "org.apache.karaf.kar");
+ managedServiceRegistration = bundleContext.registerService(ManagedService.class, this, props);
+
+ featuresServiceTracker = new SingleServiceTracker<FeaturesService>(
+ bundleContext, FeaturesService.class, this);
+ featuresServiceTracker.open();
+
+ scheduled.set(false);
+ reconfigure();
+ }
+
+ @Override
+ public void stop(BundleContext context) throws Exception {
+ featuresServiceTracker.close();
+ managedServiceRegistration.unregister();
+ executor.shutdown();
+ executor.awaitTermination(30, TimeUnit.SECONDS);
+ }
+
+ @Override
+ public void updated(Dictionary<String, ?> properties) throws ConfigurationException {
+ this.configuration = properties;
+ reconfigure();
+ }
+
+ @Override
+ public void serviceFound() {
+ reconfigure();
+ }
+
+ @Override
+ public void serviceLost() {
+ reconfigure();
+ }
+
+ @Override
+ public void serviceReplaced() {
+ reconfigure();
+ }
+
+ protected void reconfigure() {
+ if (scheduled.compareAndSet(false, true)) {
+ executor.submit(new Runnable() {
+ @Override
+ public void run() {
+ scheduled.set(false);
+ doStop();
+ try {
+ doStart();
+ } catch (Exception e) {
+ LOGGER.warn("Error starting management layer", e);
+ doStop();
+ }
+ }
+ });
+ }
+ }
+
+ protected void doStart() throws Exception {
+ FeaturesService featuresService = featuresServiceTracker.getService();
+ Dictionary<String, ?> config = configuration;
+ if (featuresService == null) {
+ return;
+ }
+
+ boolean noAutoRefreshBundles = getBoolean(config, "noAutoRefreshBundles", false);
+
+ KarServiceImpl karService = new KarServiceImpl(
+ System.getProperty("karaf.base"),
+ featuresService
+ );
+ karService.setNoAutoRefreshBundles(noAutoRefreshBundles);
+ registration = bundleContext.registerService(KarService.class, karService, null);
+
+ try {
+ KarsMBeanImpl mbean = new KarsMBeanImpl();
+ mbean.setKarService(karService);
+ Hashtable<String, Object> props = new Hashtable<String, Object>();
+ props.put("jmx.objectname", "org.apache.karaf:type=kar,name=" + System.getProperty("karaf.name"));
+ mbeanRegistration = bundleContext.registerService(
+ getInterfaceNames(mbean),
+ mbean,
+ props
+ );
+ } catch (NotCompliantMBeanException e) {
+ LOGGER.warn("Error creating Kars mbean", e);
+ }
+ }
+
+ protected void doStop() {
+ if (mbeanRegistration != null) {
+ mbeanRegistration.unregister();
+ mbeanRegistration = null;
+ }
+ if (registration != null) {
+ registration.unregister();
+ registration = null;
+ }
+ }
+
+ private String[] getInterfaceNames(Object object) {
+ List<String> names = new ArrayList<String>();
+ for (Class cl = object.getClass(); cl != Object.class; cl = cl.getSuperclass()) {
+ addSuperInterfaces(names, cl);
+ }
+ return names.toArray(new String[names.size()]);
+ }
+
+ private void addSuperInterfaces(List<String> names, Class clazz) {
+ for (Class cl : clazz.getInterfaces()) {
+ names.add(cl.getName());
+ addSuperInterfaces(names, cl);
+ }
+ }
+
+ private boolean getBoolean(Dictionary<String, ?> config, String key, boolean def) {
+ if (config != null) {
+ Object val = config.get(key);
+ if (val instanceof Boolean) {
+ return (Boolean) val;
+ } else if (val != null) {
+ return Boolean.parseBoolean(val.toString());
+ }
+ }
+ return def;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/karaf/blob/04593bdc/kar/core/src/main/resources/OSGI-INF/blueprint/kar-core.xml
----------------------------------------------------------------------
diff --git a/kar/core/src/main/resources/OSGI-INF/blueprint/kar-core.xml b/kar/core/src/main/resources/OSGI-INF/blueprint/kar-core.xml
deleted file mode 100644
index f3f824e..0000000
--- a/kar/core/src/main/resources/OSGI-INF/blueprint/kar-core.xml
+++ /dev/null
@@ -1,53 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
-
- Licensed to the Apache Software Foundation (ASF) under one or more
- contributor license agreements. See the NOTICE file distributed with
- this work for additional information regarding copyright ownership.
- The ASF licenses this file to You under the Apache License, Version
- 2.0 (the "License"); you may not use this file except in compliance
- with the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0 Unless required by
- applicable law or agreed to in writing, software distributed under the
- License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
- CONDITIONS OF ANY KIND, either express or implied. See the License for
- the specific language governing permissions and limitations under the
- License.
- -->
-<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
- xmlns:ext="http://aries.apache.org/blueprint/xmlns/blueprint-ext/v1.0.0"
- xmlns:cm="http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.1.0"
- default-activation="lazy">
-
- <ext:property-placeholder placeholder-prefix="$[" placeholder-suffix="]" />
-
- <!-- AdminConfig property place holder for the org.apache.karaf.kar -->
- <cm:property-placeholder persistent-id="org.apache.karaf.kar" update-strategy="reload">
- <cm:default-properties>
- <cm:property name="noAutoRefreshBundles" value="false"/>
- </cm:default-properties>
- </cm:property-placeholder>
-
- <reference id="featuresService" interface="org.apache.karaf.features.FeaturesService"/>
- <reference id="configAdmin" interface="org.osgi.service.cm.ConfigurationAdmin" />
-
- <bean id="karService" class="org.apache.karaf.kar.internal.KarServiceImpl">
- <argument value="$[karaf.base]" />
- <argument ref="featuresService" />
- <property name="noAutoRefreshBundles" value="${noAutoRefreshBundles}"/>
- </bean>
-
- <service ref="karService" interface="org.apache.karaf.kar.KarService"/>
-
- <bean id="mbeanImpl" class="org.apache.karaf.kar.internal.KarsMBeanImpl">
- <property name="karService" ref="karService"/>
- </bean>
-
- <service ref="mbeanImpl" auto-export="interfaces">
- <service-properties>
- <entry key="jmx.objectname" value="org.apache.karaf:type=kar,name=$[karaf.name]"/>
- </service-properties>
- </service>
-
-</blueprint>
[22/24] git commit: [KARAF-2835] Do not include blueprint in
karaf-minimal and clean distributions a bit
Posted by gn...@apache.org.
[KARAF-2835] Do not include blueprint in karaf-minimal and clean distributions a bit
Project: http://git-wip-us.apache.org/repos/asf/karaf/repo
Commit: http://git-wip-us.apache.org/repos/asf/karaf/commit/d80852d8
Tree: http://git-wip-us.apache.org/repos/asf/karaf/tree/d80852d8
Diff: http://git-wip-us.apache.org/repos/asf/karaf/diff/d80852d8
Branch: refs/heads/master
Commit: d80852d80883c8b0ff84ebe6b1e01cf64ee0a5b2
Parents: 7373515
Author: Guillaume Nodet <gn...@gmail.com>
Authored: Mon Mar 24 10:46:29 2014 +0100
Committer: Guillaume Nodet <gn...@gmail.com>
Committed: Mon Mar 24 17:30:14 2014 +0100
----------------------------------------------------------------------
assemblies/apache-karaf-minimal/pom.xml | 14 ++++++++-
assemblies/apache-karaf/pom.xml | 17 +++++++----
.../resources/etc/org.apache.karaf.features.cfg | 2 +-
.../standard/src/main/feature/feature.xml | 31 +++++++-------------
.../org/apache/karaf/itests/FeatureTest.java | 3 +-
.../apache/karaf/itests/KarafTestSupport.java | 1 -
.../org/apache/karaf/itests/RegionTest.java | 4 +++
7 files changed, 42 insertions(+), 30 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/karaf/blob/d80852d8/assemblies/apache-karaf-minimal/pom.xml
----------------------------------------------------------------------
diff --git a/assemblies/apache-karaf-minimal/pom.xml b/assemblies/apache-karaf-minimal/pom.xml
index 00060a9..db9cb71 100644
--- a/assemblies/apache-karaf-minimal/pom.xml
+++ b/assemblies/apache-karaf-minimal/pom.xml
@@ -115,7 +115,19 @@
<feature>wrapper</feature>
</installedFeatures>
<bootFeatures>
- <feature>framework</feature>
+ <feature>jaas</feature>
+ <feature>ssh</feature>
+ <feature>management</feature>
+ <feature>bundle</feature>
+ <feature>config</feature>
+ <feature>deployer</feature>
+ <feature>diagnostic</feature>
+ <feature>instance</feature>
+ <feature>kar</feature>
+ <feature>log</feature>
+ <feature>package</feature>
+ <feature>service</feature>
+ <feature>system</feature>
</bootFeatures>
</configuration>
</plugin>
http://git-wip-us.apache.org/repos/asf/karaf/blob/d80852d8/assemblies/apache-karaf/pom.xml
----------------------------------------------------------------------
diff --git a/assemblies/apache-karaf/pom.xml b/assemblies/apache-karaf/pom.xml
index 7d1d69b..4b2ee42 100644
--- a/assemblies/apache-karaf/pom.xml
+++ b/assemblies/apache-karaf/pom.xml
@@ -160,14 +160,21 @@
<feature>wrapper</feature>
</installedFeatures>
<bootFeatures>
- <feature>standard</feature>
- <feature>management</feature>
+ <feature>aries-blueprint</feature>
+ <feature>shell-compat</feature>
+ <feature>jaas</feature>
<feature>ssh</feature>
+ <feature>management</feature>
+ <feature>bundle</feature>
<feature>config</feature>
- <feature>deployers</feature>
- <feature>region</feature>
- <feature>package</feature>
+ <feature>deployer</feature>
+ <feature>diagnostic</feature>
+ <feature>instance</feature>
<feature>kar</feature>
+ <feature>log</feature>
+ <feature>package</feature>
+ <feature>service</feature>
+ <feature>system</feature>
</bootFeatures>
</configuration>
</plugin>
http://git-wip-us.apache.org/repos/asf/karaf/blob/d80852d8/assemblies/features/framework/src/main/filtered-resources/resources/etc/org.apache.karaf.features.cfg
----------------------------------------------------------------------
diff --git a/assemblies/features/framework/src/main/filtered-resources/resources/etc/org.apache.karaf.features.cfg b/assemblies/features/framework/src/main/filtered-resources/resources/etc/org.apache.karaf.features.cfg
index 9bc5df1..06495e7 100644
--- a/assemblies/features/framework/src/main/filtered-resources/resources/etc/org.apache.karaf.features.cfg
+++ b/assemblies/features/framework/src/main/filtered-resources/resources/etc/org.apache.karaf.features.cfg
@@ -41,7 +41,7 @@ featuresRepositories=mvn:org.apache.karaf.features/standard/${project.version}/x
#
# Comma separated list of features to install at startup
#
-featuresBoot=config,standard,region,package,kar,ssh,management
+featuresBoot=
#
# Defines if the boot features are started in asynchronous mode (in a dedicated thread)
http://git-wip-us.apache.org/repos/asf/karaf/blob/d80852d8/assemblies/features/standard/src/main/feature/feature.xml
----------------------------------------------------------------------
diff --git a/assemblies/features/standard/src/main/feature/feature.xml b/assemblies/features/standard/src/main/feature/feature.xml
index 4d49c44..e5af831 100644
--- a/assemblies/features/standard/src/main/feature/feature.xml
+++ b/assemblies/features/standard/src/main/feature/feature.xml
@@ -25,27 +25,9 @@
<bundle start="true" start-level="10">mvn:org.apache.karaf.service/org.apache.karaf.service.guard/${project.version}</bundle>
</feature>
- <feature name="standard" description="Karaf standard feature" version="${project.version}">
- <feature>aries-blueprint</feature>
- <feature>jaas</feature>
- <feature>ssh</feature>
- <feature>shell-compat</feature>
- <feature>bundle</feature>
- <feature>config</feature>
- <feature>deployer</feature>
- <feature>diagnostic</feature>
- <feature>instance</feature>
- <feature>log</feature>
- <feature>service</feature>
- <feature>system</feature>
- <feature>package</feature>
- <conditional>
- <condition>webconsole</condition>
- <bundle start-level="30">mvn:org.apache.karaf.webconsole/org.apache.karaf.webconsole.instance/${project.version}</bundle>
- <bundle start-level="30">mvn:org.apache.karaf.webconsole/org.apache.karaf.webconsole.features/${project.version}</bundle>
- <bundle start-level="30">mvn:org.apache.karaf.webconsole/org.apache.karaf.webconsole.gogo/${project.version}</bundle>
- <bundle start-level="30">mvn:org.apache.karaf.webconsole/org.apache.karaf.webconsole.http/${project.version}</bundle>
- </conditional>
+ <feature version="${project.version}" description="Services Security for Karaf" name="service-security">
+ <feature version="${project.version}">aries-proxy</feature>
+ <bundle start="true" start-level="10">mvn:org.apache.karaf.service/org.apache.karaf.service.guard/${project.version}</bundle>
</feature>
<feature name="aries-proxy" description="Aries Proxy" version="${project.version}">
@@ -224,6 +206,9 @@
<bundle start-level="30">mvn:org.apache.felix/org.apache.felix.metatype/${felix.metatype.version}</bundle>
<bundle start-level="30">mvn:org.apache.karaf.webconsole/org.apache.karaf.webconsole.branding/${project.version}</bundle>
<bundle start-level="30">mvn:org.apache.karaf.webconsole/org.apache.karaf.webconsole.console/${project.version}</bundle>
+ <bundle start-level="30">mvn:org.apache.karaf.webconsole/org.apache.karaf.webconsole.features/${project.version}</bundle>
+ <bundle start-level="30">mvn:org.apache.karaf.webconsole/org.apache.karaf.webconsole.gogo/${project.version}</bundle>
+ <bundle start-level="30">mvn:org.apache.karaf.webconsole/org.apache.karaf.webconsole.http/${project.version}</bundle>
<conditional>
<condition>eventadmin</condition>
<bundle start-level="30">mvn:org.apache.felix/org.apache.felix.webconsole.plugins.event/${felix.eventadmin.webconsole.plugin.version}</bundle>
@@ -232,6 +217,10 @@
<condition>scr</condition>
<bundle start-level="30">mvn:org.apache.felix/org.apache.felix.webconsole.plugins.ds/${felix.scr.webconsole.plugin.version}</bundle>
</conditional>
+ <conditional>
+ <condition>instance</condition>
+ <bundle start-level="30">mvn:org.apache.karaf.webconsole/org.apache.karaf.webconsole.instance/${project.version}</bundle>
+ </conditional>
</feature>
<feature name="ssh" description="Provide a SSHd server on Karaf" version="${project.version}">
http://git-wip-us.apache.org/repos/asf/karaf/blob/d80852d8/itests/src/test/java/org/apache/karaf/itests/FeatureTest.java
----------------------------------------------------------------------
diff --git a/itests/src/test/java/org/apache/karaf/itests/FeatureTest.java b/itests/src/test/java/org/apache/karaf/itests/FeatureTest.java
index bb42d41..2098683 100644
--- a/itests/src/test/java/org/apache/karaf/itests/FeatureTest.java
+++ b/itests/src/test/java/org/apache/karaf/itests/FeatureTest.java
@@ -34,7 +34,8 @@ public class FeatureTest extends KarafTestSupport {
@Test
public void bootFeatures() throws Exception {
- assertFeaturesInstalled("standard", "config", "region", "package", "kar", "management");
+ assertFeaturesInstalled("jaas", "ssh", "management", "bundle", "config", "deployer", "diagnostic",
+ "instance", "kar", "log", "package", "service", "system");
}
@Test
http://git-wip-us.apache.org/repos/asf/karaf/blob/d80852d8/itests/src/test/java/org/apache/karaf/itests/KarafTestSupport.java
----------------------------------------------------------------------
diff --git a/itests/src/test/java/org/apache/karaf/itests/KarafTestSupport.java b/itests/src/test/java/org/apache/karaf/itests/KarafTestSupport.java
index 7fa2146..9a59437 100644
--- a/itests/src/test/java/org/apache/karaf/itests/KarafTestSupport.java
+++ b/itests/src/test/java/org/apache/karaf/itests/KarafTestSupport.java
@@ -126,7 +126,6 @@ public class KarafTestSupport {
configureSecurity().enableKarafMBeanServerBuilder(),
keepRuntimeFolder(),
replaceConfigurationFile("etc/org.ops4j.pax.logging.cfg", getConfigFile("/etc/org.ops4j.pax.logging.cfg")),
- editConfigurationFilePut("etc/org.apache.karaf.features.cfg", "featuresBoot", "config,standard,region,package,kar,management"),
editConfigurationFilePut("etc/org.ops4j.pax.web.cfg", "org.osgi.service.http.port", HTTP_PORT),
editConfigurationFilePut("etc/org.apache.karaf.management.cfg", "rmiRegistryPort", RMI_REG_PORT),
editConfigurationFilePut("etc/org.apache.karaf.management.cfg", "rmiServerPort", RMI_SERVER_PORT)
http://git-wip-us.apache.org/repos/asf/karaf/blob/d80852d8/itests/src/test/java/org/apache/karaf/itests/RegionTest.java
----------------------------------------------------------------------
diff --git a/itests/src/test/java/org/apache/karaf/itests/RegionTest.java b/itests/src/test/java/org/apache/karaf/itests/RegionTest.java
index 3d7d6b0..0af20fe 100644
--- a/itests/src/test/java/org/apache/karaf/itests/RegionTest.java
+++ b/itests/src/test/java/org/apache/karaf/itests/RegionTest.java
@@ -27,6 +27,8 @@ public class RegionTest extends KarafTestSupport {
@Test
public void infoCommand() throws Exception {
+ installAndAssertFeature("region");
+
String infoOutput = executeCommand("region:info");
System.out.println(infoOutput);
assertTrue("Region org.eclipse.equinox.region.kernel should be present", infoOutput.contains("org.eclipse.equinox.region.kernel"));
@@ -35,6 +37,8 @@ public class RegionTest extends KarafTestSupport {
@Test
public void addRegionCommand() throws Exception {
+ installAndAssertFeature("region");
+
System.out.println(executeCommand("region:region-add itest"));
String infoOutput = executeCommand("region:info");
System.out.println(infoOutput);
[20/24] git commit: [KARAF-2833] Make log/core independent of
blueprint
Posted by gn...@apache.org.
[KARAF-2833] Make log/core independent of blueprint
Project: http://git-wip-us.apache.org/repos/asf/karaf/repo
Commit: http://git-wip-us.apache.org/repos/asf/karaf/commit/60c0f820
Tree: http://git-wip-us.apache.org/repos/asf/karaf/tree/60c0f820
Diff: http://git-wip-us.apache.org/repos/asf/karaf/diff/60c0f820
Branch: refs/heads/master
Commit: 60c0f820953a95c2e08f0475789af20d041ff849
Parents: 04593bd
Author: Guillaume Nodet <gn...@gmail.com>
Authored: Sun Mar 23 14:45:29 2014 +0100
Committer: Guillaume Nodet <gn...@gmail.com>
Committed: Mon Mar 24 17:30:13 2014 +0100
----------------------------------------------------------------------
.../standard/src/main/feature/feature.xml | 1 -
log/core/pom.xml | 12 +-
.../karaf/log/core/internal/osgi/Activator.java | 235 +++++++++++++++++++
.../resources/OSGI-INF/blueprint/blueprint.xml | 75 ------
4 files changed, 246 insertions(+), 77 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/karaf/blob/60c0f820/assemblies/features/standard/src/main/feature/feature.xml
----------------------------------------------------------------------
diff --git a/assemblies/features/standard/src/main/feature/feature.xml b/assemblies/features/standard/src/main/feature/feature.xml
index dff6bb2..8979b32 100644
--- a/assemblies/features/standard/src/main/feature/feature.xml
+++ b/assemblies/features/standard/src/main/feature/feature.xml
@@ -155,7 +155,6 @@
</feature>
<feature name="log" description="Provide Log support" version="${project.version}">
- <feature version="${project.version}">aries-blueprint</feature>
<bundle start-level="30" start="true">mvn:org.apache.karaf.log/org.apache.karaf.log.core/${project.version}</bundle>
<bundle start-level="30" start="true">mvn:org.apache.karaf.log/org.apache.karaf.log.command/${project.version}</bundle>
</feature>
http://git-wip-us.apache.org/repos/asf/karaf/blob/60c0f820/log/core/pom.xml
----------------------------------------------------------------------
diff --git a/log/core/pom.xml b/log/core/pom.xml
index 2bb59e0..261e896 100644
--- a/log/core/pom.xml
+++ b/log/core/pom.xml
@@ -59,6 +59,11 @@
<artifactId>pax-logging-api</artifactId>
<scope>provided</scope>
</dependency>
+ <dependency>
+ <groupId>org.apache.karaf</groupId>
+ <artifactId>org.apache.karaf.util</artifactId>
+ <scope>provided</scope>
+ </dependency>
</dependencies>
<build>
@@ -91,8 +96,13 @@
</Import-Package>
<Private-Package>
org.apache.karaf.log.core.internal,
- org.apache.karaf.log.core.internal.layout
+ org.apache.karaf.log.core.internal.layout,
+ org.apache.karaf.log.core.internal.osgi,
+ org.apache.karaf.util.tracker
</Private-Package>
+ <Bundle-Activator>
+ org.apache.karaf.log.core.internal.osgi.Activator
+ </Bundle-Activator>
</instructions>
</configuration>
</plugin>
http://git-wip-us.apache.org/repos/asf/karaf/blob/60c0f820/log/core/src/main/java/org/apache/karaf/log/core/internal/osgi/Activator.java
----------------------------------------------------------------------
diff --git a/log/core/src/main/java/org/apache/karaf/log/core/internal/osgi/Activator.java b/log/core/src/main/java/org/apache/karaf/log/core/internal/osgi/Activator.java
new file mode 100644
index 0000000..d9085fc
--- /dev/null
+++ b/log/core/src/main/java/org/apache/karaf/log/core/internal/osgi/Activator.java
@@ -0,0 +1,235 @@
+/*
+ * 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.karaf.log.core.internal.osgi;
+
+import java.util.ArrayList;
+import java.util.Dictionary;
+import java.util.Hashtable;
+import java.util.List;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicBoolean;
+
+import javax.management.NotCompliantMBeanException;
+
+import org.apache.karaf.log.core.LogEventFormatter;
+import org.apache.karaf.log.core.LogService;
+import org.apache.karaf.log.core.internal.LogEventFormatterImpl;
+import org.apache.karaf.log.core.internal.LogMBeanImpl;
+import org.apache.karaf.log.core.internal.LogServiceImpl;
+import org.apache.karaf.log.core.internal.LruList;
+import org.apache.karaf.util.tracker.SingleServiceTracker;
+import org.ops4j.pax.logging.spi.PaxAppender;
+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.service.cm.ConfigurationException;
+import org.osgi.service.cm.ManagedService;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class Activator implements BundleActivator, ManagedService, SingleServiceTracker.SingleServiceListener {
+
+ private static final Logger LOGGER = LoggerFactory.getLogger(Activator.class);
+
+ private ExecutorService executor = Executors.newSingleThreadExecutor();
+ private AtomicBoolean scheduled = new AtomicBoolean();
+ private BundleContext bundleContext;
+ private Dictionary<String, ?> configuration;
+ private ServiceRegistration managedServiceRegistration;
+ private SingleServiceTracker<ConfigurationAdmin> configAdminTracker;
+ private ServiceRegistration<LogService> serviceRegistration;
+ private ServiceRegistration<LogEventFormatter> formatterRegistration;
+ private ServiceRegistration<PaxAppender> appenderRegistration;
+ private ServiceRegistration mbeanRegistration;
+
+ @Override
+ public void start(BundleContext context) throws Exception {
+ bundleContext = context;
+ scheduled.set(true);
+
+ Hashtable<String, Object> props = new Hashtable<String, Object>();
+ props.put(Constants.SERVICE_PID, "org.apache.karaf.log");
+ managedServiceRegistration = bundleContext.registerService(ManagedService.class, this, props);
+
+ configAdminTracker = new SingleServiceTracker<ConfigurationAdmin>(
+ bundleContext, ConfigurationAdmin.class, this);
+ configAdminTracker.open();
+
+ scheduled.set(false);
+ reconfigure();
+ }
+
+ @Override
+ public void stop(BundleContext context) throws Exception {
+ configAdminTracker.close();
+ managedServiceRegistration.unregister();
+ executor.shutdown();
+ executor.awaitTermination(30, TimeUnit.SECONDS);
+ }
+
+ @Override
+ public void updated(Dictionary<String, ?> properties) throws ConfigurationException {
+ this.configuration = properties;
+ reconfigure();
+ }
+
+ @Override
+ public void serviceFound() {
+ reconfigure();
+ }
+
+ @Override
+ public void serviceLost() {
+ reconfigure();
+ }
+
+ @Override
+ public void serviceReplaced() {
+ reconfigure();
+ }
+
+ protected void reconfigure() {
+ if (scheduled.compareAndSet(false, true)) {
+ executor.submit(new Runnable() {
+ @Override
+ public void run() {
+ scheduled.set(false);
+ doStop();
+ try {
+ doStart();
+ } catch (Exception e) {
+ LOGGER.warn("Error starting management layer", e);
+ doStop();
+ }
+ }
+ });
+ }
+ }
+
+ protected void doStart() throws Exception {
+ ConfigurationAdmin configurationAdmin = configAdminTracker != null ? configAdminTracker.getService() : null;
+ Dictionary<String, ?> config = configuration;
+ if (configurationAdmin == null) {
+ return;
+ }
+
+ int size = getInt(config, "size", 500);
+ String pattern = getString(config, "pattern", "%d{ABSOLUTE} | %-5.5p | %-16.16t | %-32.32c{1} | %-32.32C %4L | %m%n");
+ String fatalColor = getString(config, "fatalColor", "31");
+ String errorColor = getString(config, "errorColor", "31");
+ String warnColor = getString(config, "warnColor", "35");
+ String infoColor = getString(config, "infoColor", "36");
+ String debugColor = getString(config, "debugColor", "39");
+ String traceColor = getString(config, "traceColor", "39");
+
+ LruList events = new LruList(size);
+ Hashtable<String, Object> props = new Hashtable<String, Object>();
+ props.put("org.ops4j.pax.logging.appender.name", "VmLogAppender");
+ appenderRegistration = bundleContext.registerService(
+ PaxAppender.class, events, props);
+
+ LogEventFormatterImpl formatter = new LogEventFormatterImpl();
+ formatter.setPattern(pattern);
+ formatter.setFatalColor(fatalColor);
+ formatter.setErrorColor(errorColor);
+ formatter.setWarnColor(warnColor);
+ formatter.setInfoColor(infoColor);
+ formatter.setDebugColor(debugColor);
+ formatter.setTraceColor(traceColor);
+ formatterRegistration = bundleContext.registerService(
+ LogEventFormatter.class, formatter, null);
+
+ LogServiceImpl logService = new LogServiceImpl(configurationAdmin, events);
+ serviceRegistration = bundleContext.registerService(
+ LogService.class, logService, null);
+
+
+ try {
+ LogMBeanImpl securityMBean = new LogMBeanImpl(logService);
+ props = new Hashtable<String, Object>();
+ props.put("jmx.objectname", "org.apache.karaf:type=log,name=" + System.getProperty("karaf.name"));
+ mbeanRegistration = bundleContext.registerService(
+ getInterfaceNames(securityMBean),
+ securityMBean,
+ props
+ );
+ } catch (NotCompliantMBeanException e) {
+ LOGGER.warn("Error creating Log mbean", e);
+ }
+ }
+
+ protected void doStop() {
+ if (mbeanRegistration != null) {
+ mbeanRegistration.unregister();
+ mbeanRegistration = null;
+ }
+ if (serviceRegistration != null) {
+ serviceRegistration.unregister();
+ serviceRegistration = null;
+ }
+ if (formatterRegistration != null) {
+ formatterRegistration.unregister();
+ formatterRegistration = null;
+ }
+ if (appenderRegistration != null) {
+ appenderRegistration.unregister();
+ appenderRegistration = null;
+ }
+ }
+
+ private String[] getInterfaceNames(Object object) {
+ List<String> names = new ArrayList<String>();
+ for (Class cl = object.getClass(); cl != Object.class; cl = cl.getSuperclass()) {
+ addSuperInterfaces(names, cl);
+ }
+ return names.toArray(new String[names.size()]);
+ }
+
+ private void addSuperInterfaces(List<String> names, Class clazz) {
+ for (Class cl : clazz.getInterfaces()) {
+ names.add(cl.getName());
+ addSuperInterfaces(names, cl);
+ }
+ }
+
+ private int getInt(Dictionary<String, ?> config, String key, int def) {
+ if (config != null) {
+ Object val = config.get(key);
+ if (val instanceof Number) {
+ return ((Number) val).intValue();
+ } else if (val != null) {
+ return Integer.parseInt(val.toString());
+ }
+ }
+ return def;
+ }
+
+ private String getString(Dictionary<String, ?> config, String key, String def) {
+ if (config != null) {
+ Object val = config.get(key);
+ if (val != null) {
+ return val.toString();
+ }
+ }
+ return def;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/karaf/blob/60c0f820/log/core/src/main/resources/OSGI-INF/blueprint/blueprint.xml
----------------------------------------------------------------------
diff --git a/log/core/src/main/resources/OSGI-INF/blueprint/blueprint.xml b/log/core/src/main/resources/OSGI-INF/blueprint/blueprint.xml
deleted file mode 100644
index f9b0ee4..0000000
--- a/log/core/src/main/resources/OSGI-INF/blueprint/blueprint.xml
+++ /dev/null
@@ -1,75 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
- 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.
--->
-<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
- xmlns:cm="http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.1.0"
- xmlns:ext="http://aries.apache.org/blueprint/xmlns/blueprint-ext/v1.0.0">
-
- <ext:property-placeholder placeholder-prefix="$(" placeholder-suffix=")"/>
-
- <cm:property-placeholder persistent-id="org.apache.karaf.log" update-strategy="reload">
- <cm:default-properties>
- <cm:property name="size" value="500"/>
- <cm:property name="pattern" value="%d{ABSOLUTE} | %-5.5p | %-16.16t | %-32.32c{1} | %-32.32C %4L | %m%n"/>
- <cm:property name="fatalColor" value="31"/>
- <cm:property name="errorColor" value="31"/>
- <cm:property name="warnColor" value="35"/>
- <cm:property name="infoColor" value="36"/>
- <cm:property name="debugColor" value="39"/>
- <cm:property name="traceColor" value="39"/>
- </cm:default-properties>
- </cm:property-placeholder>
-
- <reference id="configAdmin" interface="org.osgi.service.cm.ConfigurationAdmin"/>
-
- <bean id="events" class="org.apache.karaf.log.core.internal.LruList">
- <argument value="${size}"/>
- </bean>
-
- <service ref="events" interface="org.ops4j.pax.logging.spi.PaxAppender">
- <service-properties>
- <entry key="org.ops4j.pax.logging.appender.name" value="VmLogAppender"/>
- </service-properties>
- </service>
-
- <bean id="logService" class="org.apache.karaf.log.core.internal.LogServiceImpl">
- <argument ref="configAdmin"/>
- <argument ref="events" />
- </bean>
-
- <service ref="logService" interface="org.apache.karaf.log.core.LogService"/>
-
- <bean id="logMBean" class="org.apache.karaf.log.core.internal.LogMBeanImpl">
- <argument ref="logService"/>
- </bean>
-
- <service ref="logMBean" auto-export="interfaces">
- <service-properties>
- <entry key="jmx.objectname" value="org.apache.karaf:type=log,name=$(karaf.name)"/>
- </service-properties>
- </service>
-
- <bean id="formatter" class="org.apache.karaf.log.core.internal.LogEventFormatterImpl">
- <property name="pattern" value="${pattern}"/>
- <property name="fatalColor" value="${fatalColor}"/>
- <property name="errorColor" value="${errorColor}"/>
- <property name="warnColor" value="${warnColor}"/>
- <property name="infoColor" value="${infoColor}"/>
- <property name="debugColor" value="${debugColor}"/>
- <property name="traceColor" value="${traceColor}"/>
- </bean>
-
- <service ref="formatter" interface="org.apache.karaf.log.core.LogEventFormatter"/>
-
-</blueprint>
\ No newline at end of file
[23/24] git commit: [KARAF-2846] Gogo webconsole plugin is broken
Posted by gn...@apache.org.
[KARAF-2846] Gogo webconsole plugin is broken
Project: http://git-wip-us.apache.org/repos/asf/karaf/repo
Commit: http://git-wip-us.apache.org/repos/asf/karaf/commit/e30e660b
Tree: http://git-wip-us.apache.org/repos/asf/karaf/tree/e30e660b
Diff: http://git-wip-us.apache.org/repos/asf/karaf/diff/e30e660b
Branch: refs/heads/master
Commit: e30e660b577534c3f3da7ed15bebb806e2f4afa3
Parents: 7b47629
Author: Guillaume Nodet <gn...@gmail.com>
Authored: Mon Mar 24 17:29:50 2014 +0100
Committer: Guillaume Nodet <gn...@gmail.com>
Committed: Mon Mar 24 17:30:14 2014 +0100
----------------------------------------------------------------------
.../karaf/webconsole/gogo/GogoPlugin.java | 16 +++++++--------
.../karaf/webconsole/gogo/WebTerminal.java | 21 +++++++++++++-------
.../OSGI-INF/blueprint/webconsole-gogo.xml | 4 ++--
3 files changed, 24 insertions(+), 17 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/karaf/blob/e30e660b/webconsole/gogo/src/main/java/org/apache/karaf/webconsole/gogo/GogoPlugin.java
----------------------------------------------------------------------
diff --git a/webconsole/gogo/src/main/java/org/apache/karaf/webconsole/gogo/GogoPlugin.java b/webconsole/gogo/src/main/java/org/apache/karaf/webconsole/gogo/GogoPlugin.java
index dcfb00d..393c13a 100644
--- a/webconsole/gogo/src/main/java/org/apache/karaf/webconsole/gogo/GogoPlugin.java
+++ b/webconsole/gogo/src/main/java/org/apache/karaf/webconsole/gogo/GogoPlugin.java
@@ -42,14 +42,14 @@ import javax.servlet.http.HttpServletResponse;
import org.apache.felix.webconsole.AbstractWebConsolePlugin;
import org.apache.karaf.jaas.boot.principal.UserPrincipal;
-import org.apache.karaf.shell.console.Console;
-import org.apache.karaf.shell.console.factory.ConsoleFactory;
+import org.apache.karaf.shell.api.console.Session;
+import org.apache.karaf.shell.api.console.SessionFactory;
import org.osgi.framework.BundleContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
- * WebConsole plugin for {@link Console}.
+ * WebConsole plugin for {@link Session}.
*/
public class GogoPlugin extends AbstractWebConsolePlugin {
@@ -61,7 +61,7 @@ public class GogoPlugin extends AbstractWebConsolePlugin {
public static final int TERM_HEIGHT = 39;
private BundleContext bundleContext;
- private ConsoleFactory consoleFactory;
+ private SessionFactory sessionFactory;
@Override
protected boolean isHtmlRequest(HttpServletRequest request) {
@@ -72,8 +72,8 @@ public class GogoPlugin extends AbstractWebConsolePlugin {
this.bundleContext = bundleContext;
}
- public void setConsoleFactory(ConsoleFactory consoleFactory) {
- this.consoleFactory = consoleFactory;
+ public void setSessionFactory(SessionFactory sessionFactory) {
+ this.sessionFactory = sessionFactory;
}
public void start() {
@@ -185,14 +185,14 @@ public class GogoPlugin extends AbstractWebConsolePlugin {
out = new PipedInputStream();
PrintStream pipedOut = new PrintStream(new PipedOutputStream(out), true);
- Console console = consoleFactory.create(
+ Session session = sessionFactory.create(
new PipedInputStream(in),
pipedOut,
pipedOut,
new WebTerminal(TERM_WIDTH, TERM_HEIGHT),
null,
null);
- new Thread(console, "Karaf web console user " + getCurrentUserName()).start();
+ new Thread(session, "Karaf web console user " + getCurrentUserName()).start();
} catch (IOException e) {
e.printStackTrace();
throw e;
http://git-wip-us.apache.org/repos/asf/karaf/blob/e30e660b/webconsole/gogo/src/main/java/org/apache/karaf/webconsole/gogo/WebTerminal.java
----------------------------------------------------------------------
diff --git a/webconsole/gogo/src/main/java/org/apache/karaf/webconsole/gogo/WebTerminal.java b/webconsole/gogo/src/main/java/org/apache/karaf/webconsole/gogo/WebTerminal.java
index 6d66041..865a528 100644
--- a/webconsole/gogo/src/main/java/org/apache/karaf/webconsole/gogo/WebTerminal.java
+++ b/webconsole/gogo/src/main/java/org/apache/karaf/webconsole/gogo/WebTerminal.java
@@ -16,25 +16,32 @@
*/
package org.apache.karaf.webconsole.gogo;
-import jline.TerminalSupport;
+ import org.apache.karaf.shell.api.console.Terminal;
-public class WebTerminal extends TerminalSupport {
+public class WebTerminal implements Terminal {
private int width;
private int height;
+ private boolean echo = true;
public WebTerminal(int width, int height) {
- super(true);
this.width = width;
this.height = height;
}
- public void init() throws Exception {
- // nothing to do
+ @Override
+ public boolean isAnsiSupported() {
+ return true;
}
- public void restore() throws Exception {
- // nothing to do
+ @Override
+ public boolean isEchoEnabled() {
+ return echo;
+ }
+
+ @Override
+ public void setEchoEnabled(boolean enabled) {
+ echo = enabled;
}
public int getWidth() {
http://git-wip-us.apache.org/repos/asf/karaf/blob/e30e660b/webconsole/gogo/src/main/resources/OSGI-INF/blueprint/webconsole-gogo.xml
----------------------------------------------------------------------
diff --git a/webconsole/gogo/src/main/resources/OSGI-INF/blueprint/webconsole-gogo.xml b/webconsole/gogo/src/main/resources/OSGI-INF/blueprint/webconsole-gogo.xml
index 79fc42c..00c1c2d 100644
--- a/webconsole/gogo/src/main/resources/OSGI-INF/blueprint/webconsole-gogo.xml
+++ b/webconsole/gogo/src/main/resources/OSGI-INF/blueprint/webconsole-gogo.xml
@@ -19,11 +19,11 @@
-->
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0" default-activation="lazy">
- <reference id="consoleFactory" interface="org.apache.karaf.shell.console.factory.ConsoleFactory"/>
+ <reference id="sessionFactory" interface="org.apache.karaf.shell.api.console.SessionFactory"/>
<bean id="gogoPlugin" class="org.apache.karaf.webconsole.gogo.GogoPlugin" init-method="start" destroy-method="stop">
<property name="bundleContext" ref="blueprintBundleContext" />
- <property name="consoleFactory" ref="consoleFactory"/>
+ <property name="sessionFactory" ref="sessionFactory"/>
</bean>
<service ref="gogoPlugin" interface="javax.servlet.Servlet" >
<service-properties>
[14/24] [KARAF-2833] Make jaas/config,
jaas/jasypt and jaas/modules independent of blueprint
Posted by gn...@apache.org.
http://git-wip-us.apache.org/repos/asf/karaf/blob/5e2f19c4/jaas/config/src/main/java/org/apache/karaf/jaas/config/impl/NamespaceHandler.java
----------------------------------------------------------------------
diff --git a/jaas/config/src/main/java/org/apache/karaf/jaas/config/impl/NamespaceHandler.java b/jaas/config/src/main/java/org/apache/karaf/jaas/config/impl/NamespaceHandler.java
deleted file mode 100644
index a6ed36c..0000000
--- a/jaas/config/src/main/java/org/apache/karaf/jaas/config/impl/NamespaceHandler.java
+++ /dev/null
@@ -1,165 +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.karaf.jaas.config.impl;
-
-import org.apache.aries.blueprint.ParserContext;
-import org.apache.aries.blueprint.mutable.*;
-import org.apache.karaf.jaas.boot.ProxyLoginModule;
-import org.apache.karaf.jaas.config.JaasRealm;
-import org.apache.karaf.jaas.config.KeystoreInstance;
-import org.osgi.service.blueprint.container.ComponentDefinitionException;
-import org.osgi.service.blueprint.reflect.ComponentMetadata;
-import org.osgi.service.blueprint.reflect.Metadata;
-import org.osgi.service.blueprint.reflect.RefMetadata;
-import org.osgi.service.blueprint.reflect.ValueMetadata;
-import org.w3c.dom.*;
-
-import java.net.URL;
-import java.util.Arrays;
-import java.util.HashSet;
-import java.util.Set;
-
-public class NamespaceHandler implements org.apache.aries.blueprint.NamespaceHandler {
-
- public URL getSchemaLocation(String namespace) {
- if ("http://karaf.apache.org/xmlns/jaas/v1.0.0".equals(namespace)) {
- return getClass().getResource("/org/apache/karaf/jaas/config/karaf-jaas-1.0.0.xsd");
- } else {
- return getClass().getResource("/org/apache/karaf/jaas/config/karaf-jaas-1.1.0.xsd");
- }
- }
-
- public Set<Class> getManagedClasses() {
- return new HashSet<Class>(Arrays.asList(
- Config.class,
- ResourceKeystoreInstance.class
- ));
- }
-
- public Metadata parse(Element element, ParserContext context) {
- String name = element.getLocalName() != null ? element.getLocalName() : element.getNodeName();
- if ("config".equals(name)) {
- return parseConfig(element, context);
- } else if ("keystore".equals(name)) {
- return parseKeystore(element, context);
- }
- throw new ComponentDefinitionException("Bad xml syntax: unknown element '" + name + "'");
- }
-
- public ComponentMetadata decorate(Node node, ComponentMetadata component, ParserContext context) {
- throw new ComponentDefinitionException("Bad xml syntax: node decoration is not supported");
- }
-
- public ComponentMetadata parseConfig(Element element, ParserContext context) {
- MutableBeanMetadata bean = context.createMetadata(MutableBeanMetadata.class);
- bean.setRuntimeClass(Config.class);
- String name = element.getAttribute("name");
- bean.addProperty("bundleContext", createRef(context, "blueprintBundleContext"));
- bean.addProperty("name", createValue(context, name));
- String rank = element.getAttribute("rank");
- if (rank != null && rank.length() > 0) {
- bean.addProperty("rank", createValue(context, rank));
- }
- NodeList childElements = element.getElementsByTagNameNS(element.getNamespaceURI(), "module");
- if (childElements != null && childElements.getLength() > 0) {
- MutableCollectionMetadata children = context.createMetadata(MutableCollectionMetadata.class);
- for (int i = 0; i < childElements.getLength(); ++i) {
- Element childElement = (Element) childElements.item(i);
- MutableBeanMetadata md = context.createMetadata(MutableBeanMetadata.class);
- md.setRuntimeClass(Module.class);
- md.addProperty("className", createValue(context, childElement.getAttribute("className")));
- if (childElement.getAttribute("name") != null) {
- md.addProperty("name", createValue(context, childElement.getAttribute("name")));
- }
- if (childElement.getAttribute("flags") != null) {
- md.addProperty("flags", createValue(context, childElement.getAttribute("flags")));
- }
- String options = getTextValue(childElement);
- if (options != null && options.length() > 0) {
- md.addProperty("options", createValue(context, options));
- }
- children.addValue(md);
- }
- bean.addProperty("modules", children);
- }
- // Publish Config
- MutableServiceMetadata service = context.createMetadata(MutableServiceMetadata.class);
- service.setId(name);
- service.setServiceComponent(bean);
- service.addInterface(JaasRealm.class.getName());
- service.addServiceProperty(createValue(context, ProxyLoginModule.PROPERTY_MODULE), createValue(context, name));
- return service;
- }
-
- public ComponentMetadata parseKeystore(Element element, ParserContext context) {
- MutableBeanMetadata bean = context.createMetadata(MutableBeanMetadata.class);
- bean.setRuntimeClass(ResourceKeystoreInstance.class);
- // Parse name
- String name = element.getAttribute("name");
- bean.addProperty("name", createValue(context, name));
- // Parse rank
- String rank = element.getAttribute("rank");
- if (rank != null && rank.length() > 0) {
- bean.addProperty("rank", createValue(context, rank));
- }
- // Parse path
- String path = element.getAttribute("path");
- if (path != null && path.length() > 0) {
- bean.addProperty("path", createValue(context, path));
- }
- // Parse keystorePassword
- String keystorePassword = element.getAttribute("keystorePassword");
- if (keystorePassword != null && keystorePassword.length() > 0) {
- bean.addProperty("keystorePassword", createValue(context, keystorePassword));
- }
- // Parse keyPasswords
- String keyPasswords = element.getAttribute("keyPasswords");
- if (keyPasswords != null && keyPasswords.length() > 0) {
- bean.addProperty("keyPasswords", createValue(context, keyPasswords));
- }
- // Publish Config
- MutableServiceMetadata service = context.createMetadata(MutableServiceMetadata.class);
- service.setId(name);
- service.setServiceComponent(bean);
- service.addInterface(KeystoreInstance.class.getName());
- return service;
- }
-
- private ValueMetadata createValue(ParserContext context, String value) {
- MutableValueMetadata v = context.createMetadata(MutableValueMetadata.class);
- v.setStringValue(value);
- return v;
- }
-
- private RefMetadata createRef(ParserContext context, String value) {
- MutableRefMetadata r = context.createMetadata(MutableRefMetadata.class);
- r.setComponentId(value);
- return r;
- }
-
- private static String getTextValue(Element element) {
- StringBuffer value = new StringBuffer();
- NodeList nl = element.getChildNodes();
- for (int i = 0; i < nl.getLength(); i++) {
- Node item = nl.item(i);
- if ((item instanceof CharacterData && !(item instanceof Comment)) || item instanceof EntityReference) {
- value.append(item.getNodeValue());
- }
- }
- return value.toString();
- }
-}
http://git-wip-us.apache.org/repos/asf/karaf/blob/5e2f19c4/jaas/config/src/main/resources/OSGI-INF/blueprint/karaf-jaas.xml
----------------------------------------------------------------------
diff --git a/jaas/config/src/main/resources/OSGI-INF/blueprint/karaf-jaas.xml b/jaas/config/src/main/resources/OSGI-INF/blueprint/karaf-jaas.xml
deleted file mode 100644
index 897671e..0000000
--- a/jaas/config/src/main/resources/OSGI-INF/blueprint/karaf-jaas.xml
+++ /dev/null
@@ -1,61 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
-
- Licensed to the Apache Software Foundation (ASF) under one or more
- contributor license agreements. See the NOTICE file distributed with
- this work for additional information regarding copyright ownership.
- The ASF licenses this file to You under the Apache License, Version 2.0
- (the "License"); you may not use this file except in compliance with
- the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
-
--->
-<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0">
-
- <bean id="config"
- class="org.apache.karaf.jaas.config.impl.OsgiConfiguration"
- init-method="init"
- destroy-method="close"/>
-
- <reference-list id="realms"
- interface="org.apache.karaf.jaas.config.JaasRealm"
- availability="optional">
- <reference-listener ref="config" bind-method="register" unbind-method="unregister" />
- </reference-list>
-
- <bean id="proxyLoginModuleInitializer" class="org.apache.karaf.jaas.config.impl.ProxyLoginModuleInitializer" init-method="init">
- <property name="bundleContext" ref="blueprintBundleContext"/>
- </bean>
-
- <!-- Register the Straight-Through flow -->
- <bean id="keystoreManager" class="org.apache.karaf.jaas.config.impl.OsgiKeystoreManager" />
- <service ref="keystoreManager" interface="org.apache.karaf.jaas.config.KeystoreManager" />
-
- <reference-list id="keystores"
- interface="org.apache.karaf.jaas.config.KeystoreInstance"
- availability="optional">
- <reference-listener ref="keystoreManager" bind-method="register" unbind-method="unregister" />
- </reference-list>
-
- <bean id="namespaceHandler" class="org.apache.karaf.jaas.config.impl.NamespaceHandler"/>
-
- <service ref="namespaceHandler" interface="org.apache.aries.blueprint.NamespaceHandler">
- <service-properties>
- <entry key="osgi.service.blueprint.namespace" value="http://karaf.apache.org/xmlns/jaas/v1.0.0" />
- </service-properties>
- </service>
-
- <service ref="namespaceHandler" interface="org.apache.aries.blueprint.NamespaceHandler">
- <service-properties>
- <entry key="osgi.service.blueprint.namespace" value="http://karaf.apache.org/xmlns/jaas/v1.1.0" />
- </service-properties>
- </service>
-
-</blueprint>
http://git-wip-us.apache.org/repos/asf/karaf/blob/5e2f19c4/jaas/config/src/main/resources/org/apache/karaf/jaas/config/karaf-jaas-1.0.0.xsd
----------------------------------------------------------------------
diff --git a/jaas/config/src/main/resources/org/apache/karaf/jaas/config/karaf-jaas-1.0.0.xsd b/jaas/config/src/main/resources/org/apache/karaf/jaas/config/karaf-jaas-1.0.0.xsd
deleted file mode 100644
index 225665c..0000000
--- a/jaas/config/src/main/resources/org/apache/karaf/jaas/config/karaf-jaas-1.0.0.xsd
+++ /dev/null
@@ -1,62 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
-
- Licensed to the Apache Software Foundation (ASF) under one or more
- contributor license agreements. See the NOTICE file distributed with
- this work for additional information regarding copyright ownership.
- The ASF licenses this file to You under the Apache License, Version 2.0
- (the "License"); you may not use this file except in compliance with
- the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
-
--->
-<xs:schema elementFormDefault='qualified'
- targetNamespace='http://karaf.apache.org/xmlns/jaas/v1.0.0'
- xmlns:xs='http://www.w3.org/2001/XMLSchema'
- xmlns:bp="http://www.osgi.org/xmlns/blueprint/v1.0.0"
- xmlns:tns='http://karaf.apache.org/xmlns/jaas/v1.0.0'>
-
- <xs:import namespace="http://www.osgi.org/xmlns/blueprint/v1.0.0"/>
-
- <xs:element name="config">
- <xs:complexType>
- <xs:sequence>
- <xs:element name="module" minOccurs="0" maxOccurs="unbounded">
- <xs:complexType mixed="true">
- <xs:attribute name="className" use="required" type="xs:string"/>
- <xs:attribute name="flags" default="required">
- <xs:simpleType>
- <xs:restriction base="xs:NMTOKEN">
- <xs:enumeration value="required"/>
- <xs:enumeration value="requisite"/>
- <xs:enumeration value="sufficient"/>
- <xs:enumeration value="optional"/>
- </xs:restriction>
- </xs:simpleType>
- </xs:attribute>
- </xs:complexType>
- </xs:element>
- </xs:sequence>
- <xs:attribute name="name" use="required" type="xs:string"/>
- <xs:attribute name="rank" use="optional" default="0" type="xs:int"/>
- </xs:complexType>
- </xs:element>
-
- <xs:element name="keystore">
- <xs:complexType>
- <xs:attribute name="name" use="required" type="xs:string"/>
- <xs:attribute name="rank" use="optional" default="0" type="xs:int"/>
- <xs:attribute name="path" use="required" type="xs:string"/>
- <xs:attribute name="keystorePassword" use="optional" type="xs:string"/>
- <xs:attribute name="keyPasswords" use="optional" type="xs:string"/>
- </xs:complexType>
- </xs:element>
-
-</xs:schema>
http://git-wip-us.apache.org/repos/asf/karaf/blob/5e2f19c4/jaas/config/src/main/resources/org/apache/karaf/jaas/config/karaf-jaas-1.1.0.xsd
----------------------------------------------------------------------
diff --git a/jaas/config/src/main/resources/org/apache/karaf/jaas/config/karaf-jaas-1.1.0.xsd b/jaas/config/src/main/resources/org/apache/karaf/jaas/config/karaf-jaas-1.1.0.xsd
deleted file mode 100644
index f56b206..0000000
--- a/jaas/config/src/main/resources/org/apache/karaf/jaas/config/karaf-jaas-1.1.0.xsd
+++ /dev/null
@@ -1,63 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
-
- Licensed to the Apache Software Foundation (ASF) under one or more
- contributor license agreements. See the NOTICE file distributed with
- this work for additional information regarding copyright ownership.
- The ASF licenses this file to You under the Apache License, Version 2.0
- (the "License"); you may not use this file except in compliance with
- the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
-
--->
-<xs:schema elementFormDefault='qualified'
- targetNamespace='http://karaf.apache.org/xmlns/jaas/v1.1.0'
- xmlns:xs='http://www.w3.org/2001/XMLSchema'
- xmlns:bp="http://www.osgi.org/xmlns/blueprint/v1.0.0"
- xmlns:tns='http://karaf.apache.org/xmlns/jaas/v1.1.0'>
-
- <xs:import namespace="http://www.osgi.org/xmlns/blueprint/v1.0.0"/>
-
- <xs:element name="config">
- <xs:complexType>
- <xs:sequence>
- <xs:element name="module" minOccurs="0" maxOccurs="unbounded">
- <xs:complexType mixed="true">
- <xs:attribute name="name" use="optional" type="xs:string"/>
- <xs:attribute name="className" use="required" type="xs:string"/>
- <xs:attribute name="flags" default="required">
- <xs:simpleType>
- <xs:restriction base="xs:NMTOKEN">
- <xs:enumeration value="required"/>
- <xs:enumeration value="requisite"/>
- <xs:enumeration value="sufficient"/>
- <xs:enumeration value="optional"/>
- </xs:restriction>
- </xs:simpleType>
- </xs:attribute>
- </xs:complexType>
- </xs:element>
- </xs:sequence>
- <xs:attribute name="name" use="required" type="xs:string"/>
- <xs:attribute name="rank" use="optional" default="0" type="xs:int"/>
- </xs:complexType>
- </xs:element>
-
- <xs:element name="keystore">
- <xs:complexType>
- <xs:attribute name="name" use="required" type="xs:string"/>
- <xs:attribute name="rank" use="optional" default="0" type="xs:int"/>
- <xs:attribute name="path" use="required" type="xs:string"/>
- <xs:attribute name="keystorePassword" use="optional" type="xs:string"/>
- <xs:attribute name="keyPasswords" use="optional" type="xs:string"/>
- </xs:complexType>
- </xs:element>
-
-</xs:schema>
http://git-wip-us.apache.org/repos/asf/karaf/blob/5e2f19c4/jaas/jasypt/pom.xml
----------------------------------------------------------------------
diff --git a/jaas/jasypt/pom.xml b/jaas/jasypt/pom.xml
index 0cc9b35..dc7882b 100644
--- a/jaas/jasypt/pom.xml
+++ b/jaas/jasypt/pom.xml
@@ -38,7 +38,12 @@
</properties>
<dependencies>
-
+
+ <dependency>
+ <groupId>org.osgi</groupId>
+ <artifactId>org.osgi.core</artifactId>
+ </dependency>
+
<dependency>
<groupId>org.apache.karaf.jaas</groupId>
<artifactId>org.apache.karaf.jaas.modules</artifactId>
@@ -71,14 +76,6 @@
<scope>provided</scope>
</dependency>
- <!-- 4.2.0 is needed in order to have aries util work correctly within pojosr -->
- <dependency>
- <groupId>org.osgi</groupId>
- <artifactId>org.osgi.core</artifactId>
- <version>4.2.0</version>
- <scope>test</scope>
- </dependency>
-
<dependency>
<groupId>org.osgi</groupId>
<artifactId>org.osgi.compendium</artifactId>
@@ -153,12 +150,14 @@
<configuration>
<instructions>
<Import-Package>
- org.apache.aries.blueprint,
- org.osgi.service.blueprint.container,
- org.osgi.service.blueprint.reflect,
*
</Import-Package>
- <Private-Package>org.apache.karaf.jaas.jasypt.impl</Private-Package>
+ <Private-Package>
+ org.apache.karaf.jaas.jasypt.impl
+ </Private-Package>
+ <Bundle-Activator>
+ org.apache.karaf.jaas.jasypt.impl.Activator
+ </Bundle-Activator>
</instructions>
</configuration>
</plugin>
http://git-wip-us.apache.org/repos/asf/karaf/blob/5e2f19c4/jaas/jasypt/src/main/java/org/apache/karaf/jaas/jasypt/handler/EncryptablePropertyPlaceholder.java
----------------------------------------------------------------------
diff --git a/jaas/jasypt/src/main/java/org/apache/karaf/jaas/jasypt/handler/EncryptablePropertyPlaceholder.java b/jaas/jasypt/src/main/java/org/apache/karaf/jaas/jasypt/handler/EncryptablePropertyPlaceholder.java
deleted file mode 100644
index c6fed48..0000000
--- a/jaas/jasypt/src/main/java/org/apache/karaf/jaas/jasypt/handler/EncryptablePropertyPlaceholder.java
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- * 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.
- * under the License.
- */
-package org.apache.karaf.jaas.jasypt.handler;
-
-import org.jasypt.encryption.StringEncryptor;
-import org.apache.aries.blueprint.ext.AbstractPropertyPlaceholder;
-
-public class EncryptablePropertyPlaceholder extends AbstractPropertyPlaceholder {
-
- private StringEncryptor encryptor;
-
- public StringEncryptor getEncryptor() {
- return encryptor;
- }
-
- public void setEncryptor(StringEncryptor encryptor) {
- this.encryptor = encryptor;
- }
-
- public void init() {
-
- }
-
- @Override
- protected String getProperty(String val) {
- return encryptor.decrypt(val);
- }
-
-}
http://git-wip-us.apache.org/repos/asf/karaf/blob/5e2f19c4/jaas/jasypt/src/main/java/org/apache/karaf/jaas/jasypt/handler/NamespaceHandler.java
----------------------------------------------------------------------
diff --git a/jaas/jasypt/src/main/java/org/apache/karaf/jaas/jasypt/handler/NamespaceHandler.java b/jaas/jasypt/src/main/java/org/apache/karaf/jaas/jasypt/handler/NamespaceHandler.java
deleted file mode 100644
index 4a196c0..0000000
--- a/jaas/jasypt/src/main/java/org/apache/karaf/jaas/jasypt/handler/NamespaceHandler.java
+++ /dev/null
@@ -1,173 +0,0 @@
-/*
- * 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.
- * under the License.
- */
-package org.apache.karaf.jaas.jasypt.handler;
-
-import java.net.URL;
-import java.util.Arrays;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
-
-import org.apache.aries.blueprint.ParserContext;
-import org.apache.aries.blueprint.ext.PlaceholdersUtils;
-import org.apache.aries.blueprint.mutable.MutableBeanMetadata;
-import org.apache.aries.blueprint.mutable.MutableCollectionMetadata;
-import org.apache.aries.blueprint.mutable.MutableRefMetadata;
-import org.apache.aries.blueprint.mutable.MutableValueMetadata;
-import org.osgi.service.blueprint.container.ComponentDefinitionException;
-import org.osgi.service.blueprint.reflect.BeanMetadata;
-import org.osgi.service.blueprint.reflect.CollectionMetadata;
-import org.osgi.service.blueprint.reflect.ComponentMetadata;
-import org.osgi.service.blueprint.reflect.Metadata;
-import org.osgi.service.blueprint.reflect.RefMetadata;
-import org.osgi.service.blueprint.reflect.ValueMetadata;
-import org.w3c.dom.CharacterData;
-import org.w3c.dom.Comment;
-import org.w3c.dom.Element;
-import org.w3c.dom.EntityReference;
-import org.w3c.dom.Node;
-import org.w3c.dom.NodeList;
-
-public class NamespaceHandler implements org.apache.aries.blueprint.NamespaceHandler {
-
- public static final String ID_ATTRIBUTE = "id";
- public static final String PLACEHOLDER_PREFIX_ATTRIBUTE = "placeholder-prefix";
- public static final String PLACEHOLDER_SUFFIX_ATTRIBUTE = "placeholder-suffix";
- public static final String PROPERTY_PLACEHOLDER_ELEMENT = "property-placeholder";
- public static final String ENCRYPTOR_REF_ATTRIBUTE = "encryptor-ref";
- public static final String ENCRYPTOR_ELEMENT = "encryptor";
- public static final String JASYPT_NAMESPACE_1_0 = "http://karaf.apache.org/xmlns/jasypt/v1.0.0";
-
- private int idCounter;
-
- public URL getSchemaLocation(String s) {
- return getClass().getResource("/org/apache/karaf/jaas/jasypt/handler/karaf-jasypt-1.0.0.xsd");
- }
-
- public Set<Class> getManagedClasses() {
- return new HashSet<Class>(Arrays.asList(
- EncryptablePropertyPlaceholder.class
- ));
- }
-
- public Metadata parse(Element element, ParserContext context) {
- String name = element.getLocalName() != null ? element.getLocalName() : element.getNodeName();
- if (PROPERTY_PLACEHOLDER_ELEMENT.equals(name)) {
- return parsePropertyPlaceholder(element, context);
- }
- throw new ComponentDefinitionException("Bad xml syntax: unknown element '" + name + "'");
- }
-
- public ComponentMetadata decorate(Node node, ComponentMetadata componentMetadata, ParserContext parserContext) {
- throw new ComponentDefinitionException("Bad xml syntax: node decoration is not supported");
- }
-
- public ComponentMetadata parsePropertyPlaceholder(Element element, ParserContext context) {
- MutableBeanMetadata metadata = context.createMetadata(MutableBeanMetadata.class);
- metadata.setProcessor(true);
- metadata.setId(getId(context, element));
- metadata.setScope(BeanMetadata.SCOPE_SINGLETON);
- metadata.setRuntimeClass(EncryptablePropertyPlaceholder.class);
- metadata.setInitMethod("init");
- String prefix = element.hasAttribute(PLACEHOLDER_PREFIX_ATTRIBUTE)
- ? element.getAttribute(PLACEHOLDER_PREFIX_ATTRIBUTE)
- : "ENC(";
- metadata.addProperty("placeholderPrefix", createValue(context, prefix));
- String suffix = element.hasAttribute(PLACEHOLDER_SUFFIX_ATTRIBUTE)
- ? element.getAttribute(PLACEHOLDER_SUFFIX_ATTRIBUTE)
- : ")";
- metadata.addProperty("placeholderSuffix", createValue(context, suffix));
- String encryptorRef = element.hasAttribute("encryptor-ref")
- ? element.getAttribute("encryptor-ref")
- : null;
- if (encryptorRef != null) {
- metadata.addProperty("encryptor", createRef(context, encryptorRef));
- }
- NodeList nl = element.getChildNodes();
- for (int i = 0; i < nl.getLength(); i++) {
- Node node = nl.item(i);
- if (node instanceof Element) {
- Element e = (Element) node;
- if (JASYPT_NAMESPACE_1_0.equals(e.getNamespaceURI())) {
- String name = e.getLocalName() != null ? e.getLocalName() : e.getNodeName();
- if (ENCRYPTOR_ELEMENT.equals(name)) {
- if (encryptorRef != null) {
- throw new ComponentDefinitionException("Only one of " + ENCRYPTOR_REF_ATTRIBUTE + " attribute or " + ENCRYPTOR_ELEMENT + " element is allowed");
- }
- BeanMetadata encryptor = context.parseElement(BeanMetadata.class, metadata, e);
- metadata.addProperty("encryptor", encryptor);
- }
- }
- }
- }
- PlaceholdersUtils.validatePlaceholder(metadata, context.getComponentDefinitionRegistry());
- return metadata;
- }
-
- public String getId(ParserContext context, Element element) {
- if (element.hasAttribute(ID_ATTRIBUTE)) {
- return element.getAttribute(ID_ATTRIBUTE);
- } else {
- return generateId(context);
- }
- }
-
- private String generateId(ParserContext context) {
- String id;
- do {
- id = ".jaas-" + ++idCounter;
- } while (context.getComponentDefinitionRegistry().containsComponentDefinition(id));
- return id;
- }
-
- private static ValueMetadata createValue(ParserContext context, String value) {
- return createValue(context, value, null);
- }
-
- private static ValueMetadata createValue(ParserContext context, String value, String type) {
- MutableValueMetadata m = context.createMetadata(MutableValueMetadata.class);
- m.setStringValue(value);
- m.setType(type);
- return m;
- }
-
- private static CollectionMetadata createList(ParserContext context, List<String> list) {
- MutableCollectionMetadata m = context.createMetadata(MutableCollectionMetadata.class);
- m.setCollectionClass(List.class);
- m.setValueType(String.class.getName());
- for (String v : list) {
- m.addValue(createValue(context, v, String.class.getName()));
- }
- return m;
- }
-
- private RefMetadata createRef(ParserContext context, String value) {
- MutableRefMetadata r = context.createMetadata(MutableRefMetadata.class);
- r.setComponentId(value);
- return r;
- }
-
- private static String getTextValue(Element element) {
- StringBuffer value = new StringBuffer();
- NodeList nl = element.getChildNodes();
- for (int i = 0; i < nl.getLength(); i++) {
- Node item = nl.item(i);
- if ((item instanceof CharacterData && !(item instanceof Comment)) || item instanceof EntityReference) {
- value.append(item.getNodeValue());
- }
- }
- return value.toString();
- }
-}
http://git-wip-us.apache.org/repos/asf/karaf/blob/5e2f19c4/jaas/jasypt/src/main/java/org/apache/karaf/jaas/jasypt/impl/Activator.java
----------------------------------------------------------------------
diff --git a/jaas/jasypt/src/main/java/org/apache/karaf/jaas/jasypt/impl/Activator.java b/jaas/jasypt/src/main/java/org/apache/karaf/jaas/jasypt/impl/Activator.java
new file mode 100644
index 0000000..bbb3eac
--- /dev/null
+++ b/jaas/jasypt/src/main/java/org/apache/karaf/jaas/jasypt/impl/Activator.java
@@ -0,0 +1,45 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.karaf.jaas.jasypt.impl;
+
+import java.util.Hashtable;
+
+import org.apache.karaf.jaas.modules.EncryptionService;
+import org.osgi.framework.BundleActivator;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceRegistration;
+
+public class Activator implements BundleActivator {
+
+ private ServiceRegistration<EncryptionService> registration;
+
+ @Override
+ public void start(BundleContext context) throws Exception {
+ Hashtable<String, Object> props = new Hashtable<String, Object>();
+ props.put("name", "jasypt");
+ registration = context.registerService(
+ EncryptionService.class,
+ new JasyptEncryptionService(),
+ props);
+
+ }
+
+ @Override
+ public void stop(BundleContext context) throws Exception {
+ registration.unregister();
+ }
+}
http://git-wip-us.apache.org/repos/asf/karaf/blob/5e2f19c4/jaas/jasypt/src/main/resources/OSGI-INF/blueprint/karaf-jaas-jasypt.xml
----------------------------------------------------------------------
diff --git a/jaas/jasypt/src/main/resources/OSGI-INF/blueprint/karaf-jaas-jasypt.xml b/jaas/jasypt/src/main/resources/OSGI-INF/blueprint/karaf-jaas-jasypt.xml
deleted file mode 100644
index a20482a..0000000
--- a/jaas/jasypt/src/main/resources/OSGI-INF/blueprint/karaf-jaas-jasypt.xml
+++ /dev/null
@@ -1,37 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
-
- Licensed to the Apache Software Foundation (ASF) under one or more
- contributor license agreements. See the NOTICE file distributed with
- this work for additional information regarding copyright ownership.
- The ASF licenses this file to You under the Apache License, Version 2.0
- (the "License"); you may not use this file except in compliance with
- the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
-
--->
-<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0">
-
- <service interface="org.apache.karaf.jaas.modules.EncryptionService">
- <service-properties>
- <entry key="name" value="jasypt" />
- </service-properties>
- <bean class="org.apache.karaf.jaas.jasypt.impl.JasyptEncryptionService"/>
- </service>
-
- <bean id="namespaceHandler" class="org.apache.karaf.jaas.jasypt.handler.NamespaceHandler"/>
-
- <service ref="namespaceHandler" interface="org.apache.aries.blueprint.NamespaceHandler">
- <service-properties>
- <entry key="osgi.service.blueprint.namespace" value="http://karaf.apache.org/xmlns/jasypt/v1.0.0" />
- </service-properties>
- </service>
-
-</blueprint>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/karaf/blob/5e2f19c4/jaas/jasypt/src/main/resources/org/apache/karaf/jaas/jasypt/handler/karaf-jasypt-1.0.0.xsd
----------------------------------------------------------------------
diff --git a/jaas/jasypt/src/main/resources/org/apache/karaf/jaas/jasypt/handler/karaf-jasypt-1.0.0.xsd b/jaas/jasypt/src/main/resources/org/apache/karaf/jaas/jasypt/handler/karaf-jasypt-1.0.0.xsd
deleted file mode 100644
index f5e6921..0000000
--- a/jaas/jasypt/src/main/resources/org/apache/karaf/jaas/jasypt/handler/karaf-jasypt-1.0.0.xsd
+++ /dev/null
@@ -1,43 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
-
- Licensed to the Apache Software Foundation (ASF) under one or more
- contributor license agreements. See the NOTICE file distributed with
- this work for additional information regarding copyright ownership.
- The ASF licenses this file to You under the Apache License, Version 2.0
- (the "License"); you may not use this file except in compliance with
- the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
-
--->
-<xs:schema elementFormDefault='qualified'
- targetNamespace='http://karaf.apache.org/xmlns/jasypt/v1.0.0'
- xmlns:xs='http://www.w3.org/2001/XMLSchema'
- xmlns:bp="http://www.osgi.org/xmlns/blueprint/v1.0.0"
- xmlns:tns='http://karaf.apache.org/xmlns/jasypt/v1.0.0'>
-
- <xs:import namespace="http://www.osgi.org/xmlns/blueprint/v1.0.0"/>
-
- <xs:element name="property-placeholder">
- <xs:complexType>
- <xs:complexContent>
- <xs:extension base="bp:Tcomponent">
- <xs:sequence>
- <xs:element maxOccurs="1" minOccurs="0" name="encryptor" type="bp:Tbean"/>
- </xs:sequence>
- <xs:attribute name="placeholder-prefix" type="xs:string" use="optional" default="ENC("/>
- <xs:attribute name="placeholder-suffix" type="xs:string" use="optional" default=")"/>
- <xs:attribute name="encryptor-ref" type="bp:Tidref" use="optional"/>
- </xs:extension>
- </xs:complexContent>
- </xs:complexType>
- </xs:element>
-
-</xs:schema>
http://git-wip-us.apache.org/repos/asf/karaf/blob/5e2f19c4/jaas/jasypt/src/test/java/org/apache/karaf/jaas/jasypt/handler/EncryptablePropertyPlaceholderTest.java
----------------------------------------------------------------------
diff --git a/jaas/jasypt/src/test/java/org/apache/karaf/jaas/jasypt/handler/EncryptablePropertyPlaceholderTest.java b/jaas/jasypt/src/test/java/org/apache/karaf/jaas/jasypt/handler/EncryptablePropertyPlaceholderTest.java
deleted file mode 100644
index 5c80048..0000000
--- a/jaas/jasypt/src/test/java/org/apache/karaf/jaas/jasypt/handler/EncryptablePropertyPlaceholderTest.java
+++ /dev/null
@@ -1,228 +0,0 @@
-/*
- * 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.
- * under the License.
- */
-package org.apache.karaf.jaas.jasypt.handler;
-
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.net.URL;
-import java.util.Collection;
-import java.util.Dictionary;
-import java.util.Enumeration;
-import java.util.HashMap;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Map;
-import java.util.jar.JarInputStream;
-
-import de.kalpatec.pojosr.framework.PojoServiceRegistryFactoryImpl;
-import de.kalpatec.pojosr.framework.launch.BundleDescriptor;
-import de.kalpatec.pojosr.framework.launch.ClasspathScanner;
-import de.kalpatec.pojosr.framework.launch.PojoServiceRegistry;
-import de.kalpatec.pojosr.framework.launch.PojoServiceRegistryFactory;
-import junit.framework.TestCase;
-import org.jasypt.encryption.pbe.StandardPBEStringEncryptor;
-import org.jasypt.encryption.pbe.config.EnvironmentStringPBEConfig;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-import org.ops4j.pax.tinybundles.core.TinyBundle;
-import org.osgi.framework.Bundle;
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.Constants;
-import org.osgi.framework.Filter;
-import org.osgi.framework.FrameworkUtil;
-import org.osgi.framework.InvalidSyntaxException;
-import org.osgi.framework.ServiceReference;
-import org.osgi.util.tracker.ServiceTracker;
-
-import static org.ops4j.pax.tinybundles.core.TinyBundles.bundle;
-
-public class EncryptablePropertyPlaceholderTest extends TestCase {
-
- public static final long DEFAULT_TIMEOUT = 30000;
-
- private BundleContext bundleContext;
-
- @Before
- public void setUp() throws Exception {
-
- StandardPBEStringEncryptor enc = new StandardPBEStringEncryptor();
- EnvironmentStringPBEConfig env = new EnvironmentStringPBEConfig();
- env.setAlgorithm("PBEWithMD5AndDES");
- env.setPassword("password");
- enc.setConfig(env);
- String val = enc.encrypt("bar");
- System.setProperty("foo", val);
-
- System.setProperty("org.bundles.framework.storage", "target/bundles/" + System.currentTimeMillis());
- System.setProperty("karaf.name", "root");
-
- List<BundleDescriptor> bundles = new ClasspathScanner().scanForBundles("(Bundle-SymbolicName=*)");
- bundles.add(getBundleDescriptor(
- "target/jasypt.jar",
- bundle().add("OSGI-INF/blueprint/karaf-jaas-jasypt.xml", getClass().getResource("/OSGI-INF/blueprint/karaf-jaas-jasypt.xml"))
- .set("Manifest-Version", "2")
- .set("Bundle-ManifestVersion", "2")
- .set("Bundle-SymbolicName", "jasypt")
- .set("Bundle-Version", "0.0.0")));
- bundles.add(getBundleDescriptor(
- "target/test.jar",
- bundle().add("OSGI-INF/blueprint/test.xml", getClass().getResource("test.xml"))
- .set("Manifest-Version", "2")
- .set("Bundle-ManifestVersion", "2")
- .set("Bundle-SymbolicName", "test")
- .set("Bundle-Version", "0.0.0")));
-
- Map config = new HashMap();
- config.put(PojoServiceRegistryFactory.BUNDLE_DESCRIPTORS, bundles);
- PojoServiceRegistry reg = new PojoServiceRegistryFactoryImpl().newPojoServiceRegistry(config);
- bundleContext = reg.getBundleContext();
- }
-
- private BundleDescriptor getBundleDescriptor(String path, TinyBundle bundle) throws Exception {
- File file = new File(path);
- FileOutputStream fos = new FileOutputStream(file);
- copy(bundle.build(), fos);
- fos.close();
- JarInputStream jis = new JarInputStream(new FileInputStream(file));
- Map<String, String> headers = new HashMap<String, String>();
- for (Map.Entry entry : jis.getManifest().getMainAttributes().entrySet()) {
- headers.put(entry.getKey().toString(), entry.getValue().toString());
- }
- return new BundleDescriptor(
- getClass().getClassLoader(),
- new URL("jar:" + file.toURI().toString() + "!/"),
- headers);
- }
-
- @After
- public void tearDown() throws Exception {
- bundleContext.getBundle().stop();
- }
-
- @Test
- public void testPlaceholder() throws Exception {
-
- for (Bundle bundle: bundleContext.getBundles()) {
- System.out.println(bundle.getSymbolicName() + " / " + bundle.getVersion());
- }
-
- String encoded = getOsgiService(String.class, "(encoded=*)");
- assertEquals("bar", encoded);
- }
-
-
- protected <T> T getOsgiService(Class<T> type, long timeout) {
- return getOsgiService(type, null, timeout);
- }
-
- protected <T> T getOsgiService(Class<T> type) {
- return getOsgiService(type, null, DEFAULT_TIMEOUT);
- }
-
- protected <T> T getOsgiService(Class<T> type, String filter) {
- return getOsgiService(type, filter, DEFAULT_TIMEOUT);
- }
-
- protected <T> T getOsgiService(Class<T> type, String filter, long timeout) {
- ServiceTracker tracker = null;
- try {
- String flt;
- if (filter != null) {
- if (filter.startsWith("(")) {
- flt = "(&(" + Constants.OBJECTCLASS + "=" + type.getName() + ")" + filter + ")";
- } else {
- flt = "(&(" + Constants.OBJECTCLASS + "=" + type.getName() + ")(" + filter + "))";
- }
- } else {
- flt = "(" + Constants.OBJECTCLASS + "=" + type.getName() + ")";
- }
- Filter osgiFilter = FrameworkUtil.createFilter(flt);
- tracker = new ServiceTracker(bundleContext, osgiFilter, null);
- tracker.open(true);
- // Note that the tracker is not closed to keep the reference
- // This is buggy, as the service reference may change i think
- Object svc = type.cast(tracker.waitForService(timeout));
- if (svc == null) {
- Dictionary dic = bundleContext.getBundle().getHeaders();
- System.err.println("Test bundle headers: " + explode(dic));
-
- for (ServiceReference ref : asCollection(bundleContext.getAllServiceReferences(null, null))) {
- System.err.println("ServiceReference: " + ref);
- }
-
- for (ServiceReference ref : asCollection(bundleContext.getAllServiceReferences(null, flt))) {
- System.err.println("Filtered ServiceReference: " + ref);
- }
-
- throw new RuntimeException("Gave up waiting for service " + flt);
- }
- return type.cast(svc);
- } catch (InvalidSyntaxException e) {
- throw new IllegalArgumentException("Invalid filter", e);
- } catch (InterruptedException e) {
- throw new RuntimeException(e);
- }
- }
-
- /*
- * Explode the dictionary into a ,-delimited list of key=value pairs
- */
- private static String explode(Dictionary dictionary) {
- Enumeration keys = dictionary.keys();
- StringBuffer result = new StringBuffer();
- while (keys.hasMoreElements()) {
- Object key = keys.nextElement();
- result.append(String.format("%s=%s", key, dictionary.get(key)));
- if (keys.hasMoreElements()) {
- result.append(", ");
- }
- }
- return result.toString();
- }
-
- /*
- * Provides an iterable collection of references, even if the original array is null
- */
- private static final Collection<ServiceReference> asCollection(ServiceReference[] references) {
- List<ServiceReference> result = new LinkedList<ServiceReference>();
- if (references != null) {
- for (ServiceReference reference : references) {
- result.add(reference);
- }
- }
- return result;
- }
-
- public static long copy(final InputStream input, final OutputStream output) throws IOException {
- return copy(input, output, 8024);
- }
-
- public static long copy(final InputStream input, final OutputStream output, int buffersize) throws IOException {
- final byte[] buffer = new byte[buffersize];
- int n;
- long count=0;
- while (-1 != (n = input.read(buffer))) {
- output.write(buffer, 0, n);
- count += n;
- }
- return count;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/karaf/blob/5e2f19c4/jaas/jasypt/src/test/resources/org/apache/karaf/jaas/jasypt/handler/test.xml
----------------------------------------------------------------------
diff --git a/jaas/jasypt/src/test/resources/org/apache/karaf/jaas/jasypt/handler/test.xml b/jaas/jasypt/src/test/resources/org/apache/karaf/jaas/jasypt/handler/test.xml
deleted file mode 100644
index c3a2aff..0000000
--- a/jaas/jasypt/src/test/resources/org/apache/karaf/jaas/jasypt/handler/test.xml
+++ /dev/null
@@ -1,45 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
- Licensed to the Apache Software Foundation (ASF) under one or more
- contributor license agreements. See the NOTICE file distributed with
- this work for additional information regarding copyright ownership.
- The ASF licenses this file to You under the Apache License, Version 2.0
- (the "License"); you may not use this file except in compliance with
- the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
--->
-<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
- xmlns:ext="http://aries.apache.org/blueprint/xmlns/blueprint-ext/v1.0.0"
- xmlns:enc="http://karaf.apache.org/xmlns/jasypt/v1.0.0">
-
-
- <ext:property-placeholder />
-
- <enc:property-placeholder>
- <enc:encryptor class="org.jasypt.encryption.pbe.StandardPBEStringEncryptor">
- <property name="config">
- <bean class="org.jasypt.encryption.pbe.config.EnvironmentStringPBEConfig">
- <property name="algorithm" value="PBEWithMD5AndDES" />
- <property name="password" value="password" />
- </bean>
- </property>
- </enc:encryptor>
- </enc:property-placeholder>
-
- <service auto-export="all-classes">
- <service-properties>
- <entry key="encoded" value="ENC(${foo})" />
- </service-properties>
- <bean class="java.lang.String">
- <argument value="ENC(${foo})" />
- </bean>
- </service>
-
-</blueprint>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/karaf/blob/5e2f19c4/jaas/modules/pom.xml
----------------------------------------------------------------------
diff --git a/jaas/modules/pom.xml b/jaas/modules/pom.xml
index a74adc2..1ed86a4 100644
--- a/jaas/modules/pom.xml
+++ b/jaas/modules/pom.xml
@@ -114,15 +114,16 @@
<instructions>
<Import-Package>
javax.net,
- org.apache.aries.blueprint,
- org.osgi.service.blueprint.container,
- org.osgi.service.blueprint.reflect,
org.apache.karaf.jaas.config,
*
</Import-Package>
<Private-Package>
+ org.apache.karaf.jaas.modules.impl,
org.apache.felix.utils.properties
</Private-Package>
+ <Bundle-Activator>
+ org.apache.karaf.jaas.modules.impl.Activator
+ </Bundle-Activator>
</instructions>
</configuration>
</plugin>
http://git-wip-us.apache.org/repos/asf/karaf/blob/5e2f19c4/jaas/modules/src/main/java/org/apache/karaf/jaas/modules/impl/Activator.java
----------------------------------------------------------------------
diff --git a/jaas/modules/src/main/java/org/apache/karaf/jaas/modules/impl/Activator.java b/jaas/modules/src/main/java/org/apache/karaf/jaas/modules/impl/Activator.java
new file mode 100644
index 0000000..b065822
--- /dev/null
+++ b/jaas/modules/src/main/java/org/apache/karaf/jaas/modules/impl/Activator.java
@@ -0,0 +1,48 @@
+package org.apache.karaf.jaas.modules.impl;
+
+import java.util.Hashtable;
+
+import org.apache.karaf.jaas.config.JaasRealm;
+import org.apache.karaf.jaas.modules.BackingEngineFactory;
+import org.apache.karaf.jaas.modules.EncryptionService;
+import org.apache.karaf.jaas.modules.encryption.BasicEncryptionService;
+import org.apache.karaf.jaas.modules.properties.PropertiesBackingEngineFactory;
+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.ManagedService;
+
+public class Activator implements BundleActivator {
+
+ private ServiceRegistration<BackingEngineFactory> propertiesBackingEngineFactoryServiceRegistration;
+ private ServiceRegistration<EncryptionService> basicEncryptionServiceServiceRegistration;
+ private ServiceRegistration karafRealmServiceRegistration;
+
+ @Override
+ public void start(BundleContext context) throws Exception {
+ propertiesBackingEngineFactoryServiceRegistration =
+ context.registerService(BackingEngineFactory.class, new PropertiesBackingEngineFactory(), null);
+
+ Hashtable<String, Object> props = new Hashtable<String, Object>();
+ props.put(Constants.SERVICE_RANKING, -1);
+ props.put("name", "basic");
+ basicEncryptionServiceServiceRegistration =
+ context.registerService(EncryptionService.class, new BasicEncryptionService(), props);
+
+ props = new Hashtable<String, Object>();
+ props.put(Constants.SERVICE_PID, "org.apache.karaf.jaas");
+ karafRealmServiceRegistration =
+ context.registerService(new String[] {
+ JaasRealm.class.getName(),
+ ManagedService.class.getName()
+ }, new KarafRealm(context), props);
+ }
+
+ @Override
+ public void stop(BundleContext context) throws Exception {
+ karafRealmServiceRegistration.unregister();
+ basicEncryptionServiceServiceRegistration.unregister();
+ propertiesBackingEngineFactoryServiceRegistration.unregister();
+ }
+}
http://git-wip-us.apache.org/repos/asf/karaf/blob/5e2f19c4/jaas/modules/src/main/java/org/apache/karaf/jaas/modules/impl/KarafRealm.java
----------------------------------------------------------------------
diff --git a/jaas/modules/src/main/java/org/apache/karaf/jaas/modules/impl/KarafRealm.java b/jaas/modules/src/main/java/org/apache/karaf/jaas/modules/impl/KarafRealm.java
new file mode 100644
index 0000000..ecbcc1e
--- /dev/null
+++ b/jaas/modules/src/main/java/org/apache/karaf/jaas/modules/impl/KarafRealm.java
@@ -0,0 +1,109 @@
+/*
+ * 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.
+ * under the License.
+ */
+package org.apache.karaf.jaas.modules.impl;
+
+import org.apache.karaf.jaas.boot.ProxyLoginModule;
+import org.apache.karaf.jaas.config.JaasRealm;
+import org.osgi.framework.BundleContext;
+import org.osgi.service.cm.ConfigurationException;
+import org.osgi.service.cm.ManagedService;
+
+import javax.security.auth.login.AppConfigurationEntry;
+import java.io.File;
+import java.util.ArrayList;
+import java.util.Dictionary;
+import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+public class KarafRealm implements JaasRealm, ManagedService {
+
+ private static final String KARAF_ETC = System.getProperty("karaf.base") + File.separatorChar + "etc";
+ private static final String REALM = "karaf";
+ private static final String PROPERTIES_MODULE = "org.apache.karaf.jaas.modules.properties.PropertiesLoginModule";
+ private static final String PUBLIC_KEY_MODULE = "org.apache.karaf.jaas.modules.publickey.PublickeyLoginModule";
+
+ private static final String ENCRYPTION_NAME = "encryption.name";
+ private static final String ENCRYPTION_ENABLED = "encryption.enabled";
+ private static final String ENCRYPTION_PREFIX = "encryption.prefix";
+ private static final String ENCRYPTION_SUFFIX = "encryption.suffix";
+ private static final String ENCRYPTION_ALGORITHM = "encryption.algorithm";
+ private static final String ENCRYPTION_ENCODING = "encryption.encoding";
+ private static final String MODULE = "org.apache.karaf.jaas.module";
+
+ private final BundleContext bundleContext;
+ private volatile Map<String, Object> properties;
+
+ public KarafRealm(BundleContext bundleContext) {
+ this.bundleContext = bundleContext;
+ this.properties = new HashMap<String, Object>();
+ populateDefault(this.properties);
+ }
+
+ private void populateDefault(Map<String, Object> props) {
+ props.put("detailed.login.exception", "false");
+ props.put(ENCRYPTION_NAME, "");
+ props.put(ENCRYPTION_ENABLED, "false");
+ props.put(ENCRYPTION_PREFIX, "{CRYPT}");
+ props.put(ENCRYPTION_SUFFIX, "{CRYPT}");
+ props.put(ENCRYPTION_ALGORITHM, "MD5");
+ props.put(ENCRYPTION_ENCODING, "hexadecimal");
+ }
+
+ @Override
+ public void updated(Dictionary<String, ?> properties) throws ConfigurationException {
+ Map<String, Object> props = new HashMap<String, Object>();
+ populateDefault(props);
+ for (Enumeration<String> keyEnum = properties.keys(); keyEnum.hasMoreElements(); ) {
+ String key = keyEnum.nextElement();
+ props.put(key, properties.get(key));
+ }
+ this.properties = props;
+ }
+
+ @Override
+ public String getName() {
+ return REALM;
+ }
+
+ @Override
+ public int getRank() {
+ return 0;
+ }
+
+ @Override
+ public AppConfigurationEntry[] getEntries() {
+ Map<String, Object> propertiesOptions = new HashMap<String, Object>();
+ propertiesOptions.putAll(properties);
+ propertiesOptions.put(BundleContext.class.getName(), bundleContext);
+ propertiesOptions.put(ProxyLoginModule.PROPERTY_MODULE, PROPERTIES_MODULE);
+ propertiesOptions.put(ProxyLoginModule.PROPERTY_BUNDLE, Long.toString(bundleContext.getBundle().getBundleId()));
+ propertiesOptions.put("users", KARAF_ETC + File.separatorChar + "users.properties");
+
+ Map<String, Object> publicKeyOptions = new HashMap<String, Object>();
+ publicKeyOptions.putAll(properties);
+ publicKeyOptions.put(BundleContext.class.getName(), bundleContext);
+ publicKeyOptions.put(ProxyLoginModule.PROPERTY_MODULE, PUBLIC_KEY_MODULE);
+ publicKeyOptions.put(ProxyLoginModule.PROPERTY_BUNDLE, Long.toString(bundleContext.getBundle().getBundleId()));
+ publicKeyOptions.put("users", KARAF_ETC + File.separatorChar + "keys.properties");
+
+ return new AppConfigurationEntry[] {
+ new AppConfigurationEntry(ProxyLoginModule.class.getName(), AppConfigurationEntry.LoginModuleControlFlag.SUFFICIENT, propertiesOptions),
+ new AppConfigurationEntry(ProxyLoginModule.class.getName(), AppConfigurationEntry.LoginModuleControlFlag.SUFFICIENT, publicKeyOptions)
+ };
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/karaf/blob/5e2f19c4/jaas/modules/src/main/java/org/apache/karaf/jaas/modules/properties/PropertiesConverter.java
----------------------------------------------------------------------
diff --git a/jaas/modules/src/main/java/org/apache/karaf/jaas/modules/properties/PropertiesConverter.java b/jaas/modules/src/main/java/org/apache/karaf/jaas/modules/properties/PropertiesConverter.java
deleted file mode 100644
index 6a833bf..0000000
--- a/jaas/modules/src/main/java/org/apache/karaf/jaas/modules/properties/PropertiesConverter.java
+++ /dev/null
@@ -1,51 +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.karaf.jaas.modules.properties;
-
-import org.osgi.service.blueprint.container.Converter;
-import org.osgi.service.blueprint.container.ReifiedType;
-
-import java.util.Properties;
-
-/**
- * Custom converter to transform a string into a Properties instance.
- * (to avoid removing \ from the values as is done by the default blueprint converter)
- */
-public class PropertiesConverter implements Converter {
-
- public boolean canConvert(Object from, ReifiedType type) {
- return String.class.isAssignableFrom(from.getClass())
- && Properties.class.equals(type.getRawClass());
- }
-
- public Object convert(Object from, ReifiedType type) throws Exception {
- Properties properties = new Properties();
-
- String text = (String) from;
- for (String line : text.split("[\\r\\n]+")) {
- int index = line.indexOf('=');
- if (index > 0) {
- String key = line.substring(0, index).trim();
- String value = line.substring(index + 1).trim();
- properties.put(key, value.replaceAll("\\\\", "/"));
- }
- }
-
- return properties;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/karaf/blob/5e2f19c4/jaas/modules/src/main/resources/OSGI-INF/blueprint/karaf-jaas-module.xml
----------------------------------------------------------------------
diff --git a/jaas/modules/src/main/resources/OSGI-INF/blueprint/karaf-jaas-module.xml b/jaas/modules/src/main/resources/OSGI-INF/blueprint/karaf-jaas-module.xml
deleted file mode 100644
index b079902..0000000
--- a/jaas/modules/src/main/resources/OSGI-INF/blueprint/karaf-jaas-module.xml
+++ /dev/null
@@ -1,75 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
-
- Licensed to the Apache Software Foundation (ASF) under one or more
- contributor license agreements. See the NOTICE file distributed with
- this work for additional information regarding copyright ownership.
- The ASF licenses this file to You under the Apache License, Version 2.0
- (the "License"); you may not use this file except in compliance with
- the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
-
--->
-<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
- xmlns:jaas="http://karaf.apache.org/xmlns/jaas/v1.0.0"
- xmlns:cm="http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.1.0"
- xmlns:ext="http://aries.apache.org/blueprint/xmlns/blueprint-ext/v1.0.0">
-
- <type-converters>
- <bean class="org.apache.karaf.jaas.modules.properties.PropertiesConverter"/>
- </type-converters>
-
- <!-- Allow usage of System properties, especially the karaf.base property -->
- <ext:property-placeholder placeholder-prefix="$[" placeholder-suffix="]"/>
-
- <!-- AdminConfig property place holder for the org.apache.karaf.jaas -->
- <cm:property-placeholder persistent-id="org.apache.karaf.jaas" update-strategy="reload">
- <cm:default-properties>
- <cm:property name="detailed.login.exception" value="false"/>
- <cm:property name="encryption.name" value=""/>
- <cm:property name="encryption.enabled" value="false"/>
- <cm:property name="encryption.prefix" value="{CRYPT}"/>
- <cm:property name="encryption.suffix" value="{CRYPT}"/>
- <cm:property name="encryption.algorithm" value="MD5"/>
- <cm:property name="encryption.encoding" value="hexadecimal"/>
- </cm:default-properties>
- </cm:property-placeholder>
-
- <jaas:config name="karaf">
- <jaas:module className="org.apache.karaf.jaas.modules.properties.PropertiesLoginModule" flags="sufficient">
- users = $[karaf.etc]/users.properties
- detailed.login.exception = ${detailed.login.exception}
- encryption.name = ${encryption.name}
- encryption.enabled = ${encryption.enabled}
- encryption.prefix = ${encryption.prefix}
- encryption.suffix = ${encryption.suffix}
- encryption.algorithm = ${encryption.algorithm}
- encryption.encoding = ${encryption.encoding}
- </jaas:module>
- <jaas:module className="org.apache.karaf.jaas.modules.publickey.PublickeyLoginModule" flags="sufficient">
- users = $[karaf.etc]/keys.properties
- detailed.login.exception = ${detailed.login.exception}
- </jaas:module>
- </jaas:config>
-
-
- <!-- The Backing Engine Factory Service for the PropertiesLoginModule -->
- <service interface="org.apache.karaf.jaas.modules.BackingEngineFactory">
- <bean class="org.apache.karaf.jaas.modules.properties.PropertiesBackingEngineFactory"/>
- </service>
-
- <service interface="org.apache.karaf.jaas.modules.EncryptionService" ranking="-1">
- <service-properties>
- <entry key="name" value="basic"/>
- </service-properties>
- <bean class="org.apache.karaf.jaas.modules.encryption.BasicEncryptionService"/>
- </service>
-
-</blueprint>
http://git-wip-us.apache.org/repos/asf/karaf/blob/5e2f19c4/jaas/modules/src/test/java/org/apache/karaf/jaas/modules/properties/PropertiesConverterTest.java
----------------------------------------------------------------------
diff --git a/jaas/modules/src/test/java/org/apache/karaf/jaas/modules/properties/PropertiesConverterTest.java b/jaas/modules/src/test/java/org/apache/karaf/jaas/modules/properties/PropertiesConverterTest.java
deleted file mode 100644
index 0156ef8..0000000
--- a/jaas/modules/src/test/java/org/apache/karaf/jaas/modules/properties/PropertiesConverterTest.java
+++ /dev/null
@@ -1,66 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.karaf.jaas.modules.properties;
-
-import junit.framework.TestCase;
-import org.osgi.service.blueprint.container.ReifiedType;
-
-import java.util.Properties;
-import java.util.List;
-
-/**
- * Test cases for {@link org.apache.karaf.jaas.modules.properties.PropertiesConverter}
- */
-public class PropertiesConverterTest extends TestCase {
-
- private PropertiesConverter converter;
-
- public void setUp() {
- converter = new PropertiesConverter();
- }
-
- /*
- * Test the canConvert method
- */
- public void testCanConvert() {
- assertTrue(converter.canConvert("a string", new ReifiedType(Properties.class)));
- assertFalse(converter.canConvert(new Object(), new ReifiedType(Properties.class)));
- assertFalse(converter.canConvert("a string", new ReifiedType(List.class)));
- }
-
- /*
- * Test the convert method when dealing with unix paths (no \)
- */
- public void testConvertWithUnixPathNames() throws Exception {
- Properties properties =
- (Properties) converter.convert("users = /opt/karaf/etc/users.properties",
- new ReifiedType(Properties.class));
- assertNotNull(properties);
- assertEquals("/opt/karaf/etc/users.properties", properties.get("users"));
- }
-
- /*
- * Test the convert method when dealing with windows paths (avoid escaping \)
- */
- public void testConvertWithWindowsPathNames() throws Exception {
- Properties properties =
- (Properties) converter.convert("users = c:\\opt\\karaf/etc/users.properties",
- new ReifiedType(Properties.class));
- assertNotNull(properties);
- assertEquals("c:/opt/karaf/etc/users.properties", properties.get("users"));
- }
-}
http://git-wip-us.apache.org/repos/asf/karaf/blob/5e2f19c4/jaas/pom.xml
----------------------------------------------------------------------
diff --git a/jaas/pom.xml b/jaas/pom.xml
index 0a96bf8..1709e21 100644
--- a/jaas/pom.xml
+++ b/jaas/pom.xml
@@ -39,6 +39,7 @@
<module>modules</module>
<module>jasypt</module>
<module>command</module>
+ <module>blueprint</module>
</modules>
</project>
http://git-wip-us.apache.org/repos/asf/karaf/blob/5e2f19c4/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index 7e90888..73c068b 100644
--- a/pom.xml
+++ b/pom.xml
@@ -695,6 +695,16 @@
<artifactId>org.apache.karaf.jaas.modules</artifactId>
<version>${project.version}</version>
</dependency>
+ <dependency>
+ <groupId>org.apache.karaf.jaas.blueprint</groupId>
+ <artifactId>org.apache.karaf.jaas.blueprint.config</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.karaf.jaas.blueprint</groupId>
+ <artifactId>org.apache.karaf.jaas.blueprint.jasypt</artifactId>
+ <version>${project.version}</version>
+ </dependency>
<dependency>
<groupId>org.apache.karaf.webconsole</groupId>
[02/24] git commit: [KARAF-2833] Make config/core independent of
blueprint
Posted by gn...@apache.org.
[KARAF-2833] Make config/core independent of blueprint
Project: http://git-wip-us.apache.org/repos/asf/karaf/repo
Commit: http://git-wip-us.apache.org/repos/asf/karaf/commit/5db77ebe
Tree: http://git-wip-us.apache.org/repos/asf/karaf/tree/5db77ebe
Diff: http://git-wip-us.apache.org/repos/asf/karaf/diff/5db77ebe
Branch: refs/heads/master
Commit: 5db77ebe8980f0b54dc5ec15b44b9ffd2c0c7867
Parents: 766e7dd
Author: Guillaume Nodet <gn...@gmail.com>
Authored: Fri Mar 21 18:18:32 2014 +0100
Committer: Guillaume Nodet <gn...@gmail.com>
Committed: Mon Mar 24 17:30:12 2014 +0100
----------------------------------------------------------------------
.../standard/src/main/feature/feature.xml | 1 -
config/core/pom.xml | 12 +-
.../karaf/config/core/impl/osgi/Activator.java | 148 +++++++++++++++++++
.../resources/OSGI-INF/blueprint/blueprint.xml | 44 ------
4 files changed, 159 insertions(+), 46 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/karaf/blob/5db77ebe/assemblies/features/standard/src/main/feature/feature.xml
----------------------------------------------------------------------
diff --git a/assemblies/features/standard/src/main/feature/feature.xml b/assemblies/features/standard/src/main/feature/feature.xml
index 0bfb302..8656d87 100644
--- a/assemblies/features/standard/src/main/feature/feature.xml
+++ b/assemblies/features/standard/src/main/feature/feature.xml
@@ -130,7 +130,6 @@
</feature>
<feature name="config" description="Provide OSGi ConfigAdmin support" version="${project.version}">
- <feature version="${project.version}">aries-blueprint</feature>
<bundle start-level="30" start="true">mvn:org.apache.karaf.config/org.apache.karaf.config.core/${project.version}</bundle>
<bundle start-level="30" start="true">mvn:org.apache.karaf.config/org.apache.karaf.config.command/${project.version}</bundle>
</feature>
http://git-wip-us.apache.org/repos/asf/karaf/blob/5db77ebe/config/core/pom.xml
----------------------------------------------------------------------
diff --git a/config/core/pom.xml b/config/core/pom.xml
index 8fd5cc3..3fc5286 100644
--- a/config/core/pom.xml
+++ b/config/core/pom.xml
@@ -53,6 +53,11 @@
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>
+
+ <dependency>
+ <groupId>org.apache.karaf</groupId>
+ <artifactId>org.apache.karaf.util</artifactId>
+ </dependency>
<dependency>
<groupId>org.slf4j</groupId>
@@ -90,8 +95,13 @@
*
</Import-Package>
<Private-Package>
- org.apache.karaf.config.core.impl
+ org.apache.karaf.config.core.impl,
+ org.apache.karaf.config.core.impl.osgi,
+ org.apache.karaf.util.tracker
</Private-Package>
+ <Bundle-Activator>
+ org.apache.karaf.config.core.impl.osgi.Activator
+ </Bundle-Activator>
</instructions>
</configuration>
</plugin>
http://git-wip-us.apache.org/repos/asf/karaf/blob/5db77ebe/config/core/src/main/java/org/apache/karaf/config/core/impl/osgi/Activator.java
----------------------------------------------------------------------
diff --git a/config/core/src/main/java/org/apache/karaf/config/core/impl/osgi/Activator.java b/config/core/src/main/java/org/apache/karaf/config/core/impl/osgi/Activator.java
new file mode 100644
index 0000000..e8d3dd8
--- /dev/null
+++ b/config/core/src/main/java/org/apache/karaf/config/core/impl/osgi/Activator.java
@@ -0,0 +1,148 @@
+/*
+ * 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.karaf.config.core.impl.osgi;
+
+import java.util.ArrayList;
+import java.util.Hashtable;
+import java.util.List;
+import java.util.Properties;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.TimeUnit;
+
+import javax.management.NotCompliantMBeanException;
+
+import org.apache.karaf.config.core.ConfigRepository;
+import org.apache.karaf.config.core.impl.ConfigMBeanImpl;
+import org.apache.karaf.config.core.impl.ConfigRepositoryImpl;
+import org.apache.karaf.util.tracker.SingleServiceTracker;
+import org.osgi.framework.BundleActivator;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceRegistration;
+import org.osgi.service.cm.ConfigurationAdmin;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class Activator implements BundleActivator, SingleServiceTracker.SingleServiceListener {
+
+ private static final Logger LOGGER = LoggerFactory.getLogger(Activator.class);
+
+ private ExecutorService executor = Executors.newSingleThreadExecutor();
+ private BundleContext bundleContext;
+ private SingleServiceTracker<ConfigurationAdmin> configurationAdminTracker;
+
+ private ServiceRegistration<ConfigRepository> configRepositoryRegistration;
+ private ServiceRegistration configRepositoryMBeanRegistration;
+
+ @Override
+ public void start(BundleContext context) throws Exception {
+ bundleContext = context;
+ configurationAdminTracker = new SingleServiceTracker<ConfigurationAdmin>(
+ bundleContext, ConfigurationAdmin.class, this
+ );
+ configurationAdminTracker.open();
+ }
+
+ @Override
+ public void stop(BundleContext context) throws Exception {
+ configurationAdminTracker.close();
+ executor.shutdown();
+ executor.awaitTermination(30, TimeUnit.SECONDS);
+ }
+
+ protected void doStart() {
+ ConfigurationAdmin configurationAdmin = configurationAdminTracker.getService();
+
+ if (configurationAdmin == null) {
+ return;
+ }
+
+ ConfigRepository configRepository = new ConfigRepositoryImpl(configurationAdmin);
+ configRepositoryRegistration = bundleContext.registerService(ConfigRepository.class, configRepository, null);
+
+ try {
+ ConfigMBeanImpl configMBean = new ConfigMBeanImpl();
+ configMBean.setConfigRepo(configRepository);
+ Hashtable<String, Object> props = new Hashtable<String, Object>();
+ props.put("jmx.objectname", "org.apache.karaf:type=config,name=" + System.getProperty("karaf.name"));
+ configRepositoryMBeanRegistration = bundleContext.registerService(
+ getInterfaceNames(configMBean),
+ configMBean,
+ props
+ );
+ } catch (NotCompliantMBeanException e) {
+ LOGGER.warn("Error creating ConfigRepository mbean", e);
+ }
+ }
+
+ protected void doStop() {
+ if (configRepositoryRegistration != null) {
+ configRepositoryRegistration.unregister();
+ configRepositoryRegistration = null;
+ }
+ if (configRepositoryMBeanRegistration != null) {
+ configRepositoryMBeanRegistration.unregister();
+ configRepositoryMBeanRegistration = null;
+ }
+ }
+
+ @Override
+ public void serviceFound() {
+ executor.submit(new Runnable() {
+ @Override
+ public void run() {
+ doStop();
+ try {
+ doStart();
+ } catch (Exception e) {
+ LOGGER.warn("Error starting FeaturesService", e);
+ doStop();
+ }
+ }
+ });
+ }
+
+ @Override
+ public void serviceLost() {
+ serviceFound();
+ }
+
+ @Override
+ public void serviceReplaced() {
+ serviceFound();
+ }
+
+ private String[] getInterfaceNames(Object object) {
+ List<String> names = new ArrayList<String>();
+ for (Class cl = object.getClass(); cl != Object.class; cl = cl.getSuperclass()) {
+ addSuperInterfaces(names, cl);
+ }
+ return names.toArray(new String[names.size()]);
+ }
+
+ private void addSuperInterfaces(List<String> names, Class clazz) {
+ for (Class cl : clazz.getInterfaces()) {
+ names.add(cl.getName());
+ addSuperInterfaces(names, cl);
+ }
+ }
+
+ private String getString(Properties configuration, String key, String value) {
+ return configuration.getProperty(key, value);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/karaf/blob/5db77ebe/config/core/src/main/resources/OSGI-INF/blueprint/blueprint.xml
----------------------------------------------------------------------
diff --git a/config/core/src/main/resources/OSGI-INF/blueprint/blueprint.xml b/config/core/src/main/resources/OSGI-INF/blueprint/blueprint.xml
deleted file mode 100644
index 6433ed8..0000000
--- a/config/core/src/main/resources/OSGI-INF/blueprint/blueprint.xml
+++ /dev/null
@@ -1,44 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
-
- Licensed to the Apache Software Foundation (ASF) under one or more
- contributor license agreements. See the NOTICE file distributed with
- this work for additional information regarding copyright ownership.
- The ASF licenses this file to You under the Apache License, Version 2.0
- (the "License"); you may not use this file except in compliance with
- the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
-
--->
-<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
- xmlns:ext="http://aries.apache.org/blueprint/xmlns/blueprint-ext/v1.0.0"
- default-activation="lazy">
-
- <ext:property-placeholder placeholder-prefix="$[" placeholder-suffix="]" />
-
- <bean id="configRepo" class="org.apache.karaf.config.core.impl.ConfigRepositoryImpl">
- <argument ref="configAdmin"/>
- </bean>
-
- <reference id="configAdmin" interface="org.osgi.service.cm.ConfigurationAdmin" />
-
- <service interface="org.apache.karaf.config.core.ConfigRepository" ref="configRepo"/>
-
- <bean id="configMBean" class="org.apache.karaf.config.core.impl.ConfigMBeanImpl">
- <property name="configRepo" ref="configRepo"/>
- </bean>
-
- <service ref="configMBean" auto-export="interfaces">
- <service-properties>
- <entry key="jmx.objectname" value="org.apache.karaf:type=config,name=$[karaf.name]"/>
- </service-properties>
- </service>
-
-</blueprint>
[09/24] git commit: [KARAF-2833] Make shell/commands independent of
blueprint
Posted by gn...@apache.org.
[KARAF-2833] Make shell/commands independent of blueprint
Project: http://git-wip-us.apache.org/repos/asf/karaf/repo
Commit: http://git-wip-us.apache.org/repos/asf/karaf/commit/ae104080
Tree: http://git-wip-us.apache.org/repos/asf/karaf/tree/ae104080
Diff: http://git-wip-us.apache.org/repos/asf/karaf/diff/ae104080
Branch: refs/heads/master
Commit: ae104080f4d0807a721e081bc955b3ca69fbadc3
Parents: 42ce5d7
Author: Guillaume Nodet <gn...@gmail.com>
Authored: Thu Mar 20 14:24:48 2014 +0100
Committer: Guillaume Nodet <gn...@gmail.com>
Committed: Mon Mar 24 17:30:12 2014 +0100
----------------------------------------------------------------------
shell/commands/pom.xml | 3 ++
.../shell/commands/impl/info/Activator.java | 40 +++++++++++++++++++
.../impl/info/InfoBundleTrackerCustomizer.java | 24 +++---------
.../OSGI-INF/blueprint/shell-commands.xml | 41 --------------------
shell/core/pom.xml | 3 +-
shell/ssh/pom.xml | 9 ++++-
6 files changed, 59 insertions(+), 61 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/karaf/blob/ae104080/shell/commands/pom.xml
----------------------------------------------------------------------
diff --git a/shell/commands/pom.xml b/shell/commands/pom.xml
index 3e0b7d6..971e1c9 100644
--- a/shell/commands/pom.xml
+++ b/shell/commands/pom.xml
@@ -103,6 +103,9 @@
org.apache.karaf.util;-split-package:=merge-first,
org.apache.karaf.shell.commands.impl*
</Private-Package>
+ <Bundle-Activator>
+ org.apache.karaf.shell.commands.impl.info.Activator
+ </Bundle-Activator>
<Karaf-Commands>
org.apache.karaf.shell.commands.impl
</Karaf-Commands>
http://git-wip-us.apache.org/repos/asf/karaf/blob/ae104080/shell/commands/src/main/java/org/apache/karaf/shell/commands/impl/info/Activator.java
----------------------------------------------------------------------
diff --git a/shell/commands/src/main/java/org/apache/karaf/shell/commands/impl/info/Activator.java b/shell/commands/src/main/java/org/apache/karaf/shell/commands/impl/info/Activator.java
new file mode 100644
index 0000000..14dda54
--- /dev/null
+++ b/shell/commands/src/main/java/org/apache/karaf/shell/commands/impl/info/Activator.java
@@ -0,0 +1,40 @@
+/*
+ * 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.karaf.shell.commands.impl.info;
+
+import org.apache.karaf.shell.commands.info.InfoProvider;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleActivator;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceRegistration;
+import org.osgi.util.tracker.BundleTracker;
+
+public class Activator implements BundleActivator {
+
+ private BundleTracker<ServiceRegistration<InfoProvider>> tracker;
+
+ @Override
+ public void start(BundleContext context) throws Exception {
+ tracker = new BundleTracker<ServiceRegistration<InfoProvider>>(context, Bundle.ACTIVE, new InfoBundleTrackerCustomizer());
+ tracker.open();
+ }
+
+ @Override
+ public void stop(BundleContext context) throws Exception {
+ tracker.close();
+ }
+}
http://git-wip-us.apache.org/repos/asf/karaf/blob/ae104080/shell/commands/src/main/java/org/apache/karaf/shell/commands/impl/info/InfoBundleTrackerCustomizer.java
----------------------------------------------------------------------
diff --git a/shell/commands/src/main/java/org/apache/karaf/shell/commands/impl/info/InfoBundleTrackerCustomizer.java b/shell/commands/src/main/java/org/apache/karaf/shell/commands/impl/info/InfoBundleTrackerCustomizer.java
index a674ad8..c2c7589 100644
--- a/shell/commands/src/main/java/org/apache/karaf/shell/commands/impl/info/InfoBundleTrackerCustomizer.java
+++ b/shell/commands/src/main/java/org/apache/karaf/shell/commands/impl/info/InfoBundleTrackerCustomizer.java
@@ -32,7 +32,7 @@ import java.util.StringTokenizer;
/**
* Bundle tracker which check manifest headers for information.
*/
-public class InfoBundleTrackerCustomizer implements BundleTrackerCustomizer {
+public class InfoBundleTrackerCustomizer implements BundleTrackerCustomizer<ServiceRegistration<InfoProvider>> {
/**
* Logger.
@@ -40,19 +40,10 @@ public class InfoBundleTrackerCustomizer implements BundleTrackerCustomizer {
private Logger logger = LoggerFactory.getLogger(InfoBundleTrackerCustomizer.class);
/**
- * Bundle context.
- */
- private final BundleContext context;
-
- public InfoBundleTrackerCustomizer(BundleContext context) {
- this.context = context;
- }
-
- /**
* {@inheritDoc}
*/
@SuppressWarnings("unchecked")
- public Object addingBundle(Bundle bundle, BundleEvent event) {
+ public ServiceRegistration<InfoProvider> addingBundle(Bundle bundle, BundleEvent event) {
Dictionary headers = bundle.getHeaders();
String headerEntry = (String) headers.get("Karaf-Info");
@@ -64,18 +55,15 @@ public class InfoBundleTrackerCustomizer implements BundleTrackerCustomizer {
}
return null;
}
- return bundle.getBundleContext().registerService(InfoProvider.class.getName(),
+ return bundle.getBundleContext().registerService(InfoProvider.class,
provider, null);
}
- public void modifiedBundle(Bundle bundle, BundleEvent event, Object object) {
+ public void modifiedBundle(Bundle bundle, BundleEvent event, ServiceRegistration<InfoProvider> object) {
}
- public void removedBundle(Bundle bundle, BundleEvent event, Object object) {
- if (object instanceof ServiceRegistration) {
- ServiceRegistration service = (ServiceRegistration) object;
- service.unregister();
- }
+ public void removedBundle(Bundle bundle, BundleEvent event, ServiceRegistration<InfoProvider> object) {
+ object.unregister();
}
private InfoProvider createInfo(String entry) {
http://git-wip-us.apache.org/repos/asf/karaf/blob/ae104080/shell/commands/src/main/resources/OSGI-INF/blueprint/shell-commands.xml
----------------------------------------------------------------------
diff --git a/shell/commands/src/main/resources/OSGI-INF/blueprint/shell-commands.xml b/shell/commands/src/main/resources/OSGI-INF/blueprint/shell-commands.xml
deleted file mode 100644
index af2747c..0000000
--- a/shell/commands/src/main/resources/OSGI-INF/blueprint/shell-commands.xml
+++ /dev/null
@@ -1,41 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
-
- Licensed to the Apache Software Foundation (ASF) under one or more
- contributor license agreements. See the NOTICE file distributed with
- this work for additional information regarding copyright ownership.
- The ASF licenses this file to You under the Apache License, Version 2.0
- (the "License"); you may not use this file except in compliance with
- the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
-
--->
-<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0" default-activation="lazy">
-
- <!--
- <command-bundle xmlns="http://karaf.apache.org/xmlns/shell/v1.2.0"
- scan="org.apache.karaf.shell.commands.impl" />
-
- <bean id="commandCompleter" class="org.apache.karaf.shell.console.completer.CommandsCompleter"/>
- <service ref="commandCompleter" auto-export="all-classes"/>
- -->
-
- <bean class="org.osgi.util.tracker.BundleTracker" init-method="open"
- destroy-method="close">
- <argument ref="blueprintBundleContext" />
- <argument value="32" />
- <argument>
- <bean class="org.apache.karaf.shell.commands.impl.info.InfoBundleTrackerCustomizer">
- <argument ref="blueprintBundleContext" />
- </bean>
- </argument>
- </bean>
-
-</blueprint>
http://git-wip-us.apache.org/repos/asf/karaf/blob/ae104080/shell/core/pom.xml
----------------------------------------------------------------------
diff --git a/shell/core/pom.xml b/shell/core/pom.xml
index c45f473..ceb11db 100644
--- a/shell/core/pom.xml
+++ b/shell/core/pom.xml
@@ -60,6 +60,7 @@
<dependency>
<groupId>org.apache.karaf.jaas</groupId>
<artifactId>org.apache.karaf.jaas.modules</artifactId>
+ <scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.karaf.jaas</groupId>
@@ -171,7 +172,7 @@
org.apache.karaf.shell.impl.console.standalone.Main
</Main-Class>
<Embed-Dependency>
- org.apache.karaf.jaas.modules;inline="org/apache/karaf/jaas/modules/JaasHelper.class"
+ org.apache.karaf.jaas.modules;inline="org/apache/karaf/jaas/modules/JaasHelper*.class"
</Embed-Dependency>
</instructions>
<unpackBundle>true</unpackBundle>
http://git-wip-us.apache.org/repos/asf/karaf/blob/ae104080/shell/ssh/pom.xml
----------------------------------------------------------------------
diff --git a/shell/ssh/pom.xml b/shell/ssh/pom.xml
index cffaa0b..cababb5 100644
--- a/shell/ssh/pom.xml
+++ b/shell/ssh/pom.xml
@@ -71,11 +71,18 @@
<groupId>org.apache.sshd</groupId>
<artifactId>sshd-core</artifactId>
</dependency>
-
+
+ <dependency>
+ <groupId>org.apache.karaf.jaas</groupId>
+ <artifactId>org.apache.karaf.jaas.modules</artifactId>
+ </dependency>
+
<dependency>
<groupId>org.apache.karaf</groupId>
<artifactId>org.apache.karaf.util</artifactId>
+ <scope>provided</scope>
</dependency>
+
</dependencies>
<build>
[24/24] git commit: [KARAF-2805] Add a Registry#hasCommand() method
to speed-up integration tests
Posted by gn...@apache.org.
[KARAF-2805] Add a Registry#hasCommand() method to speed-up integration tests
Project: http://git-wip-us.apache.org/repos/asf/karaf/repo
Commit: http://git-wip-us.apache.org/repos/asf/karaf/commit/7b47629b
Tree: http://git-wip-us.apache.org/repos/asf/karaf/tree/7b47629b
Diff: http://git-wip-us.apache.org/repos/asf/karaf/diff/7b47629b
Branch: refs/heads/master
Commit: 7b47629bdef7fa265993b35fd60aa732895c0232
Parents: d80852d
Author: Guillaume Nodet <gn...@gmail.com>
Authored: Mon Mar 24 15:42:35 2014 +0100
Committer: Guillaume Nodet <gn...@gmail.com>
Committed: Mon Mar 24 17:30:14 2014 +0100
----------------------------------------------------------------------
.../apache/karaf/itests/KarafTestSupport.java | 20 ++++++++----
.../karaf/shell/api/console/Registry.java | 9 ++++++
.../shell/impl/action/osgi/RegistryImpl.java | 34 ++++++++++++++++++++
.../karaf/shell/impl/console/RegistryImpl.java | 34 ++++++++++++++++++++
4 files changed, 90 insertions(+), 7 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/karaf/blob/7b47629b/itests/src/test/java/org/apache/karaf/itests/KarafTestSupport.java
----------------------------------------------------------------------
diff --git a/itests/src/test/java/org/apache/karaf/itests/KarafTestSupport.java b/itests/src/test/java/org/apache/karaf/itests/KarafTestSupport.java
index 9a59437..4669b1b 100644
--- a/itests/src/test/java/org/apache/karaf/itests/KarafTestSupport.java
+++ b/itests/src/test/java/org/apache/karaf/itests/KarafTestSupport.java
@@ -96,6 +96,9 @@ public class KarafTestSupport {
@Inject
protected FeaturesService featureService;
+ @Inject
+ protected SessionFactory sessionFactory;
+
/**
* To make sure the tests run only when the boot features are fully installed
*/
@@ -279,14 +282,17 @@ public class KarafTestSupport {
command = command.substring(0, spaceIdx);
}
int colonIndx = command.indexOf(':');
-
+ String scope = (colonIndx > 0) ? command.substring(0, colonIndx) : "*";
+ String name = (colonIndx > 0) ? command.substring(colonIndx + 1) : command;
try {
- if (colonIndx > 0) {
- String scope = command.substring(0, colonIndx);
- String function = command.substring(colonIndx + 1);
- waitForService("(&(osgi.command.scope=" + scope + ")(osgi.command.function=" + function + "))", SERVICE_TIMEOUT);
- } else {
- waitForService("(osgi.command.function=" + command + ")", SERVICE_TIMEOUT);
+ long start = System.currentTimeMillis();
+ long cur = start;
+ while (cur - start < SERVICE_TIMEOUT) {
+ if (sessionFactory.getRegistry().hasCommand(scope, name)) {
+ return;
+ }
+ Thread.sleep(100);
+ cur = System.currentTimeMillis();
}
} catch (Exception e) {
throw new RuntimeException(e);
http://git-wip-us.apache.org/repos/asf/karaf/blob/7b47629b/shell/core/src/main/java/org/apache/karaf/shell/api/console/Registry.java
----------------------------------------------------------------------
diff --git a/shell/core/src/main/java/org/apache/karaf/shell/api/console/Registry.java b/shell/core/src/main/java/org/apache/karaf/shell/api/console/Registry.java
index b768d69..35c7c75 100644
--- a/shell/core/src/main/java/org/apache/karaf/shell/api/console/Registry.java
+++ b/shell/core/src/main/java/org/apache/karaf/shell/api/console/Registry.java
@@ -36,6 +36,15 @@ public interface Registry {
List<Command> getCommands();
/**
+ *
+ * @param scope
+ * @param name
+ * @return
+ * @throws InterruptedException
+ */
+ boolean hasCommand(String scope, String name);
+
+ /**
* Register a delayed service (or factory).
* In cases where instances must be created for each injection,
* a {@link Callable} can be registered and each injection will
http://git-wip-us.apache.org/repos/asf/karaf/blob/7b47629b/shell/core/src/main/java/org/apache/karaf/shell/impl/action/osgi/RegistryImpl.java
----------------------------------------------------------------------
diff --git a/shell/core/src/main/java/org/apache/karaf/shell/impl/action/osgi/RegistryImpl.java b/shell/core/src/main/java/org/apache/karaf/shell/impl/action/osgi/RegistryImpl.java
index 38f750a..e1cdd67 100644
--- a/shell/core/src/main/java/org/apache/karaf/shell/impl/action/osgi/RegistryImpl.java
+++ b/shell/core/src/main/java/org/apache/karaf/shell/impl/action/osgi/RegistryImpl.java
@@ -19,6 +19,7 @@
package org.apache.karaf.shell.impl.action.osgi;
import java.util.ArrayList;
+import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
@@ -31,6 +32,7 @@ public class RegistryImpl implements Registry {
private final Registry parent;
private final Map<Object, Object> services = new LinkedHashMap<Object, Object>();
+ private final Map<String, List<Command>> commands = new HashMap<String, List<Command>>();
public RegistryImpl(Registry parent) {
this.parent = parent;
@@ -42,6 +44,17 @@ public class RegistryImpl implements Registry {
}
@Override
+ public boolean hasCommand(String scope, String name) {
+ if (parent != null && parent.hasCommand(scope, name)) {
+ return true;
+ }
+ synchronized (services) {
+ List<Command> cmds = commands.get(scope + ":" + name);
+ return cmds != null && !cmds.isEmpty();
+ }
+ }
+
+ @Override
public <T> void register(Callable<T> factory, Class<T> clazz) {
synchronized (services) {
services.put(clazz, new Factory<T>(clazz, factory));
@@ -52,6 +65,16 @@ public class RegistryImpl implements Registry {
public void register(Object service) {
synchronized (services) {
services.put(service, service);
+ if (service instanceof Command) {
+ Command cmd = (Command) service;
+ String key = cmd.getScope() + ":" + cmd.getName();
+ List<Command> cmds = commands.get(key);
+ if (cmds == null) {
+ cmds = new ArrayList<Command>();
+ commands.put(key, cmds);
+ }
+ cmds.add(cmd);
+ }
}
}
@@ -59,6 +82,17 @@ public class RegistryImpl implements Registry {
public void unregister(Object service) {
synchronized (services) {
services.remove(service);
+ if (service instanceof Command) {
+ Command cmd = (Command) service;
+ String key = cmd.getScope() + ":" + cmd.getName();
+ List<Command> cmds = commands.get(key);
+ if (cmds != null) {
+ cmds.remove(cmd);
+ if (cmds.isEmpty()) {
+ commands.remove(key);
+ }
+ }
+ }
}
}
http://git-wip-us.apache.org/repos/asf/karaf/blob/7b47629b/shell/core/src/main/java/org/apache/karaf/shell/impl/console/RegistryImpl.java
----------------------------------------------------------------------
diff --git a/shell/core/src/main/java/org/apache/karaf/shell/impl/console/RegistryImpl.java b/shell/core/src/main/java/org/apache/karaf/shell/impl/console/RegistryImpl.java
index b607c5e..99113b7 100644
--- a/shell/core/src/main/java/org/apache/karaf/shell/impl/console/RegistryImpl.java
+++ b/shell/core/src/main/java/org/apache/karaf/shell/impl/console/RegistryImpl.java
@@ -19,6 +19,7 @@
package org.apache.karaf.shell.impl.console;
import java.util.ArrayList;
+import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
@@ -31,6 +32,7 @@ public class RegistryImpl implements Registry {
protected final Registry parent;
protected final Map<Object, Object> services = new LinkedHashMap<Object, Object>();
+ private final Map<String, List<Command>> commands = new HashMap<String, List<Command>>();
public RegistryImpl(Registry parent) {
this.parent = parent;
@@ -42,6 +44,17 @@ public class RegistryImpl implements Registry {
}
@Override
+ public boolean hasCommand(String scope, String name) {
+ if (parent != null && parent.hasCommand(scope, name)) {
+ return true;
+ }
+ synchronized (services) {
+ List<Command> cmds = commands.get(scope + ":" + name);
+ return cmds != null && !cmds.isEmpty();
+ }
+ }
+
+ @Override
public <T> void register(Callable<T> factory, Class<T> clazz) {
synchronized (services) {
services.put(factory, new Factory<T>(clazz, factory));
@@ -52,6 +65,16 @@ public class RegistryImpl implements Registry {
public void register(Object service) {
synchronized (services) {
services.put(service, service);
+ if (service instanceof Command) {
+ Command cmd = (Command) service;
+ String key = cmd.getScope() + ":" + cmd.getName();
+ List<Command> cmds = commands.get(key);
+ if (cmds == null) {
+ cmds = new ArrayList<Command>();
+ commands.put(key, cmds);
+ }
+ cmds.add(cmd);
+ }
}
}
@@ -59,6 +82,17 @@ public class RegistryImpl implements Registry {
public void unregister(Object service) {
synchronized (services) {
services.remove(service);
+ if (service instanceof Command) {
+ Command cmd = (Command) service;
+ String key = cmd.getScope() + ":" + cmd.getName();
+ List<Command> cmds = commands.get(key);
+ if (cmds != null) {
+ cmds.remove(cmd);
+ if (cmds.isEmpty()) {
+ commands.remove(key);
+ }
+ }
+ }
}
}
[15/24] git commit: [KARAF-2833] Make jaas/config,
jaas/jasypt and jaas/modules independent of blueprint
Posted by gn...@apache.org.
[KARAF-2833] Make jaas/config, jaas/jasypt and jaas/modules independent of blueprint
Project: http://git-wip-us.apache.org/repos/asf/karaf/repo
Commit: http://git-wip-us.apache.org/repos/asf/karaf/commit/5e2f19c4
Tree: http://git-wip-us.apache.org/repos/asf/karaf/tree/5e2f19c4
Diff: http://git-wip-us.apache.org/repos/asf/karaf/diff/5e2f19c4
Branch: refs/heads/master
Commit: 5e2f19c48efcf6dc8bca2b71485d36f1e47c84bc
Parents: 64e7310
Author: Guillaume Nodet <gn...@gmail.com>
Authored: Fri Mar 21 18:27:00 2014 +0100
Committer: Guillaume Nodet <gn...@gmail.com>
Committed: Mon Mar 24 17:30:13 2014 +0100
----------------------------------------------------------------------
.../standard/src/main/feature/feature.xml | 9 +-
jaas/blueprint/config/pom.xml | 82 ++++++
.../blueprint/config/impl/NamespaceHandler.java | 177 +++++++++++++
.../resources/OSGI-INF/blueprint/karaf-jaas.xml | 36 +++
.../src/main/resources/OSGI-INF/bundle.info | 14 +
.../jaas/blueprint/config/karaf-jaas-1.0.0.xsd | 62 +++++
.../jaas/blueprint/config/karaf-jaas-1.1.0.xsd | 63 +++++
jaas/blueprint/jasypt/pom.xml | 146 +++++++++++
.../handler/EncryptablePropertyPlaceholder.java | 41 +++
.../jasypt/handler/NamespaceHandler.java | 173 +++++++++++++
.../OSGI-INF/blueprint/karaf-jaas-jasypt.xml | 30 +++
.../src/main/resources/OSGI-INF/bundle.info | 14 +
.../jasypt/handler/karaf-jasypt-1.0.0.xsd | 43 ++++
...tableConfigAdminPropertyPlaceholderTest.java | 257 +++++++++++++++++++
.../EncryptablePropertyPlaceholderTest.java | 228 ++++++++++++++++
.../jasypt/src/test/resources/log4j.properties | 34 +++
.../jasypt/handler/configadmin-test.xml | 41 +++
.../jaas/blueprint/jasypt/handler/test.xml | 45 ++++
jaas/blueprint/pom.xml | 41 +++
jaas/config/pom.xml | 14 +-
.../karaf/jaas/config/impl/Activator.java | 93 +++++++
.../jaas/config/impl/NamespaceHandler.java | 165 ------------
.../resources/OSGI-INF/blueprint/karaf-jaas.xml | 61 -----
.../karaf/jaas/config/karaf-jaas-1.0.0.xsd | 62 -----
.../karaf/jaas/config/karaf-jaas-1.1.0.xsd | 63 -----
jaas/jasypt/pom.xml | 25 +-
.../handler/EncryptablePropertyPlaceholder.java | 41 ---
.../jaas/jasypt/handler/NamespaceHandler.java | 173 -------------
.../karaf/jaas/jasypt/impl/Activator.java | 45 ++++
.../OSGI-INF/blueprint/karaf-jaas-jasypt.xml | 37 ---
.../jaas/jasypt/handler/karaf-jasypt-1.0.0.xsd | 43 ----
.../EncryptablePropertyPlaceholderTest.java | 228 ----------------
.../apache/karaf/jaas/jasypt/handler/test.xml | 45 ----
jaas/modules/pom.xml | 7 +-
.../karaf/jaas/modules/impl/Activator.java | 48 ++++
.../karaf/jaas/modules/impl/KarafRealm.java | 109 ++++++++
.../modules/properties/PropertiesConverter.java | 51 ----
.../OSGI-INF/blueprint/karaf-jaas-module.xml | 75 ------
.../properties/PropertiesConverterTest.java | 66 -----
jaas/pom.xml | 1 +
pom.xml | 10 +
41 files changed, 1865 insertions(+), 1133 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/karaf/blob/5e2f19c4/assemblies/features/standard/src/main/feature/feature.xml
----------------------------------------------------------------------
diff --git a/assemblies/features/standard/src/main/feature/feature.xml b/assemblies/features/standard/src/main/feature/feature.xml
index fc42bbd..6a71520 100644
--- a/assemblies/features/standard/src/main/feature/feature.xml
+++ b/assemblies/features/standard/src/main/feature/feature.xml
@@ -146,10 +146,13 @@
</feature>
<feature name="jaas" description="Provide JAAS support" version="${project.version}">
- <feature version="${project.version}">aries-blueprint</feature>
<bundle start-level="30" start="true">mvn:org.apache.karaf.jaas/org.apache.karaf.jaas.config/${project.version}</bundle>
<bundle start-level="30" start="true">mvn:org.apache.karaf.jaas/org.apache.karaf.jaas.modules/${project.version}</bundle>
<bundle start-level="30" start="true">mvn:org.apache.karaf.jaas/org.apache.karaf.jaas.command/${project.version}</bundle>
+ <conditional>
+ <condition>aries-blueprint</condition>
+ <bundle start-level="30" start="true">mvn:org.apache.karaf.jaas.blueprint/org.apache.karaf.jaas.blueprint.config/${project.version}</bundle>
+ </conditional>
</feature>
<feature name="log" description="Provide Log support" version="${project.version}">
@@ -282,6 +285,10 @@
<bundle dependency="true" start-level="30">mvn:commons-lang/commons-lang/${commons-lang.version}</bundle>
<bundle dependency="true" start-level="30">mvn:org.apache.servicemix.bundles/org.apache.servicemix.bundles.jasypt/${jasypt.bundle.version}</bundle>
<bundle start-level="30">mvn:org.apache.karaf.jaas/org.apache.karaf.jaas.jasypt/${project.version}</bundle>
+ <conditional>
+ <condition>aries-blueprint</condition>
+ <bundle start-level="30" start="true">mvn:org.apache.karaf.jaas.blueprint/org.apache.karaf.jaas.blueprint.jasypt/${project.version}</bundle>
+ </conditional>
</feature>
<feature name="scr" description="Declarative Service support" version="${project.version}" resolver="(obr)">
http://git-wip-us.apache.org/repos/asf/karaf/blob/5e2f19c4/jaas/blueprint/config/pom.xml
----------------------------------------------------------------------
diff --git a/jaas/blueprint/config/pom.xml b/jaas/blueprint/config/pom.xml
new file mode 100644
index 0000000..efb7664
--- /dev/null
+++ b/jaas/blueprint/config/pom.xml
@@ -0,0 +1,82 @@
+<?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.karaf.jaas.blueprint</groupId>
+ <artifactId>blueprint</artifactId>
+ <version>3.1.0-SNAPSHOT</version>
+ <relativePath>../pom.xml</relativePath>
+ </parent>
+
+ <artifactId>org.apache.karaf.jaas.blueprint.config</artifactId>
+ <packaging>bundle</packaging>
+ <name>Apache Karaf :: JAAS :: Blueprint :: Config</name>
+ <description>This bundle provides a blueprint namespace handler for configuring JAAS</description>
+
+ <properties>
+ <appendedResourcesDirectory>${basedir}/../../etc/appended-resources</appendedResourcesDirectory>
+ </properties>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.osgi</groupId>
+ <artifactId>org.osgi.core</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.karaf.jaas</groupId>
+ <artifactId>org.apache.karaf.jaas.boot</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.karaf.jaas</groupId>
+ <artifactId>org.apache.karaf.jaas.config</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.aries.blueprint</groupId>
+ <artifactId>org.apache.aries.blueprint.core</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+ <configuration>
+ <instructions>
+ <Export-Package>
+ ${project.artifactId};version=${project.version}
+ </Export-Package>
+ <Import-Package>
+ !${project.artifactId},
+ *
+ </Import-Package>
+ </instructions>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
+</project>
http://git-wip-us.apache.org/repos/asf/karaf/blob/5e2f19c4/jaas/blueprint/config/src/main/java/org/apache/karaf/jaas/blueprint/config/impl/NamespaceHandler.java
----------------------------------------------------------------------
diff --git a/jaas/blueprint/config/src/main/java/org/apache/karaf/jaas/blueprint/config/impl/NamespaceHandler.java b/jaas/blueprint/config/src/main/java/org/apache/karaf/jaas/blueprint/config/impl/NamespaceHandler.java
new file mode 100644
index 0000000..0da83ae
--- /dev/null
+++ b/jaas/blueprint/config/src/main/java/org/apache/karaf/jaas/blueprint/config/impl/NamespaceHandler.java
@@ -0,0 +1,177 @@
+/*
+ * 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.karaf.jaas.blueprint.config.impl;
+
+import java.net.URL;
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.Set;
+
+import org.apache.aries.blueprint.ParserContext;
+import org.apache.aries.blueprint.mutable.MutableBeanMetadata;
+import org.apache.aries.blueprint.mutable.MutableCollectionMetadata;
+import org.apache.aries.blueprint.mutable.MutableRefMetadata;
+import org.apache.aries.blueprint.mutable.MutableServiceMetadata;
+import org.apache.aries.blueprint.mutable.MutableValueMetadata;
+import org.apache.karaf.jaas.boot.ProxyLoginModule;
+import org.apache.karaf.jaas.config.JaasRealm;
+import org.apache.karaf.jaas.config.KeystoreInstance;
+import org.apache.karaf.jaas.config.impl.Config;
+import org.apache.karaf.jaas.config.impl.Module;
+import org.apache.karaf.jaas.config.impl.ResourceKeystoreInstance;
+import org.osgi.service.blueprint.container.ComponentDefinitionException;
+import org.osgi.service.blueprint.reflect.ComponentMetadata;
+import org.osgi.service.blueprint.reflect.Metadata;
+import org.osgi.service.blueprint.reflect.RefMetadata;
+import org.osgi.service.blueprint.reflect.ValueMetadata;
+import org.w3c.dom.CharacterData;
+import org.w3c.dom.Comment;
+import org.w3c.dom.Element;
+import org.w3c.dom.EntityReference;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+
+public class NamespaceHandler implements org.apache.aries.blueprint.NamespaceHandler {
+
+ public URL getSchemaLocation(String namespace) {
+ if ("http://karaf.apache.org/xmlns/jaas/v1.0.0".equals(namespace)) {
+ return getClass().getResource("/org/apache/karaf/jaas/blueprint/config/karaf-jaas-1.0.0.xsd");
+ } else {
+ return getClass().getResource("/org/apache/karaf/jaas/blueprint/config/karaf-jaas-1.1.0.xsd");
+ }
+ }
+
+ public Set<Class> getManagedClasses() {
+ return new HashSet<Class>(Arrays.asList(
+ Config.class,
+ ResourceKeystoreInstance.class
+ ));
+ }
+
+ public Metadata parse(Element element, ParserContext context) {
+ String name = element.getLocalName() != null ? element.getLocalName() : element.getNodeName();
+ if ("config".equals(name)) {
+ return parseConfig(element, context);
+ } else if ("keystore".equals(name)) {
+ return parseKeystore(element, context);
+ }
+ throw new ComponentDefinitionException("Bad xml syntax: unknown element '" + name + "'");
+ }
+
+ public ComponentMetadata decorate(Node node, ComponentMetadata component, ParserContext context) {
+ throw new ComponentDefinitionException("Bad xml syntax: node decoration is not supported");
+ }
+
+ public ComponentMetadata parseConfig(Element element, ParserContext context) {
+ MutableBeanMetadata bean = context.createMetadata(MutableBeanMetadata.class);
+ bean.setRuntimeClass(Config.class);
+ String name = element.getAttribute("name");
+ bean.addProperty("bundleContext", createRef(context, "blueprintBundleContext"));
+ bean.addProperty("name", createValue(context, name));
+ String rank = element.getAttribute("rank");
+ if (rank != null && rank.length() > 0) {
+ bean.addProperty("rank", createValue(context, rank));
+ }
+ NodeList childElements = element.getElementsByTagNameNS(element.getNamespaceURI(), "module");
+ if (childElements != null && childElements.getLength() > 0) {
+ MutableCollectionMetadata children = context.createMetadata(MutableCollectionMetadata.class);
+ for (int i = 0; i < childElements.getLength(); ++i) {
+ Element childElement = (Element) childElements.item(i);
+ MutableBeanMetadata md = context.createMetadata(MutableBeanMetadata.class);
+ md.setRuntimeClass(Module.class);
+ md.addProperty("className", createValue(context, childElement.getAttribute("className")));
+ if (childElement.getAttribute("name") != null) {
+ md.addProperty("name", createValue(context, childElement.getAttribute("name")));
+ }
+ if (childElement.getAttribute("flags") != null) {
+ md.addProperty("flags", createValue(context, childElement.getAttribute("flags")));
+ }
+ String options = getTextValue(childElement);
+ if (options != null && options.length() > 0) {
+ md.addProperty("options", createValue(context, options));
+ }
+ children.addValue(md);
+ }
+ bean.addProperty("modules", children);
+ }
+ // Publish Config
+ MutableServiceMetadata service = context.createMetadata(MutableServiceMetadata.class);
+ service.setId(name);
+ service.setServiceComponent(bean);
+ service.addInterface(JaasRealm.class.getName());
+ service.addServiceProperty(createValue(context, ProxyLoginModule.PROPERTY_MODULE), createValue(context, name));
+ return service;
+ }
+
+ public ComponentMetadata parseKeystore(Element element, ParserContext context) {
+ MutableBeanMetadata bean = context.createMetadata(MutableBeanMetadata.class);
+ bean.setRuntimeClass(ResourceKeystoreInstance.class);
+ // Parse name
+ String name = element.getAttribute("name");
+ bean.addProperty("name", createValue(context, name));
+ // Parse rank
+ String rank = element.getAttribute("rank");
+ if (rank != null && rank.length() > 0) {
+ bean.addProperty("rank", createValue(context, rank));
+ }
+ // Parse path
+ String path = element.getAttribute("path");
+ if (path != null && path.length() > 0) {
+ bean.addProperty("path", createValue(context, path));
+ }
+ // Parse keystorePassword
+ String keystorePassword = element.getAttribute("keystorePassword");
+ if (keystorePassword != null && keystorePassword.length() > 0) {
+ bean.addProperty("keystorePassword", createValue(context, keystorePassword));
+ }
+ // Parse keyPasswords
+ String keyPasswords = element.getAttribute("keyPasswords");
+ if (keyPasswords != null && keyPasswords.length() > 0) {
+ bean.addProperty("keyPasswords", createValue(context, keyPasswords));
+ }
+ // Publish Config
+ MutableServiceMetadata service = context.createMetadata(MutableServiceMetadata.class);
+ service.setId(name);
+ service.setServiceComponent(bean);
+ service.addInterface(KeystoreInstance.class.getName());
+ return service;
+ }
+
+ private ValueMetadata createValue(ParserContext context, String value) {
+ MutableValueMetadata v = context.createMetadata(MutableValueMetadata.class);
+ v.setStringValue(value);
+ return v;
+ }
+
+ private RefMetadata createRef(ParserContext context, String value) {
+ MutableRefMetadata r = context.createMetadata(MutableRefMetadata.class);
+ r.setComponentId(value);
+ return r;
+ }
+
+ private static String getTextValue(Element element) {
+ StringBuffer value = new StringBuffer();
+ NodeList nl = element.getChildNodes();
+ for (int i = 0; i < nl.getLength(); i++) {
+ Node item = nl.item(i);
+ if ((item instanceof CharacterData && !(item instanceof Comment)) || item instanceof EntityReference) {
+ value.append(item.getNodeValue());
+ }
+ }
+ return value.toString();
+ }
+}
http://git-wip-us.apache.org/repos/asf/karaf/blob/5e2f19c4/jaas/blueprint/config/src/main/resources/OSGI-INF/blueprint/karaf-jaas.xml
----------------------------------------------------------------------
diff --git a/jaas/blueprint/config/src/main/resources/OSGI-INF/blueprint/karaf-jaas.xml b/jaas/blueprint/config/src/main/resources/OSGI-INF/blueprint/karaf-jaas.xml
new file mode 100644
index 0000000..b605006
--- /dev/null
+++ b/jaas/blueprint/config/src/main/resources/OSGI-INF/blueprint/karaf-jaas.xml
@@ -0,0 +1,36 @@
+<?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.
+
+-->
+<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0">
+
+ <bean id="namespaceHandler" class="org.apache.karaf.jaas.blueprint.config.impl.NamespaceHandler"/>
+
+ <service ref="namespaceHandler" interface="org.apache.aries.blueprint.NamespaceHandler">
+ <service-properties>
+ <entry key="osgi.service.blueprint.namespace" value="http://karaf.apache.org/xmlns/jaas/v1.0.0" />
+ </service-properties>
+ </service>
+
+ <service ref="namespaceHandler" interface="org.apache.aries.blueprint.NamespaceHandler">
+ <service-properties>
+ <entry key="osgi.service.blueprint.namespace" value="http://karaf.apache.org/xmlns/jaas/v1.1.0" />
+ </service-properties>
+ </service>
+
+</blueprint>
http://git-wip-us.apache.org/repos/asf/karaf/blob/5e2f19c4/jaas/blueprint/config/src/main/resources/OSGI-INF/bundle.info
----------------------------------------------------------------------
diff --git a/jaas/blueprint/config/src/main/resources/OSGI-INF/bundle.info b/jaas/blueprint/config/src/main/resources/OSGI-INF/bundle.info
new file mode 100644
index 0000000..6f57671
--- /dev/null
+++ b/jaas/blueprint/config/src/main/resources/OSGI-INF/bundle.info
@@ -0,0 +1,14 @@
+\u001B[1mSYNOPSIS\u001B[0m
+ ${project.name}
+
+ ${project.description}
+
+ Maven URL:
+ \u001B[33mmvn:${project.groupId}/${project.artifactId}/${project.version}\u001B[0m
+
+\u001B[1mDESCRIPTION\u001B[0m
+ A JAAS Namespace Handler for Blueprint
+
+\u001B[1mSEE ALSO\u001B[0m
+ \u001B[36mSecurity Framework\u001B[0m section of the Karaf Developer Guide.
+ \u001B[36mhttp://www.jasypt.org/\u001B[0m
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/karaf/blob/5e2f19c4/jaas/blueprint/config/src/main/resources/org/apache/karaf/jaas/blueprint/config/karaf-jaas-1.0.0.xsd
----------------------------------------------------------------------
diff --git a/jaas/blueprint/config/src/main/resources/org/apache/karaf/jaas/blueprint/config/karaf-jaas-1.0.0.xsd b/jaas/blueprint/config/src/main/resources/org/apache/karaf/jaas/blueprint/config/karaf-jaas-1.0.0.xsd
new file mode 100644
index 0000000..225665c
--- /dev/null
+++ b/jaas/blueprint/config/src/main/resources/org/apache/karaf/jaas/blueprint/config/karaf-jaas-1.0.0.xsd
@@ -0,0 +1,62 @@
+<?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.
+
+-->
+<xs:schema elementFormDefault='qualified'
+ targetNamespace='http://karaf.apache.org/xmlns/jaas/v1.0.0'
+ xmlns:xs='http://www.w3.org/2001/XMLSchema'
+ xmlns:bp="http://www.osgi.org/xmlns/blueprint/v1.0.0"
+ xmlns:tns='http://karaf.apache.org/xmlns/jaas/v1.0.0'>
+
+ <xs:import namespace="http://www.osgi.org/xmlns/blueprint/v1.0.0"/>
+
+ <xs:element name="config">
+ <xs:complexType>
+ <xs:sequence>
+ <xs:element name="module" minOccurs="0" maxOccurs="unbounded">
+ <xs:complexType mixed="true">
+ <xs:attribute name="className" use="required" type="xs:string"/>
+ <xs:attribute name="flags" default="required">
+ <xs:simpleType>
+ <xs:restriction base="xs:NMTOKEN">
+ <xs:enumeration value="required"/>
+ <xs:enumeration value="requisite"/>
+ <xs:enumeration value="sufficient"/>
+ <xs:enumeration value="optional"/>
+ </xs:restriction>
+ </xs:simpleType>
+ </xs:attribute>
+ </xs:complexType>
+ </xs:element>
+ </xs:sequence>
+ <xs:attribute name="name" use="required" type="xs:string"/>
+ <xs:attribute name="rank" use="optional" default="0" type="xs:int"/>
+ </xs:complexType>
+ </xs:element>
+
+ <xs:element name="keystore">
+ <xs:complexType>
+ <xs:attribute name="name" use="required" type="xs:string"/>
+ <xs:attribute name="rank" use="optional" default="0" type="xs:int"/>
+ <xs:attribute name="path" use="required" type="xs:string"/>
+ <xs:attribute name="keystorePassword" use="optional" type="xs:string"/>
+ <xs:attribute name="keyPasswords" use="optional" type="xs:string"/>
+ </xs:complexType>
+ </xs:element>
+
+</xs:schema>
http://git-wip-us.apache.org/repos/asf/karaf/blob/5e2f19c4/jaas/blueprint/config/src/main/resources/org/apache/karaf/jaas/blueprint/config/karaf-jaas-1.1.0.xsd
----------------------------------------------------------------------
diff --git a/jaas/blueprint/config/src/main/resources/org/apache/karaf/jaas/blueprint/config/karaf-jaas-1.1.0.xsd b/jaas/blueprint/config/src/main/resources/org/apache/karaf/jaas/blueprint/config/karaf-jaas-1.1.0.xsd
new file mode 100644
index 0000000..f56b206
--- /dev/null
+++ b/jaas/blueprint/config/src/main/resources/org/apache/karaf/jaas/blueprint/config/karaf-jaas-1.1.0.xsd
@@ -0,0 +1,63 @@
+<?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.
+
+-->
+<xs:schema elementFormDefault='qualified'
+ targetNamespace='http://karaf.apache.org/xmlns/jaas/v1.1.0'
+ xmlns:xs='http://www.w3.org/2001/XMLSchema'
+ xmlns:bp="http://www.osgi.org/xmlns/blueprint/v1.0.0"
+ xmlns:tns='http://karaf.apache.org/xmlns/jaas/v1.1.0'>
+
+ <xs:import namespace="http://www.osgi.org/xmlns/blueprint/v1.0.0"/>
+
+ <xs:element name="config">
+ <xs:complexType>
+ <xs:sequence>
+ <xs:element name="module" minOccurs="0" maxOccurs="unbounded">
+ <xs:complexType mixed="true">
+ <xs:attribute name="name" use="optional" type="xs:string"/>
+ <xs:attribute name="className" use="required" type="xs:string"/>
+ <xs:attribute name="flags" default="required">
+ <xs:simpleType>
+ <xs:restriction base="xs:NMTOKEN">
+ <xs:enumeration value="required"/>
+ <xs:enumeration value="requisite"/>
+ <xs:enumeration value="sufficient"/>
+ <xs:enumeration value="optional"/>
+ </xs:restriction>
+ </xs:simpleType>
+ </xs:attribute>
+ </xs:complexType>
+ </xs:element>
+ </xs:sequence>
+ <xs:attribute name="name" use="required" type="xs:string"/>
+ <xs:attribute name="rank" use="optional" default="0" type="xs:int"/>
+ </xs:complexType>
+ </xs:element>
+
+ <xs:element name="keystore">
+ <xs:complexType>
+ <xs:attribute name="name" use="required" type="xs:string"/>
+ <xs:attribute name="rank" use="optional" default="0" type="xs:int"/>
+ <xs:attribute name="path" use="required" type="xs:string"/>
+ <xs:attribute name="keystorePassword" use="optional" type="xs:string"/>
+ <xs:attribute name="keyPasswords" use="optional" type="xs:string"/>
+ </xs:complexType>
+ </xs:element>
+
+</xs:schema>
http://git-wip-us.apache.org/repos/asf/karaf/blob/5e2f19c4/jaas/blueprint/jasypt/pom.xml
----------------------------------------------------------------------
diff --git a/jaas/blueprint/jasypt/pom.xml b/jaas/blueprint/jasypt/pom.xml
new file mode 100644
index 0000000..e886fa1
--- /dev/null
+++ b/jaas/blueprint/jasypt/pom.xml
@@ -0,0 +1,146 @@
+<?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.karaf.jaas.blueprint</groupId>
+ <artifactId>blueprint</artifactId>
+ <version>3.1.0-SNAPSHOT</version>
+ <relativePath>../pom.xml</relativePath>
+ </parent>
+
+ <artifactId>org.apache.karaf.jaas.blueprint.jasypt</artifactId>
+ <packaging>bundle</packaging>
+ <name>Apache Karaf :: JAAS :: Blueprint :: Jasypt</name>
+ <description>This bundle provides a blueprint namespace handler for configuring Jasypt</description>
+
+ <properties>
+ <appendedResourcesDirectory>${basedir}/../../etc/appended-resources</appendedResourcesDirectory>
+ </properties>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.karaf.jaas</groupId>
+ <artifactId>org.apache.karaf.jaas.modules</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.servicemix.bundles</groupId>
+ <artifactId>org.apache.servicemix.bundles.jasypt</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.aries.blueprint</groupId>
+ <artifactId>org.apache.aries.blueprint.core</artifactId>
+ <scope>provided</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.aries.blueprint</groupId>
+ <artifactId>org.apache.aries.blueprint.cm</artifactId>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>org.apache.felix.configadmin</artifactId>
+ <scope>test</scope>
+ </dependency>
+
+ <!-- Force osgi 4.2 so that blueprint bundle tracker works correctly -->
+ <dependency>
+ <groupId>org.osgi</groupId>
+ <artifactId>org.osgi.core</artifactId>
+ <version>4.2.0</version>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.osgi</groupId>
+ <artifactId>org.osgi.compendium</artifactId>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>com.googlecode.pojosr</groupId>
+ <artifactId>de.kalpatec.pojosr.framework</artifactId>
+ <version>0.1.6</version>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.ops4j.pax.tinybundles</groupId>
+ <artifactId>tinybundles</artifactId>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.aries.proxy</groupId>
+ <artifactId>org.apache.aries.proxy.impl</artifactId>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-log4j12</artifactId>
+ <version>${slf4j.version}</version>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>jcl-over-slf4j</artifactId>
+ <version>${slf4j.version}</version>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <resources>
+ <resource>
+ <directory>${project.basedir}/src/main/resources</directory>
+ <includes>
+ <include>**/*</include>
+ </includes>
+ </resource>
+ <resource>
+ <directory>${project.basedir}/src/main/resources</directory>
+ <filtering>true</filtering>
+ <includes>
+ <include>**/*.info</include>
+ </includes>
+ </resource>
+ </resources>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+ <configuration>
+ <instructions>
+ <Export-Package></Export-Package>
+ <Import-Package>*</Import-Package>
+ </instructions>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
+</project>
http://git-wip-us.apache.org/repos/asf/karaf/blob/5e2f19c4/jaas/blueprint/jasypt/src/main/java/org/apache/karaf/jaas/blueprint/jasypt/handler/EncryptablePropertyPlaceholder.java
----------------------------------------------------------------------
diff --git a/jaas/blueprint/jasypt/src/main/java/org/apache/karaf/jaas/blueprint/jasypt/handler/EncryptablePropertyPlaceholder.java b/jaas/blueprint/jasypt/src/main/java/org/apache/karaf/jaas/blueprint/jasypt/handler/EncryptablePropertyPlaceholder.java
new file mode 100644
index 0000000..095678a
--- /dev/null
+++ b/jaas/blueprint/jasypt/src/main/java/org/apache/karaf/jaas/blueprint/jasypt/handler/EncryptablePropertyPlaceholder.java
@@ -0,0 +1,41 @@
+/*
+ * 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.
+ * under the License.
+ */
+package org.apache.karaf.jaas.blueprint.jasypt.handler;
+
+import org.jasypt.encryption.StringEncryptor;
+import org.apache.aries.blueprint.ext.AbstractPropertyPlaceholder;
+
+public class EncryptablePropertyPlaceholder extends AbstractPropertyPlaceholder {
+
+ private StringEncryptor encryptor;
+
+ public StringEncryptor getEncryptor() {
+ return encryptor;
+ }
+
+ public void setEncryptor(StringEncryptor encryptor) {
+ this.encryptor = encryptor;
+ }
+
+ public void init() {
+
+ }
+
+ @Override
+ protected String getProperty(String val) {
+ return encryptor.decrypt(val);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/karaf/blob/5e2f19c4/jaas/blueprint/jasypt/src/main/java/org/apache/karaf/jaas/blueprint/jasypt/handler/NamespaceHandler.java
----------------------------------------------------------------------
diff --git a/jaas/blueprint/jasypt/src/main/java/org/apache/karaf/jaas/blueprint/jasypt/handler/NamespaceHandler.java b/jaas/blueprint/jasypt/src/main/java/org/apache/karaf/jaas/blueprint/jasypt/handler/NamespaceHandler.java
new file mode 100644
index 0000000..1251ac9
--- /dev/null
+++ b/jaas/blueprint/jasypt/src/main/java/org/apache/karaf/jaas/blueprint/jasypt/handler/NamespaceHandler.java
@@ -0,0 +1,173 @@
+/*
+ * 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.
+ * under the License.
+ */
+package org.apache.karaf.jaas.blueprint.jasypt.handler;
+
+import java.net.URL;
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import org.apache.aries.blueprint.ParserContext;
+import org.apache.aries.blueprint.ext.PlaceholdersUtils;
+import org.apache.aries.blueprint.mutable.MutableBeanMetadata;
+import org.apache.aries.blueprint.mutable.MutableCollectionMetadata;
+import org.apache.aries.blueprint.mutable.MutableRefMetadata;
+import org.apache.aries.blueprint.mutable.MutableValueMetadata;
+import org.osgi.service.blueprint.container.ComponentDefinitionException;
+import org.osgi.service.blueprint.reflect.BeanMetadata;
+import org.osgi.service.blueprint.reflect.CollectionMetadata;
+import org.osgi.service.blueprint.reflect.ComponentMetadata;
+import org.osgi.service.blueprint.reflect.Metadata;
+import org.osgi.service.blueprint.reflect.RefMetadata;
+import org.osgi.service.blueprint.reflect.ValueMetadata;
+import org.w3c.dom.CharacterData;
+import org.w3c.dom.Comment;
+import org.w3c.dom.Element;
+import org.w3c.dom.EntityReference;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+
+public class NamespaceHandler implements org.apache.aries.blueprint.NamespaceHandler {
+
+ public static final String ID_ATTRIBUTE = "id";
+ public static final String PLACEHOLDER_PREFIX_ATTRIBUTE = "placeholder-prefix";
+ public static final String PLACEHOLDER_SUFFIX_ATTRIBUTE = "placeholder-suffix";
+ public static final String PROPERTY_PLACEHOLDER_ELEMENT = "property-placeholder";
+ public static final String ENCRYPTOR_REF_ATTRIBUTE = "encryptor-ref";
+ public static final String ENCRYPTOR_ELEMENT = "encryptor";
+ public static final String JASYPT_NAMESPACE_1_0 = "http://karaf.apache.org/xmlns/jasypt/v1.0.0";
+
+ private int idCounter;
+
+ public URL getSchemaLocation(String s) {
+ return getClass().getResource("/org/apache/karaf/jaas/blueprint/jasypt/handler/karaf-jasypt-1.0.0.xsd");
+ }
+
+ public Set<Class> getManagedClasses() {
+ return new HashSet<Class>(Arrays.asList(
+ EncryptablePropertyPlaceholder.class
+ ));
+ }
+
+ public Metadata parse(Element element, ParserContext context) {
+ String name = element.getLocalName() != null ? element.getLocalName() : element.getNodeName();
+ if (PROPERTY_PLACEHOLDER_ELEMENT.equals(name)) {
+ return parsePropertyPlaceholder(element, context);
+ }
+ throw new ComponentDefinitionException("Bad xml syntax: unknown element '" + name + "'");
+ }
+
+ public ComponentMetadata decorate(Node node, ComponentMetadata componentMetadata, ParserContext parserContext) {
+ throw new ComponentDefinitionException("Bad xml syntax: node decoration is not supported");
+ }
+
+ public ComponentMetadata parsePropertyPlaceholder(Element element, ParserContext context) {
+ MutableBeanMetadata metadata = context.createMetadata(MutableBeanMetadata.class);
+ metadata.setProcessor(true);
+ metadata.setId(getId(context, element));
+ metadata.setScope(BeanMetadata.SCOPE_SINGLETON);
+ metadata.setRuntimeClass(EncryptablePropertyPlaceholder.class);
+ metadata.setInitMethod("init");
+ String prefix = element.hasAttribute(PLACEHOLDER_PREFIX_ATTRIBUTE)
+ ? element.getAttribute(PLACEHOLDER_PREFIX_ATTRIBUTE)
+ : "ENC(";
+ metadata.addProperty("placeholderPrefix", createValue(context, prefix));
+ String suffix = element.hasAttribute(PLACEHOLDER_SUFFIX_ATTRIBUTE)
+ ? element.getAttribute(PLACEHOLDER_SUFFIX_ATTRIBUTE)
+ : ")";
+ metadata.addProperty("placeholderSuffix", createValue(context, suffix));
+ String encryptorRef = element.hasAttribute("encryptor-ref")
+ ? element.getAttribute("encryptor-ref")
+ : null;
+ if (encryptorRef != null) {
+ metadata.addProperty("encryptor", createRef(context, encryptorRef));
+ }
+ NodeList nl = element.getChildNodes();
+ for (int i = 0; i < nl.getLength(); i++) {
+ Node node = nl.item(i);
+ if (node instanceof Element) {
+ Element e = (Element) node;
+ if (JASYPT_NAMESPACE_1_0.equals(e.getNamespaceURI())) {
+ String name = e.getLocalName() != null ? e.getLocalName() : e.getNodeName();
+ if (ENCRYPTOR_ELEMENT.equals(name)) {
+ if (encryptorRef != null) {
+ throw new ComponentDefinitionException("Only one of " + ENCRYPTOR_REF_ATTRIBUTE + " attribute or " + ENCRYPTOR_ELEMENT + " element is allowed");
+ }
+ BeanMetadata encryptor = context.parseElement(BeanMetadata.class, metadata, e);
+ metadata.addProperty("encryptor", encryptor);
+ }
+ }
+ }
+ }
+ PlaceholdersUtils.validatePlaceholder(metadata, context.getComponentDefinitionRegistry());
+ return metadata;
+ }
+
+ public String getId(ParserContext context, Element element) {
+ if (element.hasAttribute(ID_ATTRIBUTE)) {
+ return element.getAttribute(ID_ATTRIBUTE);
+ } else {
+ return generateId(context);
+ }
+ }
+
+ private String generateId(ParserContext context) {
+ String id;
+ do {
+ id = ".jaas-" + ++idCounter;
+ } while (context.getComponentDefinitionRegistry().containsComponentDefinition(id));
+ return id;
+ }
+
+ private static ValueMetadata createValue(ParserContext context, String value) {
+ return createValue(context, value, null);
+ }
+
+ private static ValueMetadata createValue(ParserContext context, String value, String type) {
+ MutableValueMetadata m = context.createMetadata(MutableValueMetadata.class);
+ m.setStringValue(value);
+ m.setType(type);
+ return m;
+ }
+
+ private static CollectionMetadata createList(ParserContext context, List<String> list) {
+ MutableCollectionMetadata m = context.createMetadata(MutableCollectionMetadata.class);
+ m.setCollectionClass(List.class);
+ m.setValueType(String.class.getName());
+ for (String v : list) {
+ m.addValue(createValue(context, v, String.class.getName()));
+ }
+ return m;
+ }
+
+ private RefMetadata createRef(ParserContext context, String value) {
+ MutableRefMetadata r = context.createMetadata(MutableRefMetadata.class);
+ r.setComponentId(value);
+ return r;
+ }
+
+ private static String getTextValue(Element element) {
+ StringBuffer value = new StringBuffer();
+ NodeList nl = element.getChildNodes();
+ for (int i = 0; i < nl.getLength(); i++) {
+ Node item = nl.item(i);
+ if ((item instanceof CharacterData && !(item instanceof Comment)) || item instanceof EntityReference) {
+ value.append(item.getNodeValue());
+ }
+ }
+ return value.toString();
+ }
+}
http://git-wip-us.apache.org/repos/asf/karaf/blob/5e2f19c4/jaas/blueprint/jasypt/src/main/resources/OSGI-INF/blueprint/karaf-jaas-jasypt.xml
----------------------------------------------------------------------
diff --git a/jaas/blueprint/jasypt/src/main/resources/OSGI-INF/blueprint/karaf-jaas-jasypt.xml b/jaas/blueprint/jasypt/src/main/resources/OSGI-INF/blueprint/karaf-jaas-jasypt.xml
new file mode 100644
index 0000000..6ce6a2f
--- /dev/null
+++ b/jaas/blueprint/jasypt/src/main/resources/OSGI-INF/blueprint/karaf-jaas-jasypt.xml
@@ -0,0 +1,30 @@
+<?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.
+
+-->
+<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0">
+
+ <bean id="namespaceHandler" class="org.apache.karaf.jaas.blueprint.jasypt.handler.NamespaceHandler"/>
+
+ <service ref="namespaceHandler" interface="org.apache.aries.blueprint.NamespaceHandler">
+ <service-properties>
+ <entry key="osgi.service.blueprint.namespace" value="http://karaf.apache.org/xmlns/jasypt/v1.0.0" />
+ </service-properties>
+ </service>
+
+</blueprint>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/karaf/blob/5e2f19c4/jaas/blueprint/jasypt/src/main/resources/OSGI-INF/bundle.info
----------------------------------------------------------------------
diff --git a/jaas/blueprint/jasypt/src/main/resources/OSGI-INF/bundle.info b/jaas/blueprint/jasypt/src/main/resources/OSGI-INF/bundle.info
new file mode 100644
index 0000000..b95de28
--- /dev/null
+++ b/jaas/blueprint/jasypt/src/main/resources/OSGI-INF/bundle.info
@@ -0,0 +1,14 @@
+\u001B[1mSYNOPSIS\u001B[0m
+ ${project.name}
+
+ ${project.description}
+
+ Maven URL:
+ \u001B[33mmvn:${project.groupId}/${project.artifactId}/${project.version}\u001B[0m
+
+\u001B[1mDESCRIPTION\u001B[0m
+ A Jasypt Namespace Handler for Blueprint
+
+\u001B[1mSEE ALSO\u001B[0m
+ \u001B[36mSecurity Framework\u001B[0m section of the Karaf Developer Guide.
+ \u001B[36mhttp://www.jasypt.org/\u001B[0m
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/karaf/blob/5e2f19c4/jaas/blueprint/jasypt/src/main/resources/org/apache/karaf/jaas/blueprint/jasypt/handler/karaf-jasypt-1.0.0.xsd
----------------------------------------------------------------------
diff --git a/jaas/blueprint/jasypt/src/main/resources/org/apache/karaf/jaas/blueprint/jasypt/handler/karaf-jasypt-1.0.0.xsd b/jaas/blueprint/jasypt/src/main/resources/org/apache/karaf/jaas/blueprint/jasypt/handler/karaf-jasypt-1.0.0.xsd
new file mode 100644
index 0000000..f5e6921
--- /dev/null
+++ b/jaas/blueprint/jasypt/src/main/resources/org/apache/karaf/jaas/blueprint/jasypt/handler/karaf-jasypt-1.0.0.xsd
@@ -0,0 +1,43 @@
+<?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.
+
+-->
+<xs:schema elementFormDefault='qualified'
+ targetNamespace='http://karaf.apache.org/xmlns/jasypt/v1.0.0'
+ xmlns:xs='http://www.w3.org/2001/XMLSchema'
+ xmlns:bp="http://www.osgi.org/xmlns/blueprint/v1.0.0"
+ xmlns:tns='http://karaf.apache.org/xmlns/jasypt/v1.0.0'>
+
+ <xs:import namespace="http://www.osgi.org/xmlns/blueprint/v1.0.0"/>
+
+ <xs:element name="property-placeholder">
+ <xs:complexType>
+ <xs:complexContent>
+ <xs:extension base="bp:Tcomponent">
+ <xs:sequence>
+ <xs:element maxOccurs="1" minOccurs="0" name="encryptor" type="bp:Tbean"/>
+ </xs:sequence>
+ <xs:attribute name="placeholder-prefix" type="xs:string" use="optional" default="ENC("/>
+ <xs:attribute name="placeholder-suffix" type="xs:string" use="optional" default=")"/>
+ <xs:attribute name="encryptor-ref" type="bp:Tidref" use="optional"/>
+ </xs:extension>
+ </xs:complexContent>
+ </xs:complexType>
+ </xs:element>
+
+</xs:schema>
http://git-wip-us.apache.org/repos/asf/karaf/blob/5e2f19c4/jaas/blueprint/jasypt/src/test/java/org/apache/karaf/jaas/blueprint/jasypt/handler/EncryptableConfigAdminPropertyPlaceholderTest.java
----------------------------------------------------------------------
diff --git a/jaas/blueprint/jasypt/src/test/java/org/apache/karaf/jaas/blueprint/jasypt/handler/EncryptableConfigAdminPropertyPlaceholderTest.java b/jaas/blueprint/jasypt/src/test/java/org/apache/karaf/jaas/blueprint/jasypt/handler/EncryptableConfigAdminPropertyPlaceholderTest.java
new file mode 100644
index 0000000..db1283f
--- /dev/null
+++ b/jaas/blueprint/jasypt/src/test/java/org/apache/karaf/jaas/blueprint/jasypt/handler/EncryptableConfigAdminPropertyPlaceholderTest.java
@@ -0,0 +1,257 @@
+/*
+ * 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.
+ * under the License.
+ */
+package org.apache.karaf.jaas.blueprint.jasypt.handler;
+
+import de.kalpatec.pojosr.framework.PojoServiceRegistryFactoryImpl;
+import de.kalpatec.pojosr.framework.launch.BundleDescriptor;
+import de.kalpatec.pojosr.framework.launch.ClasspathScanner;
+import de.kalpatec.pojosr.framework.launch.PojoServiceRegistry;
+import de.kalpatec.pojosr.framework.launch.PojoServiceRegistryFactory;
+import junit.framework.TestCase;
+import org.jasypt.encryption.pbe.StandardPBEStringEncryptor;
+import org.jasypt.encryption.pbe.config.EnvironmentStringPBEConfig;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.ops4j.pax.tinybundles.core.TinyBundle;
+import org.osgi.framework.*;
+import org.osgi.service.cm.Configuration;
+import org.osgi.service.cm.ConfigurationAdmin;
+import org.osgi.util.tracker.ServiceTracker;
+
+import java.io.*;
+import java.net.URL;
+import java.util.*;
+import java.util.jar.JarInputStream;
+
+import static org.ops4j.pax.tinybundles.core.TinyBundles.bundle;
+
+public class EncryptableConfigAdminPropertyPlaceholderTest extends TestCase {
+
+ public static final long DEFAULT_TIMEOUT = 30000;
+
+ private BundleContext bundleContext;
+ private ConfigurationAdmin configAdmin;
+ private EnvironmentStringPBEConfig env;
+ private StandardPBEStringEncryptor enc;
+ private String encryptedValue;
+
+ @Before
+ public void setUp() throws Exception {
+
+ // Configure Jasypt
+ enc = new StandardPBEStringEncryptor();
+ env = new EnvironmentStringPBEConfig();
+ env.setAlgorithm("PBEWithMD5AndDES");
+ env.setPassword("password");
+ enc.setConfig(env);
+
+ System.setProperty("org.osgi.framework.storage", "target/osgi/" + System.currentTimeMillis());
+ System.setProperty("karaf.name", "root");
+
+ List<BundleDescriptor> bundles = new ClasspathScanner().scanForBundles("(Bundle-SymbolicName=*)");
+ bundles.add(getBundleDescriptor(
+ "target/jasypt2.jar",
+ bundle().add("OSGI-INF/blueprint/karaf-jaas-jasypt.xml", getClass().getResource("/OSGI-INF/blueprint/karaf-jaas-jasypt.xml"))
+ .set("Manifest-Version", "2")
+ .set("Bundle-ManifestVersion", "2")
+ .set("Bundle-SymbolicName", "jasypt")
+ .set("Bundle-Version", "0.0.0")));
+ bundles.add(getBundleDescriptor(
+ "target/test2.jar",
+ bundle().add("OSGI-INF/blueprint/config-adminTest.xml", getClass().getResource("config-adminTest.xml"))
+ .set("Manifest-Version", "2")
+ .set("Bundle-ManifestVersion", "2")
+ .set("Bundle-SymbolicName", "configtest")
+ .set("Bundle-Version", "0.0.0")));
+
+ Map config = new HashMap();
+ config.put(PojoServiceRegistryFactory.BUNDLE_DESCRIPTORS, bundles);
+ PojoServiceRegistry reg = new PojoServiceRegistryFactoryImpl().newPojoServiceRegistry(config);
+ bundleContext = reg.getBundleContext();
+ }
+
+ private BundleDescriptor getBundleDescriptor(String path, TinyBundle bundle) throws Exception {
+ File file = new File(path);
+ FileOutputStream fos = new FileOutputStream(file);
+ copy(bundle.build(), fos);
+ fos.close();
+ JarInputStream jis = new JarInputStream(new FileInputStream(file));
+ Map<String, String> headers = new HashMap<String, String>();
+ for (Map.Entry entry : jis.getManifest().getMainAttributes().entrySet()) {
+ headers.put(entry.getKey().toString(), entry.getValue().toString());
+ }
+ return new BundleDescriptor(
+ getClass().getClassLoader(),
+ new URL("jar:" + file.toURI().toString() + "!/"),
+ headers);
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ bundleContext.getBundle().stop();
+ }
+
+ @Test
+ public void testEncryptConfigProperty() throws Exception {
+
+ for (Bundle bundle : bundleContext.getBundles()) {
+ System.out.println(bundle.getSymbolicName() + " / " + bundle.getVersion());
+ }
+
+ configAdmin = getOsgiService(ConfigurationAdmin.class);
+ assertNotNull(configAdmin);
+
+ Configuration config = configAdmin.createFactoryConfiguration("encrypt.config");
+ Dictionary props = new Properties();
+
+ // Encrypt a key/value
+ // bar is encrypted and link to foo key
+ encryptedValue = enc.encrypt("bar");
+ props.put("foo", encryptedValue);
+ config.setBundleLocation(null);
+ config.update(props);
+
+ Configuration[] configs = configAdmin.listConfigurations(null);
+
+ for (Configuration conf : configs) {
+ String pid = conf.getPid();
+
+ // System.out.println(">> ConfigImpl pid : " + pid);
+
+ Dictionary<String, ?> dict = conf.getProperties();
+ for (Enumeration e = dict.keys(); e.hasMoreElements(); ) {
+ String key = (String) e.nextElement();
+ Object value = dict.get(key);
+
+ // System.out.println(">> Key : " + key + ", value : " + value);
+
+ if (key.equals("foo")) {
+ String val = (String) value;
+ // Verify encrypted value
+ assertEquals(encryptedValue, val);
+ // Decrypt and check value
+ String decrypt = enc.decrypt(val);
+ assertEquals("bar",decrypt);
+ }
+ }
+
+ }
+
+ }
+
+
+ protected <T> T getOsgiService(Class<T> type, long timeout) {
+ return getOsgiService(type, null, timeout);
+ }
+
+ protected <T> T getOsgiService(Class<T> type) {
+ return getOsgiService(type, null, DEFAULT_TIMEOUT);
+ }
+
+ protected <T> T getOsgiService(Class<T> type, String filter) {
+ return getOsgiService(type, filter, DEFAULT_TIMEOUT);
+ }
+
+ protected <T> T getOsgiService(Class<T> type, String filter, long timeout) {
+ ServiceTracker tracker = null;
+ try {
+ String flt;
+ if (filter != null) {
+ if (filter.startsWith("(")) {
+ flt = "(&(" + Constants.OBJECTCLASS + "=" + type.getName() + ")" + filter + ")";
+ } else {
+ flt = "(&(" + Constants.OBJECTCLASS + "=" + type.getName() + ")(" + filter + "))";
+ }
+ } else {
+ flt = "(" + Constants.OBJECTCLASS + "=" + type.getName() + ")";
+ }
+ Filter osgiFilter = FrameworkUtil.createFilter(flt);
+ tracker = new ServiceTracker(bundleContext, osgiFilter, null);
+ tracker.open(true);
+ // Note that the tracker is not closed to keep the reference
+ // This is buggy, as the service reference may change i think
+ Object svc = type.cast(tracker.waitForService(timeout));
+ if (svc == null) {
+ Dictionary dic = bundleContext.getBundle().getHeaders();
+ System.err.println("Test bundle headers: " + explode(dic));
+
+ for (ServiceReference ref : asCollection(bundleContext.getAllServiceReferences(null, null))) {
+ System.err.println("ServiceReference: " + ref);
+ }
+
+ for (ServiceReference ref : asCollection(bundleContext.getAllServiceReferences(null, flt))) {
+ System.err.println("Filtered ServiceReference: " + ref);
+ }
+
+ throw new RuntimeException("Gave up waiting for service " + flt);
+ }
+ return type.cast(svc);
+ } catch (InvalidSyntaxException e) {
+ throw new IllegalArgumentException("Invalid filter", e);
+ } catch (InterruptedException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ /*
+ * Explode the dictionary into a ,-delimited list of key=value pairs
+ */
+ private static String explode(Dictionary dictionary) {
+ Enumeration keys = dictionary.keys();
+ StringBuffer result = new StringBuffer();
+ while (keys.hasMoreElements()) {
+ Object key = keys.nextElement();
+ result.append(String.format("%s=%s", key, dictionary.get(key)));
+ if (keys.hasMoreElements()) {
+ result.append(", ");
+ }
+ }
+ return result.toString();
+ }
+
+ /*
+ * Provides an iterable collection of references, even if the original array is null
+ */
+ private static final Collection<ServiceReference> asCollection(ServiceReference[] references) {
+ List<ServiceReference> result = new LinkedList<ServiceReference>();
+ if (references != null) {
+ for (ServiceReference reference : references) {
+ result.add(reference);
+ }
+ }
+ return result;
+ }
+
+ public static long copy(final InputStream input, final OutputStream output) throws IOException {
+ return copy(input, output, 8024);
+ }
+
+ public static long copy(final InputStream input, final OutputStream output, int buffersize) throws IOException {
+ final byte[] buffer = new byte[buffersize];
+ int n;
+ long count = 0;
+ while (-1 != (n = input.read(buffer))) {
+ output.write(buffer, 0, n);
+ count += n;
+ }
+ return count;
+ }
+
+ /*
+ public void setConfigAdmin(ConfigurationAdmin configAdmin) {
+ this.configAdmin = configAdmin;
+ }*/
+}
http://git-wip-us.apache.org/repos/asf/karaf/blob/5e2f19c4/jaas/blueprint/jasypt/src/test/java/org/apache/karaf/jaas/blueprint/jasypt/handler/EncryptablePropertyPlaceholderTest.java
----------------------------------------------------------------------
diff --git a/jaas/blueprint/jasypt/src/test/java/org/apache/karaf/jaas/blueprint/jasypt/handler/EncryptablePropertyPlaceholderTest.java b/jaas/blueprint/jasypt/src/test/java/org/apache/karaf/jaas/blueprint/jasypt/handler/EncryptablePropertyPlaceholderTest.java
new file mode 100644
index 0000000..d3e0f7b
--- /dev/null
+++ b/jaas/blueprint/jasypt/src/test/java/org/apache/karaf/jaas/blueprint/jasypt/handler/EncryptablePropertyPlaceholderTest.java
@@ -0,0 +1,228 @@
+/*
+ * 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.
+ * under the License.
+ */
+package org.apache.karaf.jaas.blueprint.jasypt.handler;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.net.URL;
+import java.util.Collection;
+import java.util.Dictionary;
+import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.jar.JarInputStream;
+
+import de.kalpatec.pojosr.framework.PojoServiceRegistryFactoryImpl;
+import de.kalpatec.pojosr.framework.launch.BundleDescriptor;
+import de.kalpatec.pojosr.framework.launch.ClasspathScanner;
+import de.kalpatec.pojosr.framework.launch.PojoServiceRegistry;
+import de.kalpatec.pojosr.framework.launch.PojoServiceRegistryFactory;
+import junit.framework.TestCase;
+import org.jasypt.encryption.pbe.StandardPBEStringEncryptor;
+import org.jasypt.encryption.pbe.config.EnvironmentStringPBEConfig;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.ops4j.pax.tinybundles.core.TinyBundle;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.Constants;
+import org.osgi.framework.Filter;
+import org.osgi.framework.FrameworkUtil;
+import org.osgi.framework.InvalidSyntaxException;
+import org.osgi.framework.ServiceReference;
+import org.osgi.util.tracker.ServiceTracker;
+
+import static org.ops4j.pax.tinybundles.core.TinyBundles.bundle;
+
+public class EncryptablePropertyPlaceholderTest extends TestCase {
+
+ public static final long DEFAULT_TIMEOUT = 30000;
+
+ private BundleContext bundleContext;
+
+ @Before
+ public void setUp() throws Exception {
+
+ StandardPBEStringEncryptor enc = new StandardPBEStringEncryptor();
+ EnvironmentStringPBEConfig env = new EnvironmentStringPBEConfig();
+ env.setAlgorithm("PBEWithMD5AndDES");
+ env.setPassword("password");
+ enc.setConfig(env);
+ String val = enc.encrypt("bar");
+ System.setProperty("foo", val);
+
+ System.setProperty("org.bundles.framework.storage", "target/bundles/" + System.currentTimeMillis());
+ System.setProperty("karaf.name", "root");
+
+ List<BundleDescriptor> bundles = new ClasspathScanner().scanForBundles("(Bundle-SymbolicName=*)");
+ bundles.add(getBundleDescriptor(
+ "target/jasypt.jar",
+ bundle().add("OSGI-INF/blueprint/karaf-jaas-jasypt.xml", getClass().getResource("/OSGI-INF/blueprint/karaf-jaas-jasypt.xml"))
+ .set("Manifest-Version", "2")
+ .set("Bundle-ManifestVersion", "2")
+ .set("Bundle-SymbolicName", "jasypt")
+ .set("Bundle-Version", "0.0.0")));
+ bundles.add(getBundleDescriptor(
+ "target/test.jar",
+ bundle().add("OSGI-INF/blueprint/test.xml", getClass().getResource("test.xml"))
+ .set("Manifest-Version", "2")
+ .set("Bundle-ManifestVersion", "2")
+ .set("Bundle-SymbolicName", "test")
+ .set("Bundle-Version", "0.0.0")));
+
+ Map config = new HashMap();
+ config.put(PojoServiceRegistryFactory.BUNDLE_DESCRIPTORS, bundles);
+ PojoServiceRegistry reg = new PojoServiceRegistryFactoryImpl().newPojoServiceRegistry(config);
+ bundleContext = reg.getBundleContext();
+ }
+
+ private BundleDescriptor getBundleDescriptor(String path, TinyBundle bundle) throws Exception {
+ File file = new File(path);
+ FileOutputStream fos = new FileOutputStream(file);
+ copy(bundle.build(), fos);
+ fos.close();
+ JarInputStream jis = new JarInputStream(new FileInputStream(file));
+ Map<String, String> headers = new HashMap<String, String>();
+ for (Map.Entry entry : jis.getManifest().getMainAttributes().entrySet()) {
+ headers.put(entry.getKey().toString(), entry.getValue().toString());
+ }
+ return new BundleDescriptor(
+ getClass().getClassLoader(),
+ new URL("jar:" + file.toURI().toString() + "!/"),
+ headers);
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ bundleContext.getBundle().stop();
+ }
+
+ @Test
+ public void testPlaceholder() throws Exception {
+
+ for (Bundle bundle: bundleContext.getBundles()) {
+ System.out.println(bundle.getSymbolicName() + " / " + bundle.getVersion());
+ }
+
+ String encoded = getOsgiService(String.class, "(encoded=*)");
+ assertEquals("bar", encoded);
+ }
+
+
+ protected <T> T getOsgiService(Class<T> type, long timeout) {
+ return getOsgiService(type, null, timeout);
+ }
+
+ protected <T> T getOsgiService(Class<T> type) {
+ return getOsgiService(type, null, DEFAULT_TIMEOUT);
+ }
+
+ protected <T> T getOsgiService(Class<T> type, String filter) {
+ return getOsgiService(type, filter, DEFAULT_TIMEOUT);
+ }
+
+ protected <T> T getOsgiService(Class<T> type, String filter, long timeout) {
+ ServiceTracker tracker = null;
+ try {
+ String flt;
+ if (filter != null) {
+ if (filter.startsWith("(")) {
+ flt = "(&(" + Constants.OBJECTCLASS + "=" + type.getName() + ")" + filter + ")";
+ } else {
+ flt = "(&(" + Constants.OBJECTCLASS + "=" + type.getName() + ")(" + filter + "))";
+ }
+ } else {
+ flt = "(" + Constants.OBJECTCLASS + "=" + type.getName() + ")";
+ }
+ Filter osgiFilter = FrameworkUtil.createFilter(flt);
+ tracker = new ServiceTracker(bundleContext, osgiFilter, null);
+ tracker.open(true);
+ // Note that the tracker is not closed to keep the reference
+ // This is buggy, as the service reference may change i think
+ Object svc = type.cast(tracker.waitForService(timeout));
+ if (svc == null) {
+ Dictionary dic = bundleContext.getBundle().getHeaders();
+ System.err.println("Test bundle headers: " + explode(dic));
+
+ for (ServiceReference ref : asCollection(bundleContext.getAllServiceReferences(null, null))) {
+ System.err.println("ServiceReference: " + ref);
+ }
+
+ for (ServiceReference ref : asCollection(bundleContext.getAllServiceReferences(null, flt))) {
+ System.err.println("Filtered ServiceReference: " + ref);
+ }
+
+ throw new RuntimeException("Gave up waiting for service " + flt);
+ }
+ return type.cast(svc);
+ } catch (InvalidSyntaxException e) {
+ throw new IllegalArgumentException("Invalid filter", e);
+ } catch (InterruptedException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ /*
+ * Explode the dictionary into a ,-delimited list of key=value pairs
+ */
+ private static String explode(Dictionary dictionary) {
+ Enumeration keys = dictionary.keys();
+ StringBuffer result = new StringBuffer();
+ while (keys.hasMoreElements()) {
+ Object key = keys.nextElement();
+ result.append(String.format("%s=%s", key, dictionary.get(key)));
+ if (keys.hasMoreElements()) {
+ result.append(", ");
+ }
+ }
+ return result.toString();
+ }
+
+ /*
+ * Provides an iterable collection of references, even if the original array is null
+ */
+ private static final Collection<ServiceReference> asCollection(ServiceReference[] references) {
+ List<ServiceReference> result = new LinkedList<ServiceReference>();
+ if (references != null) {
+ for (ServiceReference reference : references) {
+ result.add(reference);
+ }
+ }
+ return result;
+ }
+
+ public static long copy(final InputStream input, final OutputStream output) throws IOException {
+ return copy(input, output, 8024);
+ }
+
+ public static long copy(final InputStream input, final OutputStream output, int buffersize) throws IOException {
+ final byte[] buffer = new byte[buffersize];
+ int n;
+ long count=0;
+ while (-1 != (n = input.read(buffer))) {
+ output.write(buffer, 0, n);
+ count += n;
+ }
+ return count;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/karaf/blob/5e2f19c4/jaas/blueprint/jasypt/src/test/resources/log4j.properties
----------------------------------------------------------------------
diff --git a/jaas/blueprint/jasypt/src/test/resources/log4j.properties b/jaas/blueprint/jasypt/src/test/resources/log4j.properties
new file mode 100644
index 0000000..e1cbdd1
--- /dev/null
+++ b/jaas/blueprint/jasypt/src/test/resources/log4j.properties
@@ -0,0 +1,34 @@
+## ---------------------------------------------------------------------------
+## 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.
+## ---------------------------------------------------------------------------
+
+#
+# The logging properties used during tests..
+#
+log4j.rootLogger=DEBUG, console, file
+
+# Console will only display warnnings
+log4j.appender.console=org.apache.log4j.ConsoleAppender
+log4j.appender.console.layout=org.apache.log4j.PatternLayout
+log4j.appender.console.layout.ConversionPattern=%d{ISO8601} | %-5.5p | %-16.16t | %-32.32c{1} | %-32.32C %4L | %m%n
+#log4j.appender.console.threshold=WARN
+
+# File appender will contain all info messages
+log4j.appender.file=org.apache.log4j.FileAppender
+log4j.appender.file.layout=org.apache.log4j.PatternLayout
+log4j.appender.file.layout.ConversionPattern=%d | %-5p | %m | %c | %t%n
+log4j.appender.file.file=target/test.log
+log4j.appender.file.append=true
http://git-wip-us.apache.org/repos/asf/karaf/blob/5e2f19c4/jaas/blueprint/jasypt/src/test/resources/org/apache/karaf/jaas/blueprint/jasypt/handler/configadmin-test.xml
----------------------------------------------------------------------
diff --git a/jaas/blueprint/jasypt/src/test/resources/org/apache/karaf/jaas/blueprint/jasypt/handler/configadmin-test.xml b/jaas/blueprint/jasypt/src/test/resources/org/apache/karaf/jaas/blueprint/jasypt/handler/configadmin-test.xml
new file mode 100644
index 0000000..ccb2cca
--- /dev/null
+++ b/jaas/blueprint/jasypt/src/test/resources/org/apache/karaf/jaas/blueprint/jasypt/handler/configadmin-test.xml
@@ -0,0 +1,41 @@
+<?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.
+-->
+<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
+ xmlns:ext="http://aries.apache.org/blueprint/xmlns/blueprint-ext/v1.0.0"
+ xmlns:enc="http://karaf.apache.org/xmlns/jasypt/v1.0.0"
+ xmlns:cm="http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.1.0">
+
+ <cm:property-placeholder persistent-id="encrypt.config" update-strategy="reload" >
+ <cm:default-properties>
+ <cm:property name="encoded" value="ENC(${foo})"/>
+ </cm:default-properties>
+ </cm:property-placeholder>
+
+ <enc:property-placeholder>
+ <enc:encryptor class="org.jasypt.encryption.pbe.StandardPBEStringEncryptor">
+ <property name="config">
+ <bean class="org.jasypt.encryption.pbe.config.EnvironmentStringPBEConfig">
+ <property name="algorithm" value="PBEWithMD5AndDES" />
+ <property name="password" value="password" />
+ </bean>
+ </property>
+ </enc:encryptor>
+ </enc:property-placeholder>
+
+</blueprint>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/karaf/blob/5e2f19c4/jaas/blueprint/jasypt/src/test/resources/org/apache/karaf/jaas/blueprint/jasypt/handler/test.xml
----------------------------------------------------------------------
diff --git a/jaas/blueprint/jasypt/src/test/resources/org/apache/karaf/jaas/blueprint/jasypt/handler/test.xml b/jaas/blueprint/jasypt/src/test/resources/org/apache/karaf/jaas/blueprint/jasypt/handler/test.xml
new file mode 100644
index 0000000..c3a2aff
--- /dev/null
+++ b/jaas/blueprint/jasypt/src/test/resources/org/apache/karaf/jaas/blueprint/jasypt/handler/test.xml
@@ -0,0 +1,45 @@
+<?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.
+-->
+<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
+ xmlns:ext="http://aries.apache.org/blueprint/xmlns/blueprint-ext/v1.0.0"
+ xmlns:enc="http://karaf.apache.org/xmlns/jasypt/v1.0.0">
+
+
+ <ext:property-placeholder />
+
+ <enc:property-placeholder>
+ <enc:encryptor class="org.jasypt.encryption.pbe.StandardPBEStringEncryptor">
+ <property name="config">
+ <bean class="org.jasypt.encryption.pbe.config.EnvironmentStringPBEConfig">
+ <property name="algorithm" value="PBEWithMD5AndDES" />
+ <property name="password" value="password" />
+ </bean>
+ </property>
+ </enc:encryptor>
+ </enc:property-placeholder>
+
+ <service auto-export="all-classes">
+ <service-properties>
+ <entry key="encoded" value="ENC(${foo})" />
+ </service-properties>
+ <bean class="java.lang.String">
+ <argument value="ENC(${foo})" />
+ </bean>
+ </service>
+
+</blueprint>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/karaf/blob/5e2f19c4/jaas/blueprint/pom.xml
----------------------------------------------------------------------
diff --git a/jaas/blueprint/pom.xml b/jaas/blueprint/pom.xml
new file mode 100644
index 0000000..40b5419
--- /dev/null
+++ b/jaas/blueprint/pom.xml
@@ -0,0 +1,41 @@
+<?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.karaf.jaas</groupId>
+ <artifactId>jaas</artifactId>
+ <version>3.1.0-SNAPSHOT</version>
+ <relativePath>../pom.xml</relativePath>
+ </parent>
+
+ <groupId>org.apache.karaf.jaas.blueprint</groupId>
+ <artifactId>blueprint</artifactId>
+ <packaging>pom</packaging>
+ <name>Apache Karaf :: JAAS :: Blueprint</name>
+
+ <modules>
+ <module>config</module>
+ <module>jasypt</module>
+ </modules>
+
+</project>
http://git-wip-us.apache.org/repos/asf/karaf/blob/5e2f19c4/jaas/config/pom.xml
----------------------------------------------------------------------
diff --git a/jaas/config/pom.xml b/jaas/config/pom.xml
index 55b070e..75ca172 100644
--- a/jaas/config/pom.xml
+++ b/jaas/config/pom.xml
@@ -97,18 +97,20 @@
<artifactId>maven-bundle-plugin</artifactId>
<configuration>
<instructions>
- <Export-Package>${project.artifactId};version=${project.version}</Export-Package>
+ <Export-Package>
+ ${project.artifactId};version=${project.version},
+ ${project.artifactId}.impl;version=${project.version}
+ </Export-Package>
<Import-Package>
- !${project.artifactId},
- org.apache.aries.blueprint,
- org.osgi.service.blueprint.container,
- org.osgi.service.blueprint.reflect,
+ !${project.artifactId}.*,
*
</Import-Package>
<Private-Package>
- ${project.artifactId}.impl,
org.apache.karaf.util.collections
</Private-Package>
+ <Bundle-Activator>
+ org.apache.karaf.jaas.config.impl.Activator
+ </Bundle-Activator>
</instructions>
</configuration>
</plugin>
http://git-wip-us.apache.org/repos/asf/karaf/blob/5e2f19c4/jaas/config/src/main/java/org/apache/karaf/jaas/config/impl/Activator.java
----------------------------------------------------------------------
diff --git a/jaas/config/src/main/java/org/apache/karaf/jaas/config/impl/Activator.java b/jaas/config/src/main/java/org/apache/karaf/jaas/config/impl/Activator.java
new file mode 100644
index 0000000..9fc6e53
--- /dev/null
+++ b/jaas/config/src/main/java/org/apache/karaf/jaas/config/impl/Activator.java
@@ -0,0 +1,93 @@
+/*
+ * 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.karaf.jaas.config.impl;
+
+import org.apache.karaf.jaas.boot.ProxyLoginModule;
+import org.apache.karaf.jaas.config.JaasRealm;
+import org.apache.karaf.jaas.config.KeystoreInstance;
+import org.apache.karaf.jaas.config.KeystoreManager;
+import org.osgi.framework.BundleActivator;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceReference;
+import org.osgi.framework.ServiceRegistration;
+import org.osgi.util.tracker.ServiceTracker;
+import org.osgi.util.tracker.ServiceTrackerCustomizer;
+
+public class Activator implements BundleActivator {
+
+ private OsgiConfiguration osgiConfiguration;
+ private ServiceRegistration<KeystoreManager> registration;
+ private ServiceTracker<KeystoreInstance, KeystoreInstance> keystoreInstanceServiceTracker;
+ private ServiceTracker<JaasRealm, JaasRealm> jaasRealmServiceTracker;
+
+ @Override
+ public void start(final BundleContext context) throws Exception {
+ ProxyLoginModule.init(context.getBundle(0).getBundleContext());
+
+ final OsgiKeystoreManager keystoreManager = new OsgiKeystoreManager();
+
+ keystoreInstanceServiceTracker = new ServiceTracker<KeystoreInstance, KeystoreInstance>(
+ context, KeystoreInstance.class, new ServiceTrackerCustomizer<KeystoreInstance, KeystoreInstance>() {
+ @Override
+ public KeystoreInstance addingService(ServiceReference<KeystoreInstance> reference) {
+ KeystoreInstance service = context.getService(reference);
+ keystoreManager.register(service, null);
+ return service;
+ }
+ @Override
+ public void modifiedService(ServiceReference<KeystoreInstance> reference, KeystoreInstance service) {
+ }
+ @Override
+ public void removedService(ServiceReference<KeystoreInstance> reference, KeystoreInstance service) {
+ keystoreManager.unregister(service, null);
+ context.ungetService(reference);
+ }
+ });
+ keystoreInstanceServiceTracker.open();
+
+ osgiConfiguration = new OsgiConfiguration();
+ osgiConfiguration.init();
+
+ jaasRealmServiceTracker = new ServiceTracker<JaasRealm, JaasRealm>(
+ context, JaasRealm.class, new ServiceTrackerCustomizer<JaasRealm, JaasRealm>() {
+ @Override
+ public JaasRealm addingService(ServiceReference<JaasRealm> reference) {
+ JaasRealm service = context.getService(reference);
+ osgiConfiguration.register(service, null);
+ return service;
+ }
+ @Override
+ public void modifiedService(ServiceReference<JaasRealm> reference, JaasRealm service) {
+ }
+ @Override
+ public void removedService(ServiceReference<JaasRealm> reference, JaasRealm service) {
+ osgiConfiguration.unregister(service, null);
+ }
+ });
+ jaasRealmServiceTracker.open();
+
+ registration = context.registerService(KeystoreManager.class, keystoreManager, null);
+ }
+
+ @Override
+ public void stop(BundleContext context) throws Exception {
+ registration.unregister();
+ keystoreInstanceServiceTracker.close();
+ jaasRealmServiceTracker.close();
+ osgiConfiguration.close();
+ }
+}
[06/24] git commit: Log exceptions correctly instead of using
printStackTrace()
Posted by gn...@apache.org.
Log exceptions correctly instead of using printStackTrace()
Project: http://git-wip-us.apache.org/repos/asf/karaf/repo
Commit: http://git-wip-us.apache.org/repos/asf/karaf/commit/f652fabe
Tree: http://git-wip-us.apache.org/repos/asf/karaf/tree/f652fabe
Diff: http://git-wip-us.apache.org/repos/asf/karaf/diff/f652fabe
Branch: refs/heads/master
Commit: f652fabe523d7b2c56185562132e5a3eba348f16
Parents: 9483e50
Author: Guillaume Nodet <gn...@gmail.com>
Authored: Mon Mar 24 13:21:03 2014 +0100
Committer: Guillaume Nodet <gn...@gmail.com>
Committed: Mon Mar 24 17:30:12 2014 +0100
----------------------------------------------------------------------
.../org/apache/karaf/shell/ssh/Activator.java | 25 ++++++--------------
1 file changed, 7 insertions(+), 18 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/karaf/blob/f652fabe/shell/ssh/src/main/java/org/apache/karaf/shell/ssh/Activator.java
----------------------------------------------------------------------
diff --git a/shell/ssh/src/main/java/org/apache/karaf/shell/ssh/Activator.java b/shell/ssh/src/main/java/org/apache/karaf/shell/ssh/Activator.java
index a61babc..575c871 100644
--- a/shell/ssh/src/main/java/org/apache/karaf/shell/ssh/Activator.java
+++ b/shell/ssh/src/main/java/org/apache/karaf/shell/ssh/Activator.java
@@ -45,12 +45,16 @@ import org.osgi.framework.ServiceRegistration;
import org.osgi.service.cm.ConfigurationException;
import org.osgi.service.cm.ManagedService;
import org.osgi.util.tracker.ServiceTracker;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
/**
* Activate this bundle
*/
public class Activator implements BundleActivator, ManagedService {
+ static final Logger LOGGER = LoggerFactory.getLogger(Activator.class);
+
ServiceRegistration registration;
List<Session> sessions = new CopyOnWriteArrayList<Session>();
@@ -128,7 +132,7 @@ public class Activator implements BundleActivator, ManagedService {
try {
server.start();
} catch (IOException e) {
- e.printStackTrace();
+ LOGGER.warn("Exception caught while starting SSH server", e);
}
}
}
@@ -144,7 +148,7 @@ public class Activator implements BundleActivator, ManagedService {
try {
srv.stop();
} catch (InterruptedException e) {
- e.printStackTrace();
+ LOGGER.warn("Exception caught while stopping SSH server", e);
}
}
}
@@ -158,8 +162,7 @@ public class Activator implements BundleActivator, ManagedService {
try {
server.stop();
} catch (InterruptedException e) {
- // TODO: log exception
- e.printStackTrace();
+ LOGGER.warn("Exception caught while stopping SSH server", e);
}
}
}
@@ -251,18 +254,4 @@ public class Activator implements BundleActivator, ManagedService {
return server;
}
- public void bindCommandSession(Session session) {
- sessions.add(session);
- if (agentFactory != null) {
- agentFactory.registerSession(session);
- }
- }
-
- public void unbindCommandSession(Session session) {
- sessions.remove(session);
- if (agentFactory != null) {
- agentFactory.unregisterSession(session);
- }
- }
-
}
[08/24] git commit: [KARAF-2845] Make sure
SingleServiceTracker#stop() will call SingleServiceListener#serviceLost()
Posted by gn...@apache.org.
[KARAF-2845] Make sure SingleServiceTracker#stop() will call SingleServiceListener#serviceLost()
Project: http://git-wip-us.apache.org/repos/asf/karaf/repo
Commit: http://git-wip-us.apache.org/repos/asf/karaf/commit/3cf38e7b
Tree: http://git-wip-us.apache.org/repos/asf/karaf/tree/3cf38e7b
Diff: http://git-wip-us.apache.org/repos/asf/karaf/diff/3cf38e7b
Branch: refs/heads/master
Commit: 3cf38e7b5124009067b87ef6b28a958dbd2bd336
Parents: e7f6774
Author: Guillaume Nodet <gn...@gmail.com>
Authored: Mon Mar 24 13:23:13 2014 +0100
Committer: Guillaume Nodet <gn...@gmail.com>
Committed: Mon Mar 24 17:30:12 2014 +0100
----------------------------------------------------------------------
.../org/apache/karaf/util/tracker/SingleServiceTracker.java | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/karaf/blob/3cf38e7b/util/src/main/java/org/apache/karaf/util/tracker/SingleServiceTracker.java
----------------------------------------------------------------------
diff --git a/util/src/main/java/org/apache/karaf/util/tracker/SingleServiceTracker.java b/util/src/main/java/org/apache/karaf/util/tracker/SingleServiceTracker.java
index c96e73a..a946c48 100644
--- a/util/src/main/java/org/apache/karaf/util/tracker/SingleServiceTracker.java
+++ b/util/src/main/java/org/apache/karaf/util/tracker/SingleServiceTracker.java
@@ -161,10 +161,14 @@ public final class SingleServiceTracker<T> {
if (open.compareAndSet(true, false)) {
ctx.removeServiceListener(listener);
+ ServiceReference deadRef;
synchronized (this) {
- ServiceReference deadRef = ref.getAndSet(null);
+ deadRef = ref.getAndSet(null);
service.set(null);
- if (deadRef != null) ctx.ungetService(deadRef);
+ }
+ if (deadRef != null) {
+ serviceListener.serviceLost();
+ ctx.ungetService(deadRef);
}
}
}
[16/24] git commit: [KARAF-2835] Do not include blueprint in the
karaf framework
Posted by gn...@apache.org.
[KARAF-2835] Do not include blueprint in the karaf framework
Project: http://git-wip-us.apache.org/repos/asf/karaf/repo
Commit: http://git-wip-us.apache.org/repos/asf/karaf/commit/8e129bf5
Tree: http://git-wip-us.apache.org/repos/asf/karaf/tree/8e129bf5
Diff: http://git-wip-us.apache.org/repos/asf/karaf/diff/8e129bf5
Branch: refs/heads/master
Commit: 8e129bf5db5a24d983d230b51c34e1e80883f696
Parents: 5e2f19c
Author: Guillaume Nodet <gn...@gmail.com>
Authored: Fri Mar 21 20:05:25 2014 +0100
Committer: Guillaume Nodet <gn...@gmail.com>
Committed: Mon Mar 24 17:30:13 2014 +0100
----------------------------------------------------------------------
assemblies/features/framework/pom.xml | 74 ++------------------
.../framework/src/main/feature/feature.xml | 22 ++----
itests/pom.xml | 6 ++
3 files changed, 20 insertions(+), 82 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/karaf/blob/8e129bf5/assemblies/features/framework/pom.xml
----------------------------------------------------------------------
diff --git a/assemblies/features/framework/pom.xml b/assemblies/features/framework/pom.xml
index f4ed5a6..3d7d81c 100644
--- a/assemblies/features/framework/pom.xml
+++ b/assemblies/features/framework/pom.xml
@@ -164,40 +164,6 @@
</dependency>
<dependency>
- <groupId>org.apache.karaf.features</groupId>
- <artifactId>org.apache.karaf.features.command</artifactId>
- </dependency>
- <dependency>
- <groupId>org.apache.karaf.bundle</groupId>
- <artifactId>org.apache.karaf.bundle.command</artifactId>
- </dependency>
-
- <dependency>
- <groupId>org.apache.karaf.shell</groupId>
- <artifactId>org.apache.karaf.shell.core</artifactId>
- </dependency>
- <dependency>
- <groupId>org.apache.karaf.shell</groupId>
- <artifactId>org.apache.karaf.shell.console</artifactId>
- </dependency>
- <dependency>
- <groupId>org.apache.karaf.shell</groupId>
- <artifactId>org.apache.karaf.shell.table</artifactId>
- </dependency>
-
- <dependency>
- <groupId>org.apache.karaf.system</groupId>
- <artifactId>org.apache.karaf.system.core</artifactId>
- </dependency>
- <dependency>
- <groupId>org.apache.karaf.system</groupId>
- <artifactId>org.apache.karaf.system.command</artifactId>
- </dependency>
- <dependency>
- <groupId>org.apache.karaf.shell</groupId>
- <artifactId>org.apache.karaf.shell.commands</artifactId>
- </dependency>
- <dependency>
<groupId>org.apache.felix</groupId>
<artifactId>org.apache.felix.fileinstall</artifactId>
</dependency>
@@ -207,43 +173,14 @@
</dependency>
<dependency>
- <groupId>org.ow2.asm</groupId>
- <artifactId>asm-all</artifactId>
- </dependency>
-
- <dependency>
- <groupId>org.apache.aries.blueprint</groupId>
- <artifactId>org.apache.aries.blueprint.api</artifactId>
- </dependency>
- <dependency>
- <groupId>org.apache.aries.blueprint</groupId>
- <artifactId>org.apache.aries.blueprint.cm</artifactId>
- </dependency>
- <dependency>
- <groupId>org.apache.aries.blueprint</groupId>
- <artifactId>org.apache.aries.blueprint.core.compatibility</artifactId>
- </dependency>
- <dependency>
- <groupId>org.apache.aries.blueprint</groupId>
- <artifactId>org.apache.aries.blueprint.core</artifactId>
- </dependency>
- <dependency>
- <groupId>org.apache.aries.proxy</groupId>
- <artifactId>org.apache.aries.proxy.api</artifactId>
- </dependency>
- <dependency>
- <groupId>org.apache.aries.proxy</groupId>
- <artifactId>org.apache.aries.proxy.impl</artifactId>
+ <groupId>org.apache.karaf.region</groupId>
+ <artifactId>org.apache.karaf.region.core</artifactId>
</dependency>
<dependency>
- <groupId>org.apache.aries</groupId>
- <artifactId>org.apache.aries.util</artifactId>
+ <groupId>org.apache.karaf.features</groupId>
+ <artifactId>org.apache.karaf.features.core</artifactId>
</dependency>
- <dependency>
- <groupId>org.apache.karaf.region</groupId>
- <artifactId>org.apache.karaf.region.core</artifactId>
- </dependency>
</dependencies>
<build>
@@ -421,6 +358,9 @@
<excludedArtifactIds>
<excludedArtifactId>slf4j-api</excludedArtifactId>
<excludedArtifactId>mina-core</excludedArtifactId>
+ <excludedArtifactId>sshd-core</excludedArtifactId>
+ <excludedArtifactId>jline</excludedArtifactId>
+ <excludedArtifactId>core</excludedArtifactId>
</excludedArtifactIds>
</configuration>
</execution>
http://git-wip-us.apache.org/repos/asf/karaf/blob/8e129bf5/assemblies/features/framework/src/main/feature/feature.xml
----------------------------------------------------------------------
diff --git a/assemblies/features/framework/src/main/feature/feature.xml b/assemblies/features/framework/src/main/feature/feature.xml
index 8234708..70315fb 100644
--- a/assemblies/features/framework/src/main/feature/feature.xml
+++ b/assemblies/features/framework/src/main/feature/feature.xml
@@ -22,27 +22,19 @@
including the correct start-level for the generation of the startup.propertie file -->
<feature version="${project.version}" description="Karaf core feature" name="framework">
+ <!-- mvn: and wrap: url handlers -->
<bundle start="true" start-level="5">mvn:org.ops4j.pax.url/pax-url-aether/${pax.url.version}</bundle>
<bundle start="true" start-level="5">mvn:org.ops4j.pax.url/pax-url-wrap/${pax.url.version}/jar/uber</bundle>
+ <!-- logging -->
<bundle start="true" start-level="8">mvn:org.ops4j.pax.logging/pax-logging-api/${pax.logging.version}</bundle>
<bundle start="true" start-level="8">mvn:org.ops4j.pax.logging/pax-logging-service/${pax.logging.version}</bundle>
- <bundle start="true" start-level="10">mvn:org.apache.karaf.service/org.apache.karaf.service.guard/${project.version}</bundle>
+ <!-- config admin -->
<bundle start="true" start-level="10">mvn:org.apache.felix/org.apache.felix.configadmin/${felix.configadmin.version}</bundle>
+ <!-- file install -->
<bundle start="true" start-level="11">mvn:org.apache.felix/org.apache.felix.fileinstall/${felix.fileinstall.version}</bundle>
- <bundle start="true" start-level="12">mvn:org.ow2.asm/asm-all/${asm.version}</bundle>
- <bundle start="true" start-level="20">mvn:org.apache.aries/org.apache.aries.util/${aries.util.version}</bundle>
- <bundle start="true" start-level="20">mvn:org.apache.aries.proxy/org.apache.aries.proxy.api/${aries.proxy.api.version}</bundle>
- <bundle start="true" start-level="20">mvn:org.apache.aries.proxy/org.apache.aries.proxy.impl/${aries.proxy.version}</bundle>
- <bundle start="true" start-level="20">mvn:org.apache.aries.blueprint/org.apache.aries.blueprint.api/${aries.blueprint.api.version}</bundle>
- <bundle start="true" start-level="20">mvn:org.apache.aries.blueprint/org.apache.aries.blueprint.cm/${aries.blueprint.cm.version}</bundle>
- <bundle start="true" start-level="20">mvn:org.apache.aries.blueprint/org.apache.aries.blueprint.core.compatibility/${aries.blueprint.core.compatibility.version}</bundle>
- <bundle start="true" start-level="20">mvn:org.apache.aries.blueprint/org.apache.aries.blueprint.core/${aries.blueprint.core.version}</bundle>
- <bundle start="true" start-level="24">mvn:org.apache.karaf.deployer/org.apache.karaf.deployer.spring/${project.version}</bundle>
- <bundle start="true" start-level="24">mvn:org.apache.karaf.deployer/org.apache.karaf.deployer.blueprint/${project.version}</bundle>
- <bundle start="true" start-level="24">mvn:org.apache.karaf.deployer/org.apache.karaf.deployer.wrap/${project.version}</bundle>
- <bundle start="true" start-level="25">mvn:org.apache.karaf.region/org.apache.karaf.region.core/${project.version}</bundle>
- <bundle start="true" start-level="25">mvn:org.apache.karaf.features/org.apache.karaf.features.core/${project.version}</bundle>
- <bundle start="true" start-level="26">mvn:org.apache.karaf.deployer/org.apache.karaf.deployer.features/${project.version}</bundle>
+ <!-- features service -->
+ <bundle start="true" start-level="15">mvn:org.apache.karaf.region/org.apache.karaf.region.core/${project.version}</bundle>
+ <bundle start="true" start-level="15">mvn:org.apache.karaf.features/org.apache.karaf.features.core/${project.version}</bundle>
</feature>
</features>
http://git-wip-us.apache.org/repos/asf/karaf/blob/8e129bf5/itests/pom.xml
----------------------------------------------------------------------
diff --git a/itests/pom.xml b/itests/pom.xml
index 5b0c42e..5684baf 100644
--- a/itests/pom.xml
+++ b/itests/pom.xml
@@ -74,6 +74,12 @@
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>org.apache.karaf.shell</groupId>
+ <artifactId>org.apache.karaf.shell.ssh</artifactId>
+ <scope>test</scope>
+ </dependency>
+
</dependencies>
<build>
[04/24] git commit: [KARAF-2833] Make bundle/core independent of
blueprint
Posted by gn...@apache.org.
[KARAF-2833] Make bundle/core independent of blueprint
Project: http://git-wip-us.apache.org/repos/asf/karaf/repo
Commit: http://git-wip-us.apache.org/repos/asf/karaf/commit/766e7dd2
Tree: http://git-wip-us.apache.org/repos/asf/karaf/tree/766e7dd2
Diff: http://git-wip-us.apache.org/repos/asf/karaf/diff/766e7dd2
Branch: refs/heads/master
Commit: 766e7dd2ee38df0cb1c519a684931764135a9179
Parents: ae10408
Author: Guillaume Nodet <gn...@gmail.com>
Authored: Fri Mar 21 18:14:19 2014 +0100
Committer: Guillaume Nodet <gn...@gmail.com>
Committed: Mon Mar 24 17:30:12 2014 +0100
----------------------------------------------------------------------
.../standard/src/main/feature/feature.xml | 5 +-
bundle/blueprintstate/pom.xml | 101 ++++++++++
.../state/blueprint/internal/Activator.java | 44 +++++
.../internal/BlueprintStateService.java | 140 ++++++++++++++
.../karaf/bundle/command/ListServicesTest.java | 2 +-
bundle/core/pom.xml | 5 +
.../bundle/core/internal/BlueprintListener.java | 140 --------------
.../bundle/core/internal/BundleServiceImpl.java | 14 +-
.../bundle/core/internal/osgi/Activator.java | 192 +++++++++++++++++++
.../resources/OSGI-INF/blueprint/blueprint.xml | 66 -------
bundle/pom.xml | 1 +
.../bundle/state/spring/internal/Activator.java | 18 +-
.../spring/internal/SpringStateService.java | 3 +-
pom.xml | 5 +
14 files changed, 512 insertions(+), 224 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/karaf/blob/766e7dd2/assemblies/features/standard/src/main/feature/feature.xml
----------------------------------------------------------------------
diff --git a/assemblies/features/standard/src/main/feature/feature.xml b/assemblies/features/standard/src/main/feature/feature.xml
index b334606..0bfb302 100644
--- a/assemblies/features/standard/src/main/feature/feature.xml
+++ b/assemblies/features/standard/src/main/feature/feature.xml
@@ -61,6 +61,10 @@
<bundle start-level="20">mvn:org.apache.aries.blueprint/org.apache.aries.blueprint.cm/${aries.blueprint.cm.version}</bundle>
<bundle start-level="20">mvn:org.apache.aries.blueprint/org.apache.aries.blueprint.core.compatibility/${aries.blueprint.core.compatibility.version}</bundle>
<bundle start-level="20">mvn:org.apache.aries.blueprint/org.apache.aries.blueprint.core/${aries.blueprint.core.version}</bundle>
+ <conditional>
+ <condition>bundle</condition>
+ <bundle start-level="30">mvn:org.apache.karaf.bundle/org.apache.karaf.bundle.blueprintstate/${project.version}</bundle>
+ </conditional>
</feature>
<feature name="aries-annotation" description="Aries Annotations" version="${project.version}">
@@ -121,7 +125,6 @@
</feature>
<feature name="bundle" description="Provide Bundle support" version="${project.version}">
- <feature version="${project.version}">aries-blueprint</feature>
<bundle start-level="30" start="true">mvn:org.apache.karaf.bundle/org.apache.karaf.bundle.core/${project.version}</bundle>
<bundle start-level="30" start="true">mvn:org.apache.karaf.bundle/org.apache.karaf.bundle.command/${project.version}</bundle>
</feature>
http://git-wip-us.apache.org/repos/asf/karaf/blob/766e7dd2/bundle/blueprintstate/pom.xml
----------------------------------------------------------------------
diff --git a/bundle/blueprintstate/pom.xml b/bundle/blueprintstate/pom.xml
new file mode 100644
index 0000000..b3c0449
--- /dev/null
+++ b/bundle/blueprintstate/pom.xml
@@ -0,0 +1,101 @@
+<?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.karaf.bundle</groupId>
+ <artifactId>bundle</artifactId>
+ <version>3.1.0-SNAPSHOT</version>
+ <relativePath>../pom.xml</relativePath>
+ </parent>
+
+ <artifactId>org.apache.karaf.bundle.blueprintstate</artifactId>
+ <packaging>bundle</packaging>
+ <name>Apache Karaf :: Bundle :: BlueprintStateService</name>
+ <description>Provide State Support for Blueprint bundles</description>
+
+ <properties>
+ <appendedResourcesDirectory>${basedir}/../../etc/appended-resources</appendedResourcesDirectory>
+ </properties>
+
+ <dependencies>
+
+ <dependency>
+ <groupId>org.apache.karaf.bundle</groupId>
+ <artifactId>org.apache.karaf.bundle.core</artifactId>
+ <scope>provided</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.osgi</groupId>
+ <artifactId>org.osgi.core</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-api</artifactId>
+ <scope>provided</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.aries.blueprint</groupId>
+ <artifactId>org.apache.aries.blueprint.api</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-jdk14</artifactId>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <resources>
+ <resource>
+ <directory>${project.basedir}/src/main/resources</directory>
+ <includes>
+ <include>**/*</include>
+ </includes>
+ </resource>
+ <resource>
+ <directory>${project.basedir}/src/main/resources</directory>
+ <filtering>true</filtering>
+ <includes>
+ <include>**/*.info</include>
+ </includes>
+ </resource>
+ </resources>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+ <extensions>true</extensions>
+ <configuration>
+ <instructions>
+ <Bundle-Activator>org.apache.karaf.bundle.state.blueprint.internal.Activator</Bundle-Activator>
+ </instructions>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
+</project>
http://git-wip-us.apache.org/repos/asf/karaf/blob/766e7dd2/bundle/blueprintstate/src/main/java/org/apache/karaf/bundle/state/blueprint/internal/Activator.java
----------------------------------------------------------------------
diff --git a/bundle/blueprintstate/src/main/java/org/apache/karaf/bundle/state/blueprint/internal/Activator.java b/bundle/blueprintstate/src/main/java/org/apache/karaf/bundle/state/blueprint/internal/Activator.java
new file mode 100644
index 0000000..6f44143
--- /dev/null
+++ b/bundle/blueprintstate/src/main/java/org/apache/karaf/bundle/state/blueprint/internal/Activator.java
@@ -0,0 +1,44 @@
+/*
+ * 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.karaf.bundle.state.blueprint.internal;
+
+import org.apache.karaf.bundle.core.BundleStateService;
+import org.osgi.framework.BundleActivator;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.BundleListener;
+import org.osgi.framework.ServiceRegistration;
+import org.osgi.service.blueprint.container.BlueprintListener;
+
+public class Activator implements BundleActivator {
+
+ private ServiceRegistration registration;
+
+ public void start(BundleContext bundleContext) {
+ BlueprintStateService service = new BlueprintStateService();
+ String[] classes = new String[] {
+ BlueprintListener.class.getName(),
+ BundleStateService.class.getName(),
+ BundleListener.class.getName()
+ };
+ registration = bundleContext.registerService(classes, service, null);
+ }
+
+ public void stop(BundleContext context) {
+ registration.unregister();
+ }
+
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/karaf/blob/766e7dd2/bundle/blueprintstate/src/main/java/org/apache/karaf/bundle/state/blueprint/internal/BlueprintStateService.java
----------------------------------------------------------------------
diff --git a/bundle/blueprintstate/src/main/java/org/apache/karaf/bundle/state/blueprint/internal/BlueprintStateService.java b/bundle/blueprintstate/src/main/java/org/apache/karaf/bundle/state/blueprint/internal/BlueprintStateService.java
new file mode 100644
index 0000000..89fde18
--- /dev/null
+++ b/bundle/blueprintstate/src/main/java/org/apache/karaf/bundle/state/blueprint/internal/BlueprintStateService.java
@@ -0,0 +1,140 @@
+/*
+ * 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.karaf.bundle.state.blueprint.internal;
+
+import java.io.PrintWriter;
+import java.io.StringWriter;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+
+import org.apache.karaf.bundle.core.BundleState;
+import org.apache.karaf.bundle.core.BundleStateService;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleEvent;
+import org.osgi.framework.BundleListener;
+import org.osgi.service.blueprint.container.BlueprintEvent;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * TODO: use event instance to receive WAIT topics notifications from blueprint
+ * extender
+ */
+public class BlueprintStateService implements org.osgi.service.blueprint.container.BlueprintListener, BundleListener,
+ BundleStateService {
+
+ private static final Logger LOG = LoggerFactory.getLogger(BlueprintStateService.class);
+
+ private final Map<Long, BlueprintEvent> states;
+
+ public BlueprintStateService() {
+ states = new ConcurrentHashMap<Long, BlueprintEvent>();
+ }
+
+ @Override
+ public String getName() {
+ return BundleStateService.NAME_BLUEPRINT;
+ }
+
+ @Override
+ public String getDiag(Bundle bundle) {
+ BlueprintEvent event = states.get(bundle.getBundleId());
+ if (event == null) {
+ return null;
+ }
+ if (event.getType() != BlueprintEvent.FAILURE && event.getType() != BlueprintEvent.GRACE_PERIOD
+ && event.getType() != BlueprintEvent.WAITING) {
+ return null;
+ }
+ StringBuilder message = new StringBuilder();
+ Date date = new Date(event.getTimestamp());
+ SimpleDateFormat df = new SimpleDateFormat();
+ message.append(df.format(date) + "\n");
+ if (event.getCause() != null) {
+ message.append("Exception: \n");
+ addMessages(message, event.getCause());
+ }
+ if (event.getDependencies() != null) {
+ message.append("Missing dependencies: \n");
+ for (String dep : event.getDependencies()) {
+ message.append(dep + " ");
+ }
+ message.append("\n");
+ }
+ return message.toString();
+ }
+
+ public void addMessages(StringBuilder message, Throwable ex) {
+ message.append(ex.getMessage());
+ message.append("\n");
+ StringWriter errorWriter = new StringWriter();
+ ex.printStackTrace(new PrintWriter(errorWriter));
+ message.append(errorWriter.toString());
+ message.append("\n");
+ }
+
+ @Override
+ public BundleState getState(Bundle bundle) {
+ BlueprintEvent event = states.get(bundle.getBundleId());
+ BundleState state = getState(event);
+ return (bundle.getState() != Bundle.ACTIVE) ? BundleState.Unknown : state;
+ }
+
+ @Override
+ public void blueprintEvent(BlueprintEvent blueprintEvent) {
+ if (LOG.isDebugEnabled()) {
+ BundleState state = getState(blueprintEvent);
+ LOG.debug("Blueprint app state changed to " + state + " for bundle "
+ + blueprintEvent.getBundle().getBundleId());
+ }
+ states.put(blueprintEvent.getBundle().getBundleId(), blueprintEvent);
+ }
+
+ @Override
+ public void bundleChanged(BundleEvent event) {
+ if (event.getType() == BundleEvent.UNINSTALLED) {
+ states.remove(event.getBundle().getBundleId());
+ }
+ }
+
+ private BundleState getState(BlueprintEvent blueprintEvent) {
+ if (blueprintEvent == null) {
+ return BundleState.Unknown;
+ }
+ switch (blueprintEvent.getType()) {
+ case BlueprintEvent.CREATING:
+ return BundleState.Starting;
+ case BlueprintEvent.CREATED:
+ return BundleState.Active;
+ case BlueprintEvent.DESTROYING:
+ return BundleState.Stopping;
+ case BlueprintEvent.DESTROYED:
+ return BundleState.Resolved;
+ case BlueprintEvent.FAILURE:
+ return BundleState.Failure;
+ case BlueprintEvent.GRACE_PERIOD:
+ return BundleState.GracePeriod;
+ case BlueprintEvent.WAITING:
+ return BundleState.Waiting;
+ default:
+ return BundleState.Unknown;
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/karaf/blob/766e7dd2/bundle/command/src/test/java/org/apache/karaf/bundle/command/ListServicesTest.java
----------------------------------------------------------------------
diff --git a/bundle/command/src/test/java/org/apache/karaf/bundle/command/ListServicesTest.java b/bundle/command/src/test/java/org/apache/karaf/bundle/command/ListServicesTest.java
index 2c25a44..876f605 100644
--- a/bundle/command/src/test/java/org/apache/karaf/bundle/command/ListServicesTest.java
+++ b/bundle/command/src/test/java/org/apache/karaf/bundle/command/ListServicesTest.java
@@ -32,7 +32,7 @@ public class ListServicesTest {
listServices = new ListBundleServices();
BundleContext bundleContext = new TestBundleFactory().createBundleContext();
listServices.setBundleContext(bundleContext);
- listServices.setBundleService(new BundleServiceImpl(bundleContext, Collections.EMPTY_LIST));
+ listServices.setBundleService(new BundleServiceImpl(bundleContext));
}
@Test
http://git-wip-us.apache.org/repos/asf/karaf/blob/766e7dd2/bundle/core/pom.xml
----------------------------------------------------------------------
diff --git a/bundle/core/pom.xml b/bundle/core/pom.xml
index dbcd62a..2d73be4 100644
--- a/bundle/core/pom.xml
+++ b/bundle/core/pom.xml
@@ -112,10 +112,15 @@
</Export-Package>
<Private-Package>
org.apache.karaf.bundle.core.internal,
+ org.apache.karaf.bundle.core.internal.osgi,
org.apache.karaf.util.maven,
+ org.apache.karaf.util.tracker,
org.apache.felix.utils.version,
org.apache.felix.utils.manifest
</Private-Package>
+ <Bundle-Activator>
+ org.apache.karaf.bundle.core.internal.osgi.Activator
+ </Bundle-Activator>
</instructions>
</configuration>
</plugin>
http://git-wip-us.apache.org/repos/asf/karaf/blob/766e7dd2/bundle/core/src/main/java/org/apache/karaf/bundle/core/internal/BlueprintListener.java
----------------------------------------------------------------------
diff --git a/bundle/core/src/main/java/org/apache/karaf/bundle/core/internal/BlueprintListener.java b/bundle/core/src/main/java/org/apache/karaf/bundle/core/internal/BlueprintListener.java
deleted file mode 100644
index 9840924..0000000
--- a/bundle/core/src/main/java/org/apache/karaf/bundle/core/internal/BlueprintListener.java
+++ /dev/null
@@ -1,140 +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.karaf.bundle.core.internal;
-
-import java.io.PrintWriter;
-import java.io.StringWriter;
-import java.text.SimpleDateFormat;
-import java.util.Date;
-import java.util.Map;
-import java.util.concurrent.ConcurrentHashMap;
-
-import org.apache.karaf.bundle.core.BundleState;
-import org.apache.karaf.bundle.core.BundleStateService;
-import org.osgi.framework.Bundle;
-import org.osgi.framework.BundleEvent;
-import org.osgi.framework.BundleListener;
-import org.osgi.service.blueprint.container.BlueprintEvent;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * TODO: use event instance to receive WAIT topics notifications from blueprint
- * extender
- */
-public class BlueprintListener implements org.osgi.service.blueprint.container.BlueprintListener, BundleListener,
- BundleStateService {
-
- private static final Logger LOG = LoggerFactory.getLogger(BlueprintListener.class);
-
- private final Map<Long, BlueprintEvent> states;
-
- public BlueprintListener() {
- states = new ConcurrentHashMap<Long, BlueprintEvent>();
- }
-
- @Override
- public String getName() {
- return BundleStateService.NAME_BLUEPRINT;
- }
-
- @Override
- public String getDiag(Bundle bundle) {
- BlueprintEvent event = states.get(bundle.getBundleId());
- if (event == null) {
- return null;
- }
- if (event.getType() != BlueprintEvent.FAILURE && event.getType() != BlueprintEvent.GRACE_PERIOD
- && event.getType() != BlueprintEvent.WAITING) {
- return null;
- }
- StringBuilder message = new StringBuilder();
- Date date = new Date(event.getTimestamp());
- SimpleDateFormat df = new SimpleDateFormat();
- message.append(df.format(date) + "\n");
- if (event.getCause() != null) {
- message.append("Exception: \n");
- addMessages(message, event.getCause());
- }
- if (event.getDependencies() != null) {
- message.append("Missing dependencies: \n");
- for (String dep : event.getDependencies()) {
- message.append(dep + " ");
- }
- message.append("\n");
- }
- return message.toString();
- }
-
- public void addMessages(StringBuilder message, Throwable ex) {
- message.append(ex.getMessage());
- message.append("\n");
- StringWriter errorWriter = new StringWriter();
- ex.printStackTrace(new PrintWriter(errorWriter));
- message.append(errorWriter.toString());
- message.append("\n");
- }
-
- @Override
- public BundleState getState(Bundle bundle) {
- BlueprintEvent event = states.get(bundle.getBundleId());
- BundleState state = getState(event);
- return (bundle.getState() != Bundle.ACTIVE) ? BundleState.Unknown : state;
- }
-
- @Override
- public void blueprintEvent(BlueprintEvent blueprintEvent) {
- if (LOG.isDebugEnabled()) {
- BundleState state = getState(blueprintEvent);
- LOG.debug("Blueprint app state changed to " + state + " for bundle "
- + blueprintEvent.getBundle().getBundleId());
- }
- states.put(blueprintEvent.getBundle().getBundleId(), blueprintEvent);
- }
-
- @Override
- public void bundleChanged(BundleEvent event) {
- if (event.getType() == BundleEvent.UNINSTALLED) {
- states.remove(event.getBundle().getBundleId());
- }
- }
-
- private BundleState getState(BlueprintEvent blueprintEvent) {
- if (blueprintEvent == null) {
- return BundleState.Unknown;
- }
- switch (blueprintEvent.getType()) {
- case BlueprintEvent.CREATING:
- return BundleState.Starting;
- case BlueprintEvent.CREATED:
- return BundleState.Active;
- case BlueprintEvent.DESTROYING:
- return BundleState.Stopping;
- case BlueprintEvent.DESTROYED:
- return BundleState.Resolved;
- case BlueprintEvent.FAILURE:
- return BundleState.Failure;
- case BlueprintEvent.GRACE_PERIOD:
- return BundleState.GracePeriod;
- case BlueprintEvent.WAITING:
- return BundleState.Waiting;
- default:
- return BundleState.Unknown;
- }
- }
-
-}
http://git-wip-us.apache.org/repos/asf/karaf/blob/766e7dd2/bundle/core/src/main/java/org/apache/karaf/bundle/core/internal/BundleServiceImpl.java
----------------------------------------------------------------------
diff --git a/bundle/core/src/main/java/org/apache/karaf/bundle/core/internal/BundleServiceImpl.java b/bundle/core/src/main/java/org/apache/karaf/bundle/core/internal/BundleServiceImpl.java
index f908a26..fbf047f 100644
--- a/bundle/core/src/main/java/org/apache/karaf/bundle/core/internal/BundleServiceImpl.java
+++ b/bundle/core/src/main/java/org/apache/karaf/bundle/core/internal/BundleServiceImpl.java
@@ -26,6 +26,7 @@ import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
+import java.util.concurrent.CopyOnWriteArrayList;
import org.apache.karaf.bundle.core.BundleInfo;
import org.apache.karaf.bundle.core.BundleService;
@@ -54,11 +55,18 @@ public class BundleServiceImpl implements BundleService {
private static final String ORIGINAL_WIRES = "Original-Wires";
private final BundleContext bundleContext;
- private final List<BundleStateService> stateServices;
+ private final List<BundleStateService> stateServices = new CopyOnWriteArrayList<BundleStateService>();
- public BundleServiceImpl(BundleContext bundleContext, List<BundleStateService> stateServices) {
+ public BundleServiceImpl(BundleContext bundleContext) {
this.bundleContext = bundleContext;
- this.stateServices = stateServices;
+ }
+
+ public void registerBundleStateService(BundleStateService service) {
+ stateServices.add(service);
+ }
+
+ public void unregisterBundleStateService(BundleStateService service) {
+ stateServices.remove(service);
}
@Override
http://git-wip-us.apache.org/repos/asf/karaf/blob/766e7dd2/bundle/core/src/main/java/org/apache/karaf/bundle/core/internal/osgi/Activator.java
----------------------------------------------------------------------
diff --git a/bundle/core/src/main/java/org/apache/karaf/bundle/core/internal/osgi/Activator.java b/bundle/core/src/main/java/org/apache/karaf/bundle/core/internal/osgi/Activator.java
new file mode 100644
index 0000000..df3899e
--- /dev/null
+++ b/bundle/core/src/main/java/org/apache/karaf/bundle/core/internal/osgi/Activator.java
@@ -0,0 +1,192 @@
+/*
+ * 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.karaf.bundle.core.internal.osgi;
+
+import java.util.ArrayList;
+import java.util.Hashtable;
+import java.util.List;
+import java.util.Properties;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.TimeUnit;
+
+import javax.management.NotCompliantMBeanException;
+
+import org.apache.karaf.bundle.core.BundleService;
+import org.apache.karaf.bundle.core.BundleStateService;
+import org.apache.karaf.bundle.core.BundleWatcher;
+import org.apache.karaf.bundle.core.internal.BundleServiceImpl;
+import org.apache.karaf.bundle.core.internal.BundleWatcherImpl;
+import org.apache.karaf.bundle.core.internal.BundlesMBeanImpl;
+import org.apache.karaf.bundle.core.internal.MavenConfigService;
+import org.apache.karaf.util.tracker.SingleServiceTracker;
+import org.osgi.framework.BundleActivator;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceReference;
+import org.osgi.framework.ServiceRegistration;
+import org.osgi.service.cm.ConfigurationAdmin;
+import org.osgi.util.tracker.ServiceTracker;
+import org.osgi.util.tracker.ServiceTrackerCustomizer;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class Activator implements BundleActivator, SingleServiceTracker.SingleServiceListener {
+
+ private static final Logger LOGGER = LoggerFactory.getLogger(Activator.class);
+
+ private ExecutorService executor = Executors.newSingleThreadExecutor();
+ private BundleContext bundleContext;
+ private SingleServiceTracker<ConfigurationAdmin> configurationAdminTracker;
+ private ServiceTracker<BundleStateService, BundleStateService> bundleStateServicesTracker;
+
+ private BundleWatcherImpl bundleWatcher;
+ private ServiceRegistration<BundleWatcher> bundleWatcherRegistration;
+ private ServiceRegistration<BundleService> bundleServiceRegistration;
+ private ServiceRegistration bundleServiceMBeanRegistration;
+
+ @Override
+ public void start(BundleContext context) throws Exception {
+ bundleContext = context;
+ configurationAdminTracker = new SingleServiceTracker<ConfigurationAdmin>(
+ bundleContext, ConfigurationAdmin.class, this
+ );
+ configurationAdminTracker.open();
+ }
+
+ @Override
+ public void stop(BundleContext context) throws Exception {
+ configurationAdminTracker.close();
+ executor.shutdown();
+ executor.awaitTermination(30, TimeUnit.SECONDS);
+ }
+
+ protected void doStart() {
+ ConfigurationAdmin configurationAdmin = configurationAdminTracker.getService();
+
+ if (configurationAdmin == null) {
+ return;
+ }
+
+ final BundleServiceImpl bundleService = new BundleServiceImpl(bundleContext);
+ bundleServiceRegistration = bundleContext.registerService(BundleService.class, bundleService, null);
+ bundleStateServicesTracker = new ServiceTracker<BundleStateService, BundleStateService>(
+ bundleContext, BundleStateService.class, new ServiceTrackerCustomizer<BundleStateService, BundleStateService>() {
+ @Override
+ public BundleStateService addingService(ServiceReference<BundleStateService> reference) {
+ BundleStateService service = bundleContext.getService(reference);
+ bundleService.registerBundleStateService(service);
+ return service;
+ }
+ @Override
+ public void modifiedService(ServiceReference<BundleStateService> reference, BundleStateService service) {
+ }
+ @Override
+ public void removedService(ServiceReference<BundleStateService> reference, BundleStateService service) {
+ bundleService.unregisterBundleStateService(service);
+ bundleContext.ungetService(reference);
+ }
+ }
+ );
+ bundleStateServicesTracker.open();
+
+ bundleWatcher = new BundleWatcherImpl(bundleContext, new MavenConfigService(configurationAdmin), bundleService);
+ bundleWatcher.start();
+ bundleWatcherRegistration = bundleContext.registerService(BundleWatcher.class, bundleWatcher, null);
+
+ try {
+ BundlesMBeanImpl bundlesMBeanImpl = new BundlesMBeanImpl(bundleContext, bundleService);
+ Hashtable<String, Object> props = new Hashtable<String, Object>();
+ props.put("jmx.objectname", "org.apache.karaf:type=bundle,name=" + System.getProperty("karaf.name"));
+ bundleServiceMBeanRegistration = bundleContext.registerService(
+ getInterfaceNames(bundlesMBeanImpl),
+ bundlesMBeanImpl,
+ props
+ );
+ } catch (NotCompliantMBeanException e) {
+ LOGGER.warn("Error creating FeaturesService mbean", e);
+ }
+ }
+
+ protected void doStop() {
+ if (bundleStateServicesTracker != null) {
+ bundleStateServicesTracker.close();
+ bundleStateServicesTracker = null;
+ }
+ if (bundleWatcher != null) {
+ bundleWatcher.stop();
+ bundleWatcher = null;
+ }
+ if (bundleServiceMBeanRegistration != null) {
+ bundleServiceMBeanRegistration.unregister();
+ bundleServiceMBeanRegistration = null;
+ }
+ if (bundleServiceRegistration != null) {
+ bundleServiceRegistration.unregister();
+ bundleServiceRegistration = null;
+ }
+ if (bundleWatcherRegistration != null) {
+ bundleWatcherRegistration.unregister();
+ bundleWatcherRegistration = null;
+ }
+ if (bundleWatcher != null) {
+ bundleWatcher.stop();
+ bundleWatcher = null;
+ }
+ }
+
+ @Override
+ public void serviceFound() {
+ executor.submit(new Runnable() {
+ @Override
+ public void run() {
+ doStop();
+ try {
+ doStart();
+ } catch (Exception e) {
+ LOGGER.warn("Error starting FeaturesService", e);
+ doStop();
+ }
+ }
+ });
+ }
+
+ @Override
+ public void serviceLost() {
+ serviceFound();
+ }
+
+ @Override
+ public void serviceReplaced() {
+ serviceFound();
+ }
+
+ private String[] getInterfaceNames(Object object) {
+ List<String> names = new ArrayList<String>();
+ for (Class cl = object.getClass(); cl != Object.class; cl = cl.getSuperclass()) {
+ addSuperInterfaces(names, cl);
+ }
+ return names.toArray(new String[names.size()]);
+ }
+
+ private void addSuperInterfaces(List<String> names, Class clazz) {
+ for (Class cl : clazz.getInterfaces()) {
+ names.add(cl.getName());
+ addSuperInterfaces(names, cl);
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/karaf/blob/766e7dd2/bundle/core/src/main/resources/OSGI-INF/blueprint/blueprint.xml
----------------------------------------------------------------------
diff --git a/bundle/core/src/main/resources/OSGI-INF/blueprint/blueprint.xml b/bundle/core/src/main/resources/OSGI-INF/blueprint/blueprint.xml
deleted file mode 100644
index e0512d8..0000000
--- a/bundle/core/src/main/resources/OSGI-INF/blueprint/blueprint.xml
+++ /dev/null
@@ -1,66 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
-
- Licensed to the Apache Software Foundation (ASF) under one or more
- contributor license agreements. See the NOTICE file distributed with
- this work for additional information regarding copyright ownership.
- The ASF licenses this file to You under the Apache License, Version 2.0
- (the "License"); you may not use this file except in compliance with
- the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
-
--->
-<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
- xmlns:ext="http://aries.apache.org/blueprint/xmlns/blueprint-ext/v1.0.0">
-
- <ext:property-placeholder placeholder-prefix="$[" placeholder-suffix="]"/>
-
- <reference id="configurationAdmin" interface="org.osgi.service.cm.ConfigurationAdmin"/>
- <reference-list id="bundleStateServices" interface="org.apache.karaf.bundle.core.BundleStateService" availability="optional" />
-
- <bean id="bundleService" class="org.apache.karaf.bundle.core.internal.BundleServiceImpl">
- <argument ref="blueprintBundleContext"/>
- <argument ref="bundleStateServices"/>
- </bean>
-
- <bean id="blueprintListener" class="org.apache.karaf.bundle.core.internal.BlueprintListener" />
-
-
- <bean id="bundlesMBean" class="org.apache.karaf.bundle.core.internal.BundlesMBeanImpl">
- <argument ref="blueprintBundleContext" />
- <argument ref="bundleService" />
- </bean>
-
- <bean id="watcher" class="org.apache.karaf.bundle.core.internal.BundleWatcherImpl" init-method="start" destroy-method="stop">
- <argument ref="blueprintBundleContext"/>
- <argument ref="mavenConfigService"/>
- <argument ref="bundleService"/>
- </bean>
-
- <bean id="mavenConfigService" class="org.apache.karaf.bundle.core.internal.MavenConfigService">
- <argument ref="configurationAdmin"/>
- </bean>
-
- <service ref="blueprintListener">
- <interfaces>
- <value>org.osgi.service.blueprint.container.BlueprintListener</value>
- <value>org.osgi.framework.BundleListener</value>
- <value>org.apache.karaf.bundle.core.BundleStateService</value>
- </interfaces>
- </service>
- <service interface="org.apache.karaf.bundle.core.BundleService" ref="bundleService"/>
- <service ref="bundlesMBean" auto-export="interfaces">
- <service-properties>
- <entry key="jmx.objectname" value="org.apache.karaf:type=bundle,name=$[karaf.name]"/>
- </service-properties>
- </service>
- <service ref="watcher" interface="org.apache.karaf.bundle.core.BundleWatcher"/>
-
-</blueprint>
http://git-wip-us.apache.org/repos/asf/karaf/blob/766e7dd2/bundle/pom.xml
----------------------------------------------------------------------
diff --git a/bundle/pom.xml b/bundle/pom.xml
index ec6178d..925102d 100644
--- a/bundle/pom.xml
+++ b/bundle/pom.xml
@@ -36,6 +36,7 @@
<modules>
<module>core</module>
<module>command</module>
+ <module>blueprintstate</module>
<module>springstate</module>
</modules>
http://git-wip-us.apache.org/repos/asf/karaf/blob/766e7dd2/bundle/springstate/src/main/java/org/apache/karaf/bundle/state/spring/internal/Activator.java
----------------------------------------------------------------------
diff --git a/bundle/springstate/src/main/java/org/apache/karaf/bundle/state/spring/internal/Activator.java b/bundle/springstate/src/main/java/org/apache/karaf/bundle/state/spring/internal/Activator.java
index 2845a56..09a4949 100644
--- a/bundle/springstate/src/main/java/org/apache/karaf/bundle/state/spring/internal/Activator.java
+++ b/bundle/springstate/src/main/java/org/apache/karaf/bundle/state/spring/internal/Activator.java
@@ -16,31 +16,27 @@
*/
package org.apache.karaf.bundle.state.spring.internal;
-import java.util.Dictionary;
-import java.util.Hashtable;
-
import org.apache.karaf.bundle.core.BundleStateService;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceRegistration;
import org.springframework.osgi.context.event.OsgiBundleApplicationContextListener;
public class Activator implements BundleActivator {
- public void start(BundleContext bundleContext) {
- registerSpringBundleStateService(bundleContext);
- }
+ private ServiceRegistration registration;
- private void registerSpringBundleStateService(BundleContext bundleContext) {
- SpringStateService springStateService = new SpringStateService(bundleContext);
- Dictionary<String, ?> properties = new Hashtable<String, String>();
- String[] classes2 = new String[] {
+ public void start(BundleContext bundleContext) {
+ SpringStateService services = new SpringStateService();
+ String[] classes = new String[] {
OsgiBundleApplicationContextListener.class.getName(),
BundleStateService.class.getName()
};
- bundleContext.registerService(classes2, springStateService, properties);
+ registration = bundleContext.registerService(classes, services, null);
}
public void stop(BundleContext context) {
+ registration.unregister();
}
}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/karaf/blob/766e7dd2/bundle/springstate/src/main/java/org/apache/karaf/bundle/state/spring/internal/SpringStateService.java
----------------------------------------------------------------------
diff --git a/bundle/springstate/src/main/java/org/apache/karaf/bundle/state/spring/internal/SpringStateService.java b/bundle/springstate/src/main/java/org/apache/karaf/bundle/state/spring/internal/SpringStateService.java
index d0ca26b..e09e6e1 100644
--- a/bundle/springstate/src/main/java/org/apache/karaf/bundle/state/spring/internal/SpringStateService.java
+++ b/bundle/springstate/src/main/java/org/apache/karaf/bundle/state/spring/internal/SpringStateService.java
@@ -26,7 +26,6 @@ import java.util.concurrent.ConcurrentHashMap;
import org.apache.karaf.bundle.core.BundleState;
import org.apache.karaf.bundle.core.BundleStateService;
import org.osgi.framework.Bundle;
-import org.osgi.framework.BundleContext;
import org.osgi.framework.BundleEvent;
import org.osgi.framework.BundleListener;
import org.slf4j.Logger;
@@ -44,7 +43,7 @@ public class SpringStateService implements OsgiBundleApplicationContextListener,
private final Map<Long, OsgiBundleApplicationContextEvent> states;
- public SpringStateService(BundleContext bundleContext) {
+ public SpringStateService() {
this.states = new ConcurrentHashMap<Long, OsgiBundleApplicationContextEvent>();
}
http://git-wip-us.apache.org/repos/asf/karaf/blob/766e7dd2/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index 60fd604..7e90888 100644
--- a/pom.xml
+++ b/pom.xml
@@ -393,6 +393,11 @@
<artifactId>org.apache.karaf.bundle.springstate</artifactId>
<version>${project.version}</version>
</dependency>
+ <dependency>
+ <groupId>org.apache.karaf.bundle</groupId>
+ <artifactId>org.apache.karaf.bundle.blueprintstate</artifactId>
+ <version>${project.version}</version>
+ </dependency>
<dependency>
<groupId>org.apache.karaf.package</groupId>
[21/24] git commit: [KARAF-2833] Make service/core independent of
blueprint
Posted by gn...@apache.org.
[KARAF-2833] Make service/core independent of blueprint
Project: http://git-wip-us.apache.org/repos/asf/karaf/repo
Commit: http://git-wip-us.apache.org/repos/asf/karaf/commit/a1e5d4f5
Tree: http://git-wip-us.apache.org/repos/asf/karaf/tree/a1e5d4f5
Diff: http://git-wip-us.apache.org/repos/asf/karaf/diff/a1e5d4f5
Branch: refs/heads/master
Commit: a1e5d4f59d47b18eea29b673e969fea27d897053
Parents: b355415
Author: Guillaume Nodet <gn...@gmail.com>
Authored: Sat Mar 22 16:29:37 2014 +0100
Committer: Guillaume Nodet <gn...@gmail.com>
Committed: Mon Mar 24 17:30:13 2014 +0100
----------------------------------------------------------------------
.../standard/src/main/feature/feature.xml | 1 -
service/core/pom.xml | 8 ++-
.../service/core/internal/osgi/Activator.java | 65 ++++++++++++++++++++
.../resources/OSGI-INF/blueprint/blueprint.xml | 30 ---------
4 files changed, 71 insertions(+), 33 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/karaf/blob/a1e5d4f5/assemblies/features/standard/src/main/feature/feature.xml
----------------------------------------------------------------------
diff --git a/assemblies/features/standard/src/main/feature/feature.xml b/assemblies/features/standard/src/main/feature/feature.xml
index 80c14f8..8df6409 100644
--- a/assemblies/features/standard/src/main/feature/feature.xml
+++ b/assemblies/features/standard/src/main/feature/feature.xml
@@ -173,7 +173,6 @@
</feature>
<feature name="service" description="Provide Service support" version="${project.version}">
- <feature version="${project.version}">aries-blueprint</feature>
<bundle start-level="30" start="true">mvn:org.apache.karaf.service/org.apache.karaf.service.core/${project.version}</bundle>
<bundle start-level="30" start="true">mvn:org.apache.karaf.service/org.apache.karaf.service.command/${project.version}</bundle>
</feature>
http://git-wip-us.apache.org/repos/asf/karaf/blob/a1e5d4f5/service/core/pom.xml
----------------------------------------------------------------------
diff --git a/service/core/pom.xml b/service/core/pom.xml
index 7cc7e1e..66ee92b 100644
--- a/service/core/pom.xml
+++ b/service/core/pom.xml
@@ -68,11 +68,15 @@
<configuration>
<instructions>
<Export-Package>
- org.apache.karaf.service.core
+ org.apache.karaf.service.core;-noimport:=true
</Export-Package>
<Private-Package>
- org.apache.karaf.service.core.internal
+ org.apache.karaf.service.core.internal,
+ org.apache.karaf.service.core.internal.osgi
</Private-Package>
+ <Bundle-Activator>
+ org.apache.karaf.service.core.internal.osgi.Activator
+ </Bundle-Activator>
</instructions>
</configuration>
</plugin>
http://git-wip-us.apache.org/repos/asf/karaf/blob/a1e5d4f5/service/core/src/main/java/org/apache/karaf/service/core/internal/osgi/Activator.java
----------------------------------------------------------------------
diff --git a/service/core/src/main/java/org/apache/karaf/service/core/internal/osgi/Activator.java b/service/core/src/main/java/org/apache/karaf/service/core/internal/osgi/Activator.java
new file mode 100644
index 0000000..25b9e30
--- /dev/null
+++ b/service/core/src/main/java/org/apache/karaf/service/core/internal/osgi/Activator.java
@@ -0,0 +1,65 @@
+/*
+ * 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.karaf.service.core.internal.osgi;
+
+import java.util.ArrayList;
+import java.util.Hashtable;
+import java.util.List;
+
+import org.apache.karaf.service.core.internal.ServicesMBeanImpl;
+import org.osgi.framework.BundleActivator;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceRegistration;
+
+public class Activator implements BundleActivator {
+
+ private ServiceRegistration mbeanRegistration;
+
+ @Override
+ public void start(BundleContext context) throws Exception {
+ ServicesMBeanImpl mbean = new ServicesMBeanImpl();
+ mbean.setBundleContext(context);
+ Hashtable<String, Object> props = new Hashtable<String, Object>();
+ props.put("jmx.objectname", "org.apache.karaf:type=service,name=" + System.getProperty("karaf.name"));
+ mbeanRegistration = context.registerService(
+ getInterfaceNames(mbean),
+ mbean,
+ props
+ );
+ }
+
+ @Override
+ public void stop(BundleContext context) throws Exception {
+ mbeanRegistration.unregister();
+ }
+
+ private String[] getInterfaceNames(Object object) {
+ List<String> names = new ArrayList<String>();
+ for (Class cl = object.getClass(); cl != Object.class; cl = cl.getSuperclass()) {
+ addSuperInterfaces(names, cl);
+ }
+ return names.toArray(new String[names.size()]);
+ }
+
+ private void addSuperInterfaces(List<String> names, Class clazz) {
+ for (Class cl : clazz.getInterfaces()) {
+ names.add(cl.getName());
+ addSuperInterfaces(names, cl);
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/karaf/blob/a1e5d4f5/service/core/src/main/resources/OSGI-INF/blueprint/blueprint.xml
----------------------------------------------------------------------
diff --git a/service/core/src/main/resources/OSGI-INF/blueprint/blueprint.xml b/service/core/src/main/resources/OSGI-INF/blueprint/blueprint.xml
deleted file mode 100644
index d022432..0000000
--- a/service/core/src/main/resources/OSGI-INF/blueprint/blueprint.xml
+++ /dev/null
@@ -1,30 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
- 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.
--->
-<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
- xmlns:ext="http://aries.apache.org/blueprint/xmlns/blueprint-ext/v1.0.0">
-
- <ext:property-placeholder/>
-
- <bean id="servicesMBean" class="org.apache.karaf.service.core.internal.ServicesMBeanImpl">
- <property name="bundleContext" ref="blueprintBundleContext"/>
- </bean>
-
- <service ref="servicesMBean" auto-export="interfaces">
- <service-properties>
- <entry key="jmx.objectname" value="org.apache.karaf:type=service,name=${karaf.name}"/>
- </service-properties>
- </service>
-
-</blueprint>
\ No newline at end of file
[18/24] git commit: [KARAF-2833] Make management/server independent
of blueprint
Posted by gn...@apache.org.
[KARAF-2833] Make management/server independent of blueprint
Project: http://git-wip-us.apache.org/repos/asf/karaf/repo
Commit: http://git-wip-us.apache.org/repos/asf/karaf/commit/3091414d
Tree: http://git-wip-us.apache.org/repos/asf/karaf/tree/3091414d
Diff: http://git-wip-us.apache.org/repos/asf/karaf/diff/3091414d
Branch: refs/heads/master
Commit: 3091414d3430bd8e5674200575384fb6f7783696
Parents: 42b676b
Author: Guillaume Nodet <gn...@gmail.com>
Authored: Sat Mar 22 16:13:32 2014 +0100
Committer: Guillaume Nodet <gn...@gmail.com>
Committed: Mon Mar 24 17:30:13 2014 +0100
----------------------------------------------------------------------
.../standard/src/main/feature/feature.xml | 1 -
management/server/pom.xml | 17 +-
.../karaf/management/internal/Activator.java | 326 +++++++++++++++++++
.../OSGI-INF/blueprint/karaf-management.xml | 125 -------
4 files changed, 342 insertions(+), 127 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/karaf/blob/3091414d/assemblies/features/standard/src/main/feature/feature.xml
----------------------------------------------------------------------
diff --git a/assemblies/features/standard/src/main/feature/feature.xml b/assemblies/features/standard/src/main/feature/feature.xml
index 2b0f6c4..e6e6f3f 100644
--- a/assemblies/features/standard/src/main/feature/feature.xml
+++ b/assemblies/features/standard/src/main/feature/feature.xml
@@ -250,7 +250,6 @@
<feature name="management" description="Provide a JMX MBeanServer and a set of MBeans in Karaf" version="${project.version}">
<feature version="${project.version}">jaas</feature>
- <feature version="${project.version}">aries-blueprint</feature>
<bundle dependency="true" start-level="20">mvn:org.apache.aries/org.apache.aries.util/${aries.util.version}</bundle>
<bundle start-level="30">mvn:org.apache.karaf.management/org.apache.karaf.management.server/${project.version}</bundle>
<bundle start-level="30">mvn:org.apache.aries.jmx/org.apache.aries.jmx.api/${aries.jmx.api.version}</bundle>
http://git-wip-us.apache.org/repos/asf/karaf/blob/3091414d/management/server/pom.xml
----------------------------------------------------------------------
diff --git a/management/server/pom.xml b/management/server/pom.xml
index 3147278..f4a873a 100644
--- a/management/server/pom.xml
+++ b/management/server/pom.xml
@@ -69,6 +69,17 @@
<artifactId>org.apache.karaf.service.guard</artifactId>
<scope>provided</scope>
</dependency>
+ <dependency>
+ <groupId>org.apache.karaf</groupId>
+ <artifactId>org.apache.karaf.util</artifactId>
+ <scope>provided</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-api</artifactId>
+ <scope>provided</scope>
+ </dependency>
<dependency>
<groupId>org.easymock</groupId>
@@ -103,8 +114,12 @@
<Export-Package>org.apache.karaf.management;version=${project.version};-split-package:=merge-first</Export-Package>
<Private-Package>
org.apache.karaf.management.internal,
- org.apache.karaf.service.guard.tools
+ org.apache.karaf.service.guard.tools,
+ org.apache.karaf.util.tracker
</Private-Package>
+ <Bundle-Activator>
+ org.apache.karaf.management.internal.Activator
+ </Bundle-Activator>
</instructions>
</configuration>
</plugin>
http://git-wip-us.apache.org/repos/asf/karaf/blob/3091414d/management/server/src/main/java/org/apache/karaf/management/internal/Activator.java
----------------------------------------------------------------------
diff --git a/management/server/src/main/java/org/apache/karaf/management/internal/Activator.java b/management/server/src/main/java/org/apache/karaf/management/internal/Activator.java
new file mode 100644
index 0000000..b9a6917
--- /dev/null
+++ b/management/server/src/main/java/org/apache/karaf/management/internal/Activator.java
@@ -0,0 +1,326 @@
+/*
+ * 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.karaf.management.internal;
+
+import java.util.ArrayList;
+import java.util.Dictionary;
+import java.util.HashMap;
+import java.util.Hashtable;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicBoolean;
+
+import javax.management.MBeanServer;
+import javax.management.NotCompliantMBeanException;
+import javax.management.ObjectName;
+
+import org.apache.karaf.jaas.config.KeystoreManager;
+import org.apache.karaf.management.ConnectorServerFactory;
+import org.apache.karaf.management.JaasAuthenticator;
+import org.apache.karaf.management.KarafMBeanServerGuard;
+import org.apache.karaf.management.MBeanServerFactory;
+import org.apache.karaf.management.RmiRegistryFactory;
+import org.apache.karaf.util.tracker.SingleServiceTracker;
+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.service.cm.ConfigurationException;
+import org.osgi.service.cm.ManagedService;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class Activator implements BundleActivator, ManagedService, SingleServiceTracker.SingleServiceListener {
+
+ private static final Logger LOGGER = LoggerFactory.getLogger(Activator.class);
+
+ private ExecutorService executor = Executors.newSingleThreadExecutor();
+ private AtomicBoolean scheduled = new AtomicBoolean();
+ private BundleContext bundleContext;
+ private Dictionary<String, ?> configuration;
+ private ServiceRegistration registration;
+ private SingleServiceTracker<ConfigurationAdmin> configAdminTracker;
+ private SingleServiceTracker<KeystoreManager> keystoreManagerTracker;
+ private ServiceRegistration<MBeanServer> serverRegistration;
+ private ServiceRegistration securityRegistration;
+ private ConnectorServerFactory connectorServerFactory;
+ private RmiRegistryFactory rmiRegistryFactory;
+ private MBeanServerFactory mbeanServerFactory;
+
+ @Override
+ public void start(BundleContext context) throws Exception {
+ bundleContext = context;
+ scheduled.set(true);
+
+ Hashtable<String, Object> props = new Hashtable<String, Object>();
+ props.put(Constants.SERVICE_PID, "org.apache.karaf.management");
+ registration = bundleContext.registerService(ManagedService.class, this, props);
+
+ configAdminTracker = new SingleServiceTracker<ConfigurationAdmin>(
+ bundleContext, ConfigurationAdmin.class, this);
+ keystoreManagerTracker = new SingleServiceTracker<KeystoreManager>(
+ bundleContext, KeystoreManager.class, this);
+ configAdminTracker.open();
+ keystoreManagerTracker.open();
+
+ scheduled.set(false);
+ reconfigure();
+ }
+
+ @Override
+ public void stop(BundleContext context) throws Exception {
+ keystoreManagerTracker.close();
+ configAdminTracker.close();
+ registration.unregister();
+ executor.shutdown();
+ executor.awaitTermination(30, TimeUnit.SECONDS);
+ }
+
+ @Override
+ public void updated(Dictionary<String, ?> properties) throws ConfigurationException {
+ this.configuration = properties;
+ reconfigure();
+ }
+
+ @Override
+ public void serviceFound() {
+ reconfigure();
+ }
+
+ @Override
+ public void serviceLost() {
+ reconfigure();
+ }
+
+ @Override
+ public void serviceReplaced() {
+ reconfigure();
+ }
+
+ protected void reconfigure() {
+ if (scheduled.compareAndSet(false, true)) {
+ executor.submit(new Runnable() {
+ @Override
+ public void run() {
+ scheduled.set(false);
+ doStop();
+ try {
+ doStart();
+ } catch (Exception e) {
+ LOGGER.warn("Error starting management layer", e);
+ doStop();
+ }
+ }
+ });
+ }
+ }
+
+ protected void doStart() throws Exception {
+ // This can happen while the bundle is starting as we register
+ // the ManagedService before creating the service trackers
+ if (configAdminTracker == null || keystoreManagerTracker == null) {
+ return;
+ }
+ // Verify dependencies
+ ConfigurationAdmin configurationAdmin = configAdminTracker.getService();
+ KeystoreManager keystoreManager = keystoreManagerTracker.getService();
+ Dictionary<String, ?> config = configuration;
+ if (configurationAdmin == null || keystoreManager == null) {
+ return;
+ }
+
+ String rmiRegistryHost = getString(config, "rmiRegistryHost", "");
+ int rmiRegistryPort = getInt(config, "rmiRegistryPort", 1099);
+ String rmiServerHost = getString(config, "rmiServerHost", "0.0.0.0");
+ int rmiServerPort = getInt(config, "rmiServerPort", 44444);
+
+ String jmxRealm = getString(config, "jmxRealm", "karaf");
+ String serviceUrl = getString(config, "serviceUrl",
+ "service:jmx:rmi://0.0.0.0:" + rmiServerPort + "/jndi/rmi://0.0.0.0:" + rmiRegistryPort + "/karaf-" + System.getProperty("karaf.name"));
+
+ boolean daemon = getBoolean(config, "daemon", true);
+ boolean threaded = getBoolean(config, "threaded", true);
+ ObjectName objectName = new ObjectName(getString(config, "objectName", "connector:name=rmi"));
+ long keyStoreAvailabilityTimeout = getLong(config, "keyStoreAvailabilityTimeout", 5000);
+ String authenticatorType = getString(config, "authenticatorType", "password");
+ boolean secured = getBoolean(config, "secured", false);
+ String secureAlgorithm = getString(config, "secureAlgorithm", "default");
+ String secureProtocol = getString(config, "secureProtocol", "TLS");
+ String keyStore = getString(config, "keyStore", "karaf.ks");
+ String keyAlias = getString(config, "keyAlias", "karaf");
+ String trustStore = getString(config, "trustStore", "karaf.ts");
+
+ KarafMBeanServerGuard guard = new KarafMBeanServerGuard();
+ guard.setConfigAdmin(configurationAdmin);
+ guard.init();
+
+ rmiRegistryFactory = new RmiRegistryFactory();
+ rmiRegistryFactory.setCreate(true);
+ rmiRegistryFactory.setLocate(true);
+ rmiRegistryFactory.setHost(rmiRegistryHost);
+ rmiRegistryFactory.setPort(rmiRegistryPort);
+ rmiRegistryFactory.setBundleContext(bundleContext);
+ rmiRegistryFactory.init();
+
+ mbeanServerFactory = new MBeanServerFactory();
+ mbeanServerFactory.setLocateExistingServerIfPossible(true);
+ mbeanServerFactory.init();
+
+ MBeanServer mbeanServer = mbeanServerFactory.getServer();
+
+ JaasAuthenticator jaasAuthenticator = new JaasAuthenticator();
+ jaasAuthenticator.setRealm(jmxRealm);
+
+ connectorServerFactory = new ConnectorServerFactory();
+ connectorServerFactory.setServer(mbeanServer);
+ connectorServerFactory.setServiceUrl(serviceUrl);
+ connectorServerFactory.setRmiServerHost(rmiServerHost);
+ connectorServerFactory.setDaemon(daemon);
+ connectorServerFactory.setThreaded(threaded);
+ connectorServerFactory.setObjectName(objectName);
+ Map<String, Object> environment = new HashMap<String, Object>();
+ environment.put("jmx.remote.authenticator", jaasAuthenticator);
+ connectorServerFactory.setEnvironment(environment);
+ connectorServerFactory.setKeyStoreAvailabilityTimeout(keyStoreAvailabilityTimeout);
+ connectorServerFactory.setAuthenticatorType(authenticatorType);
+ connectorServerFactory.setSecured(secured);
+ connectorServerFactory.setAlgorithm(secureAlgorithm);
+ connectorServerFactory.setSecureProtocol(secureProtocol);
+ connectorServerFactory.setKeyStore(keyStore);
+ connectorServerFactory.setKeyAlias(keyAlias);
+ connectorServerFactory.setTrustStore(trustStore);
+ connectorServerFactory.setKeystoreManager(keystoreManager);
+ connectorServerFactory.init();
+
+ try {
+ JMXSecurityMBeanImpl securityMBean = new JMXSecurityMBeanImpl();
+ securityMBean.setMBeanServer(mbeanServer);
+ Hashtable<String, Object> props = new Hashtable<String, Object>();
+ props.put("jmx.objectname", "org.apache.karaf:type=security,area=jmx,name=" + System.getProperty("karaf.name"));
+ securityRegistration = bundleContext.registerService(
+ getInterfaceNames(securityMBean),
+ securityMBean,
+ props
+ );
+ } catch (NotCompliantMBeanException e) {
+ LOGGER.warn("Error creating JMX security mbean", e);
+ }
+
+ serverRegistration = bundleContext.registerService(MBeanServer.class, mbeanServer, null);
+ }
+
+ protected void doStop() {
+ if (securityRegistration != null) {
+ securityRegistration.unregister();
+ securityRegistration = null;
+ }
+ if (serverRegistration != null) {
+ serverRegistration.unregister();
+ serverRegistration = null;
+ }
+ if (connectorServerFactory != null) {
+ try {
+ connectorServerFactory.destroy();
+ } catch (Exception e) {
+ LOGGER.warn("Error destroying ConnectorServerFactory", e);
+ }
+ connectorServerFactory = null;
+ }
+ if (mbeanServerFactory != null) {
+ try {
+ mbeanServerFactory.destroy();
+ } catch (Exception e) {
+ LOGGER.warn("Error destroying MBeanServerFactory", e);
+ }
+ mbeanServerFactory = null;
+ }
+ if (rmiRegistryFactory != null) {
+ try {
+ rmiRegistryFactory.destroy();
+ } catch (Exception e) {
+ LOGGER.warn("Error destroying RMIRegistryFactory", e);
+ }
+ rmiRegistryFactory = null;
+ }
+ }
+
+ private String[] getInterfaceNames(Object object) {
+ List<String> names = new ArrayList<String>();
+ for (Class cl = object.getClass(); cl != Object.class; cl = cl.getSuperclass()) {
+ addSuperInterfaces(names, cl);
+ }
+ return names.toArray(new String[names.size()]);
+ }
+
+ private void addSuperInterfaces(List<String> names, Class clazz) {
+ for (Class cl : clazz.getInterfaces()) {
+ names.add(cl.getName());
+ addSuperInterfaces(names, cl);
+ }
+ }
+
+ private int getInt(Dictionary<String, ?> config, String key, int def) {
+ if (config != null) {
+ Object val = config.get(key);
+ if (val instanceof Number) {
+ return ((Number) val).intValue();
+ } else if (val != null) {
+ return Integer.parseInt(val.toString());
+ }
+ }
+ return def;
+ }
+
+ private long getLong(Dictionary<String, ?> config, String key, long def) {
+ if (config != null) {
+ Object val = config.get(key);
+ if (val instanceof Number) {
+ return ((Number) val).longValue();
+ } else if (val != null) {
+ return Long.parseLong(val.toString());
+ }
+ }
+ return def;
+ }
+
+ private boolean getBoolean(Dictionary<String, ?> config, String key, boolean def) {
+ if (config != null) {
+ Object val = config.get(key);
+ if (val instanceof Boolean) {
+ return (Boolean) val;
+ } else if (val != null) {
+ return Boolean.parseBoolean(val.toString());
+ }
+ }
+ return def;
+ }
+
+ private String getString(Dictionary<String, ?> config, String key, String def) {
+ if (config != null) {
+ Object val = config.get(key);
+ if (val != null) {
+ return val.toString();
+ }
+ }
+ return def;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/karaf/blob/3091414d/management/server/src/main/resources/OSGI-INF/blueprint/karaf-management.xml
----------------------------------------------------------------------
diff --git a/management/server/src/main/resources/OSGI-INF/blueprint/karaf-management.xml b/management/server/src/main/resources/OSGI-INF/blueprint/karaf-management.xml
deleted file mode 100644
index 5795018..0000000
--- a/management/server/src/main/resources/OSGI-INF/blueprint/karaf-management.xml
+++ /dev/null
@@ -1,125 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
-
- Licensed to the Apache Software Foundation (ASF) under one or more
- contributor license agreements. See the NOTICE file distributed with
- this work for additional information regarding copyright ownership.
- The ASF licenses this file to You under the Apache License, Version 2.0
- (the "License"); you may not use this file except in compliance with
- the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
-
--->
-<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
- xmlns:cm="http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.1.0"
- xmlns:ext="http://aries.apache.org/blueprint/xmlns/blueprint-ext/v1.0.0"
- xmlns:jaas="http://karaf.apache.org/xmlns/jaas/v1.0.0">
-
- <!-- Allow the use of system properties -->
- <ext:property-placeholder placeholder-prefix="$[" placeholder-suffix="]" />
-
- <!-- Property place holder -->
- <cm:property-placeholder persistent-id="org.apache.karaf.management" update-strategy="reload">
- <cm:default-properties>
- <cm:property name="rmiRegistryHost" value=""/>
- <cm:property name="rmiRegistryPort" value="1099"/>
- <cm:property name="rmiServerHost" value="0.0.0.0"/>
- <cm:property name="rmiServerPort" value="44444"/>
- <cm:property name="jmxRealm" value="karaf"/>
- <cm:property name="serviceUrl" value="service:jmx:rmi://localhost:44444/jndi/rmi://localhost:1099/karaf-$[karaf.name]"/>
- <cm:property name="daemon" value="true"/>
- <cm:property name="threaded" value="true"/>
- <cm:property name="objectName" value="connector:name=rmi"/>
- <!-- SSL Support -->
- <cm:property name="keyStoreAvailabilityTimeout" value="5000" />
- <cm:property name="authenticatorType" value="password" />
- <cm:property name="secured" value="false" />
- <cm:property name="secureAlgorithm" value="default" />
- <cm:property name="secureProtocol" value="TLS" />
- <cm:property name="keyStore" value="karaf.ks"/>
- <cm:property name="keyAlias" value="karaf"/>
- <cm:property name="trustStore" value="karaf.ts"/>
- <cm:property name="clientAuth" value="false"/>
- </cm:default-properties>
- </cm:property-placeholder>
-
- <!-- MBeanServer bean -->
- <bean id="mbeanServerFactory" class="org.apache.karaf.management.MBeanServerFactory" init-method="init"
- destroy-method="destroy" depends-on="rmiRegistryFactory">
- <property name="locateExistingServerIfPossible" value="true"/>
- </bean>
- <bean id="mbeanServer" factory-ref="mbeanServerFactory" factory-method="getServer"/>
-
- <!-- Export the MBeanServer as an OSGi service -->
- <service ref="mbeanServer" interface="javax.management.MBeanServer"/>
-
- <!-- Create a RMI registry -->
- <bean id="rmiRegistryFactory" class="org.apache.karaf.management.RmiRegistryFactory" init-method="init"
- destroy-method="destroy">
- <property name="create" value="true"/>
- <property name="locate" value="true"/>
- <property name="host" value="${rmiRegistryHost}"/>
- <property name="port" value="${rmiRegistryPort}"/>
- <property name="bundleContext" ref="blueprintBundleContext"/>
- </bean>
-
- <!-- Create a JMX connector ServiceFactory -->
- <reference id="keystoreManager" interface="org.apache.karaf.jaas.config.KeystoreManager"/>
-
- <bean id="connectorFactory" class="org.apache.karaf.management.ConnectorServerFactory" init-method="init"
- destroy-method="destroy">
- <property name="server" ref="mbeanServer"/>
- <property name="serviceUrl" value="${serviceUrl}"/>
- <property name="rmiServerHost" value="${rmiServerHost}"/>
- <property name="daemon" value="${daemon}"/>
- <property name="threaded" value="${threaded}"/>
- <property name="objectName" value="${objectName}"/>
- <property name="environment">
- <map>
- <entry key="jmx.remote.authenticator" value-ref="jaasAuthenticator"/>
- </map>
- </property>
- <property name="keyStoreAvailabilityTimeout" value="${keyStoreAvailabilityTimeout}" />
- <property name="authenticatorType" value="${authenticatorType}" />
- <property name="secured" value="${secured}" />
- <property name="algorithm" value="${secureAlgorithm}" />
- <property name="secureProtocol" value="${secureProtocol}" />
- <property name="keyStore" value="${keyStore}"/>
- <property name="keyAlias" value="${keyAlias}"/>
- <property name="trustStore" value="${trustStore}"/>
- <property name="keystoreManager" ref="keystoreManager" />
- </bean>
-
- <!-- JAAS authenticator -->
- <bean id="jaasAuthenticator" class="org.apache.karaf.management.JaasAuthenticator">
- <property name="realm" value="${jmxRealm}"/>
- </bean>
-
- <!-- Get a reference to the ConfigurationAdmin service -->
- <reference id="configAdmin" interface="org.osgi.service.cm.ConfigurationAdmin" />
-
- <!-- For role-based security on the JMX API -->
- <bean id="karafMBeanServerGuard" class="org.apache.karaf.management.KarafMBeanServerGuard" init-method="init">
- <property name="configAdmin" ref="configAdmin" />
- </bean>
-
- <!-- JMX Security MBean -->
- <bean id="jmxSecurityMBean" class="org.apache.karaf.management.internal.JMXSecurityMBeanImpl">
- <property name="MBeanServer" ref="mbeanServer"/>
- </bean>
-
- <service ref="jmxSecurityMBean" auto-export="interfaces">
- <service-properties>
- <entry key="jmx.objectname" value="org.apache.karaf:type=security,area=jmx,name=$[karaf.name]" />
- </service-properties>
- </service>
-
-</blueprint>
-
[13/24] git commit: [KARAF-2833] Make diagnostic/core independent of
blueprint
Posted by gn...@apache.org.
[KARAF-2833] Make diagnostic/core independent of blueprint
Project: http://git-wip-us.apache.org/repos/asf/karaf/repo
Commit: http://git-wip-us.apache.org/repos/asf/karaf/commit/2a1815d3
Tree: http://git-wip-us.apache.org/repos/asf/karaf/tree/2a1815d3
Diff: http://git-wip-us.apache.org/repos/asf/karaf/diff/2a1815d3
Branch: refs/heads/master
Commit: 2a1815d333c168014a32135fa0e35f7dec5d7200
Parents: a1e5d4f
Author: Guillaume Nodet <gn...@gmail.com>
Authored: Sun Mar 23 14:44:53 2014 +0100
Committer: Guillaume Nodet <gn...@gmail.com>
Committed: Mon Mar 24 17:30:13 2014 +0100
----------------------------------------------------------------------
.../standard/src/main/feature/feature.xml | 1 -
diagnostic/core/pom.xml | 13 +-
.../core/internal/DiagnosticDumpMBeanImpl.java | 15 +--
.../core/internal/LogDumpProvider.java | 4 +-
.../core/internal/osgi/Activator.java | 131 +++++++++++++++++++
.../resources/OSGI-INF/blueprint/blueprint.xml | 70 ----------
6 files changed, 152 insertions(+), 82 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/karaf/blob/2a1815d3/assemblies/features/standard/src/main/feature/feature.xml
----------------------------------------------------------------------
diff --git a/assemblies/features/standard/src/main/feature/feature.xml b/assemblies/features/standard/src/main/feature/feature.xml
index 8df6409..9064d05 100644
--- a/assemblies/features/standard/src/main/feature/feature.xml
+++ b/assemblies/features/standard/src/main/feature/feature.xml
@@ -135,7 +135,6 @@
</feature>
<feature name="diagnostic" description="Provide Diagnostic support" version="${project.version}">
- <feature version="${project.version}">aries-blueprint</feature>
<bundle start-level="30" start="true">mvn:org.apache.karaf.diagnostic/org.apache.karaf.diagnostic.core/${project.version}</bundle>
<bundle start-level="30" start="true">mvn:org.apache.karaf.diagnostic/org.apache.karaf.diagnostic.command/${project.version}</bundle>
</feature>
http://git-wip-us.apache.org/repos/asf/karaf/blob/2a1815d3/diagnostic/core/pom.xml
----------------------------------------------------------------------
diff --git a/diagnostic/core/pom.xml b/diagnostic/core/pom.xml
index aa3054b..9a0ea67 100644
--- a/diagnostic/core/pom.xml
+++ b/diagnostic/core/pom.xml
@@ -51,6 +51,12 @@
</dependency>
<dependency>
+ <groupId>org.apache.karaf</groupId>
+ <artifactId>org.apache.karaf.util</artifactId>
+ <scope>provided</scope>
+ </dependency>
+
+ <dependency>
<groupId>org.apache.karaf.features</groupId>
<artifactId>org.apache.karaf.features.core</artifactId>
</dependency>
@@ -87,8 +93,13 @@
*
</Import-Package>
<Private-Package>
- org.apache.karaf.diagnostic.core.internal
+ org.apache.karaf.diagnostic.core.internal,
+ org.apache.karaf.diagnostic.core.internal.osgi,
+ org.apache.karaf.util.tracker
</Private-Package>
+ <Bundle-Activator>
+ org.apache.karaf.diagnostic.core.internal.osgi.Activator
+ </Bundle-Activator>
</instructions>
</configuration>
</plugin>
http://git-wip-us.apache.org/repos/asf/karaf/blob/2a1815d3/diagnostic/core/src/main/java/org/apache/karaf/diagnostic/core/internal/DiagnosticDumpMBeanImpl.java
----------------------------------------------------------------------
diff --git a/diagnostic/core/src/main/java/org/apache/karaf/diagnostic/core/internal/DiagnosticDumpMBeanImpl.java b/diagnostic/core/src/main/java/org/apache/karaf/diagnostic/core/internal/DiagnosticDumpMBeanImpl.java
index 5637e79..22e09c9 100644
--- a/diagnostic/core/src/main/java/org/apache/karaf/diagnostic/core/internal/DiagnosticDumpMBeanImpl.java
+++ b/diagnostic/core/src/main/java/org/apache/karaf/diagnostic/core/internal/DiagnosticDumpMBeanImpl.java
@@ -15,6 +15,7 @@ package org.apache.karaf.diagnostic.core.internal;
import java.io.File;
import java.util.List;
+import java.util.concurrent.CopyOnWriteArrayList;
import javax.management.MBeanException;
import javax.management.NotCompliantMBeanException;
@@ -34,7 +35,7 @@ public class DiagnosticDumpMBeanImpl extends StandardMBean implements Diagnostic
/**
* Dump providers.
*/
- private List<DumpProvider> providers;
+ private final List<DumpProvider> providers = new CopyOnWriteArrayList<DumpProvider>();
/**
* Creates new diagnostic mbean.
@@ -78,13 +79,11 @@ public class DiagnosticDumpMBeanImpl extends StandardMBean implements Diagnostic
}
}
- /**
- * Sets dump providers.
- *
- * @param providers Dump providers.
- */
- public void setProviders(List<DumpProvider> providers) {
- this.providers = providers;
+ public void registerProvider(DumpProvider provider) {
+ providers.add(provider);
}
+ public void unregisterProvider(DumpProvider provider) {
+ providers.add(provider);
+ }
}
http://git-wip-us.apache.org/repos/asf/karaf/blob/2a1815d3/diagnostic/core/src/main/java/org/apache/karaf/diagnostic/core/internal/LogDumpProvider.java
----------------------------------------------------------------------
diff --git a/diagnostic/core/src/main/java/org/apache/karaf/diagnostic/core/internal/LogDumpProvider.java b/diagnostic/core/src/main/java/org/apache/karaf/diagnostic/core/internal/LogDumpProvider.java
index 3d280f5..64b45f1 100644
--- a/diagnostic/core/src/main/java/org/apache/karaf/diagnostic/core/internal/LogDumpProvider.java
+++ b/diagnostic/core/src/main/java/org/apache/karaf/diagnostic/core/internal/LogDumpProvider.java
@@ -36,9 +36,9 @@ import org.osgi.service.cm.ConfigurationAdmin;
*/
public class LogDumpProvider implements DumpProvider {
- private BundleContext bundleContext;
+ private final BundleContext bundleContext;
- public void setBundleContext(BundleContext bundleContext) {
+ public LogDumpProvider(BundleContext bundleContext) {
this.bundleContext = bundleContext;
}
http://git-wip-us.apache.org/repos/asf/karaf/blob/2a1815d3/diagnostic/core/src/main/java/org/apache/karaf/diagnostic/core/internal/osgi/Activator.java
----------------------------------------------------------------------
diff --git a/diagnostic/core/src/main/java/org/apache/karaf/diagnostic/core/internal/osgi/Activator.java b/diagnostic/core/src/main/java/org/apache/karaf/diagnostic/core/internal/osgi/Activator.java
new file mode 100644
index 0000000..7a01daf
--- /dev/null
+++ b/diagnostic/core/src/main/java/org/apache/karaf/diagnostic/core/internal/osgi/Activator.java
@@ -0,0 +1,131 @@
+/*
+ * 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.karaf.diagnostic.core.internal.osgi;
+
+import java.util.ArrayList;
+import java.util.Hashtable;
+import java.util.List;
+
+import org.apache.karaf.diagnostic.core.DumpProvider;
+import org.apache.karaf.diagnostic.core.internal.BundleDumpProvider;
+import org.apache.karaf.diagnostic.core.internal.DiagnosticDumpMBeanImpl;
+import org.apache.karaf.diagnostic.core.internal.EnvironmentDumpProvider;
+import org.apache.karaf.diagnostic.core.internal.FeaturesDumpProvider;
+import org.apache.karaf.diagnostic.core.internal.HeapDumpProvider;
+import org.apache.karaf.diagnostic.core.internal.LogDumpProvider;
+import org.apache.karaf.diagnostic.core.internal.MemoryDumpProvider;
+import org.apache.karaf.diagnostic.core.internal.ThreadDumpProvider;
+import org.apache.karaf.features.FeaturesService;
+import org.apache.karaf.util.tracker.SingleServiceTracker;
+import org.osgi.framework.BundleActivator;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceReference;
+import org.osgi.framework.ServiceRegistration;
+import org.osgi.util.tracker.ServiceTracker;
+import org.osgi.util.tracker.ServiceTrackerCustomizer;
+
+public class Activator implements BundleActivator {
+
+ private List<ServiceRegistration<DumpProvider>> registrations;
+ private ServiceRegistration<DumpProvider> featuresProviderRegistration;
+ private ServiceRegistration mbeanRegistration;
+ private SingleServiceTracker<FeaturesService> featuresServiceTracker;
+ private ServiceTracker<DumpProvider, DumpProvider> providersTracker;
+
+ @Override
+ public void start(final BundleContext context) throws Exception {
+ registrations = new ArrayList<ServiceRegistration<DumpProvider>>();
+ registrations.add(context.registerService(DumpProvider.class, new BundleDumpProvider(context), null));
+ registrations.add(context.registerService(DumpProvider.class, new EnvironmentDumpProvider(context), null));
+ registrations.add(context.registerService(DumpProvider.class, new HeapDumpProvider(), null));
+ registrations.add(context.registerService(DumpProvider.class, new LogDumpProvider(context), null));
+ registrations.add(context.registerService(DumpProvider.class, new MemoryDumpProvider(), null));
+ registrations.add(context.registerService(DumpProvider.class, new ThreadDumpProvider(), null));
+
+ featuresServiceTracker = new SingleServiceTracker<FeaturesService>(context, FeaturesService.class, new SingleServiceTracker.SingleServiceListener() {
+ @Override
+ public void serviceFound() {
+ featuresProviderRegistration =
+ context.registerService(
+ DumpProvider.class,
+ new FeaturesDumpProvider(featuresServiceTracker.getService()),
+ null);
+ }
+ @Override
+ public void serviceLost() {
+ }
+ @Override
+ public void serviceReplaced() {
+ featuresProviderRegistration.unregister();
+ }
+ });
+
+ final DiagnosticDumpMBeanImpl diagnostic = new DiagnosticDumpMBeanImpl();
+ providersTracker = new ServiceTracker<DumpProvider, DumpProvider>(
+ context, DumpProvider.class, new ServiceTrackerCustomizer<DumpProvider, DumpProvider>() {
+ @Override
+ public DumpProvider addingService(ServiceReference<DumpProvider> reference) {
+ DumpProvider service = context.getService(reference);
+ diagnostic.registerProvider(service);
+ return service;
+ }
+ @Override
+ public void modifiedService(ServiceReference<DumpProvider> reference, DumpProvider service) {
+ }
+ @Override
+ public void removedService(ServiceReference<DumpProvider> reference, DumpProvider service) {
+ diagnostic.unregisterProvider(service);
+ context.ungetService(reference);
+ }
+ });
+ providersTracker.open();
+
+ Hashtable<String, Object> props = new Hashtable<String, Object>();
+ props.put("jmx.objectname", "org.apache.karaf:type=diagnostic,name=" + System.getProperty("karaf.name"));
+ mbeanRegistration = context.registerService(
+ getInterfaceNames(diagnostic),
+ diagnostic,
+ props
+ );
+ }
+
+ @Override
+ public void stop(BundleContext context) throws Exception {
+ mbeanRegistration.unregister();
+ featuresServiceTracker.close();
+ providersTracker.close();
+ for (ServiceRegistration<DumpProvider> reg : registrations) {
+ reg.unregister();
+ }
+ }
+
+ private String[] getInterfaceNames(Object object) {
+ List<String> names = new ArrayList<String>();
+ for (Class cl = object.getClass(); cl != Object.class; cl = cl.getSuperclass()) {
+ addSuperInterfaces(names, cl);
+ }
+ return names.toArray(new String[names.size()]);
+ }
+
+ private void addSuperInterfaces(List<String> names, Class clazz) {
+ for (Class cl : clazz.getInterfaces()) {
+ names.add(cl.getName());
+ addSuperInterfaces(names, cl);
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/karaf/blob/2a1815d3/diagnostic/core/src/main/resources/OSGI-INF/blueprint/blueprint.xml
----------------------------------------------------------------------
diff --git a/diagnostic/core/src/main/resources/OSGI-INF/blueprint/blueprint.xml b/diagnostic/core/src/main/resources/OSGI-INF/blueprint/blueprint.xml
deleted file mode 100644
index 46a3cf4..0000000
--- a/diagnostic/core/src/main/resources/OSGI-INF/blueprint/blueprint.xml
+++ /dev/null
@@ -1,70 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
-
- Licensed to the Apache Software Foundation (ASF) under one or more
- contributor license agreements. See the NOTICE file distributed with
- this work for additional information regarding copyright ownership.
- The ASF licenses this file to You under the Apache License, Version 2.0
- (the "License"); you may not use this file except in compliance with
- the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
-
--->
-<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
- xmlns:cm="http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.1.0"
- xmlns:ext="http://aries.apache.org/blueprint/xmlns/blueprint-ext/v1.0.0">
-
- <ext:property-placeholder />
-
- <bean id="features" class="org.apache.karaf.diagnostic.core.internal.FeaturesDumpProvider">
- <argument>
- <reference interface="org.apache.karaf.features.FeaturesService"
- availability="optional" />
- </argument>
- </bean>
- <service ref="features" auto-export="interfaces" />
-
- <bean id="logs" class="org.apache.karaf.diagnostic.core.internal.LogDumpProvider">
- <property name="bundleContext" ref="blueprintBundleContext"/>
- </bean>
- <service ref="logs" auto-export="interfaces" />
-
- <bean id="bundles" class="org.apache.karaf.diagnostic.core.internal.BundleDumpProvider">
- <argument ref="blueprintBundleContext" />
- </bean>
- <service ref="bundles" auto-export="interfaces" />
-
- <bean id="threads" class="org.apache.karaf.diagnostic.core.internal.ThreadDumpProvider" />
- <service ref="threads" auto-export="interfaces" />
-
- <bean id="memory" class="org.apache.karaf.diagnostic.core.internal.MemoryDumpProvider" />
- <service ref="memory" auto-export="interfaces" />
-
- <bean id="heap" class="org.apache.karaf.diagnostic.core.internal.HeapDumpProvider" />
- <service ref="heap" auto-export="interfaces" />
-
- <reference-list id="providers" availability="optional"
- interface="org.apache.karaf.diagnostic.core.DumpProvider" />
-
- <bean id="diagnosticDumpMBean" class="org.apache.karaf.diagnostic.core.internal.DiagnosticDumpMBeanImpl">
- <property name="providers" ref="providers" />
- </bean>
-
- <service ref="diagnosticDumpMBean" auto-export="interfaces">
- <service-properties>
- <entry key="jmx.objectname" value="org.apache.karaf:type=diagnostic,name=${karaf.name}"/>
- </service-properties>
- </service>
-
- <bean id="environment" class="org.apache.karaf.diagnostic.core.internal.EnvironmentDumpProvider" >
- <argument ref="blueprintBundleContext" />
- </bean>
- <service ref="environment" auto-export="interfaces" />
-</blueprint>