[KARAF-6051] Add command/operation to get the list of features provided by a features... 18/head
authorJean-Baptiste Onofré <jbonofre@apache.org>
Fri, 11 Jan 2019 15:00:06 +0000 (16:00 +0100)
committerJean-Baptiste Onofré <jbonofre@apache.org>
Fri, 11 Jan 2019 15:00:06 +0000 (16:00 +0100)
deployer/api/src/main/java/org/apache/karaf/cave/deployer/api/Deployer.java
deployer/command/src/main/java/org/apache/karaf/cave/deployer/command/FeaturesRepositoryProvideCommand.java [new file with mode: 0644]
deployer/management/src/main/java/org/apache/karaf/cave/deployer/management/CaveDeployerMBean.java
deployer/management/src/main/java/org/apache/karaf/cave/deployer/management/internal/CaveDeployerMBeanImpl.java
deployer/service/pom.xml
deployer/service/src/main/java/org/apache/karaf/cave/deployer/service/impl/DeployerImpl.java
pom.xml

index 7ca7cf8..30bb740 100644 (file)
@@ -138,6 +138,11 @@ public interface Deployer {
     List<String> kars(String connection) throws Exception;
 
     /**
+     * Return the list of features provided by a features repository.
+     */
+    List<Feature> providedFeatures(String featuresRepositoryUrl) throws Exception;
+
+    /**
      * Simple remote operation to add a features repository to a remote Karaf instance.
      */
     void addFeaturesRepository(String featuresRepositoryUrl, String connection) throws Exception;
diff --git a/deployer/command/src/main/java/org/apache/karaf/cave/deployer/command/FeaturesRepositoryProvideCommand.java b/deployer/command/src/main/java/org/apache/karaf/cave/deployer/command/FeaturesRepositoryProvideCommand.java
new file mode 100644 (file)
index 0000000..10107a5
--- /dev/null
@@ -0,0 +1,53 @@
+/*
+ * 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.cave.deployer.command;
+
+import org.apache.karaf.cave.deployer.api.Deployer;
+import org.apache.karaf.cave.deployer.api.Feature;
+import org.apache.karaf.shell.api.action.Action;
+import org.apache.karaf.shell.api.action.Argument;
+import org.apache.karaf.shell.api.action.Command;
+import org.apache.karaf.shell.api.action.lifecycle.Reference;
+import org.apache.karaf.shell.api.action.lifecycle.Service;
+import org.apache.karaf.shell.support.table.ShellTable;
+
+import java.util.List;
+
+@Service
+@Command(scope = "cave", name = "deployer-features-repo-provide", description = "List the features provided by a given features repository")
+public class FeaturesRepositoryProvideCommand implements Action {
+
+    @Reference
+    private Deployer deployer;
+
+    @Argument(index = 0, name = "featuresRepositoryUrl", description = "The location")
+    String featuresRepositoryUrl;
+
+    @Override
+    public Object execute() throws Exception {
+        List<Feature> features = deployer.providedFeatures(featuresRepositoryUrl);
+        ShellTable table = new ShellTable();
+        table.column("Name");
+        table.column("Version");
+        for (Feature feature : features) {
+            table.addRow().addContent(feature.getName(), feature.getVersion());
+        }
+        table.print(System.out);
+        return null;
+    }
+
+}
index 3a457b3..b96b7be 100644 (file)
@@ -45,6 +45,7 @@ public interface CaveDeployerMBean {
     void removeFeatureRepository(String repository, String connection) throws Exception;
     TabularData getFeatureRepositories(String connection) throws Exception;
 
+    TabularData getProvidedFeatures(String featuresRepositoryUrl) throws Exception;
     void installFeature(String feature, String connection) throws Exception;
     void uninstallFeature(String feature, String connection) throws Exception;
     TabularData getFeatures(String connection) throws Exception;
index b9f2b07..a9410fd 100644 (file)
@@ -187,6 +187,26 @@ public class CaveDeployerMBeanImpl extends StandardMBean implements CaveDeployer
     }
 
     @Override
+    public TabularData getProvidedFeatures(String featuresRepositoryUrl) throws Exception {
+        List<Feature> features = deployer.providedFeatures(featuresRepositoryUrl);
+
+        CompositeType featureType = new CompositeType("Feature", "Feature",
+                new String[]{ "Name", "Version" },
+                new String[]{ "The feature name", "The feature version" },
+                new OpenType[]{SimpleType.STRING, SimpleType.STRING});
+        TabularType tableType = new TabularType("Provided Features", "Table of provided features by a repository", featureType, new String[]{ "Name", "Version"});
+        TabularData table = new TabularDataSupport(tableType);
+
+        for (Feature feature : features) {
+            CompositeData data = new CompositeDataSupport(featureType,
+                    new String[]{"Name", "Version"},
+                    new Object[]{feature.getName(), feature.getVersion()});
+            table.put(data);
+        }
+        return table;
+    }
+
+    @Override
     public void installFeature(String feature, String connection) throws Exception {
         deployer.installFeature(feature, connection);
     }
index 0ca25a6..103df6f 100644 (file)
         <dependency>
             <groupId>org.apache.karaf.features</groupId>
             <artifactId>org.apache.karaf.features.core</artifactId>
-            <version>4.0.2</version>
+            <version>${karaf.version}</version>
         </dependency>
 
         <!-- Logging -->
                             org.apache.karaf.cave.deployer.service.impl,
                             org.apache.karaf.features.internal.model,
                             org.apache.felix.utils.version,
+                            org.apache.felix.utils.properties,
                             org.apache.karaf.util
                         </Private-Package>
                         <Embed-Dependency>
index db4c62c..38981f8 100644 (file)
@@ -558,6 +558,18 @@ public class DeployerImpl implements Deployer {
         }
     }
 
+    public List<org.apache.karaf.cave.deployer.api.Feature> providedFeatures(String featureRepositoryUrl) throws Exception {
+        Features features = JaxbUtil.unmarshal(featureRepositoryUrl, true);
+        List<org.apache.karaf.cave.deployer.api.Feature> wrappedFeatures = new ArrayList<>();
+        for (Feature feature : features.getFeature()) {
+            org.apache.karaf.cave.deployer.api.Feature wrappedFeature = new org.apache.karaf.cave.deployer.api.Feature();
+            wrappedFeature.setName(feature.getName());
+            wrappedFeature.setVersion(feature.getVersion());
+            wrappedFeatures.add(wrappedFeature);
+        }
+        return wrappedFeatures;
+    }
+
     @Override
     public void addFeaturesRepository(String artifactUrl, String connectionName) throws Exception {
         Connection connection = getConnection(connectionName);
diff --git a/pom.xml b/pom.xml
index 2a72789..deefe5e 100644 (file)
--- a/pom.xml
+++ b/pom.xml
@@ -39,7 +39,7 @@
         <cxf.version>3.1.6</cxf.version>
         <httpclient.version>4.3.4</httpclient.version>
         <jsoup.version>1.7.3</jsoup.version>
-        <karaf.version>4.1.6</karaf.version>
+        <karaf.version>4.1.7</karaf.version>
         <osgi.version>6.0.0</osgi.version>
         <commons-codec.version>1.10</commons-codec.version>
         <wagon.version>1.0</wagon.version>