HHH-16307 - Gradle plugin DSL

This commit is contained in:
Steve Ebersole 2023-03-14 15:20:38 -05:00
parent 187bf4f5e7
commit e5aa1413d8
7 changed files with 248 additions and 121 deletions

View File

@ -111,7 +111,7 @@ public class HibernateOrmPlugin implements Plugin<Project> {
genTask.injectSourceSet( ormDsl.getSourceSet() ); genTask.injectSourceSet( ormDsl.getSourceSet() );
genTask.getGenerationOutputDirectory().set( ormDsl.getJpaMetamodel().getGenerationOutputDirectory() ); genTask.getGenerationOutputDirectory().convention( ormDsl.getJpaMetamodel().getGenerationOutputDirectory() );
genTask.getApplyGeneratedAnnotation().convention( ormDsl.getJpaMetamodel().getApplyGeneratedAnnotation() ); genTask.getApplyGeneratedAnnotation().convention( ormDsl.getJpaMetamodel().getApplyGeneratedAnnotation() );
genTask.getSuppressions().convention( ormDsl.getJpaMetamodel().getSuppressions() ); genTask.getSuppressions().convention( ormDsl.getJpaMetamodel().getSuppressions() );

View File

@ -69,6 +69,11 @@ public abstract class HibernateOrmSpec implements ExtensionAware {
return javaPluginExtension.getSourceSets().getByName( name ); return javaPluginExtension.getSourceSets().getByName( name );
} }
@Override
public abstract ExtensionContainer getExtensions();
/** /**
* Should the plugin inject a dependency on the same version of `hibernate-core` * Should the plugin inject a dependency on the same version of `hibernate-core`
* as the version of this plugin? The dependency is added to the `implementation` * as the version of this plugin? The dependency is added to the `implementation`
@ -82,20 +87,6 @@ public abstract class HibernateOrmSpec implements ExtensionAware {
return useSameVersion; return useSameVersion;
} }
/**
* @see #getUseSameVersion()
*/
public void setUseSameVersion(boolean value) {
useSameVersion.set( value );
}
/**
* @see #getUseSameVersion()
*/
public void useSameVersion() {
useSameVersion.set( true );
}
/** /**
* The source-set containing the domain model. Defaults to the `main` source-set * The source-set containing the domain model. Defaults to the `main` source-set
*/ */
@ -103,34 +94,6 @@ public abstract class HibernateOrmSpec implements ExtensionAware {
return sourceSet; return sourceSet;
} }
/**
* @see #getSourceSet()
*/
public void setSourceSet(String name) {
setSourceSet( resolveSourceSet( name, project ) );
}
/**
* @see #getSourceSet()
*/
public void setSourceSet(SourceSet sourceSet) {
this.sourceSet.set( sourceSet );
}
/**
* @see #getSourceSet()
*/
public void sourceSet(String name) {
setSourceSet( resolveSourceSet( name, project ) );
}
/**
* @see #getSourceSet()
*/
public void sourceSet(SourceSet sourceSet) {
setSourceSet( sourceSet );
}
/** /**
* The languages used in the project * The languages used in the project
*/ */
@ -138,13 +101,6 @@ public abstract class HibernateOrmSpec implements ExtensionAware {
return languages; return languages;
} }
public void setLanguages(Iterable<String> languages) {
this.languages.set( languages );
}
public void languages(String language) {
this.languages.add( language );
}
/** /**
* DSL extension for configuring bytecode enhancement. Also acts as the trigger for * DSL extension for configuring bytecode enhancement. Also acts as the trigger for
@ -158,17 +114,6 @@ public abstract class HibernateOrmSpec implements ExtensionAware {
return enhancementDsl; return enhancementDsl;
} }
/**
* Provider access to {@link #getEnhancement()}
*/
public Provider<EnhancementSpec> getEnhancementDslAccess() {
return enhancementDslAccess;
}
public boolean isEnhancementEnabled() {
return enhancementDsl != null;
}
/** /**
* @see #getEnhancement() * @see #getEnhancement()
*/ */
@ -187,18 +132,6 @@ public abstract class HibernateOrmSpec implements ExtensionAware {
return jpaMetamodelDsl; return jpaMetamodelDsl;
} }
/**
* Provider access to {@link #getJpaMetamodel()}
*/
public Provider<JpaMetamodelGenerationSpec> getJpaMetamodelDslAccess() {
return jpaMetamodelDslAccess;
}
public boolean isMetamodelGenerationEnabled() {
return jpaMetamodelDsl != null;
}
/** /**
* @see #getJpaMetamodel() * @see #getJpaMetamodel()
*/ */
@ -206,6 +139,114 @@ public abstract class HibernateOrmSpec implements ExtensionAware {
action.execute( getJpaMetamodel() ); action.execute( getJpaMetamodel() );
} }
@Override
public abstract ExtensionContainer getExtensions(); public boolean isEnhancementEnabled() {
return enhancementDsl != null;
}
public boolean isMetamodelGenerationEnabled() {
return jpaMetamodelDsl != null;
}
/**
* @see #getUseSameVersion()
*
* @deprecated See the Gradle property naming <a href="https://docs.gradle.org/current/userguide/lazy_configuration.html#lazy_configuration_faqs">guidelines</a>
*/
@Deprecated(forRemoval = true)
public void setUseSameVersion(boolean value) {
useSameVersion.set( value );
}
/**
* @see #getUseSameVersion()
*
* @deprecated See the Gradle property naming <a href="https://docs.gradle.org/current/userguide/lazy_configuration.html#lazy_configuration_faqs">guidelines</a>
*/
@Deprecated(forRemoval = true)
public void useSameVersion() {
useSameVersion.set( true );
}
/**
* @see #getSourceSet()
*
* @deprecated See the Gradle property naming <a href="https://docs.gradle.org/current/userguide/lazy_configuration.html#lazy_configuration_faqs">guidelines</a>
*/
@Deprecated(forRemoval = true)
public void setSourceSet(String name) {
setSourceSet( resolveSourceSet( name, project ) );
}
/**
* @see #getSourceSet()
*
* @deprecated See the Gradle property naming <a href="https://docs.gradle.org/current/userguide/lazy_configuration.html#lazy_configuration_faqs">guidelines</a>
*/
@Deprecated(forRemoval = true)
public void setSourceSet(SourceSet sourceSet) {
this.sourceSet.set( sourceSet );
}
/**
* @see #getSourceSet()
*
* @deprecated See the Gradle property naming <a href="https://docs.gradle.org/current/userguide/lazy_configuration.html#lazy_configuration_faqs">guidelines</a>
*/
@Deprecated(forRemoval = true)
public void sourceSet(String name) {
setSourceSet( resolveSourceSet( name, project ) );
}
/**
* @see #getSourceSet()
*
* @deprecated See the Gradle property naming <a href="https://docs.gradle.org/current/userguide/lazy_configuration.html#lazy_configuration_faqs">guidelines</a>
*/
@Deprecated(forRemoval = true)
public void sourceSet(SourceSet sourceSet) {
setSourceSet( sourceSet );
}
/**
* @see #getLanguages()
*
* @deprecated See the Gradle property naming <a href="https://docs.gradle.org/current/userguide/lazy_configuration.html#lazy_configuration_faqs">guidelines</a>
*/
@Deprecated(forRemoval = true)
public void setLanguages(Iterable<String> languages) {
this.languages.set( languages );
}
/**
* @see #getLanguages()
*
* @deprecated See the Gradle property naming <a href="https://docs.gradle.org/current/userguide/lazy_configuration.html#lazy_configuration_faqs">guidelines</a>
*/
@Deprecated
public void languages(String language) {
this.languages.add( language );
}
/**
* Provider access to {@link #getEnhancement()}
*
* @deprecated See the Gradle property naming <a href="https://docs.gradle.org/current/userguide/lazy_configuration.html#lazy_configuration_faqs">guidelines</a>
*/
@Deprecated
public Provider<EnhancementSpec> getEnhancementDslAccess() {
return enhancementDslAccess;
}
/**
* Provider access to {@link #getJpaMetamodel()}
*
* @deprecated See the Gradle property naming <a href="https://docs.gradle.org/current/userguide/lazy_configuration.html#lazy_configuration_faqs">guidelines</a>
*/
@Deprecated
public Provider<JpaMetamodelGenerationSpec> getJpaMetamodelDslAccess() {
return jpaMetamodelDslAccess;
}
} }

