implement nuget push command
authorEugene Petrenko <eugene.petrenko@gmail.com>
Thu, 21 Jul 2011 13:40:53 +0000 (17:40 +0400)
committerEugene Petrenko <eugene.petrenko@gmail.com>
Thu, 21 Jul 2011 13:40:53 +0000 (17:40 +0400)
nuget-agent/src/jetbrains/buildServer/nuget/agent/commands/NuGetActionFactory.java
nuget-agent/src/jetbrains/buildServer/nuget/agent/commands/impl/LoggingNuGetActionFactoryImpl.java
nuget-agent/src/jetbrains/buildServer/nuget/agent/commands/impl/NuGetActionFactoryImpl.java
nuget-tests/src/jetbrains/buildServer/nuget/tests/agent/NuGetPushActoinFactoryTest.java [new file with mode: 0644]
nuget-tests/src/testng-nuget-tests..xml

index 911a2e6434eee09612ad62b1c86d0a119bf6873c..d9087a0a1100118a73b394b8675a7801ee98f308 100644 (file)
@@ -20,6 +20,7 @@ import jetbrains.buildServer.RunBuildException;
 import jetbrains.buildServer.agent.BuildProcess;\r
 import jetbrains.buildServer.agent.BuildRunnerContext;\r
 import jetbrains.buildServer.nuget.agent.parameters.NuGetFetchParameters;\r
+import jetbrains.buildServer.nuget.agent.parameters.NuGetPublishParameters;\r
 import jetbrains.buildServer.nuget.agent.parameters.PackagesInstallParameters;\r
 import jetbrains.buildServer.nuget.agent.parameters.PackagesUpdateParameters;\r
 import org.jetbrains.annotations.NotNull;\r
@@ -48,4 +49,11 @@ public interface NuGetActionFactory {
                                  @NotNull NuGetFetchParameters params,\r
                                  @NotNull File packagesConfig,\r
                                  @NotNull File targetFolder) throws RunBuildException;\r
+\r
+\r
+  @NotNull\r
+  BuildProcess createPush(@NotNull BuildRunnerContext context,\r
+                          @NotNull NuGetPublishParameters params,\r
+                          @NotNull File packagePath) throws RunBuildException;\r
+\r
 }\r
index ece0ccd2ab2ae955aa3157092f7441f563c4ce18..d470ed128c0229564a2576d747ad6c1874965bcc 100644 (file)
@@ -22,6 +22,7 @@ import jetbrains.buildServer.agent.BuildProgressLogger;
 import jetbrains.buildServer.agent.BuildRunnerContext;\r
 import jetbrains.buildServer.nuget.agent.commands.NuGetActionFactory;\r
 import jetbrains.buildServer.nuget.agent.parameters.NuGetFetchParameters;\r
+import jetbrains.buildServer.nuget.agent.parameters.NuGetPublishParameters;\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
@@ -52,26 +53,20 @@ public class LoggingNuGetActionFactoryImpl implements NuGetActionFactory {
                                     @NotNull final File config,\r
                                     @NotNull final File targetFolder) {\r
     return new DelegatingBuildProcess(\r
-            new DelegatingBuildProcess.Action() {\r
-              private final BuildProgressLogger logger = context.getBuild().getBuildLogger();\r
-\r
+            new LoggingAction(context, config, "install") {\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("install", "Installing NuGet packages for " + pathToLog, "nuget");\r
-\r
-\r
+              @Override\r
+              protected BuildProcess delegateToActualAction() throws RunBuildException {\r
                 return myActionFactory.createInstall(\r
                         context,\r
                         params,\r
                         config,\r
-                        targetFolder)\r
-                        ;\r
+                        targetFolder);\r
               }\r
 \r
-              public void finishedImpl() {\r
-                logger.activityFinished("install", "nuget");\r
+              @Override\r
+              protected String getBlockDescription(@NotNull String pathToLog) {\r
+                return "Installing NuGet packages for " + pathToLog;\r
               }\r
             }\r
     );\r
@@ -83,28 +78,81 @@ public class LoggingNuGetActionFactoryImpl implements NuGetActionFactory {
                                    @NotNull final File config,\r
                                    @NotNull final File targetFolder) {\r
     return new DelegatingBuildProcess(\r
-            new DelegatingBuildProcess.Action() {\r
-              private final BuildProgressLogger logger = context.getBuild().getBuildLogger();\r
-\r
+            new LoggingAction(context, config, "update") {\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
+              @Override\r
+              protected BuildProcess delegateToActualAction() throws RunBuildException {\r
                 return myActionFactory.createUpdate(\r
                         context,\r
                         params,\r
                         config,\r
-                        targetFolder)\r
-                        ;\r
+                        targetFolder);\r
               }\r
 \r
-              public void finishedImpl() {\r
-                logger.activityFinished("update", "nuget");\r
+              @Override\r
+              protected String getBlockDescription(@NotNull String pathToLog) {\r
+                return "Updating NuGet packages for " + pathToLog;\r
               }\r
             }\r
     );\r
   }\r
 \r
+  @NotNull\r
+  public BuildProcess createPush(@NotNull BuildRunnerContext context,\r
+                                 @NotNull NuGetPublishParameters params,\r
+                                 @NotNull File packagePath) throws RunBuildException {\r
+    return new DelegatingBuildProcess(\r
+            new LoggingAction(context, packagePath, "push") {\r
+      @NotNull\r
+      @Override\r
+      protected BuildProcess delegateToActualAction() throws RunBuildException {\r
+        return null;\r
+      }\r
+\r
+      @Override\r
+      protected String getBlockDescription(@NotNull String pathToLog) {\r
+        return null;\r
+      }\r
+    });\r
+  }\r
+\r
+  private abstract class LoggingAction implements DelegatingBuildProcess.Action {\r
+    private final BuildRunnerContext myContext;\r
+    private final File myFileToLog;\r
+    private final String myBlockName;\r
+\r
+    protected LoggingAction(@NotNull final BuildRunnerContext context,\r
+                            @NotNull final File fileToLog,\r
+                            @NotNull final String blockName) {\r
+      myContext = context;\r
+      myFileToLog = fileToLog;\r
+      myBlockName = blockName;\r
+    }\r
+\r
+    @NotNull\r
+    protected abstract BuildProcess delegateToActualAction() throws RunBuildException;\r
+\r
+    protected abstract String getBlockDescription(@NotNull String pathToLog);\r
+\r
+\r
+    @NotNull\r
+    public BuildProcess startImpl() throws RunBuildException {\r
+      String pathToLog = FileUtil.getRelativePath(myContext.getBuild().getCheckoutDirectory(), myFileToLog);\r
+      if (pathToLog == null) pathToLog = myFileToLog.getPath();\r
+\r
+      getLogger().activityStarted(myBlockName, getBlockDescription(pathToLog), "nuget");\r
+\r
+      return delegateToActualAction();\r
+    }\r
+\r
+    @NotNull\r
+    private BuildProgressLogger getLogger() {\r
+      return myContext.getBuild().getBuildLogger();\r
+    }\r
+\r
+    public void finishedImpl() {\r
+      getLogger().activityFinished(myBlockName, "nuget");\r
+    }\r
+  }\r
+\r
 }\r
index 86747b081837c5ce3475eaac0373638bacc5426a..0df610d6dd3ed32240083cea49565e1d2283d83e 100644 (file)
@@ -16,7 +16,6 @@
 \r
 package jetbrains.buildServer.nuget.agent.commands.impl;\r
 \r
-import com.intellij.openapi.diagnostic.Logger;\r
 import jetbrains.buildServer.RunBuildException;\r
 import jetbrains.buildServer.agent.BuildFinishedStatus;\r
 import jetbrains.buildServer.agent.BuildProcess;\r
@@ -25,6 +24,7 @@ import jetbrains.buildServer.nuget.agent.commands.CommandFactory;
 import jetbrains.buildServer.nuget.agent.commands.NuGetActionFactory;\r
 import jetbrains.buildServer.nuget.agent.install.PackageUsages;\r
 import jetbrains.buildServer.nuget.agent.parameters.NuGetFetchParameters;\r
+import jetbrains.buildServer.nuget.agent.parameters.NuGetPublishParameters;\r
 import jetbrains.buildServer.nuget.agent.parameters.PackagesInstallParameters;\r
 import jetbrains.buildServer.nuget.agent.parameters.PackagesUpdateParameters;\r
 import jetbrains.buildServer.nuget.agent.util.BuildProcessBase;\r
@@ -98,4 +98,11 @@ public class NuGetActionFactoryImpl implements NuGetActionFactory {
       }\r
     };\r
   }\r
