]> git.argeo.org Git - gpl/argeo-slc.git/blob - runtime/org.argeo.slc.support.equinox/src/main/java/org/argeo/slc/equinox/ExecutionCommandProvider.java
Prepare next development cycle
[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 @SuppressWarnings("restriction")
27 public class ExecutionCommandProvider implements CommandProvider {
28 private final static Log log = LogFactory
29 .getLog(ExecutionCommandProvider.class);
30
31 private final static String SLC_WITH_REFRESH = "slc";
32 private final static String SLC_NO_REFRESH = "slcnr";
33
34 private OsgiExecutionModulesManager modulesManager;
35
36 private RealizedFlow lastLaunch = null;
37
38 public Object _slc(CommandInterpreter ci) {
39 return exec(SLC_WITH_REFRESH, ci);
40 }
41
42 public Object _slcnr(CommandInterpreter ci) {
43 return exec(SLC_NO_REFRESH, ci);
44 }
45
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);
56 } else {
57 ci.execute("help");
58 throw new SlcException("Command not properly formatted");
59 }
60 }
61 String executionName = ci.nextArgument();
62
63 launch(slcCommand, firstArg, executionName);
64 return "COMMAND COMPLETED";
65 }
66
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 + " "
72 + executionName);
73
74 // Execute
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);
80 else
81 throw new SlcException("Unrecognized SLC command " + slcCommand);
82 }
83
84 public String getHelp() {
85 StringBuffer buf = new StringBuffer();
86 buf.append("---SLC Execution Commands---\n");
87 buf
88 .append("\tslc (<id>|<segment of bsn>) <execution bean>"
89 + " - refresh the bundle, execute an execution flow (without arg, execute last)\n");
90 buf
91 .append("\tslcnr (<id>|<segment of bsn>) <execution bean>"
92 + " - execute an execution flow (without arg, execute last)\n");
93 return buf.toString();
94
95 }
96
97 public void setModulesManager(OsgiExecutionModulesManager osgiModulesManager) {
98 this.modulesManager = osgiModulesManager;
99 }
100
101 }