add environment arguments to commandline process factory
authorEugene.Petrenko <eugene.petrenko@gmail.com>
Thu, 25 Aug 2011 10:38:14 +0000 (12:38 +0200)
committerEugene.Petrenko <eugene.petrenko@gmail.com>
Thu, 25 Aug 2011 10:38:14 +0000 (12:38 +0200)
nuget-agent/src/jetbrains/buildServer/nuget/agent/commands/impl/NuGetActionFactoryImpl.java
nuget-agent/src/jetbrains/buildServer/nuget/agent/util/CommandlineBuildProcessFactory.java
nuget-agent/src/jetbrains/buildServer/nuget/agent/util/impl/CommandlineBuildProcessFactoryImpl.java
nuget-tests/src/jetbrains/buildServer/nuget/tests/agent/NuGetInstallPackageActionFactoryTest.java
nuget-tests/src/jetbrains/buildServer/nuget/tests/agent/NuGetPackActionFactoryTest.java
nuget-tests/src/jetbrains/buildServer/nuget/tests/agent/NuGetPushActoinFactoryTest.java
nuget-tests/src/jetbrains/buildServer/nuget/tests/agent/NuGetUpdatePackageActionFactoryTest.java
nuget-tests/src/jetbrains/buildServer/nuget/tests/integration/IntegrationTestBase.java

index db156a597e7101350f60daf1aa53db0252cb80cf..2cad02b591f0faeebc220609b5d00bdd32180491 100644 (file)
@@ -30,6 +30,7 @@ import org.jetbrains.annotations.NotNull;
 \r
 import java.io.File;\r
 import java.util.Collection;\r
