Skip to content

Commit

Permalink
JENKINS-70032 : Make maven-plugin an optional dependency
Browse files Browse the repository at this point in the history
(Resolve SpotBugs warnings about NPE)
  • Loading branch information
aah9 committed Apr 4, 2023
1 parent be96def commit 96921e6
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/main/java/hudson/plugins/s3/S3CopyArtifact.java
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,11 @@ private void setResult(@Nonnull Run<?, ?> run, boolean isOk) {
else
run.setResult(Result.FAILURE);
}

private static boolean isMavenPluginInstalled() {
Jenkins instance = Jenkins.getInstanceOrNull();
return instance != null && instance.getPlugin("maven-plugin") != null;
}

@Override
public void perform(@Nonnull Run<?, ?> dst, @Nonnull FilePath targetDir, @Nonnull Launcher launcher, @Nonnull TaskListener listener) throws InterruptedException, IOException {
Expand Down Expand Up @@ -217,7 +222,7 @@ public void perform(@Nonnull Run<?, ?> dst, @Nonnull FilePath targetDir, @Nonnul

excludeFilter = env.expand(excludeFilter);

if (Jenkins.getInstanceOrNull().getPlugin("maven-plugin") != null && src instanceof MavenModuleSetBuild) {
if (isMavenPluginInstalled() && src instanceof MavenModuleSetBuild) {
// Copy artifacts from the build (ArchiveArtifacts build step)
boolean ok = perform(src, dst, includeFilter, excludeFilter, targetDir, console);

Expand Down Expand Up @@ -335,7 +340,7 @@ public FormValidation doCheckProjectName(
final FormValidation result;
final Item item = new JobResolver(value).job;
if (item != null) {
if (Jenkins.getInstanceOrNull().getPlugin("maven-plugin") != null && item instanceof MavenModuleSet) {
if (isMavenPluginInstalled() && item instanceof MavenModuleSet) {
result = FormValidation.warning(Messages.CopyArtifact_MavenProject());
} else {
result = (item instanceof MatrixProject)
Expand Down

0 comments on commit 96921e6

Please sign in to comment.