From 19e0b0e434113ccc1fe06c47683597526af52908 Mon Sep 17 00:00:00 2001 From: Roberto Perez Alcolea Date: Tue, 14 Nov 2023 12:57:22 -0800 Subject: [PATCH] GenerateLockTask: go back to conventionMapping --- .../DependencyLockTaskConfigurer.groovy | 6 +- .../tasks/GenerateLockTask.groovy | 5 +- .../tasks/GenerateLockTaskSpec.groovy | 84 ++++++++++++------- .../tasks/UpdateLockTaskSpec.groovy | 18 ++-- 4 files changed, 73 insertions(+), 40 deletions(-) diff --git a/src/main/groovy/nebula/plugin/dependencylock/DependencyLockTaskConfigurer.groovy b/src/main/groovy/nebula/plugin/dependencylock/DependencyLockTaskConfigurer.groovy index c779be5..1cfc022 100644 --- a/src/main/groovy/nebula/plugin/dependencylock/DependencyLockTaskConfigurer.groovy +++ b/src/main/groovy/nebula/plugin/dependencylock/DependencyLockTaskConfigurer.groovy @@ -200,7 +200,8 @@ class DependencyLockTaskConfigurer { shouldIgnoreDependencyLock.set(isIgnoreDependencyLock(project)) filter.set(extension.dependencyFilter) peers.set(getProjectPeers()) - configurationResolutionData.set( + generateLockTask.conventionMapping.with { + configurationResolutionData = { lockableConfigurations(project, extension.configurationNames.get(), extension.skippedConfigurationNamesPrefixes.get()).findAll { it.isCanBeResolved() }.collect { new ConfigurationResolutionData( it.name, @@ -208,7 +209,8 @@ class DependencyLockTaskConfigurer { it.incoming.resolutionResult.rootComponent ) } - ) + } + } } lockTask diff --git a/src/main/groovy/nebula/plugin/dependencylock/tasks/GenerateLockTask.groovy b/src/main/groovy/nebula/plugin/dependencylock/tasks/GenerateLockTask.groovy index 82bb7e9..f68e358 100644 --- a/src/main/groovy/nebula/plugin/dependencylock/tasks/GenerateLockTask.groovy +++ b/src/main/groovy/nebula/plugin/dependencylock/tasks/GenerateLockTask.groovy @@ -16,18 +16,17 @@ package nebula.plugin.dependencylock.tasks import nebula.plugin.dependencylock.model.ConfigurationResolutionData -import org.gradle.api.provider.ListProperty import org.gradle.api.tasks.Internal import org.gradle.work.DisableCachingByDefault @DisableCachingByDefault abstract class GenerateLockTask extends AbstractGenerateLockTask { @Internal - abstract ListProperty getConfigurationResolutionData() + Collection configurationResolutionData = [] @Override List resolveConfigurations() { - return configurationResolutionData.get() + return getConfigurationResolutionData() } } diff --git a/src/test/groovy/nebula/plugin/dependencylock/tasks/GenerateLockTaskSpec.groovy b/src/test/groovy/nebula/plugin/dependencylock/tasks/GenerateLockTaskSpec.groovy index 9943a1f..307d810 100644 --- a/src/test/groovy/nebula/plugin/dependencylock/tasks/GenerateLockTaskSpec.groovy +++ b/src/test/groovy/nebula/plugin/dependencylock/tasks/GenerateLockTaskSpec.groovy @@ -45,7 +45,8 @@ class GenerateLockTaskSpec extends ProjectSpec { task.dependenciesLock.set new File(project.layout.buildDirectory.getAsFile().get(), 'dependencies.lock') task.configurationNames.set(['testRuntimeClasspath']) task.configure { generateLockTask -> - generateLockTask.configurationResolutionData.set( + generateLockTask.conventionMapping.with { + configurationResolutionData = { lockableConfigurations(project, ['testRuntimeClasspath'] as Set).findAll { it.isCanBeResolved() }.collect { new ConfigurationResolutionData( it.name, @@ -53,7 +54,8 @@ class GenerateLockTaskSpec extends ProjectSpec { it.incoming.resolutionResult.rootComponent ) } - ) + } + } } @@ -93,7 +95,8 @@ class GenerateLockTaskSpec extends ProjectSpec { task.configurationNames.set configurationNames task.configure { generateLockTask -> - generateLockTask.configurationResolutionData.set( + generateLockTask.conventionMapping.with { + configurationResolutionData = { lockableConfigurations(project, configurationNames).findAll { it.isCanBeResolved() }.collect { new ConfigurationResolutionData( it.name, @@ -101,7 +104,8 @@ class GenerateLockTaskSpec extends ProjectSpec { it.incoming.resolutionResult.rootComponent ) } - ) + } + } } when: @@ -141,7 +145,8 @@ class GenerateLockTaskSpec extends ProjectSpec { def skippedConfigurationNames = ['zinc', 'incrementalAnalysis'] as Set task.skippedConfigurationNames.set(skippedConfigurationNames) task.configure { generateLockTask -> - generateLockTask.configurationResolutionData.set( + generateLockTask.conventionMapping.with { + configurationResolutionData = { lockableConfigurations(project,configurationNames, skippedConfigurationNames).findAll { it.isCanBeResolved() }.collect { new ConfigurationResolutionData( it.name, @@ -149,7 +154,8 @@ class GenerateLockTaskSpec extends ProjectSpec { it.incoming.resolutionResult.rootComponent ) } - ) + } + } } when: @@ -179,7 +185,8 @@ class GenerateLockTaskSpec extends ProjectSpec { task.skippedDependencies.set(['test.example:foo']) task.includeTransitives.set(true) task.configure { generateLockTask -> - generateLockTask.configurationResolutionData.set( + generateLockTask.conventionMapping.with { + configurationResolutionData = { lockableConfigurations(project, ['testRuntimeClasspath'] as Set).findAll { it.isCanBeResolved() }.collect { new ConfigurationResolutionData( it.name, @@ -187,7 +194,8 @@ class GenerateLockTaskSpec extends ProjectSpec { it.incoming.resolutionResult.rootComponent ) } - ) + } + } } String lockText = '''\ @@ -233,7 +241,8 @@ class GenerateLockTaskSpec extends ProjectSpec { task.dependenciesLock.set(new File(app.layout.buildDirectory.getAsFile().get(), 'dependencies.lock')) task.configurationNames.set( ['testRuntimeClasspath']) task.configure { generateLockTask -> - generateLockTask.configurationResolutionData.set( + generateLockTask.conventionMapping.with { + configurationResolutionData = { lockableConfigurations(project, ['testRuntimeClasspath'] as Set).findAll { it.isCanBeResolved() }.collect { new ConfigurationResolutionData( it.name, @@ -241,7 +250,8 @@ class GenerateLockTaskSpec extends ProjectSpec { it.incoming.resolutionResult.rootComponent ) } - ) + } + } } task.peers.set(app.rootProject.allprojects.collect { new LockKey(group: it.group, artifact: it.name) }) @@ -290,7 +300,8 @@ class GenerateLockTaskSpec extends ProjectSpec { task.configurationNames.set(['testRuntimeClasspath']) task.includeTransitives.set(true) task.configure { generateLockTask -> - generateLockTask.configurationResolutionData.set( + generateLockTask.conventionMapping.with { + configurationResolutionData = { lockableConfigurations(project, ['testRuntimeClasspath'] as Set).findAll { it.isCanBeResolved() }.collect { new ConfigurationResolutionData( it.name, @@ -298,7 +309,8 @@ class GenerateLockTaskSpec extends ProjectSpec { it.incoming.resolutionResult.rootComponent ) } - ) + } + } } task.peers.set(app.rootProject.allprojects.collect { new LockKey(group: it.group, artifact: it.name) }) @@ -355,7 +367,8 @@ class GenerateLockTaskSpec extends ProjectSpec { task.dependenciesLock.set new File(app.layout.buildDirectory.getAsFile().get(), 'dependencies.lock') task.configurationNames.set(['testRuntimeClasspath']) task.configure { generateLockTask -> - generateLockTask.configurationResolutionData.set( + generateLockTask.conventionMapping.with { + configurationResolutionData = { lockableConfigurations(project, ['testRuntimeClasspath'] as Set).findAll { it.isCanBeResolved() }.collect { new ConfigurationResolutionData( it.name, @@ -363,7 +376,8 @@ class GenerateLockTaskSpec extends ProjectSpec { it.incoming.resolutionResult.rootComponent ) } - ) + } + } } task.peers.set(app.rootProject.allprojects.collect { new LockKey(group: it.group, artifact: it.name) }) @@ -441,7 +455,8 @@ class GenerateLockTaskSpec extends ProjectSpec { task.dependenciesLock.set new File(app.layout.buildDirectory.getAsFile().get(), 'dependencies.lock') task.configurationNames.set(['testRuntimeClasspath']) task.configure { generateLockTask -> - generateLockTask.configurationResolutionData.set( + generateLockTask.conventionMapping.with { + configurationResolutionData = { lockableConfigurations(project, ['testRuntimeClasspath'] as Set).findAll { it.isCanBeResolved() }.collect { new ConfigurationResolutionData( it.name, @@ -449,7 +464,8 @@ class GenerateLockTaskSpec extends ProjectSpec { it.incoming.resolutionResult.rootComponent ) } - ) + } + } } task.peers.set(app.rootProject.allprojects.collect { new LockKey(group: it.group, artifact: it.name) }) @@ -500,7 +516,8 @@ class GenerateLockTaskSpec extends ProjectSpec { task.configurationNames.set(['testRuntimeClasspath']) task.includeTransitives.set true task.configure { generateLockTask -> - generateLockTask.configurationResolutionData.set( + generateLockTask.conventionMapping.with { + configurationResolutionData = { lockableConfigurations(project, ['testRuntimeClasspath'] as Set).findAll { it.isCanBeResolved() }.collect { new ConfigurationResolutionData( it.name, @@ -508,7 +525,8 @@ class GenerateLockTaskSpec extends ProjectSpec { it.incoming.resolutionResult.rootComponent ) } - ) + } + } } when: @@ -545,7 +563,8 @@ class GenerateLockTaskSpec extends ProjectSpec { task.configurationNames.set(['testRuntimeClasspath']) task.includeTransitives.set true task.configure { generateLockTask -> - generateLockTask.configurationResolutionData.set( + generateLockTask.conventionMapping.with { + configurationResolutionData = { lockableConfigurations(project, ['testRuntimeClasspath'] as Set).findAll { it.isCanBeResolved() }.collect { new ConfigurationResolutionData( it.name, @@ -553,7 +572,8 @@ class GenerateLockTaskSpec extends ProjectSpec { it.incoming.resolutionResult.rootComponent ) } - ) + } + } } when: @@ -593,7 +613,8 @@ class GenerateLockTaskSpec extends ProjectSpec { task.configurationNames.set(['testRuntimeClasspath']) task.includeTransitives.set true task.configure { generateLockTask -> - generateLockTask.configurationResolutionData.set( + generateLockTask.conventionMapping.with { + configurationResolutionData = { lockableConfigurations(project, ['testRuntimeClasspath'] as Set).findAll { it.isCanBeResolved() }.collect { new ConfigurationResolutionData( it.name, @@ -601,7 +622,8 @@ class GenerateLockTaskSpec extends ProjectSpec { it.incoming.resolutionResult.rootComponent ) } - ) + } + } } when: @@ -646,7 +668,8 @@ class GenerateLockTaskSpec extends ProjectSpec { task.configurationNames.set(['testRuntimeClasspath']) task.includeTransitives.set true task.configure { generateLockTask -> - generateLockTask.configurationResolutionData.set( + generateLockTask.conventionMapping.with { + configurationResolutionData = { lockableConfigurations(project, ['testRuntimeClasspath'] as Set).findAll { it.isCanBeResolved() }.collect { new ConfigurationResolutionData( it.name, @@ -654,7 +677,8 @@ class GenerateLockTaskSpec extends ProjectSpec { it.incoming.resolutionResult.rootComponent ) } - ) + } + } } when: task.lock() @@ -700,7 +724,8 @@ class GenerateLockTaskSpec extends ProjectSpec { task.configurationNames.set(['testRuntimeClasspath']) task.includeTransitives.set true task.configure { generateLockTask -> - generateLockTask.configurationResolutionData.set( + generateLockTask.conventionMapping.with { + configurationResolutionData = { lockableConfigurations(project, ['testRuntimeClasspath'] as Set).findAll { it.isCanBeResolved() }.collect { new ConfigurationResolutionData( it.name, @@ -708,7 +733,8 @@ class GenerateLockTaskSpec extends ProjectSpec { it.incoming.resolutionResult.rootComponent ) } - ) + } + } } when: task.lock() @@ -765,7 +791,8 @@ class GenerateLockTaskSpec extends ProjectSpec { task.configurationNames.set(['testRuntimeClasspath']) task.filter.set(filter as Closure) task.configure { generateLockTask -> - generateLockTask.configurationResolutionData.set( + generateLockTask.conventionMapping.with { + configurationResolutionData = { lockableConfigurations(project, ['testRuntimeClasspath'] as Set).findAll { it.isCanBeResolved() }.collect { new ConfigurationResolutionData( it.name, @@ -773,7 +800,8 @@ class GenerateLockTaskSpec extends ProjectSpec { it.incoming.resolutionResult.rootComponent ) } - ) + } + } } when: diff --git a/src/test/groovy/nebula/plugin/dependencylock/tasks/UpdateLockTaskSpec.groovy b/src/test/groovy/nebula/plugin/dependencylock/tasks/UpdateLockTaskSpec.groovy index 4e98259..0f99966 100644 --- a/src/test/groovy/nebula/plugin/dependencylock/tasks/UpdateLockTaskSpec.groovy +++ b/src/test/groovy/nebula/plugin/dependencylock/tasks/UpdateLockTaskSpec.groovy @@ -39,13 +39,17 @@ class UpdateLockTaskSpec extends ProjectSpec { task.dependenciesLock = new File(project.layout.buildDirectory.getAsFile().get(), 'dependencies.lock') task.configurationNames = LockGenerator.DEFAULT_CONFIG_NAMES task.configure { generateLockTask -> - configurationResolutionData.set(lockableConfigurations(project, LockGenerator.DEFAULT_CONFIG_NAMES as Set).findAll { it.isCanBeResolved() }.collect { - new ConfigurationResolutionData( - it.name, - it.incoming.resolutionResult.getAllDependencies(), - it.incoming.resolutionResult.rootComponent - ) - }) + generateLockTask.conventionMapping.with { + configurationResolutionData = { + lockableConfigurations(project, LockGenerator.DEFAULT_CONFIG_NAMES as Set).findAll { it.isCanBeResolved() }.collect { + new ConfigurationResolutionData( + it.name, + it.incoming.resolutionResult.getAllDependencies(), + it.incoming.resolutionResult.rootComponent + ) + } + } + } } task }