wrap nuget call with cmd.exe calls, do not show api key
authorEugene.Petrenko <eugene.petrenko@gmail.com>
Thu, 25 Aug 2011 11:10:36 +0000 (13:10 +0200)
committerEugene.Petrenko <eugene.petrenko@gmail.com>
Thu, 25 Aug 2011 11:10:36 +0000 (13:10 +0200)
.idea/runConfigurations/Run_Integration_Tests.xml
nuget-agent/src/jetbrains/buildServer/nuget/agent/commands/CommandFactory.java
nuget-agent/src/jetbrains/buildServer/nuget/agent/commands/impl/CommandFactoryImpl.java
nuget-agent/src/jetbrains/buildServer/nuget/agent/commands/impl/NuGetActionFactoryImpl.java
nuget-agent/src/jetbrains/buildServer/nuget/agent/util/impl/CommandlineBuildProcessFactoryImpl.java

index 824c746a8661197835da35c39fb44bd5d1831f00..0c3b564d33e0e9f74d1d30bfe575bc9b4ac086de 100644 (file)
@@ -33,6 +33,8 @@
     <RunnerSettings RunnerId="Profile ">\r
       <option name="myExternalizedOptions" value="&#13;&#10;snapshots-dir=&#13;&#10;additional-options2=onexit\=snapshot&#13;&#10;" />\r
     </RunnerSettings>\r
+    <RunnerSettings RunnerId="Run" />\r
+    <ConfigurationWrapper RunnerId="Run" />\r
     <method />\r
   </configuration>\r
 </component>
\ No newline at end of file
index dc2649a629bebc67970401920ab6f221a4fb17bb..d321926accad03a29312c5a170a2acbd18a3369c 100644 (file)
@@ -25,6 +25,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
@@ -59,12 +60,14 @@ public interface CommandFactory {
      * @param program program to run\r
      * @param workingDir working firectory of program\r
      * @param argz arguments array\r
+     * @param additionalEnvironment environment variables that has to be added\r
      * @return some result object depending of caller's desire\r
      * @throws RunBuildException if failed to create/execure command\r
      */\r
     @NotNull\r
     T createCommand(@NotNull File program,\r
-                    @NotNull final File workingDir,\r
-                    @NotNull Collection<String> argz) throws RunBuildException;\r
+                    @NotNull File workingDir,\r
+                    @NotNull Collection<String> argz,\r
+                    @NotNull Map<String, String> additionalEnvironment) throws RunBuildException;\r
   }\r
 }\r
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
index 2cad02b591f0faeebc220609b5d00bdd32180491..d27aee8f2a9de293e9acde79341db83611421d81 100644 (file)
@@ -30,7 +30,7 @@ import org.jetbrains.annotations.NotNull;
 \r
 import java.io.File;\r
 import java.util.Collection;\r
-import java.util.Collections;\r
+import java.util.Map;\r
 \r
 /**\r
  * Created by Eugene Petrenko (eugene.petrenko@gmail.com)\r
@@ -54,13 +54,14 @@ public class NuGetActionFactoryImpl implements NuGetActionFactory {
       @NotNull\r
       public BuildProcess createCommand(@NotNull File program,\r
                                         @NotNull File workingDir,\r
-                                        @NotNull Collection<String> argz) throws RunBuildException {\r
+                                        @NotNull Collection<String> argz,\r
+                                        @NotNull Map<String, String> additionalEnvironment) throws RunBuildException {\r
         return myFactory.executeCommandLine(\r
                 context,\r
                 program,\r
                 argz,\r
                 workingDir,\r
-                Collections.<String, String>emptyMap()\r
+                additionalEnvironment\r
         );\r
       }\r
     };\r
index c104b9823bd3a72125148c636705536dc44f6d5b..45608c5029793e1e77f45be8ac4800337095f650 100644 (file)
@@ -25,7 +25,9 @@ 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
@@ -42,9 +44,14 @@ public class CommandlineBuildProcessFactoryImpl implements CommandlineBuildProce
   @NotNull\r
   public BuildProcess executeCommandLine(@NotNull BuildRunnerContext hostContext,\r
                                          @NotNull File program,\r
-                                         @NotNull Collection<String> argz,\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
@@ -56,7 +63,7 @@ public class CommandlineBuildProcessFactoryImpl implements CommandlineBuildProce
       context.addEnvironmentVariable(entry.getKey(), entry.getValue());\r
     }\r
 \r
-    context.addRunnerParameter(SimpleRunnerConstants.COMMAND_EXECUTABLE, program.getPath());\r
+    context.addRunnerParameter(SimpleRunnerConstants.COMMAND_EXECUTABLE, "%env.ComSpec%");\r
     context.addRunnerParameter(SimpleRunnerConstants.COMMAND_PARAMETERS, joinCommandLineArguments(argz));\r
 \r
     return myFacade.createExecutable(hostContext.getBuild(), context);\r