Skip to content

Conversation

@machacjozef
Copy link
Member

@machacjozef machacjozef commented May 23, 2025

Description

Introduced methods to customize JAR manifests, remove specific properties, and handle dependency trees. Enhanced documentation for added functionalities like Spring factories generation, manifest building, and flattened dependencies. These changes improve JAR handling flexibility and maintain build configurability.

Dependencies

Third party dependencies

No new dependencies were introduced

Blocking Pull requests

There are no dependencies on other PR

How Has Been This Tested?

  • <Name of a test [test file](link to the test file)>

Test Configuration

<Please describe configuration for tests to run if applicable, like program parameters, host OS, VM configuration etc.>

Name Tested on
OS
Runtime
Dependency Manager
Framework version
Run parameters
Other configuration

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • My changes have been checked, personally or remotely, with @tuplle
  • I have commented my code, particularly in hard-to-understand areas
  • I have resolved all conflicts with the target branch of the PR
  • I have updated and synced my code with the target branch
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing tests pass locally with my changes:
    • Lint test
    • Unit tests
    • Integration tests
  • I have checked my contribution with code analysis tools:
  • I have made corresponding changes to the documentation:
    • Developer documentation
    • User Guides
    • Migration Guides

Summary by CodeRabbit

  • New Features
    • Added automatic removal of property files (e.g., application.properties and worker-specific configs) from the built JAR to streamline deployments.
    • Enhanced JAR manifest customization with detailed project, SCM, license, and developer metadata.
  • Documentation
    • Improved in-code documentation for better clarity and maintainability.
  • Refactor
    • Enhanced logging and internal structure for more consistent and reliable build processes.

Introduced methods to customize JAR manifests, remove specific properties, and handle dependency trees. Enhanced documentation for added functionalities like Spring factories generation, manifest building, and flattened dependencies. These changes improve JAR handling flexibility and maintain build configurability.
@machacjozef machacjozef requested a review from tuplle May 23, 2025 17:24
@machacjozef machacjozef self-assigned this May 23, 2025
@coderabbitai
Copy link

coderabbitai bot commented May 23, 2025

Walkthrough

The BuildModuleMojo class was significantly updated with comprehensive JavaDoc documentation, new utility and helper methods, and improved logging. The main functional addition is the removal of specific property files from the built JAR. Manifest customization and Spring factories generation logic were also enhanced and refactored for clarity and maintainability.

Changes

File(s) Change Summary
src/main/java/com/netgrif/maven/plugin/module/BuildModuleMojo.java - Added extensive JavaDoc documentation to fields and methods.
- Introduced private logging accessor (log()).
- Added forceEnableWorkerProfile parameter.
- Implemented removeProperties() to delete property files from the JAR post-build.
- Refactored createJarWithCustomManifest() and added copyJarExcludingManifest() for manifest handling.
- Enhanced buildCustomManifest() to include more project metadata.
- Added utility methods: putIfNotNull(), getHostAppArtifact(), findDependency(), flattenDependencies().
- Added/updated assembly descriptor methods: separateDescriptor(), singleDescriptor().
- Implemented generateSpringFactoriesToOutputDir() for Spring factories file generation.
- Added isRootOrClasspath() helper.
- Improved logging and error handling throughout.
- Updated execute() control flow to integrate new property removal logic.

Sequence Diagram(s)

sequenceDiagram
    participant Maven as Maven Build
    participant BuildModuleMojo as BuildModuleMojo
    participant JAR as Built JAR
    participant TempJAR as Temp JAR

    Maven->>BuildModuleMojo: execute()
    BuildModuleMojo->>BuildModuleMojo: generateSpringFactoriesToOutputDir()
    BuildModuleMojo->>BuildModuleMojo: createJarWithCustomManifest()
    BuildModuleMojo->>BuildModuleMojo: removeProperties()
    BuildModuleMojo->>JAR: Read JAR entries
    BuildModuleMojo->>TempJAR: Write entries excluding property files
    BuildModuleMojo->>BuildModuleMojo: Replace original JAR with Temp JAR
Loading