View File

@ -36,10 +36,18 @@ public class EnhancementSpec {
enableLazyInitialization = makeProperty( project ).convention( true ); enableLazyInitialization = makeProperty( project ).convention( true );
enableDirtyTracking = makeProperty( project ).convention( true ); enableDirtyTracking = makeProperty( project ).convention( true );
enableAssociationManagement = makeProperty( project ); enableAssociationManagement = makeProperty( project ).convention( false );
enableExtendedEnhancement = makeProperty( project ); enableExtendedEnhancement = makeProperty( project ).convention( false );
} }
@SuppressWarnings( "UnstableApiUsage" )
public static Property<Boolean> makeProperty(Project project) {
return project.getObjects().property( Boolean.class );
}
/**
* Whether any property values indicate work to be done.
*/
public boolean hasAnythingToDo() { public boolean hasAnythingToDo() {
return enableLazyInitialization.get() return enableLazyInitialization.get()
|| enableDirtyTracking.get() || enableDirtyTracking.get()
@ -47,96 +55,144 @@ public class EnhancementSpec {
|| enableExtendedEnhancement.get(); || enableExtendedEnhancement.get();
} }
@Deprecated(forRemoval = true) /**
* Whether lazy-initialization handling should be incorporated into the enhanced bytecode
*/
public Property<Boolean> getEnableLazyInitialization() { public Property<Boolean> getEnableLazyInitialization() {
return enableLazyInitialization; return enableLazyInitialization;
} }
/**
* Whether dirty-tracking should be incorporated into the enhanced bytecode
*/
public Property<Boolean> getEnableDirtyTracking() {
return enableDirtyTracking;
}
/**
* Whether bidirectional association-management handling should be incorporated into the enhanced bytecode
*/
public Property<Boolean> getEnableAssociationManagement() {
return enableAssociationManagement;
}
/**
* Whether extended enhancement should be performed.
*/
public Property<Boolean> getEnableExtendedEnhancement() {
return enableExtendedEnhancement;
}
/**
* @deprecated See the Gradle property naming <a href="https://docs.gradle.org/current/userguide/lazy_configuration.html#lazy_configuration_faqs">guidelines</a>
*/
@Deprecated(forRemoval = true) @Deprecated(forRemoval = true)
public void setEnableLazyInitialization(boolean enable) { public void setEnableLazyInitialization(boolean enable) {
enableLazyInitialization.set( enable ); enableLazyInitialization.set( enable );
} }
/**
* @deprecated See the Gradle property naming <a href="https://docs.gradle.org/current/userguide/lazy_configuration.html#lazy_configuration_faqs">guidelines</a>
*/
@Deprecated(forRemoval = true) @Deprecated(forRemoval = true)
public void enableLazyInitialization(boolean enable) { public void enableLazyInitialization(boolean enable) {
setEnableLazyInitialization( enable ); setEnableLazyInitialization( enable );
} }
/**
* @deprecated See the Gradle property naming <a href="https://docs.gradle.org/current/userguide/lazy_configuration.html#lazy_configuration_faqs">guidelines</a>
*/
@Deprecated(forRemoval = true) @Deprecated(forRemoval = true)
public void lazyInitialization(boolean enable) { public void lazyInitialization(boolean enable) {
setEnableLazyInitialization( enable ); setEnableLazyInitialization( enable );
} }
/**
* @deprecated See the Gradle property naming <a href="https://docs.gradle.org/current/userguide/lazy_configuration.html#lazy_configuration_faqs">guidelines</a>
*/
@Deprecated(forRemoval = true) @Deprecated(forRemoval = true)
public void setLazyInitialization(boolean enable) { public void setLazyInitialization(boolean enable) {
setEnableLazyInitialization( enable ); setEnableLazyInitialization( enable );
} }
/**
@Deprecated(forRemoval = true) * @deprecated See the Gradle property naming <a href="https://docs.gradle.org/current/userguide/lazy_configuration.html#lazy_configuration_faqs">guidelines</a>
public Property<Boolean> getEnableDirtyTracking() { */
return enableDirtyTracking;
}
@Deprecated(forRemoval = true) @Deprecated(forRemoval = true)
public void setEnableDirtyTracking(boolean enable) { public void setEnableDirtyTracking(boolean enable) {
enableDirtyTracking.set( enable ); enableDirtyTracking.set( enable );
} }
/**
* @deprecated See the Gradle property naming <a href="https://docs.gradle.org/current/userguide/lazy_configuration.html#lazy_configuration_faqs">guidelines</a>
*/
@Deprecated(forRemoval = true) @Deprecated(forRemoval = true)
public void enableDirtyTracking(boolean enable) { public void enableDirtyTracking(boolean enable) {
setEnableDirtyTracking( enable ); setEnableDirtyTracking( enable );
} }
/**
* @deprecated See the Gradle property naming <a href="https://docs.gradle.org/current/userguide/lazy_configuration.html#lazy_configuration_faqs">guidelines</a>
*/
@Deprecated(forRemoval = true) @Deprecated(forRemoval = true)
public void dirtyTracking(boolean enable) { public void dirtyTracking(boolean enable) {
setEnableDirtyTracking( enable ); setEnableDirtyTracking( enable );
} }
/**
* @deprecated See the Gradle property naming <a href="https://docs.gradle.org/current/userguide/lazy_configuration.html#lazy_configuration_faqs">guidelines</a>
*/
@Deprecated(forRemoval = true) @Deprecated(forRemoval = true)
public void setDirtyTracking(boolean enable) { public void setDirtyTracking(boolean enable) {
setEnableDirtyTracking( enable ); setEnableDirtyTracking( enable );
} }
/**
public Property<Boolean> getEnableAssociationManagement() { * @deprecated See the Gradle property naming <a href="https://docs.gradle.org/current/userguide/lazy_configuration.html#lazy_configuration_faqs">guidelines</a>
return enableAssociationManagement; */
} @Deprecated(forRemoval = true)
public void setEnableAssociationManagement(boolean enable) { public void setEnableAssociationManagement(boolean enable) {
enableAssociationManagement.set( enable ); enableAssociationManagement.set( enable );
} }
/**
* @deprecated See the Gradle property naming <a href="https://docs.gradle.org/current/userguide/lazy_configuration.html#lazy_configuration_faqs">guidelines</a>
*/
@Deprecated(forRemoval = true)
public void enableAssociationManagement(boolean enable) { public void enableAssociationManagement(boolean enable) {
setEnableAssociationManagement( enable ); setEnableAssociationManagement( enable );
} }
/**
* @deprecated See the Gradle property naming <a href="https://docs.gradle.org/current/userguide/lazy_configuration.html#lazy_configuration_faqs">guidelines</a>
*/
@Deprecated(forRemoval = true)
public void associationManagement(boolean enable) { public void associationManagement(boolean enable) {
setEnableAssociationManagement( enable ); setEnableAssociationManagement( enable );
} }
/**
public Property<Boolean> getEnableExtendedEnhancement() { * @deprecated See the Gradle property naming <a href="https://docs.gradle.org/current/userguide/lazy_configuration.html#lazy_configuration_faqs">guidelines</a>
return enableExtendedEnhancement; */
} @Deprecated(forRemoval = true)
public void setEnableExtendedEnhancement(boolean enable) { public void setEnableExtendedEnhancement(boolean enable) {
enableExtendedEnhancement.set( enable ); enableExtendedEnhancement.set( enable );
} }
/**
* @deprecated See the Gradle property naming <a href="https://docs.gradle.org/current/userguide/lazy_configuration.html#lazy_configuration_faqs">guidelines</a>
*/
@Deprecated(forRemoval = true)
public void enableExtendedEnhancement(boolean enable) { public void enableExtendedEnhancement(boolean enable) {
setEnableExtendedEnhancement( enable ); setEnableExtendedEnhancement( enable );
} }
/**
* @deprecated See the Gradle property naming <a href="https://docs.gradle.org/current/userguide/lazy_configuration.html#lazy_configuration_faqs">guidelines</a>
*/
@Deprecated(forRemoval = true)
public void extendedEnhancement(boolean enable) { public void extendedEnhancement(boolean enable) {
setEnableExtendedEnhancement( enable ); setEnableExtendedEnhancement( enable );
} }
@SuppressWarnings( "UnstableApiUsage" )
public static Property<Boolean> makeProperty(Project project) {
final Property<Boolean> createdProperty = project.getObjects().property( Boolean.class );
// default to false
createdProperty.convention( false );
return createdProperty;
}
} }

