Search in sources :

Example 1 with CeylonTool

use of org.eclipse.ceylon.common.tools.CeylonTool in project ceylon by eclipse.

the class TopLevelToolTests method setup.

@Before
public void setup() {
    tool = new CeylonTool();
    tool.setToolLoader(toolLoader);
}
Also used : CeylonTool(org.eclipse.ceylon.common.tools.CeylonTool) Before(org.junit.Before)

Example 2 with CeylonTool

use of org.eclipse.ceylon.common.tools.CeylonTool in project ceylon by eclipse.

the class CeylonDocToolTests method tool.

private CeylonDocTool tool(List<File> sourceFolders, String[] repositories, String overrides, List<File> docFolders, List<String> moduleName, boolean haltOnError, boolean deleteDestDir, boolean bootstrapCeylon) throws Exception {
    CeylonDocTool tool = new CeylonDocTool();
    tool.setSystemRepository("../dist/dist/repo");
    tool.setSourceFolders(sourceFolders);
    tool.setRepositoryAsStrings(Arrays.asList(repositories));
    tool.setModuleSpecs(moduleName);
    tool.setDocFolders(docFolders);
    tool.setHaltOnError(haltOnError);
    tool.setBootstrapCeylon(bootstrapCeylon);
    File dir = new File("build", "CeylonDocToolTest/" + name.getMethodName());
    if (deleteDestDir && dir.exists()) {
        FileUtil.delete(dir);
    }
    tool.setOut(dir.getAbsolutePath());
    if (overrides != null) {
        tool.setOverrides(overrides);
    }
    tool.initialize(new CeylonTool());
    return tool;
}
Also used : CeylonDocTool(org.eclipse.ceylon.ceylondoc.CeylonDocTool) CeylonTool(org.eclipse.ceylon.common.tools.CeylonTool) File(java.io.File)

Example 3 with CeylonTool

use of org.eclipse.ceylon.common.tools.CeylonTool in project ceylon by eclipse.

the class CeylonHelpTool method run.

@Override
public void run() {
    if (wantsPager && OSUtil.isWindows() && tool != null) {
        if (openHelpInBrowser()) {
            return;
        }
    }
    docBuilder.setIncludeHidden(includeHidden);
    Doc doc;
    if (tool != null) {
        doc = docBuilder.buildDoc(tool);
    } else {
        final ToolModel<CeylonTool> root = toolLoader.loadToolModel("");
        doc = docBuilder.buildDoc(root, true);
    }
    Process pagerProcess = null;
    if (wantsPager && !OSUtil.isWindows()) {
        pagerProcess = startPager();
    }
    OutputStream pagerPipe = null;
    if (pagerProcess != null)
        pagerPipe = pagerProcess.getOutputStream();
    try {
        final WordWrap wrap = getWrap(pagerPipe);
        Visitor plain = new PlainVisitor(wrap);
        if (synopsis) {
            plain = new SynopsisOnlyVisitor(plain);
        } else if (options != null) {
            plain = new OptionsOnlyVisitor(plain, new HashSet<String>(Arrays.asList(options.trim().split("\\s*,\\s*"))));
        }
        doc.accept(plain);
        wrap.flush();
    } finally {
        // shutdown pager
        if (pagerPipe != null) {
            try {
                pagerPipe.close();
            } catch (IOException e) {
            // Seems common on MacOS so let's just ignore this
            }
            // wait for pager to be done, there's no point doing anything else meanwhile
            try {
                int errorCode = pagerProcess.waitFor();
                if (errorCode != 0) {
                    throw new ToolUsageError("Pager process returned an error exit code: " + errorCode + ". Try fixing your $CEYLON_PAGER or $PAGER environment variable or invoke with the --no-pager command-line option.");
                }
            } catch (InterruptedException e) {
                throw new ToolUsageError("Pager process interrupted. Try fixing your $CEYLON_PAGER or $PAGER environment variable or invoke with the --no-pager command-line option.");
            }
        }
    }
}
Also used : Visitor(org.eclipse.ceylon.common.tools.help.model.Visitor) OutputStream(java.io.OutputStream) CeylonTool(org.eclipse.ceylon.common.tools.CeylonTool) IOException(java.io.IOException) WordWrap(org.eclipse.ceylon.common.tool.WordWrap) ToolUsageError(org.eclipse.ceylon.common.tool.ToolUsageError) Doc(org.eclipse.ceylon.common.tools.help.model.Doc)

Example 4 with CeylonTool

use of org.eclipse.ceylon.common.tools.CeylonTool in project ceylon by eclipse.

the class CeylonBashCompletionTool method run.

@Override
public void run() throws Exception {
    // we don't care about arg0
    arguments.remove(0);
    cword--;
    final CompletionResults results;
    if (cword == 0) {
        // We're completing the name of the tool to run
        results = completeToolNames(arguments.isEmpty() ? "" : arguments.get(cword));
    } else if (cword < arguments.size()) {
        String argument = arguments.get(cword);
        CeylonTool main = new CeylonTool();
        main.setArgs(arguments);
        main.setToolLoader(toolLoader);
        ToolModel<?> tool = main.getToolModel();
        if (!afterEoo()) {
            if (argument.startsWith("--")) {
                if (argument.contains("=")) {
                    results = completeLongOptionArgument(tool, argument);
                } else {
                    results = completeLongOption(tool, argument);
                }
            } else if (argument.startsWith("-")) {
                /*TODO for (OptionModel<?> option : tool.getOptions()) {
                        if (argument.charAt(argument.length()-1) == option.getShortName()) {
                            complete
                        }
                    }*/
                results = new CompletionResults();
            } else {
                // TODO it's argument completion unless the previous argument was a
                // non-pure short option
                results = new CompletionResults();
            }
        } else {
            // TODO else it must be argument completion
            results = new CompletionResults();
        }
    } else {
        // TODO we don't know what we're completing.
        // First assume it's an argument...
        // ... but if the tool doesn't have any arguments (or all the
        // arguments are already specified) then assume it's an option
        results = new CompletionResults();
    }
    results.emitCompletions();
}
Also used : ToolModel(org.eclipse.ceylon.common.tool.ToolModel) CeylonTool(org.eclipse.ceylon.common.tools.CeylonTool)

Aggregations

CeylonTool (org.eclipse.ceylon.common.tools.CeylonTool)4 File (java.io.File)1 IOException (java.io.IOException)1 OutputStream (java.io.OutputStream)1 CeylonDocTool (org.eclipse.ceylon.ceylondoc.CeylonDocTool)1 ToolModel (org.eclipse.ceylon.common.tool.ToolModel)1 ToolUsageError (org.eclipse.ceylon.common.tool.ToolUsageError)1 WordWrap (org.eclipse.ceylon.common.tool.WordWrap)1 Doc (org.eclipse.ceylon.common.tools.help.model.Doc)1 Visitor (org.eclipse.ceylon.common.tools.help.model.Visitor)1 Before (org.junit.Before)1