From 682856d45fa3e96578d844bd58208ac9fa6aa795 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Galder=20Zamarren=CC=83o?= Date: Wed, 1 Sep 2021 17:58:39 +0100 Subject: [PATCH] Process custom image classpath after parsing options #3742 * Custom image classpath processing can be impacted by exclude-config. * Moved the code out of -jar parsing, to avoid the need for specific parameter order. * Without this change, --exclude-config needs to be passed before -jar for it to have an effect. * Added verbose messages for easier debugging of native-image binary. --- .../svm/driver/DefaultOptionHandler.java | 5 ++-- .../com/oracle/svm/driver/NativeImage.java | 30 +++++++++++++++---- 2 files changed, 27 insertions(+), 8 deletions(-) diff --git a/substratevm/src/com.oracle.svm.driver/src/com/oracle/svm/driver/DefaultOptionHandler.java b/substratevm/src/com.oracle.svm.driver/src/com/oracle/svm/driver/DefaultOptionHandler.java index d5c69514cb281..96d74559b2e50 100644 --- a/substratevm/src/com.oracle.svm.driver/src/com/oracle/svm/driver/DefaultOptionHandler.java +++ b/substratevm/src/com.oracle.svm.driver/src/com/oracle/svm/driver/DefaultOptionHandler.java @@ -153,7 +153,9 @@ public boolean consume(ArgumentQueue args) { if (jarFilePathStr == null) { NativeImage.showError(requireValidJarFileMessage); } - handleJarFileArg(nativeImage.canonicalize(Paths.get(jarFilePathStr))); + final Path filePath = nativeImage.canonicalize(Paths.get(jarFilePathStr)); + nativeImage.setJarFilePath(filePath); + handleJarFileArg(filePath); nativeImage.setJarOptionMode(true); return true; case verboseOption: @@ -319,7 +321,6 @@ private void handleJarFileArg(Path filePath) { if (!NativeImage.processJarManifestMainAttributes(filePath, nativeImage::handleMainClassAttribute)) { NativeImage.showError("No manifest in " + filePath); } - nativeImage.addCustomImageClasspath(filePath); } @Override diff --git a/substratevm/src/com.oracle.svm.driver/src/com/oracle/svm/driver/NativeImage.java b/substratevm/src/com.oracle.svm.driver/src/com/oracle/svm/driver/NativeImage.java index 4031fabb0a3e8..7a177bc185de8 100644 --- a/substratevm/src/com.oracle.svm.driver/src/com/oracle/svm/driver/NativeImage.java +++ b/substratevm/src/com.oracle.svm.driver/src/com/oracle/svm/driver/NativeImage.java @@ -253,6 +253,7 @@ private static String oR(OptionKey option) { private boolean diagnostics = false; String diagnosticsDir; private boolean jarOptionMode = false; + private Path jarFilePath; private boolean dryRun = false; private String printFlagsOptionQuery = null; private String printFlagsWithExtraHelpOptionQuery = null; @@ -688,9 +689,18 @@ public void showVerboseMessage(String message) { @Override public boolean isExcluded(Path resourcePath, Path classpathEntry) { + showVerboseMessage(String.format("Attempt to check if resource %s in classpath entry %s should be excluded", resourcePath, classpathEntry)); return excludedConfigs.stream() - .filter(e -> e.jarPattern.matcher(classpathEntry.toString()).find()) - .anyMatch(e -> e.resourcePattern.matcher(resourcePath.toString()).find()); + .filter(e -> regexMatch(classpathEntry, e.jarPattern, "Classpath entry")) + .anyMatch(e -> regexMatch(resourcePath, e.resourcePattern, "Resource path")); + } + + private boolean regexMatch(Path path, Pattern pattern, String prefix) { + final boolean matches = pattern.matcher(path.toString()).find(); + if (verbose) { + showVerboseMessage(String.format("%s %s %s match pattern %s", prefix, path, matches ? "does" : "doesn't", pattern)); + } + return matches; } } @@ -1055,14 +1065,14 @@ static boolean processJarManifestMainAttributes(Path jarFilePath, BiConsumer