From 6c932b6cb9038f806bcfadea7d7429768954b697 Mon Sep 17 00:00:00 2001 From: delarea Date: Mon, 27 May 2024 18:03:54 +0300 Subject: [PATCH 1/4] Split postbuildactions by agent type --- pom.xml | 2 +- ...dAction.java => AgentPostBuildAction.java} | 15 +++--- .../jfrog/bamboo/ServerPostBuildAction.java | 53 +++++++++++++++++++ .../org/jfrog/bamboo/utils/BambooUtils.java | 7 +++ src/main/resources/atlassian-plugin.xml | 16 ++++-- 5 files changed, 82 insertions(+), 11 deletions(-) rename src/main/java/org/jfrog/bamboo/{PostBuildAction.java => AgentPostBuildAction.java} (72%) create mode 100644 src/main/java/org/jfrog/bamboo/ServerPostBuildAction.java diff --git a/pom.xml b/pom.xml index a344142..110c1a4 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ 4.0.0 org.jfrog.bamboo bamboo-jfrog-plugin - 1.0.3 + 1.0.4 JFrog Ltd diff --git a/src/main/java/org/jfrog/bamboo/PostBuildAction.java b/src/main/java/org/jfrog/bamboo/AgentPostBuildAction.java similarity index 72% rename from src/main/java/org/jfrog/bamboo/PostBuildAction.java rename to src/main/java/org/jfrog/bamboo/AgentPostBuildAction.java index 2444ed0..f2e7bd9 100644 --- a/src/main/java/org/jfrog/bamboo/PostBuildAction.java +++ b/src/main/java/org/jfrog/bamboo/AgentPostBuildAction.java @@ -1,15 +1,20 @@ package org.jfrog.bamboo; -import com.atlassian.bamboo.build.CustomPostBuildCompletedAction; +import com.atlassian.bamboo.build.CustomBuildProcessor; import com.atlassian.bamboo.v2.build.BuildContext; import com.atlassian.bamboo.variable.CustomVariableContext; -import org.codehaus.plexus.util.FileUtils; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.jetbrains.annotations.NotNull; import org.jfrog.bamboo.utils.BambooUtils; import java.io.IOException; -public class PostBuildAction implements CustomPostBuildCompletedAction { +/** + * Post-build action that deletes the Bamboo temp directory. + * Implements CustomBuildProcessor to run on the agent that is running the build. + */ +public class AgentPostBuildAction implements CustomBuildProcessor { private BuildContext buildContext; private CustomVariableContext customVariableContext; @@ -31,9 +36,7 @@ public void init(final @NotNull BuildContext buildContext) { */ @Override public @NotNull BuildContext call() throws IOException { - // Delete Bamboo temp directory - String fullBuildKey = buildContext.getResultKey().getKey(); - FileUtils.deleteDirectory(BambooUtils.getJfrogTmpSubdir(customVariableContext, fullBuildKey)); + BambooUtils.DeleteJFrogTempDir(this.buildContext, this.customVariableContext); return buildContext; } diff --git a/src/main/java/org/jfrog/bamboo/ServerPostBuildAction.java b/src/main/java/org/jfrog/bamboo/ServerPostBuildAction.java new file mode 100644 index 0000000..9389e75 --- /dev/null +++ b/src/main/java/org/jfrog/bamboo/ServerPostBuildAction.java @@ -0,0 +1,53 @@ +package org.jfrog.bamboo; + +import com.atlassian.bamboo.build.CustomBuildProcessorServer; +import com.atlassian.bamboo.v2.build.BuildContext; +import com.atlassian.bamboo.variable.CustomVariableContext; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.jetbrains.annotations.NotNull; +import org.jfrog.bamboo.utils.BambooUtils; + +import java.io.IOException; + +/** + * Post-build action that deletes the Bamboo temp directory. + * Implements CustomBuildProcessorServer to run on the server + * To make sure we have permissions and access to the temp folder we created. + */ +public class ServerPostBuildAction implements CustomBuildProcessorServer { + private BuildContext buildContext; + private CustomVariableContext customVariableContext; + + /** + * Initializes the post-build action with the build context. + * + * @param buildContext The build context. + */ + @Override + public void init(final @NotNull BuildContext buildContext) { + this.buildContext = buildContext; + } + + /** + * Performs the post-build action. + * + * @return The modified build context. + * @throws IOException If an I/O error occurs. + */ + @Override + public @NotNull BuildContext call() throws IOException { + BambooUtils.DeleteJFrogTempDir(this.buildContext, this.customVariableContext); + return buildContext; + } + + /** + * Sets the custom variable context. + * + * @param customVariableContext The custom variable context. + */ + @SuppressWarnings("unused") + public void setCustomVariableContext(CustomVariableContext customVariableContext) { + this.customVariableContext = customVariableContext; + } +} diff --git a/src/main/java/org/jfrog/bamboo/utils/BambooUtils.java b/src/main/java/org/jfrog/bamboo/utils/BambooUtils.java index 4827203..f40ff54 100644 --- a/src/main/java/org/jfrog/bamboo/utils/BambooUtils.java +++ b/src/main/java/org/jfrog/bamboo/utils/BambooUtils.java @@ -3,9 +3,11 @@ import com.atlassian.bamboo.configuration.AdministrationConfiguration; import com.atlassian.bamboo.configuration.AdministrationConfigurationAccessor; import com.atlassian.bamboo.utils.EscapeChars; +import com.atlassian.bamboo.v2.build.BuildContext; import com.atlassian.bamboo.variable.CustomVariableContext; import com.atlassian.plugin.Plugin; import com.atlassian.plugin.PluginAccessor; +import org.codehaus.plexus.util.FileUtils; import java.io.IOException; import java.nio.file.Files; @@ -85,4 +87,9 @@ public static String createBambooBuildUrl(String fullBuildKey, AdministrationCon } return summaryUrl.append("browse/").append(EscapeChars.forFormSubmission(fullBuildKey)).toString(); } + + public static void DeleteJFrogTempDir(BuildContext buildContext, CustomVariableContext customVariableContext) throws IOException { + String fullBuildKey = buildContext.getResultKey().getKey(); + FileUtils.deleteDirectory(BambooUtils.getJfrogTmpSubdir(customVariableContext, fullBuildKey)); + } } diff --git a/src/main/resources/atlassian-plugin.xml b/src/main/resources/atlassian-plugin.xml index 7139778..eef4461 100644 --- a/src/main/resources/atlassian-plugin.xml +++ b/src/main/resources/atlassian-plugin.xml @@ -17,11 +17,19 @@ - + + + Cleans up the temporary JFrog directory when the build is completed - + + + + Cleans up the temporary JFrog directory when the build is completed + Date: Mon, 27 May 2024 18:20:00 +0300 Subject: [PATCH 2/4] Update --- ...ldAction.java => AgentBuildProcessor.java} | 13 ++--- .../jfrog/bamboo/ServerPostBuildAction.java | 53 ------------------- .../org/jfrog/bamboo/utils/BambooUtils.java | 5 -- src/main/resources/atlassian-plugin.xml | 11 +--- 4 files changed, 9 insertions(+), 73 deletions(-) rename src/main/java/org/jfrog/bamboo/{AgentPostBuildAction.java => AgentBuildProcessor.java} (73%) delete mode 100644 src/main/java/org/jfrog/bamboo/ServerPostBuildAction.java diff --git a/src/main/java/org/jfrog/bamboo/AgentPostBuildAction.java b/src/main/java/org/jfrog/bamboo/AgentBuildProcessor.java similarity index 73% rename from src/main/java/org/jfrog/bamboo/AgentPostBuildAction.java rename to src/main/java/org/jfrog/bamboo/AgentBuildProcessor.java index f2e7bd9..a443a15 100644 --- a/src/main/java/org/jfrog/bamboo/AgentPostBuildAction.java +++ b/src/main/java/org/jfrog/bamboo/AgentBuildProcessor.java @@ -3,18 +3,18 @@ import com.atlassian.bamboo.build.CustomBuildProcessor; import com.atlassian.bamboo.v2.build.BuildContext; import com.atlassian.bamboo.variable.CustomVariableContext; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; +import org.codehaus.plexus.util.FileUtils; import org.jetbrains.annotations.NotNull; import org.jfrog.bamboo.utils.BambooUtils; import java.io.IOException; /** - * Post-build action that deletes the Bamboo temp directory. - * Implements CustomBuildProcessor to run on the agent that is running the build. + * Post-build action that deletes the temporary JFrog build directory, + * executed on the agent side (remote or local) to make sure we have + * access to the temp folder we created. */ -public class AgentPostBuildAction implements CustomBuildProcessor { +public class AgentBuildProcessor implements CustomBuildProcessor { private BuildContext buildContext; private CustomVariableContext customVariableContext; @@ -36,7 +36,8 @@ public void init(final @NotNull BuildContext buildContext) { */ @Override public @NotNull BuildContext call() throws IOException { - BambooUtils.DeleteJFrogTempDir(this.buildContext, this.customVariableContext); + String fullBuildKey = buildContext.getResultKey().getKey(); + FileUtils.deleteDirectory(BambooUtils.getJfrogTmpSubdir(customVariableContext, fullBuildKey)); return buildContext; } diff --git a/src/main/java/org/jfrog/bamboo/ServerPostBuildAction.java b/src/main/java/org/jfrog/bamboo/ServerPostBuildAction.java deleted file mode 100644 index 9389e75..0000000 --- a/src/main/java/org/jfrog/bamboo/ServerPostBuildAction.java +++ /dev/null @@ -1,53 +0,0 @@ -package org.jfrog.bamboo; - -import com.atlassian.bamboo.build.CustomBuildProcessorServer; -import com.atlassian.bamboo.v2.build.BuildContext; -import com.atlassian.bamboo.variable.CustomVariableContext; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; -import org.jetbrains.annotations.NotNull; -import org.jfrog.bamboo.utils.BambooUtils; - -import java.io.IOException; - -/** - * Post-build action that deletes the Bamboo temp directory. - * Implements CustomBuildProcessorServer to run on the server - * To make sure we have permissions and access to the temp folder we created. - */ -public class ServerPostBuildAction implements CustomBuildProcessorServer { - private BuildContext buildContext; - private CustomVariableContext customVariableContext; - - /** - * Initializes the post-build action with the build context. - * - * @param buildContext The build context. - */ - @Override - public void init(final @NotNull BuildContext buildContext) { - this.buildContext = buildContext; - } - - /** - * Performs the post-build action. - * - * @return The modified build context. - * @throws IOException If an I/O error occurs. - */ - @Override - public @NotNull BuildContext call() throws IOException { - BambooUtils.DeleteJFrogTempDir(this.buildContext, this.customVariableContext); - return buildContext; - } - - /** - * Sets the custom variable context. - * - * @param customVariableContext The custom variable context. - */ - @SuppressWarnings("unused") - public void setCustomVariableContext(CustomVariableContext customVariableContext) { - this.customVariableContext = customVariableContext; - } -} diff --git a/src/main/java/org/jfrog/bamboo/utils/BambooUtils.java b/src/main/java/org/jfrog/bamboo/utils/BambooUtils.java index f40ff54..af76929 100644 --- a/src/main/java/org/jfrog/bamboo/utils/BambooUtils.java +++ b/src/main/java/org/jfrog/bamboo/utils/BambooUtils.java @@ -87,9 +87,4 @@ public static String createBambooBuildUrl(String fullBuildKey, AdministrationCon } return summaryUrl.append("browse/").append(EscapeChars.forFormSubmission(fullBuildKey)).toString(); } - - public static void DeleteJFrogTempDir(BuildContext buildContext, CustomVariableContext customVariableContext) throws IOException { - String fullBuildKey = buildContext.getResultKey().getKey(); - FileUtils.deleteDirectory(BambooUtils.getJfrogTmpSubdir(customVariableContext, fullBuildKey)); - } } diff --git a/src/main/resources/atlassian-plugin.xml b/src/main/resources/atlassian-plugin.xml index eef4461..36b741b 100644 --- a/src/main/resources/atlassian-plugin.xml +++ b/src/main/resources/atlassian-plugin.xml @@ -17,19 +17,12 @@ - - + + class="org.jfrog.bamboo.AgentBuildProcessor"> Cleans up the temporary JFrog directory when the build is completed - - - Cleans up the temporary JFrog directory when the build is completed - Date: Mon, 27 May 2024 18:21:51 +0300 Subject: [PATCH 3/4] Fix diffs --- pom.xml | 2 +- src/main/java/org/jfrog/bamboo/AgentBuildProcessor.java | 1 + src/main/java/org/jfrog/bamboo/utils/BambooUtils.java | 2 -- 3 files changed, 2 insertions(+), 3 deletions(-) diff --git a/pom.xml b/pom.xml index 110c1a4..a344142 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ 4.0.0 org.jfrog.bamboo bamboo-jfrog-plugin - 1.0.4 + 1.0.3 JFrog Ltd diff --git a/src/main/java/org/jfrog/bamboo/AgentBuildProcessor.java b/src/main/java/org/jfrog/bamboo/AgentBuildProcessor.java index a443a15..3a304c3 100644 --- a/src/main/java/org/jfrog/bamboo/AgentBuildProcessor.java +++ b/src/main/java/org/jfrog/bamboo/AgentBuildProcessor.java @@ -36,6 +36,7 @@ public void init(final @NotNull BuildContext buildContext) { */ @Override public @NotNull BuildContext call() throws IOException { + // Delete Bamboo temp directory String fullBuildKey = buildContext.getResultKey().getKey(); FileUtils.deleteDirectory(BambooUtils.getJfrogTmpSubdir(customVariableContext, fullBuildKey)); return buildContext; diff --git a/src/main/java/org/jfrog/bamboo/utils/BambooUtils.java b/src/main/java/org/jfrog/bamboo/utils/BambooUtils.java index af76929..4827203 100644 --- a/src/main/java/org/jfrog/bamboo/utils/BambooUtils.java +++ b/src/main/java/org/jfrog/bamboo/utils/BambooUtils.java @@ -3,11 +3,9 @@ import com.atlassian.bamboo.configuration.AdministrationConfiguration; import com.atlassian.bamboo.configuration.AdministrationConfigurationAccessor; import com.atlassian.bamboo.utils.EscapeChars; -import com.atlassian.bamboo.v2.build.BuildContext; import com.atlassian.bamboo.variable.CustomVariableContext; import com.atlassian.plugin.Plugin; import com.atlassian.plugin.PluginAccessor; -import org.codehaus.plexus.util.FileUtils; import java.io.IOException; import java.nio.file.Files; From 010a1c3704ebdc8873c1b7f4c20ea9b7f55c1748 Mon Sep 17 00:00:00 2001 From: delarea Date: Mon, 27 May 2024 18:48:26 +0300 Subject: [PATCH 4/4] Update deps --- pom.xml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pom.xml b/pom.xml index a344142..1ee2f23 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ 4.0.0 org.jfrog.bamboo bamboo-jfrog-plugin - 1.0.3 + 1.0.4 JFrog Ltd @@ -30,7 +30,7 @@ atlassian-plugin - 9.3.3 + 9.6.2 ${bamboo.version} 8.11.4 3.0.3 @@ -41,7 +41,7 @@ ${java.version} ${java.version} - 2.41.6 + 2.41.16 @@ -106,7 +106,7 @@ org.jfrog.artifactory.client artifactory-java-client-api - 2.14.0 + 2.17.0 test