Skip to content

Commit cc368d5

Browse files
committed
[GR-44027] Fix manifest Class-Path handling of relative paths in bundle-case
1 parent e8f4769 commit cc368d5

File tree

2 files changed

+27
-4
lines changed

2 files changed

+27
-4
lines changed

substratevm/src/com.oracle.svm.driver/src/com/oracle/svm/driver/BundleSupport.java

+12-2
Original file line numberDiff line numberDiff line change
@@ -416,8 +416,8 @@ private Path substitutePath(Path origPath, Path destinationDir) {
416416
return origPath;
417417
}
418418

419-
// TODO Report error if overlapping dir-trees are passed in
420-
// TODO add .endsWith(ClasspathUtils.cpWildcardSubstitute) handling (copy whole directory)
419+
// TODO: Report error if overlapping dir-trees are passed in
420+
421421
String origFileName = origPath.getFileName().toString();
422422
int extensionPos = origFileName.lastIndexOf('.');
423423
String baseName;
@@ -447,6 +447,16 @@ private Path substitutePath(Path origPath, Path destinationDir) {
447447
return substitutedPath;
448448
}
449449

450+
Path originalPath(Path substitutedPath) {
451+
Path relativeSubstitutedPath = rootDir.relativize(substitutedPath);
452+
for (Map.Entry<Path, Path> entry : pathSubstitutions.entrySet()) {
453+
if (entry.getValue().equals(relativeSubstitutedPath)) {
454+
return entry.getKey();
455+
}
456+
}
457+
return null;
458+
}
459+
450460
private void copyFiles(Path source, Path target, boolean overwrite) {
451461
nativeImage.showVerboseMessage(nativeImage.isVVerbose(), "> Copy files from " + source + " to " + target);
452462
if (Files.isDirectory(source)) {

substratevm/src/com.oracle.svm.driver/src/com/oracle/svm/driver/NativeImage.java

+15-2
Original file line numberDiff line numberDiff line change
@@ -971,14 +971,27 @@ void handleClassPathAttribute(LinkedHashSet<Path> destination, Path jarFilePath,
971971
String classPathValue = mainAttributes.getValue("Class-Path");
972972
/* Missing Class-Path Attribute is tolerable */
973973
if (classPathValue != null) {
974+
/* Cache expensive reverse lookup in bundle-case */
975+
Path origJarFilePath = null;
974976
for (String cp : classPathValue.split(" +")) {
975977
Path manifestClassPath = Path.of(cp);
976978
if (!manifestClassPath.isAbsolute()) {
977979
/* Resolve relative manifestClassPath against directory containing jar */
978-
manifestClassPath = jarFilePath.getParent().resolve(manifestClassPath);
980+
Path relativeManifestClassPath = manifestClassPath;
981+
manifestClassPath = jarFilePath.getParent().resolve(relativeManifestClassPath);
982+
if (useBundle() && !Files.exists(manifestClassPath)) {
983+
if (origJarFilePath == null) {
984+
origJarFilePath = bundleSupport.originalPath(jarFilePath);
985+
}
986+
if (origJarFilePath == null) {
987+
assert false : "Manifest Class-Path handling failed. No original path for " + jarFilePath + " available.";
988+
break;
989+
}
990+
manifestClassPath = origJarFilePath.getParent().resolve(relativeManifestClassPath);
991+
}
979992
}
980993
/* Invalid entries in Class-Path are allowed (i.e. use strict false) */
981-
addImageClasspathEntry(destination, manifestClassPath, false);
994+
addImageClasspathEntry(destination, manifestClassPath.normalize(), false);
982995
}
983996
}
984997
}

0 commit comments

Comments
 (0)