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
.upgrade(lastLaunch
.getModuleNameVersion());
63 modulesManager
.execute(lastLaunch
);
64 } else if (SLC_NO_REFRESH
.equals(slcCommand
))
65 modulesManager
.execute(lastLaunch
);
67 throw new SlcException("Unrecognized SLC command " + slcCommand
);
70 public String
getHelp() {
71 StringBuffer buf
= new StringBuffer();
72 buf
.append("---SLC Execution Commands---\n");
74 .append("\tslc (<id>|<segment of bsn>) <execution bean>"
75 + " - refresh the bundle, execute an execution flow (without arg, execute last)\n");
77 .append("\tslcnr (<id>|<segment of bsn>) <execution bean>"
78 + " - execute an execution flow (without arg, execute last)\n");
79 return buf
.toString();
83 public void setModulesManager(OsgiExecutionModulesManager osgiModulesManager
) {
84 this.modulesManager
= osgiModulesManager
;
87 public void init() throws Exception
{
88 final String module
= System
.getProperty("slc.launch.module");
89 final String executionName
= System
.getProperty("slc.launch.execution");
96 launch(SLC_NO_REFRESH
, module
, executionName
);
97 // in case of failure OSGi runtime stays up and last
98 // launch can be used to debug by calling 'slc'
99 } catch (Exception e
) {
100 throw new SlcException("Error when executing "
101 + executionName
+ " on " + module
, e
);
104 EclipseStarter
.shutdown();
105 } catch (Exception e
) {
106 throw new SlcException("Cannot shutdown equinox.", e
);