Skip to content
This repository was archived by the owner on Apr 13, 2023. It is now read-only.

Commit c8b98b2

Browse files
committed
CeylonTool #4848: instantiate less Tool instances
And bind it only once
1 parent 587d534 commit c8b98b2

File tree

1 file changed

+18
-7
lines changed

1 file changed

+18
-7
lines changed

common/src/com/redhat/ceylon/common/tools/CeylonTool.java

+18-7
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ public class CeylonTool implements Tool {
102102
private ToolLoader pluginLoader;
103103
private ToolFactory pluginFactory;
104104
private boolean version;
105+
private Tool toolCache;
105106

106107
public CeylonTool() {
107108
}
@@ -278,8 +279,10 @@ public int execute() throws Exception {
278279
Exception error = null;
279280
CeylonConfig oldConfig = null;
280281
try {
281-
oldConfig = setupConfig();
282-
run();
282+
ToolModel<Tool> model = getToolModel();
283+
Tool tool = getTool(model);
284+
oldConfig = setupConfig(tool);
285+
run(model, tool);
283286
result = SC_OK;
284287
} catch (NoSuchToolException e) {
285288
error = e;
@@ -309,8 +312,7 @@ public int execute() throws Exception {
309312
return result;
310313
}
311314

312-
private CeylonConfig setupConfig() {
313-
Tool tool = getTool(getToolModel());
315+
private CeylonConfig setupConfig(Tool tool) {
314316
if (tool instanceof CeylonBaseTool) {
315317
CeylonBaseTool cbt = (CeylonBaseTool)tool;
316318
File cwd = cbt.getCwd();
@@ -325,19 +327,21 @@ private CeylonConfig setupConfig() {
325327
@Override
326328
public void initialize() {
327329
}
328-
330+
329331
@Override
330332
public void run() throws Exception {
333+
// do nothing?
334+
}
335+
336+
private void run(ToolModel<Tool> model, Tool tool) throws Exception {
331337
if (version) {
332338
// --version is also handled in main(), so that you can at least do
333339
// --version with a Java <7 JVM, but also do it here for consistency
334340
version(System.out);
335341
} else {
336-
final ToolModel<?> model = getToolModel();
337342
if(model.isScript()){
338343
runScript(model);
339344
}else{
340-
Tool tool = getTool(model);
341345
// Run the tool
342346
tool.run();
343347
}
@@ -412,7 +416,14 @@ public Tool getTool(ToolModel<?> model) {
412416
}
413417
if(model.isScript())
414418
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;
415424
tool = getPluginFactory().bindArguments(model, toolArgs);
425+
if(useCache)
426+
toolCache = tool;
416427
return tool;
417428
}
418429

0 commit comments

Comments
 (0)