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/10/04 11:57:37 UTC
svn commit: r1393973 - in /karaf/trunk/obr:
command/src/main/java/org/apache/karaf/obr/command/
core/src/main/java/org/apache/karaf/obr/core/
core/src/main/java/org/apache/karaf/obr/core/internal/
Author: jbonofre
Date: Thu Oct 4 09:57:37 2012
New Revision: 1393973
URL: http://svn.apache.org/viewvc?rev=1393973&view=rev
Log:
[KARAF-1765] Add deployOptional option in obr:start, obr:deploy commands and the ObrMBean
Modified:
karaf/trunk/obr/command/src/main/java/org/apache/karaf/obr/command/DeployCommand.java
karaf/trunk/obr/command/src/main/java/org/apache/karaf/obr/command/ObrCommandSupport.java
karaf/trunk/obr/command/src/main/java/org/apache/karaf/obr/command/StartCommand.java
karaf/trunk/obr/core/src/main/java/org/apache/karaf/obr/core/ObrMBean.java
karaf/trunk/obr/core/src/main/java/org/apache/karaf/obr/core/internal/Obr.java
Modified: karaf/trunk/obr/command/src/main/java/org/apache/karaf/obr/command/DeployCommand.java
URL: http://svn.apache.org/viewvc/karaf/trunk/obr/command/src/main/java/org/apache/karaf/obr/command/DeployCommand.java?rev=1393973&r1=1393972&r2=1393973&view=diff
==============================================================================
--- karaf/trunk/obr/command/src/main/java/org/apache/karaf/obr/command/DeployCommand.java (original)
+++ karaf/trunk/obr/command/src/main/java/org/apache/karaf/obr/command/DeployCommand.java Thu Oct 4 09:57:37 2012
@@ -32,8 +32,11 @@ public class DeployCommand extends ObrCo
@Option(name = "-s", aliases = { "--start" }, description = "Start the deployed bundles", required = false, multiValued = false)
protected boolean start = false;
+ @Option(name = "-d", aliases = { "--deployOptional" }, description = "Deploy optional bundles", required = false, multiValued = false)
+ protected boolean deployOptional = false;
+
protected void doExecute(RepositoryAdmin admin) throws Exception {
- doDeploy(admin, bundles, start);
+ doDeploy(admin, bundles, start, deployOptional);
}
}
Modified: karaf/trunk/obr/command/src/main/java/org/apache/karaf/obr/command/ObrCommandSupport.java
URL: http://svn.apache.org/viewvc/karaf/trunk/obr/command/src/main/java/org/apache/karaf/obr/command/ObrCommandSupport.java?rev=1393973&r1=1393972&r2=1393973&view=diff
==============================================================================
--- karaf/trunk/obr/command/src/main/java/org/apache/karaf/obr/command/ObrCommandSupport.java (original)
+++ karaf/trunk/obr/command/src/main/java/org/apache/karaf/obr/command/ObrCommandSupport.java Thu Oct 4 09:57:37 2012
@@ -56,8 +56,7 @@ public abstract class ObrCommandSupport
}
doExecute(admin);
- }
- finally {
+ } finally {
getBundleContext().ungetService(ref);
}
return null;
@@ -65,16 +64,12 @@ public abstract class ObrCommandSupport
abstract void doExecute(RepositoryAdmin admin) throws Exception;
- protected Resource[] searchRepository(RepositoryAdmin admin, String targetId, String targetVersion) throws InvalidSyntaxException
- {
+ protected Resource[] searchRepository(RepositoryAdmin admin, String targetId, String targetVersion) throws InvalidSyntaxException {
// Try to see if the targetId is a bundle ID.
- try
- {
+ try {
Bundle bundle = getBundleContext().getBundle(Long.parseLong(targetId));
targetId = bundle.getSymbolicName();
- }
- catch (NumberFormatException ex)
- {
+ } catch (NumberFormatException ex) {
// It was not a number, so ignore.
}
@@ -85,8 +80,7 @@ public abstract class ObrCommandSupport
sb.append(")(symbolicname=");
sb.append(targetId);
sb.append("))");
- if (targetVersion != null)
- {
+ if (targetVersion != null) {
sb.insert(0, "(&");
sb.append("(version=");
sb.append(targetVersion);
@@ -95,22 +89,16 @@ public abstract class ObrCommandSupport
return admin.discoverResources(sb.toString());
}
- public Resource selectNewestVersion(Resource[] resources)
- {
+ public Resource selectNewestVersion(Resource[] resources) {
int idx = -1;
Version v = null;
- for (int i = 0; (resources != null) && (i < resources.length); i++)
- {
- if (i == 0)
- {
+ for (int i = 0; (resources != null) && (i < resources.length); i++) {
+ if (i == 0) {
idx = 0;
v = resources[i].getVersion();
- }
- else
- {
+ } else {
Version vtmp = resources[i].getVersion();
- if (vtmp.compareTo(v) > 0)
- {
+ if (vtmp.compareTo(v) > 0) {
idx = i;
v = vtmp;
}
@@ -123,100 +111,78 @@ public abstract class ObrCommandSupport
String[] target;
int idx = bundle.indexOf(VERSION_DELIM);
if (idx > 0) {
- target = new String[] { bundle.substring(0, idx), bundle.substring(idx+1) };
- }
- else
- {
- target = new String[] { bundle, null };
+ target = new String[]{bundle.substring(0, idx), bundle.substring(idx + 1)};
+ } else {
+ target = new String[]{bundle, null};
}
return target;
}
- protected void printUnderline(PrintStream out, int length)
- {
- for (int i = 0; i < length; i++)
- {
+ protected void printUnderline(PrintStream out, int length) {
+ for (int i = 0; i < length; i++) {
out.print('-');
}
out.println("");
}
- protected void doDeploy(RepositoryAdmin admin, List<String> bundles, boolean start) throws Exception {
+ protected void doDeploy(RepositoryAdmin admin, List<String> bundles, boolean start, boolean deployOptional) throws Exception {
Resolver resolver = admin.resolver();
for (String bundle : bundles) {
String[] target = getTarget(bundle);
Resource resource = selectNewestVersion(searchRepository(admin, target[0], target[1]));
- if (resource != null)
- {
+ if (resource != null) {
resolver.add(resource);
- }
- else
- {
+ } else {
System.err.println("Unknown bundle - " + target[0]);
}
}
if ((resolver.getAddedResources() != null) &&
- (resolver.getAddedResources().length > 0))
- {
- if (resolver.resolve())
- {
+ (resolver.getAddedResources().length > 0)) {
+ if (resolver.resolve(deployOptional ? 0 : Resolver.NO_OPTIONAL_RESOURCES)) {
System.out.println("Target resource(s):");
printUnderline(System.out, 19);
Resource[] resources = resolver.getAddedResources();
- for (int resIdx = 0; (resources != null) && (resIdx < resources.length); resIdx++)
- {
+ for (int resIdx = 0; (resources != null) && (resIdx < resources.length); resIdx++) {
System.out.println(" " + resources[resIdx].getPresentationName()
- + " (" + resources[resIdx].getVersion() + ")");
+ + " (" + resources[resIdx].getVersion() + ")");
}
resources = resolver.getRequiredResources();
- if ((resources != null) && (resources.length > 0))
- {
+ if ((resources != null) && (resources.length > 0)) {
System.out.println("\nRequired resource(s):");
printUnderline(System.out, 21);
- for (int resIdx = 0; resIdx < resources.length; resIdx++)
- {
+ for (int resIdx = 0; resIdx < resources.length; resIdx++) {
System.out.println(" " + resources[resIdx].getPresentationName()
- + " (" + resources[resIdx].getVersion() + ")");
+ + " (" + resources[resIdx].getVersion() + ")");
}
}
- resources = resolver.getOptionalResources();
- if ((resources != null) && (resources.length > 0))
- {
- System.out.println("\nOptional resource(s):");
- printUnderline(System.out, 21);
- for (int resIdx = 0; resIdx < resources.length; resIdx++)
- {
- System.out.println(" " + resources[resIdx].getPresentationName()
- + " (" + resources[resIdx].getVersion() + ")");
+ if (deployOptional) {
+ resources = resolver.getOptionalResources();
+ if ((resources != null) && (resources.length > 0)) {
+ System.out.println("\nOptional resource(s):");
+ printUnderline(System.out, 21);
+ for (int resIdx = 0; resIdx < resources.length; resIdx++) {
+ System.out.println(" " + resources[resIdx].getPresentationName() + " (" + resources[resIdx].getVersion() + ")");
+ }
}
}
- try
- {
+ try {
System.out.print("\nDeploying...");
resolver.deploy(start ? Resolver.START : 0);
System.out.println("done.");
- }
- catch (IllegalStateException ex)
- {
+ } catch (IllegalStateException ex) {
System.err.println(ex);
}
- }
- else
- {
+ } else {
Reason[] reqs = resolver.getUnsatisfiedRequirements();
- if ((reqs != null) && (reqs.length > 0))
- {
+ if ((reqs != null) && (reqs.length > 0)) {
System.out.println("Unsatisfied requirement(s):");
printUnderline(System.out, 27);
- for (int reqIdx = 0; reqIdx < reqs.length; reqIdx++)
- {
+ for (int reqIdx = 0; reqIdx < reqs.length; reqIdx++) {
System.out.println(" " + reqs[reqIdx].getRequirement().getFilter());
System.out.println(" " + reqs[reqIdx].getResource().getPresentationName());
}
- }
- else
- {
+ } else {
System.out.println("Could not resolve targets.");
}
}
Modified: karaf/trunk/obr/command/src/main/java/org/apache/karaf/obr/command/StartCommand.java
URL: http://svn.apache.org/viewvc/karaf/trunk/obr/command/src/main/java/org/apache/karaf/obr/command/StartCommand.java?rev=1393973&r1=1393972&r2=1393973&view=diff
==============================================================================
--- karaf/trunk/obr/command/src/main/java/org/apache/karaf/obr/command/StartCommand.java (original)
+++ karaf/trunk/obr/command/src/main/java/org/apache/karaf/obr/command/StartCommand.java Thu Oct 4 09:57:37 2012
@@ -17,13 +17,23 @@
package org.apache.karaf.obr.command;
import org.apache.felix.bundlerepository.RepositoryAdmin;
+import org.apache.karaf.shell.commands.Argument;
import org.apache.karaf.shell.commands.Command;
+import org.apache.karaf.shell.commands.Option;
+
+import java.util.List;
@Command(scope = "obr", name = "start", description = "Deploys and starts a list of bundles using OBR.")
-public class StartCommand extends DeployCommand {
+public class StartCommand extends ObrCommandSupport {
+
+ @Argument(index = 0, name = "bundles", description = "List of bundles to deploy (separated by whitespaces)", required = true, multiValued = true)
+ protected List<String> bundles;
+
+ @Option(name = "-d", aliases = { "--deployOptional" }, description = "Deploy optional bundles", required = false, multiValued = false)
+ protected boolean deployOptional = false;
protected void doExecute(RepositoryAdmin admin) throws Exception {
- doDeploy(admin, bundles, true);
+ doDeploy(admin, bundles, true, deployOptional);
}
}
Modified: karaf/trunk/obr/core/src/main/java/org/apache/karaf/obr/core/ObrMBean.java
URL: http://svn.apache.org/viewvc/karaf/trunk/obr/core/src/main/java/org/apache/karaf/obr/core/ObrMBean.java?rev=1393973&r1=1393972&r2=1393973&view=diff
==============================================================================
--- karaf/trunk/obr/core/src/main/java/org/apache/karaf/obr/core/ObrMBean.java (original)
+++ karaf/trunk/obr/core/src/main/java/org/apache/karaf/obr/core/ObrMBean.java Thu Oct 4 09:57:37 2012
@@ -32,5 +32,5 @@ public interface ObrMBean {
void refreshUrl(String url) throws Exception;
void deployBundle(String bundle) throws Exception;
- void deployBundle(String bundle, boolean start) throws Exception;
+ void deployBundle(String bundle, boolean start, boolean deployOptional) throws Exception;
}
Modified: karaf/trunk/obr/core/src/main/java/org/apache/karaf/obr/core/internal/Obr.java
URL: http://svn.apache.org/viewvc/karaf/trunk/obr/core/src/main/java/org/apache/karaf/obr/core/internal/Obr.java?rev=1393973&r1=1393972&r2=1393973&view=diff
==============================================================================
--- karaf/trunk/obr/core/src/main/java/org/apache/karaf/obr/core/internal/Obr.java (original)
+++ karaf/trunk/obr/core/src/main/java/org/apache/karaf/obr/core/internal/Obr.java Thu Oct 4 09:57:37 2012
@@ -102,10 +102,10 @@ public class Obr extends StandardMBean i
}
public void deployBundle(String bundle) throws Exception {
- deployBundle(bundle, false);
+ deployBundle(bundle, false, false);
}
- public void deployBundle(String bundle, boolean start) throws Exception {
+ public void deployBundle(String bundle, boolean start, boolean deployOptional) throws Exception {
Resolver resolver = repositoryAdmin.resolver();
String[] target = getTarget(bundle);
Resource resource = selectNewestVersion(searchRepository(repositoryAdmin, target[0], target[1]));
@@ -115,16 +115,12 @@ public class Obr extends StandardMBean i
resolver.add(resource);
if ((resolver.getAddedResources() != null) &&
(resolver.getAddedResources().length > 0)) {
- }
- if (resolver.resolve()) {
- Resource[] resources = resolver.getAddedResources();
- resources = resolver.getRequiredResources();
- resources = resolver.getOptionalResources();
-
- try {
- resolver.deploy(start ? Resolver.START : 0);
- } catch (IllegalStateException ex) {
- throw new IllegalStateException("Can't deploy using OBR", ex);
+ if (resolver.resolve(deployOptional ? 0 : Resolver.NO_OPTIONAL_RESOURCES)) {
+ try {
+ resolver.deploy(start ? Resolver.START : 0);
+ } catch (IllegalStateException ex) {
+ throw new IllegalStateException("Can't deploy using OBR", ex);
+ }
}
}
}