servicemix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ccust...@apache.org
Subject svn commit: r751597 - in /servicemix/smx4/kernel/trunk/gshell/gshell-features/src/main: java/org/apache/servicemix/kernel/gshell/features/completers/ java/org/apache/servicemix/kernel/gshell/features/management/ resources/META-INF/spring/
Date Mon, 09 Mar 2009 06:21:43 GMT
Author: ccustine
Date: Mon Mar  9 06:21:39 2009
New Revision: 751597

URL: http://svn.apache.org/viewvc?rev=751597&view=rev
Log:
SMX4KNL-233 - Add argument completion for core gshell commands

Added:
    servicemix/smx4/kernel/trunk/gshell/gshell-features/src/main/java/org/apache/servicemix/kernel/gshell/features/completers/
    servicemix/smx4/kernel/trunk/gshell/gshell-features/src/main/java/org/apache/servicemix/kernel/gshell/features/completers/AvailableFeatureCompleter.java
  (contents, props changed)
      - copied, changed from r751373, servicemix/smx4/kernel/trunk/gshell/gshell-features/src/main/java/org/apache/servicemix/kernel/gshell/features/commands/FeaturesCommandSupport.java
    servicemix/smx4/kernel/trunk/gshell/gshell-features/src/main/java/org/apache/servicemix/kernel/gshell/features/completers/FeatureRepositoryCompleter.java
    servicemix/smx4/kernel/trunk/gshell/gshell-features/src/main/java/org/apache/servicemix/kernel/gshell/features/completers/InstalledFeatureCompleter.java
Modified:
    servicemix/smx4/kernel/trunk/gshell/gshell-features/src/main/java/org/apache/servicemix/kernel/gshell/features/management/ManagedFeaturesRegistry.java
    servicemix/smx4/kernel/trunk/gshell/gshell-features/src/main/resources/META-INF/spring/gshell-features.xml

Copied: servicemix/smx4/kernel/trunk/gshell/gshell-features/src/main/java/org/apache/servicemix/kernel/gshell/features/completers/AvailableFeatureCompleter.java
(from r751373, servicemix/smx4/kernel/trunk/gshell/gshell-features/src/main/java/org/apache/servicemix/kernel/gshell/features/commands/FeaturesCommandSupport.java)
URL: http://svn.apache.org/viewvc/servicemix/smx4/kernel/trunk/gshell/gshell-features/src/main/java/org/apache/servicemix/kernel/gshell/features/completers/AvailableFeatureCompleter.java?p2=servicemix/smx4/kernel/trunk/gshell/gshell-features/src/main/java/org/apache/servicemix/kernel/gshell/features/completers/AvailableFeatureCompleter.java&p1=servicemix/smx4/kernel/trunk/gshell/gshell-features/src/main/java/org/apache/servicemix/kernel/gshell/features/commands/FeaturesCommandSupport.java&r1=751373&r2=751597&rev=751597&view=diff
==============================================================================
--- servicemix/smx4/kernel/trunk/gshell/gshell-features/src/main/java/org/apache/servicemix/kernel/gshell/features/commands/FeaturesCommandSupport.java
(original)
+++ servicemix/smx4/kernel/trunk/gshell/gshell-features/src/main/java/org/apache/servicemix/kernel/gshell/features/completers/AvailableFeatureCompleter.java
Mon Mar  9 06:21:39 2009
@@ -14,36 +14,47 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.apache.servicemix.kernel.gshell.features.commands;
+package org.apache.servicemix.kernel.gshell.features.completers;
+
+import java.util.List;
+import java.util.Set;
+import java.util.Collection;
 
 import org.apache.servicemix.kernel.gshell.core.OsgiCommandSupport;
 import org.apache.servicemix.kernel.gshell.features.FeaturesService;
+import org.apache.servicemix.kernel.gshell.features.management.ManagedFeaturesRegistry;
+import org.apache.servicemix.kernel.gshell.features.management.ManagedFeature;
+import org.apache.geronimo.gshell.console.completer.StringsCompleter;
 import org.osgi.framework.ServiceReference;
+import jline.Completor;
 
