Search in sources :

Example 66 with GeneralCommandLine

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

the class PhoneGapTargets method list.

protected List<String> list(String executableName, Function<String, String> parser, boolean errorOut, String... params) {
    List<String> result = ContainerUtil.newArrayList();
    File deployExecutable = PathEnvironmentVariableUtil.findInPath(executableName);
    if (deployExecutable == null)
        return result;
    try {
        GeneralCommandLine line = new GeneralCommandLine(deployExecutable.getAbsolutePath());
        line.addParameters(params);
        ProcessOutput output = ExecUtil.execAndGetOutput(line);
        List<String> lines = null;
        if (errorOut) {
            if (!StringUtil.isEmpty(output.getStderr())) {
                lines = output.getStderrLines();
            }
        }
        if (lines == null) {
            lines = output.getStdoutLines();
        }
        if (output.getExitCode() != 0)
            return result;
        for (String value : lines) {
            ContainerUtil.addIfNotNull(result, parser.fun(value));
        }
    } catch (ExecutionException e) {
        LOGGER.debug(e.getMessage(), e);
    }
    return result;
}
Also used : GeneralCommandLine(com.intellij.execution.configurations.GeneralCommandLine) ProcessOutput(com.intellij.execution.process.ProcessOutput) ExecutionException(com.intellij.execution.ExecutionException) File(java.io.File)

Example 67 with GeneralCommandLine

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

the class KarmaServer method startServer.

private KillableColoredProcessHandler startServer(@NotNull KarmaServerSettings serverSettings) throws IOException {
    GeneralCommandLine commandLine = new GeneralCommandLine();
    serverSettings.getEnvData().configureCommandLine(commandLine, true);
    commandLine.withWorkDirectory(serverSettings.getConfigurationFile().getParentFile());
    commandLine.setExePath(serverSettings.getNodeInterpreter().getInterpreterSystemDependentPath());
    File serverFile = myKarmaJsSourcesLocator.getServerAppFile();
    //NodeCommandLineUtil.addNodeOptionsForDebugging(commandLine, Collections.emptyList(), 34598, true,
    //                                               serverSettings.getNodeInterpreter(), true);
    commandLine.addParameter(serverFile.getAbsolutePath());
    commandLine.addParameter("--karmaPackageDir=" + myServerSettings.getKarmaPackage().getSystemDependentPath());
    commandLine.addParameter("--configFile=" + serverSettings.getConfigurationFilePath());
    String browsers = serverSettings.getBrowsers();
    if (!StringUtil.isEmptyOrSpaces(browsers)) {
        commandLine.addParameter("--browsers=" + browsers);
    }
    if (myCoveragePeer != null) {
        commandLine.addParameter("--coverageTempDir=" + myCoveragePeer.getCoverageTempDir());
    }
    if (serverSettings.isDebug()) {
        commandLine.addParameter("--debug=true");
    }
    commandLine.setCharset(CharsetToolkit.UTF8_CHARSET);
    KillableColoredProcessHandler processHandler;
    try {
        processHandler = new KillableColoredProcessHandler(commandLine);
    } catch (ExecutionException e) {
        throw new IOException("Can not start Karma server: " + commandLine.getCommandLineString(), e);
    }
    final int processHashCode = System.identityHashCode(processHandler.getProcess());
    LOG.info("Karma server " + processHashCode + " started successfully: " + commandLine.getCommandLineString());
    processHandler.addProcessListener(new ProcessAdapter() {

        @Override
        public void processTerminated(final ProcessEvent event) {
            LOG.info("Karma server " + processHashCode + " terminated with exit code " + event.getExitCode());
            Disposer.dispose(myDisposable);
            fireOnTerminated(event.getExitCode());
        }
    });
    ProcessTerminatedListener.attach(processHandler);
    processHandler.setShouldDestroyProcessRecursively(true);
    return processHandler;
}
Also used : GeneralCommandLine(com.intellij.execution.configurations.GeneralCommandLine) IOException(java.io.IOException) ExecutionException(com.intellij.execution.ExecutionException) File(java.io.File)

Example 68 with GeneralCommandLine

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

the class JstdServer method createCommandLine.

