[compat6] Making compat6 layer for m-pmd-p work again

This commit is contained in:
Andreas Dangel
2024-01-19 11:49:08 +01:00
parent f13cd58c7f
commit f6440c6dab
7 changed files with 980 additions and 11 deletions

View File

@ -43,6 +43,20 @@
<build>
<plugins>
<plugin>
<groupId>org.jboss.bridger</groupId>
<artifactId>bridger</artifactId>
<version>1.6.Final</version>
<executions>
<execution>
<id>weave</id>
<phase>process-classes</phase>
<goals>
<goal>transform</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-invoker-plugin</artifactId>

View File

@ -1,4 +1,4 @@
invoker.goals.1 = verify
invoker.goals.1 = verify -e
invoker.goals.2 = pmd:check -Dformat=csv
invoker.goals.3 = pmd:check -Dformat=txt
invoker.buildResult = failure

File diff suppressed because it is too large Load Diff

View File

@ -26,10 +26,11 @@ import net.sourceforge.pmd.lang.document.TextFile;
import net.sourceforge.pmd.renderers.AbstractAccumulatingRenderer;
import net.sourceforge.pmd.reporting.FileAnalysisListener;
import net.sourceforge.pmd.reporting.GlobalAnalysisListener;
import net.sourceforge.pmd.reporting.ViolationSuppressor;
import net.sourceforge.pmd.util.BaseResultProducingCloseable;
/**
* A {@link Report} collects all informations during a PMD execution. This
* A {@link Report} collects all information during a PMD execution. This
* includes violations, suppressed violations, metrics, error during processing
* and configuration errors.
*
@ -46,7 +47,7 @@ import net.sourceforge.pmd.util.BaseResultProducingCloseable;
* These methods create a new {@link Report} rather than modifying their receiver.
* </p>
*/
public final class Report {
public class Report {
// todo move to package reporting
private final List<RuleViolation> violations = synchronizedList(new ArrayList<>());
@ -312,7 +313,7 @@ public final class Report {
* A {@link FileAnalysisListener} that accumulates events into a
* {@link Report}.
*/
public static final class ReportBuilderListener extends BaseResultProducingCloseable<Report> implements FileAnalysisListener {
public static /*final*/ class ReportBuilderListener extends BaseResultProducingCloseable<Report> implements FileAnalysisListener {
private final Report report;
@ -330,17 +331,17 @@ public final class Report {
}
@Override
public void onRuleViolation(RuleViolation violation) {
public void onRuleViolation(net.sourceforge.pmd.reporting.RuleViolation violation) {
report.addRuleViolation(violation);
}
@Override
public void onSuppressedRuleViolation(SuppressedViolation violation) {
public void onSuppressedRuleViolation(net.sourceforge.pmd.reporting.Report.SuppressedViolation violation) {
report.addSuppressedViolation(violation);
}
@Override
public void onError(ProcessingError error) {
public void onError(net.sourceforge.pmd.reporting.Report.ProcessingError error) {
report.addError(error);
}
@ -354,9 +355,9 @@ public final class Report {
* A {@link GlobalAnalysisListener} that accumulates the events of
* all files into a {@link Report}.
*/
public static final class GlobalReportBuilderListener extends BaseResultProducingCloseable<Report> implements GlobalAnalysisListener {
public static /*final*/ class GlobalReportBuilderListener extends BaseResultProducingCloseable<net.sourceforge.pmd.reporting.Report> implements GlobalAnalysisListener {
private final Report report = new Report();
private final net.sourceforge.pmd.reporting.Report report = new net.sourceforge.pmd.reporting.Report();
@Override
public FileAnalysisListener startFileAnalysis(TextFile file) {
@ -365,12 +366,12 @@ public final class Report {
}
@Override
public void onConfigError(ConfigurationError error) {
public void onConfigError(net.sourceforge.pmd.reporting.Report.ConfigurationError error) {
report.addConfigError(error);
}
@Override
protected Report getResultImpl() {
protected net.sourceforge.pmd.reporting.Report getResultImpl() {
return report;
}
}

View File

@ -0,0 +1,288 @@
/**
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
*/
// This class has been taken from 7.0.0-SNAPSHOT
// Changes: renderFileReport
package net.sourceforge.pmd.renderers;
import java.io.IOException;
import java.io.Writer;
import net.sourceforge.pmd.annotation.Experimental;
import net.sourceforge.pmd.benchmark.TimeTracker;
import net.sourceforge.pmd.benchmark.TimedOperation;
import net.sourceforge.pmd.benchmark.TimedOperationCategory;
import net.sourceforge.pmd.lang.document.TextFile;
import net.sourceforge.pmd.properties.PropertyDescriptor;
import net.sourceforge.pmd.properties.PropertySource;
import net.sourceforge.pmd.reporting.FileAnalysisListener;
import net.sourceforge.pmd.reporting.FileNameRenderer;
import net.sourceforge.pmd.reporting.GlobalAnalysisListener;
import net.sourceforge.pmd.reporting.ListenerInitializer;
import net.sourceforge.pmd.reporting.Report;
import net.sourceforge.pmd.reporting.Report.ConfigurationError;
import net.sourceforge.pmd.reporting.Report.GlobalReportBuilderListener;
import net.sourceforge.pmd.reporting.Report.ProcessingError;
import net.sourceforge.pmd.reporting.Report.ReportBuilderListener;
import net.sourceforge.pmd.reporting.Report.SuppressedViolation;
import net.sourceforge.pmd.reporting.RuleViolation;
/**
* This is an interface for rendering a Report. When a Renderer is being
* invoked, the sequence of method calls is something like the following:
* <ol>
* <li>Renderer construction/initialization</li>
* <li>{@link Renderer#setShowSuppressedViolations(boolean)}</li>
* <li>{@link Renderer#setWriter(Writer)}</li>
* <li>{@link Renderer#start()}</li>
* <li>{@link Renderer#startFileAnalysis(TextFile)} for each source file
* processed</li>
* <li>{@link Renderer#renderFileReport(Report)} for each Report instance</li>
* <li>{@link Renderer#end()}</li>
* </ol>
* <p>
* An implementation of the Renderer interface is expected to have a default
* constructor. Properties should be defined using the
* {@link #definePropertyDescriptor(PropertyDescriptor)}
* method. After the instance is created, the property values are set. This
* means, you won't have access to property values in your constructor.
*/
// TODO Are implementations expected to be thread-safe?
public interface Renderer extends PropertySource {
/**
* Get the name of the Renderer.
*
* @return The name of the Renderer.
*/
@Override
String getName();
/**
* Set the name of the Renderer.
*
* @param name
* The name of the Renderer.
*/
void setName(String name);
/**
* Get the description of the Renderer.
*
* @return The description of the Renderer.
*/
String getDescription();
/**
* Return the default filename extension to use.
*
* @return String
*/
String defaultFileExtension();
/**
* Set the description of the Renderer.
*
* @param description
* The description of the Renderer.
*/
void setDescription(String description);
/**
* Get the indicator for whether to show suppressed violations.
*
* @return <code>true</code> if suppressed violations should show,
* <code>false</code> otherwise.
*/
boolean isShowSuppressedViolations();
/**
* Set the indicator for whether to show suppressed violations.
*
* @param showSuppressedViolations
* Whether to show suppressed violations.
*/
void setShowSuppressedViolations(boolean showSuppressedViolations);
/**
* Get the Writer for the Renderer.
*
* @return The Writer.
*/
Writer getWriter();
/**
* Set the {@link FileNameRenderer} used to render file paths to the report.
* Note that this renderer does not have to use the parameter to output paths.
* Some report formats require a specific format for paths (eg a URI), and are
* allowed to circumvent the provided strategy.
*
* @param fileNameRenderer a non-null file name renderer
*/
void setFileNameRenderer(FileNameRenderer fileNameRenderer);
/**
* Set the Writer for the Renderer.
*
* @param writer The Writer.
*/
void setWriter(Writer writer);
/**
* This method is called before any source files are processed. The Renderer
* will have been fully initialized by the time this method is called, so
* the Writer and other state will be available.
*
* @throws IOException
*/
void start() throws IOException;
/**
* This method is called each time a source file is processed. It is called
* after {@link Renderer#start()}, but before
* {@link Renderer#renderFileReport(Report)} and {@link Renderer#end()}.
*
* This method may be invoked by different threads which are processing
* files independently. Therefore, any non-trivial implementation of this
* method needs to be thread-safe.
*
* @param dataSource
* The source file.
*/
void startFileAnalysis(TextFile dataSource);
/**
* Render the given file Report. There may be multiple Report instances
* which need to be rendered if produced by different threads. It is called
* after {@link Renderer#start()} and
* {@link Renderer#startFileAnalysis(TextFile)}, but before
* {@link Renderer#end()}.
*
* @param report
* A file Report.
* @throws IOException
*
* @see Report
*/
void renderFileReport(Report report) throws IOException;
/**
* This method is at the very end of the Rendering process, after
* {@link Renderer#renderFileReport(Report)}.
*/
void end() throws IOException;
void flush() throws IOException;
/**
* Sets the filename where the report should be written to. If no filename is provided,
* the renderer should write to stdout.
*
* <p>Implementations must initialize the writer of the renderer.
*
* <p>See {@link AbstractRenderer#setReportFile(String)} for the default impl.
*
* @param reportFilename the filename (optional).
*/
@Experimental
void setReportFile(String reportFilename);
/**
* Returns a new analysis listener, that handles violations by rendering
* them in an implementation-defined way.
*/
// TODO the default implementation matches the current behavior,
// ie violations are batched by file and forwarded to the renderer
// when the file is done. Many renderers could directly handle
// violations as they come though.
default GlobalAnalysisListener newListener() throws IOException {
try (TimedOperation ignored = TimeTracker.startOperation(TimedOperationCategory.REPORTING)) {
this.start();
}
return new GlobalAnalysisListener() {
// guard for the close routine
final Object reportMergeLock = new Object();
final GlobalReportBuilderListener configErrorReport = new GlobalReportBuilderListener();
@Override
public void onConfigError(ConfigurationError error) {
configErrorReport.onConfigError(error);
}
@Override
public ListenerInitializer initializer() {
return new ListenerInitializer() {
@Override
public void setFileNameRenderer(FileNameRenderer fileNameRenderer) {
Renderer.this.setFileNameRenderer(fileNameRenderer);
}
};
}
@Override
public FileAnalysisListener startFileAnalysis(TextFile file) {
Renderer renderer = Renderer.this;
renderer.startFileAnalysis(file); // this routine is thread-safe by contract
return new FileAnalysisListener() {
final ReportBuilderListener reportBuilder = new ReportBuilderListener();
@Override
public void onRuleViolation(RuleViolation violation) {
reportBuilder.onRuleViolation(violation);
}
@Override
public void onSuppressedRuleViolation(SuppressedViolation violation) {
reportBuilder.onSuppressedRuleViolation(violation);
}
@Override
public void onError(ProcessingError error) {
reportBuilder.onError(error);
}
@Override
public void close() throws Exception {
reportBuilder.close();
synchronized (reportMergeLock) {
// TODO renderFileReport should be thread-safe instead
try (TimedOperation ignored = TimeTracker.startOperation(TimedOperationCategory.REPORTING)) {
renderer.renderFileReport(reportBuilder.getResult());
}
}
}
@Override
public String toString() {
return "FileRendererListener[" + Renderer.this + "]";
}
};
}
@Override
public void close() throws Exception {
configErrorReport.close();
Renderer.this.renderFileReport(configErrorReport.getResult());
try (TimedOperation ignored = TimeTracker.startOperation(TimedOperationCategory.REPORTING)) {
end();
flush();
}
}
};
}
// --- compat
default void renderFileReport(net.sourceforge.pmd.Report report) throws IOException {
Report newReport = new Report();
newReport.merge(report);
renderFileReport(newReport);
}
}

View File

@ -0,0 +1,36 @@
/*
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
*/
package net.sourceforge.pmd.reporting;
import net.sourceforge.pmd.Rule;
import net.sourceforge.pmd.RuleViolation;
import net.sourceforge.pmd.lang.document.FileId;
public class Report extends net.sourceforge.pmd.Report {
public static class ConfigurationError extends net.sourceforge.pmd.Report.ConfigurationError {
public ConfigurationError(Rule theRule, String theIssue) {
super(theRule, theIssue);
}
}
public static class ProcessingError extends net.sourceforge.pmd.Report.ProcessingError {
public ProcessingError(Throwable error, FileId file) {
super(error, file);
}
}
public static class SuppressedViolation extends net.sourceforge.pmd.Report.SuppressedViolation {
public SuppressedViolation(RuleViolation rv, ViolationSuppressor suppressor, String userMessage) {
super(rv, suppressor, userMessage);
}
}
public static final class GlobalReportBuilderListener extends net.sourceforge.pmd.Report.GlobalReportBuilderListener {
}
public static final class ReportBuilderListener extends net.sourceforge.pmd.Report.ReportBuilderListener {
}
}

View File

@ -0,0 +1,8 @@
/*
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
*/
package net.sourceforge.pmd.reporting;
public interface RuleViolation extends net.sourceforge.pmd.RuleViolation {
}