Permalink
Browse files

Fixed a bug in script parsing.

  • Loading branch information...
1 parent 84dd0d7 commit cb73381eb0ef06258c2a24fa18ed3caae664cb66 @tlberglund committed Mar 15, 2012
View
@@ -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'
}
@@ -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
@@ -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:
@@ -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)
- }
- }
-
-}
@@ -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.