2 * Copyright (C) 2010 Mathieu Baudier <mbaudier@argeo.org>
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.
17 package org
.argeo
.slc
.equinox
;
19 import org
.apache
.commons
.logging
.Log
;
20 import org
.apache
.commons
.logging
.LogFactory
;
21 import org
.argeo
.slc
.SlcException
;
22 import org
.argeo
.slc
.osgi
.OsgiExecutionModulesManager
;
23 import org
.argeo
.slc
.process
.RealizedFlow
;
24 import org
.eclipse
.osgi
.framework
.console
.CommandInterpreter
;
25 import org
.eclipse
.osgi
.framework
.console
.CommandProvider
;
27 @SuppressWarnings("restriction")
28 public class ExecutionCommandProvider
implements CommandProvider
{
29 private final static Log log
= LogFactory
30 .getLog(ExecutionCommandProvider
.class);
32 private final static String SLC_WITH_REFRESH
= "slc";
33 private final static String SLC_NO_REFRESH
= "slcnr";
35 private OsgiExecutionModulesManager modulesManager
;
37 private RealizedFlow lastLaunch
= null;
39 public Object
_slc(CommandInterpreter ci
) {
40 return exec(SLC_WITH_REFRESH
, ci
);
43 public Object
_slcnr(CommandInterpreter ci
) {
44 return exec(SLC_NO_REFRESH
, ci
);
47 protected Object
exec(String slcCommand
, CommandInterpreter ci
) {
48 // TODO: check version
49 String firstArg
= ci
.nextArgument();
50 if (firstArg
== null) {
51 if (lastLaunch
!= null) {
52 String cmd
= slcCommand
+ " " + lastLaunch
.getModuleName()
53 + " " + lastLaunch
.getFlowDescriptor().getName();
54 if (log
.isDebugEnabled())
55 log
.debug("Execute again last command: " + cmd
);
56 return ci
.execute(cmd
);
59 throw new SlcException("Command not properly formatted");
62 String executionName
= ci
.nextArgument();
64 launch(slcCommand
, firstArg
, executionName
);
65 return "COMMAND COMPLETED";
68 protected void launch(String slcCommand
, String firstArg
,
69 String executionName
) {
70 lastLaunch
= modulesManager
.findRealizedFlow(firstArg
, executionName
);
71 if (lastLaunch
== null)
72 throw new SlcException("Cannot find launch for " + firstArg
+ " "
76 if (SLC_WITH_REFRESH
.equals(slcCommand
)) {
77 modulesManager
.upgrade(lastLaunch
.getModuleNameVersion());
78 modulesManager
.execute(lastLaunch
);
79 } else if (SLC_NO_REFRESH
.equals(slcCommand
))
80 modulesManager
.execute(lastLaunch
);
82 throw new SlcException("Unrecognized SLC command " + slcCommand
);
85 public String
getHelp() {
86 StringBuffer buf
= new StringBuffer();
87 buf
.append("---SLC Execution Commands---\n");
89 .append("\tslc (<id>|<segment of bsn>) <execution bean>"
90 + " - refresh the bundle, execute an execution flow (without arg, execute last)\n");
92 .append("\tslcnr (<id>|<segment of bsn>) <execution bean>"
93 + " - execute an execution flow (without arg, execute last)\n");
94 return buf
.toString();
98 public void setModulesManager(OsgiExecutionModulesManager osgiModulesManager
) {
99 this.modulesManager
= osgiModulesManager
;