Example usage for com.intellij.openapi.application ApplicationStarter getCommandName

List of usage examples for com.intellij.openapi.application ApplicationStarter getCommandName

Introduction

In this page you can find the example usage for com.intellij.openapi.application ApplicationStarter getCommandName.

Prototype

String getCommandName();

Source Link

Document

Command-line switch to start with this runner.

Usage

From source file:com.intellij.ide.CommandLineProcessor.java

License:Apache License

@Nullable
public static Project processExternalCommandLine(List<String> args, @Nullable String currentDirectory) {
    if (args.size() > 0) {
        LOG.info("External command line:");
        for (String arg : args) {
            LOG.info(arg);/*from   ww  w.  j a v a 2  s .co m*/
        }
    }
    LOG.info("-----");

    if (args.size() > 0) {
        String command = args.get(0);
        for (ApplicationStarter starter : Extensions.getExtensions(ApplicationStarter.EP_NAME)) {
            if (starter instanceof ApplicationStarterEx && command.equals(starter.getCommandName())) {
                LOG.info("Processing command with " + starter);
                ((ApplicationStarterEx) starter).processExternalCommandLine(ArrayUtil.toStringArray(args),
                        currentDirectory);
                return null;
            }
        }
    }

    Project lastOpenedProject = null;
    int line = -1;
    for (int i = 0, argsSize = args.size(); i < argsSize; i++) {
        String arg = args.get(i);
        if (arg.equals(StartupUtil.NO_SPLASH)) {
            continue;
        }
        if (arg.equals("-l") || arg.equals("--line")) {
            //noinspection AssignmentToForLoopParameter
            i++;
            if (i == args.size()) {
                break;
            }
            try {
                line = Integer.parseInt(args.get(i));
            } catch (NumberFormatException e) {
                line = -1;
            }
        } else {
            if (StringUtil.isQuotedString(arg)) {
                arg = StringUtil.stripQuotesAroundValue(arg);
            }
            if (currentDirectory != null && !new File(arg).isAbsolute()) {
                arg = new File(currentDirectory, arg).getAbsolutePath();
            }
            if (line != -1) {
                final VirtualFile virtualFile = LocalFileSystem.getInstance().refreshAndFindFileByPath(arg);
                if (virtualFile != null) {
                    lastOpenedProject = doOpenFile(virtualFile, line);
                } else {
                    Messages.showErrorDialog("Cannot find file '" + arg + "'", "Cannot find file");
                }
            } else {
                lastOpenedProject = doOpenFileOrProject(arg);
            }
        }
    }
    return lastOpenedProject;
}

From source file:com.intellij.idea.IdeaApplication.java

License:Apache License

@NotNull
public ApplicationStarter getStarter() {
    if (myArgs.length > 0) {
        PluginManagerCore.getPlugins();//from  www .  j  a v  a  2 s. c o m

        final ApplicationStarter[] starters = ApplicationStarter.EP_NAME.getExtensions();
        String key = myArgs[0];
        for (ApplicationStarter o : starters) {
            if (Comparing.equal(o.getCommandName(), key))
                return o;
        }
    }

    return new IdeStarter();
}