Search in sources :

Example 6 with BaseOSProcessHandler

use of com.intellij.execution.process.BaseOSProcessHandler in project ballerina by ballerina-lang.

the class BallerinaExecutor method showOutput.

private void showOutput(@NotNull OSProcessHandler originalHandler, @NotNull BallerinaHistoryProcessListener historyProcessListener) {
    if (myShowOutputOnError) {
        BaseOSProcessHandler outputHandler = new KillableColoredProcessHandler(originalHandler.getProcess(), null);
        RunContentExecutor runContentExecutor = new RunContentExecutor(myProject, outputHandler).withTitle(getPresentableName()).withActivateToolWindow(myShowOutputOnError).withFilter(new BallerinaConsoleFilter(myProject, myModule, myWorkDirectory != null ? VfsUtilCore.pathToUrl(myWorkDirectory) : null));
        Disposer.register(myProject, runContentExecutor);
        runContentExecutor.run();
        historyProcessListener.apply(outputHandler);
    }
    if (myShowNotificationsOnError) {
        showNotification("Failed to run", NotificationType.ERROR);
    }
}
Also used : RunContentExecutor(com.intellij.execution.RunContentExecutor) BaseOSProcessHandler(com.intellij.execution.process.BaseOSProcessHandler) BallerinaConsoleFilter(org.ballerinalang.plugins.idea.runconfig.BallerinaConsoleFilter) KillableColoredProcessHandler(com.intellij.execution.process.KillableColoredProcessHandler)

Example 7 with BaseOSProcessHandler

use of com.intellij.execution.process.BaseOSProcessHandler in project android by JetBrains.

the class AndroidCommonUtils method handleDexCompilationResult.

public static void handleDexCompilationResult(@NotNull Process process, @NotNull String commandLine, @NotNull String outputFilePath, @NotNull final Map<AndroidCompilerMessageKind, List<String>> messages, boolean multiDex) {
    final BaseOSProcessHandler handler = new BaseOSProcessHandler(process, commandLine, null);
    handler.addProcessListener(new ProcessAdapter() {

        private AndroidCompilerMessageKind myCategory = null;

        @Override
        public void onTextAvailable(ProcessEvent event, Key outputType) {
            String[] msgs = event.getText().split("\\n");
            for (String msg : msgs) {
                msg = msg.trim();
                String msglc = msg.toLowerCase();
                if (outputType == ProcessOutputTypes.STDERR) {
                    if (WARNING_PATTERN.matcher(msglc).matches()) {
                        myCategory = AndroidCompilerMessageKind.WARNING;
                    }
                    if (ERROR_PATTERN.matcher(msglc).matches() || EXCEPTION_PATTERN.matcher(msglc).matches() || myCategory == null) {
                        myCategory = AndroidCompilerMessageKind.ERROR;
                    }
                    messages.get(myCategory).add(msg);
                } else if (outputType == ProcessOutputTypes.STDOUT) {
                    if (!msglc.startsWith("processing")) {
                        messages.get(AndroidCompilerMessageKind.INFORMATION).add(msg);
                    }
                }
                LOG.debug(msg);
            }
        }
    });
    handler.startNotify();
    handler.waitFor();
    final List<String> errors = messages.get(AndroidCompilerMessageKind.ERROR);
    if (new File(outputFilePath).isFile()) {
        // if compilation finished correctly, show all errors as warnings
        messages.get(AndroidCompilerMessageKind.WARNING).addAll(errors);
        errors.clear();
    } else if (errors.size() == 0 && !multiDex) {
        errors.add("Cannot create classes.dex file");
    }
}
Also used : ProcessAdapter(com.intellij.execution.process.ProcessAdapter) ProcessEvent(com.intellij.execution.process.ProcessEvent) BaseOSProcessHandler(com.intellij.execution.process.BaseOSProcessHandler) Key(com.intellij.openapi.util.Key)

Example 8 with BaseOSProcessHandler

use of com.intellij.execution.process.BaseOSProcessHandler in project intellij-community by JetBrains.

the class ForkedGroovyc method runGroovyc.

@Override
public GroovycContinuation runGroovyc(Collection<String> compilationClassPath, boolean forStubs, JpsGroovySettings settings, File tempFile, final GroovycOutputParser parser) throws Exception {
    List<String> classpath = new ArrayList<>();
    if (myOptimizeClassLoading) {
        classpath.addAll(GroovyBuilder.getGroovyRtRoots());
        classpath.add(ClasspathBootstrap.getResourcePath(Function.class));
        classpath.add(ClasspathBootstrap.getResourcePath(UrlClassLoader.class));
        classpath.add(ClasspathBootstrap.getResourceFile(THashMap.class).getPath());
    } else {
        classpath.addAll(compilationClassPath);
    }
    List<String> vmParams = ContainerUtilRt.newArrayList();
    vmParams.add("-Xmx" + System.getProperty("groovyc.heap.size", settings.heapSize) + "m");
    vmParams.add("-Dfile.encoding=" + System.getProperty("file.encoding"));
    if ("false".equals(System.getProperty(GroovyRtConstants.GROOVYC_ASM_RESOLVING_ONLY))) {
        vmParams.add("-D" + GroovyRtConstants.GROOVYC_ASM_RESOLVING_ONLY + "=false");
    }
    String configScript = settings.configScript;
    if (StringUtil.isNotEmpty(configScript)) {
        vmParams.add("-D" + GroovyRtConstants.GROOVYC_CONFIG_SCRIPT + "=" + configScript);
    }
    String grapeRoot = System.getProperty(GroovycOutputParser.GRAPE_ROOT);
    if (grapeRoot != null) {
        vmParams.add("-D" + GroovycOutputParser.GRAPE_ROOT + "=" + grapeRoot);
    }
    final List<String> cmd = ExternalProcessUtil.buildJavaCommandLine(getJavaExecutable(myChunk), "org.jetbrains.groovy.compiler.rt.GroovycRunner", Collections.<String>emptyList(), classpath, vmParams, getProgramParams(tempFile, settings, forStubs));
    final Process process = Runtime.getRuntime().exec(ArrayUtil.toStringArray(cmd));
    ProcessHandler handler = new BaseOSProcessHandler(process, StringUtil.join(cmd, " "), null) {

        @NotNull
        @Override
        protected Future<?> executeOnPooledThread(@NotNull Runnable task) {
            return SharedThreadPool.getInstance().executeOnPooledThread(task);
        }

        @Override
        public void notifyTextAvailable(String text, Key outputType) {
            parser.notifyTextAvailable(text, outputType);
        }
    };
    handler.startNotify();
    handler.waitFor();
    parser.notifyFinished(process.exitValue());
    return null;
}
Also used : Function(com.intellij.util.Function) ArrayList(java.util.ArrayList) ProcessHandler(com.intellij.execution.process.ProcessHandler) BaseOSProcessHandler(com.intellij.execution.process.BaseOSProcessHandler) UrlClassLoader(com.intellij.util.lang.UrlClassLoader) NotNull(org.jetbrains.annotations.NotNull) BaseOSProcessHandler(com.intellij.execution.process.BaseOSProcessHandler) Key(com.intellij.openapi.util.Key)

