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:32:17 UTC

[19/24] git commit: [KARAF-2833] Make package/core independent of blueprint

[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>