forked from phoedos/pmd
[core] Rename MessageReporter to PmdReporter as public API
PmdReporter is supposed to be used when configuring PMD (see AbstractConfiguration#setReporter), so it can't be internal. Refs #4348
This commit is contained in:
parent
906baf9b50
commit
3a5ff11dc2
@ -196,6 +196,9 @@ The following previously deprecated classes have been removed:
|
||||
|
||||
**Renamed classes, interfaces**
|
||||
|
||||
* pmd-core
|
||||
* {%jdoc core::util.log.PmdReporter %} - has been renamed from `net.sourceforge.pmd.util.log.MessageReporter`
|
||||
|
||||
* pmd-java
|
||||
* The interface `AccessNode` has been renamed to {% jdoc java::lang.ast.ModifierOwner %}. This is only relevant
|
||||
for Java rules, which use that type directly e.g. through downcasting.
|
||||
|
@ -38,7 +38,7 @@ import net.sourceforge.pmd.renderers.Renderer;
|
||||
import net.sourceforge.pmd.renderers.RendererFactory;
|
||||
import net.sourceforge.pmd.reporting.ReportStats;
|
||||
import net.sourceforge.pmd.util.StringUtil;
|
||||
import net.sourceforge.pmd.util.log.MessageReporter;
|
||||
import net.sourceforge.pmd.util.log.PmdReporter;
|
||||
import net.sourceforge.pmd.util.log.internal.SimpleMessageReporter;
|
||||
|
||||
import picocli.CommandLine.Command;
|
||||
@ -311,7 +311,7 @@ public class PmdCommand extends AbstractAnalysisPmdSubcommand<PMDConfiguration>
|
||||
TimeTracker.startGlobalTracking();
|
||||
}
|
||||
|
||||
final MessageReporter pmdReporter = configuration.getReporter();
|
||||
final PmdReporter pmdReporter = configuration.getReporter();
|
||||
|
||||
try {
|
||||
PmdAnalysis pmd = null;
|
||||
@ -359,14 +359,14 @@ public class PmdCommand extends AbstractAnalysisPmdSubcommand<PMDConfiguration>
|
||||
}
|
||||
}
|
||||
|
||||
private void printErrorDetected(MessageReporter reporter, int errors) {
|
||||
private void printErrorDetected(PmdReporter reporter, int errors) {
|
||||
String msg = LogMessages.errorDetectedMessage(errors, "pmd");
|
||||
// note: using error level here increments the error count of the reporter,
|
||||
// which we don't want.
|
||||
reporter.info(StringUtil.quoteMessageFormat(msg));
|
||||
}
|
||||
|
||||
private void finishBenchmarker(final MessageReporter pmdReporter) {
|
||||
private void finishBenchmarker(final PmdReporter pmdReporter) {
|
||||
if (benchmark) {
|
||||
final TimingReport timingReport = TimeTracker.stopGlobalTracking();
|
||||
|
||||
|
@ -13,7 +13,7 @@ import org.slf4j.event.Level;
|
||||
|
||||
import net.sourceforge.pmd.AbstractConfiguration;
|
||||
import net.sourceforge.pmd.internal.Slf4jSimpleConfiguration;
|
||||
import net.sourceforge.pmd.util.log.MessageReporter;
|
||||
import net.sourceforge.pmd.util.log.PmdReporter;
|
||||
import net.sourceforge.pmd.util.log.internal.SimpleMessageReporter;
|
||||
|
||||
/**
|
||||
@ -46,7 +46,7 @@ public final class PmdRootLogger {
|
||||
resetLogLevel = true;
|
||||
}
|
||||
|
||||
MessageReporter pmdReporter = setupMessageReporter();
|
||||
PmdReporter pmdReporter = setupMessageReporter();
|
||||
conf.setReporter(pmdReporter);
|
||||
return runnable.apply(conf);
|
||||
} finally {
|
||||
@ -58,14 +58,14 @@ public final class PmdRootLogger {
|
||||
}
|
||||
}
|
||||
|
||||
private static @NonNull MessageReporter setupMessageReporter() {
|
||||
private static @NonNull PmdReporter setupMessageReporter() {
|
||||
// Note: This implementation uses slf4j as the backend. If PMD is integrated into an application
|
||||
// a slf4j implementation binding must be provided to see any loggings (even errors).
|
||||
// In pmd-cli, we use slf4j-simple.
|
||||
|
||||
// create a top-level reporter
|
||||
// TODO CLI errors should also be reported through this
|
||||
MessageReporter pmdReporter = new SimpleMessageReporter(log);
|
||||
PmdReporter pmdReporter = new SimpleMessageReporter(log);
|
||||
// always install java.util.logging to slf4j bridge
|
||||
Slf4jSimpleConfiguration.installJulBridge();
|
||||
// logging, mostly for testing purposes
|
||||
|
@ -25,7 +25,7 @@ import net.sourceforge.pmd.lang.LanguageRegistry;
|
||||
import net.sourceforge.pmd.lang.LanguageVersion;
|
||||
import net.sourceforge.pmd.lang.LanguageVersionDiscoverer;
|
||||
import net.sourceforge.pmd.util.AssertionUtil;
|
||||
import net.sourceforge.pmd.util.log.MessageReporter;
|
||||
import net.sourceforge.pmd.util.log.PmdReporter;
|
||||
|
||||
/**
|
||||
* Base configuration class for both PMD and CPD.
|
||||
@ -39,7 +39,7 @@ public abstract class AbstractConfiguration {
|
||||
private Charset sourceEncoding = Charset.forName(System.getProperty("file.encoding"));
|
||||
private final Map<Language, LanguagePropertyBundle> langProperties = new HashMap<>();
|
||||
private final LanguageRegistry langRegistry;
|
||||
private MessageReporter reporter;
|
||||
private PmdReporter reporter;
|
||||
private final LanguageVersionDiscoverer languageVersionDiscoverer;
|
||||
private LanguageVersion forceLanguageVersion;
|
||||
private @NonNull List<Path> inputPaths = new ArrayList<>();
|
||||
@ -49,7 +49,7 @@ public abstract class AbstractConfiguration {
|
||||
private boolean collectRecursive = true;
|
||||
|
||||
|
||||
protected AbstractConfiguration(LanguageRegistry languageRegistry, MessageReporter messageReporter) {
|
||||
protected AbstractConfiguration(LanguageRegistry languageRegistry, PmdReporter messageReporter) {
|
||||
this.langRegistry = Objects.requireNonNull(languageRegistry);
|
||||
this.languageVersionDiscoverer = new LanguageVersionDiscoverer(languageRegistry);
|
||||
this.reporter = Objects.requireNonNull(messageReporter);
|
||||
@ -100,7 +100,7 @@ public abstract class AbstractConfiguration {
|
||||
* Returns the message reporter that is to be used while running
|
||||
* the analysis.
|
||||
*/
|
||||
public @NonNull MessageReporter getReporter() {
|
||||
public @NonNull PmdReporter getReporter() {
|
||||
return reporter;
|
||||
}
|
||||
|
||||
@ -110,7 +110,7 @@ public abstract class AbstractConfiguration {
|
||||
*
|
||||
* @param reporter A non-null message reporter
|
||||
*/
|
||||
public void setReporter(@NonNull MessageReporter reporter) {
|
||||
public void setReporter(@NonNull PmdReporter reporter) {
|
||||
AssertionUtil.requireParamNotNull("reporter", reporter);
|
||||
this.reporter = reporter;
|
||||
}
|
||||
|
@ -51,7 +51,7 @@ import net.sourceforge.pmd.reporting.ReportStats;
|
||||
import net.sourceforge.pmd.reporting.ReportStatsListener;
|
||||
import net.sourceforge.pmd.util.AssertionUtil;
|
||||
import net.sourceforge.pmd.util.StringUtil;
|
||||
import net.sourceforge.pmd.util.log.MessageReporter;
|
||||
import net.sourceforge.pmd.util.log.PmdReporter;
|
||||
|
||||
/**
|
||||
* Main programmatic API of PMD. This is not a CLI entry point, see module
|
||||
@ -122,8 +122,8 @@ import net.sourceforge.pmd.util.log.MessageReporter;
|
||||
* <h3>Customizing message output</h3>
|
||||
*
|
||||
* <p>The analysis reports messages like meta warnings and errors through a
|
||||
* {@link MessageReporter} instance. To override how those messages are output,
|
||||
* you can set it in {@link PMDConfiguration#setReporter(MessageReporter)}.
|
||||
* {@link PmdReporter} instance. To override how those messages are output,
|
||||
* you can set it in {@link PMDConfiguration#setReporter(PmdReporter)}.
|
||||
* By default, it forwards messages to SLF4J.
|
||||
*
|
||||
*/
|
||||
@ -136,7 +136,7 @@ public final class PmdAnalysis implements AutoCloseable {
|
||||
private final List<GlobalAnalysisListener> listeners = new ArrayList<>();
|
||||
private final List<RuleSet> ruleSets = new ArrayList<>();
|
||||
private final PMDConfiguration configuration;
|
||||
private final MessageReporter reporter;
|
||||
private final PmdReporter reporter;
|
||||
|
||||
private final Map<Language, LanguagePropertyBundle> langProperties = new HashMap<>();
|
||||
private boolean closed;
|
||||
@ -344,7 +344,7 @@ public final class PmdAnalysis implements AutoCloseable {
|
||||
* processed. This does not return a report, as the analysis results
|
||||
* are consumed by {@link GlobalAnalysisListener} instances (of which
|
||||
* Renderers are a special case). Note that this does
|
||||
* not throw, errors are instead accumulated into a {@link MessageReporter}.
|
||||
* not throw, errors are instead accumulated into a {@link PmdReporter}.
|
||||
*/
|
||||
public void performAnalysis() {
|
||||
performAnalysisImpl(Collections.emptyList());
|
||||
@ -355,7 +355,7 @@ public final class PmdAnalysis implements AutoCloseable {
|
||||
* and finish the registered renderers. All files collected in the
|
||||
* {@linkplain #files() file collector} are processed. Returns the
|
||||
* output report. Note that this does not throw, errors are instead
|
||||
* accumulated into a {@link MessageReporter}.
|
||||
* accumulated into a {@link PmdReporter}.
|
||||
*/
|
||||
public Report performAnalysisAndCollectReport() {
|
||||
try (GlobalReportBuilderListener reportBuilder = new GlobalReportBuilderListener()) {
|
||||
@ -534,7 +534,7 @@ public final class PmdAnalysis implements AutoCloseable {
|
||||
}
|
||||
|
||||
|
||||
public MessageReporter getReporter() {
|
||||
public PmdReporter getReporter() {
|
||||
return reporter;
|
||||
}
|
||||
|
||||
@ -586,7 +586,7 @@ public final class PmdAnalysis implements AutoCloseable {
|
||||
return stats;
|
||||
}
|
||||
|
||||
static void printErrorDetected(MessageReporter reporter, int errors) {
|
||||
static void printErrorDetected(PmdReporter reporter, int errors) {
|
||||
String msg = LogMessages.errorDetectedMessage(errors, "PMD");
|
||||
// note: using error level here increments the error count of the reporter,
|
||||
// which we don't want.
|
||||
@ -598,7 +598,7 @@ public final class PmdAnalysis implements AutoCloseable {
|
||||
}
|
||||
|
||||
private static void encourageToUseIncrementalAnalysis(final PMDConfiguration configuration) {
|
||||
final MessageReporter reporter = configuration.getReporter();
|
||||
final PmdReporter reporter = configuration.getReporter();
|
||||
|
||||
if (!configuration.isIgnoreIncrementalAnalysis()
|
||||
&& configuration.getAnalysisCache() instanceof NoopAnalysisCache
|
||||
|
@ -54,7 +54,7 @@ import net.sourceforge.pmd.util.StringUtil;
|
||||
import net.sourceforge.pmd.util.internal.xml.PmdXmlReporter;
|
||||
import net.sourceforge.pmd.util.internal.xml.XmlErrorMessages;
|
||||
import net.sourceforge.pmd.util.internal.xml.XmlUtil;
|
||||
import net.sourceforge.pmd.util.log.MessageReporter;
|
||||
import net.sourceforge.pmd.util.log.PmdReporter;
|
||||
|
||||
import com.github.oowekyala.ooxml.DomUtils;
|
||||
import com.github.oowekyala.ooxml.messages.NiceXmlMessageSpec;
|
||||
@ -81,7 +81,7 @@ final class RuleSetFactory {
|
||||
private final RulePriority minimumPriority;
|
||||
private final boolean warnDeprecated;
|
||||
private final RuleSetFactoryCompatibility compatibilityFilter;
|
||||
private final MessageReporter reporter;
|
||||
private final PmdReporter reporter;
|
||||
private final boolean includeDeprecatedRuleReferences;
|
||||
|
||||
private final Map<RuleSetReferenceId, RuleSet> parsedRulesets = new HashMap<>();
|
||||
@ -92,7 +92,7 @@ final class RuleSetFactory {
|
||||
boolean warnDeprecated,
|
||||
RuleSetFactoryCompatibility compatFilter,
|
||||
boolean includeDeprecatedRuleReferences,
|
||||
MessageReporter reporter) {
|
||||
PmdReporter reporter) {
|
||||
this.resourceLoader = resourceLoader;
|
||||
this.languageRegistry = Objects.requireNonNull(languageRegistry);
|
||||
this.minimumPriority = minimumPriority;
|
||||
@ -447,7 +447,7 @@ final class RuleSetFactory {
|
||||
return null; // deleted rule
|
||||
}
|
||||
// only emit a warning if we check for deprecated syntax
|
||||
MessageReporter subReporter = warnDeprecated ? err.at(xmlPlace) : MessageReporter.quiet();
|
||||
PmdReporter subReporter = warnDeprecated ? err.at(xmlPlace) : PmdReporter.quiet();
|
||||
|
||||
List<RuleSetReferenceId> references = RuleSetReferenceId.parse(ref, subReporter);
|
||||
if (references.size() > 1 && warnDeprecated) {
|
||||
@ -677,20 +677,20 @@ final class RuleSetFactory {
|
||||
}
|
||||
|
||||
private static final class PmdXmlReporterImpl
|
||||
extends XmlMessageReporterBase<MessageReporter>
|
||||
extends XmlMessageReporterBase<PmdReporter>
|
||||
implements PmdXmlReporter {
|
||||
|
||||
private final MessageReporter pmdReporter;
|
||||
private final PmdReporter pmdReporter;
|
||||
private int errCount;
|
||||
|
||||
PmdXmlReporterImpl(MessageReporter pmdReporter, OoxmlFacade ooxml, XmlPositioner positioner) {
|
||||
PmdXmlReporterImpl(PmdReporter pmdReporter, OoxmlFacade ooxml, XmlPositioner positioner) {
|
||||
super(ooxml, positioner);
|
||||
this.pmdReporter = pmdReporter;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected MessageReporter create2ndStage(XmlPosition position, XmlPositioner positioner) {
|
||||
return new MessageReporter() {
|
||||
protected PmdReporter create2ndStage(XmlPosition position, XmlPositioner positioner) {
|
||||
return new PmdReporter() {
|
||||
@Override
|
||||
public boolean isLoggable(Level level) {
|
||||
return pmdReporter.isLoggable(level);
|
||||
|
@ -26,7 +26,7 @@ import net.sourceforge.pmd.lang.Language;
|
||||
import net.sourceforge.pmd.lang.LanguageRegistry;
|
||||
import net.sourceforge.pmd.util.CollectionUtil;
|
||||
import net.sourceforge.pmd.util.ResourceLoader;
|
||||
import net.sourceforge.pmd.util.log.MessageReporter;
|
||||
import net.sourceforge.pmd.util.log.PmdReporter;
|
||||
|
||||
/**
|
||||
* Configurable object to load rulesets from XML resources.
|
||||
@ -43,7 +43,7 @@ public final class RuleSetLoader {
|
||||
private boolean warnDeprecated = true;
|
||||
private @NonNull RuleSetFactoryCompatibility compatFilter = RuleSetFactoryCompatibility.DEFAULT;
|
||||
private boolean includeDeprecatedRuleReferences = false;
|
||||
private @NonNull MessageReporter reporter = MessageReporter.quiet();
|
||||
private @NonNull PmdReporter reporter = PmdReporter.quiet();
|
||||
|
||||
/**
|
||||
* Create a new RuleSetLoader with a default configuration.
|
||||
@ -53,7 +53,7 @@ public final class RuleSetLoader {
|
||||
// default
|
||||
}
|
||||
|
||||
RuleSetLoader withReporter(@NonNull MessageReporter reporter) {
|
||||
RuleSetLoader withReporter(@NonNull PmdReporter reporter) {
|
||||
this.reporter = Objects.requireNonNull(reporter);
|
||||
return this;
|
||||
}
|
||||
@ -153,7 +153,7 @@ public final class RuleSetLoader {
|
||||
);
|
||||
}
|
||||
|
||||
private @Nullable MessageReporter filteredReporter() {
|
||||
private @Nullable PmdReporter filteredReporter() {
|
||||
return warnDeprecated ? reporter : null;
|
||||
}
|
||||
|
||||
|
@ -19,7 +19,7 @@ import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
import net.sourceforge.pmd.annotation.InternalApi;
|
||||
import net.sourceforge.pmd.util.ResourceLoader;
|
||||
import net.sourceforge.pmd.util.log.MessageReporter;
|
||||
import net.sourceforge.pmd.util.log.PmdReporter;
|
||||
|
||||
/**
|
||||
* This class is used to parse a RuleSet reference value. Most commonly used for
|
||||
@ -147,7 +147,7 @@ public class RuleSetReferenceId {
|
||||
*/
|
||||
RuleSetReferenceId(final String id,
|
||||
final RuleSetReferenceId externalRuleSetReferenceId,
|
||||
final @Nullable MessageReporter err) {
|
||||
final @Nullable PmdReporter err) {
|
||||
this.originalRef = id;
|
||||
|
||||
if (externalRuleSetReferenceId != null && !externalRuleSetReferenceId.isExternal()) {
|
||||
@ -380,7 +380,7 @@ public class RuleSetReferenceId {
|
||||
}
|
||||
|
||||
static List<RuleSetReferenceId> parse(String referenceString,
|
||||
MessageReporter err) {
|
||||
PmdReporter err) {
|
||||
List<RuleSetReferenceId> references = new ArrayList<>();
|
||||
if (referenceString != null && referenceString.trim().length() > 0) {
|
||||
|
||||
|
@ -21,7 +21,7 @@ import net.sourceforge.pmd.lang.ast.RootNode;
|
||||
import net.sourceforge.pmd.lang.document.TextFile;
|
||||
import net.sourceforge.pmd.lang.rule.internal.RuleApplicator;
|
||||
import net.sourceforge.pmd.reporting.FileAnalysisListener;
|
||||
import net.sourceforge.pmd.util.log.MessageReporter;
|
||||
import net.sourceforge.pmd.util.log.PmdReporter;
|
||||
|
||||
/**
|
||||
* Grouping of Rules per Language in a RuleSet.
|
||||
@ -64,7 +64,7 @@ public class RuleSets {
|
||||
this.ruleSets = Collections.singletonList(ruleSet);
|
||||
}
|
||||
|
||||
public void initializeRules(LanguageProcessorRegistry lpReg, MessageReporter reporter) {
|
||||
public void initializeRules(LanguageProcessorRegistry lpReg, PmdReporter reporter) {
|
||||
// this is abusing the mutability of RuleSet, will go away eventually.
|
||||
for (RuleSet rset : ruleSets) {
|
||||
for (Iterator<Rule> iterator = rset.getRules().iterator(); iterator.hasNext();) {
|
||||
|
@ -29,7 +29,7 @@ import net.sourceforge.pmd.lang.document.FileId;
|
||||
import net.sourceforge.pmd.lang.document.TextDocument;
|
||||
import net.sourceforge.pmd.lang.document.TextFile;
|
||||
import net.sourceforge.pmd.properties.PropertyDescriptor;
|
||||
import net.sourceforge.pmd.util.log.MessageReporter;
|
||||
import net.sourceforge.pmd.util.log.PmdReporter;
|
||||
|
||||
/**
|
||||
* Main programmatic API of CPD. This is not a CLI entry point, see module
|
||||
@ -70,7 +70,7 @@ public final class CpdAnalysis implements AutoCloseable {
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(CpdAnalysis.class);
|
||||
private final CPDConfiguration configuration;
|
||||
private final FileCollector files;
|
||||
private final MessageReporter reporter;
|
||||
private final PmdReporter reporter;
|
||||
private final @Nullable CPDReportRenderer renderer;
|
||||
private @NonNull CPDListener listener = new CPDNullListener();
|
||||
|
||||
|
@ -21,7 +21,7 @@ import net.sourceforge.pmd.lang.document.FileId;
|
||||
import net.sourceforge.pmd.util.database.DBMSMetadata;
|
||||
import net.sourceforge.pmd.util.database.DBURI;
|
||||
import net.sourceforge.pmd.util.database.SourceObject;
|
||||
import net.sourceforge.pmd.util.log.MessageReporter;
|
||||
import net.sourceforge.pmd.util.log.PmdReporter;
|
||||
import net.sourceforge.pmd.util.log.internal.ErrorsAsWarningsReporter;
|
||||
|
||||
/**
|
||||
@ -57,7 +57,7 @@ public final class FileCollectionUtil {
|
||||
// This is to be able to interpret the log (will report 'adding' xxx)
|
||||
LOG.debug("Now collecting files to exclude.");
|
||||
// errors like "excluded file does not exist" are reported as warnings.
|
||||
MessageReporter mutedLog = new ErrorsAsWarningsReporter(collector.getReporter());
|
||||
PmdReporter mutedLog = new ErrorsAsWarningsReporter(collector.getReporter());
|
||||
try (FileCollector excludeCollector = collector.newCollector(mutedLog)) {
|
||||
|
||||
if (configuration.getIgnoreFile() != null) {
|
||||
|
@ -14,7 +14,7 @@ import net.sourceforge.pmd.annotation.InternalApi;
|
||||
import net.sourceforge.pmd.cache.internal.AnalysisCache;
|
||||
import net.sourceforge.pmd.lang.document.TextFile;
|
||||
import net.sourceforge.pmd.reporting.GlobalAnalysisListener;
|
||||
import net.sourceforge.pmd.util.log.MessageReporter;
|
||||
import net.sourceforge.pmd.util.log.PmdReporter;
|
||||
|
||||
/**
|
||||
* Stateful object managing the analysis for a given language.
|
||||
@ -65,7 +65,7 @@ public interface LanguageProcessor extends AutoCloseable {
|
||||
private final GlobalAnalysisListener listener;
|
||||
private final int threadCount;
|
||||
private final AnalysisCache analysisCache;
|
||||
private final MessageReporter messageReporter;
|
||||
private final PmdReporter messageReporter;
|
||||
private final LanguageProcessorRegistry lpRegistry;
|
||||
|
||||
|
||||
@ -79,7 +79,7 @@ public interface LanguageProcessor extends AutoCloseable {
|
||||
GlobalAnalysisListener listener,
|
||||
int threadCount,
|
||||
AnalysisCache analysisCache,
|
||||
MessageReporter messageReporter,
|
||||
PmdReporter messageReporter,
|
||||
LanguageProcessorRegistry lpRegistry) {
|
||||
this.rulesets = rulesets;
|
||||
this.files = files;
|
||||
@ -110,7 +110,7 @@ public interface LanguageProcessor extends AutoCloseable {
|
||||
return analysisCache;
|
||||
}
|
||||
|
||||
public MessageReporter getMessageReporter() {
|
||||
public PmdReporter getMessageReporter() {
|
||||
return messageReporter;
|
||||
}
|
||||
|
||||
|
@ -23,7 +23,7 @@ import net.sourceforge.pmd.properties.PropertyDescriptor;
|
||||
import net.sourceforge.pmd.properties.PropertySource;
|
||||
import net.sourceforge.pmd.util.CollectionUtil;
|
||||
import net.sourceforge.pmd.util.StringUtil.CaseConvention;
|
||||
import net.sourceforge.pmd.util.log.MessageReporter;
|
||||
import net.sourceforge.pmd.util.log.PmdReporter;
|
||||
|
||||
/**
|
||||
* Stores all currently initialized {@link LanguageProcessor}s during analysis.
|
||||
@ -116,14 +116,14 @@ public final class LanguageProcessorRegistry implements AutoCloseable {
|
||||
*/
|
||||
public static LanguageProcessorRegistry create(LanguageRegistry registry,
|
||||
Map<Language, LanguagePropertyBundle> languageProperties,
|
||||
MessageReporter messageReporter) {
|
||||
PmdReporter messageReporter) {
|
||||
return create(registry, languageProperties, messageReporter, System.getenv());
|
||||
}
|
||||
|
||||
// overload for testing to allow mocking the system env vars.
|
||||
static LanguageProcessorRegistry create(LanguageRegistry registry,
|
||||
Map<Language, LanguagePropertyBundle> languageProperties,
|
||||
MessageReporter messageReporter,
|
||||
PmdReporter messageReporter,
|
||||
Map<String, String> env) {
|
||||
Set<LanguageProcessor> processors = new HashSet<>();
|
||||
for (Language language : registry) {
|
||||
@ -152,7 +152,7 @@ public final class LanguageProcessorRegistry implements AutoCloseable {
|
||||
// TODO this should be reused when implementing the CLI
|
||||
public static Map<Language, LanguagePropertyBundle> derivePropertiesFromStrings(
|
||||
Map<Language, Properties> stringProperties,
|
||||
MessageReporter reporter
|
||||
PmdReporter reporter
|
||||
) {
|
||||
Map<Language, LanguagePropertyBundle> typedProperties = new HashMap<>();
|
||||
stringProperties.forEach((l, props) -> {
|
||||
@ -163,7 +163,7 @@ public final class LanguageProcessorRegistry implements AutoCloseable {
|
||||
}
|
||||
|
||||
|
||||
private static void setLanguageProperties(Map<Language, Properties> languageProperties, MessageReporter messageReporter, Language language, LanguagePropertyBundle properties) {
|
||||
private static void setLanguageProperties(Map<Language, Properties> languageProperties, PmdReporter messageReporter, Language language, LanguagePropertyBundle properties) {
|
||||
Properties props = languageProperties.get(language);
|
||||
if (props != null) {
|
||||
props.forEach((k, v) -> {
|
||||
@ -182,7 +182,7 @@ public final class LanguageProcessorRegistry implements AutoCloseable {
|
||||
private static <T> void trySetPropertyCapture(PropertySource source,
|
||||
PropertyDescriptor<T> propertyDescriptor,
|
||||
String propertyValue,
|
||||
MessageReporter reporter) {
|
||||
PmdReporter reporter) {
|
||||
try {
|
||||
T value = propertyDescriptor.serializer().fromString(propertyValue);
|
||||
source.setProperty(propertyDescriptor, value);
|
||||
@ -194,7 +194,7 @@ public final class LanguageProcessorRegistry implements AutoCloseable {
|
||||
}
|
||||
}
|
||||
|
||||
private static void readLanguagePropertiesFromEnv(LanguagePropertyBundle props, MessageReporter reporter, Map<String, String> env) {
|
||||
private static void readLanguagePropertiesFromEnv(LanguagePropertyBundle props, PmdReporter reporter, Map<String, String> env) {
|
||||
for (PropertyDescriptor<?> propertyDescriptor : props.getPropertyDescriptors()) {
|
||||
|
||||
String envVarName = getEnvironmentVariableName(props.getLanguage(), propertyDescriptor);
|
||||
|
@ -10,7 +10,7 @@ import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
import org.slf4j.event.Level;
|
||||
|
||||
import net.sourceforge.pmd.util.StringUtil;
|
||||
import net.sourceforge.pmd.util.log.MessageReporter;
|
||||
import net.sourceforge.pmd.util.log.PmdReporter;
|
||||
|
||||
/**
|
||||
* Reports errors that occur after parsing. This may be used to implement
|
||||
@ -83,10 +83,10 @@ public interface SemanticErrorReporter {
|
||||
|
||||
|
||||
/**
|
||||
* Forwards to a {@link MessageReporter}, except trace and debug
|
||||
* Forwards to a {@link PmdReporter}, except trace and debug
|
||||
* messages which are reported on a logger.
|
||||
*/
|
||||
static SemanticErrorReporter reportToLogger(MessageReporter reporter) {
|
||||
static SemanticErrorReporter reportToLogger(PmdReporter reporter) {
|
||||
return new SemanticErrorReporter() {
|
||||
|
||||
private SemanticException exception = null;
|
||||
|
@ -42,7 +42,7 @@ import net.sourceforge.pmd.lang.Language;
|
||||
import net.sourceforge.pmd.lang.LanguageVersion;
|
||||
import net.sourceforge.pmd.lang.LanguageVersionDiscoverer;
|
||||
import net.sourceforge.pmd.util.AssertionUtil;
|
||||
import net.sourceforge.pmd.util.log.MessageReporter;
|
||||
import net.sourceforge.pmd.util.log.PmdReporter;
|
||||
|
||||
/**
|
||||
* Collects files to analyse before a PMD run. This API allows opening
|
||||
@ -59,14 +59,14 @@ public final class FileCollector implements AutoCloseable {
|
||||
private final List<Closeable> resourcesToClose = new ArrayList<>();
|
||||
private Charset charset = StandardCharsets.UTF_8;
|
||||
private final LanguageVersionDiscoverer discoverer;
|
||||
private final MessageReporter reporter;
|
||||
private final PmdReporter reporter;
|
||||
private final FileId outerFsPath;
|
||||
private boolean closed;
|
||||
private boolean recursive = true;
|
||||
|
||||
// construction
|
||||
|
||||
private FileCollector(LanguageVersionDiscoverer discoverer, MessageReporter reporter, FileId outerFsPath) {
|
||||
private FileCollector(LanguageVersionDiscoverer discoverer, PmdReporter reporter, FileId outerFsPath) {
|
||||
this.discoverer = discoverer;
|
||||
this.reporter = reporter;
|
||||
this.outerFsPath = outerFsPath;
|
||||
@ -82,7 +82,7 @@ public final class FileCollector implements AutoCloseable {
|
||||
* creating a collector yourself.
|
||||
*/
|
||||
@InternalApi
|
||||
public static FileCollector newCollector(LanguageVersionDiscoverer discoverer, MessageReporter reporter) {
|
||||
public static FileCollector newCollector(LanguageVersionDiscoverer discoverer, PmdReporter reporter) {
|
||||
return new FileCollector(discoverer, reporter, null);
|
||||
}
|
||||
|
||||
@ -90,7 +90,7 @@ public final class FileCollector implements AutoCloseable {
|
||||
* Returns a new collector using the configuration except for the logger.
|
||||
*/
|
||||
@InternalApi
|
||||
public FileCollector newCollector(MessageReporter logger) {
|
||||
public FileCollector newCollector(PmdReporter logger) {
|
||||
FileCollector fileCollector = new FileCollector(discoverer, logger, null);
|
||||
fileCollector.charset = this.charset;
|
||||
return fileCollector;
|
||||
@ -118,7 +118,7 @@ public final class FileCollector implements AutoCloseable {
|
||||
* Returns the reporter for the file collection phase.
|
||||
*/
|
||||
@InternalApi
|
||||
public MessageReporter getReporter() {
|
||||
public PmdReporter getReporter() {
|
||||
return reporter;
|
||||
}
|
||||
|
||||
|
@ -15,7 +15,7 @@ import java.util.concurrent.TimeUnit;
|
||||
import net.sourceforge.pmd.RuleSets;
|
||||
import net.sourceforge.pmd.lang.LanguageProcessor.AnalysisTask;
|
||||
import net.sourceforge.pmd.lang.document.TextFile;
|
||||
import net.sourceforge.pmd.util.log.MessageReporter;
|
||||
import net.sourceforge.pmd.util.log.PmdReporter;
|
||||
|
||||
|
||||
/**
|
||||
@ -43,7 +43,7 @@ final class MultiThreadProcessor extends AbstractPMDProcessor {
|
||||
RuleSets copy = new RuleSets(task.getRulesets());
|
||||
// use a noop reporter because the copy should only contain rules that
|
||||
// initialized properly
|
||||
copy.initializeRules(task.getLpRegistry(), MessageReporter.quiet());
|
||||
copy.initializeRules(task.getLpRegistry(), PmdReporter.quiet());
|
||||
return copy;
|
||||
});
|
||||
|
||||
|
@ -63,7 +63,7 @@ import net.sourceforge.pmd.util.internal.xml.PmdXmlReporter;
|
||||
import net.sourceforge.pmd.util.internal.xml.SchemaConstant;
|
||||
import net.sourceforge.pmd.util.internal.xml.XmlErrorMessages;
|
||||
import net.sourceforge.pmd.util.internal.xml.XmlUtil;
|
||||
import net.sourceforge.pmd.util.log.MessageReporter;
|
||||
import net.sourceforge.pmd.util.log.PmdReporter;
|
||||
|
||||
import com.github.oowekyala.ooxml.DomUtils;
|
||||
import com.github.oowekyala.ooxml.messages.XmlException;
|
||||
@ -429,7 +429,7 @@ public class RuleFactory {
|
||||
}
|
||||
|
||||
|
||||
private static <T> @Nullable T tryParsePropertyValue(BuilderAndMapper<T> factory, String value, MessageReporter err) {
|
||||
private static <T> @Nullable T tryParsePropertyValue(BuilderAndMapper<T> factory, String value, PmdReporter err) {
|
||||
try {
|
||||
return factory.getXmlMapper().fromString(value);
|
||||
} catch (IllegalArgumentException e) {
|
||||
@ -437,7 +437,7 @@ public class RuleFactory {
|
||||
}
|
||||
}
|
||||
|
||||
private static <T> Comparable<T> asComparableOrThrow(T object, MessageReporter err) {
|
||||
private static <T> Comparable<T> asComparableOrThrow(T object, PmdReporter err) {
|
||||
if (object instanceof Comparable) {
|
||||
return (Comparable) object;
|
||||
}
|
||||
|
@ -4,13 +4,13 @@
|
||||
|
||||
package net.sourceforge.pmd.util.internal.xml;
|
||||
|
||||
import net.sourceforge.pmd.util.log.MessageReporter;
|
||||
import net.sourceforge.pmd.util.log.PmdReporter;
|
||||
|
||||
import com.github.oowekyala.ooxml.messages.XmlMessageReporter;
|
||||
|
||||
/**
|
||||
* @author Clément Fournier
|
||||
*/
|
||||
public interface PmdXmlReporter extends XmlMessageReporter<MessageReporter> {
|
||||
public interface PmdXmlReporter extends XmlMessageReporter<PmdReporter> {
|
||||
|
||||
}
|
||||
|
@ -9,22 +9,18 @@ import java.text.MessageFormat;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
import org.slf4j.event.Level;
|
||||
|
||||
import net.sourceforge.pmd.annotation.InternalApi;
|
||||
import net.sourceforge.pmd.util.log.internal.QuietReporter;
|
||||
|
||||
/**
|
||||
* Façade to report user-facing messages (info, warning and error).
|
||||
* Note: messages are formatted using {@link MessageFormat}.
|
||||
*
|
||||
* <p>Internal API: this is a transitional API that will be significantly
|
||||
* changed in PMD 7, with the transition to SLF4J. See https://github.com/pmd/pmd/issues/3816
|
||||
* <p>Note: messages are formatted using {@link MessageFormat}.
|
||||
*
|
||||
* TODO rename to PmdReporter
|
||||
* <p>Note: This interface was called net.sourceforge.pmd.util.log.MessageReporter in PMD 6.</p>
|
||||
*
|
||||
* @author Clément Fournier
|
||||
*/
|
||||
@InternalApi
|
||||
public interface MessageReporter {
|
||||
public interface PmdReporter {
|
||||
|
||||
// todo change String to MessageFormat in those arg lists, it's too confusing
|
||||
// where to apply MessageFormat otherwise...
|
||||
@ -101,7 +97,7 @@ public interface MessageReporter {
|
||||
* Returns a reporter instance that does not output anything, but
|
||||
* still counts errors.
|
||||
*/
|
||||
static MessageReporter quiet() {
|
||||
static PmdReporter quiet() {
|
||||
return new QuietReporter();
|
||||
}
|
||||
|
@ -6,20 +6,18 @@ package net.sourceforge.pmd.util.log.internal;
|
||||
|
||||
import org.slf4j.event.Level;
|
||||
|
||||
import net.sourceforge.pmd.annotation.InternalApi;
|
||||
import net.sourceforge.pmd.util.log.MessageReporter;
|
||||
import net.sourceforge.pmd.util.log.PmdReporter;
|
||||
|
||||
/**
|
||||
* Turns errors into warnings reported on another logger.
|
||||
*
|
||||
* @author Clément Fournier
|
||||
*/
|
||||
@InternalApi
|
||||
public final class ErrorsAsWarningsReporter extends MessageReporterBase {
|
||||
|
||||
private final MessageReporter backend;
|
||||
private final PmdReporter backend;
|
||||
|
||||
public ErrorsAsWarningsReporter(MessageReporter backend) {
|
||||
public ErrorsAsWarningsReporter(PmdReporter backend) {
|
||||
this.backend = backend;
|
||||
}
|
||||
|
||||
|
@ -14,14 +14,14 @@ import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
import org.slf4j.event.Level;
|
||||
|
||||
import net.sourceforge.pmd.util.log.MessageReporter;
|
||||
import net.sourceforge.pmd.util.log.PmdReporter;
|
||||
|
||||
/**
|
||||
* Base implementation.
|
||||
*
|
||||
* @author Clément Fournier
|
||||
*/
|
||||
public abstract class MessageReporterBase implements MessageReporter {
|
||||
public abstract class MessageReporterBase implements PmdReporter {
|
||||
|
||||
private int numErrors;
|
||||
private @Nullable Level minLevel = Level.TRACE;
|
||||
|
@ -6,16 +6,14 @@ package net.sourceforge.pmd.util.log.internal;
|
||||
|
||||
import org.slf4j.event.Level;
|
||||
|
||||
import net.sourceforge.pmd.annotation.InternalApi;
|
||||
import net.sourceforge.pmd.util.log.MessageReporter;
|
||||
import net.sourceforge.pmd.util.log.PmdReporter;
|
||||
|
||||
/**
|
||||
* A logger that ignores all messages.
|
||||
*
|
||||
* @author Clément Fournier
|
||||
*/
|
||||
@InternalApi
|
||||
public class QuietReporter extends MessageReporterBase implements MessageReporter {
|
||||
public class QuietReporter extends MessageReporterBase implements PmdReporter {
|
||||
|
||||
// note: not singleton because PmdLogger accumulates error count.
|
||||
// note: not final because used as mock in tests.
|
||||
|
@ -7,16 +7,14 @@ package net.sourceforge.pmd.util.log.internal;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.event.Level;
|
||||
|
||||
import net.sourceforge.pmd.annotation.InternalApi;
|
||||
import net.sourceforge.pmd.util.log.MessageReporter;
|
||||
import net.sourceforge.pmd.util.log.PmdReporter;
|
||||
|
||||
/**
|
||||
* A {@link Logger} (java.util) based logger impl.
|
||||
*
|
||||
* @author Clément Fournier
|
||||
*/
|
||||
@InternalApi
|
||||
public class SimpleMessageReporter extends MessageReporterBase implements MessageReporter {
|
||||
public class SimpleMessageReporter extends MessageReporterBase implements PmdReporter {
|
||||
|
||||
private final Logger backend;
|
||||
|
||||
|
@ -14,7 +14,7 @@ import org.slf4j.LoggerFactory;
|
||||
import net.sourceforge.pmd.AbstractConfiguration;
|
||||
import net.sourceforge.pmd.lang.Language;
|
||||
import net.sourceforge.pmd.lang.LanguageRegistry;
|
||||
import net.sourceforge.pmd.util.log.MessageReporter;
|
||||
import net.sourceforge.pmd.util.log.PmdReporter;
|
||||
import net.sourceforge.pmd.util.log.internal.SimpleMessageReporter;
|
||||
|
||||
public class TreeExportConfiguration extends AbstractConfiguration {
|
||||
@ -28,7 +28,7 @@ public class TreeExportConfiguration extends AbstractConfiguration {
|
||||
private Properties languageProperties = new Properties();
|
||||
private Path file;
|
||||
private boolean readStdin;
|
||||
private MessageReporter messageReporter = new SimpleMessageReporter(LOG);
|
||||
private PmdReporter messageReporter = new SimpleMessageReporter(LOG);
|
||||
|
||||
public TreeExportConfiguration(LanguageRegistry registry) {
|
||||
super(registry, new SimpleMessageReporter(LoggerFactory.getLogger(TreeExporter.class)));
|
||||
@ -86,11 +86,11 @@ public class TreeExportConfiguration extends AbstractConfiguration {
|
||||
this.readStdin = readStdin;
|
||||
}
|
||||
|
||||
public MessageReporter getMessageReporter() {
|
||||
public PmdReporter getMessageReporter() {
|
||||
return messageReporter;
|
||||
}
|
||||
|
||||
public void setMessageReporter(MessageReporter messageReporter) {
|
||||
public void setMessageReporter(PmdReporter messageReporter) {
|
||||
this.messageReporter = messageReporter;
|
||||
}
|
||||
|
||||
|
@ -21,7 +21,7 @@ import net.sourceforge.pmd.lang.ast.Parser.ParserTask;
|
||||
import net.sourceforge.pmd.lang.ast.SemanticErrorReporter;
|
||||
import net.sourceforge.pmd.lang.document.FileId;
|
||||
import net.sourceforge.pmd.lang.document.TextDocument;
|
||||
import net.sourceforge.pmd.util.log.MessageReporter;
|
||||
import net.sourceforge.pmd.util.log.PmdReporter;
|
||||
|
||||
/**
|
||||
* @author Clément Fournier
|
||||
@ -61,7 +61,7 @@ public class DummyParsingHelper implements Extension, BeforeEachCallback, AfterE
|
||||
LanguageProcessorRegistry registry = LanguageProcessorRegistry.create(
|
||||
LanguageRegistry.PMD,
|
||||
Collections.emptyMap(),
|
||||
MessageReporter.quiet()
|
||||
PmdReporter.quiet()
|
||||
);
|
||||
dummyProcessor = registry.getProcessor(DummyLanguageModule.getInstance());
|
||||
}
|
||||
|
@ -33,7 +33,7 @@ import net.sourceforge.pmd.lang.document.SimpleTestTextFile;
|
||||
import net.sourceforge.pmd.lang.rule.AbstractRule;
|
||||
import net.sourceforge.pmd.renderers.Renderer;
|
||||
import net.sourceforge.pmd.reporting.ReportStats;
|
||||
import net.sourceforge.pmd.util.log.MessageReporter;
|
||||
import net.sourceforge.pmd.util.log.PmdReporter;
|
||||
|
||||
/**
|
||||
* @author Clément Fournier
|
||||
@ -106,7 +106,7 @@ class PmdAnalysisTest {
|
||||
void testRuleFailureDuringInitialization() {
|
||||
PMDConfiguration config = new PMDConfiguration();
|
||||
config.setThreads(1);
|
||||
MessageReporter mockReporter = spy(MessageReporter.quiet());
|
||||
PmdReporter mockReporter = spy(PmdReporter.quiet());
|
||||
config.setReporter(mockReporter);
|
||||
|
||||
try (PmdAnalysis pmd = PmdAnalysis.create(config)) {
|
||||
|
@ -30,12 +30,12 @@ import org.slf4j.event.Level;
|
||||
import net.sourceforge.pmd.lang.DummyLanguageModule;
|
||||
import net.sourceforge.pmd.util.internal.xml.SchemaConstant;
|
||||
import net.sourceforge.pmd.util.internal.xml.SchemaConstants;
|
||||
import net.sourceforge.pmd.util.log.MessageReporter;
|
||||
import net.sourceforge.pmd.util.log.PmdReporter;
|
||||
import net.sourceforge.pmd.util.log.internal.SimpleMessageReporter;
|
||||
|
||||
public class RulesetFactoryTestBase {
|
||||
|
||||
protected MessageReporter mockReporter;
|
||||
protected PmdReporter mockReporter;
|
||||
|
||||
@BeforeEach
|
||||
void setup() {
|
||||
|
@ -25,14 +25,14 @@ import net.sourceforge.pmd.lang.LanguageRegistry;
|
||||
import net.sourceforge.pmd.lang.LanguageVersionDiscoverer;
|
||||
import net.sourceforge.pmd.lang.document.FileCollector;
|
||||
import net.sourceforge.pmd.lang.document.TextFile;
|
||||
import net.sourceforge.pmd.util.log.MessageReporter;
|
||||
import net.sourceforge.pmd.util.log.PmdReporter;
|
||||
|
||||
class PMDFilelistTest {
|
||||
|
||||
private static final Path RESOURCES = Paths.get("src/test/resources/net/sourceforge/pmd/cli/");
|
||||
|
||||
private @NonNull FileCollector newCollector() {
|
||||
return FileCollector.newCollector(new LanguageVersionDiscoverer(LanguageRegistry.PMD), MessageReporter.quiet());
|
||||
return FileCollector.newCollector(new LanguageVersionDiscoverer(LanguageRegistry.PMD), PmdReporter.quiet());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -13,7 +13,7 @@ import org.junit.jupiter.api.Test;
|
||||
|
||||
import net.sourceforge.pmd.properties.PropertyDescriptor;
|
||||
import net.sourceforge.pmd.properties.PropertyFactory;
|
||||
import net.sourceforge.pmd.util.log.MessageReporter;
|
||||
import net.sourceforge.pmd.util.log.PmdReporter;
|
||||
|
||||
class LanguageProcessorRegistryTest {
|
||||
@Test
|
||||
@ -28,7 +28,7 @@ class LanguageProcessorRegistryTest {
|
||||
DummyLanguagePropertyBundle bundle = new DummyLanguagePropertyBundle(dummyLanguage);
|
||||
languageProperties.put(dummyLanguage, bundle);
|
||||
|
||||
try (LanguageProcessorRegistry ignored = LanguageProcessorRegistry.create(languageRegistry, languageProperties, MessageReporter.quiet(), env)) {
|
||||
try (LanguageProcessorRegistry ignored = LanguageProcessorRegistry.create(languageRegistry, languageProperties, PmdReporter.quiet(), env)) {
|
||||
assertEquals("theValue", bundle.getRootDirectory());
|
||||
}
|
||||
}
|
||||
|
@ -22,7 +22,7 @@ import org.slf4j.event.Level;
|
||||
import org.slf4j.helpers.NOPLogger;
|
||||
|
||||
import net.sourceforge.pmd.DummyParsingHelper;
|
||||
import net.sourceforge.pmd.util.log.MessageReporter;
|
||||
import net.sourceforge.pmd.util.log.PmdReporter;
|
||||
|
||||
/**
|
||||
* Reports errors that occur after parsing. This may be used to implement
|
||||
@ -30,7 +30,7 @@ import net.sourceforge.pmd.util.log.MessageReporter;
|
||||
*/
|
||||
class SemanticErrorReporterTest {
|
||||
|
||||
MessageReporter mockReporter;
|
||||
PmdReporter mockReporter;
|
||||
Logger mockLogger;
|
||||
|
||||
@RegisterExtension
|
||||
@ -38,7 +38,7 @@ class SemanticErrorReporterTest {
|
||||
|
||||
@BeforeEach
|
||||
void setup() {
|
||||
mockReporter = mock(MessageReporter.class);
|
||||
mockReporter = mock(PmdReporter.class);
|
||||
when(mockReporter.isLoggable(Level.ERROR)).thenReturn(true);
|
||||
mockLogger = spy(NOPLogger.class);
|
||||
}
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user