mirror of
https://github.com/hibernate/hibernate-orm
synced 2025-02-17 16:44:57 +00:00
HHH-10145 - [maven plugin] Transitive dependencies as well
This commit is contained in:
parent
0089a3f40f
commit
7da8e53469
@ -19,6 +19,7 @@
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
import javassist.ClassPool;
|
import javassist.ClassPool;
|
||||||
import javassist.CtClass;
|
import javassist.CtClass;
|
||||||
@ -78,15 +79,23 @@ private boolean shouldApply() {
|
|||||||
|
|
||||||
public void execute() throws MojoExecutionException, MojoFailureException {
|
public void execute() throws MojoExecutionException, MojoFailureException {
|
||||||
if ( !shouldApply() ) {
|
if ( !shouldApply() ) {
|
||||||
|
getLog().info( "Skipping Hibernate enhancement plugin execution since there is no feature enabled" );
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
getLog().info( "Starting Hibernate enhancement for class sourceSet on " + dir );
|
// Perform a depth first search for sourceSet
|
||||||
|
|
||||||
/** Perform a depth first search for sourceSet. */
|
|
||||||
File root = new File( this.dir );
|
File root = new File( this.dir );
|
||||||
|
if ( !root.exists() ) {
|
||||||
|
getLog().info( "Skipping Hibernate enhancement plugin execution since there is no classes dir " + dir );
|
||||||
|
return;
|
||||||
|
}
|
||||||
walkDir( root );
|
walkDir( root );
|
||||||
|
if ( sourceSet.isEmpty() ) {
|
||||||
|
getLog().info( "Skipping Hibernate enhancement plugin execution since there are no classes to enhance on " + dir );
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
getLog().info( "Starting Hibernate enhancement for classes on " + dir );
|
||||||
final ClassLoader classLoader = toClassLoader( Collections.singletonList( root ) );
|
final ClassLoader classLoader = toClassLoader( Collections.singletonList( root ) );
|
||||||
|
|
||||||
EnhancementContext enhancementContext = new DefaultEnhancementContext() {
|
EnhancementContext enhancementContext = new DefaultEnhancementContext() {
|
||||||
@ -161,17 +170,22 @@ private ClassLoader toClassLoader(List<File> runtimeClasspath) throws MojoExecut
|
|||||||
}
|
}
|
||||||
|
|
||||||
// HHH-10145 Add dependencies to classpath as well - all but the ones used for testing purposes
|
// HHH-10145 Add dependencies to classpath as well - all but the ones used for testing purposes
|
||||||
|
Set<Artifact> artifacts = null;
|
||||||
MavenProject project = ( (MavenProject) getPluginContext().get( "project" ) );
|
MavenProject project = ( (MavenProject) getPluginContext().get( "project" ) );
|
||||||
if ( project != null ) {
|
if ( project != null ) {
|
||||||
for ( Artifact a : project.getDependencyArtifacts() ) {
|
// Prefer execution project when available (it includes transient dependencies)
|
||||||
|
MavenProject executionProject = project.getExecutionProject();
|
||||||
|
artifacts = ( executionProject != null ? executionProject.getArtifacts() : project.getArtifacts() );
|
||||||
|
}
|
||||||
|
if ( artifacts != null) {
|
||||||
|
for ( Artifact a : artifacts ) {
|
||||||
if ( !Artifact.SCOPE_TEST.equals( a.getScope() ) ) {
|
if ( !Artifact.SCOPE_TEST.equals( a.getScope() ) ) {
|
||||||
try {
|
try {
|
||||||
urls.add( a.getFile().toURI().toURL() );
|
urls.add( a.getFile().toURI().toURL() );
|
||||||
getLog().debug( "Adding classpath entry for dependency " + a.getId() );
|
getLog().debug( "Adding classpath entry for dependency " + a.getId() );
|
||||||
}
|
}
|
||||||
catch (MalformedURLException e) {
|
catch (MalformedURLException e) {
|
||||||
String msg = "Unable to resolve URL for dependency " + a.getId() + " at " + a.getFile()
|
String msg = "Unable to resolve URL for dependency " + a.getId() + " at " + a.getFile().getAbsolutePath();
|
||||||
.getAbsolutePath();
|
|
||||||
if ( failOnError ) {
|
if ( failOnError ) {
|
||||||
throw new MojoExecutionException( msg, e );
|
throw new MojoExecutionException( msg, e );
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user