From 8d56fa312858b711ae10d9ca393a1c8690bf3cc3 Mon Sep 17 00:00:00 2001 From: Steven Cooney Date: Tue, 4 Jun 2019 11:18:50 +0100 Subject: [PATCH] Initial Agent Plugin Setup We have added an agent side plugin which will be used to patch in the changes from a phabricator differential. We verify all the required settings are in place and enable the patching process after the repository have been cloned. Currently arcanist has been implemented to pull in the diff we are going to build upon that is the next step. --- .../phabricator/AgentBuildExtension.java | 77 +++++++++++++++++++ .../xlab/teamcity/phabricator/AppAgent.java | 4 - .../build-agent-plugin-phabricator-plugin.xml | 3 + 3 files changed, 80 insertions(+), 4 deletions(-) create mode 100644 Teamcity-Phabricator-Plugin/phabricator-plugin-agent/src/main/java/uk/xlab/teamcity/phabricator/AgentBuildExtension.java delete mode 100644 Teamcity-Phabricator-Plugin/phabricator-plugin-agent/src/main/java/uk/xlab/teamcity/phabricator/AppAgent.java diff --git a/Teamcity-Phabricator-Plugin/phabricator-plugin-agent/src/main/java/uk/xlab/teamcity/phabricator/AgentBuildExtension.java b/Teamcity-Phabricator-Plugin/phabricator-plugin-agent/src/main/java/uk/xlab/teamcity/phabricator/AgentBuildExtension.java new file mode 100644 index 0000000..36af74a --- /dev/null +++ b/Teamcity-Phabricator-Plugin/phabricator-plugin-agent/src/main/java/uk/xlab/teamcity/phabricator/AgentBuildExtension.java @@ -0,0 +1,77 @@ +package uk.xlab.teamcity.phabricator; + +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; + +import org.jetbrains.annotations.NotNull; + +import jetbrains.buildServer.agent.AgentBuildFeature; +import jetbrains.buildServer.agent.AgentLifeCycleAdapter; +import jetbrains.buildServer.agent.AgentLifeCycleListener; +import jetbrains.buildServer.agent.AgentRunningBuild; +import jetbrains.buildServer.agent.BuildProgressLogger; +import jetbrains.buildServer.util.EventDispatcher; + +public class AgentBuildExtension extends AgentLifeCycleAdapter { + + private PhabricatorAgentLogger agentLogLogger; + private BuildProgressLogger buildLogger; + private PhabricatorPluginConfig phabricatorConfig; + private boolean phabricatorTriggeredBuild = false; + + public AgentBuildExtension(@NotNull final EventDispatcher eventDispatcher, + @NotNull final PhabricatorAgentLogger phabLogger) { + eventDispatcher.addListener(this); + + agentLogLogger = phabLogger; + phabricatorConfig = new PhabricatorPluginConfig(); + phabricatorConfig.setLogger(agentLogLogger); + } + + @Override + public void buildStarted(@NotNull AgentRunningBuild runningBuild) { + // Setup logger to print to build output + buildLogger = runningBuild.getBuildLogger(); + + // Attempt to get the parameters set by the phabricator build feature. If non + // are set then the feature is not turned on. + Collection phabricatorBuildFeatureParameters = runningBuild + .getBuildFeaturesOfType(Constants.BUILD_FEATURE_TYPE); + + if (phabricatorBuildFeatureParameters.isEmpty()) { + return; + } + + // Check that the relevant build and phabricator settings/configurations are + // present + Map params = new HashMap<>(); + params.putAll(phabricatorBuildFeatureParameters.iterator().next().getParameters()); + params.putAll(runningBuild.getSharedConfigParameters()); + + // Setup plugin specific configuration + phabricatorConfig.setParameters(params); + + // Now we have set all the parameters we need to check if + // everything is present and correct for us to continue + if (!phabricatorConfig.isPluginSetup()) { + agentLogLogger.info("Plugin incorrectly configured"); + return; + } + + phabricatorTriggeredBuild = true; + agentLogLogger.info("Plugin ready"); + buildLogger.message("Phabricator Plugin - Active"); + } + + @Override + public void sourcesUpdated(@NotNull AgentRunningBuild runningBuild) { + + if (!phabricatorTriggeredBuild) { + return; + } + + buildLogger.message("PHAB: SOURCES HAVE UPDATED"); + agentLogLogger.info("PHAB: SOURCES HAVE UPDATED"); + } +} diff --git a/Teamcity-Phabricator-Plugin/phabricator-plugin-agent/src/main/java/uk/xlab/teamcity/phabricator/AppAgent.java b/Teamcity-Phabricator-Plugin/phabricator-plugin-agent/src/main/java/uk/xlab/teamcity/phabricator/AppAgent.java deleted file mode 100644 index cdc3e72..0000000 --- a/Teamcity-Phabricator-Plugin/phabricator-plugin-agent/src/main/java/uk/xlab/teamcity/phabricator/AppAgent.java +++ /dev/null @@ -1,4 +0,0 @@ -package uk.xlab.teamcity.phabricator; - -public class AppAgent { -} diff --git a/Teamcity-Phabricator-Plugin/phabricator-plugin-agent/src/main/resources/META-INF/build-agent-plugin-phabricator-plugin.xml b/Teamcity-Phabricator-Plugin/phabricator-plugin-agent/src/main/resources/META-INF/build-agent-plugin-phabricator-plugin.xml index 11265f2..8acecf4 100644 --- a/Teamcity-Phabricator-Plugin/phabricator-plugin-agent/src/main/resources/META-INF/build-agent-plugin-phabricator-plugin.xml +++ b/Teamcity-Phabricator-Plugin/phabricator-plugin-agent/src/main/resources/META-INF/build-agent-plugin-phabricator-plugin.xml @@ -4,4 +4,7 @@ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd" default-autowire="constructor"> + + +