From ac0f115d96a9c1e5cb24f35c29e4e484696ffc1d 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 | 34 ++++++++++++++----- 2 files changed, 29 insertions(+), 10 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 46fcaf8ec226..2d36ede1cb05 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 @@ -154,7 +154,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: @@ -320,7 +322,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 c2f8d8f5886e..9e8037d70e24 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 moduleOptionMode = false; private boolean dryRun = false; private String printFlagsOptionQuery = null; @@ -689,9 +690,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; } } @@ -1056,14 +1066,14 @@ static boolean processJarManifestMainAttributes(Path jarFilePath, BiConsumer