Skip to content

Commit

Permalink
Move type back to descriptor.
Browse files Browse the repository at this point in the history
  • Loading branch information
uhafner committed Dec 16, 2024
1 parent d0792af commit bb72ff7
Show file tree
Hide file tree
Showing 42 changed files with 203 additions and 152 deletions.
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
37 changes: 18 additions & 19 deletions src/main/java/edu/hm/hafner/analysis/IssueParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,17 @@ 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 defaultId = StringUtils.EMPTY;
private String defaultName = StringUtils.EMPTY;
private String id = StringUtils.EMPTY;
private String name = StringUtils.EMPTY;
private IssueType type = IssueType.WARNING;

/**
* Parses a report (given by the reader factory) 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
* factory to read input reports with a specific locale
Expand All @@ -57,17 +58,17 @@ public abstract class IssueParser implements Serializable {
* signals that the user has aborted the parsing
*/
public Report parse(final ReaderFactory readerFactory) throws ParsingException, ParsingCanceledException {
return parse(readerFactory, defaultId, defaultName);
return parse(readerFactory, id, name);
}

/**
* Parses a report (given by the reader factory) for issues.
*
* @param readerFactory
* factory to read input reports with a specific locale
* @param id
* @param customId
* the ID for the returned report
* @param name
* @param customName
* a human-readable name for the returned report
*
* @return the report containing the found issues
Expand All @@ -76,12 +77,10 @@ public Report parse(final ReaderFactory readerFactory) throws ParsingException,
* @throws ParsingCanceledException
* signals that the user has aborted the parsing
*/
public Report parse(final ReaderFactory readerFactory, final String id, final String name) throws ParsingException, ParsingCanceledException {
public Report parse(final ReaderFactory readerFactory, final String customId, final String customName) throws ParsingException, ParsingCanceledException {
var report = parseReport(readerFactory);

report.setOriginReportFile(readerFactory.getFileName());
report.setElementType(getType());
report.setOrigin(id, name);
report.setOrigin(customId, customName, type, readerFactory.getFileName());

return report;
}
Expand All @@ -100,17 +99,16 @@ public Report parse(final ReaderFactory readerFactory, final String id, final St
*/
protected abstract Report parseReport(ReaderFactory readerFactory) throws ParsingException, ParsingCanceledException;

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

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

// FIXME: back to descriptor?
public IssueType getType() {
return IssueType.WARNING;
public final void setType(final IssueType type) {
this.type = type;
}

/**
Expand Down Expand Up @@ -150,7 +148,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 Down
106 changes: 73 additions & 33 deletions src/main/java/edu/hm/hafner/analysis/Report.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@
* position 1, and so on.
*
* <p>
* Additionally, this report provides methods to find and filter issues based on different properties. To
* create issues use the provided {@link IssueBuilder builder} class.
* Additionally, this report provides methods to find and filter issues based on different properties. To create issues
* use the provided {@link IssueBuilder builder} class.
* </p>
*
* @author Ullrich Hafner
Expand Down Expand Up @@ -186,23 +186,65 @@ public String getName() {
}

/**
* Sets the origin of all issues in this report. Calling this method will associate all containing issues and
* issues in sub-reports using the specified ID and name.
* Sets the origin of all issues in this report. Calling this method will associate all containing issues and issues
* in sub-reports using the specified ID and name.
*
* @param originId
* @param id
* the ID of the report
* @param originName
* @param name
* a human-readable name for the report
*
* @deprecated use {@link #setOrigin(String, String, IssueType)}
*/
public void setOrigin(final String originId, final String originName) {
Ensure.that(originId).isNotBlank("Issue origin ID '%s' must be not blank (%s)", originId, toString());
Ensure.that(originName).isNotBlank("Issue origin name '%s' must be not blank (%s)", originName, toString());
@Deprecated
@SuppressWarnings("checkstyle:HiddenField")
public void setOrigin(final String id, final String name) {
setOrigin(id, name, IssueType.WARNING);
}

/**
* Sets the origin of all issues in this report. Calling this method will associate all containing issues and issues
* in sub-reports using the specified ID and name.
*
* @param id
* the ID of the report
* @param name
* a human-readable name for the report
* @param elementType
* the type of the issues in the report
*/
@SuppressWarnings("checkstyle:HiddenField")
public void setOrigin(final String id, final String name, final IssueType elementType) {
var normalizedId = StringUtils.defaultIfBlank(id, DEFAULT_ID);
var normalizedName = StringUtils.defaultIfBlank(name, DEFAULT_ID);

this.id = normalizedId;
this.name = normalizedName;
this.elementType = elementType;

id = originId;
name = originName;
subReports.forEach(report -> report.setOrigin(normalizedId, normalizedName, elementType));
// TODO check if we need the type for issues as well

Check warning on line 226 in src/main/java/edu/hm/hafner/analysis/Report.java

View check run for this annotation

ci.jenkins.io / Open Tasks Scanner

TODO

NORMAL: check if we need the type for issues as well
elements.forEach(issue -> issue.setOrigin(normalizedId, normalizedName));
}

subReports.forEach(report -> report.setOrigin(originId, originName));
elements.forEach(issue -> issue.setOrigin(originId, originName));
/**
* Sets the origin of all issues in this report. Calling this method will associate all containing issues and issues
* in sub-reports using the specified ID and name.
*
* @param id
* the ID of the report
* @param name
* a human-readable name for the report
* @param elementType
* the type of the issues in the report
* @param reportFile
* the report file name to add
*/
@SuppressWarnings("checkstyle:HiddenField")
public void setOrigin(final String id, final String name, final IssueType elementType,
final String reportFile) {
setOrigin(id, name, elementType);
setOriginReportFile(reportFile);
}

/**
Expand Down Expand Up @@ -261,10 +303,6 @@ public IssueType getElementType() {
return elementType;
}

public void setElementType(final IssueType elementType) {
this.elementType = elementType;
}

/**
* Returns the icon of the report. The icon might be used to customize reports in the UI.
*
Expand Down Expand Up @@ -304,8 +342,8 @@ public Report add(final Issue issue) {

/**
* Appends all the specified issues to the end of this report, preserving the order of the array elements.
* Duplicates will be skipped (the number of skipped elements is available using the method {@link
* #getDuplicatesSize()}).
* Duplicates will be skipped (the number of skipped elements is available using the method
* {@link #getDuplicatesSize()}).
*
* @param issue
* the first issue to append
Expand All @@ -326,8 +364,8 @@ public Report addAll(final Issue issue, final Issue... additionalIssues) {

/**
* Appends all of the specified issues to the end of this report, preserving the order of the array elements.
* Duplicates will be skipped (the number of skipped elements is available using the method {@link
* #getDuplicatesSize()}.
* Duplicates will be skipped (the number of skipped elements is available using the method
* {@link #getDuplicatesSize()}.
*
* @param issues
* the issues to append
Expand Down Expand Up @@ -406,8 +444,8 @@ List<Report> getSubReports() {
}

/**
* Called after deserialization to improve the memory usage and to initialize fields that have been introduced
* after the first release.
* Called after deserialization to improve the memory usage and to initialize fields that have been introduced after
* the first release.
*
* @return this
*/
Expand Down Expand Up @@ -487,7 +525,7 @@ public Issue findById(final UUID issueId) {
return stream().filter(issue -> issue.getId().equals(issueId))
.findAny()
.orElseThrow(() -> new NoSuchElementException(
"No issue found with id %s.".formatted(issueId)));
"No issue found with id %s.".formatted(issueId)));
}

/**
Expand Down Expand Up @@ -569,7 +607,8 @@ public Issue get(final int index) {
}

/**
* Returns the issues in this report that are part of modified code. This will include the issues of any sub-reports.
* Returns the issues in this report that are part of modified code. This will include the issues of any
* sub-reports.
*
* @return all issues in this report
*/
Expand Down Expand Up @@ -689,7 +728,8 @@ private boolean isEmptyOrDefault(final String value) {
private Optional<String> reportSeverity(final Severity severity) {
var size = getSizeOf(severity);
if (size > 0) {
return Optional.of(String.format(Locale.ENGLISH, "%s: %d", StringUtils.lowerCase(severity.getName()), size));
return Optional.of(
String.format(Locale.ENGLISH, "%s: %d", StringUtils.lowerCase(severity.getName()), size));
}
return Optional.empty();
}
Expand Down Expand Up @@ -935,8 +975,8 @@ public <T> Map<T, Integer> getPropertyCount(final Function<? super Issue, T> pro
}

/**
* Groups issues by a specified property. Returns the results as a mapping of property values to a new set of {@link
* Report} for this value.
* Groups issues by a specified property. Returns the results as a mapping of property values to a new set of
* {@link Report} for this value.
*
* @param propertyName
* the property to that selects the property to evaluate
Expand Down Expand Up @@ -981,7 +1021,7 @@ private void copyProperties(final Report source, final Report destination) {
destination.infoMessages.addAll(source.infoMessages);
destination.errorMessages.addAll(source.errorMessages);
destination.countersByKey = Stream.concat(
destination.countersByKey.entrySet().stream(), source.countersByKey.entrySet().stream())
destination.countersByKey.entrySet().stream(), source.countersByKey.entrySet().stream())
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue, Integer::sum));
}

Expand Down Expand Up @@ -1084,8 +1124,8 @@ public List<String> getErrorMessages() {
private List<String> mergeMessages(final List<String> thisMessages,
final Function<Report, List<String>> sumMessages) {
return Stream.concat(
subReports.stream().map(sumMessages).flatMap(Collection::stream),
thisMessages.stream())
subReports.stream().map(sumMessages).flatMap(Collection::stream),
thisMessages.stream())
.collect(Collectors.toList());
}

Expand Down Expand Up @@ -1380,7 +1420,7 @@ public static class IssueFilterBuilder {
private final Collection<Predicate<Issue>> includeFilters = new ArrayList<>();
private final Collection<Predicate<Issue>> excludeFilters = new ArrayList<>();

/** IssueType of the filter: include or exclude elements. */
/** Type of the filter: include or exclude elements. */
enum FilterType {
INCLUDE,
EXCLUDE
Expand Down Expand Up @@ -1660,7 +1700,7 @@ public IssueFilterBuilder setExcludeCategoryFilter(final String... patterns) {

//</editor-fold>

//<editor-fold desc="IssueType">
//<editor-fold desc="Type">

/**
* Add a new filter for {@code Issue::getCategory}.
Expand Down
6 changes: 0 additions & 6 deletions src/main/java/edu/hm/hafner/analysis/parser/ClairParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import edu.hm.hafner.analysis.Issue;
import edu.hm.hafner.analysis.IssueBuilder;
import edu.hm.hafner.analysis.Report;
import edu.hm.hafner.analysis.Report.IssueType;
import edu.hm.hafner.analysis.Severity;
import edu.umd.cs.findbugs.annotations.CheckForNull;

Expand All @@ -22,11 +21,6 @@ public class ClairParser extends JsonIssueParser {
@Serial
private static final long serialVersionUID = 371390072777545322L;

@Override
public IssueType getType() {
return IssueType.VULNERABILITY;
}

@Override
protected void parseJsonObject(final Report report, final JSONObject jsonReport, final IssueBuilder issueBuilder) {
var image = optStringIgnoreCase(jsonReport, "image");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ private String getCategory(final String line) {
else if (line.contains("does not support multiword aliases")) {
return "Multiword Aliases not Supported by Code Generation";
}
else if (line.contains("Unnecessary Data IssueType Conversion")) {
return "Unnecessary Data IssueType Conversion";
else if (line.contains("Unnecessary Data Type Conversion")) {
return "Unnecessary Data Type Conversion";
}
else if (line.contains("Cannot close the model")) {
return "Model Cannot be Closed";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import edu.hm.hafner.analysis.IssueBuilder;
import edu.hm.hafner.analysis.LookaheadParser;
import edu.hm.hafner.analysis.ParsingException;
import edu.hm.hafner.analysis.Report.IssueType;
import edu.hm.hafner.util.LookaheadStream;

import static j2html.TagCreator.*;
Expand Down Expand Up @@ -43,11 +42,6 @@ public ErrorProneParser() {
super(WARNINGS_PATTERN);
}

@Override
public IssueType getType() {
return IssueType.BUG;
}

@Override
protected Optional<Issue> createIssue(final Matcher matcher, final LookaheadStream lookahead,
final IssueBuilder builder) throws ParsingException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import edu.hm.hafner.analysis.Issue;
import edu.hm.hafner.analysis.IssueBuilder;
import edu.hm.hafner.analysis.LookaheadParser;
import edu.hm.hafner.analysis.Report.IssueType;
import edu.hm.hafner.analysis.Severity;
import edu.hm.hafner.analysis.util.IntegerParser;
import edu.hm.hafner.util.LookaheadStream;
Expand All @@ -34,11 +33,6 @@ public FlawfinderParser() {
super(FLAWFINDER_WARNING_PATTERN);
}

@Override
public IssueType getType() {
return IssueType.VULNERABILITY;
}

@Override
protected Optional<Issue> createIssue(final Matcher matcher, final LookaheadStream lookahead,
final IssueBuilder builder) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,6 @@ Optional<Issue> convertToIssue(final JSONObject jsonIssue, final IssueBuilder bu
if (jsonIssue.has(MODULE_NAME)) {
builder.setModuleName(jsonIssue.getString(MODULE_NAME));
}
if (jsonIssue.has(ORIGIN)) {
builder.setOrigin(jsonIssue.getString(ORIGIN));
}
if (jsonIssue.has(PACKAGE_NAME)) {
builder.setPackageName(jsonIssue.getString(PACKAGE_NAME));
}
Expand Down
Loading

0 comments on commit bb72ff7

Please sign in to comment.