HHH-8777 Completed implementation of Maven Enhance Plugin fixing issue

with
missing descriptor files. Mojo will automatically hook into build
lifecycle compile phase.

Conflicts:
	hibernate-enhance-maven-plugin/src/main/java/org/hibernate/bytecode/enhance/plugins/MavenEnhancePlugin.java
	settings.gradle
	tooling/hibernate-maven-plugin/hibernate-maven-plugin.gradle
This commit is contained in:
Jeremy Whiting 2013-12-19 15:09:40 +00:00 committed by Brett Meyer
parent 5a570ad072
commit 15acd847cf
8 changed files with 327 additions and 24 deletions

3
.gitignore vendored
View File

@ -40,3 +40,6 @@ ObjectStore
# Profiler and heap dumps
*.jps
*.hprof
# Maven Enhance Plugin
tooling/hibernate-enhance-maven-plugin/src/main/resources/pom.xml

View File

@ -21,8 +21,8 @@ project(':metamodel-generator').name = 'hibernate-jpamodelgen'
include 'hibernate-gradle-plugin'
project(':hibernate-gradle-plugin').projectDir = new File(rootProject.projectDir, "tooling/hibernate-gradle-plugin")
include 'hibernate-maven-plugin'
project(':hibernate-maven-plugin').projectDir = new File(rootProject.projectDir, "tooling/hibernate-maven-plugin")
include 'hibernate-enhance-maven-plugin'
project(':hibernate-enhance-maven-plugin').projectDir = new File(rootProject.projectDir, "tooling/hibernate-enhance-maven-plugin")
rootProject.children.each { project ->
project.buildFileName = "${project.name}.gradle"

View File

@ -0,0 +1,89 @@
apply plugin: 'java'
apply plugin: 'maven'
group = 'org.hibernate.orm.tooling'
repositories {
mavenCentral()
}
processResources.doLast {
project.build.outputDirectory = '${project.build.outputDirectory}'
copy {
from 'src/main/resources'
into processResources.destinationDir
expand ([ version: version, project: project, dir: '${dir}' ])
}
}
dependencies {
compile( libraries.maven_plugin ) {
transitive = false
}
compile( libraries.maven_plugin_tools ) {
transitive = false
}
compile( project(':hibernate-core') ) {
transitive = false
}
compile( libraries.jpa ){
transitive = false
}
compile( libraries.javassist ){
transitive = false
}
compile 'org.codehaus.plexus:plexus-utils:3.0.1'
runtime( libraries.maven_plugin ) {
}
runtime( libraries.maven_plugin_tools ) {
}
runtime( project(':hibernate-core') ) {
}
runtime( libraries.jpa ){
}
runtime( libraries.javassist ){
}
runtime 'org.codehaus.plexus:plexus-utils:3.0.1'
}
// avoiding test dependencies in generated pom
configurations.remove(configurations.getByName('testCompile'))
configurations.remove(configurations.getByName('testRuntime'))
task writeNewPom(type:Task, description: 'Writes pom.xml using merged Gradle dependency and MavenPom configuration.') {
ext.pomDefinition = pom {
project {
groupId project.group
packaging 'maven-plugin'
name 'Enhance Plugin of the Hibernate project for use with Maven build system.'
build {
plugins {
plugin {
groupId 'org.apache.maven.plugins'
artifactId 'maven-plugin-plugin'
version '3.2'
configuration {
skipErrorNoDescriptorsFound 'true'
}
executions {
execution {
id 'mojo-descriptor'
goals {
goal 'descriptor'
}
}
}
}
}
}
properties {
'project.build.sourceEncoding' 'UTF-8'
}
}
}
ext.pomDefinition.writeTo("$projectDir/src/main/resources/pom.xml")
}
processResources.dependsOn writeNewPom

View File

@ -31,6 +31,11 @@ import java.io.FileOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import javassist.ClassPool;
import javassist.CtClass;
import javassist.CtField;
import javax.persistence.ElementCollection;
import javax.persistence.Embeddable;
import javax.persistence.Entity;
@ -38,16 +43,13 @@ import javax.persistence.ManyToMany;
import javax.persistence.OneToMany;
import javax.persistence.Transient;
import javassist.ClassPool;
import javassist.CtClass;
import javassist.CtField;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.plugins.annotations.Execute;
import org.apache.maven.plugins.annotations.LifecyclePhase;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;
import org.hibernate.bytecode.enhance.spi.EnhancementContext;
import org.hibernate.bytecode.enhance.spi.Enhancer;
@ -55,9 +57,11 @@ import org.hibernate.bytecode.enhance.spi.Enhancer;
* This plugin will enhance Entity objects.
*
* @author Jeremy Whiting
* @phase "compile"
*/
@Mojo(name = "enhance")
public class HibernateEnhancementMojo extends AbstractMojo implements EnhancementContext {
@Mojo ( name="enhance", defaultPhase = LifecyclePhase.COMPILE )
@Execute ( goal ="enhance" , phase = LifecyclePhase.COMPILE )
public class MavenEnhancePlugin extends AbstractMojo implements EnhancementContext {
/**
* The contexts to use during enhancement.
@ -69,7 +73,7 @@ public class HibernateEnhancementMojo extends AbstractMojo implements Enhancemen
private static final String CLASS_EXTENSION = ".class";
@Parameter(property="dir", defaultValue="${project.build.outputDirectory}")
private String dir;
private String dir = null;
public void execute() throws MojoExecutionException, MojoFailureException {
getLog().info( "Started enhance plugin....." );
@ -142,6 +146,7 @@ public class HibernateEnhancementMojo extends AbstractMojo implements Enhancemen
private void processEntityClassFile(File javaClassFile, CtClass ctClass ) {
try {
getLog().info( String.format("Processing Entity class file [%1$s].", ctClass.getName()) );
byte[] result = enhancer.enhance( ctClass.getName(), ctClass.toBytecode() );
if(result != null)
writeEnhancedClass(javaClassFile, result);
@ -154,6 +159,7 @@ public class HibernateEnhancementMojo extends AbstractMojo implements Enhancemen
private void processCompositeClassFile(File javaClassFile, CtClass ctClass) {
try {
getLog().info( String.format("Processing Composite class file [%1$s].", ctClass.getName()) );
byte[] result = enhancer.enhanceComposite(ctClass.getName(), ctClass.toBytecode());
if(result != null)
writeEnhancedClass(javaClassFile, result);

View File

@ -0,0 +1,44 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated by maven-plugin-tools 3.2 on 2013-12-19 -->
<plugin>
<name>Enhance Plugin of the Hibernate project for use with Maven build system.</name>
<description></description>
<groupId>org.hibernate.orm.tooling</groupId>
<artifactId>hibernate-enhance-maven-plugin</artifactId>
<version>${version}</version>
<goalPrefix>hibernate-enhance</goalPrefix>
<mojos>
<mojo>
<goal>enhance</goal>
<description>This plugin will enhance Entity objects.</description>
<requiresDirectInvocation>false</requiresDirectInvocation>
<requiresProject>true</requiresProject>
<requiresReports>false</requiresReports>
<aggregator>false</aggregator>
<requiresOnline>false</requiresOnline>
<inheritedByDefault>true</inheritedByDefault>
<phase>compile</phase>
<executePhase>compile</executePhase>
<executeGoal>enhance</executeGoal>
<implementation>org.hibernate.bytecode.enhance.plugins.MavenEnhancePlugin</implementation>
<language>java</language>
<instantiationStrategy>per-lookup</instantiationStrategy>
<executionStrategy>once-per-session</executionStrategy>
<threadSafe>false</threadSafe>
<parameters>
<parameter>
<name>dir</name>
<type>java.lang.String</type>
<required>false</required>
<editable>true</editable>
<description></description>
</parameter>
</parameters>
<configuration>
<dir implementation="java.lang.String" default-value="${project.build.outputDirectory}">${dir}</dir>
</configuration>
</mojo>
</mojos>
</plugin>

View File

@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated by maven-plugin-tools 3.1 on 2013-12-19 -->
<plugin>
<name>Enhance Plugin of the Hibernate project for use with Maven build system.</name>
<description></description>
<groupId>org.hibernate.orm.tooling</groupId>
<artifactId>hibernate-enhance-maven-plugin</artifactId>
<version>${version}</version>
<goalPrefix>hibernate-enhance</goalPrefix>
<mojos/>
</plugin>

View File

@ -0,0 +1,162 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated by maven-plugin-tools 3.2 on 2013-12-19 -->
<plugin>
<name>Enhance Plugin of the Hibernate project for use with Maven build system.</name>
<description></description>
<groupId>org.hibernate.orm.tooling</groupId>
<artifactId>hibernate-enhance-maven-plugin</artifactId>
<version>${version}</version>
<goalPrefix>hibernate-enhance</goalPrefix>
<isolatedRealm>false</isolatedRealm>
<inheritedByDefault>true</inheritedByDefault>
<mojos>
<mojo>
<goal>enhance</goal>
<description>This plugin will enhance Entity objects.</description>
<requiresDirectInvocation>false</requiresDirectInvocation>
<requiresProject>true</requiresProject>
<requiresReports>false</requiresReports>
<aggregator>false</aggregator>
<requiresOnline>false</requiresOnline>
<inheritedByDefault>true</inheritedByDefault>
<phase>compile</phase>
<executePhase>compile</executePhase>
<executeGoal>enhance</executeGoal>
<implementation>org.hibernate.bytecode.enhance.plugins.MavenEnhancePlugin</implementation>
<language>java</language>
<instantiationStrategy>per-lookup</instantiationStrategy>
<executionStrategy>once-per-session</executionStrategy>
<threadSafe>false</threadSafe>
<parameters>
<parameter>
<name>dir</name>
<type>java.lang.String</type>
<required>false</required>
<editable>true</editable>
<description></description>
</parameter>
</parameters>
<configuration>
<dir implementation="java.lang.String" default-value="${project.build.outputDirectory}">${dir}</dir>
</configuration>
</mojo>
</mojos>
<dependencies>
<dependency>
<groupId>org.jboss.logging</groupId>
<artifactId>jboss-logging</artifactId>
<type>jar</type>
<version>3.1.0.GA</version>
</dependency>
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-utils</artifactId>
<type>jar</type>
<version>3.0.1</version>
</dependency>
<dependency>
<groupId>org.apache.maven.plugin-tools</groupId>
<artifactId>maven-plugin-annotations</artifactId>
<type>jar</type>
<version>3.2</version>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-artifact</artifactId>
<type>jar</type>
<version>3.0</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<type>jar</type>
<version>4.2.8.Final</version>
</dependency>
<dependency>
<groupId>antlr</groupId>
<artifactId>antlr</artifactId>
<type>jar</type>
<version>2.7.7</version>
</dependency>
<dependency>
<groupId>dom4j</groupId>
<artifactId>dom4j</artifactId>
<type>jar</type>
<version>1.6.1</version>
</dependency>
<dependency>
<groupId>org.jboss.spec.javax.transaction</groupId>
<artifactId>jboss-transaction-api_1.1_spec</artifactId>
<type>jar</type>
<version>1.0.1.Final</version>
</dependency>
<dependency>
<groupId>org.hibernate.common</groupId>
<artifactId>hibernate-commons-annotations</artifactId>
<type>jar</type>
<version>4.0.2.Final</version>
</dependency>
<dependency>
<groupId>org.hibernate.javax.persistence</groupId>
<artifactId>hibernate-jpa-2.0-api</artifactId>
<type>jar</type>
<version>1.0.1.Final</version>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-plugin-api</artifactId>
<type>jar</type>
<version>3.0.5</version>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-model</artifactId>
<type>jar</type>
<version>3.0.5</version>
</dependency>
<dependency>
<groupId>org.sonatype.sisu</groupId>
<artifactId>sisu-inject-plexus</artifactId>
<type>jar</type>
<version>2.3.0</version>
</dependency>
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-component-annotations</artifactId>
<type>jar</type>
<version>1.5.5</version>
</dependency>
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-classworlds</artifactId>
<type>jar</type>
<version>2.4</version>
</dependency>
<dependency>
<groupId>org.sonatype.sisu</groupId>
<artifactId>sisu-inject-bean</artifactId>
<type>jar</type>
<version>2.3.0</version>
</dependency>
<dependency>
<groupId>org.sonatype.sisu</groupId>
<artifactId>sisu-guice</artifactId>
<type>jar</type>
<version>3.1.0</version>
</dependency>
<dependency>
<groupId>org.sonatype.sisu</groupId>
<artifactId>sisu-guava</artifactId>
<type>jar</type>
<version>0.9.9</version>
</dependency>
<dependency>
<groupId>org.javassist</groupId>
<artifactId>javassist</artifactId>
<type>jar</type>
<version>3.18.1-GA</version>
</dependency>
</dependencies>
</plugin>

View File

@ -1,14 +0,0 @@
apply plugin: 'java'
apply plugin: 'maven'
repositories {
mavenCentral()
}
dependencies {
compile( libraries.maven_plugin )
compile( libraries.maven_plugin_tools )
compile( project(':hibernate-core') )
compile( libraries.jpa )
compile( libraries.javassist )
}