Skip to content

Commit

Permalink
[GERONIMO-6858] align defaults to graalvm 21 release
Browse files Browse the repository at this point in the history
  • Loading branch information
rmannibucau committed Jan 23, 2024
1 parent 6c987c3 commit 624ecca
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@
*/
package org.apache.geronimo.arthur.impl.nativeimage;

import static java.lang.annotation.ElementType.FIELD;
import static java.lang.annotation.RetentionPolicy.RUNTIME;
import lombok.Data;

import java.lang.annotation.Retention;
import java.lang.annotation.Target;
import java.util.ArrayList;
import java.util.Collection;

import lombok.Data;
import static java.lang.annotation.ElementType.FIELD;
import static java.lang.annotation.RetentionPolicy.RUNTIME;

@Data
public class ArthurNativeImageConfiguration {
Expand Down Expand Up @@ -76,12 +76,14 @@ public class ArthurNativeImageConfiguration {
@GraalCommandPart(order = 16, template = "--static")
private boolean buildStaticImage = true;

@Deprecated
@GraalCommandPart(order = 17, template = "--allow-incomplete-classpath")
private Boolean allowIncompleteClasspath; // recent version make it a default

@GraalCommandPart(order = 18, template = "--report-unsupported-elements-at-runtime")
private boolean reportUnsupportedElementsAtRuntime = true;

@Deprecated
@GraalCommandPart(order = 19, template = "--enable-all-security-services")
private Boolean enableAllSecurityServices = null;

Expand All @@ -97,17 +99,40 @@ public class ArthurNativeImageConfiguration {
private boolean inheritIO = true;

/**
* @param graalVersion the graalvm version used to complete this configuration, in particular allowIncompleteClasspath and enableAllSecurityServices.
* @param graalVersion the graalvm version used to complete this configuration, in particular allowIncompleteClasspath and enableAllSecurityServices.
* @param hasEmbeddedResources are some META-INF/native-image/ files present.
*/
public void complete(final String graalVersion) {
public void complete(final String graalVersion, final boolean hasEmbeddedResources) {
if (graalVersion != null && (graalVersion.startsWith("21.") || graalVersion.startsWith("20."))) {
if (allowIncompleteClasspath == null) {
allowIncompleteClasspath = true;
allowIncompleteClasspath = !graalVersion.contains("-graal"); // 21*graal* needs it false, previous 21 needs it true :facepalm:
}
if (enableAllSecurityServices == null) {
enableAllSecurityServices = true;
enableAllSecurityServices = !graalVersion.contains("-graal"); // 21*graal* needs it false, previous 21 needs it true :facepalm:
}
} else {
// /!\ we disable this flag since recent graalvm versions don't need it anymore
allowIncompleteClasspath = false;
enableAllSecurityServices = false;
}
if (!Boolean.getBoolean("arthur.unlockexperimentalvmoptions.skip") &&
(customOptions == null ||
(!customOptions.contains("-H:+UnlockExperimentalVMOptions") && !customOptions.contains("-H:-UnlockExperimentalVMOptions"))) &&
hasEmbeddedResources) {
if (customOptions == null) {
customOptions = new ArrayList<>();
}
customOptions.add("-H:+UnlockExperimentalVMOptions");
}
}

/**
* @param graalVersion the graalvm version used to complete this configuration, in particular allowIncompleteClasspath and enableAllSecurityServices.
* @deprecated use {@link #complete(String, boolean)}.
*/
@Deprecated
public void complete(final String graalVersion) {
complete(graalVersion, false);
}

public enum FallbackMode {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,10 @@
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.jar.JarFile;
import java.util.stream.Stream;
import java.util.stream.StreamSupport;
import java.util.zip.ZipEntry;

import static java.lang.ClassLoader.getSystemClassLoader;
import static java.util.Comparator.comparing;
Expand Down Expand Up @@ -190,6 +192,7 @@ public class NativeImageMojo extends ArthurMojo {
/**
* Should incomplete classpath be tolerated.
*/
@Deprecated
@Parameter(property = "arthur.allowIncompleteClasspath")
private Boolean allowIncompleteClasspath;

Expand All @@ -202,6 +205,7 @@ public class NativeImageMojo extends ArthurMojo {
/**
* Should security services be included.
*/
@Deprecated
@Parameter(property = "arthur.enableAllSecurityServices")
private Boolean enableAllSecurityServices;

Expand Down Expand Up @@ -390,7 +394,21 @@ public void execute() {
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);
configuration.complete(graalVersion, classpathEntries.values().stream()
.anyMatch(p -> {
if (Files.isDirectory(p)) {
return Files.exists(p.resolve("META-INF/native-image"));
}
if (Files.exists(p)) {
try (final JarFile jar = new JarFile(p.toFile())) {
final ZipEntry entry = jar.getEntry("META-INF/native-image");
return entry != null && entry.isDirectory();
} catch (final IOException e) {
return false;
}
}
return false;
}));

if (nativeImage == null) {
final SdkmanGraalVMInstaller graalInstaller = createInstaller();
Expand Down Expand Up @@ -481,10 +499,10 @@ protected Class<?> loadClass(final String name, final boolean resolve) throws Cl
@Override
protected Iterable<ArthurExtension> loadExtensions() {
return Stream.concat(
// classloading bypasses them since TCCL is a fake loader with the JVM as parent
Stream.of(new AnnotationExtension(), new MavenArthurExtension()),
// graalextensions
StreamSupport.stream(super.loadExtensions().spliterator(), false))
// classloading bypasses them since TCCL is a fake loader with the JVM as parent
Stream.of(new AnnotationExtension(), new MavenArthurExtension()),
// graalextensions
StreamSupport.stream(super.loadExtensions().spliterator(), false))
// ensure we dont duplicate any extension
.distinct()
.sorted(comparing(ArthurExtension::order))
Expand Down Expand Up @@ -547,22 +565,22 @@ private Stream<? extends Map.Entry<? extends Artifact, Path>> findClasspathFiles
final Artifact artifactGav = new org.apache.maven.artifact.DefaultArtifact(
groupId, artifactId, version, "compile", packaging, null, new DefaultArtifactHandler());
return Stream.concat(Stream.concat(
usePackagedArtifact ?
Stream.of(jar).map(j -> new AbstractMap.SimpleImmutableEntry<>(artifactGav, j.toPath())) :
Stream.concat(
Stream.of(classes).map(j -> new AbstractMap.SimpleImmutableEntry<>(artifactGav, j.toPath())),
supportTestArtifacts ? Stream.of(testClasses).<Map.Entry<Artifact, Path>>map(j ->
new AbstractMap.SimpleImmutableEntry<>(new org.apache.maven.artifact.DefaultArtifact(
groupId, artifactId, version, "compile", packaging, "test", new DefaultArtifactHandler()),
j.toPath())) :
Stream.empty()),
project.getArtifacts().stream()
.filter(a -> !excludedArtifacts.contains(a.getGroupId() + ':' + a.getArtifactId()))
.filter(this::handleTestInclusion)
.filter(this::isNotSvm)
.filter(a -> supportedTypes.contains(a.getType()))
.map(a -> new AbstractMap.SimpleImmutableEntry<>(a, a.getFile().toPath()))),
resolveExtension())
usePackagedArtifact ?
Stream.of(jar).map(j -> new AbstractMap.SimpleImmutableEntry<>(artifactGav, j.toPath())) :
Stream.concat(
Stream.of(classes).map(j -> new AbstractMap.SimpleImmutableEntry<>(artifactGav, j.toPath())),
supportTestArtifacts ? Stream.of(testClasses).<Map.Entry<Artifact, Path>>map(j ->
new AbstractMap.SimpleImmutableEntry<>(new org.apache.maven.artifact.DefaultArtifact(
groupId, artifactId, version, "compile", packaging, "test", new DefaultArtifactHandler()),
j.toPath())) :
Stream.empty()),
project.getArtifacts().stream()
.filter(a -> !excludedArtifacts.contains(a.getGroupId() + ':' + a.getArtifactId()))
.filter(this::handleTestInclusion)
.filter(this::isNotSvm)
.filter(a -> supportedTypes.contains(a.getType()))
.map(a -> new AbstractMap.SimpleImmutableEntry<>(a, a.getFile().toPath()))),
resolveExtension())
.filter(e -> Files.exists(e.getValue()));
}

Expand Down

0 comments on commit 624ecca

Please sign in to comment.