Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor type: make the report aware of parser properties #1111

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:

strategy:
matrix:
platform: [ubuntu-latest, macos-latest, windows-latest]
platform: [ubuntu-, macos-latest, windows-latest]
jdk: [17, 21]

runs-on: ${{ matrix.platform }}
Expand Down
17 changes: 1 addition & 16 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -292,22 +292,6 @@

<build>
<plugins>
<plugin>
<groupId>org.owasp</groupId>
<artifactId>dependency-check-maven</artifactId>
<version>11.1.0</version>
<configuration>
<nvdApiServerId>nvd.nist.gov</nvdApiServerId>
<format>JSON</format>
</configuration>
<executions>
<execution>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.sonatype.plugins</groupId>
<artifactId>nexus-staging-maven-plugin</artifactId>
Expand Down Expand Up @@ -368,6 +352,7 @@
<excludes>
<exclude>.*LineRangeList</exclude>
<exclude>.*SecureDigester</exclude>
<exclude>.*Benchmark.*</exclude>
<exclude>edu.hm.hafner.analysis.parser.*</exclude>
<exclude>edu.hm.hafner.analysis.PackageDetectors.*</exclude>
</excludes>
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/edu/hm/hafner/analysis/Issue.java
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ public static Predicate<Issue> byType(final String type) {
}

/**
* Called after de-serialization to improve the memory usage.
* Called after deserialization to improve the memory usage.
*
* @return this
*/
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/edu/hm/hafner/analysis/IssueDifference.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ public IssueDifference(final Report currentIssues, final String referenceId,
final Report referenceIssues, final Map<String, Integer> includes) {
newIssues = currentIssues.copy();
fixedIssues = referenceIssues.copy();
outstandingIssues = new Report();
newIssuesInChangedCode = new Report();
outstandingIssues = referenceIssues.copyEmptyInstance();
newIssuesInChangedCode = currentIssues.copyEmptyInstance();

referencesByHash = new HashMap<>();
referencesByFingerprint = new HashMap<>();
Expand Down
71 changes: 51 additions & 20 deletions src/main/java/edu/hm/hafner/analysis/IssueParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import org.apache.commons.lang3.StringUtils;

import edu.hm.hafner.analysis.Report.IssueType;
import edu.hm.hafner.util.SecureXmlParserFactory;
import edu.umd.cs.findbugs.annotations.CheckForNull;

Expand All @@ -18,7 +19,7 @@
@SuppressWarnings("checkstyle:JavadocVariable")
public abstract class IssueParser implements Serializable {
@Serial
private static final long serialVersionUID = 200992696185460268L;
private static final long serialVersionUID = 5L; // release 13.0.0

protected static final String ADDITIONAL_PROPERTIES = "additionalProperties";
protected static final String CATEGORY = "category";
Expand All @@ -35,42 +36,71 @@ public abstract class IssueParser implements Serializable {
protected static final String LINE_START = "lineStart";
protected static final String MESSAGE = "message";
protected static final String MODULE_NAME = "moduleName";
protected static final String ORIGIN = "origin";
protected static final String PACKAGE_NAME = "packageName";
protected static final String SEVERITY = "severity";
protected static final String TYPE = "type";

private String id = Report.DEFAULT_ID;
private String name = Report.DEFAULT_ID;
private IssueType type = IssueType.WARNING;

/**
* Parses the specified file for issues.
* Parses a report (given by the reader factory) for issues. The name and ID of the report are set to the default
* values provided by the parser descriptor.
*
* @param readerFactory
* provides a reader to the reports
* factory to read input reports with a specific locale
*
* @return the issues
* @return the report containing the found issues
* @throws ParsingException
* Signals that during parsing a non-recoverable error has been occurred
* signals that during parsing a non-recoverable error has been occurred
* @throws ParsingCanceledException
* Signals that the user has aborted the parsing
* signals that the user has aborted the parsing
*/
public abstract Report parse(ReaderFactory readerFactory) throws ParsingException, ParsingCanceledException;
public Report parse(final ReaderFactory readerFactory) throws ParsingException, ParsingCanceledException {
var report = parseReport(readerFactory);

report.setOrigin(id, name, type, readerFactory.getFileName());

return report;
}

/**
* Parses the specified file for issues. Invokes the parser using {@link #parse(ReaderFactory)} and sets the file
* name of the report.
* Parses a report (given by the reader factory) for issues.
*
* @param readerFactory
* provides a reader to the reports
* factory to read input reports with a specific locale
*
* @return the issues
* @return the report containing the found issues
* @throws ParsingException
* Signals that during parsing a non-recoverable error has been occurred
* signals that during parsing a non-recoverable error has been occurred
* @throws ParsingCanceledException
* Signals that the user has aborted the parsing
* signals that the user has aborted the parsing
*/
public Report parseFile(final ReaderFactory readerFactory) throws ParsingException, ParsingCanceledException {
var report = parse(readerFactory);
report.setOriginReportFile(readerFactory.getFileName());
return report;
protected abstract Report parseReport(ReaderFactory readerFactory) throws ParsingException, ParsingCanceledException;

public final void setId(final String id) {
this.id = id;
}

protected String getId() {
return id;
}

public final void setName(final String name) {
this.name = name;
}

protected String getName() {
return name;
}

public final void setType(final IssueType type) {
this.type = type;
}

protected IssueType getType() {
return type;
}

/**
Expand Down Expand Up @@ -110,7 +140,8 @@ protected boolean isXmlFile(final ReaderFactory readerFactory) {
* equal sequences of characters, ignoring case.
*
* <p>{@code null}s are handled without exceptions. Two {@code null}
* references are considered equal. The comparison is <strong>case insensitive</strong>.</p>
* references are considered equal. The comparison is <strong>case-insensitive</strong>.
* </p>
*
* <pre>
* equalsIgnoreCase(null, null) = true
Expand All @@ -128,7 +159,7 @@ protected boolean isXmlFile(final ReaderFactory readerFactory) {
* @return {@code true} if the CharSequences are equal (case-insensitive), or both {@code null}
*/
public static boolean equalsIgnoreCase(@CheckForNull final String a, @CheckForNull final String b) {
return StringUtils.equals(normalize(a), normalize(b));
return StringUtils.equalsIgnoreCase(normalize(a), normalize(b));
}

private static String normalize(@CheckForNull final String input) {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/edu/hm/hafner/analysis/LookaheadParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ protected LookaheadParser(final String pattern) {
}

@Override
public Report parse(final ReaderFactory readerFactory) throws ParsingException, ParsingCanceledException {
public Report parseReport(final ReaderFactory readerFactory) throws ParsingException, ParsingCanceledException {
var report = new Report();
try (Stream<String> lines = readerFactory.readStream()) {
try (var lookahead = new LookaheadStream(lines, readerFactory.getFileName())) {
Expand Down
Loading
Loading