wrap nuget call with cmd.exe calls, do not show api key
[teamcity/dotNetPackagesSupport.git] / nuget-agent / src / jetbrains / buildServer / nuget / agent / commands / impl / CommandFactoryImpl.java
index 47dc04ed9a746cde670f712740b5934503f31de6..25afca59e8b6731fbbb35c5484539801408dc1aa 100644 (file)
@@ -43,7 +43,8 @@ public class CommandFactoryImpl implements CommandFactory {
     argz.add("-OutputDirectory");\r
     argz.add(FileUtil.getCanonicalFile(targetFolder).getPath());\r
 \r
-    return executeNuGet(params.getNuGetParameters(), argz, packagesConfig.getParentFile(), factory);\r
+    final NuGetFetchParameters nuget = params.getNuGetParameters();\r
+    return executeNuGet(nuget, nuget.getNuGetPackageSources(), argz, packagesConfig.getParentFile(), factory);\r
   }\r
 \r
   @NotNull\r
@@ -63,7 +64,8 @@ public class CommandFactoryImpl implements CommandFactory {
       argz.add(id);\r
     }\r
 \r
-    return executeNuGet(params.getNuGetParameters(), argz, packagesConfig.getParentFile(), factory);\r
+    final NuGetFetchParameters nuget = params.getNuGetParameters();\r
+    return executeNuGet(nuget, nuget.getNuGetPackageSources(), argz, packagesConfig.getParentFile(), factory);\r
   }\r
 \r
   public <T> T createPack(@NotNull final NuGetPackParameters params,\r
@@ -114,10 +116,12 @@ public class CommandFactoryImpl implements CommandFactory {
   public <T> T createPush(@NotNull final NuGetPublishParameters params,\r
                           @NotNull final File packagePath,\r
                           @NotNull final Callback<T> factory) throws RunBuildException {\r
+    final String apiKey = "teamcity_nuget_api_key_" + System.currentTimeMillis();\r
+\r
     final List<String> arguments = new ArrayList<String>();\r
     arguments.add("push");\r
     arguments.add(packagePath.getPath());\r
-    arguments.add(params.getApiKey());\r
+    arguments.add("%%" + apiKey + "%%");\r
     if (params.getCreateOnly()) {\r
       arguments.add("-CreateOnly");\r
     }\r
@@ -130,18 +134,24 @@ public class CommandFactoryImpl implements CommandFactory {
                     : Arrays.asList(source),\r
             arguments,\r
             packagePath.getParentFile(),\r
+            Collections.singletonMap(apiKey, params.getApiKey()),\r
             factory);\r
   }\r
 \r
-  @NotNull\r
-  private <T> T executeNuGet(@NotNull final NuGetFetchParameters nuget,\r
+  private <T> T executeNuGet(@NotNull final NuGetParameters nuget,\r
+                             @NotNull final Collection<String> sources,\r
                              @NotNull final Collection<String> arguments,\r
                              @NotNull final File workingDir,\r
                              @NotNull final Callback<T> factory) throws RunBuildException {\r
-    return executeNuGet(nuget, nuget.getNuGetPackageSources(), arguments, workingDir, factory);\r
+    return executeNuGet(nuget, sources, arguments, workingDir, Collections.<String,String>emptyMap(), factory);\r
   }\r
 \r
-  private <T> T executeNuGet(NuGetParameters nuget, Collection<String> sources, Collection<String> arguments, File workingDir, Callback<T> factory) throws RunBuildException {\r
+  private <T> T executeNuGet(@NotNull final NuGetParameters nuget,\r
+                             @NotNull final Collection<String> sources,\r
+                             @NotNull final Collection<String> arguments,\r
+                             @NotNull final File workingDir,\r
+                             @NotNull final Map<String,String> additionalEnvironment,\r
+                             @NotNull final Callback<T> factory) throws RunBuildException {\r
     final List<String> argz = new ArrayList<String>(arguments);\r
     for (String source : sources) {\r
       argz.add("-Source");\r
@@ -151,7 +161,8 @@ public class CommandFactoryImpl implements CommandFactory {
     return factory.createCommand(\r
             nuget.getNuGetExeFile(),\r
             workingDir,\r
-            argz\r
+            argz,\r
+            additionalEnvironment\r
     );\r
   }\r
 \r