Skip to content

Commit

Permalink
fixed The jar type of java task shell script error(apache#15641)
Browse files Browse the repository at this point in the history
  • Loading branch information
yangyanh committed Feb 28, 2024
1 parent 86a848e commit 98ce0ee
Showing 1 changed file with 24 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

Expand Down Expand Up @@ -183,9 +185,8 @@ protected String buildJarCommand() {
StringBuilder builder = new StringBuilder();
builder.append(getJavaCommandPath())
.append("java").append(" ")
.append(buildResourcePath()).append(" ")
.append(buildExtDirs()).append(" ")
.append("-jar").append(" ")
.append(taskRequest.getExecutePath()).append(FOLDER_SEPARATOR)
.append(mainJarName).append(" ")
.append(javaParameters.getMainArgs().trim()).append(" ")
.append(javaParameters.getJvmArgs().trim());
Expand Down Expand Up @@ -290,13 +291,32 @@ protected String buildResourcePath() {
for (ResourceInfo info : javaParameters.getResourceFilesList()) {
builder.append(JavaConstants.PATH_SEPARATOR);
builder
.append(taskRequest.getExecutePath())
.append(FOLDER_SEPARATOR)
.append(resourceContext.getResourceItem(info.getResourceName()).getResourceAbsolutePathInLocal());
}
return builder.toString();
}

protected String buildExtDirs() {
StringBuilder builder = new StringBuilder();
if (javaParameters.isModulePath()) {
builder.append("--module-path");
} else {
builder.append("-Djava.ext.dirs=\"$JAVA_HOME/jre/lib/ext");
}
ResourceContext resourceContext = taskRequest.getResourceContext();
Set<String> set = new HashSet<>();
for (ResourceInfo info : javaParameters.getResourceFilesList()) {
String absolutePathInLocal = resourceContext.getResourceItem(info.getResourceName()).getResourceAbsolutePathInLocal();
String extdir = absolutePathInLocal.substring(0, absolutePathInLocal.lastIndexOf(File.separator));
if (set.add(extdir)) {
builder.append(JavaConstants.PATH_SEPARATOR);
builder.append(extdir);
}
}
builder.append("\"");
return builder.toString();
}

/**
* Constructs a shell command compiled from a Java source file
*
Expand Down

0 comments on commit 98ce0ee

Please sign in to comment.