From be743e0f1639a52c1e2ef060f2c3912df861752b Mon Sep 17 00:00:00 2001 From: Brandon Kearby Date: Sat, 5 Jul 2014 18:33:51 -0500 Subject: [PATCH 1/3] Fixed StackOverflow when adding exclusions --- gradle/wrapper/gradle-wrapper.properties | 4 +-- .../shadow/internal/DependencyFilter.groovy | 28 ++++++++++++++++--- 2 files changed, 26 insertions(+), 6 deletions(-) diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index d79122dea..0155caa19 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ -#Tue Apr 29 12:45:22 CDT 2014 +#Sat Jul 05 17:55:58 CDT 2014 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-1.12-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-1.12-all.zip diff --git a/src/main/groovy/com/github/jengelman/gradle/plugins/shadow/internal/DependencyFilter.groovy b/src/main/groovy/com/github/jengelman/gradle/plugins/shadow/internal/DependencyFilter.groovy index a4b10e926..2c27fb610 100644 --- a/src/main/groovy/com/github/jengelman/gradle/plugins/shadow/internal/DependencyFilter.groovy +++ b/src/main/groovy/com/github/jengelman/gradle/plugins/shadow/internal/DependencyFilter.groovy @@ -1,6 +1,7 @@ package com.github.jengelman.gradle.plugins.shadow.internal import org.apache.commons.io.FilenameUtils +import org.apache.log4j.Logger import org.gradle.api.Project import org.gradle.api.artifacts.Dependency import org.gradle.api.artifacts.ResolvedDependency @@ -9,6 +10,7 @@ import org.gradle.api.specs.Specs import org.gradle.api.tasks.util.PatternSet class DependencyFilter { + static Logger log = Logger.getLogger(DependencyFilter.class) private final Project project private final PatternSet patternSet @@ -31,6 +33,7 @@ class DependencyFilter { dependencies.collect { it.moduleArtifacts.file }.flatten().each { File file -> this.patternSet.exclude(FilenameUtils.getName(file.path)) } + dependencies.each { log.info("Excluding: ${it}")} return this } @@ -115,6 +118,7 @@ class DependencyFilter { Specs.convertClosureToSpec(spec), dependencies) } + /** * Support method for querying the resolved dependency graph using maven/project coordinates * @param spec @@ -122,14 +126,30 @@ class DependencyFilter { * @return */ protected Set findMatchingDependencies(Spec spec, - Set dependencies) { + Set dependencies) { + Set visitedDependencies = new HashSet() + return findMatchingDependenciesImpl(visitedDependencies, spec, dependencies) + } + + /** + * Impl method for querying the resolved dependency graph using maven/project coordinates + * @param spec + * @param dependencies + * @return + */ + private Set findMatchingDependenciesImpl(Set visitedDependencies, + Spec spec, + Set dependencies) { Set matched = [] dependencies.each { - if (spec.isSatisfiedBy(it)) { - matched.add(it) + if (!visitedDependencies.contains(it)) { + visitedDependencies.add(it) + if (spec.isSatisfiedBy(it)) { + matched.add(it) + } + matched.addAll(findMatchingDependenciesImpl(visitedDependencies, spec, it.children)) } - matched.addAll(findMatchingDependencies(spec, it.children)) } return matched } From 6030c217d58882af3faa719499a25878a516224b Mon Sep 17 00:00:00 2001 From: Brandon Kearby Date: Sun, 6 Jul 2014 22:27:12 -0500 Subject: [PATCH 2/3] Added @Slf4j, changed log level to debug. Added unit test for circular dependencies --- .../shadow/internal/DependencyFilter.groovy | 8 ++-- .../plugins/shadow/FilteringSpec.groovy | 38 +++++++++++++++++++ 2 files changed, 42 insertions(+), 4 deletions(-) diff --git a/src/main/groovy/com/github/jengelman/gradle/plugins/shadow/internal/DependencyFilter.groovy b/src/main/groovy/com/github/jengelman/gradle/plugins/shadow/internal/DependencyFilter.groovy index 2c27fb610..5d29b9633 100644 --- a/src/main/groovy/com/github/jengelman/gradle/plugins/shadow/internal/DependencyFilter.groovy +++ b/src/main/groovy/com/github/jengelman/gradle/plugins/shadow/internal/DependencyFilter.groovy @@ -1,7 +1,7 @@ package com.github.jengelman.gradle.plugins.shadow.internal +import groovy.util.logging.Slf4j import org.apache.commons.io.FilenameUtils -import org.apache.log4j.Logger import org.gradle.api.Project import org.gradle.api.artifacts.Dependency import org.gradle.api.artifacts.ResolvedDependency @@ -9,8 +9,8 @@ import org.gradle.api.specs.Spec import org.gradle.api.specs.Specs import org.gradle.api.tasks.util.PatternSet +@Slf4j class DependencyFilter { - static Logger log = Logger.getLogger(DependencyFilter.class) private final Project project private final PatternSet patternSet @@ -33,7 +33,7 @@ class DependencyFilter { dependencies.collect { it.moduleArtifacts.file }.flatten().each { File file -> this.patternSet.exclude(FilenameUtils.getName(file.path)) } - dependencies.each { log.info("Excluding: ${it}")} + dependencies.each { log.debug("Excluding: ${it}")} return this } @@ -126,7 +126,7 @@ class DependencyFilter { * @return */ protected Set findMatchingDependencies(Spec spec, - Set dependencies) { + Set dependencies) { Set visitedDependencies = new HashSet() return findMatchingDependenciesImpl(visitedDependencies, spec, dependencies) } diff --git a/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/FilteringSpec.groovy b/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/FilteringSpec.groovy index d73e90633..d5ca51de7 100644 --- a/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/FilteringSpec.groovy +++ b/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/FilteringSpec.groovy @@ -406,4 +406,42 @@ class FilteringSpec extends PluginSpecification { and: doesNotContain(output, ['a2.properties']) } + + def "handle exclude with circular dependency"() { + given: + repo.module('shadow', 'c', '1.0') + .insertFile('c.properties', 'c') + .dependsOn('d') + .publish() + repo.module('shadow', 'd', '1.0') + .insertFile('d.properties', 'd') + .dependsOn('c') + .publish() + + buildFile << ''' + |dependencies { + | compile 'shadow:d:1.0' + |} + | + |shadowJar { + | dependencies { + | exclude(dependency('shadow:d:1.0')) + | } + |} + '''.stripMargin() + + when: + runner.arguments << 'shadowJar' + ExecutionResult result = runner.run() + + then: + success(result) + + and: + contains(output, ['a.properties', 'a2.properties', 'b.properties', 'c.properties']) + + and: + doesNotContain(output, ['d.properties']) + } + } From 1256c682cb1d3fafe920ad52a8773f5109f4cc32 Mon Sep 17 00:00:00 2001 From: Brandon Kearby Date: Sun, 6 Jul 2014 22:39:28 -0500 Subject: [PATCH 3/3] Added @Issue(SHADOW-69) to unit test --- .../github/jengelman/gradle/plugins/shadow/FilteringSpec.groovy | 1 + 1 file changed, 1 insertion(+) diff --git a/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/FilteringSpec.groovy b/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/FilteringSpec.groovy index d5ca51de7..e9c2cbf46 100644 --- a/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/FilteringSpec.groovy +++ b/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/FilteringSpec.groovy @@ -407,6 +407,7 @@ class FilteringSpec extends PluginSpecification { doesNotContain(output, ['a2.properties']) } + @Issue("SHADOW-69") def "handle exclude with circular dependency"() { given: repo.module('shadow', 'c', '1.0')