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 @SuppressWarnings("restriction")
13 public class ExecutionCommandProvider
implements CommandProvider
{
14 private final static Log log
= LogFactory
15 .getLog(ExecutionCommandProvider
.class);
17 private final static String SLC_WITH_REFRESH
= "slc";
18 private final static String SLC_NO_REFRESH
= "slcnr";
20 private OsgiExecutionModulesManager modulesManager
;
22 private RealizedFlow lastLaunch
= null;
24 public Object
_slc(CommandInterpreter ci
) {
25 return exec(SLC_WITH_REFRESH
, ci
);
28 public Object
_slcnr(CommandInterpreter ci
) {
29 return exec(SLC_NO_REFRESH
, ci
);
32 protected Object
exec(String slcCommand
, CommandInterpreter ci
) {
33 // TODO: check version
34 String firstArg
= ci
.nextArgument();
35 if (firstArg
== null) {
36 if (lastLaunch
!= null) {
37 String cmd
= slcCommand
+ " " + lastLaunch
.getModuleName()
38 + " " + lastLaunch
.getFlowDescriptor().getName();
39 if (log
.isDebugEnabled())
40 log
.debug("Execute again last command: " + cmd
);
41 return ci
.execute(cmd
);
44 throw new SlcException("Command not properly formatted");
47 String executionName
= ci
.nextArgument();
49 launch(slcCommand
, firstArg
, executionName
);
50 return "COMMAND COMPLETED";
53 protected void launch(String slcCommand
, String firstArg
,
54 String executionName
) {
55 lastLaunch
= modulesManager
.findRealizedFlow(firstArg
, executionName
);
56 if (lastLaunch
== null)
57 throw new SlcException("Cannot find launch for " + firstArg
+ " "
61 if (SLC_WITH_REFRESH
.equals(slcCommand
))
62 modulesManager
.updateAndExecute(lastLaunch
);
63 else if (SLC_NO_REFRESH
.equals(slcCommand
))
64 modulesManager
.execute(lastLaunch
);
66 throw new SlcException("Unrecognized SLC command " + slcCommand
);
69 public String
getHelp() {
70 StringBuffer buf
= new StringBuffer();
71 buf
.append("---SLC Execution Commands---\n");
73 .append("\tslc (<id>|<segment of bsn>) <execution bean>"
74 + " - refresh the bundle, execute an execution flow (without arg, execute last)\n");
76 .append("\tslcnr (<id>|<segment of bsn>) <execution bean>"
77 + " - execute an execution flow (without arg, execute last)\n");
78 return buf
.toString();
82 public void setModulesManager(OsgiExecutionModulesManager osgiModulesManager
) {
83 this.modulesManager
= osgiModulesManager
;
86 public void init() throws Exception
{
87 final String module
= System
.getProperty("slc.launch.module");
88 final String executionName
= System
.getProperty("slc.launch.execution");
95 launch(SLC_NO_REFRESH
, module
, executionName
);
96 // in case of failure OSGi runtime stays up and last
97 // launch can be used to debug by calling 'slc'
98 } catch (Exception e
) {
99 throw new SlcException("Error when executing "
100 + executionName
+ " on " + module
, e
);
103 EclipseStarter
.shutdown();
104 } catch (Exception e
) {
105 throw new SlcException("Cannot shutdown equinox.", e
);