support packages update. Tests, Integration tests
authorEugene.Petrenko <eugene.petrenko@gmail.com>
Sun, 10 Jul 2011 12:46:37 +0000 (16:46 +0400)
committerEugene.Petrenko <eugene.petrenko@gmail.com>
Sun, 10 Jul 2011 12:46:37 +0000 (16:46 +0400)
nuget-agent/src/jetbrains/buildServer/nuget/agent/install/PackagesInstallerRunner.java
nuget-agent/src/jetbrains/buildServer/nuget/agent/install/impl/NuGetActionFactoryImpl.java
nuget-tests/src/jetbrains/buildServer/nuget/tests/agent/NuGetUpdatePackageActionFactoryTest.java
nuget-tests/src/jetbrains/buildServer/nuget/tests/integration/InstallPackageIntegtatoinTest.java
nuget-tests/src/testng-nuget-tests..xml

index 0b79e860e792e9b3941e80314cd6bad315d9dc89..d9e45746c5cbf478f72eb28461769d0c88dc7426 100644 (file)
@@ -22,12 +22,14 @@ import jetbrains.buildServer.agent.*;
 import jetbrains.buildServer.nuget.agent.parameters.NuGetParameters;\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.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.Nullable;\r
 \r
 import java.io.File;\r
 \r
@@ -55,6 +57,7 @@ public class PackagesInstallerRunner implements AgentBuildRunner, AgentBuildRunn
     final 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
 \r
     if (installParameters == null) {\r
       throw new RunBuildException("NuGet install packages must be enabled");\r
@@ -63,7 +66,7 @@ public class PackagesInstallerRunner implements AgentBuildRunner, AgentBuildRunn
     final LocateNuGetConfigBuildProcess locate = new LocateNuGetConfigBuildProcess(\r
             parameters,\r
             context.getBuild().getBuildLogger(),\r
-            createLocateCallback(context, process, installParameters)\r
+            createLocateCallback(context, process, installParameters, updateParameters)\r
     );\r
     process.pushBuildProcess(locate);\r
 \r
@@ -73,7 +76,8 @@ public class PackagesInstallerRunner implements AgentBuildRunner, AgentBuildRunn
   @NotNull\r
   private Callback createLocateCallback(@NotNull final BuildRunnerContext context,\r
                                         @NotNull final CompositeBuildProcessImpl process,\r
-                                        @NotNull final PackagesInstallParameters parameters) {\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
@@ -84,12 +88,18 @@ public class PackagesInstallerRunner implements AgentBuildRunner, AgentBuildRunn
 \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
-                                    parameters,\r
+                                    installParameters,\r
                                     config,\r
                                     targetFolder)\r
                                     ;\r
@@ -105,6 +115,36 @@ public class PackagesInstallerRunner implements AgentBuildRunner, AgentBuildRunn
     };\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
index 0eb14b8f40bb386025740be6f4cb8231f352e7c6..1ce6cafedc2f1095073a1bccff5040d7e4d8e6e9 100644 (file)
@@ -72,6 +72,7 @@ public class NuGetActionFactoryImpl implements NuGetActionFactory {
     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
index afb4d94265020628c851d6cc55f9e0f2364a63ec..022d936a047281aefa648a7cb7827446ace33d56 100644 (file)
@@ -77,7 +77,7 @@ public class NuGetUpdatePackageActionFactoryTest extends BaseTestCase {
       oneOf(myProcessFactory).executeCommandLine(\r
               ctx,\r
               nuget,\r
-              Arrays.asList("update", myConfig.getPath(), "-RepositoryPath", myTarget.getPath()),\r
+              Arrays.asList("update", myConfig.getPath(), "-Verbose", "-RepositoryPath", myTarget.getPath()),\r
               myConfig.getParentFile()\r
       );\r
     }});\r
@@ -98,7 +98,7 @@ public class NuGetUpdatePackageActionFactoryTest extends BaseTestCase {
       oneOf(myProcessFactory).executeCommandLine(\r
               ctx,\r
               nuget,\r
-              Arrays.asList("update", myConfig.getPath(), "-RepositoryPath", myTarget.getPath(), "-Id", "aaa", "-Id", "bbb"),\r
+              Arrays.asList("update", myConfig.getPath(), "-Verbose", "-RepositoryPath", myTarget.getPath(), "-Id", "aaa", "-Id", "bbb"),\r
               myConfig.getParentFile()\r
       );\r
     }});\r
@@ -119,7 +119,7 @@ public class NuGetUpdatePackageActionFactoryTest extends BaseTestCase {
       oneOf(myProcessFactory).executeCommandLine(\r
               ctx,\r
               nuget,\r
-              Arrays.asList("update", myConfig.getPath(), "-Safe", "-RepositoryPath", myTarget.getPath()),\r
+              Arrays.asList("update", myConfig.getPath(), "-Safe", "-Verbose", "-RepositoryPath", myTarget.getPath()),\r
               myConfig.getParentFile()\r
       );\r
     }});\r
