X-Git-Url: http://git.argeo.org/?a=blobdiff_plain;f=runtime%2Forg.argeo.slc.support.equinox%2Fsrc%2Fmain%2Fjava%2Forg%2Fargeo%2Fslc%2Fequinox%2FExecutionCommandProvider.java;h=3a90807807225921eee47c728f3d25446e61712a;hb=c83e59caa846134d0a2d5eff2485d994255c12cc;hp=ca49e8fdc6b8db7370f79ed26d0343b2d215c5c3;hpb=1f0b304d0a789fff4fec7005a59dedaa40a0b61d;p=gpl%2Fargeo-slc.git diff --git a/runtime/org.argeo.slc.support.equinox/src/main/java/org/argeo/slc/equinox/ExecutionCommandProvider.java b/runtime/org.argeo.slc.support.equinox/src/main/java/org/argeo/slc/equinox/ExecutionCommandProvider.java index ca49e8fdc..3a9080780 100644 --- a/runtime/org.argeo.slc.support.equinox/src/main/java/org/argeo/slc/equinox/ExecutionCommandProvider.java +++ b/runtime/org.argeo.slc.support.equinox/src/main/java/org/argeo/slc/equinox/ExecutionCommandProvider.java @@ -1,41 +1,99 @@ package org.argeo.slc.equinox; +import java.util.ArrayList; +import java.util.Iterator; import java.util.List; +import org.argeo.slc.SlcException; +import org.argeo.slc.execution.ExecutionFlowDescriptor; import org.argeo.slc.execution.ExecutionModule; -import org.argeo.slc.process.SlcExecution; import org.eclipse.osgi.framework.console.CommandInterpreter; import org.eclipse.osgi.framework.console.CommandProvider; +import org.osgi.framework.Bundle; +import org.osgi.framework.BundleContext; +import org.osgi.framework.BundleException; +import org.osgi.framework.ServiceReference; +import org.springframework.osgi.context.BundleContextAware; -public class ExecutionCommandProvider implements CommandProvider { +public class ExecutionCommandProvider implements CommandProvider, + BundleContextAware { private List executionModules; + private BundleContext bundleContext; - public Object _slc_execute(CommandInterpreter ci) { - String moduleName = ci.nextArgument(); + public Object _slc_exec(CommandInterpreter ci) { + // TODO: check version + String firstArg = ci.nextArgument(); String executionName = ci.nextArgument(); - - SlcExecution slcExecution = new SlcExecution(); - slcExecution.getAttributes().put("slc.flows", executionName); + String moduleName = null; + Long bundleId = null; + try { + bundleId = Long.parseLong(firstArg); + } catch (NumberFormatException e) { + // silent + } + + Bundle bundle = null; + if (bundleId != null) { + bundle = bundleContext.getBundle(bundleId); + } else { + for (Bundle b : bundleContext.getBundles()) { + if (b.getSymbolicName().contains(firstArg)) { + bundle = b; + break; + } + } + } + + if (bundle != null) { + moduleName = bundle.getSymbolicName(); +// try { +// bundle.stop(); +// bundle.update(); +// bundle.start(); +// +// // FIXME: potential infinite loop +// while (bundle.getState() == Bundle.STARTING) { +// try { +// Thread.sleep(500); +// } catch (InterruptedException e) { +// // silent +// } +// } +// } catch (BundleException e) { +// throw new SlcException( +// "Could not update the bundle for module " + moduleName, +// e); +// } + } + + // Find module ExecutionModule module = null; - for (ExecutionModule moduleT : executionModules) { - if(moduleT.getName().equals(moduleName)){ - // TODO: check version - module = moduleT; - break; + if (moduleName != null) { + for (Iterator it = executionModules.iterator(); it + .hasNext();) { + ExecutionModule moduleT = it.next(); + if (moduleT.getName().equals(moduleName)) { + module = moduleT; + break; + } } } - if(module!=null) - module.execute(slcExecution); - - return null; + if (module != null) { + ExecutionFlowDescriptor descriptor = new ExecutionFlowDescriptor(); + descriptor.setName(executionName); + module.execute(descriptor); + return "Executed " + executionName + " from " + moduleName; + } else + return "Could not find any execution module matching these requirements."; } public String getHelp() { StringBuffer buf = new StringBuffer(); buf.append("---SLC Execution Commands---\n"); - buf.append("\tslc_execute - Execute an execution flow\n"); + buf + .append("\tslc_exec (|) - execute an execution flow\n"); return buf.toString(); } @@ -44,4 +102,8 @@ public class ExecutionCommandProvider implements CommandProvider { this.executionModules = executionModules; } + public void setBundleContext(BundleContext bundleContext) { + this.bundleContext = bundleContext; + } + }