|
19 | 19 | import java.util.ArrayList;
|
20 | 20 | import java.util.Collections;
|
21 | 21 | import java.util.List;
|
| 22 | +import java.util.Set; |
22 | 23 |
|
23 | 24 | import javassist.ClassPool;
|
24 | 25 | import javassist.CtClass;
|
@@ -78,15 +79,23 @@ private boolean shouldApply() {
|
78 | 79 |
|
79 | 80 | public void execute() throws MojoExecutionException, MojoFailureException {
|
80 | 81 | if ( !shouldApply() ) {
|
| 82 | + getLog().info( "Skipping Hibernate enhancement plugin execution since there is no feature enabled" ); |
81 | 83 | return;
|
82 | 84 | }
|
83 | 85 |
|
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 |
87 | 87 | 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 | + } |
88 | 92 | 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 | + } |
89 | 97 |
|
| 98 | + getLog().info( "Starting Hibernate enhancement for classes on " + dir ); |
90 | 99 | final ClassLoader classLoader = toClassLoader( Collections.singletonList( root ) );
|
91 | 100 |
|
92 | 101 | EnhancementContext enhancementContext = new DefaultEnhancementContext() {
|
@@ -161,17 +170,22 @@ private ClassLoader toClassLoader(List<File> runtimeClasspath) throws MojoExecut
|
161 | 170 | }
|
162 | 171 |
|
163 | 172 | // HHH-10145 Add dependencies to classpath as well - all but the ones used for testing purposes
|
| 173 | + Set<Artifact> artifacts = null; |
164 | 174 | MavenProject project = ( (MavenProject) getPluginContext().get( "project" ) );
|
165 | 175 | 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 ) { |
167 | 182 | if ( !Artifact.SCOPE_TEST.equals( a.getScope() ) ) {
|
168 | 183 | try {
|
169 | 184 | urls.add( a.getFile().toURI().toURL() );
|
170 | 185 | getLog().debug( "Adding classpath entry for dependency " + a.getId() );
|
171 | 186 | }
|
172 | 187 | 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(); |
175 | 189 | if ( failOnError ) {
|
176 | 190 | throw new MojoExecutionException( msg, e );
|
177 | 191 | }
|
|
0 commit comments