|
13 | 13 | import org.gradle.TaskExecutionRequest; |
14 | 14 | import org.gradle.api.Action; |
15 | 15 | import org.gradle.api.DomainObjectCollection; |
| 16 | +import org.gradle.api.NamedDomainObjectContainer; |
16 | 17 | import org.gradle.api.NamedDomainObjectSet; |
17 | 18 | import org.gradle.api.Project; |
18 | 19 | import org.gradle.api.Transformer; |
@@ -350,6 +351,49 @@ public static Set<Dependency> collect(NamedDomainObjectSet<Configuration> config |
350 | 351 | .collect(Collectors.toSet()); |
351 | 352 | } |
352 | 353 |
|
| 354 | + public static NamedDomainObjectSet<SourceSet> collect(Project project, boolean transitive, Dependency dependency) { |
| 355 | + return collect(project, transitive, dependency::equals); |
| 356 | + } |
| 357 | + |
| 358 | + public static NamedDomainObjectSet<SourceSet> collect(Project project, boolean transitive, Spec<? super Dependency> dependency) { |
| 359 | + return collect( |
| 360 | + project.getExtensions().getByType(JavaPluginExtension.class).getSourceSets(), |
| 361 | + project.getConfigurations(), |
| 362 | + transitive, |
| 363 | + dependency |
| 364 | + ); |
| 365 | + } |
| 366 | + |
| 367 | + public static NamedDomainObjectSet<SourceSet> collect(NamedDomainObjectContainer<SourceSet> sourceSets, NamedDomainObjectSet<Configuration> configurations, boolean transitive, Dependency dependency) { |
| 368 | + return collect(sourceSets, configurations, transitive, dependency::equals); |
| 369 | + } |
| 370 | + |
| 371 | + public static NamedDomainObjectSet<SourceSet> collect(NamedDomainObjectContainer<SourceSet> sourceSets, NamedDomainObjectSet<Configuration> configurations, boolean transitive, Spec<? super Dependency> dependency) { |
| 372 | + return sourceSets.matching(sourceSet -> { |
| 373 | + var candidates = configurations.named(name -> |
| 374 | + // Always check these resolvable configurations |
| 375 | + name.equals(sourceSet.getCompileClasspathConfigurationName()) |
| 376 | + || name.equals(sourceSet.getRuntimeClasspathConfigurationName()) |
| 377 | + || name.equals(sourceSet.getAnnotationProcessorConfigurationName()) |
| 378 | + |
| 379 | + // If not checking transitively, we need to check these declared configurations as well |
| 380 | + || (!transitive && ( |
| 381 | + name.equals(sourceSet.getCompileOnlyConfigurationName()) |
| 382 | + || name.equals(sourceSet.getCompileOnlyApiConfigurationName()) |
| 383 | + || name.equals(sourceSet.getRuntimeOnlyConfigurationName()) |
| 384 | + || name.equals(sourceSet.getImplementationConfigurationName()) |
| 385 | + || name.equals(sourceSet.getApiConfigurationName()) |
| 386 | + )) |
| 387 | + ); |
| 388 | + |
| 389 | + // The candidate matches if the dependency set matches our dependency spec |
| 390 | + return !candidates.matching(configuration -> { |
| 391 | + var dependencies = transitive ? configuration.getAllDependencies() : configuration.getDependencies(); |
| 392 | + return !dependencies.matching(dependency).isEmpty(); |
| 393 | + }).isEmpty(); |
| 394 | + }); |
| 395 | + } |
| 396 | + |
353 | 397 | static <T> void guardCheck(T t) { } |
354 | 398 |
|
355 | 399 | /// Iterates through the given source set's classpath configurations using the given action. |
|
0 commit comments