Skip to content

Commit 31a8abb

Browse files
committed
HHH-18644: New and improved hibernate-maven-plugin
- Iterate over the 'fileSets' parameter in 'EnhanceMojo#assembleSourceSet()' and call 'EnhanceMojo#addFileSetToSourceSet(FileSet)' for each fileSet found - Adapt test class EnhanceMojoTest * Add a new field 'fileSetsField' and populate it in the 'EnhanceMojoTest#beforeEach()' method * Change test method 'EnhanceMojoTest#testAssembleSourceSet()' to prepare and set a fileSet in the 'enhanceMojo' object under test * Use the new 'fileSetsField' instance variable in the test method 'EnhanceMojoTest#testProcessParameters()' - Adapt the integration test * Add a new java class 'org.foo.Baz' * Add some new 'fileSets' configuration to the 'pom.xml' * Add some new assertions to the 'verify.groovy' script Signed-off-by: Koen Aers <[email protected]>
1 parent e4adb25 commit 31a8abb

File tree

5 files changed

+46
-3
lines changed

5 files changed

+46
-3
lines changed

src/it/enhance/pom.xml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,14 @@
2525
<id>enhance</id>
2626
<phase>process-classes</phase>
2727
<configuration>
28+
<fileSets>
29+
<fileSet>
30+
<directory>${project.build.directory}/classes</directory>
31+
<excludes>
32+
<exclude>**/Baz.class</exclude>
33+
</excludes>
34+
</fileSet>
35+
</fileSets>
2836
<enableLazyInitialization>true</enableLazyInitialization>
2937
</configuration>
3038
<goals>
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package org.foo;
2+
3+
import jakarta.persistence.Entity;
4+
5+
@Entity
6+
public class Baz {
7+
8+
private String foo;
9+
10+
String getFoo() {
11+
return foo;
12+
}
13+
14+
public void setFoo(String f) {
15+
foo = f;
16+
}
17+
18+
}

src/it/enhance/verify.groovy

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@ if (!fooClassFile.exists()) {
2727
throw new FileNotFoundException("File should exist: " + fooClassFile);
2828
}
2929

30+
File bazClassFile = new File(classesFolder, "org/foo/Baz.class");
31+
if (!bazClassFile.exists()) {
32+
throw new FileNotFoundException("File should exist: " + bazClassFile);
33+
}
34+
3035
File buildLog = new File(basedir, "build.log");
3136
if (!buildLog.exists()) {
3237
throw new FileNotFoundException("File should exist: " + buildLog);
@@ -41,7 +46,12 @@ assert listOfStrings.contains("[DEBUG] (f) enableLazyInitialization = true");
4146
assert listOfStrings.contains("[DEBUG] (f) enableExtendedEnhancement = false");
4247
assert listOfStrings.contains("[DEBUG] Starting execution of enhance mojo");
4348
assert listOfStrings.contains("[DEBUG] Starting assembly of the source set");
49+
assert listOfStrings.contains("[DEBUG] Processing FileSet");
50+
assert listOfStrings.contains("[DEBUG] Using base directory: " + classesFolder);
4451
assert listOfStrings.contains("[INFO] Added file to source set: " + barClassFile);
52+
assert listOfStrings.contains("[INFO] Added file to source set: " + fooClassFile);
53+
assert !listOfStrings.contains("[INFO] Added file to source set: " + bazClassFile);
54+
assert listOfStrings.contains("[DEBUG] FileSet was processed succesfully");
4555
assert listOfStrings.contains("[DEBUG] Ending the assembly of the source set");
4656
assert listOfStrings.contains("[DEBUG] Creating bytecode enhancer");
4757
assert listOfStrings.contains("[DEBUG] Creating enhancement context");

src/main/java/org/hibernate/orm/tooling/maven/enhance/EnhanceMojo.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,9 @@ private void processParameters() {
104104

105105
private void assembleSourceSet() {
106106
getLog().debug("Starting assembly of the source set");
107-
addToSourceSetIfNeeded(classesDirectory);
107+
for (FileSet fileSet : fileSets) {
108+
addFileSetToSourceSet(fileSet);
109+
}
108110
getLog().debug("Ending the assembly of the source set");
109111
}
110112

src/test/java/org/hibernate/orm/tooling/maven/enhance/EnhanceMojoTest.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ public class EnhanceMojoTest {
5656
private List<String> logMessages = new ArrayList<String>();
5757

5858
private Field classesDirectoryField;
59+
private Field fileSetsField;
5960
private Field sourceSetField;
6061
private Field enhancerField;
6162

@@ -71,6 +72,8 @@ public class EnhanceMojoTest {
7172
void beforeEach() throws Exception {
7273
classesDirectoryField = EnhanceMojo.class.getDeclaredField("classesDirectory");
7374
classesDirectoryField.setAccessible(true);
75+
fileSetsField = EnhanceMojo.class.getDeclaredField("fileSets");
76+
fileSetsField.setAccessible(true);
7477
sourceSetField = EnhanceMojo.class.getDeclaredField("sourceSet");
7578
sourceSetField.setAccessible(true);
7679
enhancerField = EnhanceMojo.class.getDeclaredField("enhancer");
@@ -94,6 +97,10 @@ void beforeEach() throws Exception {
9497
void testAssembleSourceSet() throws Exception {
9598
Method assembleSourceSetMethod = EnhanceMojo.class.getDeclaredMethod("assembleSourceSet");
9699
assembleSourceSetMethod.setAccessible(true);
100+
FileSet[] fileSets = new FileSet[1];
101+
fileSets[0] = new FileSet();
102+
fileSets[0].setDirectory(classesDirectory.getAbsolutePath());
103+
fileSetsField.set(enhanceMojo, fileSets);
97104
List<?> sourceSet = (List<?>)sourceSetField.get(enhanceMojo);
98105
assertTrue(sourceSet.isEmpty());
99106
assembleSourceSetMethod.invoke(enhanceMojo);
@@ -492,8 +499,6 @@ void testProcessParameters() throws Exception {
492499
enableLazyInitializationField.setAccessible(true);
493500
Field enableDirtyTrackingField = EnhanceMojo.class.getDeclaredField("enableDirtyTracking");
494501
enableDirtyTrackingField.setAccessible(true);
495-
Field fileSetsField = EnhanceMojo.class.getDeclaredField("fileSets");
496-
fileSetsField.setAccessible(true);
497502
assertTrue(logMessages.isEmpty());
498503
assertNull(fileSetsField.get(enhanceMojo));
499504
verifyParametersMethod.invoke(enhanceMojo);

0 commit comments

Comments
 (0)