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

Support AWT image resize via new AWT extension #20239

Merged
merged 1 commit into from
Sep 23, 2021
Merged
Show file tree
Hide file tree
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
8 changes: 7 additions & 1 deletion .github/native-tests.json
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,12 @@
"timeout": 70,
"test-modules": "devtools-registry-client",
"os-name": "ubuntu-latest"
}
},
{
"category": "AWT, ImageIO and Java2D",
"timeout": 20,
"test-modules": "awt",
"os-name": "ubuntu-latest"
}
]
}
10 changes: 10 additions & 0 deletions bom/application/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5414,6 +5414,16 @@
<artifactId>quarkus-vertx-web-deployment</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-awt</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-awt-deployment</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
</dependencyManagement>

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package io.quarkus.runtime.graal;

import org.graalvm.nativeimage.ImageSingletons;
import org.graalvm.nativeimage.hosted.Feature;
import org.graalvm.nativeimage.impl.RuntimeClassInitializationSupport;

import com.oracle.svm.core.annotate.AutomaticFeature;

/**
* Technically, this should live in extensions/awt,
* but currently all code that relies on JAXB
* requires at the very least sun.java2d package to be runtime initialized.
*
* Having sun.java2d code initialized at build time caused issues,
* which is why a substitution was set in place to avoid such code making it to the binary:
* https://github.com/quarkusio/quarkus/commit/ef87e5567cf3ac462a3f12aad4b5b530d9220223
*
* So, as long as JAXB graphics code has not been excluded completely from JAXB,
* it is safer to define all image related packages to be runtime initialized directly in core.
*/
@AutomaticFeature
public class AwtFeature implements Feature {
@Override
public void afterRegistration(AfterRegistrationAccess access) {
final RuntimeClassInitializationSupport runtimeInit = ImageSingletons.lookup(RuntimeClassInitializationSupport.class);
final String reason = "Quarkus run time init for AWT";
runtimeInit.initializeAtRunTime("com.sun.imageio", reason);
runtimeInit.initializeAtRunTime("java.awt", reason);
runtimeInit.initializeAtRunTime("javax.imageio", reason);
runtimeInit.initializeAtRunTime("sun.awt", reason);
runtimeInit.initializeAtRunTime("sun.font", reason);
runtimeInit.initializeAtRunTime("sun.java2d", reason);
}
}

This file was deleted.

13 changes: 13 additions & 0 deletions devtools/bom-descriptor-json/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,19 @@
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-awt</artifactId>
<version>${project.version}</version>
<type>pom</type>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>*</groupId>
<artifactId>*</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-azure-functions-http</artifactId>
Expand Down
13 changes: 13 additions & 0 deletions docs/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,19 @@
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-awt-deployment</artifactId>
<version>${project.version}</version>
<type>pom</type>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>*</groupId>
<artifactId>*</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-azure-functions-http-deployment</artifactId>
Expand Down
43 changes: 43 additions & 0 deletions extensions/awt/deployment/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-awt-parent</artifactId>
<version>999-SNAPSHOT</version>
</parent>
<artifactId>quarkus-awt-deployment</artifactId>
<name>Quarkus - Awt - Deployment</name>
<dependencies>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-arc-deployment</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-awt</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-junit5-internal</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<annotationProcessorPaths>
<path>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-extension-processor</artifactId>
<version>${project.version}</version>
</path>
</annotationProcessorPaths>
</configuration>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
package io.quarkus.awt.deployment;

import io.quarkus.deployment.annotations.BuildStep;
import io.quarkus.deployment.builditem.FeatureBuildItem;
import io.quarkus.deployment.builditem.nativeimage.JniRuntimeAccessBuildItem;
import io.quarkus.deployment.builditem.nativeimage.ReflectiveClassBuildItem;

