1 package org
.argeo
.slc
.equinox
;
3 import org
.apache
.commons
.logging
.Log
;
4 import org
.apache
.commons
.logging
.LogFactory
;
5 import org
.argeo
.slc
.SlcException
;
6 import org
.argeo
.slc
.osgi
.OsgiExecutionModulesManager
;
7 import org
.argeo
.slc
.process
.RealizedFlow
;
8 import org
.eclipse
.core
.runtime
.adaptor
.EclipseStarter
;
9 import org
.eclipse
.osgi
.framework
.console
.CommandInterpreter
;
10 import org
.eclipse
.osgi
.framework
.console
.CommandProvider
;
12 public class ExecutionCommandProvider
implements CommandProvider
{
13 private final static Log log
= LogFactory
14 .getLog(ExecutionCommandProvider
.class);
16 private final static String SLC_WITH_REFRESH
= "slc";
17 private final static String SLC_NO_REFRESH
= "slcnr";
19 private OsgiExecutionModulesManager modulesManager
;
21 private RealizedFlow lastLaunch
= null;
23 public Object
_slc(CommandInterpreter ci
) {
24 return exec(SLC_WITH_REFRESH
, ci
);
27 public Object
_slcnr(CommandInterpreter ci
) {
28 return exec(SLC_NO_REFRESH
, ci
);
31 protected Object
exec(String slcCommand
, CommandInterpreter ci
) {
32 // TODO: check version
33 String firstArg
= ci
.nextArgument();
34 if (firstArg
== null) {
35 if (lastLaunch
!= null) {
36 String cmd
= slcCommand
+ " " + lastLaunch
.getModuleName()
37 + " " + lastLaunch
.getFlowDescriptor().getName();
38 if (log
.isDebugEnabled())
39 log
.debug("Execute again last command: " + cmd
);
40 return ci
.execute(cmd
);
43 throw new SlcException("Command not properly formatted");
46 String executionName
= ci
.nextArgument();
48 launch(slcCommand
, firstArg
, executionName
);
49 return "COMMAND COMPLETED";
52 protected void launch(String slcCommand
, String firstArg
,
53 String executionName
) {
54 lastLaunch
= modulesManager
.findRealizedFlow(firstArg
, executionName
);
55 if (lastLaunch
== null)
56 throw new SlcException("Cannot find launch for " + firstArg
+ " "
60 if (SLC_WITH_REFRESH
.equals(slcCommand
))
61 modulesManager
.updateAndExecute(lastLaunch
);
62 else if (SLC_NO_REFRESH
.equals(slcCommand
))
63 modulesManager
.execute(lastLaunch
);
65 throw new SlcException("Unrecognized SLC command " + slcCommand
);
68 public String
getHelp() {
69 StringBuffer buf
= new StringBuffer();
70 buf
.append("---SLC Execution Commands---\n");
72 .append("\tslc (<id>|<segment of bsn>) <execution bean>"
73 + " - refresh the bundle, execute an execution flow (without arg, execute last)\n");
75 .append("\tslcnr (<id>|<segment of bsn>) <execution bean>"
76 + " - execute an execution flow (without arg, execute last)\n");
77 return buf
.toString();
81 public void setModulesManager(OsgiExecutionModulesManager osgiModulesManager
) {
82 this.modulesManager
= osgiModulesManager
;
85 public void init() throws Exception
{
86 final String module
= System
.getProperty("slc.launch.module");
87 final String executionName
= System
.getProperty("slc.launch.execution");
94 launch(SLC_NO_REFRESH
, module
, executionName
);
95 // in case of failure OSGi runtime stays up and last
96 // launch can be used to debug by calling 'slc'
97 } catch (Exception e
) {
98 throw new SlcException("Error when executing "
99 + executionName
+ " on " + module
, e
);
102 EclipseStarter
.shutdown();
103 } catch (Exception e
) {
104 throw new SlcException("Cannot shutdown equinox.", e
);