Skip to content

Commit b4b6fa9

Browse files
barreirosebersole
authored andcommitted
HHH-10145 - [maven plugin] Transitive dependencies as well
(cherry picked from commit 7da8e53)
1 parent ab4cada commit b4b6fa9

File tree

1 file changed

+20
-6
lines changed

1 file changed

+20
-6
lines changed

tooling/hibernate-enhance-maven-plugin/src/main/java/org/hibernate/orm/tooling/maven/MavenEnhancePlugin.java

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import java.util.ArrayList;
2020
import java.util.Collections;
2121
import java.util.List;
22+
import java.util.Set;
2223

2324
import javassist.ClassPool;
2425
import javassist.CtClass;
@@ -78,15 +79,23 @@ private boolean shouldApply() {
7879

7980
public void execute() throws MojoExecutionException, MojoFailureException {
8081
if ( !shouldApply() ) {
82+
getLog().info( "Skipping Hibernate enhancement plugin execution since there is no feature enabled" );
8183
return;
8284
}
8385

84-
getLog().info( "Starting Hibernate enhancement for class sourceSet on " + dir );
85-
86-
/** Perform a depth first search for sourceSet. */
86+
// Perform a depth first search for sourceSet
8787
File root = new File( this.dir );
88+
if ( !root.exists() ) {
89+
getLog().info( "Skipping Hibernate enhancement plugin execution since there is no classes dir " + dir );
90+
return;
91+
}
8892
walkDir( root );
93+
if ( sourceSet.isEmpty() ) {
94+
getLog().info( "Skipping Hibernate enhancement plugin execution since there are no classes to enhance on " + dir );
95+
return;
96+
}
8997

98+
getLog().info( "Starting Hibernate enhancement for classes on " + dir );
9099
final ClassLoader classLoader = toClassLoader( Collections.singletonList( root ) );
91100

92101
EnhancementContext enhancementContext = new DefaultEnhancementContext() {
@@ -161,17 +170,22 @@ private ClassLoader toClassLoader(List<File> runtimeClasspath) throws MojoExecut
161170
}
162171

163172
// HHH-10145 Add dependencies to classpath as well - all but the ones used for testing purposes
173+
Set<Artifact> artifacts = null;
164174
MavenProject project = ( (MavenProject) getPluginContext().get( "project" ) );
165175
if ( project != null ) {
166-
for ( Artifact a : project.getDependencyArtifacts() ) {
176+
// Prefer execution project when available (it includes transient dependencies)
177+
MavenProject executionProject = project.getExecutionProject();
178+
artifacts = ( executionProject != null ? executionProject.getArtifacts() : project.getArtifacts() );
179+
}
180+
if ( artifacts != null) {
181+
for ( Artifact a : artifacts ) {
167182
if ( !Artifact.SCOPE_TEST.equals( a.getScope() ) ) {
168183
try {
169184
urls.add( a.getFile().toURI().toURL() );
170185
getLog().debug( "Adding classpath entry for dependency " + a.getId() );
171186
}
172187
catch (MalformedURLException e) {
173-
String msg = "Unable to resolve URL for dependency " + a.getId() + " at " + a.getFile()
174-
.getAbsolutePath();
188+
String msg = "Unable to resolve URL for dependency " + a.getId() + " at " + a.getFile().getAbsolutePath();
175189
if ( failOnError ) {
176190
throw new MojoExecutionException( msg, e );
177191
}

0 commit comments

Comments
 (0)