class AwtProcessor {
private static final String FEATURE = "awt";

@BuildStep
ReflectiveClassBuildItem setupReflectionClasses() {
return new ReflectiveClassBuildItem(false, false,
"sun.awt.X11GraphicsEnvironment",
"sun.awt.X11.XToolkit");
}

@BuildStep
JniRuntimeAccessBuildItem setupJava2DClasses() {
return new JniRuntimeAccessBuildItem(true, true, true,
"java.awt.AlphaComposite",
"java.awt.Color",
"java.awt.geom.AffineTransform",
"java.awt.geom.Path2D",
"java.awt.geom.Path2D$Float",
"java.awt.image.BufferedImage",
"java.awt.image.ColorModel",
"java.awt.image.IndexColorModel",
"java.awt.image.Raster",
"java.awt.image.SampleModel",
"java.awt.image.SinglePixelPackedSampleModel",
"sun.awt.SunHints",
"sun.awt.image.BufImgSurfaceData$ICMColorData",
"sun.awt.image.ByteComponentRaster",
"sun.awt.image.BytePackedRaster",
"sun.awt.image.ImageRepresentation",
"sun.awt.image.IntegerComponentRaster",
"sun.java2d.Disposer",
"sun.java2d.InvalidPipeException",
"sun.java2d.NullSurfaceData",
"sun.java2d.SunGraphics2D",
"sun.java2d.SurfaceData",
"sun.java2d.loops.Blit",
"sun.java2d.loops.BlitBg",
"sun.java2d.loops.CompositeType",
"sun.java2d.loops.DrawGlyphList",
"sun.java2d.loops.DrawGlyphListAA",
"sun.java2d.loops.DrawGlyphListLCD",
"sun.java2d.loops.DrawLine",
"sun.java2d.loops.DrawParallelogram",
"sun.java2d.loops.DrawPath",
"sun.java2d.loops.DrawPolygons",
"sun.java2d.loops.DrawRect",
"sun.java2d.loops.FillParallelogram",
"sun.java2d.loops.FillPath",
"sun.java2d.loops.FillRect",
"sun.java2d.loops.FillSpans",
"sun.java2d.loops.GraphicsPrimitive",
"sun.java2d.loops.GraphicsPrimitiveMgr",
"sun.java2d.loops.GraphicsPrimitive[]",
"sun.java2d.loops.MaskBlit",
"sun.java2d.loops.MaskFill",
"sun.java2d.loops.ScaledBlit",
"sun.java2d.loops.SurfaceType",
"sun.java2d.loops.TransformHelper",
"sun.java2d.loops.XORComposite",
"sun.java2d.pipe.Region",
"sun.java2d.pipe.RegionIterator");
}

@BuildStep
FeatureBuildItem feature() {
return new FeatureBuildItem(FEATURE);
}
}
17 changes: 17 additions & 0 deletions extensions/awt/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-extensions-parent</artifactId>
<version>999-SNAPSHOT</version>
</parent>
<artifactId>quarkus-awt-parent</artifactId>
<packaging>pom</packaging>
<name>Quarkus - Awt - Parent</name>
<modules>
<module>deployment</module>
<module>runtime</module>
</modules>
</project>
44 changes: 44 additions & 0 deletions extensions/awt/runtime/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-awt-parent</artifactId>
<version>999-SNAPSHOT</version>
</parent>
<artifactId>quarkus-awt</artifactId>
<name>Quarkus - Awt - Runtime</name>
<description>Enable AWT and Java2D usage</description>
<dependencies>
gastaldi marked this conversation as resolved.
Show resolved Hide resolved
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-arc</artifactId>
</dependency>
<dependency>
<groupId>org.graalvm.nativeimage</groupId>
<artifactId>svm</artifactId>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-bootstrap-maven-plugin</artifactId>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<annotationProcessorPaths>
<path>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-extension-processor</artifactId>
<version>${project.version}</version>
</path>
</annotationProcessorPaths>
</configuration>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
name: AWT
metadata:
keywords:
- awt
- font
- java2d
- image
- imageio
# guide: ...
categories:
- "miscellaneous"
status: "preview"
2 changes: 2 additions & 0 deletions extensions/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,8 @@

<!-- Relocations -->
<module>vertx-web</module>

<module>awt</module>
</modules>

<build>
Expand Down
4 changes: 4 additions & 0 deletions extensions/tika/deployment/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@
<groupId>io.quarkus</groupId>
<artifactId>quarkus-arc-deployment</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-awt-deployment</artifactId>
</dependency>
<!-- the tika parsers depend on http-client -->
<dependency>
<groupId>io.quarkus</groupId>
Expand Down
4 changes: 4 additions & 0 deletions extensions/tika/runtime/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@
<groupId>io.quarkus</groupId>
<artifactId>quarkus-arc</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-awt</artifactId>
</dependency>
<!-- the tika parsers depend on http-client -->
<dependency>
<groupId>io.quarkus</groupId>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package io.quarkus.tika.runtime.graal;

import org.graalvm.nativeimage.ImageSingletons;
import org.graalvm.nativeimage.hosted.Feature;
import org.graalvm.nativeimage.impl.RuntimeClassInitializationSupport;

import com.oracle.svm.core.annotate.AutomaticFeature;

@AutomaticFeature
public class TikaFeature implements Feature {
@Override
public void afterRegistration(AfterRegistrationAccess access) {
final RuntimeClassInitializationSupport runtimeInit = ImageSingletons.lookup(RuntimeClassInitializationSupport.class);
final String reason = "Quarkus run time init for Apache Tika";
runtimeInit.initializeAtRunTime("org.apache.pdfbox", reason);
runtimeInit.initializeAtRunTime("org.apache.poi.hssf.util", reason);
runtimeInit.initializeAtRunTime("org.apache.poi.ss.format", reason);
}
}
Loading