Search in sources :

Example 1 with CommandLineTokenizer

use of com.intellij.execution.configurations.CommandLineTokenizer in project android by JetBrains.

the class AndroidGradleBuildConfiguration method getCommandLineOptions.

@NotNull
public String[] getCommandLineOptions() {
    List<String> options = Lists.newArrayList();
    CommandLineTokenizer tokenizer = new CommandLineTokenizer(COMMAND_LINE_OPTIONS);
    while (tokenizer.hasMoreTokens()) {
        options.add(tokenizer.nextToken());
    }
    return ArrayUtil.toStringArray(options);
}
Also used : CommandLineTokenizer(com.intellij.execution.configurations.CommandLineTokenizer) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with CommandLineTokenizer

use of com.intellij.execution.configurations.CommandLineTokenizer in project intellij-plugins by JetBrains.

the class DartCommandLineRunningState method setupParameters.

private void setupParameters(@NotNull final GeneralCommandLine commandLine, @Nullable final String overriddenMainFilePath) throws ExecutionException {
    int customObservatoryPort = -1;
    final String vmOptions = myRunnerParameters.getVMOptions();
    if (vmOptions != null) {
        final StringTokenizer vmOptionsTokenizer = new CommandLineTokenizer(vmOptions);
        while (vmOptionsTokenizer.hasMoreTokens()) {
            final String vmOption = vmOptionsTokenizer.nextToken();
            commandLine.addParameter(vmOption);
            try {
                if (vmOption.equals("--enable-vm-service") || vmOption.equals("--observe")) {
                    // default port, see https://www.dartlang.org/tools/dart-vm/
                    customObservatoryPort = 8181;
                } else if (vmOption.startsWith("--enable-vm-service:")) {
                    customObservatoryPort = parseIntBeforeSlash(vmOption.substring("--enable-vm-service:".length()));
                } else if (vmOption.startsWith("--observe:")) {
                    customObservatoryPort = parseIntBeforeSlash(vmOption.substring("--observe:".length()));
                }
            } catch (NumberFormatException ignore) {
            /**/
            }
        }
    }
    if (myRunnerParameters.isCheckedMode()) {
        commandLine.addParameter(DartiumUtil.CHECKED_MODE_OPTION);
    }
    final VirtualFile dartFile;
    try {
        dartFile = myRunnerParameters.getDartFileOrDirectory();
    } catch (RuntimeConfigurationError e) {
        throw new ExecutionException(e);
    }
    if (DefaultDebugExecutor.EXECUTOR_ID.equals(getEnvironment().getExecutor().getId())) {
        commandLine.addParameter("--pause_isolates_on_start");
    }
    if (customObservatoryPort > 0) {
        myObservatoryPort = customObservatoryPort;
    } else {
        try {
            myObservatoryPort = NetUtils.findAvailableSocketPort();
        } catch (IOException e) {
            throw new ExecutionException(e);
        }
        commandLine.addParameter("--enable-vm-service:" + myObservatoryPort);
        if (getEnvironment().getRunner() instanceof DartCoverageProgramRunner) {
            commandLine.addParameter("--pause-isolates-on-exit");
        }
    }
    commandLine.addParameter(FileUtil.toSystemDependentName(overriddenMainFilePath == null ? dartFile.getPath() : overriddenMainFilePath));
    final String arguments = myRunnerParameters.getArguments();
    if (arguments != null) {
        StringTokenizer argumentsTokenizer = new CommandLineTokenizer(arguments);
        while (argumentsTokenizer.hasMoreTokens()) {
            commandLine.addParameter(argumentsTokenizer.nextToken());
        }
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) IOException(java.io.IOException) ExecutionException(com.intellij.execution.ExecutionException) RuntimeConfigurationError(com.intellij.execution.configurations.RuntimeConfigurationError) DartCoverageProgramRunner(com.jetbrains.lang.dart.coverage.DartCoverageProgramRunner) CommandLineTokenizer(com.intellij.execution.configurations.CommandLineTokenizer)

Example 3 with CommandLineTokenizer

use of com.intellij.execution.configurations.CommandLineTokenizer in project intellij-plugins by JetBrains.

the class DartConsoleFolding method getPlaceholderText.

@Nullable
@Override
public String getPlaceholderText(@NotNull final List<String> lines) {
    if (lines.size() == 1 && lines.get(0).startsWith(DartConsoleFilter.OBSERVATORY_LISTENING_ON)) {
        return " [Observatory: " + lines.get(0).substring(DartConsoleFilter.OBSERVATORY_LISTENING_ON.length()) + "]";
    }
    if (lines.size() == 1 && lines.get(0).contains(TEST_RUNNER_MARKER)) {
        return foldTestRunnerCommand(lines.get(0));
    }
    // exception folding
    if (isFrameLine(lines.get(0))) {
        return " [" + lines.size() + " more...]";
    }
    final String fullText = StringUtil.join(lines, "\n");
    if (!lines.get(0).contains(DART_MARKER) || lines.size() == 2 && !lines.get(1).startsWith(DartConsoleFilter.OBSERVATORY_LISTENING_ON) || lines.size() > 2) {
        // unexpected text
        return fullText;
    }
    final String line = lines.get(0);
    int index = line.indexOf(' ');
    assert index > 0 && line.substring(0, index + 1).endsWith(DART_MARKER) : line;
    while (line.length() > index + 1 && line.charAt(index + 1) == '-') {
        index = line.indexOf(" ", index + 1);
    }
    // can't happen
    if (index < 0)
        return fullText;
    final CommandLineTokenizer tok = new CommandLineTokenizer(line.substring(index));
    // can't happen
    if (!tok.hasMoreTokens())
        return fullText;
    final String filePath = tok.nextToken();
    // can't happen
    if (!filePath.contains(File.separator))
        return fullText;
    final StringBuilder b = new StringBuilder();
    b.append("dart ");
    b.append(PathUtil.getFileName(filePath));
    while (tok.hasMoreTokens()) {
        // program arguments
        b.append(" ").append(tok.nextToken());
    }
    if (lines.size() == 2 && lines.get(1).startsWith(DartConsoleFilter.OBSERVATORY_LISTENING_ON)) {
        b.append(" [Observatory: ").append(lines.get(1).substring(DartConsoleFilter.OBSERVATORY_LISTENING_ON.length())).append("]");
    }
    return b.toString();
}
Also used : CommandLineTokenizer(com.intellij.execution.configurations.CommandLineTokenizer) Nullable(org.jetbrains.annotations.Nullable)

Example 4 with CommandLineTokenizer

use of com.intellij.execution.configurations.CommandLineTokenizer in project intellij-plugins by JetBrains.

the class JSConditionalCompilationDefinitionsProviderImpl method processDefinitionsFromCompilerOptions.

private static boolean processDefinitionsFromCompilerOptions(final String compilerOptions, final Processor<Pair<String, String>> processor) {
    if (StringUtil.isEmpty(compilerOptions))
        return true;
    for (CommandLineTokenizer stringTokenizer = new CommandLineTokenizer(compilerOptions); stringTokenizer.hasMoreTokens(); ) {
        final String token = stringTokenizer.nextToken();
        for (String option : CONDITIONAL_COMPILATION_DEFINITION_OPTION_ALIASES) {
            if (token.startsWith("-" + option + "=") || token.startsWith("-" + option + "+=")) {
                final String optionValue = token.substring(token.indexOf("=") + 1);
                final int commaIndex = optionValue.indexOf(',');
                if (commaIndex > 0) {
                    if (!processor.process(Pair.create(optionValue.substring(0, commaIndex), optionValue.substring(commaIndex + 1))))
                        return false;
                }
            } else if (token.equals("-" + option) && stringTokenizer.countTokens() >= 2) {
                final String name = stringTokenizer.peekNextToken();
                // advance tokenizer position
                stringTokenizer.nextToken();
                final String value = stringTokenizer.peekNextToken();
                if (FlexCommonUtils.canBeCompilerOptionValue(value)) {
                    // advance tokenizer position
                    stringTokenizer.nextToken();
                    if (!processor.process(Pair.create(name, value)))
                        return false;
                }
            }
        }
    }
    return true;
}
Also used : CommandLineTokenizer(com.intellij.execution.configurations.CommandLineTokenizer)

Aggregations

CommandLineTokenizer (com.intellij.execution.configurations.CommandLineTokenizer)4 ExecutionException (com.intellij.execution.ExecutionException)1 RuntimeConfigurationError (com.intellij.execution.configurations.RuntimeConfigurationError)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 DartCoverageProgramRunner (com.jetbrains.lang.dart.coverage.DartCoverageProgramRunner)1 IOException (java.io.IOException)1 NotNull (org.jetbrains.annotations.NotNull)1 Nullable (org.jetbrains.annotations.Nullable)1