private static GeneralCommandLine createCommandLine(@NotNull JstdServerSettings settings) {
    GeneralCommandLine commandLine = new GeneralCommandLine();
    commandLine.setExePath(System.getProperty("java.home") + File.separator + "bin" + File.separator + "java");
    Charset charset = StandardCharsets.UTF_8;
    commandLine.setCharset(charset);
    commandLine.addParameter("-Dfile.encoding=" + charset.name());
    //commandLine.addParameter("-Xdebug");
    //commandLine.addParameter("-Xrunjdwp:transport=dt_socket,address=5000,server=y,suspend=y");
    File file = new File(PathUtil.getJarPathForClass(JsTestDriverServer.class));
    commandLine.setWorkDirectory(file.getParentFile());
    commandLine.addParameter("-cp");
    commandLine.addParameter(getClasspath());
    commandLine.addParameter("com.google.jstestdriver.idea.rt.server.JstdServerMain");
    commandLine.addParameter("--port");
    commandLine.addParameter(String.valueOf(settings.getPort()));
    commandLine.addParameter("--runnerMode");
    commandLine.addParameter(settings.getRunnerMode().name());
    commandLine.addParameter("--browserTimeout");
    commandLine.addParameter(String.valueOf(settings.getBrowserTimeoutMillis()));
    return commandLine;
}
Also used : GeneralCommandLine(com.intellij.execution.configurations.GeneralCommandLine) JsTestDriverServer(com.google.jstestdriver.JsTestDriverServer) Charset(java.nio.charset.Charset) File(java.io.File)

Example 69 with GeneralCommandLine

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

the class JstdServer method start.

@NotNull
private static OSProcessHandler start(@NotNull JstdServerSettings settings, int id) throws IOException {
    GeneralCommandLine commandLine = createCommandLine(settings);
    OSProcessHandler processHandler;
    try {
        processHandler = new KillableColoredProcessHandler(commandLine);
    } catch (ExecutionException e) {
        throw new IOException("Cannot start " + formatName(id, null) + ".\nCommand: " + commandLine.getCommandLineString(), e);
    }
    LOG.info(formatName(id, processHandler.getProcess()) + " started successfully: " + commandLine.getCommandLineString());
    ProcessTerminatedListener.attach(processHandler);
    processHandler.setShouldDestroyProcessRecursively(true);
    return processHandler;
}
Also used : GeneralCommandLine(com.intellij.execution.configurations.GeneralCommandLine) IOException(java.io.IOException) ExecutionException(com.intellij.execution.ExecutionException) NotNull(org.jetbrains.annotations.NotNull)

Example 70 with GeneralCommandLine

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

the class Flexmojos4GenerateConfigTask method runGeneratorServer.

private void runGeneratorServer(MavenProjectsManager mavenProjectsManager, Project project) throws IOException, ExecutionException, MavenProcessCanceledException {
    final SimpleJavaParameters params = new SimpleJavaParameters();
    params.setJdk(new SimpleJavaSdkType().createJdk("tmp", SystemProperties.getJavaHome()));
    final MavenGeneralSettings mavenGeneralSettings = mavenProjectsManager.getGeneralSettings();
    final ParametersList programParametersList = params.getProgramParametersList();
    programParametersList.add(getSettingsFilePath(mavenGeneralSettings.getEffectiveGlobalSettingsIoFile()));
    programParametersList.add(getSettingsFilePath(mavenGeneralSettings.getEffectiveUserSettingsIoFile()));
    programParametersList.add(mavenGeneralSettings.getEffectiveLocalRepository().getAbsolutePath());
    programParametersList.add(mavenGeneralSettings.isWorkOffline() ? "t" : "f");
    //noinspection ConstantConditions
    programParametersList.add(project.getBaseDir().getPath() + "/.idea/flexmojos");
    configureMavenClassPath(mavenGeneralSettings, params.getClassPath());
    final File userVmP = new File(SystemProperties.getUserHome(), "fcg-vmp");
    if (userVmP.exists()) {
        params.getVMParametersList().addParametersString(FileUtil.loadFile(userVmP));
    }
    params.setMainClass("com.intellij.flex.maven.GeneratorServer");
    final GeneralCommandLine commandLine = params.toCommandLine();
    commandLine.setRedirectErrorStream(true);
    LOG.info("Generate Flex Configs Task:" + commandLine.getCommandLineString());
    indicator.checkCanceled();
    process = commandLine.createProcess();
    ApplicationManager.getApplication().executeOnPooledThread(new OutputReader(project));
    //noinspection IOResourceOpenedButNotSafelyClosed
    out = new DataOutputStream(new BufferedOutputStream(process.getOutputStream()));
    writeExplicitProfiles(mavenProjectsManager.getExplicitProfiles().getEnabledProfiles());
    writeWorkspaceMap(myTree.getProjects());
    out.writeUTF(FlexCommonUtils.getPathToBundledJar("flexmojos-idea-configurator.jar"));
    out.writeUTF(getIdeaConfiguratorClassName());
}
Also used : ParametersList(com.intellij.execution.configurations.ParametersList) SimpleJavaParameters(com.intellij.execution.configurations.SimpleJavaParameters) GeneralCommandLine(com.intellij.execution.configurations.GeneralCommandLine) SimpleJavaSdkType(com.intellij.openapi.projectRoots.SimpleJavaSdkType) VirtualFile(com.intellij.openapi.vfs.VirtualFile)

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