|
33 | 33 | import org.gradle.api.file.Directory; |
34 | 34 | import org.gradle.api.file.ProjectLayout; |
35 | 35 | import org.gradle.api.file.RegularFile; |
| 36 | +import org.gradle.api.file.RegularFileProperty; |
36 | 37 | import org.gradle.api.plugins.HelpTasksPlugin; |
37 | 38 | import org.gradle.api.plugins.JavaPlugin; |
38 | 39 | import org.gradle.api.provider.Provider; |
39 | 40 | import org.gradle.api.tasks.SourceSetContainer; |
40 | 41 | import org.gradle.util.GradleVersion; |
41 | 42 | import org.gradlex.javamodule.moduleinfo.tasks.ModuleDescriptorRecommendation; |
42 | 43 |
|
| 44 | +import java.io.CharArrayReader; |
43 | 45 | import java.io.File; |
| 46 | +import java.io.IOException; |
| 47 | +import java.lang.reflect.Method; |
44 | 48 | import java.util.Collection; |
| 49 | +import java.util.Collections; |
45 | 50 | import java.util.Comparator; |
46 | 51 | import java.util.List; |
47 | 52 | import java.util.Map; |
| 53 | +import java.util.Properties; |
48 | 54 | import java.util.Set; |
49 | 55 | import java.util.stream.Collectors; |
50 | 56 | import java.util.stream.Stream; |
@@ -198,12 +204,40 @@ private void registerTransform(String fileExtension, Project project, ExtraJavaM |
198 | 204 | .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue, (k1, k2) -> k1)).entrySet().stream() |
199 | 205 | .collect(Collectors.toMap(Map.Entry::getKey, c -> new PublishedMetadata(c.getKey(), c.getValue(), project))) |
200 | 206 | )); |
| 207 | + |
| 208 | + p.getAdditionalKnownModules().set(extractFromModuleDependenciesPlugin(project)); |
201 | 209 | }); |
202 | 210 | t.getFrom().attribute(artifactType, fileExtension).attribute(javaModule, false); |
203 | 211 | t.getTo().attribute(artifactType, fileExtension).attribute(javaModule, true); |
204 | 212 | }); |
205 | 213 | } |
206 | 214 |
|
| 215 | + private Provider<Map<String, String>> extractFromModuleDependenciesPlugin(Project project) { |
| 216 | + return project.provider(() -> { |
| 217 | + Object javaModuleDependencies = project.getExtensions().findByName("javaModuleDependencies"); |
| 218 | + if (javaModuleDependencies == null) { |
| 219 | + return Collections.emptyMap(); |
| 220 | + } |
| 221 | + try { |
| 222 | + Method getModulesProperties = javaModuleDependencies.getClass().getMethod("getModulesProperties"); |
| 223 | + RegularFileProperty file = (RegularFileProperty) getModulesProperties.invoke(javaModuleDependencies); |
| 224 | + return project.getProviders().fileContents(file).getAsText().map(c -> { |
| 225 | + Properties p = new Properties(); |
| 226 | + try { |
| 227 | + p.load(new CharArrayReader(c.toCharArray())); |
| 228 | + } catch (IOException e) { |
| 229 | + throw new RuntimeException(e); |
| 230 | + } |
| 231 | + @SuppressWarnings({"rawtypes", "unchecked"}) |
| 232 | + Map<String, String> result = (Map) p; |
| 233 | + return result; |
| 234 | + }).getOrElse(Collections.emptyMap()); |
| 235 | + } catch (ReflectiveOperationException e) { |
| 236 | + throw new RuntimeException(e); |
| 237 | + } |
| 238 | + }); |
| 239 | + } |
| 240 | + |
207 | 241 | private Stream<Map.Entry<String, Configuration>> existingComponentsOfInterest(Configuration resolvable, ExtraJavaModuleInfoPluginExtension extension) { |
208 | 242 | Set<String> componentsOfInterest = componentsOfInterest(extension); |
209 | 243 | if (componentsOfInterest.isEmpty()) { |
|
0 commit comments