Skip to content

Commit

Permalink
CeylonTool ceylon/ceylon-runtime#53: instantiate less Tool instances
Browse files Browse the repository at this point in the history
And bind it only once
  • Loading branch information
FroMage committed May 6, 2014
1 parent d4a9d4e commit de51087
Showing 1 changed file with 18 additions and 7 deletions.
25 changes: 18 additions & 7 deletions src/com/redhat/ceylon/common/tools/CeylonTool.java
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ public class CeylonTool implements Tool {
private ToolLoader pluginLoader;
private ToolFactory pluginFactory;
private boolean version;
private Tool toolCache;

public CeylonTool() {
}
Expand Down Expand Up @@ -278,8 +279,10 @@ public int execute() throws Exception {
Exception error = null;
CeylonConfig oldConfig = null;
try {
oldConfig = setupConfig();
run();
ToolModel<Tool> model = getToolModel();
Tool tool = getTool(model);
oldConfig = setupConfig(tool);
run(model, tool);
result = SC_OK;
} catch (NoSuchToolException e) {
error = e;
Expand Down Expand Up @@ -309,8 +312,7 @@ public int execute() throws Exception {
return result;
}

private CeylonConfig setupConfig() {
Tool tool = getTool(getToolModel());
private CeylonConfig setupConfig(Tool tool) {
if (tool instanceof CeylonBaseTool) {
CeylonBaseTool cbt = (CeylonBaseTool)tool;
File cwd = cbt.getCwd();
Expand All @@ -325,19 +327,21 @@ private CeylonConfig setupConfig() {
@Override
public void initialize() {
}

@Override
public void run() throws Exception {
// do nothing?
}

private void run(ToolModel<Tool> model, Tool tool) throws Exception {
if (version) {
// --version is also handled in main(), so that you can at least do
// --version with a Java <7 JVM, but also do it here for consistency
version(System.out);
} else {
final ToolModel<?> model = getToolModel();
if(model.isScript()){
runScript(model);
}else{
Tool tool = getTool(model);
// Run the tool
tool.run();
}
Expand Down Expand Up @@ -412,7 +416,14 @@ public Tool getTool(ToolModel<?> model) {
}
if(model.isScript())
return null;
boolean useCache = false;
if(toolName != null && toolName.equals(model.getName()))
useCache = true;
if(useCache && toolCache != null)
return toolCache;
tool = getPluginFactory().bindArguments(model, toolArgs);
if(useCache)
toolCache = tool;
return tool;
}

Expand Down

0 comments on commit de51087

Please sign in to comment.