Search in sources :

Example 71 with ExecutionException

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

the class SendToMayaCommand method run.

public void run() {
    try {
        final ProcessHandler process = createRunInMayaProcessHandler();
        new RunContentExecutor(myProject, process).withTitle(getTitle()).withRerun(() -> this.run()).withStop(() -> process.destroyProcess(), () -> !process.isProcessTerminated()).run();
    } catch (ExecutionException e) {
        Messages.showErrorDialog(myProject, e.getMessage(), getTitle());
    }
}
Also used : ProcessHandler(com.intellij.execution.process.ProcessHandler) RunContentExecutor(com.intellij.execution.RunContentExecutor) ExecutionException(com.intellij.execution.ExecutionException)

Example 72 with ExecutionException

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

the class SendToMayaCommand method createRunInMayaProcessHandler.

private ProcessHandler createRunInMayaProcessHandler() throws ExecutionException {
    try {
        final Socket socket = new Socket("127.0.0.1", myPythonCommandPort);
        final SocketProcessHandler processHandler = new SocketProcessHandler(socket, getTitle());
        try {
            PrintWriter writer = new PrintWriter(new BufferedOutputStream(socket.getOutputStream()));
            if (myScriptText != null) {
                String[] lines = getScriptLines();
                writeLines(writer, lines);
                processHandler.notifyTextAvailable("Sent " + lines.length + " line" + (lines.length != 1 ? "s" : "") + " to command port " + myPythonCommandPort + "\n", ProcessOutputTypes.SYSTEM);
            } else {
                writeFile(writer, myFile);
                processHandler.notifyTextAvailable("Sent " + myFile.getPath() + " to command port " + myPythonCommandPort + "\n", ProcessOutputTypes.SYSTEM);
            }
            writer.flush();
        } catch (Exception e) {
            if (!socket.isClosed()) {
                socket.close();
            }
            throw new ExecutionException(e.getMessage());
        }
        return processHandler;
    } catch (Exception e) {
        throw new ExecutionException(e.getMessage());
    }
}
Also used : ExecutionException(com.intellij.execution.ExecutionException) BufferedOutputStream(java.io.BufferedOutputStream) Socket(java.net.Socket) ExecutionException(com.intellij.execution.ExecutionException) PrintWriter(java.io.PrintWriter)

Example 73 with ExecutionException

use of com.intellij.execution.ExecutionException 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 74 with ExecutionException

use of com.intellij.execution.ExecutionException 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 75 with ExecutionException

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

the class Flexmojos4GenerateConfigTask method perform.

@Override
public void perform(Project project, MavenEmbeddersManager embeddersManager, MavenConsole console, final MavenProgressIndicator indicator) throws MavenProcessCanceledException {
    final long start = System.currentTimeMillis();
    this.indicator = indicator;
    indicator.setText(FlexBundle.message("generating.flex.configs"));
    try {
        runGeneratorServer(MavenProjectsManager.getInstance(project), project);
        writeProjects(project);
    } catch (IOException e) {
        showWarning(project, e.getMessage());
        LOG.error(e);
    } catch (ExecutionException e) {
        showWarning(project, e.getMessage());
    }
    if (process == null) {
        return;
    }
    //noinspection WhileLoopSpinsOnField
    while (process != null) {
        try {
            //noinspection BusyWait
            Thread.sleep(500);
        } catch (InterruptedException ignored) {
            break;
        }
        if (indicator.isCanceled()) {
            LOG.warn("Generating flex configs canceled");
            if (process != null) {
                process.destroy();
            }
            break;
        }
    }
    if (postTask != null) {
        MavenUtil.invokeAndWait(project, postTask);
        MavenUtil.invokeAndWaitWriteAction(project, () -> {
            for (Map.Entry<Module, String> entry : myModuleToConfigFilePath.entrySet()) {
                if (entry.getKey().isDisposed())
                    continue;
                final VirtualFile configFile = LocalFileSystem.getInstance().refreshAndFindFileByPath(entry.getValue());
                if (configFile != null && !configFile.isDirectory()) {
                    Flexmojos3GenerateConfigTask.updateMainClass(entry.getKey(), configFile);
                }
            }
        });
    }
    final long duration = System.currentTimeMillis() - start;
    LOG.info("Generating flex configs took " + duration + " ms: " + duration / 60000 + " min " + (duration % 60000) / 1000 + "sec");
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) ExecutionException(com.intellij.execution.ExecutionException) Module(com.intellij.openapi.module.Module) THashMap(gnu.trove.THashMap)

Aggregations

ExecutionException (com.intellij.execution.ExecutionException)154 NotNull (org.jetbrains.annotations.NotNull)42 GeneralCommandLine (com.intellij.execution.configurations.GeneralCommandLine)39 IOException (java.io.IOException)35 File (java.io.File)34 VirtualFile (com.intellij.openapi.vfs.VirtualFile)26 Sdk (com.intellij.openapi.projectRoots.Sdk)20 Nullable (org.jetbrains.annotations.Nullable)20 Project (com.intellij.openapi.project.Project)19 ProcessHandler (com.intellij.execution.process.ProcessHandler)17 ProcessOutput (com.intellij.execution.process.ProcessOutput)17 Module (com.intellij.openapi.module.Module)13 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)12 Key (com.intellij.openapi.util.Key)12 ExecutionEnvironment (com.intellij.execution.runners.ExecutionEnvironment)10 ProcessAdapter (com.intellij.execution.process.ProcessAdapter)9 ProcessEvent (com.intellij.execution.process.ProcessEvent)8 JavaParameters (com.intellij.execution.configurations.JavaParameters)7 RunContentDescriptor (com.intellij.execution.ui.RunContentDescriptor)7 ArrayList (java.util.ArrayList)7