2 * Copyright (C) 2007-2012 Argeo GmbH
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package org
.argeo
.slc
.equinox
;
18 import org
.apache
.commons
.logging
.Log
;
19 import org
.apache
.commons
.logging
.LogFactory
;
20 import org
.argeo
.slc
.SlcException
;
21 import org
.argeo
.slc
.execution
.RealizedFlow
;
22 import org
.argeo
.slc
.osgi
.OsgiExecutionModulesManager
;
23 import org
.eclipse
.osgi
.framework
.console
.CommandInterpreter
;
24 import org
.eclipse
.osgi
.framework
.console
.CommandProvider
;
26 public class ExecutionCommandProvider
implements CommandProvider
{
27 private final static Log log
= LogFactory
28 .getLog(ExecutionCommandProvider
.class);
30 private final static String SLC_WITH_REFRESH
= "slc";
31 private final static String SLC_NO_REFRESH
= "slcnr";
33 private OsgiExecutionModulesManager modulesManager
;
35 private RealizedFlow lastLaunch
= null;
37 public Object
_slc(CommandInterpreter ci
) {
38 return exec(SLC_WITH_REFRESH
, ci
);
41 public Object
_slcnr(CommandInterpreter ci
) {
42 return exec(SLC_NO_REFRESH
, ci
);
45 protected Object
exec(String slcCommand
, CommandInterpreter ci
) {
46 // TODO: check version
47 String firstArg
= ci
.nextArgument();
48 if (firstArg
== null) {
49 if (lastLaunch
!= null) {
50 String cmd
= slcCommand
+ " " + lastLaunch
.getModuleName()
51 + " " + lastLaunch
.getFlowDescriptor().getName();
52 if (log
.isDebugEnabled())
53 log
.debug("Execute again last command: " + cmd
);
54 return ci
.execute(cmd
);
57 throw new SlcException("Command not properly formatted");
60 String executionName
= ci
.nextArgument();
62 launch(slcCommand
, firstArg
, executionName
);
63 return "COMMAND COMPLETED";
66 protected void launch(String slcCommand
, String firstArg
,
67 String executionName
) {
68 lastLaunch
= modulesManager
.findRealizedFlow(firstArg
, executionName
);
69 if (lastLaunch
== null)
70 throw new SlcException("Cannot find launch for " + firstArg
+ " "
74 if (SLC_WITH_REFRESH
.equals(slcCommand
)) {
75 modulesManager
.upgrade(lastLaunch
.getModuleNameVersion());
76 modulesManager
.execute(lastLaunch
);
77 } else if (SLC_NO_REFRESH
.equals(slcCommand
))
78 modulesManager
.execute(lastLaunch
);
80 throw new SlcException("Unrecognized SLC command " + slcCommand
);
83 public String
getHelp() {
84 StringBuffer buf
= new StringBuffer();
85 buf
.append("---SLC Execution Commands---\n");
87 .append("\tslc (<id>|<segment of bsn>) <execution bean>"
88 + " - refresh the bundle, execute an execution flow (without arg, execute last)\n");
90 .append("\tslcnr (<id>|<segment of bsn>) <execution bean>"
91 + " - execute an execution flow (without arg, execute last)\n");
92 return buf
.toString();
96 public void setModulesManager(OsgiExecutionModulesManager osgiModulesManager
) {
97 this.modulesManager
= osgiModulesManager
;