HHH-18644 - New and improved hibernate-maven-plugin

This commit is contained in:
Steve Ebersole 2024-10-17 09:22:37 -05:00
parent 356b7f54bb
commit dd8e186416
39 changed files with 310 additions and 1024 deletions

View File

@ -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'

View File

@ -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

View File

@ -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

View File

@ -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' )

View File

@ -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' )

View File

@ -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' )

View File

@ -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'

View File

@ -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 {

View File

@ -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.

View File

@ -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' )

View File

@ -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' )

View File

@ -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' )

View File

@ -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' )

View File

@ -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

View File

@ -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 {

View File

@ -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'

View File

@ -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' )

View File

@ -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' )

View File

@ -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' )

View File

@ -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' )

View File

@ -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"
}
}
}

View File

@ -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;
}
}

View File

@ -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<Project> {
@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<MavenEmbedderService> 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<Directory> 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<MavenPluginDescriptorTask> 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 ) );
}
}

View File

@ -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<MavenEmbedderService.Config> {
interface Config extends BuildServiceParameters {
Property<String> 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<String> 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
}
}

View File

@ -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<MavenEmbedderService> 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" );
}
}

View File

@ -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")

View File

@ -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 {

View File

@ -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 <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/
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<dependency>"\
+ "\n <groupId>" + split[0] + "</groupId>"\
+ "\n <artifactId>" + split[1] + "</artifactId>"\
+ "\n <version>" + split[2] + "</version>"\
+ "\n <type>jar</type>"\
+ "\n</dependency>"
}
def generateMavenDependency(Provider<?> gradleDependencyProvider) {
String[] split = gradleDependencyProvider.get().toString().split(":")
return "\n<dependency>"\
+ "\n <groupId>" + split[0] + "</groupId>"\
+ "\n <artifactId>" + split[1] + "</artifactId>"\
+ "\n <version>" + split[2] + "</version>"\
+ "\n <type>jar</type>"\
+ "\n</dependency>"
}
// 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'

View File

@ -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<File> sourceSet = new ArrayList<File>();
@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<String> 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<File> runtimeClasspath) throws MojoExecutionException {
List<URL> urls = new ArrayList<URL>( 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<Artifact> 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, '.' );
}
}

View File

@ -1,18 +0,0 @@
<lifecycleMappingMetadata>
<pluginExecutions>
<pluginExecution>
<pluginExecutionFilter>
<goals>
<goal>enhance</goal>
</goals>
</pluginExecutionFilter>
<action>
<execute>
<runOnIncremental>true</runOnIncremental>
<runOnConfiguration>false</runOnConfiguration>
</execute>
</action>
</pluginExecution>
</pluginExecutions>
</lifecycleMappingMetadata>

View File

@ -1,102 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ 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>.
-->
<plugin>
<name>Hibernate Enhance Maven Plugin</name>
<description>Enhance Plugin of the Hibernate project for use with Maven build system.</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.orm.tooling.maven.MavenEnhancePlugin</implementation>
<language>java</language>
<instantiationStrategy>per-lookup</instantiationStrategy>
<executionStrategy>once-per-session</executionStrategy>
<threadSafe>false</threadSafe>
<parameters>
<parameter>
<name>base</name>
<type>java.lang.String</type>
<required>false</required>
<editable>true</editable>
<description>The root folder for .class files</description>
</parameter>
<parameter>
<name>dir</name>
<type>java.lang.String</type>
<required>false</required>
<editable>true</editable>
<description>Base directory where to search for .class files</description>
</parameter>
<parameter>
<name>classNames</name>
<type>java.lang.String</type>
<required>false</required>
<editable>true</editable>
<description>Comma separated string of class names for which enhancement needs to be done</description>
</parameter>
<parameter>
<name>failOnError</name>
<type>java.lang.Boolean</type>
<required>false</required>
<editable>true</editable>
<description>Indicates whether the build will continue even if there are enhancement errors</description>
</parameter>
<parameter>
<name>enableLazyInitialization</name>
<type>java.lang.Boolean</type>
<required>false</required>
<editable>true</editable>
<description>DEPRECATED: Enable enhancement for lazy loading of attributes. This setting is deprecated for removal without a replacement.</description>
</parameter>
<parameter>
<name>enableDirtyTracking</name>
<type>java.lang.Boolean</type>
<required>false</required>
<editable>true</editable>
<description>DEPRECATED: Enable enhancement for tracking of dirty attributes. This setting is deprecated for removal without a replacement.</description>
</parameter>
<parameter>
<name>enableAssociationManagement</name>
<type>java.lang.Boolean</type>
<required>false</required>
<editable>true</editable>
<description>Enable enhancement for management of bi-direction associations</description>
</parameter>
<parameter>
<name>enableExtendedEnhancement</name>
<type>java.lang.Boolean</type>
<required>false</required>
<editable>true</editable>
<description>Enable enhancement of field access</description>
</parameter>
</parameters>
<configuration>
<base>${project.build.outputDirectory}</base>
<dir>${project.build.outputDirectory}</dir>
<failOnError>true</failOnError>
<enableLazyInitialization>true</enableLazyInitialization>
<enableDirtyTracking>true</enableDirtyTracking>
<enableAssociationManagement>false</enableAssociationManagement>
<enableExtendedEnhancement>false</enableExtendedEnhancement>
</configuration>
</mojo>
</mojos>
</plugin>

