Search in sources :

Example 46 with GeneralCommandLine

use of com.intellij.execution.configurations.GeneralCommandLine in project intellij-community by JetBrains.

the class GeneralCommandLineTest method winShellScriptQuoting.

@Test
public void winShellScriptQuoting() throws Exception {
    assumeTrue(SystemInfo.isWindows);
    String scriptPrefix = "my_script";
    for (String scriptExt : new String[] { ".cmd", ".bat" }) {
        File script = ExecUtil.createTempExecutableScript(scriptPrefix, scriptExt, "@echo %1\n");
        String param = "a&b";
        GeneralCommandLine commandLine = createCommandLine(script.getAbsolutePath(), param);
        String text = commandLine.getPreparedCommandLine(Platform.WINDOWS);
        assertEquals(commandLine.getExePath() + "\n" + StringUtil.wrapWithDoubleQuote(param), text);
        try {
            String output = execAndGetOutput(commandLine);
            assertEquals(StringUtil.wrapWithDoubleQuote(param), output.trim());
        } finally {
            FileUtil.delete(script);
        }
    }
}
Also used : GeneralCommandLine(com.intellij.execution.configurations.GeneralCommandLine) File(java.io.File) Test(org.junit.Test)

Example 47 with GeneralCommandLine

use of com.intellij.execution.configurations.GeneralCommandLine in project intellij-community by JetBrains.

the class GeneralCommandLineTest method winShellQuotingWithExtraSwitch.

@Test
public void winShellQuotingWithExtraSwitch() throws Exception {
    assumeTrue(SystemInfo.isWindows);
    String param = "a&b";
    GeneralCommandLine commandLine = createCommandLine(ExecUtil.getWindowsShellName(), "/D", "/C", "echo", param);
    String output = execAndGetOutput(commandLine);
    assertEquals(StringUtil.wrapWithDoubleQuote(param), output.trim());
}
Also used : GeneralCommandLine(com.intellij.execution.configurations.GeneralCommandLine) Test(org.junit.Test)

Example 48 with GeneralCommandLine

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

the class DartCommandLineRunningState method doStartProcess.

protected ProcessHandler doStartProcess(@Nullable final String overriddenMainFilePath) throws ExecutionException {
    final GeneralCommandLine commandLine = createCommandLine(overriddenMainFilePath);
    // Workaround for "Observatory listening on ..." message that is concatenated (without line break) with the message following it
    final OSProcessHandler processHandler = new ColoredProcessHandler(commandLine) {

        @Override
        public void coloredTextAvailable(@NotNull String text, @NotNull Key attributes) {
            if (text.startsWith(DartConsoleFilter.OBSERVATORY_LISTENING_ON)) {
                text += "\n";
            }
            super.coloredTextAvailable(text, attributes);
        }
    };
    processHandler.addProcessListener(new ProcessAdapter() {

        @Override
        public void onTextAvailable(final ProcessEvent event, final Key outputType) {
            final String prefix = DartConsoleFilter.OBSERVATORY_LISTENING_ON + "http://";
            final String text = event.getText().trim();
            if (text.startsWith(prefix)) {
                processHandler.removeProcessListener(this);
                final String url = "http://" + text.substring(prefix.length());
                for (Consumer<String> consumer : myObservatoryUrlConsumers) {
                    consumer.consume(url);
                }
            }
        }
    });
    // Check for and display any analysis errors when we launch a Dart app.
    final Project project = getEnvironment().getProject();
    try {
        final DartRunConfiguration dartRunConfiguration = (DartRunConfiguration) getEnvironment().getRunProfile();
        final VirtualFile launchFile = dartRunConfiguration.getRunnerParameters().getDartFileOrDirectory();
        String launchTitle = "Analysis issues with " + dartRunConfiguration.getName();
        DartExecutionHelper.displayIssues(project, launchFile, launchTitle, dartRunConfiguration.getIcon());
    } catch (RuntimeConfigurationError error) {
        DartExecutionHelper.clearIssueNotifications(project);
    }
    ProcessTerminatedListener.attach(processHandler, getEnvironment().getProject());
    return processHandler;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) NotNull(org.jetbrains.annotations.NotNull) Project(com.intellij.openapi.project.Project) DartRunConfiguration(com.jetbrains.lang.dart.ide.runner.base.DartRunConfiguration) Consumer(com.intellij.util.Consumer) GeneralCommandLine(com.intellij.execution.configurations.GeneralCommandLine) RuntimeConfigurationError(com.intellij.execution.configurations.RuntimeConfigurationError) Key(com.intellij.openapi.util.Key)

