Skip to content

Commit

Permalink
close #54, remove excluded dependencies from task inputs
Browse files Browse the repository at this point in the history
  • Loading branch information
johnrengelman committed Jun 26, 2014
1 parent 08c269a commit 6928a53
Show file tree
Hide file tree
Showing 5 changed files with 94 additions and 1 deletion.
2 changes: 2 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ v1.0.0

+ Previously known as v0.9.0
+ All changes from 0.9.0-M1 to 0.9.0-M5
+ Properly configure the ShadowJar task inputs to observe the include/excludes from the `dependencies` block. This
allows UP-TO-DATE checking to work properly when changing the `dependencies` rules ([Issue #54](https://github.com/johnrengelman/shadow/issues/54))

v0.9.0-M5
=========
Expand Down
4 changes: 3 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ dependencies {
}

test {
testLogging.showStandardStreams = true
if (System.env.CI == 'true') {
testLogging.showStandardStreams = true
}
}

jar {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,17 @@ import com.github.jengelman.gradle.plugins.shadow.relocation.SimpleRelocator
import com.github.jengelman.gradle.plugins.shadow.transformers.AppendingTransformer
import com.github.jengelman.gradle.plugins.shadow.transformers.ServiceFileTransformer
import com.github.jengelman.gradle.plugins.shadow.transformers.Transformer
import org.apache.commons.io.FilenameUtils
import org.gradle.api.file.FileCollection
import org.gradle.api.file.FileTree
import org.gradle.api.file.FileTreeElement
import org.gradle.api.internal.DocumentationRegistry
import org.gradle.api.internal.file.copy.CopyAction
import org.gradle.api.specs.Spec
import org.gradle.api.tasks.Input
import org.gradle.api.tasks.InputFiles
import org.gradle.api.tasks.Optional
import org.gradle.api.tasks.SkipWhenEmpty
import org.gradle.api.tasks.TaskAction
import org.gradle.api.tasks.bundling.Jar
import org.gradle.api.tasks.util.PatternSet
Expand Down Expand Up @@ -40,6 +49,26 @@ class ShadowJar extends Jar {
logger.info(shadowStats.toString())
}

@Override
@InputFiles @SkipWhenEmpty @Optional
// SHADOW-54 Need to remove filtered dependencies from inputs list
public FileCollection getSource() {
super.source - excludedDependencies
}

/**
* Gets a list of dependency files that are being excluded
* @return
*/
protected FileCollection getExcludedDependencies() {
def allDependencies = super.source.filter {
def ext = FilenameUtils.getExtension(it.name)
return ext == 'zip' || ext == 'jar'
}.asFileTree
def includedDependencies = allDependencies.matching(dependencyFilter.patternSet)
return allDependencies - includedDependencies
}

/**
* Configure inclusion/exclusion of module & project dependencies into uber jar
* @param c
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import com.github.jengelman.gradle.plugins.shadow.util.AppendableMavenFileReposi
import com.github.jengelman.gradle.plugins.shadow.util.PluginSpecification
import org.gradle.testkit.functional.ExecutionResult
import spock.lang.Ignore
import spock.lang.Issue

class FilteringSpec extends PluginSpecification {

Expand Down Expand Up @@ -108,6 +109,61 @@ class FilteringSpec extends PluginSpecification {
doesNotContain(output, ['d.properties'])
}

@Issue("SHADOW-54")
def "dependency exclusions affect UP-TO-DATE check"() {
given:
repo.module('shadow', 'c', '1.0')
.insertFile('c.properties', 'c')
.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'])

when: 'Update build file shadowJar dependency exclusion'
buildFile.text = buildFile.text.replace('exclude(dependency(\'shadow:d:1.0\'))',
'exclude(dependency(\'shadow:c:1.0\'))')

result = runner.run()

then:
success(result)

and:
assert !taskUpToDate(result, 'shadowJar')

and:
contains(output, ['a.properties', 'a2.properties', 'b.properties', 'd.properties'])

and:
doesNotContain(output, ['c.properties'])
}

def "include dependency, excluding all others"() {
given:
repo.module('shadow', 'c', '1.0')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,10 @@ class PluginSpecification extends Specification {
assert result.standardError, 'Gradle build succeeded'
}

boolean taskUpToDate(ExecutionResult result, String taskName) {
result.standardOutput.find(/:${taskName}(.*)/).trim().contains('UP-TO-DATE')
}

protected getOutput() {
file('build/libs/shadow.jar')
}
Expand Down

0 comments on commit 6928a53

Please sign in to comment.