Skip to content

Commit

Permalink
Merge pull request #1041 from jenkinsci/dependabot/maven/edu.hm.hafne…
Browse files Browse the repository at this point in the history
…r-codingstyle-pom-4.3.0

Bump edu.hm.hafner:codingstyle-pom from 3.43.0 to 4.3.0
  • Loading branch information
uhafner committed Apr 15, 2024
2 parents 2c6ce0f + ded0e94 commit 9777b63
Show file tree
Hide file tree
Showing 41 changed files with 132 additions and 101 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/quality-monitor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,12 @@ jobs:
{
"id": "checkstyle",
"name": "CheckStyle",
"pattern": "**/target/checkstyle-result.xml"
"pattern": "**/target/checkstyle-*/checkstyle-result.xml"
},
{
"id": "pmd",
"name": "PMD",
"pattern": "**/target/pmd.xml"
"pattern": "**/target/pmd-*/pmd.xml"
}
]
},
Expand Down
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>edu.hm.hafner</groupId>
<artifactId>codingstyle-pom</artifactId>
<version>3.43.0</version>
<version>4.5.0</version>
<relativePath />
</parent>

Expand Down Expand Up @@ -49,7 +49,7 @@
</developer>
</developers>

<url>https://www.cs.hm.edu/die_fakultaet/ansprechpartner/professoren/hafner/index.de.html</url>
<url>https://cs.hm.edu/~hafner</url>

<properties>
<scmTag>HEAD</scmTag>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ public FileReaderFactory(final Path file) {
this(file, null);
}

@SuppressWarnings("PMD.CloseResource")
@Override @MustBeClosed
public Reader create() {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ private String asHex(final byte[] bytes) {
hexChars[j * 2] = HEX_CHARACTERS[v >>> 4];
hexChars[j * 2 + 1] = HEX_CHARACTERS[v & 0x0F];
}
return new String(hexChars);
return String.valueOf(hexChars);
}

