Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AwtProcessor use the default native-image version if necessary #37629

Merged
merged 1 commit into from
Dec 9, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
package io.quarkus.awt.deployment;

import static io.quarkus.deployment.builditem.nativeimage.UnsupportedOSBuildItem.Os.WINDOWS;
import static io.quarkus.deployment.pkg.steps.GraalVM.Version.CURRENT;

import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.stream.Stream;

import org.jboss.logging.Logger;

import io.quarkus.awt.runtime.graal.DarwinAwtFeature;
import io.quarkus.deployment.Feature;
import io.quarkus.deployment.annotations.BuildProducer;
Expand All @@ -26,9 +29,12 @@
import io.quarkus.deployment.pkg.builditem.ProcessInheritIODisabledBuildItem;
import io.quarkus.deployment.pkg.steps.GraalVM;
import io.quarkus.deployment.pkg.steps.NativeOrNativeSourcesBuild;
import io.quarkus.deployment.pkg.steps.NoopNativeImageBuildRunner;

class AwtProcessor {

private static final Logger log = Logger.getLogger(AwtProcessor.class);

@BuildStep
FeatureBuildItem feature() {
return new FeatureBuildItem(Feature.AWT);
Expand Down Expand Up @@ -74,6 +80,7 @@ ReflectiveClassBuildItem setupReflectionClasses() {

@BuildStep(onlyIf = NativeOrNativeSourcesBuild.class)
ReflectiveClassBuildItem setupReflectionClassesWithMethods() {
//@formatter:off
return ReflectiveClassBuildItem.builder(
"javax.imageio.plugins.tiff.BaselineTIFFTagSet",
"javax.imageio.plugins.tiff.ExifGPSTagSet",
Expand All @@ -91,7 +98,9 @@ ReflectiveClassBuildItem setupReflectionClassesWithMethods() {
"sun.java2d.loops.SetDrawRectANY",
"sun.java2d.loops.SetFillPathANY",
"sun.java2d.loops.SetFillRectANY",
"sun.java2d.loops.SetFillSpansANY").methods().build();
"sun.java2d.loops.SetFillSpansANY"
).methods().build();
//@formatter:on
}

@BuildStep(onlyIf = NativeOrNativeSourcesBuild.class)
Expand All @@ -103,7 +112,14 @@ void setupAWTInit(BuildProducer<JniRuntimeAccessBuildItem> jc,
Optional<ProcessInheritIODisabledBuildItem> processInheritIODisabledBuildItem) {
nativeImageRunnerBuildItem.getBuildRunner()
.setup(processInheritIODisabled.isPresent() || processInheritIODisabledBuildItem.isPresent());
final GraalVM.Version v = nativeImageRunnerBuildItem.getBuildRunner().getGraalVMVersion();
final GraalVM.Version v;
if (nativeImageRunnerBuildItem.getBuildRunner() instanceof NoopNativeImageBuildRunner) {
v = CURRENT;
log.warnf("native-image is not installed. " +
"Using the default %s version as a reference to build native-sources step.", v.getVersionAsString());
} else {
v = nativeImageRunnerBuildItem.getBuildRunner().getGraalVMVersion();
}
// Dynamically loading shared objects instead
// of baking in static libs: https://github.com/oracle/graal/issues/4921
if (v.compareTo(GraalVM.Version.VERSION_23_0_0) >= 0) {
Expand All @@ -130,7 +146,12 @@ JniRuntimeAccessBuildItem setupJava2DClasses(NativeImageRunnerBuildItem nativeIm
Optional<ProcessInheritIODisabledBuildItem> processInheritIODisabledBuildItem) {
nativeImageRunnerBuildItem.getBuildRunner()
.setup(processInheritIODisabled.isPresent() || processInheritIODisabledBuildItem.isPresent());
final GraalVM.Version v = nativeImageRunnerBuildItem.getBuildRunner().getGraalVMVersion();
final GraalVM.Version v;
if (nativeImageRunnerBuildItem.getBuildRunner() instanceof NoopNativeImageBuildRunner) {
v = CURRENT;
} else {
v = nativeImageRunnerBuildItem.getBuildRunner().getGraalVMVersion();
}
final List<String> classes = new ArrayList<>();
classes.add("com.sun.imageio.plugins.jpeg.JPEGImageReader");
classes.add("com.sun.imageio.plugins.jpeg.JPEGImageWriter");
Expand Down Expand Up @@ -283,6 +304,7 @@ void runtimeInitializedClasses(BuildProducer<RuntimeInitializedPackageBuildItem>
* Note that this initialization is not enough if user wants to deserialize actual images
* (e.g. from XML). AWT Extension must be loaded for decoding JDK supported image formats.
*/
//@formatter:off
Stream.of(
"com.sun.imageio",
"java.awt",
Expand All @@ -292,5 +314,6 @@ void runtimeInitializedClasses(BuildProducer<RuntimeInitializedPackageBuildItem>
"sun.java2d")
.map(RuntimeInitializedPackageBuildItem::new)
.forEach(runtimeInitilizedPackages::produce);
//@formatter:on
}
}
Loading