Created
October 20, 2011 10:04
-
-
Save tlberglund/1300809 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
apply plugin: 'groovy' | |
import org.gradle.examples.liquibase.LiquibaseTask | |
import org.gradle.examples.liquibase.ChangeLogConverter | |
buildscript { | |
repositories { | |
mavenCentral() | |
} | |
dependencies { | |
classpath 'org.liquibase:liquibase-core:2.0.1' | |
classpath 'com.h2database:h2:1.3.153' | |
} | |
} | |
repositories { | |
mavenCentral() | |
} | |
dependencies { | |
groovy 'org.codehaus.groovy:groovy:1.8.0' | |
runtime 'com.h2database:h2:1.3.153' | |
runtime 'com.augusttechgroup:groovy-liquibase-dsl:0.7.0' | |
} | |
task wrapper(type: Wrapper) { | |
gradleVersion = '1.0-milestone-2' | |
} | |
props = new Properties() | |
props.load(new FileInputStream(file('database.properties'))) | |
database = [:] | |
database.url = props.getProperty('url') | |
database.username = props.getProperty('username') | |
database.password = props.getProperty('password') | |
database.changeLogFile = props.getProperty('change.log.file') | |
task buildSchema(type: JavaExec) { | |
group = 'database' | |
classpath = runtimeClasspath | |
workingDir = projectDir | |
main = 'org.h2.tools.RunScript' | |
args = ['-url', database.url, '-user', database.username, '-script', 'create-schema-generic.sql'] | |
} | |
task startDatabase(type: JavaExec) { | |
group = 'database' | |
workingDir = projectDir | |
main = 'org.h2.tools.Server' | |
classpath = runtimeClasspath | |
} | |
[ 'generateChangeLog', 'changeLogSync', 'update' ].each { commandName -> | |
task "${commandName}"(type: LiquibaseTask) { | |
url = database.url | |
username = database.username | |
password = database.password | |
changeLogFile = database.changeLogFile | |
command = name | |
} | |
} | |
task changeLogReport { | |
inputs.file(database.changeLogFile) | |
outputs.file("${buildDir}/reports/changelog.csv") | |
doLast { | |
file("${buildDir}/reports/changelog.csv").withWriter { writer -> | |
def changelog = new XmlSlurper().parse(database.changeLogFile) | |
changelog.changeSet.each { changeSet -> | |
writer.println("${changeSet.@author},${changeSet.@id}") | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment