Skip to content

Commit

Permalink
[GR-44027] Fix manifest Class-Path handling of relative paths in bund…
Browse files Browse the repository at this point in the history
…le-case
  • Loading branch information
olpaw committed Mar 2, 2023
1 parent e8f4769 commit cc368d5
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -416,8 +416,8 @@ private Path substitutePath(Path origPath, Path destinationDir) {
return origPath;
}

// TODO Report error if overlapping dir-trees are passed in
// TODO add .endsWith(ClasspathUtils.cpWildcardSubstitute) handling (copy whole directory)
// TODO: Report error if overlapping dir-trees are passed in

String origFileName = origPath.getFileName().toString();
int extensionPos = origFileName.lastIndexOf('.');
String baseName;
Expand Down Expand Up @@ -447,6 +447,16 @@ private Path substitutePath(Path origPath, Path destinationDir) {
return substitutedPath;
}

Path originalPath(Path substitutedPath) {
Path relativeSubstitutedPath = rootDir.relativize(substitutedPath);
for (Map.Entry<Path, Path> entry : pathSubstitutions.entrySet()) {
if (entry.getValue().equals(relativeSubstitutedPath)) {
return entry.getKey();
}
}
return null;
}

private void copyFiles(Path source, Path target, boolean overwrite) {
nativeImage.showVerboseMessage(nativeImage.isVVerbose(), "> Copy files from " + source + " to " + target);
if (Files.isDirectory(source)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -971,14 +971,27 @@ void handleClassPathAttribute(LinkedHashSet<Path> destination, Path jarFilePath,
String classPathValue = mainAttributes.getValue("Class-Path");
/* Missing Class-Path Attribute is tolerable */
if (classPathValue != null) {
/* Cache expensive reverse lookup in bundle-case */
Path origJarFilePath = null;
for (String cp : classPathValue.split(" +")) {
Path manifestClassPath = Path.of(cp);
if (!manifestClassPath.isAbsolute()) {
/* Resolve relative manifestClassPath against directory containing jar */
manifestClassPath = jarFilePath.getParent().resolve(manifestClassPath);
Path relativeManifestClassPath = manifestClassPath;
manifestClassPath = jarFilePath.getParent().resolve(relativeManifestClassPath);
if (useBundle() && !Files.exists(manifestClassPath)) {
if (origJarFilePath == null) {
origJarFilePath = bundleSupport.originalPath(jarFilePath);
}
if (origJarFilePath == null) {
assert false : "Manifest Class-Path handling failed. No original path for " + jarFilePath + " available.";
break;
}
manifestClassPath = origJarFilePath.getParent().resolve(relativeManifestClassPath);
}
}
/* Invalid entries in Class-Path are allowed (i.e. use strict false) */
addImageClasspathEntry(destination, manifestClassPath, false);
addImageClasspathEntry(destination, manifestClassPath.normalize(), false);
}
}
}
Expand Down

0 comments on commit cc368d5

Please sign in to comment.