Skip to content

Commit 088b15f

Browse files
barreirosebersole
authored andcommitted
HHH-9938 - field access parameter on maven enhacement plugin
1 parent 417baff commit 088b15f

File tree

4 files changed

+38
-6
lines changed

4 files changed

+38
-6
lines changed

documentation/src/main/asciidoc/topical/bytecode/BytecodeEnhancement.adoc

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,14 @@ on the plugin are:
9999
* `enableLazyInitialization`
100100
* `enableDirtyTracking`
101101
* `enableAssociationManagement`
102+
* `enableFieldAccessEnhancement`
102103

103-
These are all enabled by default. Even if the plugin is enabled, the bytecode enhancement can be bypassed by disabling
104-
all the capabilities.
104+
Field access is not enhanced by default, because it can potentially trigger enhancement of code outside the entities.
105+
Other capabilities are enabled by default. Even if the plugin is enabled, the bytecode enhancement can be bypassed by
106+
disabling all the capabilities.
107+
108+
There is also a parameter `failOnError` that controls what happens in case of error. Default behavior is to fail the
109+
build, but it can be set so that only a warning is issued.
105110

106111
To use the Hibernate Maven plugin on a build it must added to the model (pom.xml) along with other plugins that may be
107112
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
121126
<executions>
122127
<execution>
123128
<configuration>
129+
<failOnError>true</failOnError>
124130
<enableLazyInitialization>true</enableLazyInitialization>
125131
<enableDirtyTracking>true</enableDirtyTracking>
126132
<enableAssociationManagement>true</enableAssociationManagement>
133+
<enableFieldAccessEnhancement>false</enableFieldAccessEnhancement>
127134
</configuration>
128135
<goals>
129136
<goal>enhance</goal>

tooling/hibernate-enhance-maven-plugin/src/main/java/org/hibernate/orm/tooling/maven/MavenEnhancePlugin.java

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,11 @@ public class MavenEnhancePlugin extends AbstractMojo {
6767
@Parameter(property = "enableAssociationManagement", defaultValue = "true")
6868
private boolean enableAssociationManagement = true;
6969

70+
@Parameter(property = "enableFieldAccessEnhancement", defaultValue = "false")
71+
private boolean enableFieldAccessEnhancement = false;
72+
7073
private boolean shouldApply() {
71-
return enableLazyInitialization || enableDirtyTracking || enableAssociationManagement;
74+
return enableLazyInitialization || enableDirtyTracking || enableAssociationManagement || enableFieldAccessEnhancement;
7275
}
7376

7477
public void execute() throws MojoExecutionException, MojoFailureException {
@@ -109,6 +112,11 @@ public boolean hasLazyLoadableAttributes(CtClass classDescriptor) {
109112
public boolean isLazyLoadable(CtField field) {
110113
return enableLazyInitialization;
111114
}
115+
116+
@Override
117+
public boolean doFieldAccessEnhancement(CtClass classDescriptor) {
118+
return enableFieldAccessEnhancement;
119+
}
112120
};
113121

114122
final Enhancer enhancer = new Enhancer( enhancementContext );
@@ -120,9 +128,11 @@ public boolean isLazyLoadable(CtField field) {
120128
continue;
121129
}
122130

123-
if ( !enhancementContext.isEntityClass( ctClass ) && !enhancementContext.isCompositeClass( ctClass ) ) {
124-
getLog().info( "Skipping class file [" + file.getAbsolutePath() + "], not an entity nor embeddable" );
125-
continue;
131+
if ( !enableLazyInitialization ) {
132+
if ( !enhancementContext.isEntityClass( ctClass ) && !enhancementContext.isCompositeClass( ctClass ) ) {
133+
getLog().info( "Skipping class file [" + file.getAbsolutePath() + "], not an entity nor embeddable" );
134+
continue;
135+
}
126136
}
127137

128138
final byte[] enhancedBytecode = doEnhancement( ctClass, enhancer );

tooling/hibernate-enhance-maven-plugin/src/main/resources/META-INF/maven/org.hibernate.orm.tooling/hibernate-enhance-maven-plugin/plugin-help.xml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,13 +66,21 @@
6666
<editable>true</editable>
6767
<description>Enable enhancement for management of bi-direction associations</description>
6868
</parameter>
69+
<parameter>
70+
<name>enableFieldAccessEnhancement</name>
71+
<type>java.lang.Boolean</type>
72+
<required>false</required>
73+
<editable>true</editable>
74+
<description>Enable enhancement of field access</description>
75+
</parameter>
6976
</parameters>
7077
<configuration>
7178
<dir>${project.build.outputDirectory}</dir>
7279
<failOnError>true</failOnError>
7380
<enableLazyInitialization>true</enableLazyInitialization>
7481
<enableDirtyTracking>true</enableDirtyTracking>
7582
<enableAssociationManagement>true</enableAssociationManagement>
83+
<enableFieldAccessEnhancement>false</enableFieldAccessEnhancement>
7684
</configuration>
7785
</mojo>
7886
</mojos>

tooling/hibernate-enhance-maven-plugin/src/main/resources/META-INF/maven/plugin.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,13 @@
6868
<editable>true</editable>
6969
<description>Enable enhancement for management of bi-direction associations</description>
7070
</parameter>
71+
<parameter>
72+
<name>enableFieldAccessEnhancement</name>
73+
<type>java.lang.Boolean</type>
74+
<required>false</required>
75+
<editable>true</editable>
76+
<description>Enable enhancement of field access</description>
77+
</parameter>
7178
</parameters>
7279
<configuration>
7380
<dir>${project.build.outputDirectory}</dir>

0 commit comments

Comments
 (0)