HHH-8777 Completed implementation of Maven Enhance Plugin fixing issue with

missing descriptor files. Mojo will automatically hook into build
lifecycle compile phase.
This commit is contained in:
Jeremy Whiting 2013-12-19 15:09:40 +00:00 committed by Brett Meyer
parent 1dcdc445b4
commit 85792026ae
8 changed files with 319 additions and 16 deletions

3
.gitignore vendored
View File

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

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 )
}

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

@ -46,6 +46,8 @@ import javax.persistence.Transient;
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;
@ -55,8 +57,10 @@ import org.hibernate.bytecode.enhance.spi.Enhancer;
* This plugin will enhance Entity objects.
*
* @author Jeremy Whiting
* @phase "compile"
*/
@Mojo(name = "enhance")
@Mojo ( name="enhance", defaultPhase = LifecyclePhase.COMPILE )
@Execute ( goal ="enhance" , phase = LifecyclePhase.COMPILE )
public class MavenEnhancePlugin extends AbstractMojo implements EnhancementContext {
/**
@ -142,6 +146,7 @@ public class MavenEnhancePlugin extends AbstractMojo implements EnhancementConte
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 MavenEnhancePlugin extends AbstractMojo implements EnhancementConte
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

@ -11,7 +11,7 @@ include 'hibernate-proxool'
include 'hibernate-ehcache'
include 'hibernate-infinispan'
include 'hibernate-gradle-plugin'
include 'enhance-maven-plugin'
include 'hibernate-enhance-maven-plugin'
include 'documentation'
include 'release'