call packages install after nuget update command to ensure no missing packages. Worka...
authorEugene.Petrenko <eugene.petrenko@gmail.com>
Mon, 11 Jul 2011 11:08:58 +0000 (15:08 +0400)
committerEugene.Petrenko <eugene.petrenko@gmail.com>
Mon, 11 Jul 2011 11:08:58 +0000 (15:08 +0400)
nuget-agent/src/jetbrains/buildServer/nuget/agent/install/PackagesInstallerBuilder.java [new file with mode: 0644]
nuget-agent/src/jetbrains/buildServer/nuget/agent/install/PackagesInstallerRunner.java
nuget-tests/src/jetbrains/buildServer/nuget/tests/integration/InstallPackageIntegtatoinTest.java

diff --git a/nuget-agent/src/jetbrains/buildServer/nuget/agent/install/PackagesInstallerBuilder.java b/nuget-agent/src/jetbrains/buildServer/nuget/agent/install/PackagesInstallerBuilder.java
new file mode 100644 (file)
index 0000000..e8a7584
--- /dev/null
@@ -0,0 +1,121 @@
+/*\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.install;\r
+\r
+import jetbrains.buildServer.RunBuildException;\r
+import jetbrains.buildServer.agent.BuildProcess;\r
+import jetbrains.buildServer.agent.BuildProgressLogger;\r
+import jetbrains.buildServer.agent.BuildRunnerContext;\r
+import jetbrains.buildServer.nuget.agent.parameters.PackagesInstallParameters;\r
+import jetbrains.buildServer.nuget.agent.parameters.PackagesUpdateParameters;\r
+import jetbrains.buildServer.nuget.agent.util.BuildProcessContinuation;\r
+import jetbrains.buildServer.nuget.agent.util.DelegatingBuildProcess;\r
+import jetbrains.buildServer.util.FileUtil;\r
+import org.jetbrains.annotations.NotNull;\r
+import org.jetbrains.annotations.Nullable;\r
+\r
+import java.io.File;\r
+\r
+/**\r
+* Created by Eugene Petrenko (eugene.petrenko@gmail.com)\r
+* Date: 11.07.11 14:57\r
+*/\r
+public class PackagesInstallerBuilder implements LocateNuGetConfigBuildProcess.Callback {\r
+  private final NuGetActionFactory myActionFactory;\r
+  private final BuildProcessContinuation myInstall;\r
+  private final BuildProcessContinuation myUpdate;\r
+  private final BuildProcessContinuation myPostUpdate;\r
+  private final BuildRunnerContext myContext;\r
+\r
+  private final PackagesUpdateParameters myUpdateParameters;\r
+  private final PackagesInstallParameters myInstallParameters;\r
+\r
+  public PackagesInstallerBuilder(@NotNull final NuGetActionFactory actionFactory,\r
+                                  @NotNull final BuildProcessContinuation install,\r
+                                  @NotNull final BuildProcessContinuation update,\r
+                                  @NotNull final BuildProcessContinuation postUpdate,\r
+                                  @NotNull final BuildRunnerContext context,\r
+                                  @NotNull final PackagesInstallParameters installParameters,\r
+                                  @Nullable final PackagesUpdateParameters updateParameters) {\r
+    myInstall = install;\r
+    myUpdate = update;\r
+    myPostUpdate = postUpdate;\r
+    myContext = context;\r
+    myUpdateParameters = updateParameters;\r
+    myInstallParameters = installParameters;\r
+    myActionFactory = actionFactory;\r
+  }\r
+\r
+  public final void onPackagesConfigFound(@NotNull final File config, @NotNull final File targetFolder) {\r
+    myInstall.pushBuildProcess(createInstallAction(config, targetFolder));\r
+\r
+    if (myUpdateParameters == null) return;\r
+    myUpdate.pushBuildProcess(createUpdateAction(config, targetFolder));\r
+    myPostUpdate.pushBuildProcess(createInstallAction(config, targetFolder));\r
+  }\r
+\r
+  private DelegatingBuildProcess createUpdateAction(final File config, final File targetFolder) {\r
+    return new DelegatingBuildProcess(\r
+            new DelegatingBuildProcess.Action() {\r
+              private final BuildProgressLogger logger = myContext.getBuild().getBuildLogger();\r
+\r
+              @NotNull\r
+              public BuildProcess startImpl() throws RunBuildException {\r
+                String pathToLog = FileUtil.getRelativePath(myContext.getBuild().getCheckoutDirectory(), config);\r
+                if (pathToLog == null) pathToLog = config.getPath();\r
+                logger.activityStarted("update", "Updating NuGet packages for " + pathToLog, "nuget");\r
+\r
+                return myActionFactory.createUpdate(myContext,\r
+                        myUpdateParameters,\r
+                        config,\r
+                        targetFolder)\r
+                        ;\r
+              }\r
+\r
+              public void finishedImpl() {\r
+                logger.activityFinished("update", "nuget");\r
+              }\r
+            }\r
+    );\r
+  }\r
+\r
+  private DelegatingBuildProcess createInstallAction(final File config, final File targetFolder) {\r
+    return new DelegatingBuildProcess(\r
+            new DelegatingBuildProcess.Action() {\r
+              private final BuildProgressLogger logger = myContext.getBuild().getBuildLogger();\r
+\r
+              @NotNull\r
+              public BuildProcess startImpl() throws RunBuildException {\r
+                String pathToLog = FileUtil.getRelativePath(myContext.getBuild().getCheckoutDirectory(), config);\r
+                if (pathToLog == null) pathToLog = config.getPath();\r
+                logger.activityStarted("install", "Installing NuGet packages for " + pathToLog, "nuget");\r
+\r
+\r
+                return myActionFactory.createInstall(myContext,\r
+                        myInstallParameters,\r
+                        config,\r
+                        targetFolder)\r
+                        ;\r
+              }\r
+\r
+              public void finishedImpl() {\r
+                logger.activityFinished("install", "nuget");\r
+              }\r
+            }\r
+    );\r
+  }\r
+}\r
index d9e45746c5cbf478f72eb28461769d0c88dc7426..37bfffa0c75bfead9961fc2015ed668af12fc51a 100644 (file)
@@ -23,17 +23,11 @@ import jetbrains.buildServer.nuget.agent.parameters.NuGetParameters;
 import jetbrains.buildServer.nuget.agent.parameters.PackagesParametersFactory;\r
 import jetbrains.buildServer.nuget.agent.parameters.PackagesInstallParameters;\r
 import jetbrains.buildServer.nuget.agent.parameters.PackagesUpdateParameters;\r
 import jetbrains.buildServer.nuget.agent.parameters.PackagesParametersFactory;\r
 import jetbrains.buildServer.nuget.agent.parameters.PackagesInstallParameters;\r
 import jetbrains.buildServer.nuget.agent.parameters.PackagesUpdateParameters;\r
