Skip to content

Commit

Permalink
Backwards compatibility of direct closure assignment (fixes #331)
Browse files Browse the repository at this point in the history
  • Loading branch information
ben-manes committed Sep 1, 2019
1 parent 8881189 commit 5720042
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 7 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
bin
build
out
.java-version
.classpath
.settings
.project
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ apply plugin: 'nexus'
apply plugin: 'codenarc'

group = 'com.github.ben-manes'
version = '0.23.0'
version = '0.24.0'

sourceCompatibility = '1.6'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ import org.gradle.api.DefaultTask
import org.gradle.api.tasks.Input
import org.gradle.api.tasks.Optional
import org.gradle.api.tasks.TaskAction
import org.gradle.util.ConfigureUtil
import org.gradle.util.SingleMessageLogger;

import static com.github.benmanes.gradle.versions.updates.gradle.GradleReleaseChannel.*

Expand Down Expand Up @@ -53,7 +55,9 @@ class DependencyUpdatesTask extends DefaultTask {
boolean checkForGradleUpdate = true

Object outputFormatter = 'plain'
Action<? super ResolutionStrategyWithCurrent> resolutionStrategyAction = null

Closure resolutionStrategy = null;
private Action<? super ResolutionStrategyWithCurrent> resolutionStrategyAction = null

DependencyUpdatesTask() {
description = 'Displays the dependency updates for the project.'
Expand All @@ -66,6 +70,12 @@ class DependencyUpdatesTask extends DefaultTask {
def dependencyUpdates() {
project.evaluationDependsOnChildren()

if (resolutionStrategy != null) {
resolutionStrategy(ConfigureUtil.configureUsing(resolutionStrategy))
SingleMessageLogger.nagUserWith('dependencyUpdates.resolutionStrategy', /* removalDetails */ '',
'Remove the assignment operator, \'=\', when setting this task property', /* contextualAdvice */ null);
}

def evaluator = new DependencyUpdates(project, resolutionStrategyAction, revisionLevel(),
outputFormatterProp(), outputDirectory(), getReportfileName(), checkForGradleUpdate, gradleReleaseChannelLevel())
DependencyUpdatesReporter reporter = evaluator.run()
Expand All @@ -78,6 +88,7 @@ class DependencyUpdatesTask extends DefaultTask {
*/
void resolutionStrategy(final Action<? super ResolutionStrategyWithCurrent> resolutionStrategy) {
this.resolutionStrategyAction = resolutionStrategy
this.resolutionStrategy = null
}

/** Returns the resolution revision level. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ final class ComponentSelectionRuleSourceSpec extends Specification {
}

@Unroll
def 'component selection works with rule-source'() {
def 'component selection works with rule-source (#assignment)'() {
given:
def classpathString = pluginClasspath
.collect { it.absolutePath.replace('\\', '\\\\') } // escape backslashes in Windows paths
Expand Down Expand Up @@ -55,15 +55,15 @@ final class ComponentSelectionRuleSourceSpec extends Specification {
dependencies {
compile 'com.google.inject:guice:2.0'
}
dependencyUpdates.resolutionStrategy {
dependencyUpdates.resolutionStrategy ${assignment} {
componentSelection {
all(new Rule())
}
}
class Rule {
@Mutate
void select(ComponentSelectionWithCurrent selection) {
if (selection.candidate.version == "3.1" && selection.currentVersion == "2.0") {
Expand All @@ -83,5 +83,8 @@ final class ComponentSelectionRuleSourceSpec extends Specification {
then:
result.output.contains('com.google.inject:guice [2.0 -> 3.0]')
srdErrWriter.toString().empty

where:
assignment << [' ', '=']
}
}

0 comments on commit 5720042

Please sign in to comment.