Skip to content

Commit

Permalink
Merge pull request #176 from nebula-plugins/introduce-skippedConfigur…
Browse files Browse the repository at this point in the history
…ationNamesPrefixes

Introduce skipped configuration names prefixes
  • Loading branch information
rpalcolea committed Oct 12, 2019
2 parents 42998b5 + 1ac0d6f commit 7f8991b
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class DependencyLockExtension {
String lockFile = 'dependencies.lock'
String globalLockFile = 'global.lock'
Set<String> configurationNames = [] as Set
Set<String> skippedConfigurationNamesPrefixes = [] as Set
Closure dependencyFilter = { String group, String name, String version -> true }
Set<String> updateDependencies = [] as Set
Set<String> skippedDependencies = [] as Set
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ class DependencyLockTaskConfigurer {
new File(project.buildDir, clLockFileName ?: extension.lockFile)
}
configurationNames = { extension.configurationNames }
skippedConfigurationNames = { extension.skippedConfigurationNamesPrefixes }
}

lockTask
Expand Down Expand Up @@ -234,7 +235,7 @@ class DependencyLockTaskConfigurer {
def subprojects = project.subprojects.collect { subproject ->
def ext = subproject.getExtensions().findByType(DependencyLockExtension)
if (ext != null) {
Collection<Configuration> lockableConfigurations = lockableConfigurations(project, subproject, ext.configurationNames)
Collection<Configuration> lockableConfigurations = lockableConfigurations(project, subproject, ext.configurationNames, extension.skippedConfigurationNamesPrefixes)
Collection<Configuration> configurations = filterNonLockableConfigurationsAndProvideWarningsForGlobalLockSubproject(subproject, ext.configurationNames, lockableConfigurations)

configurations
Expand All @@ -252,7 +253,7 @@ class DependencyLockTaskConfigurer {
def conf = project.configurations.detachedConfiguration(subprojectsArray)
project.allprojects.each { it.configurations.add(conf) }

[conf] + lockableConfigurations(project, project, extension.configurationNames)
[conf] + lockableConfigurations(project, project, extension.configurationNames, extension.skippedConfigurationNamesPrefixes)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class GenerateLockTask extends AbstractLockTask {
private String WRITE_CORE_LOCK_TASK_TO_RUN = "`./gradlew dependencies --write-locks`"
private String MIGRATE_TO_CORE_LOCK_TASK_NAME = "migrateToCoreLocks"
private static final Logger LOGGER = Logging.getLogger(GenerateLockTask)
private static final List<String> DEFAULT_NON_LOCKABLE_CONFIGURATIONS = ['zinc']

@Internal
String description = 'Create a lock file in build/<configured name>'
Expand All @@ -50,6 +51,9 @@ class GenerateLockTask extends AbstractLockTask {
@Internal
Set<String> configurationNames

@Internal
Set<String> skippedConfigurationNames

@Internal
Closure filter = { group, name, version -> true }

Expand Down Expand Up @@ -85,27 +89,35 @@ class GenerateLockTask extends AbstractLockTask {
if (DependencyLockTaskConfigurer.shouldIgnoreDependencyLock(project)) {
throw new DependencyLockException("Dependency locks cannot be generated. The plugin is disabled for this project (dependencyLock.ignore is set to true)")
}
Collection<Configuration> confs = getConfigurations() ?: lockableConfigurations(project, project, getConfigurationNames())
Collection<Configuration> confs = getConfigurations() ?: lockableConfigurations(project, project, getConfigurationNames(), getSkippedConfigurationNames())
Map dependencyMap = new GenerateLockFromConfigurations().lock(confs)
new DependencyLockWriter(getDependenciesLock(), getSkippedDependencies()).writeLock(dependencyMap)
}

static Collection<Configuration> lockableConfigurations(Project taskProject, Project project, Set<String> configurationNames) {
static Collection<Configuration> lockableConfigurations(Project taskProject, Project project, Set<String> configurationNames, Set<String> skippedConfigurationNamesPrefixes = []) {
Set<Configuration> lockableConfigurations = []
if (configurationNames.empty) {
if (Configuration.class.declaredMethods.any { it.name == 'isCanBeResolved' }) {
project.configurations.findAll {
lockableConfigurations.addAll project.configurations.findAll {
if (taskProject == project) {
it.canBeResolved && !ConfigurationFilters.safelyHasAResolutionAlternative(it)
} else {
it.canBeResolved && it.canBeConsumed && !ConfigurationFilters.safelyHasAResolutionAlternative(it)
}
}
} else {
project.configurations.asList()
lockableConfigurations.addAll project.configurations.asList()
}
} else {
configurationNames.collect { project.configurations.getByName(it) }
lockableConfigurations.addAll configurationNames.collect { project.configurations.getByName(it) }
}

lockableConfigurations.removeAll {
Configuration configuration -> skippedConfigurationNamesPrefixes.any {
String prefix -> configuration.name.startsWith(prefix)
}
}
return lockableConfigurations
}

static Collection<Configuration> filterNonLockableConfigurationsAndProvideWarningsForGlobalLockSubproject(Project subproject, Set<String> configurationNames, Collection<Configuration> lockableConfigurations) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,44 @@ class GenerateLockTaskSpec extends ProjectSpec {
task.dependenciesLock.text == lockText
}

def 'simple lock for all lockable configurations - without skippedConfigurationsPrefixes'() {
project.apply plugin: 'java'

project.repositories { maven { url Fixture.repo } }
project.configurations {
zinc
incrementalAnalysisTest
}
project.dependencies {
zinc 'test.example:foo:2.+'
incrementalAnalysisTest 'test.example:foo:2.+'
implementation 'test.example:foo:2.+'
}

GenerateLockTask task = project.tasks.create(taskName, GenerateLockTask)
task.dependenciesLock = new File(project.buildDir, 'dependencies.lock')
task.configurationNames = project.configurations
.stream()
.filter { it.isCanBeResolved() }
.collect { it.name }
.toSet()
task.skippedConfigurationNames = ['zinc', 'incrementalAnalysis']

when:
task.lock()

then:
String lockText = LockGenerator.duplicateIntoConfigsWhenUsingImplementationConfigurationOnly(
'''\
"test.example:foo": {
"locked": "2.0.1",
"requested": "2.+"
}'''.stripIndent())
task.dependenciesLock.text == lockText
!task.dependenciesLock.text.contains('"zinc"')
!task.dependenciesLock.text.contains('"incrementalAnalysisTest"')
}

def 'skip dependencies via transitives when configured'() {
project.apply plugin: 'java'
project.repositories { maven { url Fixture.repo } }
Expand Down

0 comments on commit 7f8991b

Please sign in to comment.