Search in sources :

Example 1 with Tool

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();
}
Also used : ToolFactory(org.eclipse.ceylon.common.tool.ToolFactory) ArrayList(java.util.ArrayList) ToolLoader(org.eclipse.ceylon.common.tool.ToolLoader) NonFatalToolMessage(org.eclipse.ceylon.common.tool.NonFatalToolMessage) IOException(java.io.IOException) Tool(org.eclipse.ceylon.common.tool.Tool) CeylonBaseTool(org.eclipse.ceylon.common.tool.CeylonBaseTool)

Example 2 with Tool

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;
}
Also used : ToolFactory(org.eclipse.ceylon.common.tool.ToolFactory) ToolLoader(org.eclipse.ceylon.common.tool.ToolLoader) NonFatalToolMessage(org.eclipse.ceylon.common.tool.NonFatalToolMessage) IOException(java.io.IOException) Tool(org.eclipse.ceylon.common.tool.Tool) CeylonBaseTool(org.eclipse.ceylon.common.tool.CeylonBaseTool)

Example 3 with Tool

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;
}
Also used : CeylonConfig(org.eclipse.ceylon.common.config.CeylonConfig) OptionArgumentException(org.eclipse.ceylon.common.tool.OptionArgumentException) IOException(java.io.IOException) NoSuchToolException(org.eclipse.ceylon.common.tool.NoSuchToolException) ModelException(org.eclipse.ceylon.common.tool.ModelException) Tool(org.eclipse.ceylon.common.tool.Tool) CeylonBaseTool(org.eclipse.ceylon.common.tool.CeylonBaseTool)

Example 4 with Tool

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;
}
Also used : AnnotatedToolModel(org.eclipse.ceylon.common.tool.AnnotatedToolModel) NoSuchToolException(org.eclipse.ceylon.common.tool.NoSuchToolException) Tool(org.eclipse.ceylon.common.tool.Tool) CeylonBaseTool(org.eclipse.ceylon.common.tool.CeylonBaseTool)

Aggregations

CeylonBaseTool (org.eclipse.ceylon.common.tool.CeylonBaseTool)4 Tool (org.eclipse.ceylon.common.tool.Tool)4 IOException (java.io.IOException)3 NoSuchToolException (org.eclipse.ceylon.common.tool.NoSuchToolException)2 NonFatalToolMessage (org.eclipse.ceylon.common.tool.NonFatalToolMessage)2 ToolFactory (org.eclipse.ceylon.common.tool.ToolFactory)2 ToolLoader (org.eclipse.ceylon.common.tool.ToolLoader)2 ArrayList (java.util.ArrayList)1 CeylonConfig (org.eclipse.ceylon.common.config.CeylonConfig)1 AnnotatedToolModel (org.eclipse.ceylon.common.tool.AnnotatedToolModel)1 ModelException (org.eclipse.ceylon.common.tool.ModelException)1 OptionArgumentException (org.eclipse.ceylon.common.tool.OptionArgumentException)1