Possibly related PRs

  • Add support for custom JAR manifests and Spring auto-config #1: The main PR extends the functionality introduced in the retrieved PR by adding property file removal from the JAR and enhanced logging and documentation, while both modify the same class BuildModuleMojo and share core methods like createJarWithCustomManifest() and buildCustomManifest(), indicating a direct continuation and expansion of the retrieved PR’s features.

Suggested labels

enhancement

Note

⚡️ AI Code Reviews for VS Code, Cursor, Windsurf

CodeRabbit 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.
Learn more here.

✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need 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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

coderabbitai bot added a commit that referenced this pull request May 23, 2025
Docstrings generation was requested by @machacjozef.

* #2 (comment)

The following files were modified:

* `src/main/java/com/netgrif/maven/plugin/module/BuildModuleMojo.java`
@coderabbitai
Copy link

coderabbitai bot commented May 23, 2025

Note

Generated docstrings for this pull request at #3

@coderabbitai coderabbitai bot added the enhancement New feature or request label May 23, 2025
Copy link

@coderabbitai coderabbitai bot left a 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

🔭 Outside diff range comments (2)
src/main/java/com/netgrif/maven/plugin/module/BuildModuleMojo.java (2)

347-349: ⚠️ Potential issue

Compile-time failure: List#getFirst() is not available

java.util.List has no getFirst() method – the code will not compile.
Fix by accessing the first element with get(0) or stream().findFirst().

-            putIfNotNull(customAttributes, "Netgrif-License", project.getLicenses().getFirst());
+            putIfNotNull(customAttributes, "Netgrif-License", project.getLicenses().get(0));

423-427: ⚠️ Potential issue

Null-pointer risk when hostApp is not supplied

The else if (hostApp.isValid()) branch dereferences hostApp without a null-check, which will throw an NPE when hostApp is null and naeVersion is blank.

