HHH-13133 Review logging usage in the MavenEnhancePlugin

This commit is contained in:
Sanne Grinovero 2019-08-05 11:42:24 +01:00
parent ac7d7f4d6f
commit 71fe4229b4
1 changed files with 18 additions and 12 deletions

View File

@ -24,6 +24,7 @@ import org.apache.maven.artifact.Artifact;
import org.apache.maven.plugin.AbstractMojo; import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException; import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.plugin.logging.Log;
import org.apache.maven.plugins.annotations.Component; import org.apache.maven.plugins.annotations.Component;
import org.apache.maven.plugins.annotations.Execute; import org.apache.maven.plugins.annotations.Execute;
import org.apache.maven.plugins.annotations.LifecyclePhase; import org.apache.maven.plugins.annotations.LifecyclePhase;
@ -85,8 +86,9 @@ public class MavenEnhancePlugin extends AbstractMojo {
@Override @Override
public void execute() throws MojoExecutionException, MojoFailureException { public void execute() throws MojoExecutionException, MojoFailureException {
final Log log = getLog();
if ( !shouldApply() ) { if ( !shouldApply() ) {
getLog().warn( "Skipping Hibernate bytecode enhancement plugin execution since no feature is enabled" ); log.warn( "Skipping Hibernate bytecode enhancement plugin execution since no feature is enabled" );
return; return;
} }
@ -97,16 +99,16 @@ public class MavenEnhancePlugin extends AbstractMojo {
// 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() ) { if ( !root.exists() ) {
getLog().info( "Skipping Hibernate enhancement plugin execution since there is no classes dir " + dir ); log.info( "Skipping Hibernate enhancement plugin execution since there is no classes dir " + dir );
return; return;
} }
walkDir( root ); walkDir( root );
if ( sourceSet.isEmpty() ) { if ( sourceSet.isEmpty() ) {
getLog().info( "Skipping Hibernate enhancement plugin execution since there are no classes to enhance on " + dir ); log.info( "Skipping Hibernate enhancement plugin execution since there are no classes to enhance on " + dir );
return; return;
} }
getLog().info( "Starting Hibernate enhancement for classes on " + dir ); log.info( "Starting Hibernate enhancement for classes on " + dir );
final ClassLoader classLoader = toClassLoader( Collections.singletonList( new File( base ) ) ); final ClassLoader classLoader = toClassLoader( Collections.singletonList( new File( base ) ) );
EnhancementContext enhancementContext = new DefaultEnhancementContext() { EnhancementContext enhancementContext = new DefaultEnhancementContext() {
@ -142,7 +144,7 @@ public class MavenEnhancePlugin extends AbstractMojo {
}; };
if ( enableExtendedEnhancement ) { if ( enableExtendedEnhancement ) {
getLog().warn( "Extended enhancement is enabled. Classes other than entities may be modified. You should consider access the entities using getter/setter methods and disable this property. Use at your own risk." ); log.warn( "Extended enhancement is enabled. Classes other than entities may be modified. You should consider access the entities using getter/setter methods and disable this property. Use at your own risk." );
} }
final Enhancer enhancer = Environment.getBytecodeProvider().getEnhancer( enhancementContext ); final Enhancer enhancer = Environment.getBytecodeProvider().getEnhancer( enhancementContext );
@ -156,24 +158,28 @@ public class MavenEnhancePlugin extends AbstractMojo {
} }
writeOutEnhancedClass( enhancedBytecode, file ); writeOutEnhancedClass( enhancedBytecode, file );
if ( log.isDebugEnabled() ) {
getLog().debug( "Successfully enhanced class [" + file + "]" ); log.debug( "Successfully enhanced class [" + file + "]" );
}
} }
} }
private ClassLoader toClassLoader(List<File> runtimeClasspath) throws MojoExecutionException { private ClassLoader toClassLoader(List<File> runtimeClasspath) throws MojoExecutionException {
List<URL> urls = new ArrayList<URL>(); List<URL> urls = new ArrayList<URL>( runtimeClasspath.size() );
final Log log = getLog();
for ( File file : runtimeClasspath ) { for ( File file : runtimeClasspath ) {
try { try {
urls.add( file.toURI().toURL() ); urls.add( file.toURI().toURL() );
getLog().debug( "Adding classpath entry for classes root " + file.getAbsolutePath() ); if ( log.isDebugEnabled() ) {
log.debug( "Adding classpath entry for classes root " + file.getAbsolutePath() );
}
} }
catch (MalformedURLException e) { catch (MalformedURLException e) {
String msg = "Unable to resolve classpath entry to URL: " + file.getAbsolutePath(); String msg = "Unable to resolve classpath entry to URL: " + file.getAbsolutePath();
if ( failOnError ) { if ( failOnError ) {
throw new MojoExecutionException( msg, e ); throw new MojoExecutionException( msg, e );
} }
getLog().warn( msg ); log.warn( msg );
} }
} }
@ -185,14 +191,14 @@ public class MavenEnhancePlugin extends AbstractMojo {
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() ); log.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().getAbsolutePath(); String msg = "Unable to resolve URL for dependency " + a.getId() + " at " + a.getFile().getAbsolutePath();
if ( failOnError ) { if ( failOnError ) {
throw new MojoExecutionException( msg, e ); throw new MojoExecutionException( msg, e );
} }
getLog().warn( msg ); log.warn( msg );
} }
} }
} }