View File

@ -56,30 +56,55 @@ public class JpaMetamodelGenerationSpec {
return applyGeneratedAnnotation; return applyGeneratedAnnotation;
} }
public void applyGeneratedAnnotation(boolean apply) {
applyGeneratedAnnotation.set( apply );
}
public SetProperty<String> getSuppressions() { public SetProperty<String> getSuppressions() {
return suppressions; return suppressions;
} }
public void suppress(String warning) {
suppressions.add( warning );
}
public DirectoryProperty getGenerationOutputDirectory() { public DirectoryProperty getGenerationOutputDirectory() {
return generationOutputDirectory; return generationOutputDirectory;
} }
public void generationOutputDirectory(Object ref) {
generationOutputDirectory.set( project.file( ref ) );
}
public DirectoryProperty getCompileOutputDirectory() { public DirectoryProperty getCompileOutputDirectory() {
return compileOutputDirectory; return compileOutputDirectory;
} }
/**
* @see #getApplyGeneratedAnnotation()
*
* @deprecated See the Gradle property naming <a href="https://docs.gradle.org/current/userguide/lazy_configuration.html#lazy_configuration_faqs">guidelines</a>
*/
@Deprecated(forRemoval = true)
public void applyGeneratedAnnotation(boolean apply) {
applyGeneratedAnnotation.set( apply );
}
/**
* @see #getSuppressions()
*
* @deprecated See the Gradle property naming <a href="https://docs.gradle.org/current/userguide/lazy_configuration.html#lazy_configuration_faqs">guidelines</a>
*/
@Deprecated(forRemoval = true)
public void suppress(String warning) {
suppressions.add( warning );
}
/**
* @see #getGenerationOutputDirectory()
*
* @deprecated See the Gradle property naming <a href="https://docs.gradle.org/current/userguide/lazy_configuration.html#lazy_configuration_faqs">guidelines</a>
*/
@Deprecated(forRemoval = true)
public void generationOutputDirectory(Object ref) {
generationOutputDirectory.set( project.file( ref ) );
}
/**
* @see #getCompileOutputDirectory()
*
* @deprecated See the Gradle property naming <a href="https://docs.gradle.org/current/userguide/lazy_configuration.html#lazy_configuration_faqs">guidelines</a>
*/
@Deprecated(forRemoval = true)
public void compileOutputDirectory(Object ref) { public void compileOutputDirectory(Object ref) {
compileOutputDirectory.set( project.file( ref ) ); compileOutputDirectory.set( project.file( ref ) );
} }