-public abstract class FeaturesCommandSupport extends OsgiCommandSupport {
+/**
+ * {@link jline.Completor} for available features.
+ *
+ * Displays a list of available features from installed repositories.
+ *
+ */
+public class AvailableFeatureCompleter implements Completor {
 
-    protected Object doExecute() throws Exception {
-        // Get repository admin service.
-        ServiceReference ref = getBundleContext().getServiceReference(FeaturesService.class.getName());
-        if (ref == null) {
-            io.out.println("FeaturesService service is unavailable.");
-            return null;
-        }
-        try {
-            FeaturesService admin = (FeaturesService) getBundleContext().getService(ref);
-            if (admin == null) {
-                io.out.println("FeaturesService service is unavailable.");
-                return null;
-            }
+    private ManagedFeaturesRegistry featuresRegistry;
+    private StringsCompleter delegate;
 
-            doExecute(admin);
-        }
-        finally {
-            getBundleContext().ungetService(ref);
+    public void setFeaturesRegistry(ManagedFeaturesRegistry featuresRegistry) {
+        this.featuresRegistry = featuresRegistry;
+    }
+
+    @Override
+    public int complete(final String buffer, final int cursor, final List candidates) {
+
+        Collection<ManagedFeature> features = featuresRegistry.getAvailableFeatures().values();
+        delegate = new StringsCompleter();
+
+        for (ManagedFeature feature : features) {
+            delegate.getStrings().add(feature.getName());
         }
-        return null;
+        
+        return delegate.complete(buffer, cursor, candidates);
     }
 
-    protected abstract void doExecute(FeaturesService admin) throws Exception;
 
-}
+}
\ No newline at end of file

Propchange: servicemix/smx4/kernel/trunk/gshell/gshell-features/src/main/java/org/apache/servicemix/kernel/gshell/features/completers/AvailableFeatureCompleter.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: servicemix/smx4/kernel/trunk/gshell/gshell-features/src/main/java/org/apache/servicemix/kernel/gshell/features/completers/FeatureRepositoryCompleter.java
URL: http://svn.apache.org/viewvc/servicemix/smx4/kernel/trunk/gshell/gshell-features/src/main/java/org/apache/servicemix/kernel/gshell/features/completers/FeatureRepositoryCompleter.java?rev=751597&view=auto
==============================================================================
--- servicemix/smx4/kernel/trunk/gshell/gshell-features/src/main/java/org/apache/servicemix/kernel/gshell/features/completers/FeatureRepositoryCompleter.java
(added)
+++ servicemix/smx4/kernel/trunk/gshell/gshell-features/src/main/java/org/apache/servicemix/kernel/gshell/features/completers/FeatureRepositoryCompleter.java
Mon Mar  9 06:21:39 2009
@@ -0,0 +1,52 @@
+/*
+ * 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.servicemix.kernel.gshell.features.completers;
+
+import java.util.List;
+import java.util.Collection;
+
+import org.apache.servicemix.kernel.gshell.core.OsgiCommandSupport;
+import org.apache.servicemix.kernel.gshell.features.FeaturesService;
+import org.apache.servicemix.kernel.gshell.features.management.ManagedFeaturesRegistry;
+import org.apache.servicemix.kernel.gshell.features.management.ManagedFeature;
+import org.apache.geronimo.gshell.console.completer.StringsCompleter;
+import org.osgi.framework.ServiceReference;
+import jline.Completor;
+
+/**
+ * {@link jline.Completor} for Feature Repository URLs.
+ *
+ * Displays a list of currently installed Feature repositories.
+ *
+ */
+
+public class FeatureRepositoryCompleter implements Completor {
+
+    private ManagedFeaturesRegistry featuresRegistry;
+
+    public void setFeaturesRegistry(ManagedFeaturesRegistry featuresRegistry) {
+        this.featuresRegistry = featuresRegistry;
+    }
+
+    @Override
+    public int complete(final String buffer, final int cursor, final List candidates) {
+        StringsCompleter delegate = new StringsCompleter(featuresRegistry.getRepositories().keySet());
+        return delegate.complete(buffer, cursor, candidates);
+    }
+
+
+}
\ No newline at end of file

Added: servicemix/smx4/kernel/trunk/gshell/gshell-features/src/main/java/org/apache/servicemix/kernel/gshell/features/completers/InstalledFeatureCompleter.java
URL: http://svn.apache.org/viewvc/servicemix/smx4/kernel/trunk/gshell/gshell-features/src/main/java/org/apache/servicemix/kernel/gshell/features/completers/InstalledFeatureCompleter.java?rev=751597&view=auto
==============================================================================
--- servicemix/smx4/kernel/trunk/gshell/gshell-features/src/main/java/org/apache/servicemix/kernel/gshell/features/completers/InstalledFeatureCompleter.java
(added)
+++ servicemix/smx4/kernel/trunk/gshell/gshell-features/src/main/java/org/apache/servicemix/kernel/gshell/features/completers/InstalledFeatureCompleter.java
Mon Mar  9 06:21:39 2009
@@ -0,0 +1,58 @@
+/*
+ * 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.servicemix.kernel.gshell.features.completers;
+
+import java.util.List;
+import java.util.Collection;
+
+import org.apache.servicemix.kernel.gshell.core.OsgiCommandSupport;
+import org.apache.servicemix.kernel.gshell.features.FeaturesService;
+import org.apache.servicemix.kernel.gshell.features.management.ManagedFeaturesRegistry;
+import org.apache.servicemix.kernel.gshell.features.management.ManagedFeature;
+import org.apache.geronimo.gshell.console.completer.StringsCompleter;
+import org.osgi.framework.ServiceReference;
+import jline.Completor;
+
+/**
+ * {@link jline.Completor} for installed features.
+ *
+ * Displays a list of currently installed features.
+ *
+ */
+public class InstalledFeatureCompleter implements Completor {
+
+    private ManagedFeaturesRegistry featuresRegistry;
+    private StringsCompleter delegate;
+
+    public void setFeaturesRegistry(ManagedFeaturesRegistry featuresRegistry) {
+        this.featuresRegistry = featuresRegistry;
+    }
+
+    @Override
+    public int complete(final String buffer, final int cursor, final List candidates) {
+        Collection<ManagedFeature> features = featuresRegistry.getInstalledFeatures().values();
+        delegate = new StringsCompleter();
+
+        for (ManagedFeature feature : features) {
+            delegate.getStrings().add(feature.getName());
+        }
+
+        return delegate.complete(buffer, cursor, candidates);
+    }
+
+
+}
\ No newline at end of file

Modified: servicemix/smx4/kernel/trunk/gshell/gshell-features/src/main/java/org/apache/servicemix/kernel/gshell/features/management/ManagedFeaturesRegistry.java
URL: http://svn.apache.org/viewvc/servicemix/smx4/kernel/trunk/gshell/gshell-features/src/main/java/org/apache/servicemix/kernel/gshell/features/management/ManagedFeaturesRegistry.java?rev=751597&r1=751596&r2=751597&view=diff
==============================================================================
--- servicemix/smx4/kernel/trunk/gshell/gshell-features/src/main/java/org/apache/servicemix/kernel/gshell/features/management/ManagedFeaturesRegistry.java
(original)
+++ servicemix/smx4/kernel/trunk/gshell/gshell-features/src/main/java/org/apache/servicemix/kernel/gshell/features/management/ManagedFeaturesRegistry.java
Mon Mar  9 06:21:39 2009
@@ -70,6 +70,18 @@
         repositories = new ConcurrentHashMap<String, ManagedRepository>();
     }
 
+    public Map<String, ManagedFeature> getAvailableFeatures() {
+        return availableFeatures;
+    }
+
+    public Map<String, ManagedFeature> getInstalledFeatures() {
+        return installedFeatures;
+    }
+
+    public Map<String, ManagedRepository> getRepositories() {
+        return repositories;
+    }
+
     public void setFeaturesService(FeaturesService featuresService) {
         this.featuresService = featuresService;
     }

Modified: servicemix/smx4/kernel/trunk/gshell/gshell-features/src/main/resources/META-INF/spring/gshell-features.xml
URL: http://svn.apache.org/viewvc/servicemix/smx4/kernel/trunk/gshell/gshell-features/src/main/resources/META-INF/spring/gshell-features.xml?rev=751597&r1=751596&r2=751597&view=diff
==============================================================================
--- servicemix/smx4/kernel/trunk/gshell/gshell-features/src/main/resources/META-INF/spring/gshell-features.xml
(original)
+++ servicemix/smx4/kernel/trunk/gshell/gshell-features/src/main/resources/META-INF/spring/gshell-features.xml
Mon Mar  9 06:21:39 2009
@@ -49,15 +49,24 @@
         </gshell:command>
         <gshell:command name="features/removeUrl">
             <gshell:action class="org.apache.servicemix.kernel.gshell.features.commands.RemoveUrlCommand"
/>
+            <gshell:completers>
+                <ref bean="removeUrlCompleter" />
+            </gshell:completers>
         </gshell:command>
         <gshell:command name="features/refreshUrl">
             <gshell:action class="org.apache.servicemix.kernel.gshell.features.commands.RefreshUrlCommand"
/>
         </gshell:command>
         <gshell:command name="features/install">
             <gshell:action class="org.apache.servicemix.kernel.gshell.features.commands.InstallFeatureCommand"
/>
+            <gshell:completers>
+                <ref bean="installFeatureCompleter" /> 
+            </gshell:completers>
         </gshell:command>
         <gshell:command name="features/uninstall">
             <gshell:action class="org.apache.servicemix.kernel.gshell.features.commands.UninstallFeatureCommand"
/>
+            <gshell:completers>
+                <ref bean="uninstallFeatureCompleter" />
+            </gshell:completers>
         </gshell:command>
         <gshell:command name="features/list">
             <gshell:action class="org.apache.servicemix.kernel.gshell.features.commands.ListFeaturesCommand"
/>
@@ -111,4 +120,16 @@
         <osgi:listener ref="featureServiceRegistry" bind-method="registerMBeanServer"
/>
     </osgi:reference>
 
+    <bean id="installFeatureCompleter" class="org.apache.servicemix.kernel.gshell.features.completers.AvailableFeatureCompleter">
+        <property name="featuresRegistry" ref="featureServiceRegistry" />
+    </bean>
+
+    <bean id="uninstallFeatureCompleter" class="org.apache.servicemix.kernel.gshell.features.completers.InstalledFeatureCompleter">
+        <property name="featuresRegistry" ref="featureServiceRegistry" />
+    </bean>
+
+    <bean id="removeUrlCompleter" class="org.apache.servicemix.kernel.gshell.features.completers.FeatureRepositoryCompleter">
+        <property name="featuresRegistry" ref="featureServiceRegistry" />
+    </bean>
+
 </beans>
\ No newline at end of file



Mime
View raw message