Skip to content

Commit

Permalink
Fix path encoding issue in window (again)
Browse files Browse the repository at this point in the history
We need to keep relative paths in classpath jar since compiler with
classpath support relative path only

Change-Id: Ibffd9b7c29cbcb59564f304cabbdae9673b1b250
  • Loading branch information
ngyukman committed Mar 23, 2023
1 parent 974e476 commit da0824f
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 12 deletions.
14 changes: 7 additions & 7 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ subprojects {
[compileJava, compileTestJava]*.options*.encoding = 'UTF-8'

group = "co.paralleluniverse"
version = "1.0.4-ullink4"
version = "1.0.4-ullink5"
status = "integration"
description = "Simple Java deployment"
ext.url = "https://github.com/puniverse/capsule"
Expand Down Expand Up @@ -59,10 +59,10 @@ subprojects {
}

dependencies {
testCompile 'junit:junit:4.12'
testCompile 'org.truth0:truth:0.23'
testCompile 'com.google.jimfs:jimfs:1.1'
testCompile 'org.jooq:joor:0.9.6'
testImplementation 'junit:junit:4.12'
testImplementation 'org.truth0:truth:0.23'
testImplementation 'com.google.jimfs:jimfs:1.1'
testImplementation 'org.jooq:joor:0.9.6'
javancss 'org.codehaus.javancss:javancss:33.54'
}

Expand Down Expand Up @@ -231,8 +231,8 @@ project (':capsule') {

project (':capsule-util') {
dependencies {
runtime project(':capsule')
compile files("${System.getProperty('java.home')}/../lib/tools.jar")
runtimeOnly project(':capsule')
implementation files("${System.getProperty('java.home')}/../lib/tools.jar")
}

javadoc {
Expand Down
22 changes: 17 additions & 5 deletions capsule/src/main/java/Capsule.java
Original file line number Diff line number Diff line change
Expand Up @@ -5429,8 +5429,9 @@ private List<Path> handleLongClasspath(List<Path> cp, int extra, List<?>... args
// visible for testing
static Path createPathingJar(Path dir, List<Path> cp) {
try {
final List<String> paths = createPathingClassPath(cp);
final Path pathingJar = Files.createTempFile(dir.toAbsolutePath(), "capsule_pathing_jar", ".jar");
final Path absolutePath = dir.toAbsolutePath();
final List<String> paths = createPathingClassPath(absolutePath, cp);
final Path pathingJar = Files.createTempFile(absolutePath, "capsule_pathing_jar", ".jar");
final Manifest man = new Manifest();
man.getMainAttributes().putValue(ATTR_MANIFEST_VERSION, "1.0");
man.getMainAttributes().putValue(ATTR_CLASS_PATH, join(paths, " "));
Expand All @@ -5442,11 +5443,22 @@ static Path createPathingJar(Path dir, List<Path> cp) {
}
}

private static List<String> createPathingClassPath(List<Path> cp) {
private static List<String> createPathingClassPath(Path dir, List<Path> cp) {
boolean allPathsHaveSameRoot = true;
for (Path p : cp) {
if (!dir.getRoot().equals(p.getRoot())) {
allPathsHaveSameRoot = false;
break;
}
}

final List<String> paths = new ArrayList<>(cp.size());
for (Path p : cp) { // In order to use the Class-Path attribute, we must either relativize the paths, or specify them as file URLs
// always use absolute path to avoid encoding issue
paths.add(p.toUri().toString());
if (allPathsHaveSameRoot)
// path must be at least encoding spaces since ATTR_CLASS_PATH is delimited by space in createPathingJar()
paths.add(dir.relativize(p).toString().replace(" ", "%20"));
else
paths.add(p.toUri().toString());
}
return paths;
}
Expand Down

0 comments on commit da0824f

Please sign in to comment.