+\r
+  @NotNull\r
+  public BuildProcess createPush(@NotNull BuildRunnerContext context,\r
+                                 @NotNull NuGetPublishParameters params,\r
+                                 @NotNull File packagePath) throws RunBuildException {\r
+    return myCommandFactory.createPush(params, packagePath, getCallback(context));\r
+  }\r
 }\r
diff --git a/nuget-tests/src/jetbrains/buildServer/nuget/tests/agent/NuGetPushActoinFactoryTest.java b/nuget-tests/src/jetbrains/buildServer/nuget/tests/agent/NuGetPushActoinFactoryTest.java
new file mode 100644 (file)
index 0000000..782939b
--- /dev/null
@@ -0,0 +1,76 @@
+/*\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.commands.impl.CommandFactoryImpl;\r
+import jetbrains.buildServer.nuget.agent.commands.impl.NuGetActionFactoryImpl;\r
+import jetbrains.buildServer.nuget.agent.install.PackageUsages;\r
+import jetbrains.buildServer.nuget.agent.parameters.NuGetPublishParameters;\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.util.Arrays;\r
+\r
+/**\r
+ * Created by Eugene Petrenko (eugene.petrenko@gmail.com)\r
+ * Date: 21.07.11 16:46\r
+ */\r
+public class NuGetPushActoinFactoryTest extends BaseTestCase {\r
+  private Mockery m;\r
+  private CommandlineBuildProcessFactory myProcessFactory;\r
+  private NuGetActionFactoryImpl i;\r
+  private BuildRunnerContext ctx;\r
+  private NuGetPublishParameters ps;\r
+  private File myFile;\r
+  private File myNuGet;\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
+    PackageUsages pu = m.mock(PackageUsages.class);\r
+    i = new NuGetActionFactoryImpl(myProcessFactory, pu, new CommandFactoryImpl());\r
+    ctx = m.mock(BuildRunnerContext.class);\r
+    ps = m.mock(NuGetPublishParameters.class);\r
+\r
+    myFile = createTempFile();\r
+    myNuGet = createTempFile();\r
+  }\r
+\r
+  @Test\r
+  public void test_command_push() throws RunBuildException {\r
+    m.checking(new Expectations(){{\r
+      allowing(ps).getNuGetExeFile(); will(returnValue(myNuGet));\r
+      allowing(ps).getApiKey(); will(returnValue("api-key-guid"));\r
+      allowing(ps).getPublishSource(); will(returnValue("push-feed"));\r
+\r
+      oneOf(myProcessFactory).executeCommandLine(ctx, myNuGet, Arrays.asList(myFile.getPath(), "api-key-guid", "-Source", "push-feed"), myFile.getParentFile());\r
+    }});\r
+\r
+    i.createPush(ctx, ps, myFile);\r
+  }\r
+\r
+}\r
index 866a2b0ee6f12c19e93d8a9cd09ef1b67d5f329e..18b02138586d891c239347887ec4c392f53dbd14 100644 (file)
@@ -7,8 +7,10 @@
       <class name="jetbrains.buildServer.nuget.tests.agent.PackagesWatcherTest"/>\r
       <class name="jetbrains.buildServer.nuget.tests.agent.LocateNuGetConfigBuildProcessTest"/>\r
       <class name="jetbrains.buildServer.nuget.tests.agent.PackagesInstallerBuilderTest"/>\r
+\r
       <class name="jetbrains.buildServer.nuget.tests.agent.NuGetInstallPackageActionFactoryTest"/>\r
       <class name="jetbrains.buildServer.nuget.tests.agent.NuGetUpdatePackageActionFactoryTest"/>\r
+      <class name="jetbrains.buildServer.nuget.tests.agent.NuGetPushActoinFactoryTest"/>\r
 \r
       <class name="jetbrains.buildServer.nuget.tests.common.PackageDependenciesStoreTest"/>\r
 \r