View File

@ -37,13 +37,12 @@ hibernate {
useSameVersion = false useSameVersion = false
sourceSet = 'mySpecialSourceSet' sourceSet = 'mySpecialSourceSet'
enhancement { enhancement {
lazyInitialization( true ) enableLazyInitialization.set(true)
lazyInitialization = true
enableDirtyTracking.set(true)
dirtyTracking = true dirtyTracking = true
} }
jpaMetamodel { jpaMetamodel {
} }
} }
tasks.withType(JavaCompile).forEach {
logger.lifecycle " - compile task : " + it.name
}

View File

@ -28,7 +28,10 @@ dependencies {
hibernate { hibernate {
useSameVersion = false useSameVersion = false
enhancement { enhancement {
lazyInitialization( true ) enableLazyInitialization.set(true)
lazyInitialization = true
enableDirtyTracking.set(true)
dirtyTracking = true dirtyTracking = true
} }
jpaMetamodel { jpaMetamodel {

View File

@ -28,7 +28,10 @@ dependencies {
hibernate { hibernate {
useSameVersion = false useSameVersion = false
enhancement { enhancement {
lazyInitialization( true ) enableLazyInitialization.set(true)
lazyInitialization = true
enableDirtyTracking.set(true)
dirtyTracking = true dirtyTracking = true
} }
jpaMetamodel { jpaMetamodel {