|
25 | 25 | import org.gradle.api.artifacts.component.ComponentIdentifier; |
26 | 26 | import org.gradle.api.artifacts.component.ModuleComponentIdentifier; |
27 | 27 | import org.gradle.api.artifacts.dsl.DependencyHandler; |
28 | | -import org.gradle.api.artifacts.result.DependencyResult; |
29 | 28 | import org.gradle.api.artifacts.result.ResolvedArtifactResult; |
30 | 29 | import org.gradle.api.artifacts.result.ResolvedComponentResult; |
31 | | -import org.gradle.api.artifacts.result.ResolvedDependencyResult; |
32 | 30 | import org.gradle.api.attributes.Attribute; |
33 | 31 | import org.gradle.api.attributes.Category; |
34 | 32 | import org.gradle.api.attributes.Usage; |
|
60 | 58 | /** |
61 | 59 | * Entry point of the plugin. |
62 | 60 | */ |
63 | | -@SuppressWarnings("unused") |
64 | 61 | @NonNullApi |
65 | 62 | public abstract class ExtraJavaModuleInfoPlugin implements Plugin<Project> { |
66 | | - private static final Attribute<String> CATEGORY_ATTRIBUTE_UNTYPED = Attribute.of(CATEGORY_ATTRIBUTE.getName(), String.class); |
67 | 63 |
|
68 | 64 | @Override |
69 | 65 | public void apply(Project project) { |
@@ -193,57 +189,44 @@ private void registerTransform(String fileExtension, Project project, ExtraJavaM |
193 | 189 | p.getMergeJarIds().set(artifacts.map(new IdExtractor())); |
194 | 190 | p.getMergeJars().set(artifacts.map(new FileExtractor(project.getLayout()))); |
195 | 191 |
|
196 | | - p.getCompileClasspathDependencies().set(project.provider(() -> |
197 | | - toStringMap(sourceSets.stream().flatMap(s -> filteredResolutionResult(configurations.getByName(s.getCompileClasspathConfigurationName()), componentsOfInterest(extension)))))); |
198 | | - p.getRuntimeClasspathDependencies().set(project.provider(() -> |
199 | | - toStringMap(sourceSets.stream().flatMap(s -> filteredResolutionResult(configurations.getByName(s.getRuntimeClasspathConfigurationName()), componentsOfInterest(extension)))))); |
200 | | - p.getAnnotationProcessorClasspathDependencies().set(project.provider(() -> |
201 | | - toStringMap(sourceSets.stream().flatMap(s -> filteredResolutionResult(configurations.getByName(s.getAnnotationProcessorConfigurationName()), componentsOfInterest(extension)))))); |
| 192 | + p.getRequiresFromMetadata().set(project.provider(() -> sourceSets.stream().flatMap(s -> Stream.of( |
| 193 | + s.getRuntimeClasspathConfigurationName(), |
| 194 | + s.getCompileClasspathConfigurationName(), |
| 195 | + s.getAnnotationProcessorConfigurationName() |
| 196 | + )) |
| 197 | + .flatMap(resolvable -> existingComponentsOfInterest(configurations.getByName(resolvable), extension)) |
| 198 | + .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue, (k1, k2) -> k1)).entrySet().stream() |
| 199 | + .collect(Collectors.toMap(Map.Entry::getKey, c -> new PublishedMetadata(c.getKey(), c.getValue(), project))) |
| 200 | + )); |
202 | 201 | }); |
203 | 202 | t.getFrom().attribute(artifactType, fileExtension).attribute(javaModule, false); |
204 | 203 | t.getTo().attribute(artifactType, fileExtension).attribute(javaModule, true); |
205 | 204 | }); |
206 | 205 | } |
207 | 206 |
|
208 | | - private static Set<String> componentsOfInterest(ExtraJavaModuleInfoPluginExtension extension) { |
209 | | - return extension.getModuleSpecs().get().values().stream().filter(ExtraJavaModuleInfoPlugin::needsDependencies).map(ModuleSpec::getIdentifier).collect(Collectors.toSet()); |
210 | | - } |
211 | | - |
212 | | - private Stream<ResolvedComponentResult> filteredResolutionResult(Configuration configuration, Set<String> componentsOfInterest) { |
| 207 | + private Stream<Map.Entry<String, Configuration>> existingComponentsOfInterest(Configuration resolvable, ExtraJavaModuleInfoPluginExtension extension) { |
| 208 | + Set<String> componentsOfInterest = componentsOfInterest(extension); |
213 | 209 | if (componentsOfInterest.isEmpty()) { |
214 | 210 | return Stream.empty(); |
215 | 211 | } |
216 | | - return configuration.getIncoming().getResolutionResult().getAllComponents().stream().filter(c -> componentsOfInterest.contains(ga(c.getId()))); |
| 212 | + |
| 213 | + return resolvable.getIncoming().getResolutionResult().getAllComponents().stream() |
| 214 | + .filter(c -> componentsOfInterest.contains(ga(c.getId()))) |
| 215 | + .collect(Collectors.toMap(c -> c.getId().toString(), c -> resolvable)).entrySet().stream(); |
217 | 216 | } |
218 | 217 |
|
219 | | - private Map<String, Set<String>> toStringMap(Stream<ResolvedComponentResult> result) { |
220 | | - return result.collect(Collectors.toMap( |
221 | | - c -> ga(c.getId()), |
222 | | - c -> c.getDependencies().stream().filter(ExtraJavaModuleInfoPlugin::filterComponentDependencies).map(ExtraJavaModuleInfoPlugin::ga).collect(Collectors.toSet()), |
223 | | - (dependencies1, dependencies2) -> dependencies1)); |
| 218 | + private static Set<String> componentsOfInterest(ExtraJavaModuleInfoPluginExtension extension) { |
| 219 | + return extension.getModuleSpecs().get().values().stream() |
| 220 | + .filter(ExtraJavaModuleInfoPlugin::needsDependencies) |
| 221 | + .map(ModuleSpec::getIdentifier) |
| 222 | + .collect(Collectors.toSet()); |
224 | 223 | } |
225 | 224 |
|
226 | 225 | private static boolean needsDependencies(ModuleSpec moduleSpec) { |
227 | 226 | return moduleSpec instanceof ModuleInfo && ((ModuleInfo) moduleSpec).requireAllDefinedDependencies; |
228 | 227 | } |
229 | 228 |
|
230 | | - private static boolean filterComponentDependencies(DependencyResult d) { |
231 | | - if (d instanceof ResolvedDependencyResult) { |
232 | | - Category category = ((ResolvedDependencyResult) d).getResolvedVariant().getAttributes().getAttribute(CATEGORY_ATTRIBUTE); |
233 | | - String categoryUntyped = ((ResolvedDependencyResult) d).getResolvedVariant().getAttributes().getAttribute(CATEGORY_ATTRIBUTE_UNTYPED); |
234 | | - return LIBRARY.equals(categoryUntyped) || (category != null && LIBRARY.equals(category.getName())); |
235 | | - } |
236 | | - return false; |
237 | | - } |
238 | | - |
239 | | - private static String ga(DependencyResult d) { |
240 | | - if (d instanceof ResolvedDependencyResult) { |
241 | | - return ga(((ResolvedDependencyResult) d).getSelected().getId()); |
242 | | - } |
243 | | - return d.getRequested().getDisplayName(); |
244 | | - } |
245 | | - |
246 | | - private static String ga(ComponentIdentifier id) { |
| 229 | + static String ga(ComponentIdentifier id) { |
247 | 230 | if (id instanceof ModuleComponentIdentifier) { |
248 | 231 | return ((ModuleComponentIdentifier) id).getGroup() + ":" + ((ModuleComponentIdentifier) id).getModule(); |
249 | 232 | } |
|
0 commit comments