You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@karaf.apache.org by cm...@apache.org on 2010/08/23 15:36:44 UTC

svn commit: r988118 - in /karaf/trunk/features/command/src/main: java/org/apache/karaf/features/command/ListUrlCommand.java resources/OSGI-INF/blueprint/features-command.xml

Author: cmoulliard
Date: Mon Aug 23 13:36:44 2010
New Revision: 988118

URL: http://svn.apache.org/viewvc?rev=988118&view=rev
Log:
karaf-149 : Add a features:removeRepository command

Modified:
    karaf/trunk/features/command/src/main/java/org/apache/karaf/features/command/ListUrlCommand.java
    karaf/trunk/features/command/src/main/resources/OSGI-INF/blueprint/features-command.xml

Modified: karaf/trunk/features/command/src/main/java/org/apache/karaf/features/command/ListUrlCommand.java
URL: http://svn.apache.org/viewvc/karaf/trunk/features/command/src/main/java/org/apache/karaf/features/command/ListUrlCommand.java?rev=988118&r1=988117&r2=988118&view=diff
==============================================================================
--- karaf/trunk/features/command/src/main/java/org/apache/karaf/features/command/ListUrlCommand.java (original)
+++ karaf/trunk/features/command/src/main/java/org/apache/karaf/features/command/ListUrlCommand.java Mon Aug 23 13:36:44 2010
@@ -23,15 +23,46 @@ import org.apache.felix.gogo.commands.Co
 @Command(scope = "features", name = "listUrl", description = "Displays a list of all defined repository URLs.")
 public class ListUrlCommand extends FeaturesCommandSupport {
 
+	private static final String REPOSITORY = "Repository";
+	private static final String REPOSITORY_URL = "Repository URL";
+	
     protected void doExecute(FeaturesService admin) throws Exception {
+    	
+        StringBuffer sb = null;      
+
         Repository[] repos = admin.listRepositories();
+          
+    	int maxRepositorySize = REPOSITORY.length();    	
+        int maxRepositoryUrlSize = REPOSITORY_URL.length();
+        for (Repository r : repos) { 
+        	maxRepositorySize = Math.max(maxRepositorySize, r.getName().length());
+        	maxRepositoryUrlSize = Math.max(maxRepositoryUrlSize, r.getURI().toString().length());
+        }
+        
         if ((repos != null) && (repos.length > 0)) {
-            for (int i = 0; i < repos.length; i++) {
-            	String status = repos[i].isValid() ? "    valid" : "    invalid";
-            	System.out.println(repos[i].getURI().toString() + status);
+            // Prepare the header
+            sb = new StringBuffer();        
+            append(sb, REPOSITORY, maxRepositorySize + 2);
+            append(sb, REPOSITORY_URL, maxRepositoryUrlSize + 2);        
+            System.out.println(sb.toString());
+            
+
+        	for (int i = 0; i < repos.length; i++) {
+            	sb = new StringBuffer();        
+                append(sb, repos[i].getName(), maxRepositorySize + 2);
+                append(sb, repos[i].getURI().toString(), maxRepositoryUrlSize + 2); 
+            	sb.append(repos[i].isValid() ? "    valid" : "    invalid");
+            	System.out.println(sb.toString());
             }
         } else {
             System.out.println("No repository URLs are set.");
         }
     }
+    
+    private void append(StringBuffer sb, String s, int width) { 
+    	sb.append(s);
+    	for (int i = s.length(); i < width; i++) { 
+    		sb.append(" ");
+    	}
+    }
 }

Modified: karaf/trunk/features/command/src/main/resources/OSGI-INF/blueprint/features-command.xml
URL: http://svn.apache.org/viewvc/karaf/trunk/features/command/src/main/resources/OSGI-INF/blueprint/features-command.xml?rev=988118&r1=988117&r2=988118&view=diff
==============================================================================
--- karaf/trunk/features/command/src/main/resources/OSGI-INF/blueprint/features-command.xml (original)
+++ karaf/trunk/features/command/src/main/resources/OSGI-INF/blueprint/features-command.xml Mon Aug 23 13:36:44 2010
@@ -33,6 +33,12 @@
                 <ref component-id="featureUrlCompleter" />
             </completers>
         </command>
+        <command name="features/removeRepository">
+            <action class="org.apache.karaf.features.command.RemoveRepositoryCommand"/>
+            <completers>
+                <ref component-id="featureRepositoryNameCompleter" />
+            </completers>        
+        </command>        
         <command name="features/refreshUrl">
             <action class="org.apache.karaf.features.command.RefreshUrlCommand"/>
             <completers>
@@ -85,5 +91,9 @@
     <bean id="featureUrlCompleter" class="org.apache.karaf.features.command.completers.FeatureRepositoryCompleter">
         <property name="featuresService" ref="featuresService" />
     </bean>
+    
+    <bean id="featureRepositoryNameCompleter" class="org.apache.karaf.features.command.completers.FeatureRepositoryNameCompleter">
+    	<property name="featuresService" ref="featuresService"/>
+    </bean>
 
 </blueprint>