use of org.eclipse.ceylon.common.tool.Tool in project ceylon by eclipse.
the class RepoUsingTool method getSourceDirsForCompiler.
/**
* Use in subclasses that accept compilation before run
*/
protected List<File> getSourceDirsForCompiler(ModuleQuery.Type type) {
List<String> args = new ArrayList<String>(compilerArguments.size() + 1);
args.addAll(compilerArguments);
ToolFactory pluginFactory = new ToolFactory();
ToolLoader pluginLoader = new CeylonToolLoader();
String toolName;
if (type == ModuleQuery.Type.JVM) {
toolName = "compile";
} else if (type == ModuleQuery.Type.JS) {
toolName = "compile-js";
} else if (type == ModuleQuery.Type.DART) {
toolName = "compile-dart";
} else {
throw new IllegalArgumentException("Unknown compile flags passed");
}
try {
ToolModel<Tool> model = pluginLoader.loadToolModel(toolName);
Tool tool = pluginFactory.bindArguments(model, pluginLoader.<CeylonTool>instance("", null), args);
if (tool instanceof RepoUsingTool)
return ((RepoUsingTool) tool).getSourceDirs();
} catch (NonFatalToolMessage m) {
m.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
return DefaultToolOptions.getCompilerSourceDirs();
}
use of org.eclipse.ceylon.common.tool.Tool in project ceylon by eclipse.
the class RepoUsingTool method runCompiler.
private boolean runCompiler(RepositoryManager repoMgr, String name, ModuleQuery.Type type, String compileFlags) {
List<String> args = getCompilerArguments();
if (compileFlags != null) {
args.add("--include-dependencies=" + compileFlags);
}
if (!compileFlags.contains(COMPILE_FORCE) && type == ModuleQuery.Type.JVM) {
args.add("--incremental");
}
args.add(name);
ToolFactory pluginFactory = new ToolFactory();
ToolLoader pluginLoader = new CeylonToolLoader();
String toolName;
if (type == ModuleQuery.Type.JVM) {
toolName = "compile";
} else if (type == ModuleQuery.Type.JS) {
toolName = "compile-js";
} else if (type == ModuleQuery.Type.DART) {
toolName = "compile-dart";
} else {
throw new IllegalArgumentException("Unknown compile flags passed");
}
try {
ToolModel<Tool> model = pluginLoader.loadToolModel(toolName);
Tool tool = pluginFactory.bindArguments(model, pluginLoader.<CeylonTool>instance("", null), args);
msg("compiling", name).newline();
tool.run();
// Make sure we can find the newly created module
repoMgr.refresh(false);
if (repoMgr == rm) {
rm = null;
}
} catch (NonFatalToolMessage m) {
} catch (Exception e) {
return false;
}
return true;
}
use of org.eclipse.ceylon.common.tool.Tool in project ceylon by eclipse.
the class CeylonTool method execute.
// Warning: this method called by reflection in Launcher
public int execute() throws Exception {
int result = SC_OK;
try {
setSystemCwd();
String[] names = (toolName != null) ? getToolNames() : new String[] { null };
for (String singleToolName : names) {
ToolModel<Tool> model = getToolModel(singleToolName);
Tool tool = getTool(model);
CeylonConfig oldConfig2 = null;
if (oldConfig == null) {
oldConfig2 = setupConfig(tool);
}
try {
run(model, tool);
result = SC_OK;
} finally {
if (oldConfig2 != null) {
CeylonConfig.set(oldConfig2);
}
}
}
} catch (Exception e) {
result = handleException(this, e);
} finally {
if (oldConfig != null) {
CeylonConfig.set(oldConfig);
oldConfig = null;
}
}
System.out.flush();
return result;
}
use of org.eclipse.ceylon.common.tool.Tool in project ceylon by eclipse.
the class CeylonTool method getTool.
public Tool getTool(ToolModel<?> model) {
Tool tool = null;
if (model == null) {
ArgumentModel<?> argumentModel = getToolModel("").getArguments().get(0);
// XXX Very evil hack to work around the fact that the CeyonTool does
// not use subtools yet, and so the model used to generate help doc
// doesn't quite work right.
argumentModel.setName("command");
throw new NoSuchToolException(argumentModel, getToolName());
}
if (!(model instanceof AnnotatedToolModel))
return null;
boolean useCache = false;
if (toolName != null && toolName.equals(model.getName()))
useCache = true;
if (useCache && toolCache != null)
return toolCache;
tool = getPluginFactory().bindArguments(model, this, toolArgs);
if (useCache)
toolCache = tool;
return tool;
}
Aggregations