[GERONIMO-6836] avoid warning about allow-incomplete-classpath and enableAllSecurityS... master
authorRomain Manni-Bucau <rmannibucau@gmail.com>
Thu, 9 Jun 2022 13:06:36 +0000 (15:06 +0200)
committerRomain Manni-Bucau <rmannibucau@gmail.com>
Thu, 9 Jun 2022 13:06:36 +0000 (15:06 +0200)
arthur-impl/src/main/java/org/apache/geronimo/arthur/impl/nativeimage/ArthurNativeImageConfiguration.java
arthur-impl/src/test/java/org/apache/geronimo/arthur/impl/nativeimage/CommandGeneratorTest.java
arthur-maven-plugin/src/main/java/org/apache/geronimo/arthur/maven/mojo/ArthurMojo.java
arthur-maven-plugin/src/main/java/org/apache/geronimo/arthur/maven/mojo/NativeImageMojo.java

index 68f874f391af3fe445480c9935cc821bf0e326e4..f381361164a4ed1cb2e6f8949e1a577724ad73e7 100644 (file)
@@ -77,7 +77,7 @@ public class ArthurNativeImageConfiguration {
     private boolean buildStaticImage = true;
 
     @GraalCommandPart(order = 17, template = "--allow-incomplete-classpath")
-    private boolean allowIncompleteClasspath = true;
+    private Boolean allowIncompleteClasspath; // recent version make it a default
 
     @GraalCommandPart(order = 18, template = "--report-unsupported-elements-at-runtime")
     private boolean reportUnsupportedElementsAtRuntime = true;
@@ -96,6 +96,20 @@ public class ArthurNativeImageConfiguration {
 
     private boolean inheritIO = true;
 
+    /**
+     * @param graalVersion the graalvm version used to complete this configuration, in particular allowIncompleteClasspath and enableAllSecurityServices.
+     */
+    public void complete(final String graalVersion) {
+        if (graalVersion != null && (graalVersion.startsWith("21.") || graalVersion.startsWith("20."))) {
+            if (allowIncompleteClasspath == null) {
+                allowIncompleteClasspath = true;
+            }
+            if (enableAllSecurityServices == null) {
+                enableAllSecurityServices = true;
+            }
+        }
+    }
+
     public enum FallbackMode {
         no, auto, force
     }
index 820752dd69f207e37b1a04fa56fe52b810a48997..e7940398c39ebb9ff862f619fbc1c3713a399eca 100644 (file)
@@ -108,7 +108,7 @@ class CommandGeneratorTest {
                                 "native-image", "-classpath",
                                 "-H:MaxRuntimeCompileMethods=1000", "-H:+EnforceMaxRuntimeCompileMethods",
                                 "-H:+AddAllCharsets", "-H:+ReportExceptionStackTraces",
-                                "--no-fallback", "--static", "--allow-incomplete-classpath",
+                                "--no-fallback", "--static",
                                 "--report-unsupported-elements-at-runtime",
                                 "main", "main.graal.exec")),
                 new Case(
@@ -117,7 +117,7 @@ class CommandGeneratorTest {
                                 "native-image", "-classpath", "foo" + File.pathSeparator + "bar",
                                 "-H:MaxRuntimeCompileMethods=1000", "-H:+EnforceMaxRuntimeCompileMethods",
                                 "-H:+AddAllCharsets", "-H:+ReportExceptionStackTraces",
-                                "--no-fallback", "--static", "--allow-incomplete-classpath",
+                                "--no-fallback", "--static",
                                 "--report-unsupported-elements-at-runtime",
                                 "main", "main.graal.exec")),
                 new Case(
index 669a78ddc3ed70fd1ae81d18dde137b1c2b745b2..444828db29cdc2153f47c42da3db138f968b1092 100644 (file)
@@ -80,7 +80,7 @@ public abstract class ArthurMojo extends AbstractMojo {
      * It contains the graal version and can be suffixed by the graal java version prefixed with "r" (as on sdkman).
      */
     @Parameter(property = "arthur.graalVersion", defaultValue = "20.3.0.r8")
-    private String graalVersion;
+    protected String graalVersion;
 
     /**
      * In case Graal must be downloaded to get native-image, which platform to download, auto will handle it for you.
index 1818793cdd900708af139e5a26f8883a8f9ee8fa..81b3c42989cb3c3c67b95542a0a25300195a5304 100644 (file)
@@ -79,6 +79,7 @@ import java.util.stream.StreamSupport;
 import static java.lang.ClassLoader.getSystemClassLoader;
 import static java.util.Comparator.comparing;
 import static java.util.Optional.ofNullable;
+import static java.util.stream.Collectors.joining;
 import static java.util.stream.Collectors.toList;
 import static java.util.stream.Collectors.toMap;
 import static lombok.AccessLevel.PROTECTED;
@@ -189,8 +190,8 @@ public class NativeImageMojo extends ArthurMojo {
     /**
      * Should incomplete classpath be tolerated.
      */
-    @Parameter(property = "arthur.allowIncompleteClasspath", defaultValue = "true")
-    private boolean allowIncompleteClasspath;
+    @Parameter(property = "arthur.allowIncompleteClasspath")
+    private Boolean allowIncompleteClasspath;
 
     /**
      * Should unsupported element be reported at runtime or not. It is not a recommended option but it is often needed.
@@ -201,8 +202,8 @@ public class NativeImageMojo extends ArthurMojo {
     /**
      * Should security services be included.
      */
-    @Parameter(property = "arthur.enableAllSecurityServices", defaultValue = "true")
-    private boolean enableAllSecurityServices;
+    @Parameter(property = "arthur.enableAllSecurityServices")
+    private Boolean enableAllSecurityServices;
 
     /**
      * Which main to compile.
@@ -389,6 +390,8 @@ public class NativeImageMojo extends ArthurMojo {
         final Map<Artifact, Path> classpathEntries = findClasspathFiles().collect(toMap(Map.Entry::getKey, Map.Entry::getValue, (a, b) -> a));
 
         final ArthurNativeImageConfiguration configuration = getConfiguration(classpathEntries.values());
+        configuration.complete(graalVersion);
+
         if (nativeImage == null) {
             final SdkmanGraalVMInstaller graalInstaller = createInstaller();
             final Path graalHome = graalInstaller.install();
@@ -408,6 +411,9 @@ public class NativeImageMojo extends ArthurMojo {
         final ClassLoader parentLoader = useTcclAsScanningParentClassLoader ?
                 thread.getContextClassLoader() : getSystemClassLoader();
         final ClassLoader oldLoader = thread.getContextClassLoader();
+        if (getLog().isDebugEnabled()) {
+            getLog().debug("Classpath:\n" + Stream.of(urls).map(URL::toExternalForm).collect(joining("\n")));
+        }
         try (final URLClassLoader loader = new URLClassLoader(urls, parentLoader) {
             @Override
             protected Class<?> loadClass(final String name, final boolean resolve) throws ClassNotFoundException {