HHH-10146 - [gradle plugin] Create loading classloader after classes have been compiled

(cherry picked from commit 0089a3f40f)
This commit is contained in:
barreiro 2015-09-29 04:59:01 +01:00 committed by Steve Ebersole
parent 577bd4752a
commit ab4cada056
1 changed files with 4 additions and 9 deletions

View File

@ -76,15 +76,14 @@ public class HibernatePlugin implements Plugin<Project> {
project.getLogger().debug( "Applying Hibernate enhancement action to SourceSet.{}", sourceSet.getName() ); project.getLogger().debug( "Applying Hibernate enhancement action to SourceSet.{}", sourceSet.getName() );
final Task compileTask = project.getTasks().findByName( sourceSet.getCompileJavaTaskName() ); final Task compileTask = project.getTasks().findByName( sourceSet.getCompileJavaTaskName() );
final ClassLoader classLoader = toClassLoader( sourceSet.getRuntimeClasspath() );
compileTask.doLast( compileTask.doLast(
new Action<Task>() { new Action<Task>() {
@Override @Override
public void execute(Task task) { public void execute(Task task) {
project.getLogger().debug( "Starting Hibernate enhancement on SourceSet.{}", sourceSet.getName() ); project.getLogger().debug( "Starting Hibernate enhancement on SourceSet.{}", sourceSet.getName() );
final ClassLoader classLoader = toClassLoader( sourceSet.getRuntimeClasspath() );
EnhancementContext enhancementContext = new DefaultEnhancementContext() { EnhancementContext enhancementContext = new DefaultEnhancementContext() {
@Override @Override
public ClassLoader getLoadingClassLoader() { public ClassLoader getLoadingClassLoader() {
@ -120,7 +119,6 @@ public class HibernatePlugin implements Plugin<Project> {
final Enhancer enhancer = new Enhancer( enhancementContext ); final Enhancer enhancer = new Enhancer( enhancementContext );
final ClassPool classPool = new ClassPool( false ); final ClassPool classPool = new ClassPool( false );
final FileTree fileTree = project.fileTree( sourceSet.getOutput().getClassesDir() ); final FileTree fileTree = project.fileTree( sourceSet.getOutput().getClassesDir() );
for ( File file : fileTree ) { for ( File file : fileTree ) {
if ( !file.getName().endsWith( ".class" ) ) { if ( !file.getName().endsWith( ".class" ) ) {
@ -151,16 +149,13 @@ public class HibernatePlugin implements Plugin<Project> {
for ( File file : runtimeClasspath ) { for ( File file : runtimeClasspath ) {
try { try {
urls.add( file.toURI().toURL() ); urls.add( file.toURI().toURL() );
logger.debug( "Adding classpath entry for " + file.getAbsolutePath() );
} }
catch (MalformedURLException e) { catch (MalformedURLException e) {
throw new GradleException( "Unable to resolve classpath entry to URL : " + file.getAbsolutePath(), e ); throw new GradleException( "Unable to resolve classpath entry to URL : " + file.getAbsolutePath(), e );
} }
} }
return new URLClassLoader( urls.toArray( new URL[urls.size()] ), Enhancer.class.getClassLoader() );
return new URLClassLoader(
urls.toArray( new URL[urls.size()] ),
Enhancer.class.getClassLoader()
);
} }
private CtClass toCtClass(File file, ClassPool classPool) { private CtClass toCtClass(File file, ClassPool classPool) {