Created
December 5, 2013 14:35
-
-
Save aya-eiya/7806038 to your computer and use it in GitHub Desktop.
GradleでOpenJPAのenhanceタスクを実装 ref: http://qiita.com/aya_eiya/items/65561d8e534c602818b6
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
def relativize = {file-> | |
projectDir.toURI().relativize(file.toURI()).toString() | |
} | |
task(enhance,dependsOn:classes) << { | |
description 'OpenJPA enhancer task.' | |
ant.taskdef ( | |
name : 'openjpac', | |
classpath : project.runtimeClasspath.asPath, | |
classname : 'org.apache.openjpa.ant.PCEnhancerTask' | |
) | |
def resurcesDir = sourceSets.main.output.resourcesDir | |
def mainOutDir = relativize(sourceSets.main.output.classesDir) | |
def jpacOutDir = relativize(sourceSets.main.output.classesDir) - ~/\/$/+ '_jpa/' | |
def orgDir = relativize(sourceSets.main.output.classesDir) - ~/\/$/+ '_org/' | |
ant.mkdir(dir:orgDir) | |
ant.copy(todir:orgDir){ | |
fileset(dir:mainOutDir){ | |
include(name:'**') | |
} | |
} | |
resurcesDir.eachFileRecurse(groovy.io.FileType.FILES) { | |
propertiesFile -> | |
ant.mkdir(dir:jpacOutDir) | |
if(propertiesFile.name ==~ /.*persistence.*\.xml/){ | |
def propertiesFilePath = relativize(propertiesFile) | |
ant.openjpac( | |
classpath:project.runtimeClasspath.asPath, | |
addDefaultConstructor:true, | |
enforcePropertyRestrictions:true, | |
directory:jpacOutDir | |
){ | |
config(propertiesFile:propertiesFilePath) | |
} | |
} | |
ant.move(todir:mainOutDir){ | |
fileset(dir:jpacOutDir){ | |
include(name:'**') | |
} | |
} | |
ant.delete(dir:jpacOutDir) | |
} | |
} | |
jar { | |
dependsOn enhance | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment