package dev.caskeleton.buildlogic.strictlane; import java.util.Collections; import java.util.LinkedHashSet; import java.util.Set; import java.util.concurrent.atomic.AtomicLong; import org.gradle.api.tasks.testing.TestDescriptor; import org.gradle.api.tasks.testing.TestListener; import org.gradle.api.tasks.testing.TestResult; final class StrictLaneExecutionTracker implements TestListener { private final boolean collectSelectors; private final AtomicLong executed = new AtomicLong(); private final AtomicLong skipped = new AtomicLong(); private final Set executedSelectors = Collections.synchronizedSet(new LinkedHashSet<>()); StrictLaneExecutionTracker(boolean collectSelectors) { this.collectSelectors = collectSelectors; } long executedCount() { return executed.get(); } long skippedCount() { return skipped.get(); } Set executedSelectors() { synchronized (executedSelectors) { return Set.copyOf(executedSelectors); } } @Override public void beforeSuite(TestDescriptor suite) {} @Override public void afterSuite(TestDescriptor suite, TestResult result) {} @Override public void beforeTest(TestDescriptor testDescriptor) {} @Override public void afterTest(TestDescriptor descriptor, TestResult result) { if (result.getResultType() == TestResult.ResultType.SKIPPED) { skipped.incrementAndGet(); return; } executed.incrementAndGet(); if (collectSelectors) { String className = descriptor.getClassName(); if (className != null) { executedSelectors.add(className); executedSelectors.add(className + "." + descriptor.getName()); } } } }