HHH-9938 - field access parameter on maven enhacement plugin

This commit is contained in:
barreiro 2015-07-21 03:25:25 +01:00 committed by Steve Ebersole
parent 417baffa13
commit 088b15f451
4 changed files with 38 additions and 6 deletions

View File

@ -99,9 +99,14 @@ on the plugin are:
* `enableLazyInitialization`
* `enableDirtyTracking`
* `enableAssociationManagement`
* `enableFieldAccessEnhancement`
These are all enabled by default. Even if the plugin is enabled, the bytecode enhancement can be bypassed by disabling
all the capabilities.
Field access is not enhanced by default, because it can potentially trigger enhancement of code outside the entities.
Other capabilities are enabled by default. Even if the plugin is enabled, the bytecode enhancement can be bypassed by
disabling all the capabilities.
There is also a parameter `failOnError` that controls what happens in case of error. Default behavior is to fail the
build, but it can be set so that only a warning is issued.
To use the Hibernate Maven plugin on a build it must added to the model (pom.xml) along with other plugins that may be
already in use. The XML snippet below is an example of how to declare and configure the plugin.
@ -121,9 +126,11 @@ already in use. The XML snippet below is an example of how to declare and config
<executions>
<execution>
<configuration>
<failOnError>true</failOnError>
<enableLazyInitialization>true</enableLazyInitialization>
<enableDirtyTracking>true</enableDirtyTracking>
<enableAssociationManagement>true</enableAssociationManagement>
<enableFieldAccessEnhancement>false</enableFieldAccessEnhancement>
</configuration>
<goals>
<goal>enhance</goal>

View File

@ -67,8 +67,11 @@ public class MavenEnhancePlugin extends AbstractMojo {
@Parameter(property = "enableAssociationManagement", defaultValue = "true")
private boolean enableAssociationManagement = true;
@Parameter(property = "enableFieldAccessEnhancement", defaultValue = "false")
private boolean enableFieldAccessEnhancement = false;
private boolean shouldApply() {
return enableLazyInitialization || enableDirtyTracking || enableAssociationManagement;
return enableLazyInitialization || enableDirtyTracking || enableAssociationManagement || enableFieldAccessEnhancement;
}
public void execute() throws MojoExecutionException, MojoFailureException {
@ -109,6 +112,11 @@ public class MavenEnhancePlugin extends AbstractMojo {
public boolean isLazyLoadable(CtField field) {
return enableLazyInitialization;
}
@Override
public boolean doFieldAccessEnhancement(CtClass classDescriptor) {
return enableFieldAccessEnhancement;
}
};
final Enhancer enhancer = new Enhancer( enhancementContext );
@ -120,10 +128,12 @@ public class MavenEnhancePlugin extends AbstractMojo {
continue;
}
if ( !enableLazyInitialization ) {
if ( !enhancementContext.isEntityClass( ctClass ) && !enhancementContext.isCompositeClass( ctClass ) ) {
getLog().info( "Skipping class file [" + file.getAbsolutePath() + "], not an entity nor embeddable" );
continue;
}
}
final byte[] enhancedBytecode = doEnhancement( ctClass, enhancer );
writeOutEnhancedClass( enhancedBytecode, ctClass, file );

View File

@ -66,6 +66,13 @@
<editable>true</editable>
<description>Enable enhancement for management of bi-direction associations</description>
</parameter>
<parameter>
<name>enableFieldAccessEnhancement</name>
<type>java.lang.Boolean</type>
<required>false</required>
<editable>true</editable>
<description>Enable enhancement of field access</description>
</parameter>
</parameters>
<configuration>
<dir>${project.build.outputDirectory}</dir>
@ -73,6 +80,7 @@
<enableLazyInitialization>true</enableLazyInitialization>
<enableDirtyTracking>true</enableDirtyTracking>
<enableAssociationManagement>true</enableAssociationManagement>
<enableFieldAccessEnhancement>false</enableFieldAccessEnhancement>
</configuration>
</mojo>
</mojos>

View File

@ -68,6 +68,13 @@
<editable>true</editable>
<description>Enable enhancement for management of bi-direction associations</description>
</parameter>
<parameter>
<name>enableFieldAccessEnhancement</name>
<type>java.lang.Boolean</type>
<required>false</required>
<editable>true</editable>
<description>Enable enhancement of field access</description>
</parameter>
</parameters>
<configuration>
<dir>${project.build.outputDirectory}</dir>