Example 9 with BaseOSProcessHandler

use of com.intellij.execution.process.BaseOSProcessHandler in project intellij-elixir by KronicDeth.

the class ElixirBuilder method runMix.

private static void runMix(@NotNull ElixirTarget target, @NotNull String elixirPath, @NotNull String mixPath, @Nullable String contentRootPath, @NotNull ElixirCompilerOptions compilerOptions, @NotNull CompileContext context) throws ProjectBuildException {
    GeneralCommandLine commandLine = new GeneralCommandLine();
    commandLine.withWorkDirectory(contentRootPath);
    commandLine.setExePath(elixirPath);
    commandLine.addParameter(mixPath);
    commandLine.addParameter(target.isTests() ? "test" : "compile");
    addCompileOptions(commandLine, compilerOptions);
    Process process;
    try {
        process = commandLine.createProcess();
    } catch (ExecutionException e) {
        throw new ProjectBuildException("Failed to run mix.", e);
    }
    BaseOSProcessHandler handler = new BaseOSProcessHandler(process, commandLine.getCommandLineString(), Charset.defaultCharset());
    ProcessAdapter adapter = new ElixirCompilerProcessAdapter(context, MIX_NAME, commandLine.getWorkDirectory().getPath());
    handler.addProcessListener(adapter);
    handler.startNotify();
    handler.waitFor();
}
Also used : ProjectBuildException(org.jetbrains.jps.incremental.ProjectBuildException) ProcessAdapter(com.intellij.execution.process.ProcessAdapter) BaseOSProcessHandler(com.intellij.execution.process.BaseOSProcessHandler)

Example 10 with BaseOSProcessHandler

use of com.intellij.execution.process.BaseOSProcessHandler in project intellij-elixir by KronicDeth.

the class ElixirBuilder method runElixirc.

private static void runElixirc(ElixirTarget target, CompileContext context, ElixirCompilerOptions compilerOptions, Collection<File> files, File outputDirectory) throws ProjectBuildException {
    GeneralCommandLine commandLine = getElixircCommandLine(target, context, compilerOptions, files, outputDirectory);
    Process process;
    try {
        process = commandLine.createProcess();
    } catch (ExecutionException e) {
        throw new ProjectBuildException("Failed to launch elixir compiler", e);
    }
    BaseOSProcessHandler handler = new BaseOSProcessHandler(process, commandLine.getCommandLineString(), Charset.defaultCharset());
    ProcessAdapter adapter = new ElixirCompilerProcessAdapter(context, ElIXIRC_NAME, "");
    handler.addProcessListener(adapter);
    handler.startNotify();
    handler.waitFor();
}
Also used : ProjectBuildException(org.jetbrains.jps.incremental.ProjectBuildException) ProcessAdapter(com.intellij.execution.process.ProcessAdapter) BaseOSProcessHandler(com.intellij.execution.process.BaseOSProcessHandler)

Aggregations

BaseOSProcessHandler (com.intellij.execution.process.BaseOSProcessHandler)11 ProcessAdapter (com.intellij.execution.process.ProcessAdapter)7 ProcessEvent (com.intellij.execution.process.ProcessEvent)4 Key (com.intellij.openapi.util.Key)4 ProjectBuildException (org.jetbrains.jps.incremental.ProjectBuildException)4 IOException (java.io.IOException)2 NotNull (org.jetbrains.annotations.NotNull)2 Nullable (org.jetbrains.annotations.Nullable)2 ExecutionException (com.intellij.execution.ExecutionException)1 RunContentExecutor (com.intellij.execution.RunContentExecutor)1 GeneralCommandLine (com.intellij.execution.configurations.GeneralCommandLine)1 KillableColoredProcessHandler (com.intellij.execution.process.KillableColoredProcessHandler)1 ProcessHandler (com.intellij.execution.process.ProcessHandler)1 Function (com.intellij.util.Function)1 UrlClassLoader (com.intellij.util.lang.UrlClassLoader)1 THashMap (gnu.trove.THashMap)1 File (java.io.File)1 OutputStream (java.io.OutputStream)1 Charset (java.nio.charset.Charset)1 ArrayList (java.util.ArrayList)1