From 2925825f9cb4c3ca1797f522cf9c8f8868a19b8a Mon Sep 17 00:00:00 2001 From: Roman Shevchenko Date: Wed, 24 Apr 2013 20:24:37 +0200 Subject: [PATCH] Command line API cleaned, take 2 --- .../openapi/projectRoots/JdkUtil.java | 2 +- .../configurations/GeneralCommandLine.java | 38 +++++-------------- .../execution/GeneralCommandLineTest.java | 2 +- .../connections/ConnectionOnProcess.java | 3 +- .../src/git4idea/commands/GitHandler.java | 3 +- .../plugins/groovy/mvc/MvcFramework.java | 2 +- 6 files changed, 17 insertions(+), 33 deletions(-) diff --git a/platform/lang-api/src/com/intellij/openapi/projectRoots/JdkUtil.java b/platform/lang-api/src/com/intellij/openapi/projectRoots/JdkUtil.java index fc5d141aad57..6eaa636943be 100644 --- a/platform/lang-api/src/com/intellij/openapi/projectRoots/JdkUtil.java +++ b/platform/lang-api/src/com/intellij/openapi/projectRoots/JdkUtil.java @@ -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; diff --git a/platform/platform-api/src/com/intellij/execution/configurations/GeneralCommandLine.java b/platform/platform-api/src/com/intellij/execution/configurations/GeneralCommandLine.java index 410cdfb06b7e..c49c42561748 100644 --- a/platform/platform-api/src/com/intellij/execution/configurations/GeneralCommandLine.java +++ b/platform/platform-api/src/com/intellij/execution/configurations/GeneralCommandLine.java @@ -48,7 +48,7 @@ public class GeneralCommandLine implements UserDataHolder { private String myExePath = null; private File myWorkDirectory = null; - private Map myEnvParams = null; + private final Map 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 getEnvironment() { - return myEnvParams != null ? Collections.unmodifiableMap(myEnvParams) : Collections.emptyMap(); + return myEnvParams; } /** @deprecated use {@link #getEnvironment()} (to remove in IDEA 14) */ @SuppressWarnings("unused") public Map getEnvParams() { - return myEnvParams; + return getEnvironment(); } - public void setEnvironment(@Nullable Map 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 envParams) { - myEnvParams = envParams; + public void setEnvParams(@Nullable Map 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 envVars = new THashMap(CaseInsensitiveStringHashingStrategy.INSTANCE); envVars.putAll(environment); diff --git a/platform/platform-tests/testSrc/com/intellij/execution/GeneralCommandLineTest.java b/platform/platform-tests/testSrc/com/intellij/execution/GeneralCommandLineTest.java index 8edda25b922a..7994aea2dd6c 100644 --- a/platform/platform-tests/testSrc/com/intellij/execution/GeneralCommandLineTest.java +++ b/platform/platform-tests/testSrc/com/intellij/execution/GeneralCommandLineTest.java @@ -229,7 +229,7 @@ public class GeneralCommandLineTest { } private static void checkEnvPassing(GeneralCommandLine commandLine, Map testEnv, boolean passParentEnv) throws Exception { - commandLine.setEnvironment(testEnv); + commandLine.getEnvironment().putAll(testEnv); commandLine.setPassParentEnvironment(passParentEnv); String output = execAndGetOutput(commandLine, null); diff --git a/plugins/cvs/cvs-core/src/com/intellij/cvsSupport2/connections/ConnectionOnProcess.java b/plugins/cvs/cvs-core/src/com/intellij/cvsSupport2/connections/ConnectionOnProcess.java index bcf34e8f48a0..b866d1cd9136 100644 --- a/plugins/cvs/cvs-core/src/com/intellij/cvsSupport2/connections/ConnectionOnProcess.java +++ b/plugins/cvs/cvs-core/src/com/intellij/cvsSupport2/connections/ConnectionOnProcess.java @@ -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( diff --git a/plugins/git4idea/src/git4idea/commands/GitHandler.java b/plugins/git4idea/src/git4idea/commands/GitHandler.java index 0669a9ee164e..0816bb93db0e 100644 --- a/plugins/git4idea/src/git4idea/commands/GitHandler.java +++ b/plugins/git4idea/src/git4idea/commands/GitHandler.java @@ -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(); diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/mvc/MvcFramework.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/mvc/MvcFramework.java index c9c968814d85..05948bb888ec 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/mvc/MvcFramework.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/mvc/MvcFramework.java @@ -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);