import jetbrains.buildServer.agent.BuildRunnerContext;\r
import jetbrains.buildServer.nuget.agent.install.NuGetActionFactory;\r
import jetbrains.buildServer.nuget.agent.install.PackagesInstallParameters;\r
+import jetbrains.buildServer.nuget.agent.install.PackagesUpdateParameters;\r
import jetbrains.buildServer.nuget.agent.util.CommandlineBuildProcessFactory;\r
import jetbrains.buildServer.util.FileUtil;\r
import org.jetbrains.annotations.NotNull;\r
packagesConfig.getParentFile()\r
);\r
}\r
+\r
+\r
+ @NotNull\r
+ public BuildProcess createUpdate(@NotNull final BuildRunnerContext context,\r
+ @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("-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
+ for (String source : params.getNuGetPackageSources()) {\r
+ argz.add("-Source");\r
+ argz.add(source);\r
+ }\r
+\r
+ return myFactory.executeCommandLine(\r
+ context,\r
+ params.getNuGetExeFile(),\r
+ argz,\r
+ packagesConfig.getParentFile()\r
+ );\r
+ }\r
}\r
--- /dev/null
+/*\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.tests.agent;\r
+\r
+import jetbrains.buildServer.BaseTestCase;\r
+import jetbrains.buildServer.RunBuildException;\r
+import jetbrains.buildServer.agent.BuildRunnerContext;\r
+import jetbrains.buildServer.nuget.agent.install.PackagesUpdateParameters;\r
+import jetbrains.buildServer.nuget.agent.install.impl.NuGetActionFactoryImpl;\r
+import jetbrains.buildServer.nuget.agent.util.CommandlineBuildProcessFactory;\r
+import org.jmock.Expectations;\r
+import org.jmock.Mockery;\r
+import org.testng.annotations.BeforeMethod;\r
+import org.testng.annotations.Test;\r
+\r
+import java.io.File;\r
+import java.io.IOException;\r
+import java.util.Arrays;\r
+import java.util.Collections;\r
+\r
+/**\r
+ * Created by Eugene Petrenko (eugene.petrenko@gmail.com)\r
+ * Date: 10.07.11 14:29\r
+ */\r
+public class NuGetUpdatePackageActionFactoryTest extends BaseTestCase {\r
+ private Mockery m;\r
+ private CommandlineBuildProcessFactory myProcessFactory;\r
+ private NuGetActionFactoryImpl i;\r
+ private BuildRunnerContext ctx;\r
+ private PackagesUpdateParameters ps;\r
+ private File myTarget;\r
+ private File myConfig;\r
+\r
+ @BeforeMethod\r
+ @Override\r
+ protected void setUp() throws Exception {\r
+ super.setUp();\r
+ m = new Mockery();\r
+ myProcessFactory = m.mock(CommandlineBuildProcessFactory.class);\r
+ i = new NuGetActionFactoryImpl(myProcessFactory);\r
+ ctx = m.mock(BuildRunnerContext.class);\r
+ ps = m.mock(PackagesUpdateParameters.class);\r
+\r
+ myTarget = createTempDir();\r
+ myConfig = createTempFile();\r
+ }\r
+\r
+ @Test\r
+ public void test_no_sources() 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).getUseSafeUpdate(); will(returnValue(false));\r
+ allowing(ps).getPackagesToUpdate(); will(returnValue(Collections.<String>emptyList()));\r
+\r
+ oneOf(myProcessFactory).executeCommandLine(\r
+ ctx,\r
+ nuget,\r
+ Arrays.asList("update", myConfig.getPath(), "-RepositoryPath", myTarget.getPath()),\r
+ myConfig.getParentFile()\r
+ );\r
+ }});\r
+\r
+ i.createUpdate(ctx, ps, myConfig, myTarget);\r
+ m.assertIsSatisfied();\r
+ }\r
+\r
+ @Test\r
+ public void test_packageIds() 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).getUseSafeUpdate(); will(returnValue(false));\r
+ allowing(ps).getPackagesToUpdate(); will(returnValue(Arrays.asList("aaa", "bbb")));\r
+\r
+ oneOf(myProcessFactory).executeCommandLine(\r
+ ctx,\r
+ nuget,\r
+ Arrays.asList("update", myConfig.getPath(), "-RepositoryPath", myTarget.getPath(), "-Id", "aaa", "-Id", "bbb"),\r
+ myConfig.getParentFile()\r
+ );\r
+ }});\r
+\r
+ i.createUpdate(ctx, ps, myConfig, myTarget);\r
+ m.assertIsSatisfied();\r
+ }\r
+\r
+ @Test\r
+ public void test_safe() 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).getUseSafeUpdate(); will(returnValue(true));\r
+ allowing(ps).getPackagesToUpdate(); will(returnValue(Collections.<String>emptyList()));\r
+\r
+ oneOf(myProcessFactory).executeCommandLine(\r
+ ctx,\r
+ nuget,\r
+ Arrays.asList("update", myConfig.getPath(), "-Safe", "-RepositoryPath", myTarget.getPath()),\r
+ myConfig.getParentFile()\r
+ );\r
+ }});\r
+\r
+ i.createUpdate(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).getUseSafeUpdate(); will(returnValue(false));\r
+ allowing(ps).getPackagesToUpdate(); will(returnValue(Collections.<String>emptyList()));\r
+\r
+ oneOf(myProcessFactory).executeCommandLine(\r
+ ctx,\r
+ nuget,\r
+ Arrays.asList("update", myConfig.getPath(), "-RepositoryPath", myTarget.getPath(), "-Source", "aaa", "-Source", "bbb"),\r
+ myConfig.getParentFile()\r
+ );\r
+ }});\r
+\r
+ i.createUpdate(ctx, ps, myConfig, myTarget);\r
+ m.assertIsSatisfied();\r
+ }\r
+\r
+\r
+}\r