introduce DelegatingBuildProcess, avoid exception from listener on LocateNuGetConfigB...
authorEugene.Petrenko <eugene.petrenko@gmail.com>
Thu, 7 Jul 2011 15:01:49 +0000 (19:01 +0400)
committerEugene.Petrenko <eugene.petrenko@gmail.com>
Thu, 7 Jul 2011 15:01:49 +0000 (19:01 +0400)
nuget-agent/src/jetbrains/buildServer/nuget/agent/install/LocateNuGetConfigBuildProcess.java
nuget-agent/src/jetbrains/buildServer/nuget/agent/install/PackagesInstallerRunner.java
nuget-agent/src/jetbrains/buildServer/nuget/agent/util/DelegatingBuildProcess.java [new file with mode: 0644]

index 75370b2d2fb65cd753f5a56477dc970d5e2609f3..a230c622eea9df8d33a971c70bdc31960ddbccf8 100644 (file)
@@ -57,9 +57,8 @@ public class LocateNuGetConfigBuildProcess extends BuildProcessBase {
      * Called when packages.config is found\r
      * @param config full path to packages.config file\r
      * @param targetFolder target folder to store packages\r
-     * @throws jetbrains.buildServer.RunBuildException if failed to process callback\r
      */\r
-    void onPackagesConfigFound(@NotNull final File config, @NotNull final File targetFolder) throws RunBuildException;\r
+    void onPackagesConfigFound(@NotNull final File config, @NotNull final File targetFolder);\r
   }\r
 \r
   @Override\r
index cd5c3ee630637930e5a2d371dce359b203a0c98e..7d11d07973389c73f0193a4fc9f4a55e224609a8 100644 (file)
@@ -19,6 +19,7 @@ package jetbrains.buildServer.nuget.agent.install;
 import com.intellij.openapi.diagnostic.Logger;\r
 import jetbrains.buildServer.RunBuildException;\r
 import jetbrains.buildServer.agent.*;\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.PackagesInstallerConstants;\r
@@ -64,13 +65,29 @@ public class PackagesInstallerRunner implements AgentBuildRunner, AgentBuildRunn
                                         @NotNull final CompositeBuildProcessImpl process,\r
                                         @NotNull final PackagesInstallParameters parameters) {\r
     return new Callback() {\r
-      public void onPackagesConfigFound(@NotNull File config,\r
-                                        @NotNull File targetFolder) throws RunBuildException {\r
+      public void onPackagesConfigFound(@NotNull final File config,\r
+                                        @NotNull final File targetFolder) {\r
         process.pushBuildProcess(\r
-                myInstallActionFactory.createBuildProcess(context,\r
-                        parameters,\r
-                        config,\r
-                        targetFolder)\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
+                            logger.activityStarted("install", "Installing NuGet packages for " + config, "nuget");\r
+\r
+                            return myInstallActionFactory.createBuildProcess(context,\r
+                                    parameters,\r
+                                    config,\r
+                                    targetFolder)\r
+                                    ;\r
+                          }\r
+\r
+                          public void finishedImpl() {\r
+                            logger.activityFinished("install", "nuget");\r
+                          }\r
+                        }\r
+                )\r
         );\r
       }\r
     };\r
diff --git a/nuget-agent/src/jetbrains/buildServer/nuget/agent/util/DelegatingBuildProcess.java b/nuget-agent/src/jetbrains/buildServer/nuget/agent/util/DelegatingBuildProcess.java
new file mode 100644 (file)
index 0000000..9e9060e
--- /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.agent.util;\r
+\r
+import jetbrains.buildServer.RunBuildException;\r
+import jetbrains.buildServer.agent.BuildFinishedStatus;\r
+import jetbrains.buildServer.agent.BuildProcess;\r
+import org.jetbrains.annotations.NotNull;\r
+\r
+import java.util.concurrent.atomic.AtomicReference;\r
+\r
+/**\r
+ * Created by Eugene Petrenko (eugene.petrenko@gmail.com)\r
+ * Date: 07.07.11 18:41\r
+ */\r
+public class DelegatingBuildProcess extends BuildProcessBase {\r
+  private final AtomicReference<BuildProcess> myReference = new AtomicReference<BuildProcess>();\r
+  private final Action myAction;\r
+\r
+  public DelegatingBuildProcess(@NotNull final Action action) {\r
+    myAction = action;\r
+  }\r
+\r
+  @Override\r
+  public final void start() throws RunBuildException {\r
+    super.start();\r
+    if (isInterrupted()) return;\r
+\r
+    myReference.set(myAction.startImpl());\r
+  }\r
+\r
+  @Override\r
+  protected final void interruptImpl() {\r
+    super.interruptImpl();\r
+    BuildProcess process = myReference.get();\r
+    if (process != null) process.interrupt();\r
+  }\r
+\r
+  @Override\r
+  protected final BuildFinishedStatus waitForImpl() throws RunBuildException {\r
+    BuildProcess process = myReference.get();\r
+    if (isInterrupted()) return BuildFinishedStatus.INTERRUPTED;\r
+\r
+    try {\r
+      if (process != null) {\r
+        process.start();\r
+        return process.waitFor();\r
+      }\r
+    } finally {\r
+      myAction.finishedImpl();\r
+    }\r
+\r
+    if (isInterrupted()) return BuildFinishedStatus.INTERRUPTED;\r
+    return BuildFinishedStatus.FINISHED_SUCCESS;\r
+  }\r
+\r
+  public static interface Action {\r
+    @NotNull\r
+    BuildProcess startImpl() throws RunBuildException;\r
+    void finishedImpl();\r
+  }\r
+}\r