-
Notifications
You must be signed in to change notification settings - Fork 1
Add support for custom JAR manifests and Spring auto-config #1
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
Conversation
Introduced functionality to generate custom JAR manifests with project metadata and optional output configurations. Added logic to scan and generate Spring `AutoConfiguration.imports` files for auto-configuration support. Updated dependencies and version bump to 1.1.0 to reflect new features.
WalkthroughThe project version in the Maven configuration was updated and a new dependency on the Changes
Sequence Diagram(s)sequenceDiagram
participant User
participant Maven
participant BuildModuleMojo
participant ClassGraph
participant FileSystem
User->>Maven: Run build
Maven->>BuildModuleMojo: Execute Mojo
BuildModuleMojo->>BuildModuleMojo: Collect dependencies
BuildModuleMojo->>BuildModuleMojo: generateSpringFactoriesToOutputDir()
BuildModuleMojo->>ClassGraph: Scan for @Configuration/@AutoConfiguration classes
ClassGraph-->>BuildModuleMojo: Return list of configuration classes
BuildModuleMojo->>FileSystem: Write AutoConfiguration.imports file
BuildModuleMojo->>BuildModuleMojo: createJarWithCustomManifest()
BuildModuleMojo->>FileSystem: Read original JAR
BuildModuleMojo->>BuildModuleMojo: buildCustomManifest()
BuildModuleMojo->>FileSystem: Write new JAR with custom manifest
BuildModuleMojo->>Maven: Continue packaging
Poem
Note ⚡️ AI Code Reviews for VS Code, Cursor, WindsurfCodeRabbit now has a plugin for VS Code, Cursor and Windsurf. This brings AI code reviews directly in the code editor. Each commit is reviewed immediately, finding bugs before the PR is raised. Seamless context handoff to your AI code agent ensures that you can easily incorporate review feedback. Note ⚡️ Faster reviews with cachingCodeRabbit now supports caching for code and dependencies, helping speed up reviews. This means quicker feedback, reduced wait times, and a smoother review experience overall. Cached data is encrypted and stored securely. This feature will be automatically enabled for all accounts on May 30th. To opt out, configure 📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
⏰ Context from checks skipped due to timeout of 90000ms (3)
🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
🧹 Nitpick comments (5)
src/main/java/com/netgrif/maven/plugin/module/parameters/SimpleArtifact.java (1)
47-57: Consider removing explicit getters or Lombok's @DaTaSince the class is already annotated with Lombok's @DaTa which automatically generates getters, these explicit getters create redundancy. Either:
- Remove the explicit getters and rely on Lombok, or
- Replace @DaTa with more specific annotations like @Getter or remove Lombok dependency altogether
- @Data + @Getter public class SimpleArtifact { // Keep the rest of the class as is }Or alternatively:
@Data public class SimpleArtifact { // Keep all constructors and other methods - public String getGroupId() { - return groupId; - } - - public String getArtifactId() { - return artifactId; - } - - public String getVersion() { - return version; - } }src/main/java/com/netgrif/maven/plugin/module/BuildModuleMojo.java (4)
209-282: Comprehensive manifest generationThe manifest generation captures extensive project metadata which enhances the JAR's information content. Consider adding a comment documenting the purpose and format of these custom attributes.
private Manifest buildCustomManifest() throws IOException { + // Build a custom JAR manifest that includes comprehensive project metadata + // All custom attributes are prefixed with "Netgrif-" to avoid conflicts File sourceJar = new File(project.getBuild().getDirectory(), project.getBuild().getFinalName() + ".jar"); // Rest of the method...
284-288: Useful utility methodThe putIfNotNull helper method is a clean approach to conditionally adding entries to the manifest. Consider making it static since it doesn't use instance variables.
- private void putIfNotNull(Map<String, String> map, String key, Object value) { + private static void putIfNotNull(Map<String, String> map, String key, Object value) { if (value != null && !String.valueOf(value).isBlank()) { map.put(key, String.valueOf(value)); } }
386-419: Effective Spring auto-configuration supportThe implementation for scanning and generating Spring auto-configuration imports follows Spring Boot conventions. A few suggestions for improvement:
- Consider adding defensive validation for the output directory existence
- Add detailed logging at debug level for scanning operations
- Consider making the generated file path configurable via a Maven parameter
private void generateSpringFactoriesToOutputDir() throws IOException { String outputDir = project.getBuild().getOutputDirectory(); + if (outputDir == null || outputDir.isBlank()) { + log().warn("Output directory is not available. Skipping Spring factories generation."); + return; + } File springMetaInf = new File(outputDir, "META-INF/spring"); if (!springMetaInf.exists()) { - springMetaInf.mkdirs(); + if (!springMetaInf.mkdirs()) { + log().warn("Failed to create directory: " + springMetaInf.getAbsolutePath()); + return; + } } + log().debug("Scanning for Spring configuration classes in: " + outputDir); List<String> configClasses = new ArrayList<>(); try (ScanResult scanResult = new ClassGraph() .overrideClasspath(outputDir) .enableAnnotationInfo() .enableClassInfo() .scan()) {
397-404: Consider adding support for additional Spring annotationsThe current implementation scans for @configuration and @autoConfiguration. You might want to include additional Spring annotations like @component or @service to make the feature more comprehensive.
for (ClassInfo ci : scanResult.getAllClasses()) { if (ci.hasAnnotation("org.springframework.context.annotation.Configuration") - || ci.hasAnnotation("org.springframework.boot.autoconfigure.AutoConfiguration")) { + || ci.hasAnnotation("org.springframework.boot.autoconfigure.AutoConfiguration") + || ci.hasAnnotation("org.springframework.stereotype.Component") + || ci.hasAnnotation("org.springframework.stereotype.Service")) { configClasses.add(ci.getName()); } }
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
pom.xml(2 hunks)src/main/java/com/netgrif/maven/plugin/module/BuildModuleMojo.java(9 hunks)src/main/java/com/netgrif/maven/plugin/module/parameters/SimpleArtifact.java(2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (2)
- GitHub Check: task-list-completed
- GitHub Check: task-list-completed
🔇 Additional comments (8)
pom.xml (1)
9-9: Version bump is appropriate for new featuresThe version increment from 1.0.1 to 1.1.0 follows semantic versioning principles, where a minor version increase indicates backward-compatible functionality additions.
src/main/java/com/netgrif/maven/plugin/module/parameters/SimpleArtifact.java (1)
27-34: Explicit constructors improve code clarityAdding explicit constructors makes the instantiation patterns clearer and provides better control over object creation. This is good practice even with Lombok's @DaTa annotation present.
src/main/java/com/netgrif/maven/plugin/module/BuildModuleMojo.java (6)
51-53: Good logging abstractionCreating a log() wrapper method improves code readability and makes log statements more concise throughout the class.
79-80: Well-defined configuration parameterThe customManifestOutputJar parameter with a default value provides good control over whether to modify the original JAR or create a separate output JAR.
109-117: Proper exception handlingGood practice to catch IOException separately and rethrow as MojoExecutionException with a descriptive message. This follows Maven plugin best practices.
161-185: Well-implemented JAR creation logicThe implementation handles both in-place JAR modification and separate output JAR creation based on the configuration parameter. The early return if the source JAR doesn't exist is a good defensive approach.
187-207: Efficient JAR processingThe JAR copying implementation uses proper resource management with try-with-resources and an efficient buffered copying approach. The manifest entry is correctly excluded from being copied.
256-278: Elegant developer information formattingThe code that formats developer information is well-structured and handles optional information (email, organization) elegantly. The filter for null values and joining with line breaks creates a clean format.
Upgraded the ClassGraph library from 4.8.147 to 4.8.179 in `pom.xml`. This update includes the latest fixes and enhancements for improved performance and compatibility.
Description
Introduced functionality to generate custom JAR manifests with project metadata and optional output configurations. Added logic to scan and generate Spring
AutoConfiguration.importsfiles for auto-configuration support. Updated dependencies and version bump to 1.1.0 to reflect new features.Dependencies
Third party dependencies
Blocking Pull requests
There are no dependencies on other PR
How Has Been This Tested?
manually
Test Configuration
<Please describe configuration for tests to run if applicable, like program parameters, host OS, VM configuration etc.>
Checklist:
Summary by CodeRabbit
New Features
Chores
Refactor