-import jetbrains.buildServer.nuget.agent.util.DelegatingBuildProcess;\r
+import jetbrains.buildServer.nuget.agent.util.CompositeBuildProcess;\r
 import jetbrains.buildServer.nuget.agent.util.impl.CompositeBuildProcessImpl;\r
 import jetbrains.buildServer.nuget.common.DotNetConstants;\r
 import jetbrains.buildServer.nuget.common.PackagesConstants;\r
 import jetbrains.buildServer.nuget.agent.util.impl.CompositeBuildProcessImpl;\r
 import jetbrains.buildServer.nuget.common.DotNetConstants;\r
 import jetbrains.buildServer.nuget.common.PackagesConstants;\r
-import jetbrains.buildServer.util.FileUtil;\r
 import org.jetbrains.annotations.NotNull;\r
 import org.jetbrains.annotations.NotNull;\r
-import org.jetbrains.annotations.Nullable;\r
-\r
-import java.io.File;\r
-\r
-import static jetbrains.buildServer.nuget.agent.install.LocateNuGetConfigBuildProcess.Callback;\r
 \r
 /**\r
  * Created by Eugene Petrenko (eugene.petrenko@gmail.com)\r
 \r
 /**\r
  * Created by Eugene Petrenko (eugene.petrenko@gmail.com)\r
@@ -42,19 +36,19 @@ import static jetbrains.buildServer.nuget.agent.install.LocateNuGetConfigBuildPr
 public class PackagesInstallerRunner implements AgentBuildRunner, AgentBuildRunnerInfo {\r
   private static final Logger LOG = Logger.getInstance(PackagesInstallerRunner.class.getName());\r
 \r
 public class PackagesInstallerRunner implements AgentBuildRunner, AgentBuildRunnerInfo {\r
   private static final Logger LOG = Logger.getInstance(PackagesInstallerRunner.class.getName());\r
 \r
-  private final NuGetActionFactory myInstallActionFactory;\r
+  private final NuGetActionFactory myNuGetActionFactory;\r
   private final PackagesParametersFactory myParametersFactory;\r
 \r
   private final PackagesParametersFactory myParametersFactory;\r
 \r
-  public PackagesInstallerRunner(@NotNull final NuGetActionFactory installActionFactory,\r
+  public PackagesInstallerRunner(@NotNull final NuGetActionFactory nuGetActionFactory,\r
                                  @NotNull final PackagesParametersFactory parametersFactory) {\r
                                  @NotNull final PackagesParametersFactory parametersFactory) {\r
-    myInstallActionFactory = installActionFactory;\r
+    myNuGetActionFactory = nuGetActionFactory;\r
     myParametersFactory = parametersFactory;\r
   }\r
 \r
   @NotNull\r
   public BuildProcess createBuildProcess(@NotNull AgentRunningBuild runningBuild,\r
                                          @NotNull final BuildRunnerContext context) throws RunBuildException {\r
     myParametersFactory = parametersFactory;\r
   }\r
 \r
   @NotNull\r
   public BuildProcess createBuildProcess(@NotNull AgentRunningBuild runningBuild,\r
                                          @NotNull final BuildRunnerContext context) throws RunBuildException {\r
-    final CompositeBuildProcessImpl process = new CompositeBuildProcessImpl();\r
+    CompositeBuildProcessImpl process = new CompositeBuildProcessImpl();\r
     final NuGetParameters parameters = myParametersFactory.loadNuGetParameters(context);\r
     final PackagesInstallParameters installParameters = myParametersFactory.loadInstallPackagesParameters(context, parameters);\r
     final PackagesUpdateParameters updateParameters = myParametersFactory.loadUpdatePackagesParameters(context, parameters);\r
     final NuGetParameters parameters = myParametersFactory.loadNuGetParameters(context);\r
     final PackagesInstallParameters installParameters = myParametersFactory.loadInstallPackagesParameters(context, parameters);\r
     final PackagesUpdateParameters updateParameters = myParametersFactory.loadUpdatePackagesParameters(context, parameters);\r
@@ -63,88 +57,31 @@ public class PackagesInstallerRunner implements AgentBuildRunner, AgentBuildRunn
       throw new RunBuildException("NuGet install packages must be enabled");\r
     }\r
 \r
       throw new RunBuildException("NuGet install packages must be enabled");\r
     }\r
 \r
+    final CompositeBuildProcess install = new CompositeBuildProcessImpl();\r
+    final CompositeBuildProcess update = new CompositeBuildProcessImpl();\r
+    final CompositeBuildProcess postUpdate = new CompositeBuildProcessImpl();\r
+\r
     final LocateNuGetConfigBuildProcess locate = new LocateNuGetConfigBuildProcess(\r
             parameters,\r
             context.getBuild().getBuildLogger(),\r
     final LocateNuGetConfigBuildProcess locate = new LocateNuGetConfigBuildProcess(\r
             parameters,\r
             context.getBuild().getBuildLogger(),\r
-            createLocateCallback(context, process, installParameters, updateParameters)\r
-    );\r
+            new PackagesInstallerBuilder(\r
+                    myNuGetActionFactory,\r
+                    install,\r
+                    update,\r
+                    postUpdate,\r
+                    context,\r
+                    installParameters,\r
+                    updateParameters\r
+            ));\r
+\r
     process.pushBuildProcess(locate);\r
     process.pushBuildProcess(locate);\r
+    process.pushBuildProcess(install);\r
+    process.pushBuildProcess(update);\r
+    process.pushBuildProcess(postUpdate);\r
 \r
     return process;\r
   }\r
 \r
 \r
     return process;\r
   }\r
 \r
-  @NotNull\r
-  private Callback createLocateCallback(@NotNull final BuildRunnerContext context,\r
-                                        @NotNull final CompositeBuildProcessImpl process,\r
-                                        @NotNull final PackagesInstallParameters installParameters,\r
-                                        @Nullable final PackagesUpdateParameters updateParameters) {\r
-    return new Callback() {\r
-      public void onPackagesConfigFound(@NotNull final File config,\r
-                                        @NotNull final File targetFolder) {\r
-        process.pushBuildProcess(\r
-                new DelegatingBuildProcess(\r
-                        new DelegatingBuildProcess.Action() {\r
-                          private final BuildProgressLogger logger = context.getBuild().getBuildLogger();\r
-\r
-                          @NotNull\r
-                          public BuildProcess startImpl() throws RunBuildException {\r
-                            if (updateParameters != null) {\r
-                              process.pushBuildProcess(\r
-                                      createUpdateCallback(context, updateParameters, config, targetFolder));\r
-                            }\r
-\r
-                            String pathToLog = FileUtil.getRelativePath(context.getBuild().getCheckoutDirectory(), config);\r
-                            if (pathToLog == null) pathToLog = config.getPath();\r
-                            logger.activityStarted("install", "Installing NuGet packages for " + pathToLog, "nuget");\r
-\r
-\r
-                            return myInstallActionFactory.createInstall(context,\r
-                                    installParameters,\r
-                                    config,\r
-                                    targetFolder)\r
-                                    ;\r
-                          }\r
-\r
-                          public void finishedImpl() {\r
-                            logger.activityFinished("install", "nuget");\r
-                          }\r
-                        }\r
-                )\r
-        );\r
-      }\r
-    };\r
-  }\r
-\r
-  @NotNull\r
-  private BuildProcess createUpdateCallback(@NotNull final BuildRunnerContext context,\r
-                                            @NotNull final PackagesUpdateParameters parameters,\r
-                                            @NotNull final File config,\r
-                                            @NotNull final File targetFolder) {\r
-    return\r
-            new DelegatingBuildProcess(\r
-                    new DelegatingBuildProcess.Action() {\r
-                      private final BuildProgressLogger logger = context.getBuild().getBuildLogger();\r
-\r
-                      @NotNull\r
-                      public BuildProcess startImpl() throws RunBuildException {\r
-                        String pathToLog = FileUtil.getRelativePath(context.getBuild().getCheckoutDirectory(), config);\r
-                        if (pathToLog == null) pathToLog = config.getPath();\r
-                        logger.activityStarted("update", "Updating NuGet packages for " + pathToLog, "nuget");\r
-\r
-                        return myInstallActionFactory.createUpdate(context,\r
-                                parameters,\r
-                                config,\r
-                                targetFolder)\r
-                                ;\r
-                      }\r
-\r
-                      public void finishedImpl() {\r
-                        logger.activityFinished("update", "nuget");\r
-                      }\r
-                    }\r
-            );\r
-  }\r
-\r
   @NotNull\r
   public AgentBuildRunnerInfo getRunnerInfo() {\r
     return this;\r
   @NotNull\r
   public AgentBuildRunnerInfo getRunnerInfo() {\r
     return this;\r
index a6802e44108dec1aff0ee7c946cf5777248fe273..0bd397811181bdef98510524b6eff6e97011e9db 100644 (file)
@@ -127,9 +127,10 @@ public class InstallPackageIntegtatoinTest extends BuildProcessTestCase {
     System.out.println("installed packageses = " + packageses);\r
 \r
     Assert.assertTrue(new File(myRoot, "packages/NUnit.2.5.7.10213").isDirectory());\r
     System.out.println("installed packageses = " + packageses);\r
 \r
     Assert.assertTrue(new File(myRoot, "packages/NUnit.2.5.7.10213").isDirectory());\r
+    Assert.assertTrue(new File(myRoot, "packages/NUnit.2.5.10.11092").isDirectory());\r
     Assert.assertTrue(new File(myRoot, "packages/NInject.2.2.1.4").isDirectory());\r
     Assert.assertTrue(new File(myRoot, "packages/Machine.Specifications.0.4.13.0").isDirectory());\r
     Assert.assertTrue(new File(myRoot, "packages/NInject.2.2.1.4").isDirectory());\r
     Assert.assertTrue(new File(myRoot, "packages/Machine.Specifications.0.4.13.0").isDirectory());\r
-    Assert.assertEquals(4, packageses.size());\r
+    Assert.assertEquals(5, packageses.size());\r
   }\r
 \r
   @Test\r
   }\r
 \r
   @Test\r
@@ -151,9 +152,10 @@ public class InstallPackageIntegtatoinTest extends BuildProcessTestCase {
     System.out.println("installed packageses = " + packageses);\r
 \r
     Assert.assertTrue(new File(myRoot, "packages/NUnit.2.5.7.10213").isDirectory());\r
     System.out.println("installed packageses = " + packageses);\r
 \r
     Assert.assertTrue(new File(myRoot, "packages/NUnit.2.5.7.10213").isDirectory());\r
+    Assert.assertTrue(new File(myRoot, "packages/NUnit.2.5.10.11092").isDirectory());\r
     Assert.assertTrue(new File(myRoot, "packages/NInject.2.2.1.4").isDirectory());\r
     Assert.assertTrue(new File(myRoot, "packages/Machine.Specifications.0.4.13.0").isDirectory());\r
     Assert.assertTrue(new File(myRoot, "packages/NInject.2.2.1.4").isDirectory());\r
     Assert.assertTrue(new File(myRoot, "packages/Machine.Specifications.0.4.13.0").isDirectory());\r
-    Assert.assertEquals(4, packageses.size());\r
+    Assert.assertEquals(5, packageses.size());\r
   }\r
 \r
   @Test\r
   }\r
 \r
   @Test\r