HHH-8309 - Create hibernate-orm subprojects for maven and gradle plugins
This commit is contained in:
parent
41e29b7bad
commit
cf7bb0dcec
|
@ -1,34 +1,7 @@
|
||||||
/*
|
|
||||||
* Hibernate, Relational Persistence for Idiomatic Java
|
|
||||||
*
|
|
||||||
* Copyright (c) 2013, Red Hat Inc. or third-party contributors as
|
|
||||||
* indicated by the @author tags or express copyright attribution
|
|
||||||
* statements applied by the authors. All third-party contributions are
|
|
||||||
* distributed under license by Red Hat Inc.
|
|
||||||
*
|
|
||||||
* This copyrighted material is made available to anyone wishing to use, modify,
|
|
||||||
* copy, or redistribute it subject to the terms and conditions of the GNU
|
|
||||||
* Lesser General Public License, as published by the Free Software Foundation.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
|
||||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
|
||||||
* for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU Lesser General Public License
|
|
||||||
* along with this distribution; if not, write to:
|
|
||||||
* Free Software Foundation, Inc.
|
|
||||||
* 51 Franklin Street, Fifth Floor
|
|
||||||
* Boston, MA 02110-1301 USA
|
|
||||||
*/
|
|
||||||
apply plugin: 'groovy'
|
apply plugin: 'groovy'
|
||||||
apply plugin: 'maven'
|
apply plugin: 'maven'
|
||||||
apply plugin: 'java'
|
apply plugin: 'java'
|
||||||
|
|
||||||
repositories {
|
|
||||||
mavenCentral()
|
|
||||||
}
|
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
compile( project(':hibernate-core') )
|
compile( project(':hibernate-core') )
|
||||||
compile( libraries.jpa )
|
compile( libraries.jpa )
|
||||||
|
@ -36,12 +9,3 @@ dependencies {
|
||||||
compile gradleApi()
|
compile gradleApi()
|
||||||
compile localGroovy()
|
compile localGroovy()
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Available for testing locally. */
|
|
||||||
install {
|
|
||||||
repositories.mavenInstaller {
|
|
||||||
pom.groupId = 'org.hibernate'
|
|
||||||
pom.artifactId = 'hibernate-gradle-plugin'
|
|
||||||
pom.version = '1.0'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,62 +0,0 @@
|
||||||
/*
|
|
||||||
* Hibernate, Relational Persistence for Idiomatic Java
|
|
||||||
*
|
|
||||||
* Copyright (c) 2013, Red Hat Inc. or third-party contributors as
|
|
||||||
* indicated by the @author tags or express copyright attribution
|
|
||||||
* statements applied by the authors. All third-party contributions are
|
|
||||||
* distributed under license by Red Hat Inc.
|
|
||||||
*
|
|
||||||
* This copyrighted material is made available to anyone wishing to use, modify,
|
|
||||||
* copy, or redistribute it subject to the terms and conditions of the GNU
|
|
||||||
* Lesser General Public License, as published by the Free Software Foundation.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
|
||||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
|
||||||
* for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU Lesser General Public License
|
|
||||||
* along with this distribution; if not, write to:
|
|
||||||
* Free Software Foundation, Inc.
|
|
||||||
* 51 Franklin Street, Fifth Floor
|
|
||||||
* Boston, MA 02110-1301 USA
|
|
||||||
*/
|
|
||||||
package org.hibernate.bytecode.enhance.plugins;
|
|
||||||
|
|
||||||
import org.gradle.api.Plugin;
|
|
||||||
import org.gradle.api.Project;
|
|
||||||
import org.gradle.api.Task;
|
|
||||||
import org.gradle.api.plugins.BasePlugin;
|
|
||||||
import org.gradle.api.plugins.JavaBasePlugin;
|
|
||||||
import org.gradle.api.artifacts.Configuration;
|
|
||||||
import org.gradle.api.plugins.JavaPlugin;
|
|
||||||
import org.hibernate.bytecode.enhance.plugins.EnhanceTask;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This plugin will add Entity enhancement behaviour to the build lifecycle.
|
|
||||||
*
|
|
||||||
* @author Jeremy Whiting
|
|
||||||
*/
|
|
||||||
@SuppressWarnings("serial")
|
|
||||||
public class EnhancePlugin implements Plugin<Project>{
|
|
||||||
|
|
||||||
public static final String ENHANCE_TASK_NAME = "enhance";
|
|
||||||
public static final String HAPPENS_AFTER_ENHANCE_TASK_NAME = JavaPlugin.JAR_TASK_NAME;
|
|
||||||
|
|
||||||
public void apply(Project project) {
|
|
||||||
project.getLogger().debug( "Applying enhance plugin to project." );
|
|
||||||
configureTask( project );
|
|
||||||
project.getLogger().debug( String.format( "DAG has been configured with enhance task dependent on [%s].", JavaPlugin.CLASSES_TASK_NAME ) );
|
|
||||||
}
|
|
||||||
|
|
||||||
private void configureTask(Project project) {
|
|
||||||
EnhanceTask enhanceTask = project.getTasks().create( ENHANCE_TASK_NAME, EnhanceTask.class );
|
|
||||||
enhanceTask.setGroup(BasePlugin.BUILD_GROUP);
|
|
||||||
// connect up the task in the task dependency graph
|
|
||||||
Task classesTask = project.getTasks().getByName( JavaPlugin.CLASSES_TASK_NAME );
|
|
||||||
enhanceTask.dependsOn( classesTask );
|
|
||||||
|
|
||||||
Task jarTask = project.getTasks().getByName( HAPPENS_AFTER_ENHANCE_TASK_NAME );
|
|
||||||
jarTask.dependsOn( enhanceTask );
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -21,32 +21,30 @@
|
||||||
* 51 Franklin Street, Fifth Floor
|
* 51 Franklin Street, Fifth Floor
|
||||||
* Boston, MA 02110-1301 USA
|
* Boston, MA 02110-1301 USA
|
||||||
*/
|
*/
|
||||||
package org.hibernate.bytecode.enhance.plugins
|
package org.hibernate.tooling.gradle
|
||||||
|
|
||||||
import org.hibernate.bytecode.enhance.spi.Enhancer
|
|
||||||
import org.hibernate.bytecode.enhance.spi.EnhancementContext
|
|
||||||
import javassist.ClassPool
|
import javassist.ClassPool
|
||||||
import javassist.CtClass
|
import javassist.CtClass
|
||||||
import javassist.CtField
|
import javassist.CtField
|
||||||
import javax.persistence.Transient
|
|
||||||
import javax.persistence.Entity
|
|
||||||
import java.io.FileInputStream
|
|
||||||
import java.io.FileOutputStream
|
|
||||||
import org.gradle.api.DefaultTask
|
import org.gradle.api.DefaultTask
|
||||||
import org.gradle.api.plugins.Convention
|
|
||||||
import org.gradle.api.tasks.TaskAction
|
|
||||||
import org.gradle.api.file.FileTree
|
import org.gradle.api.file.FileTree
|
||||||
|
import org.gradle.api.tasks.TaskAction
|
||||||
|
import org.hibernate.bytecode.enhance.spi.EnhancementContext
|
||||||
|
import org.hibernate.bytecode.enhance.spi.Enhancer
|
||||||
|
|
||||||
|
import javax.persistence.Entity
|
||||||
|
import javax.persistence.Transient
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Plugin to enhance Entities using the context(s) to determine
|
* Gradle Task to apply Hibernate's bytecode Enhancer
|
||||||
* which to apply.
|
*
|
||||||
* @author Jeremy Whiting
|
* @author Jeremy Whiting
|
||||||
*/
|
*/
|
||||||
public class EnhanceTask extends DefaultTask implements EnhancementContext {
|
public class EnhancerTask extends DefaultTask implements EnhancementContext {
|
||||||
|
|
||||||
private ClassLoader overridden
|
private ClassLoader overridden
|
||||||
|
|
||||||
public EnhanceTask() {
|
public EnhancerTask() {
|
||||||
super()
|
super()
|
||||||
setDescription( 'Enhances Entity classes for efficient association referencing.' )
|
setDescription( 'Enhances Entity classes for efficient association referencing.' )
|
||||||
}
|
}
|
||||||
|
@ -58,27 +56,32 @@ public class EnhanceTask extends DefaultTask implements EnhancementContext {
|
||||||
ext.enhancer = new Enhancer( this )
|
ext.enhancer = new Enhancer( this )
|
||||||
FileTree tree = project.fileTree( dir: project.sourceSets.main.output.classesDir )
|
FileTree tree = project.fileTree( dir: project.sourceSets.main.output.classesDir )
|
||||||
tree.include '**/*.class'
|
tree.include '**/*.class'
|
||||||
tree.each(
|
tree.each( { File file ->
|
||||||
{ File file ->
|
|
||||||
final byte[] enhancedBytecode;
|
final byte[] enhancedBytecode;
|
||||||
InputStream is = null;
|
InputStream is = null;
|
||||||
CtClass clas = null;
|
CtClass clas = null;
|
||||||
try {
|
try {
|
||||||
is = new FileInputStream( file.toString() )
|
is = new FileInputStream( file.toString() )
|
||||||
clas = ext.pool.makeClass( is )
|
clas = ext.pool.makeClass( is )
|
||||||
|
// Enhancer already does this check to see if it should enhance, why are we doing it again here?
|
||||||
if ( !clas.hasAnnotation( Entity.class ) ) {
|
if ( !clas.hasAnnotation( Entity.class ) ) {
|
||||||
logger.debug( "Class $file not an annotated Entity class. skipping..." )
|
logger.debug( "Class $file not an annotated Entity class. skipping..." )
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
enhancedBytecode = ext.enhancer.enhance( clas.getName(), clas.toBytecode() );
|
enhancedBytecode = ext.enhancer.enhance( clas.getName(), clas.toBytecode() );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception e) {
|
catch (Exception e) {
|
||||||
logger.error( "Unable to enhance class [${file.toString()}]", e )
|
logger.error( "Unable to enhance class [${file.toString()}]", e )
|
||||||
return
|
return
|
||||||
} finally {
|
}
|
||||||
|
finally {
|
||||||
try {
|
try {
|
||||||
if (null != is) is.close();
|
if ( null != is ) {
|
||||||
} finally{}
|
is.close()
|
||||||
|
};
|
||||||
|
}
|
||||||
|
finally {}
|
||||||
}
|
}
|
||||||
if ( null != enhancedBytecode ) {
|
if ( null != enhancedBytecode ) {
|
||||||
if ( file.delete() ) {
|
if ( file.delete() ) {
|
||||||
|
@ -96,7 +99,9 @@ public class EnhanceTask extends DefaultTask implements EnhancementContext {
|
||||||
}
|
}
|
||||||
finally {
|
finally {
|
||||||
try {
|
try {
|
||||||
if (outputStream != null) outputStream.close()
|
if ( outputStream != null ) {
|
||||||
|
outputStream.close()
|
||||||
|
}
|
||||||
clas.detach()//release memory
|
clas.detach()//release memory
|
||||||
}
|
}
|
||||||
catch (IOException ignore) {
|
catch (IOException ignore) {
|
||||||
|
@ -135,6 +140,7 @@ public class EnhanceTask extends DefaultTask implements EnhancementContext {
|
||||||
public boolean isCompositeClass(CtClass classDescriptor) {
|
public boolean isCompositeClass(CtClass classDescriptor) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean doDirtyCheckingInline(CtClass classDescriptor) {
|
public boolean doDirtyCheckingInline(CtClass classDescriptor) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
|
@ -0,0 +1,75 @@
|
||||||
|
/*
|
||||||
|
* Hibernate, Relational Persistence for Idiomatic Java
|
||||||
|
*
|
||||||
|
* Copyright (c) 2013, Red Hat Inc. or third-party contributors as
|
||||||
|
* indicated by the @author tags or express copyright attribution
|
||||||
|
* statements applied by the authors. All third-party contributions are
|
||||||
|
* distributed under license by Red Hat Inc.
|
||||||
|
*
|
||||||
|
* This copyrighted material is made available to anyone wishing to use, modify,
|
||||||
|
* copy, or redistribute it subject to the terms and conditions of the GNU
|
||||||
|
* Lesser General Public License, as published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||||
|
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||||
|
* for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with this distribution; if not, write to:
|
||||||
|
* Free Software Foundation, Inc.
|
||||||
|
* 51 Franklin Street, Fifth Floor
|
||||||
|
* Boston, MA 02110-1301 USA
|
||||||
|
*/
|
||||||
|
package org.hibernate.tooling.gradle;
|
||||||
|
|
||||||
|
import org.gradle.api.Plugin;
|
||||||
|
import org.gradle.api.Project;
|
||||||
|
import org.gradle.api.Task;
|
||||||
|
import org.gradle.api.plugins.BasePlugin;
|
||||||
|
import org.gradle.api.plugins.JavaPlugin;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The Hibernate Gradle plugin. Adds Hibernate build-time capabilities into your Gradle-based build.
|
||||||
|
*
|
||||||
|
* @author Jeremy Whiting
|
||||||
|
* @author Steve Ebersole
|
||||||
|
*/
|
||||||
|
@SuppressWarnings("serial")
|
||||||
|
public class HibernatePlugin implements Plugin<Project> {
|
||||||
|
|
||||||
|
public static final String ENHANCE_TASK_NAME = "enhance";
|
||||||
|
|
||||||
|
public void apply(Project project) {
|
||||||
|
applyEnhancement( project );
|
||||||
|
}
|
||||||
|
|
||||||
|
private void applyEnhancement(Project project) {
|
||||||
|
project.getLogger().debug( "Applying Hibernate enhancement to project." );
|
||||||
|
|
||||||
|
// few things...
|
||||||
|
|
||||||
|
// 1) would probably be best as a doLast Action attached to the compile task rather than
|
||||||
|
// a task. Really ideally would be a task association for "always run after", but Gradle
|
||||||
|
// does not yet have that (mustRunAfter is very different semantic, finalizedBy is closer but
|
||||||
|
// will run even if the first task fails). The initial attempt here fell into the "maven" trap
|
||||||
|
// of trying to run a dependent task by attaching it to a task know to run after the we want to run after;
|
||||||
|
// which is a situation tailored made for Task.doLast
|
||||||
|
|
||||||
|
// 2) would be better to allow specifying which SourceSet to apply this to. For example, in the Hibernate
|
||||||
|
// build itself, this would be best applied to the 'test' sourceSet; though generally speaking the
|
||||||
|
// 'main' sourceSet is more appropriate
|
||||||
|
|
||||||
|
// for now, we'll just:
|
||||||
|
// 1) use a EnhancerTask + finalizedBy
|
||||||
|
// 2) apply to main sourceSet
|
||||||
|
|
||||||
|
EnhancerTask enhancerTask = project.getTasks().create( ENHANCE_TASK_NAME, EnhancerTask.class );
|
||||||
|
enhancerTask.setGroup( BasePlugin.BUILD_GROUP );
|
||||||
|
|
||||||
|
// connect up the task in the task dependency graph
|
||||||
|
Task classesTask = project.getTasks().getByName( JavaPlugin.CLASSES_TASK_NAME );
|
||||||
|
enhancerTask.dependsOn( classesTask );
|
||||||
|
classesTask.finalizedBy( enhancerTask );
|
||||||
|
}
|
||||||
|
}
|
|
@ -1 +0,0 @@
|
||||||
implementation-class=org.hibernate.bytecode.enhance.plugins.EnhancePlugin
|
|
|
@ -0,0 +1 @@
|
||||||
|
implementation-class=org.hibernate.tooling.gradle.HibernatePlugin
|
|
@ -55,7 +55,7 @@ import org.apache.maven.plugins.annotations.Parameter;
|
||||||
* @author Jeremy Whiting
|
* @author Jeremy Whiting
|
||||||
*/
|
*/
|
||||||
@Mojo(name = "enhance")
|
@Mojo(name = "enhance")
|
||||||
public class MavenEnhancePlugin extends AbstractMojo {
|
public class HibernateEnhancementMojo extends AbstractMojo {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The contexts to use during enhancement.
|
* The contexts to use during enhancement.
|
|
@ -11,7 +11,7 @@ include 'hibernate-proxool'
|
||||||
include 'hibernate-ehcache'
|
include 'hibernate-ehcache'
|
||||||
include 'hibernate-infinispan'
|
include 'hibernate-infinispan'
|
||||||
include 'hibernate-gradle-plugin'
|
include 'hibernate-gradle-plugin'
|
||||||
include 'enhance-maven-plugin'
|
include 'hibernate-maven-plugin'
|
||||||
include 'documentation'
|
include 'documentation'
|
||||||
include 'release'
|
include 'release'
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue