implement agent-side of publish changes runner
authorEugene Petrenko <eugene.petrenko@gmail.com>
Thu, 21 Jul 2011 16:13:30 +0000 (20:13 +0400)
committerEugene Petrenko <eugene.petrenko@gmail.com>
Thu, 21 Jul 2011 16:13:30 +0000 (20:13 +0400)
nuget-agent/src/META-INF/build-agent-plugin-nuget.xml
nuget-agent/src/jetbrains/buildServer/nuget/agent/publish/MatchFilesBuildProcess.java [new file with mode: 0644]
nuget-agent/src/jetbrains/buildServer/nuget/agent/publish/PackagesPublishRunner.java [new file with mode: 0644]
nuget-agent/src/jetbrains/buildServer/nuget/agent/publish/PackagesPublishRunnerRegistrar.java [moved from nuget-agent/src/jetbrains/buildServer/nuget/agent/publish/PublishService.java with 63% similarity]
nuget-agent/src/jetbrains/buildServer/nuget/agent/publish/PublishCommandlineBuildServiceFactory.java [deleted file]

index a6dd5d3cc2e1a30dbf503bffb8c2f3f263587ee6..813e425a3b96911f52c3df63964dc18d98bd584c 100644 (file)
@@ -13,6 +13,9 @@
   <bean class="jetbrains.buildServer.nuget.agent.install.PackagesInstallerRunner"/>\r
   <bean class="jetbrains.buildServer.nuget.agent.install.PackagesInstallerRunnerRegistrar"/>\r
 \r
+  <bean class="jetbrains.buildServer.nuget.agent.publish.PackagesPublishRunner"/>\r
+  <bean class="jetbrains.buildServer.nuget.agent.publish.PackagesPublishRunnerRegistrar"/>\r
+\r
   <bean class="jetbrains.buildServer.nuget.agent.commands.impl.CommandFactoryImpl"/>\r
   <bean class="jetbrains.buildServer.nuget.agent.commands.impl.LoggingNuGetActionFactoryImpl">\r
     <constructor-arg>\r
diff --git a/nuget-agent/src/jetbrains/buildServer/nuget/agent/publish/MatchFilesBuildProcess.java b/nuget-agent/src/jetbrains/buildServer/nuget/agent/publish/MatchFilesBuildProcess.java
new file mode 100644 (file)
index 0000000..4598f0a
--- /dev/null
@@ -0,0 +1,84 @@
+/*\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.publish;\r
+\r
+import com.intellij.openapi.diagnostic.Logger;\r
+import com.intellij.openapi.util.SystemInfo;\r
+import jetbrains.buildServer.RunBuildException;\r
+import jetbrains.buildServer.agent.BuildFinishedStatus;\r
+import jetbrains.buildServer.agent.BuildRunnerContext;\r
+import jetbrains.buildServer.agent.util.AntPatternFileFinder;\r
+import jetbrains.buildServer.nuget.agent.parameters.NuGetPublishParameters;\r
+import jetbrains.buildServer.nuget.agent.util.BuildProcessBase;\r
+import org.jetbrains.annotations.NotNull;\r
+\r
+import java.io.File;\r
+import java.io.IOException;\r
+import java.util.Collection;\r
+\r
+/**\r
+ * Created by Eugene Petrenko (eugene.petrenko@gmail.com)\r
+ * Date: 21.07.11 20:02\r
+ */\r
+public class MatchFilesBuildProcess extends BuildProcessBase {\r
+  private static final Logger LOG = Logger.getInstance(MatchFilesBuildProcess.class.getName());\r
+\r
+  private final BuildRunnerContext myContext;\r
+  private final NuGetPublishParameters myParameters;\r
+  private final Callback myCallback;\r
+\r
+  public MatchFilesBuildProcess(@NotNull final BuildRunnerContext context,\r
+                                @NotNull final NuGetPublishParameters parameters,\r
+                                @NotNull final Callback callback) {\r
+    myContext = context;\r
+    myParameters = parameters;\r
+    myCallback = callback;\r
+  }\r
+\r
+  @NotNull\r
+  @Override\r
+  protected BuildFinishedStatus waitForImpl() throws RunBuildException {\r
+    final Collection<String> files = myParameters.getFiles();\r
+    final String[] includes = files.toArray(new String[files.size()]);\r
+    AntPatternFileFinder finder = new AntPatternFileFinder(\r
+            includes,\r
+            new String[0],\r
+            SystemInfo.isFileSystemCaseSensitive\r
+    );\r
+\r
+    try {\r
+      final File root = myContext.getBuild().getCheckoutDirectory();\r
+      final File[] result = finder.findFiles(root);\r
+      if (result.length == 0) {\r
+        throw new RunBuildException("Failed to find files to push mathing: " + files + " under " + root + ". No packages to publish. ");\r
+      }\r
+\r
+      for (File file : result) {\r
+        LOG.debug("Found nugkg to push: " + file);\r
+        myCallback.fileFound(file);\r
+      }\r
+    } catch (IOException e) {\r
+      throw new RunBuildException("Failed to find packages to push. " + e.getMessage(), e);\r
+    }\r
+\r
+    return BuildFinishedStatus.FINISHED_SUCCESS;\r
+  }\r
+\r
+  public static interface Callback {\r
+    void fileFound(@NotNull final File file) throws RunBuildException;\r
+  }\r
+}\r
diff --git a/nuget-agent/src/jetbrains/buildServer/nuget/agent/publish/PackagesPublishRunner.java b/nuget-agent/src/jetbrains/buildServer/nuget/agent/publish/PackagesPublishRunner.java
new file mode 100644 (file)
index 0000000..59d928c
--- /dev/null
@@ -0,0 +1,89 @@
+/*\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.publish;\r
+\r
+import com.intellij.openapi.diagnostic.Logger;\r
+import jetbrains.buildServer.RunBuildException;\r
+import jetbrains.buildServer.agent.*;\r
+import jetbrains.buildServer.nuget.agent.commands.NuGetActionFactory;\r
+import jetbrains.buildServer.nuget.agent.parameters.NuGetPublishParameters;\r
+import jetbrains.buildServer.nuget.agent.parameters.PackagesParametersFactory;\r
+import jetbrains.buildServer.nuget.agent.util.CompositeBuildProcess;\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 org.jetbrains.annotations.NotNull;\r
+\r
+import java.io.File;\r
+\r
+/**\r
+ * Created by Eugene Petrenko (eugene.petrenko@gmail.com)\r
+ * Date: 21.07.11 15:15\r
+ */\r
+public class PackagesPublishRunner implements AgentBuildRunner, AgentBuildRunnerInfo {\r
+  private static final Logger LOG = Logger.getInstance(PackagesPublishRunner.class.getName());\r
+\r
+  private final NuGetActionFactory myActionFactory;\r
+  private final PackagesParametersFactory myParametersFactory;\r
+\r
+  public PackagesPublishRunner(@NotNull final NuGetActionFactory actionFactory,\r
+                               @NotNull final PackagesParametersFactory parametersFactory) {\r
+    myActionFactory = actionFactory;\r
+    myParametersFactory = parametersFactory;\r
+  }\r
+\r
+  @NotNull\r
+  public BuildProcess createBuildProcess(@NotNull final AgentRunningBuild runningBuild,\r
+                                         @NotNull final BuildRunnerContext context) throws RunBuildException {\r
+    final CompositeBuildProcess process = new CompositeBuildProcessImpl();\r
+    final NuGetPublishParameters params = myParametersFactory.loadPublishParameters(context);\r
+\r
+    process.pushBuildProcess(new MatchFilesBuildProcess(context, params, new MatchFilesBuildProcess.Callback() {\r
+      public void fileFound(@NotNull File file) throws RunBuildException {\r
+        process.pushBuildProcess(\r
+                myActionFactory.createPush(context, params, file)\r
+        );\r
+      }\r
+    }));\r
+\r
+    return process;\r
+  }\r
+\r
+  @NotNull\r
+  public AgentBuildRunnerInfo getRunnerInfo() {\r
+    return this;\r
+  }\r
+\r
+  @NotNull\r
+  public String getType() {\r
+    return PackagesConstants.PUBLISH_RUN_TYPE;\r
+  }\r
+\r
+  public boolean canRun(@NotNull BuildAgentConfiguration agentConfiguration) {\r
+    if (!agentConfiguration.getSystemInfo().isWindows()) {\r
+      LOG.warn("NuGet packages installer available only under windows");\r
+      return false;\r
+    }\r
+\r
+    if (!agentConfiguration.getConfigurationParameters().containsKey(DotNetConstants.DOT_NET_FRAMEWORK_4_x86)) {\r
+      LOG.warn("NuGet requires .NET Framework 4.0 x86 installed");\r
+      return false;\r
+    }\r
+\r
+    return true;\r
+  }\r
+}
\ No newline at end of file
similarity index 63%
rename from nuget-agent/src/jetbrains/buildServer/nuget/agent/publish/PublishService.java
rename to nuget-agent/src/jetbrains/buildServer/nuget/agent/publish/PackagesPublishRunnerRegistrar.java
index cea1d7af2584fc76d79d6e111698a0ce4a7a9738..ec28556890b30d45f925f168c18e93e85b7b4877 100644 (file)
 \r
 package jetbrains.buildServer.nuget.agent.publish;\r
 \r
