Skip to content

Commit d3e0d76

Browse files
committed
HHH-18644: New and improved hibernate-maven-plugin
- Isolate the message strings for method 'EnhanceMojo#enhanceClass(File)' - Use the isolated messages above and add verifications concerning the logging in 'EnhanceMojoTest#testEnhanceClass()' Signed-off-by: Koen Aers <[email protected]>
1 parent 848d93a commit d3e0d76

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

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

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -205,19 +205,19 @@ private void performEnhancement() {
205205
}
206206

207207
private void enhanceClass(File classFile) {
208-
getLog().debug("Trying to enhance class file: " + classFile);
208+
getLog().debug(TRYING_TO_ENHANCE_CLASS_FILE.formatted(classFile));
209209
try {
210210
byte[] newBytes = enhancer.enhance(
211211
determineClassName(classFile),
212212
Files.readAllBytes(classFile.toPath()));
213213
if (newBytes != null) {
214214
writeByteCodeToFile(newBytes, classFile);
215-
getLog().info("Succesfully enhanced class file: " + classFile);
215+
getLog().info(SUCCESFULLY_ENHANCED_CLASS_FILE.formatted(classFile));
216216
} else {
217-
getLog().info("Skipping file: " + classFile);
217+
getLog().info(SKIPPING_FILE.formatted(classFile));
218218
}
219219
} catch (EnhancementException | IOException e) {
220-
getLog().error("An exception occurred while trying to class file: " + classFile, e);;
220+
getLog().error(ERROR_WHILE_ENHANCING_CLASS_FILE.formatted(classFile), e);;
221221
}
222222
}
223223

@@ -261,6 +261,8 @@ private boolean clearFile(File file) {
261261

262262
// info messages
263263
static final String SUCCESFULLY_CLEARED_FILE = "Succesfully cleared the contents of file: %s";
264+
static final String SUCCESFULLY_ENHANCED_CLASS_FILE = "Succesfully enhanced class file: %s";
265+
static final String SKIPPING_FILE = "Skipping file: %s";
264266

265267
// warning messages
266268
static final String PROBLEM_CLEARING_FILE = "Problem clearing file for writing out enhancements [ %s ]";
@@ -270,11 +272,13 @@ private boolean clearFile(File file) {
270272
static final String UNABLE_TO_DELETE_FILE = "Unable to delete file: %s";
271273
static final String ERROR_WRITING_BYTES_TO_FILE = "Error writing bytes to file : %s";
272274
static final String ERROR_OPENING_FILE_FOR_WRITING = "Error opening file for writing : %s";
275+
static final String ERROR_WHILE_ENHANCING_CLASS_FILE = "An exception occurred while trying to class file: %s";
273276

274277
// debug messages
275278
static final String TRYING_TO_CLEAR_FILE = "Trying to clear the contents of file: %s";
276279
static final String AMOUNT_BYTES_WRITTEN_TO_FILE = "%s bytes were succesfully written to file: %s";
277280
static final String WRITING_BYTE_CODE_TO_FILE = "Writing byte code to file: %s";
278281
static final String DETERMINE_CLASS_NAME_FOR_FILE = "Determining class name for file: %s";
282+
static final String TRYING_TO_ENHANCE_CLASS_FILE = "Trying to enhance class file: %s";
279283

280284
}

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -375,9 +375,14 @@ public Object invoke(Object proxy, Method method, Object[] args) throws Throwabl
375375
}
376376
});
377377
long beforeRuns = barClassFile.lastModified();
378+
// First Run -> file is modified
378379
enhancerField.set(enhanceMojo, enhancer);
379380
assertEquals(0, calls.get(0));
380381
enhanceClassMethod.invoke(enhanceMojo, barClassFile);
382+
// check log messages
383+
for (String s: logMessages) {
384+
System.out.println(s);
385+
}
381386
long afterFirstRun = barClassFile.lastModified();
382387
assertEquals(1, calls.get(0));
383388
assertTrue(afterFirstRun >= beforeRuns);

0 commit comments

Comments
 (0)