re-implement hide of nuget api key in build logs, add more tests for it master
authorEugene.Petrenko <eugene.petrenko@gmail.com>
Thu, 25 Aug 2011 12:27:23 +0000 (14:27 +0200)
committerEugene.Petrenko <eugene.petrenko@gmail.com>
Thu, 25 Aug 2011 12:27:23 +0000 (14:27 +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 d27aee8f2a9de293e9acde79341db83611421d81..3e5f94a52cea58828de52c885efb56b61e55479a 100644 (file)
@@ -16,6 +16,7 @@
 \r
 package jetbrains.buildServer.nuget.agent.commands.impl;\r
 \r
+import com.intellij.openapi.diagnostic.Logger;\r
 import jetbrains.buildServer.RunBuildException;\r
 import jetbrains.buildServer.agent.BuildFinishedStatus;\r
 import jetbrains.buildServer.agent.BuildProcess;\r
@@ -26,10 +27,13 @@ import jetbrains.buildServer.nuget.agent.dependencies.PackageUsages;
 import jetbrains.buildServer.nuget.agent.parameters.*;\r
 import jetbrains.buildServer.nuget.agent.util.BuildProcessBase;\r
 import jetbrains.buildServer.nuget.agent.util.CommandlineBuildProcessFactory;\r
+import jetbrains.buildServer.util.StringUtil;\r
 import org.jetbrains.annotations.NotNull;\r
 \r
 import java.io.File;\r
+import java.util.ArrayList;\r
 import java.util.Collection;\r
+import java.util.List;\r
 import java.util.Map;\r
 \r
 /**\r
@@ -37,6 +41,8 @@ import java.util.Map;
  * Date: 07.07.11 17:49\r
  */\r
 public class NuGetActionFactoryImpl implements NuGetActionFactory {\r
+  private static final Logger LOG = Logger.getInstance(NuGetActionFactoryImpl.class.getName());\r
+\r
   private final CommandFactory myCommandFactory;\r
   private final CommandlineBuildProcessFactory myFactory;\r
   private final PackageUsages myPackageUsages;\r
@@ -54,11 +60,22 @@ public class NuGetActionFactoryImpl implements NuGetActionFactory {
       @NotNull\r
       public BuildProcess createCommand(@NotNull File program,\r
                                         @NotNull File workingDir,\r
-                                        @NotNull Collection<String> argz,\r
+                                        @NotNull Collection<String> _argz,\r
                                         @NotNull Map<String, String> additionalEnvironment) throws RunBuildException {\r
+        String cmd = context.getBuildParameters().getEnvironmentVariables().get("ComSpec");\r
+        if (StringUtil.isEmptyOrSpaces(cmd)) {\r
+          LOG.warn("Failed to find path to cmd.exe in %ComSpec% environment variable");\r
+          cmd = "cmd.exe";\r
+        }\r
+\r
+        List<String> argz = new ArrayList<String>();\r
+        argz.add("/c");\r
+        argz.add(program.getPath());\r
+        argz.addAll(_argz);\r
+\r
         return myFactory.executeCommandLine(\r
                 context,\r
-                program,\r
+                cmd,\r
                 argz,\r
                 workingDir,\r
                 additionalEnvironment\r
index aba0851e90ad63f7e7511aa12a7b90797b96fa17..4b2fa52c1b43537a3f7d8d20855da9b917e9f8ca 100644 (file)
@@ -32,7 +32,7 @@ import java.util.Map;
 public interface CommandlineBuildProcessFactory {\r
   @NotNull\r
   BuildProcess executeCommandLine(@NotNull BuildRunnerContext hostContext,\r
-                                  @NotNull File program,\r
+                                  @NotNull String program,\r
                                   @NotNull Collection<String> argz,\r
                                   @NotNull File workingDir,\r
                                   @NotNull Map<String, String> additionalEnvironment) throws RunBuildException;\r
index 45608c5029793e1e77f45be8ac4800337095f650..ab47ec445d8fa395fe225b698bb39fb724f8366d 100644 (file)
@@ -25,9 +25,7 @@ import jetbrains.buildServer.runner.SimpleRunnerConstants;
 import org.jetbrains.annotations.NotNull;\r
 \r
 import java.io.File;\r
-import java.util.ArrayList;\r
 import java.util.Collection;\r
-import java.util.List;\r
 import java.util.Map;\r
 \r
 /**\r
@@ -43,15 +41,10 @@ public class CommandlineBuildProcessFactoryImpl implements CommandlineBuildProce
 \r
   @NotNull\r
   public BuildProcess executeCommandLine(@NotNull BuildRunnerContext hostContext,\r
-                                         @NotNull File program,\r
-                                         @NotNull Collection<String> _argz,\r
+                                         @NotNull String program,\r
+                                         @NotNull Collection<String> argz,\r
                                          @NotNull File workingDir,\r
                                          @NotNull final Map<String, String> additionalEnvironment) throws RunBuildException {\r
-    final List<String> argz = new ArrayList<String>();\r
-    argz.add("/c");\r
-    argz.add(program.getPath());\r
-    argz.addAll(_argz);\r
-\r
     BuildRunnerContext context = myFacade.createBuildRunnerContext(\r
             hostContext.getBuild(),\r
             SimpleRunnerConstants.TYPE,\r
@@ -63,7 +56,7 @@ public class CommandlineBuildProcessFactoryImpl implements CommandlineBuildProce
       context.addEnvironmentVariable(entry.getKey(), entry.getValue());\r
     }\r
 \r
-    context.addRunnerParameter(SimpleRunnerConstants.COMMAND_EXECUTABLE, "%env.ComSpec%");\r
+    context.addRunnerParameter(SimpleRunnerConstants.COMMAND_EXECUTABLE, program);\r
     context.addRunnerParameter(SimpleRunnerConstants.COMMAND_PARAMETERS, joinCommandLineArguments(argz));\r
 \r
     return myFacade.createExecutable(hostContext.getBuild(), context);\r
index c8924da33c513aa3dfa8ea7249d9931b83c3b67a..09e51c65cd4c10502fa3eac661d2f779cb280a91 100644 (file)
@@ -18,6 +18,7 @@ package jetbrains.buildServer.nuget.tests.agent;
 \r
 import jetbrains.buildServer.BaseTestCase;\r
 import jetbrains.buildServer.RunBuildException;\r
+import jetbrains.buildServer.agent.BuildParametersMap;\r
 import jetbrains.buildServer.agent.BuildRunnerContext;\r
 import jetbrains.buildServer.nuget.agent.commands.impl.CommandFactoryImpl;\r
 import jetbrains.buildServer.nuget.agent.commands.impl.NuGetActionFactoryImpl;\r
@@ -48,6 +49,9 @@ public class NuGetInstallPackageActionFactoryTest extends BaseTestCase {
   private NuGetFetchParameters nugetParams;\r
   private File myTarget;\r
   private File myConfig;\r
+  private String cmd;\r
+  private BuildParametersMap myBuildParametersMap;\r
+\r
 \r
   @BeforeMethod\r
   @Override\r
@@ -64,7 +68,13 @@ public class NuGetInstallPackageActionFactoryTest extends BaseTestCase {
     myTarget = createTempDir();\r
     myConfig = createTempFile();\r
 \r
+    myBuildParametersMap = m.mock(BuildParametersMap.class);\r
+    cmd = System.getenv("ComSpec");\r
+\r
     m.checking(new Expectations(){{\r
+      allowing(ctx).getBuildParameters(); will(returnValue(myBuildParametersMap));\r
+      allowing(myBuildParametersMap).getEnvironmentVariables(); will(returnValue(Collections.singletonMap("ComSpec", cmd)));\r
+\r
       allowing(ps).getNuGetParameters(); will(returnValue(nugetParams));\r
     }});\r
   }\r
@@ -79,8 +89,8 @@ public class NuGetInstallPackageActionFactoryTest extends BaseTestCase {
 \r
       oneOf(myProcessFactory).executeCommandLine(\r
               ctx,\r
-              nuget,\r
-              Arrays.asList("install", myConfig.getPath(), "-OutputDirectory", myTarget.getPath()),\r
+              cmd,\r
+              Arrays.asList("/c", nuget.getPath(), "install", myConfig.getPath(), "-OutputDirectory", myTarget.getPath()),\r
               myConfig.getParentFile(),\r
               Collections.<String, String>emptyMap()\r
       );\r
@@ -100,8 +110,8 @@ public class NuGetInstallPackageActionFactoryTest extends BaseTestCase {
 \r
       oneOf(myProcessFactory).executeCommandLine(\r
               ctx,\r
-              nuget,\r
-              Arrays.asList("install", myConfig.getPath(), "-ExcludeVersion", "-OutputDirectory", myTarget.getPath()),\r
+              cmd,\r
+              Arrays.asList("/c", nuget.getPath(), "install", myConfig.getPath(), "-ExcludeVersion", "-OutputDirectory", myTarget.getPath()),\r
               myConfig.getParentFile(),\r
               Collections.<String, String>emptyMap()\r
       );\r
@@ -121,8 +131,8 @@ public class NuGetInstallPackageActionFactoryTest extends BaseTestCase {
 \r
       oneOf(myProcessFactory).executeCommandLine(\r
               ctx,\r
-              nuget,\r
-              Arrays.asList("install", myConfig.getPath(), "-OutputDirectory", myTarget.getPath(), "-Source", "aaa", "-Source", "bbb"),\r
+              cmd,\r
+              Arrays.asList("/c", nuget.getPath(), "install", myConfig.getPath(), "-OutputDirectory", myTarget.getPath(), "-Source", "aaa", "-Source", "bbb"),\r
               myConfig.getParentFile(),\r
               Collections.<String, String>emptyMap()\r
       );\r
index 1d670cbd253e38aa8b2f1db5a79fe7bd195867bc..37da9d799410efb047b132bceec77243d73b68e9 100644 (file)
@@ -19,6 +19,7 @@ package jetbrains.buildServer.nuget.tests.agent;
 import jetbrains.buildServer.BaseTestCase;\r
 import jetbrains.buildServer.RunBuildException;\r
 import jetbrains.buildServer.agent.AgentRunningBuild;\r
+import jetbrains.buildServer.agent.BuildParametersMap;\r
 import jetbrains.buildServer.agent.BuildRunnerContext;\r
 import jetbrains.buildServer.nuget.agent.commands.impl.CommandFactoryImpl;\r
 import jetbrains.buildServer.nuget.agent.commands.impl.NuGetActionFactoryImpl;\r
@@ -55,6 +56,9 @@ public class NuGetPackActionFactoryTest extends BaseTestCase {
   private Collection<String> myExcludes;\r
   private Collection<String> myProperties;\r
   private Collection<String> myExtra;\r
+  private String cmd;\r
+  private BuildParametersMap myBuildParametersMap;\r
+\r
 \r
 \r
   @BeforeMethod\r
@@ -78,8 +82,14 @@ public class NuGetPackActionFactoryTest extends BaseTestCase {
     myExcludes = new ArrayList<String>();\r
     myProperties = new ArrayList<String>();\r
     myExtra = new ArrayList<String>();\r
+    myBuildParametersMap = m.mock(BuildParametersMap.class);\r
+    cmd = System.getenv("ComSpec");\r
 \r
     m.checking(new Expectations(){{\r
+      allowing(ctx).getBuildParameters(); will(returnValue(myBuildParametersMap));\r
+      allowing(myBuildParametersMap).getEnvironmentVariables(); will(returnValue(Collections.singletonMap("ComSpec", cmd)));\r
+\r
+\r
       allowing(ctx).getBuild(); will(returnValue(build));\r
       allowing(build).getCheckoutDirectory(); will(returnValue(myWorkingDir));\r
       allowing(myPackParameters).getSpecFile(); will(returnValue(myFile));\r
@@ -101,9 +111,9 @@ public class NuGetPackActionFactoryTest extends BaseTestCase {
       allowing(myPackParameters).packTool(); will(returnValue(false));\r
       allowing(myPackParameters).packSymbols(); will(returnValue(false));\r
 \r
-      oneOf(myProcessFactory).executeCommandLine(ctx, myNuGet,\r
+      oneOf(myProcessFactory).executeCommandLine(ctx, cmd,\r
               Arrays.asList(\r
-                      "pack", myFile.getPath(), "-OutputDirectory", myOut.getPath(), "-BasePath", myRoot.getPath(), "-Verbose", "-Version", "45.239.32.12")\r
+                      "/c", myNuGet.getPath(), "pack", myFile.getPath(), "-OutputDirectory", myOut.getPath(), "-BasePath", myRoot.getPath(), "-Verbose", "-Version", "45.239.32.12")\r
               , myWorkingDir,\r
               Collections.<String, String>emptyMap());\r
     }});\r
@@ -120,9 +130,9 @@ public class NuGetPackActionFactoryTest extends BaseTestCase {
       allowing(myPackParameters).packTool(); will(returnValue(false));\r
       allowing(myPackParameters).packSymbols(); will(returnValue(false));\r
 \r
-      oneOf(myProcessFactory).executeCommandLine(ctx, myNuGet,\r
+      oneOf(myProcessFactory).executeCommandLine(ctx, cmd,\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
+                      "/c", myNuGet.getPath(), "pack", myFile.getPath(), "-OutputDirectory", myOut.getPath(), "-BasePath", myRoot.getPath(), "-Verbose", "-Version", "45.239.32.12", "-Properties", "p1=p2", "-Properties", "p3=p24")\r
               , myWorkingDir,\r
               Collections.<String, String>emptyMap());\r
     }});\r
@@ -141,9 +151,9 @@ public class NuGetPackActionFactoryTest extends BaseTestCase {
       allowing(myPackParameters).packSymbols();\r
       will(returnValue(false));\r
 \r
-      oneOf(myProcessFactory).executeCommandLine(ctx, myNuGet,\r
+      oneOf(myProcessFactory).executeCommandLine(ctx, cmd,\r
               Arrays.asList(\r
-                      "pack", myFile.getPath(), "-OutputDirectory", myOut.getPath(), "-BasePath", myRoot.getPath(), "-Verbose", "-Version", "45.239.32.12", "arg1", "arg2")\r
+                      "/c", myNuGet.getPath(), "pack", myFile.getPath(), "-OutputDirectory", myOut.getPath(), "-BasePath", myRoot.getPath(), "-Verbose", "-Version", "45.239.32.12", "arg1", "arg2")\r
               , myWorkingDir,\r
               Collections.<String, String>emptyMap());\r
     }});\r
@@ -160,9 +170,9 @@ public class NuGetPackActionFactoryTest extends BaseTestCase {
       allowing(myPackParameters).packTool(); will(returnValue(false));\r
       allowing(myPackParameters).packSymbols(); will(returnValue(false));\r
 \r
-      oneOf(myProcessFactory).executeCommandLine(ctx, myNuGet,\r
+      oneOf(myProcessFactory).executeCommandLine(ctx, cmd,\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
+                      "/c", myNuGet.getPath(), "pack", myFile.getPath(), "-OutputDirectory", myOut.getPath(), "-BasePath", myRoot.getPath(), "-Verbose", "-Version", "45.239.32.12", "-Exclude", "aaa", "-Exclude", "d/v/de")\r
               , myWorkingDir,\r
               Collections.<String, String>emptyMap());\r
     }});\r
@@ -177,9 +187,9 @@ public class NuGetPackActionFactoryTest extends BaseTestCase {
       allowing(myPackParameters).packTool(); will(returnValue(true));\r
       allowing(myPackParameters).packSymbols(); will(returnValue(false));\r
 \r
-      oneOf(myProcessFactory).executeCommandLine(ctx, myNuGet,\r
+      oneOf(myProcessFactory).executeCommandLine(ctx, cmd,\r
               Arrays.asList(\r
-                      "pack", myFile.getPath(), "-OutputDirectory", myOut.getPath(), "-BasePath", myRoot.getPath(), "-Verbose", "-Version", "45.239.32.12", "-Tool")\r
+                      "/c", myNuGet.getPath(), "pack", myFile.getPath(), "-OutputDirectory", myOut.getPath(), "-BasePath", myRoot.getPath(), "-Verbose", "-Version", "45.239.32.12", "-Tool")\r
               , myWorkingDir,\r
               Collections.<String, String>emptyMap());\r
     }});\r
@@ -194,9 +204,9 @@ public class NuGetPackActionFactoryTest extends BaseTestCase {
       allowing(myPackParameters).packTool(); will(returnValue(false));\r
       allowing(myPackParameters).packSymbols(); will(returnValue(true));\r
 \r
-      oneOf(myProcessFactory).executeCommandLine(ctx, myNuGet,\r
+      oneOf(myProcessFactory).executeCommandLine(ctx, cmd,\r
               Arrays.asList(\r
-                      "pack", myFile.getPath(), "-OutputDirectory", myOut.getPath(), "-BasePath", myRoot.getPath(), "-Verbose", "-Version", "45.239.32.12", "-Symbols")\r
+                      "/c", myNuGet.getPath(), "pack", myFile.getPath(), "-OutputDirectory", myOut.getPath(), "-BasePath", myRoot.getPath(), "-Verbose", "-Version", "45.239.32.12", "-Symbols")\r
               , myWorkingDir,\r
               Collections.<String, String>emptyMap());\r
     }});\r
index a684e647ae074588b1fcde47a50a7899682f6ee8..3818d3b06b3f47ddd2af6b524a945cbb2a4475b4 100644 (file)
@@ -18,20 +18,25 @@ package jetbrains.buildServer.nuget.tests.agent;
 \r
 import jetbrains.buildServer.BaseTestCase;\r
 import jetbrains.buildServer.RunBuildException;\r
+import jetbrains.buildServer.agent.BuildParametersMap;\r
 import jetbrains.buildServer.agent.BuildRunnerContext;\r
 import jetbrains.buildServer.nuget.agent.commands.impl.CommandFactoryImpl;\r
 import jetbrains.buildServer.nuget.agent.commands.impl.NuGetActionFactoryImpl;\r
 import jetbrains.buildServer.nuget.agent.dependencies.PackageUsages;\r
 import jetbrains.buildServer.nuget.agent.parameters.NuGetPublishParameters;\r
 import jetbrains.buildServer.nuget.agent.util.CommandlineBuildProcessFactory;\r
+import org.hamcrest.BaseMatcher;\r
+import org.hamcrest.Description;\r
+import org.jetbrains.annotations.NotNull;\r
 import org.jmock.Expectations;\r
 import org.jmock.Mockery;\r
 import org.testng.annotations.BeforeMethod;\r
 import org.testng.annotations.Test;\r
 \r
 import java.io.File;\r
-import java.util.Arrays;\r
 import java.util.Collections;\r
+import java.util.List;\r
+import java.util.Map;\r
 \r
 /**\r
  * Created by Eugene Petrenko (eugene.petrenko@gmail.com)\r
@@ -45,6 +50,9 @@ public class NuGetPushActoinFactoryTest extends BaseTestCase {
   private NuGetPublishParameters ps;\r
   private File myFile;\r
   private File myNuGet;\r
+  private String cmd;\r
+  private BuildParametersMap myBuildParametersMap;\r
+\r
 \r
   @BeforeMethod\r
   @Override\r
@@ -57,10 +65,65 @@ public class NuGetPushActoinFactoryTest extends BaseTestCase {
     ctx = m.mock(BuildRunnerContext.class);\r
     ps = m.mock(NuGetPublishParameters.class);\r
 \r
+    myBuildParametersMap = m.mock(BuildParametersMap.class);\r
+    cmd = System.getenv("ComSpec");\r
+\r
+    m.checking(new Expectations(){{\r
+      allowing(ctx).getBuildParameters(); will(returnValue(myBuildParametersMap));\r
+      allowing(myBuildParametersMap).getEnvironmentVariables(); will(returnValue(Collections.singletonMap("ComSpec", cmd)));\r
+    }});\r
+\r
     myFile = createTempFile();\r
     myNuGet = createTempFile();\r
   }\r
 \r
+  private org.hamcrest.Matcher<List<String>> arguments(final String... args) {\r
+    return new BaseMatcher<List<String>>() {\r
+      public boolean matches(Object o) {\r
+        List<String> text = (List<String>) o;\r
+\r
+        if (text.size() != args.length) {\r
+          return false;\r
+        }\r
+\r
+        for (int i = 0; i < args.length; i++) {\r
+          if (args[i].startsWith("%%teamcity_nuget_api_key_")) {\r
+            final String actual = text.get(i).replaceAll("%%teamcity_nuget_api_key_\\d+%%", "%%teamcity_nuget_api_key_DDD%%");\r
+            if (!actual.equals(args[i])) return false;\r
+          }\r
+        }\r
+        return true;\r
+      }\r
+\r
+      public void describeTo(Description description) {\r
+        description.appendText("Should match: [");\r
+        for (String arg : args) {\r
+          description.appendValue(arg);\r
+          description.appendText(", ");\r
+        }\r
+        description.appendText("]");\r
+      }\r
+    };\r
+  }\r
+\r
+  private org.hamcrest.Matcher<Map<String, String>> envApi(@NotNull final String key) {\r
+    return new BaseMatcher<Map<String, String>>() {\r
+      public boolean matches(Object o) {\r
+        Map<String, String> map = (Map<String, String>) o;\r
+        for (Map.Entry<String, String> e : map.entrySet()) {\r
+          if (e.getKey().startsWith("teamcity_nuget_api_key_")) {\r
+            return key.equals(e.getValue());\r
+          }\r
+        }\r
+        return false;\r
+      }\r
+\r
+      public void describeTo(Description description) {\r
+        description.appendText("Environment map should contain value: ").appendValue(key);\r
+      }\r
+    };\r
+  }\r
+\r
   @Test\r
   public void test_command_push() throws RunBuildException {\r
     m.checking(new Expectations(){{\r
@@ -69,7 +132,10 @@ 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(),Collections.<String, String>emptyMap()\r
+      oneOf(myProcessFactory).executeCommandLine(with(equal(ctx)), with(equal(cmd)),\r
+              with(arguments("/c", myNuGet.getPath(), "push", myFile.getPath(), "%%teamcity_nuget_api_key_DDD%%", "-Source", "push-feed")),\r
+              with(equal(myFile.getParentFile())),\r
+              with(envApi("api-key-guid"))\r
       );\r
     }});\r
 \r
@@ -86,7 +152,11 @@ 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(), Collections.<String, String>emptyMap());\r
+      oneOf(myProcessFactory).executeCommandLine(with(equal(ctx)), with(equal(cmd)),\r
+              with(arguments("/c", myNuGet.getPath(), "push", myFile.getPath(), "%%teamcity_nuget_api_key_DDD%%")),\r
+              with(equal(myFile.getParentFile())),\r
+              with(envApi("api-key-guid"))\r
+      );\r
     }});\r
 \r
     i.createPush(ctx, ps, myFile);\r
@@ -102,7 +172,11 @@ 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(), Collections.<String, String>emptyMap());\r
+      oneOf(myProcessFactory).executeCommandLine(with(equal(ctx)), with(equal(cmd)),\r
+              with(arguments("/c", myNuGet.getPath(), "push", myFile.getPath(), "%%teamcity_nuget_api_key_DDD%%", "-CreateOnly", "-Source", "push-feed")),\r
+              with(equal(myFile.getParentFile())),\r
+              with(envApi("api-key-guid"))\r
+      );\r
     }});\r
 \r
     i.createPush(ctx, ps, myFile);\r
index ef4860b0c9daf2256c88cfa90bf9645e7aac4a7d..0d67a302d1d8fea98f4bf5e1c071e49988b52b18 100644 (file)
@@ -18,6 +18,7 @@ package jetbrains.buildServer.nuget.tests.agent;
 \r
 import jetbrains.buildServer.BaseTestCase;\r
 import jetbrains.buildServer.RunBuildException;\r
+import jetbrains.buildServer.agent.BuildParametersMap;\r
 import jetbrains.buildServer.agent.BuildRunnerContext;\r
 import jetbrains.buildServer.nuget.agent.commands.impl.CommandFactoryImpl;\r
 import jetbrains.buildServer.nuget.agent.commands.impl.NuGetActionFactoryImpl;\r
@@ -48,6 +49,9 @@ public class NuGetUpdatePackageActionFactoryTest extends BaseTestCase {
   private PackagesUpdateParameters ps;\r
   private File myTarget;\r
   private File myConfig;\r
+  private String cmd;\r
+  private BuildParametersMap myBuildParametersMap;\r
+\r
 \r
   @BeforeMethod\r
   @Override\r
@@ -63,7 +67,14 @@ public class NuGetUpdatePackageActionFactoryTest extends BaseTestCase {
 \r
     myTarget = createTempDir();\r
     myConfig = createTempFile();\r
+\r
+    myBuildParametersMap = m.mock(BuildParametersMap.class);\r
+    cmd = System.getenv("ComSpec");\r
+\r
     m.checking(new Expectations(){{\r
+      allowing(ctx).getBuildParameters(); will(returnValue(myBuildParametersMap));\r
+      allowing(myBuildParametersMap).getEnvironmentVariables(); will(returnValue(Collections.singletonMap("ComSpec", cmd)));\r
+\r
       allowing(ps).getNuGetParameters(); will(returnValue(nugetParams));\r
     }});\r
   }\r
@@ -79,8 +90,8 @@ public class NuGetUpdatePackageActionFactoryTest extends BaseTestCase {
 \r
       oneOf(myProcessFactory).executeCommandLine(\r
               ctx,\r
-              nuget,\r
-              Arrays.asList("update", myConfig.getPath(), "-Verbose", "-RepositoryPath", myTarget.getPath()),\r
+              cmd,\r
+              Arrays.asList("/c", nuget.getPath(), "update", myConfig.getPath(), "-Verbose", "-RepositoryPath", myTarget.getPath()),\r
               myConfig.getParentFile(),\r
               Collections.<String, String>emptyMap()\r
       );\r
@@ -101,8 +112,8 @@ public class NuGetUpdatePackageActionFactoryTest extends BaseTestCase {
 \r
       oneOf(myProcessFactory).executeCommandLine(\r
               ctx,\r
-              nuget,\r
-              Arrays.asList("update", myConfig.getPath(), "-Verbose", "-RepositoryPath", myTarget.getPath(), "-Id", "aaa", "-Id", "bbb"),\r
+              cmd,\r
+              Arrays.asList("/c", nuget.getPath(), "update", myConfig.getPath(), "-Verbose", "-RepositoryPath", myTarget.getPath(), "-Id", "aaa", "-Id", "bbb"),\r
               myConfig.getParentFile(),\r
               Collections.<String, String>emptyMap()\r
       );\r
@@ -123,8 +134,8 @@ public class NuGetUpdatePackageActionFactoryTest extends BaseTestCase {
 \r
       oneOf(myProcessFactory).executeCommandLine(\r
               ctx,\r
-              nuget,\r
-              Arrays.asList("update", myConfig.getPath(), "-Safe", "-Verbose", "-RepositoryPath", myTarget.getPath()),\r
+              cmd,\r
+              Arrays.asList("/c", nuget.getPath(), "update", myConfig.getPath(), "-Safe", "-Verbose", "-RepositoryPath", myTarget.getPath()),\r
               myConfig.getParentFile(),\r
               Collections.<String, String>emptyMap()\r
       );\r
@@ -145,8 +156,8 @@ public class NuGetUpdatePackageActionFactoryTest extends BaseTestCase {
 \r
       oneOf(myProcessFactory).executeCommandLine(\r
               ctx,\r
-              nuget,\r
-              Arrays.asList("update", myConfig.getPath(), "-Verbose", "-RepositoryPath", myTarget.getPath(), "-Source", "aaa", "-Source", "bbb"),\r
+              cmd,\r
+              Arrays.asList("/c", nuget.getPath(), "update", myConfig.getPath(), "-Verbose", "-RepositoryPath", myTarget.getPath(), "-Source", "aaa", "-Source", "bbb"),\r
               myConfig.getParentFile(),\r
               Collections.<String, String>emptyMap()\r
       );\r
index b0c245221e1ebe39a726d935fd2ef95156065f0d..2d518fbb0c72ff5e9ca4dbf33c0a77fc69220dfc 100644 (file)
@@ -41,6 +41,7 @@ import org.testng.annotations.BeforeMethod;
 \r
 import java.io.File;\r
 import java.util.Collection;\r
+import java.util.Collections;\r
 import java.util.HashMap;\r
 import java.util.Map;\r
 \r
@@ -60,6 +61,8 @@ public class IntegrationTestBase extends BuildProcessTestCase {
   protected NuGetPackagesCollector myCollector;\r
   protected NuGetActionFactory myActionFactory;\r
   private BuildProcess myMockProcess;\r
+  protected BuildParametersMap myBuildParametersMap;\r
+  protected String cmd;\r
 \r
   @NotNull\r
   protected String getCommandsOutput() {\r
@@ -79,8 +82,14 @@ public class IntegrationTestBase extends BuildProcessTestCase {
     myParametersFactory = m.mock(PackagesParametersFactory.class);\r
     myMockProcess = m.mock(BuildProcess.class);\r
     myNuGet = m.mock(NuGetFetchParameters.class);\r
+    myBuildParametersMap = m.mock(BuildParametersMap.class);\r
+\r
+    cmd = System.getenv("ComSpec");\r
+\r
+    m.checking(new Expectations(){{\r
+      allowing(myContext).getBuildParameters(); will(returnValue(myBuildParametersMap));\r
+      allowing(myBuildParametersMap).getEnvironmentVariables(); will(returnValue(Collections.singletonMap("ComSpec", cmd)));\r
 \r
-    m.checking(new Expectations() {{\r
       allowing(myContext).getBuild();\r
       will(returnValue(myBuild));\r
       allowing(myBuild).getBuildLogger();\r
@@ -114,7 +123,7 @@ public class IntegrationTestBase extends BuildProcessTestCase {
     return new CommandlineBuildProcessFactory() {\r
       @NotNull\r
       public BuildProcess executeCommandLine(@NotNull final BuildRunnerContext hostContext,\r
-                                             @NotNull final File program,\r
+                                             @NotNull final String program,\r
                                              @NotNull final Collection<String> argz,\r
                                              @NotNull final File workingDir,\r
                                              @NotNull final Map<String, String> additionalEnvironment) throws RunBuildException {\r
@@ -123,9 +132,9 @@ public class IntegrationTestBase extends BuildProcessTestCase {
           @Override\r
           protected BuildFinishedStatus waitForImpl() throws RunBuildException {\r
             GeneralCommandLine cmd = new GeneralCommandLine();\r
-            cmd.setExePath(program.getPath());\r
+            cmd.setExePath(program);\r
             for (String arg : argz) {\r
-              cmd.addParameter(arg);\r
+              cmd.addParameter(arg.replaceAll("%+", "%"));\r
             }\r
             cmd.setWorkingDirectory(workingDir);\r
 \r