@@ -140,7 +140,7 @@ public class NuGetUpdatePackageActionFactoryTest extends BaseTestCase {
       oneOf(myProcessFactory).executeCommandLine(\r
               ctx,\r
               nuget,\r
-              Arrays.asList("update", myConfig.getPath(), "-RepositoryPath", myTarget.getPath(), "-Source", "aaa", "-Source", "bbb"),\r
+              Arrays.asList("update", myConfig.getPath(), "-Verbose", "-RepositoryPath", myTarget.getPath(), "-Source", "aaa", "-Source", "bbb"),\r
               myConfig.getParentFile()\r
       );\r
     }});\r
index 6b4ba3b0cfad58e53a9a7c7233b65c18da375ee5..a6802e44108dec1aff0ee7c946cf5777248fe273 100644 (file)
@@ -26,6 +26,7 @@ import jetbrains.buildServer.nuget.agent.parameters.PackagesParametersFactory;
 import jetbrains.buildServer.nuget.agent.parameters.PackagesInstallParameters;\r
 import jetbrains.buildServer.nuget.agent.install.PackagesInstallerRunner;\r
 import jetbrains.buildServer.nuget.agent.install.impl.NuGetActionFactoryImpl;\r
+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.nuget.tests.util.BuildProcessTestCase;\r
@@ -55,7 +56,8 @@ public class InstallPackageIntegtatoinTest extends BuildProcessTestCase {
   private BuildRunnerContext myContext;\r
   private BuildProgressLogger myLogger;\r
   private PackagesParametersFactory myParametersFactory;\r
-  private PackagesInstallParameters myParameters;\r
+  private PackagesInstallParameters myInstall;\r
+  private PackagesUpdateParameters myUpdate;\r
   private NuGetParameters myNuGet;\r
   private BuildProcess myMockProcess;\r
 \r
@@ -69,7 +71,8 @@ public class InstallPackageIntegtatoinTest extends BuildProcessTestCase {
     myContext = m.mock(BuildRunnerContext.class);\r
     myLogger = m.mock(BuildProgressLogger.class);\r
     myParametersFactory = m.mock(PackagesParametersFactory.class);\r
-    myParameters = m.mock(PackagesInstallParameters.class);\r
+    myInstall = m.mock(PackagesInstallParameters.class);\r
+    myUpdate = m.mock(PackagesUpdateParameters.class);\r
     myMockProcess = m.mock(BuildProcess.class);\r
     myNuGet = m.mock(NuGetParameters.class);\r
 \r
@@ -85,7 +88,8 @@ public class InstallPackageIntegtatoinTest extends BuildProcessTestCase {
       allowing(myLogger).activityStarted(with(equal("install")), with(any(String.class)), with(any(String.class)));\r
       allowing(myLogger).activityFinished(with(equal("install")), with(any(String.class)));\r
 \r
-      allowing(myParameters).getNuGetParameters(); will(returnValue(myNuGet));\r
+      allowing(myInstall).getNuGetParameters(); will(returnValue(myNuGet));\r
+      allowing(myUpdate).getNuGetParameters(); will(returnValue(myNuGet));\r
     }});\r
   }\r
 \r
@@ -93,7 +97,55 @@ public class InstallPackageIntegtatoinTest extends BuildProcessTestCase {
   public void test_01_online_sources() throws RunBuildException {\r
     ArchiveUtil.unpackZip(getTestDataPath("test-01.zip"), "", myRoot);\r
 \r
-    fetchPackages(new File(myRoot, "sln1-lib.sln"), Collections.<String>emptyList(), false);\r
+    fetchPackages(new File(myRoot, "sln1-lib.sln"), Collections.<String>emptyList(), false, false);\r
+\r
+    List<File> packageses = Arrays.asList(new File(myRoot, "packages").listFiles());\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/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
+  }\r
+\r
+  @Test\r
+  public void test_01_online_sources_update() throws RunBuildException {\r
+    ArchiveUtil.unpackZip(getTestDataPath("test-01.zip"), "", myRoot);\r
+\r
+    m.checking(new Expectations(){{\r
+      allowing(myLogger).activityStarted(with(equal("update")), with(any(String.class)), with(equal("nuget")));\r
+      allowing(myLogger).activityFinished(with(equal("update")), with(equal("nuget")));\r
+\r
+      allowing(myUpdate).getUseSafeUpdate(); will(returnValue(false));\r
+      allowing(myUpdate).getPackagesToUpdate(); will(returnValue(Collections.<String>emptyList()));\r
+    }});\r
+\r
+    fetchPackages(new File(myRoot, "sln1-lib.sln"), Collections.<String>emptyList(), false, true);\r
+\r
+\r
+    List<File> packageses = Arrays.asList(new File(myRoot, "packages").listFiles());\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/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
+  }\r
+\r
+  @Test\r
+  public void test_01_online_sources_update_safe() throws RunBuildException {\r
+    ArchiveUtil.unpackZip(getTestDataPath("test-01.zip"), "", myRoot);\r
+\r
+    m.checking(new Expectations(){{\r
+      allowing(myLogger).activityStarted(with(equal("update")), with(any(String.class)), with(equal("nuget")));\r
+      allowing(myLogger).activityFinished(with(equal("update")), with(equal("nuget")));\r
+\r
+      allowing(myUpdate).getUseSafeUpdate(); will(returnValue(true));\r
+      allowing(myUpdate).getPackagesToUpdate(); will(returnValue(Collections.<String>emptyList()));\r
+    }});\r
+\r
+    fetchPackages(new File(myRoot, "sln1-lib.sln"), Collections.<String>emptyList(), false, true);\r
+\r
 \r
     List<File> packageses = Arrays.asList(new File(myRoot, "packages").listFiles());\r
     System.out.println("installed packageses = " + packageses);\r
@@ -108,7 +160,7 @@ public class InstallPackageIntegtatoinTest extends BuildProcessTestCase {
   public void test_01_online_sources_ecludeVersion() throws RunBuildException {\r
     ArchiveUtil.unpackZip(getTestDataPath("test-01.zip"), "", myRoot);\r
 \r
-    fetchPackages(new File(myRoot, "sln1-lib.sln"), Collections.<String>emptyList(), true);\r
+    fetchPackages(new File(myRoot, "sln1-lib.sln"), Collections.<String>emptyList(), true, false);\r
 \r
     List<File> packageses = Arrays.asList(new File(myRoot, "packages").listFiles());\r
     System.out.println("installed packageses = " + packageses);\r
@@ -125,7 +177,7 @@ public class InstallPackageIntegtatoinTest extends BuildProcessTestCase {
     File sourcesDir = new File(myRoot, "js");\r
     ArchiveUtil.unpackZip(getTestDataPath("test-01-sources.zip"), "", sourcesDir);\r
 \r
-    fetchPackages(new File(myRoot, "sln1-lib.sln"), Arrays.asList("file:///" + sourcesDir.getPath()), false);\r
+    fetchPackages(new File(myRoot, "sln1-lib.sln"), Arrays.asList("file:///" + sourcesDir.getPath()), false, false);\r
 \r
     List<File> packageses = Arrays.asList(new File(myRoot, "packages").listFiles());\r
     System.out.println("installed packageses = " + packageses);\r
@@ -136,15 +188,19 @@ public class InstallPackageIntegtatoinTest extends BuildProcessTestCase {
     Assert.assertEquals(4, packageses.size());\r
   }\r
 \r
-  private void fetchPackages(final File sln, final List<String> sources, final boolean excludeVersion) throws RunBuildException {\r
+  private void fetchPackages(final File sln,\r
+                             final List<String> sources,\r
+                             final boolean excludeVersion,\r
+                             final boolean update) throws RunBuildException {\r
     m.checking(new Expectations() {{\r
       allowing(myParametersFactory).loadNuGetParameters(myContext);  will(returnValue(myNuGet));\r
-      allowing(myParametersFactory).loadInstallPackagesParameters(myContext, myNuGet);  will(returnValue(myParameters));\r
+      allowing(myParametersFactory).loadInstallPackagesParameters(myContext, myNuGet);  will(returnValue(myInstall));\r
 \r
       allowing(myNuGet).getNuGetExeFile(); will(returnValue(getPathToNuGet()));\r
       allowing(myNuGet).getSolutionFile(); will(returnValue(sln));\r
       allowing(myNuGet).getNuGetPackageSources(); will(returnValue(sources));\r
-      allowing(myParameters).getExcludeVersion(); will(returnValue(excludeVersion));\r
+      allowing(myInstall).getExcludeVersion(); will(returnValue(excludeVersion));\r
+      allowing(myParametersFactory).loadUpdatePackagesParameters(myContext, myNuGet);  will(returnValue(update ? myUpdate : null));\r
     }});\r
 \r
     BuildProcess proc = new PackagesInstallerRunner(\r
index a824e97c85598a33e6d9768dc4c8fe3c76ec19b4..47ae74cc595e4ddedf255370fc9b2e776bfb801c 100644 (file)
@@ -5,6 +5,7 @@
     <classes>\r
       <class name="jetbrains.buildServer.nuget.tests.agent.LocateNuGetConfigBuildProcessTest"/>\r
       <class name="jetbrains.buildServer.nuget.tests.agent.NuGetInstallPackageActionFactoryTest"/>\r
+      <class name="jetbrains.buildServer.nuget.tests.agent.NuGetUpdatePackageActionFactoryTest"/>\r
 \r
       <class name="jetbrains.buildServer.nuget.tests.util.CompositeBuildProcessTest"/>\r
       <class name="jetbrains.buildServer.nuget.tests.util.DelegatingBuildProcessTest"/>\r