Skip to content

Commit

Permalink
Merge pull request #69 from brandonkearby/master
Browse files Browse the repository at this point in the history
Fixed StackOverflow when adding exclusions
  • Loading branch information
johnrengelman committed Jul 16, 2014
2 parents f5c0674 + 1256c68 commit 3349095
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 6 deletions.
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.github.jengelman.gradle.plugins.shadow.internal

import groovy.util.logging.Slf4j
import org.apache.commons.io.FilenameUtils
import org.gradle.api.Project
import org.gradle.api.artifacts.Dependency
Expand All @@ -8,6 +9,7 @@ import org.gradle.api.specs.Spec
import org.gradle.api.specs.Specs
import org.gradle.api.tasks.util.PatternSet

@Slf4j
class DependencyFilter {

private final Project project
Expand All @@ -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.debug("Excluding: ${it}")}
return this
}

Expand Down Expand Up @@ -115,21 +118,38 @@ class DependencyFilter {
Specs.<? super ResolvedDependency>convertClosureToSpec(spec), dependencies)
}


/**
* Support method for querying the resolved dependency graph using maven/project coordinates
* @param spec
* @param dependencies
* @return
*/
protected Set<ResolvedDependency> findMatchingDependencies(Spec<? super ResolvedDependency> spec,
Set<ResolvedDependency> dependencies) {
Set<ResolvedDependency> dependencies) {
Set<ResolvedDependency> visitedDependencies = new HashSet<ResolvedDependency>()
return findMatchingDependenciesImpl(visitedDependencies, spec, dependencies)
}

/**
* Impl method for querying the resolved dependency graph using maven/project coordinates
* @param spec
* @param dependencies
* @return
*/
private Set<ResolvedDependency> findMatchingDependenciesImpl(Set<ResolvedDependency> visitedDependencies,
Spec<? super ResolvedDependency> spec,
Set<ResolvedDependency> dependencies) {

Set<ResolvedDependency> 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
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -406,4 +406,43 @@ class FilteringSpec extends PluginSpecification {
and:
doesNotContain(output, ['a2.properties'])
}

@Issue("SHADOW-69")
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'])
}

}

0 comments on commit 3349095

Please sign in to comment.