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

Automatically exposes jdk modules #1340

Merged
merged 5 commits into from
Sep 23, 2024

Conversation

CrazyHZM
Copy link
Contributor

@CrazyHZM CrazyHZM commented Aug 29, 2024

Summary by CodeRabbit

Summary by CodeRabbit

  • New Features

    • Introduced new dynamic module application context initializers to enhance modular capabilities.
    • Added utility methods for managing module visibility in Java's module system.
    • Updated versioning to improve dependency management and testing capabilities.
  • Tests

    • Added unit tests to validate the functionality of the new module utility methods and application context initializers, ensuring correct behavior under various configurations.

Signed-off-by: JermaineHua <[email protected]>
Copy link

coderabbitai bot commented Aug 29, 2024

Walkthrough

The changes introduce a new versioning scheme in the pom.xml file, transitioning to 4.4.0-SNAPSHOT. New classes such as DynamicModuleApplicationContextInitializer, DynamicModuleExportApplicationContextInitializer, and AutoModuleExportApplicationContextInitializer are added to enhance module management and accessibility in the SOFA Boot framework. The ModuleUtil class is introduced for managing module visibility, and the spring.factories file is updated to register the new initializers. Additionally, test classes are created to validate the functionality of the new module utilities.

Changes

Files Change Summary
pom.xml Updated <revision> from 4.3.0 to 4.4.0-SNAPSHOT and added mockito-inline dependency.
.../Initializer/DynamicModuleApplicationContextInitializer.java Introduced a new class implementing ApplicationContextInitializer for dynamic module initialization.
.../Initializer/DynamicModuleExportApplicationContextInitializer.java Introduced a new class implementing ApplicationContextInitializer for exporting JDK module packages.
.../Initializer/AutoModuleExportApplicationContextInitializer.java Added a new class for managing module exports based on configuration settings.
.../util/ModuleUtil.java Added ModuleUtil class with methods for managing module visibility and accessibility.
.../META-INF/spring.factories Updated to register new initializers for Spring Boot application.
.../util/ModuleUtilTests.java Added JUnit test class to validate ModuleUtil.exportAllJDKModulePackageToAll() functionality.
.../initializer/AutoModuleExportApplicationContextInitializerTests.java Added unit tests for AutoModuleExportApplicationContextInitializer to validate module export behavior.

Sequence Diagram(s)

sequenceDiagram
    participant App as Application
    participant DynamicInitializer as DynamicModuleApplicationContextInitializer
    participant ExportInitializer as DynamicModuleExportApplicationContextInitializer
    participant AutoExportInitializer as AutoModuleExportApplicationContextInitializer
    participant ModuleUtil as ModuleUtil

    App->>DynamicInitializer: Initialize Application Context
    DynamicInitializer->>ModuleUtil: Call exportAllJDKModulePackageToAll()
    ModuleUtil-->>DynamicInitializer: Modify module accessibility
    DynamicInitializer-->>App: Complete initialization

    App->>ExportInitializer: Initialize Export Context
    ExportInitializer->>ModuleUtil: Call exportAllModulePackageToAll()
    ModuleUtil-->>ExportInitializer: Modify module package accessibility
    ExportInitializer-->>App: Complete export initialization

    App->>AutoExportInitializer: Initialize Auto Module Export
    AutoExportInitializer->>ModuleUtil: Check configuration and export modules
    ModuleUtil-->>AutoExportInitializer: Modify module export based on config
    AutoExportInitializer-->>App: Complete auto module export initialization
Loading

🐰 In the meadow, hopping with glee,
New modules dance, oh so free!
Version four point four, a snapshot bright,
With utilities to make things right.
Spring's embrace, a joyful cheer,
Hopping forward, the future is near! 🌼✨

Possibly related PRs

  • 4.4.0-SNAPSHOT #1334: The changes in this PR involve updating the <revision> property in the pom.xml file from 4.3.0 to 4.4.0-SNAPSHOT, which directly relates to the versioning changes in the main PR.

Suggested labels

size/XS


Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 24ac036 and 065d200.

