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-jmod-plugin.git
The following commit(s) were added to refs/heads/master by this push: new ed6f471 use strings instead of file for describe and list ocmmands (#34) ed6f471 is described below commit ed6f471cb73fc7fa1147239f6c657d37cb77b130 Author: Elliotte Rusty Harold <elh...@users.noreply.github.com> AuthorDate: Wed Dec 18 16:31:55 2024 +0000 use strings instead of file for describe and list ocmmands (#34) avoid IO --- .../maven/plugins/jmod/JModDescribeMojo.java | 52 ++++++--------------- .../apache/maven/plugins/jmod/JModListMojo.java | 54 ++++++---------------- 2 files changed, 29 insertions(+), 77 deletions(-) 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 bd30821..a73414f 100644 --- a/src/main/java/org/apache/maven/plugins/jmod/JModDescribeMojo.java +++ b/src/main/java/org/apache/maven/plugins/jmod/JModDescribeMojo.java @@ -22,8 +22,6 @@ import javax.inject.Inject; import java.io.File; import java.io.IOException; -import java.io.Writer; -import java.nio.file.Files; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.MojoFailureException; @@ -62,50 +60,28 @@ public class JModDescribeMojo extends AbstractJModMojo { } public void execute() throws MojoExecutionException, MojoFailureException { - - String jModExecutable; try { - jModExecutable = getJModExecutable(); - } catch (IOException e) { - throw new MojoFailureException("Unable to find jmod command: " + e.getMessage(), e); - } + String jModExecutable = getJModExecutable(); + getLog().debug("Toolchain in maven-jmod-plugin: jmod [ " + jModExecutable + " ]"); - getLog().debug("Toolchain in maven-jmod-plugin: jmod [ " + jModExecutable + " ]"); + Commandline cmd = createJModDescribeCommandLine(); + cmd.setExecutable(jModExecutable); - if (!jmodFile.exists() || !jmodFile.isFile()) { - throw new MojoFailureException("Unable to find " + jmodFile.getAbsolutePath()); - } - - Commandline cmd; - try { - cmd = createJModDescribeCommandLine(jmodFile); + getLog().info("The following information is contained in the module file " + jmodFile.getAbsolutePath()); + executeCommand(cmd, outputDirectory); } catch (IOException e) { - throw new MojoExecutionException(e.getMessage()); + throw new MojoFailureException("Unable to find jmod command: " + e.getMessage(), e); } - cmd.setExecutable(jModExecutable); - - getLog().info("The following information is contained in the module file " + jmodFile.getAbsolutePath()); - executeCommand(cmd, outputDirectory); } - private Commandline createJModDescribeCommandLine(File resultingJModFile) throws IOException { - File file = new File(outputDirectory, "jmodDescribeArgs"); - if (!getLog().isDebugEnabled()) { - file.deleteOnExit(); + private Commandline createJModDescribeCommandLine() throws MojoFailureException { + if (!jmodFile.exists() || !jmodFile.isFile()) { + throw new MojoFailureException("Unable to find " + jmodFile.getAbsolutePath()); } - file.getParentFile().mkdirs(); - file.createNewFile(); - try (Writer out = Files.newBufferedWriter(file.toPath())) { - out.write("describe\n"); - - out.write(resultingJModFile.getAbsolutePath()); - out.write("\n"); - - Commandline cmd = new Commandline(); - cmd.createArg().setValue('@' + file.getAbsolutePath()); - - return cmd; - } + Commandline commandLine = new Commandline(); + commandLine.createArg().setValue("describe"); + commandLine.createArg().setValue(jmodFile.getAbsolutePath()); + return commandLine; } } 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 133fa38..c95d0b6 100644 --- a/src/main/java/org/apache/maven/plugins/jmod/JModListMojo.java +++ b/src/main/java/org/apache/maven/plugins/jmod/JModListMojo.java @@ -22,8 +22,6 @@ import javax.inject.Inject; import java.io.File; import java.io.IOException; -import java.io.Writer; -import java.nio.file.Files; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.MojoFailureException; @@ -46,7 +44,7 @@ public class JModListMojo extends AbstractJModMojo { private File outputDirectory; /** - * The name of the jmod file which is used to be examined via <code>jmod list jmodFile</code> + * The name of the jmod file which is examined via <code>jmod list jmodFile</code>. */ // @formatter:off @Parameter( @@ -62,50 +60,28 @@ public class JModListMojo extends AbstractJModMojo { } public void execute() throws MojoExecutionException, MojoFailureException { - - String jModExecutable; try { - jModExecutable = getJModExecutable(); - } catch (IOException e) { - throw new MojoFailureException("Unable to find jmod command: " + e.getMessage(), e); - } + String jModExecutable = getJModExecutable(); + getLog().debug("Toolchain in maven-jmod-plugin: jmod [ " + jModExecutable + " ]"); - getLog().info("Toolchain in maven-jmod-plugin: jmod [ " + jModExecutable + " ]"); + Commandline cmd = createJModListCommandLine(); + cmd.setExecutable(jModExecutable); - if (!jmodFile.exists() || !jmodFile.isFile()) { - throw new MojoFailureException("Unable to find " + jmodFile.getAbsolutePath()); - } - - Commandline cmd; - try { - cmd = createJModListCommandLine(jmodFile); + getLog().info("The following files are contained in the module file " + jmodFile.getAbsolutePath()); + executeCommand(cmd, outputDirectory); } catch (IOException e) { - throw new MojoExecutionException(e.getMessage()); + throw new MojoFailureException("Unable to find jmod command: " + e.getMessage(), e); } - cmd.setExecutable(jModExecutable); - - getLog().info("The following files are contained in the module file " + jmodFile.getAbsolutePath()); - executeCommand(cmd, outputDirectory); } - private Commandline createJModListCommandLine(File resultingJModFile) throws IOException { - File file = new File(outputDirectory, "jmodListArgs"); - if (!getLog().isDebugEnabled()) { - file.deleteOnExit(); + private Commandline createJModListCommandLine() throws MojoFailureException { + if (!jmodFile.exists() || !jmodFile.isFile()) { + throw new MojoFailureException("Unable to find " + jmodFile.getAbsolutePath()); } - file.getParentFile().mkdirs(); - file.createNewFile(); - try (Writer out = Files.newBufferedWriter(file.toPath())) { - out.write("list\n"); - - out.write(resultingJModFile.getAbsolutePath()); - out.write("\n"); - - Commandline cmd = new Commandline(); - cmd.createArg().setValue('@' + file.getAbsolutePath()); - - return cmd; - } + Commandline commandLine = new Commandline(); + commandLine.createArg().setValue("list"); + commandLine.createArg().setValue(jmodFile.getAbsolutePath()); + return commandLine; } }