Author: cschneider Date: Fri Jul 8 12:32:36 2011 New Revision: 1144288 URL: http://svn.apache.org/viewvc?rev=1144288&view=rev Log: Refactored ListCommand to get the RepositoryAdmin service using blueprint
Modified: karaf/trunk/shell/obr/src/main/java/org/apache/karaf/shell/obr/ListCommand.java karaf/trunk/shell/obr/src/main/resources/OSGI-INF/blueprint/shell-obr.xml karaf/trunk/shell/obr/src/test/java/org/apache/karaf/shell/obr/ListCommandTest.java Modified: karaf/trunk/shell/obr/src/main/java/org/apache/karaf/shell/obr/ListCommand.java URL: http://svn.apache.org/viewvc/karaf/trunk/shell/obr/src/main/java/org/apache/karaf/shell/obr/ListCommand.java?rev=1144288&r1=1144287&r2=1144288&view=diff ============================================================================== --- karaf/trunk/shell/obr/src/main/java/org/apache/karaf/shell/obr/ListCommand.java (original) +++ karaf/trunk/shell/obr/src/main/java/org/apache/karaf/shell/obr/ListCommand.java Fri Jul 8 12:32:36 2011 @@ -20,16 +20,25 @@ import java.util.List; import org.apache.felix.bundlerepository.RepositoryAdmin; import org.apache.felix.bundlerepository.Resource; +import org.apache.felix.gogo.commands.Action; import org.apache.felix.gogo.commands.Argument; import org.apache.felix.gogo.commands.Command; +import org.apache.felix.service.command.CommandSession; @Command(scope = "obr", name = "list", description = "Lists OBR bundles, optionally providing the given packages.") -public class ListCommand extends ObrCommandSupport { +public class ListCommand implements Action { @Argument(index = 0, name = "packages", description = "A list of packages separated by whitespaces.", required = false, multiValued = true) List<String> packages; + + RepositoryAdmin repoAdmin; - void doExecute(RepositoryAdmin admin) throws Exception { + public void setRepoAdmin(RepositoryAdmin repoAdmin) { + this.repoAdmin = repoAdmin; + } + + @Override + public Object execute(CommandSession session) throws Exception { StringBuilder substr = new StringBuilder(); if (packages != null) { @@ -45,7 +54,7 @@ public class ListCommand extends ObrComm } else { query = "(|(presentationname=*" + substr + "*)(symbolicname=*" + substr + "*))"; } - Resource[] resources = admin.discoverResources(query); + Resource[] resources = repoAdmin.discoverResources(query); int maxPName = 4; int maxSName = 13; int maxVersion = 7; @@ -68,6 +77,7 @@ public class ListCommand extends ObrComm if (resources == null || resources.length == 0) { System.out.println("No matching bundles."); } + return null; } private String emptyIfNull(Object st) { Modified: karaf/trunk/shell/obr/src/main/resources/OSGI-INF/blueprint/shell-obr.xml URL: http://svn.apache.org/viewvc/karaf/trunk/shell/obr/src/main/resources/OSGI-INF/blueprint/shell-obr.xml?rev=1144288&r1=1144287&r2=1144288&view=diff ============================================================================== --- karaf/trunk/shell/obr/src/main/resources/OSGI-INF/blueprint/shell-obr.xml (original) +++ karaf/trunk/shell/obr/src/main/resources/OSGI-INF/blueprint/shell-obr.xml Fri Jul 8 12:32:36 2011 @@ -18,6 +18,7 @@ --> <blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0" default-activation="lazy"> + <reference id="repoAdmin" interface="org.apache.felix.bundlerepository.RepositoryAdmin"/> <command-bundle xmlns="http://karaf.apache.org/xmlns/shell/v1.0.0"> <command name="obr/addUrl"> @@ -33,7 +34,9 @@ <action class="org.apache.karaf.shell.obr.InfoCommand"/> </command> <command name="obr/list"> - <action class="org.apache.karaf.shell.obr.ListCommand"/> + <action class="org.apache.karaf.shell.obr.ListCommand"> + <property name="repoAdmin" ref="repoAdmin"/> + </action> </command> <command name="obr/listUrl"> <action class="org.apache.karaf.shell.obr.ListUrlCommand"/> Modified: karaf/trunk/shell/obr/src/test/java/org/apache/karaf/shell/obr/ListCommandTest.java URL: http://svn.apache.org/viewvc/karaf/trunk/shell/obr/src/test/java/org/apache/karaf/shell/obr/ListCommandTest.java?rev=1144288&r1=1144287&r2=1144288&view=diff ============================================================================== --- karaf/trunk/shell/obr/src/test/java/org/apache/karaf/shell/obr/ListCommandTest.java (original) +++ karaf/trunk/shell/obr/src/test/java/org/apache/karaf/shell/obr/ListCommandTest.java Fri Jul 8 12:32:36 2011 @@ -18,6 +18,7 @@ public class ListCommandTest { IMocksControl control = EasyMock.createControl(); RepositoryAdmin repoAdmin = control.createMock(RepositoryAdmin.class); ListCommand command = new ListCommand(); + command.setRepoAdmin(repoAdmin); Resource[] resources = new Resource[] { createResource("My bundle", "my.bundle", "1.0.0"), @@ -27,7 +28,7 @@ public class ListCommandTest { andReturn(resources); control.replay(); - command.doExecute(repoAdmin); + command.execute(null); control.verify(); }