You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@karaf.apache.org by gg...@apache.org on 2017/12/06 19:03:50 UTC

[karaf] 02/17: [KARAF-5376] Include new Features JAXB model info in feature:* commands

This is an automated email from the ASF dual-hosted git repository.

ggrzybek pushed a commit to branch KARAF-5376-overrides_v2
in repository https://gitbox.apache.org/repos/asf/karaf.git

commit 752d50016b19fa0624c83ccc29a4fade3e47ab23
Author: Grzegorz Grzybek <gr...@gmail.com>
AuthorDate: Mon Nov 6 13:24:22 2017 +0100

    [KARAF-5376] Include new Features JAXB model info in feature:* commands
---
 .../karaf/features/command/InfoFeatureCommand.java |  3 +++
 .../features/command/ListFeaturesCommand.java      | 17 +++++++++++++++-
 .../karaf/features/command/RepoListCommand.java    | 23 +++++++++++++++++-----
 .../internal/service/RepositoryCacheImpl.java      |  2 ++
 .../features/internal/service/RepositoryImpl.java  |  6 ++++++
 5 files changed, 45 insertions(+), 6 deletions(-)

diff --git a/features/command/src/main/java/org/apache/karaf/features/command/InfoFeatureCommand.java b/features/command/src/main/java/org/apache/karaf/features/command/InfoFeatureCommand.java
index 1ecc0a0..7c6a775 100644
--- a/features/command/src/main/java/org/apache/karaf/features/command/InfoFeatureCommand.java
+++ b/features/command/src/main/java/org/apache/karaf/features/command/InfoFeatureCommand.java
@@ -209,6 +209,9 @@ public class InfoFeatureCommand extends FeaturesCommandSupport {
                 if(startLevel > 0) {
                     sb.append(" start-level=").append(startLevel);
                 }
+                if (featureBundle.isOverriden()) {
+                    sb.append(" (overriden from " + featureBundle.getOriginalLocation() + ")");
+                }
                 System.out.println(sb.toString());
             }
         }
diff --git a/features/command/src/main/java/org/apache/karaf/features/command/ListFeaturesCommand.java b/features/command/src/main/java/org/apache/karaf/features/command/ListFeaturesCommand.java
index 6bf9f9c..9e17153 100644
--- a/features/command/src/main/java/org/apache/karaf/features/command/ListFeaturesCommand.java
+++ b/features/command/src/main/java/org/apache/karaf/features/command/ListFeaturesCommand.java
@@ -27,6 +27,7 @@ import org.apache.karaf.features.Repository;
 import org.apache.karaf.shell.api.action.Command;
 import org.apache.karaf.shell.api.action.Option;
 import org.apache.karaf.shell.api.action.lifecycle.Service;
+import org.apache.karaf.shell.support.table.Row;
 import org.apache.karaf.shell.support.table.ShellTable;
 
 @Command(scope = "feature", name = "list", description = "Lists all existing features available from the defined repositories.")
