Skip to content

Commit ab4cada

Browse files
barreirosebersole
authored andcommitted
HHH-10146 - [gradle plugin] Create loading classloader after classes have been compiled
(cherry picked from commit 0089a3f)
1 parent 577bd47 commit ab4cada

File tree

1 file changed

+4
-9
lines changed
  • tooling/hibernate-gradle-plugin/src/main/groovy/org/hibernate/orm/tooling/gradle

1 file changed

+4
-9
lines changed

tooling/hibernate-gradle-plugin/src/main/groovy/org/hibernate/orm/tooling/gradle/HibernatePlugin.java

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -76,15 +76,14 @@ private void applyEnhancement(final Project project, final HibernateExtension hi
7676
project.getLogger().debug( "Applying Hibernate enhancement action to SourceSet.{}", sourceSet.getName() );
7777

7878
final Task compileTask = project.getTasks().findByName( sourceSet.getCompileJavaTaskName() );
79-
80-
final ClassLoader classLoader = toClassLoader( sourceSet.getRuntimeClasspath() );
81-
8279
compileTask.doLast(
8380
new Action<Task>() {
8481
@Override
8582
public void execute(Task task) {
8683
project.getLogger().debug( "Starting Hibernate enhancement on SourceSet.{}", sourceSet.getName() );
8784

85+
final ClassLoader classLoader = toClassLoader( sourceSet.getRuntimeClasspath() );
86+
8887
EnhancementContext enhancementContext = new DefaultEnhancementContext() {
8988
@Override
9089
public ClassLoader getLoadingClassLoader() {
@@ -120,7 +119,6 @@ public boolean doFieldAccessEnhancement(CtClass classDescriptor) {
120119
final Enhancer enhancer = new Enhancer( enhancementContext );
121120
final ClassPool classPool = new ClassPool( false );
122121

123-
124122
final FileTree fileTree = project.fileTree( sourceSet.getOutput().getClassesDir() );
125123
for ( File file : fileTree ) {
126124
if ( !file.getName().endsWith( ".class" ) ) {
@@ -151,16 +149,13 @@ private ClassLoader toClassLoader(FileCollection runtimeClasspath) {
151149
for ( File file : runtimeClasspath ) {
152150
try {
153151
urls.add( file.toURI().toURL() );
152+
logger.debug( "Adding classpath entry for " + file.getAbsolutePath() );
154153
}
155154
catch (MalformedURLException e) {
156155
throw new GradleException( "Unable to resolve classpath entry to URL : " + file.getAbsolutePath(), e );
157156
}
158157
}
159-
160-
return new URLClassLoader(
161-
urls.toArray( new URL[urls.size()] ),
162-
Enhancer.class.getClassLoader()
163-
);
158+
return new URLClassLoader( urls.toArray( new URL[urls.size()] ), Enhancer.class.getClassLoader() );
164159
}
165160

166161
private CtClass toCtClass(File file, ClassPool classPool) {

0 commit comments

Comments
 (0)