Skip to content

Commit 95a69c9

Browse files
committed
Configure defacto constant name conventions in checkstyle
* public, protected and package-private constants are upper case * private constants may have any case * except for logger
1 parent 52ab970 commit 95a69c9

5 files changed

Lines changed: 55 additions & 44 deletions

File tree

gradle/config/checkstyle/checkstyleMain.xml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,17 @@
4848
<module name="EqualsAvoidNull"/>
4949
<module name="EmptyStatement"/>
5050
<module name="MissingDeprecated"/>
51+
<module name="ConstantName">
52+
<property name="applyToPrivate" value="false"/>
53+
</module>
54+
<module name="ConstantName">
55+
<!-- private static final fields may have any name, but loggers must be lowercase-->
56+
<property name="format" value="^logger$|^(?!^LOGGER$).*$"/>
57+
<property name="applyToPublic" value="false"/>
58+
<property name="applyToProtected" value="false"/>
59+
<property name="applyToPackage" value="false"/>
60+
</module>
61+
5162
</module>
5263

5364
<module name="JavadocPackage" />

junit-jupiter-engine/src/main/java/org/junit/jupiter/engine/descriptor/AbstractExtensionContext.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
*/
5555
abstract class AbstractExtensionContext<T extends TestDescriptor> implements ExtensionContextInternal, AutoCloseable {
5656

57-
private static final Logger LOGGER = LoggerFactory.getLogger(AbstractExtensionContext.class);
57+
private static final Logger logger = LoggerFactory.getLogger(AbstractExtensionContext.class);
5858
private static final Namespace CLOSEABLE_RESOURCE_LOGGING_NAMESPACE = Namespace.create(
5959
AbstractExtensionContext.class, "CloseableResourceLogging");
6060

@@ -113,7 +113,7 @@ private <N> NamespacedHierarchicalStore.CloseAction<N> createCloseAction() {
113113
if (value instanceof Store.CloseableResource resource) {
114114
if (isAutoCloseEnabled) {
115115
store.computeIfAbsent(value.getClass(), type -> {
116-
LOGGER.warn(() -> "Type implements CloseableResource but not AutoCloseable: " + type.getName());
116+
logger.warn(() -> "Type implements CloseableResource but not AutoCloseable: " + type.getName());
117117
return true;
118118
});
119119
}

junit-jupiter-engine/src/main/java/org/junit/jupiter/engine/extension/TempDirectory.java

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ private static ExtensionContext.Store getContextSpecificStore(ExtensionContext c
273273
@SuppressWarnings("deprecation")
274274
static class CloseablePath implements Store.CloseableResource, AutoCloseable {
275275

276-
private static final Logger LOGGER = LoggerFactory.getLogger(CloseablePath.class);
276+
private static final Logger logger = LoggerFactory.getLogger(CloseablePath.class);
277277

278278
private final Path dir;
279279
private final TempDirFactory factory;
@@ -311,26 +311,26 @@ public void close() throws IOException {
311311
try {
312312
if (this.cleanupMode == NEVER
313313
|| (this.cleanupMode == ON_SUCCESS && selfOrChildFailed(this.extensionContext))) {
314-
LOGGER.info(() -> "Skipping cleanup of temp dir %s for %s due to CleanupMode.%s.".formatted(
314+
logger.info(() -> "Skipping cleanup of temp dir %s for %s due to CleanupMode.%s.".formatted(
315315
this.dir, descriptionFor(this.annotatedElement), this.cleanupMode.name()));
316316
return;
317317
}
318318

319319
FileOperations fileOperations = this.extensionContext.getStore(NAMESPACE) //
320320
.getOrDefault(FILE_OPERATIONS_KEY, FileOperations.class, FileOperations.DEFAULT);
321321
FileOperations loggingFileOperations = file -> {
322-
LOGGER.trace(() -> "Attempting to delete " + file);
322+
logger.trace(() -> "Attempting to delete " + file);
323323
try {
324324
fileOperations.delete(file);
325-
LOGGER.trace(() -> "Successfully deleted " + file);
325+
logger.trace(() -> "Successfully deleted " + file);
326326
}
327327
catch (IOException e) {
328-
LOGGER.trace(e, () -> "Failed to delete " + file);
328+
logger.trace(e, () -> "Failed to delete " + file);
329329
throw e;
330330
}
331331
};
332332

333-
LOGGER.trace(() -> "Cleaning up temp dir " + this.dir);
333+
logger.trace(() -> "Cleaning up temp dir " + this.dir);
334334
SortedMap<Path, IOException> failures = deleteAllFilesAndDirectories(loggingFileOperations);
335335
if (!failures.isEmpty()) {
336336
throw createIOExceptionWithAttachedFailures(failures);
@@ -383,7 +383,7 @@ private SortedMap<Path, IOException> deleteAllFilesAndDirectories(FileOperations
383383

384384
@Override
385385
public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException {
386-
LOGGER.trace(() -> "preVisitDirectory: " + dir);
386+
logger.trace(() -> "preVisitDirectory: " + dir);
387387
if (isLinkWithTargetOutsideTempDir(dir)) {
388388
warnAboutLinkWithTargetOutsideTempDir("link", dir);
389389
delete(dir);
@@ -397,7 +397,7 @@ public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) th
397397

398398
@Override
399399
public FileVisitResult visitFileFailed(Path file, IOException exc) {
400-
LOGGER.trace(exc, () -> "visitFileFailed: " + file);
400+
logger.trace(exc, () -> "visitFileFailed: " + file);
401401
if (exc instanceof NoSuchFileException && !Files.exists(file, LinkOption.NOFOLLOW_LINKS)) {
402402
return CONTINUE;
403403
}
@@ -408,7 +408,7 @@ public FileVisitResult visitFileFailed(Path file, IOException exc) {
408408

409409
@Override
410410
public FileVisitResult visitFile(Path file, BasicFileAttributes attributes) throws IOException {
411-
LOGGER.trace(() -> "visitFile: " + file);
411+
logger.trace(() -> "visitFile: " + file);
412412
if (Files.isSymbolicLink(file) && isLinkWithTargetOutsideTempDir(file)) {
413413
warnAboutLinkWithTargetOutsideTempDir("symbolic link", file);
414414
}
@@ -418,7 +418,7 @@ public FileVisitResult visitFile(Path file, BasicFileAttributes attributes) thro
418418

419419
@Override
420420
public FileVisitResult postVisitDirectory(Path dir, IOException exc) {
421-
LOGGER.trace(exc, () -> "postVisitDirectory: " + dir);
421+
logger.trace(exc, () -> "postVisitDirectory: " + dir);
422422
delete(dir);
423423
return CONTINUE;
424424
}
@@ -430,15 +430,15 @@ private boolean isLinkWithTargetOutsideTempDir(Path path) {
430430
return !path.toRealPath().startsWith(rootRealPath);
431431
}
432432
catch (IOException e) {
433-
LOGGER.trace(e,
433+
logger.trace(e,
434434
() -> "Failed to determine real path for " + path + "; assuming it is not a link");
435435
return false;
436436
}
437437
}
438438

439439
private void warnAboutLinkWithTargetOutsideTempDir(String linkType, Path file) throws IOException {
440440
Path realPath = file.toRealPath();
441-
LOGGER.warn(() -> """
441+
logger.warn(() -> """
442442
Deleting %s from location inside of temp dir (%s) \
443443
to location outside of temp dir (%s) but not the target file/directory""".formatted(
444444
linkType, file, realPath));

junit-platform-engine/src/main/java/org/junit/platform/engine/support/hierarchical/WorkerThreadPoolHierarchicalTestExecutorService.java

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ public final class WorkerThreadPoolHierarchicalTestExecutorService implements Hi
9595
directly.
9696
*/
9797

98-
private static final Logger LOGGER = LoggerFactory.getLogger(WorkerThreadPoolHierarchicalTestExecutorService.class);
98+
private static final Logger logger = LoggerFactory.getLogger(WorkerThreadPoolHierarchicalTestExecutorService.class);
9999

100100
private final WorkQueue workQueue = new WorkQueue();
101101
private final ExecutorService executor;
@@ -137,18 +137,18 @@ public final class WorkerThreadPoolHierarchicalTestExecutorService implements Hi
137137
executor = new ThreadPoolExecutor(configuration.getCorePoolSize(), configuration.getMaxPoolSize(),
138138
configuration.getKeepAliveSeconds(), SECONDS, new SynchronousQueue<>(), threadFactory,
139139
rejectedExecutionHandler);
140-
LOGGER.trace(() -> "initialized thread pool for parallelism of " + configuration.getParallelism());
140+
logger.trace(() -> "initialized thread pool for parallelism of " + configuration.getParallelism());
141141
}
142142

143143
@Override
144144
public void close() {
145-
LOGGER.trace(() -> "shutting down thread pool");
145+
logger.trace(() -> "shutting down thread pool");
146146
executor.shutdownNow();
147147
}
148148

149149
@Override
150150
public Future<@Nullable Void> submit(TestTask testTask) {
151-
LOGGER.trace(() -> "submit: " + testTask);
151+
logger.trace(() -> "submit: " + testTask);
152152

153153
var workerThread = WorkerThread.get();
154154
if (workerThread == null) {
@@ -173,7 +173,7 @@ public void close() {
173173
*/
174174
@Override
175175
public void invokeAll(List<? extends TestTask> testTasks) {
176-
LOGGER.trace(() -> "invokeAll: " + testTasks);
176+
logger.trace(() -> "invokeAll: " + testTasks);
177177

178178
var workerThread = WorkerThread.get();
179179
Preconditions.condition(workerThread != null && workerThread.executor() == this,
@@ -219,13 +219,13 @@ private record RunLeaseAwareWorker(WorkerLease workerLease, BooleanSupplier pare
219219

220220
@Override
221221
public void run() {
222-
LOGGER.trace(() -> "starting worker");
222+
logger.trace(() -> "starting worker");
223223
try {
224224
WorkerThread.getOrThrow().processQueueEntries(workerLease, parentDoneCondition);
225225
}
226226
finally {
227227
workerLease.release(parentDoneCondition);
228-
LOGGER.trace(() -> "stopping worker");
228+
logger.trace(() -> "stopping worker");
229229
}
230230
}
231231
}
@@ -286,11 +286,11 @@ void processQueueEntries(WorkerLease workerLease, BooleanSupplier doneCondition)
286286
this.workerLease = workerLease;
287287
while (!executor.isShutdown()) {
288288
if (doneCondition.getAsBoolean()) {
289-
LOGGER.trace(() -> "yielding resource lock");
289+
logger.trace(() -> "yielding resource lock");
290290
break;
291291
}
292292
if (workQueue.isEmpty()) {
293-
LOGGER.trace(() -> "no queue entries available");
293+
logger.trace(() -> "no queue entries available");
294294
break;
295295
}
296296
processQueueEntries();
@@ -415,7 +415,7 @@ private WorkStealResult tryToStealWork(WorkQueue.Entry entry, BlockingMode block
415415
}
416416
var claimed = workQueue.remove(entry);
417417
if (claimed) {
418-
LOGGER.trace(() -> "stole work: " + entry.task);
418+
logger.trace(() -> "stole work: " + entry.task);
419419
var executed = executeStolenWork(entry, blockingMode);
420420
if (executed) {
421421
return WorkStealResult.EXECUTED_BY_THIS_WORKER;
@@ -439,7 +439,7 @@ private void waitFor(Map<WorkStealResult, List<WorkQueue.Entry>> queueEntriesByR
439439
}
440440
else {
441441
runBlocking(future::isDone, () -> {
442-
LOGGER.trace(() -> "blocking for forked children : %s".formatted(children));
442+
logger.trace(() -> "blocking for forked children : %s".formatted(children));
443443
return future.join();
444444
});
445445
}
@@ -457,7 +457,7 @@ private void executeAll(List<? extends TestTask> children) {
457457
if (children.isEmpty()) {
458458
return;
459459
}
460-
LOGGER.trace(() -> "running %d children directly".formatted(children.size()));
460+
logger.trace(() -> "running %d children directly".formatted(children.size()));
461461
if (children.size() == 1) {
462462
executeTask(children.get(0));
463463
return;
@@ -509,48 +509,48 @@ private void executeTask(TestTask testTask) {
509509
if (!executed) {
510510
var resourceLock = testTask.getResourceLock();
511511
try (var ignored = runBlocking(() -> false, () -> {
512-
LOGGER.trace(() -> "blocking for resource lock: " + resourceLock);
512+
logger.trace(() -> "blocking for resource lock: " + resourceLock);
513513
return resourceLock.acquire();
514514
})) {
515-
LOGGER.trace(() -> "acquired resource lock: " + resourceLock);
515+
logger.trace(() -> "acquired resource lock: " + resourceLock);
516516
doExecute(testTask);
517517
}
518518
catch (InterruptedException ex) {
519519
Thread.currentThread().interrupt();
520520
}
521521
finally {
522-
LOGGER.trace(() -> "released resource lock: " + resourceLock);
522+
logger.trace(() -> "released resource lock: " + resourceLock);
523523
}
524524
}
525525
}
526526

527527
private boolean tryExecuteTask(TestTask testTask) {
528528
var resourceLock = testTask.getResourceLock();
529529
if (resourceLock.tryAcquire()) {
530-
LOGGER.trace(() -> "acquired resource lock: " + resourceLock);
530+
logger.trace(() -> "acquired resource lock: " + resourceLock);
531531
try (resourceLock) {
532532
doExecute(testTask);
533533
return true;
534534
}
535535
finally {
536-
LOGGER.trace(() -> "released resource lock: " + resourceLock);
536+
logger.trace(() -> "released resource lock: " + resourceLock);
537537
}
538538
}
539539
else {
540-
LOGGER.trace(() -> "failed to acquire resource lock: " + resourceLock);
540+
logger.trace(() -> "failed to acquire resource lock: " + resourceLock);
541541
}
542542
return false;
543543
}
544544

545545
private void doExecute(TestTask testTask) {
546-
LOGGER.trace(() -> "executing: " + testTask);
546+
logger.trace(() -> "executing: " + testTask);
547547
stateStack.push(new State());
548548
try {
549549
testTask.execute();
550550
}
551551
finally {
552552
stateStack.pop();
553-
LOGGER.trace(() -> "finished executing: " + testTask);
553+
logger.trace(() -> "finished executing: " + testTask);
554554
}
555555
}
556556

@@ -650,7 +650,7 @@ private static class WorkStealingFuture extends BlockingAwareFuture<@Nullable Vo
650650
if (entry.future.isDone()) {
651651
return callable.call();
652652
}
653-
LOGGER.trace(() -> "blocking for child task: " + entry.task);
653+
logger.trace(() -> "blocking for child task: " + entry.task);
654654
return workerThread.runBlocking(entry.future::isDone, () -> {
655655
try {
656656
return callable.call();
@@ -673,7 +673,7 @@ private static class WorkQueue implements Iterable<WorkQueue.Entry> {
673673

674674
Entry add(TestTask task, int index) {
675675
Entry entry = new Entry(task, index);
676-
LOGGER.trace(() -> "forking: " + entry.task);
676+
logger.trace(() -> "forking: " + entry.task);
677677
return doAdd(entry);
678678
}
679679

@@ -682,7 +682,7 @@ void addAll(Collection<Entry> entries) {
682682
}
683683

684684
void reAdd(Entry entry) {
685-
LOGGER.trace(() -> "re-enqueuing: " + entry.task);
685+
logger.trace(() -> "re-enqueuing: " + entry.task);
686686
doAdd(entry);
687687
}
688688

@@ -726,10 +726,10 @@ private static final class Entry {
726726
this.future = new CompletableFuture<>();
727727
this.future.whenComplete((__, t) -> {
728728
if (t == null) {
729-
LOGGER.trace(() -> "completed normally: " + task);
729+
logger.trace(() -> "completed normally: " + task);
730730
}
731731
else {
732-
LOGGER.trace(t, () -> "completed exceptionally: " + task);
732+
logger.trace(t, () -> "completed exceptionally: " + task);
733733
}
734734
});
735735
this.task = task;
@@ -828,7 +828,7 @@ static class WorkerLeaseManager {
828828
WorkerLease tryAcquire() {
829829
boolean acquired = semaphore.tryAcquire();
830830
if (acquired) {
831-
LOGGER.trace(() -> "acquired worker lease for new worker (available: %d)".formatted(
831+
logger.trace(() -> "acquired worker lease for new worker (available: %d)".formatted(
832832
semaphore.availablePermits()));
833833
return new WorkerLease(this::release);
834834
}
@@ -837,7 +837,7 @@ WorkerLease tryAcquire() {
837837

838838
private ReacquisitionToken release(BooleanSupplier doneCondition) {
839839
semaphore.release();
840-
LOGGER.trace(() -> "release worker lease (available: %d)".formatted(semaphore.availablePermits()));
840+
logger.trace(() -> "release worker lease (available: %d)".formatted(semaphore.availablePermits()));
841841
compensation.accept(doneCondition);
842842
return new ReacquisitionToken();
843843
}
@@ -850,7 +850,7 @@ void reacquire() throws InterruptedException {
850850
Preconditions.condition(!used, "Lease was already reacquired");
851851
used = true;
852852
semaphore.acquire();
853-
LOGGER.trace(() -> "reacquired worker lease (available: %d)".formatted(semaphore.availablePermits()));
853+
logger.trace(() -> "reacquired worker lease (available: %d)".formatted(semaphore.availablePermits()));
854854
}
855855
}
856856

junit-platform-launcher/src/main/java/org/junit/platform/launcher/core/EngineFilterer.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232

3333
class EngineFilterer {
3434

35-
private static final Logger LOGGER = LoggerFactory.getLogger(EngineFilterer.class);
35+
private static final Logger logger = LoggerFactory.getLogger(EngineFilterer.class);
3636

3737
private final List<EngineFilter> engineFilters;
3838

@@ -57,7 +57,7 @@ void performSanityChecks() {
5757

5858
private void warnIfAllEnginesExcluded() {
5959
if (!checkedTestEngines.isEmpty() && checkedTestEngines.values().stream().allMatch(excluded -> excluded)) {
60-
LOGGER.warn(() -> "All TestEngines were excluded by EngineFilters.\n" + getStateDescription());
60+
logger.warn(() -> "All TestEngines were excluded by EngineFilters.\n" + getStateDescription());
6161
}
6262
}
6363

0 commit comments

Comments
 (0)