Files selected for processing (1)
  • sofa-boot-project/sofa-boot/src/main/java/com/alipay/sofa/boot/util/ModuleUtil.java (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • sofa-boot-project/sofa-boot/src/main/java/com/alipay/sofa/boot/util/ModuleUtil.java

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
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.
    -- Generate unit testing code for this file.
    • 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 generate unit testing code for this file.
    -- @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 generate unit testing code.
    -- @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.

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 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.

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: 6

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 1f4e235 and e289863.

Files selected for processing (6)
  • pom.xml (1 hunks)
  • sofa-boot-project/sofa-boot/src/main/java/com/alipay/sofa/boot/Initializer/DynamicModuleApplicationContextInitializer.java (1 hunks)
  • sofa-boot-project/sofa-boot/src/main/java/com/alipay/sofa/boot/util/ModuleUtil.java (1 hunks)
  • sofa-boot-project/sofa-boot/src/main/java/com/alipay/sofa/boot/util/UnsafeUtil.java (1 hunks)
  • sofa-boot-project/sofa-boot/src/main/resources/META-INF/spring.factories (1 hunks)
  • sofa-boot-project/sofa-boot/src/test/java/com/alipay/sofa/boot/util/ModuleUtilTests.java (1 hunks)
Additional comments not posted (20)
sofa-boot-project/sofa-boot/src/main/resources/META-INF/spring.factories (1)

18-19: LGTM! But verify the implementation of the new initializer.

The addition of com.alipay.sofa.boot.Initializer.DynamicModuleApplicationContextInitializer to the list of ApplicationContextInitializer seems appropriate. Ensure that the new initializer is correctly implemented and does not introduce any issues.

The code changes are approved.

Run the following script to verify the implementation of the new initializer:

Verification successful

Implementation Verified: DynamicModuleApplicationContextInitializer

The DynamicModuleApplicationContextInitializer is correctly implemented as an ApplicationContextInitializer. It overrides the initialize method to call ModuleUtil.exportAllJDKModulePackageToAll(). Ensure that this utility function behaves as expected.

  • File: sofa-boot-project/sofa-boot/src/main/java/com/alipay/sofa/boot/Initializer/DynamicModuleApplicationContextInitializer.java
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the implementation of the new initializer.

# Test: Search for the implementation of the new initializer. Expect: Only occurrences of the new implementation.
rg --type java $'DynamicModuleApplicationContextInitializer'

Length of output: 238


Script:

#!/bin/bash
# Extract the implementation details of the DynamicModuleApplicationContextInitializer class.
ast-grep --lang java --pattern $'class DynamicModuleApplicationContextInitializer {
  $$$
}' sofa-boot-project/sofa-boot/src/main/java/com/alipay/sofa/boot/Initializer/DynamicModuleApplicationContextInitializer.java

Length of output: 216


Script:

#!/bin/bash
# Use rg to extract the implementation details of the DynamicModuleApplicationContextInitializer class.
rg 'class DynamicModuleApplicationContextInitializer' -A 50 sofa-boot-project/sofa-boot/src/main/java/com/alipay/sofa/boot/Initializer/DynamicModuleApplicationContextInitializer.java

Length of output: 580

sofa-boot-project/sofa-boot/src/main/java/com/alipay/sofa/boot/Initializer/DynamicModuleApplicationContextInitializer.java (5)

1-16: LGTM!

The license header is appropriate and correctly formatted.

The code changes are approved.


17-17: LGTM!

The package declaration is appropriate and correctly formatted.

The code changes are approved.


19-21: LGTM!

The imports are appropriate and correctly formatted.

The code changes are approved.


28-30: LGTM!

The class declaration is appropriate and correctly formatted.

The code changes are approved.


31-34: LGTM! But verify the implementation of ModuleUtil.exportAllJDKModulePackageToAll().

The method implementation is appropriate. Ensure that the ModuleUtil.exportAllJDKModulePackageToAll() method is correctly implemented and does not introduce any issues.

The code changes are approved.

Run the following script to verify the implementation of ModuleUtil.exportAllJDKModulePackageToAll():

Verification successful

