Skip to content

Commit

Permalink
Use old API methods for task inputs and outputs
Browse files Browse the repository at this point in the history
Will revert deprecation in next commit.

+review REVIEW-6038
  • Loading branch information
lptr committed Jun 8, 2016
1 parent 8b9bfe6 commit 2fb7d2d
Show file tree
Hide file tree
Showing 39 changed files with 82 additions and 98 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class InMemoryTaskArtifactsIntegrationTest extends DaemonIntegrationSpec {
task someTask {
inputs.property "someEnum", SomeEnum.E1
def f = new File("build/e1")
outputs.includeDir f
outputs.dir f
doLast {
f.mkdirs()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ class InputOutputEnsuringTaskExecuterIntegrationTest extends AbstractIntegration
it.configure {
println "Inputs are configured via nested configure()"
}
it.includeFile("input.txt")
it.file("input.txt")
}
outputs.configure {
it.configure {
println "Outputs are configured via nested configure()"
}
it.includeFile("output.txt")
it.file("output.txt")
}
doLast {
file("output.txt") << file("input.txt")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -367,13 +367,13 @@ class CopyTaskIntegrationSpec extends AbstractIntegrationSpec {
configurations { compile }
dependencies { compile files('a.jar') }
task fileProducer {
outputs.includeFile 'build/out.txt'
outputs.file 'build/out.txt'
doLast {
file('build/out.txt').text = 'some content'
}
}
task dirProducer {
outputs.includeDir 'build/outdir'
outputs.dir 'build/outdir'
doLast {
file('build/outdir').mkdirs()
file('build/outdir/file1.txt').text = 'some content'
Expand Down Expand Up @@ -404,13 +404,13 @@ class CopyTaskIntegrationSpec extends AbstractIntegrationSpec {
configurations { compile }
dependencies { compile files('a.jar') }
task fileProducer {
outputs.includeFile 'build/out.txt'
outputs.file 'build/out.txt'
doLast {
file('build/out.txt').text = 'some content'
}
}
task dirProducer {
outputs.includeDir 'build/outdir'
outputs.dir 'build/outdir'
doLast {
file('build/outdir').mkdirs()
file('build/outdir/file1.txt').text = 'some content'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class FailingIncrementalTasksIntegrationTest extends AbstractIntegrationSpec {
def "consecutively failing task has correct up-to-date status and failure"() {
buildFile << """
task foo {
outputs.includeFile("out.txt")
outputs.file("out.txt")
doLast {
if (project.file("out.txt").exists()) {
throw new RuntimeException("Boo!")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -398,15 +398,15 @@ task b(type: DirTransformerTask) {
public void canUseUpToDatePredicateToForceTaskToExecute() {
testFile('build.gradle') << '''
task inputsAndOutputs {
inputs.includeFiles 'src.txt'
outputs.includeFile 'src.a.txt'
inputs.files 'src.txt'
outputs.file 'src.a.txt'
outputs.upToDateWhen { project.hasProperty('uptodate') }
doFirst {
outputs.files.singleFile.text = "[${inputs.files.singleFile.text}]"
}
}
task noOutputs {
inputs.includeFile 'src.txt'
inputs.file 'src.txt'
outputs.upToDateWhen { project.hasProperty('uptodate') }
doFirst { }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class MyTask extends DefaultTask {
}

task generateConfigFile {
outputs.includeFile "config.txt"
outputs.file "config.txt"
doLast {
file("config.txt").text = "my config"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public boolean attachActions(final TaskPropertyActionContext context) {
final boolean skipWhenEmpty = context.isAnnotationPresent(SkipWhenEmpty.class);
context.setConfigureAction(new UpdateAction() {
public void update(TaskInternal task, Callable<Object> futureValue) {
task.getInputs().includeDir(futureValue).withPropertyName(context.getName()).skipWhenEmpty(skipWhenEmpty);
task.getInputs().dir(futureValue).withPropertyName(context.getName()).skipWhenEmpty(skipWhenEmpty);
}
});
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public boolean attachActions(final TaskPropertyActionContext context) {
context.setValidationAction(inputFileValidation);
context.setConfigureAction(new UpdateAction() {
public void update(TaskInternal task, Callable<Object> futureValue) {
task.getInputs().includeFiles(futureValue).withPropertyName(context.getName());
task.getInputs().files(futureValue).withPropertyName(context.getName());
}
});
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public boolean attachActions(final TaskPropertyActionContext context) {
final boolean skipWhenEmpty = context.isAnnotationPresent(SkipWhenEmpty.class);
context.setConfigureAction(new UpdateAction() {
public void update(TaskInternal task, Callable<Object> futureValue) {
task.getInputs().includeFiles(futureValue).withPropertyName(context.getName()).skipWhenEmpty(skipWhenEmpty);
task.getInputs().files(futureValue).withPropertyName(context.getName()).skipWhenEmpty(skipWhenEmpty);
}
});
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public void execute(TaskOutputs taskOutputs) {
if (directories != null) {
int counter = 0;
for (File directory : directories) {
taskOutputs.includeDir(directory).withPropertyName(context.getName() + "$" + (++counter));
taskOutputs.dir(directory).withPropertyName(context.getName() + "$" + (++counter));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ protected void validate(String propertyName, Object value, Collection<String> me

@Override
protected void update(TaskPropertyActionContext context, TaskInternal task, final Callable<Object> futureValue) {
task.getOutputs().includeDir(futureValue).withPropertyName(context.getName());
task.getOutputs().dir(futureValue).withPropertyName(context.getName());
task.prependParallelSafeAction(new Action<Task>() {
public void execute(Task task) {
File directory = uncheckedCast(uncheckedCall(futureValue));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ protected void validate(String propertyName, Object value, Collection<String> me

@Override
protected void update(TaskPropertyActionContext context, TaskInternal task, final Callable<Object> futureValue) {
task.getOutputs().includeFile(futureValue).withPropertyName(context.getName());
task.getOutputs().file(futureValue).withPropertyName(context.getName());
task.prependParallelSafeAction(new Action<Task>() {
public void execute(Task task) {
File file = (File) uncheckedCall(futureValue);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public void execute(TaskOutputs taskOutputs) {
if (files != null) {
int counter = 0;
for (File file : files) {
taskOutputs.includeFile(file).withPropertyName(context.getName() + "$" + (++counter));
taskOutputs.file(file).withPropertyName(context.getName() + "$" + (++counter));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -703,13 +703,13 @@ public class DefaultTaskArtifactStateRepositoryTest extends Specification {
TaskInternal task() {
final TaskInternal task = TestUtil.createTask(type, project, path)
if (inputs != null) {
task.getInputs().includeFiles(inputs)
task.getInputs().files(inputs)
}
if (inputProperties != null) {
task.getInputs().properties(inputProperties)
}
if (outputs != null) {
outputs.each { task.getOutputs().includeFile(it) }
outputs.each { task.getOutputs().file(it) }
}
task.doLast(new org.gradle.api.Action<Object>() {
public void execute(Object o) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,64 +53,48 @@ class DefaultTaskInputsTest extends Specification {
inputs.sourceFiles.empty
}

def canRegisterInputFiles() {
when:
inputs.files('a')

then:
inputs.files.files == [new File('a')] as Set
}

def canRegisterInputDir() {
when:
inputs.dir('a')

then:
inputs.files.files == [treeFile] as Set
}

def "can register input file"() {
when: inputs.includeFile("a")
when: inputs.file("a")
then:
inputs.files.files.toList() == [new File('a')]
inputs.fileProperties*.propertyName.toList() == ['$1']
inputs.fileProperties*.propertyFiles*.files.flatten() == [new File("a")]
}

def "can register input file with property name"() {
when: inputs.includeFile("a").withPropertyName("prop")
when: inputs.file("a").withPropertyName("prop")
then:
inputs.files.files.toList() == [new File('a')]
inputs.fileProperties*.propertyName.toList() == ['prop']
inputs.fileProperties*.propertyFiles*.files.flatten() == [new File("a")]
}

def "can register input files"() {
when: inputs.includeFiles("a", "b")
when: inputs.files("a", "b")
then:
inputs.files.files.toList() == [new File("a"), new File("b")]
inputs.fileProperties*.propertyName == ['$1']
inputs.fileProperties*.propertyFiles*.files.flatten() == [new File("a"), new File("b")]
}

def "can register input files with property naem"() {
when: inputs.includeFiles("a", "b").withPropertyName("prop")
when: inputs.files("a", "b").withPropertyName("prop")
then:
inputs.files.files.sort() == [new File("a"), new File("b")]
inputs.fileProperties*.propertyName == ['prop']
inputs.fileProperties*.propertyFiles*.files.flatten() == [new File("a"), new File("b")]
}

def "can register input dir"() {
when: inputs.includeDir("a")
when: inputs.dir("a")
then:
inputs.files.files.toList() == [treeFile]
inputs.fileProperties*.propertyName == ['$1']
inputs.fileProperties*.propertyFiles*.files.flatten() == [treeFile]
}

def "can register input dir with property name"() {
when: inputs.includeDir("a").withPropertyName("prop")
when: inputs.dir("a").withPropertyName("prop")
then:
inputs.files.files.toList() == [treeFile]
inputs.fileProperties*.propertyName == ['prop']
Expand Down Expand Up @@ -177,12 +161,12 @@ class DefaultTaskInputsTest extends Specification {
}

def "can register source files"() {
when: inputs.includeFiles("a", "b").withPropertyName("prop")
when: inputs.files("a", "b").withPropertyName("prop")
then:
inputs.hasInputs
!inputs.hasSourceFiles

when: inputs.includeFiles(["s1", "s2"]).skipWhenEmpty()
when: inputs.files(["s1", "s2"]).skipWhenEmpty()
then:
inputs.hasSourceFiles
inputs.files.files.toList() == [new File("a"), new File("b"), new File("s1"), new File("s2")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,31 +55,31 @@ class DefaultTaskOutputsTest extends Specification {
}

def "can register output file"() {
when: outputs.includeFile("a")
when: outputs.file("a")
then:
outputs.files.files.toList() == [new File('a')]
outputs.fileProperties*.propertyName.toList() == ['$1']
outputs.fileProperties*.propertyFiles*.files.flatten() == [new File("a")]
}

def "can register output file with property name"() {
when: outputs.includeFile("a").withPropertyName("prop")
when: outputs.file("a").withPropertyName("prop")
then:
outputs.files.files.toList() == [new File('a')]
outputs.fileProperties*.propertyName.toList() == ['prop']
outputs.fileProperties*.propertyFiles*.files.flatten() == [new File("a")]
}

def "can register output dir"() {
when: outputs.includeDir("a")
when: outputs.file("a")
then:
outputs.files.files.toList() == [new File('a')]
outputs.fileProperties*.propertyName.toList() == ['$1']
outputs.fileProperties*.propertyFiles*.files.flatten() == [new File("a")]
}

def "can register output dir with property name"() {
when: outputs.includeDir("a").withPropertyName("prop")
when: outputs.dir("a").withPropertyName("prop")
then:
outputs.files.files.toList() == [new File('a')]
outputs.fileProperties*.propertyName.toList() == ['prop']
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ project(":b") {
configurations { compile }
dependencies { compile(project(':a')) { artifact { name = 'y'; type = 'jar' } } }
task test {
inputs.includeFiles configurations.compile
inputs.files configurations.compile
doFirst {
assert configurations.compile.files.collect { it.name } == ['y.jar', 'externalA-1.5.jar']
}
Expand Down Expand Up @@ -382,7 +382,7 @@ project(":b") {
configurations { compile }
dependencies { compile(project(':a')) { artifact { name = 'b'; type = 'jar' } } }
task test {
inputs.includeFiles configurations.compile
inputs.files configurations.compile
doFirst {
assert configurations.compile.files.collect { it.name } == ['a-b.jar', 'externalA-1.5.jar']
}
Expand Down
2 changes: 1 addition & 1 deletion subprojects/docs/src/samples/application/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ applicationDefaultJvmArgs = ["-Dgreeting.language=en"]
// START SNIPPET distribution-spec
task createDocs {
def docs = file("$buildDir/docs")
outputs.includeDir docs
outputs.dir docs
doLast {
docs.mkdirs()
new File(docs, "readme.txt").write("Read me!")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ repositories {
task createClasspathManifest {
def outputDir = file("$buildDir/$name")

inputs.includeFiles sourceSets.main.runtimeClasspath
outputs.includeDir outputDir
inputs.files sourceSets.main.runtimeClasspath
outputs.dir outputDir

doLast {
outputDir.mkdirs()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ task copyMethod << {
// START SNIPPET copy-method-with-dependency
task copyMethodWithExplicitDependencies{
// up-to-date check for inputs, plus add copyTask as dependency
inputs.includeFile copyTask
outputs.includeDir 'some-dir' // up-to-date check for outputs
inputs.file copyTask
outputs.dir 'some-dir' // up-to-date check for outputs
doLast{
copy {
// Copy the output of copyTask
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
task transform {
ext.srcFile = file('mountains.xml')
ext.destDir = new File(buildDir, 'generated')
inputs.includeFile srcFile
outputs.includeDir destDir
inputs.file srcFile
outputs.dir destDir
// END SNIPPET declare-inputs-and-outputs
doLast {
println "Transforming source file."
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class CdtIdePlugin implements Plugin<Project> {
}
}

inputs.includeFiles({ task.settings.includeRoots }).withPropertyName("settings.includeRoots")
inputs.files({ task.settings.includeRoots }).withPropertyName("settings.includeRoots")
inputFile = project.file(".cproject")
outputFile = project.file(".cproject")
factory { new CprojectDescriptor() }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,7 @@ class Main {
task createDocs {
def docs = file("\$buildDir/docs")
outputs.includeDir docs
outputs.dir docs
doLast {
assert docs.mkdirs()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ class BuildAggregationIntegrationTest extends AbstractIntegrationTest {
dependsOn upper
tasks = ["upper"]
startParameter.searchUpwards = false
outputs.includeFile "build.gradle" // having an output (or input) triggers the bug
outputs.file "build.gradle" // having an output (or input) triggers the bug
}
"""

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ dependencies { compile 'commons-io:commons-io:1.4@jar' }
content += """
task 'hello$i' {
File file = file('$TEST_FILE')
outputs.includeFile file
outputs.file file
doLast {
configurations.compile.resolve()
file.parentFile.mkdirs()
Expand All @@ -192,7 +192,7 @@ dependencies { other 'commons-lang:commons-lang:2.6@jar' }
task newTask {
File file = file('$TEST_FILE')
outputs.includeFile file
outputs.file file
doLast {
configurations.other.resolve()
file.parentFile.mkdirs()
Expand Down
Loading

0 comments on commit 2fb7d2d

Please sign in to comment.