Cleanup (OSProcessHandler(cl.startProcess(), cl.getCommandLine(), cl.getCharset()) -> OSProcessHandler(cl))

This commit is contained in:
Roman Shevchenko
2015-09-25 19:04:26 +03:00
parent 84b4bc94a5
commit 2dc2f33df5
11 changed files with 43 additions and 75 deletions
@@ -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.
@@ -15,31 +15,26 @@
*/
package com.intellij.execution.configurations;
import com.intellij.execution.ExecutionException;
import com.intellij.execution.process.ColoredProcessHandler;
import com.intellij.execution.process.DefaultJavaProcessHandler;
import com.intellij.execution.process.OSProcessHandler;
import com.intellij.execution.process.ProcessTerminatedListener;
import com.intellij.execution.ExecutionException;
import org.jetbrains.annotations.NotNull;
/**
* @author spleaner
*/
public class JavaCommandLineStateUtil {
private JavaCommandLineStateUtil() {
}
private JavaCommandLineStateUtil() { }
@NotNull
public static OSProcessHandler startProcess(@NotNull final GeneralCommandLine commandLine) throws ExecutionException {
public static OSProcessHandler startProcess(@NotNull GeneralCommandLine commandLine) throws ExecutionException {
return startProcess(commandLine, false);
}
@NotNull
public static OSProcessHandler startProcess(@NotNull final GeneralCommandLine commandLine,
final boolean ansiColoring) throws ExecutionException {
final OSProcessHandler processHandler = ansiColoring ? new ColoredProcessHandler(commandLine)
: new DefaultJavaProcessHandler(commandLine);
public static OSProcessHandler startProcess(@NotNull GeneralCommandLine commandLine, boolean ansiColoring) throws ExecutionException {
OSProcessHandler processHandler = ansiColoring ? new ColoredProcessHandler(commandLine) : new OSProcessHandler(commandLine);
ProcessTerminatedListener.attach(processHandler);
return processHandler;
}
@@ -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.
@@ -20,27 +20,22 @@ 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;
/** @deprecated use {@link OSProcessHandler} (to be removed in IDEA 17) */
@SuppressWarnings("unused")
public class DefaultJavaProcessHandler extends OSProcessHandler {
private final Charset myCharset;
public DefaultJavaProcessHandler(final JavaParameters javaParameters) throws ExecutionException {
this(CommandLineBuilder.createFromJavaParameters(javaParameters));
public DefaultJavaProcessHandler(@NotNull JavaParameters javaParameters) throws ExecutionException {
super(CommandLineBuilder.createFromJavaParameters(javaParameters));
}
public DefaultJavaProcessHandler(final GeneralCommandLine commandLine) throws ExecutionException {
this(commandLine.createProcess(), commandLine.getCommandLineString(), commandLine.getCharset());
public DefaultJavaProcessHandler(@NotNull GeneralCommandLine commandLine) throws ExecutionException {
super(commandLine);
}
public DefaultJavaProcessHandler(final Process process, final String commandLine, @NotNull final Charset charset) {
super(process, commandLine);
myCharset = charset;
}
@Override
public Charset getCharset() {
return myCharset;
public DefaultJavaProcessHandler(@NotNull Process process, @Nullable String commandLine, @NotNull Charset charset) {
super(process, commandLine, charset);
}
}
@@ -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.
@@ -68,7 +68,6 @@ import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.io.File;
import java.nio.charset.Charset;
import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;
import java.util.List;
@@ -199,17 +198,9 @@ public class RemoteExternalSystemCommunicationManager implements ExternalSystemC
throw new ExecutionException("No sdk is defined. Params: " + params);
}
final GeneralCommandLine commandLine = JdkUtil.setupJVMCommandLine(
((JavaSdkType)sdk.getSdkType()).getVMExecutablePath(sdk),
params,
false
);
final OSProcessHandler processHandler = new OSProcessHandler(commandLine.createProcess(), commandLine.getCommandLineString()) {
@Override
public Charset getCharset() {
return commandLine.getCharset();
}
};
String executablePath = ((JavaSdkType)sdk.getSdkType()).getVMExecutablePath(sdk);
GeneralCommandLine commandLine = JdkUtil.setupJVMCommandLine(executablePath, params, false);
OSProcessHandler processHandler = new OSProcessHandler(commandLine);
ProcessTerminatedListener.attach(processHandler);
return processHandler;
}
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2011 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.
@@ -114,12 +114,7 @@ public class SimpleJavaParameters extends SimpleProgramParameters {
assert sdk != null : "SDK should be defined";
final String exePath = ((JavaSdkType)sdk.getSdkType()).getVMExecutablePath(sdk);
final GeneralCommandLine commandLine = JdkUtil.setupJVMCommandLine(exePath, this, myUseDynamicClasspath);
final OSProcessHandler processHandler = new OSProcessHandler(commandLine.createProcess(), commandLine.getCommandLineString()) {
@Override
public Charset getCharset() {
return commandLine.getCharset();
}
};
final OSProcessHandler processHandler = new OSProcessHandler(commandLine);
ProcessTerminatedListener.attach(processHandler);
return processHandler;
}
@@ -18,10 +18,10 @@ package com.intellij.execution.process;
import com.intellij.execution.ExecutionException;
import com.intellij.execution.configurations.GeneralCommandLine;
import com.intellij.execution.configurations.PtyCommandLine;
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;
@@ -35,18 +35,15 @@ public class ColoredProcessHandler extends OSProcessHandler implements AnsiEscap
private final List<AnsiEscapeDecoder.ColoredTextAcceptor> myColoredTextListeners = ContainerUtil.newArrayList();
public ColoredProcessHandler(final GeneralCommandLine commandLine) throws ExecutionException {
super(commandLine.createProcess(), commandLine.getCommandLineString(), commandLine.getCharset());
setHasPty(commandLine instanceof PtyCommandLine);
public ColoredProcessHandler(@NotNull GeneralCommandLine commandLine) throws ExecutionException {
super(commandLine);
}
public ColoredProcessHandler(Process process, String commandLine) {
public ColoredProcessHandler(@NotNull Process process, @Nullable String commandLine) {
super(process, commandLine);
}
public ColoredProcessHandler(final Process process,
final String commandLine,
@NotNull final Charset charset) {
public ColoredProcessHandler(@NotNull Process process, @Nullable String commandLine, @NotNull Charset charset) {
super(process, commandLine, charset);
}
@@ -50,7 +50,7 @@ public class KillableColoredProcessHandler extends ColoredProcessHandler impleme
* Starts a process with a {@link RunnerMediator mediator} when {@code withMediator} is set to {@code true} and the platform is Windows.
*/
public KillableColoredProcessHandler(@NotNull GeneralCommandLine commandLine, boolean withMediator) throws ExecutionException {
super(mediate(commandLine, withMediator).createProcess(), commandLine.getCommandLineString(), commandLine.getCharset());
super(mediate(commandLine, withMediator));
myMediatedProcess = withMediator && MEDIATOR_KEY.get(commandLine) == Boolean.TRUE;
}
@@ -20,7 +20,7 @@ import com.intellij.execution.CantRunException;
import com.intellij.execution.ExecutionException;
import com.intellij.execution.configurations.GeneralCommandLine;
import com.intellij.execution.configurations.JavaParameters;
import com.intellij.execution.process.DefaultJavaProcessHandler;
import com.intellij.execution.process.OSProcessHandler;
import com.intellij.execution.process.ProcessOutputTypes;
import com.intellij.notification.NotificationDisplayType;
import com.intellij.notification.NotificationGroup;
@@ -209,8 +209,7 @@ public class GrabDependencies implements IntentionAction {
lines.put(grabText, JdkUtil.setupJVMCommandLine(exePath, javaParameters, true));
}
ProgressManager.getInstance().run(new Task.Backgroundable(project, "Processing @Grab annotations") {
ProgressManager.getInstance().run(new Task.Backgroundable(project, "Processing @Grab Annotations") {
@Override
public void run(@NotNull ProgressIndicator indicator) {
int jarCount = 0;
@@ -276,7 +275,7 @@ public class GrabDependencies implements IntentionAction {
return false;
}
private static class GrapeProcessHandler extends DefaultJavaProcessHandler {
private static class GrapeProcessHandler extends OSProcessHandler {
private final StringBuilder myStdOut = new StringBuilder();
private final StringBuilder myStdErr = new StringBuilder();
private final Module myModule;
@@ -15,6 +15,8 @@
*/
package org.zmlx.hg4idea.execution;
import com.intellij.execution.ExecutionException;
import com.intellij.execution.configurations.GeneralCommandLine;
import com.intellij.execution.process.OSProcessHandler;
import com.intellij.util.io.BaseDataReader;
import com.intellij.util.io.BinaryOutputReader;
@@ -23,7 +25,6 @@ import org.jetbrains.annotations.Nullable;
import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.nio.charset.Charset;
import java.util.concurrent.Future;
class HgCommandProcessHandler extends OSProcessHandler {
@@ -31,12 +32,9 @@ class HgCommandProcessHandler extends OSProcessHandler {
private final boolean myBinary;
private final ByteArrayOutputStream myBinaryOutput;
public HgCommandProcessHandler(@NotNull final Process process,
@Nullable final String commandLine,
@Nullable final Charset charset,
boolean isBinary) {
super(process, commandLine, charset);
myBinary = isBinary;
public HgCommandProcessHandler(@NotNull GeneralCommandLine commandLine, boolean binary) throws ExecutionException {
super(commandLine);
myBinary = binary;
myBinaryOutput = new ByteArrayOutputStream();
}
@@ -56,9 +56,7 @@ public final class ShellCommand {
public HgCommandResult execute(final boolean showTextOnIndicator, boolean isBinary) throws ShellCommandException, InterruptedException {
final ProgressIndicator indicator = ProgressManager.getInstance().getProgressIndicator();
try {
final Process process = myCommandLine.createProcess();
HgCommandProcessHandler processHandler =
new HgCommandProcessHandler(process, myCommandLine.toString(), myCommandLine.getCharset(), isBinary);
HgCommandProcessHandler processHandler = new HgCommandProcessHandler(myCommandLine, isBinary);
CapturingProcessAdapter outputAdapter = new CapturingProcessAdapter() {
@Override
@@ -19,8 +19,8 @@
package org.jetbrains.idea.maven.execution;
import com.intellij.execution.ExecutionException;
import com.intellij.execution.configurations.CommandLineBuilder;
import com.intellij.execution.configurations.JavaParameters;
import com.intellij.execution.process.DefaultJavaProcessHandler;
import com.intellij.execution.process.OSProcessHandler;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.progress.ProgressIndicator;
@@ -51,7 +51,7 @@ public class MavenExternalExecutor extends MavenExecutor {
super(parameters, RunnerBundle.message("external.executor.caption"), console);
try {
myJavaParameters = MavenExternalParameters.createJavaParameters(project, myParameters, coreSettings, runnerSettings);
myJavaParameters = MavenExternalParameters.createJavaParameters(project, myParameters, coreSettings, runnerSettings, null);
}
catch (ExecutionException e) {
myParameterCreationError = e;
@@ -67,7 +67,8 @@ public class MavenExternalExecutor extends MavenExecutor {
}
myProcessHandler =
new DefaultJavaProcessHandler(myJavaParameters) {
new OSProcessHandler(CommandLineBuilder.createFromJavaParameters(myJavaParameters)) {
@Override
public void notifyTextAvailable(String text, Key outputType) {
// todo move this logic to ConsoleAdapter class
if (!myConsole.isSuppressed(text)) {
@@ -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.
@@ -356,8 +356,7 @@ public class MavenServerManager extends RemoteObjectWrapper<MavenServer> impleme
GeneralCommandLine commandLine = JdkUtil.setupJVMCommandLine(exePath, params, false);
OSProcessHandler processHandler =
new OSProcessHandler(commandLine.createProcess(), commandLine.getCommandLineString(), commandLine.getCharset());
OSProcessHandler processHandler = new OSProcessHandler(commandLine);
processHandler.setShouldDestroyProcessRecursively(false);