Skip to content

Commit e4adb25

Browse files
committed
HHH-18644: New and improved hibernate-maven-plugin
- Rename method 'EnhanceMojo#verifyParameters()' to 'EnhanceMojo#processParameters()' and populate the 'fileSets' instance variable if it is 'null' - Rename test method 'EnhanceMojoTest#testVerifyParameters()' to 'EnhanceMojoTest#testProcessParameters()' and add some checks for the above changes Signed-off-by: Koen Aers <[email protected]>
1 parent 0e947d7 commit e4adb25

File tree

2 files changed

+24
-6
lines changed

2 files changed

+24
-6
lines changed

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,21 +79,27 @@ public class EnhanceMojo extends AbstractMojo {
7979

8080
public void execute() {
8181
getLog().debug("Starting execution of enhance mojo");
82-
verifyParameters();
82+
processParameters();
8383
assembleSourceSet();
8484
createEnhancer();
8585
discoverTypes();
8686
performEnhancement();
8787
getLog().debug("Ending execution of enhance mojo");
8888
}
8989

90-
private void verifyParameters() {
90+
private void processParameters() {
9191
if (!enableLazyInitialization) {
9292
getLog().warn( "The 'enableLazyInitialization' configuration is deprecated and will be removed. Set the value to 'true' to get rid of this warning" );
9393
}
9494
if (!enableDirtyTracking) {
9595
getLog().warn( "The 'enableDirtyTracking' configuration is deprecated and will be removed. Set the value to 'true' to get rid of this warning" );
9696
}
97+
if (fileSets == null) {
98+
fileSets = new FileSet[1];
99+
fileSets[0] = new FileSet();
100+
fileSets[0].setDirectory(classesDirectory.getAbsolutePath());
101+
getLog().debug("Addded a default FileSet with base directory: " + fileSets[0].getDirectory());
102+
}
97103
}
98104

99105
private void assembleSourceSet() {

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

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -477,30 +477,42 @@ void testExecute() throws Exception {
477477
}
478478

479479
@Test
480-
void testVerifyParameters() throws Exception {
480+
void testProcessParameters() throws Exception {
481481
String lazyInitializationDeprecatedWarning =
482482
"[WARNING] The 'enableLazyInitialization' configuration is deprecated and will be removed. Set the value to 'true' to get rid of this warning";
483483
String dirtyTrackingDeprecatedWarning =
484484
"[WARNING] The 'enableDirtyTracking' configuration is deprecated and will be removed. Set the value to 'true' to get rid of this warning";
485+
String defaultFileSetAddedMessage =
486+
"[DEBUG] Addded a default FileSet with base directory: " + classesDirectory.getAbsolutePath();
485487
Method verifyParametersMethod = EnhanceMojo.class.getDeclaredMethod(
486-
"verifyParameters",
488+
"processParameters",
487489
new Class[] {});
488490
verifyParametersMethod.setAccessible(true);
489491
Field enableLazyInitializationField = EnhanceMojo.class.getDeclaredField("enableLazyInitialization");
490492
enableLazyInitializationField.setAccessible(true);
491493
Field enableDirtyTrackingField = EnhanceMojo.class.getDeclaredField("enableDirtyTracking");
492494
enableDirtyTrackingField.setAccessible(true);
495+
Field fileSetsField = EnhanceMojo.class.getDeclaredField("fileSets");
496+
fileSetsField.setAccessible(true);
493497
assertTrue(logMessages.isEmpty());
498+
assertNull(fileSetsField.get(enhanceMojo));
494499
verifyParametersMethod.invoke(enhanceMojo);
495-
assertEquals(2, logMessages.size());
500+
assertEquals(3, logMessages.size());
496501
assertTrue(logMessages.contains(lazyInitializationDeprecatedWarning));
497502
assertTrue(logMessages.contains(dirtyTrackingDeprecatedWarning));
503+
assertTrue(logMessages.contains(defaultFileSetAddedMessage));
504+
FileSet[] fileSets = (FileSet[])fileSetsField.get(enhanceMojo);
505+
assertNotNull(fileSets);
506+
assertEquals(1, fileSets.length);
507+
assertEquals(classesDirectory.getAbsolutePath(), fileSets[0].getDirectory());
508+
fileSetsField.set(enhanceMojo, null);
498509
logMessages.clear();
499510
assertTrue(logMessages.isEmpty());
500511
enableLazyInitializationField.set(enhanceMojo, Boolean.TRUE);
501512
enableDirtyTrackingField.set(enhanceMojo, Boolean.TRUE);
502513
verifyParametersMethod.invoke(enhanceMojo);
503-
assertTrue(logMessages.isEmpty());
514+
assertEquals(1, logMessages.size());
515+
assertTrue(logMessages.contains(defaultFileSetAddedMessage));
504516
}
505517

506518
private Log createLog() {

0 commit comments

Comments
 (0)