From dd8e186416e77d6d1ed09e585eeeccbc4bc0cb38 Mon Sep 17 00:00:00 2001 From: Steve Ebersole Date: Thu, 17 Oct 2024 09:22:37 -0500 Subject: [PATCH] HHH-18644 - New and improved hibernate-maven-plugin --- documentation/documentation.gradle | 2 +- gradle/published-java-module.gradle | 66 --- gradle/relocated-published-java-module.gradle | 73 ++++ hibernate-agroal/hibernate-agroal.gradle | 2 +- hibernate-c3p0/hibernate-c3p0.gradle | 2 +- .../hibernate-community-dialects.gradle | 2 +- hibernate-core/hibernate-core.gradle | 2 +- hibernate-envers/hibernate-envers.gradle | 2 +- hibernate-graalvm/hibernate-graalvm.gradle | 2 +- hibernate-hikaricp/hibernate-hikaricp.gradle | 2 +- hibernate-jcache/hibernate-jcache.gradle | 2 +- hibernate-jfr/hibernate-jfr.gradle | 2 +- .../hibernate-micrometer.gradle | 2 +- hibernate-platform/hibernate-platform.gradle | 2 +- hibernate-proxool/hibernate-proxool.gradle | 2 +- hibernate-spatial/hibernate-spatial.gradle | 2 +- hibernate-testing/hibernate-testing.gradle | 2 +- hibernate-ucp/hibernate-ucp.gradle | 2 +- hibernate-vector/hibernate-vector.gradle | 2 +- hibernate-vibur/hibernate-vibur.gradle | 2 +- local-build-plugins/build.gradle | 9 + .../maven/embedder/MavenEmbedderConfig.java | 29 ++ .../maven/embedder/MavenEmbedderPlugin.java | 71 ++++ .../maven/embedder/MavenEmbedderService.java | 51 +++ .../embedder/MavenPluginDescriptorTask.java | 36 ++ settings.gradle | 4 +- tooling/hibernate-ant/hibernate-ant.gradle | 2 +- .../hibernate-enhance-maven-plugin.gradle | 113 ------ .../orm/tooling/maven/MavenEnhancePlugin.java | 377 ------------------ .../m2e/lifecycle-mapping-metadata.xml | 18 - .../plugin-help.xml | 102 ----- .../org.hibernate.orm.tooling/plugin-help.xml | 16 - .../main/resources/META-INF/maven/plugin.xml | 186 --------- .../orm/tooling/maven/ChildEntity.java | 14 - .../tooling/maven/MavenEnhancePluginTest.java | 78 ---- .../orm/tooling/maven/ParentEntity.java | 14 - .../orm/tooling/maven/TestEntity.java | 18 - .../hibernate-maven-plugin.gradle | 19 + .../hibernate-processor.gradle | 2 +- 39 files changed, 310 insertions(+), 1024 deletions(-) create mode 100644 gradle/relocated-published-java-module.gradle create mode 100644 local-build-plugins/src/main/java/org/hibernate/build/maven/embedder/MavenEmbedderConfig.java create mode 100644 local-build-plugins/src/main/java/org/hibernate/build/maven/embedder/MavenEmbedderPlugin.java create mode 100644 local-build-plugins/src/main/java/org/hibernate/build/maven/embedder/MavenEmbedderService.java create mode 100644 local-build-plugins/src/main/java/org/hibernate/build/maven/embedder/MavenPluginDescriptorTask.java delete mode 100644 tooling/hibernate-enhance-maven-plugin/hibernate-enhance-maven-plugin.gradle delete mode 100644 tooling/hibernate-enhance-maven-plugin/src/main/java/org/hibernate/orm/tooling/maven/MavenEnhancePlugin.java delete mode 100644 tooling/hibernate-enhance-maven-plugin/src/main/resources/META-INF/m2e/lifecycle-mapping-metadata.xml delete mode 100644 tooling/hibernate-enhance-maven-plugin/src/main/resources/META-INF/maven/org.hibernate.orm.tooling/hibernate-enhance-maven-plugin/plugin-help.xml delete mode 100644 tooling/hibernate-enhance-maven-plugin/src/main/resources/META-INF/maven/org.hibernate.orm.tooling/plugin-help.xml delete mode 100644 tooling/hibernate-enhance-maven-plugin/src/main/resources/META-INF/maven/plugin.xml delete mode 100644 tooling/hibernate-enhance-maven-plugin/src/test/java/org/hibernate/orm/tooling/maven/ChildEntity.java delete mode 100644 tooling/hibernate-enhance-maven-plugin/src/test/java/org/hibernate/orm/tooling/maven/MavenEnhancePluginTest.java delete mode 100644 tooling/hibernate-enhance-maven-plugin/src/test/java/org/hibernate/orm/tooling/maven/ParentEntity.java delete mode 100644 tooling/hibernate-enhance-maven-plugin/src/test/java/org/hibernate/orm/tooling/maven/TestEntity.java create mode 100644 tooling/hibernate-maven-plugin/hibernate-maven-plugin.gradle diff --git a/documentation/documentation.gradle b/documentation/documentation.gradle index ab3342725d..678e848e38 100644 --- a/documentation/documentation.gradle +++ b/documentation/documentation.gradle @@ -137,7 +137,7 @@ dependencies { reportAggregation project(':hibernate-spatial') reportAggregation project(':hibernate-vibur') reportAggregation project(':hibernate-ant') - reportAggregation project(':hibernate-enhance-maven-plugin') + reportAggregation project(':hibernate-maven-plugin') reportAggregation project(':hibernate-processor') asciidoctorGems 'rubygems:rouge:4.1.1' diff --git a/gradle/published-java-module.gradle b/gradle/published-java-module.gradle index b9ea71617b..be7d9a1568 100644 --- a/gradle/published-java-module.gradle +++ b/gradle/published-java-module.gradle @@ -33,71 +33,6 @@ java { withSourcesJar() } -publishing { - publications { - // main publication - publishedArtifacts { - from components.java - } - - // relocation for the published artifacts based on the old groupId - relocationPom( MavenPublication ) { - pom { - name = project.name + ' - relocation' - groupId = 'org.hibernate' - artifactId = project.name - version = project.version - - description = project.description - url = 'https://hibernate.org/orm' - - organization { - name = 'Hibernate.org' - url = 'https://hibernate.org' - } - - licenses { - license { - name = 'GNU Library General Public License v2.1 or later' - url = 'https://www.opensource.org/licenses/LGPL-2.1' - comments = 'See discussion at https://hibernate.org/community/license/ for more details.' - distribution = 'repo' - } - } - - scm { - url = 'https://github.com/hibernate/hibernate-orm' - connection = 'scm:git:https://github.com/hibernate/hibernate-orm.git' - developerConnection = 'scm:git:git@github.com:hibernate/hibernate-orm.git' - } - - developers { - developer { - id = 'hibernate-team' - name = 'The Hibernate Development Team' - organization = 'Hibernate.org' - organizationUrl = 'https://hibernate.org' - } - } - - issueManagement { - system = 'jira' - url = 'https://hibernate.atlassian.net/browse/HHH' - } - - distributionManagement { - relocation { - groupId = 'org.hibernate.orm' - artifactId = project.name - version = project.version - } - } - } - } - } -} - - var signingKey = resolveSigningKey() var signingPassword = findSigningProperty( "signingPassword" ) @@ -237,7 +172,6 @@ tasks.release.dependsOn tasks.test, tasks.publishToSonatype tasks.preVerifyRelease.dependsOn build tasks.preVerifyRelease.dependsOn generateMetadataFileForPublishedArtifactsPublication tasks.preVerifyRelease.dependsOn generatePomFileForPublishedArtifactsPublication -tasks.preVerifyRelease.dependsOn generatePomFileForRelocationPomPublication tasks.publishToSonatype.mustRunAfter test diff --git a/gradle/relocated-published-java-module.gradle b/gradle/relocated-published-java-module.gradle new file mode 100644 index 0000000000..8aeee228a4 --- /dev/null +++ b/gradle/relocated-published-java-module.gradle @@ -0,0 +1,73 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +apply from: rootProject.file( 'gradle/published-java-module.gradle' ) + +publishing { + publications { + // main publication + publishedArtifacts { + from components.java + } + + // relocation for the published artifacts based on the old groupId + relocationPom( MavenPublication ) { + pom { + name = project.name + ' - relocation' + groupId = 'org.hibernate' + artifactId = project.name + version = project.version + + description = project.description + url = 'https://hibernate.org/orm' + + organization { + name = 'Hibernate.org' + url = 'https://hibernate.org' + } + + licenses { + license { + name = 'GNU Library General Public License v2.1 or later' + url = 'https://www.opensource.org/licenses/LGPL-2.1' + comments = 'See discussion at https://hibernate.org/community/license/ for more details.' + distribution = 'repo' + } + } + + scm { + url = 'https://github.com/hibernate/hibernate-orm' + connection = 'scm:git:https://github.com/hibernate/hibernate-orm.git' + developerConnection = 'scm:git:git@github.com:hibernate/hibernate-orm.git' + } + + developers { + developer { + id = 'hibernate-team' + name = 'The Hibernate Development Team' + organization = 'Hibernate.org' + organizationUrl = 'https://hibernate.org' + } + } + + issueManagement { + system = 'jira' + url = 'https://hibernate.atlassian.net/browse/HHH' + } + + distributionManagement { + relocation { + groupId = 'org.hibernate.orm' + artifactId = project.name + version = project.version + } + } + } + } + } +} + +tasks.preVerifyRelease.dependsOn generatePomFileForRelocationPomPublication \ No newline at end of file diff --git a/hibernate-agroal/hibernate-agroal.gradle b/hibernate-agroal/hibernate-agroal.gradle index 54ae8107de..f5534b84e4 100644 --- a/hibernate-agroal/hibernate-agroal.gradle +++ b/hibernate-agroal/hibernate-agroal.gradle @@ -7,7 +7,7 @@ description = 'Integration for Agroal as a ConnectionProvider for Hibernate ORM' -apply from: rootProject.file( 'gradle/published-java-module.gradle' ) +apply from: rootProject.file( 'gradle/relocated-published-java-module.gradle' ) dependencies { implementation project( ':hibernate-core' ) diff --git a/hibernate-c3p0/hibernate-c3p0.gradle b/hibernate-c3p0/hibernate-c3p0.gradle index b5bce3e188..1ee183146a 100644 --- a/hibernate-c3p0/hibernate-c3p0.gradle +++ b/hibernate-c3p0/hibernate-c3p0.gradle @@ -7,7 +7,7 @@ description = 'Integration for c3p0 Connection pooling into Hibernate ORM' -apply from: rootProject.file( 'gradle/published-java-module.gradle' ) +apply from: rootProject.file( 'gradle/relocated-published-java-module.gradle' ) dependencies { implementation project( ':hibernate-core' ) diff --git a/hibernate-community-dialects/hibernate-community-dialects.gradle b/hibernate-community-dialects/hibernate-community-dialects.gradle index aa5b903582..df3ca41efd 100644 --- a/hibernate-community-dialects/hibernate-community-dialects.gradle +++ b/hibernate-community-dialects/hibernate-community-dialects.gradle @@ -7,7 +7,7 @@ description = 'Hibernate\'s community supported dialects' -apply from: rootProject.file( 'gradle/published-java-module.gradle' ) +apply from: rootProject.file( 'gradle/relocated-published-java-module.gradle' ) dependencies { api project( ':hibernate-core' ) diff --git a/hibernate-core/hibernate-core.gradle b/hibernate-core/hibernate-core.gradle index d3b1634a21..62b237fcec 100644 --- a/hibernate-core/hibernate-core.gradle +++ b/hibernate-core/hibernate-core.gradle @@ -12,7 +12,7 @@ plugins { description = 'Hibernate\'s core ORM functionality' -apply from: rootProject.file( 'gradle/published-java-module.gradle' ) +apply from: rootProject.file( 'gradle/relocated-published-java-module.gradle' ) apply plugin: 'org.hibernate.orm.antlr' apply plugin: 'org.hibernate.matrix-test' diff --git a/hibernate-envers/hibernate-envers.gradle b/hibernate-envers/hibernate-envers.gradle index a6371f84e0..a358ad371f 100644 --- a/hibernate-envers/hibernate-envers.gradle +++ b/hibernate-envers/hibernate-envers.gradle @@ -7,7 +7,7 @@ description = 'Hibernate\'s entity version (audit/history) support' -apply from: rootProject.file( 'gradle/published-java-module.gradle' ) +apply from: rootProject.file( 'gradle/relocated-published-java-module.gradle' ) apply plugin: 'org.hibernate.matrix-test' dependencies { diff --git a/hibernate-graalvm/hibernate-graalvm.gradle b/hibernate-graalvm/hibernate-graalvm.gradle index de9def0022..4d6e82e75f 100644 --- a/hibernate-graalvm/hibernate-graalvm.gradle +++ b/hibernate-graalvm/hibernate-graalvm.gradle @@ -7,7 +7,7 @@ description = "Experimental extension to make it easier to compile applications into a GraalVM native image" -apply from: rootProject.file( 'gradle/published-java-module.gradle' ) +apply from: rootProject.file( 'gradle/relocated-published-java-module.gradle' ) dependencies { //No need for transitive dependencies: this is all just metadata to be used as companion jar. diff --git a/hibernate-hikaricp/hibernate-hikaricp.gradle b/hibernate-hikaricp/hibernate-hikaricp.gradle index 0729d5cf88..f1078a3de5 100644 --- a/hibernate-hikaricp/hibernate-hikaricp.gradle +++ b/hibernate-hikaricp/hibernate-hikaricp.gradle @@ -7,7 +7,7 @@ description = 'Integration for HikariCP into Hibernate O/RM' -apply from: rootProject.file( 'gradle/published-java-module.gradle' ) +apply from: rootProject.file( 'gradle/relocated-published-java-module.gradle' ) dependencies { implementation project( ':hibernate-core' ) diff --git a/hibernate-jcache/hibernate-jcache.gradle b/hibernate-jcache/hibernate-jcache.gradle index 1aa17a8ac2..aa205c868f 100644 --- a/hibernate-jcache/hibernate-jcache.gradle +++ b/hibernate-jcache/hibernate-jcache.gradle @@ -1,6 +1,6 @@ description = 'Integration for javax.cache into Hibernate as a second-level caching service' -apply from: rootProject.file( 'gradle/published-java-module.gradle' ) +apply from: rootProject.file( 'gradle/relocated-published-java-module.gradle' ) dependencies { api project( ':hibernate-core' ) diff --git a/hibernate-jfr/hibernate-jfr.gradle b/hibernate-jfr/hibernate-jfr.gradle index b3c47e306b..560d5de739 100644 --- a/hibernate-jfr/hibernate-jfr.gradle +++ b/hibernate-jfr/hibernate-jfr.gradle @@ -7,7 +7,7 @@ description = 'Integration for JDK JFR into Hibernate O/RM' -apply from: rootProject.file( 'gradle/published-java-module.gradle' ) +apply from: rootProject.file( 'gradle/relocated-published-java-module.gradle' ) dependencies { implementation project( ':hibernate-core' ) diff --git a/hibernate-micrometer/hibernate-micrometer.gradle b/hibernate-micrometer/hibernate-micrometer.gradle index e4730808fa..16e5c0f7a5 100644 --- a/hibernate-micrometer/hibernate-micrometer.gradle +++ b/hibernate-micrometer/hibernate-micrometer.gradle @@ -1,6 +1,6 @@ description = 'Integration for Micrometer metrics into Hibernate as a metrics collection package' -apply from: rootProject.file( 'gradle/published-java-module.gradle' ) +apply from: rootProject.file( 'gradle/relocated-published-java-module.gradle' ) dependencies { implementation project( ':hibernate-core' ) diff --git a/hibernate-platform/hibernate-platform.gradle b/hibernate-platform/hibernate-platform.gradle index 036b36d879..a4b633c17c 100644 --- a/hibernate-platform/hibernate-platform.gradle +++ b/hibernate-platform/hibernate-platform.gradle @@ -32,7 +32,7 @@ dependencies { api project( ":hibernate-processor" ) api project( ":hibernate-gradle-plugin" ) - api project( ":hibernate-enhance-maven-plugin" ) + api project( ":hibernate-maven-plugin" ) api project( ":hibernate-ant" ) api libs.hibernateModels diff --git a/hibernate-proxool/hibernate-proxool.gradle b/hibernate-proxool/hibernate-proxool.gradle index 679c5340dc..3c9463ab71 100644 --- a/hibernate-proxool/hibernate-proxool.gradle +++ b/hibernate-proxool/hibernate-proxool.gradle @@ -7,7 +7,7 @@ description = 'Integration for Proxool Connection pooling into Hibernate O/RM' -apply from: rootProject.file( 'gradle/published-java-module.gradle' ) +apply from: rootProject.file( 'gradle/relocated-published-java-module.gradle' ) dependencies { diff --git a/hibernate-spatial/hibernate-spatial.gradle b/hibernate-spatial/hibernate-spatial.gradle index f178213093..671ff80641 100644 --- a/hibernate-spatial/hibernate-spatial.gradle +++ b/hibernate-spatial/hibernate-spatial.gradle @@ -7,7 +7,7 @@ description = 'Integrate support for Spatial/GIS data into Hibernate O/RM' -apply from: rootProject.file( 'gradle/published-java-module.gradle' ) +apply from: rootProject.file( 'gradle/relocated-published-java-module.gradle' ) apply plugin: 'org.hibernate.matrix-test' diff --git a/hibernate-testing/hibernate-testing.gradle b/hibernate-testing/hibernate-testing.gradle index ed0bf21cd5..68d556ff9a 100644 --- a/hibernate-testing/hibernate-testing.gradle +++ b/hibernate-testing/hibernate-testing.gradle @@ -7,7 +7,7 @@ description = 'Support for testing Hibernate ORM functionality' -apply from: rootProject.file( 'gradle/published-java-module.gradle' ) +apply from: rootProject.file( 'gradle/relocated-published-java-module.gradle' ) dependencies { api project( ':hibernate-core' ) diff --git a/hibernate-ucp/hibernate-ucp.gradle b/hibernate-ucp/hibernate-ucp.gradle index 1f99ed287d..7c5843e6ba 100644 --- a/hibernate-ucp/hibernate-ucp.gradle +++ b/hibernate-ucp/hibernate-ucp.gradle @@ -7,7 +7,7 @@ description = 'Integration for Oracle UCP into Hibernate O/RM' -apply from: rootProject.file( 'gradle/published-java-module.gradle' ) +apply from: rootProject.file( 'gradle/relocated-published-java-module.gradle' ) dependencies { implementation project( ':hibernate-core' ) diff --git a/hibernate-vector/hibernate-vector.gradle b/hibernate-vector/hibernate-vector.gradle index f0277a6bde..ece85d16d1 100644 --- a/hibernate-vector/hibernate-vector.gradle +++ b/hibernate-vector/hibernate-vector.gradle @@ -7,7 +7,7 @@ description = 'Hibernate\'s extensions for vector support' -apply from: rootProject.file( 'gradle/published-java-module.gradle' ) +apply from: rootProject.file( 'gradle/relocated-published-java-module.gradle' ) dependencies { api project( ':hibernate-core' ) diff --git a/hibernate-vibur/hibernate-vibur.gradle b/hibernate-vibur/hibernate-vibur.gradle index 1702a15b44..0eaf50e210 100644 --- a/hibernate-vibur/hibernate-vibur.gradle +++ b/hibernate-vibur/hibernate-vibur.gradle @@ -7,7 +7,7 @@ description = 'Integration for Vibur Connection pooling as a Hibernate ORM ConnectionProvider' -apply from: rootProject.file( 'gradle/published-java-module.gradle' ) +apply from: rootProject.file( 'gradle/relocated-published-java-module.gradle' ) dependencies { implementation project( ':hibernate-core' ) diff --git a/local-build-plugins/build.gradle b/local-build-plugins/build.gradle index 1419125bfb..c5f42d6716 100644 --- a/local-build-plugins/build.gradle +++ b/local-build-plugins/build.gradle @@ -22,6 +22,11 @@ dependencies { implementation 'jakarta.json:jakarta.json-api:2.0.1' implementation 'org.eclipse:yasson:2.0.4' implementation 'org.jsoup:jsoup:1.15.3' + + implementation "org.apache.maven:maven-embedder:3.9.9" + implementation "org.apache.maven:maven-compat:3.9.9" + implementation "org.apache.maven.resolver:maven-resolver-connector-basic:1.9.18" + implementation "org.apache.maven.resolver:maven-resolver-transport-http:1.9.18" } tasks.compileJava { @@ -80,6 +85,10 @@ gradlePlugin { id = 'org.hibernate.orm.build.java-module' implementationClass = 'org.hibernate.orm.toolchains.JavaModulePlugin' } + register( "mavenEmbedder" ) { + id = "org.hibernate.build.maven-embedder" + implementationClass = "org.hibernate.build.maven.embedder.MavenEmbedderPlugin" + } } } diff --git a/local-build-plugins/src/main/java/org/hibernate/build/maven/embedder/MavenEmbedderConfig.java b/local-build-plugins/src/main/java/org/hibernate/build/maven/embedder/MavenEmbedderConfig.java new file mode 100644 index 0000000000..2faf5320b7 --- /dev/null +++ b/local-build-plugins/src/main/java/org/hibernate/build/maven/embedder/MavenEmbedderConfig.java @@ -0,0 +1,29 @@ +package org.hibernate.build.maven.embedder; + +import org.gradle.api.Project; +import org.gradle.api.file.DirectoryProperty; + +import javax.inject.Inject; + +/** + * Gradle DSL extension for configuring the {@linkplain MavenEmbedderPlugin maven-embedder plugin} + * + * @author Steve Ebersole + */ +public class MavenEmbedderConfig { + private DirectoryProperty localRepositoryDirectory; + + @Inject + public MavenEmbedderConfig(Project project) { + localRepositoryDirectory = project.getObjects().directoryProperty(); + localRepositoryDirectory.convention( project.getLayout().getBuildDirectory().dir( "maven-embedder/maven-local" ) ); + } + + public DirectoryProperty getLocalRepositoryDirectory() { + return localRepositoryDirectory; + } + + public void setLocalRepositoryDirectory(DirectoryProperty localRepositoryDirectory) { + this.localRepositoryDirectory = localRepositoryDirectory; + } +} diff --git a/local-build-plugins/src/main/java/org/hibernate/build/maven/embedder/MavenEmbedderPlugin.java b/local-build-plugins/src/main/java/org/hibernate/build/maven/embedder/MavenEmbedderPlugin.java new file mode 100644 index 0000000000..9aa4867c1a --- /dev/null +++ b/local-build-plugins/src/main/java/org/hibernate/build/maven/embedder/MavenEmbedderPlugin.java @@ -0,0 +1,71 @@ +package org.hibernate.build.maven.embedder; + +import org.gradle.api.Plugin; +import org.gradle.api.Project; +import org.gradle.api.file.Directory; +import org.gradle.api.provider.Provider; +import org.gradle.api.services.BuildServiceRegistry; +import org.gradle.api.tasks.SourceSet; +import org.gradle.api.tasks.SourceSetContainer; +import org.gradle.api.tasks.TaskProvider; + +/** + * Plugin for integrating Maven Embedder into the Gradle build to execute + * some Maven tasks/goals/mojos. + * + * @author Steve Ebersole + */ +public class MavenEmbedderPlugin implements Plugin { + @Override + public void apply(Project project) { + // be sure to mirror the output dirs + project.getLayout().getBuildDirectory().set( project.getLayout().getProjectDirectory().dir( "target" ) ); + + final BuildServiceRegistry sharedServices = project.getGradle().getSharedServices(); + + // add a DSL extension for configuration + final MavenEmbedderConfig dsl = project.getExtensions().create( + "mavenEmbedder", + MavenEmbedderConfig.class + ); + + // add the MavenEmbedderService shared-build-service + final Provider embedderServiceProvider = sharedServices.registerIfAbsent( + "maven-embedder", + MavenEmbedderService.class, (spec) -> { + spec.getParameters().getProjectVersion().set( project.getVersion().toString() ); + spec.getParameters().getWorkingDirectory().set( project.getLayout().getProjectDirectory() ); + spec.getParameters().getMavenLocalDirectory().set( dsl.getLocalRepositoryDirectory() ); + } + ); + + // Via the plugin's POM, we tell Maven to generate the descriptors into + // `target/generated/sources/plugin-descriptors/META-INF/maven`. + // `META-INF/maven` is the relative path we need inside the jar, so we + // configure the "resource directory" in Gradle to be just the + // `target/generated/sources/plugin-descriptors` part. + final Provider descriptorsDir = project.getLayout().getBuildDirectory().dir( "generated/sources/plugin-descriptors" ); + + // create the "mirror" task which calls the appropriate Maven tasks/goals/mojos behind the scenes using the embedder service + final TaskProvider generatePluginDescriptorTask = project.getTasks().register( "generatePluginDescriptor", MavenPluginDescriptorTask.class, (task) -> { + task.setGroup( "maven embedder" ); + + task.getMavenEmbedderService().set( embedderServiceProvider ); + task.usesService( embedderServiceProvider ); + + // deal with the "descriptor directory" - + // 1. we need this on the Gradle side for up-to-date checking, etc + task.getDescriptorDirectory().set( descriptorsDir ); + // 2. add the resource dir to the main source-set's resources so that it is picked up for jar + final SourceSetContainer sourceSets = project.getExtensions().getByType( SourceSetContainer.class ); + final SourceSet mainSourceSet = sourceSets.getByName( "main" ); + mainSourceSet.getResources().srcDir( task.getDescriptorDirectory() ); + + // we need compilation to happen before we generate the descriptors + task.dependsOn( "compileJava" ); + } ); + + // we need the descriptor generation to happen before we jar + project.getTasks().named( "jar", (jarTask) -> jarTask.dependsOn( generatePluginDescriptorTask ) ); + } +} diff --git a/local-build-plugins/src/main/java/org/hibernate/build/maven/embedder/MavenEmbedderService.java b/local-build-plugins/src/main/java/org/hibernate/build/maven/embedder/MavenEmbedderService.java new file mode 100644 index 0000000000..6309c07909 --- /dev/null +++ b/local-build-plugins/src/main/java/org/hibernate/build/maven/embedder/MavenEmbedderService.java @@ -0,0 +1,51 @@ +package org.hibernate.build.maven.embedder; + +import org.apache.maven.cli.MavenCli; +import org.gradle.api.file.Directory; +import org.gradle.api.file.DirectoryProperty; +import org.gradle.api.provider.Property; +import org.gradle.api.services.BuildService; +import org.gradle.api.services.BuildServiceParameters; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +/** + * Wrapper around the Maven Embedder as a Gradle build-service + * + * @author Steve Ebersole + */ +public abstract class MavenEmbedderService implements BuildService { + interface Config extends BuildServiceParameters { + Property getProjectVersion(); + DirectoryProperty getWorkingDirectory(); + DirectoryProperty getMavenLocalDirectory(); + } + + private final MavenCli embedder; + + public MavenEmbedderService() { + // this needs to be set for some reason. + // NOTE : even though it is named "multi module", here we are only interested in the specific project + System.setProperty( "maven.multiModuleProjectDirectory", getParameters().getWorkingDirectory().toString() ); + embedder = new MavenCli(); + } + + public void execute(String... tasksAndArgs) { + final List cml = new ArrayList<>(); + Collections.addAll( cml, tasksAndArgs ); + + final Directory mavenLocalDirectory = getParameters().getMavenLocalDirectory().get(); + cml.add( "-Dmaven.repo.local=\"" + mavenLocalDirectory.getAsFile().getAbsolutePath() + "\"" ); + cml.add( "-Dorm.project.version=" + getParameters().getProjectVersion().get() ); + + final Directory workingDirectory = getParameters().getWorkingDirectory().get(); + final String workingDirectoryPath = workingDirectory.getAsFile().getAbsolutePath(); + + // todo : consider bridging Maven out/err to Gradle logging + + final int resultCode = embedder.doMain( cml.toArray(new String[0]), workingDirectoryPath, System.out, System.err ); + // todo : do something with result-code + } +} diff --git a/local-build-plugins/src/main/java/org/hibernate/build/maven/embedder/MavenPluginDescriptorTask.java b/local-build-plugins/src/main/java/org/hibernate/build/maven/embedder/MavenPluginDescriptorTask.java new file mode 100644 index 0000000000..8a873934ca --- /dev/null +++ b/local-build-plugins/src/main/java/org/hibernate/build/maven/embedder/MavenPluginDescriptorTask.java @@ -0,0 +1,36 @@ +package org.hibernate.build.maven.embedder; + +import org.gradle.api.DefaultTask; +import org.gradle.api.file.DirectoryProperty; +import org.gradle.api.provider.Property; +import org.gradle.api.services.ServiceReference; +import org.gradle.api.tasks.OutputDirectory; +import org.gradle.api.tasks.TaskAction; + +/** + * Task which "mirrors" the Maven task/goal/mojo for generating + * plugin descriptors. + * + * @author Steve Ebersole + */ +public abstract class MavenPluginDescriptorTask extends DefaultTask { + // This property provides access to the service instance + @ServiceReference + abstract Property getMavenEmbedderService(); + + @OutputDirectory + abstract DirectoryProperty getDescriptorDirectory(); + + public MavenPluginDescriptorTask() { + // todo : what else is the descriptor/pom dependent upon? + getInputs().property( "project-version", getProject().getVersion() ); + } + + @TaskAction + public void generateDescriptor() { + getMavenEmbedderService().get().execute( "plugin:descriptor" ); + // todo : anything else? e.g. + //getMavenEmbedderService().get().execute( "plugin:addPluginArtifactMetadata" ); + //getMavenEmbedderService().get().execute( "plugin:helpmojo" ); + } +} diff --git a/settings.gradle b/settings.gradle index 13b6b6b11f..d81c0372fc 100644 --- a/settings.gradle +++ b/settings.gradle @@ -354,8 +354,8 @@ project(':metamodel-generator').name = 'hibernate-processor' include 'hibernate-gradle-plugin' project(':hibernate-gradle-plugin').projectDir = new File(rootProject.projectDir, "tooling/hibernate-gradle-plugin") -include 'hibernate-enhance-maven-plugin' -project(':hibernate-enhance-maven-plugin').projectDir = new File(rootProject.projectDir, "tooling/hibernate-enhance-maven-plugin") +include 'hibernate-maven-plugin' +project(':hibernate-maven-plugin').projectDir = new File(rootProject.projectDir, "tooling/hibernate-maven-plugin") include 'hibernate-ant' project(':hibernate-ant').projectDir = new File(rootProject.projectDir, "tooling/hibernate-ant") diff --git a/tooling/hibernate-ant/hibernate-ant.gradle b/tooling/hibernate-ant/hibernate-ant.gradle index 279cbae869..20b9895ddb 100644 --- a/tooling/hibernate-ant/hibernate-ant.gradle +++ b/tooling/hibernate-ant/hibernate-ant.gradle @@ -1,7 +1,7 @@ description = 'Annotation Processor to generate JPA 2 static metamodel classes' -apply from: rootProject.file( 'gradle/published-java-module.gradle' ) +apply from: rootProject.file( 'gradle/relocated-published-java-module.gradle' ) apply plugin: 'org.hibernate.build.version-injection' dependencies { diff --git a/tooling/hibernate-enhance-maven-plugin/hibernate-enhance-maven-plugin.gradle b/tooling/hibernate-enhance-maven-plugin/hibernate-enhance-maven-plugin.gradle deleted file mode 100644 index 373691241d..0000000000 --- a/tooling/hibernate-enhance-maven-plugin/hibernate-enhance-maven-plugin.gradle +++ /dev/null @@ -1,113 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * License: GNU Lesser General Public License (LGPL), version 2.1 or later. - * See the lgpl.txt file in the root directory or . - */ -description = 'Enhance Plugin of the Hibernate project for use with Maven build system.' - -apply from: rootProject.file( 'gradle/published-java-module.gradle' ) -apply plugin: 'maven-publish' - - -import org.apache.tools.ant.filters.ReplaceTokens -group = 'org.hibernate.orm.tooling' - -processResources { - include "**/lifecycle-mapping-metadata.xml" - include "**/plugin-help.xml" - into processResources.destinationDir - filter(ReplaceTokens, tokens: ['version' : project.version]) -} - -dependencies { - implementation( project(':hibernate-core') ) { transitive = false } - implementation( jakartaLibs.jpa ) { transitive = false } - implementation( jakartaLibs.jta ) { transitive = false } - implementation libs.byteBuddy - - implementation( mavenLibs.mavenCore ) { transitive = false } - implementation( mavenLibs.mavenArtifact ) { transitive = false } - implementation( mavenLibs.mavenPlugin ) { transitive = false } - implementation( mavenLibs.mavenPluginTools ) { transitive = false } - - implementation 'org.codehaus.plexus:plexus-utils:3.0.24' - implementation 'org.sonatype.plexus:plexus-build-api:0.0.7' - - runtimeOnly mavenLibs.mavenCore - runtimeOnly mavenLibs.mavenArtifact - runtimeOnly mavenLibs.mavenPlugin - runtimeOnly mavenLibs.mavenPluginTools -} - -// Inject dependencies into plugin.xml -// Note: injecting the full dependency, rather than just the version, -// removing the need to maintain artifact names that might change with upgrades (JPA/JTA API version, etc.) -task processPluginXml(type: Copy) { - // force out-of-date if version changes - inputs.property("version", project.version) - - from "src/main/resources/META-INF/maven/plugin.xml" - into "$processResources.destinationDir/META-INF/maven" - filter(ReplaceTokens, tokens: ['version' : project.version, 'generated-dependencies' :\ - generateMavenDependency(jakartaLibs.jpa)\ - + generateMavenDependency(libs.antlr)\ - + generateMavenDependency(jakartaLibs.jta)\ - + generateMavenDependency(libs.hibernateModels)\ - + generateMavenDependency(libs.jandex)\ - + generateMavenDependency(libs.byteBuddy)\ - + generateMavenDependency(libs.logging)\ - + generateMavenDependency("org.hibernate:hibernate-core:" + project.version)]) -} - -// TODO: There may be a way to do this directly with Gradle's Maven plugin, but it's still incubating -// and I'd rather not rely on it yet. -def generateMavenDependency(String gradleDependency) { - String[] split = gradleDependency.split(":") - return "\n"\ - + "\n " + split[0] + ""\ - + "\n " + split[1] + ""\ - + "\n " + split[2] + ""\ - + "\n jar"\ - + "\n" -} - -def generateMavenDependency(Provider gradleDependencyProvider) { - String[] split = gradleDependencyProvider.get().toString().split(":") - return "\n"\ - + "\n " + split[0] + ""\ - + "\n " + split[1] + ""\ - + "\n " + split[2] + ""\ - + "\n jar"\ - + "\n" -} - -// Writes pom.xml using merged Gradle dependency and MavenPom configuration. -tasks.named('generatePomFileForPublishedArtifactsPublication') { - pom.with { - packaging 'maven-plugin' - name.set('Hibernate Enhance Maven Plugin') - description 'Enhance Plugin of the Hibernate project for use with Maven build system.' - properties.put( - 'project.build.sourceEncoding', 'UTF-8' - ) - // HHH-9679 --- build in pom{} conflicts with FactoryBuilderSupport#build so we write that portion of XML by hand - withXml { - asNode().appendNode('build').appendNode('plugins').appendNode('plugin').with { - appendNode('groupId', 'org.apache.maven.plugins') - appendNode('artifactId', 'maven-plugin-plugin') - appendNode('version', '3.2') - appendNode('configuration').appendNode('skipErrorNoDescriptorsFound', 'true') - appendNode('executions').appendNode('execution').with { - appendNode('id', 'mojo-descriptor') - appendNode('goals').appendNode('goal', 'descriptor') - } - } - } - } -} - -processResources.dependsOn processPluginXml -// We need this filter here, otherwise Gradle or the JUnit Jupiter platform will load classes at a point -// when they are not yet enhanced, leading to test failures -test.include '**/*Test.class' diff --git a/tooling/hibernate-enhance-maven-plugin/src/main/java/org/hibernate/orm/tooling/maven/MavenEnhancePlugin.java b/tooling/hibernate-enhance-maven-plugin/src/main/java/org/hibernate/orm/tooling/maven/MavenEnhancePlugin.java deleted file mode 100644 index 04c26425cf..0000000000 --- a/tooling/hibernate-enhance-maven-plugin/src/main/java/org/hibernate/orm/tooling/maven/MavenEnhancePlugin.java +++ /dev/null @@ -1,377 +0,0 @@ -/* - * SPDX-License-Identifier: LGPL-2.1-or-later - * Copyright Red Hat Inc. and Hibernate Authors - */ -package org.hibernate.orm.tooling.maven; - -import java.io.ByteArrayOutputStream; -import java.io.File; -import java.io.FileFilter; -import java.io.FileInputStream; -import java.io.IOException; -import java.io.OutputStream; -import java.net.MalformedURLException; -import java.net.URL; -import java.net.URLClassLoader; -import java.nio.file.Path; -import java.util.*; - -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.plugin.logging.Log; -import org.apache.maven.plugins.annotations.Component; -import org.apache.maven.plugins.annotations.LifecyclePhase; -import org.apache.maven.plugins.annotations.Mojo; -import org.apache.maven.plugins.annotations.Parameter; -import org.apache.maven.plugins.annotations.ResolutionScope; -import org.apache.maven.project.MavenProject; - -import org.hibernate.bytecode.enhance.spi.DefaultEnhancementContext; -import org.hibernate.bytecode.enhance.spi.EnhancementContext; -import org.hibernate.bytecode.enhance.spi.Enhancer; -import org.hibernate.bytecode.enhance.spi.UnloadedClass; -import org.hibernate.bytecode.enhance.spi.UnloadedField; -import org.hibernate.bytecode.spi.BytecodeProvider; - -import org.sonatype.plexus.build.incremental.BuildContext; - -import static org.hibernate.bytecode.internal.BytecodeProviderInitiator.buildDefaultBytecodeProvider; - -/** - * This plugin will enhance Entity objects. - * - * @author Jeremy Whiting - * @author Luis Barreiro - */ -@Mojo(name = "enhance", defaultPhase = LifecyclePhase.COMPILE, requiresDependencyResolution = ResolutionScope.COMPILE_PLUS_RUNTIME) -public class MavenEnhancePlugin extends AbstractMojo { - - /** - * The contexts to use during enhancement. - */ - private List sourceSet = new ArrayList(); - - @Component - private BuildContext buildContext; - - @Parameter(property = "base", defaultValue = "${project.build.outputDirectory}") - private String base; - - @Parameter(property = "dir", defaultValue = "${project.build.outputDirectory}") - private String dir; - - @Parameter(property = "classNames", defaultValue = "") - private String classNames; - - @Parameter(property = "failOnError", defaultValue = "true") - private boolean failOnError = true; - - @Parameter(property = "enableLazyInitialization", defaultValue = "true") - private boolean enableLazyInitialization; - - @Parameter(property = "enableDirtyTracking", defaultValue = "true") - private boolean enableDirtyTracking; - - @Parameter(property = "enableAssociationManagement", defaultValue = "false") - private boolean enableAssociationManagement; - - @Parameter(property = "enableExtendedEnhancement", defaultValue = "false") - private boolean enableExtendedEnhancement; - - private boolean shouldApply() { - return enableLazyInitialization || enableDirtyTracking || enableAssociationManagement || enableExtendedEnhancement; - } - - @Override - public void execute() throws MojoExecutionException, MojoFailureException { - final Log log = getLog(); - if ( !shouldApply() ) { - log.warn( "Skipping Hibernate bytecode enhancement plugin execution since no feature is enabled" ); - return; - } - - if ( !dir.startsWith( base ) ) { - throw new MojoExecutionException( "The enhancement directory 'dir' (" + dir + ") is no subdirectory of 'base' (" + base + ")" ); - } - - // Perform a depth first search for sourceSet - File root = new File( this.dir ); - if ( !root.exists() ) { - log.info( "Skipping Hibernate enhancement plugin execution since there is no classes dir " + dir ); - return; - } - walkDir( root ); - if ( sourceSet.isEmpty() ) { - log.info( "Skipping Hibernate enhancement plugin execution since there are no classes to enhance on " + dir ); - return; - } - - List classesToEnhance = new ArrayList<>(); - if(classNames != null && classNames.length() >= 1) { - classesToEnhance = Arrays.asList(classNames.split(",")); - } - - log.info( "Starting Hibernate enhancement for classes on " + dir ); - final ClassLoader classLoader = toClassLoader( Collections.singletonList( new File( base ) ) ); - - EnhancementContext enhancementContext = new DefaultEnhancementContext() { - @Override - public ClassLoader getLoadingClassLoader() { - return classLoader; - } - - @Override - public boolean doBiDirectionalAssociationManagement(UnloadedField field) { - return enableAssociationManagement; - } - - @Override - public boolean doDirtyCheckingInline(UnloadedClass classDescriptor) { - return enableDirtyTracking; - } - - @Override - public boolean hasLazyLoadableAttributes(UnloadedClass classDescriptor) { - return enableLazyInitialization; - } - - @Override - public boolean isLazyLoadable(UnloadedField field) { - return enableLazyInitialization; - } - - @Override - public boolean doExtendedEnhancement(UnloadedClass classDescriptor) { - return enableExtendedEnhancement; - } - }; - - if ( !enableLazyInitialization ) { - log.warn( "The 'enableLazyInitialization' configuration is deprecated and will be removed. Set the value to 'true' to get rid of this warning" ); - } - if ( !enableDirtyTracking ) { - log.warn( "The 'enableDirtyTracking' configuration is deprecated and will be removed. Set the value to 'true' to get rid of this warning" ); - } - if ( enableExtendedEnhancement ) { - log.warn( "Extended enhancement is enabled. Classes other than entities may be modified. You should consider access the entities using getter/setter methods and disable this property. Use at your own risk." ); - } - - //TODO allow the Maven plugin to configure the bytecode enhancer? - final BytecodeProvider bytecodeProvider = buildDefaultBytecodeProvider(); - try { - final Enhancer enhancer = bytecodeProvider.getEnhancer( enhancementContext ); - - for ( File file : sourceSet ) { - discoverTypes( file, enhancer ); - if ( log.isDebugEnabled() ) { - log.debug( "Successfully discovered types for class [" + file + "]" ); - } - } - for ( File file : sourceSet ) { - - String className = determineClassName(root, file); - - if(! (classesToEnhance.size()==0 || classesToEnhance.contains(className))) { - continue; - } - - final byte[] enhancedBytecode = doEnhancement( file, enhancer ); - - if ( enhancedBytecode == null ) { - continue; - } - - writeOutEnhancedClass( enhancedBytecode, file ); - if ( log.isDebugEnabled() ) { - log.debug( "Successfully enhanced class [" + file + "]" ); - } - } - } - finally { - bytecodeProvider.resetCaches(); - } - } - - private ClassLoader toClassLoader(List runtimeClasspath) throws MojoExecutionException { - List urls = new ArrayList( runtimeClasspath.size() ); - final Log log = getLog(); - for ( File file : runtimeClasspath ) { - try { - urls.add( file.toURI().toURL() ); - if ( log.isDebugEnabled() ) { - log.debug( "Adding classpath entry for classes root " + file.getAbsolutePath() ); - } - } - catch (MalformedURLException e) { - String msg = "Unable to resolve classpath entry to URL: " + file.getAbsolutePath(); - if ( failOnError ) { - throw new MojoExecutionException( msg, e ); - } - log.warn( msg ); - } - } - - // HHH-10145 Add dependencies to classpath as well - all but the ones used for testing purposes - MavenProject project = ( (MavenProject) getPluginContext().get( "project" ) ); - Set artifacts = project.getArtifacts(); - if ( artifacts != null) { - for ( Artifact a : artifacts ) { - if ( !Artifact.SCOPE_TEST.equals( a.getScope() ) ) { - try { - urls.add( a.getFile().toURI().toURL() ); - log.debug( "Adding classpath entry for dependency " + a.getId() ); - } - catch (MalformedURLException e) { - String msg = "Unable to resolve URL for dependency " + a.getId() + " at " + a.getFile().getAbsolutePath(); - if ( failOnError ) { - throw new MojoExecutionException( msg, e ); - } - log.warn( msg ); - } - } - } - } - - return new URLClassLoader( urls.toArray( new URL[urls.size()] ), Enhancer.class.getClassLoader() ); - } - - private byte[] doEnhancement(File javaClassFile, Enhancer enhancer) throws MojoExecutionException { - try { - String className = javaClassFile.getAbsolutePath().substring( - base.length() + 1, - javaClassFile.getAbsolutePath().length() - ".class".length() - ).replace( File.separatorChar, '.' ); - ByteArrayOutputStream originalBytes = new ByteArrayOutputStream(); - FileInputStream fileInputStream = new FileInputStream( javaClassFile ); - try { - byte[] buffer = new byte[1024]; - int length; - while ( ( length = fileInputStream.read( buffer ) ) != -1 ) { - originalBytes.write( buffer, 0, length ); - } - } - finally { - fileInputStream.close(); - } - return enhancer.enhance( className, originalBytes.toByteArray() ); - } - catch (Exception e) { - String msg = "Unable to enhance class: " + javaClassFile.getName(); - if ( failOnError ) { - throw new MojoExecutionException( msg, e ); - } - buildContext.addMessage( javaClassFile, 0, 0, msg, BuildContext.SEVERITY_WARNING, e ); - return null; - } - } - - private void discoverTypes(File javaClassFile, Enhancer enhancer) throws MojoExecutionException { - try { - String className = javaClassFile.getAbsolutePath().substring( - base.length() + 1, - javaClassFile.getAbsolutePath().length() - ".class".length() - ).replace( File.separatorChar, '.' ); - ByteArrayOutputStream originalBytes = new ByteArrayOutputStream(); - FileInputStream fileInputStream = new FileInputStream( javaClassFile ); - try { - byte[] buffer = new byte[1024]; - int length; - while ( ( length = fileInputStream.read( buffer ) ) != -1 ) { - originalBytes.write( buffer, 0, length ); - } - } - finally { - fileInputStream.close(); - } - enhancer.discoverTypes( className, originalBytes.toByteArray() ); - } - catch (Exception e) { - String msg = "Unable to discover types for class: " + javaClassFile.getName(); - if ( failOnError ) { - throw new MojoExecutionException( msg, e ); - } - buildContext.addMessage( javaClassFile, 0, 0, msg, BuildContext.SEVERITY_WARNING, e ); - } - } - - /** - * Expects a directory. - */ - private void walkDir(File dir) { - walkDir( - dir, - new FileFilter() { - @Override - public boolean accept(File pathname) { - return ( pathname.isFile() && pathname.getName().endsWith( ".class" ) ); - } - }, - new FileFilter() { - @Override - public boolean accept(File pathname) { - return ( pathname.isDirectory() ); - } - } - ); - } - - private void walkDir(File dir, FileFilter classesFilter, FileFilter dirFilter) { - File[] dirs = dir.listFiles( dirFilter ); - for ( File dir1 : dirs ) { - walkDir( dir1, classesFilter, dirFilter ); - } - File[] files = dir.listFiles( classesFilter ); - Collections.addAll( this.sourceSet, files ); - } - - private void writeOutEnhancedClass(byte[] enhancedBytecode, File file) throws MojoExecutionException { - try { - if ( file.delete() ) { - if ( !file.createNewFile() ) { - buildContext.addMessage( file, 0, 0, "Unable to recreate class file", BuildContext.SEVERITY_ERROR, null ); - } - } - else { - buildContext.addMessage( file, 0, 0, "Unable to delete class file", BuildContext.SEVERITY_ERROR, null ); - } - } - catch (IOException e) { - buildContext.addMessage( file, 0, 0, "Problem preparing class file for writing out enhancements", BuildContext.SEVERITY_WARNING, e ); - } - - OutputStream outputStream = null; - try { - outputStream = buildContext.newFileOutputStream( file ); - outputStream.write( enhancedBytecode ); - outputStream.flush(); - } - catch (IOException e) { - String msg = String.format( "Error writing to enhanced class [%s] to file [%s]", file.getName(), file.getAbsolutePath() ); - if ( failOnError ) { - throw new MojoExecutionException( msg, e ); - } - buildContext.addMessage( file, 0, 0, msg, BuildContext.SEVERITY_WARNING, e ); - } - finally { - try { - if ( outputStream != null ) { - outputStream.close(); - } - } - catch (IOException ignore) { - } - } - } - - private String determineClassName(File root, File javaClassFile) { - final Path relativeClassPath = root.toPath().relativize( javaClassFile.toPath() ); - final String relativeClassPathString = relativeClassPath.toString(); - final String classNameBase = relativeClassPathString.substring( - 0, - relativeClassPathString.length() - ".class".length() - ); - return classNameBase.replace( File.separatorChar, '.' ); - } -} diff --git a/tooling/hibernate-enhance-maven-plugin/src/main/resources/META-INF/m2e/lifecycle-mapping-metadata.xml b/tooling/hibernate-enhance-maven-plugin/src/main/resources/META-INF/m2e/lifecycle-mapping-metadata.xml deleted file mode 100644 index 7ae74429fc..0000000000 --- a/tooling/hibernate-enhance-maven-plugin/src/main/resources/META-INF/m2e/lifecycle-mapping-metadata.xml +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - enhance - - - - - true - false - - - - - - diff --git a/tooling/hibernate-enhance-maven-plugin/src/main/resources/META-INF/maven/org.hibernate.orm.tooling/hibernate-enhance-maven-plugin/plugin-help.xml b/tooling/hibernate-enhance-maven-plugin/src/main/resources/META-INF/maven/org.hibernate.orm.tooling/hibernate-enhance-maven-plugin/plugin-help.xml deleted file mode 100644 index 8f31bbbc14..0000000000 --- a/tooling/hibernate-enhance-maven-plugin/src/main/resources/META-INF/maven/org.hibernate.orm.tooling/hibernate-enhance-maven-plugin/plugin-help.xml +++ /dev/null @@ -1,102 +0,0 @@ - - - - Hibernate Enhance Maven Plugin - 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.orm.tooling.maven.MavenEnhancePlugin - java - per-lookup - once-per-session - false - - - base - java.lang.String - false - true - The root folder for .class files - - - dir - java.lang.String - false - true - Base directory where to search for .class files - - - classNames - java.lang.String - false - true - Comma separated string of class names for which enhancement needs to be done - - - failOnError - java.lang.Boolean - false - true - Indicates whether the build will continue even if there are enhancement errors - - - enableLazyInitialization - java.lang.Boolean - false - true - DEPRECATED: Enable enhancement for lazy loading of attributes. This setting is deprecated for removal without a replacement. - - - enableDirtyTracking - java.lang.Boolean - false - true - DEPRECATED: Enable enhancement for tracking of dirty attributes. This setting is deprecated for removal without a replacement. - - - enableAssociationManagement - java.lang.Boolean - false - true - Enable enhancement for management of bi-direction associations - - - enableExtendedEnhancement - java.lang.Boolean - false - true - Enable enhancement of field access - - - - ${project.build.outputDirectory} - ${project.build.outputDirectory} - true - true - true - false - false - - - - \ No newline at end of file diff --git a/tooling/hibernate-enhance-maven-plugin/src/main/resources/META-INF/maven/org.hibernate.orm.tooling/plugin-help.xml b/tooling/hibernate-enhance-maven-plugin/src/main/resources/META-INF/maven/org.hibernate.orm.tooling/plugin-help.xml deleted file mode 100644 index 9d37cb7d78..0000000000 --- a/tooling/hibernate-enhance-maven-plugin/src/main/resources/META-INF/maven/org.hibernate.orm.tooling/plugin-help.xml +++ /dev/null @@ -1,16 +0,0 @@ - - - - Hibernate Enhance Maven Plugin - 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/tooling/hibernate-enhance-maven-plugin/src/main/resources/META-INF/maven/plugin.xml b/tooling/hibernate-enhance-maven-plugin/src/main/resources/META-INF/maven/plugin.xml deleted file mode 100644 index 7a4fc7869f..0000000000 --- a/tooling/hibernate-enhance-maven-plugin/src/main/resources/META-INF/maven/plugin.xml +++ /dev/null @@ -1,186 +0,0 @@ - - - - Hibernate Enhance Maven Plugin - 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+runtime - compile - org.hibernate.orm.tooling.maven.MavenEnhancePlugin - java - per-lookup - once-per-session - false - - - base - java.lang.String - false - true - The root folder for .class files - - - dir - java.lang.String - false - true - Base directory where to search for .class files - - - classNames - java.lang.String - false - true - Comma separated string of class names for which enhancement needs to be done - - - failOnError - java.lang.Boolean - false - true - Indicates whether the build will continue even if there are enhancement errors - - - enableLazyInitialization - java.lang.Boolean - false - true - DEPRECATED: Enable enhancement for lazy loading of attributes. This setting is deprecated for removal without a replacement. - - - enableDirtyTracking - java.lang.Boolean - false - true - DEPRECATED: Enable enhancement for tracking of dirty attributes. This setting is deprecated for removal without a replacement. - - - enableAssociationManagement - java.lang.Boolean - false - true - Enable enhancement for management of bi-direction associations - - - enableExtendedEnhancement - java.lang.Boolean - false - true - Enable enhancement of field access - - - - ${project.build.outputDirectory} - ${project.build.outputDirectory} - true - true - true - false - false - - - - org.sonatype.plexus.build.incremental.BuildContext - buildContext - - - - - - - @generated-dependencies@ - - - org.codehaus.plexus - plexus-utils - jar - 3.0.24 - - - org.codehaus.plexus - plexus-build-api - jar - 0.0.7 - - - org.apache.maven.plugin-tools - maven-plugin-annotations - jar - 3.2 - - - org.apache.maven - maven-artifact - jar - 3.0 - - - 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 - - - diff --git a/tooling/hibernate-enhance-maven-plugin/src/test/java/org/hibernate/orm/tooling/maven/ChildEntity.java b/tooling/hibernate-enhance-maven-plugin/src/test/java/org/hibernate/orm/tooling/maven/ChildEntity.java deleted file mode 100644 index 185eb5d7a9..0000000000 --- a/tooling/hibernate-enhance-maven-plugin/src/test/java/org/hibernate/orm/tooling/maven/ChildEntity.java +++ /dev/null @@ -1,14 +0,0 @@ -/* - * SPDX-License-Identifier: LGPL-2.1-or-later - * Copyright Red Hat Inc. and Hibernate Authors - */ -package org.hibernate.orm.tooling.maven; - -import jakarta.persistence.MappedSuperclass; - -@MappedSuperclass -public class ChildEntity extends ParentEntity { - - String childValue; - -} diff --git a/tooling/hibernate-enhance-maven-plugin/src/test/java/org/hibernate/orm/tooling/maven/MavenEnhancePluginTest.java b/tooling/hibernate-enhance-maven-plugin/src/test/java/org/hibernate/orm/tooling/maven/MavenEnhancePluginTest.java deleted file mode 100644 index 6e2cd49407..0000000000 --- a/tooling/hibernate-enhance-maven-plugin/src/test/java/org/hibernate/orm/tooling/maven/MavenEnhancePluginTest.java +++ /dev/null @@ -1,78 +0,0 @@ -/* - * SPDX-License-Identifier: LGPL-2.1-or-later - * Copyright Red Hat Inc. and Hibernate Authors - */ -package org.hibernate.orm.tooling.maven; - -import org.apache.maven.project.MavenProject; -import org.codehaus.plexus.util.ReflectionUtils; -import org.hibernate.engine.spi.Managed; -import org.junit.Assert; -import org.junit.Test; -import org.sonatype.plexus.build.incremental.DefaultBuildContext; - -import java.io.File; -import java.lang.reflect.Field; -import java.net.URL; -import java.net.URLClassLoader; -import java.util.HashMap; -import java.util.Map; - -/** - * Test case for Maven Enhance Plugin - * - * @author Luis Barreiro - */ -public class MavenEnhancePluginTest { - - @Test - public void testEnhancePlugin() throws Exception { - File baseDir = new File("target/classes/java/test"); - URL[] baseURLs = { baseDir.toURI().toURL() }; - - MavenEnhancePlugin plugin = new MavenEnhancePlugin(); - - Map pluginContext = new HashMap<>(); - pluginContext.put( "project", new MavenProject() ); - - setVariableValueToObject( plugin, "pluginContext", pluginContext ); - setVariableValueToObject( plugin, "buildContext", new DefaultBuildContext() ); - - setVariableValueToObject( plugin, "base", baseDir.getAbsolutePath() ); - setVariableValueToObject( plugin, "dir", baseDir.getAbsolutePath() ); - setVariableValueToObject( plugin, "classNames", "" ); - - setVariableValueToObject( plugin, "failOnError", true ); - setVariableValueToObject( plugin, "enableLazyInitialization", true ); - setVariableValueToObject( plugin, "enableDirtyTracking", true ); - setVariableValueToObject( plugin, "enableAssociationManagement", true ); - setVariableValueToObject( plugin, "enableExtendedEnhancement", false ); - - plugin.execute(); - - try ( URLClassLoader classLoader = new URLClassLoader( baseURLs , getClass().getClassLoader() ) ) { - - Assert.assertTrue( declaresManaged( classLoader.loadClass( ParentEntity.class.getName() ) ) ); - Assert.assertTrue( declaresManaged( classLoader.loadClass( ChildEntity.class.getName() ) ) ); - Assert.assertTrue( declaresManaged( classLoader.loadClass( TestEntity.class.getName() ) ) ); - - } - - } - - private void setVariableValueToObject( Object object, String variable, Object value ) throws IllegalAccessException { - Field field = ReflectionUtils.getFieldByNameIncludingSuperclasses( variable, object.getClass() ); - field.setAccessible( true ); - field.set( object, value ); - } - - private boolean declaresManaged(Class clazz) { - for ( Class interfaceClazz : clazz.getInterfaces() ) { - if ( Managed.class.isAssignableFrom( interfaceClazz ) ) { - return true; - } - } - return false; - } - -} diff --git a/tooling/hibernate-enhance-maven-plugin/src/test/java/org/hibernate/orm/tooling/maven/ParentEntity.java b/tooling/hibernate-enhance-maven-plugin/src/test/java/org/hibernate/orm/tooling/maven/ParentEntity.java deleted file mode 100644 index 3027f694b0..0000000000 --- a/tooling/hibernate-enhance-maven-plugin/src/test/java/org/hibernate/orm/tooling/maven/ParentEntity.java +++ /dev/null @@ -1,14 +0,0 @@ -/* - * SPDX-License-Identifier: LGPL-2.1-or-later - * Copyright Red Hat Inc. and Hibernate Authors - */ -package org.hibernate.orm.tooling.maven; - -import jakarta.persistence.MappedSuperclass; - -@MappedSuperclass -public class ParentEntity { - - String parentValue; - -} diff --git a/tooling/hibernate-enhance-maven-plugin/src/test/java/org/hibernate/orm/tooling/maven/TestEntity.java b/tooling/hibernate-enhance-maven-plugin/src/test/java/org/hibernate/orm/tooling/maven/TestEntity.java deleted file mode 100644 index e39e83be21..0000000000 --- a/tooling/hibernate-enhance-maven-plugin/src/test/java/org/hibernate/orm/tooling/maven/TestEntity.java +++ /dev/null @@ -1,18 +0,0 @@ -/* - * SPDX-License-Identifier: LGPL-2.1-or-later - * Copyright Red Hat Inc. and Hibernate Authors - */ -package org.hibernate.orm.tooling.maven; - -import jakarta.persistence.Entity; -import jakarta.persistence.Id; - -@Entity -public class TestEntity extends ChildEntity { - - @Id - long id; - - String testValue; - -} diff --git a/tooling/hibernate-maven-plugin/hibernate-maven-plugin.gradle b/tooling/hibernate-maven-plugin/hibernate-maven-plugin.gradle new file mode 100644 index 0000000000..0593bff642 --- /dev/null +++ b/tooling/hibernate-maven-plugin/hibernate-maven-plugin.gradle @@ -0,0 +1,19 @@ +description = 'Maven plugin to integrate aspects of Hibernate into your build.' + +apply from: rootProject.file( 'gradle/published-java-module.gradle' ) +apply plugin: 'org.hibernate.build.maven-embedder' + +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ + +dependencies { + implementation project( ":hibernate-core" ) + + implementation "org.apache.maven:maven-plugin-api:3.6.3" + implementation "org.apache.maven.plugin-tools:maven-plugin-annotations:3.6.0" + implementation "org.apache.maven:maven-project:2.2.1" +} \ No newline at end of file diff --git a/tooling/metamodel-generator/hibernate-processor.gradle b/tooling/metamodel-generator/hibernate-processor.gradle index 5dca8ed122..54aeb9b78b 100644 --- a/tooling/metamodel-generator/hibernate-processor.gradle +++ b/tooling/metamodel-generator/hibernate-processor.gradle @@ -8,7 +8,7 @@ import de.thetaphi.forbiddenapis.gradle.CheckForbiddenApis */ description = 'Hibernate compile-time tooling' -apply from: rootProject.file( 'gradle/published-java-module.gradle' ) +apply from: rootProject.file( 'gradle/relocated-published-java-module.gradle' ) apply plugin: 'org.hibernate.build.version-injection' //java {