Command line API cleaned, take 2

This commit is contained in:
Roman Shevchenko
2013-04-24 20:24:37 +02:00
parent 69291499bd
commit 2925825f9c
6 changed files with 17 additions and 33 deletions
@@ -164,7 +164,7 @@ public class JdkUtil {
commandLine.setExePath(exePath);
final ParametersList vmParametersList = javaParameters.getVMParametersList();
commandLine.setEnvironment(javaParameters.getEnv());
commandLine.getEnvironment().putAll(javaParameters.getEnv());
commandLine.setPassParentEnvironment(javaParameters.isPassParentEnvs());
final Class commandLineWrapper;
@@ -48,7 +48,7 @@ public class GeneralCommandLine implements UserDataHolder {
private String myExePath = null;
private File myWorkDirectory = null;
private Map<String, String> myEnvParams = null;
private final Map<String, String> myEnvParams = ContainerUtil.newTroveMap();
private boolean myPassParentEnvironment = true;
private final ParametersList myProgramParams = new ParametersList();
private Charset myCharset = CharsetToolkit.getDefaultSystemCharset();
@@ -93,40 +93,22 @@ public class GeneralCommandLine implements UserDataHolder {
@NotNull
public Map<String, String> getEnvironment() {
return myEnvParams != null ? Collections.unmodifiableMap(myEnvParams) : Collections.<String, String>emptyMap();
return myEnvParams;
}
/** @deprecated use {@link #getEnvironment()} (to remove in IDEA 14) */
@SuppressWarnings("unused")
public Map<String, String> getEnvParams() {
return myEnvParams;
return getEnvironment();
}
public void setEnvironment(@Nullable Map<String, String> envVars) {
if (envVars != null) {
if (myEnvParams == null) myEnvParams = ContainerUtil.newHashMap();
myEnvParams.putAll(envVars);
}
}
public void setEnvironment(@NotNull String name, @NotNull String value) {
if (myEnvParams == null) myEnvParams = ContainerUtil.newHashMap();
myEnvParams.put(name, value);
}
public void removeEnvironment(@NotNull String name) {
if (myEnvParams != null) {
myEnvParams.remove(name);
if (myEnvParams.isEmpty()) {
myEnvParams = null;
}
}
}
/** @deprecated use {@link #setEnvironment(Map)} (to remove in IDEA 14) */
/** @deprecated use {@link #getEnvironment()} (to remove in IDEA 14) */
@SuppressWarnings("unused")
public void setEnvParams(@Nullable final Map<String, String> envParams) {
myEnvParams = envParams;
public void setEnvParams(@Nullable Map<String, String> envParams) {
myEnvParams.clear();
if (envParams != null) {
myEnvParams.putAll(envParams);
}
}
public void setPassParentEnvironment(boolean passParentEnvironment) {
@@ -271,7 +253,7 @@ public class GeneralCommandLine implements UserDataHolder {
environment.clear();
}
if (myEnvParams != null && !myEnvParams.isEmpty()) {
if (!myEnvParams.isEmpty()) {
if (SystemInfo.isWindows) {
THashMap<String, String> envVars = new THashMap<String, String>(CaseInsensitiveStringHashingStrategy.INSTANCE);
envVars.putAll(environment);
@@ -229,7 +229,7 @@ public class GeneralCommandLineTest {
}
private static void checkEnvPassing(GeneralCommandLine commandLine, Map<String, String> testEnv, boolean passParentEnv) throws Exception {
commandLine.setEnvironment(testEnv);
commandLine.getEnvironment().putAll(testEnv);
commandLine.setPassParentEnvironment(passParentEnv);
String output = execAndGetOutput(commandLine, null);
@@ -142,7 +142,8 @@ public abstract class ConnectionOnProcess implements IConnection {
protected synchronized void execute(GeneralCommandLine commandLine) throws AuthenticationException {
try {
commandLine.setEnvironment(EnvironmentUtil.getEnvironmentProperties());
commandLine.getEnvironment().clear();
commandLine.getEnvironment().putAll(EnvironmentUtil.getEnvironmentProperties());
myProcess = commandLine.createProcess();
myErrThread = new ReadProcessThread(
@@ -451,7 +451,8 @@ public abstract class GitHandler {
LOG.debug(String.format("handler=%s, port=%s", myHandlerNo, port));
addAuthListener(httpAuthenticator);
}
myCommandLine.setEnvironment(myEnv);
myCommandLine.getEnvironment().clear();
myCommandLine.getEnvironment().putAll(myEnv);
// start process
myProcess = startProcess();
startHandlingStreams();
@@ -389,7 +389,7 @@ public abstract class MvcFramework {
final VirtualFile griffonHome = getSdkRoot(module);
if (griffonHome != null) {
commandLine.setEnvironment(getSdkHomePropertyName(), FileUtil.toSystemDependentName(griffonHome.getPath()));
commandLine.getEnvironment().put(getSdkHomePropertyName(), FileUtil.toSystemDependentName(griffonHome.getPath()));
}
final VirtualFile root = findAppRoot(module);