Implementation Verified: Review the use of catch-all Throwable in exportAllJDKModulePackageToAll().

The method exportAllJDKModulePackageToAll() is implemented to export JDK module packages to all modules with exception handling. However, the use of a catch-all Throwable could potentially hide issues. Consider refining this to handle specific exceptions.

  • File: sofa-boot-project/sofa-boot/src/main/java/com/alipay/sofa/boot/util/ModuleUtil.java
  • Lines: 47-61
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the implementation of `ModuleUtil.exportAllJDKModulePackageToAll()`.

# Test: Search for the implementation of `ModuleUtil.exportAllJDKModulePackageToAll()`. Expect: Only occurrences of the implementation.
rg --type java $'exportAllJDKModulePackageToAll'

Length of output: 507


Script:

#!/bin/bash
# Extract the implementation of `exportAllJDKModulePackageToAll()` from `ModuleUtil.java`.
ast-grep --lang java --pattern $'public static void exportAllJDKModulePackageToAll() {
  $$$
}' sofa-boot-project/sofa-boot/src/main/java/com/alipay/sofa/boot/util/ModuleUtil.java

Length of output: 2044

sofa-boot-project/sofa-boot/src/test/java/com/alipay/sofa/boot/util/ModuleUtilTests.java (5)

1-16: LGTM!

The license header is appropriate and correctly formatted.

The code changes are approved.


17-17: LGTM!

The package declaration is appropriate and correctly formatted.

The code changes are approved.


19-27: LGTM!

The imports are appropriate and correctly formatted.

The code changes are approved.


34-34: LGTM!

The class declaration is appropriate and correctly formatted.

The code changes are approved.


36-50: LGTM!

The test method is appropriate and correctly validates the behavior of ModuleUtil.exportAllJDKModulePackageToAll().

The code changes are approved.

pom.xml (1)

38-38: LGTM!

The versioning change to 4.4.0-SNAPSHOT is appropriate for ongoing development.

The code changes are approved.

sofa-boot-project/sofa-boot/src/main/java/com/alipay/sofa/boot/util/ModuleUtil.java (8)

91-93: LGTM!

The method is correctly implemented.

The code changes are approved.


102-104: LGTM!

The method is correctly implemented.

The code changes are approved.


113-115: LGTM!

The method is correctly implemented.

The code changes are approved.


124-126: LGTM!

The method is correctly implemented.

The code changes are approved.


135-137: LGTM!

The method is correctly implemented.

The code changes are approved.


147-149: LGTM!

The method is correctly implemented.

The code changes are approved.


158-160: LGTM!

The method is correctly implemented.

The code changes are approved.


168-170: LGTM!

The method is correctly implemented.

The code changes are approved.

@CrazyHZM CrazyHZM force-pushed the feat/dynamic_export_and_open branch from e289863 to 88c7e01 Compare August 29, 2024 07:40
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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between e289863 and 88c7e01.

Files selected for processing (5)
  • sofa-boot-project/sofa-boot/src/main/java/com/alipay/sofa/boot/Initializer/DynamicModuleExportApplicationContextInitializer.java (1 hunks)
  • sofa-boot-project/sofa-boot/src/main/java/com/alipay/sofa/boot/util/ModuleUtil.java (1 hunks)
  • sofa-boot-project/sofa-boot/src/main/java/com/alipay/sofa/boot/util/UnsafeUtil.java (1 hunks)
  • sofa-boot-project/sofa-boot/src/main/resources/META-INF/spring.factories (1 hunks)
  • sofa-boot-project/sofa-boot/src/test/java/com/alipay/sofa/boot/util/ModuleUtilTests.java (1 hunks)
Files skipped from review as they are similar to previous changes (4)
  • sofa-boot-project/sofa-boot/src/main/java/com/alipay/sofa/boot/util/ModuleUtil.java
  • sofa-boot-project/sofa-boot/src/main/java/com/alipay/sofa/boot/util/UnsafeUtil.java
  • sofa-boot-project/sofa-boot/src/main/resources/META-INF/spring.factories
  • sofa-boot-project/sofa-boot/src/test/java/com/alipay/sofa/boot/util/ModuleUtilTests.java
