support -ExcludeVersion nuget parameter
authorEugene.Petrenko <eugene.petrenko@gmail.com>
Sat, 9 Jul 2011 12:35:34 +0000 (16:35 +0400)
committerEugene.Petrenko <eugene.petrenko@gmail.com>
Sat, 9 Jul 2011 12:35:34 +0000 (16:35 +0400)
nuget-agent/src/jetbrains/buildServer/nuget/agent/install/PackagesInstallParameters.java
nuget-agent/src/jetbrains/buildServer/nuget/agent/install/impl/NuGetInstallPackageActionFactoryImpl.java
nuget-agent/src/jetbrains/buildServer/nuget/agent/install/impl/PackageInstallParametersFactoryImpl.java
nuget-common/src/jetbrains/buildServer/nuget/common/PackagesInstallerConstants.java
nuget-server/resources/install/editInstallPackage.jsp
nuget-server/resources/install/viewInstallPackage.jsp
nuget-server/src/jetbrains/buildServer/nuget/server/install/InstallBean.java
nuget-tests/src/jetbrains/buildServer/nuget/tests/agent/NuGetInstallPackageActionFactoryTest.java
nuget-tests/src/jetbrains/buildServer/nuget/tests/integration/InstallPackageIntegtatoinTest.java

index 4e424badf3261370be48900b4d5fa830da56b85b..11f1289e6c65649f89f159e66c3bff560ce2a9ba 100644 (file)
@@ -47,4 +47,11 @@ public interface PackagesInstallParameters {
    */\r
   @NotNull\r
   Collection<String> getNuGetPackageSources();\r
+\r
+  /**\r
+   * @return true if pacakges are expected to be installed\r
+   *         without version\r
+   *         numbers in directory names\r
+   */\r
+  boolean getExcludeVersion();\r
 }\r
index 2f7185c9ae8c28d8fc627700da43bfbf04171ec9..1eaa437ec0caa1cc568e559c4806a514c4226fce 100644 (file)
@@ -47,6 +47,9 @@ public class NuGetInstallPackageActionFactoryImpl implements NuGetInstallPackage
     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
index 58d60edb453c0de8fb127dbbd230f64c87af1413..79b324ac04227156e574a71ad1cf860ee86153e1 100644 (file)
@@ -20,7 +20,6 @@ import jetbrains.buildServer.RunBuildException;
 import jetbrains.buildServer.agent.BuildRunnerContext;\r
 import jetbrains.buildServer.nuget.agent.install.PackageInstallParametersFactory;\r
 import jetbrains.buildServer.nuget.agent.install.PackagesInstallParameters;\r
-import jetbrains.buildServer.nuget.common.PackagesInstallerConstants;\r
 import jetbrains.buildServer.util.FileUtil;\r
 import jetbrains.buildServer.util.StringUtil;\r
 import org.jetbrains.annotations.NotNull;\r
@@ -32,6 +31,8 @@ import java.util.Collection;
 import java.util.Collections;\r
 import java.util.List;\r
 \r