@@ -42,6 +43,9 @@ public class ListFeaturesCommand extends FeaturesCommandSupport {
     @Option(name = "-s", aliases = {"--show-hidden"}, description = "Display hidden features", required = false, multiValued = false)
     boolean showHidden;
 
+    @Option(name = "-b", aliases = {"--show-blacklisted"}, description = "Display blacklisted features", required = false, multiValued = false)
+    boolean showBlacklisted;
+
     @Option(name = "-o", aliases = {"--ordered"}, description = "Display a list using alphabetical order ", required = false, multiValued = false)
     boolean ordered;
 
@@ -58,6 +62,9 @@ public class ListFeaturesCommand extends FeaturesCommandSupport {
         table.column("State");
         table.column("Repository");
         table.column("Description").maxSize(50);
+        if (showBlacklisted) {
+            table.column("Blacklisted");
+        }
         table.emptyTableText(onlyInstalled ? "No features installed" : "No features available");
 
         List<Repository> repos = Arrays.asList(featuresService.listRepositories());
@@ -75,17 +82,25 @@ public class ListFeaturesCommand extends FeaturesCommandSupport {
                     // Filter out not installed features if we only want to see the installed ones
                     continue;
                 }
+                if (!showBlacklisted && f.isBlacklisted()) {
+                    // Filter out blacklisted
+                    continue;
+                }
                 if (!showHidden && f.isHidden()) {
                     // Filter out hidden feature if not asked to display those
                     continue;
                 }
-                table.addRow().addContent(
+                Row row = table.addRow();
+                row.addContent(
                         f.getName(),
                         f.getVersion(),
                         featuresService.isRequired(f) ? "x" : "",
                         featuresService.getState(f.getId()),
                         r.getName(),
                         f.getDescription());
+                if (showBlacklisted) {
+                    row.addContent(f.isBlacklisted() ? "yes" : "no");
+                }
                 if (isInstalledViaDeployDir(r.getName())) {
                     needsLegend = true;
                 }
diff --git a/features/command/src/main/java/org/apache/karaf/features/command/RepoListCommand.java b/features/command/src/main/java/org/apache/karaf/features/command/RepoListCommand.java
index 50f3b95..a91182f 100644
--- a/features/command/src/main/java/org/apache/karaf/features/command/RepoListCommand.java
+++ b/features/command/src/main/java/org/apache/karaf/features/command/RepoListCommand.java
@@ -25,6 +25,7 @@ import org.apache.karaf.shell.api.action.Command;
 import org.apache.karaf.shell.api.action.Option;
 import org.apache.karaf.shell.api.action.lifecycle.Service;
 import org.apache.karaf.shell.support.MultiException;
+import org.apache.karaf.shell.support.table.Row;
 import org.apache.karaf.shell.support.table.ShellTable;
 
 @Command(scope = "feature", name = "repo-list", description = "Displays a list of all defined repositories.")
@@ -34,9 +35,12 @@ public class RepoListCommand extends FeaturesCommandSupport {
     @Option(name="-r", description="Reload all feature urls", required = false, multiValued = false)
     boolean reload;
 
+    @Option(name = "-b", aliases = { " --show-blacklisted" }, description = "Also display blacklisted repositories", required = false, multiValued = false)
+    boolean showBlacklisted = false;
+
     @Option(name = "--no-format", description = "Disable table rendered output", required = false, multiValued = false)
     boolean noFormat;
-    
+
     protected void doExecute(FeaturesService featuresService) throws Exception {
         if (reload) {
             reloadAllRepos(featuresService);
@@ -45,15 +49,24 @@ public class RepoListCommand extends FeaturesCommandSupport {
         ShellTable table = new ShellTable();
         table.column("Repository");
         table.column("URL");
+        if (showBlacklisted) {
+            table.column("Blacklisted");
+        }
         table.emptyTableText("No repositories available");
 
         Repository[] repos = featuresService.listRepositories();
-     	for (Repository repo : repos) {
+        for (Repository repo : repos) {
             if (repo != null) {
-     	        table.addRow().addContent(repo.getName(), repo.getURI().toString()); 
+                if (showBlacklisted || !repo.isBlacklisted()) {
+                    Row row = table.addRow();
+                    row.addContent(repo.getName(), repo.getURI().toString());
+                    if (showBlacklisted) {
+                        row.addContent(repo.isBlacklisted() ? "yes" : "no");
+                    }
+                }
             }
-     	}
-     	table.print(System.out, !noFormat);
+        }
+        table.print(System.out, !noFormat);
     }
 
     private void reloadAllRepos(FeaturesService featuresService) throws Exception {
diff --git a/features/core/src/main/java/org/apache/karaf/features/internal/service/RepositoryCacheImpl.java b/features/core/src/main/java/org/apache/karaf/features/internal/service/RepositoryCacheImpl.java
index d33b39d..9874a20 100644
--- a/features/core/src/main/java/org/apache/karaf/features/internal/service/RepositoryCacheImpl.java
+++ b/features/core/src/main/java/org/apache/karaf/features/internal/service/RepositoryCacheImpl.java
@@ -46,7 +46,9 @@ public class RepositoryCacheImpl implements RepositoryCache {
     public Repository create(URI uri, boolean validate) {
         RepositoryImpl repository = new RepositoryImpl(uri, validate);
         if (featuresProcessor != null) {
+            // maybe it could be done better - first we have to set if entire repo is blacklisted
             repository.setBlacklisted(featuresProcessor.isRepositoryBlacklisted(uri));
+            // processing features will take the above flag into account to blacklist (if needed) the features
             repository.processFeatures(featuresProcessor);
         }
         return repository;
diff --git a/features/core/src/main/java/org/apache/karaf/features/internal/service/RepositoryImpl.java b/features/core/src/main/java/org/apache/karaf/features/internal/service/RepositoryImpl.java
index 31aadaf..3d76c23 100644
--- a/features/core/src/main/java/org/apache/karaf/features/internal/service/RepositoryImpl.java
+++ b/features/core/src/main/java/org/apache/karaf/features/internal/service/RepositoryImpl.java
@@ -107,6 +107,12 @@ public class RepositoryImpl implements Repository {
      */
     public void processFeatures(FeaturesProcessor processor) {
         processor.process(features);
+        if (blacklisted) {
+            // all features of blacklisted repository are blacklisted too
+            for (org.apache.karaf.features.internal.model.Feature feature : features.getFeature()) {
+                feature.setBlacklisted(true);
+            }
+        }
     }
 
     static class InterruptibleInputStream extends FilterInputStream {

-- 
To stop receiving notification emails like this one, please contact
"commits@karaf.apache.org" <co...@karaf.apache.org>.