Révision 3637
TXM/trunk/org.txm.rcp/src/main/java/org/txm/rcp/Application.java (revision 3637) | ||
---|---|---|
311 | 311 |
} |
312 | 312 |
|
313 | 313 |
if (argsList.contains("--action=new")) { |
314 |
String path = argsList.get(argsList.size() -2);
|
|
314 |
String path = argsList.get(argsList.indexOf("--action=new") + 1);
|
|
315 | 315 |
File sourcePath = new File(path); |
316 | 316 |
|
317 |
String name = argsList.get(argsList.size() -1);
|
|
317 |
String name = argsList.get(argsList.indexOf("--action=new") + 2);
|
|
318 | 318 |
|
319 | 319 |
ret = doNew(sourcePath, name); |
320 | 320 |
|
... | ... | |
339 | 339 |
} else if (argsList.contains("--action=groovy")) { |
340 | 340 |
|
341 | 341 |
|
342 |
String path = argsList.get(argsList.size() -1).trim();
|
|
342 |
String path = argsList.get(argsList.indexOf("--action=groovy") + 1).trim();
|
|
343 | 343 |
|
344 | 344 |
ret = doGroovy(path, argsList); |
345 | 345 |
} else if (argsList.contains("--action=R")) { |
... | ... | |
370 | 370 |
if (!script.isFile()) return -1; |
371 | 371 |
if (!script.exists()) return -1; |
372 | 372 |
if (!script.getName().endsWith(".groovy")) return -1; |
373 |
ExecuteScript.executeScript(path, null, new StructuredSelection(), argsList); |
|
373 |
try { |
|
374 |
JobHandler job = ExecuteScript.executeScript(path, null, new StructuredSelection(), argsList); |
|
375 |
if (job != null) { |
|
376 |
job.join(); |
|
377 |
} |
|
378 |
} catch(Throwable e) { |
|
379 |
e.printStackTrace(); |
|
380 |
return -1; |
|
381 |
} |
|
374 | 382 |
return 0; |
375 | 383 |
} |
376 | 384 |
|
... | ... | |
380 | 388 |
if (!script.isFile()) return -1; |
381 | 389 |
if (!script.exists()) return -1; |
382 | 390 |
if (!script.getName().endsWith(".R")) return -1; |
391 |
|
|
383 | 392 |
EnginesManager<? extends Engine> em = Toolbox.getEngineManager(EngineType.STATS); |
384 | 393 |
if (em == null) return -1; |
385 | 394 |
|
386 | 395 |
Engine e = em.getEngine("R"); |
387 | 396 |
if (e == null || !e.isRunning()) return -1; |
388 | 397 |
|
389 |
ExecuteScript.executeScript(path, null, new StructuredSelection(), argsList); |
|
398 |
JobHandler job = ExecuteScript.executeScript(path, null, new StructuredSelection(), argsList); |
|
399 |
if (job != null) { |
|
400 |
try { |
|
401 |
job.join(); |
|
402 |
} catch (Throwable e1) { |
|
403 |
e1.printStackTrace(); |
|
404 |
return -1; |
|
405 |
} |
|
406 |
} |
|
390 | 407 |
|
391 | 408 |
return 0; |
392 | 409 |
} |
TXM/trunk/org.txm.rcp/src/main/java/org/txm/rcp/utils/JobHandler.java (revision 3637) | ||
---|---|---|
29 | 29 |
|
30 | 30 |
import java.util.concurrent.Semaphore; |
31 | 31 |
|
32 |
import org.eclipse.core.resources.ResourcesPlugin; |
|
33 | 32 |
import org.eclipse.core.runtime.IProgressMonitor; |
34 |
import org.eclipse.core.runtime.jobs.ISchedulingRule; |
|
35 | 33 |
import org.eclipse.core.runtime.jobs.Job; |
36 |
import org.eclipse.swt.widgets.Composite; |
|
37 | 34 |
import org.eclipse.swt.widgets.Display; |
38 |
import org.eclipse.ui.internal.progress.ProgressManagerUtil; |
|
39 |
import org.eclipse.ui.texteditor.ISchedulingRuleProvider; |
|
40 | 35 |
import org.txm.rcp.Application; |
41 | 36 |
import org.txm.rcp.StatusLine; |
42 | 37 |
import org.txm.rcp.messages.TXMUIMessages; |
TXM/trunk/org.txm.rcp/src/main/java/org/txm/rcp/handlers/scripts/ExecuteGroovyMacro.java (revision 3637) | ||
---|---|---|
52 | 52 |
import org.txm.Toolbox; |
53 | 53 |
import org.txm.rcp.editors.TxtEditor; |
54 | 54 |
import org.txm.rcp.swt.dialog.LastOpened; |
55 |
import org.txm.rcp.utils.JobHandler; |
|
55 | 56 |
// TODO: Auto-generated Javadoc |
56 | 57 |
/** |
57 | 58 |
* Handler: execute a Macro (Groovy script that opens an UI for parameters) |
... | ... | |
120 | 121 |
return execute(result, page, selection, stringArgs, null, null); |
121 | 122 |
} |
122 | 123 |
|
123 |
public static IStatus execute(String scriptpath, IWorkbenchPart page, ISelection selection, List<String> args, HashMap<String, Object> parameters, HashMap<String, Object> defaultParameters) {
|
|
124 |
public static JobHandler execute(String scriptpath, IWorkbenchPart page, ISelection selection, List<String> args, HashMap<String, Object> parameters, HashMap<String, Object> defaultParameters) {
|
|
124 | 125 |
//IPreferencesService service = Platform.getPreferencesService(); |
125 | 126 |
String scriptRootDir = Toolbox.getTxmHomePath() + "/scripts"; //$NON-NLS-1$ |
126 | 127 |
File currentRootDir = new File(scriptRootDir, "groovy/user"); //$NON-NLS-1$ |
TXM/trunk/org.txm.rcp/src/main/java/org/txm/rcp/handlers/scripts/ExecuteGroovyScript.java (revision 3637) | ||
---|---|---|
156 | 156 |
* @param sel current selection, might be null |
157 | 157 |
* @return |
158 | 158 |
*/ |
159 |
public static IStatus executeScript(String scriptpath, final IWorkbenchPart page, final ISelection selection, boolean modal, String stringArgs) {
|
|
159 |
public static JobHandler executeScript(String scriptpath, final IWorkbenchPart page, final ISelection selection, boolean modal, String stringArgs) {
|
|
160 | 160 |
IPreferencesService service = Platform.getPreferencesService(); |
161 | 161 |
// String scriptRootDir = service.getString(Application.PLUGIN_ID, |
162 | 162 |
// ScriptPreferencePage.SCRIPT_ROOT_DIR, |
... | ... | |
186 | 186 |
* @param page current active page, might be null |
187 | 187 |
* @param sel current selection, might be null |
188 | 188 |
*/ |
189 |
public static IStatus executeScript(String scriptpath, final IWorkbenchPart page, final ISelection selection) {
|
|
189 |
public static JobHandler executeScript(String scriptpath, final IWorkbenchPart page, final ISelection selection) {
|
|
190 | 190 |
return executeScript(scriptpath, page, selection, false, null); |
191 | 191 |
} |
192 | 192 |
|
... | ... | |
197 | 197 |
* @param page current active page, might be null |
198 | 198 |
* @param sel current selection, might be null |
199 | 199 |
*/ |
200 |
public static IStatus executeScript(final File currentRootDir, String scriptpath, final IWorkbenchPart page, final ISelection sel, final boolean modal, final List<String> stringArgs, HashMap<String, Object> parameters, HashMap<String, Object> defaultParameters) {
|
|
200 |
public static JobHandler executeScript(final File currentRootDir, String scriptpath, final IWorkbenchPart page, final ISelection sel, final boolean modal, final List<String> stringArgs, HashMap<String, Object> parameters, HashMap<String, Object> defaultParameters) {
|
|
201 | 201 |
// check script |
202 | 202 |
final File scriptfile = new File(scriptpath); |
203 | 203 |
if (!scriptfile.exists()) { |
204 | 204 |
Log.severe(NLS.bind(TXMUIMessages.p0ScriptFileDoesntExist, scriptpath)); |
205 |
return Status.CANCEL_STATUS;
|
|
205 |
return null;
|
|
206 | 206 |
} |
207 | 207 |
ExecuteLastGroovyScript.setLastScript(scriptfile, currentRootDir.getName().equals("macro")); // register last groovy script //$NON-NLS-1$ |
208 | 208 |
|
... | ... | |
231 | 231 |
String path = scriptfile.getAbsolutePath(); |
232 | 232 |
if (!path.startsWith(dir)) { |
233 | 233 |
Log.severe(TXMUIMessages.bind(TXMUIMessages.theP1GroovyScriptMustBeInTheP0Folder, dir, path)); |
234 |
return Status.CANCEL_STATUS;
|
|
234 |
return null;
|
|
235 | 235 |
} |
236 | 236 |
final String relativepath = path.substring(dir.length()+1); |
237 | 237 |
|
... | ... | |
280 | 280 |
} else { |
281 | 281 |
Log.severe(TXMUIMessages.theUserCanceledTheScriptExecution); |
282 | 282 |
} |
283 |
} catch (Exception e) {
|
|
283 |
} catch (Throwable e) {
|
|
284 | 284 |
Log.severe(TXMUIMessages.errorDuringScriptExecutionColon+e); |
285 | 285 |
e.printStackTrace(); |
286 | 286 |
} finally { |
... | ... | |
291 | 291 |
}; |
292 | 292 |
|
293 | 293 |
jobhandler.startJob(modal); |
294 |
return Status.OK_STATUS;
|
|
294 |
return jobhandler;
|
|
295 | 295 |
// //gse.loadScriptByName("scripts/B.groovy"); |
296 | 296 |
// gse.run("A.groovy", new Binding()); |
297 | 297 |
|
TXM/trunk/org.txm.rcp/src/main/java/org/txm/rcp/handlers/scripts/ExecuteScript.java (revision 3637) | ||
---|---|---|
64 | 64 |
import org.txm.rcp.messages.TXMUIMessages; |
65 | 65 |
import org.txm.rcp.preferences.RCPPreferences; |
66 | 66 |
import org.txm.rcp.swt.dialog.LastOpened; |
67 |
import org.txm.rcp.utils.JobHandler; |
|
67 | 68 |
import org.txm.utils.logger.Log; |
68 | 69 |
// TODO: Auto-generated Javadoc |
69 | 70 |
/** |
... | ... | |
187 | 188 |
* |
188 | 189 |
* @param scriptpath the scriptfile |
189 | 190 |
*/ |
190 |
public static IStatus executeScript(String scriptpath, final IWorkbenchPart page, final ISelection selection, List<String> stringArgs) {
|
|
191 |
if (scriptpath == null) return Status.CANCEL_STATUS;
|
|
191 |
public static JobHandler executeScript(String scriptpath, final IWorkbenchPart page, final ISelection selection, List<String> stringArgs) {
|
|
192 |
if (scriptpath == null) return null;
|
|
192 | 193 |
File script = new File(scriptpath); |
193 |
if (!script.exists()) return Status.CANCEL_STATUS;
|
|
194 |
if (!script.exists()) return null;
|
|
194 | 195 |
|
195 | 196 |
String ext = script.getName(); |
196 | 197 |
int i = ext.lastIndexOf("."); //$NON-NLS-1$ |
... | ... | |
207 | 208 |
HashMap<String, Object> env = new HashMap<String, Object>(); |
208 | 209 |
env.put("page", page); // selection //$NON-NLS-1$ |
209 | 210 |
env.put("selection", selection); // selection //$NON-NLS-1$ |
210 |
return se.executeScript(script, env, stringArgs); |
|
211 |
se.executeScript(script, env, stringArgs); // TODO move JobHanddler to the Toolbox plugin |
|
212 |
return null; |
|
211 | 213 |
} else { |
212 | 214 |
Log.warning(TXMUIMessages.noInterpreterFoundForScriptFileExtension+script.getName()); |
213 | 215 |
} |
214 | 216 |
} |
215 | 217 |
|
216 |
return Status.CANCEL_STATUS;
|
|
218 |
return null;
|
|
217 | 219 |
} |
218 | 220 |
} |
Formats disponibles : Unified diff