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/18 13:36:47 UTC
(maven-jmod-plugin) branch close created (now b48e911)
This is an automated email from the ASF dual-hosted git repository.
elharo pushed a change to branch close
in repository https://gitbox.apache.org/repos/asf/maven-jmod-plugin.git
at b48e911 Use modern I/O
This branch includes the following new commits:
new b48e911 Use modern I/O
The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
(maven-jmod-plugin) 01/01: Use modern I/O
Posted by el...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
elharo pushed a commit to branch close
in repository https://gitbox.apache.org/repos/asf/maven-jmod-plugin.git
commit b48e911e85403fd604de2f294633053298923d9e
Author: Elliotte Rusty Harold <el...@ibiblio.org>
AuthorDate: Wed Dec 18 08:36:27 2024 -0500
Use modern I/O
---
.../apache/maven/plugins/jmod/JModCreateMojo.java | 191 +++++++++++----------
.../maven/plugins/jmod/JModDescribeMojo.java | 25 +--
.../apache/maven/plugins/jmod/JModListMojo.java | 19 +-
3 files changed, 123 insertions(+), 112 deletions(-)
diff --git a/src/main/java/org/apache/maven/plugins/jmod/JModCreateMojo.java b/src/main/java/org/apache/maven/plugins/jmod/JModCreateMojo.java
index 8a40aec..5610d87 100644
--- a/src/main/java/org/apache/maven/plugins/jmod/JModCreateMojo.java
+++ b/src/main/java/org/apache/maven/plugins/jmod/JModCreateMojo.java
@@ -22,7 +22,8 @@ import javax.inject.Inject;
import java.io.File;
import java.io.IOException;
-import java.io.PrintStream;
+import java.io.Writer;
+import java.nio.file.Files;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
@@ -490,114 +491,122 @@ public class JModCreateMojo extends AbstractJModMojo {
file.getParentFile().mkdirs();
file.createNewFile();
- PrintStream argsFile = new PrintStream(file);
+ try (Writer out = Files.newBufferedWriter(file.toPath())) {
+ out.write("create\n");
- argsFile.println("create");
-
- if (moduleVersion != null) {
- argsFile.println("--module-version");
- argsFile.println(moduleVersion);
- }
+ if (moduleVersion != null) {
+ out.write("--module-version\n");
+ out.write(moduleVersion);
+ out.write('\n');
+ }
- List<String> classPaths;
- if (classpathElements != null) {
- classPaths = new ArrayList<>(classpathElements);
- } else {
- classPaths = new ArrayList<>(1);
- }
- if (targetClassesDirectory.exists()) {
- classPaths.add(targetClassesDirectory.getAbsolutePath());
- }
+ List<String> classPaths;
+ if (classpathElements != null) {
+ classPaths = new ArrayList<>(classpathElements);
+ } else {
+ classPaths = new ArrayList<>(1);
+ }
+ if (targetClassesDirectory.exists()) {
+ classPaths.add(targetClassesDirectory.getAbsolutePath());
+ }
- argsFile.println("--class-path");
- argsFile.append('"')
- .append(getPlatformSeparatedList(classPaths).replace("\\", "\\\\"))
- .println('"');
-
- if (excludes != null && !excludes.isEmpty()) {
- argsFile.println("--exclude");
- String commaSeparatedList = getCommaSeparatedList(excludes);
- argsFile.append('"')
- .append(commaSeparatedList.replace("\\", "\\\\"))
- .println('"');
- }
+ out.write("--class-path\n");
+ out.write('"');
+ out.write(getPlatformSeparatedList(classPaths).replace("\\", "\\\\"));
+ out.write("\"\n");
+
+ if (excludes != null && !excludes.isEmpty()) {
+ out.write("--exclude\n");
+ String commaSeparatedList = getCommaSeparatedList(excludes);
+ out.write('"');
+ out.write(commaSeparatedList.replace("\\", "\\\\"));
+ out.write("\"\n");
+ }
- List<String> configList = handleConfigurationListWithDefault(configs, DEFAULT_CONFIG_DIRECTORY);
- if (!configList.isEmpty()) {
- argsFile.println("--config");
- // Should we quote the paths?
- argsFile.println(getPlatformSeparatedList(configList));
- }
+ List<String> configList = handleConfigurationListWithDefault(configs, DEFAULT_CONFIG_DIRECTORY);
+ if (!configList.isEmpty()) {
+ out.write("--config\n");
+ out.write(getPlatformSeparatedList(configList));
+ out.write('\n');
+ }
- if (StringUtils.isNotBlank(mainClass)) {
- argsFile.println("--main-class");
- argsFile.println(mainClass);
- }
+ if (StringUtils.isNotBlank(mainClass)) {
+ out.write("--main-class\n");
+ out.write(mainClass);
+ out.write('\n');
+ }
- List<String> cmdsList = handleConfigurationListWithDefault(cmds, DEFAULT_CMD_DIRECTORY);
- if (!cmdsList.isEmpty()) {
- argsFile.println("--cmds");
- argsFile.println(getPlatformSeparatedList(cmdsList));
- }
+ List<String> cmdsList = handleConfigurationListWithDefault(cmds, DEFAULT_CMD_DIRECTORY);
+ if (!cmdsList.isEmpty()) {
+ out.write("--cmds\n");
+ out.write(getPlatformSeparatedList(cmdsList));
+ out.write('\n');
+ }
- List<String> libsList = handleConfigurationListWithDefault(libs, DEFAULT_LIB_DIRECTORY);
- if (!libsList.isEmpty()) {
- argsFile.println("--libs");
- argsFile.println(getPlatformSeparatedList(libsList));
- }
+ List<String> libsList = handleConfigurationListWithDefault(libs, DEFAULT_LIB_DIRECTORY);
+ if (!libsList.isEmpty()) {
+ out.write("--libs");
+ out.write(getPlatformSeparatedList(libsList));
+ out.write('\n');
+ }
- List<String> headerFilesList = handleConfigurationListWithDefault(headerFiles, DEFAULT_HEADER_FILES_DIRECTORY);
- if (!headerFilesList.isEmpty()) {
- argsFile.println("--header-files");
- argsFile.println(getPlatformSeparatedList(headerFilesList));
- }
+ List<String> headerFilesList =
+ handleConfigurationListWithDefault(headerFiles, DEFAULT_HEADER_FILES_DIRECTORY);
+ if (!headerFilesList.isEmpty()) {
+ out.write("--header-files\n");
+ out.write(getPlatformSeparatedList(headerFilesList));
+ out.write('\n');
+ }
- List<String> legalNoticesList =
- handleConfigurationListWithDefault(legalNotices, DEFAULT_LEGAL_NOTICES_DIRECTORY);
- if (!legalNoticesList.isEmpty()) {
- argsFile.println("--legal-notices");
- argsFile.println(getPlatformSeparatedList(legalNoticesList));
- }
+ List<String> legalNoticesList =
+ handleConfigurationListWithDefault(legalNotices, DEFAULT_LEGAL_NOTICES_DIRECTORY);
+ if (!legalNoticesList.isEmpty()) {
+ out.write("--legal-notices\n");
+ out.write(getPlatformSeparatedList(legalNoticesList));
+ out.write('\n');
+ }
- List<String> manPagesList = handleConfigurationListWithDefault(manPages, DEFAULT_MAN_PAGES_DIRECTORY);
- if (!manPagesList.isEmpty()) {
- argsFile.println("--man-pages");
- argsFile.println(getPlatformSeparatedList(manPagesList));
- }
+ List<String> manPagesList = handleConfigurationListWithDefault(manPages, DEFAULT_MAN_PAGES_DIRECTORY);
+ if (!manPagesList.isEmpty()) {
+ out.write("--man-pages\n");
+ out.write(getPlatformSeparatedList(manPagesList));
+ out.write('\n');
+ }
- List<String> modulePaths = new ArrayList<>(modulepathElements);
- modulePaths.add(new File(javaHome, JMODS).getAbsolutePath());
+ List<String> modulePaths = new ArrayList<>(modulepathElements);
+ modulePaths.add(new File(javaHome, JMODS).getAbsolutePath());
- if (modulePaths != null) {
- // @formatter:off
- argsFile.println("--module-path");
- argsFile.append('"')
- .append(getPlatformSeparatedList(modulePaths).replace("\\", "\\\\"))
- .println('"');
- // @formatter:off
- }
+ if (modulePaths != null) {
+ out.write("--module-path\n");
+ out.write('"');
+ out.write(getPlatformSeparatedList(modulePaths).replace("\\", "\\\\"));
+ out.write("\"\n");
+ }
- if (targetPlatform != null) {
- argsFile.println("--target-platform");
- argsFile.println(targetPlatform);
- }
+ if (targetPlatform != null) {
+ out.write("--target-platform\n");
+ out.write(targetPlatform);
+ out.write('\n');
+ }
- if (warnIfResolved != null) {
- argsFile.println("--warn-if-resolved");
- argsFile.println(warnIfResolved);
- }
+ if (warnIfResolved != null) {
+ out.write("--warn-if-resolved\n");
+ out.write(warnIfResolved);
+ out.write('\n');
+ }
- if (doNotResolveByDefault) {
- argsFile.println("--do-not-resolve-by-default");
- }
+ if (doNotResolveByDefault) {
+ out.write("--do-not-resolve-by-default\n");
+ }
- argsFile.println(resultingJModFile.getAbsolutePath());
- argsFile.close();
+ out.write(resultingJModFile.getAbsolutePath());
+ out.write('\n');
- Commandline cmd = new Commandline();
- cmd.createArg().setValue('@' + file.getAbsolutePath());
+ Commandline cmd = new Commandline();
+ cmd.createArg().setValue('@' + file.getAbsolutePath());
- return cmd;
+ return cmd;
+ }
}
private boolean isConfigurationDefinedInPOM(List<String> configuration) {
diff --git a/src/main/java/org/apache/maven/plugins/jmod/JModDescribeMojo.java b/src/main/java/org/apache/maven/plugins/jmod/JModDescribeMojo.java
index 01589f5..597b4ba 100644
--- a/src/main/java/org/apache/maven/plugins/jmod/JModDescribeMojo.java
+++ b/src/main/java/org/apache/maven/plugins/jmod/JModDescribeMojo.java
@@ -22,7 +22,8 @@ import javax.inject.Inject;
import java.io.File;
import java.io.IOException;
-import java.io.PrintStream;
+import java.io.Writer;
+import java.nio.file.Files;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
@@ -45,7 +46,7 @@ public class JModDescribeMojo extends AbstractJModMojo {
private File outputDirectory;
/**
- * The name of the jmod file which is used to be examined via <code>jmod describe jmodFile</code>
+ * The name of the jmod file which is examined via <code>jmod describe jmodFile</code>
*/
// @formatter:off
@Parameter(
@@ -69,7 +70,7 @@ public class JModDescribeMojo extends AbstractJModMojo {
throw new MojoFailureException("Unable to find jmod command: " + e.getMessage(), e);
}
- getLog().info("Toolchain in maven-jmod-plugin: jmod [ " + jModExecutable + " ]");
+ getLog().debug("Toolchain in maven-jmod-plugin: jmod [ " + jModExecutable + " ]");
if (!jmodFile.exists() || !jmodFile.isFile()) {
throw new MojoFailureException("Unable to find " + jmodFile.getAbsolutePath());
@@ -87,7 +88,7 @@ public class JModDescribeMojo extends AbstractJModMojo {
executeCommand(cmd, outputDirectory);
}
- private Commandline createJModDescribeCommandLine(File resultingJModFile) throws IOException {
+ protected Commandline createJModDescribeCommandLine(File resultingJModFile) throws IOException {
File file = new File(outputDirectory, "jmodDescribeArgs");
if (!getLog().isDebugEnabled()) {
file.deleteOnExit();
@@ -95,16 +96,16 @@ public class JModDescribeMojo extends AbstractJModMojo {
file.getParentFile().mkdirs();
file.createNewFile();
- PrintStream argsFile = new PrintStream(file);
+ try (Writer out = Files.newBufferedWriter(file.toPath())) {
+ out.write("describe\n");
- argsFile.println("describe");
+ out.write(resultingJModFile.getAbsolutePath());
+ out.write("\n");
- argsFile.println(resultingJModFile.getAbsolutePath());
- argsFile.close();
+ Commandline cmd = new Commandline();
+ cmd.createArg().setValue('@' + file.getAbsolutePath());
- Commandline cmd = new Commandline();
- cmd.createArg().setValue('@' + file.getAbsolutePath());
-
- return cmd;
+ return cmd;
+ }
}
}
diff --git a/src/main/java/org/apache/maven/plugins/jmod/JModListMojo.java b/src/main/java/org/apache/maven/plugins/jmod/JModListMojo.java
index a2ddd7f..133fa38 100644
--- a/src/main/java/org/apache/maven/plugins/jmod/JModListMojo.java
+++ b/src/main/java/org/apache/maven/plugins/jmod/JModListMojo.java
@@ -22,7 +22,8 @@ import javax.inject.Inject;
import java.io.File;
import java.io.IOException;
-import java.io.PrintStream;
+import java.io.Writer;
+import java.nio.file.Files;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
@@ -95,16 +96,16 @@ public class JModListMojo extends AbstractJModMojo {
file.getParentFile().mkdirs();
file.createNewFile();
- PrintStream argsFile = new PrintStream(file);
+ try (Writer out = Files.newBufferedWriter(file.toPath())) {
+ out.write("list\n");
- argsFile.println("list");
+ out.write(resultingJModFile.getAbsolutePath());
+ out.write("\n");
- argsFile.println(resultingJModFile.getAbsolutePath());
- argsFile.close();
+ Commandline cmd = new Commandline();
+ cmd.createArg().setValue('@' + file.getAbsolutePath());
- Commandline cmd = new Commandline();
- cmd.createArg().setValue('@' + file.getAbsolutePath());
-
- return cmd;
+ return cmd;
+ }
}
}