View File

@ -1,16 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ 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>.
-->
<plugin>
<name>Hibernate Enhance Maven Plugin</name>
<description>Enhance Plugin of the Hibernate project for use with Maven build system.</description>
<groupId>org.hibernate.orm.tooling</groupId>
<artifactId>hibernate-enhance-maven-plugin</artifactId>
<version>@version@</version>
<goalPrefix>hibernate-enhance</goalPrefix>
<mojos/>
</plugin>

View File

@ -1,186 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ 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>.
-->
<plugin>
<name>Hibernate Enhance Maven Plugin</name>
<description>Enhance Plugin of the Hibernate project for use with Maven build system.</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>
<requiresDependencyResolution>compile+runtime</requiresDependencyResolution>
<phase>compile</phase>
<implementation>org.hibernate.orm.tooling.maven.MavenEnhancePlugin</implementation>
<language>java</language>
<instantiationStrategy>per-lookup</instantiationStrategy>
<executionStrategy>once-per-session</executionStrategy>
<threadSafe>false</threadSafe>
<parameters>
<parameter>
<name>base</name>
<type>java.lang.String</type>
<required>false</required>
<editable>true</editable>
<description>The root folder for .class files</description>
</parameter>
<parameter>
<name>dir</name>
<type>java.lang.String</type>
<required>false</required>
<editable>true</editable>
<description>Base directory where to search for .class files</description>
</parameter>
<parameter>
<name>classNames</name>
<type>java.lang.String</type>
<required>false</required>
<editable>true</editable>
<description>Comma separated string of class names for which enhancement needs to be done</description>
</parameter>
<parameter>
<name>failOnError</name>
<type>java.lang.Boolean</type>
<required>false</required>
<editable>true</editable>
<description>Indicates whether the build will continue even if there are enhancement errors</description>
</parameter>
<parameter>
<name>enableLazyInitialization</name>
<type>java.lang.Boolean</type>
<required>false</required>
<editable>true</editable>
<description>DEPRECATED: Enable enhancement for lazy loading of attributes. This setting is deprecated for removal without a replacement.</description>
</parameter>
<parameter>
<name>enableDirtyTracking</name>
<type>java.lang.Boolean</type>
<required>false</required>
<editable>true</editable>
<description>DEPRECATED: Enable enhancement for tracking of dirty attributes. This setting is deprecated for removal without a replacement.</description>
</parameter>
<parameter>
<name>enableAssociationManagement</name>
<type>java.lang.Boolean</type>
<required>false</required>
<editable>true</editable>
<description>Enable enhancement for management of bi-direction associations</description>
</parameter>
<parameter>
<name>enableExtendedEnhancement</name>
<type>java.lang.Boolean</type>
<required>false</required>
<editable>true</editable>
<description>Enable enhancement of field access</description>
</parameter>
</parameters>
<configuration>
<base>${project.build.outputDirectory}</base>
<dir>${project.build.outputDirectory}</dir>
<failOnError>true</failOnError>
<enableLazyInitialization>true</enableLazyInitialization>
<enableDirtyTracking>true</enableDirtyTracking>
<enableAssociationManagement>false</enableAssociationManagement>
<enableExtendedEnhancement>false</enableExtendedEnhancement>
</configuration>
<requirements>
<requirement>
<role>org.sonatype.plexus.build.incremental.BuildContext</role>
<field-name>buildContext</field-name>
</requirement>
</requirements>
</mojo>
</mojos>
<dependencies>
<!-- Generated by Gradle -->
@generated-dependencies@
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-utils</artifactId>
<type>jar</type>
<version>3.0.24</version>
</dependency>
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-build-api</artifactId>
<type>jar</type>
<version>0.0.7</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.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>
</dependencies>
</plugin>

View File

@ -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;
}

View File

@ -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<String, Object> 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;
}
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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"
}

View File

@ -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 {