Example 49 with GeneralCommandLine

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

the class JstdRunProfileState method createOSProcessHandler.

@NotNull
private KillableColoredProcessHandler createOSProcessHandler(@NotNull String serverUrl) throws ExecutionException {
    Map<TestRunner.ParameterKey, String> params = createParameterMap(serverUrl);
    GeneralCommandLine commandLine = createCommandLine(params);
    KillableColoredProcessHandler processHandler = new KillableColoredProcessHandler(commandLine, true);
    ProcessTerminatedListener.attach(processHandler);
    return processHandler;
}
Also used : GeneralCommandLine(com.intellij.execution.configurations.GeneralCommandLine) KillableColoredProcessHandler(com.intellij.execution.process.KillableColoredProcessHandler) NotNull(org.jetbrains.annotations.NotNull)

Example 50 with GeneralCommandLine

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

the class JstdRunProfileState method createCommandLine.

@NotNull
private static GeneralCommandLine createCommandLine(@NotNull Map<TestRunner.ParameterKey, String> parameters) {
    GeneralCommandLine commandLine = new GeneralCommandLine();
    commandLine.setExePath(System.getProperty("java.home") + File.separator + "bin" + File.separator + "java");
    // uncomment this if you want to debug jsTestDriver code in the test-runner process
    //commandLine.addParameter("-Xdebug");
    //commandLine.addParameter("-Xrunjdwp:transport=dt_socket,address=5000,server=y,suspend=y");
    File file = new File(PathUtil.getJarPathForClass(JsTestDriverServer.class));
    commandLine.withWorkDirectory(file.getParentFile());
    commandLine.addParameter("-cp");
    commandLine.addParameter(buildClasspath());
    commandLine.addParameter(TestRunner.class.getName());
    for (Map.Entry<TestRunner.ParameterKey, String> param : parameters.entrySet()) {
        String keyValue = EscapeUtils.join(Arrays.asList(param.getKey().name().toLowerCase(Locale.ENGLISH), param.getValue()), '=');
        commandLine.addParameter("--" + keyValue);
    }
    return commandLine;
}
Also used : TestRunner(com.google.jstestdriver.idea.rt.TestRunner) GeneralCommandLine(com.intellij.execution.configurations.GeneralCommandLine) JsTestDriverServer(com.google.jstestdriver.JsTestDriverServer) VirtualFile(com.intellij.openapi.vfs.VirtualFile) PsiFile(com.intellij.psi.PsiFile) JSFile(com.intellij.lang.javascript.psi.JSFile) File(java.io.File) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

GeneralCommandLine (com.intellij.execution.configurations.GeneralCommandLine)179 ExecutionException (com.intellij.execution.ExecutionException)70 NotNull (org.jetbrains.annotations.NotNull)47 File (java.io.File)41 VirtualFile (com.intellij.openapi.vfs.VirtualFile)31 OSProcessHandler (com.intellij.execution.process.OSProcessHandler)25 ProcessOutput (com.intellij.execution.process.ProcessOutput)25 Key (com.intellij.openapi.util.Key)18 ProcessEvent (com.intellij.execution.process.ProcessEvent)15 Project (com.intellij.openapi.project.Project)15 IOException (java.io.IOException)15 Nullable (org.jetbrains.annotations.Nullable)15 ProcessAdapter (com.intellij.execution.process.ProcessAdapter)14 CapturingProcessHandler (com.intellij.execution.process.CapturingProcessHandler)13 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)12 Sdk (com.intellij.openapi.projectRoots.Sdk)9 PsiFile (com.intellij.psi.PsiFile)9 ArrayList (java.util.ArrayList)9 Module (com.intellij.openapi.module.Module)8 ProcessHandler (com.intellij.execution.process.ProcessHandler)7