Search in sources :

Example 76 with ExecutionException

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

the class KarmaExecutionSession method findTopLevelSuiteNames.

private static List<String> findTopLevelSuiteNames(@NotNull Project project, @NotNull String testFilePath) throws ExecutionException {
    VirtualFile file = LocalFileFinder.findFile(testFilePath);
    if (file == null) {
        throw new ExecutionException("Cannot find test file by " + testFilePath);
    }
    PsiFile psiFile = PsiManager.getInstance(project).findFile(file);
    JSFile jsFile = ObjectUtils.tryCast(psiFile, JSFile.class);
    if (jsFile == null) {
        LOG.info("Not a JavaScript file " + testFilePath + ", " + (psiFile == null ? "null" : psiFile.getClass()));
        throw new ExecutionException("Not a JavaScript file: " + testFilePath);
    }
    JasmineFileStructure jasmine = JasmineFileStructureBuilder.getInstance().fetchCachedTestFileStructure(jsFile);
    List<String> elements = jasmine.getTopLevelElements();
    if (!elements.isEmpty()) {
        return elements;
    }
    QUnitFileStructure qunit = QUnitFileStructureBuilder.getInstance().fetchCachedTestFileStructure(jsFile);
    elements = qunit.getTopLevelElements();
    if (!elements.isEmpty()) {
        return elements;
    }
    throw new ExecutionException("No tests found in " + testFilePath);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) PsiFile(com.intellij.psi.PsiFile) ExecutionException(com.intellij.execution.ExecutionException) JSFile(com.intellij.lang.javascript.psi.JSFile) JasmineFileStructure(com.intellij.javascript.testFramework.jasmine.JasmineFileStructure) QUnitFileStructure(com.intellij.javascript.testFramework.qunit.QUnitFileStructure)

Example 77 with ExecutionException

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

the class KarmaExecutionSession method createProcessHandler.

@NotNull
private ProcessHandler createProcessHandler(@NotNull final KarmaServer server) throws ExecutionException {
    final File clientAppFile;
    try {
        clientAppFile = server.getKarmaJsSourcesLocator().getClientAppFile();
    } catch (IOException e) {
        throw new ExecutionException("Can't find karma-intellij test runner", e);
    }
    if (server.areBrowsersReady()) {
        return createOSProcessHandler(server, clientAppFile);
    }
    final NopProcessHandler nopProcessHandler = new NopProcessHandler();
    terminateOnServerShutdown(server, nopProcessHandler);
    return nopProcessHandler;
}
Also used : IOException(java.io.IOException) ExecutionException(com.intellij.execution.ExecutionException) 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)

Example 78 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 79 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 80 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)

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