-
Notifications
You must be signed in to change notification settings - Fork 3
/
embulk-integration-test.gradle
113 lines (95 loc) · 3.72 KB
/
embulk-integration-test.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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
// This part is made based on 'https://raw.github.com/brunodecarvalho/gradle-plugins/master/integration-test.gradle'
// Assumes 'java', 'groovy' or 'scala' plugins have been applied before
// Add integration test source sets
sourceSets {
integrationTest { sourceSet ->
["java", "groovy", "scala", "resources"].each {
if (!sourceSet.hasProperty(it)) return
sourceSet."$it".srcDir file("src/integration-test/${it}")
}
}
}
// Setup dependencies for integration testing
dependencies {
integrationTestCompile sourceSets.main.output
integrationTestCompile sourceSets.test.output
integrationTestCompile configurations.testCompile
integrationTestRuntime configurations.testRuntime
integrationTestCompile configurations.testImplementation
}
// Define integration test task
task integrationTest(type: Test) {
testClassesDirs = sourceSets.integrationTest.output.classesDirs
classpath = sourceSets.integrationTest.runtimeClasspath
}
///// This part is made based on https://raw.githubusercontent.com/hata/gradle-plugins/master/embulk-integration-test.gradle.
//
// If you would like to override embulkDownloadURL, then define
// embulkDownloadURL in gradle.properties or other config.
// And if you use embulk v0.9.x, then change embulkLogPathOption to --log
// because the option is changed.
// e.g.
// def embulkDownloadURL = 'https://dl.embulk.org/embulk-0.9.25.jar'
// def embulkLogPathOption = '--log'
def embulkDownloadURL = 'https://dl.embulk.org/embulk-0.11.4.jar'
def embulkLogPathOption = '--log-path'
def embulkJarPath = ''
def enableIntegrationTestFlag = Boolean.getBoolean('enableIntegrationTest')
def embulkIntegrationTestDir = 'embulk.integrationtest.dir'
task initIntegrationTestProperties {
if (project.hasProperty('embulkDownloadURL')) {
embulkDownloadURL = project.findProperty('embulkDownloadURL')
}
if (project.hasProperty('embulkLogPathOption')) {
embulkLogPathOption = project.findProperty('embulkLogPathOption')
}
if (project.hasProperty('embulkJarPath')) {
embulkJarPath = project.findProperty('embulkJarPath')
} else {
embulkJarPath = "$temporaryDir/embulk/bin/embulk.jar"
}
println("Set download url ${embulkDownloadURL} and jar path ${embulkJarPath}")
}
task downloadEmbulk {
doFirst {
if (!enableIntegrationTestFlag || new File(embulkJarPath).exists()) {
throw new StopExecutionException('Skip downloadEmbulk task.')
}
}
doLast {
println("Try to download embulk from ${embulkDownloadURL} to ${embulkJarPath}")
exec {
executable "sh"
args "-c", "curl --create-dirs -o $embulkJarPath -L $embulkDownloadURL"
}
}
}
integrationTest.doFirst {
// gemContents is generated by gem task. So, this task should be run after gem.
String libDir = file('build/gemContents/lib').absolutePath
String baseDir = "$temporaryDir/embulk"
systemProperty "$embulkIntegrationTestDir", "$baseDir"
if (!enableIntegrationTestFlag) {
throw new StopExecutionException('Skip integrationTest task.')
}
copy {
from 'src/integration-test/resources'
into baseDir
}
fileTree(dir: "$baseDir", include: "*.yml").visit { config ->
['preview', 'run'].each { embulkCommand ->
String logFile = "${config.file.absolutePath}.${embulkCommand}.log"
delete logFile
println("Run integrationTest for ${config.file.absolutePath}")
exec {
workingDir baseDir
executable "sh"
args "-c", "java -jar $embulkJarPath $embulkCommand -I $libDir $config.file.absolutePath $embulkLogPathOption $logFile"
}
}
}
}
project.tasks.downloadEmbulk.dependsOn(initIntegrationTestProperties)
project.tasks.integrationTest.dependsOn(downloadEmbulk)
// Make sure 'check' task calls integration test
// check.dependsOn integrationTest