This is an automated email from the ASF dual-hosted git repository.

bmarwell pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/maven-jlink-plugin.git

commit dc1ddc495b31ebd959a33acdb8b7ac95547daad4
Author: Peter <[email protected]>
AuthorDate: Mon Sep 29 15:56:20 2025 +1000

    Refactor artifact attachment logic into separate method with guard clauses
---
 src/it/projects/attach_skip/verify.groovy          |  7 ++----
 .../org/apache/maven/plugins/jlink/JLinkMojo.java  | 28 +++++++++++++---------
 2 files changed, 19 insertions(+), 16 deletions(-)

diff --git a/src/it/projects/attach_skip/verify.groovy 
b/src/it/projects/attach_skip/verify.groovy
index 401b199..d67a5b6 100644
--- a/src/it/projects/attach_skip/verify.groovy
+++ b/src/it/projects/attach_skip/verify.groovy
@@ -23,8 +23,7 @@ import java.util.*;
 import java.util.jar.*;
 import org.codehaus.plexus.util.*;
 
-try
-{
+try {
     File target = new File( basedir, "target" )
     if ( !target.exists() || !target.isDirectory() ) {
         System.err.println( "target file is missing or not a directory." )
@@ -87,9 +86,7 @@ try
     }
 
     return true
-}
-catch( Throwable e )
-{
+} catch( Throwable e ) {
     e.printStackTrace()
     return false
 }
diff --git a/src/main/java/org/apache/maven/plugins/jlink/JLinkMojo.java 
b/src/main/java/org/apache/maven/plugins/jlink/JLinkMojo.java
index 4fdabc5..0dc98e1 100644
--- a/src/main/java/org/apache/maven/plugins/jlink/JLinkMojo.java
+++ b/src/main/java/org/apache/maven/plugins/jlink/JLinkMojo.java
@@ -474,17 +474,7 @@ public class JLinkMojo extends AbstractJLinkMojo {
 
         File createZipArchiveFromImage = 
createZipArchiveFromImage(buildDirectory, outputDirectoryImage);
 
-        if (attach) {
-            if (hasClassifier()) {
-                projectHelper.attachArtifact(getProject(), "jlink", 
getClassifier(), createZipArchiveFromImage);
-            } else {
-                if (projectHasAlreadySetAnArtifact()) {
-                    throw new MojoExecutionException("You have to use a 
classifier "
-                            + "to attach supplemental artifacts to the project 
instead of replacing them.");
-                }
-                getProject().getArtifact().setFile(createZipArchiveFromImage);
-            }
-        }
+        attachArtifactUnlessDisabled(createZipArchiveFromImage);
     }
 
     /**
@@ -640,6 +630,22 @@ public class JLinkMojo extends AbstractJLinkMojo {
         return resultArchive;
     }
 
+    private void attachArtifactUnlessDisabled(File artifactFile) throws 
MojoExecutionException {
+        if (!attach) {
+            return;
+        }
+
+        if (hasClassifier()) {
+            projectHelper.attachArtifact(getProject(), "jlink", 
getClassifier(), artifactFile);
+        } else {
+            if (projectHasAlreadySetAnArtifact()) {
+                throw new MojoExecutionException("You have to use a classifier 
"
+                        + "to attach supplemental artifacts to the project 
instead of replacing them.");
+            }
+            getProject().getArtifact().setFile(artifactFile);
+        }
+    }
+
     private void failIfParametersAreNotInTheirValidValueRanges() throws 
MojoFailureException {
         if (endian != null && (!"big".equals(endian) && 
!"little".equals(endian))) {
             String message = "The given endian parameter " + endian

Reply via email to