FELIX-2113: update to latest OBR snapshot
git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@917461 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/karaf/shell/obr/src/main/java/org/apache/felix/karaf/shell/obr/AddUrlCommand.java b/karaf/shell/obr/src/main/java/org/apache/felix/karaf/shell/obr/AddUrlCommand.java
index e1ac172..00c8b03 100644
--- a/karaf/shell/obr/src/main/java/org/apache/felix/karaf/shell/obr/AddUrlCommand.java
+++ b/karaf/shell/obr/src/main/java/org/apache/felix/karaf/shell/obr/AddUrlCommand.java
@@ -19,7 +19,7 @@
import java.net.URL;
import java.util.List;
-import org.osgi.service.obr.RepositoryAdmin;
+import org.apache.felix.bundlerepository.RepositoryAdmin;
import org.apache.felix.gogo.commands.Argument;
import org.apache.felix.gogo.commands.Command;
diff --git a/karaf/shell/obr/src/main/java/org/apache/felix/karaf/shell/obr/DeployCommand.java b/karaf/shell/obr/src/main/java/org/apache/felix/karaf/shell/obr/DeployCommand.java
index c2bf6e3..b29b8c2 100644
--- a/karaf/shell/obr/src/main/java/org/apache/felix/karaf/shell/obr/DeployCommand.java
+++ b/karaf/shell/obr/src/main/java/org/apache/felix/karaf/shell/obr/DeployCommand.java
@@ -18,7 +18,7 @@
import java.util.List;
-import org.osgi.service.obr.RepositoryAdmin;
+import org.apache.felix.bundlerepository.RepositoryAdmin;
import org.apache.felix.gogo.commands.Argument;
import org.apache.felix.gogo.commands.Command;
diff --git a/karaf/shell/obr/src/main/java/org/apache/felix/karaf/shell/obr/FindCommand.java b/karaf/shell/obr/src/main/java/org/apache/felix/karaf/shell/obr/FindCommand.java
index 3de0a6e..f6098f0 100644
--- a/karaf/shell/obr/src/main/java/org/apache/felix/karaf/shell/obr/FindCommand.java
+++ b/karaf/shell/obr/src/main/java/org/apache/felix/karaf/shell/obr/FindCommand.java
@@ -19,15 +19,15 @@
import java.util.ArrayList;
import java.util.List;
+import org.apache.felix.bundlerepository.Capability;
+import org.apache.felix.bundlerepository.Repository;
+import org.apache.felix.bundlerepository.RepositoryAdmin;
+import org.apache.felix.bundlerepository.Requirement;
+import org.apache.felix.bundlerepository.Resource;
import org.apache.felix.gogo.commands.Argument;
import org.apache.felix.gogo.commands.Command;
import org.osgi.framework.InvalidSyntaxException;
import org.osgi.framework.Version;
-import org.osgi.service.obr.Capability;
-import org.osgi.service.obr.Repository;
-import org.osgi.service.obr.RepositoryAdmin;
-import org.osgi.service.obr.Requirement;
-import org.osgi.service.obr.Resource;
@Command(scope = "obr", name = "find", description = "Find OBR bundles for a given filter")
public class FindCommand extends ObrCommandSupport {
@@ -62,25 +62,4 @@
}
}
- private Requirement parseRequirement(RepositoryAdmin admin, String req) throws InvalidSyntaxException {
- int p = req.indexOf(':');
- String name;
- String filter;
- if (p > 0) {
- name = req.substring(0, p);
- filter = req.substring(p + 1);
- } else {
- if (req.contains("package")) {
- name = "package";
- } else {
- name = "bundle";
- }
- filter = req;
- }
- if (!filter.startsWith("(")) {
- filter = "(" + filter + ")";
- }
- return admin.requirement(name, filter);
- }
-
}
\ No newline at end of file
diff --git a/karaf/shell/obr/src/main/java/org/apache/felix/karaf/shell/obr/InfoCommand.java b/karaf/shell/obr/src/main/java/org/apache/felix/karaf/shell/obr/InfoCommand.java
index e66a65f..c3950ed 100644
--- a/karaf/shell/obr/src/main/java/org/apache/felix/karaf/shell/obr/InfoCommand.java
+++ b/karaf/shell/obr/src/main/java/org/apache/felix/karaf/shell/obr/InfoCommand.java
@@ -22,12 +22,12 @@
import java.util.List;
import java.util.Map;
+import org.apache.felix.bundlerepository.Capability;
+import org.apache.felix.bundlerepository.RepositoryAdmin;
+import org.apache.felix.bundlerepository.Requirement;
+import org.apache.felix.bundlerepository.Resource;
import org.apache.felix.gogo.commands.Argument;
import org.apache.felix.gogo.commands.Command;
-import org.osgi.service.obr.Capability;
-import org.osgi.service.obr.RepositoryAdmin;
-import org.osgi.service.obr.Requirement;
-import org.osgi.service.obr.Resource;
@Command(scope = "obr", name = "info", description = "Prints information about OBR bundles")
public class InfoCommand extends ObrCommandSupport {
diff --git a/karaf/shell/obr/src/main/java/org/apache/felix/karaf/shell/obr/ListCommand.java b/karaf/shell/obr/src/main/java/org/apache/felix/karaf/shell/obr/ListCommand.java
index b2e1185..bb76b86 100644
--- a/karaf/shell/obr/src/main/java/org/apache/felix/karaf/shell/obr/ListCommand.java
+++ b/karaf/shell/obr/src/main/java/org/apache/felix/karaf/shell/obr/ListCommand.java
@@ -18,9 +18,9 @@
import java.util.List;
+import org.apache.felix.bundlerepository.RepositoryAdmin;
+import org.apache.felix.bundlerepository.Resource;
import org.osgi.framework.Version;
-import org.osgi.service.obr.RepositoryAdmin;
-import org.osgi.service.obr.Resource;
import org.apache.felix.gogo.commands.Argument;
import org.apache.felix.gogo.commands.Command;
diff --git a/karaf/shell/obr/src/main/java/org/apache/felix/karaf/shell/obr/ListUrlCommand.java b/karaf/shell/obr/src/main/java/org/apache/felix/karaf/shell/obr/ListUrlCommand.java
index e66c9e8..7c74663 100644
--- a/karaf/shell/obr/src/main/java/org/apache/felix/karaf/shell/obr/ListUrlCommand.java
+++ b/karaf/shell/obr/src/main/java/org/apache/felix/karaf/shell/obr/ListUrlCommand.java
@@ -16,8 +16,8 @@
*/
package org.apache.felix.karaf.shell.obr;
-import org.osgi.service.obr.Repository;
-import org.osgi.service.obr.RepositoryAdmin;
+import org.apache.felix.bundlerepository.Repository;
+import org.apache.felix.bundlerepository.RepositoryAdmin;
import org.apache.felix.gogo.commands.Command;
@Command(scope = "obr", name = "listUrl", description = "Displays the repository URLs currently associated with the OBR service.")
diff --git a/karaf/shell/obr/src/main/java/org/apache/felix/karaf/shell/obr/ObrCommandSupport.java b/karaf/shell/obr/src/main/java/org/apache/felix/karaf/shell/obr/ObrCommandSupport.java
index 80ec89e..eb59dc3 100644
--- a/karaf/shell/obr/src/main/java/org/apache/felix/karaf/shell/obr/ObrCommandSupport.java
+++ b/karaf/shell/obr/src/main/java/org/apache/felix/karaf/shell/obr/ObrCommandSupport.java
@@ -19,14 +19,15 @@
import java.io.PrintStream;
import java.util.List;
+import org.apache.felix.bundlerepository.RepositoryAdmin;
+import org.apache.felix.bundlerepository.Requirement;
+import org.apache.felix.bundlerepository.Resolver;
+import org.apache.felix.bundlerepository.Resource;
import org.apache.felix.karaf.shell.console.OsgiCommandSupport;
import org.osgi.framework.Bundle;
+import org.osgi.framework.InvalidSyntaxException;
import org.osgi.framework.ServiceReference;
import org.osgi.framework.Version;
-import org.osgi.service.obr.RepositoryAdmin;
-import org.osgi.service.obr.Requirement;
-import org.osgi.service.obr.Resolver;
-import org.osgi.service.obr.Resource;
public abstract class ObrCommandSupport extends OsgiCommandSupport {
@@ -218,4 +219,37 @@
}
}
+
+
+ protected Requirement parseRequirement(RepositoryAdmin admin, String req) throws InvalidSyntaxException {
+ int p = req.indexOf(':');
+ String name;
+ String filter;
+ if (p > 0) {
+ name = req.substring(0, p);
+ filter = req.substring(p + 1);
+ } else {
+ if (req.contains("package")) {
+ name = "package";
+ } else if (req.contains("service")) {
+ name = "service";
+ } else {
+ name = "bundle";
+ }
+ filter = req;
+ }
+ if (!filter.startsWith("(")) {
+ filter = "(" + filter + ")";
+ }
+ return admin.requirement(name, filter);
+ }
+
+ protected Requirement[] parseRequirements(RepositoryAdmin admin, List<String> requirements) throws InvalidSyntaxException {
+ Requirement[] reqs = new Requirement[requirements.size()];
+ for (int i = 0; i < reqs.length; i++) {
+ reqs[i] = parseRequirement(admin, requirements.get(i));
+ }
+ return reqs;
+ }
+
}
diff --git a/karaf/shell/obr/src/main/java/org/apache/felix/karaf/shell/obr/RefreshUrlCommand.java b/karaf/shell/obr/src/main/java/org/apache/felix/karaf/shell/obr/RefreshUrlCommand.java
index 888d6f8..f55f5b1 100644
--- a/karaf/shell/obr/src/main/java/org/apache/felix/karaf/shell/obr/RefreshUrlCommand.java
+++ b/karaf/shell/obr/src/main/java/org/apache/felix/karaf/shell/obr/RefreshUrlCommand.java
@@ -19,8 +19,8 @@
import java.net.URL;
import java.util.List;
-import org.osgi.service.obr.Repository;
-import org.osgi.service.obr.RepositoryAdmin;
+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;
diff --git a/karaf/shell/obr/src/main/java/org/apache/felix/karaf/shell/obr/RemoveUrlCommand.java b/karaf/shell/obr/src/main/java/org/apache/felix/karaf/shell/obr/RemoveUrlCommand.java
index 452a6da..123de1d 100644
--- a/karaf/shell/obr/src/main/java/org/apache/felix/karaf/shell/obr/RemoveUrlCommand.java
+++ b/karaf/shell/obr/src/main/java/org/apache/felix/karaf/shell/obr/RemoveUrlCommand.java
@@ -19,9 +19,9 @@
import java.net.URL;
import java.util.List;
+import org.apache.felix.bundlerepository.RepositoryAdmin;
import org.apache.felix.gogo.commands.Argument;
import org.apache.felix.gogo.commands.Command;
-import org.osgi.service.obr.RepositoryAdmin;
@Command(scope = "obr", name = "removeUrl", description = "Removes a list of repository URLs from the OBR service.")
public class RemoveUrlCommand extends ObrCommandSupport {
diff --git a/karaf/shell/obr/src/main/java/org/apache/felix/karaf/shell/obr/ResolveCommand.java b/karaf/shell/obr/src/main/java/org/apache/felix/karaf/shell/obr/ResolveCommand.java
index fe5929d..8b73a90 100644
--- a/karaf/shell/obr/src/main/java/org/apache/felix/karaf/shell/obr/ResolveCommand.java
+++ b/karaf/shell/obr/src/main/java/org/apache/felix/karaf/shell/obr/ResolveCommand.java
@@ -16,44 +16,75 @@
*/
package org.apache.felix.karaf.shell.obr;
+import java.util.ArrayList;
+import java.util.Arrays;
import java.util.List;
+import org.apache.felix.bundlerepository.Repository;
+import org.apache.felix.bundlerepository.RepositoryAdmin;
+import org.apache.felix.bundlerepository.Requirement;
+import org.apache.felix.bundlerepository.Resolver;
+import org.apache.felix.bundlerepository.Resource;
import org.apache.felix.gogo.commands.Argument;
import org.apache.felix.gogo.commands.Command;
import org.apache.felix.gogo.commands.Option;
-import org.osgi.framework.InvalidSyntaxException;
-import org.osgi.service.obr.RepositoryAdmin;
-import org.osgi.service.obr.Requirement;
-import org.osgi.service.obr.Resolver;
-import org.osgi.service.obr.Resource;
@Command(scope = "obr", name = "resolve", description = "Show the resolution output for a given set of requirements")
public class ResolveCommand extends ObrCommandSupport {
- @Option(name = "-w", aliases = "--why", description = "Display the reason if the inclusion of the resource")
+ @Option(name = "-w", aliases = "--why", description = "Display the reason of the inclusion of the resource")
boolean why;
+ @Option(name = "-l", aliases = "--no-local", description = "Ignore local resources during resolution")
+ boolean noLocal;
+
+ @Option(name = "--no-remote", description = "Ignore remote resources during resolution")
+ boolean noRemote;
+
+ @Option(name = "--deploy", description = "Deploy the selected bundles")
+ boolean deploy;
+
+ @Option(name = "--start", description = "Deploy and start the selected bundles")
+ boolean start;
+
+ @Option(name = "--optional", description = "Resolve optional dependencies")
+ boolean optional;
+
@Argument(index = 0, name = "requirements", description = "Requirements", required = true, multiValued = true)
List<String> requirements;
protected void doExecute(RepositoryAdmin admin) throws Exception {
- Resolver resolver = admin.resolver();
- for (Requirement requirement : getRequirements(admin)) {
+ List<Repository> repositories = new ArrayList<Repository>();
+ repositories.add(admin.getSystemRepository());
+ if (!noLocal) {
+ repositories.add(admin.getLocalRepository());
+ }
+ if (!noRemote) {
+ repositories.addAll(Arrays.asList(admin.listRepositories()));
+ }
+ Resolver resolver = admin.resolver(repositories.toArray(new Repository[repositories.size()]));
+ for (Requirement requirement : parseRequirements(admin, requirements)) {
resolver.add(requirement);
}
- if (resolver.resolve()) {
+ if (resolver.resolve(optional ? 0 : Resolver.NO_OPTIONAL_REQUIREMENTS)) {
Resource[] resources;
resources = resolver.getRequiredResources();
if ((resources != null) && (resources.length > 0)) {
System.out.println("Required resource(s):");
printUnderline(System.out, 21);
for (int resIdx = 0; resIdx < resources.length; resIdx++) {
- System.out.println(" " + resources[resIdx].getPresentationName()
- + " (" + resources[resIdx].getVersion() + ")");
+ System.out.println(" " + resources[resIdx].getPresentationName() + " (" + resources[resIdx].getVersion() + ")");
if (why) {
- Requirement[] r = resolver.getReason(resources[resIdx]);
- for (int reqIdx = 0; r != null && reqIdx < r.length; reqIdx++) {
- System.out.println(" - " + r[reqIdx].getName() + ":" + r[reqIdx].getFilter());
+ Requirement[] req = resolver.getReason(resources[resIdx]);
+ for (int reqIdx = 0; req != null && reqIdx < req.length; reqIdx++) {
+ if (!req[reqIdx].isOptional()) {
+ Resource r = req[reqIdx].getResource();
+ if (r != null) {
+ System.out.println(" - " + r.getPresentationName() + " / " + req[reqIdx].getName() + ":" + req[reqIdx].getFilter());
+ } else {
+ System.out.println(" - " + req[reqIdx].getName() + ":" + req[reqIdx].getFilter());
+ }
+ }
}
}
}
@@ -67,13 +98,32 @@
System.out.println(" " + resources[resIdx].getPresentationName()
+ " (" + resources[resIdx].getVersion() + ")");
if (why) {
- Requirement[] r = resolver.getReason(resources[resIdx]);
- for (int reqIdx = 0; r != null && reqIdx < r.length; reqIdx++) {
- System.out.println(" - " + r[reqIdx].getName() + ":" + r[reqIdx].getFilter());
+ Requirement[] req = resolver.getReason(resources[resIdx]);
+ for (int reqIdx = 0; req != null && reqIdx < req.length; reqIdx++) {
+ if (!req[reqIdx].isOptional()) {
+ Resource r = req[reqIdx].getResource();
+ if (r != null) {
+ System.out.println(" - " + r.getPresentationName() + " / " + req[reqIdx].getName() + ":" + req[reqIdx].getFilter());
+ } else {
+ System.out.println(" - " + req[reqIdx].getName() + ":" + req[reqIdx].getFilter());
+ }
+ }
}
}
}
}
+ if (deploy || start) {
+ try
+ {
+ System.out.print("\nDeploying...");
+ resolver.deploy(start);
+ System.out.println("done.");
+ }
+ catch (IllegalStateException ex)
+ {
+ System.err.println(ex);
+ }
+ }
} else {
Requirement[] reqs = resolver.getUnsatisfiedRequirements();
if ((reqs != null) && (reqs.length > 0)) {
@@ -92,33 +142,4 @@
}
}
- private Requirement[] getRequirements(RepositoryAdmin admin) throws InvalidSyntaxException {
- Requirement[] reqs = new Requirement[requirements.size()];
- for (int i = 0; i < reqs.length; i++) {
- reqs[i] = parseRequirement(admin, requirements.get(i));
- }
- return reqs;
- }
-
- private Requirement parseRequirement(RepositoryAdmin admin, String req) throws InvalidSyntaxException {
- int p = req.indexOf(':');
- String name;
- String filter;
- if (p > 0) {
- name = req.substring(0, p);
- filter = req.substring(p + 1);
- } else {
- if (req.contains("package")) {
- name = "package";
- } else {
- name = "bundle";
- }
- filter = req;
- }
- if (!filter.startsWith("(")) {
- filter = "(" + filter + ")";
- }
- return admin.requirement(name, filter);
- }
-
}
\ No newline at end of file
diff --git a/karaf/shell/obr/src/main/java/org/apache/felix/karaf/shell/obr/SourceCommand.java b/karaf/shell/obr/src/main/java/org/apache/felix/karaf/shell/obr/SourceCommand.java
index 3e8dcfd..7bc4df4 100644
--- a/karaf/shell/obr/src/main/java/org/apache/felix/karaf/shell/obr/SourceCommand.java
+++ b/karaf/shell/obr/src/main/java/org/apache/felix/karaf/shell/obr/SourceCommand.java
@@ -19,12 +19,12 @@
import java.net.URL;
import java.util.List;
+import org.apache.felix.bundlerepository.RepositoryAdmin;
+import org.apache.felix.bundlerepository.Resource;
import org.apache.felix.gogo.commands.Option;
import org.apache.felix.gogo.commands.Argument;
import org.apache.felix.gogo.commands.Command;
import org.apache.felix.karaf.shell.obr.util.FileUtil;
-import org.osgi.service.obr.RepositoryAdmin;
-import org.osgi.service.obr.Resource;
@Command(scope = "obr", name = "source", description = "Download the sources for an OBR bundle.")
public class SourceCommand extends ObrCommandSupport {
diff --git a/karaf/shell/obr/src/main/java/org/apache/felix/karaf/shell/obr/StartCommand.java b/karaf/shell/obr/src/main/java/org/apache/felix/karaf/shell/obr/StartCommand.java
index 0164846..f662881 100644
--- a/karaf/shell/obr/src/main/java/org/apache/felix/karaf/shell/obr/StartCommand.java
+++ b/karaf/shell/obr/src/main/java/org/apache/felix/karaf/shell/obr/StartCommand.java
@@ -16,7 +16,7 @@
*/
package org.apache.felix.karaf.shell.obr;
-import org.osgi.service.obr.RepositoryAdmin;
+import org.apache.felix.bundlerepository.RepositoryAdmin;
import org.apache.felix.gogo.commands.Command;
@Command(scope = "obr", name = "start", description = "Deploy and start a list of bundles using OBR.")