@@ -102,6 +102,7 @@ public class CeylonTool implements Tool {
102
102
private ToolLoader pluginLoader ;
103
103
private ToolFactory pluginFactory ;
104
104
private boolean version ;
105
+ private Tool toolCache ;
105
106
106
107
public CeylonTool () {
107
108
}
@@ -278,8 +279,10 @@ public int execute() throws Exception {
278
279
Exception error = null ;
279
280
CeylonConfig oldConfig = null ;
280
281
try {
281
- oldConfig = setupConfig ();
282
- run ();
282
+ ToolModel <Tool > model = getToolModel ();
283
+ Tool tool = getTool (model );
284
+ oldConfig = setupConfig (tool );
285
+ run (model , tool );
283
286
result = SC_OK ;
284
287
} catch (NoSuchToolException e ) {
285
288
error = e ;
@@ -309,8 +312,7 @@ public int execute() throws Exception {
309
312
return result ;
310
313
}
311
314
312
- private CeylonConfig setupConfig () {
313
- Tool tool = getTool (getToolModel ());
315
+ private CeylonConfig setupConfig (Tool tool ) {
314
316
if (tool instanceof CeylonBaseTool ) {
315
317
CeylonBaseTool cbt = (CeylonBaseTool )tool ;
316
318
File cwd = cbt .getCwd ();
@@ -325,19 +327,21 @@ private CeylonConfig setupConfig() {
325
327
@ Override
326
328
public void initialize () {
327
329
}
328
-
330
+
329
331
@ Override
330
332
public void run () throws Exception {
333
+ // do nothing?
334
+ }
335
+
336
+ private void run (ToolModel <Tool > model , Tool tool ) throws Exception {
331
337
if (version ) {
332
338
// --version is also handled in main(), so that you can at least do
333
339
// --version with a Java <7 JVM, but also do it here for consistency
334
340
version (System .out );
335
341
} else {
336
- final ToolModel <?> model = getToolModel ();
337
342
if (model .isScript ()){
338
343
runScript (model );
339
344
}else {
340
- Tool tool = getTool (model );
341
345
// Run the tool
342
346
tool .run ();
343
347
}
@@ -412,7 +416,14 @@ public Tool getTool(ToolModel<?> model) {
412
416
}
413
417
if (model .isScript ())
414
418
return null ;
419
+ boolean useCache = false ;
420
+ if (toolName != null && toolName .equals (model .getName ()))
421
+ useCache = true ;
422
+ if (useCache && toolCache != null )
423
+ return toolCache ;
415
424
tool = getPluginFactory ().bindArguments (model , toolArgs );
425
+ if (useCache )
426
+ toolCache = tool ;
416
427
return tool ;
417
428
}
418
429
0 commit comments