HHH-11282 - HHH-11287 - HHH-11288 - [ hibernate-enhance-maven-plugin ] m2e/Eclipse integration + requiresDependencyResolution in descriptor + use project artifacts
Get artifacts from project, not executionProject
This commit is contained in:
parent
919557f250
commit
71d278b77d
|
@ -16,6 +16,7 @@ repositories {
|
||||||
}
|
}
|
||||||
|
|
||||||
processResources {
|
processResources {
|
||||||
|
include "**/lifecycle-mapping-metadata.xml"
|
||||||
include "**/plugin-help.xml"
|
include "**/plugin-help.xml"
|
||||||
into processResources.destinationDir
|
into processResources.destinationDir
|
||||||
filter(ReplaceTokens, tokens: ['version' : project.version])
|
filter(ReplaceTokens, tokens: ['version' : project.version])
|
||||||
|
@ -30,6 +31,7 @@ dependencies {
|
||||||
compile( libraries.jpa ) { transitive = false }
|
compile( libraries.jpa ) { transitive = false }
|
||||||
compile( libraries.javassist ) { transitive = false }
|
compile( libraries.javassist ) { transitive = false }
|
||||||
compile 'org.codehaus.plexus:plexus-utils:3.0.1'
|
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_core )
|
||||||
runtime( libraries.maven_artifact )
|
runtime( libraries.maven_artifact )
|
||||||
runtime( libraries.maven_plugin )
|
runtime( libraries.maven_plugin )
|
||||||
|
|
|
@ -10,9 +10,9 @@ import java.io.File;
|
||||||
import java.io.FileFilter;
|
import java.io.FileFilter;
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
import java.io.FileNotFoundException;
|
import java.io.FileNotFoundException;
|
||||||
import java.io.FileOutputStream;
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
import java.io.OutputStream;
|
||||||
import java.net.MalformedURLException;
|
import java.net.MalformedURLException;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.net.URLClassLoader;
|
import java.net.URLClassLoader;
|
||||||
|
@ -29,6 +29,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.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;
|
||||||
import org.apache.maven.plugins.annotations.Mojo;
|
import org.apache.maven.plugins.annotations.Mojo;
|
||||||
|
@ -40,6 +41,8 @@ import org.hibernate.bytecode.enhance.spi.DefaultEnhancementContext;
|
||||||
import org.hibernate.bytecode.enhance.spi.EnhancementContext;
|
import org.hibernate.bytecode.enhance.spi.EnhancementContext;
|
||||||
import org.hibernate.bytecode.enhance.spi.Enhancer;
|
import org.hibernate.bytecode.enhance.spi.Enhancer;
|
||||||
|
|
||||||
|
import org.sonatype.plexus.build.incremental.BuildContext;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This plugin will enhance Entity objects.
|
* This plugin will enhance Entity objects.
|
||||||
*
|
*
|
||||||
|
@ -55,6 +58,9 @@ public class MavenEnhancePlugin extends AbstractMojo {
|
||||||
*/
|
*/
|
||||||
private List<File> sourceSet = new ArrayList<File>();
|
private List<File> sourceSet = new ArrayList<File>();
|
||||||
|
|
||||||
|
@Component
|
||||||
|
private BuildContext buildContext;
|
||||||
|
|
||||||
@Parameter(property = "dir", defaultValue = "${project.build.outputDirectory}")
|
@Parameter(property = "dir", defaultValue = "${project.build.outputDirectory}")
|
||||||
private String dir;
|
private String dir;
|
||||||
|
|
||||||
|
@ -143,16 +149,8 @@ public class MavenEnhancePlugin extends AbstractMojo {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( !enableLazyInitialization ) {
|
|
||||||
if ( !enhancementContext.isEntityClass( ctClass )
|
|
||||||
&& !enhancementContext.isCompositeClass( ctClass )
|
|
||||||
&& !enhancementContext.isMappedSuperclassClass( ctClass ) ) {
|
|
||||||
getLog().info( "Skipping class file [" + file.getAbsolutePath() + "], not an entity nor embeddable" );
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
final byte[] enhancedBytecode = doEnhancement( ctClass, enhancer );
|
byte[] enhancedBytecode = doEnhancement( file, ctClass, enhancer );
|
||||||
writeOutEnhancedClass( enhancedBytecode, ctClass, file );
|
writeOutEnhancedClass( enhancedBytecode, ctClass, file );
|
||||||
|
|
||||||
getLog().info( "Successfully enhanced class [" + ctClass.getName() + "]" );
|
getLog().info( "Successfully enhanced class [" + ctClass.getName() + "]" );
|
||||||
|
@ -176,13 +174,8 @@ public class MavenEnhancePlugin extends AbstractMojo {
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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 ) {
|
Set<Artifact> artifacts = project.getArtifacts();
|
||||||
// Prefer execution project when available (it includes transient dependencies)
|
|
||||||
MavenProject executionProject = project.getExecutionProject();
|
|
||||||
artifacts = ( executionProject != null ? executionProject.getArtifacts() : project.getArtifacts() );
|
|
||||||
}
|
|
||||||
if ( artifacts != null) {
|
if ( artifacts != null) {
|
||||||
for ( Artifact a : artifacts ) {
|
for ( Artifact a : artifacts ) {
|
||||||
if ( !Artifact.SCOPE_TEST.equals( a.getScope() ) ) {
|
if ( !Artifact.SCOPE_TEST.equals( a.getScope() ) ) {
|
||||||
|
@ -239,7 +232,7 @@ public class MavenEnhancePlugin extends AbstractMojo {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private byte[] doEnhancement(CtClass ctClass, Enhancer enhancer) throws MojoExecutionException {
|
private byte[] doEnhancement(File javaClassFile, CtClass ctClass, Enhancer enhancer) throws MojoExecutionException {
|
||||||
try {
|
try {
|
||||||
return enhancer.enhance( ctClass.getName(), ctClass.toBytecode() );
|
return enhancer.enhance( ctClass.getName(), ctClass.toBytecode() );
|
||||||
}
|
}
|
||||||
|
@ -248,7 +241,7 @@ public class MavenEnhancePlugin extends AbstractMojo {
|
||||||
if ( failOnError ) {
|
if ( failOnError ) {
|
||||||
throw new MojoExecutionException( msg, e );
|
throw new MojoExecutionException( msg, e );
|
||||||
}
|
}
|
||||||
getLog().warn( msg );
|
buildContext.addMessage( javaClassFile, 0, 0, msg, BuildContext.SEVERITY_WARNING, e );
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -290,45 +283,39 @@ public class MavenEnhancePlugin extends AbstractMojo {
|
||||||
try {
|
try {
|
||||||
if ( file.delete() ) {
|
if ( file.delete() ) {
|
||||||
if ( !file.createNewFile() ) {
|
if ( !file.createNewFile() ) {
|
||||||
getLog().error( "Unable to recreate class file [" + ctClass.getName() + "]" );
|
buildContext.addMessage( file, 0, 0, "Unable to recreate class file", BuildContext.SEVERITY_ERROR, null );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
getLog().error( "Unable to delete class file [" + ctClass.getName() + "]" );
|
buildContext.addMessage( file, 0, 0, "Unable to delete class file", BuildContext.SEVERITY_ERROR, null );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (IOException e) {
|
catch (IOException e) {
|
||||||
getLog().warn( "Problem preparing class file for writing out enhancements [" + ctClass.getName() + "]" );
|
buildContext.addMessage( file, 0, 0, "Problem preparing class file for writing out enhancements", BuildContext.SEVERITY_WARNING, e );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
OutputStream outputStream = null;
|
||||||
try {
|
try {
|
||||||
FileOutputStream outputStream = new FileOutputStream( file, false );
|
outputStream = buildContext.newFileOutputStream( file );
|
||||||
try {
|
|
||||||
outputStream.write( enhancedBytecode );
|
outputStream.write( enhancedBytecode );
|
||||||
outputStream.flush();
|
outputStream.flush();
|
||||||
}
|
}
|
||||||
catch (IOException e) {
|
catch (IOException e) {
|
||||||
String msg = String.format( "Error writing to enhanced class [%s] to file [%s]", ctClass.getName(), file.getAbsolutePath() );
|
String msg = String.format( "Error writing to enhanced class [%s] to file [%s]", file.getName(), file.getAbsolutePath() );
|
||||||
if ( failOnError ) {
|
if ( failOnError ) {
|
||||||
throw new MojoExecutionException( msg, e );
|
throw new MojoExecutionException( msg, e );
|
||||||
}
|
}
|
||||||
getLog().warn( msg );
|
buildContext.addMessage( file, 0, 0, msg, BuildContext.SEVERITY_WARNING, e );
|
||||||
}
|
}
|
||||||
finally {
|
finally {
|
||||||
try {
|
try {
|
||||||
|
if( outputStream != null ) {
|
||||||
outputStream.close();
|
outputStream.close();
|
||||||
ctClass.detach();
|
ctClass.detach();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
catch (IOException ignore) {
|
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 );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -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>
|
||||||
|
|
|
@ -24,6 +24,7 @@
|
||||||
<aggregator>false</aggregator>
|
<aggregator>false</aggregator>
|
||||||
<requiresOnline>false</requiresOnline>
|
<requiresOnline>false</requiresOnline>
|
||||||
<inheritedByDefault>true</inheritedByDefault>
|
<inheritedByDefault>true</inheritedByDefault>
|
||||||
|
<requiresDependencyResolution>compile+runtime</requiresDependencyResolution>
|
||||||
<phase>compile</phase>
|
<phase>compile</phase>
|
||||||
<executePhase>compile</executePhase>
|
<executePhase>compile</executePhase>
|
||||||
<executeGoal>enhance</executeGoal>
|
<executeGoal>enhance</executeGoal>
|
||||||
|
@ -84,6 +85,12 @@
|
||||||
<enableAssociationManagement>false</enableAssociationManagement>
|
<enableAssociationManagement>false</enableAssociationManagement>
|
||||||
<enableExtendedEnhancement>false</enableExtendedEnhancement>
|
<enableExtendedEnhancement>false</enableExtendedEnhancement>
|
||||||
</configuration>
|
</configuration>
|
||||||
|
<requirements>
|
||||||
|
<requirement>
|
||||||
|
<role>org.sonatype.plexus.build.incremental.BuildContext</role>
|
||||||
|
<field-name>buildContext</field-name>
|
||||||
|
</requirement>
|
||||||
|
</requirements>
|
||||||
</mojo>
|
</mojo>
|
||||||
</mojos>
|
</mojos>
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
@ -96,6 +103,12 @@
|
||||||
<type>jar</type>
|
<type>jar</type>
|
||||||
<version>3.0.1</version>
|
<version>3.0.1</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.codehaus.plexus</groupId>
|
||||||
|
<artifactId>plexus-build-api</artifactId>
|
||||||
|
<type>jar</type>
|
||||||
|
<version>0.0.7</version>
|
||||||
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.apache.maven.plugin-tools</groupId>
|
<groupId>org.apache.maven.plugin-tools</groupId>
|
||||||
<artifactId>maven-plugin-annotations</artifactId>
|
<artifactId>maven-plugin-annotations</artifactId>
|
||||||
|
|
Loading…
Reference in New Issue