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
191 changes: 100 additions & 91 deletions src/main/java/org/apache/maven/plugins/jmod/JModCreateMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@

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;
Expand Down Expand Up @@ -490,114 +491,122 @@ private Commandline createJModCreateCommandLine(File resultingJModFile) throws I
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\n");
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) {
Expand Down
23 changes: 12 additions & 11 deletions src/main/java/org/apache/maven/plugins/jmod/JModDescribeMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@

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;
Expand All @@ -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(
Expand All @@ -69,7 +70,7 @@ public void execute() throws MojoExecutionException, MojoFailureException {
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());
Expand All @@ -95,16 +96,16 @@ private Commandline createJModDescribeCommandLine(File resultingJModFile) throws
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;
}
}
}
19 changes: 10 additions & 9 deletions src/main/java/org/apache/maven/plugins/jmod/JModListMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@

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;
Expand Down Expand Up @@ -95,16 +96,16 @@ private Commandline createJModListCommandLine(File resultingJModFile) throws IOE
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;
}
}
}