This repository has been archived by the owner on Jan 22, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.gradle
81 lines (67 loc) · 2.26 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
group 'gq.erokhin'
version '1.0-SNAPSHOT'
apply plugin: 'groovy'
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'org.postgresql:postgresql:42.1.4'
}
}
repositories {
jcenter()
maven { url 'https://jitpack.io' }
}
ext {
pgPort = project.findProperty('pgPort') as Integer ?: 54321
pgDockerName = project.findProperty('pgDockerName') ?: 'pg_zq_test'
}
dependencies {
testCompile 'org.codehaus.groovy:groovy-all:2.4.10'
testCompile 'org.spockframework:spock-core:1.1-groovy-2.4'
testCompile 'com.zaxxer:HikariCP:2.7.2'
testCompile 'org.codehaus.gpars:gpars:1.2.1'
testRuntime 'org.postgresql:postgresql:42.1.4'
}
task startPostgres(type: Exec) {
description "Starts latest PostgreSQL for testing"
commandLine "bash", "-c", """
echo Removing old test container
docker ps -q -a -f name=${project.ext.pgDockerName} | xargs docker rm -f &&
echo Starting new PostgreSQL container
docker run --name ${project.ext.pgDockerName} -p ${project.ext.pgPort}:5432 -i -t -d postgres:latest &&
echo Waiting for PostgreSQL to be ready
docker ps -q -a -f name=${project.ext.pgDockerName} | xargs docker logs -f | grep -q 'PostgreSQL init process complete; ready for start up.' &&
sleep 1s
echo PostgreSQL container started
"""
}
task applySQL() {
description "Apply zq sql scripts on database"
shouldRunAfter startPostgres
doLast {
//noinspection UnnecessaryQualifiedReference
groovy.sql.Sql.withInstance(
"jdbc:postgresql://localhost:${project.ext.pgPort}/postgres",
'postgres',
'postgres',
'org.postgresql.Driver') { groovy.sql.Sql sql ->
project.fileTree('src/sql').sort().each { file ->
sql.execute(file.text)
logger.quiet("Applied $file")
}
}
}
}
test {
dependsOn startPostgres, applySQL
afterTest { desc, result ->
logger.quiet "Executing test ${desc.name} [${desc.className}] with result: ${result.resultType}"
}
}
gradle.class.classLoader.addURL(
buildscript.configurations.classpath.find({
it.name.contains('postgresql')
}).toURI().toURL()
)