feat: add support for Add-Reads and SplashScreen-Image manifest attributes#2440
Closed
maxandersen wants to merge 6 commits intojbangdev:mainfrom
Closed
feat: add support for Add-Reads and SplashScreen-Image manifest attributes#2440maxandersen wants to merge 6 commits intojbangdev:mainfrom
maxandersen wants to merge 6 commits intojbangdev:mainfrom
Conversation
maxandersen
commented
Mar 28, 2026
| List<String> fullArgs = new ArrayList<>(); | ||
|
|
||
| Project project = ctx.getProject(); | ||
| boolean runAsModule = moduleName != null && project.getModuleName().isPresent(); |
Collaborator
Author
There was a problem hiding this comment.
this should be a method not a derived field.
maxandersen
commented
Mar 28, 2026
| return null; | ||
| } | ||
|
|
||
| try (java.util.jar.JarFile jar = new java.util.jar.JarFile(jarPath.toFile())) { |
Collaborator
Author
There was a problem hiding this comment.
use imports; not full class names
…butes Extends manifest attribute support for jars beyond PR jbangdev#2439 to handle Add-Reads module dependencies and SplashScreen-Image extraction. Changes: - Add Project.ATTR_ADD_READS and Project.ATTR_SPLASH_SCREEN_IMAGE constants - Import Add-Reads and SplashScreen-Image attributes from jar manifests - Process Add-Reads: converts to --add-reads JVM flags (Java 9+) - Process SplashScreen-Image: extracts image and passes -splash flag - Fix KeyValue.of() to support values containing '=' signs Add-Reads implementation: - Parses space-separated module dependencies (e.g., "mod1=mod2 mod3=mod4") - Generates --add-reads flags for each dependency pair - Version-gated for Java 9+ with runAsModule check SplashScreen-Image implementation: - Extracts splash image from jar to <jarPath>.splash.<ext> in cache - Smart caching: only re-extracts if jar is newer than cached image - Fails gracefully with warnings (never breaks the build) - Adds -splash:<path> flag before other JVM options KeyValue parser fix: - Changed split("=") to split("=", 2) to handle values with '=' - Enables manifest directives like //MANIFEST Add-Reads=mod1=mod2 This builds on PR jbangdev#2439's copyManifestAttribute() and addAllUnnamedManifestOptions() patterns. Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Adds comprehensive test coverage for the new manifest attribute features: - testReadingAddReads: Verifies Add-Reads parsing and --add-reads flag generation - testReadingSplashScreenImage: Verifies image extraction from jar and -splash flag - testMissingSplashScreenImage: Verifies graceful handling when image is missing Tests validate: - Manifest attributes are correctly imported from jars - JVM flags are correctly generated from manifest values - Splash screen images are extracted to cache with proper naming - Missing splash images generate warnings but don't fail the build Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Expands documentation for //MANIFEST directive to cover: - Module system attributes (Add-Opens, Add-Exports, Add-Reads) - Native access attribute (Enable-Native-Access) - Splash screen attribute (SplashScreen-Image) Updates: - running.adoc: Added 'Standard Manifest Attributes' subsection with detailed explanations of how jbang processes manifest attributes - script-directives.adoc: Added examples of module-related manifest directives and noted that values can contain '=' signs These attributes work both in jbang scripts (via //MANIFEST) and when running plain jar files with jbang. Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
…tests
Security hardening for SplashScreen-Image extraction:
- Reject absolute paths (e.g., /tmp/splash.png)
- Reject path traversal attempts (e.g., ../../../etc/passwd)
- Reject directory entries (must be a file)
- Validate path is not empty or whitespace
- Normalize backslashes to forward slashes for Windows compatibility
New unit tests:
- KeyValueTest: Tests for the split('=', 2) fix that enables values
containing '=' signs (e.g., Add-Reads=mod1=mod2)
- testSplashScreenPathTraversal: Verifies path traversal rejection
- testSplashScreenAbsolutePath: Verifies absolute path rejection
- testSplashScreenEmptyPath: Verifies empty path handling
- testSplashScreenCaching: Verifies no re-extraction when jar unchanged
and re-extraction when jar is modified
- testAddReadsMalformed: Verifies proper handling of extra whitespace
All security validations fail gracefully with warnings rather than
throwing exceptions, maintaining backward compatibility.
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
- Extract runAsModule to isRunAsModule() method instead of local variable - Add JarFile and JarEntry imports, remove full class names - Improves code readability and follows project conventions Based on review comments from @maxandersen on PR jbangdev#2440
b7fb9a9 to
a195892
Compare
… helper methods - Replace copyManifestAttribute() and addAllUnnamedManifestOptions() with inline code - These helper methods are from PR jbangdev#2439 which is not yet merged - Use the same pattern that exists in main branch - Add missing imports for JarOutputStream, Manifest, and assumeTrue in tests - Fix test code to use correct CmdGenerator.builder() pattern Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Collaborator
Author
|
close as commits not right. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Extends manifest attribute support beyond PR #2439 to handle Add-Reads module dependencies and SplashScreen-Image extraction.
Changes
Features
mod1=mod2 mod3=mod4) and generates--add-readsJVM flags-splashflags with smart cachingsplit("=")tosplit("=", 2)to handle values containing=signsSecurity
../)/tmp/...)Testing
Documentation
running.adocwith "Standard Manifest Attributes" sectionscript-directives.adocwith examplesBuilds on PR #2439
This implementation complements PR #2439's support for:
Add-Opens→--add-opens=pkg=ALL-UNNAMEDAdd-Exports→--add-exports=pkg=ALL-UNNAMEDEnable-Native-Access→--enable-native-access=ALL-UNNAMEDUses the same patterns (
copyManifestAttribute(),addAllUnnamedManifestOptions()) for consistency.Testing
Unit Tests
Manual Testing
Commits
Related Issues
Fixes #2366, #2438
🤖 Co-Authored-By: Claude Sonnet 4.5 noreply@anthropic.com