HHH-11282 - Support m2e/Eclipse integration in hibernate-enhance-maven-plugin

This commit is contained in:
Craig Andrews 2016-11-29 12:20:12 -05:00 committed by Steve Ebersole
parent cff4ea1ce6
commit 5f8db1066d
4 changed files with 60 additions and 28 deletions

View File

@ -16,6 +16,7 @@ repositories {
}
processResources {
include "**/lifecycle-mapping-metadata.xml"
include "**/plugin-help.xml"
into processResources.destinationDir
filter(ReplaceTokens, tokens: ['version' : project.version])
@ -31,6 +32,7 @@ dependencies {
compile( libraries.javassist ) { transitive = false }
compile( libraries.byteBuddy ) { transitive = false }
compile 'org.codehaus.plexus:plexus-utils:3.0.1'
compile 'org.sonatype.plexus:plexus-build-api:0.0.7'
runtime( libraries.maven_core )
runtime( libraries.maven_artifact )
runtime( libraries.maven_plugin )

View File

@ -9,8 +9,8 @@ package org.hibernate.orm.tooling.maven;
import java.io.File;
import java.io.FileFilter;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLClassLoader;
@ -23,6 +23,7 @@ import org.apache.maven.artifact.Artifact;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.plugins.annotations.Component;
import org.apache.maven.plugins.annotations.Execute;
import org.apache.maven.plugins.annotations.LifecyclePhase;
import org.apache.maven.plugins.annotations.Mojo;
@ -37,6 +38,8 @@ import org.hibernate.bytecode.enhance.spi.UnloadedClass;
import org.hibernate.bytecode.enhance.spi.UnloadedField;
import org.hibernate.cfg.Environment;
import org.sonatype.plexus.build.incremental.BuildContext;
/**
* This plugin will enhance Entity objects.
*
@ -52,6 +55,9 @@ public class MavenEnhancePlugin extends AbstractMojo {
*/
private List<File> sourceSet = new ArrayList<File>();
@Component
private BuildContext buildContext;
@Parameter(property = "dir", defaultValue = "${project.build.outputDirectory}")
private String dir;
@ -201,7 +207,7 @@ public class MavenEnhancePlugin extends AbstractMojo {
if ( failOnError ) {
throw new MojoExecutionException( msg, e );
}
getLog().warn( msg );
buildContext.addMessage( javaClassFile, 0, 0, msg, BuildContext.SEVERITY_WARNING, e );
return null;
}
}
@ -240,20 +246,20 @@ public class MavenEnhancePlugin extends AbstractMojo {
try {
if ( file.delete() ) {
if ( !file.createNewFile() ) {
getLog().error( "Unable to recreate class file [" + file.getName() + "]" );
buildContext.addMessage( file, 0, 0, "Unable to recreate class file", BuildContext.SEVERITY_ERROR, null );
}
}
else {
getLog().error( "Unable to delete class file [" + file.getName() + "]" );
buildContext.addMessage( file, 0, 0, "Unable to delete class file", BuildContext.SEVERITY_ERROR, null );
}
}
catch (IOException e) {
getLog().warn( "Problem preparing class file for writing out enhancements [" + file.getName() + "]" );
buildContext.addMessage( file, 0, 0, "Problem preparing class file for writing out enhancements", BuildContext.SEVERITY_WARNING, e );
}
OutputStream outputStream = null;
try {
FileOutputStream outputStream = new FileOutputStream( file, false );
try {
outputStream = buildContext.newFileOutputStream( file );
outputStream.write( enhancedBytecode );
outputStream.flush();
}
@ -262,22 +268,16 @@ public class MavenEnhancePlugin extends AbstractMojo {
if ( failOnError ) {
throw new MojoExecutionException( msg, e );
}
getLog().warn( msg );
buildContext.addMessage( file, 0, 0, msg, BuildContext.SEVERITY_WARNING, e );
}
finally {
try {
if( outputStream != null ) {
outputStream.close();
}
}
catch (IOException ignore) {
}
}
}
catch (FileNotFoundException e) {
String msg = "Error opening class file for writing: " + file.getAbsolutePath();
if ( failOnError ) {
throw new MojoExecutionException( msg, e );
}
getLog().warn( msg );
}
}
}

View File

@ -0,0 +1,18 @@
<lifecycleMappingMetadata>
<pluginExecutions>
<pluginExecution>
<pluginExecutionFilter>
<goals>
<goal>enhance</goal>
</goals>
</pluginExecutionFilter>
<action>
<execute>
<runOnIncremental>true</runOnIncremental>
<runOnConfiguration>false</runOnConfiguration>
</execute>
</action>
</pluginExecution>
</pluginExecutions>
</lifecycleMappingMetadata>

View File

@ -84,6 +84,12 @@
<enableAssociationManagement>false</enableAssociationManagement>
<enableExtendedEnhancement>false</enableExtendedEnhancement>
</configuration>
<requirements>
<requirement>
<role>org.sonatype.plexus.build.incremental.BuildContext</role>
<field-name>buildContext</field-name>
</requirement>
</requirements>
</mojo>
</mojos>
<dependencies>
@ -96,6 +102,12 @@
<type>jar</type>
<version>3.0.1</version>
</dependency>
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-build-api</artifactId>
<type>jar</type>
<version>0.0.7</version>
</dependency>
<dependency>
<groupId>org.apache.maven.plugin-tools</groupId>
<artifactId>maven-plugin-annotations</artifactId>