Search in sources :

Example 1 with BaseOSProcessHandler

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

the class FlexCommonUtils method getVersionOfAirSdkIncludedInFlexSdk.

@Nullable
public static String getVersionOfAirSdkIncludedInFlexSdk(final String flexSdkHomePath) {
    final File adtFile = new File(flexSdkHomePath + "/lib/adt.jar");
    if (!adtFile.isFile()) {
        return null;
    }
    String version = ourAdtJarPathAndTimestampToVersion.get(Pair.create(adtFile.getPath(), adtFile.lastModified()));
    if (version != null) {
        return version;
    }
    try {
        final Ref<String> versionRef = Ref.create();
        final String javaExecutable = FileUtil.toSystemDependentName((SystemProperties.getJavaHome() + "/bin/java" + (SystemInfo.isWindows ? ".exe" : "")));
        String[] cmdarray = { javaExecutable, "-jar", adtFile.getPath(), "-version" };
        final Process process = Runtime.getRuntime().exec(cmdarray);
        final BaseOSProcessHandler handler = new BaseOSProcessHandler(process, StringUtil.join(cmdarray, " "), Charset.defaultCharset());
        handler.addProcessListener(new ProcessAdapter() {

            public void onTextAvailable(ProcessEvent event, Key outputType) {
                if (outputType != ProcessOutputTypes.SYSTEM) {
                    parseAirVersionFromAdtOutput(event.getText().trim(), versionRef);
                }
            }
        });
        handler.startNotify();
        handler.waitFor(3000);
        if (!handler.isProcessTerminated()) {
            handler.destroyProcess();
        }
        version = versionRef.get();
        ourAdtJarPathAndTimestampToVersion.put(Pair.create(adtFile.getPath(), adtFile.lastModified()), version);
        return version;
    } catch (IOException e) {
    /*ignore*/
    }
    return null;
}
Also used : ProcessAdapter(com.intellij.execution.process.ProcessAdapter) ProcessEvent(com.intellij.execution.process.ProcessEvent) BaseOSProcessHandler(com.intellij.execution.process.BaseOSProcessHandler) Nullable(org.jetbrains.annotations.Nullable)

Example 2 with BaseOSProcessHandler

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

the class AndroidCommonUtils method executeZipAlign.

@Nullable
public static String executeZipAlign(@NotNull String zipAlignPath, @NotNull File source, @NotNull File destination) {
    List<String> commandLine = Arrays.asList(zipAlignPath, "-f", "4", source.getAbsolutePath(), destination.getAbsolutePath());
    final ProcessBuilder processBuilder = new ProcessBuilder(commandLine);
    BaseOSProcessHandler handler;
    try {
        handler = new BaseOSProcessHandler(processBuilder.start(), StringUtil.join(commandLine, " "), null);
    } catch (IOException e) {
        return e.getMessage();
    }
    final StringBuilder builder = new StringBuilder();
    handler.addProcessListener(new ProcessAdapter() {

        @Override
        public void onTextAvailable(ProcessEvent event, Key outputType) {
            builder.append(event.getText());
        }
    });
    handler.startNotify();
    handler.waitFor();
    int exitCode = handler.getProcess().exitValue();
    return exitCode != 0 ? builder.toString() : null;
}
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) Nullable(org.jetbrains.annotations.Nullable)

Example 3 with BaseOSProcessHandler

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

the class ProcessBackedConsoleExecuteActionHandler method sendText.

public void sendText(String line) {
    final Charset charset = myProcessHandler instanceof BaseOSProcessHandler ? ((BaseOSProcessHandler) myProcessHandler).getCharset() : null;
    final OutputStream outputStream = myProcessHandler.getProcessInput();
    assert outputStream != null : "output stream is null";
    try {
        byte[] bytes = charset != null ? line.getBytes(charset) : line.getBytes();
        outputStream.write(bytes);
        outputStream.flush();
    } catch (IOException ignored) {
    }
}
Also used : OutputStream(java.io.OutputStream) Charset(java.nio.charset.Charset) IOException(java.io.IOException) BaseOSProcessHandler(com.intellij.execution.process.BaseOSProcessHandler)

Example 4 with BaseOSProcessHandler

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

the class RmiStubsGenerator method generateRmiStubs.

private ExitCode generateRmiStubs(final CompileContext context, Map<ModuleBuildTarget, Collection<ClassItem>> remoteClasses, ModuleChunk chunk, OutputConsumer outputConsumer) {
    ExitCode exitCode = ExitCode.NOTHING_DONE;
    final Collection<File> classpath = ProjectPaths.getCompilationClasspath(chunk, false);
    final StringBuilder buf = new StringBuilder();
    for (File file : classpath) {
        if (buf.length() > 0) {
            buf.append(File.pathSeparator);
        }
        buf.append(file.getPath());
    }
    final String classpathString = buf.toString();
    final String rmicPath = getPathToRmic(chunk);
    final RmicCompilerOptions options = getOptions(context);
    final List<ModuleBuildTarget> targetsProcessed = new ArrayList<>(remoteClasses.size());
    for (Map.Entry<ModuleBuildTarget, Collection<ClassItem>> entry : remoteClasses.entrySet()) {
        try {
            final ModuleBuildTarget target = entry.getKey();
            final Collection<String> cmdLine = createStartupCommand(target, rmicPath, classpathString, options, entry.getValue());
            final Process process = Runtime.getRuntime().exec(ArrayUtil.toStringArray(cmdLine));
            final BaseOSProcessHandler handler = new BaseOSProcessHandler(process, StringUtil.join(cmdLine, " "), null) {

                @NotNull
                @Override
                protected Future<?> executeOnPooledThread(@NotNull Runnable task) {
                    return SharedThreadPool.getInstance().executeOnPooledThread(task);
                }
            };
            final RmicOutputParser stdOutParser = new RmicOutputParser(context, getPresentableName());
            final RmicOutputParser stdErrParser = new RmicOutputParser(context, getPresentableName());
            handler.addProcessListener(new ProcessAdapter() {

                @Override
                public void onTextAvailable(ProcessEvent event, Key outputType) {
                    if (outputType == ProcessOutputTypes.STDOUT) {
                        stdOutParser.append(event.getText());
                    } else if (outputType == ProcessOutputTypes.STDERR) {
                        stdErrParser.append(event.getText());
                    }
                }

                @Override
                public void processTerminated(ProcessEvent event) {
                    super.processTerminated(event);
                }
            });
            handler.startNotify();
            handler.waitFor();
            targetsProcessed.add(target);
            if (stdErrParser.isErrorsReported() || stdOutParser.isErrorsReported()) {
                break;
            } else {
                final int exitValue = handler.getProcess().exitValue();
                if (exitValue != 0) {
                    context.processMessage(new CompilerMessage(getPresentableName(), BuildMessage.Kind.ERROR, "RMI stub generation failed"));
                    break;
                }
            }
        } catch (IOException e) {
            context.processMessage(new CompilerMessage(getPresentableName(), e));
            break;
        }
    }
    // registering generated files
    final Map<File, File[]> fsCache = new THashMap<>(FileUtil.FILE_HASHING_STRATEGY);
    for (ModuleBuildTarget target : targetsProcessed) {
        final Collection<ClassItem> items = remoteClasses.get(target);
        for (ClassItem item : items) {
            File[] children = fsCache.get(item.parentDir);
            if (children == null) {
                children = item.parentDir.listFiles();
                if (children == null) {
                    children = EMPTY_FILE_ARRAY;
                }
                fsCache.put(item.parentDir, children);
            }
            final Collection<File> files = item.selectGeneratedFiles(children);
            if (!files.isEmpty()) {
                final Collection<String> sources = item.compiledClass.getSourceFilesPaths();
                for (File generated : files) {
                    try {
                        outputConsumer.registerOutputFile(target, generated, sources);
                    } catch (IOException e) {
                        context.processMessage(new CompilerMessage(getPresentableName(), e));
                    }
                }
            }
        }
    }
    return exitCode;
}
Also used : CompilerMessage(org.jetbrains.jps.incremental.messages.CompilerMessage) NotNull(org.jetbrains.annotations.NotNull) THashMap(gnu.trove.THashMap) ProcessAdapter(com.intellij.execution.process.ProcessAdapter) ProcessEvent(com.intellij.execution.process.ProcessEvent) RmicCompilerOptions(org.jetbrains.jps.model.java.compiler.RmicCompilerOptions) IOException(java.io.IOException) BaseOSProcessHandler(com.intellij.execution.process.BaseOSProcessHandler) File(java.io.File) THashMap(gnu.trove.THashMap) Key(com.intellij.openapi.util.Key)

Example 5 with BaseOSProcessHandler

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

the class MixBuilder method runMix.

private static void runMix(@NotNull String elixirPath, @NotNull String mixPath, @Nullable String contentRootPath, boolean addDebugInfo, @NotNull CompileContext context) throws ProjectBuildException {
    GeneralCommandLine commandLine = new GeneralCommandLine();
    commandLine.withWorkDirectory(contentRootPath);
    commandLine.setExePath(elixirPath);
    commandLine.addParameter(mixPath);
    commandLine.addParameter("compile");
    if (!addDebugInfo) {
        commandLine.addParameter("--no-debug-info");
    }
    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, 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) GeneralCommandLine(com.intellij.execution.configurations.GeneralCommandLine) ExecutionException(com.intellij.execution.ExecutionException) 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