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:07 UTC

[09/24] git commit: [KARAF-2833] Make shell/commands independent of blueprint

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