Skip to content

Commit

Permalink
VerifyPublicationTask: use Provider<ResolvedComponentResult> instead …
Browse files Browse the repository at this point in the history
…of runtimeClasspath
  • Loading branch information
rpalcolea committed Mar 21, 2023
1 parent 4e84395 commit a455d55
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class PublishVerificationPlugin implements Plugin<Project> {
void execute(VerifyPublicationTask verifyPublicationTask) {
verifyPublicationTask.projectName.set(project.name)
verifyPublicationTask.targetStatus.set(project.status.toString())
verifyPublicationTask.runtimeClasspath.set(project.configurations.named(sourceSet.getRuntimeClasspathConfigurationName()))
verifyPublicationTask.resolvedComponentResultProvider = project.configurations.named(sourceSet.getRuntimeClasspathConfigurationName()).get().incoming.resolutionResult.rootComponent
verifyPublicationTask.ignore.set(extension.ignore)
verifyPublicationTask.ignoreGroups.set(extension.ignoreGroups)
verifyPublicationTask.verificationViolationsCollectorHolderExtension.set(verificationViolationsCollectorHolderExtension)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@ import org.gradle.api.DefaultTask
import org.gradle.api.artifacts.*
import org.gradle.api.artifacts.component.ProjectComponentIdentifier
import org.gradle.api.artifacts.result.DependencyResult
import org.gradle.api.artifacts.result.ResolvedComponentResult
import org.gradle.api.artifacts.result.ResolvedDependencyResult
import org.gradle.api.artifacts.result.UnresolvedDependencyResult
import org.gradle.api.provider.ListProperty
import org.gradle.api.provider.Property
import org.gradle.api.provider.Provider
import org.gradle.api.provider.SetProperty
import org.gradle.api.tasks.Classpath
import org.gradle.api.tasks.Input
Expand All @@ -28,13 +30,12 @@ abstract class VerifyPublicationTask extends DefaultTask {
@Input
abstract Property<String> getTargetStatus()

@InputFiles
@Classpath
abstract Property<Configuration> getRuntimeClasspath()

@Input
abstract Property<String> getProjectName()

@Internal
Provider<ResolvedComponentResult> resolvedComponentResultProvider

@Input
abstract ListProperty<Dependency> getDefinedDependencies()

Expand All @@ -47,16 +48,16 @@ abstract class VerifyPublicationTask extends DefaultTask {

@TaskAction
void verifyDependencies() {
Set<ResolvedDependencyResult> firstLevel = getNonProjectDependencies(runtimeClasspath.get())
Set<ResolvedDependencyResult> firstLevel = getNonProjectDependencies(resolvedComponentResultProvider.get())
List<StatusVerificationViolation> violations = new StatusVerification(ignore.get(), ignoreGroups.get(), targetStatus.get()).verify(firstLevel)

List<VersionSelectorVerificationViolation> versionViolations = new VersionSelectorVerification(ignore.get(), ignoreGroups.get()).verify(definedDependencies.get())

verificationViolationsCollectorHolderExtension.get().collector.put(projectName.get(), new ViolationsContainer(statusViolations: violations, versionSelectorViolations: versionViolations))
}

private static Set<ResolvedDependencyResult> getNonProjectDependencies(Configuration runtimeClasspath) {
Set<? extends DependencyResult> firstLevelDependencies = runtimeClasspath.incoming.resolutionResult.root.getDependencies()
private static Set<ResolvedDependencyResult> getNonProjectDependencies(ResolvedComponentResult resolvedComponentResult) {
Set<? extends DependencyResult> firstLevelDependencies = resolvedComponentResult.dependencies
.findAll { !it.constraint }
List<UnresolvedDependencyResult> unresolvedDependencies = firstLevelDependencies.findAll { it instanceof UnresolvedDependencyResult } as List<UnresolvedDependencyResult>
if (! unresolvedDependencies.isEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ class VerifyPublicationTaskSpec extends Specification {
task.configure {
ignore.set(Collections.emptySet())
ignoreGroups.set(Collections.emptySet())
runtimeClasspath.set(project.configurations.getByName(project.sourceSets.main.getRuntimeClasspathConfigurationName()))
resolvedComponentResultProvider = project.configurations.named(project.sourceSets.main.getRuntimeClasspathConfigurationName()).get().incoming.resolutionResult.rootComponent
definedDependencies.set(project.configurations.collect { Configuration configuration ->
configuration.dependencies
}.flatten() as List<Dependency>)
Expand Down

0 comments on commit a455d55

Please sign in to comment.