Skip to content

Commit

Permalink
Use shared mappings from 'java-module-dependencies' for 'known modules'
Browse files Browse the repository at this point in the history
  • Loading branch information
jjohannes committed Jan 3, 2024
1 parent 120812e commit c057d0c
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 6 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Extra Java Module Info Gradle Plugin - Changelog

## Version 1.6.2
* [New] - Use shared mappings from 'java-module-dependencies' for 'known modules' (if available)

## Version 1.6.1
* [Fixed] [#89](https://github.com/gradlex-org/extra-java-module-info/issues/89) - Make Jar patching reproducible

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -494,13 +494,31 @@ private byte[] readAllBytes(InputStream inputStream) throws IOException {

private String gaToModuleName(String ga) {
ModuleSpec moduleSpec = getParameters().getModuleSpecs().get().get(ga);
if (moduleSpec == null) {
throw new RuntimeException("[requires directives from metadata] " +
"The module name of the following component is not known: " + ga +
"\n - If it is already a module, make the module name known using 'knownModule(\"" + ga + "\", \"<module name>\")'" +
"\n - If it is not a module, patch it using 'module()' or 'automaticModule()'");
if (moduleSpec != null) {
return moduleSpec.getModuleName();
}
return moduleSpec.getModuleName();
String moduleNameFromSharedMapping = moduleNameFromSharedMapping(ga);
if (moduleNameFromSharedMapping != null) {
return moduleNameFromSharedMapping;
}

throw new RuntimeException("[requires directives from metadata] " +
"The module name of the following component is not known: " + ga +
"\n - If it is already a module, make the module name known using 'knownModule(\"" + ga + "\", \"<module name>\")'" +
"\n - If it is not a module, patch it using 'module()' or 'automaticModule()'");
}

@Nullable
private String moduleNameFromSharedMapping(String ga) {
try {
Class<?> sharedMappings = Class.forName("org.gradlex.javamodule.dependencies.SharedMappings");
@SuppressWarnings("unchecked")
Map<String, String> mappings = (Map<String, String>) sharedMappings.getDeclaredField("mappings").get(null);
Optional<String> found = mappings.entrySet().stream().filter(
e -> e.getValue().equals(ga)).map(Map.Entry::getKey).findFirst();
return found.orElse(null);
} catch (ReflectiveOperationException ignored) { }
return null;
}

private static boolean isModuleInfoClass(String jarEntryName) {
Expand Down

0 comments on commit c057d0c

Please sign in to comment.