generate nuget commands without BuildProcesses
authorEugene Petrenko <eugene.petrenko@gmail.com>
Thu, 21 Jul 2011 12:18:56 +0000 (16:18 +0400)
committerEugene Petrenko <eugene.petrenko@gmail.com>
Thu, 21 Jul 2011 12:18:56 +0000 (16:18 +0400)
nuget-agent/src/META-INF/build-agent-plugin-nuget.xml
nuget-agent/src/jetbrains/buildServer/nuget/agent/commands/CommandFactory.java [new file with mode: 0644]
nuget-agent/src/jetbrains/buildServer/nuget/agent/commands/impl/CommandFactoryImpl.java [new file with mode: 0644]
nuget-agent/src/jetbrains/buildServer/nuget/agent/install/impl/NuGetActionFactoryImpl.java
nuget-tests/src/jetbrains/buildServer/nuget/tests/agent/NuGetInstallPackageActionFactoryTest.java
nuget-tests/src/jetbrains/buildServer/nuget/tests/agent/NuGetUpdatePackageActionFactoryTest.java
nuget-tests/src/jetbrains/buildServer/nuget/tests/integration/InstallPackageIntegtatoinTest.java

index 433fa93abba7e11a69623ebc0483bfc9f3eb3ded..89f7ef3bb04788787cbc32d8353be9fd3e41aa56 100644 (file)
@@ -13,6 +13,7 @@
   <bean class="jetbrains.buildServer.nuget.agent.install.PackagesInstallerRunner"/>\r
   <bean class="jetbrains.buildServer.nuget.agent.install.PackagesInstallerRunnerRegistrar"/>\r
 \r
+  <bean class="jetbrains.buildServer.nuget.agent.commands.impl.CommandFactoryImpl"/>\r
   <bean class="jetbrains.buildServer.nuget.agent.install.impl.LoggingNuGetActionFactoryImpl">\r
     <constructor-arg>\r
       <bean class="jetbrains.buildServer.nuget.agent.install.impl.NuGetActionFactoryImpl"/>\r