+import java.util.Collections;\r
 \r
 /**\r
  * Created by Eugene Petrenko (eugene.petrenko@gmail.com)\r
@@ -58,7 +59,8 @@ public class NuGetActionFactoryImpl implements NuGetActionFactory {
                 context,\r
                 program,\r
                 argz,\r
-                workingDir\r
+                workingDir,\r
+                Collections.<String, String>emptyMap()\r
         );\r
       }\r
     };\r
index c01e642b8a4b5e0bbf49402556b266679a3a4f9d..aba0851e90ad63f7e7511aa12a7b90797b96fa17 100644 (file)
@@ -23,6 +23,7 @@ import org.jetbrains.annotations.NotNull;
 \r
 import java.io.File;\r
 import java.util.Collection;\r
+import java.util.Map;\r
 \r
 /**\r
  * Created by Eugene Petrenko (eugene.petrenko@gmail.com)\r
@@ -33,5 +34,6 @@ public interface CommandlineBuildProcessFactory {
   BuildProcess executeCommandLine(@NotNull BuildRunnerContext hostContext,\r
                                   @NotNull File program,\r
                                   @NotNull Collection<String> argz,\r
-                                  @NotNull File workingDir) throws RunBuildException;\r
+                                  @NotNull File workingDir,\r
+                                  @NotNull Map<String, String> additionalEnvironment) throws RunBuildException;\r
 }\r
index 767ea8485d9f80dfef1116f313951b19c9375a38..c104b9823bd3a72125148c636705536dc44f6d5b 100644 (file)
@@ -26,6 +26,7 @@ import org.jetbrains.annotations.NotNull;
 \r
 import java.io.File;\r
 import java.util.Collection;\r
+import java.util.Map;\r
 \r
 /**\r
  * Created by Eugene Petrenko (eugene.petrenko@gmail.com)\r
@@ -42,7 +43,8 @@ public class CommandlineBuildProcessFactoryImpl implements CommandlineBuildProce
   public BuildProcess executeCommandLine(@NotNull BuildRunnerContext hostContext,\r
                                          @NotNull File program,\r
                                          @NotNull Collection<String> argz,\r
-                                         @NotNull File workingDir) throws RunBuildException {\r
+                                         @NotNull File workingDir,\r
+                                         @NotNull final Map<String, String> additionalEnvironment) throws RunBuildException {\r
     BuildRunnerContext context = myFacade.createBuildRunnerContext(\r
             hostContext.getBuild(),\r
             SimpleRunnerConstants.TYPE,\r
@@ -50,6 +52,10 @@ public class CommandlineBuildProcessFactoryImpl implements CommandlineBuildProce
             hostContext\r
     );\r
 \r
+    for (Map.Entry<String, String> entry : additionalEnvironment.entrySet()) {\r
+      context.addEnvironmentVariable(entry.getKey(), entry.getValue());\r
+    }\r
+\r
     context.addRunnerParameter(SimpleRunnerConstants.COMMAND_EXECUTABLE, program.getPath());\r
     context.addRunnerParameter(SimpleRunnerConstants.COMMAND_PARAMETERS, joinCommandLineArguments(argz));\r
 \r
index e0a3e98a8c2df13990e965916d64e78df69102b0..c8924da33c513aa3dfa8ea7249d9931b83c3b67a 100644 (file)
@@ -81,7 +81,8 @@ public class NuGetInstallPackageActionFactoryTest extends BaseTestCase {
               ctx,\r
               nuget,\r
               Arrays.asList("install", myConfig.getPath(), "-OutputDirectory", myTarget.getPath()),\r
-              myConfig.getParentFile()\r
+              myConfig.getParentFile(),\r
+              Collections.<String, String>emptyMap()\r
       );\r
     }});\r
 \r
@@ -101,7 +102,8 @@ public class NuGetInstallPackageActionFactoryTest extends BaseTestCase {
               ctx,\r
               nuget,\r
               Arrays.asList("install", myConfig.getPath(), "-ExcludeVersion", "-OutputDirectory", myTarget.getPath()),\r
-              myConfig.getParentFile()\r
+              myConfig.getParentFile(),\r
+              Collections.<String, String>emptyMap()\r
       );\r
     }});\r
 \r
@@ -121,7 +123,8 @@ public class NuGetInstallPackageActionFactoryTest extends BaseTestCase {
               ctx,\r
               nuget,\r
               Arrays.asList("install", myConfig.getPath(), "-OutputDirectory", myTarget.getPath(), "-Source", "aaa", "-Source", "bbb"),\r
-              myConfig.getParentFile()\r
+              myConfig.getParentFile(),\r
+              Collections.<String, String>emptyMap()\r
       );\r
     }});\r
 \r
index ff522c3a20c316a3d8936b8e81a1fe71df2aa666..1d670cbd253e38aa8b2f1db5a79fe7bd195867bc 100644 (file)
@@ -34,6 +34,7 @@ import java.io.File;
 import java.util.ArrayList;\r
 import java.util.Arrays;\r
 import java.util.Collection;\r
+import java.util.Collections;\r
 \r
 /**\r
  * @author Eugene Petrenko (eugene.petrenko@gmail.com)\r
@@ -103,7 +104,8 @@ public class NuGetPackActionFactoryTest extends BaseTestCase {
       oneOf(myProcessFactory).executeCommandLine(ctx, myNuGet,\r
               Arrays.asList(\r
                       "pack", myFile.getPath(), "-OutputDirectory", myOut.getPath(), "-BasePath", myRoot.getPath(), "-Verbose", "-Version", "45.239.32.12")\r
-              , myWorkingDir);\r
+              , myWorkingDir,\r
+              Collections.<String, String>emptyMap());\r
     }});\r
 \r
     i.createPack(ctx, myPackParameters);\r
@@ -121,7 +123,8 @@ public class NuGetPackActionFactoryTest extends BaseTestCase {
       oneOf(myProcessFactory).executeCommandLine(ctx, myNuGet,\r
               Arrays.asList(\r
                       "pack", myFile.getPath(), "-OutputDirectory", myOut.getPath(), "-BasePath", myRoot.getPath(), "-Verbose", "-Version", "45.239.32.12", "-Properties", "p1=p2", "-Properties", "p3=p24")\r
-              , myWorkingDir);\r
+              , myWorkingDir,\r
+              Collections.<String, String>emptyMap());\r
     }});\r
 \r
     i.createPack(ctx, myPackParameters);\r
@@ -141,7 +144,8 @@ public class NuGetPackActionFactoryTest extends BaseTestCase {
       oneOf(myProcessFactory).executeCommandLine(ctx, myNuGet,\r
               Arrays.asList(\r
                       "pack", myFile.getPath(), "-OutputDirectory", myOut.getPath(), "-BasePath", myRoot.getPath(), "-Verbose", "-Version", "45.239.32.12", "arg1", "arg2")\r
-              , myWorkingDir);\r
+              , myWorkingDir,\r
+              Collections.<String, String>emptyMap());\r
     }});\r
 \r
     i.createPack(ctx, myPackParameters);\r
@@ -159,7 +163,8 @@ public class NuGetPackActionFactoryTest extends BaseTestCase {
       oneOf(myProcessFactory).executeCommandLine(ctx, myNuGet,\r
               Arrays.asList(\r
                       "pack", myFile.getPath(), "-OutputDirectory", myOut.getPath(), "-BasePath", myRoot.getPath(), "-Verbose", "-Version", "45.239.32.12", "-Exclude", "aaa", "-Exclude", "d/v/de")\r
-              , myWorkingDir);\r
+              , myWorkingDir,\r
+              Collections.<String, String>emptyMap());\r
     }});\r
 \r
     i.createPack(ctx, myPackParameters);\r
@@ -175,7 +180,8 @@ public class NuGetPackActionFactoryTest extends BaseTestCase {
       oneOf(myProcessFactory).executeCommandLine(ctx, myNuGet,\r
               Arrays.asList(\r
                       "pack", myFile.getPath(), "-OutputDirectory", myOut.getPath(), "-BasePath", myRoot.getPath(), "-Verbose", "-Version", "45.239.32.12", "-Tool")\r
-              , myWorkingDir);\r
+              , myWorkingDir,\r
+              Collections.<String, String>emptyMap());\r
     }});\r
 \r
     i.createPack(ctx, myPackParameters);\r
@@ -191,7 +197,8 @@ public class NuGetPackActionFactoryTest extends BaseTestCase {
       oneOf(myProcessFactory).executeCommandLine(ctx, myNuGet,\r
               Arrays.asList(\r
                       "pack", myFile.getPath(), "-OutputDirectory", myOut.getPath(), "-BasePath", myRoot.getPath(), "-Verbose", "-Version", "45.239.32.12", "-Symbols")\r
-              , myWorkingDir);\r
+              , myWorkingDir,\r
+              Collections.<String, String>emptyMap());\r
     }});\r
 \r
     i.createPack(ctx, myPackParameters);\r
index 167adf5ba1bb7fd1dab4523674304c6c37fe7921..a684e647ae074588b1fcde47a50a7899682f6ee8 100644 (file)
@@ -31,6 +31,7 @@ import org.testng.annotations.Test;
 \r
 import java.io.File;\r
 import java.util.Arrays;\r
+import java.util.Collections;\r
 \r
 /**\r
  * Created by Eugene Petrenko (eugene.petrenko@gmail.com)\r
@@ -68,7 +69,8 @@ public class NuGetPushActoinFactoryTest extends BaseTestCase {
       allowing(ps).getPublishSource(); will(returnValue("push-feed"));\r
       allowing(ps).getCreateOnly(); will(returnValue(false));\r
 \r
-      oneOf(myProcessFactory).executeCommandLine(ctx, myNuGet, Arrays.asList("push", myFile.getPath(), "api-key-guid", "-Source", "push-feed"), myFile.getParentFile());\r
+      oneOf(myProcessFactory).executeCommandLine(ctx, myNuGet, Arrays.asList("push", myFile.getPath(), "api-key-guid", "-Source", "push-feed"), myFile.getParentFile(),Collections.<String, String>emptyMap()\r
+      );\r
     }});\r
 \r
     i.createPush(ctx, ps, myFile);\r
@@ -84,7 +86,7 @@ public class NuGetPushActoinFactoryTest extends BaseTestCase {
       allowing(ps).getPublishSource(); will(returnValue(null));\r
       allowing(ps).getCreateOnly(); will(returnValue(false));\r
 \r
-      oneOf(myProcessFactory).executeCommandLine(ctx, myNuGet, Arrays.asList("push", myFile.getPath(), "api-key-guid"), myFile.getParentFile());\r
+      oneOf(myProcessFactory).executeCommandLine(ctx, myNuGet, Arrays.asList("push", myFile.getPath(), "api-key-guid"), myFile.getParentFile(), Collections.<String, String>emptyMap());\r
     }});\r
 \r
     i.createPush(ctx, ps, myFile);\r
@@ -100,7 +102,7 @@ public class NuGetPushActoinFactoryTest extends BaseTestCase {
       allowing(ps).getPublishSource(); will(returnValue("push-feed"));\r
       allowing(ps).getCreateOnly(); will(returnValue(true));\r
 \r
-      oneOf(myProcessFactory).executeCommandLine(ctx, myNuGet, Arrays.asList("push", myFile.getPath(), "api-key-guid", "-CreateOnly", "-Source", "push-feed"), myFile.getParentFile());\r
+      oneOf(myProcessFactory).executeCommandLine(ctx, myNuGet, Arrays.asList("push", myFile.getPath(), "api-key-guid", "-CreateOnly", "-Source", "push-feed"), myFile.getParentFile(), Collections.<String, String>emptyMap());\r
     }});\r
 \r
     i.createPush(ctx, ps, myFile);\r
index 348a4a6e2267f14200457a1563dc95afc945c09a..ef4860b0c9daf2256c88cfa90bf9645e7aac4a7d 100644 (file)
@@ -81,7 +81,8 @@ public class NuGetUpdatePackageActionFactoryTest extends BaseTestCase {
               ctx,\r
               nuget,\r
               Arrays.asList("update", myConfig.getPath(), "-Verbose", "-RepositoryPath", myTarget.getPath()),\r
-              myConfig.getParentFile()\r
+              myConfig.getParentFile(),\r
+              Collections.<String, String>emptyMap()\r
       );\r
     }});\r
 \r
@@ -102,7 +103,8 @@ public class NuGetUpdatePackageActionFactoryTest extends BaseTestCase {
               ctx,\r
               nuget,\r
               Arrays.asList("update", myConfig.getPath(), "-Verbose", "-RepositoryPath", myTarget.getPath(), "-Id", "aaa", "-Id", "bbb"),\r
-              myConfig.getParentFile()\r
+              myConfig.getParentFile(),\r
+              Collections.<String, String>emptyMap()\r
       );\r
     }});\r
 \r
@@ -123,7 +125,8 @@ public class NuGetUpdatePackageActionFactoryTest extends BaseTestCase {
               ctx,\r
               nuget,\r
               Arrays.asList("update", myConfig.getPath(), "-Safe", "-Verbose", "-RepositoryPath", myTarget.getPath()),\r
-              myConfig.getParentFile()\r
+              myConfig.getParentFile(),\r
+              Collections.<String, String>emptyMap()\r
       );\r
     }});\r
 \r
@@ -144,7 +147,8 @@ public class NuGetUpdatePackageActionFactoryTest extends BaseTestCase {
               ctx,\r
               nuget,\r
               Arrays.asList("update", myConfig.getPath(), "-Verbose", "-RepositoryPath", myTarget.getPath(), "-Source", "aaa", "-Source", "bbb"),\r
-              myConfig.getParentFile()\r
+              myConfig.getParentFile(),\r
+              Collections.<String, String>emptyMap()\r
       );\r
     }});\r
 \r
@@ -152,5 +156,4 @@ public class NuGetUpdatePackageActionFactoryTest extends BaseTestCase {
     m.assertIsSatisfied();\r
   }\r
 \r
-\r
 }\r
index e64f624204fdff61c359b02dfa123f8cff5e8ca2..b0c245221e1ebe39a726d935fd2ef95156065f0d 100644 (file)
@@ -41,6 +41,8 @@ import org.testng.annotations.BeforeMethod;
 \r
 import java.io.File;\r
 import java.util.Collection;\r
+import java.util.HashMap;\r
+import java.util.Map;\r
 \r
 /**\r
  * Created by Eugene Petrenko (eugene.petrenko@gmail.com)\r
@@ -114,7 +116,8 @@ public class IntegrationTestBase extends BuildProcessTestCase {
       public BuildProcess executeCommandLine(@NotNull final BuildRunnerContext hostContext,\r
                                              @NotNull final File program,\r
                                              @NotNull final Collection<String> argz,\r
-                                             @NotNull final File workingDir) throws RunBuildException {\r
+                                             @NotNull final File workingDir,\r
+                                             @NotNull final Map<String, String> additionalEnvironment) throws RunBuildException {\r
         return new BuildProcessBase() {\r
           @NotNull\r
           @Override\r
@@ -126,6 +129,11 @@ public class IntegrationTestBase extends BuildProcessTestCase {
             }\r
             cmd.setWorkingDirectory(workingDir);\r
 \r
+            Map<String, String> env = new HashMap<String, String>();\r
+            env.putAll(System.getenv());\r
+            env.putAll(additionalEnvironment);\r
+            cmd.setEnvParams(env);\r
+\r
             System.out.println("Run: " + cmd.getCommandLineString());\r
 \r
             ExecResult result = SimpleCommandLineProcessRunner.runCommand(cmd, new byte[0]);\r