]> git.argeo.org Git - gpl/argeo-slc.git/blob - runtime/org.argeo.slc.support.equinox/src/main/java/org/argeo/slc/equinox/ExecutionCommandProvider.java
Start repairing SLC console command
[gpl/argeo-slc.git] / runtime / org.argeo.slc.support.equinox / src / main / java / org / argeo / slc / equinox / ExecutionCommandProvider.java
1 /*
2 * Copyright (C) 2007-2012 Argeo GmbH
3 *
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
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
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.
15 */
16 package org.argeo.slc.equinox;
17
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;
25
26 public class ExecutionCommandProvider implements CommandProvider {
27 private final static Log log = LogFactory
28 .getLog(ExecutionCommandProvider.class);
29
30 private final static String SLC_WITH_REFRESH = "slc";
31 private final static String SLC_NO_REFRESH = "slcnr";
32
33 private OsgiExecutionModulesManager modulesManager;
34
35 private RealizedFlow lastLaunch = null;
36
37 public Object _slc(CommandInterpreter ci) {
38 return exec(SLC_WITH_REFRESH, ci);
39 }
40
41 public Object _slcnr(CommandInterpreter ci) {
42 return exec(SLC_NO_REFRESH, ci);
43 }
44
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);
55 } else {
56 ci.execute("help");
57 throw new SlcException("Command not properly formatted");
58 }
59 }
60 String executionName = ci.nextArgument();
61
62 launch(slcCommand, firstArg, executionName);
63 return "COMMAND COMPLETED";
64 }
65
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 + " "
71 + executionName);
72
73 // Execute
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);
79 else
80 throw new SlcException("Unrecognized SLC command " + slcCommand);
81 }
82
83 public String getHelp() {
84 StringBuffer buf = new StringBuffer();
85 buf.append("---SLC Execution Commands---\n");
86 buf
87 .append("\tslc (<id>|<segment of bsn>) <execution bean>"
88 + " - refresh the bundle, execute an execution flow (without arg, execute last)\n");
89 buf
90 .append("\tslcnr (<id>|<segment of bsn>) <execution bean>"
91 + " - execute an execution flow (without arg, execute last)\n");
92 return buf.toString();
93
94 }
95
96 public void setModulesManager(OsgiExecutionModulesManager osgiModulesManager) {
97 this.modulesManager = osgiModulesManager;
98 }
99
100 }