diff --git a/nuget-agent/src/jetbrains/buildServer/nuget/agent/commands/CommandFactory.java b/nuget-agent/src/jetbrains/buildServer/nuget/agent/commands/CommandFactory.java
new file mode 100644 (file)
index 0000000..177624a
--- /dev/null
@@ -0,0 +1,48 @@
+/*\r
+ * Copyright 2000-2011 JetBrains s.r.o.\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ */\r
+\r
+package jetbrains.buildServer.nuget.agent.commands;\r
+\r
+import jetbrains.buildServer.RunBuildException;\r
+import jetbrains.buildServer.nuget.agent.parameters.PackagesInstallParameters;\r
+import jetbrains.buildServer.nuget.agent.parameters.PackagesUpdateParameters;\r
+import org.jetbrains.annotations.NotNull;\r
+\r
+import java.io.File;\r
+import java.util.Collection;\r
+\r
+/**\r
+ * Created by Eugene Petrenko (eugene.petrenko@gmail.com)\r
+ * Date: 21.07.11 16:07\r
+ */\r
+public interface CommandFactory {\r
+\r
+  @NotNull\r
+  <T> T createInstall(@NotNull PackagesInstallParameters params,\r
+                      @NotNull File packagesConfig,\r
+                      @NotNull File targetFolder,\r
+                      @NotNull Callback<T> factory) throws RunBuildException;\r
+\r
+  @NotNull\r
+  <T> T createUpdate(@NotNull PackagesUpdateParameters params,\r
+                     @NotNull File packagesConfig,\r
+                     @NotNull File targetFolder,\r
+                     @NotNull Callback<T> factory) throws RunBuildException;\r
+\r
+  public interface Callback<T> {\r
+    T createCommand(@NotNull File program, @NotNull final File workingDir, @NotNull Collection<String> argz) throws RunBuildException;\r
+  }\r
+}\r
diff --git a/nuget-agent/src/jetbrains/buildServer/nuget/agent/commands/impl/CommandFactoryImpl.java b/nuget-agent/src/jetbrains/buildServer/nuget/agent/commands/impl/CommandFactoryImpl.java
new file mode 100644 (file)
index 0000000..1b078d0
--- /dev/null
@@ -0,0 +1,90 @@
+/*\r
+ * Copyright 2000-2011 JetBrains s.r.o.\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ */\r
+\r
+package jetbrains.buildServer.nuget.agent.commands.impl;\r
+\r
+import jetbrains.buildServer.RunBuildException;\r
+import jetbrains.buildServer.nuget.agent.commands.CommandFactory;\r
+import jetbrains.buildServer.nuget.agent.parameters.NuGetFetchParameters;\r
+import jetbrains.buildServer.nuget.agent.parameters.PackagesInstallParameters;\r
+import jetbrains.buildServer.nuget.agent.parameters.PackagesUpdateParameters;\r
+import jetbrains.buildServer.util.FileUtil;\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
+\r
+/**\r
+ * Created by Eugene Petrenko (eugene.petrenko@gmail.com)\r
+ * Date: 21.07.11 16:10\r
+ */\r
+public class CommandFactoryImpl implements CommandFactory {\r
+\r
+  @NotNull\r
+  public <T> T createInstall(@NotNull PackagesInstallParameters params, @NotNull File packagesConfig, @NotNull File targetFolder, @NotNull Callback<T> factory) throws RunBuildException {\r
+    final List<String> argz = new ArrayList<String>();\r
+    argz.add("install");\r
+    argz.add(FileUtil.getCanonicalFile(packagesConfig).getPath()); //path to package\r
+    if (params.getExcludeVersion()) {\r
+      argz.add("-ExcludeVersion");\r
+    }\r
+    argz.add("-OutputDirectory");\r
+    argz.add(FileUtil.getCanonicalFile(targetFolder).getPath());\r
+\r
+    return executeNuGet(params.getNuGetParameters(), argz, packagesConfig.getParentFile(), factory);\r
+  }\r
+\r
+  @NotNull\r
+  public <T> T createUpdate(@NotNull PackagesUpdateParameters params, @NotNull File packagesConfig, @NotNull File targetFolder, @NotNull Callback<T> factory) throws RunBuildException {\r
+    final List<String> argz = new ArrayList<String>();\r
+    argz.add("update");\r
+    argz.add(FileUtil.getCanonicalFile(packagesConfig).getPath()); //path to package\r
+    if (params.getUseSafeUpdate()) {\r
+      argz.add("-Safe");\r
+    }\r
+    argz.add("-Verbose");\r
+    argz.add("-RepositoryPath");\r
+    argz.add(FileUtil.getCanonicalFile(targetFolder).getPath());\r
+\r
+    for (String id : params.getPackagesToUpdate()) {\r
+      argz.add("-Id");\r
+      argz.add(id);\r
+    }\r
+\r
+    return executeNuGet(params.getNuGetParameters(), argz, packagesConfig.getParentFile(), factory);\r
+  }\r
+\r
+  @NotNull\r
+  private <T> T executeNuGet(@NotNull final NuGetFetchParameters nuget,\r
+                             @NotNull final Collection<String> arguments,\r
+                             @NotNull final File workingDir,\r
+                             @NotNull final Callback<T> factory) throws RunBuildException {\r
+    final List<String> argz = new ArrayList<String>(arguments);\r
+    for (String source : nuget.getNuGetPackageSources()) {\r
+      argz.add("-Source");\r
+      argz.add(source);\r
+    }\r
+\r
+    return factory.createCommand(\r
+            nuget.getNuGetExeFile(),\r
+            workingDir,\r
+            argz\r
+    );\r
+  }\r
+\r
+}\r
index 40a0dee9a9b2decd50801943c55f7fcd0f12608c..b4ec51522750cfa0b81c5387945ce27591923e2c 100644 (file)
@@ -21,6 +21,7 @@ import jetbrains.buildServer.RunBuildException;
 import jetbrains.buildServer.agent.BuildFinishedStatus;\r
 import jetbrains.buildServer.agent.BuildProcess;\r
 import jetbrains.buildServer.agent.BuildRunnerContext;\r
+import jetbrains.buildServer.nuget.agent.commands.CommandFactory;\r
 import jetbrains.buildServer.nuget.agent.install.NuGetActionFactory;\r
 import jetbrains.buildServer.nuget.agent.install.PackageUsages;\r
 import jetbrains.buildServer.nuget.agent.parameters.NuGetFetchParameters;\r