@VisibleForTesting
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 @@ -60,7 +60,7 @@ public static String getPropertyValueAsString(final Issue issue, final String pr
* @return the function that obtains the value
*/
public static Function<Issue, String> getPropertyValueGetter(final String propertyName) {
return issue -> Issue.getPropertyValueAsString(issue, propertyName);
return issue -> getPropertyValueAsString(issue, propertyName);
}

/**
Expand Down
9 changes: 3 additions & 6 deletions src/main/java/edu/hm/hafner/analysis/IssueDifference.java
Original file line number Diff line number Diff line change
Expand Up @@ -84,19 +84,16 @@ public IssueDifference(final Report currentIssues, final String referenceId,

private void findIssuesInChangedCode(final Map<String, Integer> includes) {
for (Entry<String, Integer> include : includes.entrySet()) {
newIssues.filter(issue -> filter(issue, include.getKey(), include.getValue()))
newIssues.filter(issue -> isInFileAtPosition(issue, include.getKey(), include.getValue()))
.stream()
.map(Issue::getId)
.map(newIssues::remove)
.forEach(newIssuesInChangedCode::add);
}
}

private boolean filter(final Issue issue, final String fileName, final int line) {
if (!issue.getFileName().endsWith(fileName)) {
return false;
}
return issue.affectsLine(line);
private boolean isInFileAtPosition(final Issue issue, final String fileName, final int line) {
return issue.getFileName().endsWith(fileName) && issue.affectsLine(line);

Check warning on line 96 in src/main/java/edu/hm/hafner/analysis/IssueDifference.java

View workflow job for this annotation

GitHub Actions / Quality Monitor

Not covered lines

Lines 86-96 are not covered by tests
}

private List<UUID> matchIssuesByEquals(final Report currentIssues) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,6 @@ public void markIssuesInModifiedCode(final Report report, final Map<String, Set<
private boolean affectsChangedLineInFile(final Issue issue, final String fileName, final Set<Integer> lines) {
var normalizedPath = PATH_UTIL.getRelativePath(fileName);

if (!issue.getFileName().endsWith(normalizedPath)) { // check only the suffix
return false;
}
return lines.stream().anyMatch(issue::affectsLine);
return issue.getFileName().endsWith(normalizedPath) && lines.stream().anyMatch(issue::affectsLine);
}
}
20 changes: 11 additions & 9 deletions src/main/java/edu/hm/hafner/analysis/LookaheadParser.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package edu.hm.hafner.analysis;

import java.util.ArrayDeque;
import java.util.Deque;
import java.util.Optional;
import java.util.Stack;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Stream;
Expand All @@ -12,9 +13,9 @@

/**
* Parses a report file line by line for issues using a pre-defined regular expression. If the regular expression
* matches then the abstract method {@link #createIssue(Matcher, LookaheadStream, IssueBuilder)} will be called. Sub
* classes need to provide an implementation that transforms the {@link Matcher} instance into a new issue. If required,
* sub classes may consume additional lines from the report file before control is handed back to the template method of
* matches then the abstract method {@link #createIssue(Matcher, LookaheadStream, IssueBuilder)} will be called.
* Subclasses need to provide an implementation that transforms the {@link Matcher} instance into a new issue. If required,
* subclasses may consume additional lines from the report file before control is handed back to the template method of
* this parser.
*
* @author Ullrich Hafner
Expand All @@ -38,7 +39,7 @@ public abstract class LookaheadParser extends IssueParser {

private final Pattern pattern;

private final Stack<String> recursiveDirectories;
private final Deque<String> recursiveDirectories;

/**
* Creates a new instance of {@link LookaheadParser}.
Expand All @@ -50,7 +51,7 @@ protected LookaheadParser(final String pattern) {
super();

this.pattern = Pattern.compile(pattern);
this.recursiveDirectories = new Stack<>();
this.recursiveDirectories = new ArrayDeque<>();
}

@Override
Expand All @@ -65,6 +66,7 @@ public Report parse(final ReaderFactory readerFactory) throws ParsingException,
return postProcess(report);
}

@SuppressWarnings("PMD.DoNotUseThreads")
private void parse(final Report report, final LookaheadStream lookahead) {
try (IssueBuilder builder = new IssueBuilder()) {
while (lookahead.hasNext()) {
Expand Down Expand Up @@ -107,7 +109,7 @@ protected void preprocessLine(final String line) {
* @return The new directory to change to
*/
private String enterDirectory(final String line, final Report log) {
extractDirectory(line, ENTERING_DIRECTORY_PATH, log).map(recursiveDirectories::push);
extractDirectory(line, ENTERING_DIRECTORY_PATH, log).ifPresent(recursiveDirectories::push);
return recursiveDirectories.isEmpty() ? NO_DIRECTORY : recursiveDirectories.peek();
}

Expand All @@ -118,9 +120,9 @@ private String enterDirectory(final String line, final Report log) {
* @return The last directory seen, or an empty String if we have returned to the beginning
*/
private String leaveDirectory() {
if (!recursiveDirectories.empty()) {
if (!recursiveDirectories.isEmpty()) {
recursiveDirectories.pop();
if (!recursiveDirectories.empty()) {
if (!recursiveDirectories.isEmpty()) {
return recursiveDirectories.peek();
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/edu/hm/hafner/analysis/ModuleDetector.java
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public String guessModuleName(final String originalFileName) {
* @return the found files (as absolute paths)
*/
private List<String> find(final Path path) {
ArrayList<String> absoluteFileNames = new ArrayList<>();
List<String> absoluteFileNames = new ArrayList<>();

for (AbstractModuleDetector moduleDetector : moduleDetectors) {
String[] relativeFileNames = factory.find(path, moduleDetector.getPattern());
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/edu/hm/hafner/analysis/PackageNameResolver.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;

import edu.hm.hafner.util.VisibleForTesting;
import static edu.hm.hafner.analysis.PackageDetectors.*;

import static edu.hm.hafner.analysis.PackageDetectors.*;
import static java.util.function.Function.*;

/**
Expand All @@ -29,7 +30,7 @@ public PackageNameResolver() {

@VisibleForTesting
PackageNameResolver(final FileSystem fileSystem) {
ArrayList<AbstractPackageDetector> detectors = new ArrayList<>(Arrays.asList(
List<AbstractPackageDetector> detectors = new ArrayList<>(Arrays.asList(
new JavaPackageDetector(fileSystem),
new CSharpNamespaceDetector(fileSystem),
new KotlinPackageDetector(fileSystem)
Expand Down
16 changes: 11 additions & 5 deletions src/main/java/edu/hm/hafner/analysis/Report.java
Original file line number Diff line number Diff line change
Expand Up @@ -358,10 +358,14 @@ public Report addAll(final Report... reports) {
}

private boolean contains(final Issue issue) {
if (elements.contains(issue)) {
return true;
}
return subReports.stream().map(r -> r.contains(issue)).reduce(Boolean::logicalOr).orElse(false);
return elements.contains(issue) || subReportsContains(issue);
}

private Boolean subReportsContains(final Issue issue) {
return subReports.stream()
.map(r -> r.contains(issue))
.reduce(Boolean::logicalOr)
.orElse(false);
}

@VisibleForTesting
Expand Down Expand Up @@ -1089,6 +1093,8 @@ private void writeLongString(final ObjectOutputStream output, final String value
}

@SuppressWarnings("unchecked")
@SuppressFBWarnings(value = "MC_OVERRIDABLE_METHOD_CALL_IN_READ_OBJECT",
justification = "False positive, the overridden method is in already initialized objects")
private void readObject(final ObjectInputStream input) throws IOException, ClassNotFoundException {
elements = new LinkedHashSet<>();
readIssues(input, input.readInt());
Expand Down Expand Up @@ -1157,7 +1163,7 @@ private String readLongString(final ObjectInputStream input) throws IOException
for (int j = 0; j < chars.length; j++) {
chars[j] = input.readChar();
}
return new String(chars);
return String.valueOf(chars);
}

/**
Expand Down
12 changes: 6 additions & 6 deletions src/main/java/edu/hm/hafner/analysis/Severity.java
Original file line number Diff line number Diff line change
Expand Up @@ -96,18 +96,18 @@ public static Severity valueOf(@CheckForNull final String severity, final Severi
*/
public static Severity guessFromString(@CheckForNull final String severity) {
if (StringUtils.containsAnyIgnoreCase(severity, "error", "severe", "critical", "fatal")) {
return Severity.ERROR;
return ERROR;
}
if (StringUtils.containsAnyIgnoreCase(severity, "info", "note", "low")) {
return Severity.WARNING_LOW;
return WARNING_LOW;
}
if (StringUtils.containsAnyIgnoreCase(severity, "warning", "medium")) {
return Severity.WARNING_NORMAL;
return WARNING_NORMAL;
}
if (StringUtils.containsIgnoreCase(severity, "high")) {
return Severity.WARNING_HIGH;
return WARNING_HIGH;
}
return Severity.WARNING_LOW;
return WARNING_LOW;
}

/**
Expand All @@ -120,7 +120,7 @@ public static Severity guessFromString(@CheckForNull final String severity) {
*/
public static Collection<Severity> collectSeveritiesFrom(final Severity minimumSeverity) {
List<Severity> priorities = new ArrayList<>();
priorities.add(Severity.ERROR);
priorities.add(ERROR);
if (WARNING_HIGH.equals(minimumSeverity)) {
priorities.add(WARNING_HIGH);
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/edu/hm/hafner/analysis/parser/AjcParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ private void fillMessageAndCategory(final IssueBuilder builder, final String lin
category = Categories.DEPRECATION;
}
else if (line.contains("adviceDidNotMatch")) {
category = AjcParser.ADVICE;
category = ADVICE;
}
else {
category = "";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import edu.hm.hafner.analysis.ParsingException;
import edu.hm.hafner.analysis.Severity;
import edu.hm.hafner.util.LookaheadStream;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;

import static edu.hm.hafner.analysis.util.IntegerParser.*;

Expand Down Expand Up @@ -40,7 +41,7 @@ public DrMemoryParser() {
super(DR_MEMORY_WARNING_PATTERN);
}

@Override
@Override @SuppressFBWarnings(value = "POTENTIAL_XML_INJECTION", justification = "Message is cleaned in UI")
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 @@ -19,6 +19,8 @@ public class IarCstatParser extends LookaheadParser {

private static final String IAR_WARNING_PATTERN = ANT_TASK
+ "(?:\"?(.*?)\"?[\\(,](\\d+)\\)?\\s+)?(Severity-(?:Low|Medium|High))\\[(\\S+)\\]:(.*)$";
private static final String SEVERITY_LOW = "Severity-Low";
private static final String SEVERITY_HIGH = "Severity-High";

/**
* Creates a new instance of {@link IarCstatParser}.
Expand All @@ -45,10 +47,10 @@ protected Optional<Issue> createIssue(final Matcher matcher, final LookaheadStre

private Severity mapSeverity(final String category) {
Severity severity;
if ("Severity-Low".equals(category)) {
if (SEVERITY_LOW.equals(category)) {
severity = Severity.WARNING_LOW;
}
else if ("Severity-High".equals(category)) {
else if (SEVERITY_HIGH.equals(category)) {
severity = Severity.WARNING_HIGH;
}
else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import java.util.List;
import java.util.Optional;

import edu.hm.hafner.analysis.util.IntegerParser;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.text.StringEscapeUtils;
import org.w3c.dom.Document;
Expand All @@ -16,6 +15,7 @@
import edu.hm.hafner.analysis.ReaderFactory;
import edu.hm.hafner.analysis.Report;
import edu.hm.hafner.analysis.Severity;
import edu.hm.hafner.analysis.util.IntegerParser;
import edu.hm.hafner.analysis.util.XmlElementUtil;

/**
Expand All @@ -26,6 +26,8 @@
public class IdeaInspectionParser extends IssueParser {
private static final long serialVersionUID = 3307389086106375473L;
private static final String PATH_PREFIX = "file://";
private static final String WARNING = "WARNING";
private static final String ERROR = "ERROR";

@Override
public Report parse(final ReaderFactory readerFactory) throws ParsingException {
Expand Down Expand Up @@ -58,10 +60,10 @@ private Report parseProblems(final List<Element> elements) {

private Severity getPriority(final String severity) {
Severity priority = Severity.WARNING_LOW;
if ("WARNING".equals(severity)) {
if (WARNING.equals(severity)) {
priority = Severity.WARNING_NORMAL;
}
else if ("ERROR".equals(severity)) {
else if (ERROR.equals(severity)) {

Check warning on line 66 in src/main/java/edu/hm/hafner/analysis/parser/IdeaInspectionParser.java

View workflow job for this annotation

GitHub Actions / Quality Monitor

Partially covered line

Line 66 is only partially covered, one branch is missing
priority = Severity.WARNING_HIGH;

Check warning on line 67 in src/main/java/edu/hm/hafner/analysis/parser/IdeaInspectionParser.java

View workflow job for this annotation

GitHub Actions / Quality Monitor

Not covered line

Line 67 is not covered by tests
}
return priority;
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/edu/hm/hafner/analysis/parser/LintParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
*/
public class LintParser extends IssueParser {
private static final long serialVersionUID = 3341424685245834156L;
private static final String FILE = "file";

@Override
public Report parse(final ReaderFactory readerFactory) throws ParsingException {
Expand Down Expand Up @@ -56,7 +57,7 @@ public void startElement(final String namespaceURI,
return; // Start element, good to skip
}

if ("file".equals(key)) {
if (FILE.equals(key)) {
fileName = atts.getValue("name");
return;
}
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/edu/hm/hafner/analysis/parser/MentorParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import edu.hm.hafner.analysis.IssueBuilder;
import edu.hm.hafner.analysis.LookaheadParser;
import edu.hm.hafner.util.LookaheadStream;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;

/**
* Parser for Mentor Graphics Modelsim/Questa Simulator.
Expand Down Expand Up @@ -125,6 +126,7 @@ private void parseVsimMessage(final LookaheadStream lookahead, final IssueBuilde
builder.setMessage(parsedMessage);
}

@SuppressFBWarnings(value = "POTENTIAL_XML_INJECTION", justification = "Message is cleaned in UI")
private String parseSimTime(final LookaheadStream lookahead, final IssueBuilder builder) {
StringBuilder description = new StringBuilder();
String timeLine = "";
Expand Down
Loading

0 comments on commit 9777b63

Please sign in to comment.