Move cache nagging into PmdAnalysis

- It was already done as part of the execution, so have it self-contained
 - The method runAndReturnStats is open up as public
This commit is contained in:
Juan Martín Sotuyo Dodero committed 2022-10-15 02:04:10 -03:00
1 parent adb08a9838
commit 7006d7fc3d
2 files changed
+17 -15

No files matched your search

@@ -26,7 +26,6 @@ import net.sourceforge.pmd.benchmark.TextTimingReportRenderer;
import net.sourceforge.pmd.benchmark.TimeTracker;
import net.sourceforge.pmd.benchmark.TimingReport;
import net.sourceforge.pmd.benchmark.TimingReportRenderer;
import net.sourceforge.pmd.cache.NoopAnalysisCache;
import net.sourceforge.pmd.cli.PMDCommandLineInterface;
import net.sourceforge.pmd.cli.PmdParametersParseResult;
import net.sourceforge.pmd.cli.internal.CliMessages;
@@ -72,18 +71,6 @@ public final class PMD {
private PMD() {
}
static void encourageToUseIncrementalAnalysis(final PMDConfiguration configuration) {
if (!configuration.isIgnoreIncrementalAnalysis()
&& configuration.getAnalysisCache() instanceof NoopAnalysisCache
&& log.isWarnEnabled()) {
final String version =
PMDVersion.isUnknown() || PMDVersion.isSnapshot() ? "latest" : "pmd-" + PMDVersion.VERSION;
log.warn("This analysis could be faster, please consider using Incremental Analysis: "
+ "https://pmd.github.io/{}/pmd_userdocs_incremental_analysis.html", version);
}
}
/**
* Run PMD using the given configuration. This replaces the other overload.
*
@@ -16,12 +16,14 @@ import java.util.Set;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.slf4j.event.Level;
import net.sourceforge.pmd.Report.GlobalReportBuilderListener;
import net.sourceforge.pmd.benchmark.TimeTracker;
import net.sourceforge.pmd.benchmark.TimedOperation;
import net.sourceforge.pmd.benchmark.TimedOperationCategory;
import net.sourceforge.pmd.cache.AnalysisCacheListener;
import net.sourceforge.pmd.cache.NoopAnalysisCache;
import net.sourceforge.pmd.cli.internal.CliMessages;
import net.sourceforge.pmd.cli.internal.ProgressBarListener;
import net.sourceforge.pmd.internal.util.AssertionUtil;
@@ -301,7 +303,7 @@ public final class PmdAnalysis implements AutoCloseable {
listener.onConfigError(new Report.ConfigurationError(rule, rule.dysfunctionReason()));
}
PMD.encourageToUseIncrementalAnalysis(configuration);
encourageToUseIncrementalAnalysis(configuration);
try (AbstractPMDProcessor processor = AbstractPMDProcessor.newFileProcessor(configuration)) {
processor.processFiles(rulesets, textFiles, listener);
}
@@ -400,7 +402,7 @@ public final class PmdAnalysis implements AutoCloseable {
}
}
ReportStats runAndReturnStats() {
public ReportStats runAndReturnStats() {
if (getRulesets().isEmpty()) {
return ReportStats.empty();
}
@@ -437,4 +439,17 @@ public final class PmdAnalysis implements AutoCloseable {
void printErrorDetected(int errors) {
printErrorDetected(getReporter(), errors);
}
private static void encourageToUseIncrementalAnalysis(final PMDConfiguration configuration) {
final MessageReporter reporter = configuration.getReporter();
if (!configuration.isIgnoreIncrementalAnalysis()
&& configuration.getAnalysisCache() instanceof NoopAnalysisCache
&& reporter.isLoggable(Level.WARN)) {
final String version =
PMDVersion.isUnknown() || PMDVersion.isSnapshot() ? "latest" : "pmd-" + PMDVersion.VERSION;
reporter.warn("This analysis could be faster, please consider using Incremental Analysis: "
+ "https://pmd.github.io/{}/pmd_userdocs_incremental_analysis.html", version);
}
}
}