Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 14 additions & 38 deletions src/main/java/org/apache/maven/plugins/jmod/JModDescribeMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@

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;
Expand Down Expand Up @@ -62,50 +60,28 @@ public JModDescribeMojo(ToolchainManager toolchainManager) {
}

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;
}
}
54 changes: 15 additions & 39 deletions src/main/java/org/apache/maven/plugins/jmod/JModListMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@

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;
Expand All @@ -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(
Expand All @@ -62,50 +60,28 @@ public JModListMojo(ToolchainManager toolchainManager) {
}

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;
}
}