-import jetbrains.buildServer.RunBuildException;\r
-import jetbrains.buildServer.agent.runner.BuildServiceAdapter;\r
-import jetbrains.buildServer.agent.runner.ProgramCommandLine;\r
+import jetbrains.buildServer.agent.impl.BuildRunnerRegistry;\r
 import org.jetbrains.annotations.NotNull;\r
 \r
 /**\r
  * Created by Eugene Petrenko (eugene.petrenko@gmail.com)\r
- * Date: 21.07.11 15:17\r
+ * Date: 21.07.11 20:00\r
  */\r
-public class PublishService extends BuildServiceAdapter {\r
-  @NotNull\r
-  @Override\r
-  public ProgramCommandLine makeProgramCommandLine() throws RunBuildException {\r
-    throw new RunBuildException("Not implemented");\r
+public class PackagesPublishRunnerRegistrar {\r
+  public PackagesPublishRunnerRegistrar(@NotNull final BuildRunnerRegistry reg,\r
+                                        @NotNull final PackagesPublishRunner runner) {\r
+    reg.registerRunner(runner);\r
   }\r
 }\r
diff --git a/nuget-agent/src/jetbrains/buildServer/nuget/agent/publish/PublishCommandlineBuildServiceFactory.java b/nuget-agent/src/jetbrains/buildServer/nuget/agent/publish/PublishCommandlineBuildServiceFactory.java
deleted file mode 100644 (file)
index 4e631b7..0000000
+++ /dev/null
@@ -1,62 +0,0 @@
-/*\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.publish;\r
-\r
-import com.intellij.openapi.diagnostic.Logger;\r
-import jetbrains.buildServer.agent.AgentBuildRunnerInfo;\r
-import jetbrains.buildServer.agent.BuildAgentConfiguration;\r
-import jetbrains.buildServer.agent.runner.CommandLineBuildService;\r
-import jetbrains.buildServer.agent.runner.CommandLineBuildServiceFactory;\r
-import jetbrains.buildServer.nuget.common.DotNetConstants;\r
-import jetbrains.buildServer.nuget.common.PackagesConstants;\r
-import org.jetbrains.annotations.NotNull;\r
-\r
-/**\r
- * Created by Eugene Petrenko (eugene.petrenko@gmail.com)\r
- * Date: 21.07.11 15:15\r
- */\r
-public class PublishCommandlineBuildServiceFactory implements CommandLineBuildServiceFactory, AgentBuildRunnerInfo {\r
-  private static final Logger LOG = Logger.getInstance(PublishCommandlineBuildServiceFactory.class.getName());\r
-  @NotNull\r
-  public CommandLineBuildService createService() {\r
-    return new PublishService();\r
-  }\r
-\r
-  @NotNull\r
-  public AgentBuildRunnerInfo getBuildRunnerInfo() {\r
-    return this;\r
-  }\r
-\r
-  @NotNull\r
-  public String getType() {\r
-    return PackagesConstants.PUBLISH_RUN_TYPE;\r
-  }\r
-\r
-  public boolean canRun(@NotNull BuildAgentConfiguration agentConfiguration) {\r
-    if (!agentConfiguration.getSystemInfo().isWindows()) {\r
-      LOG.warn("NuGet packages installer available only under windows");\r
-      return false;\r
-    }\r
-\r
-    if (!agentConfiguration.getConfigurationParameters().containsKey(DotNetConstants.DOT_NET_FRAMEWORK_4_x86)) {\r
-      LOG.warn("NuGet requires .NET Framework 4.0 x86 installed");\r
-      return false;\r
-    }\r
-\r
-    return true;\r
-  }\r
-}
\ No newline at end of file