Skip to content

Instantly share code, notes, and snippets.

@aya-eiya
Created December 5, 2013 14:35
Show Gist options
  • Save aya-eiya/7806038 to your computer and use it in GitHub Desktop.
Save aya-eiya/7806038 to your computer and use it in GitHub Desktop.
GradleでOpenJPAのenhanceタスクを実装 ref: http://qiita.com/aya_eiya/items/65561d8e534c602818b6
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