2 * Copyright (C) 2007-2012 Mathieu Baudier
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
.osgi
.OsgiExecutionModulesManager
;
22 import org
.argeo
.slc
.process
.RealizedFlow
;
23 import org
.eclipse
.osgi
.framework
.console
.CommandInterpreter
;
24 import org
.eclipse
.osgi
.framework
.console
.CommandProvider
;
26 @SuppressWarnings("restriction")
27 public class ExecutionCommandProvider
implements CommandProvider
{
28 private final static Log log
= LogFactory
29 .getLog(ExecutionCommandProvider
.class);
31 private final static String SLC_WITH_REFRESH
= "slc";
32 private final static String SLC_NO_REFRESH
= "slcnr";
34 private OsgiExecutionModulesManager modulesManager
;
36 private RealizedFlow lastLaunch
= null;
38 public Object
_slc(CommandInterpreter ci
) {
39 return exec(SLC_WITH_REFRESH
, ci
);
42 public Object
_slcnr(CommandInterpreter ci
) {
43 return exec(SLC_NO_REFRESH
, ci
);
46 protected Object
exec(String slcCommand
, CommandInterpreter ci
) {
47 // TODO: check version
48 String firstArg
= ci
.nextArgument();
49 if (firstArg
== null) {
50 if (lastLaunch
!= null) {
51 String cmd
= slcCommand
+ " " + lastLaunch
.getModuleName()
52 + " " + lastLaunch
.getFlowDescriptor().getName();
53 if (log
.isDebugEnabled())
54 log
.debug("Execute again last command: " + cmd
);
55 return ci
.execute(cmd
);
58 throw new SlcException("Command not properly formatted");
61 String executionName
= ci
.nextArgument();
63 launch(slcCommand
, firstArg
, executionName
);
64 return "COMMAND COMPLETED";
67 protected void launch(String slcCommand
, String firstArg
,
68 String executionName
) {
69 lastLaunch
= modulesManager
.findRealizedFlow(firstArg
, executionName
);
70 if (lastLaunch
== null)
71 throw new SlcException("Cannot find launch for " + firstArg
+ " "
75 if (SLC_WITH_REFRESH
.equals(slcCommand
)) {
76 modulesManager
.upgrade(lastLaunch
.getModuleNameVersion());
77 modulesManager
.execute(lastLaunch
);
78 } else if (SLC_NO_REFRESH
.equals(slcCommand
))
79 modulesManager
.execute(lastLaunch
);
81 throw new SlcException("Unrecognized SLC command " + slcCommand
);
84 public String
getHelp() {
85 StringBuffer buf
= new StringBuffer();
86 buf
.append("---SLC Execution Commands---\n");
88 .append("\tslc (<id>|<segment of bsn>) <execution bean>"
89 + " - refresh the bundle, execute an execution flow (without arg, execute last)\n");
91 .append("\tslcnr (<id>|<segment of bsn>) <execution bean>"
92 + " - execute an execution flow (without arg, execute last)\n");
93 return buf
.toString();
97 public void setModulesManager(OsgiExecutionModulesManager osgiModulesManager
) {
98 this.modulesManager
= osgiModulesManager
;