Skip to content

Commit

Permalink
Fixed a bug in script parsing.
Browse files Browse the repository at this point in the history
  • Loading branch information
tlberglund committed Mar 15, 2012
1 parent 84dd0d7 commit cb73381
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 33 deletions.
6 changes: 3 additions & 3 deletions build.gradle
Expand Up @@ -20,10 +20,10 @@ repositories {


dependencies {
groovy 'org.codehaus.groovy:groovy:1.8.4'
runtime 'org.codehaus.groovy:groovy:1.8.4'
groovy 'org.codehaus.groovy:groovy:1.8.6'
runtime 'org.codehaus.groovy:groovy:1.8.6'
testCompile 'junit:junit:4.8.2'
compile 'org.liquibase:liquibase-core:2.0.1'
compile 'org.liquibase:liquibase-core:2.0.3'
deployment "org.apache.maven.wagon:wagon-webdav-jackrabbit:1.0-beta-7"
testRuntime 'com.h2database:h2:1.3.159'
}
Expand Down
Expand Up @@ -45,19 +45,15 @@ class GroovyLiquibaseChangeLogParser
def changeLog = new DatabaseChangeLog(physicalChangeLogLocation)
changeLog.setChangeLogParameters(changeLogParameters)

Binding binding = new Binding()
binding.changeLogParser = this
binding.changeLog = changeLog
binding.resourceAccessor = resourceAccessor
CompilerConfiguration conf = new CompilerConfiguration()
conf.setScriptBaseClass(ParserScript.canonicalName)
GroovyShell shell = new GroovyShell(binding, conf)
def binding = new Binding()
def shell = new GroovyShell(binding)

// Parse the script, give it the local changeLog instance, give it access
// to root-level method delegates, and call.
def script = shell.parse(new InputStreamReader(inputStream, "UTF8"))
script.metaClass.getDatabaseChangeLog = { -> changeLog }
script.metaClass.getResourceAccessor = { -> resourceAccessor }
script.metaClass.methodMissing = changeLogMethodMissing
script.run()

// The changeLog will have been populated by the script
Expand All @@ -84,6 +80,17 @@ class GroovyLiquibaseChangeLogParser
}


def getChangeLogMethodMissing() {
{ name, args ->
if(name == 'databaseChangeLog') {
processDatabaseChangeLogRootElement(databaseChangeLog, resourceAccessor, args)
}
else {
throw new ChangeLogParseException("Unrecognized root element ${name}")
}
}
}

private def processDatabaseChangeLogRootElement(databaseChangeLog, resourceAccessor, args) {
switch(args.size()) {
case 0:
Expand Down Expand Up @@ -121,26 +128,3 @@ class GroovyLiquibaseChangeLogParser
}
}

abstract class ParserScript extends Script {

@Override
void setProperty(String name, value) {
if ("databaseChangeLog" == name) {
changeLogParser.processDatabaseChangeLogRootElement(changeLog, resourceAccessor, [value])
}
else {
super.setProperty(name, value)
}
}

@Override
Object invokeMethod(String name, Object args) {
if ("databaseChangeLog" == name) {
changeLogParser.processDatabaseChangeLogRootElement(changeLog, resourceAccessor, args)
}
else {
return super.invokeMethod(name, args)
}
}

}
42 changes: 42 additions & 0 deletions src/main/groovy/liquibase/parser/ext/ParserScript.groovy
@@ -0,0 +1,42 @@
/*
* Copyright 2011-2012 Tim Berglund
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package liquibase.parser.ext


abstract class ParserScript extends Script {

@Override
void setProperty(String name, value) {
if ("databaseChangeLog" == name) {
changeLogParser.processDatabaseChangeLogRootElement(changeLog, resourceAccessor, [value])
}
else {
super.setProperty(name, value)
}
}

@Override
Object invokeMethod(String name, Object args) {
if ("databaseChangeLog" == name) {
changeLogParser.processDatabaseChangeLogRootElement(changeLog, resourceAccessor, args)
}
else {
return super.invokeMethod(name, args)
}
}

}

0 comments on commit cb73381

Please sign in to comment.