-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.gradle
115 lines (90 loc) · 3.22 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
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
114
115
apply plugin : 'java'
apply plugin: 'cargo'
import groovy.sql.Sql
configurations {
flyway
classpath
}
repositories {
mavenCentral()
}
buildscript {
repositories {
add(new org.apache.ivy.plugins.resolver.URLResolver()) {
name = 'GitHub'
addArtifactPattern 'http://cloud.github.com/downloads/[organisation]/[module]/[module]-[revision].[ext]'
}
}
dependencies {
classpath 'bmuschko:gradle-cargo-plugin:0.5.6'
}
}
dependencies {
compile "com.googlecode.flyway:flyway-core:1.7"
compile "com.googlecode.flyway:flyway-ant:1.7"
compile "postgresql:postgresql:9.1-901.jdbc4"
compile "c3p0:c3p0:0.9.0.4"
flyway "com.googlecode.flyway:flyway-ant:1.7"
flyway "postgresql:postgresql:9.1-901.jdbc4"
classpath 'postgresql:postgresql:9.1-901.jdbc4'
flyway files("$dbJarDestinationLocation/$dbJarName")
cargo "org.codehaus.cargo:cargo-core-uberjar:$cargoVersion",
"org.codehaus.cargo:cargo-ant:$cargoVersion"
}
cargo {
containerId = serverName
port = Integer.valueOf(serverPort)
deployable {
file = file(destinationLocation + File.separator + warName)
}
local {
homeDir = file(serverHome)
output = file(serverLogFile)
}
}
task deployOpenLmis(dependsOn: "setupDB") << {
println("Deploying...")
tasks.migrateDB.execute()
cargoStopLocal.execute()
tasks.downloadFile.execute()
cargoRunLocal.execute()
}
task downloadFile << {
println("Downloading war...")
ant.get(src: warSourceUrl.replace('buildVersion', buildVersion) + warName, dest: destinationLocation, verbose: 'true')
println("Downloaded")
}
task setupDB(dependsOn: ["createDB",clean]) << {
ext.flyway_classpath = files(configurations.flyway)
ant.taskdef(name: 'flywayInit', classname: 'com.googlecode.flyway.ant.InitTask', classpath: ext.flyway_classpath.asPath)
ant.flywayInit(driver: 'org.postgresql.Driver', url: 'jdbc:postgresql:' + dbName, user: dbUser, password: dbPassword)
}
task createDB(dependsOn: "dropDB") << {
println("Creating Database..")
executeSql('create database ' + dbName)
}
task dropDB() << {
println("Dropping Datbase..")
executeSql('drop database if exists ' + dbName)
}
def executeSql(String statement) {
configurations.classpath.each { file ->
gradle.class.classLoader.addURL(file.toURI().toURL())
}
driverName = 'org.postgresql.Driver'
Class.forName(driverName)
Sql sql = (Sql) Sql.newInstance(
"jdbc:postgresql://$databaseHostName:$databasePort" ,
dbUser,
dbPassword,
driverName
)
sql.execute(statement)
}
task migrateDB() << {
println("Migrating database...")
ant.get(src: dbJarSourceUrl.replace('buildVersion', buildVersion) + dbJarName, dest: dbJarDestinationLocation, verbose: 'true')
ext.flyway_classpath = files(sourceSets.main.resources.srcDirs) + files(configurations.flyway)
ant.taskdef(name: 'flywayMigrate', classname: 'com.googlecode.flyway.ant.MigrateTask', classpath: ext.flyway_classpath.asPath)
ant.flywayMigrate(driver: 'org.postgresql.Driver', url: "jdbc:postgresql://$databaseHostName:$databasePort/$dbName" , user: dbUser, password: dbPassword)
}