You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by el...@apache.org on 2024/12/08 11:59:56 UTC
(maven-jlink-plugin) branch master updated: [MJLINK-90] Make class more direct and simpler (#229)
This is an automated email from the ASF dual-hosted git repository.
elharo pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/maven-jlink-plugin.git
The following commit(s) were added to refs/heads/master by this push:
new b57848a [MJLINK-90] Make class more direct and simpler (#229)
b57848a is described below
commit b57848a942c13d142885ede5f9cc97f0e34b64b5
Author: Elliotte Rusty Harold <el...@users.noreply.github.com>
AuthorDate: Sun Dec 8 11:59:51 2024 +0000
[MJLINK-90] Make class more direct and simpler (#229)
* simplify
---
.../maven/plugins/jlink/AbstractJLinkMojo.java | 48 -----------------
.../org/apache/maven/plugins/jlink/JLinkMojo.java | 63 +++++++++++++++-------
2 files changed, 44 insertions(+), 67 deletions(-)
diff --git a/src/main/java/org/apache/maven/plugins/jlink/AbstractJLinkMojo.java b/src/main/java/org/apache/maven/plugins/jlink/AbstractJLinkMojo.java
index ce45942..28b419e 100644
--- a/src/main/java/org/apache/maven/plugins/jlink/AbstractJLinkMojo.java
+++ b/src/main/java/org/apache/maven/plugins/jlink/AbstractJLinkMojo.java
@@ -124,54 +124,6 @@ public abstract class AbstractJLinkMojo extends AbstractMojo {
return session;
}
- /**
- * Returns the archive file to generate, based on an optional classifier.
- *
- * @param basedir the output directory
- * @param finalName the name of the ear file
- * @param classifier an optional classifier
- * @param archiveExt The extension of the file.
- * @return the file to generate
- */
- protected File getArchiveFile(File basedir, String finalName, String classifier, String archiveExt) {
- if (basedir == null) {
- throw new IllegalArgumentException("basedir is not allowed to be null");
- }
- if (finalName == null) {
- throw new IllegalArgumentException("finalName is not allowed to be null");
- }
- if (archiveExt == null) {
- throw new IllegalArgumentException("archiveExt is not allowed to be null");
- }
-
- if (finalName.isEmpty()) {
- throw new IllegalArgumentException("finalName is not allowed to be empty.");
- }
- if (archiveExt.isEmpty()) {
- throw new IllegalArgumentException("archiveExt is not allowed to be empty.");
- }
-
- StringBuilder fileName = new StringBuilder(finalName);
-
- if (hasClassifier(classifier)) {
- fileName.append("-").append(classifier);
- }
-
- fileName.append('.');
- fileName.append(archiveExt);
-
- return new File(basedir, fileName.toString());
- }
-
- protected boolean hasClassifier(String classifier) {
- boolean result = false;
- if (classifier != null && !classifier.isEmpty()) {
- result = true;
- }
-
- return result;
- }
-
/**
* This will convert a module path separated by either {@code :} or {@code ;} into a string which uses the platform
* path separator uniformly.
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 b2704da..1bf5e2b 100644
--- a/src/main/java/org/apache/maven/plugins/jlink/JLinkMojo.java
+++ b/src/main/java/org/apache/maven/plugins/jlink/JLinkMojo.java
@@ -243,7 +243,7 @@ public class JLinkMojo extends AbstractJLinkMojo {
* The byte order of the generated Java Run Time image. <code>--endian <little|big></code>. If the endian is
* not given the default is: <code>native</code>.
*/
- // TODO: Should we define either little or big as default? or should we left as it.
+ // TODO: Should we define either little or big as default? or should we leave it as is?
@Parameter
private String endian;
@@ -273,14 +273,14 @@ public class JLinkMojo extends AbstractJLinkMojo {
private boolean ignoreSigningInformation;
/**
- * This will suppress to have an <code>includes</code> directory in the resulting Java Run Time Image. The JLink
+ * This will omit an <code>includes</code> directory from the resulting Java Run Time Image. The JLink
* command line equivalent is: <code>--no-header-files</code>
*/
@Parameter(defaultValue = "false")
private boolean noHeaderFiles;
/**
- * This will suppress to have the <code>man</code> directory in the resulting Java Run Time Image. The JLink command
+ * This will omit the <code>man</code> directory from the resulting Java Run Time Image. The JLink command
* line equivalent is: <code>--no-man-pages</code>
*/
@Parameter(defaultValue = "false")
@@ -345,8 +345,8 @@ public class JLinkMojo extends AbstractJLinkMojo {
/**
* Classifier to add to the artifact generated. If given, the artifact will be attached
* as a supplemental artifact.
- * If not given this will create the main artifact which is the default behavior.
- * If you try to do that a second time without using a classifier the build will fail.
+ * If not given, this will create the main artifact which is the default behavior.
+ * If you try to do that a second time without using a classifier, the build will fail.
*/
@Parameter
private String classifier;
@@ -405,7 +405,7 @@ public class JLinkMojo extends AbstractJLinkMojo {
ifOutputDirectoryExistsDelteIt();
- JLinkExecutor jLinkExec = getExecutor();
+ JLinkExecutor jLinkExec = getJlinkExecutor();
Collection<String> modulesToAdd = new ArrayList<>();
if (addModules != null) {
modulesToAdd.addAll(addModules);
@@ -548,10 +548,6 @@ public class JLinkMojo extends AbstractJLinkMojo {
return modulepathElements;
}
- private JLinkExecutor getExecutor() {
- return getJlinkExecutor();
- }
-
private boolean projectHasAlreadySetAnArtifact() {
if (getProject().getArtifact().getFile() != null) {
return getProject().getArtifact().getFile().isFile();
@@ -561,15 +557,10 @@ public class JLinkMojo extends AbstractJLinkMojo {
}
/**
- * @return true in case where the classifier is not {@code null} and contains something else than white spaces.
+ * @return true when the classifier is not {@code null} and not empty
*/
- protected boolean hasClassifier() {
- boolean result = false;
- if (getClassifier() != null && !getClassifier().isEmpty()) {
- result = true;
- }
-
- return result;
+ private boolean hasClassifier() {
+ return hasClassifier(getClassifier());
}
private File createZipArchiveFromImage(File outputDirectory, File outputDirectoryImage)
@@ -582,7 +573,7 @@ public class JLinkMojo extends AbstractJLinkMojo {
zipArchiver.configureReproducibleBuild(FileTime.from(lastModified.get()));
}
- File resultArchive = getArchiveFile(outputDirectory, finalName, getClassifier(), "zip");
+ File resultArchive = getZipFile(outputDirectory, finalName, getClassifier());
zipArchiver.setDestFile(resultArchive);
try {
@@ -780,7 +771,41 @@ public class JLinkMojo extends AbstractJLinkMojo {
/**
* {@inheritDoc}
*/
+ @Override
protected String getClassifier() {
return classifier;
}
+
+ /**
+ * Returns the archive file to generate, based on an optional classifier.
+ *
+ * @param basedir the output directory
+ * @param finalName the name of the zip file
+ * @param classifier an optional classifier
+ * @return the file to generate
+ */
+ private static File getZipFile(File basedir, String finalName, String classifier) {
+ if (finalName.isEmpty()) {
+ throw new IllegalArgumentException("finalName is not allowed to be empty.");
+ }
+
+ StringBuilder fileName = new StringBuilder(finalName);
+
+ if (hasClassifier(classifier)) {
+ fileName.append("-").append(classifier);
+ }
+
+ fileName.append(".zip");
+
+ return new File(basedir, fileName.toString());
+ }
+
+ private static boolean hasClassifier(String classifier) {
+ boolean result = false;
+ if (classifier != null && !classifier.isEmpty()) {
+ result = true;
+ }
+
+ return result;
+ }
}