Skip to content

Commit

Permalink
Auto module export with reentrant protection
Browse files Browse the repository at this point in the history
Signed-off-by: JermaineHua <[email protected]>
  • Loading branch information
CrazyHZM committed Sep 23, 2024
1 parent 6d844ab commit 4008141
Showing 1 changed file with 14 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,21 @@
*/
public class ModuleUtil {

Check warning on line 31 in sofa-boot-project/sofa-boot/src/main/java/com/alipay/sofa/boot/util/ModuleUtil.java

View check run for this annotation

Codecov / codecov/patch

sofa-boot-project/sofa-boot/src/main/java/com/alipay/sofa/boot/util/ModuleUtil.java#L31

Added line #L31 was not covered by tests

private static final Logger LOGGER = SofaBootLoggerFactory
.getLogger(ModuleUtil.class);
private static final Logger LOGGER = SofaBootLoggerFactory
.getLogger(ModuleUtil.class);

private static final MethodHandle implAddOpensToAllUnnamed;

private static final MethodHandle implAddOpens;

private static final MethodHandle implAddExportsToAllUnnamed;

private static final MethodHandle implAddExports;

private static final Map<String, Module> nameToModules;

private static boolean isExported = false;

static {
implAddOpensToAllUnnamed = createModuleMethodHandle("implAddOpensToAllUnnamed",
String.class);
Expand All @@ -54,15 +60,17 @@ public class ModuleUtil {
*/
public static void exportAllJDKModulePackageToAll() {
try {
if (nameToModules != null) {
if (!isExported && nameToModules != null) {
nameToModules.forEach((name, module) -> module.getPackages().forEach(pkgName -> {
if (isJDKModulePackage(pkgName)) {
addOpensToAll(module, pkgName);
addExportsToAll(module, pkgName);
}
}));
}
isExported = true;
} catch (Throwable t) {
isExported = false;
LOGGER.error("Failed to export all JDK module package to all", t);

Check warning on line 74 in sofa-boot-project/sofa-boot/src/main/java/com/alipay/sofa/boot/util/ModuleUtil.java

View check run for this annotation

Codecov / codecov/patch

sofa-boot-project/sofa-boot/src/main/java/com/alipay/sofa/boot/util/ModuleUtil.java#L72-L74

Added lines #L72 - L74 were not covered by tests
}
}
Expand All @@ -76,14 +84,15 @@ private static boolean isJDKModulePackage(String modulePackageName) {
*/
public static void exportAllModulePackageToAll() {
try {
Map<String, Module> nameToModules = getNameToModule();
if (nameToModules != null) {
if (!isExported && nameToModules != null) {
nameToModules.forEach((name, module) -> module.getPackages().forEach(pkgName -> {
addOpensToAll(module, pkgName);
addExportsToAll(module, pkgName);
}));

Check warning on line 91 in sofa-boot-project/sofa-boot/src/main/java/com/alipay/sofa/boot/util/ModuleUtil.java

View check run for this annotation

Codecov / codecov/patch

sofa-boot-project/sofa-boot/src/main/java/com/alipay/sofa/boot/util/ModuleUtil.java#L88-L91

Added lines #L88 - L91 were not covered by tests
}
isExported = true;
} catch (Throwable t) {
isExported = false;
LOGGER.error("Failed to export all module package to all", t);
}
}

Check warning on line 98 in sofa-boot-project/sofa-boot/src/main/java/com/alipay/sofa/boot/util/ModuleUtil.java

View check run for this annotation

Codecov / codecov/patch

sofa-boot-project/sofa-boot/src/main/java/com/alipay/sofa/boot/util/ModuleUtil.java#L93-L98

Added lines #L93 - L98 were not covered by tests
Expand Down

0 comments on commit 4008141

Please sign in to comment.