Skip to content

Commit

Permalink
[jlink] relativize paths in jdeps command invocation
Browse files Browse the repository at this point in the history
  • Loading branch information
aalmiray committed Feb 25, 2022
1 parent ea7659d commit 8c4206f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,19 @@ protected void executeCommandCapturing(Command command, OutputStream out) throws
}
}

protected void executeCommandCapturing(Path directory, Command command, OutputStream out) throws AssemblerProcessingException {
try {
int exitValue = new CommandExecutor(context.getLogger())
.executeCommandCapturing(directory, command, out);
if (exitValue != 0) {
context.getLogger().error(out.toString().trim());
throw new CommandException(RB.$("ERROR_command_execution_exit_value", exitValue));
}
} catch (CommandException e) {
throw new AssemblerProcessingException(RB.$("ERROR_unexpected_error"), e);
}
}

protected void copyFileSets(JReleaserContext context, Path destination) throws AssemblerProcessingException {
try {
for (FileSet fileSet : assembler.getFileSets()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -281,11 +281,10 @@ private Set<String> resolveModuleNames(JReleaserContext context, Path jdkPath, P
} else if (!assembler.getJdeps().getTargets().isEmpty()) {
cmd.arg("--class-path");
if (assembler.getJdeps().isUseWildcardInPath()) {
cmd.arg(
jarsDirectory.resolve("universal").toAbsolutePath() +
cmd.arg("universal" +
File.separator + "*" +
File.pathSeparator +
jarsDirectory.resolve(platform) +
platform +
File.separator + "*");
} else {
calculateJarPath(jarsDirectory, platform, cmd, true);
Expand All @@ -301,7 +300,7 @@ private Set<String> resolveModuleNames(JReleaserContext context, Path jdkPath, P

context.getLogger().debug(String.join(" ", cmd.getArgs()));
ByteArrayOutputStream out = new ByteArrayOutputStream();
executeCommandCapturing(cmd, out);
executeCommandCapturing(jarsDirectory, cmd, out);

String output = out.toString().trim();
long lineCount = Arrays.stream(output.split(System.lineSeparator()))
Expand All @@ -321,13 +320,13 @@ private void calculateJarPath(Path jarsDirectory, String platform, Command cmd,
StringBuilder pathBuilder = new StringBuilder();

String s = listFilesAndProcess(jarsDirectory.resolve("universal"), files ->
files.map(Path::toAbsolutePath)
files.map(jarsDirectory::relativize)
.map(Object::toString)
.collect(joining(File.pathSeparator)));
pathBuilder.append(s);

String platformSpecific = listFilesAndProcess(jarsDirectory.resolve(platform), files ->
files.map(Path::toAbsolutePath)
files.map(jarsDirectory::relativize)
.map(Object::toString)
.collect(joining(File.pathSeparator)));

Expand All @@ -339,12 +338,12 @@ private void calculateJarPath(Path jarsDirectory, String platform, Command cmd,
cmd.arg(pathBuilder.toString());
} else {
listFilesAndConsume(jarsDirectory.resolve("universal"), files ->
files.map(Path::toAbsolutePath)
files.map(jarsDirectory::relativize)
.map(Object::toString)
.forEach(cmd::arg));

listFilesAndConsume(jarsDirectory.resolve(platform), files ->
files.map(Path::toAbsolutePath)
files.map(jarsDirectory::relativize)
.map(Object::toString)
.forEach(cmd::arg));
}
Expand Down

0 comments on commit 8c4206f

Please sign in to comment.