Skip to content

Commit

Permalink
Make maven-plugin an optional dependency (#244)
Browse files Browse the repository at this point in the history
  • Loading branch information
aah9 authored May 29, 2023
1 parent f1f416e commit da70453
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
1 change: 1 addition & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@
<groupId>org.jenkins-ci.main</groupId>
<artifactId>maven-plugin</artifactId>
<version>3.16</version>
<optional>true</optional>
<exclusions>
<exclusion>
<groupId>commons-io</groupId>
Expand Down
20 changes: 13 additions & 7 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 (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,12 +340,13 @@ public FormValidation doCheckProjectName(
final FormValidation result;
final Item item = new JobResolver(value).job;
if (item != null) {

result = item instanceof MavenModuleSet
? FormValidation.warning(Messages.CopyArtifact_MavenProject())
: (item instanceof MatrixProject
? FormValidation.warning(Messages.CopyArtifact_MatrixProject())
: FormValidation.ok());
if (isMavenPluginInstalled() && item instanceof MavenModuleSet) {
result = FormValidation.warning(Messages.CopyArtifact_MavenProject());
} else {
result = (item instanceof MatrixProject)
? FormValidation.warning(Messages.CopyArtifact_MatrixProject())
: FormValidation.ok();
}
}
else if (value.indexOf('$') >= 0) {
result = FormValidation.warning(Messages.CopyArtifact_ParameterizedName());
Expand Down

0 comments on commit da70453

Please sign in to comment.