Skip to content

Commit

Permalink
Update AwtProcessor.java
Browse files Browse the repository at this point in the history
Update AWTprocessor
  • Loading branch information
kairoh authored Apr 16, 2024
1 parent 0508902 commit 16c4fe4
Showing 1 changed file with 44 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +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.awt.runtime.graal.WindowsAwtFeature;
import io.quarkus.deployment.Feature;
Expand All @@ -18,12 +24,18 @@
import io.quarkus.deployment.builditem.nativeimage.NativeMinimalJavaVersionBuildItem;
import io.quarkus.deployment.builditem.nativeimage.ReflectiveClassBuildItem;
import io.quarkus.deployment.builditem.nativeimage.RuntimeInitializedPackageBuildItem;
import io.quarkus.deployment.builditem.nativeimage.UnsupportedOSBuildItem;
import io.quarkus.deployment.pkg.builditem.NativeImageRunnerBuildItem;
import io.quarkus.deployment.pkg.builditem.ProcessInheritIODisabled;
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 All @@ -47,7 +59,7 @@ UnsupportedOSBuildItem osSupportCheck() {

@BuildStep(onlyIf = NativeOrNativeSourcesBuild.class)
NativeMinimalJavaVersionBuildItem nativeMinimalJavaVersionBuildItem() {
return new NativeMinimalJavaVersionBuildItem(11, 13,
return new NativeMinimalJavaVersionBuildItem("11.0.13",
"AWT: Some MLib related operations, such as filter in awt.image.ConvolveOp will not work. " +
"See https://bugs.openjdk.java.net/browse/JDK-8254024");
}
Expand All @@ -64,6 +76,7 @@ void resources(

@BuildStep(onlyIf = NativeOrNativeSourcesBuild.class)
ReflectiveClassBuildItem setupReflectionClasses() {
//@formatter:off
return ReflectiveClassBuildItem.builder( //
"com.sun.imageio.plugins.common.I18N",
"sun.awt.X11.XToolkit",
Expand All @@ -73,10 +86,12 @@ ReflectiveClassBuildItem setupReflectionClasses() {
"sun.lwawt.macosx.LWCToolkit",
"com.apple.eawt.Application" //
).build();
//@formatter:on
}

@BuildStep(onlyIf = NativeOrNativeSourcesBuild.class)
ReflectiveClassBuildItem setupReflectionClassesWithMethods() {
//@formatter:off
return ReflectiveClassBuildItem.builder( //
"javax.imageio.plugins.tiff.BaselineTIFFTagSet",
"javax.imageio.plugins.tiff.ExifGPSTagSet",
Expand Down Expand Up @@ -105,17 +120,28 @@ ReflectiveClassBuildItem setupReflectionClassesWithMethods() {
"sun.java2d.loops.XorDrawPathANY",
"sun.java2d.loops.XorDrawRectANY",
"sun.java2d.loops.XorDrawGlyphListANY",
"sun.java2d.loops.XorDrawGlyphListAAANY"
//
"sun.java2d.loops.XorDrawGlyphListAAANY" //
).methods().build();
//@formatter:on
}

@BuildStep(onlyIf = NativeOrNativeSourcesBuild.class)
void setupAWTInit(BuildProducer<JniRuntimeAccessBuildItem> jc,
BuildProducer<JniRuntimeAccessMethodBuildItem> jm,
BuildProducer<JniRuntimeAccessFieldBuildItem> jf,
NativeImageRunnerBuildItem nativeImageRunnerBuildItem) {
final GraalVM.Version v = nativeImageRunnerBuildItem.getBuildRunner().getGraalVMVersion();
NativeImageRunnerBuildItem nativeImageRunnerBuildItem,
Optional<ProcessInheritIODisabled> processInheritIODisabled,
Optional<ProcessInheritIODisabledBuildItem> processInheritIODisabledBuildItem) {
nativeImageRunnerBuildItem.getBuildRunner()
.setup(processInheritIODisabled.isPresent() || processInheritIODisabledBuildItem.isPresent());
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 @@ -137,8 +163,17 @@ void setupAWTInit(BuildProducer<JniRuntimeAccessBuildItem> jc,
}

@BuildStep(onlyIf = NativeOrNativeSourcesBuild.class)
JniRuntimeAccessBuildItem setupJava2DClasses(NativeImageRunnerBuildItem nativeImageRunnerBuildItem) {
final GraalVM.Version v = nativeImageRunnerBuildItem.getBuildRunner().getGraalVMVersion();
JniRuntimeAccessBuildItem setupJava2DClasses(NativeImageRunnerBuildItem nativeImageRunnerBuildItem,
Optional<ProcessInheritIODisabled> processInheritIODisabled,
Optional<ProcessInheritIODisabledBuildItem> processInheritIODisabledBuildItem) {
nativeImageRunnerBuildItem.getBuildRunner()
.setup(processInheritIODisabled.isPresent() || processInheritIODisabledBuildItem.isPresent());
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 @@ -307,6 +342,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 @@ -316,6 +352,6 @@ void runtimeInitializedClasses(BuildProducer<RuntimeInitializedPackageBuildItem>
"sun.java2d")
.map(RuntimeInitializedPackageBuildItem::new)
.forEach(runtimeInitilizedPackages::produce);
//@formatter:on
}

}

0 comments on commit 16c4fe4

Please sign in to comment.