You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@karaf.apache.org by jb...@apache.org on 2012/07/30 09:33:14 UTC

svn commit: r1367013 - in /karaf/branches/karaf-2.3.x/shell/obr/src/main/java/org/apache/karaf/shell/obr: RefreshUrlCommand.java RemoveUrlCommand.java

Author: jbonofre
Date: Mon Jul 30 07:33:13 2012
New Revision: 1367013

URL: http://svn.apache.org/viewvc?rev=1367013&view=rev
Log:
[KARAF-1676] Add support of index to manipulate OBR URLs

Modified:
    karaf/branches/karaf-2.3.x/shell/obr/src/main/java/org/apache/karaf/shell/obr/RefreshUrlCommand.java
    karaf/branches/karaf-2.3.x/shell/obr/src/main/java/org/apache/karaf/shell/obr/RemoveUrlCommand.java

Modified: karaf/branches/karaf-2.3.x/shell/obr/src/main/java/org/apache/karaf/shell/obr/RefreshUrlCommand.java
URL: http://svn.apache.org/viewvc/karaf/branches/karaf-2.3.x/shell/obr/src/main/java/org/apache/karaf/shell/obr/RefreshUrlCommand.java?rev=1367013&r1=1367012&r2=1367013&view=diff
==============================================================================
--- karaf/branches/karaf-2.3.x/shell/obr/src/main/java/org/apache/karaf/shell/obr/RefreshUrlCommand.java (original)
+++ karaf/branches/karaf-2.3.x/shell/obr/src/main/java/org/apache/karaf/shell/obr/RefreshUrlCommand.java Mon Jul 30 07:33:13 2012
@@ -22,17 +22,31 @@ import org.apache.felix.bundlerepository
 import org.apache.felix.bundlerepository.RepositoryAdmin;
 import org.apache.felix.gogo.commands.Argument;
 import org.apache.felix.gogo.commands.Command;
+import org.apache.felix.gogo.commands.Option;
 
 @Command(scope = "obr", name = "refreshUrl", description = "Reloads the repositories to obtain a fresh list of bundles.")
 public class RefreshUrlCommand extends ObrCommandSupport {
 
-    @Argument(index = 0, name = "urls", description = "Repository URLs to refresh (leave empty for all)", required = false, multiValued = true)
-    List<String> urls;
+    @Option(name = "-i", aliases = { "--index" }, description = "Use index to identify URL", required = false, multiValued = false)
+    boolean useIndex;
+
+    @Argument(index = 0, name = "ids", description = "Repository URLs (or indexes if you use -i) to refresh (leave empty for all)", required = false, multiValued = true)
+    List<String> ids;
 
     protected void doExecute(RepositoryAdmin admin) throws Exception {
-		if (urls != null && !urls.isEmpty()) {
-			for (String url : urls) {
-				admin.addRepository(url);
+		if (ids != null && !ids.isEmpty()) {
+			for (String id : ids) {
+                if (useIndex) {
+                    Repository[] repos = admin.listRepositories();
+                    int index = Integer.parseInt(id);
+                    if (index >= 0 && index < repos.length) {
+                        admin.addRepository(repos[index].getURI());
+                    } else {
+                        System.err.println("Invalid index");
+                    }
+                } else {
+				    admin.addRepository(id);
+                }
 			}
 		} else {
 			Repository[] repos = admin.listRepositories();

Modified: karaf/branches/karaf-2.3.x/shell/obr/src/main/java/org/apache/karaf/shell/obr/RemoveUrlCommand.java
URL: http://svn.apache.org/viewvc/karaf/branches/karaf-2.3.x/shell/obr/src/main/java/org/apache/karaf/shell/obr/RemoveUrlCommand.java?rev=1367013&r1=1367012&r2=1367013&view=diff
==============================================================================
--- karaf/branches/karaf-2.3.x/shell/obr/src/main/java/org/apache/karaf/shell/obr/RemoveUrlCommand.java (original)
+++ karaf/branches/karaf-2.3.x/shell/obr/src/main/java/org/apache/karaf/shell/obr/RemoveUrlCommand.java Mon Jul 30 07:33:13 2012
@@ -18,19 +18,34 @@ package org.apache.karaf.shell.obr;
 
 import java.util.List;
 
+import org.apache.felix.bundlerepository.Repository;
 import org.apache.felix.bundlerepository.RepositoryAdmin;
 import org.apache.felix.gogo.commands.Argument;
 import org.apache.felix.gogo.commands.Command;
+import org.apache.felix.gogo.commands.Option;
 
 @Command(scope = "obr", name = "removeUrl", description = "Removes a list of repository URLs from the OBR service.")
 public class RemoveUrlCommand extends ObrCommandSupport {
 
-    @Argument(index = 0, name = "urls", description = "Repository URLs to remove from OBR service", required = true, multiValued = true)
-    List<String> urls;
+    @Option(name = "-i", aliases = { "--index" }, description = "Use index to identify URL", required = false, multiValued = false)
+    boolean useIndex;
+
+    @Argument(index = 0, name = "ids", description = "Repository URLs (or indexes if you use -i) to remove from OBR service", required = true, multiValued = true)
+    List<String> ids;
 
     protected void doExecute(RepositoryAdmin admin) throws Exception {
-        for (String url : urls) {
-            admin.removeRepository(url);
+        for (String id : ids) {
+            if (useIndex) {
+                Repository[] repos = admin.listRepositories();
+                int index = Integer.parseInt(id);
+                if (index >= 0 && index < repos.length) {
+                    admin.removeRepository(repos[index].getURI());
+                } else {
+                    System.err.println("Invalid index");
+                }
+            } else {
+                admin.removeRepository(id);
+            }
         }
         persistRepositoryList(admin);
     }