-
Notifications
You must be signed in to change notification settings - Fork 13
/
build.gradle
82 lines (72 loc) · 2.29 KB
/
build.gradle
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
task originalInputs() {
doLast {
file('inputs').mkdir()
file('inputs/1.txt').text = 'Content for file 1.'
file('inputs/2.txt').text = 'Content for file 2.'
file('inputs/3.txt').text = 'Content for file 3.'
}
}
// START SNIPPET updated-inputs
task updateInputs() {
doLast {
file('inputs/1.txt').text = 'Changed content for existing file 1.'
file('inputs/4.txt').text = 'Content for new file 4.'
}
}
// END SNIPPET updated-inputs
// START SNIPPET removed-input
task removeInput() {
doLast {
file('inputs/3.txt').delete()
}
}
// END SNIPPET removed-input
// START SNIPPET removed-output
task removeOutput() {
doLast {
file("$buildDir/outputs/1.txt").delete()
}
}
// END SNIPPET removed-output
// START SNIPPET reverse
task incrementalReverse(type: IncrementalReverseTask) {
inputDir = file('inputs')
outputDir = file("$buildDir/outputs")
inputProperty = project.properties['taskInputProperty'] ?: 'original'
}
// END SNIPPET reverse
// START SNIPPET incremental-task
class IncrementalReverseTask extends DefaultTask {
@InputDirectory
def File inputDir
@OutputDirectory
def File outputDir
@Input
def inputProperty
@TaskAction
void execute(IncrementalTaskInputs inputs) {
println inputs.incremental ? 'CHANGED inputs considered out of date'
: 'ALL inputs considered out of date'
// START SNIPPET handle-non-incremental-inputs
if (!inputs.incremental)
project.delete(outputDir.listFiles())
// END SNIPPET handle-non-incremental-inputs
// START SNIPPET out-of-date-inputs
inputs.outOfDate { change ->
if (change.file.file) {
println "out of date: ${change.file.name}"
def targetFile = new File(outputDir, change.file.name)
targetFile.text = change.file.text.reverse()
}
}
// END SNIPPET out-of-date-inputs
// START SNIPPET removed-inputs
inputs.removed { change ->
println "removed: ${change.file.name}"
def targetFile = new File(outputDir, change.file.name)
targetFile.delete()
}
// END SNIPPET removed-inputs
}
}
// END SNIPPET incremental-task