From 85792026ae4a95a31fd546bf61ff5704f44c7d8b Mon Sep 17 00:00:00 2001 From: Jeremy Whiting Date: Thu, 19 Dec 2013 15:09:40 +0000 Subject: [PATCH] HHH-8777 Completed implementation of Maven Enhance Plugin fixing issue with missing descriptor files. Mojo will automatically hook into build lifecycle compile phase. --- .gitignore | 3 + .../enhance-maven-plugin.gradle | 14 -- .../hibernate-enhance-maven-plugin.gradle | 89 ++++++++++ .../enhance/plugins/MavenEnhancePlugin.java | 8 +- .../plugin-help.xml | 44 +++++ .../org.hibernate.orm.tooling/plugin-help.xml | 13 ++ .../main/resources/META-INF/maven/plugin.xml | 162 ++++++++++++++++++ settings.gradle | 2 +- 8 files changed, 319 insertions(+), 16 deletions(-) delete mode 100644 enhance-maven-plugin/enhance-maven-plugin.gradle create mode 100644 hibernate-enhance-maven-plugin/hibernate-enhance-maven-plugin.gradle rename {enhance-maven-plugin => hibernate-enhance-maven-plugin}/src/main/java/org/hibernate/bytecode/enhance/plugins/MavenEnhancePlugin.java (94%) create mode 100644 hibernate-enhance-maven-plugin/src/main/resources/META-INF/maven/org.hibernate.orm.tooling/hibernate-enhance-maven-plugin/plugin-help.xml create mode 100644 hibernate-enhance-maven-plugin/src/main/resources/META-INF/maven/org.hibernate.orm.tooling/plugin-help.xml create mode 100644 hibernate-enhance-maven-plugin/src/main/resources/META-INF/maven/plugin.xml diff --git a/.gitignore b/.gitignore index 164c5fcfab..eea1679a2f 100644 --- a/.gitignore +++ b/.gitignore @@ -39,3 +39,6 @@ ObjectStore # Profiler and heap dumps *.jps *.hprof + +# Maven Enhance Plugin +hibernate-enhance-maven-plugin/src/main/resources/pom.xml diff --git a/enhance-maven-plugin/enhance-maven-plugin.gradle b/enhance-maven-plugin/enhance-maven-plugin.gradle deleted file mode 100644 index 0dbbc2742c..0000000000 --- a/enhance-maven-plugin/enhance-maven-plugin.gradle +++ /dev/null @@ -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 ) -} diff --git a/hibernate-enhance-maven-plugin/hibernate-enhance-maven-plugin.gradle b/hibernate-enhance-maven-plugin/hibernate-enhance-maven-plugin.gradle new file mode 100644 index 0000000000..0b6966a4cc --- /dev/null +++ b/hibernate-enhance-maven-plugin/hibernate-enhance-maven-plugin.gradle @@ -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 + diff --git a/enhance-maven-plugin/src/main/java/org/hibernate/bytecode/enhance/plugins/MavenEnhancePlugin.java b/hibernate-enhance-maven-plugin/src/main/java/org/hibernate/bytecode/enhance/plugins/MavenEnhancePlugin.java similarity index 94% rename from enhance-maven-plugin/src/main/java/org/hibernate/bytecode/enhance/plugins/MavenEnhancePlugin.java rename to hibernate-enhance-maven-plugin/src/main/java/org/hibernate/bytecode/enhance/plugins/MavenEnhancePlugin.java index 130320f3d6..ae72e39422 100644 --- a/enhance-maven-plugin/src/main/java/org/hibernate/bytecode/enhance/plugins/MavenEnhancePlugin.java +++ b/hibernate-enhance-maven-plugin/src/main/java/org/hibernate/bytecode/enhance/plugins/MavenEnhancePlugin.java @@ -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); diff --git a/hibernate-enhance-maven-plugin/src/main/resources/META-INF/maven/org.hibernate.orm.tooling/hibernate-enhance-maven-plugin/plugin-help.xml b/hibernate-enhance-maven-plugin/src/main/resources/META-INF/maven/org.hibernate.orm.tooling/hibernate-enhance-maven-plugin/plugin-help.xml new file mode 100644 index 0000000000..d9e84b3cea --- /dev/null +++ b/hibernate-enhance-maven-plugin/src/main/resources/META-INF/maven/org.hibernate.orm.tooling/hibernate-enhance-maven-plugin/plugin-help.xml @@ -0,0 +1,44 @@ + + + + + + Enhance Plugin of the Hibernate project for use with Maven build system. + + org.hibernate.orm.tooling + hibernate-enhance-maven-plugin + ${version} + hibernate-enhance + + + enhance + This plugin will enhance Entity objects. + false + true + false + false + false + true + compile + compile + enhance + org.hibernate.bytecode.enhance.plugins.MavenEnhancePlugin + java + per-lookup + once-per-session + false + + + dir + java.lang.String + false + true + + + + + ${dir} + + + + \ No newline at end of file diff --git a/hibernate-enhance-maven-plugin/src/main/resources/META-INF/maven/org.hibernate.orm.tooling/plugin-help.xml b/hibernate-enhance-maven-plugin/src/main/resources/META-INF/maven/org.hibernate.orm.tooling/plugin-help.xml new file mode 100644 index 0000000000..00fc267a80 --- /dev/null +++ b/hibernate-enhance-maven-plugin/src/main/resources/META-INF/maven/org.hibernate.orm.tooling/plugin-help.xml @@ -0,0 +1,13 @@ + + + + + + Enhance Plugin of the Hibernate project for use with Maven build system. + + org.hibernate.orm.tooling + hibernate-enhance-maven-plugin + ${version} + hibernate-enhance + + \ No newline at end of file diff --git a/hibernate-enhance-maven-plugin/src/main/resources/META-INF/maven/plugin.xml b/hibernate-enhance-maven-plugin/src/main/resources/META-INF/maven/plugin.xml new file mode 100644 index 0000000000..ea4d1d4096 --- /dev/null +++ b/hibernate-enhance-maven-plugin/src/main/resources/META-INF/maven/plugin.xml @@ -0,0 +1,162 @@ + + + + + + Enhance Plugin of the Hibernate project for use with Maven build system. + + org.hibernate.orm.tooling + hibernate-enhance-maven-plugin + ${version} + hibernate-enhance + false + true + + + enhance + This plugin will enhance Entity objects. + false + true + false + false + false + true + compile + compile + enhance + org.hibernate.bytecode.enhance.plugins.MavenEnhancePlugin + java + per-lookup + once-per-session + false + + + dir + java.lang.String + false + true + + + + + ${dir} + + + + + + org.jboss.logging + jboss-logging + jar + 3.1.0.GA + + + org.codehaus.plexus + plexus-utils + jar + 3.0.1 + + + org.apache.maven.plugin-tools + maven-plugin-annotations + jar + 3.2 + + + org.apache.maven + maven-artifact + jar + 3.0 + + + org.hibernate + hibernate-core + jar + 4.2.8.Final + + + antlr + antlr + jar + 2.7.7 + + + dom4j + dom4j + jar + 1.6.1 + + + org.jboss.spec.javax.transaction + jboss-transaction-api_1.1_spec + jar + 1.0.1.Final + + + org.hibernate.common + hibernate-commons-annotations + jar + 4.0.2.Final + + + org.hibernate.javax.persistence + hibernate-jpa-2.0-api + jar + 1.0.1.Final + + + org.apache.maven + maven-plugin-api + jar + 3.0.5 + + + org.apache.maven + maven-model + jar + 3.0.5 + + + org.sonatype.sisu + sisu-inject-plexus + jar + 2.3.0 + + + org.codehaus.plexus + plexus-component-annotations + jar + 1.5.5 + + + org.codehaus.plexus + plexus-classworlds + jar + 2.4 + + + org.sonatype.sisu + sisu-inject-bean + jar + 2.3.0 + + + org.sonatype.sisu + sisu-guice + jar + 3.1.0 + + + org.sonatype.sisu + sisu-guava + jar + 0.9.9 + + + org.javassist + javassist + jar + 3.18.1-GA + + + \ No newline at end of file diff --git a/settings.gradle b/settings.gradle index f09b30a853..d887694b24 100644 --- a/settings.gradle +++ b/settings.gradle @@ -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'