LoginSignup
0
0

More than 5 years have passed since last update.

GradleでOpenJPAのenhanceタスクを実装

Posted at

ネットに転がっている方法を寄せ集めただけですが。

いくつかのpersstence.xmlを使っている場合にも対応しています。

元のクラスも(何に使うのかはわからんが)残しています。

openjpa.gradle
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
}
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0