@@ -28,13 +29,10 @@ import jetbrains.buildServer.nuget.agent.parameters.PackagesInstallParameters;
 import jetbrains.buildServer.nuget.agent.parameters.PackagesUpdateParameters;\r
 import jetbrains.buildServer.nuget.agent.util.BuildProcessBase;\r
 import jetbrains.buildServer.nuget.agent.util.CommandlineBuildProcessFactory;\r
-import jetbrains.buildServer.util.FileUtil;\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
 \r
 /**\r
  * Created by Eugene Petrenko (eugene.petrenko@gmail.com)\r
@@ -43,13 +41,31 @@ import java.util.List;
 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
 \r
   public NuGetActionFactoryImpl(@NotNull final CommandlineBuildProcessFactory factory,\r
-                                @NotNull final PackageUsages packageUsages) {\r
+                                @NotNull final PackageUsages packageUsages,\r
+                                @NotNull final CommandFactory commandFactory) {\r
     myFactory = factory;\r
     myPackageUsages = packageUsages;\r
+    myCommandFactory = commandFactory;\r
+  }\r
+\r
+  private CommandFactory.Callback<BuildProcess> getCallback(@NotNull final BuildRunnerContext context) {\r
+    return new CommandFactory.Callback<BuildProcess>() {\r
+      public BuildProcess createCommand(@NotNull File program,\r
+                                        @NotNull File workingDir,\r
+                                        @NotNull Collection<String> argz) throws RunBuildException {\r
+        return myFactory.executeCommandLine(\r
+                context,\r
+                program,\r
+                argz,\r
+                workingDir\r
+        );\r
+      }\r
+    };\r
   }\r
 \r
   @NotNull\r
@@ -57,16 +73,7 @@ public class NuGetActionFactoryImpl implements NuGetActionFactory {
                                     @NotNull final PackagesInstallParameters params,\r
                                     @NotNull final File packagesConfig,\r
                                     @NotNull final File targetFolder) throws RunBuildException {\r
-    final List<String> argz = new ArrayList<String>();\r
-    argz.add("install");\r
-    argz.add(FileUtil.getCanonicalFile(packagesConfig).getPath()); //path to package\r
-    if (params.getExcludeVersion()) {\r
-      argz.add("-ExcludeVersion");\r
-    }\r
-    argz.add("-OutputDirectory");\r
-    argz.add(FileUtil.getCanonicalFile(targetFolder).getPath());\r
-\r
-    return executeNuGet(context, params.getNuGetParameters(), argz, packagesConfig.getParentFile());\r
+    return myCommandFactory.createInstall(params, packagesConfig, targetFolder, getCallback(context));\r
   }\r
 \r
 \r
@@ -75,22 +82,7 @@ public class NuGetActionFactoryImpl implements NuGetActionFactory {
                                    @NotNull final PackagesUpdateParameters params,\r
                                    @NotNull final File packagesConfig,\r
                                    @NotNull final File targetFolder) throws RunBuildException {\r
-    final List<String> argz = new ArrayList<String>();\r
-    argz.add("update");\r
-    argz.add(FileUtil.getCanonicalFile(packagesConfig).getPath()); //path to package\r
-    if (params.getUseSafeUpdate()) {\r
-      argz.add("-Safe");\r
-    }\r
-    argz.add("-Verbose");\r
-    argz.add("-RepositoryPath");\r
-    argz.add(FileUtil.getCanonicalFile(targetFolder).getPath());\r
-\r
-    for (String id : params.getPackagesToUpdate()) {\r
-      argz.add("-Id");\r
-      argz.add(id);\r
-    }\r
-\r
-    return executeNuGet(context, params.getNuGetParameters(), argz, packagesConfig.getParentFile());\r
+    return myCommandFactory.createUpdate(params, packagesConfig, targetFolder, getCallback(context));\r
   }\r
 \r
   @NotNull\r
@@ -107,23 +99,4 @@ public class NuGetActionFactoryImpl implements NuGetActionFactory {
       }\r
     };\r
   }\r
-\r
-  @NotNull\r
-  private BuildProcess executeNuGet(@NotNull final BuildRunnerContext context,\r
-                                    @NotNull final NuGetFetchParameters nuget,\r
-                                    @NotNull final Collection<String> arguments,\r
-                                    @NotNull final File workingDirectory) throws RunBuildException {\r
-    final List<String> argz = new ArrayList<String>(arguments);\r
-    for (String source : nuget.getNuGetPackageSources()) {\r
-      argz.add("-Source");\r
-      argz.add(source);\r
-    }\r
-\r
-    return myFactory.executeCommandLine(\r
-            context,\r
-            nuget.getNuGetExeFile(),\r
-            argz,\r
-            workingDirectory\r
-    );\r
-  }\r
 }\r
index 54195d3a1c1885debb95bcd15d3a6e61d930cf6a..dc1edf856dd171ce24975c592dc9cbf0691161a5 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.BuildRunnerContext;\r
+import jetbrains.buildServer.nuget.agent.commands.impl.CommandFactoryImpl;\r
 import jetbrains.buildServer.nuget.agent.install.PackageUsages;\r
 import jetbrains.buildServer.nuget.agent.parameters.NuGetFetchParameters;\r
 import jetbrains.buildServer.nuget.agent.parameters.PackagesInstallParameters;\r
@@ -55,7 +56,7 @@ public class NuGetInstallPackageActionFactoryTest extends BaseTestCase {
     m = new Mockery();\r
     myProcessFactory = m.mock(CommandlineBuildProcessFactory.class);\r
     PackageUsages pu = m.mock(PackageUsages.class);\r
-    i = new NuGetActionFactoryImpl(myProcessFactory, pu);\r
+    i = new NuGetActionFactoryImpl(myProcessFactory, pu, new CommandFactoryImpl());\r
     ctx = m.mock(BuildRunnerContext.class);\r
     ps = m.mock(PackagesInstallParameters.class);\r
     nugetParams = m.mock(NuGetFetchParameters.class);\r
index d175827fc24cd7ceaeac4a1b59cb5910e9d6cbee..4ac392cae6473d272920173ad53adec61431a505 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.BuildRunnerContext;\r
+import jetbrains.buildServer.nuget.agent.commands.impl.CommandFactoryImpl;\r
 import jetbrains.buildServer.nuget.agent.install.PackageUsages;\r
 import jetbrains.buildServer.nuget.agent.parameters.NuGetFetchParameters;\r
 import jetbrains.buildServer.nuget.agent.parameters.PackagesUpdateParameters;\r
@@ -55,7 +56,7 @@ public class NuGetUpdatePackageActionFactoryTest extends BaseTestCase {
     m = new Mockery();\r
     myProcessFactory = m.mock(CommandlineBuildProcessFactory.class);\r
     PackageUsages pu = m.mock(PackageUsages.class);\r
-    i = new NuGetActionFactoryImpl(myProcessFactory, pu);\r
+    i = new NuGetActionFactoryImpl(myProcessFactory, pu, new CommandFactoryImpl());\r
     ctx = m.mock(BuildRunnerContext.class);\r
     ps = m.mock(PackagesUpdateParameters.class);\r
     nugetParams = m.mock(NuGetFetchParameters.class);\r
index 22b9278a2ec255a2d83a489c2d95a1f386b75ad2..434c7c2cabd30298f20e0b7edf9b9910daa41083 100644 (file)
@@ -21,6 +21,7 @@ import jetbrains.buildServer.ExecResult;
 import jetbrains.buildServer.RunBuildException;\r
 import jetbrains.buildServer.SimpleCommandLineProcessRunner;\r
 import jetbrains.buildServer.agent.*;\r
+import jetbrains.buildServer.nuget.agent.commands.impl.CommandFactoryImpl;\r
 import jetbrains.buildServer.nuget.agent.install.PackageUsages;\r
 import jetbrains.buildServer.nuget.agent.install.PackagesInstallerRunner;\r
 import jetbrains.buildServer.nuget.agent.install.impl.NuGetActionFactoryImpl;\r
@@ -278,7 +279,7 @@ public class InstallPackageIntegtatoinTest extends BuildProcessTestCase {
     );\r
 \r
     BuildProcess proc = new PackagesInstallerRunner(\r
-            new NuGetActionFactoryImpl(executingFactory(), pu),\r
+            new NuGetActionFactoryImpl(executingFactory(), pu, new CommandFactoryImpl()),\r
             myParametersFactory\r
     ).createBuildProcess(myBuild, myContext);\r
 \r