-        } else if (hostApp.isValid()) {
+        } else if (hostApp != null && hostApp.isValid()) {
🧹 Nitpick comments (4)
src/main/java/com/netgrif/maven/plugin/module/BuildModuleMojo.java (4)

284-297: Jar entry metadata is lost during copy

new JarEntry(name) recreates the entry but drops timestamps, compression method, extra fields, etc. Use the copy-constructor so all attributes are preserved:

-                jarOut.putNextEntry(new JarEntry(name));
+                jarOut.putNextEntry(new JarEntry(entry));

Optionally copy/set the time explicitly if you need deterministic builds.


589-595: Use UTF-8 when writing the imports file

PrintWriter without charset uses the platform default, yielding non-deterministic builds across machines. Specify UTF-8 explicitly:

-importsFile, "org.springframework.boot.autoconfigure.AutoConfiguration.imports");
-        try (PrintWriter writer = new PrintWriter(new FileWriter(importsFile))) {
+importsFile, "org.springframework.boot.autoconfigure.AutoConfiguration.imports");
+        try (PrintWriter writer =
+                 new PrintWriter(Files.newBufferedWriter(importsFile.toPath(),
+                                                         StandardCharsets.UTF_8))) {

Add import java.nio.charset.StandardCharsets;.


675-680: File.renameTo is non-portable; prefer Files.move with ATOMIC_MOVE

renameTo can silently fail across filesystems. Using NIO provides better reliability and atomicity.

-        if (!tempJar.renameTo(jarFile)) {
-            throw new IOException("Could not rename temp JAR to original name!");
-        }
+        try {
+            Files.move(tempJar.toPath(), jarFile.toPath(),
+                       StandardCopyOption.REPLACE_EXISTING,
+                       StandardCopyOption.ATOMIC_MOVE);
+        } catch (IOException ex) {
+            throw new IOException("Could not replace original JAR with temporary copy", ex);
+        }

Remember to add the required imports:

import java.nio.file.Files;
import java.nio.file.StandardCopyOption;

683-686: Method name could be clearer

isRootOrClasspath also accepts any path starting with "BOOT-INF/classes/", not only classpath-root entries. Consider renaming to isRootOrBootClasspath (or similar) to better reflect intent.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ffd6380 and d798386.

📒 Files selected for processing (1)
  • src/main/java/com/netgrif/maven/plugin/module/BuildModuleMojo.java (11 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (6)
  • GitHub Check: task-list-completed
  • GitHub Check: task-list-completed
  • GitHub Check: task-list-completed
  • GitHub Check: task-list-completed
  • GitHub Check: task-list-completed
  • GitHub Check: task-list-completed

Previously, the code assumed the presence of a manifest in JAR files, leading to a NullPointerException if it was absent. This fix provides a default manifest when none is found, ensuring robust handling of such cases.
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

♻️ Duplicate comments (1)
src/main/java/com/netgrif/maven/plugin/module/BuildModuleMojo.java (1)

642-646: Fixed manifest handling to prevent null manifest issues.

This implementation correctly handles the case where the source JAR lacks a manifest by creating a new one if needed. This addresses the previous review comment about potential null manifest issues.

🧹 Nitpick comments (2)
src/main/java/com/netgrif/maven/plugin/module/BuildModuleMojo.java (2)

600-684: Consider adding summary logging for property removal.

While the implementation correctly removes specified property files, it would be helpful to add summary logging at the end of the method to indicate how many files were removed in total.

    if (!tempJar.renameTo(jarFile)) {
        throw new IOException("Could not rename temp JAR to original name!");
    }
+   log().info("Property files removal completed successfully");
}

545-597: Consider handling directory creation failure.

The method doesn't verify if springMetaInf.mkdirs() succeeds. Add error handling to ensure the directory is created before proceeding.

    File springMetaInf = new File(outputDir, "META-INF/spring");
    if (!springMetaInf.exists()) {
-       springMetaInf.mkdirs();
+       if (!springMetaInf.mkdirs()) {
+           throw new IOException("Failed to create directory: " + springMetaInf.getAbsolutePath());
+       }
    }
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d798386 and 19929b6.

📒 Files selected for processing (1)
  • src/main/java/com/netgrif/maven/plugin/module/BuildModuleMojo.java (11 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: task-list-completed
  • GitHub Check: task-list-completed
  • GitHub Check: task-list-completed
🔇 Additional comments (9)
src/main/java/com/netgrif/maven/plugin/module/BuildModuleMojo.java (9)

51-58: Nice addition of a logging accessor method.

Adding a dedicated log() method provides consistent access to the logger throughout the class and makes future logger implementation changes easier.


135-136: Good addition of the worker profile flag.

The forceEnableWorkerProfile parameter with clear documentation provides a configurable way to control whether worker-specific properties are included in the final JAR.


178-178: Well-placed call to the new property removal method.

The removeProperties() call is appropriately sequenced after Spring factories generation and manifest customization, ensuring all necessary processing completes before file cleanup.


226-267: Well-structured manifest handling with proper error management.

The createJarWithCustomManifest() method has clear execution paths based on the customManifestOutputJar flag, good error handling, and appropriate logging.


686-689: Good helper method for path checking.

The isRootOrClasspath() method provides a clean abstraction for checking if a file is at the root level or in the BOOT-INF/classes directory, making the property removal logic more readable.


301-391: Thorough manifest enrichment with project metadata.

The buildCustomManifest() method comprehensively enriches the manifest with various project metadata, enhancing jar identification and traceability. The formatting of developer information is particularly well-handled.


431-457: Well-implemented recursive dependency search.

The findDependency method effectively searches through the dependency tree using a clear recursive approach with proper null checking and early returns.


459-478: Clean implementation of dependency flattening.

The flattenDependencies method efficiently collects all dependencies from a hierarchical structure using a recursive approach and proper null safety.


480-509: Well-documented descriptor builder with proper exclusion handling.

The separateDescriptor method is now better documented and handles exclusions correctly, with appropriate debug logging.

@machacjozef machacjozef reopened this May 23, 2025
@machacjozef machacjozef merged commit 7635c52 into main May 23, 2025
5 of 6 checks passed
@machacjozef machacjozef deleted the feature/remove-properties branch May 23, 2025 18:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants