Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom task fixes #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,6 @@ database.properties
.project
bin/
maven-central.properties
gradle.properties
gradle.properties
groovy-liquibase.ipr
groovy-liquibase.iws
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ well as the upcoming Gradle 2.0 release.
Tim Berglund has asked me to take on the continued maintenance of this project,
so I've had to change the maven group ID to one for which I have permission to
publish on Maven Central. Going forward, this parser will be available under
the ```net.saliman``` group id. The artifact ID will remain the same:
```groovy-liquibase-dsl```.
the ```net.saliman``` group id. The artifact ID, ```groovy-liquibase-dsl```,
will remain the same.

My thanks to Tim for the opportunity to help out with this great project.

Expand Down
9 changes: 5 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
apply plugin: 'groovy'
apply plugin: 'maven'
apply plugin: 'signing'
apply plugin: 'idea'


version = '1.0.0'
version = '1.0.1'
group = 'net.saliman'
def artifact = 'groovy-liquibase-dsl'

Expand Down Expand Up @@ -49,7 +50,7 @@ task groovydocJar(type: Jar, dependsOn: groovydoc) {
from fileTree(groovydoc.destinationDir)
}

artifacts {
artifacts {
archives groovydocJar, sourceJar
}

Expand All @@ -72,7 +73,7 @@ uploadPublished {
signPom(deployment)
}
name = 'mavenCentralReleaseDeployer'
repository(url: "https://oss.sonatype.org/service/local/staging/deploy/maven2/") {
repository(url: "https://oss.sonatype.org/service/local/staging/deploy/maven2/") {
authentication(userName: mavenCentralUsername, password: mavenCentralPassword)
releases(updatePolicy: 'always')
snapshots(updatePolicy: 'never')
Expand All @@ -85,7 +86,7 @@ uploadPublished {
// A single place to create the POM configuration, so it can be
// applied from the install and the upload tasks.
//
def getPomConfiguration() {
def getPomConfiguration() {
return {
name('Groovy Liquibase DSL')
description('A Groovy-based DSL for the Liquibase database refactoring tool.')
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -482,8 +482,8 @@ class ChangeSetDelegate {
void customChange(Map params, Closure closure = null) {
def change = new CustomChangeWrapper()
change.classLoader = this.class.classLoader
change.className = DelegateUtil.expandExpressions(params['class'], databaseChangeLog)

def customTaskClassName = params['className'] ? params['className'] : params['class']
change.setClass(DelegateUtil.expandExpressions(customTaskClassName, databaseChangeLog))
if ( closure ) {
def delegate = new KeyValueDelegate()
closure.delegate = delegate
Expand Down
2 changes: 1 addition & 1 deletion src/test/changelog/changelog.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ databaseChangeLog(logicalFilePath: '') {


changeSet(id: 'custom-refactoring', author: 'tlberglund') {
customChange(class: 'net.saliman.liquibase.MonkeyRefactoring') {
customChange(className: 'net.saliman.liquibase.MonkeyRefactoring') {
tableName('animal')
species('monkey')
status('angry')
Expand Down
21 changes: 20 additions & 1 deletion src/test/changelog/simple-changelog.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,26 @@
databaseChangeLog(logicalFilePath: '.') {

changeSet(author: 'tlberglund', id: 'change-set-001') {


myParametrizedCustomChange{
name('myProperty')
value('prop1')
}
myParametrizedCustomChange{
myProperty('prop2')
}
customChange(className: 'net.saliman.liquibase.custom.MyParametrizedCustomChange') {
name('myProperty')
value('prop3')
}
customChange(className: 'net.saliman.liquibase.custom.MyCustomSqlChange') {
}
}

changeSet(author: 'tlberglund', id: 'change-set-001') {
myParametrizedCustomChange{
myProperty('prop4')
}
}

}
Original file line number Diff line number Diff line change
@@ -1,14 +1,7 @@
package groovy.runtime.metaclass.net.saliman.liquibase.delegate

import groovy.lang.ExpandoMetaClass
import groovy.lang.MetaClassRegistry

import org.codehaus.groovy.runtime.metaclass.ClosureMetaMethod.AnonymousMetaMethod

import net.saliman.liquibase.change.CustomProgrammaticChangeWrapper
import net.saliman.liquibase.custom.MyCustomSqlChange


/**
* This defines an ExpandoMetaClass on net.saliman.liquibase.delegate.ChangeSetDelegate
* so that we can manipulate the class at runtime to add new methods. In this example,
Expand All @@ -23,10 +16,21 @@ class ChangeSetDelegateMetaClass
ChangeSetDelegateMetaClass(MetaClassRegistry reg, Class clazz) {
super(clazz, true, false)

addMetaMethod(new AnonymousMetaMethod({ addChange(new CustomProgrammaticChangeWrapper(new MyCustomSqlChange())) },
'myCustomSqlChange',
addMetaMethod(new AnonymousMetaMethod(
{
customChange([className: 'net.saliman.liquibase.custom.MyCustomSqlChange'], {})
},
'myCustomSqlChange',
clazz))


addMetaMethod(new AnonymousMetaMethod(
{Closure closure = null ->
customChange([className: 'net.saliman.liquibase.custom.MyParametrizedCustomChange'], closure)
},
'myParametrizedCustomChange',
clazz))

initialize()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package net.saliman.liquibase.custom

import liquibase.change.custom.CustomChange
import liquibase.database.Database
import liquibase.exception.ValidationErrors
import liquibase.resource.ResourceAccessor
import liquibase.statement.SqlStatement
import liquibase.statement.core.RawSqlStatement

/**
* A trivial liquibase CustomSqlChange that will be added to the DSL
* through groovy metaprogramming
*
* @see groovy.runtime.metaclass.net.saliman.liquibase.delegate.ChangeSetDelegateMetaClass
* @author Jason Clawson
*/
class MyParametrizedCustomChange implements CustomChange {

def myProperty

MyParametrizedCustomChange() {
super()
}

String getConfirmationMessage() {
return 'confirmation message here'
}

void setUp() {
;
}

public void setFileOpener(ResourceAccessor resourceAccessor) {
;
}

ValidationErrors validate(Database database) {
new ValidationErrors()
}

SqlStatement[] generateStatements(Database database) {
[new RawSqlStatement("SELECT * FROM monkey where property= ${myProperty}")]
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,7 @@ class CustomRefactoringTests extends ChangeSetTests {
@Test
void customRefactoringWithClassAndNoParameters() {
buildChangeSet {
customChange(class: 'org.liquibase.change.custom.MonkeyChange')
customChange(className: 'org.liquibase.change.custom.MonkeyChange')
}

assertEquals 0, changeSet.getRollBackChanges().length
Expand All @@ -447,7 +447,7 @@ class CustomRefactoringTests extends ChangeSetTests {
@Test
void customRefactoringWithClassAndParameters() {
buildChangeSet {
customChange(class: 'org.liquibase.change.custom.MonkeyChange') {
customChange(className: 'org.liquibase.change.custom.MonkeyChange') {
emotion('angry')
'rfid-tag'(28763)
}
Expand Down
Loading