Additional comments not posted (3)
sofa-boot-project/sofa-boot/src/main/java/com/alipay/sofa/boot/Initializer/DynamicModuleExportApplicationContextInitializer.java (3)

1-16: LGTM!

The license header is correctly formatted.

The code changes are approved.


17-22: LGTM!

The package declaration and imports are appropriate.

The code changes are approved.


23-34: LGTM!

The class DynamicModuleExportApplicationContextInitializer correctly implements ApplicationContextInitializer<ConfigurableApplicationContext>. The initialize method is straightforward and calls a utility method to export JDK modules.

The code changes are approved.

Signed-off-by: JermaineHua <[email protected]>
@CrazyHZM CrazyHZM force-pushed the feat/dynamic_export_and_open branch from 88c7e01 to 97cc8c5 Compare August 29, 2024 08:53
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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 88c7e01 and 97cc8c5.

Files selected for processing (5)
  • sofa-boot-project/sofa-boot/src/main/java/com/alipay/sofa/boot/Initializer/DynamicModuleExportApplicationContextInitializer.java (1 hunks)
  • sofa-boot-project/sofa-boot/src/main/java/com/alipay/sofa/boot/util/ModuleUtil.java (1 hunks)
  • sofa-boot-project/sofa-boot/src/main/java/com/alipay/sofa/boot/util/UnsafeUtil.java (1 hunks)
  • sofa-boot-project/sofa-boot/src/main/resources/META-INF/spring.factories (1 hunks)
  • sofa-boot-project/sofa-boot/src/test/java/com/alipay/sofa/boot/util/ModuleUtilTests.java (1 hunks)
Files skipped from review due to trivial changes (1)
  • sofa-boot-project/sofa-boot/src/main/java/com/alipay/sofa/boot/util/ModuleUtil.java
Files skipped from review as they are similar to previous changes (4)
  • sofa-boot-project/sofa-boot/src/main/java/com/alipay/sofa/boot/Initializer/DynamicModuleExportApplicationContextInitializer.java
  • sofa-boot-project/sofa-boot/src/main/java/com/alipay/sofa/boot/util/UnsafeUtil.java
  • sofa-boot-project/sofa-boot/src/main/resources/META-INF/spring.factories
  • sofa-boot-project/sofa-boot/src/test/java/com/alipay/sofa/boot/util/ModuleUtilTests.java

Copy link

codecov bot commented Aug 29, 2024

Codecov Report

Attention: Patch coverage is 58.42697% with 37 lines in your changes missing coverage. Please review.

Project coverage is 82.93%. Comparing base (b4c939a) to head (065d200).
Report is 2 commits behind head on master.

Files with missing lines Patch % Lines
...ain/java/com/alipay/sofa/boot/util/ModuleUtil.java 45.16% 33 Missing and 1 partial ⚠️
...ain/java/com/alipay/sofa/boot/util/UnsafeUtil.java 84.21% 3 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##             master    #1340      +/-   ##
============================================
- Coverage     83.20%   82.93%   -0.27%     
- Complexity     2951     2972      +21     
============================================
  Files           337      340       +3     
  Lines          9739     9828      +89     
  Branches       1174     1176       +2     
============================================
+ Hits           8103     8151      +48     
- Misses         1125     1161      +36     
- Partials        511      516       +5     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

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: 3

Outside diff range and nitpick comments (1)
sofa-boot-project/sofa-boot/src/main/java/com/alipay/sofa/boot/util/ModuleUtil.java (1)

218-227: Avoid using UnsafeUtil for reflection to enhance compatibility

The use of UnsafeUtil in createModuleMethodHandle() and getModuleLayerFieldsValue() relies on internal APIs, which can lead to compatibility issues across different Java versions. It's recommended to use standard reflection APIs or MethodHandles provided by the Java language to achieve the desired functionality without depending on unsafe operations.

Also applies to: 235-245

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 6d844ab and 4008141.

Files selected for processing (1)
  • sofa-boot-project/sofa-boot/src/main/java/com/alipay/sofa/boot/util/ModuleUtil.java (1 hunks)

Comment on lines +188 to +186
public static boolean invokeModuleMethod(MethodHandle method, String moduleName,
String packageName) {
Copy link

Choose a reason for hiding this comment

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

Add null checks for method handles to prevent NullPointerException

The method parameter may be null if the method handle creation fails. Invoking method.invoke(...) without checking for null can lead to a NullPointerException. Please add a null check before using the method handle.

Apply this diff to add null checks:

 public static boolean invokeModuleMethod(MethodHandle method, String moduleName,
                                          String packageName) {
+    if (method == null) {
+        LOGGER.error("Method handle is null for module: {}, package: {}", moduleName, packageName);
+        return false;
+    }
     Optional<Module> findModule = ModuleLayer.boot().findModule(moduleName);
     if (findModule.isPresent()) {
         try {
             return invokeModuleMethod(method, findModule.get(), packageName);
         } catch (Throwable t) {
             LOGGER.error("Failed to invoke ModuleLayer method: {}", method, t);
         }
     }
     return false;
 }

 public static boolean invokeModuleMethod(MethodHandle method, Module module, String packageName) {
+    if (method == null) {
+        LOGGER.error("Method handle is null for module: {}, package: {}", module.getName(), packageName);
+        return false;
+    }
     try {
         method.invoke(module, packageName);
         return true;
     } catch (Throwable t) {
         LOGGER.error("Failed to invoke Module method: {}", method, t);
     }
     return false;
 }

Also applies to: 201-202


private static final Map<String, Module> nameToModules;

private static boolean isExported = false;
Copy link

Choose a reason for hiding this comment

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

Use separate flags for export methods to avoid unintended behavior

The isExported flag is shared between exportAllJDKModulePackageToAll() and exportAllModulePackageToAll(). If one method sets isExported to true, the other method will skip execution, which might not be the intended behavior. Consider using separate flags to control each method independently.

Apply this diff to introduce separate flags:

-private static boolean                   isExported = false;
+private static boolean                   isJdkModulesExported = false;
+private static boolean                   isAllModulesExported = false;

 public static void exportAllJDKModulePackageToAll() {
     try {
-        if (!isExported && nameToModules != null) {
+        if (!isJdkModulesExported && nameToModules != null) {
             nameToModules.forEach((name, module) -> module.getPackages().forEach(pkgName -> {
                 if (isJDKModulePackage(pkgName)) {
                     addOpensToAll(module, pkgName);
                     addExportsToAll(module, pkgName);
                 }
             }));
         }
-        isExported = true;
+        isJdkModulesExported = true;
     } catch (Throwable t) {
-        isExported = false;
+        isJdkModulesExported = false;
         LOGGER.error("Failed to export all JDK module package to all", t);
     }
 }

 public static void exportAllModulePackageToAll() {
     try {
-        if (!isExported && nameToModules != null) {
+        if (!isAllModulesExported && nameToModules != null) {
             nameToModules.forEach((name, module) -> module.getPackages().forEach(pkgName -> {
                 addOpensToAll(module, pkgName);
                 addExportsToAll(module, pkgName);
             }));
         }
-        isExported = true;
+        isAllModulesExported = true;
     } catch (Throwable t) {
-        isExported = false;
+        isAllModulesExported = false;
         LOGGER.error("Failed to export all module package to all", t);
     }
 }

Also applies to: 63-63, 87-87

Comment on lines +254 to +252
return (Map<String, Module>) getModuleLayerFieldsValue("nameToModule");
}
Copy link

Choose a reason for hiding this comment

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

Handle potential ClassCastException in getNameToModule()

Casting the result of getModuleLayerFieldsValue("nameToModule") to (Map<String, Module>) may result in a ClassCastException if the field does not contain the expected type. Consider adding a type check before casting to ensure safety.

Apply this diff to safely handle the cast:

 public static Map<String, Module> getNameToModule() {
-    return (Map<String, Module>) getModuleLayerFieldsValue("nameToModule");
+    Object moduleMap = getModuleLayerFieldsValue("nameToModule");
+    if (moduleMap instanceof Map) {
+        return (Map<String, Module>) moduleMap;
+    } else {
+        LOGGER.error("Expected nameToModule to be a Map<String, Module>, but got: {}", moduleMap);
+        return null;
+    }
 }
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
return (Map<String, Module>) getModuleLayerFieldsValue("nameToModule");
}
public static Map<String, Module> getNameToModule() {
Object moduleMap = getModuleLayerFieldsValue("nameToModule");
if (moduleMap instanceof Map) {
return (Map<String, Module>) moduleMap;
} else {
LOGGER.error("Expected nameToModule to be a Map<String, Module>, but got: {}", moduleMap);
return null;
}
}

@CrazyHZM CrazyHZM force-pushed the feat/dynamic_export_and_open branch 5 times, most recently from e95642b to 3663c21 Compare September 23, 2024 06:39
@sofastack-cla sofastack-cla bot added size/L and removed size/XL labels Sep 23, 2024
Copy link
Contributor

@HzjNeverStop HzjNeverStop left a comment

Choose a reason for hiding this comment

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

LGTM

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

Outside diff range and nitpick comments (1)
sofa-boot-project/sofa-boot/src/test/java/com/alipay/sofa/boot/initializer/AutoModuleExportApplicationContextInitializerTests.java (1)

33-77: Consider adding tests for edge cases and combined configurations.

The current test suite covers the main scenarios well. To further improve the test coverage, consider adding tests for:

  1. Combined configurations (e.g., both JDK and all module export enabled/disabled).
  2. Edge cases, such as invalid property values.
  3. Interaction with other related configurations or initializers, if any.

These additional tests would ensure robustness across a wider range of scenarios.

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 3663c21 and 24ac036.

Files selected for processing (2)
  • sofa-boot-project/sofa-boot/src/main/java/com/alipay/sofa/boot/util/ModuleUtil.java (1 hunks)
  • sofa-boot-project/sofa-boot/src/test/java/com/alipay/sofa/boot/initializer/AutoModuleExportApplicationContextInitializerTests.java (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • sofa-boot-project/sofa-boot/src/main/java/com/alipay/sofa/boot/util/ModuleUtil.java
Additional comments not posted (6)
sofa-boot-project/sofa-boot/src/test/java/com/alipay/sofa/boot/initializer/AutoModuleExportApplicationContextInitializerTests.java (6)

1-33: LGTM: File structure and imports are well-organized.

The file has the appropriate license header, correct package declaration, and all necessary imports. The class is properly annotated with author and version information.


35-42: LGTM: Proper test setup.

The setUp method correctly resets the ModuleUtil state and initializes the ApplicationContextRunner with the AutoModuleExportApplicationContextInitializer. This ensures a clean state before each test execution.


44-51: LGTM: Correct verification of default JDK module export behavior.

The jdkDefaultTrue test method effectively verifies that exportAllJDKModulePackageToAll is called once when no specific properties are set, which is the expected default behavior.


53-59: LGTM: Correct verification of default all module export behavior.

The allDefaultFalse test method effectively verifies that exportAllModulePackageToAll is not called when no specific properties are set, which is the expected default behavior.


61-68: LGTM: Correct verification of disabled JDK module export behavior.

The jdkDisable test method effectively verifies that exportAllJDKModulePackageToAll is not called when the property sofa.boot.auto.module.export.jdk.enable is set to false, which is the expected behavior when JDK module export is explicitly disabled.


70-76: LGTM: Correct verification of enabled all module export behavior.

The allEnable test method effectively verifies that exportAllModulePackageToAll is called once when the property sofa.boot.auto.module.export.all.enable is set to true, which is the expected behavior when all module export is explicitly enabled.

@sofastack-cla sofastack-cla bot added size/L and removed size/XL labels Sep 23, 2024
@HzjNeverStop HzjNeverStop merged commit 5ca7e69 into sofastack:master Sep 23, 2024
5 of 7 checks passed
@CrazyHZM CrazyHZM deleted the feat/dynamic_export_and_open branch September 23, 2024 10:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants