diff --git a/java/compiler/impl/src/com/intellij/compiler/server/BuildManager.java b/java/compiler/impl/src/com/intellij/compiler/server/BuildManager.java index cdfec3942eb8..2b188e15cb20 100644 --- a/java/compiler/impl/src/com/intellij/compiler/server/BuildManager.java +++ b/java/compiler/impl/src/com/intellij/compiler/server/BuildManager.java @@ -1203,9 +1203,7 @@ public class BuildManager implements Disposable { LOG.error(e); } - final Process process = cmdLine.createProcess(); - - final OSProcessHandler processHandler = new OSProcessHandler(process, null, mySystemCharset, BuildMain.class.getName()+" external process") { + final OSProcessHandler processHandler = new OSProcessHandler(cmdLine) { @Override protected boolean shouldDestroyProcessRecursively() { return true; diff --git a/java/execution/openapi/src/com/intellij/execution/process/DefaultJavaProcessHandler.java b/java/execution/openapi/src/com/intellij/execution/process/DefaultJavaProcessHandler.java index 424a9f911e2a..901524c655e5 100644 --- a/java/execution/openapi/src/com/intellij/execution/process/DefaultJavaProcessHandler.java +++ b/java/execution/openapi/src/com/intellij/execution/process/DefaultJavaProcessHandler.java @@ -20,7 +20,6 @@ import com.intellij.execution.configurations.CommandLineBuilder; import com.intellij.execution.configurations.GeneralCommandLine; import com.intellij.execution.configurations.JavaParameters; import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; import java.nio.charset.Charset; @@ -35,7 +34,7 @@ public class DefaultJavaProcessHandler extends OSProcessHandler { super(commandLine); } - public DefaultJavaProcessHandler(@NotNull Process process, @Nullable String commandLine, @NotNull Charset charset) { + public DefaultJavaProcessHandler(@NotNull Process process, @NotNull String commandLine, @NotNull Charset charset) { super(process, commandLine, charset); } } diff --git a/java/testFramework/src/com/intellij/testFramework/CompilerTester.java b/java/testFramework/src/com/intellij/testFramework/CompilerTester.java index 739ea68802a0..3ab01e7cece1 100644 --- a/java/testFramework/src/com/intellij/testFramework/CompilerTester.java +++ b/java/testFramework/src/com/intellij/testFramework/CompilerTester.java @@ -21,6 +21,7 @@ import com.intellij.openapi.application.Result; import com.intellij.openapi.application.WriteAction; import com.intellij.openapi.command.WriteCommandAction; import com.intellij.openapi.compiler.*; +import com.intellij.openapi.fileEditor.impl.LoadTextUtil; import com.intellij.openapi.module.Module; import com.intellij.openapi.project.Project; import com.intellij.openapi.projectRoots.impl.JavaAwareProjectJdkTableImpl; @@ -28,6 +29,7 @@ import com.intellij.openapi.roots.CompilerModuleExtension; import com.intellij.openapi.roots.CompilerProjectExtension; import com.intellij.openapi.roots.ModuleRootManager; import com.intellij.openapi.roots.ModuleRootModificationUtil; +import com.intellij.openapi.util.ThrowableComputable; import com.intellij.openapi.vfs.VfsUtil; import com.intellij.openapi.vfs.VfsUtilCore; import com.intellij.openapi.vfs.VirtualFile; @@ -209,10 +211,18 @@ public class CompilerTester { public void run() throws Throwable { PlatformTestUtil.saveProject(getProject()); CompilerTestUtil.saveApplicationSettings(); - for (Module module : myModules) { + for (final Module module : myModules) { File ioFile = new File(module.getModuleFilePath()); if (!ioFile.exists()) { getProject().save(); + WriteCommandAction.runWriteCommandAction(getProject(), new ThrowableComputable() { + @Override + public Object compute() throws Throwable { + String text = LoadTextUtil.loadText(module.getModuleFile()).toString(); + VfsUtil.saveText(module.getModuleFile(), text); + return null; + } + }); assert ioFile.exists() : "File does not exist: " + ioFile.getPath(); } } diff --git a/jps/jps-builders/src/org/jetbrains/jps/incremental/instrumentation/RmiStubsGenerator.java b/jps/jps-builders/src/org/jetbrains/jps/incremental/instrumentation/RmiStubsGenerator.java index fffb87931d36..dcee7859c327 100644 --- a/jps/jps-builders/src/org/jetbrains/jps/incremental/instrumentation/RmiStubsGenerator.java +++ b/jps/jps-builders/src/org/jetbrains/jps/incremental/instrumentation/RmiStubsGenerator.java @@ -139,7 +139,7 @@ public class RmiStubsGenerator extends ClassProcessingBuilder { target, rmicPath, classpathString, options, entry.getValue() ); final Process process = Runtime.getRuntime().exec(ArrayUtil.toStringArray(cmdLine)); - final BaseOSProcessHandler handler = new BaseOSProcessHandler(process, null, null) { + final BaseOSProcessHandler handler = new BaseOSProcessHandler(process, StringUtil.join(cmdLine, " "), null) { @NotNull @Override protected Future executeOnPooledThread(@NotNull Runnable task) { diff --git a/jps/jps-builders/src/org/jetbrains/jps/incremental/java/JavaBuilder.java b/jps/jps-builders/src/org/jetbrains/jps/incremental/java/JavaBuilder.java index 216a2fd4f32e..ce9cecea271e 100644 --- a/jps/jps-builders/src/org/jetbrains/jps/incremental/java/JavaBuilder.java +++ b/jps/jps-builders/src/org/jetbrains/jps/incremental/java/JavaBuilder.java @@ -531,8 +531,8 @@ public class JavaBuilder extends ModuleLevelBuilder { final int listenPort = findFreePort(); server = new ExternalJavacManager(Utils.getSystemRoot()) { @Override - protected ExternalJavacProcessHandler createProcessHandler(Process process) { - return new ExternalJavacProcessHandler(process) { + protected ExternalJavacProcessHandler createProcessHandler(@NotNull Process process, @NotNull String commandLine) { + return new ExternalJavacProcessHandler(process, commandLine) { @Override @NotNull protected Future executeOnPooledThread(@NotNull Runnable task) { diff --git a/jps/jps-builders/src/org/jetbrains/jps/javac/ExternalJavacManager.java b/jps/jps-builders/src/org/jetbrains/jps/javac/ExternalJavacManager.java index c3305d5abb5d..cecdd12e411b 100644 --- a/jps/jps-builders/src/org/jetbrains/jps/javac/ExternalJavacManager.java +++ b/jps/jps-builders/src/org/jetbrains/jps/javac/ExternalJavacManager.java @@ -273,11 +273,11 @@ public class ExternalJavacManager { builder.directory(workingDir); final Process process = builder.start(); - return createProcessHandler(process); + return createProcessHandler(process, StringUtil.join(cmdLine, " ")); } - protected ExternalJavacProcessHandler createProcessHandler(Process process) { - return new ExternalJavacProcessHandler(process); + protected ExternalJavacProcessHandler createProcessHandler(@NotNull Process process, @NotNull String commandLine) { + return new ExternalJavacProcessHandler(process, commandLine); } private static void appendParam(List cmdLine, String param) { @@ -299,8 +299,8 @@ public class ExternalJavacManager { protected static class ExternalJavacProcessHandler extends BaseOSProcessHandler { private volatile int myExitCode; - protected ExternalJavacProcessHandler(Process process) { - super(process, null, null, "External javac process"); + protected ExternalJavacProcessHandler(@NotNull Process process, @NotNull String commandLine) { + super(process, commandLine, null); addProcessListener(new ProcessAdapter() { @Override public void processTerminated(ProcessEvent event) { diff --git a/platform/lang-impl/src/com/intellij/tools/Tool.java b/platform/lang-impl/src/com/intellij/tools/Tool.java index dcebe09ca258..77606ab188c3 100644 --- a/platform/lang-impl/src/com/intellij/tools/Tool.java +++ b/platform/lang-impl/src/com/intellij/tools/Tool.java @@ -293,7 +293,7 @@ public class Tool implements SchemeElement { if (commandLine == null) { return; } - OSProcessHandler handler = new OSProcessHandler(commandLine.createProcess(), commandLine.getCommandLineString()); + OSProcessHandler handler = new OSProcessHandler(commandLine); handler.addProcessListener(new ToolProcessAdapter(project, synchronizeAfterExecution(), getName())); if (processListener != null) { handler.addProcessListener(processListener); diff --git a/platform/lang-impl/src/com/intellij/tools/ToolRunProfile.java b/platform/lang-impl/src/com/intellij/tools/ToolRunProfile.java index cc7598be4bb3..94ffbb340422 100644 --- a/platform/lang-impl/src/com/intellij/tools/ToolRunProfile.java +++ b/platform/lang-impl/src/com/intellij/tools/ToolRunProfile.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2015 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -105,7 +105,7 @@ public class ToolRunProfile implements ModuleRunProfile{ @NotNull protected OSProcessHandler startProcess() throws ExecutionException { final GeneralCommandLine commandLine = createCommandLine(); - final OSProcessHandler processHandler = new ColoredProcessHandler(commandLine.createProcess(), commandLine.getCommandLineString()); + final OSProcessHandler processHandler = new ColoredProcessHandler(commandLine); ProcessTerminatedListener.attach(processHandler); return processHandler; } diff --git a/platform/platform-api/src/com/intellij/execution/process/CapturingAnsiEscapesAwareProcessHandler.java b/platform/platform-api/src/com/intellij/execution/process/CapturingAnsiEscapesAwareProcessHandler.java index 96544b8ba83c..4dfa2e3faf54 100644 --- a/platform/platform-api/src/com/intellij/execution/process/CapturingAnsiEscapesAwareProcessHandler.java +++ b/platform/platform-api/src/com/intellij/execution/process/CapturingAnsiEscapesAwareProcessHandler.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2014 JetBrains s.r.o. + * Copyright 2000-2015 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -31,10 +31,18 @@ public class CapturingAnsiEscapesAwareProcessHandler extends CapturingProcessHan super(commandLine); } + @Deprecated + /** + * @deprecated use {@link CapturingAnsiEscapesAwareProcessHandler#CapturingAnsiEscapesAwareProcessHandler(Process, String)} instead + */ public CapturingAnsiEscapesAwareProcessHandler(Process process) { super(process); } + public CapturingAnsiEscapesAwareProcessHandler(@NotNull Process process, @NotNull String commandLine) { + super(process, null, commandLine); + } + @Override protected CapturingProcessAdapter createProcessAdapter(ProcessOutput processOutput) { return new AnsiEscapesAwareAdapter(processOutput); diff --git a/platform/platform-api/src/com/intellij/execution/process/CapturingProcessHandler.java b/platform/platform-api/src/com/intellij/execution/process/CapturingProcessHandler.java index 189113a5db31..bc132ddfab63 100644 --- a/platform/platform-api/src/com/intellij/execution/process/CapturingProcessHandler.java +++ b/platform/platform-api/src/com/intellij/execution/process/CapturingProcessHandler.java @@ -39,10 +39,18 @@ public class CapturingProcessHandler extends OSProcessHandler { addProcessListener(createProcessAdapter(myOutput)); } + @Deprecated + /** + * @deprecated Use {@link CapturingProcessHandler#CapturingProcessHandler(Process, Charset, String)} instead + */ public CapturingProcessHandler(@NotNull Process process) { this(process, null, ""); } + @Deprecated + /** + * @deprecated Use {@link CapturingProcessHandler#CapturingProcessHandler(Process, Charset, String)} instead + */ public CapturingProcessHandler(@NotNull Process process, @Nullable Charset charset) { this(process, charset, ""); } diff --git a/platform/platform-api/src/com/intellij/execution/process/ColoredProcessHandler.java b/platform/platform-api/src/com/intellij/execution/process/ColoredProcessHandler.java index 9887964a4b0c..927ec87c9365 100644 --- a/platform/platform-api/src/com/intellij/execution/process/ColoredProcessHandler.java +++ b/platform/platform-api/src/com/intellij/execution/process/ColoredProcessHandler.java @@ -21,7 +21,6 @@ import com.intellij.execution.configurations.GeneralCommandLine; import com.intellij.openapi.util.Key; import com.intellij.util.containers.ContainerUtil; import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; import java.nio.charset.Charset; import java.util.List; @@ -39,11 +38,11 @@ public class ColoredProcessHandler extends OSProcessHandler implements AnsiEscap super(commandLine); } - public ColoredProcessHandler(@NotNull Process process, @Nullable String commandLine) { + public ColoredProcessHandler(@NotNull Process process, @NotNull String commandLine) { super(process, commandLine); } - public ColoredProcessHandler(@NotNull Process process, @Nullable String commandLine, @NotNull Charset charset) { + public ColoredProcessHandler(@NotNull Process process, @NotNull String commandLine, @NotNull Charset charset) { super(process, commandLine, charset); } diff --git a/platform/platform-api/src/com/intellij/execution/process/OSProcessHandler.java b/platform/platform-api/src/com/intellij/execution/process/OSProcessHandler.java index 83c8890959ef..949438fa05c5 100644 --- a/platform/platform-api/src/com/intellij/execution/process/OSProcessHandler.java +++ b/platform/platform-api/src/com/intellij/execution/process/OSProcessHandler.java @@ -38,26 +38,22 @@ public class OSProcessHandler extends BaseOSProcessHandler { setHasPty(commandLine instanceof PtyCommandLine); } + @Deprecated + /** + * @deprecated use {@link OSProcessHandler#OSProcessHandler(Process, String)} or any other ctr instead + */ public OSProcessHandler(@NotNull Process process) { this(process, null); } - public OSProcessHandler(@NotNull Process process, @Nullable String commandLine) { + public OSProcessHandler(@NotNull Process process, /*NotNull*/ String commandLine) { this(process, commandLine, EncodingManager.getInstance().getDefaultCharset()); } - @Deprecated - /** - * @deprecated Use {@link OSProcessHandler#OSProcessHandler(Process, String, Charset, String)} instead - */ - public OSProcessHandler(@NotNull Process process, @Nullable String commandLine, @Nullable Charset charset) { + public OSProcessHandler(@NotNull Process process, /*@NotNull*/ String commandLine, @Nullable Charset charset) { super(process, commandLine, charset); } - public OSProcessHandler(@NotNull Process process, @Nullable String commandLine, @Nullable Charset charset, @NotNull String presentableName) { - super(process, commandLine, charset, presentableName); - } - @NotNull @Override protected Future executeOnPooledThread(@NotNull Runnable task) { diff --git a/platform/platform-api/src/com/intellij/execution/util/ExecUtil.java b/platform/platform-api/src/com/intellij/execution/util/ExecUtil.java index 5af440cc2d6a..2af60247514a 100644 --- a/platform/platform-api/src/com/intellij/execution/util/ExecUtil.java +++ b/platform/platform-api/src/com/intellij/execution/util/ExecUtil.java @@ -182,7 +182,7 @@ public class ExecUtil { } @NotNull - private static GeneralCommandLine sudoCommand(@NotNull GeneralCommandLine commandLine, @NotNull String prompt) throws ExecutionException, IOException { + public static GeneralCommandLine sudoCommand(@NotNull GeneralCommandLine commandLine, @NotNull String prompt) throws ExecutionException, IOException { if (SystemInfo.isUnix && "root".equals(System.getenv("USER"))) { return commandLine; } @@ -318,8 +318,8 @@ public class ExecUtil { /** @deprecated use {@link #execAndGetOutput(GeneralCommandLine)} instead (to be removed in IDEA 16) */ @SuppressWarnings("unused") public static ProcessOutput execAndGetOutput(@NotNull List command, @Nullable String workDir) throws ExecutionException { - Process process = new GeneralCommandLine(command).withWorkDirectory(workDir).createProcess(); - return new CapturingProcessHandler(process).runProcess(); + GeneralCommandLine commandLine = new GeneralCommandLine(command).withWorkDirectory(workDir); + return new CapturingProcessHandler(commandLine).runProcess(); } /** @deprecated use {@link #execAndReadLine(GeneralCommandLine)} instead (to be removed in IDEA 16) */ diff --git a/platform/platform-impl/src/com/intellij/execution/ExecutableValidator.java b/platform/platform-impl/src/com/intellij/execution/ExecutableValidator.java index 4e36e1bcbf67..b26a9e430141 100644 --- a/platform/platform-impl/src/com/intellij/execution/ExecutableValidator.java +++ b/platform/platform-impl/src/com/intellij/execution/ExecutableValidator.java @@ -106,7 +106,8 @@ public abstract class ExecutableValidator { GeneralCommandLine commandLine = new GeneralCommandLine(); commandLine.setExePath(executable); commandLine.addParameters(processParameters); - CapturingProcessHandler handler = new CapturingProcessHandler(commandLine.createProcess(), CharsetToolkit.getDefaultSystemCharset(), executable); + commandLine.setCharset(CharsetToolkit.getDefaultSystemCharset()); + CapturingProcessHandler handler = new CapturingProcessHandler(commandLine); ProcessOutput result = handler.runProcess(TIMEOUT_MS); boolean timeout = result.isTimeout(); int exitCode = result.getExitCode(); diff --git a/platform/platform-impl/src/com/intellij/execution/process/KillableColoredProcessHandler.java b/platform/platform-impl/src/com/intellij/execution/process/KillableColoredProcessHandler.java index 11228a9650a7..b9154ca0228e 100644 --- a/platform/platform-impl/src/com/intellij/execution/process/KillableColoredProcessHandler.java +++ b/platform/platform-impl/src/com/intellij/execution/process/KillableColoredProcessHandler.java @@ -22,7 +22,6 @@ import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.util.Key; import com.intellij.openapi.util.SystemInfo; import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; import java.io.IOException; import java.nio.charset.Charset; @@ -54,11 +53,11 @@ public class KillableColoredProcessHandler extends ColoredProcessHandler impleme myMediatedProcess = withMediator && MEDIATOR_KEY.get(commandLine) == Boolean.TRUE; } - public KillableColoredProcessHandler(@NotNull Process process, @Nullable String commandLine) { + public KillableColoredProcessHandler(@NotNull Process process, @NotNull String commandLine) { super(process, commandLine); } - public KillableColoredProcessHandler(@NotNull Process process, @Nullable String commandLine, @NotNull Charset charset) { + public KillableColoredProcessHandler(@NotNull Process process, @NotNull String commandLine, @NotNull Charset charset) { super(process, commandLine, charset); } diff --git a/platform/platform-impl/src/com/intellij/execution/process/ScriptRunnerUtil.java b/platform/platform-impl/src/com/intellij/execution/process/ScriptRunnerUtil.java index f0f9d1654900..09d86a24fce5 100644 --- a/platform/platform-impl/src/com/intellij/execution/process/ScriptRunnerUtil.java +++ b/platform/platform-impl/src/com/intellij/execution/process/ScriptRunnerUtil.java @@ -69,7 +69,7 @@ public final class ScriptRunnerUtil { public static String getProcessOutput(@NotNull GeneralCommandLine commandLine, @NotNull Condition outputTypeFilter, long timeout) throws ExecutionException { - return getProcessOutput(new OSProcessHandler(commandLine.createProcess(), commandLine.getCommandLineString()), outputTypeFilter, + return getProcessOutput(new OSProcessHandler(commandLine), outputTypeFilter, timeout); } @@ -136,9 +136,8 @@ public final class ScriptRunnerUtil { if (charset == null) { charset = EncodingManager.getInstance().getDefaultCharset(); } - final OSProcessHandler processHandler = new ColoredProcessHandler(commandLine.createProcess(), - commandLine.getCommandLineString(), - charset); + commandLine.setCharset(charset); + final OSProcessHandler processHandler = new ColoredProcessHandler(commandLine); if (LOG.isDebugEnabled()) { processHandler.addProcessListener(new ProcessAdapter() { @Override diff --git a/platform/platform-impl/src/com/intellij/openapi/vfs/impl/local/NativeFileWatcherImpl.java b/platform/platform-impl/src/com/intellij/openapi/vfs/impl/local/NativeFileWatcherImpl.java index ced6f3d0cb30..c2fdec64b16a 100644 --- a/platform/platform-impl/src/com/intellij/openapi/vfs/impl/local/NativeFileWatcherImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/vfs/impl/local/NativeFileWatcherImpl.java @@ -292,8 +292,8 @@ public class NativeFileWatcherImpl extends PluggableFileWatcher { private final BufferedWriter myWriter; @SuppressWarnings("IOResourceOpenedButNotSafelyClosed") - private MyProcessHandler(@NotNull Process process, @NotNull String presentableName) { - super(process, null, null, presentableName); // do not access EncodingManager here + private MyProcessHandler(@NotNull Process process, @NotNull String commandLine) { + super(process, commandLine, null); // do not access EncodingManager here myWriter = new BufferedWriter(new OutputStreamWriter(process.getOutputStream())); } diff --git a/platform/platform-impl/src/com/intellij/remote/BaseRemoteProcessHandler.java b/platform/platform-impl/src/com/intellij/remote/BaseRemoteProcessHandler.java index 9e9a104ab867..fe613e4e08fc 100644 --- a/platform/platform-impl/src/com/intellij/remote/BaseRemoteProcessHandler.java +++ b/platform/platform-impl/src/com/intellij/remote/BaseRemoteProcessHandler.java @@ -15,12 +15,12 @@ */ package com.intellij.remote; +import com.intellij.execution.CommandLineUtil; import com.intellij.execution.TaskExecutor; import com.intellij.execution.process.*; import com.intellij.openapi.application.Application; import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.diagnostic.Logger; -import com.intellij.openapi.util.text.StringUtil; import com.intellij.util.Consumer; import com.intellij.util.io.BaseOutputReader; import org.jetbrains.annotations.NotNull; @@ -37,7 +37,7 @@ import java.util.concurrent.Future; */ public class BaseRemoteProcessHandler extends AbstractRemoteProcessHandler implements TaskExecutor { private static final Logger LOG = Logger.getInstance(BaseRemoteProcessHandler.class); - @Nullable + @NotNull protected final String myCommandLine; protected final ProcessWaitFor myWaitFor; @Nullable @@ -45,14 +45,15 @@ public class BaseRemoteProcessHandler extends AbstractR protected T myProcess; public BaseRemoteProcessHandler(@NotNull T process, - @Nullable String commandLine, + @NotNull String commandLine, @Nullable Charset charset) { myProcess = process; myCommandLine = commandLine; - myWaitFor = new ProcessWaitFor(process, this, StringUtil.notNullize(commandLine)); + myWaitFor = new ProcessWaitFor(process, this, CommandLineUtil.extractPresentableName(commandLine)); myCharset = charset; } + @Override public T getProcess() { return myProcess; } @@ -66,15 +67,13 @@ public class BaseRemoteProcessHandler extends AbstractR @Override public void startNotify() { - if (myCommandLine != null) { - notifyTextAvailable(myCommandLine + '\n', ProcessOutputTypes.SYSTEM); - } + notifyTextAvailable(myCommandLine + '\n', ProcessOutputTypes.SYSTEM); addProcessListener(new ProcessAdapter() { @Override public void startNotified(final ProcessEvent event) { try { - final RemoteOutputReader stdoutReader = new RemoteOutputReader(myProcess.getInputStream(), getCharset(), myProcess) { + final RemoteOutputReader stdoutReader = new RemoteOutputReader(myProcess.getInputStream(), getCharset(), myProcess, myCommandLine) { @Override protected void onTextAvailable(@NotNull String text) { notifyTextAvailable(text, ProcessOutputTypes.STDOUT); @@ -87,7 +86,7 @@ public class BaseRemoteProcessHandler extends AbstractR } }; - final RemoteOutputReader stderrReader = new RemoteOutputReader(myProcess.getErrorStream(), getCharset(), myProcess) { + final RemoteOutputReader stderrReader = new RemoteOutputReader(myProcess.getErrorStream(), getCharset(), myProcess, myCommandLine) { @Override protected void onTextAvailable(@NotNull String text) { notifyTextAvailable(text, ProcessOutputTypes.STDERR); @@ -142,6 +141,7 @@ public class BaseRemoteProcessHandler extends AbstractR getProcess().destroy(); } + @Override protected void detachProcessImpl() { final Runnable runnable = new Runnable() { @Override @@ -197,18 +197,18 @@ public class BaseRemoteProcessHandler extends AbstractR } private abstract static class RemoteOutputReader extends BaseOutputReader { - @NotNull private final RemoteProcess myRemoteProcess; private boolean myClosed; - public RemoteOutputReader(@NotNull InputStream inputStream, Charset charset, @NotNull RemoteProcess remoteProcess) { + RemoteOutputReader(@NotNull InputStream inputStream, Charset charset, @NotNull RemoteProcess remoteProcess, @NotNull String commandLine) { super(inputStream, charset); myRemoteProcess = remoteProcess; - start(); + start(CommandLineUtil.extractPresentableName(commandLine)); } + @Override protected void doRun() { try { @@ -245,6 +245,7 @@ public class BaseRemoteProcessHandler extends AbstractR myClosed = closed; } + @Override public void waitFor() throws InterruptedException { while (!isClosed()) { Thread.sleep(100); diff --git a/platform/platform-impl/src/com/intellij/remote/ColoredRemoteProcessHandler.java b/platform/platform-impl/src/com/intellij/remote/ColoredRemoteProcessHandler.java index df1f0720a6ef..1ce65ecabcbb 100644 --- a/platform/platform-impl/src/com/intellij/remote/ColoredRemoteProcessHandler.java +++ b/platform/platform-impl/src/com/intellij/remote/ColoredRemoteProcessHandler.java @@ -1,3 +1,18 @@ +/* + * Copyright 2000-2015 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package com.intellij.remote; import com.intellij.execution.process.AnsiEscapeDecoder; @@ -14,7 +29,7 @@ public class ColoredRemoteProcessHandler extends BaseRe private final AnsiEscapeDecoder myAnsiEscapeDecoder = new AnsiEscapeDecoder(); public ColoredRemoteProcessHandler(@NotNull T process, - @Nullable String commandLine, @Nullable Charset charset) { + @NotNull String commandLine, @Nullable Charset charset) { super(process, commandLine, charset); } diff --git a/platform/util/src/com/intellij/execution/CommandLineUtil.java b/platform/util/src/com/intellij/execution/CommandLineUtil.java index 15c2c8605e2d..27139d3a52d2 100644 --- a/platform/util/src/com/intellij/execution/CommandLineUtil.java +++ b/platform/util/src/com/intellij/execution/CommandLineUtil.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2014 JetBrains s.r.o. + * Copyright 2000-2015 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,6 +20,8 @@ import com.intellij.openapi.util.text.StringUtil; import com.intellij.util.containers.ContainerUtil; import org.jetbrains.annotations.NotNull; +import java.io.File; +import java.util.Iterator; import java.util.List; public class CommandLineUtil { @@ -92,4 +94,25 @@ public class CommandLineUtil { private static boolean isQuoted(String s, char ch) { return s.length() >= 2 && s.charAt(0) == ch && s.charAt(s.length() - 1) == ch; } + + @NotNull + public static String extractPresentableName(@NotNull String commandLine) { + String executable = commandLine.trim(); + if (StringUtil.startsWithChar(executable, '\"') || StringUtil.startsWithChar(executable, '\'')) { + char quote = executable.charAt(0); + for (int i=1;i words = StringUtil.tokenize(commandLine, " \t\n\r\f").iterator(); + executable = words.hasNext() ? words.next() : executable; + } + + return new File(executable.trim()).getName(); + } } diff --git a/platform/util/src/com/intellij/execution/process/BaseOSProcessHandler.java b/platform/util/src/com/intellij/execution/process/BaseOSProcessHandler.java index dcd887019332..6b85cafd296f 100644 --- a/platform/util/src/com/intellij/execution/process/BaseOSProcessHandler.java +++ b/platform/util/src/com/intellij/execution/process/BaseOSProcessHandler.java @@ -15,6 +15,7 @@ */ package com.intellij.execution.process; +import com.intellij.execution.CommandLineUtil; import com.intellij.execution.TaskExecutor; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.util.Key; @@ -47,24 +48,22 @@ public class BaseOSProcessHandler extends ProcessHandler implements TaskExecutor protected final Process myProcess; protected final String myCommandLine; protected final Charset myCharset; - @NotNull private final String myPresentableName; + @NotNull protected final String myPresentableName; protected final ProcessWaitFor myWaitFor; - @Deprecated /** - * todo remove in IDEA16 - * @deprecated Use {@link BaseOSProcessHandler#BaseOSProcessHandler(Process, String, Charset, String)} instead + * + * @param commandLine must be not null (for correct thread attribution in the stacktrace) */ - public BaseOSProcessHandler(@NotNull Process process, @Nullable String commandLine, @Nullable Charset charset) { - this(process, commandLine, charset, StringUtil.notNullize(commandLine)); - } - - public BaseOSProcessHandler(@NotNull Process process, @Nullable String commandLine, @Nullable Charset charset, @NotNull String presentableName) { + public BaseOSProcessHandler(@NotNull Process process, /*NotNull*/String commandLine, @Nullable Charset charset) { myProcess = process; myCommandLine = commandLine; myCharset = charset; - myPresentableName = presentableName; - myWaitFor = new ProcessWaitFor(process, this, presentableName); + if (StringUtil.isEmpty(commandLine)) { + LOG.warn(new IllegalArgumentException("Must specify non-empty 'commandLine' parameter")); + } + myPresentableName = CommandLineUtil.extractPresentableName(StringUtil.notNullize(commandLine)); + myWaitFor = new ProcessWaitFor(process, this, myPresentableName); } /** @@ -246,7 +245,7 @@ public class BaseOSProcessHandler extends ProcessHandler implements TaskExecutor return myProcess.getOutputStream(); } - @Nullable + /*NotNull*/ public String getCommandLine() { return myCommandLine; } diff --git a/platform/util/src/com/intellij/util/io/OutputReader.java b/platform/util/src/com/intellij/util/io/OutputReader.java index e8bd4f30679e..5159766ea0f6 100644 --- a/platform/util/src/com/intellij/util/io/OutputReader.java +++ b/platform/util/src/com/intellij/util/io/OutputReader.java @@ -32,14 +32,14 @@ public abstract class OutputReader extends BaseOutputReader { private final Semaphore myReadFullySemaphore = new Semaphore(); - public OutputReader(@NotNull InputStream inputStream, @Nullable Charset charset, @Nullable SleepingPolicy sleepingPolicy) { + public OutputReader(@NotNull InputStream inputStream, @Nullable Charset charset, @Nullable SleepingPolicy sleepingPolicy, @NotNull String presentableName) { super(inputStream, charset, sleepingPolicy); - start(); + start(presentableName); } - public OutputReader(@NotNull InputStream inputStream, @Nullable Charset charset) { + public OutputReader(@NotNull InputStream inputStream, @Nullable Charset charset, @NotNull String presentableName) { super(inputStream, charset); - start(); + start(presentableName); } @Deprecated diff --git a/platform/util/testSrc/com/intellij/util/io/BaseOutputReaderTest.java b/platform/util/testSrc/com/intellij/util/io/BaseOutputReaderTest.java index 6e855a128589..4f616dd079da 100644 --- a/platform/util/testSrc/com/intellij/util/io/BaseOutputReaderTest.java +++ b/platform/util/testSrc/com/intellij/util/io/BaseOutputReaderTest.java @@ -15,6 +15,7 @@ */ package com.intellij.util.io; +import com.intellij.execution.CommandLineUtil; import com.intellij.openapi.util.SystemInfo; import com.intellij.openapi.util.text.StringUtil; import com.intellij.util.ConcurrencyUtil; @@ -48,9 +49,9 @@ public class BaseOutputReaderTest { private static class TestOutputReader extends BaseOutputReader { private final List myLines = Collections.synchronizedList(new ArrayList()); - public TestOutputReader(InputStream stream, SleepingPolicy sleepingPolicy) { + public TestOutputReader(InputStream stream, SleepingPolicy sleepingPolicy, String commandLine) { super(stream, null, sleepingPolicy); - start(BaseOutputReaderTest.class.getSimpleName()); + start(CommandLineUtil.extractPresentableName(commandLine)); } @Override @@ -96,8 +97,9 @@ public class BaseOutputReaderTest { File dir = new File(url.toURI()); for (int i = 0; i < StringUtil.countChars(className, '.') + 1; i++) dir = dir.getParentFile(); - Process process = new ProcessBuilder(java, "-cp", dir.getPath(), className).redirectErrorStream(true).start(); - TestOutputReader reader = new TestOutputReader(process.getInputStream(), policy); + String[] cmd = {java, "-cp", dir.getPath(), className}; + Process process = new ProcessBuilder(cmd).redirectErrorStream(true).start(); + TestOutputReader reader = new TestOutputReader(process.getInputStream(), policy, StringUtil.join(cmd, " ")); process.waitFor(); reader.stop(); reader.waitFor(); diff --git a/platform/vcs-impl/testSrc/com/intellij/openapi/vcs/Executor.java b/platform/vcs-impl/testSrc/com/intellij/openapi/vcs/Executor.java index 7acc62e9ae5d..6ee584fc92e0 100644 --- a/platform/vcs-impl/testSrc/com/intellij/openapi/vcs/Executor.java +++ b/platform/vcs-impl/testSrc/com/intellij/openapi/vcs/Executor.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2012 JetBrains s.r.o. + * Copyright 2000-2015 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -189,10 +189,11 @@ public class Executor { throw new RuntimeException(e); } - CapturingProcessHandler handler = new CapturingProcessHandler(clientProcess, CharsetToolkit.getDefaultSystemCharset()); + String commandLine = StringUtil.join(params, " "); + CapturingProcessHandler handler = new CapturingProcessHandler(clientProcess, CharsetToolkit.getDefaultSystemCharset(), commandLine); ProcessOutput result = handler.runProcess(30 * 1000); if (result.isTimeout()) { - throw new RuntimeException("Timeout waiting for the command execution. Command: " + StringUtil.join(params, " ")); + throw new RuntimeException("Timeout waiting for the command execution. Command: " + commandLine); } String stdout = result.getStdout().trim(); diff --git a/platform/vcs-impl/testSrc/com/intellij/testFramework/vcs/TestClientRunner.java b/platform/vcs-impl/testSrc/com/intellij/testFramework/vcs/TestClientRunner.java index 9c631f6c1ee0..bd8c95eb270a 100644 --- a/platform/vcs-impl/testSrc/com/intellij/testFramework/vcs/TestClientRunner.java +++ b/platform/vcs-impl/testSrc/com/intellij/testFramework/vcs/TestClientRunner.java @@ -92,7 +92,7 @@ public class TestClientRunner { } } - final CapturingProcessHandler handler = new CapturingProcessHandler(clientProcess, CharsetToolkit.getDefaultSystemCharset()); + final CapturingProcessHandler handler = new CapturingProcessHandler(clientProcess, CharsetToolkit.getDefaultSystemCharset(), StringUtil.join(arguments, " ")); final ProcessOutput result = handler.runProcess(100*1000, false); if (myTraceClient || result.isTimeout()) { LOG.debug("*** result: " + result.getExitCode()); diff --git a/plugins/git4idea/src/git4idea/commands/GitTextHandler.java b/plugins/git4idea/src/git4idea/commands/GitTextHandler.java index c064265cda3c..466b030d9b8b 100644 --- a/plugins/git4idea/src/git4idea/commands/GitTextHandler.java +++ b/plugins/git4idea/src/git4idea/commands/GitTextHandler.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2014 JetBrains s.r.o. + * Copyright 2000-2015 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -137,17 +137,13 @@ public abstract class GitTextHandler extends GitHandler { } public ProcessHandler createProcess(@NotNull GeneralCommandLine commandLine) throws ExecutionException { - Process process = commandLine.createProcess(); - return new MyOSProcessHandler(process, commandLine, getCharset()); + commandLine.setCharset(getCharset()); + return new MyOSProcessHandler(commandLine); } private static class MyOSProcessHandler extends OSProcessHandler { - @NotNull - private final Charset myCharset; - - public MyOSProcessHandler(Process process, GeneralCommandLine commandLine, @NotNull Charset charset) { - super(process, commandLine.getCommandLineString()); - myCharset = charset; + private MyOSProcessHandler(@NotNull GeneralCommandLine commandLine) throws ExecutionException { + super(commandLine); } @NotNull diff --git a/plugins/git4idea/src/git4idea/config/GitExecutableDetector.java b/plugins/git4idea/src/git4idea/config/GitExecutableDetector.java index 8a556d6826eb..8647e1b01041 100644 --- a/plugins/git4idea/src/git4idea/config/GitExecutableDetector.java +++ b/plugins/git4idea/src/git4idea/config/GitExecutableDetector.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2012 JetBrains s.r.o. + * Copyright 2000-2015 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -216,8 +216,9 @@ public class GitExecutableDetector { protected boolean runs(@NotNull String exec) { GeneralCommandLine commandLine = new GeneralCommandLine(); commandLine.setExePath(exec); + commandLine.setCharset(CharsetToolkit.getDefaultSystemCharset()); try { - CapturingProcessHandler handler = new CapturingProcessHandler(commandLine.createProcess(), CharsetToolkit.getDefaultSystemCharset()); + CapturingProcessHandler handler = new CapturingProcessHandler(commandLine); ProcessOutput result = handler.runProcess((int)TimeUnit.SECONDS.toMillis(5)); return !result.isTimeout(); } diff --git a/plugins/git4idea/src/git4idea/config/GitVersion.java b/plugins/git4idea/src/git4idea/config/GitVersion.java index 9ff365900eb0..ca0a6c22c252 100644 --- a/plugins/git4idea/src/git4idea/config/GitVersion.java +++ b/plugins/git4idea/src/git4idea/config/GitVersion.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2015 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -145,7 +145,8 @@ public final class GitVersion implements Comparable { GeneralCommandLine commandLine = new GeneralCommandLine(); commandLine.setExePath(gitExecutable); commandLine.addParameter("--version"); - CapturingProcessHandler handler = new CapturingProcessHandler(commandLine.createProcess(), CharsetToolkit.getDefaultSystemCharset()); + commandLine.setCharset(CharsetToolkit.getDefaultSystemCharset()); + CapturingProcessHandler handler = new CapturingProcessHandler(commandLine); ProgressIndicator indicator = ProgressManager.getInstance().getProgressIndicator(); ProcessOutput result = indicator == null ? handler.runProcess(ExecutableValidator.TIMEOUT_MS) : diff --git a/plugins/google-app-engine/jps-plugin/src/org/jetbrains/jps/appengine/build/EnhancerProcessHandlerBase.java b/plugins/google-app-engine/jps-plugin/src/org/jetbrains/jps/appengine/build/EnhancerProcessHandlerBase.java index a2c075b92d21..199ba864345c 100644 --- a/plugins/google-app-engine/jps-plugin/src/org/jetbrains/jps/appengine/build/EnhancerProcessHandlerBase.java +++ b/plugins/google-app-engine/jps-plugin/src/org/jetbrains/jps/appengine/build/EnhancerProcessHandlerBase.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2013 JetBrains s.r.o. + * Copyright 2000-2015 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -24,6 +24,7 @@ import com.intellij.openapi.util.Key; import com.intellij.openapi.util.io.FileUtil; import com.intellij.util.containers.FactoryMap; import org.jetbrains.annotations.NonNls; +import org.jetbrains.annotations.NotNull; import java.io.File; import java.io.IOException; @@ -41,7 +42,7 @@ public abstract class EnhancerProcessHandlerBase extends BaseOSProcessHandler { } }; - public EnhancerProcessHandlerBase(Process process, String commandLine, Charset charset) { + public EnhancerProcessHandlerBase(Process process, @NotNull String commandLine, Charset charset) { super(process, commandLine, charset); addProcessListener(new ProcessAdapter() { @Override diff --git a/plugins/google-app-engine/source/com/intellij/appengine/actions/AppEngineUploader.java b/plugins/google-app-engine/source/com/intellij/appengine/actions/AppEngineUploader.java index a7688f721b3c..0d1dbd276ba2 100644 --- a/plugins/google-app-engine/source/com/intellij/appengine/actions/AppEngineUploader.java +++ b/plugins/google-app-engine/source/com/intellij/appengine/actions/AppEngineUploader.java @@ -184,9 +184,8 @@ public class AppEngineUploader { } private void startUploadingProcess() { - final Process process; - final GeneralCommandLine commandLine; + final ProcessHandler processHandler; try { JavaParameters parameters = new JavaParameters(); parameters.configureByModule(myAppEngineFacet.getModule(), JavaParameters.JDK_ONLY); @@ -213,15 +212,14 @@ public class AppEngineUploader { programParameters.add("update"); programParameters.add(FileUtil.toSystemDependentName(myArtifact.getOutputPath())); - commandLine = CommandLineBuilder.createFromJavaParameters(parameters); - process = commandLine.createProcess(); + final GeneralCommandLine commandLine = CommandLineBuilder.createFromJavaParameters(parameters); + processHandler = new OSProcessHandler(commandLine); } catch (ExecutionException e) { myCallback.errorOccurred("Cannot start uploading: " + e.getMessage()); return; } - final ProcessHandler processHandler = new OSProcessHandler(process, commandLine.getCommandLineString()); processHandler.addProcessListener(new MyProcessListener(processHandler, null, myLoggingHandler)); myLoggingHandler.attachToProcess(processHandler); processHandler.startNotify(); diff --git a/plugins/google-app-engine/source/com/intellij/appengine/enhancement/EnhancerProcessHandler.java b/plugins/google-app-engine/source/com/intellij/appengine/enhancement/EnhancerProcessHandler.java index a2c518eb4f75..303114b1e4e8 100644 --- a/plugins/google-app-engine/source/com/intellij/appengine/enhancement/EnhancerProcessHandler.java +++ b/plugins/google-app-engine/source/com/intellij/appengine/enhancement/EnhancerProcessHandler.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2013 JetBrains s.r.o. + * Copyright 2000-2015 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,6 +17,7 @@ package com.intellij.appengine.enhancement; import com.intellij.openapi.compiler.CompileContext; import com.intellij.openapi.compiler.CompilerMessageCategory; +import org.jetbrains.annotations.NotNull; import org.jetbrains.jps.appengine.build.EnhancerProcessHandlerBase; /** @@ -25,7 +26,7 @@ import org.jetbrains.jps.appengine.build.EnhancerProcessHandlerBase; public class EnhancerProcessHandler extends EnhancerProcessHandlerBase { private final CompileContext myContext; - public EnhancerProcessHandler(final Process process, final String commandLine, CompileContext context) { + public EnhancerProcessHandler(final Process process, @NotNull String commandLine, CompileContext context) { super(process, commandLine, null); myContext = context; } diff --git a/plugins/groovy/jps-plugin/src/org/jetbrains/jps/incremental/groovy/ForkedGroovyc.java b/plugins/groovy/jps-plugin/src/org/jetbrains/jps/incremental/groovy/ForkedGroovyc.java index 81a1c3749f53..e3277fd0df33 100644 --- a/plugins/groovy/jps-plugin/src/org/jetbrains/jps/incremental/groovy/ForkedGroovyc.java +++ b/plugins/groovy/jps-plugin/src/org/jetbrains/jps/incremental/groovy/ForkedGroovyc.java @@ -96,7 +96,7 @@ class ForkedGroovyc implements GroovycFlavor { getProgramParams(tempFile, settings, forStubs) ); final Process process = Runtime.getRuntime().exec(ArrayUtil.toStringArray(cmd)); - ProcessHandler handler = new BaseOSProcessHandler(process, null, null) { + ProcessHandler handler = new BaseOSProcessHandler(process, StringUtil.join(cmd, " "), null) { @NotNull @Override protected Future executeOnPooledThread(@NotNull Runnable task) { diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/console/GroovyConsole.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/console/GroovyConsole.java index b337fb10aa9b..ac03ca70ad3d 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/console/GroovyConsole.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/console/GroovyConsole.java @@ -220,8 +220,7 @@ public class GroovyConsole { assert sdkType instanceof JavaSdkType; final String exePath = ((JavaSdkType)sdkType).getVMExecutablePath(sdk); final GeneralCommandLine commandLine = JdkUtil.setupJVMCommandLine(exePath, javaParameters, true); - final Process process = commandLine.createProcess(); - return new OSProcessHandler(process, commandLine.getCommandLineString()) { + return new OSProcessHandler(commandLine) { @Override public boolean isSilentlyDestroyOnClose() { return true; diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/mvc/MvcConsole.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/mvc/MvcConsole.java index c3e2c31ca0fc..e36a96e417d0 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/mvc/MvcConsole.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/mvc/MvcConsole.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2014 JetBrains s.r.o. + * Copyright 2000-2015 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -255,11 +255,10 @@ public class MvcConsole implements Disposable { myConsole.print(commandLine.getCommandLineString(), ConsoleViewContentType.SYSTEM_OUTPUT); final OSProcessHandler handler; try { - Process process = commandLine.createProcess(); - handler = new OSProcessHandler(process); + handler = new OSProcessHandler(commandLine); @SuppressWarnings("IOResourceOpenedButNotSafelyClosed") - OutputStreamWriter writer = new OutputStreamWriter(process.getOutputStream()); + OutputStreamWriter writer = new OutputStreamWriter(handler.getProcess().getOutputStream()); for (String s : input) { writer.write(s); } diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/shell/GroovyShellRunnerImpl.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/shell/GroovyShellRunnerImpl.java index fbd3542dc4ec..683f94e608f3 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/shell/GroovyShellRunnerImpl.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/shell/GroovyShellRunnerImpl.java @@ -17,6 +17,7 @@ package org.jetbrains.plugins.groovy.shell; import com.intellij.execution.ExecutionException; import com.intellij.execution.Executor; +import com.intellij.execution.configurations.GeneralCommandLine; import com.intellij.execution.configurations.JavaParameters; import com.intellij.execution.console.ConsoleHistoryController; import com.intellij.execution.console.LanguageConsoleView; @@ -34,7 +35,6 @@ import com.intellij.openapi.projectRoots.Sdk; import com.intellij.openapi.projectRoots.SdkTypeId; import com.intellij.openapi.roots.ModuleRootManager; import com.intellij.openapi.ui.Messages; -import com.intellij.openapi.util.Disposer; import com.intellij.openapi.util.Key; import com.intellij.util.Consumer; import org.jetbrains.annotations.NotNull; @@ -57,6 +57,7 @@ public class GroovyShellRunnerImpl extends AbstractConsoleRunnerWithHistory taskFiles = task.getTaskFiles(); - final CapturingProcessHandler handler = new CapturingProcessHandler(testProcess); + final CapturingProcessHandler handler = new CapturingProcessHandler(testProcess, null, commandLine); final ProcessOutput output = handler.runProcessWithProgressIndicator(indicator); if (indicator.isCanceled()) { ApplicationManager.getApplication().invokeLater(new Runnable() { diff --git a/python/educational/interactive-learning/src/com/jetbrains/edu/learning/actions/StudyRunAction.java b/python/educational/interactive-learning/src/com/jetbrains/edu/learning/actions/StudyRunAction.java index ebf0fa887538..aba8cd2e283a 100644 --- a/python/educational/interactive-learning/src/com/jetbrains/edu/learning/actions/StudyRunAction.java +++ b/python/educational/interactive-learning/src/com/jetbrains/edu/learning/actions/StudyRunAction.java @@ -67,17 +67,15 @@ public class StudyRunAction extends DumbAwareAction { String sdkHomePath = sdk.getHomePath(); if (sdkHomePath != null) { cmd.setExePath(sdkHomePath); - Process process; StudyUtils.setCommandLineParameters(cmd, project, filePath, sdkHomePath, currentTask); try { - process = cmd.createProcess(); + myHandler = new OSProcessHandler(cmd); } catch (ExecutionException e) { LOG.error(e); return; } - myHandler = new OSProcessHandler(process); for (ProcessListener processListener : myProcessListeners) { myHandler.addProcessListener(processListener); diff --git a/python/educational/interactive-learning/src/com/jetbrains/edu/learning/run/StudySmartChecker.java b/python/educational/interactive-learning/src/com/jetbrains/edu/learning/run/StudySmartChecker.java index 01eac4a9d6b4..d3a1b52f9df0 100644 --- a/python/educational/interactive-learning/src/com/jetbrains/edu/learning/run/StudySmartChecker.java +++ b/python/educational/interactive-learning/src/com/jetbrains/edu/learning/run/StudySmartChecker.java @@ -14,10 +14,10 @@ import com.jetbrains.edu.EduDocumentListener; import com.jetbrains.edu.EduNames; import com.jetbrains.edu.EduUtils; import com.jetbrains.edu.courseFormat.AnswerPlaceholder; +import com.jetbrains.edu.courseFormat.StudyStatus; import com.jetbrains.edu.courseFormat.TaskFile; import com.jetbrains.edu.learning.StudyTaskManager; import com.jetbrains.edu.learning.StudyUtils; -import com.jetbrains.edu.courseFormat.StudyStatus; import org.jetbrains.annotations.NotNull; import java.io.File; @@ -68,7 +68,7 @@ public class StudySmartChecker { }); VirtualFile fileWindows = EduUtils.flushWindows(windowTaskFile, windowCopy, true); Process smartTestProcess = testRunner.createCheckProcess(project, windowCopy.getPath()); - final CapturingProcessHandler handler = new CapturingProcessHandler(smartTestProcess); + final CapturingProcessHandler handler = new CapturingProcessHandler(smartTestProcess, null, windowCopy.getPath()); final ProcessOutput output = handler.runProcess(); boolean res = testRunner.getTestsOutput(output).isSuccess(); StudyTaskManager.getInstance(project).setStatus(userAnswerPlaceholder, res ? StudyStatus.Solved : StudyStatus.Failed); diff --git a/python/pydevSrc/com/jetbrains/python/debugger/pydev/RemoteDebugger.java b/python/pydevSrc/com/jetbrains/python/debugger/pydev/RemoteDebugger.java index ddff587b8a58..7778a06a4730 100644 --- a/python/pydevSrc/com/jetbrains/python/debugger/pydev/RemoteDebugger.java +++ b/python/pydevSrc/com/jetbrains/python/debugger/pydev/RemoteDebugger.java @@ -490,7 +490,7 @@ public class RemoteDebugger implements ProcessDebugger { private DebuggerReader(final InputStream stream) throws IOException { super(stream, CharsetToolkit.UTF8_CHARSET, SleepingPolicy.BLOCKING); //TODO: correct encoding? - start(); + start(getClass().getName()); } protected void doRun() { diff --git a/python/src/com/jetbrains/pyqt/CompileQrcAction.java b/python/src/com/jetbrains/pyqt/CompileQrcAction.java index c5fd2da282dc..af5e7e1f50f1 100644 --- a/python/src/com/jetbrains/pyqt/CompileQrcAction.java +++ b/python/src/com/jetbrains/pyqt/CompileQrcAction.java @@ -65,7 +65,7 @@ public class CompileQrcAction extends AnAction { cmdLine.addParameter(vFile.getPath()); } try { - ProcessHandler process = new OSProcessHandler(cmdLine.createProcess(), cmdLine.getCommandLineString()); + ProcessHandler process = new OSProcessHandler(cmdLine); ProcessTerminatedListener.attach(process); new RunContentExecutor(project, process) .withTitle("Compile .qrc") diff --git a/python/src/com/jetbrains/python/console/PyConsoleProcessHandler.java b/python/src/com/jetbrains/python/console/PyConsoleProcessHandler.java index 161344107d1b..b6a0f7b0d932 100644 --- a/python/src/com/jetbrains/python/console/PyConsoleProcessHandler.java +++ b/python/src/com/jetbrains/python/console/PyConsoleProcessHandler.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2014 JetBrains s.r.o. + * Copyright 2000-2015 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,6 +21,7 @@ import com.intellij.openapi.util.Key; import com.intellij.openapi.util.text.StringUtil; import com.intellij.util.ui.UIUtil; import com.jetbrains.python.run.PythonProcessHandler; +import org.jetbrains.annotations.NotNull; import java.nio.charset.Charset; @@ -33,7 +34,8 @@ public class PyConsoleProcessHandler extends PythonProcessHandler { public PyConsoleProcessHandler(final Process process, PythonConsoleView consoleView, - PydevConsoleCommunication pydevConsoleCommunication, final String commandLine, + PydevConsoleCommunication pydevConsoleCommunication, + @NotNull String commandLine, final Charset charset) { super(process, commandLine, charset); myConsoleView = consoleView; diff --git a/python/src/com/jetbrains/python/console/PydevConsoleRunner.java b/python/src/com/jetbrains/python/console/PydevConsoleRunner.java index 3d741a15a99a..6afa2ec73f5f 100644 --- a/python/src/com/jetbrains/python/console/PydevConsoleRunner.java +++ b/python/src/com/jetbrains/python/console/PydevConsoleRunner.java @@ -328,6 +328,7 @@ public class PydevConsoleRunner extends AbstractConsoleRunnerWithHistory environment = new HashMap(System.getenv()); PythonEnvUtil.setPythonUnbuffered(environment); PythonEnvUtil.setPythonDontWriteBytecode(environment); - final GeneralCommandLine commandLine = new GeneralCommandLine(cmdline).withWorkDirectory(workingDir).withEnvironment(environment); + GeneralCommandLine commandLine = new GeneralCommandLine(cmdline).withWorkDirectory(workingDir).withEnvironment(environment); if (useSudo) { - process = ExecUtil.sudo(commandLine, "Please enter your password to make changes in system packages: "); + commandLine = ExecUtil.sudoCommand(commandLine, "Please enter your password to make changes in system packages: "); } - else { - process = commandLine.createProcess(); - } - final CapturingProcessHandler handler = new CapturingProcessHandler(process); + final CapturingProcessHandler handler = new CapturingProcessHandler(commandLine); final ProgressIndicator indicator = ProgressManager.getInstance().getProgressIndicator(); final ProcessOutput result; if (showProgress && indicator != null) { diff --git a/python/src/com/jetbrains/python/packaging/ui/PyCondaManagementService.java b/python/src/com/jetbrains/python/packaging/ui/PyCondaManagementService.java index 0a545e5416c5..e9de093485dc 100644 --- a/python/src/com/jetbrains/python/packaging/ui/PyCondaManagementService.java +++ b/python/src/com/jetbrains/python/packaging/ui/PyCondaManagementService.java @@ -72,8 +72,7 @@ public class PyCondaManagementService extends PyPackageManagementService { final GeneralCommandLine commandLine = new GeneralCommandLine(parameters); try { - final Process process = commandLine.createProcess(); - final CapturingProcessHandler handler = new CapturingProcessHandler(process); + final CapturingProcessHandler handler = new CapturingProcessHandler(commandLine); final ProcessOutput result = handler.runProcess(); final int exitCode = result.getExitCode(); if (exitCode != 0) { @@ -96,8 +95,7 @@ public class PyCondaManagementService extends PyPackageManagementService { final GeneralCommandLine commandLine = new GeneralCommandLine(parameters); try { - final Process process = commandLine.createProcess(); - final CapturingProcessHandler handler = new CapturingProcessHandler(process); + final CapturingProcessHandler handler = new CapturingProcessHandler(commandLine); final ProcessOutput result = handler.runProcess(); final int exitCode = result.getExitCode(); if (exitCode != 0) { diff --git a/python/src/com/jetbrains/python/remote/PyRemoteProcessHandlerBase.java b/python/src/com/jetbrains/python/remote/PyRemoteProcessHandlerBase.java index cd336fc7b16a..8bdb9d65a622 100644 --- a/python/src/com/jetbrains/python/remote/PyRemoteProcessHandlerBase.java +++ b/python/src/com/jetbrains/python/remote/PyRemoteProcessHandlerBase.java @@ -1,3 +1,18 @@ +/* + * Copyright 2000-2015 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package com.jetbrains.python.remote; import com.intellij.remote.ColoredRemoteProcessHandler; @@ -12,7 +27,7 @@ import java.nio.charset.Charset; */ public abstract class PyRemoteProcessHandlerBase extends ColoredRemoteProcessHandler implements PyRemoteProcessControl { public PyRemoteProcessHandlerBase(@NotNull RemoteProcess process, - @Nullable String commandLine, + @NotNull String commandLine, @Nullable Charset charset) { super(process, commandLine, charset); } diff --git a/python/src/com/jetbrains/python/run/PythonProcessHandler.java b/python/src/com/jetbrains/python/run/PythonProcessHandler.java index 7ae0709ccce6..06897647f08f 100644 --- a/python/src/com/jetbrains/python/run/PythonProcessHandler.java +++ b/python/src/com/jetbrains/python/run/PythonProcessHandler.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2014 JetBrains s.r.o. + * Copyright 2000-2015 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -37,7 +37,7 @@ public class PythonProcessHandler extends KillableColoredProcessHandler { super(commandLine, softKillOnWin); } - public PythonProcessHandler(Process process, String commandLine, @NotNull Charset charset) { + public PythonProcessHandler(Process process, @NotNull String commandLine, @NotNull Charset charset) { super(process, commandLine, charset); } diff --git a/python/src/com/jetbrains/python/sdk/PySdkUtil.java b/python/src/com/jetbrains/python/sdk/PySdkUtil.java index 386966488643..33dc9a0ced13 100644 --- a/python/src/com/jetbrains/python/sdk/PySdkUtil.java +++ b/python/src/com/jetbrains/python/sdk/PySdkUtil.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2014 JetBrains s.r.o. + * Copyright 2000-2015 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -126,8 +126,8 @@ public class PySdkUtil { final Map env = extraEnv != null ? mergeEnvVariables(systemEnv, extraEnv) : systemEnv; try { - final Process process = cmd.withWorkDirectory(homePath).withEnvironment(env).createProcess(); - final CapturingProcessHandler processHandler = new CapturingProcessHandler(process); + GeneralCommandLine commandLine = cmd.withWorkDirectory(homePath).withEnvironment(env); + final CapturingProcessHandler processHandler = new CapturingProcessHandler(commandLine); if (stdin != null) { final OutputStream processInput = processHandler.getProcessInput(); assert processInput != null; diff --git a/python/testSrc/com/jetbrains/python/testing/JythonUnitTestUtil.java b/python/testSrc/com/jetbrains/python/testing/JythonUnitTestUtil.java index 1e0c1422178f..c6717c6fd6e2 100644 --- a/python/testSrc/com/jetbrains/python/testing/JythonUnitTestUtil.java +++ b/python/testSrc/com/jetbrains/python/testing/JythonUnitTestUtil.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2013 JetBrains s.r.o. + * Copyright 2000-2015 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -50,7 +50,7 @@ public class JythonUnitTestUtil { parameters.setWorkingDirectory(workDir); final GeneralCommandLine commandLine = JdkUtil.setupJVMCommandLine(sdkType.getVMExecutablePath(ideaJdk), parameters, false); - final CapturingProcessHandler processHandler = new CapturingProcessHandler(commandLine.createProcess()); + final CapturingProcessHandler processHandler = new CapturingProcessHandler(commandLine); return processHandler.runProcess(); } }