+import static jetbrains.buildServer.nuget.common.PackagesInstallerConstants.*;\r
+\r
 /**\r
  * Created by Eugene Petrenko (eugene.petrenko@gmail.com)\r
  * Date: 07.07.11 18:09\r
@@ -57,17 +58,17 @@ public class PackageInstallParametersFactoryImpl implements PackageInstallParame
 \r
       @NotNull\r
       public File getSolutionFile() throws RunBuildException {\r
-        return resolvePath(PackagesInstallerConstants.SLN_PATH, "Visual Studio .sln file");\r
+        return resolvePath(SLN_PATH, "Visual Studio .sln file");\r
       }\r
 \r
       @NotNull\r
       public File getNuGetExeFile() throws RunBuildException {\r
-        return resolvePath(PackagesInstallerConstants.NUGET_PATH, "nuget.exe");\r
+        return resolvePath(NUGET_PATH, "nuget.exe");\r
       }\r
 \r
       @NotNull\r
       public Collection<String> getNuGetPackageSources() {\r
-        String sources = context.getRunnerParameters().get(PackagesInstallerConstants.NUGET_SOURCES);\r
+        String sources = context.getRunnerParameters().get(NUGET_SOURCES);\r
         if (sources == null) return Collections.emptyList();\r
 \r
         List<String> list = new ArrayList<String>();\r
@@ -80,6 +81,10 @@ public class PackageInstallParametersFactoryImpl implements PackageInstallParame
 \r
         return Collections.unmodifiableList(list);\r
       }\r
+\r
+      public boolean getExcludeVersion() {\r
+        return !StringUtil.isEmptyOrSpaces(context.getRunnerParameters().get(NUGET_EXCLUDE_VERSION));\r
+      }\r
     };\r
   }\r
 }\r
index e686fca208cb19393229bbd1a8f5f7f20b7fb56c..f442f3e6d567be336f085bd03d5e51667ac13a28 100644 (file)
@@ -26,5 +26,6 @@ public interface PackagesInstallerConstants {
 \r
   public static final String NUGET_PATH = "nuget.path";\r
   public static final String NUGET_SOURCES = "nuget.sources";\r
+  public static final String NUGET_EXCLUDE_VERSION = "nuget.excludeVersion";\r
   public static final String SLN_PATH = "sln.path";\r
 }\r
index cb0c7b36d61dc1ba089330705fd52162a45a95e4..f7e547f43b81b8b5f489a644b745cc5f6c52ff8a 100644 (file)
 </l:settingsGroup>\r
 \r
 <l:settingsGroup title="Packages">\r
-<tr>\r
-  <th>Path to solution file</th>\r
-  <td>\r
-    <props:textProperty name="${ib.solutionPathKey}" className="longField"/>\r
-    <span class="smallNote">Specify path to Visual Studio solution file (.sln)</span>\r
-  </td>\r
-</tr>\r
+  <tr>\r
+    <th>Path to solution file</th>\r
+    <td>\r
+      <props:textProperty name="${ib.solutionPathKey}" className="longField"/>\r
+      <span class="smallNote">Specify path to Visual Studio solution file (.sln)</span>\r
+    </td>\r
+  </tr>\r
+  <tr>\r
+    <th>Options</th>\r
+    <td>\r
+      <props:checkboxProperty name="${ib.excludeVersionKey}"/>\r
+      Exclude version from package folder names\r
+      <span class="smallNote">Makes NuGet exlude package version from package folders. Equivalent of -ExcludeVersion commandline argument</span>\r
+    </td>\r
+  </tr>\r
+\r
 </l:settingsGroup>\r
index 672d3979aed3ff363d30e31939adaf79c522aa37..ce99f151083e146cb3156e4cab83af0d7e3e8a5b 100644 (file)
@@ -29,3 +29,7 @@
 <div class="parameter">\r
   Path to .sln: <strong><props:displayValue name="${ib.solutionPathKey}"/></strong>\r
 </div>\r
+\r
+<div class="parameter">\r
+  Exclude Version: <strong><props:displayCheckboxValue name="${ib.excludeVersionKey}"/></strong>\r
+</div>\r
index 59dd28f87d785c5ade26a60aed63c3546c65625f..b7388b8e4e46d9d7d8b9746ee2e1e0695fce18af 100644 (file)
@@ -26,4 +26,5 @@ public class InstallBean {
   public String getNuGetPathKey() { return PackagesInstallerConstants.NUGET_PATH; }\r
   public String getNuGetSourcesKey() { return PackagesInstallerConstants.NUGET_SOURCES; }\r
   public String getSolutionPathKey() { return PackagesInstallerConstants.SLN_PATH; }\r
+  public String getExcludeVersionKey() { return PackagesInstallerConstants.NUGET_EXCLUDE_VERSION;}\r
 }\r
index b23b2926994c57be93ceed8784cf9db8e17376bc..90d6ab9d6604d55a5209b18cfbc03481418dfc90 100644 (file)
@@ -65,6 +65,7 @@ public class NuGetInstallPackageActionFactoryTest extends BaseTestCase {
     m.checking(new Expectations(){{\r
       allowing(ps).getNuGetPackageSources(); will(returnValue(Collections.<String>emptyList()));\r
       allowing(ps).getNuGetExeFile();  will(returnValue(nuget));\r
+      allowing(ps).getExcludeVersion(); will(returnValue(false));\r
 \r
       oneOf(myProcessFactory).executeCommandLine(\r
               ctx,\r
@@ -78,12 +79,33 @@ public class NuGetInstallPackageActionFactoryTest extends BaseTestCase {
     m.assertIsSatisfied();\r
   }\r
 \r
+  @Test\r
+  public void test_no_sources_excludeVersion() throws RunBuildException, IOException {\r
+    final File nuget = createTempFile();\r
+    m.checking(new Expectations(){{\r
+      allowing(ps).getNuGetPackageSources(); will(returnValue(Collections.<String>emptyList()));\r
+      allowing(ps).getNuGetExeFile();  will(returnValue(nuget));\r
+      allowing(ps).getExcludeVersion(); will(returnValue(true));\r
+\r
+      oneOf(myProcessFactory).executeCommandLine(\r
+              ctx,\r
+              nuget,\r
+              Arrays.asList("install", myConfig.getPath(), "-ExcludeVersion", "-OutputDirectory", myTarget.getPath()),\r
+              myConfig.getParentFile()\r
+      );\r
+    }});\r
+\r
+    i.createBuildProcess(ctx, ps, myConfig, myTarget);\r
+    m.assertIsSatisfied();\r
+  }\r
+\r
   @Test\r
   public void test_sources() throws RunBuildException, IOException {\r
     final File nuget = createTempFile();\r
     m.checking(new Expectations(){{\r
       allowing(ps).getNuGetPackageSources(); will(returnValue(Arrays.asList("aaa", "bbb")));\r
       allowing(ps).getNuGetExeFile();  will(returnValue(nuget));\r
+      allowing(ps).getExcludeVersion(); will(returnValue(false));\r
 \r
       oneOf(myProcessFactory).executeCommandLine(\r
               ctx,\r
index 9c09a3d8eb8a665bf9df5f4166f980aeb628d22d..a5835b71a35ec4270bc3c363031336a3165d7559 100644 (file)
@@ -92,7 +92,7 @@ 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());\r
+    fetchPackages(new File(myRoot, "sln1-lib.sln"), Collections.<String>emptyList(), false);\r
 \r
     List<File> packageses = Arrays.asList(new File(myRoot, "packages").listFiles());\r
     System.out.println("installed packageses = " + packageses);\r
@@ -103,13 +103,28 @@ public class InstallPackageIntegtatoinTest extends BuildProcessTestCase {
     Assert.assertEquals(4, packageses.size());\r
   }\r
 \r
+  @Test\r
+  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
+\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").isDirectory());\r
+    Assert.assertTrue(new File(myRoot, "packages/NInject").isDirectory());\r
+    Assert.assertTrue(new File(myRoot, "packages/Machine.Specifications").isDirectory());\r
+    Assert.assertEquals(4, packageses.size());\r
+  }\r
+\r
   @Test(enabled = false, dependsOnGroups = "Need to understand how to check NuGet uses only specified sources")\r
   public void test_01_local_sources() throws RunBuildException {\r
     ArchiveUtil.unpackZip(getTestDataPath("test-01.zip"), "", myRoot);\r
     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()));\r
+    fetchPackages(new File(myRoot, "sln1-lib.sln"), Arrays.asList("file:///" + sourcesDir.getPath()), false);\r
 \r
     List<File> packageses = Arrays.asList(new File(myRoot, "packages").listFiles());\r
     System.out.println("installed packageses = " + packageses);\r
@@ -120,7 +135,7 @@ public class InstallPackageIntegtatoinTest extends BuildProcessTestCase {
     Assert.assertEquals(4, packageses.size());\r
   }\r
 \r
-  private void fetchPackages(final File sln, final List<String> sources) throws RunBuildException {\r
+  private void fetchPackages(final File sln, final List<String> sources, final boolean excludeVersion) throws RunBuildException {\r
     m.checking(new Expectations() {{\r
       allowing(myParametersFactory).loadParameters(myContext);\r
       will(returnValue(myParameters));\r
@@ -131,6 +146,8 @@ public class InstallPackageIntegtatoinTest extends BuildProcessTestCase {
       will(returnValue(sln));\r
       allowing(myParameters).getNuGetPackageSources();\r
       will(returnValue(sources));\r
+      allowing(myParameters).getExcludeVersion();\r
+      will(returnValue(excludeVersion));\r
     }});\r
 \r
     BuildProcess proc = new PackagesInstallerRunner(\r