Fix: Include charset resources in native image for Cp1252 support - #227
Fix: Include charset resources in native image for Cp1252 support#227bmarwell wants to merge 10 commits into
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #227 +/- ##
=======================================
Coverage 72.11% 72.11%
=======================================
Files 26 26
Lines 563 563
Branches 52 52
=======================================
Hits 406 406
Misses 128 128
Partials 29 29 ☔ View full report in Codecov by Harness. |
53223de to
6181be0
Compare
bmarwell
left a comment
There was a problem hiding this comment.
- The test files were committed as UTF-8, and it would need to be converted before testing starts
- The tests actually only run against the Java version. Instead they need to run against the current binary version.
Fixes #190 - Add charset provider SPI and resource patterns to resource-config.json - Include sun/nio/cs/* for core charsets (UTF-8, ASCII, ISO-8859-1) - Include sun/nio/cs/ext/* for extended charsets (Cp1252, Windows-1252) - Add integration test CharsetSupportIT to verify charset availability - Add test resource file with Cp1252 characters The -H:+AddAllCharsets flag includes charset classes but not the required resource files (SPI metadata and charset mapping data). This change explicitly includes those resources to ensure charsets like Cp1252 are available at runtime in the native image. Tested on: Linux (current platform) Requires testing on: Windows to verify Cp1252 support
6181be0 to
e381106
Compare
bmarwell
left a comment
There was a problem hiding this comment.
I have reviewed the PR and have a few suggestions for improvement.
Summary of Suggestions
- Rename Test Class: Rename to to better reflect its purpose as a native image integration test.
- Refactor Duplication: and the new native test share significant logic for setup and path resolution. These should be moved to a base class or utility.
- Verify Maven Wrapper: Ensure the update to Maven 4 RC-5 is intentional.
- Standardize Scripts: The additions look good for cross-platform stability.
I will add specific line comments with suggested changes.
bmarwell
left a comment
There was a problem hiding this comment.
I have reviewed the PR and have a few suggestions for improvement.
Summary of Suggestions
- Rename Test Class: Rename CharsetSupportAdditionalIT to CharsetSupportNativeIT to better reflect its purpose as a native image integration test.
- Refactor Duplication: CharsetSupportIT and the new native test share significant logic for setup and path resolution. These should be moved to a base class or utility.
- Verify Maven Wrapper: Ensure the update to Maven 4 RC-5 is intentional.
- Standardize Scripts: The .gitattributes additions look good for cross-platform stability.
I will add specific line comments with suggested changes.
bmarwell
left a comment
There was a problem hiding this comment.
-p integration-tests/jreleaser-builtin/src/test/java/io/github/bmarwell/jfmt/its/jreleaser/builtin/CharsetSupportAdditionalIT.java -b "Suggestion: Rename this class to 'CharsetSupportNativeIT' as requested. Also, we should consider refactoring the common setup logic shared with CharsetSupportIT into a base class."
bmarwell
left a comment
There was a problem hiding this comment.
Suggestion: Rename 'CharsetSupportAdditionalIT' to 'CharsetSupportNativeIT' as requested. Also, we should consider refactoring the common setup logic shared with 'CharsetSupportIT' into a base class to reduce duplication.
bmarwell
left a comment
There was a problem hiding this comment.
Confirm if the Maven Wrapper update from RC-4 to RC-5 is intentional and verified as stable for the project.
|
Look at this run: https://github.com/bmarwell/jfmt/actions/runs/28373430791/job/84057044002?pr=227 The output is: as well as Further maven output: Find the cause and fix the workflow. |
Fixed in a15a59e. Cause: the Linux smoke-test step ran Fix: updated the smoke-test Maven call to |
There was a problem hiding this comment.
Pull request overview
This PR addresses #190 by ensuring extended charsets (notably Windows-1252 / Cp1252) work in the GraalVM native image by explicitly including the required charset provider resources, and by adding integration tests that exercise Cp1252 input through the native binary.
Changes:
- Extend
cliGraalVM native-image resource configuration to include charset SPI metadata and charset provider resources. - Add integration tests and a Cp1252-containing Java source fixture to validate
print,list, anddiffbehavior withoutUnsupportedCharsetException. - Add CI “smoke test” steps and Maven properties to pass native-profile intent into integration test runs.
Reviewed changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
pom.xml |
Introduces a default jfmt.native.profile.active property and toggles it in the native profile for test gating. |
integration-tests/pom.xml |
Centralizes jfmt.directory and propagates jfmt.native.profile.active into IT JVM system properties. |
integration-tests/jreleaser-builtin/src/test/resources/charset/Cp1252Test.java |
Adds a fixture containing Cp1252-specific characters used by the integration tests. |
integration-tests/jreleaser-builtin/src/test/java/io/github/bmarwell/jfmt/its/jreleaser/builtin/NativeItConditions.java |
Adds assumptions to run charset native ITs only when the native profile is active and on GraalVM. |
integration-tests/jreleaser-builtin/src/test/java/io/github/bmarwell/jfmt/its/jreleaser/builtin/CharsetSupportNativeIT.java |
Adds native-binary-focused charset tests for print and diff. |
integration-tests/jreleaser-builtin/src/test/java/io/github/bmarwell/jfmt/its/jreleaser/builtin/CharsetSupportIT.java |
Adds broader charset integration coverage across print, list, and diff. |
integration-tests/jreleaser-builtin/src/test/java/io/github/bmarwell/jfmt/its/jreleaser/builtin/AbstractCharsetIT.java |
Adds shared setup to generate a Windows-1252 encoded test file for the ITs. |
integration-tests/it-extension/src/main/java/io/github/bmarwell/jfmt/its/extension/JFmtExtension.java |
Adjusts the spawned process environment (but currently does so in a platform-dependent way). |
cli/src/main/graalvm-native/resource-config.json |
Adds charset-related resource include patterns for native-image. |
.github/workflows/build-native.yml |
Adds smoke test steps that run the native binary and execute the relevant integration tests on Linux. |
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> Signed-off-by: Benjamin Marwell <bmarwell@apache.org>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> Signed-off-by: Benjamin Marwell <bmarwell@apache.org>
| <configuration> | ||
| <systemPropertyVariables> | ||
| <jfmt.directory>${project.build.directory}/jfmt/jfmt-${project.version}</jfmt.directory> | ||
| <jfmt.directory>${jfmt.directory}</jfmt.directory> | ||
| <jfmt.native.profile.active>${jfmt.native.profile.active}</jfmt.native.profile.active> | ||
| </systemPropertyVariables> | ||
| </configuration> |
There was a problem hiding this comment.
Fixed in the latest commit by adding combine.self="merge" to the failsafe <systemPropertyVariables> element, matching the pattern already used for surefire.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> Signed-off-by: Benjamin Marwell <bmarwell@apache.org>
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 10 out of 10 changed files in this pull request and generated no new comments.
Comments suppressed due to low confidence (2)
integration-tests/jreleaser-builtin/src/test/java/io/github/bmarwell/jfmt/its/jreleaser/builtin/CharsetSupportNativeIT.java:15
CharsetSupportNativeITduplicates the coverage already provided byCharsetSupportIT(same base class, same commands, overlapping assertions). Keeping both will increase native-IT runtime and maintenance cost; consider merging them into a single test class (or splitting into JVM vs native tests explicitly).
@JFmtTest
class CharsetSupportNativeIT extends AbstractCharsetIT {
@Test
@JFmtTest(args = { "print", "target/test-classes/charset/Cp1252Test.java" })
.github/workflows/build-native.yml:288
- The Windows smoke-test block exits after
--help, so the new charset native integration tests are never exercised on Windows (the platform where #190 was reported). Consider running the sameintegration-tests/jreleaser-builtinverify step here before exiting.
JFMT_BAT=$(cygpath -w "$JFMT_DIR/bin/jfmt.bat")
cmd.exe /c "\"$JFMT_BAT\" --help"
exit 0
Description
Fixes #190 - UnsupportedCharsetException: Cp1252 with Windows image
This PR adds explicit charset resource inclusion to the GraalVM native image configuration to ensure Windows-1252 (Cp1252) and other extended charsets are available at runtime.
Problem
The existing
-H:+AddAllCharsetsflag innative-image.propertiesincludes charset classes but does not automatically include the required resource files (SPI metadata and charset mapping data). This causesUnsupportedCharsetException: Cp1252when the Eclipse JDT Platform tries to useCharset.forName("Cp1252")on Windows systems.Solution
Added three resource patterns to
resource-config.json:META-INF/services/java.nio.charset.spi.CharsetProvider- Service provider configurationsun/nio/cs/*- Core charset providers (UTF-8, ASCII, ISO-8859-1)sun/nio/cs/ext/*- Extended charset providers (Cp1252, Windows-1252, etc.)Changes
Configuration
cli/src/main/graalvm-native/resource-config.jsonTesting
Added:
integration-tests/jreleaser-builtin/src/test/java/io/github/bmarwell/jfmt/its/jreleaser/builtin/CharsetSupportIT.javaprint,list, anddiffcommands with Cp1252 charactersUnsupportedCharsetExceptionis thrownAdded:
integration-tests/jreleaser-builtin/src/test/resources/charset/Cp1252Test.javaTesting Notes
Technical Details
The
-H:+AddAllCharsetsflag and explicit resource inclusion work together:Charset.forName()to workThis is the standard GraalVM approach for ensuring charset availability in native images.
Related Issues
Closes #190