diff --git a/pom.xml b/pom.xml index 05004e96b..9c7cacde4 100644 --- a/pom.xml +++ b/pom.xml @@ -292,6 +292,21 @@ + + org.openrewrite.maven + rewrite-maven-plugin + ${rewrite-maven-plugin.version} + + + org.openrewrite.java.migrate.UpgradeToJava17 + org.openrewrite.java.migrate.util.SequencedCollection + org.openrewrite.java.migrate.lang.var.UseVarForObject + org.openrewrite.java.migrate.net.JavaNetAPIs + org.openrewrite.java.migrate.util.JavaUtilAPIs + org.openrewrite.java.migrate.lang.StringRulesRecipes + + + org.owasp dependency-check-maven diff --git a/src/main/java/edu/hm/hafner/analysis/AbstractPackageDetector.java b/src/main/java/edu/hm/hafner/analysis/AbstractPackageDetector.java index 92fb7983b..e4f1ac274 100644 --- a/src/main/java/edu/hm/hafner/analysis/AbstractPackageDetector.java +++ b/src/main/java/edu/hm/hafner/analysis/AbstractPackageDetector.java @@ -46,7 +46,7 @@ abstract class AbstractPackageDetector { */ public String detectPackageName(final String fileName, final Charset charset) { if (accepts(fileName)) { - try (InputStream stream = fileSystem.openFile(fileName)) { + try (var stream = fileSystem.openFile(fileName)) { return detectPackageName(stream, charset); } catch (IOException | InvalidPathException ignore) { @@ -58,7 +58,7 @@ public String detectPackageName(final String fileName, final Charset charset) { @VisibleForTesting String detectPackageName(final InputStream stream, final Charset charset) throws IOException { - try (BufferedReader buffer = new BufferedReader(new InputStreamReader(BOMInputStream.builder().setInputStream(stream).get(), charset))) { + try (var buffer = new BufferedReader(new InputStreamReader(BOMInputStream.builder().setInputStream(stream).get(), charset))) { return detectPackageName(buffer.lines()); } } @@ -73,7 +73,7 @@ String detectPackageName(final InputStream stream, final Charset charset) throws * @return the detected package or namespace name */ String detectPackageName(final Stream lines) { - Pattern pattern = getPattern(); + var pattern = getPattern(); return lines.map(pattern::matcher) .filter(Matcher::matches) .findFirst() diff --git a/src/main/java/edu/hm/hafner/analysis/AntModuleDetector.java b/src/main/java/edu/hm/hafner/analysis/AntModuleDetector.java index 72b32926b..bec77c18d 100644 --- a/src/main/java/edu/hm/hafner/analysis/AntModuleDetector.java +++ b/src/main/java/edu/hm/hafner/analysis/AntModuleDetector.java @@ -44,15 +44,15 @@ void collectProjects(final Map mapping, final List proje * @return the project name or an empty string if the name could not be resolved */ private String parseBuildXml(final String buildXml) { - try (InputStream file = getFactory().open(buildXml)) { + try (var file = getFactory().open(buildXml)) { var digester = new SecureDigester(ModuleDetector.class); digester.push(new StringBuilder()); - String xPath = "project"; + var xPath = "project"; digester.addCallMethod(xPath, "append", 1); digester.addCallParam(xPath, 0, "name"); - StringBuilder result = digester.parse(file); + var result = digester.parse(file); return result.toString(); } catch (IOException | SAXException | InvalidPathException ignored) { diff --git a/src/main/java/edu/hm/hafner/analysis/Categories.java b/src/main/java/edu/hm/hafner/analysis/Categories.java index d4965ae83..53046396d 100644 --- a/src/main/java/edu/hm/hafner/analysis/Categories.java +++ b/src/main/java/edu/hm/hafner/analysis/Categories.java @@ -49,7 +49,7 @@ public static String guessCategory(@CheckForNull final String message) { * @return the actual category */ public static String guessCategoryIfEmpty(@CheckForNull final String category, @CheckForNull final String message) { - String capitalized = StringUtils.capitalize(category); + var capitalized = StringUtils.capitalize(category); if (StringUtils.isEmpty(capitalized)) { capitalized = guessCategory(message); } diff --git a/src/main/java/edu/hm/hafner/analysis/FileNameResolver.java b/src/main/java/edu/hm/hafner/analysis/FileNameResolver.java index b0505d119..4eaec616e 100644 --- a/src/main/java/edu/hm/hafner/analysis/FileNameResolver.java +++ b/src/main/java/edu/hm/hafner/analysis/FileNameResolver.java @@ -47,7 +47,7 @@ public void run(final Report report, final String sourceDirectoryPrefix, .filter(entry -> PATH_UTIL.exists(entry.getValue(), sourceDirectoryPrefix)) .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); - try (IssueBuilder builder = new IssueBuilder()) { + try (var builder = new IssueBuilder()) { report.stream() .filter(issue -> pathMapping.containsKey(issue.getFileName())) .forEach(issue -> issue.setFileName(sourceDirectoryPrefix, diff --git a/src/main/java/edu/hm/hafner/analysis/FileReaderFactory.java b/src/main/java/edu/hm/hafner/analysis/FileReaderFactory.java index 790cf1fc0..a2569b26c 100644 --- a/src/main/java/edu/hm/hafner/analysis/FileReaderFactory.java +++ b/src/main/java/edu/hm/hafner/analysis/FileReaderFactory.java @@ -80,9 +80,9 @@ public Reader create() { @CheckForNull private Charset detectCharset(final InputStream inputStream) throws IOException { - try (Reader reader = new InputStreamReader(inputStream, StandardCharsets.US_ASCII)) { - XMLStreamReader xmlStreamReader = new SecureXmlParserFactory().createXmlStreamReader(reader); - String encodingTitle = xmlStreamReader.getCharacterEncodingScheme(); + try (var reader = new InputStreamReader(inputStream, StandardCharsets.US_ASCII)) { + var xmlStreamReader = new SecureXmlParserFactory().createXmlStreamReader(reader); + var encodingTitle = xmlStreamReader.getCharacterEncodingScheme(); if (encodingTitle != null) { return Charset.forName(encodingTitle); } diff --git a/src/main/java/edu/hm/hafner/analysis/FingerprintGenerator.java b/src/main/java/edu/hm/hafner/analysis/FingerprintGenerator.java index 00d466785..6b9c52a62 100644 --- a/src/main/java/edu/hm/hafner/analysis/FingerprintGenerator.java +++ b/src/main/java/edu/hm/hafner/analysis/FingerprintGenerator.java @@ -64,10 +64,10 @@ private boolean hasAllowedExtension(final String fileName) { private int computeFingerprint(final Issue issue, final FullTextFingerprint algorithm, final Charset charset, final FilteredLog log) { - String absolutePath = issue.getAbsolutePath(); + var absolutePath = issue.getAbsolutePath(); try { if (issue.hasFileName()) { - String digest = algorithm.compute(absolutePath, issue.getLineStart(), charset); + var digest = algorithm.compute(absolutePath, issue.getLineStart(), charset); issue.setFingerprint(digest); return 1; } diff --git a/src/main/java/edu/hm/hafner/analysis/FullTextFingerprint.java b/src/main/java/edu/hm/hafner/analysis/FullTextFingerprint.java index d6d37c5d5..a6b64eb18 100644 --- a/src/main/java/edu/hm/hafner/analysis/FullTextFingerprint.java +++ b/src/main/java/edu/hm/hafner/analysis/FullTextFingerprint.java @@ -4,7 +4,7 @@ import java.nio.charset.Charset; import java.nio.file.Files; import java.nio.file.InvalidPathException; -import java.nio.file.Paths; +import java.nio.file.Path; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; import java.util.Iterator; @@ -83,7 +83,7 @@ String getFallbackFingerprint(final String fileName) { @VisibleForTesting String createFingerprint(final int line, final Stream lines, final Charset charset) { - String context = extractContext(line, lines.iterator()); + var context = extractContext(line, lines.iterator()); lines.close(); digest.update(context.getBytes(charset)); @@ -137,7 +137,7 @@ static class FileSystem { @MustBeClosed Stream readLinesFromFile(final String fileName, final Charset charset) throws IOException, InvalidPathException { - return Files.lines(Paths.get(fileName), charset); + return Files.lines(Path.of(fileName), charset); } } } diff --git a/src/main/java/edu/hm/hafner/analysis/GradleModuleDetector.java b/src/main/java/edu/hm/hafner/analysis/GradleModuleDetector.java index 60622b3a7..05303735e 100644 --- a/src/main/java/edu/hm/hafner/analysis/GradleModuleDetector.java +++ b/src/main/java/edu/hm/hafner/analysis/GradleModuleDetector.java @@ -59,8 +59,8 @@ else if (fileName.endsWith(SETTINGS_GRADLE) || fileName.endsWith(SETTINGS_GRADLE * @return the project name or an empty string if the name could not be resolved */ private String parseGradle(final String buildScript) { - String basePath = FilenameUtils.getPathNoEndSeparator(buildScript); - String parentDirName = FilenameUtils.getName(basePath); + var basePath = FilenameUtils.getPathNoEndSeparator(buildScript); + var parentDirName = FilenameUtils.getName(basePath); return StringUtils.trimToEmpty(parentDirName); } @@ -75,10 +75,10 @@ private String parseGradle(final String buildScript) { private String parseGradleSettings(final String settingsFile) { String name = null; - try (InputStream input = getFactory().open(settingsFile); - Scanner scan = new Scanner(input, "UTF-8")) { + try (var input = getFactory().open(settingsFile); + var scan = new Scanner(input, "UTF-8")) { while (scan.hasNextLine()) { - String line = scan.findInLine(RE_GRADLE_SET_PROJECT_NAME); + var line = scan.findInLine(RE_GRADLE_SET_PROJECT_NAME); if (line != null) { name = scan.match().group(2); diff --git a/src/main/java/edu/hm/hafner/analysis/Issue.java b/src/main/java/edu/hm/hafner/analysis/Issue.java index 4d803513b..f4cb3229a 100644 --- a/src/main/java/edu/hm/hafner/analysis/Issue.java +++ b/src/main/java/edu/hm/hafner/analysis/Issue.java @@ -488,7 +488,7 @@ TreeString getFileNameTreeString() { */ public String getFolder() { try { - String folder = FilenameUtils.getPath(getFileName()); + var folder = FilenameUtils.getPath(getFileName()); if (StringUtils.isBlank(folder)) { return UNDEFINED; } @@ -905,7 +905,7 @@ public boolean equals(@CheckForNull final Object o) { return false; } - Issue issue = (Issue) o; + var issue = (Issue) o; if (lineStart != issue.lineStart) { return false; diff --git a/src/main/java/edu/hm/hafner/analysis/IssueBuilder.java b/src/main/java/edu/hm/hafner/analysis/IssueBuilder.java index 2ae76a2be..bd6cf5c46 100644 --- a/src/main/java/edu/hm/hafner/analysis/IssueBuilder.java +++ b/src/main/java/edu/hm/hafner/analysis/IssueBuilder.java @@ -534,7 +534,7 @@ public IssueBuilder copy(final Issue copy) { * @return the created issue */ public Issue build() { - Issue issue = buildWithConstructor(); + var issue = buildWithConstructor(); id = UUID.randomUUID(); // make sure that multiple invocations will create different IDs return issue; } @@ -546,7 +546,7 @@ public Issue build() { * @return the created issue */ public Issue buildAndClean() { - Issue issue = buildWithConstructor(); + var issue = buildWithConstructor(); clean(); return issue; } @@ -566,7 +566,7 @@ private Issue buildWithConstructor() { @SuppressFBWarnings(value = "NP_NULL_ON_SOME_PATH", justification = "False positive, `lineRanges != null` avoids a NullPointerException") private void cleanupLineRanges() { if (lineRanges != null && !lineRanges.isEmpty()) { - LineRange firstRange = lineRanges.get(0); + var firstRange = lineRanges.get(0); if (lineStart == 0) { this.lineStart = firstRange.getStart(); this.lineEnd = firstRange.getEnd(); diff --git a/src/main/java/edu/hm/hafner/analysis/IssueDifference.java b/src/main/java/edu/hm/hafner/analysis/IssueDifference.java index b3c1ba782..195bd1620 100644 --- a/src/main/java/edu/hm/hafner/analysis/IssueDifference.java +++ b/src/main/java/edu/hm/hafner/analysis/IssueDifference.java @@ -72,7 +72,7 @@ public IssueDifference(final Report currentIssues, final String referenceId, } List removed = matchIssuesByEquals(currentIssues); - Report secondPass = currentIssues.copy(); + var secondPass = currentIssues.copy(); removed.forEach(secondPass::remove); matchIssuesByFingerprint(secondPass); @@ -128,8 +128,8 @@ private void removeIssueFromMap(final Map> map, final K key, } private UUID remove(final Issue current, final Issue oldIssue) { - UUID id = current.getId(); - Issue issueWithLatestProperties = newIssues.remove(id); + var id = current.getId(); + var issueWithLatestProperties = newIssues.remove(id); issueWithLatestProperties.setReference(oldIssue.getReference()); outstandingIssues.add(issueWithLatestProperties); fixedIssues.remove(oldIssue.getId()); diff --git a/src/main/java/edu/hm/hafner/analysis/IssueParser.java b/src/main/java/edu/hm/hafner/analysis/IssueParser.java index bd1a78478..1641161b1 100644 --- a/src/main/java/edu/hm/hafner/analysis/IssueParser.java +++ b/src/main/java/edu/hm/hafner/analysis/IssueParser.java @@ -68,7 +68,7 @@ public abstract class IssueParser implements Serializable { * Signals that the user has aborted the parsing */ public Report parseFile(final ReaderFactory readerFactory) throws ParsingException, ParsingCanceledException { - Report report = parse(readerFactory); + var report = parse(readerFactory); report.setOriginReportFile(readerFactory.getFileName()); return report; } diff --git a/src/main/java/edu/hm/hafner/analysis/LookaheadParser.java b/src/main/java/edu/hm/hafner/analysis/LookaheadParser.java index dccc533a9..ebef38c3d 100644 --- a/src/main/java/edu/hm/hafner/analysis/LookaheadParser.java +++ b/src/main/java/edu/hm/hafner/analysis/LookaheadParser.java @@ -60,7 +60,7 @@ protected LookaheadParser(final String pattern) { public Report parse(final ReaderFactory readerFactory) throws ParsingException, ParsingCanceledException { var report = new Report(); try (Stream lines = readerFactory.readStream()) { - try (LookaheadStream lookahead = new LookaheadStream(lines, readerFactory.getFileName())) { + try (var lookahead = new LookaheadStream(lines, readerFactory.getFileName())) { parse(report, lookahead); } } @@ -70,13 +70,13 @@ public Report parse(final ReaderFactory readerFactory) throws ParsingException, @SuppressWarnings("PMD.DoNotUseThreads") private void parse(final Report report, final LookaheadStream lookahead) { - try (IssueBuilder builder = new IssueBuilder()) { + try (var builder = new IssueBuilder()) { while (lookahead.hasNext()) { - String line = lookahead.next(); + var line = lookahead.next(); handleDirectoryChanges(builder, line, report); preprocessLine(line); if (isLineInteresting(line)) { - Matcher matcher = pattern.matcher(line); + var matcher = pattern.matcher(line); if (matcher.find()) { createIssue(matcher, lookahead, builder).ifPresent(report::add); } @@ -174,10 +174,10 @@ private Optional extractDirectory(final String line, final Pattern makeP throws ParsingException { if (!makePath.toString().contains("")) { throw new IllegalArgumentException( - String.format("%s does not contain a capture group named 'dir'", makePath)); + "%s does not contain a capture group named 'dir'".formatted(makePath)); } - Matcher makeLineMatcher = makePath.matcher(line); + var makeLineMatcher = makePath.matcher(line); if (makeLineMatcher.matches()) { return Optional.of(removeHyphen(makeLineMatcher.group("dir"))); } @@ -239,7 +239,7 @@ protected Report postProcess(final Report report) { * @return directory path without leading or trailing hyphen */ private String removeHyphen(final String dir) { - String path = dir; + var path = dir; path = StringUtils.stripStart(path, HYPHEN); path = StringUtils.stripEnd(path, HYPHEN); return path; diff --git a/src/main/java/edu/hm/hafner/analysis/MavenModuleDetector.java b/src/main/java/edu/hm/hafner/analysis/MavenModuleDetector.java index b871615f7..d96c191c4 100644 --- a/src/main/java/edu/hm/hafner/analysis/MavenModuleDetector.java +++ b/src/main/java/edu/hm/hafner/analysis/MavenModuleDetector.java @@ -44,19 +44,19 @@ public void collectProjects(final Map mapping, final List createFilesToModuleMapping(final Path workspace) { * @return a module name or an empty string */ public String guessModuleName(final String originalFileName) { - String fullPath = originalFileName.replace('\\', '/'); + var fullPath = originalFileName.replace('\\', '/'); - String guessedModule = StringUtils.EMPTY; + var guessedModule = StringUtils.EMPTY; for (String path : prefixes) { if (fullPath.startsWith(path) && fileNameToModuleName.containsKey(path)) { guessedModule = fileNameToModuleName.get(path); @@ -111,9 +111,9 @@ private List find(final Path path) { List absoluteFileNames = new ArrayList<>(); for (AbstractModuleDetector moduleDetector : moduleDetectors) { - String[] relativeFileNames = factory.find(path, moduleDetector.getPattern()); + var relativeFileNames = factory.find(path, moduleDetector.getPattern()); for (String relativeFileName : relativeFileNames) { - String relativePath = normalizePath(relativeFileName); + var relativePath = normalizePath(relativeFileName); if (relativePath.startsWith(SLASH)) { absoluteFileNames.add(relativePath); } diff --git a/src/main/java/edu/hm/hafner/analysis/OsgiModuleDetector.java b/src/main/java/edu/hm/hafner/analysis/OsgiModuleDetector.java index ac6077246..3e803bc84 100644 --- a/src/main/java/edu/hm/hafner/analysis/OsgiModuleDetector.java +++ b/src/main/java/edu/hm/hafner/analysis/OsgiModuleDetector.java @@ -52,11 +52,11 @@ public void collectProjects(final Map mapping, final List packageDetectors.detectPackageName(fileName, charset))); - try (IssueBuilder builder = new IssueBuilder()) { + try (var builder = new IssueBuilder()) { report.stream().forEach(issue -> { if (!issue.hasPackageName()) { issue.setPackageName(builder.internPackageName(packagesOfFiles.get(issue.getAbsolutePath()))); diff --git a/src/main/java/edu/hm/hafner/analysis/ParsingException.java b/src/main/java/edu/hm/hafner/analysis/ParsingException.java index e6c7da68e..49aec8c73 100644 --- a/src/main/java/edu/hm/hafner/analysis/ParsingException.java +++ b/src/main/java/edu/hm/hafner/analysis/ParsingException.java @@ -42,7 +42,7 @@ public ParsingException(final Throwable cause) { */ @FormatMethod public ParsingException(final Throwable cause, final String messageFormat, final Object... args) { - super(createMessage(cause, String.format(messageFormat, args)), cause); + super(createMessage(cause, messageFormat.formatted(args)), cause); } /** @@ -60,11 +60,11 @@ public ParsingException(final Throwable cause, final String messageFormat, final */ @FormatMethod public ParsingException(final String messageFormat, final Object... args) { - super(String.format(messageFormat, args)); + super(messageFormat.formatted(args)); } private static String createMessage(final Throwable cause, final String message) { - return String.format("%s%n%s%n%s", message, + return "%s%n%s%n%s".formatted(message, ExceptionUtils.getMessage(cause), ExceptionUtils.getStackTrace(cause)); } } diff --git a/src/main/java/edu/hm/hafner/analysis/ReaderFactory.java b/src/main/java/edu/hm/hafner/analysis/ReaderFactory.java index d3ac9aad0..619e5bca0 100644 --- a/src/main/java/edu/hm/hafner/analysis/ReaderFactory.java +++ b/src/main/java/edu/hm/hafner/analysis/ReaderFactory.java @@ -141,7 +141,7 @@ public String readString() { * if the file could not be parsed */ public Document readDocument() { - try (Reader reader = create()) { + try (var reader = create()) { var parserFactory = new SecureXmlParserFactory(); return parserFactory.readDocument(reader, getCharset()); } @@ -169,7 +169,7 @@ public Charset getCharset() { * if the file could not be parsed */ public void parse(final DefaultHandler handler) { - try (Reader reader = create()) { + try (var reader = create()) { new SecureXmlParserFactory().parse(reader, getCharset(), handler); } catch (IOException | SecureXmlParserFactory.ParsingException exception) { diff --git a/src/main/java/edu/hm/hafner/analysis/Report.java b/src/main/java/edu/hm/hafner/analysis/Report.java index 0124ad008..f34981de2 100644 --- a/src/main/java/edu/hm/hafner/analysis/Report.java +++ b/src/main/java/edu/hm/hafner/analysis/Report.java @@ -352,7 +352,7 @@ public Report addAll(final Report... reports) { } for (Report report : reportsToAdd) { - Report copyWithoutDuplicates = report.copyEmptyInstance(); + var copyWithoutDuplicates = report.copyEmptyInstance(); for (Issue issue : report) { if (contains(issue)) { duplicatesSize++; // elements are marked as duplicate if the fingerprint is different @@ -419,7 +419,7 @@ Issue remove(final UUID issueId) { if (issue.isPresent()) { return issue.get(); } - throw new NoSuchElementException(String.format("No removed found with id %s.", issueId)); + throw new NoSuchElementException("No removed found with id %s.".formatted(issueId)); } private Optional removeIfContained(final UUID issueId) { @@ -459,7 +459,7 @@ public Issue findById(final UUID issueId) { return stream().filter(issue -> issue.getId().equals(issueId)) .findAny() .orElseThrow(() -> new NoSuchElementException( - String.format("No issue found with id %s.", issueId))); + "No issue found with id %s.".formatted(issueId))); } /** @@ -483,7 +483,7 @@ public Set findByProperty(final Predicate criterion) { * @return the found issues */ public Report filter(final Predicate criterion) { - Report filtered = copyEmptyInstance(); + var filtered = copyEmptyInstance(); filtered.addAll(elements.stream().filter(criterion).collect(Collectors.toList())); for (Report subReport : subReports) { filtered.addAll(subReport.filter(criterion)); @@ -921,7 +921,7 @@ public void mergeLogMessages(final FilteredLog log) { */ @FormatMethod public void logInfo(final String format, final Object... args) { - infoMessages.add(String.format(format, args)); + infoMessages.add(format.formatted(args)); } /** @@ -938,7 +938,7 @@ public void logInfo(final String format, final Object... args) { */ @FormatMethod public void logError(final String format, final Object... args) { - errorMessages.add(String.format(format, args)); + errorMessages.add(format.formatted(args)); } /** @@ -1103,24 +1103,24 @@ private void readObject(final ObjectInputStream input) throws IOException, Class private void readIssues(final ObjectInputStream input, final int size) throws IOException, ClassNotFoundException { var builder = new TreeStringBuilder(); for (int i = 0; i < size; i++) { - String path = input.readUTF(); - TreeString fileName = builder.intern(input.readUTF()); + var path = input.readUTF(); + var fileName = builder.intern(input.readUTF()); int lineStart = input.readInt(); int lineEnd = input.readInt(); int columnStart = input.readInt(); int columnEnd = input.readInt(); var lineRanges = (LineRangeList) input.readObject(); - String category = input.readUTF(); - String type = input.readUTF(); + var category = input.readUTF(); + var type = input.readUTF(); var packageName = builder.intern(input.readUTF()); - String moduleName = input.readUTF(); + var moduleName = input.readUTF(); var severity = Severity.valueOf(input.readUTF()); var message = builder.intern(readLongString(input)); - String description = readLongString(input); - String origin = input.readUTF(); - String originName = input.readUTF(); - String reference = input.readUTF(); - String fingerprint = input.readUTF(); + var description = readLongString(input); + var origin = input.readUTF(); + var originName = input.readUTF(); + var reference = input.readUTF(); + var fingerprint = input.readUTF(); var additionalProperties = (Serializable) input.readObject(); var uuid = (UUID) input.readObject(); @@ -1161,7 +1161,7 @@ public String getNameOfOrigin(final String origin) { } for (Report subReport : subReports) { - String nameOfSubReport = subReport.getNameOfOrigin(origin); + var nameOfSubReport = subReport.getNameOfOrigin(origin); if (!DEFAULT_ID.equals(nameOfSubReport)) { return nameOfSubReport; } @@ -1654,7 +1654,7 @@ public IssueFilterBuilder setExcludeMessageFilter(final String... patterns) { } private void addMessageFilter(final Collection patterns, final FilterType filterType) { - addNewFilter(patterns, issue -> String.format("%s%n%s", issue.getMessage(), issue.getDescription()), + addNewFilter(patterns, issue -> "%s%n%s".formatted(issue.getMessage(), issue.getDescription()), filterType); } // diff --git a/src/main/java/edu/hm/hafner/analysis/Severity.java b/src/main/java/edu/hm/hafner/analysis/Severity.java index cf14228a8..5faa530dd 100644 --- a/src/main/java/edu/hm/hafner/analysis/Severity.java +++ b/src/main/java/edu/hm/hafner/analysis/Severity.java @@ -3,9 +3,7 @@ import java.io.Serial; import java.io.Serializable; import java.util.ArrayList; -import java.util.Arrays; import java.util.Collection; -import java.util.Collections; import java.util.LinkedHashSet; import java.util.List; import java.util.Objects; @@ -41,8 +39,7 @@ public class Severity implements Serializable { /** A warning with priority low. Mapping of warning priorities is determined by the corresponding tool. */ public static final Severity WARNING_LOW = new Severity("LOW"); - private static final Set ALL_SEVERITIES = Collections.unmodifiableSet(new LinkedHashSet<>( - Arrays.asList(ERROR, WARNING_HIGH, WARNING_NORMAL, WARNING_LOW))); + private static final Set ALL_SEVERITIES = Set.of(ERROR, WARNING_HIGH, WARNING_NORMAL, WARNING_LOW); /** * Creates a new {@link Severity} with the specified name. If the name is the same as the name of one of the diff --git a/src/main/java/edu/hm/hafner/analysis/parser/AbstractMavenLogParser.java b/src/main/java/edu/hm/hafner/analysis/parser/AbstractMavenLogParser.java index 808fe3ad6..64d593134 100644 --- a/src/main/java/edu/hm/hafner/analysis/parser/AbstractMavenLogParser.java +++ b/src/main/java/edu/hm/hafner/analysis/parser/AbstractMavenLogParser.java @@ -47,16 +47,16 @@ protected AbstractMavenLogParser(final String pattern) { @Override protected void preprocessLine(final String line) { - Matcher goalMatcher = MAVEN_PLUGIN_START.matcher(line); + var goalMatcher = MAVEN_PLUGIN_START.matcher(line); if (goalMatcher.find()) { - goal = String.format("%s:%s", goalMatcher.group("id"), goalMatcher.group("goal")); + goal = "%s:%s".formatted(goalMatcher.group("id"), goalMatcher.group("goal")); } else if (line.contains("[INFO] BUILD ")) { goal = StringUtils.EMPTY; // reset goal after build } - Matcher moduleMatcher = MAVEN_MODULE_START.matcher(line); + var moduleMatcher = MAVEN_MODULE_START.matcher(line); if (moduleMatcher.find()) { module = moduleMatcher.group("id"); } diff --git a/src/main/java/edu/hm/hafner/analysis/parser/AjcParser.java b/src/main/java/edu/hm/hafner/analysis/parser/AjcParser.java index b81d71f93..732ddf25f 100644 --- a/src/main/java/edu/hm/hafner/analysis/parser/AjcParser.java +++ b/src/main/java/edu/hm/hafner/analysis/parser/AjcParser.java @@ -38,14 +38,14 @@ public Report parse(final ReaderFactory reader) throws ParsingException { } private Report parse(final Stream lines) { - try (IssueBuilder builder = new IssueBuilder()) { + try (var builder = new IssueBuilder()) { var report = new Report(); - States state = States.START; + var state = States.START; Iterator lineIterator = lines.iterator(); while (lineIterator.hasNext()) { - String line = lineIterator.next(); + var line = lineIterator.next(); // clean up any ESC characters (e.g. terminal colors) line = ESCAPE_CHARACTERS.matcher(line).replaceAll(""); diff --git a/src/main/java/edu/hm/hafner/analysis/parser/AquaScannerParser.java b/src/main/java/edu/hm/hafner/analysis/parser/AquaScannerParser.java index 55b0bedc4..1759c3271 100644 --- a/src/main/java/edu/hm/hafner/analysis/parser/AquaScannerParser.java +++ b/src/main/java/edu/hm/hafner/analysis/parser/AquaScannerParser.java @@ -29,7 +29,7 @@ public class AquaScannerParser extends JsonIssueParser { @Override protected void parseJsonObject(final Report report, final JSONObject jsonReport, final IssueBuilder issueBuilder) { - JSONArray resources = jsonReport.optJSONArray("resources"); + var resources = jsonReport.optJSONArray("resources"); if (resources != null) { parseResources(report, resources, issueBuilder); } @@ -37,9 +37,8 @@ protected void parseJsonObject(final Report report, final JSONObject jsonReport, private void parseResources(final Report report, final JSONArray resources, final IssueBuilder issueBuilder) { for (int i = 0; i < resources.length(); i++) { - final Object item = resources.get(i); - if (item instanceof JSONObject) { - var resourceWrapper = (JSONObject) item; + final var item = resources.get(i); + if (item instanceof JSONObject resourceWrapper) { if (!resourceWrapper.isNull("vulnerabilities") && !resourceWrapper.isNull("resource")) { var resource = resourceWrapper.getJSONObject("resource"); parseVulnerabilities(report, issueBuilder, resourceWrapper, resource); @@ -52,15 +51,15 @@ private void parseVulnerabilities(final Report report, final IssueBuilder issueB final JSONObject resourceWrapper, final JSONObject resource) { var vulnerabilities = resourceWrapper.getJSONArray("vulnerabilities"); for (Object vulnerability : vulnerabilities) { - if (vulnerability instanceof JSONObject) { - report.add(convertToIssue(resource, (JSONObject) vulnerability, issueBuilder)); + if (vulnerability instanceof JSONObject object) { + report.add(convertToIssue(resource, object, issueBuilder)); } } } private Issue convertToIssue(final JSONObject resource, final JSONObject vulnerability, final IssueBuilder issueBuilder) { - String fileName = resource.optString("path", resource.optString("name", VALUE_NOT_SET)); + var fileName = resource.optString("path", resource.optString("name", VALUE_NOT_SET)); return issueBuilder .setFileName(fileName) .setSeverity(mapSeverity(vulnerability.optString("aqua_severity", "UNKNOWN"))) @@ -83,9 +82,9 @@ else if (StringUtils.equalsIgnoreCase(string, AQUA_VULNERABILITY_LEVEL_TAG_HIGH) } private String formatDescription(final String fileName, final JSONObject resource, final JSONObject vulnerability) { - String version = resource.optString("version", VALUE_NOT_SET); - String severity = vulnerability.optString("aqua_severity", "UNKOWN"); - String description = vulnerability.optString("description", ""); + var version = resource.optString("version", VALUE_NOT_SET); + var severity = vulnerability.optString("aqua_severity", "UNKOWN"); + var description = vulnerability.optString("description", ""); return join(div(b("Resource: "), text(fileName)), div(b("Installed Version: "), text(version)), div(b("Aqua Severity: "), text(severity)), diff --git a/src/main/java/edu/hm/hafner/analysis/parser/Armcc5CompilerParser.java b/src/main/java/edu/hm/hafner/analysis/parser/Armcc5CompilerParser.java index 3852e3e4d..265d25919 100644 --- a/src/main/java/edu/hm/hafner/analysis/parser/Armcc5CompilerParser.java +++ b/src/main/java/edu/hm/hafner/analysis/parser/Armcc5CompilerParser.java @@ -36,7 +36,7 @@ protected boolean isLineInteresting(final String line) { @Override protected Optional createIssue(final Matcher matcher, final LookaheadStream lookahead, final IssueBuilder builder) { - String type = matcher.group(3); + var type = matcher.group(3); Severity priority; if (equalsIgnoreCase(type, "error")) { @@ -46,8 +46,8 @@ protected Optional createIssue(final Matcher matcher, final LookaheadStre priority = Severity.WARNING_NORMAL; } - String errorCode = matcher.group(4); - String message = matcher.group(5); + var errorCode = matcher.group(4); + var message = matcher.group(5); return builder.setFileName(matcher.group(1)) .setLineStart(matcher.group(2)) .setMessage(errorCode + " - " + message) diff --git a/src/main/java/edu/hm/hafner/analysis/parser/ArmccCompilerParser.java b/src/main/java/edu/hm/hafner/analysis/parser/ArmccCompilerParser.java index f858c88cb..a035fcecb 100644 --- a/src/main/java/edu/hm/hafner/analysis/parser/ArmccCompilerParser.java +++ b/src/main/java/edu/hm/hafner/analysis/parser/ArmccCompilerParser.java @@ -33,7 +33,7 @@ public ArmccCompilerParser() { @Override protected Optional createIssue(final Matcher matcher, final LookaheadStream lookahead, final IssueBuilder builder) { - String type = matcher.group(3); + var type = matcher.group(3); int errorCode = parseInt(matcher.group(4)); Severity priority; @@ -43,7 +43,7 @@ protected Optional createIssue(final Matcher matcher, final LookaheadStre else { priority = Severity.WARNING_NORMAL; } - String message = matcher.group(5); + var message = matcher.group(5); return builder.setFileName(matcher.group(1)).setLineStart(matcher.group(2)).setMessage(errorCode + " - " + message) .setSeverity(priority).buildOptional(); diff --git a/src/main/java/edu/hm/hafner/analysis/parser/BluePearlParser.java b/src/main/java/edu/hm/hafner/analysis/parser/BluePearlParser.java index 6aa852b17..1d9a7ee49 100644 --- a/src/main/java/edu/hm/hafner/analysis/parser/BluePearlParser.java +++ b/src/main/java/edu/hm/hafner/analysis/parser/BluePearlParser.java @@ -32,7 +32,7 @@ public BluePearlParser() { @Override protected Optional createIssue(final Matcher matcher, final LookaheadStream lookahead, final IssueBuilder builder) { - String priority = matcher.group("severity"); + var priority = matcher.group("severity"); if (equalsIgnoreCase(priority, "F")) { builder.setSeverity(Severity.ERROR); } diff --git a/src/main/java/edu/hm/hafner/analysis/parser/BrakemanParser.java b/src/main/java/edu/hm/hafner/analysis/parser/BrakemanParser.java index 804323cc7..2ea13e4fd 100644 --- a/src/main/java/edu/hm/hafner/analysis/parser/BrakemanParser.java +++ b/src/main/java/edu/hm/hafner/analysis/parser/BrakemanParser.java @@ -23,23 +23,23 @@ public class BrakemanParser extends JsonIssueParser { @Override protected void parseJsonObject(final Report report, final JSONObject jsonReport, final IssueBuilder issueBuilder) { - JSONArray warnings = jsonReport.getJSONArray("warnings"); + var warnings = jsonReport.getJSONArray("warnings"); for (Object warning : warnings) { report.add(convertToIssue((JSONObject) warning, issueBuilder)); } } private Issue convertToIssue(final JSONObject warning, final IssueBuilder issueBuilder) throws JSONException { - String fileName = warning.getString("file"); - String category = warning.getString("warning_type"); - Severity severity = getSeverity(warning.getString("confidence")); - String fingerprint = warning.getString("fingerprint"); - String warningType = warning.getString("check_name"); + var fileName = warning.getString("file"); + var category = warning.getString("warning_type"); + var severity = getSeverity(warning.getString("confidence")); + var fingerprint = warning.getString("fingerprint"); + var warningType = warning.getString("check_name"); var message = new StringBuilder(); message.append(warning.getString("message")); if (warning.has("code")) { - String code = warning.optString("code", ""); + var code = warning.optString("code", ""); if (!code.isEmpty()) { message.append(": ").append(warning.getString("code")); diff --git a/src/main/java/edu/hm/hafner/analysis/parser/CMakeParser.java b/src/main/java/edu/hm/hafner/analysis/parser/CMakeParser.java index ae4ab6aa1..9441e5513 100644 --- a/src/main/java/edu/hm/hafner/analysis/parser/CMakeParser.java +++ b/src/main/java/edu/hm/hafner/analysis/parser/CMakeParser.java @@ -35,7 +35,7 @@ public CMakeParser() { protected Optional createIssue(final Matcher matcher, final LookaheadStream lookahead, final IssueBuilder builder) { // if the category is contained in brackets, remove those brackets - String category = StringUtils.strip(matcher.group("category"), "()"); + var category = StringUtils.strip(matcher.group("category"), "()"); int prefixLength = matcher.group("prefix").length(); return builder.setFileName(matcher.group("file")) .setLineStart(matcher.group("line")) diff --git a/src/main/java/edu/hm/hafner/analysis/parser/CargoCheckParser.java b/src/main/java/edu/hm/hafner/analysis/parser/CargoCheckParser.java index f3a3839d2..ea3c69ca7 100644 --- a/src/main/java/edu/hm/hafner/analysis/parser/CargoCheckParser.java +++ b/src/main/java/edu/hm/hafner/analysis/parser/CargoCheckParser.java @@ -72,11 +72,10 @@ public class CargoCheckParser extends IssueParser { public Report parse(final ReaderFactory readerFactory) throws ParsingException, ParsingCanceledException { var report = new Report(); - try (Stream lines = readerFactory.readStream(); IssueBuilder issueBuilder = new IssueBuilder()) { + try (Stream lines = readerFactory.readStream(); var issueBuilder = new IssueBuilder()) { lines.map(line -> (JSONObject) new JSONTokener(line).nextValue()) .map(object -> extractIssue(object, issueBuilder)) - .filter(Optional::isPresent) - .map(Optional::get) + .flatMap(Optional::stream) .forEach(report::add); } @@ -94,22 +93,22 @@ public Report parse(final ReaderFactory readerFactory) throws ParsingException, * @return a built {@link Issue} object if any was present. */ private Optional extractIssue(final JSONObject object, final IssueBuilder issueBuilder) { - String reason = object.getString(REASON); + var reason = object.getString(REASON); if (!ANALYSIS_MESSAGE_REASON.equals(reason)) { return Optional.empty(); } - JSONObject message = object.getJSONObject(MESSAGE); + var message = object.getJSONObject(MESSAGE); if (message.isNull(MESSAGE_CODE)) { return Optional.empty(); } - JSONObject code = message.getJSONObject(MESSAGE_CODE); - String category = code.getString(MESSAGE_CODE_CATEGORY); - String renderedMessage = message.getString(MESSAGE_RENDERED); - Severity severity = Severity.guessFromString(message.getString(MESSAGE_LEVEL)); + var code = message.getJSONObject(MESSAGE_CODE); + var category = code.getString(MESSAGE_CODE_CATEGORY); + var renderedMessage = message.getString(MESSAGE_RENDERED); + var severity = Severity.guessFromString(message.getString(MESSAGE_LEVEL)); return parseDetails(message) .map(details -> issueBuilder @@ -131,7 +130,7 @@ private Optional parseDetails(final JSONObject message) var span = spans.getJSONObject(index); if (span.getBoolean(MESSAGE_SPAN_IS_PRIMARY)) { - String fileName = span.getString(MESSAGE_SPAN_FILE_NAME); + var fileName = span.getString(MESSAGE_SPAN_FILE_NAME); int lineStart = span.getInt(MESSAGE_SPAN_LINE_START); int lineEnd = span.getInt(MESSAGE_SPAN_LINE_END); int columnStart = span.getInt(MESSAGE_SPAN_COLUMN_START); diff --git a/src/main/java/edu/hm/hafner/analysis/parser/CargoClippyParser.java b/src/main/java/edu/hm/hafner/analysis/parser/CargoClippyParser.java index 53f20a63d..0baaca176 100644 --- a/src/main/java/edu/hm/hafner/analysis/parser/CargoClippyParser.java +++ b/src/main/java/edu/hm/hafner/analysis/parser/CargoClippyParser.java @@ -57,9 +57,9 @@ public CargoClippyParser() { @Override protected Optional createIssue(final Matcher matcher, final LookaheadStream lookahead, final IssueBuilder builder) { - final Severity defaultSeverity = Severity.guessFromString(matcher.group("level").trim()); + final var defaultSeverity = Severity.guessFromString(matcher.group("level").trim()); - FileInformation description = createRecommendationMessage(lookahead); + var description = createRecommendationMessage(lookahead); description.setLevel(matcher.group("level")); description.setSummary(matcher.group("summary")); @@ -90,7 +90,7 @@ private FileInformation createRecommendationMessage(final LookaheadStream lookah var fileInformation = new FileInformation(); while (lookahead.hasNext(CARGO_CLIPP_CONTEXT_CONTINUES)) { - String line = lookahead.next(); + var line = lookahead.next(); var fileInfoMatcher = CARGO_CLIPPY_FILE_PATTERN.matcher(line); if (fileInfoMatcher.matches()) { diff --git a/src/main/java/edu/hm/hafner/analysis/parser/ClairParser.java b/src/main/java/edu/hm/hafner/analysis/parser/ClairParser.java index 957990735..515fd1718 100644 --- a/src/main/java/edu/hm/hafner/analysis/parser/ClairParser.java +++ b/src/main/java/edu/hm/hafner/analysis/parser/ClairParser.java @@ -23,11 +23,11 @@ public class ClairParser extends JsonIssueParser { @Override protected void parseJsonObject(final Report report, final JSONObject jsonReport, final IssueBuilder issueBuilder) { - String image = optStringIgnoreCase(jsonReport, "image"); - JSONArray vulnerabilities = optJsonArrayIgnoreCase(jsonReport, "vulnerabilities"); + var image = optStringIgnoreCase(jsonReport, "image"); + var vulnerabilities = optJsonArrayIgnoreCase(jsonReport, "vulnerabilities"); for (Object vulnerability : vulnerabilities) { - if (vulnerability instanceof JSONObject) { - report.add(convertToIssue((JSONObject) vulnerability, image, issueBuilder)); + if (vulnerability instanceof JSONObject object) { + report.add(convertToIssue(object, image, issueBuilder)); } } } @@ -50,7 +50,7 @@ private Issue convertToIssue(final JSONObject jsonIssue, @CheckForNull final Str private void appendIfNotEmpty(final JSONObject issue, final StringBuilder message, final String key, final String head) { - final String text = optStringIgnoreCase(issue, key); + final var text = optStringIgnoreCase(issue, key); if (text != null && !text.isEmpty()) { if (message.length() > 0 && !":".equals(head)) { message.append(' '); @@ -73,19 +73,19 @@ else if (equalsIgnoreCase(level, "high")) { } private JSONArray optJsonArrayIgnoreCase(final JSONObject json, final String searchKey) { - final Object result = optIgnoreCase(json, searchKey); - return result instanceof JSONArray ? (JSONArray) result : new JSONArray(); + final var result = optIgnoreCase(json, searchKey); + return result instanceof JSONArray jsona ? jsona : new JSONArray(); } @CheckForNull private String optStringIgnoreCase(final JSONObject json, final String searchKey) { - final Object result = optIgnoreCase(json, searchKey); - return result instanceof String ? (String) result : null; + final var result = optIgnoreCase(json, searchKey); + return result instanceof String s ? s : null; } @CheckForNull private Object optIgnoreCase(final JSONObject json, final String searchKey) { - Object result = json.opt(searchKey); + var result = json.opt(searchKey); if (result == null) { result = searchIgnoreCase(json, searchKey); } diff --git a/src/main/java/edu/hm/hafner/analysis/parser/ClangAnalyzerPlistParser.java b/src/main/java/edu/hm/hafner/analysis/parser/ClangAnalyzerPlistParser.java index d0a45749d..8dd64bbc4 100644 --- a/src/main/java/edu/hm/hafner/analysis/parser/ClangAnalyzerPlistParser.java +++ b/src/main/java/edu/hm/hafner/analysis/parser/ClangAnalyzerPlistParser.java @@ -39,8 +39,8 @@ public boolean accepts(final ReaderFactory readerFactory) { @Override public Report parse(final ReaderFactory readerFactory) throws ParsingException { - try (IssueBuilder issueBuilder = new IssueBuilder()) { - Document doc = readerFactory.readDocument(); + try (var issueBuilder = new IssueBuilder()) { + var doc = readerFactory.readDocument(); var xPathFactory = XPathFactory.newInstance(); var xPath = xPathFactory.newXPath(); @@ -105,14 +105,14 @@ private static String getFileName(final List files, final Element diag, @SuppressFBWarnings(value = "XPATH_INJECTION", justification = "parameter is a constant") private static XPathExpression compileDiagStrPath(final XPath xPath, final String field) throws XPathExpressionException { - String search = "./key[text()='" + field + "']/following-sibling::string"; + var search = "./key[text()='" + field + "']/following-sibling::string"; return xPath.compile(search); } @SuppressFBWarnings(value = "XPATH_INJECTION", justification = "parameter is a constant") private static XPathExpression compileDiagLocationPath(final XPath xPath, final String field) throws XPathExpressionException { - String search = "./key[text()='location']/following-sibling::dict/key[text()='" + field + var search = "./key[text()='location']/following-sibling::dict/key[text()='" + field + "']/following-sibling::integer"; return xPath.compile(search); } diff --git a/src/main/java/edu/hm/hafner/analysis/parser/ClangParser.java b/src/main/java/edu/hm/hafner/analysis/parser/ClangParser.java index 97237b8e2..5f6d24db8 100644 --- a/src/main/java/edu/hm/hafner/analysis/parser/ClangParser.java +++ b/src/main/java/edu/hm/hafner/analysis/parser/ClangParser.java @@ -34,7 +34,7 @@ public ClangParser() { @Override protected Optional createIssue(final Matcher matcher, final LookaheadStream lookahead, final IssueBuilder builder) { - String message = matcher.group(6); + var message = matcher.group(6); if (IGNORE_FORMAT.matcher(message).matches()) { return Optional.empty(); } diff --git a/src/main/java/edu/hm/hafner/analysis/parser/CodeCheckerParser.java b/src/main/java/edu/hm/hafner/analysis/parser/CodeCheckerParser.java index f3f8b917b..582a38ea3 100644 --- a/src/main/java/edu/hm/hafner/analysis/parser/CodeCheckerParser.java +++ b/src/main/java/edu/hm/hafner/analysis/parser/CodeCheckerParser.java @@ -35,7 +35,7 @@ public CodeCheckerParser() { @Override protected Optional createIssue(final Matcher matcher, final LookaheadStream lookahead, final IssueBuilder builder) { - Severity severity = getSeverity(matcher.group("severity")); + var severity = getSeverity(matcher.group("severity")); return builder.setFileName(matcher.group("path")) .setSeverity(severity) .setLineStart(matcher.group("line")) diff --git a/src/main/java/edu/hm/hafner/analysis/parser/CppLintParser.java b/src/main/java/edu/hm/hafner/analysis/parser/CppLintParser.java index df58a4198..2fad59e77 100644 --- a/src/main/java/edu/hm/hafner/analysis/parser/CppLintParser.java +++ b/src/main/java/edu/hm/hafner/analysis/parser/CppLintParser.java @@ -35,7 +35,7 @@ public CppLintParser() { @Override protected Optional createIssue(final Matcher matcher, final LookaheadStream lookahead, final IssueBuilder builder) { - Severity priority = mapPriority(matcher.group(5)); + var priority = mapPriority(matcher.group(5)); return builder.setFileName(matcher.group(1)) .setLineStart(matcher.group(2)) diff --git a/src/main/java/edu/hm/hafner/analysis/parser/DScannerParser.java b/src/main/java/edu/hm/hafner/analysis/parser/DScannerParser.java index dd44794f2..839b223b0 100644 --- a/src/main/java/edu/hm/hafner/analysis/parser/DScannerParser.java +++ b/src/main/java/edu/hm/hafner/analysis/parser/DScannerParser.java @@ -24,7 +24,7 @@ public class DScannerParser extends JsonParser { @Override Optional convertToIssue(final JSONObject jsonIssue, final IssueBuilder builder) { if (jsonIssue.has(KEY)) { - String key = jsonIssue.getString(KEY); + var key = jsonIssue.getString(KEY); builder.setCategory(key); builder.setSeverity(getSeverityByKey(key)); } @@ -44,7 +44,7 @@ Optional convertToIssue(final JSONObject jsonIssue, final IssueBuilder bu } private Severity getSeverityByKey(final String key) { - String[] parts = key.split("\\.", -1); + var parts = key.split("\\.", -1); switch (parts[1]) { case "confusing": diff --git a/src/main/java/edu/hm/hafner/analysis/parser/DockerLintParser.java b/src/main/java/edu/hm/hafner/analysis/parser/DockerLintParser.java index 84f6b0f81..7ecc08e91 100644 --- a/src/main/java/edu/hm/hafner/analysis/parser/DockerLintParser.java +++ b/src/main/java/edu/hm/hafner/analysis/parser/DockerLintParser.java @@ -33,12 +33,12 @@ public class DockerLintParser extends JsonIssueParser { @Override protected void parseJsonObject(final Report report, final JSONObject jsonReport, final IssueBuilder issueBuilder) { for (String severityGroupName : jsonReport.keySet()) { - Object severityGroup = jsonReport.get(severityGroupName); - if (severityGroup instanceof JSONObject) { - JSONArray data = ((JSONObject) severityGroup).optJSONArray("data"); + var severityGroup = jsonReport.get(severityGroupName); + if (severityGroup instanceof final JSONObject object) { + var data = object.optJSONArray("data"); for (Object issue : data) { - if (issue instanceof JSONObject) { - report.add(convertToIssue((JSONObject) issue, issueBuilder)); + if (issue instanceof final JSONObject jsonObject) { + report.add(convertToIssue(jsonObject, issueBuilder)); } } } @@ -53,7 +53,7 @@ private Issue convertToIssue(final JSONObject jsonIssue, final IssueBuilder buil message.append(jsonIssue.getString("description")); } if (jsonIssue.has("reference_url")) { - Object refUrl = jsonIssue.get("reference_url"); + var refUrl = jsonIssue.get("reference_url"); message.append(" See "); message.append(collapseReferenceUrl(refUrl)); } @@ -68,8 +68,8 @@ private Issue convertToIssue(final JSONObject jsonIssue, final IssueBuilder buil private String collapseReferenceUrl(final Object refUrl) { var referenceUrl = new StringBuilder(); - if (refUrl instanceof JSONArray) { - for (Object part : (JSONArray) refUrl) { + if (refUrl instanceof final JSONArray array) { + for (Object part : array) { referenceUrl.append(part); } } diff --git a/src/main/java/edu/hm/hafner/analysis/parser/DrMemoryParser.java b/src/main/java/edu/hm/hafner/analysis/parser/DrMemoryParser.java index 023a1528a..77cf36477 100644 --- a/src/main/java/edu/hm/hafner/analysis/parser/DrMemoryParser.java +++ b/src/main/java/edu/hm/hafner/analysis/parser/DrMemoryParser.java @@ -47,7 +47,7 @@ public DrMemoryParser() { protected Optional createIssue(final Matcher matcher, final LookaheadStream lookahead, final IssueBuilder builder) throws ParsingException { - String header = matcher.group(1); + var header = matcher.group(1); var messageBuilder = new StringBuilder(header); while (lookahead.hasNext("Elapsed time")) { @@ -57,7 +57,7 @@ protected Optional createIssue(final Matcher matcher, final LookaheadStre var stacktraceBuilder = new StringBuilder(); while (lookahead.hasNext("^#.*")) { - String stackTrace = lookahead.next(); + var stackTrace = lookahead.next(); stacktraceBuilder.append(stackTrace); stacktraceBuilder.append("
"); @@ -134,14 +134,14 @@ private void findOriginatingErrorLocation(final String stackTrace, final IssueBu builder.setFileName("-"); builder.setLineStart(0); for (String line : stackTrace.split("
", -1)) { - Matcher pathMatcher = FILE_PATH_PATTERN.matcher(line); + var pathMatcher = FILE_PATH_PATTERN.matcher(line); if (pathMatcher.find()) { - String path = pathMatcher.group("file"); + var path = pathMatcher.group("file"); builder.setFileName(path); builder.setLineStart(parseInt(pathMatcher.group("line"))); - Matcher jenkinsPathMatcher = JENKINS_PATH_PATTERN.matcher(path); + var jenkinsPathMatcher = JENKINS_PATH_PATTERN.matcher(path); if (jenkinsPathMatcher.find()) { return; } diff --git a/src/main/java/edu/hm/hafner/analysis/parser/EclipseMavenParser.java b/src/main/java/edu/hm/hafner/analysis/parser/EclipseMavenParser.java index 413fa129b..3019a569a 100644 --- a/src/main/java/edu/hm/hafner/analysis/parser/EclipseMavenParser.java +++ b/src/main/java/edu/hm/hafner/analysis/parser/EclipseMavenParser.java @@ -54,7 +54,7 @@ protected Optional createIssue(final Matcher matcher, final LookaheadStre .setFileName(matcher.group("file")) .setLineStart(matcher.group("line")); - String message = matcher.group("message"); + var message = matcher.group("message"); if (StringUtils.isNotBlank(message)) { // single line format builder.setMessage(message); extractCategory(builder, message); diff --git a/src/main/java/edu/hm/hafner/analysis/parser/EclipseParser.java b/src/main/java/edu/hm/hafner/analysis/parser/EclipseParser.java index b6e2e704e..7efc925ae 100644 --- a/src/main/java/edu/hm/hafner/analysis/parser/EclipseParser.java +++ b/src/main/java/edu/hm/hafner/analysis/parser/EclipseParser.java @@ -74,9 +74,9 @@ protected Optional createIssue(final Matcher matcher, final LookaheadStre } static void extractMessage(final IssueBuilder builder, final String message) { - Matcher messageMatcher = ANT_PREFIX.matcher(message); + var messageMatcher = ANT_PREFIX.matcher(message); if (messageMatcher.matches()) { - String msg = messageMatcher.group(1); + var msg = messageMatcher.group(1); builder.setMessage(msg); extractCategory(builder, msg); } diff --git a/src/main/java/edu/hm/hafner/analysis/parser/EclipseXMLParser.java b/src/main/java/edu/hm/hafner/analysis/parser/EclipseXMLParser.java index c2737e7f1..e54b6f255 100644 --- a/src/main/java/edu/hm/hafner/analysis/parser/EclipseXMLParser.java +++ b/src/main/java/edu/hm/hafner/analysis/parser/EclipseXMLParser.java @@ -51,7 +51,7 @@ public boolean accepts(final ReaderFactory readerFactory) { @Override public Report parse(final ReaderFactory readerFactory) throws ParsingException { - try (IssueBuilder issueBuilder = new IssueBuilder()) { + try (var issueBuilder = new IssueBuilder()) { var doc = readerFactory.readDocument(); var xPathFactory = XPathFactory.newInstance(); @@ -64,7 +64,7 @@ public Report parse(final ReaderFactory readerFactory) throws ParsingException { var sources = (NodeList) sourcePath.evaluate(doc, XPathConstants.NODESET); for (Element source : XmlElementUtil.nodeListToList(sources)) { - String fileName = fileNamePath.evaluate(source); + var fileName = fileNamePath.evaluate(source); issueBuilder.setFileName(fileName); var problems = (NodeList) problemsPath.evaluate(source, XPathConstants.NODESET); diff --git a/src/main/java/edu/hm/hafner/analysis/parser/EmbeddedEngineerParser.java b/src/main/java/edu/hm/hafner/analysis/parser/EmbeddedEngineerParser.java index b7d7b9298..b6c4d7931 100644 --- a/src/main/java/edu/hm/hafner/analysis/parser/EmbeddedEngineerParser.java +++ b/src/main/java/edu/hm/hafner/analysis/parser/EmbeddedEngineerParser.java @@ -38,7 +38,7 @@ public class EmbeddedEngineerParser extends IssueParser { @Override public Report parse(final ReaderFactory reader) throws ParsingException { try (Stream lines = reader.readStream()) { - try (LookaheadStream lookahead = new LookaheadStream(lines, reader.getFileName())) { + try (var lookahead = new LookaheadStream(lines, reader.getFileName())) { return parse(lookahead); } } @@ -48,13 +48,13 @@ public Report parse(final ReaderFactory reader) throws ParsingException { } private Report parse(final LookaheadStream lookahead) { - try (IssueBuilder builder = new IssueBuilder()) { - String file = parseFileName(lookahead); + try (var builder = new IssueBuilder()) { + var file = parseFileName(lookahead); var report = new Report(); while (lookahead.hasNext() && lookahead.hasNext(LOG_BEGINNING_PATTERN)) { - String lines = this.readMultipleLines(lookahead); - Matcher matcher = SPECIAL_WARNING_PATTERN.matcher(lines); - Matcher warningMatcher = WARNING_PATTERN.matcher(lines); + var lines = this.readMultipleLines(lookahead); + var matcher = SPECIAL_WARNING_PATTERN.matcher(lines); + var warningMatcher = WARNING_PATTERN.matcher(lines); if (matcher.matches() || warningMatcher.matches()) { String group; @@ -62,7 +62,7 @@ private Report parse(final LookaheadStream lookahead) { if (matcher.matches()) { group = matcher.group("severity"); - description = String.format("%s'%s' %s%s", + description = "%s'%s' %s%s".formatted( matcher.group("description"), matcher.group("module"), matcher.group("details"), @@ -73,11 +73,11 @@ private Report parse(final LookaheadStream lookahead) { else { group = warningMatcher.group("severity"); builder.setCategory(warningMatcher.group("category")); - description = String.format("%s %s", + description = "%s %s".formatted( warningMatcher.group("category"), warningMatcher.group("description")); } - Severity priority = mapPriority(lines, group); + var priority = mapPriority(lines, group); builder.setDescription(description); builder.setFileName(file); builder.setSeverity(priority); @@ -98,8 +98,8 @@ private String readMultipleLines(final LookaheadStream lookahead) { private String parseFileName(final LookaheadStream lineIterator) { while (lineIterator.hasNext()) { - String line = lineIterator.next(); - Matcher matcher = HEADER_PATTERN.matcher(line); + var line = lineIterator.next(); + var matcher = HEADER_PATTERN.matcher(line); if (matcher.matches()) { return matcher.group("file"); } diff --git a/src/main/java/edu/hm/hafner/analysis/parser/ErlcParser.java b/src/main/java/edu/hm/hafner/analysis/parser/ErlcParser.java index 241a14858..e40ae7f48 100644 --- a/src/main/java/edu/hm/hafner/analysis/parser/ErlcParser.java +++ b/src/main/java/edu/hm/hafner/analysis/parser/ErlcParser.java @@ -34,7 +34,7 @@ protected Optional createIssue(final Matcher matcher, final LookaheadStre final IssueBuilder builder) { Severity priority; String category; - String categoryMatch = matcher.group(3); + var categoryMatch = matcher.group(3); if (equalsIgnoreCase(categoryMatch, "warning: ")) { priority = Severity.WARNING_NORMAL; diff --git a/src/main/java/edu/hm/hafner/analysis/parser/ErrorProneParser.java b/src/main/java/edu/hm/hafner/analysis/parser/ErrorProneParser.java index 72a71b9b1..eaac9d6c1 100644 --- a/src/main/java/edu/hm/hafner/analysis/parser/ErrorProneParser.java +++ b/src/main/java/edu/hm/hafner/analysis/parser/ErrorProneParser.java @@ -45,7 +45,7 @@ public ErrorProneParser() { @Override protected Optional createIssue(final Matcher matcher, final LookaheadStream lookahead, final IssueBuilder builder) throws ParsingException { - String description = createDescription(lookahead); + var description = createDescription(lookahead); if (description.contains(SEE_ERROR_PRONE_DOCUMENTATION)) { builder.setFileName(matcher.group("file")) .setLineStart(matcher.group("line")) @@ -76,8 +76,8 @@ static String createDescription(final LookaheadStream lookahead) { var url = new StringBuilder(); boolean urlFound = false; // skip all text before the URL while (lookahead.hasNext("^\\s+.*")) { - String line = lookahead.next(); - Matcher urlMatcher = URL_PATTERN.matcher(line); + var line = lookahead.next(); + var urlMatcher = URL_PATTERN.matcher(line); if (urlMatcher.matches()) { url.append(p().with(a() .withHref(urlMatcher.group("url")) @@ -85,7 +85,7 @@ static String createDescription(final LookaheadStream lookahead) { urlFound = true; } else { - Matcher fixMatcher = FIX_PATTERN.matcher(line); + var fixMatcher = FIX_PATTERN.matcher(line); if (fixMatcher.matches()) { description.append("Did you mean: "); description.append(pre().with( diff --git a/src/main/java/edu/hm/hafner/analysis/parser/FlawfinderParser.java b/src/main/java/edu/hm/hafner/analysis/parser/FlawfinderParser.java index 7bfa5c1b4..453f5f58b 100644 --- a/src/main/java/edu/hm/hafner/analysis/parser/FlawfinderParser.java +++ b/src/main/java/edu/hm/hafner/analysis/parser/FlawfinderParser.java @@ -36,8 +36,8 @@ public FlawfinderParser() { @Override protected Optional createIssue(final Matcher matcher, final LookaheadStream lookahead, final IssueBuilder builder) { - String message = matcher.group("message"); - String category = matcher.group("category"); + var message = matcher.group("message"); + var category = matcher.group("category"); var priority = extractPriority(IntegerParser.parseInt(matcher.group("severity"))); diff --git a/src/main/java/edu/hm/hafner/analysis/parser/FlowParser.java b/src/main/java/edu/hm/hafner/analysis/parser/FlowParser.java index 16d47e477..cd2d144cb 100644 --- a/src/main/java/edu/hm/hafner/analysis/parser/FlowParser.java +++ b/src/main/java/edu/hm/hafner/analysis/parser/FlowParser.java @@ -47,9 +47,9 @@ public class FlowParser extends JsonIssueParser { @Override public boolean accepts(final ReaderFactory readerFactory) { - try (Reader reader = readerFactory.create()) { - Object value = new JSONTokener(reader).nextValue(); - return value instanceof JSONObject && ((JSONObject) value).has(FLOW_VERSION); + try (var reader = readerFactory.create()) { + var value = new JSONTokener(reader).nextValue(); + return value instanceof JSONObject jsono && jsono.has(FLOW_VERSION); } catch (IOException | JSONException ignored) { return false; @@ -66,8 +66,7 @@ protected void parseJsonObject(final Report report, final JSONObject jsonReport, private void extractIssues(final JSONArray elements, final Report report, final IssueBuilder issueBuilder) { for (Object object : elements) { - if (object instanceof JSONObject) { - var issue = (JSONObject) object; + if (object instanceof JSONObject issue) { findFirstMessage(issue).ifPresent( jsonObject -> report.add(createIssueFromJsonObject(issue, jsonObject, issueBuilder))); } @@ -114,7 +113,7 @@ private Issue createIssueFromJsonObject(final JSONObject issue, final JSONObject * @return the severity. */ private Severity parseSeverity(final JSONObject issue) { - String level = issue.optString(ISSUE_LEVEL); + var level = issue.optString(ISSUE_LEVEL); if (LEVEL_ERROR.equals(level)) { return Severity.ERROR; } diff --git a/src/main/java/edu/hm/hafner/analysis/parser/Gcc4CompilerParser.java b/src/main/java/edu/hm/hafner/analysis/parser/Gcc4CompilerParser.java index a66c85253..f0ab5f528 100644 --- a/src/main/java/edu/hm/hafner/analysis/parser/Gcc4CompilerParser.java +++ b/src/main/java/edu/hm/hafner/analysis/parser/Gcc4CompilerParser.java @@ -51,7 +51,7 @@ protected Optional createIssue(final Matcher matcher, final LookaheadStre final IssueBuilder builder) { var message = new StringBuilder(matcher.group(5)); - Matcher classMatcher = CLASS_PATTERN.matcher(message.toString()); + var classMatcher = CLASS_PATTERN.matcher(message.toString()); if (classMatcher.find() && classMatcher.group(1) != null) { builder.setCategory(classMatcher.group(1)); } @@ -71,7 +71,7 @@ protected Optional createIssue(final Matcher matcher, final LookaheadStre @SuppressWarnings("PMD.AvoidLiteralsInIfCondition") private boolean isMessageContinuation(final LookaheadStream lookahead) { - String peek = lookahead.peekNext(); + var peek = lookahead.peekNext(); if (peek.length() < 3) { return false; } diff --git a/src/main/java/edu/hm/hafner/analysis/parser/Gcc4LinkerParser.java b/src/main/java/edu/hm/hafner/analysis/parser/Gcc4LinkerParser.java index ebd1129b4..bb9c5d095 100644 --- a/src/main/java/edu/hm/hafner/analysis/parser/Gcc4LinkerParser.java +++ b/src/main/java/edu/hm/hafner/analysis/parser/Gcc4LinkerParser.java @@ -57,7 +57,7 @@ protected Optional createIssue(final Matcher matcher, final LookaheadStre else { builder.setSeverity(WARNING_HIGH); } - String message = matcher.group(5); + var message = matcher.group(5); builder.setMessage(message); if (StringUtils.endsWith(message, ":")) { return Optional.empty(); diff --git a/src/main/java/edu/hm/hafner/analysis/parser/GccParser.java b/src/main/java/edu/hm/hafner/analysis/parser/GccParser.java index 68fe2e250..69b118026 100644 --- a/src/main/java/edu/hm/hafner/analysis/parser/GccParser.java +++ b/src/main/java/edu/hm/hafner/analysis/parser/GccParser.java @@ -47,7 +47,7 @@ protected Optional createIssue(final Matcher matcher, final LookaheadStre .buildOptional(); } - String fileName = matcher.group(1); + var fileName = matcher.group(1); if (StringUtils.contains(fileName, "cleartool")) { return Optional.empty(); } diff --git a/src/main/java/edu/hm/hafner/analysis/parser/GhsMultiParser.java b/src/main/java/edu/hm/hafner/analysis/parser/GhsMultiParser.java index b48268707..5728bdcff 100644 --- a/src/main/java/edu/hm/hafner/analysis/parser/GhsMultiParser.java +++ b/src/main/java/edu/hm/hafner/analysis/parser/GhsMultiParser.java @@ -45,8 +45,8 @@ public GhsMultiParser() { @Override protected Optional createIssue(final Matcher matcher, final LookaheadStream lookahead, final IssueBuilder builder) { - String type = StringUtils.capitalize(matcher.group("severity")); - String messageStart = matcher.group("message"); + var type = StringUtils.capitalize(matcher.group("severity")); + var messageStart = matcher.group("message"); String message; @@ -82,7 +82,7 @@ protected Optional createIssue(final Matcher matcher, final LookaheadStre * @return concatenated message string */ private String extractMessage(final String messageStart, final LookaheadStream lookahead) { - StringBuilder messageBuilder = new StringBuilder(messageStart).append("\n"); + var messageBuilder = new StringBuilder(messageStart).append("\n"); while (!lookahead.hasNext(MESSAGE_END_REGEX) && lookahead.hasNext()) { messageBuilder.append(lookahead.next()).append("\n"); diff --git a/src/main/java/edu/hm/hafner/analysis/parser/GnuFortranParser.java b/src/main/java/edu/hm/hafner/analysis/parser/GnuFortranParser.java index 1a34c034e..c8077e8fd 100644 --- a/src/main/java/edu/hm/hafner/analysis/parser/GnuFortranParser.java +++ b/src/main/java/edu/hm/hafner/analysis/parser/GnuFortranParser.java @@ -89,8 +89,8 @@ protected Optional createIssue(final Matcher matcher, final LookaheadStre return Optional.empty(); } - String errorMessageLine = lookahead.peekNext(); - Matcher messageMatcher = ERROR_MESSAGE_PATTERN.matcher(errorMessageLine); + var errorMessageLine = lookahead.peekNext(); + var messageMatcher = ERROR_MESSAGE_PATTERN.matcher(errorMessageLine); if (!messageMatcher.matches()) { // Invalid message line. return Optional.empty(); @@ -98,8 +98,8 @@ protected Optional createIssue(final Matcher matcher, final LookaheadStre lookahead.next(); // Get the category (warning, error, ...) and message and trim location references. - String category = MESSAGE_TRIM_PATTERN.matcher(messageMatcher.group(1)).replaceAll(""); - String message = MESSAGE_TRIM_PATTERN.matcher(messageMatcher.group(2)).replaceAll(""); + var category = MESSAGE_TRIM_PATTERN.matcher(messageMatcher.group(1)).replaceAll(""); + var message = MESSAGE_TRIM_PATTERN.matcher(messageMatcher.group(2)).replaceAll(""); // If the message was not directly in the previous line, interpret the last line of the matched text as message. if (message.isEmpty() && lookahead.hasNext()) { diff --git a/src/main/java/edu/hm/hafner/analysis/parser/GoLintParser.java b/src/main/java/edu/hm/hafner/analysis/parser/GoLintParser.java index a5629ed7e..4ec23d4ac 100644 --- a/src/main/java/edu/hm/hafner/analysis/parser/GoLintParser.java +++ b/src/main/java/edu/hm/hafner/analysis/parser/GoLintParser.java @@ -33,8 +33,8 @@ public GoLintParser() { @Override protected Optional createIssue(final Matcher matcher, final LookaheadStream lookahead, final IssueBuilder builder) { - String message = matcher.group(4); - String category = guessCategory(message); + var message = matcher.group(4); + var category = guessCategory(message); return builder.setFileName(matcher.group(1)) .setLineStart(matcher.group(2)) diff --git a/src/main/java/edu/hm/hafner/analysis/parser/GrypeParser.java b/src/main/java/edu/hm/hafner/analysis/parser/GrypeParser.java index 83f09bf08..32ef8ca73 100644 --- a/src/main/java/edu/hm/hafner/analysis/parser/GrypeParser.java +++ b/src/main/java/edu/hm/hafner/analysis/parser/GrypeParser.java @@ -37,22 +37,22 @@ public class GrypeParser extends JsonIssueParser { @Override protected void parseJsonObject(final Report report, final JSONObject jsonReport, final IssueBuilder issueBuilder) { - final JSONArray matches = jsonReport.getJSONArray(MATCHES_TAG); + final var matches = jsonReport.getJSONArray(MATCHES_TAG); for (int i = 0; i < matches.length(); i++) { - final JSONObject match = matches.getJSONObject(i); + final var match = matches.getJSONObject(i); if (match.has(VULNERABILIY_TAG)) { - Issue issue = getIssue(issueBuilder, match); + var issue = getIssue(issueBuilder, match); report.add(issue); } } } private Issue getIssue(final IssueBuilder issueBuilder, final JSONObject match) { - JSONObject vulnerability = match.getJSONObject(VULNERABILIY_TAG); - JSONObject artifact = match.getJSONObject(ARTIFACT_TAG); - String fileName = artifact.getJSONArray(LOCATIONS_TAG).getJSONObject(0).getString(PATH_TAG); - String packageName = artifact.optString(NAME_TAG, "Unknown"); - String version = artifact.optString(VERSION_TAG, ""); + var vulnerability = match.getJSONObject(VULNERABILIY_TAG); + var artifact = match.getJSONObject(ARTIFACT_TAG); + var fileName = artifact.getJSONArray(LOCATIONS_TAG).getJSONObject(0).getString(PATH_TAG); + var packageName = artifact.optString(NAME_TAG, "Unknown"); + var version = artifact.optString(VERSION_TAG, ""); if (!version.isEmpty()) { packageName = packageName + " " + version; } diff --git a/src/main/java/edu/hm/hafner/analysis/parser/HadoLintParser.java b/src/main/java/edu/hm/hafner/analysis/parser/HadoLintParser.java index f80d37dd4..3153502a7 100644 --- a/src/main/java/edu/hm/hafner/analysis/parser/HadoLintParser.java +++ b/src/main/java/edu/hm/hafner/analysis/parser/HadoLintParser.java @@ -31,8 +31,8 @@ public class HadoLintParser extends JsonIssueParser { @Override protected void parseJsonArray(final Report report, final JSONArray jsonReport, final IssueBuilder issueBuilder) { for (Object issue : jsonReport) { - if (issue instanceof JSONObject) { - report.add(convertToIssue((JSONObject) issue, issueBuilder)); + if (issue instanceof JSONObject object) { + report.add(convertToIssue(object, issueBuilder)); } } } diff --git a/src/main/java/edu/hm/hafner/analysis/parser/IdeaInspectionParser.java b/src/main/java/edu/hm/hafner/analysis/parser/IdeaInspectionParser.java index b52c55884..843bbaa6f 100644 --- a/src/main/java/edu/hm/hafner/analysis/parser/IdeaInspectionParser.java +++ b/src/main/java/edu/hm/hafner/analysis/parser/IdeaInspectionParser.java @@ -32,7 +32,7 @@ public class IdeaInspectionParser extends IssueParser { @Override public Report parse(final ReaderFactory readerFactory) throws ParsingException { - Document document = readerFactory.readDocument(); + var document = readerFactory.readDocument(); var rootElement = (Element) document.getElementsByTagName("problems").item(0); return parseProblems(XmlElementUtil.getChildElementsByName(rootElement, "problem")); @@ -40,12 +40,12 @@ public Report parse(final ReaderFactory readerFactory) throws ParsingException { private Report parseProblems(final List elements) { var problems = new Report(); - try (IssueBuilder issueBuilder = new IssueBuilder()) { + try (var issueBuilder = new IssueBuilder()) { for (Element element : elements) { - String file = getChildValue(element, "file"); + var file = getChildValue(element, "file"); var problemClass = XmlElementUtil.getFirstChildElementByName(element, "problem_class"); if (problemClass.isPresent()) { - Element problem = problemClass.get(); + var problem = problemClass.get(); issueBuilder.setFileName(stripPathPrefix(file)) .setLineStart(IntegerParser.parseInt(getChildValue(element, "line"))) .setCategory(StringEscapeUtils.unescapeXml(getValue(problem))) @@ -60,7 +60,7 @@ private Report parseProblems(final List elements) { } private Severity getPriority(final String severity) { - Severity priority = Severity.WARNING_LOW; + var priority = Severity.WARNING_LOW; if (WARNING.equals(severity)) { priority = Severity.WARNING_NORMAL; } @@ -81,7 +81,7 @@ private String getValue(final Element element) { private String getChildValue(final Element element, final String childTag) { var firstElement = XmlElementUtil.getFirstChildElementByName(element, childTag); if (firstElement.isPresent()) { - Node child = firstElement.get().getFirstChild(); + var child = firstElement.get().getFirstChild(); if (child != null) { return child.getNodeValue(); } diff --git a/src/main/java/edu/hm/hafner/analysis/parser/IntelParser.java b/src/main/java/edu/hm/hafner/analysis/parser/IntelParser.java index 889198de8..c15498eb3 100644 --- a/src/main/java/edu/hm/hafner/analysis/parser/IntelParser.java +++ b/src/main/java/edu/hm/hafner/analysis/parser/IntelParser.java @@ -38,7 +38,7 @@ protected boolean isLineInteresting(final String line) { @Override protected Optional createIssue(final Matcher matcher, final LookaheadStream lookahead, final IssueBuilder builder) { - String category = StringUtils.capitalize(matcher.group(5)); + var category = StringUtils.capitalize(matcher.group(5)); Severity priority; if (StringUtils.startsWith(category, "Remark") || StringUtils.startsWith(category, "Message")) { diff --git a/src/main/java/edu/hm/hafner/analysis/parser/InvalidsParser.java b/src/main/java/edu/hm/hafner/analysis/parser/InvalidsParser.java index 8a91f8d71..fdf3ad5ec 100644 --- a/src/main/java/edu/hm/hafner/analysis/parser/InvalidsParser.java +++ b/src/main/java/edu/hm/hafner/analysis/parser/InvalidsParser.java @@ -34,8 +34,8 @@ public InvalidsParser() { @Override protected Optional createIssue(final Matcher matcher, final LookaheadStream lookahead, final IssueBuilder builder) { - String type = WARNING_PREFIX + StringUtils.capitalize(StringUtils.lowerCase(matcher.group(4))); - String category = matcher.group(6); + var type = WARNING_PREFIX + StringUtils.capitalize(StringUtils.lowerCase(matcher.group(4))); + var category = matcher.group(6); Severity priority; if (StringUtils.contains(category, "PLW-07")) { priority = Severity.WARNING_LOW; diff --git a/src/main/java/edu/hm/hafner/analysis/parser/JavaDocParser.java b/src/main/java/edu/hm/hafner/analysis/parser/JavaDocParser.java index 0a2a9ddb3..361022d5d 100644 --- a/src/main/java/edu/hm/hafner/analysis/parser/JavaDocParser.java +++ b/src/main/java/edu/hm/hafner/analysis/parser/JavaDocParser.java @@ -57,12 +57,12 @@ private boolean hasWarningsPrefixAndWarningInMessage(final String line) { @Override protected Optional createIssue(final Matcher matcher, final LookaheadStream lookahead, final IssueBuilder builder) { - String type = matcher.group(3); + var type = matcher.group(3); - String message = matcher.group(4); - Matcher tagMatcher = TAG_PATTERN.matcher(message); + var message = matcher.group(4); + var tagMatcher = TAG_PATTERN.matcher(message); if (tagMatcher.matches()) { - builder.setCategory(String.format("JavaDoc %s", tagMatcher.group(1))); + builder.setCategory("JavaDoc %s".formatted(tagMatcher.group(1))); } else { builder.setCategory("-"); diff --git a/src/main/java/edu/hm/hafner/analysis/parser/JavacParser.java b/src/main/java/edu/hm/hafner/analysis/parser/JavacParser.java index 21ed9b616..851e12b95 100644 --- a/src/main/java/edu/hm/hafner/analysis/parser/JavacParser.java +++ b/src/main/java/edu/hm/hafner/analysis/parser/JavacParser.java @@ -65,7 +65,7 @@ protected Optional createIssue(final Matcher matcher, final LookaheadStre return Optional.empty(); } - String type = matcher.group(1); + var type = matcher.group(1); if (SEVERITY_ERROR.equals(type) || SEVERITY_ERROR_SHORT.equals(type)) { builder.setSeverity(Severity.ERROR); } @@ -73,8 +73,8 @@ protected Optional createIssue(final Matcher matcher, final LookaheadStre builder.setSeverity(Severity.WARNING_NORMAL); } - String message = matcher.group(10); - String category = guessCategoryIfEmpty(matcher.group(9), message); + var message = matcher.group(10); + var category = guessCategoryIfEmpty(matcher.group(9), message); // get rid of leading / from windows compiler output JENKINS-66738 return builder.setFileName(RegExUtils.replaceAll(matcher.group(2), "^/([a-zA-Z]):", "$1:")) diff --git a/src/main/java/edu/hm/hafner/analysis/parser/JsonBaseParser.java b/src/main/java/edu/hm/hafner/analysis/parser/JsonBaseParser.java index 547ef8f1f..d2b063669 100644 --- a/src/main/java/edu/hm/hafner/analysis/parser/JsonBaseParser.java +++ b/src/main/java/edu/hm/hafner/analysis/parser/JsonBaseParser.java @@ -32,7 +32,7 @@ abstract class JsonBaseParser extends IssueParser { * @return issue instance */ Optional convertToIssue(final JSONObject jsonIssue) { - try (IssueBuilder builder = new IssueBuilder()) { + try (var builder = new IssueBuilder()) { return convertToIssue(jsonIssue, builder); } } @@ -78,8 +78,8 @@ Optional convertToIssue(final JSONObject jsonIssue, final IssueBuilder bu builder.setLineEnd(jsonIssue.getInt(LINE_END)); } if (jsonIssue.has(LINE_RANGES)) { - JSONArray jsonRanges = jsonIssue.getJSONArray(LINE_RANGES); - LineRangeList lineRanges = convertToLineRangeList(jsonRanges); + var jsonRanges = jsonIssue.getJSONArray(LINE_RANGES); + var lineRanges = convertToLineRangeList(jsonRanges); builder.setLineRanges(lineRanges); } if (jsonIssue.has(LINE_START)) { @@ -109,7 +109,7 @@ Optional convertToIssue(final JSONObject jsonIssue, final IssueBuilder bu private LineRangeList convertToLineRangeList(final JSONArray jsonRanges) { var lineRanges = new LineRangeList(); for (int i = 0; i < jsonRanges.length(); i++) { - JSONObject jsonRange = jsonRanges.getJSONObject(i); + var jsonRange = jsonRanges.getJSONObject(i); if (jsonRange.has(LINE_RANGE_START)) { if (jsonRange.has(LINE_RANGE_END)) { lineRanges.add(new LineRange(jsonRange.getInt(LINE_RANGE_START), diff --git a/src/main/java/edu/hm/hafner/analysis/parser/JsonIssueParser.java b/src/main/java/edu/hm/hafner/analysis/parser/JsonIssueParser.java index e4ad233e2..9dd504230 100644 --- a/src/main/java/edu/hm/hafner/analysis/parser/JsonIssueParser.java +++ b/src/main/java/edu/hm/hafner/analysis/parser/JsonIssueParser.java @@ -1,7 +1,6 @@ package edu.hm.hafner.analysis.parser; import java.io.IOException; -import java.io.Reader; import java.io.Serial; import org.json.JSONArray; @@ -27,16 +26,12 @@ public abstract class JsonIssueParser extends IssueParser { @Override public Report parse(final ReaderFactory readerFactory) throws ParsingException { var report = new Report(); - try (Reader reader = readerFactory.create(); IssueBuilder issueBuilder = new IssueBuilder()) { + try (var reader = readerFactory.create(); var issueBuilder = new IssueBuilder()) { var parsedValue = new JSONTokener(reader).nextValue(); - if (parsedValue instanceof JSONObject) { - var jsonReport = (JSONObject) parsedValue; - + if (parsedValue instanceof final JSONObject jsonReport) { parseJsonObject(report, jsonReport, issueBuilder); } - else if (parsedValue instanceof JSONArray) { - var jsonReport = (JSONArray) parsedValue; - + else if (parsedValue instanceof final JSONArray jsonReport) { parseJsonArray(report, jsonReport, issueBuilder); } else { diff --git a/src/main/java/edu/hm/hafner/analysis/parser/JsonLogParser.java b/src/main/java/edu/hm/hafner/analysis/parser/JsonLogParser.java index 296be8b45..dc6df85f0 100644 --- a/src/main/java/edu/hm/hafner/analysis/parser/JsonLogParser.java +++ b/src/main/java/edu/hm/hafner/analysis/parser/JsonLogParser.java @@ -23,7 +23,7 @@ public class JsonLogParser extends JsonBaseParser { @Override public boolean accepts(final ReaderFactory readerFactory) { - String fileName = readerFactory.getFileName(); + var fileName = readerFactory.getFileName(); return !fileName.endsWith(".xml") && !fileName.endsWith(".json"); } @@ -36,8 +36,7 @@ public Report parse(final ReaderFactory readerFactory) throws ParsingException { .filter(line -> !line.startsWith("//")) .filter(line -> line.charAt(0) != '#') .map(line -> parseIssue(line, report)) - .filter(Optional::isPresent) - .map(Optional::get) + .flatMap(Optional::stream) .forEach(report::add); return report; } diff --git a/src/main/java/edu/hm/hafner/analysis/parser/JsonParser.java b/src/main/java/edu/hm/hafner/analysis/parser/JsonParser.java index 4e6af3b63..a9fa71c8f 100644 --- a/src/main/java/edu/hm/hafner/analysis/parser/JsonParser.java +++ b/src/main/java/edu/hm/hafner/analysis/parser/JsonParser.java @@ -35,17 +35,16 @@ public boolean accepts(final ReaderFactory readerFactory) { @Override public Report parse(final ReaderFactory readerFactory) throws ParsingException { - try (Reader reader = readerFactory.create(); IssueBuilder builder = new IssueBuilder()) { + try (var reader = readerFactory.create(); var builder = new IssueBuilder()) { var jsonReport = (JSONObject) new JSONTokener(reader).nextValue(); var report = new Report(); if (jsonReport.has(ISSUES)) { - JSONArray issues = jsonReport.getJSONArray(ISSUES); + var issues = jsonReport.getJSONArray(ISSUES); StreamSupport.stream(issues.spliterator(), SEQUENTIAL) .filter(JSONObject.class::isInstance) .map(o -> convertToIssue((JSONObject) o, builder)) - .filter(Optional::isPresent) - .map(Optional::get) + .flatMap(Optional::stream) .forEach(report::add); } return report; diff --git a/src/main/java/edu/hm/hafner/analysis/parser/LintParser.java b/src/main/java/edu/hm/hafner/analysis/parser/LintParser.java index 85ac3ef55..044440574 100644 --- a/src/main/java/edu/hm/hafner/analysis/parser/LintParser.java +++ b/src/main/java/edu/hm/hafner/analysis/parser/LintParser.java @@ -71,10 +71,10 @@ public void startElement(final String namespaceURI, } private void createWarning(final Attributes attributes) { - String category = StringUtils.EMPTY; - Severity priority = Severity.WARNING_NORMAL; + var category = StringUtils.EMPTY; + var priority = Severity.WARNING_NORMAL; - String message = extractFrom(attributes, "reason", "message"); + var message = extractFrom(attributes, "reason", "message"); if (message.startsWith("Expected")) { priority = Severity.WARNING_HIGH; category = CATEGORY_PARSING; @@ -105,7 +105,7 @@ else if (message.contains("is better written in dot notation")) { } private String extractFrom(final Attributes atts, final String first, final String second) { - String value = atts.getValue(first); + var value = atts.getValue(first); if (StringUtils.isEmpty(value)) { value = atts.getValue(second); } diff --git a/src/main/java/edu/hm/hafner/analysis/parser/MavenConsoleParser.java b/src/main/java/edu/hm/hafner/analysis/parser/MavenConsoleParser.java index 54cbfd33b..8269e191c 100644 --- a/src/main/java/edu/hm/hafner/analysis/parser/MavenConsoleParser.java +++ b/src/main/java/edu/hm/hafner/analysis/parser/MavenConsoleParser.java @@ -68,23 +68,23 @@ private boolean isValidGoal() { @Override protected Optional createIssue(final Matcher matcher, final LookaheadStream lookahead, final IssueBuilder builder) throws ParsingException { - String severity = matcher.group("severity"); + var severity = matcher.group("severity"); builder.setLineStart(lookahead.getLine()).guessSeverity(severity); var message = new StringBuilder(matcher.group("message")); if (hasGoals(MAVEN_ENFORCER_PLUGIN)) { - String timestamp = matcher.group("timestamp"); + var timestamp = matcher.group("timestamp"); int length = StringUtils.length(timestamp); - String continuation = "^(?:.*\\s|)\\[(INFO|WARNING|ERROR)"; + var continuation = "^(?:.*\\s|)\\[(INFO|WARNING|ERROR)"; while (lookahead.hasNext() && !lookahead.hasNext(continuation)) { message.append('\n'); message.append(StringUtils.substring(lookahead.next(), length)); } } else { - String continuation = "^(?:.*\\s\\s|)\\[" + severity + "\\] "; + var continuation = "^(?:.*\\s\\s|)\\[" + severity + "\\] "; while (lookahead.hasNext(continuation)) { message.append('\n'); message.append(RegExUtils.removeFirst(lookahead.next(), continuation)); diff --git a/src/main/java/edu/hm/hafner/analysis/parser/MentorParser.java b/src/main/java/edu/hm/hafner/analysis/parser/MentorParser.java index 9f138c5ca..543d130b7 100644 --- a/src/main/java/edu/hm/hafner/analysis/parser/MentorParser.java +++ b/src/main/java/edu/hm/hafner/analysis/parser/MentorParser.java @@ -69,7 +69,7 @@ protected Optional createIssue(final Matcher matcher, final LookaheadStre builder.guessSeverity(matcher.group("priority")); - String message = matcher.group("message"); + var message = matcher.group("message"); if (message.contains("while parsing file")) { parseLongVlogMessage(lookahead, builder); } @@ -91,7 +91,7 @@ private void parseLongVlogMessage(final LookaheadStream lookahead, final IssueBu } private void parseVlogMessage(final IssueBuilder builder, final String message) { - String parsedMessage = message; + var parsedMessage = message; builder.setCategory("vlog"); // If we can refine the message, the do. // Else just return what we got passed. @@ -113,10 +113,10 @@ private void parseVlogMessage(final IssueBuilder builder, final String message) private void parseVsimMessage(final LookaheadStream lookahead, final IssueBuilder builder, final String message) { builder.setDescription(parseSimTime(lookahead, builder)); - String parsedMessage = message; + var parsedMessage = message; // If we can refine the message, the do. // Else just return what we got passed. - Matcher vsim = VSIM_PATTERN.matcher(message); + var vsim = VSIM_PATTERN.matcher(message); if (vsim.matches()) { builder.setCategory(vsim.group("category")); builder.setFileName(vsim.group("filename")); @@ -129,7 +129,7 @@ private void parseVsimMessage(final LookaheadStream lookahead, final IssueBuilde @SuppressFBWarnings(value = "POTENTIAL_XML_INJECTION", justification = "Message is cleaned in UI") private String parseSimTime(final LookaheadStream lookahead, final IssueBuilder builder) { var description = new StringBuilder(); - String timeLine = ""; + var timeLine = ""; while (lookahead.hasNext() && lookahead.peekNext().startsWith("# ") && !lookahead.peekNext().startsWith("# **")) { @@ -140,7 +140,7 @@ private String parseSimTime(final LookaheadStream lookahead, final IssueBuilder description.append("
"); description.append(timeLine); } - Matcher tf = TIME_FILE_PATTERN.matcher(timeLine); + var tf = TIME_FILE_PATTERN.matcher(timeLine); if (tf.matches()) { builder.setModuleName(tf.group("module")); builder.setFileName(tf.group("filename")); diff --git a/src/main/java/edu/hm/hafner/analysis/parser/MetrowerksCwLinkerParser.java b/src/main/java/edu/hm/hafner/analysis/parser/MetrowerksCwLinkerParser.java index 4be5041b3..73586e1c6 100644 --- a/src/main/java/edu/hm/hafner/analysis/parser/MetrowerksCwLinkerParser.java +++ b/src/main/java/edu/hm/hafner/analysis/parser/MetrowerksCwLinkerParser.java @@ -32,8 +32,8 @@ public MetrowerksCwLinkerParser() { @Override protected Optional createIssue(final Matcher matcher, final LookaheadStream lookahead, final IssueBuilder builder) { - String message = matcher.group(2); - String messageCategory = matcher.group(1); + var message = matcher.group(2); + var messageCategory = matcher.group(1); Severity priority; String category; diff --git a/src/main/java/edu/hm/hafner/analysis/parser/MsBuildParser.java b/src/main/java/edu/hm/hafner/analysis/parser/MsBuildParser.java index ebd0f1f69..dc0826d4e 100644 --- a/src/main/java/edu/hm/hafner/analysis/parser/MsBuildParser.java +++ b/src/main/java/edu/hm/hafner/analysis/parser/MsBuildParser.java @@ -53,9 +53,9 @@ public MsBuildParser() { @Override protected Optional createIssue(final Matcher matcher, final LookaheadStream lookahead, final IssueBuilder builder) { - String fileName = determineFileName(matcher); + var fileName = determineFileName(matcher); - Matcher fileExtensionMatcher = IGNORED_TOOLS_PATTERN.matcher(fileName); + var fileExtensionMatcher = IGNORED_TOOLS_PATTERN.matcher(fileName); if (!fileExtensionMatcher.find()) { return Optional.empty(); } @@ -79,7 +79,7 @@ protected Optional createIssue(final Matcher matcher, final LookaheadStre .buildOptional(); } - String category = matcher.group(9); + var category = matcher.group(9); if (EXPECTED_CATEGORY.equals(category)) { return Optional.empty(); } @@ -124,7 +124,7 @@ else if (StringUtils.isNotBlank(matcher.group(7))) { fileName = "unknown.file"; } - String projectDir = matcher.group(12); + var projectDir = matcher.group(12); if (canResolveRelativeFileName(fileName, projectDir)) { fileName = FilenameUtils.concat(projectDir, fileName); } diff --git a/src/main/java/edu/hm/hafner/analysis/parser/OTDockerLintParser.java b/src/main/java/edu/hm/hafner/analysis/parser/OTDockerLintParser.java index d27cc9b9f..c204467ef 100644 --- a/src/main/java/edu/hm/hafner/analysis/parser/OTDockerLintParser.java +++ b/src/main/java/edu/hm/hafner/analysis/parser/OTDockerLintParser.java @@ -28,8 +28,8 @@ public boolean accepts(final ReaderFactory readerFactory) { @Override protected void parseJsonArray(final Report report, final JSONArray jsonReport, final IssueBuilder issueBuilder) { for (Object entry : jsonReport) { - if (entry instanceof JSONObject) { - parseJsonObject(report, (JSONObject) entry, issueBuilder); + if (entry instanceof JSONObject object) { + parseJsonObject(report, object, issueBuilder); } } } diff --git a/src/main/java/edu/hm/hafner/analysis/parser/OwaspDependencyCheckParser.java b/src/main/java/edu/hm/hafner/analysis/parser/OwaspDependencyCheckParser.java index ab1695145..e9ac60fe6 100644 --- a/src/main/java/edu/hm/hafner/analysis/parser/OwaspDependencyCheckParser.java +++ b/src/main/java/edu/hm/hafner/analysis/parser/OwaspDependencyCheckParser.java @@ -11,8 +11,6 @@ import edu.hm.hafner.analysis.Severity; import edu.umd.cs.findbugs.annotations.CheckForNull; -import static java.lang.String.*; - /** * OWASP dependency check JSON report parser. */ @@ -21,7 +19,7 @@ public class OwaspDependencyCheckParser extends JsonIssueParser { private static final long serialVersionUID = -1369431674771459756L; private static final String NDIST_NVD_DETAIL_URL_TEMPLATE = "https://nvd.nist.gov/vuln/detail/%1$s"; - private static final String LINK_TEMPLATE = format("%1$s", NDIST_NVD_DETAIL_URL_TEMPLATE); + private static final String LINK_TEMPLATE = "%1$s".formatted(NDIST_NVD_DETAIL_URL_TEMPLATE); private static final String DEPENDENCIES = "dependencies"; private static final String VULNERABILITIES = "vulnerabilities"; @@ -35,42 +33,42 @@ public class OwaspDependencyCheckParser extends JsonIssueParser { @Override protected void parseJsonObject(final Report report, final JSONObject jsonReport, final IssueBuilder issueBuilder) { - final JSONArray dependencies = jsonReport.getJSONArray(DEPENDENCIES); + final var dependencies = jsonReport.getJSONArray(DEPENDENCIES); for (int i = 0; i < dependencies.length(); i++) { - final JSONObject dependency = dependencies.getJSONObject(i); + final var dependency = dependencies.getJSONObject(i); if (!dependency.has(VULNERABILITIES)) { continue; } issueBuilder.setFileName(dependency.getString("fileName")); - final JSONArray vulnerabilities = dependency.getJSONArray(VULNERABILITIES); + final var vulnerabilities = dependency.getJSONArray(VULNERABILITIES); for (int j = 0; j < vulnerabilities.length(); j++) { - final JSONObject vulnerability = vulnerabilities.getJSONObject(j); + final var vulnerability = vulnerabilities.getJSONObject(j); report.add(createIssueFromVulnerability(vulnerability, issueBuilder)); } } } private Issue createIssueFromVulnerability(final JSONObject vulnerability, final IssueBuilder issueBuilder) { - final String name = vulnerability.getString(NAME); + final var name = vulnerability.getString(NAME); return issueBuilder .setSeverity(mapSeverity(vulnerability.getString(SEVERITY))) .setCategory(determineCategory(vulnerability)) .setType(name) .setMessage(vulnerability.getString(DESCRIPTION)) - .setDescription(format(LINK_TEMPLATE, name)) + .setDescription(LINK_TEMPLATE.formatted(name)) .build(); } @CheckForNull private String determineCategory(final JSONObject vulnerability) { - final JSONObject cvssv3 = vulnerability.optJSONObject(CVSSV3); + final var cvssv3 = vulnerability.optJSONObject(CVSSV3); if (cvssv3 != null) { - final String category = cvssv3.optString(ATTACK_VECTOR, null); + final var category = cvssv3.optString(ATTACK_VECTOR, null); if (category != null) { return category; } } - final JSONObject cvssv2 = vulnerability.optJSONObject(CVSSV2); + final var cvssv2 = vulnerability.optJSONObject(CVSSV2); if (cvssv2 != null) { return cvssv2.optString(ACCESS_VECTOR, null); } diff --git a/src/main/java/edu/hm/hafner/analysis/parser/P4Parser.java b/src/main/java/edu/hm/hafner/analysis/parser/P4Parser.java index 5addda7e5..a1c4fe962 100644 --- a/src/main/java/edu/hm/hafner/analysis/parser/P4Parser.java +++ b/src/main/java/edu/hm/hafner/analysis/parser/P4Parser.java @@ -40,8 +40,8 @@ public P4Parser() { @Override protected Optional createIssue(final Matcher matcher, final LookaheadStream lookahead, final IssueBuilder builder) { - String category = matcher.group(2).trim(); - Severity p = mapPriority(category); + var category = matcher.group(2).trim(); + var p = mapPriority(category); return builder.setFileName(matcher.group(1).trim()).setLineStart(0).setCategory(category).setMessage( matcher.group(1).trim()) .setSeverity(p).buildOptional(); diff --git a/src/main/java/edu/hm/hafner/analysis/parser/Pep8Parser.java b/src/main/java/edu/hm/hafner/analysis/parser/Pep8Parser.java index e63cf53b9..7a5bdfe39 100644 --- a/src/main/java/edu/hm/hafner/analysis/parser/Pep8Parser.java +++ b/src/main/java/edu/hm/hafner/analysis/parser/Pep8Parser.java @@ -33,8 +33,8 @@ public Pep8Parser() { @Override protected Optional createIssue(final Matcher matcher, final LookaheadStream lookahead, final IssueBuilder builder) { - String message = matcher.group(5); - String category = guessCategoryIfEmpty(matcher.group(4), message); + var message = matcher.group(5); + var category = guessCategoryIfEmpty(matcher.group(4), message); return builder.setFileName(matcher.group(1)) .setLineStart(matcher.group(2)) diff --git a/src/main/java/edu/hm/hafner/analysis/parser/PhpParser.java b/src/main/java/edu/hm/hafner/analysis/parser/PhpParser.java index 29749e6a2..85bcd0b61 100644 --- a/src/main/java/edu/hm/hafner/analysis/parser/PhpParser.java +++ b/src/main/java/edu/hm/hafner/analysis/parser/PhpParser.java @@ -37,7 +37,7 @@ protected boolean isLineInteresting(final String line) { @Override protected Optional createIssue(final Matcher matcher, final LookaheadStream lookahead, final IssueBuilder builder) { - String category = matcher.group(1); + var category = matcher.group(1); builder.setCategory(category).setSeverity(mapPriority(category)); if (matcher.group(5) == null) { diff --git a/src/main/java/edu/hm/hafner/analysis/parser/PnpmAuditParser.java b/src/main/java/edu/hm/hafner/analysis/parser/PnpmAuditParser.java index 2376da823..2998ee882 100644 --- a/src/main/java/edu/hm/hafner/analysis/parser/PnpmAuditParser.java +++ b/src/main/java/edu/hm/hafner/analysis/parser/PnpmAuditParser.java @@ -75,8 +75,8 @@ private String mapType(final JSONObject vulnerability) { } private String formatCategory(final JSONObject vulnerability) { - String moduleName = vulnerability.optString("module_name"); - String title = vulnerability.optString("title"); + var moduleName = vulnerability.optString("module_name"); + var title = vulnerability.optString("title"); if (moduleName != null && title != null) { return title.replace(moduleName, "").replace(" in ", ""); @@ -110,10 +110,10 @@ private String formatDescription(final JSONObject vulnerability) { getValueAsContainerTag(vulnerability, "module_name", "Module").ifPresent(vulnerabilityTags::add); - final JSONArray findings = vulnerability.optJSONArray("findings"); + final var findings = vulnerability.optJSONArray("findings"); if (findings != null && !findings.isEmpty()) { var firstFinding = (JSONObject) findings.opt(0); - String installedVersion = firstFinding.optString("version"); + var installedVersion = firstFinding.optString("version"); getValueAsContainerTag(installedVersion, "Installed Version").ifPresent(vulnerabilityTags::add); } @@ -129,7 +129,7 @@ private String formatDescription(final JSONObject vulnerability) { } private Optional getValueAsContainerTag(final JSONObject vulnerability, final String tagOfValue) { - String value = vulnerability.optString(tagOfValue); + var value = vulnerability.optString(tagOfValue); if (value == null || value.isEmpty()) { return Optional.empty(); @@ -148,7 +148,7 @@ private Optional getValueAsContainerTag(final String value, final private Optional getValueAsContainerTag(final JSONObject vulnerability, final String tagOfValue, final String label) { - String value = vulnerability.optString(tagOfValue); + var value = vulnerability.optString(tagOfValue); if (value == null || value.isEmpty()) { return Optional.empty(); diff --git a/src/main/java/edu/hm/hafner/analysis/parser/PolyspaceParser.java b/src/main/java/edu/hm/hafner/analysis/parser/PolyspaceParser.java index e8bbdcdc3..1f356b9e7 100644 --- a/src/main/java/edu/hm/hafner/analysis/parser/PolyspaceParser.java +++ b/src/main/java/edu/hm/hafner/analysis/parser/PolyspaceParser.java @@ -40,14 +40,14 @@ public Report parse(final ReaderFactory reader) throws ParsingException { } private Report parse(final Stream lines) { - try (IssueBuilder builder = new IssueBuilder()) { + try (var builder = new IssueBuilder()) { var report = new Report(); var lineIterator = lines.iterator(); int offset = detectLineOffset(lineIterator); while (lineIterator.hasNext()) { - String line = lineIterator.next(); + var line = lineIterator.next(); var attributes = line.split("\\t", 15 + offset); if (containsAnyIgnoreCase(attributes[9], "Unreviewed", "To investigate", "To fix", "Other")) { diff --git a/src/main/java/edu/hm/hafner/analysis/parser/ProtoLintJsonParser.java b/src/main/java/edu/hm/hafner/analysis/parser/ProtoLintJsonParser.java index 8536babae..59ff3ddac 100644 --- a/src/main/java/edu/hm/hafner/analysis/parser/ProtoLintJsonParser.java +++ b/src/main/java/edu/hm/hafner/analysis/parser/ProtoLintJsonParser.java @@ -27,8 +27,8 @@ public class ProtoLintJsonParser extends JsonIssueParser { @Override protected void parseJsonObject(final Report report, final JSONObject jsonReport, final IssueBuilder issueBuilder) { - String basedir = jsonReport.optString("basedir"); - JSONArray results = jsonReport.optJSONArray("lints", new JSONArray(0)); + var basedir = jsonReport.optString("basedir"); + var results = jsonReport.optJSONArray("lints", new JSONArray(0)); parseResults(report, basedir, results, issueBuilder); } @@ -43,7 +43,7 @@ private void parseResults(final Report report, final String basedir, final JSONA private Issue convertToIssue(final String basedir, final JSONObject finding, final IssueBuilder issueBuilder) { // The filename is always relative to the working dir the protoLint process was started with. // In order to get the absolute filename we need to prepend the basedir which is available with protoLint >= 0.50.2 - String filename = finding.getString("filename"); + var filename = finding.getString("filename"); if (!basedir.isEmpty()) { filename = basedir + "/" + filename; } diff --git a/src/main/java/edu/hm/hafner/analysis/parser/PuppetLintParser.java b/src/main/java/edu/hm/hafner/analysis/parser/PuppetLintParser.java index 8c1d61b14..50fe2f159 100644 --- a/src/main/java/edu/hm/hafner/analysis/parser/PuppetLintParser.java +++ b/src/main/java/edu/hm/hafner/analysis/parser/PuppetLintParser.java @@ -48,7 +48,7 @@ protected Optional createIssue(final Matcher matcher, final LookaheadStre } private Severity mapPriority(final String level) { - Severity priority = Severity.WARNING_NORMAL; + var priority = Severity.WARNING_NORMAL; if (level.contains("error") || level.contains("ERROR")) { priority = Severity.WARNING_HIGH; } @@ -63,11 +63,11 @@ private String detectModuleName(final String fileName) { } private String splitFileName(final String fileName) { - Matcher matcher = PACKAGE_PATTERN.matcher(fileName); + var matcher = PACKAGE_PATTERN.matcher(fileName); if (matcher.find()) { - String main = matcher.group(2); - String subclassed = matcher.group(3); - String module = SEPARATOR + main; + var main = matcher.group(2); + var subclassed = matcher.group(3); + var module = SEPARATOR + main; if (StringUtils.isNotBlank(subclassed)) { module += StringUtils.replace(subclassed, "/", SEPARATOR); } diff --git a/src/main/java/edu/hm/hafner/analysis/parser/PyLintParser.java b/src/main/java/edu/hm/hafner/analysis/parser/PyLintParser.java index 63c66fb90..b532a9f69 100644 --- a/src/main/java/edu/hm/hafner/analysis/parser/PyLintParser.java +++ b/src/main/java/edu/hm/hafner/analysis/parser/PyLintParser.java @@ -42,12 +42,12 @@ protected boolean isLineInteresting(final String line) { @Override protected Optional createIssue(final Matcher matcher, final LookaheadStream lookahead, final IssueBuilder builder) { - String category = matcher.group("category"); + var category = matcher.group("category"); builder.setSeverity(mapPriority(category)); builder.setCategory(mapCategory(category)); builder.setType(StringUtils.firstNonBlank(matcher.group("symbol"), matcher.group("type"), UNKNOWN_TYPE)); - String moduleName = matcher.group("module"); + var moduleName = matcher.group("module"); if (moduleName == null) { builder.setPackageName("-").setModuleName("-"); } diff --git a/src/main/java/edu/hm/hafner/analysis/parser/QtTranslationParser.java b/src/main/java/edu/hm/hafner/analysis/parser/QtTranslationParser.java index e5fea6758..b3e4da8e4 100644 --- a/src/main/java/edu/hm/hafner/analysis/parser/QtTranslationParser.java +++ b/src/main/java/edu/hm/hafner/analysis/parser/QtTranslationParser.java @@ -218,7 +218,7 @@ public void characters(final char[] ch, final int start, final int length) { } private void verifyElementTypeRelation(final String element) { - String parent = expectedElementTypeParents.getOrDefault(element, ""); + var parent = expectedElementTypeParents.getOrDefault(element, ""); if (parent == null) { if (!elementTypeStack.isEmpty()) { throw new ParsingException("Element type \"%s\" does not expect to be a root element (line %d).", diff --git a/src/main/java/edu/hm/hafner/analysis/parser/RevApiParser.java b/src/main/java/edu/hm/hafner/analysis/parser/RevApiParser.java index 35a6a18aa..312df5c8d 100644 --- a/src/main/java/edu/hm/hafner/analysis/parser/RevApiParser.java +++ b/src/main/java/edu/hm/hafner/analysis/parser/RevApiParser.java @@ -28,8 +28,8 @@ public class RevApiParser extends JsonIssueParser { @Override protected void parseJsonArray(final Report report, final JSONArray jsonReport, final IssueBuilder issueBuilder) { for (Object issue : jsonReport) { - if (issue instanceof JSONObject) { - report.add(convertToIssue((JSONObject) issue, issueBuilder)); + if (issue instanceof JSONObject object) { + report.add(convertToIssue(object, issueBuilder)); } else { report.logError("RevApi issues no instance of JSON"); @@ -56,22 +56,22 @@ private RevApiInfoExtension convertToGroup(final JSONObject jsonIssue) { private static Map extractSeverities(final JSONObject jsonIssue) { Map allSeverities = new HashMap<>(); for (Object severity : jsonIssue.getJSONArray("classification")) { - if (severity instanceof JSONObject) { - allSeverities.put(((JSONObject) severity).getString("compatibility"), ((JSONObject) severity).getString("severity")); + if (severity instanceof JSONObject object) { + allSeverities.put(object.getString("compatibility"), object.getString("severity")); } } return allSeverities; } private static String extractChange(final JSONObject jsonIssue, final String key) { - String value = jsonIssue.get(key).toString(); + var value = jsonIssue.get(key).toString(); return "null".equals(value) ? "-" : value; } private void addAttachments(final JSONArray attachments, final IssueBuilder builder) { - String packageName = attachments.getJSONObject(0).getString("value"); - String classSimpleName = attachments.getJSONObject(2).getString("value"); - String elementKind = attachments.getJSONObject(3).getString("value"); + var packageName = attachments.getJSONObject(0).getString("value"); + var classSimpleName = attachments.getJSONObject(2).getString("value"); + var elementKind = attachments.getJSONObject(3).getString("value"); builder.setFileName(classSimpleName); builder.setPackageName(packageName); builder.setCategory(elementKind); @@ -80,8 +80,8 @@ private void addAttachments(final JSONArray attachments, final IssueBuilder buil private Severity evaluateSeverity(final JSONArray classification) { Set allSeverities = new HashSet<>(); for (Object severity : classification) { - if (severity instanceof JSONObject) { - allSeverities.add(toSeverity(((JSONObject) severity).getString("severity"))); + if (severity instanceof JSONObject object) { + allSeverities.add(toSeverity(object.getString("severity"))); } } if (allSeverities.contains(Severity.WARNING_HIGH)) { @@ -109,11 +109,11 @@ private Severity toSeverity(final String level) { private String getDescription(final JSONObject jsonIssue) { var severityDescription = new StringBuilder(CAPACITY); for (Object severity : jsonIssue.getJSONArray("classification")) { - if (severity instanceof JSONObject) { + if (severity instanceof JSONObject object) { severityDescription.append("

Compatibility: ") - .append(((JSONObject) severity).getString("compatibility")) + .append(object.getString("compatibility")) .append(" Severity: ") - .append(((JSONObject) severity).getString("severity")) + .append(object.getString("severity")) .append("

"); } } diff --git a/src/main/java/edu/hm/hafner/analysis/parser/RfLintParser.java b/src/main/java/edu/hm/hafner/analysis/parser/RfLintParser.java index c65f045e9..3bcaf786f 100644 --- a/src/main/java/edu/hm/hafner/analysis/parser/RfLintParser.java +++ b/src/main/java/edu/hm/hafner/analysis/parser/RfLintParser.java @@ -1,7 +1,7 @@ package edu.hm.hafner.analysis.parser; import java.io.Serial; -import java.nio.file.Paths; +import java.nio.file.Path; import java.util.Objects; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -160,7 +160,7 @@ public static RfLintRuleName fromName(final String name) { @Override public Report parse(final ReaderFactory readerFactory) { - try (Stream lines = readerFactory.readStream(); IssueBuilder builder = new IssueBuilder()) { + try (Stream lines = readerFactory.readStream(); var builder = new IssueBuilder()) { var warnings = new Report(); lines.forEach(line -> parseLine(builder, warnings, line)); return warnings; @@ -169,11 +169,11 @@ public Report parse(final ReaderFactory readerFactory) { @SuppressWarnings("PMD.DoNotUseThreads") private void parseLine(final IssueBuilder builder, final Report warnings, final String line) { - Matcher fileMatcher = FILE_PATTERN.matcher(line); + var fileMatcher = FILE_PATTERN.matcher(line); if (fileMatcher.find()) { fileName = fileMatcher.group(1); } - Matcher matcher = WARNING_PATTERN.matcher(line); + var matcher = WARNING_PATTERN.matcher(line); if (matcher.find()) { warnings.add(createIssue(matcher, builder)); } @@ -183,15 +183,15 @@ private void parseLine(final IssueBuilder builder, final Report warnings, final } private Issue createIssue(final Matcher matcher, final IssueBuilder builder) { - String message = matcher.group("message"); - String severityStr = guessCategoryIfEmpty(matcher.group("severity"), message); - Severity priority = RfLintSeverity.fromCharacter(severityStr.charAt(0)).getSeverityLevel(); - String ruleName = matcher.group("ruleName"); + var message = matcher.group("message"); + var severityStr = guessCategoryIfEmpty(matcher.group("severity"), message); + var priority = RfLintSeverity.fromCharacter(severityStr.charAt(0)).getSeverityLevel(); + var ruleName = matcher.group("ruleName"); - RfLintCategory category = RfLintRuleName.fromName(ruleName).getCategory(); + var category = RfLintRuleName.fromName(ruleName).getCategory(); return builder.setFileName(fileName) - .setPackageName(Objects.toString(Paths.get(fileName).getParent())) + .setPackageName(Objects.toString(Path.of(fileName).getParent())) .setLineStart(matcher.group("lineNumber")) .setColumnStart(matcher.group("columnNumber")) .setCategory(category.getName()) diff --git a/src/main/java/edu/hm/hafner/analysis/parser/RobocopyParser.java b/src/main/java/edu/hm/hafner/analysis/parser/RobocopyParser.java index 13b4ef941..d927a89ee 100644 --- a/src/main/java/edu/hm/hafner/analysis/parser/RobocopyParser.java +++ b/src/main/java/edu/hm/hafner/analysis/parser/RobocopyParser.java @@ -31,7 +31,7 @@ public RobocopyParser() { @Override protected Optional createIssue(final Matcher matcher, final LookaheadStream lookahead, final IssueBuilder builder) { - String file = matcher.group(4).split("\\s{11}", -1)[0]; + var file = matcher.group(4).split("\\s{11}", -1)[0]; return builder.setFileName(file) .setLineStart(0) .setCategory(matcher.group(2)) diff --git a/src/main/java/edu/hm/hafner/analysis/parser/RuboCopParser.java b/src/main/java/edu/hm/hafner/analysis/parser/RuboCopParser.java index f91e4a7ca..ded57314a 100644 --- a/src/main/java/edu/hm/hafner/analysis/parser/RuboCopParser.java +++ b/src/main/java/edu/hm/hafner/analysis/parser/RuboCopParser.java @@ -36,11 +36,11 @@ public RuboCopParser() { @Override protected Optional createIssue(final Matcher matcher, final LookaheadStream lookahead, final IssueBuilder builder) { - String message = matcher.group("message"); - String category = guessCategoryIfEmpty(matcher.group("category"), message); + var message = matcher.group("message"); + var category = guessCategoryIfEmpty(matcher.group("category"), message); - String severity = matcher.group("severity"); - Severity priority = Severity.WARNING_NORMAL; + var severity = matcher.group("severity"); + var priority = Severity.WARNING_NORMAL; if (ERROR.equals(severity) || FATAL.equals(severity)) { priority = Severity.WARNING_HIGH; } diff --git a/src/main/java/edu/hm/hafner/analysis/parser/SimulinkCheckParser.java b/src/main/java/edu/hm/hafner/analysis/parser/SimulinkCheckParser.java index a63afe95d..7d092acd2 100644 --- a/src/main/java/edu/hm/hafner/analysis/parser/SimulinkCheckParser.java +++ b/src/main/java/edu/hm/hafner/analysis/parser/SimulinkCheckParser.java @@ -38,9 +38,9 @@ public class SimulinkCheckParser extends IssueParser { @Override public Report parse(final ReaderFactory readerFactory) throws ParsingException { - try (IssueBuilder issueBuilder = new IssueBuilder(); - Reader reader = readerFactory.create(); - InputStream targetStream = ReaderInputStream.builder().setReader(reader).setCharset(readerFactory.getCharset()).get()) { + try (var issueBuilder = new IssueBuilder(); + var reader = readerFactory.create(); + var targetStream = ReaderInputStream.builder().setReader(reader).setCharset(readerFactory.getCharset()).get()) { var document = Jsoup.parse(targetStream, readerFactory.getCharset().name(), EMPTY_BASE_URI); var systemElements = document.select(REPORT_CONTENT); @@ -50,7 +50,7 @@ public Report parse(final ReaderFactory readerFactory) throws ParsingException { } var report = new Report(); - String system = systemElement.id(); + var system = systemElement.id(); parseIssues(report, document, issueBuilder, system, WARNING); parseIssues(report, document, issueBuilder, system, FAILED); parseIssues(report, document, issueBuilder, system, NOT_RUN); @@ -80,7 +80,7 @@ private static void parseHeading(final Report report, final IssueBuilder issueBu final Element element, final Elements headings, final String headingElement) { var headingSplit = headingElement.split("\\."); if (headingSplit.length > 0) { - String issueTxt = headings.text(); + var issueTxt = headings.text(); var textMatcher = TEXT_PATTERN.matcher(issueTxt); if (textMatcher.matches()) { @@ -88,7 +88,7 @@ private static void parseHeading(final Report report, final IssueBuilder issueBu issueBuilder.setDescription(textMatcher.group(3)); } else { - Element parent = element.parent(); + var parent = element.parent(); if (parent != null) { parseParent(issueBuilder, headingSplit, issueTxt, parent); } @@ -100,7 +100,7 @@ private static void parseHeading(final Report report, final IssueBuilder issueBu private static void parseParent(final IssueBuilder issueBuilder, final String[] headingSplit, final String issueTxt, final Element parent) { - String parentId = parent.id(); + var parentId = parent.id(); int prefix = parentId.indexOf(SW_PREFIX); if (prefix >= 0) { issueBuilder.setModuleName(parentId.substring(prefix) + "." + headingSplit[headingSplit.length - 1]); diff --git a/src/main/java/edu/hm/hafner/analysis/parser/SonarQubeParser.java b/src/main/java/edu/hm/hafner/analysis/parser/SonarQubeParser.java index 832f58c8d..15281aca0 100644 --- a/src/main/java/edu/hm/hafner/analysis/parser/SonarQubeParser.java +++ b/src/main/java/edu/hm/hafner/analysis/parser/SonarQubeParser.java @@ -65,7 +65,7 @@ public abstract class SonarQubeParser extends JsonIssueParser { @Override public boolean accepts(final ReaderFactory readerFactory) { - try (Reader reader = readerFactory.create()) { + try (var reader = readerFactory.create()) { return accepts((JSONObject) new JSONTokener(reader).nextValue()); } catch (IOException ignored) { @@ -94,8 +94,7 @@ protected void parseJsonObject(final Report report, final JSONObject jsonReport, private void extractIssues(final JSONArray elements, final Report report, final IssueBuilder issueBuilder) { for (Object object : elements) { - if (object instanceof JSONObject) { - var issue = (JSONObject) object; + if (object instanceof JSONObject issue) { if (filterIssue(issue)) { report.add(createIssueFromJsonObject(issue, issueBuilder)); } @@ -150,19 +149,19 @@ private Issue createIssueFromJsonObject(final JSONObject issue, final IssueBuild */ private String parseFilename(final JSONObject issue) { // Get component - String componentKey = issue.optString(ISSUE_COMPONENT, null); - JSONObject component = findComponentByKey(componentKey); + var componentKey = issue.optString(ISSUE_COMPONENT, null); + var component = findComponentByKey(componentKey); if (component == null) { - String issueComponentKey = issue.optString(ISSUE_COMPONENT); + var issueComponentKey = issue.optString(ISSUE_COMPONENT); return issueComponentKey.substring(issueComponentKey.lastIndexOf(':')); } else { // Get file path inside module - String filePath = component.optString(COMPONENT_PATH); + var filePath = component.optString(COMPONENT_PATH); // Get module file path - String modulePath = getModulePath(component, issue); + var modulePath = getModulePath(component, issue); return modulePath + filePath; } } @@ -232,7 +231,7 @@ private String parseMessage(final JSONObject issue) { * @return the priority. */ private Severity parsePriority(final JSONObject issue) { - String severity = issue.optString(ISSUE_SEVERITY, null); + var severity = issue.optString(ISSUE_SEVERITY, null); return severityToPriority(severity); } @@ -249,10 +248,10 @@ private Severity parsePriority(final JSONObject issue) { * @return the module path. */ String parseModulePath(final JSONObject moduleKeyObject, final String componentKey) { - String modulePath = ""; + var modulePath = ""; if (moduleKeyObject.has(componentKey)) { - String moduleKey = moduleKeyObject.getString(componentKey); - JSONObject moduleComponent = findComponentByKey(moduleKey); + var moduleKey = moduleKeyObject.getString(componentKey); + var moduleComponent = findComponentByKey(moduleKey); if (moduleComponent != null && moduleComponent.has(COMPONENT_PATH)) { modulePath = moduleComponent.getString(COMPONENT_PATH) + "/"; } @@ -272,10 +271,9 @@ String parseModulePath(final JSONObject moduleKeyObject, final String componentK private JSONObject findComponentByKey(final String key) { if (components != null && key != null) { for (Object component : components) { - if (component instanceof JSONObject) { - var jsonComponent = (JSONObject) component; + if (component instanceof JSONObject jsonComponent) { if (key.equals(jsonComponent.optString(COMPONENT_KEY))) { - return (JSONObject) component; + return jsonComponent; } } } @@ -300,7 +298,7 @@ private JSONObject findComponentByKey(final String key) { * @return a priority object corresponding to the passed severity. */ private Severity severityToPriority(final String severity) { - Severity priority = Severity.WARNING_NORMAL; + var priority = Severity.WARNING_NORMAL; // Severity MAJOR is omitted as it corresponds with default Severity: NORMAL if (severity != null) { if (SEVERITY_BLOCKER.equals(severity) || SEVERITY_CRITICAL.equals(severity)) { diff --git a/src/main/java/edu/hm/hafner/analysis/parser/SphinxBuildLinkCheckParser.java b/src/main/java/edu/hm/hafner/analysis/parser/SphinxBuildLinkCheckParser.java index 86b9e58a5..981f60963 100644 --- a/src/main/java/edu/hm/hafner/analysis/parser/SphinxBuildLinkCheckParser.java +++ b/src/main/java/edu/hm/hafner/analysis/parser/SphinxBuildLinkCheckParser.java @@ -33,8 +33,8 @@ public SphinxBuildLinkCheckParser() { @Override protected Optional createIssue(final Matcher matcher, final LookaheadStream lookahead, final IssueBuilder builder) { - String message = matcher.group(4); - String category = guessCategoryIfEmpty(matcher.group(3), message); + var message = matcher.group(4); + var category = guessCategoryIfEmpty(matcher.group(3), message); return builder.setFileName(matcher.group(1)) .setLineStart(matcher.group(2)) diff --git a/src/main/java/edu/hm/hafner/analysis/parser/SphinxBuildParser.java b/src/main/java/edu/hm/hafner/analysis/parser/SphinxBuildParser.java index 65fe81eca..5c1c80000 100644 --- a/src/main/java/edu/hm/hafner/analysis/parser/SphinxBuildParser.java +++ b/src/main/java/edu/hm/hafner/analysis/parser/SphinxBuildParser.java @@ -33,8 +33,8 @@ public SphinxBuildParser() { @Override protected Optional createIssue(final Matcher matcher, final LookaheadStream lookahead, final IssueBuilder builder) { - String message = matcher.group(4); - String category = guessCategoryIfEmpty(matcher.group(3), message); + var message = matcher.group(4); + var category = guessCategoryIfEmpty(matcher.group(3), message); return builder.setFileName(matcher.group(1)) .setLineStart(matcher.group(2)) diff --git a/src/main/java/edu/hm/hafner/analysis/parser/StyleCopParser.java b/src/main/java/edu/hm/hafner/analysis/parser/StyleCopParser.java index fbb45542a..9e12bef1e 100644 --- a/src/main/java/edu/hm/hafner/analysis/parser/StyleCopParser.java +++ b/src/main/java/edu/hm/hafner/analysis/parser/StyleCopParser.java @@ -40,7 +40,7 @@ public Report parse(final ReaderFactory readerFactory) throws ParsingException { } private Report parseViolations(final List elements) { - try (IssueBuilder issueBuilder = new IssueBuilder()) { + try (var issueBuilder = new IssueBuilder()) { var report = new Report(); for (Element element : elements) { issueBuilder.setFileName(getString(element, "Source")) @@ -65,7 +65,7 @@ private Report parseViolations(final List elements) { * @return category of violation */ private String getCategory(final Element element) { - String ruleNameSpace = getString(element, "RuleNamespace"); + var ruleNameSpace = getString(element, "RuleNamespace"); int i = ruleNameSpace.lastIndexOf('.'); if (i == -1) { diff --git a/src/main/java/edu/hm/hafner/analysis/parser/TaglistParser.java b/src/main/java/edu/hm/hafner/analysis/parser/TaglistParser.java index 6b56ae908..1138879ef 100644 --- a/src/main/java/edu/hm/hafner/analysis/parser/TaglistParser.java +++ b/src/main/java/edu/hm/hafner/analysis/parser/TaglistParser.java @@ -29,7 +29,7 @@ public class TaglistParser extends IssueParser { @Override public Report parse(final ReaderFactory readerFactory) throws ParsingException { - try (IssueBuilder issueBuilder = new IssueBuilder()) { + try (var issueBuilder = new IssueBuilder()) { var xPathFactory = XPathFactory.newInstance(); var xPath = xPathFactory.newXPath(); @@ -38,12 +38,12 @@ public Report parse(final ReaderFactory readerFactory) throws ParsingException { var document = readerFactory.readDocument(); var tags = (NodeList) xPath.evaluate("/report/tags/tag", document, XPathConstants.NODESET); for (Element tag : XmlElementUtil.nodeListToList(tags)) { - String category = xPath.evaluate("@name", tag); + var category = xPath.evaluate("@name", tag); issueBuilder.setCategory(category); var files = (NodeList) xPath.evaluate("files/file", tag, XPathConstants.NODESET); for (Element file : XmlElementUtil.nodeListToList(files)) { - String clazz = xPath.evaluate("@name", file); + var clazz = xPath.evaluate("@name", file); if (clazz != null) { issueBuilder.setFileName(class2file(clazz)); issueBuilder.setPackageName(class2package(clazz)); diff --git a/src/main/java/edu/hm/hafner/analysis/parser/TaskingVxCompilerParser.java b/src/main/java/edu/hm/hafner/analysis/parser/TaskingVxCompilerParser.java index 3a25beb7f..02227522a 100644 --- a/src/main/java/edu/hm/hafner/analysis/parser/TaskingVxCompilerParser.java +++ b/src/main/java/edu/hm/hafner/analysis/parser/TaskingVxCompilerParser.java @@ -33,7 +33,7 @@ public TaskingVxCompilerParser() { @Override protected Optional createIssue(final Matcher matcher, final LookaheadStream lookahead, final IssueBuilder builder) { - String type = matcher.group(1); + var type = matcher.group(1); Severity priority; String category; diff --git a/src/main/java/edu/hm/hafner/analysis/parser/TiCcsParser.java b/src/main/java/edu/hm/hafner/analysis/parser/TiCcsParser.java index 0fe2177a2..fedeef79b 100644 --- a/src/main/java/edu/hm/hafner/analysis/parser/TiCcsParser.java +++ b/src/main/java/edu/hm/hafner/analysis/parser/TiCcsParser.java @@ -34,7 +34,7 @@ public TiCcsParser() { @Override protected Optional createIssue(final Matcher matcher, final LookaheadStream lookahead, final IssueBuilder builder) { - String lineNumber = matcher.group(5); + var lineNumber = matcher.group(5); if (StringUtils.isBlank(lineNumber)) { lineNumber = matcher.group(10); } diff --git a/src/main/java/edu/hm/hafner/analysis/parser/TrivyParser.java b/src/main/java/edu/hm/hafner/analysis/parser/TrivyParser.java index ffa3ad26a..5c5e3cd25 100644 --- a/src/main/java/edu/hm/hafner/analysis/parser/TrivyParser.java +++ b/src/main/java/edu/hm/hafner/analysis/parser/TrivyParser.java @@ -35,7 +35,7 @@ public class TrivyParser extends JsonIssueParser { */ @Override protected void parseJsonObject(final Report report, final JSONObject jsonReport, final IssueBuilder issueBuilder) { - JSONArray results = jsonReport.optJSONArray("Results"); + var results = jsonReport.optJSONArray("Results"); if (results != null) { parseResults(report, results, issueBuilder); } @@ -86,11 +86,11 @@ else if (TRIVY_VULNERABILITY_LEVEL_TAG_HIGH.equalsIgnoreCase(string)) { } private String formatDescription(final JSONObject vulnerability) { - String fileName = vulnerability.optString("PkgName", VALUE_NOT_SET); - String installedVersion = vulnerability.optString("InstalledVersion", VALUE_NOT_SET); - String fixedVersion = vulnerability.optString("FixedVersion", "still open"); - String severity = vulnerability.optString("Severity", "UNKOWN"); - String description = vulnerability.optString("Description", ""); + var fileName = vulnerability.optString("PkgName", VALUE_NOT_SET); + var installedVersion = vulnerability.optString("InstalledVersion", VALUE_NOT_SET); + var fixedVersion = vulnerability.optString("FixedVersion", "still open"); + var severity = vulnerability.optString("Severity", "UNKOWN"); + var description = vulnerability.optString("Description", ""); return join(p(div(b("File: "), text(fileName)), div(b("Installed Version: "), text(installedVersion)), div(b("Fixed Version: "), text(fixedVersion)), diff --git a/src/main/java/edu/hm/hafner/analysis/parser/VeraCodePipelineScannerParser.java b/src/main/java/edu/hm/hafner/analysis/parser/VeraCodePipelineScannerParser.java index 520a65f24..860f0d4cd 100644 --- a/src/main/java/edu/hm/hafner/analysis/parser/VeraCodePipelineScannerParser.java +++ b/src/main/java/edu/hm/hafner/analysis/parser/VeraCodePipelineScannerParser.java @@ -27,7 +27,7 @@ public class VeraCodePipelineScannerParser extends JsonIssueParser { @Override protected void parseJsonObject(final Report report, final JSONObject jsonReport, final IssueBuilder issueBuilder) { - JSONArray findings = jsonReport.optJSONArray("findings"); + var findings = jsonReport.optJSONArray("findings"); if (findings != null) { parseFindings(report, findings, issueBuilder); } @@ -35,24 +35,23 @@ protected void parseJsonObject(final Report report, final JSONObject jsonReport, private void parseFindings(final Report report, final JSONArray resources, final IssueBuilder issueBuilder) { for (int i = 0; i < resources.length(); i++) { - Object item = resources.get(i); - if (item instanceof JSONObject) { - var finding = (JSONObject) item; + var item = resources.get(i); + if (item instanceof JSONObject finding) { report.add(convertToIssue(finding, issueBuilder)); } } } private Issue convertToIssue(final JSONObject finding, final IssueBuilder issueBuilder) { - final String rawFileName = getSourceFileField(finding, "file", VALUE_NOT_SET); - final String enrichedFileName = getEnrichedFileName(rawFileName); + final var rawFileName = getSourceFileField(finding, "file", VALUE_NOT_SET); + final var enrichedFileName = getEnrichedFileName(rawFileName); final int line = getSourceFileField(finding, "line", 0); final int severity = finding.getInt("severity"); - final String title = finding.getString("title"); - final String issueType = finding.getString("issue_type"); - final String issueTypeId = finding.getString("issue_type_id"); - final String scope = getSourceFileField(finding, "scope", VALUE_NOT_SET); - final String packageName = getPackageName(scope); + final var title = finding.getString("title"); + final var issueType = finding.getString("issue_type"); + final var issueTypeId = finding.getString("issue_type_id"); + final var scope = getSourceFileField(finding, "scope", VALUE_NOT_SET); + final var packageName = getPackageName(scope); return issueBuilder .setFileName(enrichedFileName) .setLineStart(line) @@ -112,9 +111,9 @@ private String getPackageName(final String scope) { * @return field value of the source file */ private T getSourceFileField(final JSONObject finding, final String key, final T altValue) { - final JSONObject files = finding.optJSONObject("files"); + final var files = finding.optJSONObject("files"); if (files != null) { - final JSONObject sourceFile = files.optJSONObject("source_file"); + final var sourceFile = files.optJSONObject("source_file"); if (sourceFile != null) { return (T) sourceFile.get(key); } @@ -146,10 +145,10 @@ else if (severity >= VERACODE_HIGH_THRESHOLD) { } private String formatDescription(final String fileName, final JSONObject finding) { - final String cweId = finding.optString("cwe_id", VALUE_NOT_SET); - final String flawLink = finding.optString("flaw_details_link", VALUE_NOT_SET); - final String severity = finding.optString("severity", VALUE_NOT_SET); - final String displayHtml = finding.optString("display_text", VALUE_NOT_SET); + final var cweId = finding.optString("cwe_id", VALUE_NOT_SET); + final var flawLink = finding.optString("flaw_details_link", VALUE_NOT_SET); + final var severity = finding.optString("severity", VALUE_NOT_SET); + final var displayHtml = finding.optString("display_text", VALUE_NOT_SET); return join(div(b("Resource: "), text(fileName)), div(b("CWE Id: "), text(cweId)), div(b("Flaw Details: "), text(flawLink)), diff --git a/src/main/java/edu/hm/hafner/analysis/parser/XlcCompilerParser.java b/src/main/java/edu/hm/hafner/analysis/parser/XlcCompilerParser.java index 9186ecda4..0695f3fd2 100644 --- a/src/main/java/edu/hm/hafner/analysis/parser/XlcCompilerParser.java +++ b/src/main/java/edu/hm/hafner/analysis/parser/XlcCompilerParser.java @@ -56,9 +56,9 @@ private Severity toPriority(final String severity) { @Override protected Optional createIssue(final Matcher matcher, final LookaheadStream lookahead, final IssueBuilder builder) { - String line = matcher.group(0); + var line = matcher.group(0); - Matcher lineMatcher = PATTERN_WITH_LINE.matcher(line); + var lineMatcher = PATTERN_WITH_LINE.matcher(line); if (lineMatcher.find()) { return builder.setFileName(lineMatcher.group(1)) .setLineStart(lineMatcher.group(2)) @@ -72,7 +72,7 @@ protected Optional createIssue(final Matcher matcher, final LookaheadStre } private Optional createIssueWithoutLine(final IssueBuilder builder, final String line) { - Matcher matcher = PATTERN_WITHOUT_LINE.matcher(line); + var matcher = PATTERN_WITHOUT_LINE.matcher(line); if (matcher.find()) { return builder.setFileName("") .setLineStart(0) diff --git a/src/main/java/edu/hm/hafner/analysis/parser/XlcLinkerParser.java b/src/main/java/edu/hm/hafner/analysis/parser/XlcLinkerParser.java index eff72fe42..20da13c0d 100644 --- a/src/main/java/edu/hm/hafner/analysis/parser/XlcLinkerParser.java +++ b/src/main/java/edu/hm/hafner/analysis/parser/XlcLinkerParser.java @@ -44,25 +44,25 @@ public XlcLinkerParser() { @Override protected Optional createIssue(final Matcher matcher, final LookaheadStream lookahead, final IssueBuilder builder) { - String line = matcher.group(0); + var line = matcher.group(0); builder.setFileName("").setLineStart(0); - Matcher lineMatcher = PATTERN_ERROR_1.matcher(line); + var lineMatcher = PATTERN_ERROR_1.matcher(line); if (lineMatcher.find()) { - String category = lineMatcher.group(1); - String message = lineMatcher.group(2); + var category = lineMatcher.group(1); + var message = lineMatcher.group(2); return builder.setCategory(category).setMessage(message).setSeverity(Severity.WARNING_HIGH).buildOptional(); } lineMatcher = PATTERN_ERROR_2.matcher(line); if (lineMatcher.find()) { - String category = lineMatcher.group(1); - String message = lineMatcher.group(2); + var category = lineMatcher.group(1); + var message = lineMatcher.group(2); return builder.setCategory(category).setMessage(message).setSeverity(Severity.WARNING_HIGH).buildOptional(); } lineMatcher = PATTERN_WARNING.matcher(line); if (lineMatcher.find()) { - String category = lineMatcher.group(1); - String message = lineMatcher.group(2); + var category = lineMatcher.group(1); + var message = lineMatcher.group(2); return builder.setCategory(category) .setMessage(message) .setSeverity(Severity.WARNING_NORMAL) @@ -70,8 +70,8 @@ protected Optional createIssue(final Matcher matcher, final LookaheadStre } lineMatcher = PATTERN_INFO.matcher(line); if (lineMatcher.find()) { - String category = lineMatcher.group(1); - String message = lineMatcher.group(2); + var category = lineMatcher.group(1); + var message = lineMatcher.group(2); return builder.setCategory(category).setMessage(message).setSeverity(Severity.WARNING_LOW).buildOptional(); } return Optional.empty(); diff --git a/src/main/java/edu/hm/hafner/analysis/parser/XmlParser.java b/src/main/java/edu/hm/hafner/analysis/parser/XmlParser.java index d79be8069..43294d2b5 100644 --- a/src/main/java/edu/hm/hafner/analysis/parser/XmlParser.java +++ b/src/main/java/edu/hm/hafner/analysis/parser/XmlParser.java @@ -72,7 +72,7 @@ public boolean accepts(final ReaderFactory readerFactory) { @Override @SuppressFBWarnings("XPATH_INJECTION") public Report parse(final ReaderFactory readerFactory) { - try (IssueBuilder issueBuilder = new IssueBuilder()) { + try (var issueBuilder = new IssueBuilder()) { var doc = readerFactory.readDocument(); var xPathFactory = XPathFactory.newInstance(); var path = xPathFactory.newXPath(); @@ -128,8 +128,8 @@ private LineRangeList readLineRanges(final XPath path, final NodeList lineRanges var endNode = (Element) path.evaluate(LINE_RANGE_END, lineRangeNode, XPathConstants.NODE); if (startNode != null && startNode.getFirstChild() != null && endNode != null && endNode.getFirstChild() != null) { - String startValue = startNode.getFirstChild().getNodeValue().trim(); - String endValue = endNode.getFirstChild().getNodeValue().trim(); + var startValue = startNode.getFirstChild().getNodeValue().trim(); + var endValue = endNode.getFirstChild().getNodeValue().trim(); try { int start = Integer.parseInt(startValue); int end = Integer.parseInt(endValue); diff --git a/src/main/java/edu/hm/hafner/analysis/parser/YoctoScannerParser.java b/src/main/java/edu/hm/hafner/analysis/parser/YoctoScannerParser.java index 2a1cad5d8..903a7ffa8 100644 --- a/src/main/java/edu/hm/hafner/analysis/parser/YoctoScannerParser.java +++ b/src/main/java/edu/hm/hafner/analysis/parser/YoctoScannerParser.java @@ -33,9 +33,8 @@ protected void parseJsonObject(final Report report, final JSONObject jsonReport, private void parseResources(final Report report, final JSONArray packages, final IssueBuilder issueBuilder) { for (int i = 0; i < packages.length(); i++) { - final Object item = packages.get(i); - if (item instanceof JSONObject) { - var resourceWrapper = (JSONObject) item; + final var item = packages.get(i); + if (item instanceof JSONObject resourceWrapper) { if (!resourceWrapper.isNull("issue")) { parseVulnerabilities(report, issueBuilder, resourceWrapper); } @@ -45,11 +44,10 @@ private void parseResources(final Report report, final JSONArray packages, final private void parseVulnerabilities(final Report report, final IssueBuilder issueBuilder, final JSONObject resourceWrapper) { - final JSONArray vulnerabilities = resourceWrapper.getJSONArray("issue"); + final var vulnerabilities = resourceWrapper.getJSONArray("issue"); for (Object vulnerability : vulnerabilities) { - if (vulnerability instanceof JSONObject) { - var obj = (JSONObject) vulnerability; - String status = obj.getString("status"); + if (vulnerability instanceof JSONObject obj) { + var status = obj.getString("status"); boolean unpatched = "Unpatched".equals(status); if (unpatched) { report.add(convertToIssue(resourceWrapper, obj, issueBuilder)); @@ -60,8 +58,8 @@ private void parseVulnerabilities(final Report report, final IssueBuilder issueB private Issue convertToIssue(final JSONObject resource, final JSONObject vulnerability, final IssueBuilder issueBuilder) { - final String packageName = resource.getString("name"); - final String fileName = vulnerability.optString("id", "UNKNOWN"); + final var packageName = resource.getString("name"); + final var fileName = vulnerability.optString("id", "UNKNOWN"); return issueBuilder .setType(fileName) .setFileName(packageName) @@ -72,7 +70,7 @@ private Issue convertToIssue(final JSONObject resource, final JSONObject vulnera } private Severity mapSeverity(final JSONObject vulnerability) { - Double score = INVALID_SCORE; + var score = INVALID_SCORE; boolean hasScoreV3 = vulnerability.has("scorev3"); if (hasScoreV3) { @@ -97,11 +95,11 @@ else if (score >= 7.0 && score <= 10.0) { } private String formatDescription(final String packageName, final JSONObject resource, final JSONObject vulnerability) { - final String version = resource.optString("version", VALUE_NOT_SET); - final String layer = resource.optString("layer", "UNKOWN"); - final String vector = vulnerability.optString("vector", "UNKOWN"); - final String link = vulnerability.optString("link", "UNKOWN"); - final String description = vulnerability.optString("summary", ""); + final var version = resource.optString("version", VALUE_NOT_SET); + final var layer = resource.optString("layer", "UNKOWN"); + final var vector = vulnerability.optString("vector", "UNKOWN"); + final var link = vulnerability.optString("link", "UNKOWN"); + final var description = vulnerability.optString("summary", ""); return join(div(b("Package: "), text(packageName)), div(b("Version: "), text(version)), diff --git a/src/main/java/edu/hm/hafner/analysis/parser/YuiCompressorParser.java b/src/main/java/edu/hm/hafner/analysis/parser/YuiCompressorParser.java index e2690895b..ad1a2c170 100644 --- a/src/main/java/edu/hm/hafner/analysis/parser/YuiCompressorParser.java +++ b/src/main/java/edu/hm/hafner/analysis/parser/YuiCompressorParser.java @@ -40,12 +40,12 @@ public YuiCompressorParser() { @Override protected Optional createIssue(final Matcher matcher, final LookaheadStream lookahead, final IssueBuilder builder) { - String messageHeader = matcher.group(1); + var messageHeader = matcher.group(1); String messageDetails = lookahead.hasNext() ? lookahead.next() : ""; - CategoryAndPriority categoryAndPriority = getCategoryAndPriority(messageHeader); + var categoryAndPriority = getCategoryAndPriority(messageHeader); - String message = messageHeader + " [" + messageDetails + "]"; + var message = messageHeader + " [" + messageDetails + "]"; return builder.setFileName("unknown.file").setLineStart(0).setCategory(categoryAndPriority.getCategory()) .setMessage(message).setSeverity(categoryAndPriority.getPriority()).buildOptional(); diff --git a/src/main/java/edu/hm/hafner/analysis/parser/ccm/CcmParser.java b/src/main/java/edu/hm/hafner/analysis/parser/ccm/CcmParser.java index d177a7c60..6d7112d9a 100644 --- a/src/main/java/edu/hm/hafner/analysis/parser/ccm/CcmParser.java +++ b/src/main/java/edu/hm/hafner/analysis/parser/ccm/CcmParser.java @@ -1,7 +1,6 @@ package edu.hm.hafner.analysis.parser.ccm; import java.io.IOException; -import java.io.Reader; import java.io.Serial; import java.util.Locale; @@ -35,11 +34,11 @@ public Report parse(final ReaderFactory readerFactory) throws ParsingException { private Ccm parseCcmXmlFile(final ReaderFactory ccmXmlFile) { var digester = new SecureDigester(CcmParser.class); - String rootXPath = "ccm"; + var rootXPath = "ccm"; digester.addObjectCreate(rootXPath, Ccm.class); digester.addSetProperties(rootXPath); - String fileMetric = "ccm/metric"; + var fileMetric = "ccm/metric"; digester.addObjectCreate(fileMetric, Metric.class); digester.addSetProperties(fileMetric); digester.addBeanPropertySetter("ccm/metric/complexity"); @@ -50,7 +49,7 @@ private Ccm parseCcmXmlFile(final ReaderFactory ccmXmlFile) { digester.addBeanPropertySetter("ccm/metric/endLineNumber"); digester.addSetNext(fileMetric, "addMetric", Metric.class.getName()); - try (Reader reader = ccmXmlFile.create()) { + try (var reader = ccmXmlFile.create()) { Ccm report = digester.parse(reader); if (report == null) { throw new ParsingException("Input stream is not a CCM file."); @@ -64,13 +63,13 @@ private Ccm parseCcmXmlFile(final ReaderFactory ccmXmlFile) { } private Report convert(final Ccm collection) { - try (IssueBuilder issueBuilder = new IssueBuilder()) { + try (var issueBuilder = new IssueBuilder()) { var report = new Report(); for (Metric metric : collection.getMetrics()) { - Severity priority = calculateMetricPriority(metric); + var priority = calculateMetricPriority(metric); - String complexity = String.format(Locale.ENGLISH, "%s has a complexity of %d", metric.getUnit(), + var complexity = String.format(Locale.ENGLISH, "%s has a complexity of %d", metric.getUnit(), metric.getComplexity()); issueBuilder.setSeverity(priority) @@ -99,7 +98,7 @@ else if (isMetricModeratePriority(metric)) { } private boolean isMetricHighPriority(final Metric metric) { - String metricClassification = metric.getClassification(); + var metricClassification = metric.getClassification(); if (StringUtils.contains(metricClassification, "high")) { return true; } @@ -108,7 +107,7 @@ private boolean isMetricHighPriority(final Metric metric) { } private boolean isMetricModeratePriority(final Metric metric) { - String metricClassification = metric.getClassification(); + var metricClassification = metric.getClassification(); return StringUtils.contains(metricClassification, "moderate") || "B".equals(metricClassification); diff --git a/src/main/java/edu/hm/hafner/analysis/parser/checkstyle/CheckStyleParser.java b/src/main/java/edu/hm/hafner/analysis/parser/checkstyle/CheckStyleParser.java index f92196c9b..1685c2f6f 100644 --- a/src/main/java/edu/hm/hafner/analysis/parser/checkstyle/CheckStyleParser.java +++ b/src/main/java/edu/hm/hafner/analysis/parser/checkstyle/CheckStyleParser.java @@ -1,10 +1,8 @@ package edu.hm.hafner.analysis.parser.checkstyle; import java.io.IOException; -import java.io.Reader; import java.io.Serial; -import org.apache.commons.digester3.Digester; import org.apache.commons.lang3.StringUtils; import org.xml.sax.SAXException; @@ -27,23 +25,23 @@ public class CheckStyleParser extends IssueParser { @Override public Report parse(final ReaderFactory readerFactory) throws ParsingException { - Digester digester = new SecureDigester(CheckStyleParser.class); + var digester = new SecureDigester(CheckStyleParser.class); - String rootXPath = "checkstyle"; + var rootXPath = "checkstyle"; digester.addObjectCreate(rootXPath, CheckStyle.class); digester.addSetProperties(rootXPath); - String fileXPath = "checkstyle/file"; + var fileXPath = "checkstyle/file"; digester.addObjectCreate(fileXPath, File.class); digester.addSetProperties(fileXPath); digester.addSetNext(fileXPath, "addFile", File.class.getName()); - String bugXPath = "checkstyle/file/error"; + var bugXPath = "checkstyle/file/error"; digester.addObjectCreate(bugXPath, Error.class); digester.addSetProperties(bugXPath); digester.addSetNext(bugXPath, "addError", Error.class.getName()); - try (Reader reader = readerFactory.create()) { + try (var reader = readerFactory.create()) { CheckStyle checkStyle = digester.parse(reader); if (checkStyle == null) { throw new ParsingException("Input stream is not a Checkstyle file."); @@ -65,14 +63,14 @@ public Report parse(final ReaderFactory readerFactory) throws ParsingException { * @return a maven module of the annotations API */ private Report convert(final CheckStyle collection) { - try (IssueBuilder issueBuilder = new IssueBuilder()) { + try (var issueBuilder = new IssueBuilder()) { var report = new Report(); for (File file : collection.getFiles()) { if (isValidWarning(file)) { for (Error error : file.getErrors()) { issueBuilder.guessSeverity(error.getSeverity()); - String source = error.getSource(); + var source = error.getSource(); issueBuilder.setType(getType(source)); issueBuilder.setCategory(getCategory(source)); issueBuilder.setMessage(error.getMessage()); diff --git a/src/main/java/edu/hm/hafner/analysis/parser/checkstyle/CheckStyleRules.java b/src/main/java/edu/hm/hafner/analysis/parser/checkstyle/CheckStyleRules.java index 2a66fd549..c2a7443b3 100644 --- a/src/main/java/edu/hm/hafner/analysis/parser/checkstyle/CheckStyleRules.java +++ b/src/main/java/edu/hm/hafner/analysis/parser/checkstyle/CheckStyleRules.java @@ -34,8 +34,8 @@ public CheckStyleRules() { "imports", "javadoc", "metrics", "misc", "modifier", "naming", "regexp", "reporting", "sizes", "whitespace"}; for (String ruleFile : ruleFiles) { - try (InputStream inputStream = CheckStyleRules.class.getResourceAsStream("config_" + ruleFile + ".xml")) { - Digester digester = createDigester(); + try (var inputStream = CheckStyleRules.class.getResourceAsStream("config_" + ruleFile + ".xml")) { + var digester = createDigester(); List rules = new ArrayList<>(); digester.push(rules); digester.parse(inputStream); @@ -66,12 +66,12 @@ private void log(final Throwable exception) { private Digester createDigester() throws ParserConfigurationException { var digester = new SecureDigester(CheckStyleRules.class); - String section = "*/section"; + var section = "*/section"; digester.addObjectCreate(section, Rule.class); digester.addSetProperties(section); digester.addSetNext(section, "add"); - String subSection = "*/section/subsection"; + var subSection = "*/section/subsection"; digester.addObjectCreate(subSection, Topic.class); digester.addSetProperties(subSection); digester.addSetNext(subSection, "setDescription"); @@ -97,7 +97,7 @@ public Collection getRules() { * @return the Checkstyle rule with the specified name. */ public Rule getRule(final String name) { - Rule rule = rulesByName.get(name); + var rule = rulesByName.get(name); if (rule == null) { rule = rulesByName.get(StringUtils.removeEnd(name, "Check")); } diff --git a/src/main/java/edu/hm/hafner/analysis/parser/checkstyle/TopicRule.java b/src/main/java/edu/hm/hafner/analysis/parser/checkstyle/TopicRule.java index 5213c4870..f035bd1d2 100644 --- a/src/main/java/edu/hm/hafner/analysis/parser/checkstyle/TopicRule.java +++ b/src/main/java/edu/hm/hafner/analysis/parser/checkstyle/TopicRule.java @@ -4,7 +4,6 @@ import java.lang.reflect.InvocationTargetException; import javax.xml.parsers.ParserConfigurationException; import javax.xml.transform.OutputKeys; -import javax.xml.transform.Transformer; import javax.xml.transform.TransformerException; import javax.xml.transform.dom.DOMSource; import javax.xml.transform.stream.StreamResult; @@ -39,7 +38,7 @@ public class TopicRule extends NodeCreateRule { public void end(final String namespace, final String name) throws TransformerException, InvocationTargetException, NoSuchMethodException, IllegalAccessException { Element subsection = getDigester().pop(); - String description = extractNodeContent(subsection); + var description = extractNodeContent(subsection); MethodUtils.invokeExactMethod(getDigester().peek(), "setValue", description); } @@ -58,14 +57,14 @@ public void end(final String namespace, final String name) private String extractNodeContent(final Element subsection) throws TransformerException { var content = new StringWriter(); - Transformer transformer = new SecureXmlParserFactory().createTransformer(); + var transformer = new SecureXmlParserFactory().createTransformer(); transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes"); transformer.transform(new DOMSource(subsection), new StreamResult(content)); - String text = content.toString(); - String prefixRemoved = StringUtils.substringAfter(text, ">"); - String suffixRemoved = StringUtils.substringBeforeLast(prefixRemoved, "<"); + var text = content.toString(); + var prefixRemoved = StringUtils.substringAfter(text, ">"); + var suffixRemoved = StringUtils.substringBeforeLast(prefixRemoved, "<"); - String endSourceRemoved = StringUtils.replace(suffixRemoved, "", ""); + var endSourceRemoved = StringUtils.replace(suffixRemoved, "", ""); return StringUtils.replace(endSourceRemoved, "", "
");
     }
diff --git a/src/main/java/edu/hm/hafner/analysis/parser/dry/AbstractDryParser.java b/src/main/java/edu/hm/hafner/analysis/parser/dry/AbstractDryParser.java
index 1dd1cf294..278fc5ae9 100644
--- a/src/main/java/edu/hm/hafner/analysis/parser/dry/AbstractDryParser.java
+++ b/src/main/java/edu/hm/hafner/analysis/parser/dry/AbstractDryParser.java
@@ -69,15 +69,15 @@ protected Severity getPriority(final int lines) {
 
     @Override
     public Report parse(final ReaderFactory readerFactory) throws ParsingCanceledException, ParsingException {
-        Digester digester = new SecureDigester(AbstractDryParser.class);
+        var digester = new SecureDigester(AbstractDryParser.class);
 
         configureParser(digester);
 
         List duplications = new ArrayList<>();
         digester.push(duplications);
 
-        try (Reader reader = readerFactory.create(); IssueBuilder issueBuilder = new IssueBuilder()) {
-            Object result = digester.parse(reader);
+        try (var reader = readerFactory.create(); var issueBuilder = new IssueBuilder()) {
+            var result = digester.parse(reader);
             if (result != duplications) { // NOPMD
                 throw new ParsingException("Input stream is not a valid duplications file.");
             }
diff --git a/src/main/java/edu/hm/hafner/analysis/parser/dry/cpd/CpdParser.java b/src/main/java/edu/hm/hafner/analysis/parser/dry/cpd/CpdParser.java
index c27d1a260..b6b6ed001 100644
--- a/src/main/java/edu/hm/hafner/analysis/parser/dry/cpd/CpdParser.java
+++ b/src/main/java/edu/hm/hafner/analysis/parser/dry/cpd/CpdParser.java
@@ -43,13 +43,13 @@ public CpdParser() {
 
     @Override
     protected void configureParser(final Digester digester) {
-        String duplicationXPath = "*/pmd-cpd/duplication";
+        var duplicationXPath = "*/pmd-cpd/duplication";
         digester.addObjectCreate(duplicationXPath, Duplication.class);
         digester.addSetProperties(duplicationXPath);
         digester.addCallMethod(duplicationXPath + "/codefragment", "setCodeFragment", 0);
         digester.addSetNext(duplicationXPath, "add");
 
-        String fileXPath = duplicationXPath + "/file";
+        var fileXPath = duplicationXPath + "/file";
         digester.addObjectCreate(fileXPath, SourceFile.class);
         digester.addSetProperties(fileXPath);
         digester.addSetNext(fileXPath, "addFile", SourceFile.class.getName());
@@ -68,7 +68,7 @@ protected Report convertDuplicationsToIssues(final List duplication
                         .setFileName(file.getPath())
                         .setType("CPD")
                         .setAdditionalProperties(group);
-                Issue issue = issueBuilder.build();
+                var issue = issueBuilder.build();
                 group.add(issue);
                 report.add(issue);
             }
diff --git a/src/main/java/edu/hm/hafner/analysis/parser/dry/dupfinder/DupFinderParser.java b/src/main/java/edu/hm/hafner/analysis/parser/dry/dupfinder/DupFinderParser.java
index 080c8e7fc..3996740dc 100644
--- a/src/main/java/edu/hm/hafner/analysis/parser/dry/dupfinder/DupFinderParser.java
+++ b/src/main/java/edu/hm/hafner/analysis/parser/dry/dupfinder/DupFinderParser.java
@@ -43,24 +43,24 @@ public DupFinderParser() {
 
     @Override
     protected void configureParser(final Digester digester) {
-        String duplicationXPath = "*/DuplicatesReport/Duplicates/Duplicate";
+        var duplicationXPath = "*/DuplicatesReport/Duplicates/Duplicate";
         digester.addObjectCreate(duplicationXPath, Duplicate.class);
         digester.addSetProperties(duplicationXPath, "Cost", "cost");
         digester.addSetNext(duplicationXPath, "add");
 
-        String fragmentXPath = duplicationXPath + "/Fragment";
+        var fragmentXPath = duplicationXPath + "/Fragment";
         digester.addObjectCreate(fragmentXPath, Fragment.class);
         digester.addBeanPropertySetter(fragmentXPath + "/FileName", "fileName");
         digester.addBeanPropertySetter(fragmentXPath + "/Text", "text");
         digester.addSetNext(fragmentXPath, "addFragment", Fragment.class.getName());
 
-        String lineRangeXPath = fragmentXPath + "/LineRange";
+        var lineRangeXPath = fragmentXPath + "/LineRange";
         digester.addObjectCreate(lineRangeXPath, Range.class);
         digester.addSetProperties(lineRangeXPath, "Start", "start");
         digester.addSetProperties(lineRangeXPath, "End", "end");
         digester.addSetNext(lineRangeXPath, "setLineRange", Range.class.getName());
 
-        String offsetRangeXPath = fragmentXPath + "/OffsetRange";
+        var offsetRangeXPath = fragmentXPath + "/OffsetRange";
         digester.addObjectCreate(offsetRangeXPath, Range.class);
         digester.addSetProperties(offsetRangeXPath, "Start", "start");
         digester.addSetProperties(offsetRangeXPath, "End", "end");
@@ -75,7 +75,7 @@ protected Report convertDuplicationsToIssues(final List duplications,
             var group = new DuplicationGroup();
             for (Fragment fragment : duplication.getFragments()) {
                 group.setCodeFragment(fragment.getText());
-                Range lineRange = fragment.getLineRange();
+                var lineRange = fragment.getLineRange();
                 int count = lineRange.getEnd() - lineRange.getStart() + 1;
                 issueBuilder.setSeverity(getPriority(count))
                         .setLineStart(lineRange.getStart())
@@ -83,7 +83,7 @@ protected Report convertDuplicationsToIssues(final List duplications,
                         .setFileName(fragment.getFileName())
                         .setType("DupFinder")
                         .setAdditionalProperties(group);
-                Issue issue = issueBuilder.build();
+                var issue = issueBuilder.build();
                 group.add(issue);
                 report.add(issue);
             }
diff --git a/src/main/java/edu/hm/hafner/analysis/parser/dry/simian/SimianParser.java b/src/main/java/edu/hm/hafner/analysis/parser/dry/simian/SimianParser.java
index 7ee5aecb3..d8ea9f843 100644
--- a/src/main/java/edu/hm/hafner/analysis/parser/dry/simian/SimianParser.java
+++ b/src/main/java/edu/hm/hafner/analysis/parser/dry/simian/SimianParser.java
@@ -43,12 +43,12 @@ public SimianParser() {
 
     @Override
     protected void configureParser(final Digester digester) {
-        String duplicationXPath = "*/simian/check/set";
+        var duplicationXPath = "*/simian/check/set";
         digester.addObjectCreate(duplicationXPath, Set.class);
         digester.addSetProperties(duplicationXPath);
         digester.addSetNext(duplicationXPath, "add");
 
-        String fileXPath = duplicationXPath + "/block";
+        var fileXPath = duplicationXPath + "/block";
         digester.addObjectCreate(fileXPath, Block.class);
         digester.addSetProperties(fileXPath);
         digester.addSetNext(fileXPath, "addBlock", Block.class.getName());
@@ -67,7 +67,7 @@ protected Report convertDuplicationsToIssues(final List duplications, final
                         .setFileName(file.getSourceFile())
                         .setAdditionalProperties(group)
                         .setType("Simian");
-                Issue issue = issueBuilder.build();
+                var issue = issueBuilder.build();
                 group.add(issue);
                 report.add(issue);
             }
diff --git a/src/main/java/edu/hm/hafner/analysis/parser/findbugs/FindBugsMessages.java b/src/main/java/edu/hm/hafner/analysis/parser/findbugs/FindBugsMessages.java
index bef99b2b6..80f7f9f5f 100644
--- a/src/main/java/edu/hm/hafner/analysis/parser/findbugs/FindBugsMessages.java
+++ b/src/main/java/edu/hm/hafner/analysis/parser/findbugs/FindBugsMessages.java
@@ -45,7 +45,7 @@ public FindBugsMessages() {
 
     private void loadMessages(final String fileName, final Map messagesCache,
             final Map shortMessagesCache) throws IOException, SAXException {
-        try (InputStream file = FindBugsMessages.class.getResourceAsStream(fileName)) {
+        try (var file = FindBugsMessages.class.getResourceAsStream(fileName)) {
             List patterns = parse(file);
             for (Pattern pattern : patterns) {
                 messagesCache.put(pattern.getType(), pattern.getDescription());
@@ -71,7 +71,7 @@ public List parse(final InputStream file) throws IOException, SAXExcept
         List patterns = new ArrayList<>();
         digester.push(patterns);
 
-        String startPattern = "*/BugPattern";
+        var startPattern = "*/BugPattern";
         digester.addObjectCreate(startPattern, Pattern.class);
         digester.addSetProperties(startPattern);
         digester.addCallMethod("*/BugPattern/Details", "setDescription", 0);
diff --git a/src/main/java/edu/hm/hafner/analysis/parser/findbugs/FindBugsParser.java b/src/main/java/edu/hm/hafner/analysis/parser/findbugs/FindBugsParser.java
index ff755a9c1..c7648fd3e 100644
--- a/src/main/java/edu/hm/hafner/analysis/parser/findbugs/FindBugsParser.java
+++ b/src/main/java/edu/hm/hafner/analysis/parser/findbugs/FindBugsParser.java
@@ -80,9 +80,9 @@ public FindBugsParser(final PriorityProperty priorityProperty) {
 
     @Override
     public Report parse(final ReaderFactory readerFactory) throws ParsingException {
-        try (IssueBuilder builder = new IssueBuilder()) {
+        try (var builder = new IssueBuilder()) {
             List sources = new ArrayList<>();
-            String moduleRoot = StringUtils.substringBefore(readerFactory.getFileName(), "/target/");
+            var moduleRoot = StringUtils.substringBefore(readerFactory.getFileName(), "/target/");
             sources.add(moduleRoot + "/src/main/java");
             sources.add(moduleRoot + "/src/test/java");
             sources.add(moduleRoot + "/src");
@@ -97,7 +97,7 @@ Report parse(final ReaderFactory readerFactory, final Collection sources
         Map hashToMessageMapping = new HashMap<>();
         Map categories = new HashMap<>();
 
-        try (Reader input = readerFactory.create()) {
+        try (var input = readerFactory.create()) {
             List bugs = preParse(input);
             for (XmlBugInstance bug : bugs) {
                 hashToMessageMapping.put(bug.getInstanceHash(), bug.getMessage());
@@ -130,10 +130,10 @@ Report parse(final ReaderFactory readerFactory, final Collection sources
     private Report parse(final ReaderFactory readerFactory, final Collection sources,
             final IssueBuilder builder, final Map hashToMessageMapping,
             final Map categories) {
-        try (Reader input = readerFactory.create()) {
-            SortedBugCollection bugs = readXml(input);
+        try (var input = readerFactory.create()) {
+            var bugs = readXml(input);
 
-            try (Project project = bugs.getProject()) {
+            try (var project = bugs.getProject()) {
                 return convertBugsToIssues(sources, builder, hashToMessageMapping, categories, bugs, project);
             }
         }
@@ -147,18 +147,18 @@ private Report convertBugsToIssues(final Collection sources, final Issue
             final SortedBugCollection collection, final Project project) {
         project.addSourceDirs(sources);
 
-        try (SourceFinder sourceFinder = new SourceFinder(project)) {
+        try (var sourceFinder = new SourceFinder(project)) {
             if (StringUtils.isNotBlank(project.getProjectName())) {
                 builder.setModuleName(project.getProjectName());
             }
 
             var report = new Report();
             for (BugInstance warning : collection.getCollection()) {
-                SourceLineAnnotation sourceLine = warning.getPrimarySourceLineAnnotation();
+                var sourceLine = warning.getPrimarySourceLineAnnotation();
 
-                String message = warning.getMessage();
-                String type = warning.getType();
-                String category = categories.get(type);
+                var message = warning.getMessage();
+                var type = warning.getType();
+                var category = categories.get(type);
                 if (category == null) { // alternately, only if warning.getBugPattern().getType().equals("UNKNOWN")
                     category = warning.getBugPattern().getCategory();
                 }
@@ -196,13 +196,13 @@ private Report convertBugsToIssues(final Collection sources, final Issue
      */
     @VisibleForTesting
     List preParse(final Reader file) throws SAXException, IOException {
-        Digester digester = new SecureDigester(FindBugsParser.class);
+        var digester = new SecureDigester(FindBugsParser.class);
 
-        String rootXPath = "BugCollection/BugInstance";
+        var rootXPath = "BugCollection/BugInstance";
         digester.addObjectCreate(rootXPath, XmlBugInstance.class);
         digester.addSetProperties(rootXPath);
 
-        String fileXPath = rootXPath + "/LongMessage";
+        var fileXPath = rootXPath + "/LongMessage";
         digester.addCallMethod(fileXPath, "setMessage", 0);
 
         digester.addSetNext(rootXPath, "add", Object.class.getName());
@@ -247,8 +247,7 @@ private void setAffectedLines(final BugInstance warning, final IssueBuilder buil
         var lineRanges = new LineRangeList();
         while (annotationIterator.hasNext()) {
             var bugAnnotation = annotationIterator.next();
-            if (bugAnnotation instanceof SourceLineAnnotation) {
-                var annotation = (SourceLineAnnotation) bugAnnotation;
+            if (bugAnnotation instanceof SourceLineAnnotation annotation) {
                 var lineRange = new LineRange(annotation.getStartLine(), annotation.getEndLine());
                 if (!lineRanges.contains(lineRange) && !primary.equals(lineRange)) {
                     lineRanges.add(lineRange);
diff --git a/src/main/java/edu/hm/hafner/analysis/parser/fxcop/FxCopParser.java b/src/main/java/edu/hm/hafner/analysis/parser/fxcop/FxCopParser.java
index 05c2f691a..49055f4ee 100644
--- a/src/main/java/edu/hm/hafner/analysis/parser/fxcop/FxCopParser.java
+++ b/src/main/java/edu/hm/hafner/analysis/parser/fxcop/FxCopParser.java
@@ -34,7 +34,7 @@ private static class XmlParser {
         private final FxCopRuleSet ruleSet = new FxCopRuleSet();
 
         public Report parse(final ReaderFactory readerFactory) throws ParsingException, ParsingCanceledException {
-            try (IssueBuilder issueBuilder = new IssueBuilder()) {
+            try (var issueBuilder = new IssueBuilder()) {
                 var doc = readerFactory.readDocument();
 
                 var mainNode = doc.getElementsByTagName("FxCopReport");
@@ -61,7 +61,7 @@ private void parseTargets(final Element rootElement, final IssueBuilder issueBui
             var targetsElement = XmlElementUtil.getFirstChildElementByName(rootElement, "Targets");
             if (targetsElement.isPresent()) {
                 for (Element target : XmlElementUtil.getChildElementsByName(targetsElement.get(), "Target")) {
-                    String name = getString(target, "Name");
+                    var name = getString(target, "Name");
                     parseMessages(target, name, issueBuilder);
                     parseModules(target, name, issueBuilder);
                     parseResources(target, name, issueBuilder);
@@ -74,7 +74,7 @@ private void parseResources(final Element target, final String parentName,
             var resources = XmlElementUtil.getFirstChildElementByName(target, "Resources");
             if (resources.isPresent()) {
                 for (Element resource : XmlElementUtil.getChildElementsByName(resources.get(), "Resource")) {
-                    String name = getString(resource, "Name");
+                    var name = getString(resource, "Name");
                     parseMessages(resource, name, issueBuilder);
                 }
             }
@@ -85,7 +85,7 @@ private void parseModules(final Element target, final String parentName,
             var modulesElement = XmlElementUtil.getFirstChildElementByName(target, "Modules");
             if (modulesElement.isPresent()) {
                 for (Element module : XmlElementUtil.getChildElementsByName(modulesElement.get(), "Module")) {
-                    String name = getString(module, "Name");
+                    var name = getString(module, "Name");
                     parseMessages(module, name, issueBuilder);
                     parseNamespaces(module, issueBuilder);
                 }
@@ -96,7 +96,7 @@ private void parseNamespaces(final Element rootElement, final IssueBuilder issue
             var namespacesElement = XmlElementUtil.getFirstChildElementByName(rootElement, "Namespaces");
             if (namespacesElement.isPresent()) {
                 for (Element namespace : XmlElementUtil.getChildElementsByName(namespacesElement.get(), "Namespace")) {
-                    String name = getString(namespace, "Name");
+                    var name = getString(namespace, "Name");
 
                     parseMessages(namespace, name, issueBuilder);
                     parseTypes(namespace, name, issueBuilder);
@@ -109,7 +109,7 @@ private void parseTypes(final Element typesElement, final String parentName,
             var types = XmlElementUtil.getFirstChildElementByName(typesElement, "Types");
             if (types.isPresent()) {
                 for (Element type : XmlElementUtil.getChildElementsByName(types.get(), "Type")) {
-                    String name = parentName + "." + getString(type, "Name");
+                    var name = parentName + "." + getString(type, "Name");
 
                     parseMessages(type, name, issueBuilder);
                     parseMembers(type, name, issueBuilder);
@@ -157,10 +157,10 @@ private void parseMessages(final Element messages, final String parentName,
 
         private void parseIssue(final Element issue, final Element parent, final String parentName,
                 final IssueBuilder issueBuilder) {
-            String typeName = getString(parent, "TypeName");
-            String category = getString(parent, "Category");
-            String checkId = getString(parent, "CheckId");
-            String issueLevel = getString(issue, "Level");
+            var typeName = getString(parent, "TypeName");
+            var category = getString(parent, "Category");
+            var checkId = getString(parent, "CheckId");
+            var issueLevel = getString(issue, "Level");
 
             var msgBuilder = new StringBuilder(CAPACITY);
             var rule = ruleSet.getRule(category, checkId);
@@ -177,9 +177,9 @@ private void parseIssue(final Element issue, final Element parent, final String
             msgBuilder.append(" - ");
             msgBuilder.append(issue.getTextContent());
 
-            String filePath = getString(issue, "Path");
-            String fileName = getString(issue, "File");
-            String fileLine = getString(issue, "Line");
+            var filePath = getString(issue, "Path");
+            var fileName = getString(issue, "File");
+            var fileLine = getString(issue, "Line");
 
             issueBuilder.setFileName(filePath + "/" + fileName)
                     .setLineStart(fileLine)
diff --git a/src/main/java/edu/hm/hafner/analysis/parser/fxcop/FxCopRuleSet.java b/src/main/java/edu/hm/hafner/analysis/parser/fxcop/FxCopRuleSet.java
index 98e293d09..10017eb92 100644
--- a/src/main/java/edu/hm/hafner/analysis/parser/fxcop/FxCopRuleSet.java
+++ b/src/main/java/edu/hm/hafner/analysis/parser/fxcop/FxCopRuleSet.java
@@ -24,7 +24,7 @@ public class FxCopRuleSet {
      * @param element the element
      */
     public void addRule(final Element element) {
-        FxCopRule rule = new FxCopRule(element.getAttribute("TypeName"), element.getAttribute("Category"), element
+        var rule = new FxCopRule(element.getAttribute("TypeName"), element.getAttribute("Category"), element
                 .getAttribute("CheckId"));
         rule.setUrl(getNamedTagText(element, "Url"));
         rule.setDescription(getNamedTagText(element, "Description"));
@@ -79,7 +79,7 @@ public boolean contains(final String category, final String checkId) {
      */
     @CheckForNull
     public FxCopRule getRule(final String category, final String checkId) {
-        String key = getRuleKey(category, checkId);
+        var key = getRuleKey(category, checkId);
         FxCopRule rule = null;
         if (rules.containsKey(key)) {
             rule = rules.get(key);
diff --git a/src/main/java/edu/hm/hafner/analysis/parser/gendarme/GendarmeParser.java b/src/main/java/edu/hm/hafner/analysis/parser/gendarme/GendarmeParser.java
index 25e9137d8..244c31f2e 100644
--- a/src/main/java/edu/hm/hafner/analysis/parser/gendarme/GendarmeParser.java
+++ b/src/main/java/edu/hm/hafner/analysis/parser/gendarme/GendarmeParser.java
@@ -51,21 +51,21 @@ public Report parse(final ReaderFactory factory) throws ParsingException {
     }
 
     private Report parseViolations(final List ruleElements, final Map rules) {
-        try (IssueBuilder issueBuilder = new IssueBuilder()) {
+        try (var issueBuilder = new IssueBuilder()) {
             var warnings = new Report();
             for (Element ruleElement : ruleElements) {
-                String ruleName = ruleElement.getAttribute("Name");
-                String problem = ruleElement.getElementsByTagName("problem").item(0).getTextContent();
+                var ruleName = ruleElement.getAttribute("Name");
+                var problem = ruleElement.getElementsByTagName("problem").item(0).getTextContent();
                 List targetElements = XmlElementUtil.getChildElementsByName(ruleElement, "target");
 
                 var rule = rules.get(ruleName);
                 if (rule != null) {
                     for (Element targetElement : targetElements) {
                         var defectElement = (Element) targetElement.getElementsByTagName("defect").item(0);
-                        String source = defectElement.getAttribute("Source");
+                        var source = defectElement.getAttribute("Source");
 
-                        String fileName = extractFileNameMatch(rule, source, 1);
-                        Severity priority = extractPriority(defectElement);
+                        var fileName = extractFileNameMatch(rule, source, 1);
+                        var priority = extractPriority(defectElement);
                         int line = parseInt(extractFileNameMatch(rule, source, 2));
 
                         issueBuilder.setFileName(fileName)
@@ -93,9 +93,9 @@ private Severity extractPriority(final Element defectElement) {
     }
 
     private String extractFileNameMatch(final GendarmeRule rule, final String source, final int group) {
-        String fileName = StringUtils.EMPTY;
+        var fileName = StringUtils.EMPTY;
         if (rule.getType() == GendarmeRuleType.Method) {
-            Matcher matcher = FILE_PATTERN.matcher(source);
+            var matcher = FILE_PATTERN.matcher(source);
             if (matcher.matches()) {
                 fileName = matcher.group(group);
             }
@@ -111,7 +111,7 @@ private Map parseRules(final List ruleElements) {
             rule.setName(ruleElement.getAttribute("Name"));
             rule.setTypeName(ruleElement.getTextContent());
 
-            String typeString = ruleElement.getAttribute(TYPE);
+            var typeString = ruleElement.getAttribute(TYPE);
             switch (typeString) {
                 case TYPE:
                     rule.setType(GendarmeRuleType.Type);
diff --git a/src/main/java/edu/hm/hafner/analysis/parser/jcreport/JcReportParser.java b/src/main/java/edu/hm/hafner/analysis/parser/jcreport/JcReportParser.java
index f52953d89..eadbd38b4 100644
--- a/src/main/java/edu/hm/hafner/analysis/parser/jcreport/JcReportParser.java
+++ b/src/main/java/edu/hm/hafner/analysis/parser/jcreport/JcReportParser.java
@@ -24,14 +24,14 @@ public class JcReportParser extends IssueParser {
 
     @Override
     public Report parse(final ReaderFactory reader) {
-        try (IssueBuilder issueBuilder = new IssueBuilder()) {
-            edu.hm.hafner.analysis.parser.jcreport.Report report = createReport(reader);
+        try (var issueBuilder = new IssueBuilder()) {
+            var report = createReport(reader);
             var warnings = new Report();
             for (int i = 0; i < report.getFiles().size(); i++) {
-                File file = report.getFiles().get(i);
+                var file = report.getFiles().get(i);
 
                 for (int j = 0; j < file.getItems().size(); j++) {
-                    Item item = file.getItems().get(j);
+                    var item = file.getItems().get(j);
                     issueBuilder.setFileName(file.getName())
                             .setLineStart(item.getLine())
                             .setColumnStart(item.getColumn())
@@ -62,18 +62,18 @@ public edu.hm.hafner.analysis.parser.jcreport.Report createReport(final ReaderFa
             throws ParsingException {
         var digester = new SecureDigester(JcReportParser.class);
 
-        String report = "report";
+        var report = "report";
         digester.addObjectCreate(report, edu.hm.hafner.analysis.parser.jcreport.Report.class);
         digester.addSetProperties(report);
 
-        String file = "report/file";
+        var file = "report/file";
         digester.addObjectCreate(file, File.class);
         digester.addSetProperties(file, "package", "packageName");
         digester.addSetProperties(file, "src-dir", "srcdir");
         digester.addSetProperties(file);
         digester.addSetNext(file, "addFile", File.class.getName());
 
-        String item = "report/file/item";
+        var item = "report/file/item";
         digester.addObjectCreate(item, Item.class);
         digester.addSetProperties(item);
         digester.addSetProperties(item, "finding-type", "findingtype");
@@ -81,7 +81,7 @@ public edu.hm.hafner.analysis.parser.jcreport.Report createReport(final ReaderFa
         digester.addSetProperties(item, "end-column", "endcolumn");
         digester.addSetNext(item, "addItem", Item.class.getName());
 
-        try (Reader reader = readerFactory.create()) {
+        try (var reader = readerFactory.create()) {
             return digester.parse(reader);
         }
         catch (IOException | SAXException e) {
diff --git a/src/main/java/edu/hm/hafner/analysis/parser/pmd/PmdParser.java b/src/main/java/edu/hm/hafner/analysis/parser/pmd/PmdParser.java
index e2126a8b6..5743f8fee 100644
--- a/src/main/java/edu/hm/hafner/analysis/parser/pmd/PmdParser.java
+++ b/src/main/java/edu/hm/hafner/analysis/parser/pmd/PmdParser.java
@@ -1,7 +1,6 @@
 package edu.hm.hafner.analysis.parser.pmd;
 
 import java.io.IOException;
-import java.io.Reader;
 import java.io.Serial;
 
 import org.apache.commons.lang3.StringUtils;
@@ -31,7 +30,7 @@ public class PmdParser extends IssueParser {
 
     @Override
     public Report parse(final ReaderFactory readerFactory) throws ParsingException {
-        Report issues = parseIssues(readerFactory);
+        var issues = parseIssues(readerFactory);
         parseErrors(readerFactory).stream().forEach(issues::add);
         return issues;
     }
@@ -39,22 +38,22 @@ public Report parse(final ReaderFactory readerFactory) throws ParsingException {
     private Report parseIssues(final ReaderFactory readerFactory) {
         var digester = new SecureDigester(PmdParser.class);
 
-        String rootXPath = "pmd";
+        var rootXPath = "pmd";
         digester.addObjectCreate(rootXPath, Pmd.class);
         digester.addSetProperties(rootXPath);
 
-        String fileXPath = "pmd/file";
+        var fileXPath = "pmd/file";
         digester.addObjectCreate(fileXPath, File.class);
         digester.addSetProperties(fileXPath);
         digester.addSetNext(fileXPath, "addFile", File.class.getName());
 
-        String bugXPath = "pmd/file/violation";
+        var bugXPath = "pmd/file/violation";
         digester.addObjectCreate(bugXPath, Violation.class);
         digester.addSetProperties(bugXPath);
         digester.addCallMethod(bugXPath, "setMessage", 0);
         digester.addSetNext(bugXPath, "addViolation", Violation.class.getName());
 
-        try (Reader reader = readerFactory.create()) {
+        try (var reader = readerFactory.create()) {
             Pmd pmd = digester.parse(reader);
             if (pmd == null) {
                 throw new ParsingException("Input stream is not a PMD file.");
@@ -70,17 +69,17 @@ private Report parseIssues(final ReaderFactory readerFactory) {
     private Report parseErrors(final ReaderFactory readerFactory) {
         var digester = new SecureDigester(PmdParser.class);
 
-        String rootXPath = "pmd";
+        var rootXPath = "pmd";
         digester.addObjectCreate(rootXPath, Pmd.class);
         digester.addSetProperties(rootXPath);
 
-        String errorXPath = "pmd/error";
+        var errorXPath = "pmd/error";
         digester.addObjectCreate(errorXPath, PmdError.class);
         digester.addSetProperties(errorXPath);
         digester.addSetNext(errorXPath, "addError", PmdError.class.getName());
         digester.addCallMethod(errorXPath, "setDescription", 0);
 
-        try (Reader reader = readerFactory.create()) {
+        try (var reader = readerFactory.create()) {
             Pmd pmd = digester.parse(reader);
             if (pmd == null) {
                 throw new ParsingException("Input stream is not a PMD file.");
@@ -94,7 +93,7 @@ private Report parseErrors(final ReaderFactory readerFactory) {
     }
 
     private Report convertIssues(final Pmd pmdIssues) {
-        try (IssueBuilder issueBuilder = new IssueBuilder()) {
+        try (var issueBuilder = new IssueBuilder()) {
             var report = new Report();
             for (File file : pmdIssues.getFiles()) {
                 for (Violation warning : file.getViolations()) {
@@ -116,7 +115,7 @@ private Report convertIssues(final Pmd pmdIssues) {
     }
 
     private Report convertErrors(final Pmd pmdIssues) {
-        try (IssueBuilder issueBuilder = new IssueBuilder()) {
+        try (var issueBuilder = new IssueBuilder()) {
             var report = new Report();
             for (PmdError error : pmdIssues.getErrors()) {
                 issueBuilder.setSeverity(Severity.ERROR)
@@ -140,7 +139,7 @@ else if (warning.getPriority() > PMD_PRIORITY_MAPPED_TO_LOW_PRIORITY) {
     }
 
     private String createMessage(final Violation warning) {
-        String original = warning.getMessage();
+        var original = warning.getMessage();
         if (original == null) {
             return StringUtils.EMPTY;
         }
diff --git a/src/main/java/edu/hm/hafner/analysis/parser/pvsstudio/PlogMessagesReader.java b/src/main/java/edu/hm/hafner/analysis/parser/pvsstudio/PlogMessagesReader.java
index 63f1861c7..40c718e54 100644
--- a/src/main/java/edu/hm/hafner/analysis/parser/pvsstudio/PlogMessagesReader.java
+++ b/src/main/java/edu/hm/hafner/analysis/parser/pvsstudio/PlogMessagesReader.java
@@ -37,11 +37,11 @@ List getMessagesFromReport(final ReaderFactory readerFactory) {
         var plogDoc = readerFactory.readDocument();
         plogDoc.getDocumentElement().normalize();
 
-        NodeList nList = plogDoc.getElementsByTagName("PVS-Studio_Analysis_Log");
+        var nList = plogDoc.getElementsByTagName("PVS-Studio_Analysis_Log");
 
         List plogMessages = new ArrayList<>();
         for (int nodeCount = 0; nodeCount < nList.getLength(); nodeCount++) {
-            Node nNode = nList.item(nodeCount);
+            var nNode = nList.item(nodeCount);
 
             if (nNode.getNodeType() == Node.ELEMENT_NODE) {
                 processNode(plogMessages, nNode);
diff --git a/src/main/java/edu/hm/hafner/analysis/parser/pvsstudio/PvsStudioParser.java b/src/main/java/edu/hm/hafner/analysis/parser/pvsstudio/PvsStudioParser.java
index 6c0b78a83..c048e8885 100644
--- a/src/main/java/edu/hm/hafner/analysis/parser/pvsstudio/PvsStudioParser.java
+++ b/src/main/java/edu/hm/hafner/analysis/parser/pvsstudio/PvsStudioParser.java
@@ -40,7 +40,7 @@ else if (SEVERITY_LOW.equals(level)) {
 
     @Override
     public Report parse(final ReaderFactory readerFactory) throws ParsingException, ParsingCanceledException {
-        try (IssueBuilder issueBuilder = new IssueBuilder()) {
+        try (var issueBuilder = new IssueBuilder()) {
             var report = new Report();
             var parser = new PlogMessagesReader();
 
diff --git a/src/main/java/edu/hm/hafner/analysis/parser/pylint/PyLintDescriptions.java b/src/main/java/edu/hm/hafner/analysis/parser/pylint/PyLintDescriptions.java
index 8c1f02323..667633483 100644
--- a/src/main/java/edu/hm/hafner/analysis/parser/pylint/PyLintDescriptions.java
+++ b/src/main/java/edu/hm/hafner/analysis/parser/pylint/PyLintDescriptions.java
@@ -26,11 +26,11 @@ public class PyLintDescriptions {
     public PyLintDescriptions() {
         var parser = new JSONParser(JSONParser.MODE_JSON_SIMPLE);
 
-        try (InputStream inputStream = PyLintDescriptions.class.getResourceAsStream("pylint-descriptions.json")) {
+        try (var inputStream = PyLintDescriptions.class.getResourceAsStream("pylint-descriptions.json")) {
             var elements = (JSONArray) parser.parse(inputStream);
             for (Object element : elements) {
                 var object = (JSONObject) element;
-                String description = object.getAsString("description");
+                var description = object.getAsString("description");
                 descriptionByName.put(object.getAsString("name"), description);
                 descriptionById.put(object.getAsString("code"), description);
             }
diff --git a/src/main/java/edu/hm/hafner/analysis/parser/violations/AbstractViolationAdapter.java b/src/main/java/edu/hm/hafner/analysis/parser/violations/AbstractViolationAdapter.java
index c39c6bdd0..1e57b2984 100644
--- a/src/main/java/edu/hm/hafner/analysis/parser/violations/AbstractViolationAdapter.java
+++ b/src/main/java/edu/hm/hafner/analysis/parser/violations/AbstractViolationAdapter.java
@@ -36,7 +36,7 @@ public abstract class AbstractViolationAdapter extends IssueParser {
     public Report parse(final ReaderFactory readerFactory)
             throws ParsingCanceledException, ParsingException {
         try {
-            ViolationsParser parser = createParser();
+            var parser = createParser();
             Set violations = parser.parseReportOutput(readerFactory.readString(),
                     new NullViolationsLogger());
             return convertToReport(violations);
@@ -62,7 +62,7 @@ public Report parse(final ReaderFactory readerFactory)
      * @return the report
      */
     Report convertToReport(final Set violations) {
-        try (IssueBuilder builder = new IssueBuilder()) {
+        try (var builder = new IssueBuilder()) {
             var report = new Report();
 
             for (Violation violation : violations) {
diff --git a/src/main/java/edu/hm/hafner/analysis/parser/violations/CppCheckAdapter.java b/src/main/java/edu/hm/hafner/analysis/parser/violations/CppCheckAdapter.java
index f2e980f40..80f3b155f 100644
--- a/src/main/java/edu/hm/hafner/analysis/parser/violations/CppCheckAdapter.java
+++ b/src/main/java/edu/hm/hafner/analysis/parser/violations/CppCheckAdapter.java
@@ -30,7 +30,7 @@ CPPCheckParser createParser() {
 
     @Override
     Report convertToReport(final Set violations) {
-        try (IssueBuilder issueBuilder = new IssueBuilder()) {
+        try (var issueBuilder = new IssueBuilder()) {
             var violationsPerGroup = new LinkedHashSet<>(violations).stream()
                     .collect(Collectors.groupingBy(Violation::getGroup));
 
diff --git a/src/main/java/edu/hm/hafner/analysis/parser/violations/DocFxAdapter.java b/src/main/java/edu/hm/hafner/analysis/parser/violations/DocFxAdapter.java
index 480d19d54..118f913a2 100644
--- a/src/main/java/edu/hm/hafner/analysis/parser/violations/DocFxAdapter.java
+++ b/src/main/java/edu/hm/hafner/analysis/parser/violations/DocFxAdapter.java
@@ -6,7 +6,7 @@
 import se.bjurr.violations.lib.model.Violation;
 import se.bjurr.violations.lib.parsers.DocFXParser;
 
-import static se.bjurr.violations.lib.model.SEVERITY.*;
+import static se.bjurr.violations.lib.model.SEVERITY.INFO;
 
 /**
  * Parses DocFX files.
@@ -24,7 +24,7 @@ DocFXParser createParser() {
 
     @Override
     boolean isValid(final Violation violation) {
-        SEVERITY severity = violation.getSeverity();
+        var severity = violation.getSeverity();
         return severity != INFO;
     }
 }
diff --git a/src/main/java/edu/hm/hafner/analysis/parser/violations/JUnitAdapter.java b/src/main/java/edu/hm/hafner/analysis/parser/violations/JUnitAdapter.java
index 455c1d82c..350dc209e 100644
--- a/src/main/java/edu/hm/hafner/analysis/parser/violations/JUnitAdapter.java
+++ b/src/main/java/edu/hm/hafner/analysis/parser/violations/JUnitAdapter.java
@@ -35,7 +35,7 @@ JUnitParser createParser() {
 
     @Override
     public Report parse(final ReaderFactory readerFactory) throws ParsingCanceledException, ParsingException {
-        Report report = super.parse(readerFactory);
+        var report = super.parse(readerFactory);
         int total = count(readerFactory, " violations) {
-        try (IssueBuilder issueBuilder = new IssueBuilder()) {
+        try (var issueBuilder = new IssueBuilder()) {
             var report = new Report();
 
             for (Violation violation: violations) {
@@ -67,14 +67,13 @@ private String generateDescriptionHtml(final Violation violation) {
     }
 
     private ContainerTag generateGeneralTableHtml(final String executable, final String uniqueId, @CheckForNull final String threadId, @CheckForNull final String threadName, @CheckForNull final JSONArray auxWhats) {
-        ContainerTag generalTable =
-                table(
-                        attrs(".table.table-striped"),
-                        maybeGenerateTableRowHtml("Executable", executable),
-                        maybeGenerateTableRowHtml("Unique Id", uniqueId),
-                        maybeGenerateTableRowHtml("Thread Id", threadId),
-                        maybeGenerateTableRowHtml("Thread Name", threadName)
-                );
+        var generalTable = table(
+                attrs(".table.table-striped"),
+                maybeGenerateTableRowHtml("Executable", executable),
+                maybeGenerateTableRowHtml("Unique Id", uniqueId),
+                maybeGenerateTableRowHtml("Thread Id", threadId),
+                maybeGenerateTableRowHtml("Thread Name", threadName)
+        );
 
         if (auxWhats != null && !auxWhats.isEmpty()) {
             for (int auxwhatIndex = 0; auxwhatIndex < auxWhats.length(); auxwhatIndex++) {
@@ -105,7 +104,7 @@ private ContainerTag maybeGenerateStackTracesHtml(@CheckForNull final String sta
                     msg = auxWhats.getString(stackIndex - 1);
                 }
 
-                String title = "Auxiliary Stack Trace";
+                var title = "Auxiliary Stack Trace";
 
                 if (stacks.length() > NUMBERED_STACK_THRESHOLD) {
                     title += " #" + stackIndex;
@@ -164,10 +163,10 @@ private ContainerTag maybeGenerateTableRowHtml(final String name, @CheckForNull
 
     @CheckForNull
     private ContainerTag maybeGenerateStackFrameFileTableRowHtml(final JSONObject frame) throws JSONException {
-        String file = frame.optString("file");
+        var file = frame.optString("file");
 
         if (StringUtils.isNotBlank(file)) {
-            String dir = frame.optString("dir");
+            var dir = frame.optString("dir");
             int line = frame.optInt("line", NO_LINE);
             var fileBuilder = new StringBuilder(256);
 
@@ -189,7 +188,7 @@ private ContainerTag maybeGenerateStackFrameFileTableRowHtml(final JSONObject fr
 
     @CheckForNull
     private JSONArray getAuxWhatsArray(final Map specifics) {
-        String auxWhatsJson = specifics.get("auxwhats");
+        var auxWhatsJson = specifics.get("auxwhats");
         return StringUtils.isNotBlank(auxWhatsJson) ? new JSONArray(new JSONTokener(auxWhatsJson)) : null;
     }
 }
diff --git a/src/main/java/edu/hm/hafner/analysis/registry/DryDescriptor.java b/src/main/java/edu/hm/hafner/analysis/registry/DryDescriptor.java
index 36391449d..02e08ae46 100644
--- a/src/main/java/edu/hm/hafner/analysis/registry/DryDescriptor.java
+++ b/src/main/java/edu/hm/hafner/analysis/registry/DryDescriptor.java
@@ -50,8 +50,8 @@ private int convertThreshold(final String key, final int defaultValue, final Opt
     }
 
     private String getDuplicateCode(@CheckForNull final Serializable properties) {
-        if (properties instanceof DuplicationGroup) {
-            return pre().with(new UnescapedText(getCodeFragment((DuplicationGroup) properties)))
+        if (properties instanceof DuplicationGroup group) {
+            return pre().with(new UnescapedText(getCodeFragment(group)))
                     .renderFormatted();
         }
         else {
diff --git a/src/main/java/edu/hm/hafner/analysis/registry/IarCstatDescriptor.java b/src/main/java/edu/hm/hafner/analysis/registry/IarCstatDescriptor.java
index 8a4c4b4a8..3db63801f 100644
--- a/src/main/java/edu/hm/hafner/analysis/registry/IarCstatDescriptor.java
+++ b/src/main/java/edu/hm/hafner/analysis/registry/IarCstatDescriptor.java
@@ -23,14 +23,15 @@ public IssueParser createParser(final Option... options) {
 
     @Override
     public String getHelp() {
-        return "

The IAR C-STAT static analysis tool finds potential issues in code by doing an analysis " - + "on the source code level. Use the following icstat command to generate the output on " - + "stdout in the correct format:

"
-                + "icstat --db a.db --checks checks.ch commands commands.txt"
-                + "
where the commands.txt contains:
"
-                + "analyze - iccxxxxcompiler_opts cstat1.c\n"
-                + "analyze - iccxxxxcompiler_opts cstat2.c"
-                + "
" - + "For details check the IAR C-STAT guide.

"; + return """ +

The IAR C-STAT static analysis tool finds potential issues in code by doing an analysis \ + on the source code level. Use the following icstat command to generate the output on \ + stdout in the correct format:

\
+                icstat --db a.db --checks checks.ch commands commands.txt\
+                
where the commands.txt contains:
\
+                analyze - iccxxxxcompiler_opts cstat1.c
+                analyze - iccxxxxcompiler_opts cstat2.c\
+                
\ + For details check the IAR C-STAT guide.

"""; } } diff --git a/src/main/java/edu/hm/hafner/analysis/registry/ParserRegistry.java b/src/main/java/edu/hm/hafner/analysis/registry/ParserRegistry.java index ae6fe93b1..57bdea582 100644 --- a/src/main/java/edu/hm/hafner/analysis/registry/ParserRegistry.java +++ b/src/main/java/edu/hm/hafner/analysis/registry/ParserRegistry.java @@ -257,21 +257,23 @@ public static void main(final String... unused) throws IOException { List descriptors = new ParserRegistry().getAllDescriptors(); descriptors.sort(Comparator.comparing(ParserDescriptor::getName)); - try (PrintWriter file = new PrintWriter("SUPPORTED-FORMATS.md", StandardCharsets.UTF_8)) { + try (var file = new PrintWriter("SUPPORTED-FORMATS.md", StandardCharsets.UTF_8)) { file.printf("%n", LocalDateTime.now(ZoneId.of("Europe/Berlin")), ParserRegistry.class.getSimpleName()); - file.println("# Supported Report Formats\n" - + "\n" - + "The static analysis model supports the following report formats.\n" - + "\n" - + "If your tool is not yet supported, you can\n" - + "1. export the issues of your tool to the native XML or JSON format (or any other format).\n" - + "2. provide a [pull request](https://github.com/jenkinsci/analysis-model/pulls) with a new parser.\n" - + "\n" - + "If your tool is supported, but some properties are missing (icon, URL, etc.), please file a " - + "[pull request](https://github.com/jenkinsci/analysis-model/pulls).\n" - + "\n"); + file.println(""" + # Supported Report Formats + + The static analysis model supports the following report formats. + + If your tool is not yet supported, you can + 1. export the issues of your tool to the native XML or JSON format (or any other format). + 2. provide a [pull request](https://github.com/jenkinsci/analysis-model/pulls) with a new parser. + + If your tool is supported, but some properties are missing (icon, URL, etc.), please file a \ + [pull request](https://github.com/jenkinsci/analysis-model/pulls). + + """); List lines = descriptors.stream() .map(ParserRegistry::getTableRows) @@ -302,8 +304,8 @@ private static List getTableRows(final ParserDescriptor descriptor } private static DomContent getName(final ParserDescriptor descriptor) { - String name = descriptor.getName(); - String url = descriptor.getUrl(); + var name = descriptor.getName(); + var url = descriptor.getUrl(); if (url.isEmpty()) { return text(name); } @@ -311,7 +313,7 @@ private static DomContent getName(final ParserDescriptor descriptor) { } private static DomContent getIcon(final ParserDescriptor descriptor) { - String url = descriptor.getIconUrl(); + var url = descriptor.getIconUrl(); if (url.isEmpty()) { return text("-"); } diff --git a/src/main/java/edu/hm/hafner/analysis/registry/PcLintDescriptor.java b/src/main/java/edu/hm/hafner/analysis/registry/PcLintDescriptor.java index 6524bbcd8..dd3880af6 100644 --- a/src/main/java/edu/hm/hafner/analysis/registry/PcLintDescriptor.java +++ b/src/main/java/edu/hm/hafner/analysis/registry/PcLintDescriptor.java @@ -23,11 +23,12 @@ public IssueParser createParser(final Option... options) { @Override public String getHelp() { - return "

Use the following PC-Lint properties to create an output file in the correct format:

"
-                + "-v // turn off verbosity\n"
-                + "-width(0) // don't insert line breaks (unlimited output width)\n"
-                + "-\"format=%f(%l): %t %n: %m\"\n"
-                + "-hs1 // The height of a message should be 1\n"
-                + "

"; + return """ +

Use the following PC-Lint properties to create an output file in the correct format:

\
+                -v // turn off verbosity
+                -width(0) // don't insert line breaks (unlimited output width)
+                -"format=%f(%l): %t %n: %m"
+                -hs1 // The height of a message should be 1
+                

"""; } } diff --git a/src/main/java/edu/hm/hafner/analysis/util/Deferred.java b/src/main/java/edu/hm/hafner/analysis/util/Deferred.java index 76dbac8ed..d58e7a166 100644 --- a/src/main/java/edu/hm/hafner/analysis/util/Deferred.java +++ b/src/main/java/edu/hm/hafner/analysis/util/Deferred.java @@ -33,7 +33,7 @@ public Deferred(final Supplier supplier) { * @return the instance */ public T get() { - T tmp = object; + var tmp = object; if (tmp == null) { tmp = supplier.get(); } diff --git a/src/main/java/edu/hm/hafner/analysis/util/XmlElementUtil.java b/src/main/java/edu/hm/hafner/analysis/util/XmlElementUtil.java index 347aaf707..c5033c3a4 100644 --- a/src/main/java/edu/hm/hafner/analysis/util/XmlElementUtil.java +++ b/src/main/java/edu/hm/hafner/analysis/util/XmlElementUtil.java @@ -31,7 +31,7 @@ public final class XmlElementUtil { public static List getChildElementsByName(final Element parent, final String name) { List elements = new ArrayList<>(); if (parent != null) { - Node child = parent.getFirstChild(); + var child = parent.getFirstChild(); while (child != null) { if (child.getNodeType() == Node.ELEMENT_NODE && child.getNodeName().equals(name)) { elements.add((Element) child); @@ -71,7 +71,7 @@ public static List nodeListToList(@CheckForNull final NodeList nodeList int length = nodeList.getLength(); List elements = new ArrayList<>(length); for (int i = 0; i < length; i++) { - Node node = nodeList.item(i); + var node = nodeList.item(i); if (node.getNodeType() == Node.ELEMENT_NODE) { elements.add((Element) node); } diff --git a/src/test/java/edu/hm/hafner/analysis/AbstractBenchmark.java b/src/test/java/edu/hm/hafner/analysis/AbstractBenchmark.java index 1be6e5cc0..e0203cd01 100644 --- a/src/test/java/edu/hm/hafner/analysis/AbstractBenchmark.java +++ b/src/test/java/edu/hm/hafner/analysis/AbstractBenchmark.java @@ -27,7 +27,7 @@ public abstract class AbstractBenchmark { */ @Test public void benchmark() throws RunnerException { - Options opt = new OptionsBuilder() + var opt = new OptionsBuilder() .include(this.getClass().getName() + ".*") .addProfiler(StackProfiler.class) .build(); diff --git a/src/test/java/edu/hm/hafner/analysis/AbstractModuleDetectorTest.java b/src/test/java/edu/hm/hafner/analysis/AbstractModuleDetectorTest.java index 2a9633b28..2689bf793 100644 --- a/src/test/java/edu/hm/hafner/analysis/AbstractModuleDetectorTest.java +++ b/src/test/java/edu/hm/hafner/analysis/AbstractModuleDetectorTest.java @@ -5,7 +5,6 @@ import java.io.IOException; import java.io.InputStream; import java.nio.file.Path; -import java.nio.file.Paths; import org.apache.commons.lang3.StringUtils; import org.junit.jupiter.api.Test; @@ -18,15 +17,15 @@ import static org.mockito.Mockito.*; abstract class AbstractModuleDetectorTest extends ResourceTest { - static final Path ROOT = Paths.get(File.pathSeparatorChar == ';' ? "C:\\Windows" : "/tmp"); - static final Path ROOT_ABSOLUTE = Paths.get(File.pathSeparatorChar == ';' ? "C:\\" : "/"); + static final Path ROOT = Path.of(File.pathSeparatorChar == ';' ? "C:\\Windows" : "/tmp"); + static final Path ROOT_ABSOLUTE = Path.of(File.pathSeparatorChar == ';' ? "C:\\" : "/"); static final String PREFIX = new PathUtil().getAbsolutePath(ROOT) + "/"; static final String MANIFEST = "MANIFEST.MF"; static final String MANIFEST_NAME = "MANIFEST-NAME.MF"; @Test void shouldIgnoreExceptionsDuringParsing() { - FileSystem fileSystem = createFileSystemStub(stub -> { + var fileSystem = createFileSystemStub(stub -> { when(stub.find(any(), anyString())).thenReturn(new String[]{ getPathPrefix() + getProjectFileName() }); @@ -46,7 +45,7 @@ void shouldIgnoreExceptionsDuringParsing() { protected FileSystem createFileSystemStub(final Stub stub) { try { - FileSystem fileSystem = mock(FileSystem.class); + var fileSystem = mock(FileSystem.class); stub.apply(fileSystem); return fileSystem; } diff --git a/src/test/java/edu/hm/hafner/analysis/CSharpNamespaceDetectorTest.java b/src/test/java/edu/hm/hafner/analysis/CSharpNamespaceDetectorTest.java index 8fd7b17b0..369970c85 100644 --- a/src/test/java/edu/hm/hafner/analysis/CSharpNamespaceDetectorTest.java +++ b/src/test/java/edu/hm/hafner/analysis/CSharpNamespaceDetectorTest.java @@ -27,7 +27,7 @@ class CSharpNamespaceDetectorTest extends ResourceTest { "pom.xml, -", "MavenJavaTest.txt, -"}) void shouldExtractPackageNameFromJavaSource(final String fileName, final String expectedPackage) throws IOException { - try (InputStream stream = asInputStream(fileName)) { + try (var stream = asInputStream(fileName)) { assertThat(new CSharpNamespaceDetector().detectPackageName(stream, StandardCharsets.UTF_8)) .isEqualTo(expectedPackage); } diff --git a/src/test/java/edu/hm/hafner/analysis/DuplicationGroupTest.java b/src/test/java/edu/hm/hafner/analysis/DuplicationGroupTest.java index df9dae26d..627d225c9 100644 --- a/src/test/java/edu/hm/hafner/analysis/DuplicationGroupTest.java +++ b/src/test/java/edu/hm/hafner/analysis/DuplicationGroupTest.java @@ -27,7 +27,7 @@ class DuplicationGroupTest extends SerializableTest { protected DuplicationGroup createSerializable() { var group = new DuplicationGroup(); - try (IssueBuilder builder = new IssueBuilder()) { + try (var builder = new IssueBuilder()) { group.add(builder.setAdditionalProperties(group).setFileName("1").build()); group.add(builder.setAdditionalProperties(group).setFileName("2").build()); } @@ -47,7 +47,7 @@ protected void assertThatRestoredInstanceEqualsOriginalInstance( */ @Test void shouldReadIssueFromOldSerialization() { - byte[] restored = readAllBytes(SERIALIZATION_NAME); + var restored = readAllBytes(SERIALIZATION_NAME); assertThatSerializableCanBeRestoredFrom(restored); } @@ -81,13 +81,13 @@ void shouldNotOverwriteFragmentOnceItHasBeenSet() { @Test void shouldReferenceAllDuplications() { - try (IssueBuilder builder = new IssueBuilder()) { + try (var builder = new IssueBuilder()) { var group = new DuplicationGroup(CODE_FRAGMENT); assertThat(group.getDuplications()).isEmpty(); - Issue first = builder.setAdditionalProperties(group).build(); - Issue second = builder.setAdditionalProperties(group).build(); + var first = builder.setAdditionalProperties(group).build(); + var second = builder.setAdditionalProperties(group).build(); group.add(first); group.add(second); @@ -99,7 +99,7 @@ void shouldReferenceAllDuplications() { @Test void shouldObeyEqualsContract() { - try (IssueBuilder builder = new IssueBuilder()) { + try (var builder = new IssueBuilder()) { var red = new LineRangeList(); red.add(new LineRange(1)); var blue = new LineRangeList(); diff --git a/src/test/java/edu/hm/hafner/analysis/FileNameResolverTest.java b/src/test/java/edu/hm/hafner/analysis/FileNameResolverTest.java index 36f28c845..796664569 100644 --- a/src/test/java/edu/hm/hafner/analysis/FileNameResolverTest.java +++ b/src/test/java/edu/hm/hafner/analysis/FileNameResolverTest.java @@ -6,7 +6,6 @@ import java.net.URISyntaxException; import java.net.URL; import java.nio.file.Path; -import java.nio.file.Paths; import java.util.function.Predicate; import java.util.stream.Collectors; @@ -29,7 +28,7 @@ @SuppressFBWarnings("DMI") class FileNameResolverTest { private static final URI RESOURCE_FOLDER = getResourceFolder(); - private static final Path RESOURCE_FOLDER_PATH = Paths.get(RESOURCE_FOLDER); + private static final Path RESOURCE_FOLDER_PATH = Path.of(RESOURCE_FOLDER); private static final String RESOURCE_FOLDER_STRING = getResourcePath(); private static final String ID = "ID"; @@ -79,7 +78,7 @@ void shouldDoNothingIfNoIssuesPresent() { void shouldSetPath() { var report = new Report(); - try (IssueBuilder builder = new IssueBuilder()) { + try (var builder = new IssueBuilder()) { report.add(builder.setFileName(RELATIVE_FILE).build()); } @@ -100,7 +99,7 @@ void shouldSetPath() { void shouldNotSetPath() { var report = new Report(); - try (IssueBuilder builder = new IssueBuilder()) { + try (var builder = new IssueBuilder()) { report.add(builder.setFileName("not here").build()); } @@ -121,7 +120,7 @@ void shouldNotSetPath() { void shouldNotTouchAbsolutePathOrEmptyPath() { var report = new Report(); - try (IssueBuilder builder = new IssueBuilder()) { + try (var builder = new IssueBuilder()) { report.add(builder.setFileName("").build()); report.add(builder.setFileName("skip").build()); report.add(builder.setFileName(RELATIVE_FILE).build()); @@ -169,7 +168,7 @@ void shouldNotTouchAbsolutePathOrEmptyPath() { @ValueSource(strings = {"../analysis/relative.txt", "./relative.txt", "../../hafner/analysis/relative.txt"}) @DisplayName("Should normalize different relative paths to the same file (file name is relative)") void shouldResolveRelativePath(final String fileName) { - try (IssueBuilder builder = new IssueBuilder()) { + try (var builder = new IssueBuilder()) { var report = createIssuesSingleton(fileName, builder.setOrigin(ID)); resolvePaths(report, RESOURCE_FOLDER_PATH); @@ -181,22 +180,22 @@ void shouldResolveRelativePath(final String fileName) { @ValueSource(strings = {"../analysis/relative.txt", "./relative.txt", "../../hafner/analysis/relative.txt"}) @DisplayName("Should normalize different relative paths to the same file (file name is absolute)") void shouldNormalizePaths(final String fileName) { - try (IssueBuilder issueBuilder = new IssueBuilder()) { - Issue issue = issueBuilder + try (var issueBuilder = new IssueBuilder()) { + var issue = issueBuilder .setDirectory(RESOURCE_FOLDER_STRING) .setFileName(normalize(fileName)) .build(); var report = new Report(); report.add(issue); - resolvePaths(report, Paths.get(RESOURCE_FOLDER)); + resolvePaths(report, Path.of(RESOURCE_FOLDER)); assertThatFileResolvesToRelativeFile(report, fileName); } } private void assertThatFileResolvesToRelativeFile(final Report report, final String fileName) { - String description = String.format("Resolving file '%s'", normalize(fileName)); + var description = "Resolving file '%s'".formatted(normalize(fileName)); assertThat(report.get(0).getFileName()).as(description).isEqualTo(RELATIVE_FILE); assertThat(report.getErrorMessages()).as(description).isEmpty(); assertThat(report.getInfoMessages()).as(description).hasSize(1); @@ -206,10 +205,10 @@ private void assertThatFileResolvesToRelativeFile(final Report report, final Str @Test @DisplayName("Should replace relative issue path with absolute path in relative path of workspace") void shouldResolveRelativePathInWorkspaceSubFolder() { - try (IssueBuilder builder = new IssueBuilder()) { + try (var builder = new IssueBuilder()) { Report report; - String fileName = "child.txt"; + var fileName = "child.txt"; report = createIssuesSingleton(fileName, builder.setOrigin(ID)); resolvePaths(report, RESOURCE_FOLDER_PATH); @@ -233,7 +232,7 @@ private void assertThatOneFileIsUnresolved(final Report report) { } private static String getResourcePath() { - String workspace = RESOURCE_FOLDER.getPath(); + var workspace = RESOURCE_FOLDER.getPath(); if (isWindows() && workspace.charAt(0) == SLASH) { workspace = workspace.substring(1); } @@ -251,7 +250,7 @@ private static boolean isWindows() { private Report createIssuesSingleton(final String fileName, final IssueBuilder issueBuilder) { var report = new Report(); - Issue issue = issueBuilder.setFileName(fileName).build(); + var issue = issueBuilder.setFileName(fileName).build(); report.add(issue); return report; } @@ -262,8 +261,8 @@ private String normalize(final String fileName) { private static URI getResourceFolder() { try { - URL resource = FileNameResolverTest.class.getResource(RELATIVE_FILE); - String fileName = resource.toExternalForm(); + var resource = FileNameResolverTest.class.getResource(RELATIVE_FILE); + var fileName = resource.toExternalForm(); return new URL(fileName.replace(RELATIVE_FILE, "")).toURI(); } catch (MalformedURLException | URISyntaxException e) { diff --git a/src/test/java/edu/hm/hafner/analysis/FileReaderFactoryTest.java b/src/test/java/edu/hm/hafner/analysis/FileReaderFactoryTest.java index a7a4f0633..cd3d02f4f 100644 --- a/src/test/java/edu/hm/hafner/analysis/FileReaderFactoryTest.java +++ b/src/test/java/edu/hm/hafner/analysis/FileReaderFactoryTest.java @@ -8,7 +8,6 @@ import java.nio.file.Path; import org.junit.jupiter.api.Test; -import org.w3c.dom.Document; import com.google.errorprone.annotations.MustBeClosed; @@ -29,64 +28,66 @@ void shouldRemoveColorCodesAfterAllLineMappers() { var factory = new ConsoleLogReaderFactory( getResourceAsFile("ath-colored.log")); - assertThat(factory.readString()).isEqualTo("[WARNING]\n" - + "[WARNING] Some problems were encountered while building the effective model for edu.hm.hafner.irrelevant.groupId:random-artifactId:jar:1.0\n" - + "[WARNING] 'build.plugins.plugin.version' for org.apache.maven.plugins:maven-compiler-plugin is missing. @ line 13, column 15\n" - + "[WARNING] \n" - + "[WARNING] It is highly recommended to fix these problems because they threaten the stability of your build.\n" - + "[WARNING] \n" - + "[WARNING] For this reason, future Maven versions might no longer support building such malformed projects.\n" - + "[WARNING] "); + assertThat(factory.readString()).isEqualToIgnoringWhitespace(""" + [WARNING] + [WARNING] Some problems were encountered while building the effective model for edu.hm.hafner.irrelevant.groupId:random-artifactId:jar:1.0 + [WARNING] 'build.plugins.plugin.version' for org.apache.maven.plugins:maven-compiler-plugin is missing. @ line 13, column 15 + [WARNING] + [WARNING] It is highly recommended to fix these problems because they threaten the stability of your build. + [WARNING] + [WARNING] For this reason, future Maven versions might no longer support building such malformed projects. + [WARNING] + """); } @Test void shouldNotAccessInternet() { - FileReaderFactory factory = createFactory("eclipse-withinfo.xml", UTF_8); - Document document = factory.readDocument(); + var factory = createFactory("eclipse-withinfo.xml", UTF_8); + var document = factory.readDocument(); assertThat(document).isNotNull(); } @Test void useDefinedEncodingUtf8() { - FileReaderFactory factory = createFactory("encoded-with-UTF8.xml", UTF_8); + var factory = createFactory("encoded-with-UTF8.xml", UTF_8); assertEncoding(factory, UTF_8); } @Test void detectEncodingOfUtf8XmlFile() { - FileReaderFactory factory = createFactory("encoded-with-UTF8.xml"); + var factory = createFactory("encoded-with-UTF8.xml"); assertEncoding(factory, UTF_8); } @Test void useDefinedEncodingIso88591() { - FileReaderFactory factory = createFactory("encoded-with-ISO8859-1.xml", StandardCharsets.ISO_8859_1); + var factory = createFactory("encoded-with-ISO8859-1.xml", StandardCharsets.ISO_8859_1); assertEncoding(factory, StandardCharsets.ISO_8859_1); } @Test void detectEncodingOfIso88591XmlFile() { - FileReaderFactory factory = createFactory("encoded-with-ISO8859-1.xml"); + var factory = createFactory("encoded-with-ISO8859-1.xml"); assertEncoding(factory, StandardCharsets.ISO_8859_1); } @Test void detectEncodingWithoutEncodingXmlFile() { - FileReaderFactory factory = createFactory("encoded-without-encoding.xml"); + var factory = createFactory("encoded-without-encoding.xml"); assertEncoding(factory, UTF_8); } @Test void detectEncodingOfTextFile() { - FileReaderFactory factory = createFactory("context.txt"); + var factory = createFactory("context.txt"); factory.readString(); assertThat(factory.getCharset()).isEqualTo(UTF_8); } private void assertEncoding(final FileReaderFactory factory, final Charset charset) { - Document document = factory.readDocument(); + var document = factory.readDocument(); assertThat(factory.getCharset()).isEqualTo(charset); assertThat(document.getElementsByTagName("text").item(0).getChildNodes().item(0).getNodeValue()) .isEqualTo("aä"); @@ -113,7 +114,7 @@ static class ConsoleLogReaderFactory extends ReaderFactory { private static final String POSTAMBLE_STR = "\u001B[0m"; private static String removeNotes(final String wholeLine) { - String line = wholeLine; + var line = wholeLine; while (true) { int start = line.indexOf(PREAMBLE_STR); if (start < 0) { diff --git a/src/test/java/edu/hm/hafner/analysis/FingerprintGeneratorBenchmark.java b/src/test/java/edu/hm/hafner/analysis/FingerprintGeneratorBenchmark.java index c8302951f..4e41d403e 100644 --- a/src/test/java/edu/hm/hafner/analysis/FingerprintGeneratorBenchmark.java +++ b/src/test/java/edu/hm/hafner/analysis/FingerprintGeneratorBenchmark.java @@ -89,7 +89,7 @@ public void doSetup() { @SuppressFBWarnings("PREDICTABLE_RANDOM") private Report createMultipleIssues(final int number) { var report = new Report(); - try (IssueBuilder builder = new IssueBuilder()) { + try (var builder = new IssueBuilder()) { builder.setFileName(AFFECTED_FILE_NAME); for (int i = 0; i < number; i++) { builder.setLineStart(random.nextInt() * 26); diff --git a/src/test/java/edu/hm/hafner/analysis/FingerprintGeneratorTest.java b/src/test/java/edu/hm/hafner/analysis/FingerprintGeneratorTest.java index 24d529584..ad0bc8650 100644 --- a/src/test/java/edu/hm/hafner/analysis/FingerprintGeneratorTest.java +++ b/src/test/java/edu/hm/hafner/analysis/FingerprintGeneratorTest.java @@ -30,13 +30,13 @@ void shouldSkipFingerprintingIfEncodingIsWrong() throws IOException { var generator = new FingerprintGenerator(); Report report; - try (IssueBuilder issueBuilder = new IssueBuilder()) { + try (var issueBuilder = new IssueBuilder()) { issueBuilder.setFileName(AFFECTED_FILE_NAME); report = createIssues(); report.add(issueBuilder.build()); } - FileSystem fileSystem = mock(FileSystem.class); + var fileSystem = mock(FileSystem.class); when(fileSystem.readLinesFromFile(anyString(), any())) .thenThrow(new UncheckedIOException(new MalformedInputException(1))); @@ -44,20 +44,20 @@ void shouldSkipFingerprintingIfEncodingIsWrong() throws IOException { assertThatIssueHasDefaultFingerprint(report); assertThat(report.getErrorMessages()).contains( - String.format("- 'file.txt', provided encoding '%s' seems to be wrong", CHARSET_AFFECTED_FILE)); + "- 'file.txt', provided encoding '%s' seems to be wrong".formatted(CHARSET_AFFECTED_FILE)); } @Test void shouldNotChangeIssuesWithFingerPrint() { - try (IssueBuilder issueBuilder = new IssueBuilder()) { + try (var issueBuilder = new IssueBuilder()) { var generator = new FingerprintGenerator(); issueBuilder.setFileName(AFFECTED_FILE_NAME); - Report report = createIssues(); + var report = createIssues(); report.add(issueBuilder.build()); assertThat(report.get(0).hasFingerprint()).isFalse(); - String alreadySet = "already-set"; + var alreadySet = "already-set"; report.add(issueBuilder.setFingerprint(alreadySet).setMessage(AFFECTED_FILE_NAME).build()); generator.run(createFullTextFingerprint("fingerprint-two.txt"), report, CHARSET_AFFECTED_FILE); @@ -69,7 +69,7 @@ void shouldNotChangeIssuesWithFingerPrint() { @Test void shouldSetDefaultFingerprintIfNoFileIsGiven() { - try (IssueBuilder issueBuilder = new IssueBuilder()) { + try (var issueBuilder = new IssueBuilder()) { var generator = new FingerprintGenerator(); var report = new Report(); @@ -123,8 +123,8 @@ void shouldAssignDifferentFingerprint() { generator.run(fingerprint, report, CHARSET_AFFECTED_FILE); - Issue referenceIssue = report.get(0); - Issue currentIssue = report.get(1); + var referenceIssue = report.get(0); + var currentIssue = report.get(1); assertThat(referenceIssue).isNotEqualTo(currentIssue); assertThat(referenceIssue.getFingerprint()).isNotEqualTo(currentIssue.getFingerprint()); @@ -170,7 +170,7 @@ void shouldUseFallbackFingerprintOnIllegalFilenamesOnWindows(final String fileNa } private Report createReportWithOneIssueFor(final String fileName) { - try (IssueBuilder issueBuilder = new IssueBuilder()) { + try (var issueBuilder = new IssueBuilder()) { var report = new Report(); report.add(issueBuilder.setFileName(fileName).build()); return report; @@ -182,14 +182,14 @@ private void assertThatIssueHasDefaultFingerprint(final Report report) { } private FullTextFingerprint createFullTextFingerprint(final String secondFile) { - FileSystem fileSystem = stubFileSystem("fingerprint-one.txt", secondFile); + var fileSystem = stubFileSystem("fingerprint-one.txt", secondFile); return new FullTextFingerprint(fileSystem); } private Report createTwoIssues() { - try (IssueBuilder builder = new IssueBuilder()) { - Report report = createIssues(); + try (var builder = new IssueBuilder()) { + var report = createIssues(); builder.setFileName(AFFECTED_FILE_NAME); builder.setLineStart(5); report.add(builder.setPackageName("a").build()); diff --git a/src/test/java/edu/hm/hafner/analysis/GradleModuleDetectorTest.java b/src/test/java/edu/hm/hafner/analysis/GradleModuleDetectorTest.java index 633cc294e..0091eda0e 100644 --- a/src/test/java/edu/hm/hafner/analysis/GradleModuleDetectorTest.java +++ b/src/test/java/edu/hm/hafner/analysis/GradleModuleDetectorTest.java @@ -33,7 +33,7 @@ String getProjectFileName() { @Test void shouldIdentifyModuleByReadingGradlePath() { - FileSystem factory = createFileSystemStub(stub -> + var factory = createFileSystemStub(stub -> when(stub.find(any(), anyString())).thenReturn( new String[]{PATH_PREFIX_GRADLE + GradleModuleDetector.BUILD_GRADLE})); @@ -47,7 +47,7 @@ void shouldIdentifyModuleByReadingGradlePath() { @Test void shouldIdentifyModuleByFindingClosestGradlePath() { - FileSystem factory = createFileSystemStub(stub -> + var factory = createFileSystemStub(stub -> when(stub.find(any(), anyString())).thenReturn(new String[]{ PATH_PREFIX_GRADLE + GradleModuleDetector.BUILD_GRADLE, PATH_PREFIX_GRADLE + "moduleB/" + GradleModuleDetector.BUILD_GRADLE, @@ -55,7 +55,7 @@ void shouldIdentifyModuleByFindingClosestGradlePath() { })); var detector = new ModuleDetector(ROOT, factory); - String gradleWorkspace = PREFIX + PATH_PREFIX_GRADLE; + var gradleWorkspace = PREFIX + PATH_PREFIX_GRADLE; assertThat(detector.guessModuleName( gradleWorkspace + "a-module/build/reports/something.txt")) @@ -71,7 +71,7 @@ void shouldIdentifyModuleByFindingClosestGradlePath() { @Test void shouldIdentifyModuleByReadingGradleKtsPath() { - FileSystem factory = createFileSystemStub(stub -> + var factory = createFileSystemStub(stub -> when(stub.find(any(), anyString())).thenReturn( new String[]{PATH_PREFIX_GRADLE + GradleModuleDetector.BUILD_GRADLE_KTS})); @@ -85,7 +85,7 @@ void shouldIdentifyModuleByReadingGradleKtsPath() { @Test void shouldIdentifyModuleByReadingGradleSettings() { - FileSystem factory = createFileSystemStub(stub -> { + var factory = createFileSystemStub(stub -> { when(stub.find(any(), anyString())).thenReturn(new String[]{ PATH_PREFIX_GRADLE + GradleModuleDetector.SETTINGS_GRADLE, PATH_PREFIX_GRADLE + "moduleB/" + GradleModuleDetector.BUILD_GRADLE, @@ -95,7 +95,7 @@ void shouldIdentifyModuleByReadingGradleSettings() { }); var detector = new ModuleDetector(ROOT, factory); - String gradleWorkspace = PREFIX + PATH_PREFIX_GRADLE; + var gradleWorkspace = PREFIX + PATH_PREFIX_GRADLE; assertThat(detector.guessModuleName( gradleWorkspace + "a-module/build/reports/something.txt")) @@ -111,7 +111,7 @@ void shouldIdentifyModuleByReadingGradleSettings() { @Test void shouldIdentifyModuleByReadingGradleSettingsKts() { - FileSystem factory = createFileSystemStub(stub -> { + var factory = createFileSystemStub(stub -> { when(stub.find(any(), anyString())).thenReturn(new String[]{ PATH_PREFIX_GRADLE + GradleModuleDetector.SETTINGS_GRADLE_KTS, }); @@ -119,7 +119,7 @@ void shouldIdentifyModuleByReadingGradleSettingsKts() { }); var detector = new ModuleDetector(ROOT, factory); - String gradleWorkspace = PREFIX + PATH_PREFIX_GRADLE; + var gradleWorkspace = PREFIX + PATH_PREFIX_GRADLE; assertThat(detector.guessModuleName(gradleWorkspace + "build/reports/something.txt")) .isEqualTo(EXPECTED_GRADLE_MODULE_ROOT); @@ -129,7 +129,7 @@ void shouldIdentifyModuleByReadingGradleSettingsKts() { @Test void shouldEnsureThatGradleSettingsHasPrecedenceOverRootBuild() { - FileSystem factory = createFileSystemStub(stub -> { + var factory = createFileSystemStub(stub -> { when(stub.find(any(), anyString())).thenReturn(new String[]{ PATH_PREFIX_GRADLE + GradleModuleDetector.BUILD_GRADLE, PATH_PREFIX_GRADLE + GradleModuleDetector.SETTINGS_GRADLE, @@ -140,7 +140,7 @@ void shouldEnsureThatGradleSettingsHasPrecedenceOverRootBuild() { }); var detector = new ModuleDetector(ROOT, factory); - String gradleWorkspace = PREFIX + PATH_PREFIX_GRADLE; + var gradleWorkspace = PREFIX + PATH_PREFIX_GRADLE; assertThat(detector.guessModuleName( gradleWorkspace + "a-module/build/reports/something.txt")) @@ -156,14 +156,14 @@ void shouldEnsureThatGradleSettingsHasPrecedenceOverRootBuild() { @Test void shouldEnsureThatGradleSettingsCanParseFormat1() { - FileSystem factory = createFileSystemStub(stub -> { + var factory = createFileSystemStub(stub -> { when(stub.find(any(), anyString())).thenReturn(new String[]{ PATH_PREFIX_GRADLE + GradleModuleDetector.SETTINGS_GRADLE, }); when(stub.open(anyString())).thenAnswer(fileName -> read("settings-1.gradle")); }); - String gradleWorkspace = PREFIX + PATH_PREFIX_GRADLE; + var gradleWorkspace = PREFIX + PATH_PREFIX_GRADLE; var detector = new ModuleDetector(ROOT, factory); assertThat(detector.guessModuleName(gradleWorkspace + "build/reports/something.txt")) @@ -172,14 +172,14 @@ void shouldEnsureThatGradleSettingsCanParseFormat1() { @Test void shouldEnsureThatGradleSettingsCanParseFormat2() { - FileSystem factory = createFileSystemStub(stub -> { + var factory = createFileSystemStub(stub -> { when(stub.find(any(), anyString())).thenReturn(new String[]{ PATH_PREFIX_GRADLE + GradleModuleDetector.SETTINGS_GRADLE, }); when(stub.open(anyString())).thenAnswer(fileName -> read("settings-2.gradle")); }); - String gradleWorkspace = PREFIX + PATH_PREFIX_GRADLE; + var gradleWorkspace = PREFIX + PATH_PREFIX_GRADLE; var detector = new ModuleDetector(ROOT, factory); assertThat(detector.guessModuleName(gradleWorkspace + "build/reports/something.txt")) @@ -188,14 +188,14 @@ void shouldEnsureThatGradleSettingsCanParseFormat2() { @Test void shouldEnsureThatGradleSettingsCanParseFormat3() { - FileSystem factory = createFileSystemStub(stub -> { + var factory = createFileSystemStub(stub -> { when(stub.find(any(), anyString())).thenReturn(new String[]{ PATH_PREFIX_GRADLE + GradleModuleDetector.SETTINGS_GRADLE, }); when(stub.open(anyString())).thenAnswer(fileName -> read("settings-3.gradle")); }); - String gradleWorkspace = PREFIX + PATH_PREFIX_GRADLE; + var gradleWorkspace = PREFIX + PATH_PREFIX_GRADLE; var detector = new ModuleDetector(ROOT, factory); assertThat(detector.guessModuleName(gradleWorkspace + "build/reports/something.txt")) @@ -204,14 +204,14 @@ void shouldEnsureThatGradleSettingsCanParseFormat3() { @Test void shouldEnsureThatGradleSettingsCanParseFormat4() { - FileSystem factory = createFileSystemStub(stub -> { + var factory = createFileSystemStub(stub -> { when(stub.find(any(), anyString())).thenReturn(new String[]{ PATH_PREFIX_GRADLE + GradleModuleDetector.SETTINGS_GRADLE, }); when(stub.open(anyString())).thenAnswer(fileName -> read("settings-4.gradle")); }); - String gradleWorkspace = PREFIX + PATH_PREFIX_GRADLE; + var gradleWorkspace = PREFIX + PATH_PREFIX_GRADLE; var detector = new ModuleDetector(ROOT, factory); assertThat(detector.guessModuleName(gradleWorkspace + "build/reports/something.txt")) @@ -220,7 +220,7 @@ void shouldEnsureThatGradleSettingsCanParseFormat4() { @Test void shouldIgnoreGradleSettingsWithoutProjectName() { - FileSystem factory = createFileSystemStub(stub -> { + var factory = createFileSystemStub(stub -> { when(stub.find(any(), anyString())).thenReturn(new String[]{ PATH_PREFIX_GRADLE + GradleModuleDetector.BUILD_GRADLE, PATH_PREFIX_GRADLE + GradleModuleDetector.SETTINGS_GRADLE, @@ -228,7 +228,7 @@ void shouldIgnoreGradleSettingsWithoutProjectName() { when(stub.open(anyString())).thenAnswer(fileName -> read("settings-5.gradle")); }); - String gradleWorkspace = PREFIX + PATH_PREFIX_GRADLE; + var gradleWorkspace = PREFIX + PATH_PREFIX_GRADLE; var detector = new ModuleDetector(ROOT, factory); assertThat(detector.guessModuleName(gradleWorkspace + "build/reports/something.txt")) @@ -237,7 +237,7 @@ void shouldIgnoreGradleSettingsWithoutProjectName() { @Test void shouldIgnoreGradleFileWithNoParentPath() { - FileSystem factory = createFileSystemStub(stub -> + var factory = createFileSystemStub(stub -> when(stub.find(any(), anyString())).thenReturn(new String[]{ GradleModuleDetector.BUILD_GRADLE, })); diff --git a/src/test/java/edu/hm/hafner/analysis/IssueBuilderTest.java b/src/test/java/edu/hm/hafner/analysis/IssueBuilderTest.java index 190c506ac..606c38f98 100644 --- a/src/test/java/edu/hm/hafner/analysis/IssueBuilderTest.java +++ b/src/test/java/edu/hm/hafner/analysis/IssueBuilderTest.java @@ -36,7 +36,7 @@ class IssueBuilderTest { @SuppressFBWarnings("DMI") @Test void shouldCreateAbsolutePath() { - try (IssueBuilder builder = new IssueBuilder()) { + try (var builder = new IssueBuilder()) { builder.setFileName(RELATIVE_FILE); assertThat(builder.build()) @@ -85,15 +85,15 @@ void shouldCreateAbsolutePath() { "C:\\file.txt" }) void shouldGetBaseName(final String fullPath) { - try (IssueBuilder issueBuilder = new IssueBuilder()) { + try (var issueBuilder = new IssueBuilder()) { assertThat(issueBuilder.setFileName(fullPath).build()).hasBaseName("file.txt"); } } @Test void shouldCreateDefaultIssueIfNothingSpecified() { - try (IssueBuilder builder = new IssueBuilder()) { - Issue issue = builder.build(); + try (var builder = new IssueBuilder()) { + var issue = builder.build(); assertThat(issue).isEqualTo(DEFAULT_ISSUE); } @@ -114,7 +114,7 @@ void shouldCreateDefaultIssueIfNothingSpecified() { "-1, -1, 0, 0"}) void shouldHaveValidLineRange( final int start, final int end, final int expectedStart, final int expectedEnd) { - try (IssueBuilder builder = new IssueBuilder()) { + try (var builder = new IssueBuilder()) { builder.setLineStart(start).setLineEnd(end); assertThat(builder.build()).hasLineStart(expectedStart).hasLineEnd(expectedEnd); } @@ -135,7 +135,7 @@ void shouldHaveValidLineRange( "-1, -1, 0, 0"}) void shouldHaveValidColumnRange( final int start, final int end, final int expectedStart, final int expectedEnd) { - try (IssueBuilder builder = new IssueBuilder()) { + try (var builder = new IssueBuilder()) { builder.setColumnStart(start).setColumnEnd(end); assertThat(builder.build()).hasColumnStart(expectedStart).hasColumnEnd(expectedEnd); } @@ -143,25 +143,25 @@ void shouldHaveValidColumnRange( @Test void shouldMapStringNumbers() { - try (IssueBuilder builder = new IssueBuilder()) { + try (var builder = new IssueBuilder()) { assertThat(builder.setLineStart("nix").build()).hasLineStart(0); assertThat(builder.setLineStart("-1").build()).hasLineStart(0); assertThat(builder.setLineStart("0").build()).hasLineStart(0); assertThat(builder.setLineStart("1").build()).hasLineStart(1); } - try (IssueBuilder builder = new IssueBuilder()) { + try (var builder = new IssueBuilder()) { assertThat(builder.setLineEnd("nix").build()).hasLineEnd(0); assertThat(builder.setLineEnd("-1").build()).hasLineEnd(0); assertThat(builder.setLineEnd("0").build()).hasLineEnd(0); assertThat(builder.setLineEnd("1").build()).hasLineEnd(1); } - try (IssueBuilder builder = new IssueBuilder()) { + try (var builder = new IssueBuilder()) { assertThat(builder.setColumnStart("nix").build()).hasColumnStart(0); assertThat(builder.setColumnStart("-1").build()).hasColumnStart(0); assertThat(builder.setColumnStart("0").build()).hasColumnStart(0); assertThat(builder.setColumnStart("1").build()).hasColumnStart(1); } - try (IssueBuilder builder = new IssueBuilder()) { + try (var builder = new IssueBuilder()) { assertThat(builder.setColumnEnd("nix").build()).hasColumnEnd(0); assertThat(builder.setColumnEnd("-1").build()).hasColumnEnd(0); assertThat(builder.setColumnEnd("0").build()).hasColumnEnd(0); @@ -172,8 +172,8 @@ void shouldMapStringNumbers() { @Test @SuppressFBWarnings("DMI") void shouldCreateIssueWithAllPropertiesInitialized() { - try (IssueBuilder builder = new IssueBuilder()) { - Issue issue = builder + try (var builder = new IssueBuilder()) { + var issue = builder .setFileName(FILE_NAME) .setLineStart(LINE_START) .setLineEnd(LINE_END) @@ -199,7 +199,7 @@ void shouldCreateIssueWithAllPropertiesInitialized() { assertThatIssueIsEqualToFilled(builder.build()); // same result because builder is not cleaned assertThatIssueIsEqualToFilled(builder.buildAndClean()); - try (IssueBuilder emptyBuilder = new IssueBuilder()) { + try (var emptyBuilder = new IssueBuilder()) { emptyBuilder.setOrigin(ORIGIN); emptyBuilder.setOriginName(ORIGIN_NAME); assertThat(builder.build()).isEqualTo(emptyBuilder.build()); @@ -215,8 +215,8 @@ private void assertThatIssueIsEqualToFilled(final Issue issue) { @Test void shouldCopyAllPropertiesOfAnIssue() { - try (IssueBuilder builder = new IssueBuilder()) { - Issue copy = builder.copy(FILLED_ISSUE).build(); + try (var builder = new IssueBuilder()) { + var copy = builder.copy(FILLED_ISSUE).build(); assertThat(copy).isNotSameAs(FILLED_ISSUE); assertThatIssueIsEqualToFilled(copy); @@ -225,10 +225,10 @@ void shouldCopyAllPropertiesOfAnIssue() { @Test void shouldCreateNewInstanceOnEveryCall() { - try (IssueBuilder builder = new IssueBuilder()) { + try (var builder = new IssueBuilder()) { builder.copy(FILLED_ISSUE); - Issue issue1 = builder.build(); - Issue issue2 = builder.build(); + var issue1 = builder.build(); + var issue2 = builder.build(); assertThat(issue1).isNotSameAs(issue2); assertThat(issue1).isEqualTo(issue2); @@ -237,7 +237,7 @@ void shouldCreateNewInstanceOnEveryCall() { @Test void shouldCollectLineRanges() { - try (IssueBuilder builder = new IssueBuilder()) { + try (var builder = new IssueBuilder()) { builder.setLineStart(1).setLineEnd(2); var lineRanges = new LineRangeList(); lineRanges.add(new LineRange(3, 4)); @@ -248,7 +248,7 @@ void shouldCollectLineRanges() { assertThat(issue).hasLineStart(1).hasLineEnd(2); assertThat(issue).hasOnlyLineRanges(new LineRange(3, 4), new LineRange(5, 6)); - try (IssueBuilder copy = new IssueBuilder()) { + try (var copy = new IssueBuilder()) { copy.copy(issue); assertThat(copy.build()).hasOnlyLineRanges(new LineRange(3, 4), new LineRange(5, 6)); } @@ -257,7 +257,7 @@ void shouldCollectLineRanges() { @Test void shouldMoveLineRangeToAttributes() { - try (IssueBuilder builder = new IssueBuilder()) { + try (var builder = new IssueBuilder()) { var lineRanges = new LineRangeList(); lineRanges.add(new LineRange(1, 2)); builder.setLineRanges(lineRanges); @@ -270,7 +270,7 @@ void shouldMoveLineRangeToAttributes() { @Test void shouldMoveLineRangeToAttributesEvenIfLineEndIsSet() { - try (IssueBuilder builder = new IssueBuilder()) { + try (var builder = new IssueBuilder()) { builder.setLineEnd(2); var lineRanges = new LineRangeList(); lineRanges.add(new LineRange(1, 2)); @@ -284,7 +284,7 @@ void shouldMoveLineRangeToAttributesEvenIfLineEndIsSet() { @Test void shouldCleanupLineRanges() { - try (IssueBuilder builder = new IssueBuilder()) { + try (var builder = new IssueBuilder()) { builder.setLineStart(1).setLineEnd(2); var lineRanges = new LineRangeList(); lineRanges.add(new LineRange(1, 2)); @@ -298,7 +298,7 @@ void shouldCleanupLineRanges() { @Test void shouldNotCleanupDifferentLineRanges() { - try (IssueBuilder builder = new IssueBuilder()) { + try (var builder = new IssueBuilder()) { builder.setLineStart(1).setLineEnd(2); var lineRanges = new LineRangeList(); lineRanges.add(new LineRange(1, 3)); @@ -312,8 +312,8 @@ void shouldNotCleanupDifferentLineRanges() { @Test void shouldUseProvidedId() { - try (IssueBuilder builder = new IssueBuilder()) { - UUID id = UUID.randomUUID(); + try (var builder = new IssueBuilder()) { + var id = UUID.randomUUID(); builder.setId(id); assertThat(builder.build()).hasId(id); @@ -326,7 +326,7 @@ void shouldUseProvidedId() { @Test void testFileNameBackslashConversion() { - try (IssueBuilder builder = new IssueBuilder()) { + try (var builder = new IssueBuilder()) { var issue = builder.setFileName(FILE_NAME_WITH_BACKSLASHES).build(); assertThat(issue).hasFileName(FILE_NAME); @@ -335,7 +335,7 @@ void testFileNameBackslashConversion() { @Test void shouldCacheFileName() { - try (IssueBuilder builder = new IssueBuilder()) { + try (var builder = new IssueBuilder()) { var issue = builder.setFileName("fileName").build(); var anotherIssue = builder.setFileName("fileName").build(); @@ -345,7 +345,7 @@ void shouldCacheFileName() { @Test void shouldCachePackageName() { - try (IssueBuilder builder = new IssueBuilder()) { + try (var builder = new IssueBuilder()) { var issue = builder.setPackageName("packageName").build(); var anotherIssue = builder.setFileName("packageName").build(); @@ -355,9 +355,9 @@ void shouldCachePackageName() { @Test void shouldCacheMessage() { - try (IssueBuilder builder = new IssueBuilder()) { - Issue issue = builder.setMessage("message").build(); - Issue anotherIssue = builder.setMessage("message").build(); + try (var builder = new IssueBuilder()) { + var issue = builder.setMessage("message").build(); + var anotherIssue = builder.setMessage("message").build(); assertThat(issue.getMessageTreeString()).isSameAs(anotherIssue.getMessageTreeString()); } @@ -365,9 +365,9 @@ void shouldCacheMessage() { @Test void testMessageDescriptionStripped() { - try (IssueBuilder builder = new IssueBuilder()) { - Issue issue = builder.setMessage(" message ").setDescription(" description ").build(); - Issue anotherIssue = builder.setMessage("message").setDescription("description").build(); + try (var builder = new IssueBuilder()) { + var issue = builder.setMessage(" message ").setDescription(" description ").build(); + var anotherIssue = builder.setMessage("message").setDescription("description").build(); assertThat(issue.getMessageTreeString()).isSameAs(anotherIssue.getMessageTreeString()); assertThat(issue.getDescription()).isSameAs(anotherIssue.getDescription()); diff --git a/src/test/java/edu/hm/hafner/analysis/IssueDifferenceBenchmark.java b/src/test/java/edu/hm/hafner/analysis/IssueDifferenceBenchmark.java index 16cd4dfa0..a0856dec3 100644 --- a/src/test/java/edu/hm/hafner/analysis/IssueDifferenceBenchmark.java +++ b/src/test/java/edu/hm/hafner/analysis/IssueDifferenceBenchmark.java @@ -72,7 +72,7 @@ public void doSetup() { } private Issue createIssue(final String message, final String fingerprint) { - try (IssueBuilder builder = new IssueBuilder()) { + try (var builder = new IssueBuilder()) { builder.setFileName("file-name") .setLineStart(1) .setLineEnd(2) diff --git a/src/test/java/edu/hm/hafner/analysis/IssueDifferenceTest.java b/src/test/java/edu/hm/hafner/analysis/IssueDifferenceTest.java index a28153ef7..6cf7344e7 100644 --- a/src/test/java/edu/hm/hafner/analysis/IssueDifferenceTest.java +++ b/src/test/java/edu/hm/hafner/analysis/IssueDifferenceTest.java @@ -93,7 +93,7 @@ void shouldCreateIssueDifferenceWithEmptyCurrent() { assertThat(issueDifference.getNewIssues()).isEmpty(); assertThat(issueDifference.getOutstandingIssues()).isEmpty(); - Report fixed = issueDifference.getFixedIssues(); + var fixed = issueDifference.getFixedIssues(); assertThat(fixed).hasSize(2); assertThat(fixed.get(0)).hasMessage("OLD 1").hasReference(REFERENCE_BUILD); @@ -111,7 +111,7 @@ void shouldCreateIssueDifferenceWithEmptyReference() { assertThat(issueDifference.getFixedIssues()).isEmpty(); assertThat(issueDifference.getOutstandingIssues()).isEmpty(); - Report newIssues = issueDifference.getNewIssues(); + var newIssues = issueDifference.getNewIssues(); assertThat(newIssues).hasSize(2); assertThat(newIssues.get(0)).hasMessage("NEW 1").hasReference(CURRENT_BUILD); assertThat(newIssues.get(1)).hasMessage("NEW 2").hasReference(CURRENT_BUILD); @@ -120,9 +120,9 @@ void shouldCreateIssueDifferenceWithEmptyReference() { @Test @org.junitpioneer.jupiter.Issue("JENKINS-56324") void shouldAlsoUseFingerprintIfIssuesAreEqual() { - Report referenceIssues = new Report().addAll( + var referenceIssues = new Report().addAll( createIssue("OLD 1", "FP")); - Report currentIssues = new Report().addAll( + var currentIssues = new Report().addAll( createIssue("NEW 1", "FP"), createIssue("OLD 1", "FP")); @@ -130,21 +130,21 @@ void shouldAlsoUseFingerprintIfIssuesAreEqual() { assertThat(issueDifference.getFixedIssues()).isEmpty(); - Report outstandingIssues = issueDifference.getOutstandingIssues(); + var outstandingIssues = issueDifference.getOutstandingIssues(); assertThat(outstandingIssues).hasSize(1); assertThat(outstandingIssues.get(0)).hasMessage("OLD 1").hasReference(REFERENCE_BUILD); - Report newIssues = issueDifference.getNewIssues(); + var newIssues = issueDifference.getNewIssues(); assertThat(newIssues).hasSize(1); assertThat(newIssues.get(0)).hasMessage("NEW 1").hasReference(CURRENT_BUILD); } @Test void shouldRemoveForSecondPass() { - Report referenceIssues = new Report().addAll( + var referenceIssues = new Report().addAll( createIssue("NEW 1", "FP1"), createIssue("NEW 2", "FP1")); - Report currentIssues = new Report().addAll( + var currentIssues = new Report().addAll( createIssue("NEW 1", "FP1"), createIssue("NEW 3", "FP2")); @@ -160,7 +160,7 @@ private Issue createIssue(final String message, final String fingerprint) { } private Issue createIssue(final String message, final String fingerprint, final String fileName) { - try (IssueBuilder builder = new IssueBuilder()) { + try (var builder = new IssueBuilder()) { builder.setFileName(fileName) .setLineStart(1) .setLineEnd(2) diff --git a/src/test/java/edu/hm/hafner/analysis/IssueTest.java b/src/test/java/edu/hm/hafner/analysis/IssueTest.java index df5fdb3a5..85cbe7202 100644 --- a/src/test/java/edu/hm/hafner/analysis/IssueTest.java +++ b/src/test/java/edu/hm/hafner/analysis/IssueTest.java @@ -65,7 +65,7 @@ void shouldSplitFileNameElements() { MESSAGE_TS, DESCRIPTION, ORIGIN, ORIGIN_NAME, REFERENCE, FINGERPRINT, ADDITIONAL_PROPERTIES, UUID.randomUUID()); - try (SoftAssertions softly = new SoftAssertions()) { + try (var softly = new SoftAssertions()) { softly.assertThat(issue) .hasFileName(FILE_NAME) .hasPath(PATH_NAME) @@ -75,7 +75,7 @@ void shouldSplitFileNameElements() { var newName = TreeString.valueOf("new.txt"); issue.setFileName("/new", newName); - try (SoftAssertions softly = new SoftAssertions()) { + try (var softly = new SoftAssertions()) { softly.assertThat(issue) .hasFileName("new.txt") .hasPath("/new") @@ -94,7 +94,7 @@ void shouldSplitFileNameElements() { MESSAGE_TS, DESCRIPTION, ORIGIN, ORIGIN_NAME, REFERENCE, FINGERPRINT, ADDITIONAL_PROPERTIES, UUID.randomUUID()); - try (SoftAssertions softly = new SoftAssertions()) { + try (var softly = new SoftAssertions()) { softly.assertThat(emptyPath) .hasFileName(FILE_NAME) .hasPath(UNDEFINED) @@ -110,7 +110,7 @@ void shouldConvertWindowsNames() { MESSAGE_TS, DESCRIPTION, ORIGIN, ORIGIN_NAME, REFERENCE, FINGERPRINT, ADDITIONAL_PROPERTIES, UUID.randomUUID()); - try (SoftAssertions softly = new SoftAssertions()) { + try (var softly = new SoftAssertions()) { softly.assertThat(issue) .hasFileName(FILE_NAME) .hasPath(WINDOWS_PATH) @@ -160,7 +160,7 @@ void shouldEnsureThatEndIsGreaterOrEqualStart() { void shouldSetAllPropertiesInConstructor() { var issue = createFilledIssue(); - try (SoftAssertions softly = new SoftAssertions()) { + try (var softly = new SoftAssertions()) { softly.assertThat(issue.getId()).isNotNull(); softly.assertThat(issue) .hasFileName(FILE_NAME) @@ -183,7 +183,7 @@ void shouldSetAllPropertiesInConstructor() { softly.assertThat(issue.hasModuleName()).isTrue(); } - try (SoftAssertions softly = new SoftAssertions()) { + try (var softly = new SoftAssertions()) { softly.assertThat(Issue.getPropertyValueAsString(issue, "fileName")) .isEqualTo(issue.getFileName()); softly.assertThat(Issue.getPropertyValueAsString(issue, "category")) @@ -199,21 +199,21 @@ void shouldSetAllPropertiesInConstructor() { void shouldChangeMutableProperties() { var issue = createFilledIssue(); - String origin = "new-origin"; + var origin = "new-origin"; issue.setOrigin(origin); - String reference = "new-reference"; + var reference = "new-reference"; issue.setReference(reference); - String moduleName = "new-module"; + var moduleName = "new-module"; issue.setModuleName(moduleName); - String packageName = "new-package"; + var packageName = "new-package"; issue.setPackageName(TREE_STRING_BUILDER.intern(packageName)); - TreeString fileName = TREE_STRING_BUILDER.intern("new-file"); - String pathName = "new-path"; + var fileName = TREE_STRING_BUILDER.intern("new-file"); + var pathName = "new-path"; issue.setFileName(pathName, fileName); - String fingerprint = "new-fingerprint"; + var fingerprint = "new-fingerprint"; issue.setFingerprint(fingerprint); - try (SoftAssertions softly = new SoftAssertions()) { + try (var softly = new SoftAssertions()) { softly.assertThat(issue) .hasOrigin(origin) .hasReference(reference) @@ -225,10 +225,10 @@ void shouldChangeMutableProperties() { .hasFingerprint(fingerprint); } - String originName = "new-origin-name"; + var originName = "new-origin-name"; issue.setOrigin(origin, originName); - try (SoftAssertions softly = new SoftAssertions()) { + try (var softly = new SoftAssertions()) { softly.assertThat(issue) .hasOrigin(origin) .hasOriginName(originName) @@ -263,7 +263,7 @@ void testDefaultIssueEmptyStringsNegativeIntegers() { } private void assertIsDefaultIssue(final Issue issue) { - try (SoftAssertions softly = new SoftAssertions()) { + try (var softly = new SoftAssertions()) { softly.assertThat(issue.getId()).isNotNull(); softly.assertThat(issue) .hasFileName(UNDEFINED) @@ -291,7 +291,7 @@ void testZeroLineColumnEndsDefaultToLineColumnStarts() { FINGERPRINT, ADDITIONAL_PROPERTIES, UUID.randomUUID()); - try (SoftAssertions softly = new SoftAssertions()) { + try (var softly = new SoftAssertions()) { softly.assertThat(issue) .hasLineStart(LINE_START) .hasLineEnd(LINE_START) @@ -313,8 +313,8 @@ void testNullPriorityDefaultsToNormal() { @Test void testIdRandomlyGenerated() { - Issue one = createFilledIssue(); - Issue another = createFilledIssue(); + var one = createFilledIssue(); + var another = createFilledIssue(); assertThat(one.getId()).isNotEqualTo(another.getId()); } @@ -362,7 +362,7 @@ protected void assertThatRestoredInstanceEqualsOriginalInstance(final Issue orig */ @Test void shouldReadIssueFromOldSerialization() { - byte[] restored = readAllBytes(SERIALIZATION_NAME); + var restored = readAllBytes(SERIALIZATION_NAME); assertThatSerializableCanBeRestoredFrom(restored); } diff --git a/src/test/java/edu/hm/hafner/analysis/JavaPackageDetectorTest.java b/src/test/java/edu/hm/hafner/analysis/JavaPackageDetectorTest.java index 99d73edbb..093b94f77 100644 --- a/src/test/java/edu/hm/hafner/analysis/JavaPackageDetectorTest.java +++ b/src/test/java/edu/hm/hafner/analysis/JavaPackageDetectorTest.java @@ -27,7 +27,7 @@ class JavaPackageDetectorTest extends ResourceTest { "pom.xml, -", "ActionBinding.cs, -"}) void shouldExtractPackageNameFromJavaSource(final String fileName, final String expectedPackage) throws IOException { - try (InputStream stream = asInputStream(fileName)) { + try (var stream = asInputStream(fileName)) { assertThat(new JavaPackageDetector().detectPackageName(stream, UTF_8)) .isEqualTo(expectedPackage); } diff --git a/src/test/java/edu/hm/hafner/analysis/KotlinPackageDetectorTest.java b/src/test/java/edu/hm/hafner/analysis/KotlinPackageDetectorTest.java index 115d31cae..632ae33b4 100644 --- a/src/test/java/edu/hm/hafner/analysis/KotlinPackageDetectorTest.java +++ b/src/test/java/edu/hm/hafner/analysis/KotlinPackageDetectorTest.java @@ -27,7 +27,7 @@ class KotlinPackageDetectorTest extends ResourceTest { "pom.xml, -", "ActionBinding.cs, -"}) void shouldExtractPackageNameFromKotlinSource(final String fileName, final String expectedPackage) throws IOException { - try (InputStream stream = asInputStream(fileName)) { + try (var stream = asInputStream(fileName)) { assertThat(new KotlinPackageDetector().detectPackageName(stream, UTF_8)) .isEqualTo(expectedPackage); } diff --git a/src/test/java/edu/hm/hafner/analysis/MavenModuleDetectorTest.java b/src/test/java/edu/hm/hafner/analysis/MavenModuleDetectorTest.java index 676dab477..6de66e195 100644 --- a/src/test/java/edu/hm/hafner/analysis/MavenModuleDetectorTest.java +++ b/src/test/java/edu/hm/hafner/analysis/MavenModuleDetectorTest.java @@ -30,7 +30,7 @@ String getProjectFileName() { @Test void shouldIdentifyModuleByReadingMavenPom() { - FileSystem factory = createFileSystemStub(stub -> { + var factory = createFileSystemStub(stub -> { when(stub.find(any(), anyString())).thenReturn( new String[]{PATH_PREFIX_MAVEN + MavenModuleDetector.MAVEN_POM}); when(stub.open(anyString())).thenAnswer(fileName -> read(MavenModuleDetector.MAVEN_POM)); @@ -47,14 +47,14 @@ void shouldIdentifyModuleByReadingMavenPom() { @Test void shouldIdentifyModuleByReadingMavenPomWithoutName() { - FileSystem factory = createFileSystemStub(stub -> { + var factory = createFileSystemStub(stub -> { when(stub.find(any(), anyString())).thenReturn(new String[]{PATH_PREFIX_MAVEN + MavenModuleDetector.MAVEN_POM}); when(stub.open(anyString())).thenAnswer(filename -> read("no-name-pom.xml")); }); var detector = new ModuleDetector(ROOT, factory); - String artifactId = "com.avaloq.adt.core"; + var artifactId = "com.avaloq.adt.core"; assertThat(detector.guessModuleName(PREFIX + PATH_PREFIX_MAVEN + "something.txt")) .isEqualTo(artifactId); assertThat(detector.guessModuleName(PREFIX + PATH_PREFIX_MAVEN + "in/between/something.txt")) diff --git a/src/test/java/edu/hm/hafner/analysis/ModuleDetectorTest.java b/src/test/java/edu/hm/hafner/analysis/ModuleDetectorTest.java index a639d4db2..ab16f615d 100644 --- a/src/test/java/edu/hm/hafner/analysis/ModuleDetectorTest.java +++ b/src/test/java/edu/hm/hafner/analysis/ModuleDetectorTest.java @@ -4,7 +4,6 @@ import java.io.IOException; import java.io.InputStream; import java.nio.file.Path; -import java.nio.file.Paths; import org.apache.commons.io.IOUtils; import org.junit.jupiter.api.Test; @@ -24,7 +23,7 @@ @SuppressFBWarnings("DMI") class ModuleDetectorTest extends ResourceTest { private static final String MANIFEST = "MANIFEST.MF"; - private static final Path ROOT = Paths.get(File.pathSeparatorChar == ';' ? "C:\\Windows" : "/tmp"); + private static final Path ROOT = Path.of(File.pathSeparatorChar == ';' ? "C:\\Windows" : "/tmp"); private static final String PREFIX = new PathUtil().getAbsolutePath(ROOT) + "/"; private static final String PATH_PREFIX_MAVEN = "path/to/maven/"; @@ -40,9 +39,9 @@ private InputStream read(final String fileName) { @Test void shouldIdentifyModuleIfThereAreMoreEntries() { - FileSystem factory = createFileSystemStub(stub -> { - String ant = PATH_PREFIX_ANT + AntModuleDetector.ANT_PROJECT; - String maven = PATH_PREFIX_MAVEN + MavenModuleDetector.MAVEN_POM; + var factory = createFileSystemStub(stub -> { + var ant = PATH_PREFIX_ANT + AntModuleDetector.ANT_PROJECT; + var maven = PATH_PREFIX_MAVEN + MavenModuleDetector.MAVEN_POM; when(stub.find(any(), anyString())).thenReturn(new String[]{ant, maven}); when(stub.open(PREFIX + ant)).thenReturn(read(AntModuleDetector.ANT_PROJECT)); when(stub.open(PREFIX + maven)).thenAnswer(filename -> read(MavenModuleDetector.MAVEN_POM)); @@ -58,9 +57,9 @@ void shouldIdentifyModuleIfThereAreMoreEntries() { @Test void shouldEnsureThatMavenHasPrecedenceOverAnt() { - String prefix = "/prefix/"; - String ant = prefix + AntModuleDetector.ANT_PROJECT; - String maven = prefix + MavenModuleDetector.MAVEN_POM; + var prefix = "/prefix/"; + var ant = prefix + AntModuleDetector.ANT_PROJECT; + var maven = prefix + MavenModuleDetector.MAVEN_POM; verifyOrder(prefix, ant, maven, new String[]{ant, maven}); verifyOrder(prefix, ant, maven, new String[]{maven, ant}); @@ -68,10 +67,10 @@ void shouldEnsureThatMavenHasPrecedenceOverAnt() { @Test void shouldEnsureThatOsgiHasPrecedenceOverMavenAndAnt() { - String prefix = "/prefix/"; - String ant = prefix + AntModuleDetector.ANT_PROJECT; - String maven = prefix + MavenModuleDetector.MAVEN_POM; - String osgi = prefix + OsgiModuleDetector.OSGI_BUNDLE; + var prefix = "/prefix/"; + var ant = prefix + AntModuleDetector.ANT_PROJECT; + var maven = prefix + MavenModuleDetector.MAVEN_POM; + var osgi = prefix + OsgiModuleDetector.OSGI_BUNDLE; verifyOrder(prefix, ant, maven, osgi, ant, maven, osgi); verifyOrder(prefix, ant, maven, osgi, ant, osgi, maven); @@ -83,7 +82,7 @@ void shouldEnsureThatOsgiHasPrecedenceOverMavenAndAnt() { @SuppressWarnings("PMD.UseVarargs") private void verifyOrder(final String prefix, final String ant, final String maven, final String[] foundFiles) { - FileSystem factory = createFileSystemStub(stub -> { + var factory = createFileSystemStub(stub -> { when(stub.find(any(), anyString())).thenReturn(foundFiles); when(stub.open(ant)).thenReturn(read(AntModuleDetector.ANT_PROJECT)); when(stub.open(maven)).thenAnswer(filename -> read(MavenModuleDetector.MAVEN_POM)); @@ -96,7 +95,7 @@ private void verifyOrder(final String prefix, final String ant, final String mav private void verifyOrder(final String prefix, final String ant, final String maven, final String osgi, final String... foundFiles) { - FileSystem fileSystem = createFileSystemStub(stub -> { + var fileSystem = createFileSystemStub(stub -> { when(stub.find(any(), anyString())).thenReturn(foundFiles); when(stub.open(ant)).thenAnswer(filename -> read(AntModuleDetector.ANT_PROJECT)); when(stub.open(maven)).thenAnswer(filename -> read(MavenModuleDetector.MAVEN_POM)); @@ -116,7 +115,7 @@ private InputStream createEmptyStream() { private FileSystem createFileSystemStub(final Stub stub) { try { - FileSystem fileSystem = mock(FileSystem.class); + var fileSystem = mock(FileSystem.class); stub.apply(fileSystem); return fileSystem; } diff --git a/src/test/java/edu/hm/hafner/analysis/ModuleResolverTest.java b/src/test/java/edu/hm/hafner/analysis/ModuleResolverTest.java index 668704f86..459d4cb8e 100644 --- a/src/test/java/edu/hm/hafner/analysis/ModuleResolverTest.java +++ b/src/test/java/edu/hm/hafner/analysis/ModuleResolverTest.java @@ -16,15 +16,15 @@ class ModuleResolverTest { @Test @SuppressFBWarnings("DMI") void shouldAssignModuleName() { - try (IssueBuilder builder = new IssueBuilder()) { + try (var builder = new IssueBuilder()) { var report = new Report(); - String fileName = "/file/with/warnings.txt"; + var fileName = "/file/with/warnings.txt"; builder.setFileName(fileName); - Issue noModule = builder.build(); + var noModule = builder.build(); report.add(noModule); builder.setModuleName("module2"); - Issue withModule = builder.build(); + var withModule = builder.build(); report.add(withModule); var detector = mock(ModuleDetector.class); diff --git a/src/test/java/edu/hm/hafner/analysis/OsgiModuleDetectorTest.java b/src/test/java/edu/hm/hafner/analysis/OsgiModuleDetectorTest.java index 6a18235c4..d6704c8d8 100644 --- a/src/test/java/edu/hm/hafner/analysis/OsgiModuleDetectorTest.java +++ b/src/test/java/edu/hm/hafner/analysis/OsgiModuleDetectorTest.java @@ -33,7 +33,7 @@ String getProjectFileName() { @Test void shouldIdentifyModuleByReadingOsgiBundle() { - FileSystem factory = createFileSystemStub(stub -> { + var factory = createFileSystemStub(stub -> { when(stub.find(any(), anyString())).thenReturn(new String[]{PATH_PREFIX_OSGI + OsgiModuleDetector.OSGI_BUNDLE}); when(stub.open(anyString())).thenReturn(read(MANIFEST)); }); @@ -50,14 +50,14 @@ void shouldIdentifyModuleByReadingOsgiBundle() { @Test void shouldIdentifyModuleByReadingOsgiBundleWithVendorInL10nProperties() { - FileSystem factory = createFileSystemStub(stub -> { + var factory = createFileSystemStub(stub -> { when(stub.find(any(), anyString())).thenReturn(new String[]{PATH_PREFIX_OSGI + OsgiModuleDetector.OSGI_BUNDLE}); when(stub.open(anyString())).thenReturn(read(MANIFEST), read("l10n.properties")); }); var detector = new ModuleDetector(ROOT, factory); - String expectedName = "de.faktorlogik.prototyp (My Vendor)"; + var expectedName = "de.faktorlogik.prototyp (My Vendor)"; assertThat(detector.guessModuleName(PREFIX + PATH_PREFIX_OSGI + "something.txt")) .isEqualTo(expectedName); assertThat(detector.guessModuleName(PREFIX + PATH_PREFIX_OSGI + "in/between/something.txt")) @@ -68,7 +68,7 @@ void shouldIdentifyModuleByReadingOsgiBundleWithVendorInL10nProperties() { @Test void shouldIdentifyModuleByReadingOsgiBundleWithManifestName() { - FileSystem fileSystem = createFileSystemStub(stub -> { + var fileSystem = createFileSystemStub(stub -> { when(stub.find(any(), anyString())).thenReturn( new String[]{PATH_PREFIX_OSGI + OsgiModuleDetector.OSGI_BUNDLE}); when(stub.open(anyString())).thenReturn(read(MANIFEST_NAME), read("l10n.properties")); @@ -76,7 +76,7 @@ void shouldIdentifyModuleByReadingOsgiBundleWithManifestName() { var detector = new ModuleDetector(ROOT, fileSystem); - String expectedName = "My Bundle"; + var expectedName = "My Bundle"; assertThat(detector.guessModuleName(PREFIX + PATH_PREFIX_OSGI + "something.txt")) .isEqualTo(expectedName); assertThat(detector.guessModuleName(PREFIX + PATH_PREFIX_OSGI + "in/between/something.txt")) diff --git a/src/test/java/edu/hm/hafner/analysis/PackageDetectorsTest.java b/src/test/java/edu/hm/hafner/analysis/PackageDetectorsTest.java index de024a611..d6b93d89e 100644 --- a/src/test/java/edu/hm/hafner/analysis/PackageDetectorsTest.java +++ b/src/test/java/edu/hm/hafner/analysis/PackageDetectorsTest.java @@ -27,8 +27,8 @@ class PackageDetectorsTest extends ResourceTest { "MavenJavaTest.txt, -", "pom.xml, -"}) void shouldExtractPackageNames(final String fileName, final String expectedPackage) throws IOException { - try (InputStream stream = asInputStream(fileName)) { - FileSystem fileSystem = mock(FileSystem.class); + try (var stream = asInputStream(fileName)) { + var fileSystem = mock(FileSystem.class); when(fileSystem.openFile(fileName)).thenReturn(stream); ArrayList detectors = new ArrayList<>(Arrays.asList( diff --git a/src/test/java/edu/hm/hafner/analysis/PackageNameResolverBenchmark.java b/src/test/java/edu/hm/hafner/analysis/PackageNameResolverBenchmark.java index 0aca7a051..cd9740923 100644 --- a/src/test/java/edu/hm/hafner/analysis/PackageNameResolverBenchmark.java +++ b/src/test/java/edu/hm/hafner/analysis/PackageNameResolverBenchmark.java @@ -41,7 +41,7 @@ public void benchmark1000IssuesTest(final BenchmarkState state) throws IOExcepti } private FileSystem createFileSystemStub() throws IOException { - FileSystem fileSystemStub = mock(FileSystem.class); + var fileSystemStub = mock(FileSystem.class); when(fileSystemStub.openFile(FILE_NO_PACKAGE)) .thenReturn(new ByteArrayInputStream("package a.name;".getBytes(StandardCharsets.UTF_8))); return fileSystemStub; diff --git a/src/test/java/edu/hm/hafner/analysis/PackageNameResolverTest.java b/src/test/java/edu/hm/hafner/analysis/PackageNameResolverTest.java index 3366e8734..43e1b6a3e 100644 --- a/src/test/java/edu/hm/hafner/analysis/PackageNameResolverTest.java +++ b/src/test/java/edu/hm/hafner/analysis/PackageNameResolverTest.java @@ -26,7 +26,7 @@ class PackageNameResolverTest { @Test void shouldDoNothingForEmptyIssues() { - Report report = createIssues(); + var report = createIssues(); var resolver = new PackageNameResolver(); resolver.run(report, StandardCharsets.UTF_8); @@ -36,7 +36,7 @@ void shouldDoNothingForEmptyIssues() { @Test void shouldSkipExistingPackage() { - Report report = createIssues(); + var report = createIssues(); report.add(ISSUE_WITH_PACKAGE); var resolver = new PackageNameResolver(); @@ -48,7 +48,7 @@ void shouldSkipExistingPackage() { @Test void shouldResolvePackage() throws IOException { - Report report = createIssues(); + var report = createIssues(); report.add(ISSUE_WITHOUT_PACKAGE); var resolver = new PackageNameResolver(createFileSystemStub()); @@ -61,7 +61,7 @@ void shouldResolvePackage() throws IOException { @Test void shouldResolvePackageAndSkipExistingPackage() throws IOException { - Report report = createIssues(); + var report = createIssues(); report.add(ISSUE_WITHOUT_PACKAGE); report.add(ISSUE_WITH_PACKAGE); @@ -75,7 +75,7 @@ void shouldResolvePackageAndSkipExistingPackage() throws IOException { } private FileSystem createFileSystemStub() throws IOException { - FileSystem fileSystemStub = mock(FileSystem.class); + var fileSystemStub = mock(FileSystem.class); when(fileSystemStub.openFile(FILE_NO_PACKAGE)) .thenReturn(new ByteArrayInputStream("package a.name;".getBytes(StandardCharsets.UTF_8))); return fileSystemStub; diff --git a/src/test/java/edu/hm/hafner/analysis/ReportSerializationBenchmark.java b/src/test/java/edu/hm/hafner/analysis/ReportSerializationBenchmark.java index 716fdcc77..3e69a6fe7 100644 --- a/src/test/java/edu/hm/hafner/analysis/ReportSerializationBenchmark.java +++ b/src/test/java/edu/hm/hafner/analysis/ReportSerializationBenchmark.java @@ -46,7 +46,7 @@ public void benchmarkingReportDeserialization(final Blackhole blackhole) { } private static Report createReportWith(final int number) { - try (IssueBuilder builder = new IssueBuilder()) { + try (var builder = new IssueBuilder()) { var report = new Report(); builder.setFileName(AFFECTED_FILE_NAME); builder.setLineStart(5); @@ -67,7 +67,7 @@ private static Report createReportWith(final int number) { * @return bytes */ private static byte[] toByteArray(final Report report) { - try (var out = new ByteArrayOutputStream(); ObjectOutputStream stream = new ObjectOutputStream(out)) { + try (var out = new ByteArrayOutputStream(); var stream = new ObjectOutputStream(out)) { stream.writeObject(report); return out.toByteArray(); } @@ -87,7 +87,7 @@ private static byte[] toByteArray(final Report report) { @SuppressFBWarnings("OBJECT_DESERIALIZATION") @SuppressWarnings("BanSerializableRead") private static Report toReport(final byte[] bytes) { - try (var in = new ByteArrayInputStream(bytes); ObjectInputStream stream = new ObjectInputStream(in)) { + try (var in = new ByteArrayInputStream(bytes); var stream = new ObjectInputStream(in)) { return (Report) stream.readObject(); } catch (IOException | ClassNotFoundException exception) { diff --git a/src/test/java/edu/hm/hafner/analysis/ReportTest.java b/src/test/java/edu/hm/hafner/analysis/ReportTest.java index f13d96744..69f6a2629 100644 --- a/src/test/java/edu/hm/hafner/analysis/ReportTest.java +++ b/src/test/java/edu/hm/hafner/analysis/ReportTest.java @@ -143,7 +143,7 @@ void shouldVerifyExistenceOfProperties() { assertThat(report.hasTypes()).isFalse(); assertThat(report.hasSeverities()).isFalse(); - try (IssueBuilder builder = new IssueBuilder()) { + try (var builder = new IssueBuilder()) { report.add(builder.build()); // add the first issue } assertThat(report.hasTools()).isFalse(); @@ -166,8 +166,8 @@ void shouldVerifyExistenceOfProperties() { } private void verifySeverity(final Report report) { - try (IssueBuilder issueBuilder = new IssueBuilder()) { - Issue additional = issueBuilder.setSeverity(Severity.WARNING_HIGH).build(); + try (var issueBuilder = new IssueBuilder()) { + var additional = issueBuilder.setSeverity(Severity.WARNING_HIGH).build(); report.add(additional); assertThat(report.hasTools()).isFalse(); assertThat(report.hasModules()).isFalse(); @@ -182,8 +182,8 @@ private void verifySeverity(final Report report) { } private void verifyType(final Report report) { - try (IssueBuilder issueBuilder = new IssueBuilder()) { - Issue additional = issueBuilder.setType("type").build(); + try (var issueBuilder = new IssueBuilder()) { + var additional = issueBuilder.setType("type").build(); report.add(additional); assertThat(report.hasTools()).isFalse(); assertThat(report.hasModules()).isFalse(); @@ -198,8 +198,8 @@ private void verifyType(final Report report) { } private void verifyCategory(final Report report) { - try (IssueBuilder issueBuilder = new IssueBuilder()) { - Issue additional = issueBuilder.setCategory("category").build(); + try (var issueBuilder = new IssueBuilder()) { + var additional = issueBuilder.setCategory("category").build(); report.add(additional); assertThat(report.hasTools()).isFalse(); assertThat(report.hasModules()).isFalse(); @@ -214,8 +214,8 @@ private void verifyCategory(final Report report) { } private void verifyFile(final Report report) { - try (IssueBuilder issueBuilder = new IssueBuilder()) { - Issue additional = issueBuilder.setFileName("file").build(); + try (var issueBuilder = new IssueBuilder()) { + var additional = issueBuilder.setFileName("file").build(); report.add(additional); assertThat(report.hasTools()).isFalse(); assertThat(report.hasModules()).isFalse(); @@ -231,8 +231,8 @@ private void verifyFile(final Report report) { @SuppressFBWarnings("DMI") private void verifyFolder(final Report report) { - try (IssueBuilder builder = new IssueBuilder()) { - Issue additional = builder.setFileName("/tmp/file.txt").build(); + try (var builder = new IssueBuilder()) { + var additional = builder.setFileName("/tmp/file.txt").build(); report.add(additional); assertThat(report.hasTools()).isFalse(); assertThat(report.hasModules()).isFalse(); @@ -243,7 +243,7 @@ private void verifyFolder(final Report report) { assertThat(report.hasTypes()).isFalse(); assertThat(report.hasSeverities()).isFalse(); - Issue withPackageName = builder.setPackageName("something").build(); + var withPackageName = builder.setPackageName("something").build(); report.add(withPackageName); assertThat(report.hasPackages()).isTrue(); assertThat(report.hasFolders()).isFalse(); @@ -254,8 +254,8 @@ private void verifyFolder(final Report report) { } private void verifyPackage(final Report report) { - try (IssueBuilder issueBuilder = new IssueBuilder()) { - Issue additional = issueBuilder.setPackageName("package").build(); + try (var issueBuilder = new IssueBuilder()) { + var additional = issueBuilder.setPackageName("package").build(); report.add(additional); assertThat(report.hasTools()).isFalse(); assertThat(report.hasModules()).isFalse(); @@ -270,8 +270,8 @@ private void verifyPackage(final Report report) { } private void verifyModule(final Report report) { - try (IssueBuilder issueBuilder = new IssueBuilder()) { - Issue additional = issueBuilder.setModuleName("module").build(); + try (var issueBuilder = new IssueBuilder()) { + var additional = issueBuilder.setModuleName("module").build(); report.add(additional); assertThat(report.hasTools()).isFalse(); assertThat(report.hasModules()).isTrue(); @@ -286,8 +286,8 @@ private void verifyModule(final Report report) { } private void verifyOrigin(final Report report) { - try (IssueBuilder issueBuilder = new IssueBuilder()) { - Issue additional = issueBuilder.setOrigin("origin").build(); + try (var issueBuilder = new IssueBuilder()) { + var additional = issueBuilder.setOrigin("origin").build(); report.add(additional); assertThat(report.hasTools()).isTrue(); assertThat(report.hasModules()).isFalse(); @@ -385,7 +385,7 @@ void shouldCopyProperties() { assertThat(empty.getCounter("other")).isZero(); assertThat(empty.hasCounter("other")).isFalse(); - Report filtered = expected.filter(issue -> true); + var filtered = expected.filter(issue -> true); assertThat(filtered).isEqualTo(expected); assertThatAllIssuesHaveBeenAdded(filtered); } @@ -540,7 +540,7 @@ void shouldAddMultipleIssuesToNonEmpty() { } private void assertThatAllIssuesHaveBeenAdded(final Report report) { - try (SoftAssertions softly = new SoftAssertions()) { + try (var softly = new SoftAssertions()) { softly.assertThat(report) .hasSize(6) .hasDuplicatesSize(0); @@ -600,7 +600,7 @@ private void shouldRemoveOneIssue(final Issue... initialElements) { void shouldThrowExceptionWhenRemovingWithWrongKey() { var report = new Report(); - UUID id = HIGH.getId(); + var id = HIGH.getId(); assertThatThrownBy(() -> report.remove(id)) .isInstanceOf(NoSuchElementException.class) .hasMessageContaining(id.toString()); @@ -611,7 +611,7 @@ void shouldFindIfOnlyOneIssue() { var report = new Report(); report.addAll(Collections.singletonList(HIGH)); - Issue found = report.findById(HIGH.getId()); + var found = report.findById(HIGH.getId()); assertThat(found).isSameAs(HIGH); } @@ -627,7 +627,7 @@ private void shouldFindIssue(final Issue... elements) { var report = new Report(); report.addAll(asList(elements)); - Issue found = report.findById(HIGH.getId()); + var found = report.findById(HIGH.getId()); assertThat(found).isSameAs(HIGH); } @@ -642,7 +642,7 @@ private void shouldFindNothing(final Issue... elements) { var report = new Report(); report.addAll(asList(elements)); - UUID id = NORMAL_2.getId(); + var id = NORMAL_2.getId(); assertThatThrownBy(() -> report.findById(id)) .isInstanceOf(NoSuchElementException.class) .hasMessageContaining(id.toString()); @@ -753,12 +753,12 @@ void shouldFilterByProperty() { private void assertFilterFor(final BiFunction builderSetter, final Function> propertyGetter, final String propertyName, final Function> predicate) { - try (IssueBuilder builder = new IssueBuilder()) { + try (var builder = new IssueBuilder()) { var report = new Report(); for (int i = 1; i < 4; i++) { for (int j = i; j < 4; j++) { - Issue build = builderSetter.apply(builder, "name " + i).setMessage(i + " " + j).build(); + var build = builderSetter.apply(builder, "name " + i).setMessage(i + " " + j).build(); report.add(build); } } @@ -832,20 +832,20 @@ protected void assertThatRestoredInstanceEqualsOriginalInstance(final Report ori */ @Test void shouldReadIssueFromOldSerialization() { - byte[] restored = readAllBytes(SERIALIZATION_NAME); + var restored = readAllBytes(SERIALIZATION_NAME); assertThatSerializableCanBeRestoredFrom(restored); } @Test void shouldWriteLongMessages() { - try (IssueBuilder builder = new IssueBuilder()) { + try (var builder = new IssueBuilder()) { var report = new Report(); report.add(builder.setMessage(createLongMessage()).build()); - byte[] bytes = toByteArray(report); - Report restored = restore(bytes); + var bytes = toByteArray(report); + var restored = restore(bytes); assertThat(report).isEqualTo(restored); } @@ -885,7 +885,7 @@ void shouldPrintAllIssues() { void shouldPrintAllIssuesToPrintStream() { var report = readCheckStyleReport(); - try (PrintStream printStream = mock(PrintStream.class)) { + try (var printStream = mock(PrintStream.class)) { report.print(new StandardOutputPrinter(printStream)); for (Issue issue : report) { @@ -895,7 +895,7 @@ void shouldPrintAllIssuesToPrintStream() { } private Report readCheckStyleReport() { - String fileName = "parser/checkstyle/all-severities.xml"; + var fileName = "parser/checkstyle/all-severities.xml"; var report = new CheckStyleParser().parseFile(read(fileName)); report.add(new IssueBuilder().setSeverity(Severity.WARNING_HIGH).setMessage("Severity High warning").build()); assertThat(report).hasSize(4); @@ -926,9 +926,9 @@ void shouldCreateReportWithOptions() { @Test void shouldSetOriginAndReference() { - try (IssueBuilder builder = new IssueBuilder()) { + try (var builder = new IssueBuilder()) { var report = new Report(); - Issue checkstyleWarning = builder.setFileName("A.java") + var checkstyleWarning = builder.setFileName("A.java") .setCategory("Style") .setLineStart(1) .buildAndClean(); @@ -1033,7 +1033,7 @@ void shouldCopyIdRecursively() { @Test void shouldAddSubReports() { - try (IssueBuilder builder = new IssueBuilder()) { + try (var builder = new IssueBuilder()) { var checkStyle = new Report(CHECKSTYLE_ID, CHECKSTYLE_NAME, "checkstyle.xml"); var checkstyleWarning = builder.setFileName("A.java") .setCategory("Style") diff --git a/src/test/java/edu/hm/hafner/analysis/SeverityTest.java b/src/test/java/edu/hm/hafner/analysis/SeverityTest.java index 073e58a80..23a12b6c7 100644 --- a/src/test/java/edu/hm/hafner/analysis/SeverityTest.java +++ b/src/test/java/edu/hm/hafner/analysis/SeverityTest.java @@ -40,7 +40,7 @@ void shouldAssignSeverities() { @Test @SuppressWarnings("PMD.LiteralsFirstInComparisons") void shouldCreateNewSeverityThatOverridesEqualsAndToString() { - String name = "severity"; + var name = "severity"; var severity = new Severity(name); assertThat(severity.getName()).isEqualTo(name); @@ -57,7 +57,7 @@ void shouldReturnLinkToConstants() { assertThat(Severity.valueOf("normal")).isSameAs(Severity.WARNING_NORMAL); assertThat(Severity.valueOf("low")).isSameAs(Severity.WARNING_LOW); - String name = "severity"; + var name = "severity"; assertThat(Severity.valueOf(name)).isEqualTo(new Severity(name)); } diff --git a/src/test/java/edu/hm/hafner/analysis/parser/AntJavacParserTest.java b/src/test/java/edu/hm/hafner/analysis/parser/AntJavacParserTest.java index e58b25ba2..0f89d3100 100644 --- a/src/test/java/edu/hm/hafner/analysis/parser/AntJavacParserTest.java +++ b/src/test/java/edu/hm/hafner/analysis/parser/AntJavacParserTest.java @@ -25,7 +25,7 @@ class AntJavacParserTest extends AbstractParserTest { @Test void issue67521IgnoreJavaDocWarnings() { - Report warnings = parse("javadoc-in-java.log"); + var warnings = parse("javadoc-in-java.log"); assertThat(warnings).isEmpty(); } @@ -47,7 +47,7 @@ void issue55805() { */ @Test void issue63346() { - Report report = parse("issue63346.txt"); + var report = parse("issue63346.txt"); assertThat(report).isEmpty(); } @@ -59,7 +59,7 @@ void issue63346() { */ @Test void testIssue24611() { - Report warnings = parse("issue24611.txt"); + var warnings = parse("issue24611.txt"); assertThat(warnings).hasSize(2); } @@ -71,11 +71,11 @@ void testIssue24611() { */ @Test void issue21240() { - Report warnings = parse("issue21240.txt"); + var warnings = parse("issue21240.txt"); assertThat(warnings).hasSize(1); - try (SoftAssertions softly = new SoftAssertions()) { + try (var softly = new SoftAssertions()) { softly.assertThat(warnings.get(0)) .hasSeverity(Severity.WARNING_NORMAL) .hasLineStart(0) @@ -93,11 +93,11 @@ void issue21240() { */ @Test void issue2133() { - Report warnings = parse("issue2133.txt"); + var warnings = parse("issue2133.txt"); assertThat(warnings).hasSize(2); - try (SoftAssertions softly = new SoftAssertions()) { + try (var softly = new SoftAssertions()) { softly.assertThat(warnings.get(0)) .hasSeverity(Severity.WARNING_NORMAL) .hasCategory(DEFAULT_CATEGORY) @@ -125,11 +125,11 @@ void issue2133() { */ @Test void issue4098() { - Report warnings = parse("issue4098.txt"); + var warnings = parse("issue4098.txt"); assertThat(warnings).hasSize(1); - try (SoftAssertions softly = new SoftAssertions()) { + try (var softly = new SoftAssertions()) { softly.assertThat(warnings.get(0)) .hasSeverity(Severity.WARNING_NORMAL) .hasCategory("Path") @@ -148,7 +148,7 @@ void issue4098() { */ @Test void issue2316() { - Report warnings = parse("issue2316.txt"); + var warnings = parse("issue2316.txt"); assertThat(warnings) .hasSize(18) @@ -160,7 +160,7 @@ void issue2316() { */ @Test void parseDifferentTaskNames() { - Report warnings = parse("taskname.txt"); + var warnings = parse("taskname.txt"); assertThat(warnings).hasSize(1).hasDuplicatesSize(2); } @@ -170,11 +170,11 @@ void parseDifferentTaskNames() { */ @Test void parseArrayInDeprecatedMethod() { - Report warnings = parse("issue5868.txt"); + var warnings = parse("issue5868.txt"); assertThat(warnings).hasSize(1); - try (SoftAssertions softly = new SoftAssertions()) { + try (var softly = new SoftAssertions()) { softly.assertThat(warnings.get(0)).hasSeverity(Severity.WARNING_NORMAL) .hasCategory("Deprecation") .hasLineStart(225) @@ -187,11 +187,11 @@ void parseArrayInDeprecatedMethod() { @Test void shouldReadErrors() { - Report warnings = parse("gradle.java.log"); + var warnings = parse("gradle.java.log"); assertThat(warnings).hasSize(1); - try (SoftAssertions softly = new SoftAssertions()) { + try (var softly = new SoftAssertions()) { softly.assertThat(warnings.get(0)).hasSeverity(Severity.ERROR) .hasLineStart(59) .hasMessage("';' expected") @@ -207,7 +207,7 @@ void shouldReadErrors() { @Test void parseJapaneseWarnings() { // force to use windows-31j - the default encoding on Windows Japanese. - Report warnings = createParser().parse( + var warnings = createParser().parse( new FileReaderFactory(getResourceAsFile("ant-javac-japanese.txt"), Charset.forName("windows-31j"))); @@ -234,7 +234,7 @@ protected AntJavacParser createParser() { @Test void shouldNotParseJavaCompilerAndJavaDocWarnings() { - Report warnings = parse("issue63346.log"); + var warnings = parse("issue63346.log"); assertThat(warnings).hasSize(0); } } diff --git a/src/test/java/edu/hm/hafner/analysis/parser/AquaScannerParserTest.java b/src/test/java/edu/hm/hafner/analysis/parser/AquaScannerParserTest.java index a2b2c591b..9916010f2 100644 --- a/src/test/java/edu/hm/hafner/analysis/parser/AquaScannerParserTest.java +++ b/src/test/java/edu/hm/hafner/analysis/parser/AquaScannerParserTest.java @@ -57,7 +57,7 @@ protected void assertThatIssuesArePresent(final Report report, final SoftAsserti @Test void shouldHandleEmptyResultsJenkins67296() { - Report report = parse("issue67296.json"); + var report = parse("issue67296.json"); assertThat(report).isEmpty(); } diff --git a/src/test/java/edu/hm/hafner/analysis/parser/CheckStyleParserTest.java b/src/test/java/edu/hm/hafner/analysis/parser/CheckStyleParserTest.java index a302287ae..24f842d58 100644 --- a/src/test/java/edu/hm/hafner/analysis/parser/CheckStyleParserTest.java +++ b/src/test/java/edu/hm/hafner/analysis/parser/CheckStyleParserTest.java @@ -49,7 +49,7 @@ protected void assertThatIssuesArePresent(final Report report, final SoftAsserti */ @Test void issue25511() { - Report report = parseInCheckStyleFolder("issue25511.xml"); + var report = parseInCheckStyleFolder("issue25511.xml"); assertThat(report).hasSize(2); @@ -64,7 +64,7 @@ void issue25511() { */ @Test void testColumnPositions() { - Report report = parseInCheckStyleFolder("issue19122.xml"); + var report = parseInCheckStyleFolder("issue19122.xml"); assertThat(report).hasSize(58); } @@ -76,7 +76,7 @@ void testColumnPositions() { */ @Test void shouldExtractTypeEvenIfNoDotPresent() { - Report report = parseInCheckStyleFolder("issue60859.xml"); + var report = parseInCheckStyleFolder("issue60859.xml"); assertThat(report).hasSize(3); assertThat(report.get(0)).hasMessage( @@ -104,7 +104,7 @@ void shouldExtractTypeEvenIfNoDotPresent() { */ @Test void testParsingOfScalaStyleFormat() { - Report report = parseInCheckStyleFolder("scalastyle-output.xml"); + var report = parseInCheckStyleFolder("scalastyle-output.xml"); assertThat(report).hasSize(2); } @@ -116,7 +116,7 @@ void testParsingOfScalaStyleFormat() { */ @Test void shouldParseErrorToSeverityError() { - Report report = parseInCheckStyleFolder(REPORT_WITH_ALL_SEVERITES); + var report = parseInCheckStyleFolder(REPORT_WITH_ALL_SEVERITES); assertThat(report.get(0)).hasSeverity(Severity.ERROR); } @@ -125,7 +125,7 @@ void shouldParseErrorToSeverityError() { */ @Test void shouldParseWarningToSeverityWarningNormal() { - Report report = parseInCheckStyleFolder(REPORT_WITH_ALL_SEVERITES); + var report = parseInCheckStyleFolder(REPORT_WITH_ALL_SEVERITES); assertThat(report.get(1)).hasSeverity(Severity.WARNING_NORMAL); } @@ -134,7 +134,7 @@ void shouldParseWarningToSeverityWarningNormal() { */ @Test void shouldParseInfoToSeverityWarningLow() { - Report report = parseInCheckStyleFolder(REPORT_WITH_ALL_SEVERITES); + var report = parseInCheckStyleFolder(REPORT_WITH_ALL_SEVERITES); assertThat(report.get(2)).hasSeverity(Severity.WARNING_LOW); } diff --git a/src/test/java/edu/hm/hafner/analysis/parser/ClairParserTest.java b/src/test/java/edu/hm/hafner/analysis/parser/ClairParserTest.java index 13fed21dc..9b0387d85 100644 --- a/src/test/java/edu/hm/hafner/analysis/parser/ClairParserTest.java +++ b/src/test/java/edu/hm/hafner/analysis/parser/ClairParserTest.java @@ -54,7 +54,7 @@ void accepts() { @Test void unusualInput() { - Report report = parse("clair-unusual.json"); + var report = parse("clair-unusual.json"); assertThat(report).hasSize(5); assertThat(report.get(0)) .hasSeverity(Severity.WARNING_LOW) diff --git a/src/test/java/edu/hm/hafner/analysis/parser/ClangAnalyzerPlistParserTest.java b/src/test/java/edu/hm/hafner/analysis/parser/ClangAnalyzerPlistParserTest.java index 515454d12..faf319673 100644 --- a/src/test/java/edu/hm/hafner/analysis/parser/ClangAnalyzerPlistParserTest.java +++ b/src/test/java/edu/hm/hafner/analysis/parser/ClangAnalyzerPlistParserTest.java @@ -56,7 +56,7 @@ protected void assertThatIssuesArePresent(final Report report, final SoftAsserti @Test void shouldOnlyAcceptXmlFiles() { - ClangAnalyzerPlistParser parser = createParser(); + var parser = createParser(); assertThat(parser.accepts(createReaderFactory("clang-analyzer-test.txt"))).isTrue(); diff --git a/src/test/java/edu/hm/hafner/analysis/parser/ClangParserTest.java b/src/test/java/edu/hm/hafner/analysis/parser/ClangParserTest.java index ff0fc6e75..57b8293ec 100644 --- a/src/test/java/edu/hm/hafner/analysis/parser/ClangParserTest.java +++ b/src/test/java/edu/hm/hafner/analysis/parser/ClangParserTest.java @@ -110,11 +110,11 @@ protected void assertThatIssuesArePresent(final Report report, final SoftAsserti */ @Test void issue31936() { - Report warnings = parse("issue31936.txt"); + var warnings = parse("issue31936.txt"); assertThat(warnings).hasSize(1); - try (SoftAssertions softly = new SoftAssertions()) { + try (var softly = new SoftAssertions()) { softly.assertThat(warnings.get(0)).hasLineStart(1211) .hasLineEnd(1211) .hasColumnStart(26) @@ -134,7 +134,7 @@ void issue31936() { */ @Test void shouldNotDetectTestResults() { - Report warnings = parse("timestamps.log"); + var warnings = parse("timestamps.log"); assertThat(warnings).isEmpty(); } @@ -146,7 +146,7 @@ void shouldNotDetectTestResults() { */ @Test void issue36817() { - Report warnings = parse("issue36817.txt"); + var warnings = parse("issue36817.txt"); assertThat(warnings).isEmpty(); } @@ -158,11 +158,11 @@ void issue36817() { */ @Test void issue18084() { - Report warnings = parse("issue18084.txt"); + var warnings = parse("issue18084.txt"); assertThat(warnings).hasSize(1); - try (SoftAssertions softly = new SoftAssertions()) { + try (var softly = new SoftAssertions()) { softly.assertThat(warnings.get(0)).hasLineStart(10) .hasLineEnd(10) .hasColumnStart(10) @@ -181,11 +181,11 @@ void issue18084() { */ @Test void issue14333() { - Report warnings = parse("issue14333.txt"); + var warnings = parse("issue14333.txt"); assertThat(warnings).hasSize(1); - try (SoftAssertions softly = new SoftAssertions()) { + try (var softly = new SoftAssertions()) { softly.assertThat(warnings.get(0)).hasLineStart(1518) .hasLineEnd(1518) .hasColumnStart(28) @@ -199,11 +199,11 @@ void issue14333() { @Test void assertThatClangPathsAreCorrectForAllPlatforms() { - Report warnings = parse("llvm-clang.txt"); + var warnings = parse("llvm-clang.txt"); assertThat(warnings).hasSize(3); - try (SoftAssertions softly = new SoftAssertions()) { + try (var softly = new SoftAssertions()) { softly.assertThat(warnings.get(0)).hasLineStart(35) .hasLineEnd(35) .hasColumnStart(15) diff --git a/src/test/java/edu/hm/hafner/analysis/parser/ClangTidyParserTest.java b/src/test/java/edu/hm/hafner/analysis/parser/ClangTidyParserTest.java index 8def8f8f9..311912a05 100644 --- a/src/test/java/edu/hm/hafner/analysis/parser/ClangTidyParserTest.java +++ b/src/test/java/edu/hm/hafner/analysis/parser/ClangTidyParserTest.java @@ -109,7 +109,7 @@ protected void assertThatIssuesArePresent(final Report annotation, final SoftAss @Test void issue56915() { - Report warnings = parse("issue56915.txt"); + var warnings = parse("issue56915.txt"); assertThat(warnings).hasSize(3); } } diff --git a/src/test/java/edu/hm/hafner/analysis/parser/CodeCheckerParserTest.java b/src/test/java/edu/hm/hafner/analysis/parser/CodeCheckerParserTest.java index 026b66020..cd97004fa 100644 --- a/src/test/java/edu/hm/hafner/analysis/parser/CodeCheckerParserTest.java +++ b/src/test/java/edu/hm/hafner/analysis/parser/CodeCheckerParserTest.java @@ -66,7 +66,7 @@ protected void assertThatIssuesArePresent(final Report report, final SoftAsserti @Test void shouldParseWindowsPaths() { - Report report = parse("CodeChecker_with_windows_paths.txt"); + var report = parse("CodeChecker_with_windows_paths.txt"); assertThat(report).hasSize(5); assertThat(report.get(0)) .hasLineStart(15) diff --git a/src/test/java/edu/hm/hafner/analysis/parser/CppLintParserTest.java b/src/test/java/edu/hm/hafner/analysis/parser/CppLintParserTest.java index a5a2e7d44..3ee9c5d08 100644 --- a/src/test/java/edu/hm/hafner/analysis/parser/CppLintParserTest.java +++ b/src/test/java/edu/hm/hafner/analysis/parser/CppLintParserTest.java @@ -26,11 +26,11 @@ class CppLintParserTest extends AbstractParserTest { */ @Test void issue18290() { - Report warnings = parse("issue18290.txt"); + var warnings = parse("issue18290.txt"); assertThat(warnings).hasSize(2); - try (SoftAssertions softly = new SoftAssertions()) { + try (var softly = new SoftAssertions()) { softly.assertThat(warnings.get(0)).hasLineStart(399) .hasLineEnd(399) .hasMessage("Missing space before {") @@ -64,11 +64,11 @@ protected void assertThatIssuesArePresent(final Report report, final SoftAsserti */ @Test void cpplintMessageWithColon() { - Report warnings = parse("cpplint-message-with-colon.txt"); + var warnings = parse("cpplint-message-with-colon.txt"); assertThat(warnings).hasSize(1); - try (SoftAssertions softly = new SoftAssertions()) { + try (var softly = new SoftAssertions()) { softly.assertThat(warnings.get(0)) .hasLineStart(1) .hasLineEnd(1) diff --git a/src/test/java/edu/hm/hafner/analysis/parser/DScannerParserTest.java b/src/test/java/edu/hm/hafner/analysis/parser/DScannerParserTest.java index a95e2631e..2ad347ffa 100644 --- a/src/test/java/edu/hm/hafner/analysis/parser/DScannerParserTest.java +++ b/src/test/java/edu/hm/hafner/analysis/parser/DScannerParserTest.java @@ -58,7 +58,7 @@ protected void assertThatIssuesArePresent(final Report report, final SoftAsserti @Test void shouldHandleIncompleteReports() { - Report report = createParser().parse(createReaderFactory("dscanner-incomplete-report.json")); + var report = createParser().parse(createReaderFactory("dscanner-incomplete-report.json")); assertThat(report).hasSize(2); assertThat(report.getErrorMessages()).isEmpty(); } diff --git a/src/test/java/edu/hm/hafner/analysis/parser/DoxygenParserTest.java b/src/test/java/edu/hm/hafner/analysis/parser/DoxygenParserTest.java index 10ac08d37..da94ecc90 100644 --- a/src/test/java/edu/hm/hafner/analysis/parser/DoxygenParserTest.java +++ b/src/test/java/edu/hm/hafner/analysis/parser/DoxygenParserTest.java @@ -33,15 +33,16 @@ protected DoxygenParserTest() { */ @Test void issue64657() { - Report report = parse("issue64657.txt"); + var report = parse("issue64657.txt"); assertThat(report).hasSize(3); assertThat(report.get(0)) .hasLineStart(0) .hasMessage( - "doxygen no longer ships with the FreeSans font.\n" - + " You may want to clear or change DOT_FONTNAME.\n" - + " Otherwise you run the risk that the wrong font is being used for dot generated graphs.") + """ + doxygen no longer ships with the FreeSans font. + You may want to clear or change DOT_FONTNAME. + Otherwise you run the risk that the wrong font is being used for dot generated graphs.""") .hasFileName("-") .hasSeverity(Severity.WARNING_NORMAL); @@ -66,17 +67,18 @@ void issue64657() { */ @Test void issue7178() { - Report report = parse("issue7178.txt"); + var report = parse("issue7178.txt"); assertThat(report).hasSize(1); assertThat(report.get(0)) .hasLineStart(977) .hasMessage( - "‘t_day_of_year.boost::CV::constrained_value >::value_’ may be used uninitialized in this function\n" - + "Compiling library/datetimelib/Timezone.cpp\n" - + "Compiling library/datetimelib/TimezoneDB.cpp\n" - + "Creating libdatetimelib.a\n" - + "ar: creating /home/hudson_slave/workspace/RX-kernel-daily_i686-linux-gcc41/trunk/src/arch/i686-linux-gcc41/build/Debug/libdatetimelib.a") + """ + ‘t_day_of_year.boost::CV::constrained_value >::value_’ may be used uninitialized in this function + Compiling library/datetimelib/Timezone.cpp + Compiling library/datetimelib/TimezoneDB.cpp + Creating libdatetimelib.a + ar: creating /home/hudson_slave/workspace/RX-kernel-daily_i686-linux-gcc41/trunk/src/arch/i686-linux-gcc41/build/Debug/libdatetimelib.a""") .hasFileName( "/home/hudson_slave/workspace/RX-kernel-daily_i686-linux-gcc41/trunk/src/3rdparty/boost/exp/boost/date_time/time_facet.hpp") .hasSeverity(Severity.WARNING_NORMAL); @@ -89,13 +91,13 @@ void issue7178() { */ @Test void issue55840() { - Report linuxReport = parse("issue55840.linux.txt"); + var linuxReport = parse("issue55840.linux.txt"); assertThat(linuxReport).hasSize(14); for (Issue issue : linuxReport) { assertThat(issue.getFileName()).startsWith("/srv/www/jenkins/workspace/code_master/pump/"); } - Report windowsReport = parse("issue55840.windows.txt"); + var windowsReport = parse("issue55840.windows.txt"); assertThat(windowsReport).hasSize(15); for (Issue issue : windowsReport) { assertThat(issue.getFileName()).startsWith("C:/jenkins/workspace/24-Test-Jenkins-WinTen-Extension@2/pump"); @@ -109,8 +111,8 @@ void issue55840() { */ @Test void issue6971() { - Report warnings = parse("issue6971.txt"); - try (SoftAssertions softly = new SoftAssertions()) { + var warnings = parse("issue6971.txt"); + try (var softly = new SoftAssertions()) { softly.assertThat(warnings).hasSize(4); Iterator iterator = warnings.iterator(); @@ -197,21 +199,23 @@ protected void assertThatIssuesArePresent(final Report report, final SoftAsserti softly.assertThat(iterator.next()) .hasLineEnd(1351) .hasLineStart(1351) - .hasMessage("no matching file member found for \n" - + "defaulttype::RigidDeriv< 3, double > sofa::core::componentmodel::behavior::inertiaForce< defaulttype::RigidCoord< 3, double >, defaulttype::RigidDeriv< 3, double >, objectmodel::BaseContext::Vec3, defaulttype::RigidMass< 3, double >, objectmodel::BaseContext::SpatialVector >(const sofa::defaulttype::SolidTypes::SpatialVector &vframe, const objectmodel::BaseContext::Vec3 &aframe, const defaulttype::RigidMass< 3, double > &mass, const defaulttype::RigidCoord< 3, double > &x, const defaulttype::RigidDeriv< 3, double > &v)\n" - + "Possible candidates:\n" - + " Deriv inertiaForce(const SV &, const Vec &, const M &, const Coord &, const Deriv &)") + .hasMessage(""" + no matching file member found for\s + defaulttype::RigidDeriv< 3, double > sofa::core::componentmodel::behavior::inertiaForce< defaulttype::RigidCoord< 3, double >, defaulttype::RigidDeriv< 3, double >, objectmodel::BaseContext::Vec3, defaulttype::RigidMass< 3, double >, objectmodel::BaseContext::SpatialVector >(const sofa::defaulttype::SolidTypes::SpatialVector &vframe, const objectmodel::BaseContext::Vec3 &aframe, const defaulttype::RigidMass< 3, double > &mass, const defaulttype::RigidCoord< 3, double > &x, const defaulttype::RigidDeriv< 3, double > &v) + Possible candidates: + Deriv inertiaForce(const SV &, const Vec &, const M &, const Coord &, const Deriv &)""") .hasFileName("/home/user/myproject/defaulttype/RigidTypes.h") .hasSeverity(Severity.WARNING_NORMAL); softly.assertThat(iterator.next()) .hasLineEnd(569) .hasLineStart(569) - .hasMessage("no uniquely matching class member found for\n" - + " template < R >\n" - + " SolidTypes< R >::Vec sofa::defaulttype::SolidTypes< R >::mult(const typename sofa::defaulttype::Mat< 3, 3, Real > &m, const typename SolidTypes< R >::Vec &v)\n" - + "Possible candidates:\n" - + " static Vec sofa::defaulttype::SolidTypes< R >::mult(const Mat &m, const Vec &v) at line 404 of file /home/user/myprojeOdeSolverct/defaulttype/SolidTypes.h") + .hasMessage(""" + no uniquely matching class member found for + template < R > + SolidTypes< R >::Vec sofa::defaulttype::SolidTypes< R >::mult(const typename sofa::defaulttype::Mat< 3, 3, Real > &m, const typename SolidTypes< R >::Vec &v) + Possible candidates: + static Vec sofa::defaulttype::SolidTypes< R >::mult(const Mat &m, const Vec &v) at line 404 of file /home/user/myprojeOdeSolverct/defaulttype/SolidTypes.h""") .hasFileName("/home/user/myproject/defaulttype/SolidTypes.inl") .hasSeverity(Severity.WARNING_NORMAL); @@ -226,11 +230,12 @@ protected void assertThatIssuesArePresent(final Report report, final SoftAsserti softly.assertThat(iterator.next()) .hasLineEnd(496) .hasLineStart(496) - .hasMessage("no matching file member found for \n" - + "void sofa::helper::lcp_lexicolemke(int *nn, double *vec, double *q, double *zlem, double *wlem, int *info, int *iparamLCP, double *dparamLCP)\n" - + "Possible candidates:\n" - + " int lcp_lexicolemke(int dim, double *q, double **M, double *res)\n" - + " int lcp_lexicolemke(int dim, double *q, double **M, double **A, double *res)") + .hasMessage(""" + no matching file member found for\s + void sofa::helper::lcp_lexicolemke(int *nn, double *vec, double *q, double *zlem, double *wlem, int *info, int *iparamLCP, double *dparamLCP) + Possible candidates: + int lcp_lexicolemke(int dim, double *q, double **M, double *res) + int lcp_lexicolemke(int dim, double *q, double **M, double **A, double *res)""") .hasFileName("/home/user/myproject/helper/LCPcalc.cpp") .hasSeverity(Severity.WARNING_NORMAL); diff --git a/src/test/java/edu/hm/hafner/analysis/parser/EclipseMavenParserTest.java b/src/test/java/edu/hm/hafner/analysis/parser/EclipseMavenParserTest.java index aad4f57d3..2b8495aee 100644 --- a/src/test/java/edu/hm/hafner/analysis/parser/EclipseMavenParserTest.java +++ b/src/test/java/edu/hm/hafner/analysis/parser/EclipseMavenParserTest.java @@ -62,7 +62,7 @@ protected void assertThatIssuesArePresent(final Report report, final SoftAsserti */ @Test void shouldNotFindAntIssues() { - Report warnings = parse("eclipse.txt"); + var warnings = parse("eclipse.txt"); assertThat(warnings).hasSize(0); } @@ -74,11 +74,11 @@ void shouldNotFindAntIssues() { */ @Test void issue21377() { - Report warnings = parse("issue21377.txt"); + var warnings = parse("issue21377.txt"); assertThat(warnings).hasSize(1); - try (SoftAssertions softly = new SoftAssertions()) { + try (var softly = new SoftAssertions()) { softly.assertThat(warnings.get(0)) .hasSeverity(Severity.WARNING_NORMAL) .hasLineStart(13) @@ -96,11 +96,11 @@ void issue21377() { */ @Test void issue55368() { - Report warnings = parse("issue55368.txt"); + var warnings = parse("issue55368.txt"); assertThat(warnings).hasSize(3); - try (SoftAssertions softly = new SoftAssertions()) { + try (var softly = new SoftAssertions()) { softly.assertThat(warnings.get(0)) .hasSeverity(Severity.WARNING_NORMAL) .hasLineStart(9) @@ -127,13 +127,13 @@ void issue55368() { */ @Test void javadocCategory() { - Report warnings = parse("eclipse-maven-withjavadoc.log"); + var warnings = parse("eclipse-maven-withjavadoc.log"); EclipseSharedChecks.verifyCategory(warnings); } @Test void shouldOnlyAcceptTextFiles() { - EclipseMavenParser parser = createParser(); + var parser = createParser(); assertThat(parser.accepts(createReaderFactory("eclipse-withinfo.txt"))).isTrue(); assertThat(parser.accepts(createReaderFactory("eclipse-withinfo.xml"))).isFalse(); diff --git a/src/test/java/edu/hm/hafner/analysis/parser/EclipseParserTest.java b/src/test/java/edu/hm/hafner/analysis/parser/EclipseParserTest.java index b937ef026..8b82bc9bf 100644 --- a/src/test/java/edu/hm/hafner/analysis/parser/EclipseParserTest.java +++ b/src/test/java/edu/hm/hafner/analysis/parser/EclipseParserTest.java @@ -28,7 +28,7 @@ protected EclipseParser createParser() { protected void assertThatIssuesArePresent(final Report report, final SoftAssertions softly) { assertThat(report).hasSize(8); - Issue annotation = report.get(0); + var annotation = report.get(0); softly.assertThat(annotation) .hasSeverity(Severity.WARNING_NORMAL) .hasLineStart(3) @@ -46,11 +46,11 @@ protected void assertThatIssuesArePresent(final Report report, final SoftAsserti */ @Test void issue55358() { - Report warnings = parse("java-eclipse-ant.log"); + var warnings = parse("java-eclipse-ant.log"); assertThat(warnings).hasSize(27); - try (SoftAssertions softly = new SoftAssertions()) { + try (var softly = new SoftAssertions()) { softly.assertThat(warnings.get(0)) .hasSeverity(Severity.WARNING_NORMAL) .hasLineStart(82) @@ -68,7 +68,7 @@ void issue55358() { */ @Test void issue12822() { - Report warnings = parse("issue12822.txt"); + var warnings = parse("issue12822.txt"); assertThat(warnings).hasSize(15); } @@ -80,10 +80,10 @@ void issue12822() { */ @Test void issue6427() { - Report warnings = parse("issue6427.txt"); + var warnings = parse("issue6427.txt"); assertThat(warnings).hasSize(18); - try (SoftAssertions softly = new SoftAssertions()) { + try (var softly = new SoftAssertions()) { softly.assertThat(warnings.get(0)) .hasSeverity(Severity.WARNING_NORMAL) .hasLineStart(10) @@ -103,11 +103,11 @@ void issue6427() { */ @Test void issue7077() { - Report warnings = parse("issue7077.txt"); + var warnings = parse("issue7077.txt"); assertThat(warnings).hasSize(2); - try (SoftAssertions softly = new SoftAssertions()) { + try (var softly = new SoftAssertions()) { softly.assertThat(warnings.get(0)).hasSeverity(Severity.WARNING_NORMAL) .hasLineStart(90) .hasLineEnd(90) @@ -134,7 +134,7 @@ void issue7077() { */ @Test void issue7077all() { - Report sorted = parse("issue7077-all.txt"); + var sorted = parse("issue7077-all.txt"); assertThat(sorted).hasSize(45); @@ -148,10 +148,10 @@ void issue7077all() { @Test void issue57379() { - Report report = parse("issue57379.txt"); + var report = parse("issue57379.txt"); assertThat(report).hasSize(1); - try (SoftAssertions softly = new SoftAssertions()) { + try (var softly = new SoftAssertions()) { softly.assertThat(report.get(0)) .hasSeverity(Severity.WARNING_NORMAL) .hasLineStart(3) @@ -168,11 +168,11 @@ void issue57379() { */ @Test void infoLogLevel() { - Report report = parse("eclipse-withinfo.txt"); + var report = parse("eclipse-withinfo.txt"); assertThat(report).hasSize(6); - try (SoftAssertions softly = new SoftAssertions()) { + try (var softly = new SoftAssertions()) { softly.assertThat(report.get(0)) .hasSeverity(Severity.ERROR) .hasLineStart(8) @@ -229,13 +229,13 @@ void infoLogLevel() { */ @Test void javadocCategory() { - Report warnings = parse("eclipse-withjavadoc.log"); + var warnings = parse("eclipse-withjavadoc.log"); EclipseSharedChecks.verifyCategory(warnings); } @Test void shouldOnlyAcceptTextFiles() { - EclipseParser parser = createParser(); + var parser = createParser(); assertThat(parser.accepts(createReaderFactory("eclipse-withinfo.txt"))).isTrue(); assertThat(parser.accepts(createReaderFactory("eclipse-withinfo.xml"))).isFalse(); diff --git a/src/test/java/edu/hm/hafner/analysis/parser/EclipseSharedChecks.java b/src/test/java/edu/hm/hafner/analysis/parser/EclipseSharedChecks.java index da70cac73..00b41d08d 100644 --- a/src/test/java/edu/hm/hafner/analysis/parser/EclipseSharedChecks.java +++ b/src/test/java/edu/hm/hafner/analysis/parser/EclipseSharedChecks.java @@ -26,7 +26,7 @@ private EclipseSharedChecks() { static void verifyCategory(final Report warnings) { assertThat(warnings).hasSize(5); - try (SoftAssertions softly = new SoftAssertions()) { + try (var softly = new SoftAssertions()) { softly.assertThat(warnings.get(0)) .hasSeverity(Severity.WARNING_NORMAL) .hasLineStart(1) diff --git a/src/test/java/edu/hm/hafner/analysis/parser/EclipseXMLParserTest.java b/src/test/java/edu/hm/hafner/analysis/parser/EclipseXMLParserTest.java index 99b92344d..be50b0219 100644 --- a/src/test/java/edu/hm/hafner/analysis/parser/EclipseXMLParserTest.java +++ b/src/test/java/edu/hm/hafner/analysis/parser/EclipseXMLParserTest.java @@ -95,11 +95,11 @@ protected void assertThatIssuesArePresent(final Report report, final SoftAsserti */ @Test void javadocCategory() { - Report warnings = parse("eclipse-withjavadoc.xml"); + var warnings = parse("eclipse-withjavadoc.xml"); assertThat(warnings).hasSize(5); - try (SoftAssertions softly = new SoftAssertions()) { + try (var softly = new SoftAssertions()) { softly.assertThat(warnings.get(0)) .hasSeverity(Severity.WARNING_NORMAL) .hasLineStart(1) @@ -139,7 +139,7 @@ void javadocCategory() { @Test void shouldOnlyAcceptXmlFiles() { - EclipseXMLParser parser = createParser(); + var parser = createParser(); assertThat(parser.accepts(createReaderFactory("eclipse-withinfo.xml"))).isTrue(); diff --git a/src/test/java/edu/hm/hafner/analysis/parser/ErrorProneParserTest.java b/src/test/java/edu/hm/hafner/analysis/parser/ErrorProneParserTest.java index f1475d3e7..d9872bfa3 100644 --- a/src/test/java/edu/hm/hafner/analysis/parser/ErrorProneParserTest.java +++ b/src/test/java/edu/hm/hafner/analysis/parser/ErrorProneParserTest.java @@ -45,7 +45,7 @@ protected void assertThatIssuesArePresent(final Report report, final SoftAsserti @Test void shouldFindAllWarnings() { - Report report = parse("error-prone-maven.log"); + var report = parse("error-prone-maven.log"); assertThat(report).hasSize(1); assertThat(report.get(0)) @@ -59,7 +59,7 @@ void shouldFindAllWarnings() { @Test void shouldFindAllNewWarnings() { - Report report = parse("maven-error-prone.log"); + var report = parse("maven-error-prone.log"); assertThat(report).hasSize(37); assertThat(report.get(0)) @@ -72,7 +72,7 @@ void shouldFindAllNewWarnings() { @Test void shouldSkipJavacWarnings() { - Report report = parse("javac.log"); + var report = parse("javac.log"); assertThat(report).hasSize(4); assertThat(report.get(0)) diff --git a/src/test/java/edu/hm/hafner/analysis/parser/FxcopParserTest.java b/src/test/java/edu/hm/hafner/analysis/parser/FxcopParserTest.java index d64664b81..7aca0f2c2 100644 --- a/src/test/java/edu/hm/hafner/analysis/parser/FxcopParserTest.java +++ b/src/test/java/edu/hm/hafner/analysis/parser/FxcopParserTest.java @@ -50,7 +50,7 @@ protected void assertThatIssuesArePresent(final Report report, final SoftAsserti */ @Test void testJenkins14172() { - Report result = parse("issue14172.xml"); + var result = parse("issue14172.xml"); assertThat(result).hasSize(44); } diff --git a/src/test/java/edu/hm/hafner/analysis/parser/Gcc4CompilerParserTest.java b/src/test/java/edu/hm/hafner/analysis/parser/Gcc4CompilerParserTest.java index 72c76cf72..c2e69db8b 100644 --- a/src/test/java/edu/hm/hafner/analysis/parser/Gcc4CompilerParserTest.java +++ b/src/test/java/edu/hm/hafner/analysis/parser/Gcc4CompilerParserTest.java @@ -91,8 +91,9 @@ protected void assertThatIssuesArePresent(final Report report, final SoftAsserti softly.assertThat(iterator.next()) .hasLineStart(352) .hasLineEnd(352) - .hasMessage("'s2.mepSector2::lubrications' may be used uninitialized in this function\n" - + "main/mep.cpp:1477: note: 's2.mepSector2::lubrications' was declared here") + .hasMessage(""" + 's2.mepSector2::lubrications' may be used uninitialized in this function + main/mep.cpp:1477: note: 's2.mepSector2::lubrications' was declared here""") .hasFileName("main/mep.cpp") .hasSeverity(Severity.WARNING_NORMAL); @@ -129,8 +130,9 @@ protected void assertThatIssuesArePresent(final Report report, final SoftAsserti softly.assertThat(iterator.next()) .hasLineStart(12) .hasLineEnd(12) - .hasMessage("expected ';' before 'return'\n" - + "foo bar.hello*world:12:") + .hasMessage(""" + expected ';' before 'return' + foo bar.hello*world:12:""") .hasFileName("fo:oo.cpp") .hasSeverity(Severity.ERROR); @@ -145,8 +147,8 @@ protected void assertThatIssuesArePresent(final Report report, final SoftAsserti @Test void shouldAssignAbsolutePath() { - Report report = parse("gnuMakeGcc.txt"); - try (SoftAssertions softly = new SoftAssertions()) { + var report = parse("gnuMakeGcc.txt"); + try (var softly = new SoftAssertions()) { Iterator iterator = report.iterator(); softly.assertThat(report).hasSize(12); softly.assertThat(iterator.next()) @@ -195,8 +197,9 @@ void shouldAssignAbsolutePath() { .hasSeverity(Severity.WARNING_NORMAL) .hasLineStart(352) .hasLineEnd(352) - .hasMessage("'s2.mepSector2::lubrications' may be used uninitialized in this function\n" - + "main/mep.cpp:1477: note: 's2.mepSector2::lubrications' was declared here") + .hasMessage(""" + 's2.mepSector2::lubrications' may be used uninitialized in this function + main/mep.cpp:1477: note: 's2.mepSector2::lubrications' was declared here""") .hasFileName("/dir1/dir2/main/mep.cpp"); softly.assertThat(iterator.next()) @@ -243,14 +246,14 @@ void shouldAssignAbsolutePath() { /** Should not report warnings already detected by {@link Gcc4LinkerParser}. */ @Test void shouldNotReportGccWarnings() { - Report warnings = parse("gcc4ld.txt"); + var warnings = parse("gcc4ld.txt"); assertThat(warnings).isEmpty(); } @Test void shouldResolveAbsolutePaths() { - Report warnings = createParser().parse(createReaderFactory("absolute-paths.txt")); + var warnings = createParser().parse(createReaderFactory("absolute-paths.txt")); assertThat(warnings).hasSize(188); @@ -266,7 +269,7 @@ void shouldResolveAbsolutePaths() { */ @Test void issue66835() { - Report warnings = createParser().parse(createReaderFactory("issue66835.makefile.log")); + var warnings = createParser().parse(createReaderFactory("issue66835.makefile.log")); assertThat(warnings).hasSize(3); @@ -290,7 +293,7 @@ void issue66835() { */ @Test void issue66923() { - Report warnings = createParser().parse(createReaderFactory("issue66923.txt")); + var warnings = createParser().parse(createReaderFactory("issue66923.txt")); assertThat(warnings).hasSize(0); assertThat(warnings).doesNotHaveErrors(); @@ -303,7 +306,7 @@ void issue66923() { */ @Test void issue69242() { - Report warnings = createParser().parse(createReaderFactory("issue69242.txt")); + var warnings = createParser().parse(createReaderFactory("issue69242.txt")); assertThat(warnings).hasSize(2); assertThat(warnings).doesNotHaveErrors(); @@ -319,33 +322,35 @@ void issue69242() { */ @Test void issue56020() { - Report makefileReport = parse("issue56020.makefile.log"); + var makefileReport = parse("issue56020.makefile.log"); assertThat(makefileReport).hasSize(1); - try (SoftAssertions softly = new SoftAssertions()) { + try (var softly = new SoftAssertions()) { softly.assertThat(makefileReport.get(0)) .hasLineStart(1) .hasColumnStart(26) - .hasMessage("unused variable ‘a’ [-Wunused-variable]\n" - + " void doSomething() { int a; }\n" - + " ^") + .hasMessage(""" + unused variable ‘a’ [-Wunused-variable] + void doSomething() { int a; } + ^""") .hasFileName("/shd/CTC/TOOLS/Jenkins/workspace/ChrisTest/main.cpp") .hasCategory("unused-variable") .hasSeverity(Severity.WARNING_NORMAL); } - Report ninjaReport = parse("issue56020.ninja.log"); + var ninjaReport = parse("issue56020.ninja.log"); assertThat(ninjaReport).hasSize(1); - try (SoftAssertions softly = new SoftAssertions()) { + try (var softly = new SoftAssertions()) { softly.assertThat(ninjaReport.get(0)) .hasLineStart(1) .hasColumnStart(26) - .hasMessage("unused variable ‘a’ [-Wunused-variable]\n" - + " void doSomething() { int a; }\n" - + " ^") + .hasMessage(""" + unused variable ‘a’ [-Wunused-variable] + void doSomething() { int a; } + ^""") .hasFileName("/shd/CTC/TOOLS/Jenkins/workspace/ChrisTest/main.cpp") .hasCategory("unused-variable") .hasSeverity(Severity.WARNING_NORMAL); @@ -359,17 +364,18 @@ void issue56020() { */ @Test void issue18081() { - Report warnings = parse("issue18081.txt"); + var warnings = parse("issue18081.txt"); assertThat(warnings).hasSize(1); - try (SoftAssertions softly = new SoftAssertions()) { + try (var softly = new SoftAssertions()) { softly.assertThat(warnings.get(0)) .hasLineStart(10) .hasLineEnd(10) - .hasMessage("'test.h' file not found\n" - + "#include \"test.h\"\n" - + " ^") + .hasMessage(""" + 'test.h' file not found + #include "test.h" + ^""") .hasFileName("./test.h") .hasSeverity(Severity.ERROR); } @@ -382,11 +388,11 @@ void issue18081() { */ @Test void issue9926() { - Report warnings = parse("issue9926.txt"); + var warnings = parse("issue9926.txt"); assertThat(warnings).hasSize(1); - try (SoftAssertions softly = new SoftAssertions()) { + try (var softly = new SoftAssertions()) { softly.assertThat(warnings.get(0)) .hasLineStart(52) .hasLineEnd(52) @@ -403,7 +409,7 @@ void issue9926() { */ @Test void issue6563() { - Report warnings = parse("issue6563.txt"); + var warnings = parse("issue6563.txt"); assertThat(warnings).hasSize(10); } @@ -415,7 +421,7 @@ void issue6563() { */ @Test void issue5606() { - Report warnings = parse("issue5606.txt"); + var warnings = parse("issue5606.txt"); assertThat(warnings).hasSize(5).hasDuplicatesSize(5); } @@ -427,7 +433,7 @@ void issue5606() { */ @Test void issue5605() { - Report warnings = parse("issue5605.txt"); + var warnings = parse("issue5605.txt"); assertThat(warnings).hasSize(2).hasDuplicatesSize(4); } @@ -439,7 +445,7 @@ void issue5605() { */ @Test void issue5445() { - Report warnings = parse("issue5445.txt"); + var warnings = parse("issue5445.txt"); assertThat(warnings).isEmpty(); } @@ -451,7 +457,7 @@ void issue5445() { */ @Test void issue5870() { - Report warnings = parse("issue5870.txt"); + var warnings = parse("issue5870.txt"); assertThat(warnings) .isEmpty(); @@ -464,14 +470,14 @@ void issue5870() { */ @Test void issue11799() { - Report warnings = parse("issue11799.txt"); + var warnings = parse("issue11799.txt"); assertThat(warnings) .hasSize(4); Iterator iterator = warnings.iterator(); - try (SoftAssertions softly = new SoftAssertions()) { + try (var softly = new SoftAssertions()) { softly.assertThat(iterator.next()) .hasLineStart(4) .hasLineEnd(4) @@ -514,7 +520,7 @@ void issue11799() { */ @Test void issue56612() { - Report warnings = parse("issue56612.log"); + var warnings = parse("issue56612.log"); assertThat(warnings).hasSize(6); @@ -528,7 +534,7 @@ void issue56612() { Predicate predicate = new IssueFilterBuilder() .setExcludeMessageFilter(".*QVTKWidget.*", ".*tmpnam.*") .setExcludeFileNameFilter(".*qrc_icons\\.cpp.*").build(); - Report filtered = warnings.filter(predicate); + var filtered = warnings.filter(predicate); assertThat(filtered).hasSize(0); } @@ -539,18 +545,19 @@ void issue56612() { */ @Test void issue55221() { - Report warnings = parse("issue55221.txt"); + var warnings = parse("issue55221.txt"); assertThat(warnings).hasSize(6).hasDuplicatesSize(2); - try (SoftAssertions softly = new SoftAssertions()) { + try (var softly = new SoftAssertions()) { softly.assertThat(warnings.get(0)) .hasLineStart(204) .hasColumnStart(26) .hasMessage( - "‘StarLibs::Camelot::ScBitTrue::StarUlPhyRxCommonCamelot::SectorDLCAL’ will be initialized after [-Wreorder]\n" - + "ParamNumeric SectorDLCAL;\n" - + "^~~~~~~~~~~") + """ + ‘StarLibs::Camelot::ScBitTrue::StarUlPhyRxCommonCamelot::SectorDLCAL’ will be initialized after [-Wreorder] + ParamNumeric SectorDLCAL; + ^~~~~~~~~~~""") .hasFileName( "/data/hudsonuser/workspace/Regression_test_SystemC_gcc@2/StarLibs/Camelot/ScBitTrue/StarUlPhyRxCommonCamelot.h") .hasCategory("reorder") @@ -560,9 +567,10 @@ void issue55221() { .hasLineStart(179) .hasColumnStart(32) .hasMessage( - "‘ParamNumeric StarLibs::Camelot::ScBitTrue::StarUlPhyRxCommonCamelot::UseDSPBuilderFFT’ [-Wreorder]\n" - + "ParamNumeric UseDSPBuilderFFT;\n" - + "^~~~~~~~~~~~~~~~") + """ + ‘ParamNumeric StarLibs::Camelot::ScBitTrue::StarUlPhyRxCommonCamelot::UseDSPBuilderFFT’ [-Wreorder] + ParamNumeric UseDSPBuilderFFT; + ^~~~~~~~~~~~~~~~""") .hasFileName( "/data/hudsonuser/workspace/Regression_test_SystemC_gcc@2/StarLibs/Camelot/ScBitTrue/StarUlPhyRxCommonCamelot.h") .hasCategory("reorder") @@ -590,11 +598,12 @@ void issue55221() { .hasLineStart(168) .hasColumnStart(21) .hasMessage( - "dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]\n" - + "In file included from ../../../StarLibs/Camelot/ScBitTrue/AlteraDspBuilderFFT/csl/steps.h:4:0,\n" - + " from ../../../StarLibs/Camelot/ScBitTrue/AlteraDspBuilderFFT/csl/csl.h:4,\n" - + " from vfft_fft_core_VFFT1_CModel.h:2,\n" - + " from vfft_fft_core_VFFT1_CModel.cpp:2:") + """ + dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing] + In file included from ../../../StarLibs/Camelot/ScBitTrue/AlteraDspBuilderFFT/csl/steps.h:4:0, + from ../../../StarLibs/Camelot/ScBitTrue/AlteraDspBuilderFFT/csl/csl.h:4, + from vfft_fft_core_VFFT1_CModel.h:2, + from vfft_fft_core_VFFT1_CModel.cpp:2:""") .hasFileName( "/data/hudsonuser/workspace/Regression_test_SystemC_gcc/StarLibs/Camelot/ScBitTrue/AlteraDspBuilderFFT/csl/stimulus_file.h") .hasCategory("strict-aliasing") diff --git a/src/test/java/edu/hm/hafner/analysis/parser/Gcc4LinkerParserTest.java b/src/test/java/edu/hm/hafner/analysis/parser/Gcc4LinkerParserTest.java index 0a450e52a..d87da4a46 100644 --- a/src/test/java/edu/hm/hafner/analysis/parser/Gcc4LinkerParserTest.java +++ b/src/test/java/edu/hm/hafner/analysis/parser/Gcc4LinkerParserTest.java @@ -97,7 +97,7 @@ protected void assertThatIssuesArePresent(final Report report, final SoftAsserti /** Should not report warnings already detected by {@link Gcc4CompilerParser}. */ @Test void shouldNotReportGccWarnings() { - Report warnings = parse("gcc4.txt"); + var warnings = parse("gcc4.txt"); assertThat(warnings).hasSize(2); assertThatMessageHasUndefinedReference(warnings, 0); @@ -115,7 +115,7 @@ private void assertThatMessageHasUndefinedReference(final Report warnings, final */ @Test void issue5445() { - Report warnings = parse("issue5445.txt"); + var warnings = parse("issue5445.txt"); assertThat(warnings).isEmpty(); } @@ -127,7 +127,7 @@ void issue5445() { */ @Test void issue5870() { - Report warnings = parse("issue5870.txt"); + var warnings = parse("issue5870.txt"); assertThat(warnings).isEmpty(); } @@ -139,7 +139,7 @@ void issue5870() { */ @Test void issue6563() { - Report warnings = parse("issue6563.txt"); + var warnings = parse("issue6563.txt"); assertThat(warnings).isEmpty(); } diff --git a/src/test/java/edu/hm/hafner/analysis/parser/GccParserTest.java b/src/test/java/edu/hm/hafner/analysis/parser/GccParserTest.java index e2cc0f709..1ad16d7ab 100644 --- a/src/test/java/edu/hm/hafner/analysis/parser/GccParserTest.java +++ b/src/test/java/edu/hm/hafner/analysis/parser/GccParserTest.java @@ -33,7 +33,7 @@ protected GccParserTest() { */ @Test void issue34141() { - Report warnings = parse("issue34141.txt"); + var warnings = parse("issue34141.txt"); assertThat(warnings).isEmpty(); } @@ -45,11 +45,11 @@ void issue34141() { */ @Test void issue17309() { - Report warnings = parse("issue17309.txt"); + var warnings = parse("issue17309.txt"); assertThat(warnings).hasSize(1); - try (SoftAssertions softly = new SoftAssertions()) { + try (var softly = new SoftAssertions()) { softly.assertThat(warnings.get(0)) .hasLineStart(4) .hasLineEnd(4) @@ -67,11 +67,11 @@ void issue17309() { */ @Test void issue9926() { - Report warnings = parse("issue9926.txt"); + var warnings = parse("issue9926.txt"); assertThat(warnings).hasSize(1); - try (SoftAssertions softly = new SoftAssertions()) { + try (var softly = new SoftAssertions()) { softly.assertThat(warnings.get(0)) .hasLineStart(52) .hasLineEnd(52) @@ -161,13 +161,13 @@ protected void assertThatIssuesArePresent(final Report report, final SoftAsserti */ @Test void issue3897and3898() { - Report warnings = parse("issue3897.txt"); + var warnings = parse("issue3897.txt"); assertThat(warnings).hasSize(3); Iterator iterator = warnings.iterator(); - try (SoftAssertions softly = new SoftAssertions()) { + try (var softly = new SoftAssertions()) { softly.assertThat(iterator.next()) .hasLineStart(12) .hasLineEnd(12) @@ -201,13 +201,13 @@ void issue3897and3898() { */ @Test void issue4712() { - Report warnings = parse("issue4712.txt"); + var warnings = parse("issue4712.txt"); assertThat(warnings).hasSize(2); Iterator iterator = warnings.iterator(); - try (SoftAssertions softly = new SoftAssertions()) { + try (var softly = new SoftAssertions()) { softly.assertThat(iterator.next()) .hasLineStart(352) .hasLineEnd(352) @@ -233,7 +233,7 @@ void issue4712() { */ @Test void issue4700() { - Report warnings = parse("issue4700.txt"); + var warnings = parse("issue4700.txt"); assertThat(warnings).isEmpty(); } @@ -245,11 +245,11 @@ void issue4700() { */ @Test void issue4707() { - Report warnings = parse("issue4707.txt"); + var warnings = parse("issue4707.txt"); assertThat(warnings).hasSize(11).hasDuplicatesSize(11); - try (SoftAssertions softly = new SoftAssertions()) { + try (var softly = new SoftAssertions()) { softly.assertThat(warnings.get(0)) .hasLineStart(1128) .hasLineEnd(1128) @@ -268,11 +268,11 @@ void issue4707() { */ @Test void issue4010() { - Report warnings = parse("issue4010.txt"); + var warnings = parse("issue4010.txt"); assertThat(warnings).hasSize(1); - try (SoftAssertions softly = new SoftAssertions()) { + try (var softly = new SoftAssertions()) { softly.assertThat(warnings.get(0)) .hasLineStart(0) .hasLineEnd(0) @@ -290,13 +290,13 @@ void issue4010() { */ @Test void issue4274() { - Report warnings = parse("issue4274.txt"); + var warnings = parse("issue4274.txt"); assertThat(warnings).hasSize(4); Iterator iterator = warnings.iterator(); - try (SoftAssertions softly = new SoftAssertions()) { + try (var softly = new SoftAssertions()) { softly.assertThat(iterator.next()) .hasLineStart(638) .hasLineEnd(638) @@ -338,14 +338,14 @@ void issue4274() { */ @Test void issue4260() { - Report warnings = parse("issue4260.txt"); + var warnings = parse("issue4260.txt"); assertThat(warnings).hasSize(1); } @Test @org.junitpioneer.jupiter.Issue("JENKINS-70996") void ignoreDirectoriesFromOtherTools() { - Report warnings = parse("issue70996.txt"); + var warnings = parse("issue70996.txt"); assertThat(warnings).hasSize(8); } diff --git a/src/test/java/edu/hm/hafner/analysis/parser/GhsMultiParserTest.java b/src/test/java/edu/hm/hafner/analysis/parser/GhsMultiParserTest.java index 60db2d7d4..7d1470c2e 100644 --- a/src/test/java/edu/hm/hafner/analysis/parser/GhsMultiParserTest.java +++ b/src/test/java/edu/hm/hafner/analysis/parser/GhsMultiParserTest.java @@ -78,23 +78,25 @@ protected void assertThatIssuesArePresent(final Report report, final SoftAsserti */ @Test void issue59118() { - Report warnings = parse("issue59118.txt"); + var warnings = parse("issue59118.txt"); assertThat(warnings).hasSize(2); assertThat(warnings.get(0)) .hasLineStart(19) - .hasMessage("[2019-08-28T08:44:26.749Z] operands of logical && or || must be primary expressions\n" - + "\n" - + "[2019-08-28T08:44:26.749Z] #if !defined(_STDARG_H) && !defined(_STDIO_H) && !defined(_GHS_WCHAR_H)") + .hasMessage(""" + [2019-08-28T08:44:26.749Z] operands of logical && or || must be primary expressions + + [2019-08-28T08:44:26.749Z] #if !defined(_STDARG_H) && !defined(_STDIO_H) && !defined(_GHS_WCHAR_H)""") .hasFileName("C:/Path/To/bar.h") .hasCategory("#1729-D") .hasSeverity(Severity.WARNING_NORMAL); assertThat(warnings.get(1)) .hasLineStart(491) - .hasMessage("[2019-08-28T08:44:28.122Z] operands of logical && or || must be primary expressions\n" - + "\n" - + "[2019-08-28T08:44:28.122Z] if(t_deltaInterval != t_u4Interval && t_deltaInterval != 0)") + .hasMessage(""" + [2019-08-28T08:44:28.122Z] operands of logical && or || must be primary expressions + + [2019-08-28T08:44:28.122Z] if(t_deltaInterval != t_u4Interval && t_deltaInterval != 0)""") .hasFileName("../../../../Sources/Foo/Bar/Test.c") .hasCategory("#1729-D") .hasSeverity(Severity.WARNING_NORMAL); @@ -102,7 +104,7 @@ void issue59118() { @Test void issue66130() { - Report warnings = parse("issue66130.log"); + var warnings = parse("issue66130.log"); assertThat(warnings).hasSize(2); assertThat(warnings.get(0)).hasMessage("extra \";\" ignored\nSome Description") diff --git a/src/test/java/edu/hm/hafner/analysis/parser/GnuFortranParserTest.java b/src/test/java/edu/hm/hafner/analysis/parser/GnuFortranParserTest.java index 77352d786..d60c5f07a 100644 --- a/src/test/java/edu/hm/hafner/analysis/parser/GnuFortranParserTest.java +++ b/src/test/java/edu/hm/hafner/analysis/parser/GnuFortranParserTest.java @@ -70,11 +70,11 @@ protected void assertThatIssuesArePresent(final Report report, final SoftAsserti */ @Test void testWarningParser() { - Report warnings = parse("GnuFortranWarning.txt"); + var warnings = parse("GnuFortranWarning.txt"); assertThat(warnings).hasSize(1); - try (SoftAssertions softly = new SoftAssertions()) { + try (var softly = new SoftAssertions()) { softly.assertThat(warnings.get(0)) .hasSeverity(Severity.WARNING_NORMAL) .hasCategory("Warning") @@ -90,11 +90,11 @@ void testWarningParser() { */ @Test void testErrorParser() { - Report warnings = parse("GnuFortranError.txt"); + var warnings = parse("GnuFortranError.txt"); assertThat(warnings).hasSize(1); - try (SoftAssertions softly = new SoftAssertions()) { + try (var softly = new SoftAssertions()) { softly.assertThat(warnings.get(0)) .hasSeverity(Severity.ERROR) .hasCategory("Error") @@ -112,11 +112,11 @@ void testErrorParser() { */ @Test void testFatalErrorParser() { - Report warnings = parse("GnuFortranFatalError.txt"); + var warnings = parse("GnuFortranFatalError.txt"); assertThat(warnings).hasSize(1); - try (SoftAssertions softly = new SoftAssertions()) { + try (var softly = new SoftAssertions()) { softly.assertThat(warnings.get(0)) .hasSeverity(Severity.ERROR) .hasCategory("Fatal Error") @@ -133,11 +133,11 @@ void testFatalErrorParser() { */ @Test void testInternalErrorParser() { - Report warnings = parse("GnuFortranInternalError.txt"); + var warnings = parse("GnuFortranInternalError.txt"); assertThat(warnings).hasSize(1); - try (SoftAssertions softly = new SoftAssertions()) { + try (var softly = new SoftAssertions()) { softly.assertThat(warnings.get(0)) .hasSeverity(Severity.ERROR) .hasCategory("Internal Error") @@ -154,7 +154,7 @@ void testInternalErrorParser() { */ @Test void testInvalidParser() { - Report warnings = parse("GnuFortranInvalid.txt"); + var warnings = parse("GnuFortranInvalid.txt"); assertThat(warnings).hasSize(0); } diff --git a/src/test/java/edu/hm/hafner/analysis/parser/GradleErrorProneParserTest.java b/src/test/java/edu/hm/hafner/analysis/parser/GradleErrorProneParserTest.java index 0462ca929..652018fe1 100644 --- a/src/test/java/edu/hm/hafner/analysis/parser/GradleErrorProneParserTest.java +++ b/src/test/java/edu/hm/hafner/analysis/parser/GradleErrorProneParserTest.java @@ -33,7 +33,7 @@ protected void assertThatIssuesArePresent(final Report report, final SoftAsserti @Test void shouldParseGradleLogWithWindowsDrive() { - Report report = parse("issue55846.log"); + var report = parse("issue55846.log"); assertThat(report).hasSize(2); assertThat(report.get(0)) diff --git a/src/test/java/edu/hm/hafner/analysis/parser/HadoLintParserTest.java b/src/test/java/edu/hm/hafner/analysis/parser/HadoLintParserTest.java index bbd1940a4..198ac0e58 100644 --- a/src/test/java/edu/hm/hafner/analysis/parser/HadoLintParserTest.java +++ b/src/test/java/edu/hm/hafner/analysis/parser/HadoLintParserTest.java @@ -55,7 +55,7 @@ void accepts() { @Test void unusualInput() { - Report report = parse("hadolint-unsual.json"); + var report = parse("hadolint-unsual.json"); assertThat(report).hasSize(4); assertThat(report.get(1)) .hasSeverity(Severity.ERROR); diff --git a/src/test/java/edu/hm/hafner/analysis/parser/IarParserTest.java b/src/test/java/edu/hm/hafner/analysis/parser/IarParserTest.java index a77d09131..3b3e8f64f 100644 --- a/src/test/java/edu/hm/hafner/analysis/parser/IarParserTest.java +++ b/src/test/java/edu/hm/hafner/analysis/parser/IarParserTest.java @@ -87,10 +87,10 @@ protected void assertThatIssuesArePresent(final Report report, final SoftAsserti */ @Test void issue58159Utf8() { - Report warnings = createParser().parse( + var warnings = createParser().parse( new FileReaderFactory(getResourceAsFile("issue58159-2.txt"))); - String collect = warnings.stream().map(Objects::toString).collect(Collectors.joining("\n")); + var collect = warnings.stream().map(Objects::toString).collect(Collectors.joining("\n")); assertThat(warnings).as(collect).hasDuplicatesSize(4).hasSize(61); } @@ -101,10 +101,10 @@ void issue58159Utf8() { */ @Test void issue55750() { - Report warnings = parse("issue55750.txt"); + var warnings = parse("issue55750.txt"); assertThat(warnings).hasSize(4); - try (SoftAssertions softly = new SoftAssertions()) { + try (var softly = new SoftAssertions()) { softly.assertThat(warnings.get(0)) .hasSeverity(Severity.WARNING_NORMAL) .hasCategory("Pe852") diff --git a/src/test/java/edu/hm/hafner/analysis/parser/IdeaInspectionParserTest.java b/src/test/java/edu/hm/hafner/analysis/parser/IdeaInspectionParserTest.java index 7cf0f1434..a10ea6763 100644 --- a/src/test/java/edu/hm/hafner/analysis/parser/IdeaInspectionParserTest.java +++ b/src/test/java/edu/hm/hafner/analysis/parser/IdeaInspectionParserTest.java @@ -49,12 +49,12 @@ protected void assertThatIssuesArePresent(final Report report, final SoftAsserti */ @Test void issue56235() { - Report warnings = parse("issue56235.xml"); + var warnings = parse("issue56235.xml"); assertThat(warnings).hasSize(7); Iterator iterator = warnings.iterator(); - try (SoftAssertions softly = new SoftAssertions()) { + try (var softly = new SoftAssertions()) { softly.assertThat(iterator.next()) .hasSeverity(Severity.WARNING_NORMAL) .hasCategory("Optional.isPresent() can be replaced with functional-style expression") diff --git a/src/test/java/edu/hm/hafner/analysis/parser/IntelParserTest.java b/src/test/java/edu/hm/hafner/analysis/parser/IntelParserTest.java index eec6edd45..6ddac9292 100644 --- a/src/test/java/edu/hm/hafner/analysis/parser/IntelParserTest.java +++ b/src/test/java/edu/hm/hafner/analysis/parser/IntelParserTest.java @@ -109,11 +109,11 @@ protected void assertThatIssuesArePresent(final Report report, final SoftAsserti */ @Test void issue5402() { - Report warnings = parse("issue5402.txt"); + var warnings = parse("issue5402.txt"); assertThat(warnings).hasSize(4); - try (SoftAssertions softly = new SoftAssertions()) { + try (var softly = new SoftAssertions()) { softly.assertThat(warnings.get(0)) .hasSeverity(Severity.WARNING_NORMAL) .hasCategory("Warning #177") diff --git a/src/test/java/edu/hm/hafner/analysis/parser/InvalidsParserTest.java b/src/test/java/edu/hm/hafner/analysis/parser/InvalidsParserTest.java index 8a34dcff1..86a3608f3 100644 --- a/src/test/java/edu/hm/hafner/analysis/parser/InvalidsParserTest.java +++ b/src/test/java/edu/hm/hafner/analysis/parser/InvalidsParserTest.java @@ -24,7 +24,7 @@ protected InvalidsParser createParser() { protected void assertThatIssuesArePresent(final Report report, final SoftAssertions softly) { assertThat(report).hasSize(3); - String type = "Oracle Invalid"; + var type = "Oracle Invalid"; softly.assertThat(report.get(0)) .hasSeverity(Severity.WARNING_NORMAL) .hasCategory("PLW-05004") diff --git a/src/test/java/edu/hm/hafner/analysis/parser/JSLintParserTest.java b/src/test/java/edu/hm/hafner/analysis/parser/JSLintParserTest.java index fc58ba571..4ebd1cf56 100644 --- a/src/test/java/edu/hm/hafner/analysis/parser/JSLintParserTest.java +++ b/src/test/java/edu/hm/hafner/analysis/parser/JSLintParserTest.java @@ -28,11 +28,11 @@ class JSLintParserTest extends AbstractParserTest { */ @Test void issue19127() { - Report warnings = parse("jslint/jslint.xml"); + var warnings = parse("jslint/jslint.xml"); assertThat(warnings).hasSize(197); - try (SoftAssertions softly = new SoftAssertions()) { + try (var softly = new SoftAssertions()) { softly.assertThat(warnings.get(0)) .hasSeverity(Severity.WARNING_HIGH) .hasCategory(LintParser.JSLintXmlSaxParser.CATEGORY_UNDEFINED_VARIABLE) @@ -49,7 +49,7 @@ void issue19127() { */ @Test void testParseWithSingleFile() { - Report results = parse("jslint/single.xml"); + var results = parse("jslint/single.xml"); assertThat(results).hasSize(51); } @@ -59,7 +59,7 @@ void testParseWithSingleFile() { */ @Test void testCssLint() { - Report results = parse("jslint/csslint.xml"); + var results = parse("jslint/csslint.xml"); assertThat(results).hasSize(51); } diff --git a/src/test/java/edu/hm/hafner/analysis/parser/JavaDocParserTest.java b/src/test/java/edu/hm/hafner/analysis/parser/JavaDocParserTest.java index a6995781c..fb8c1fcdb 100644 --- a/src/test/java/edu/hm/hafner/analysis/parser/JavaDocParserTest.java +++ b/src/test/java/edu/hm/hafner/analysis/parser/JavaDocParserTest.java @@ -45,14 +45,14 @@ protected JavaDocParser createParser() { @Test void issue67521IgnoreJavaDocWarnings() { - Report warnings = parse("javadoc-in-java.log"); + var warnings = parse("javadoc-in-java.log"); assertThat(warnings).hasSize(12); } @Test void issue70658RemovePrefixAndSuffixFromMavenPlugins() { - Report warnings = parse("maven.3.9.1.log"); + var warnings = parse("maven.3.9.1.log"); assertThat(warnings).hasSize(1); assertThat(warnings.get(0)) @@ -67,7 +67,7 @@ void issue70658RemovePrefixAndSuffixFromMavenPlugins() { */ @Test void shouldHaveCategory() { - Report warnings = parse("javadoc-category.txt"); + var warnings = parse("javadoc-category.txt"); assertThat(warnings).hasSize(4); assertThat(warnings.filter(Issue.byCategory("JavaDoc @return"))).hasSize(4); @@ -78,7 +78,7 @@ void shouldHaveCategory() { */ @Test void falseJavaDocPositives() { - Report warnings = parse("all.txt"); + var warnings = parse("all.txt"); assertThat(warnings).hasSize(8); } @@ -90,10 +90,10 @@ void falseJavaDocPositives() { */ @Test void issue37975() { - Report warnings = parse("issue37975.txt"); + var warnings = parse("issue37975.txt"); assertThat(warnings).hasSize(3); - try (SoftAssertions softly = new SoftAssertions()) { + try (var softly = new SoftAssertions()) { softly.assertThat(warnings.get(0)) .hasSeverity(Severity.ERROR) .hasLineStart(79) @@ -124,10 +124,10 @@ void issue37975() { */ @Test void issue32298() { - Report warnings = parse("issue32298.txt"); + var warnings = parse("issue32298.txt"); assertThat(warnings).hasSize(7); - try (SoftAssertions softly = new SoftAssertions()) { + try (var softly = new SoftAssertions()) { softly.assertThat(warnings.get(0)) .hasSeverity(Severity.WARNING_NORMAL) .hasCategory(JAVA_DOC_PARAM) @@ -190,11 +190,11 @@ void issue32298() { */ @Test void issue4576() { - Report warnings = parse("issue4576.txt"); + var warnings = parse("issue4576.txt"); assertThat(warnings).hasSize(2); - try (SoftAssertions softly = new SoftAssertions()) { + try (var softly = new SoftAssertions()) { softly.assertThat(warnings.get(0)) .hasSeverity(Severity.WARNING_NORMAL) .hasLineStart(0) @@ -219,7 +219,7 @@ void issue4576() { */ @Test void issue8630() { - Report warnings = parse("issue8630.txt"); + var warnings = parse("issue8630.txt"); assertThat(warnings).isEmpty(); } @@ -231,11 +231,11 @@ void issue8630() { */ @Test void issue7718() { - Report warnings = parse("issue7718.txt"); + var warnings = parse("issue7718.txt"); assertThat(warnings).hasSize(7); Iterator iterator = warnings.iterator(); - try (SoftAssertions softly = new SoftAssertions()) { + try (var softly = new SoftAssertions()) { softly.assertThat(iterator.next()) .hasSeverity(Severity.WARNING_NORMAL) .hasCategory("JavaDoc @sys") @@ -301,7 +301,7 @@ void issue7718() { */ @Test void issue54506() { - Report warnings = parse("issue54506.txt"); + var warnings = parse("issue54506.txt"); assertThat(warnings).isEmpty(); } @@ -318,7 +318,7 @@ void issue55805() { @Test void shouldParseJavaDocsWarningsWithMavenSourcePlugin() { - Report warnings = parse("issue63346.log"); + var warnings = parse("issue63346.log"); assertThat(warnings).hasSize(3); assertThat(warnings.get(0)).hasSeverity(Severity.WARNING_NORMAL) diff --git a/src/test/java/edu/hm/hafner/analysis/parser/JavacParserTest.java b/src/test/java/edu/hm/hafner/analysis/parser/JavacParserTest.java index 08ede7d60..67e62f257 100644 --- a/src/test/java/edu/hm/hafner/analysis/parser/JavacParserTest.java +++ b/src/test/java/edu/hm/hafner/analysis/parser/JavacParserTest.java @@ -30,21 +30,21 @@ protected JavacParser createParser() { @Test void issue70658RemovePrefixAndSuffixFromMavenPlugins() { - Report warnings = parse("maven.3.9.1.log"); + var warnings = parse("maven.3.9.1.log"); assertThat(warnings).hasSize(1); } @Test @org.junitpioneer.jupiter.Issue("JENKINS-72077") void issue72077IgnoreTestWarnings() { - Report warnings = parse("issue72077.txt"); + var warnings = parse("issue72077.txt"); assertThat(warnings).isEmpty(); } @Test void issue67521IgnoreJavaDocWarnings() { - Report warnings = parse("javadoc-in-java.log"); + var warnings = parse("javadoc-in-java.log"); assertThat(warnings).isEmpty(); } @@ -70,7 +70,7 @@ protected void assertThatIssuesArePresent(final Report report, final SoftAsserti */ @Test void issue63346() { - Report report = parse("issue63346.txt"); + var report = parse("issue63346.txt"); assertThat(report).isEmpty(); } @@ -82,10 +82,10 @@ void issue63346() { */ @Test void issue66738() { - Report report = parse("issue66738.txt"); + var report = parse("issue66738.txt"); assertThat(report).hasSize(2); - try (SoftAssertions softly = new SoftAssertions()) { + try (var softly = new SoftAssertions()) { softly.assertThat(report.get(1)) .hasSeverity(Severity.WARNING_NORMAL) .hasCategory("") @@ -115,7 +115,7 @@ void issue55805() { */ @Test void shouldParseAnsiColorCodedLog() { - Report report = parse("maven-ansi.txt"); + var report = parse("maven-ansi.txt"); assertThat(report).hasSize(4); } @@ -125,7 +125,7 @@ void shouldParseAnsiColorCodedLog() { */ @Test void shouldParseErrors() { - Report warnings = parse("javac-errors.txt"); + var warnings = parse("javac-errors.txt"); assertThat(warnings).hasSize(4); assertThat(warnings.get(0)).hasSeverity(Severity.ERROR); @@ -138,7 +138,7 @@ void shouldParseErrors() { */ @Test void shouldParseTimestamps() { - Report warnings = parse("javac-timestamps.txt"); + var warnings = parse("javac-timestamps.txt"); assertThat(warnings).hasSize(5); assertThat(warnings.get(0)).hasMessage("Test1"); @@ -155,7 +155,7 @@ void shouldParseTimestamps() { */ @Test void issue14043() { - Report warnings = parse("issue14043.txt"); + var warnings = parse("issue14043.txt"); assertThat(warnings).isEmpty(); } @@ -163,7 +163,7 @@ void issue14043() { /** Verifies that the Kotlin maven plugin warnings are correctly parsed. */ @Test void kotlinMavenPlugin() { - Report warnings = parse("kotlin-maven-plugin.txt"); + var warnings = parse("kotlin-maven-plugin.txt"); assertThat(warnings).hasSize(4); } @@ -173,7 +173,7 @@ void kotlinMavenPlugin() { */ @Test void kotlinGradle() { - Report warnings = parse("kotlin-gradle.txt"); + var warnings = parse("kotlin-gradle.txt"); assertThat(warnings).hasSize(4); } @@ -183,7 +183,7 @@ void kotlinGradle() { */ @Test void kotlinGradleError() { - Report errors = parse("kotlin-gradle-error.txt"); + var errors = parse("kotlin-gradle-error.txt"); assertThat(errors).hasSize(1); } @@ -193,11 +193,11 @@ void kotlinGradleError() { */ @Test void parseArrayInDeprecatedMethod() { - Report warnings = parse("issue5868.txt"); + var warnings = parse("issue5868.txt"); assertThat(warnings).hasSize(1); - try (SoftAssertions softly = new SoftAssertions()) { + try (var softly = new SoftAssertions()) { softly.assertThat(warnings.get(0)) .hasSeverity(Severity.WARNING_NORMAL) .hasCategory("Deprecation") @@ -213,11 +213,11 @@ void parseArrayInDeprecatedMethod() { */ @Test void parseParallelPipelineOutput() { - Report warnings = parse("javac-parallel-pipeline.txt"); + var warnings = parse("javac-parallel-pipeline.txt"); assertThat(warnings).hasSize(2); - try (SoftAssertions softly = new SoftAssertions()) { + try (var softly = new SoftAssertions()) { softly.assertThat(warnings.get(0)) .hasSeverity(Severity.WARNING_NORMAL) .hasCategory(Categories.DEPRECATION) @@ -240,7 +240,7 @@ void parseParallelPipelineOutput() { */ @Test void parseMaven() { - Report warnings = parse("maven.txt"); + var warnings = parse("maven.txt"); assertThat(warnings).hasSize(5); @@ -254,7 +254,7 @@ void parseMaven() { @Test void shouldNotIncludeErrorprone() { - Report warnings = parse("javac-errorprone.txt"); + var warnings = parse("javac-errorprone.txt"); assertThat(warnings).hasSize(2); assertThat(warnings.get(0)).hasSeverity(Severity.ERROR); @@ -274,7 +274,7 @@ void shouldNotIncludeErrorprone() { * the line number of the warning */ private void assertThatWarningIsAtLine(final Issue annotation, final int lineNumber) { - try (SoftAssertions softly = new SoftAssertions()) { + try (var softly = new SoftAssertions()) { softly.assertThat(annotation) .hasSeverity(Severity.WARNING_NORMAL) .hasCategory(Categories.PROPRIETARY_API) @@ -287,7 +287,7 @@ private void assertThatWarningIsAtLine(final Issue annotation, final int lineNum @Test void shouldParseJavaWarningsInMavenCompilerPlugin() { - Report warnings = parse("issue63346.log"); + var warnings = parse("issue63346.log"); assertThat(warnings).hasSize(4); assertThat(warnings.get(0)).hasSeverity(Severity.WARNING_NORMAL) @@ -313,7 +313,7 @@ void shouldParseJavaWarningsInMavenCompilerPlugin() { */ @Test void kotlin18WarningStyle() { - Report warnings = parse("kotlin-1_8.txt"); + var warnings = parse("kotlin-1_8.txt"); assertThat(warnings).hasSize(7); @@ -356,7 +356,7 @@ void kotlin18WarningStyle() { */ @Test void kotlinAndCmakeDirectoryOutput() { - Report warnings = parse("kotlin-cmake.txt"); + var warnings = parse("kotlin-cmake.txt"); assertThat(warnings).hasSize(5); diff --git a/src/test/java/edu/hm/hafner/analysis/parser/JcReportParserTest.java b/src/test/java/edu/hm/hafner/analysis/parser/JcReportParserTest.java index aa4ab5735..5c7f0ae08 100644 --- a/src/test/java/edu/hm/hafner/analysis/parser/JcReportParserTest.java +++ b/src/test/java/edu/hm/hafner/analysis/parser/JcReportParserTest.java @@ -31,7 +31,7 @@ class JcReportParserTest extends AbstractParserTest { */ @Test void testGetWarningList() { - Report warnings = parseDefaultFile(); + var warnings = parseDefaultFile(); assertThat(warnings).hasSize(6).hasDuplicatesSize(1); } @@ -44,12 +44,12 @@ void testGetWarningList() { */ @Test void testReportParserProperties() { - ReaderFactory factory = createReaderFactory("jcreport/testReportProps.xml"); - edu.hm.hafner.analysis.parser.jcreport.Report testReportProps = new JcReportParser().createReport(factory); + var factory = createReaderFactory("jcreport/testReportProps.xml"); + var testReportProps = new JcReportParser().createReport(factory); assertThat(testReportProps.getFiles()).hasSize(1); - File file = testReportProps.getFiles().get(0); + var file = testReportProps.getFiles().get(0); assertThat(file.getClassname()).isEqualTo("SomeClass"); assertThat(file.getLevel()).isEqualTo("SomeLevel"); assertThat(file.getLoc()).isEqualTo("173"); @@ -57,7 +57,7 @@ void testReportParserProperties() { assertThat(file.getPackageName()).isEqualTo("SomePackage"); assertThat(file.getSrcdir()).isEqualTo("SomeDirectory"); - Item item = file.getItems().get(0); + var item = file.getItems().get(0); assertThat(item.getColumn()).isEqualTo("0"); assertThat(item.getEndcolumn()).isEqualTo("3"); assertThat(item.getFindingtype()).isEqualTo("SomeType"); diff --git a/src/test/java/edu/hm/hafner/analysis/parser/JsonLogParserTest.java b/src/test/java/edu/hm/hafner/analysis/parser/JsonLogParserTest.java index f59eb4a09..62192af86 100644 --- a/src/test/java/edu/hm/hafner/analysis/parser/JsonLogParserTest.java +++ b/src/test/java/edu/hm/hafner/analysis/parser/JsonLogParserTest.java @@ -82,7 +82,7 @@ void shouldNotAcceptXmlAndJsonFiles() { @Test void shouldReportDuplicateKey() { - Report report = parse("json-issues-duplicate.log"); + var report = parse("json-issues-duplicate.log"); assertThat(report).hasSize(0); assertThat(report.getErrorMessages()).contains( "Could not parse line: «{\"fileName\":\"invalid1.xml\",\"fileName\":\"invalid2.xml\"}»"); @@ -90,7 +90,7 @@ void shouldReportDuplicateKey() { @Test void shouldReportLineBreak() { - Report report = parse("json-issues-lineBreak.log"); + var report = parse("json-issues-lineBreak.log"); assertThat(report).hasSize(0); assertThat(report.getErrorMessages()).contains( "Could not parse line: «\"description\":\"an \\\"important\\\" description\"}»"); @@ -98,8 +98,8 @@ void shouldReportLineBreak() { @Test void emptyReport() { - JsonLogParser parser = createParser(); - Report report = parser.parse(createReaderFactory("json-issues-empty.txt")); + var parser = createParser(); + var report = parser.parse(createReaderFactory("json-issues-empty.txt")); assertThat(report).hasSize(0); } diff --git a/src/test/java/edu/hm/hafner/analysis/parser/MavenConsoleParserTest.java b/src/test/java/edu/hm/hafner/analysis/parser/MavenConsoleParserTest.java index ada2b57b0..e603f9e89 100644 --- a/src/test/java/edu/hm/hafner/analysis/parser/MavenConsoleParserTest.java +++ b/src/test/java/edu/hm/hafner/analysis/parser/MavenConsoleParserTest.java @@ -36,14 +36,14 @@ void issue72011MavenEnforcerExceptionWhenEmpty() { @Test void issue70658RemovePrefixAndSuffixFromMavenPlugins() { - Report warnings = parse("maven.3.9.1.log"); + var warnings = parse("maven.3.9.1.log"); assertThat(warnings).hasSize(2); } @Test void shouldAssignTypesFromGoals() { - Report warnings = parse("maven-goals.log"); + var warnings = parse("maven-goals.log"); assertThat(warnings).hasSize(3); @@ -72,7 +72,7 @@ void shouldAssignTypesFromGoals() { */ @Test void issue64284() { - Report warnings = parse("issue64284.log"); + var warnings = parse("issue64284.log"); assertThat(warnings).hasSize(3); } @@ -83,7 +83,7 @@ private void assertThatDescriptionIs(final Report warnings, final int index, fin @Test void shouldLocateCorrectLineNumber() { - Report warnings = parse("maven-line-number.log"); + var warnings = parse("maven-line-number.log"); assertThat(warnings).hasSize(1); assertThat(warnings.get(0)).hasSeverity(Severity.WARNING_NORMAL) @@ -102,94 +102,97 @@ void shouldLocateCorrectLineNumber() { */ @Test void issue16826() { - Report warnings = parse("issue16826.txt"); + var warnings = parse("issue16826.txt"); assertThat(warnings).hasSize(1); } @Test void shouldDetectEnforcerMessages() { - Report warnings = parse("maven-enforcer.log"); + var warnings = parse("maven-enforcer.log"); assertThat(warnings).hasSize(1); assertThat(warnings.get(0)) .hasDescription( - "
Rule 4: org.apache.maven.plugins.enforcer.RequireUpperBoundDeps failed with message:\n"
-                                + "Failed while enforcing RequireUpperBoundDeps. The error(s) are [\n"
-                                + "Require upper bound dependencies error for org.jenkins-ci:annotation-indexer:1.11 paths to dependency are:\n"
-                                + "+-io.jenkins.plugins:warnings-ng:2.2.0-SNAPSHOT\n"
-                                + "  +-org.jenkins-ci.plugins:git:3.9.1\n"
-                                + "    +-org.jenkins-ci:annotation-indexer:1.11\n"
-                                + "and\n"
-                                + "+-io.jenkins.plugins:warnings-ng:2.2.0-SNAPSHOT\n"
-                                + "  +-org.jenkins-ci.main:jenkins-core:2.89.1\n"
-                                + "    +-org.jenkins-ci:annotation-indexer:1.12\n"
-                                + "and\n"
-                                + "+-io.jenkins.plugins:warnings-ng:2.2.0-SNAPSHOT\n"
-                                + "  +-org.kohsuke:access-modifier-annotation:1.15\n"
-                                + "    +-org.jenkins-ci:annotation-indexer:1.4\n"
-                                + "and\n"
-                                + "+-io.jenkins.plugins:warnings-ng:2.2.0-SNAPSHOT\n"
-                                + "  +-org.jenkins-ci.plugins:git:3.9.1\n"
-                                + "    +-com.infradna.tool:bridge-method-annotation:1.17\n"
-                                + "      +-org.jenkins-ci:annotation-indexer:1.4\n"
-                                + "and\n"
-                                + "+-io.jenkins.plugins:warnings-ng:2.2.0-SNAPSHOT\n"
-                                + "  +-org.jenkins-ci.main:jenkins-core:2.89.1\n"
-                                + "    +-org.jenkins-ci:bytecode-compatibility-transformer:1.8\n"
-                                + "      +-org.jenkins-ci:annotation-indexer:1.4\n"
-                                + ",\n"
-                                + "Require upper bound dependencies error for commons-net:commons-net:3.5 paths to dependency are:\n"
-                                + "+-io.jenkins.plugins:warnings-ng:2.2.0-SNAPSHOT\n"
-                                + "  +-org.jenkins-ci.main:maven-plugin:3.1.2\n"
-                                + "    +-org.apache.maven.wagon:wagon-ftp:3.0.0\n"
-                                + "      +-commons-net:commons-net:3.5\n"
-                                + "and\n"
-                                + "+-io.jenkins.plugins:warnings-ng:2.2.0-SNAPSHOT\n"
-                                + "  +-org.jenkins-ci.main:jenkins-test-harness:2.42\n"
-                                + "    +-org.jenkins-ci.main:jenkins-test-harness-htmlunit:2.31-1\n"
-                                + "      +-commons-net:commons-net:3.6\n"
-                                + "]
"); + """ +
Rule 4: org.apache.maven.plugins.enforcer.RequireUpperBoundDeps failed with message:
+                        Failed while enforcing RequireUpperBoundDeps. The error(s) are [
+                        Require upper bound dependencies error for org.jenkins-ci:annotation-indexer:1.11 paths to dependency are:
+                        +-io.jenkins.plugins:warnings-ng:2.2.0-SNAPSHOT
+                          +-org.jenkins-ci.plugins:git:3.9.1
+                            +-org.jenkins-ci:annotation-indexer:1.11
+                        and
+                        +-io.jenkins.plugins:warnings-ng:2.2.0-SNAPSHOT
+                          +-org.jenkins-ci.main:jenkins-core:2.89.1
+                            +-org.jenkins-ci:annotation-indexer:1.12
+                        and
+                        +-io.jenkins.plugins:warnings-ng:2.2.0-SNAPSHOT
+                          +-org.kohsuke:access-modifier-annotation:1.15
+                            +-org.jenkins-ci:annotation-indexer:1.4
+                        and
+                        +-io.jenkins.plugins:warnings-ng:2.2.0-SNAPSHOT
+                          +-org.jenkins-ci.plugins:git:3.9.1
+                            +-com.infradna.tool:bridge-method-annotation:1.17
+                              +-org.jenkins-ci:annotation-indexer:1.4
+                        and
+                        +-io.jenkins.plugins:warnings-ng:2.2.0-SNAPSHOT
+                          +-org.jenkins-ci.main:jenkins-core:2.89.1
+                            +-org.jenkins-ci:bytecode-compatibility-transformer:1.8
+                              +-org.jenkins-ci:annotation-indexer:1.4
+                        ,
+                        Require upper bound dependencies error for commons-net:commons-net:3.5 paths to dependency are:
+                        +-io.jenkins.plugins:warnings-ng:2.2.0-SNAPSHOT
+                          +-org.jenkins-ci.main:maven-plugin:3.1.2
+                            +-org.apache.maven.wagon:wagon-ftp:3.0.0
+                              +-commons-net:commons-net:3.5
+                        and
+                        +-io.jenkins.plugins:warnings-ng:2.2.0-SNAPSHOT
+                          +-org.jenkins-ci.main:jenkins-test-harness:2.42
+                            +-org.jenkins-ci.main:jenkins-test-harness-htmlunit:2.31-1
+                              +-commons-net:commons-net:3.6
+                        ]
"""); } @Test void shouldDetectEnforcerMessagesWithTimeStamp() { - Report warnings = parse("maven-enforcer2.log"); + var warnings = parse("maven-enforcer2.log"); assertThat(warnings).hasSize(2); assertThat(warnings.get(0)) - .hasDescription("
\n"
-                        + "Dependency convergence error for com.google.http-client:google-http-client-jackson2:1.22.0 paths to dependency are:\n"
-                        + "+-com.<org>:web:165.0-SNAPSHOT\n"
-                        + "  +-com.<org>:notestore:165.0-SNAPSHOT\n"
-                        + "    +-com.<org>.service:gcs-lib:2.1-SNAPSHOT\n"
-                        + "      +-com.google.cloud:google-cloud-storage:1.3.1\n"
-                        + "        +-com.google.cloud:google-cloud-core-http:1.3.1\n"
-                        + "          +-com.google.http-client:google-http-client-jackson2:1.22.0\n"
-                        + "and\n"
-                        + "+-com.<org>:web:165.0-SNAPSHOT\n"
-                        + "  +-com.<org>:notestore:165.0-SNAPSHOT\n"
-                        + "    +-com.google.cloud:google-cloud-spanner:0.21.1-beta\n"
-                        + "      +-com.google.api:gax-grpc:0.22.0\n"
-                        + "        +-com.google.auth:google-auth-library-oauth2-http:0.7.0\n"
-                        + "          +-com.google.http-client:google-http-client-jackson2:1.19.0\n"
-                        + "and\n"
-                        + "+-com.<org>:web:165.0-SNAPSHOT\n"
-                        + "  +-com.google.api-client:google-api-client:1.22.0\n"
-                        + "    +-com.google.http-client:google-http-client-jackson2:1.22.0\n"
-                        + "
"); + .hasDescription(""" +

+                        Dependency convergence error for com.google.http-client:google-http-client-jackson2:1.22.0 paths to dependency are:
+                        +-com.<org>:web:165.0-SNAPSHOT
+                          +-com.<org>:notestore:165.0-SNAPSHOT
+                            +-com.<org>.service:gcs-lib:2.1-SNAPSHOT
+                              +-com.google.cloud:google-cloud-storage:1.3.1
+                                +-com.google.cloud:google-cloud-core-http:1.3.1
+                                  +-com.google.http-client:google-http-client-jackson2:1.22.0
+                        and
+                        +-com.<org>:web:165.0-SNAPSHOT
+                          +-com.<org>:notestore:165.0-SNAPSHOT
+                            +-com.google.cloud:google-cloud-spanner:0.21.1-beta
+                              +-com.google.api:gax-grpc:0.22.0
+                                +-com.google.auth:google-auth-library-oauth2-http:0.7.0
+                                  +-com.google.http-client:google-http-client-jackson2:1.19.0
+                        and
+                        +-com.<org>:web:165.0-SNAPSHOT
+                          +-com.google.api-client:google-api-client:1.22.0
+                            +-com.google.http-client:google-http-client-jackson2:1.22.0
+                        
"""); assertThat(warnings.get(1)) - .hasDescription("
\n"
-                        + "Dependency convergence error for com.google.code.gson:gson:2.2.1 paths to dependency are:\n"
-                        + "+-com.<org>:web:165.0-SNAPSHOT\n"
-                        + "  +-com.<org>:notestore:165.0-SNAPSHOT\n"
-                        + "    +-com.<org>:telesign:1.1\n"
-                        + "      +-com.google.code.gson:gson:2.2.1
"); + .hasDescription(""" +

+                        Dependency convergence error for com.google.code.gson:gson:2.2.1 paths to dependency are:
+                        +-com.<org>:web:165.0-SNAPSHOT
+                          +-com.<org>:notestore:165.0-SNAPSHOT
+                            +-com.<org>:telesign:1.1
+                              +-com.google.code.gson:gson:2.2.1
"""); } @Test void shouldIdentifyMavenModules() { - Report warnings = parse("maven-multimodule.log"); + var warnings = parse("maven-multimodule.log"); assertThat(warnings).hasSize(2); assertThat(warnings.get(0)).hasModuleName("edu.hm.hafner:analysis-model"); diff --git a/src/test/java/edu/hm/hafner/analysis/parser/MsBuildParserTest.java b/src/test/java/edu/hm/hafner/analysis/parser/MsBuildParserTest.java index 1694a9f13..0cb2ea33f 100644 --- a/src/test/java/edu/hm/hafner/analysis/parser/MsBuildParserTest.java +++ b/src/test/java/edu/hm/hafner/analysis/parser/MsBuildParserTest.java @@ -27,14 +27,14 @@ class MsBuildParserTest extends AbstractParserTest { */ @Test void shouldRemoveAnsiColors() { - Report warnings = parse("MSBuildANSIColor.txt"); + var warnings = parse("MSBuildANSIColor.txt"); assertThat(warnings) .hasSize(1); assertThatReportHasSeverities(warnings, 0, 0, 1, 0); - try (SoftAssertions softly = new SoftAssertions()) { + try (var softly = new SoftAssertions()) { softly.assertThat(warnings.get(0)) .hasFileName("C:/j/6aa722/src/CodeRunner/GenericCodeRunner/CompositeCode.cs") .hasCategory("CS1591") @@ -66,7 +66,7 @@ void issue56613() { */ @Test void issue42823() { - Report warnings = parse("issue42823.txt"); + var warnings = parse("issue42823.txt"); assertThat(warnings).isEmpty(); } @@ -77,11 +77,11 @@ void issue42823() { */ @Test void issue56193() { - Report warnings = parse("issue56193.log"); + var warnings = parse("issue56193.log"); assertThat(warnings).hasSize(1); - try (SoftAssertions softly = new SoftAssertions()) { + try (var softly = new SoftAssertions()) { softly.assertThat(warnings.get(0)) .hasFileName("G:/Jenkins-Alserver-Slave/workspace/ninjamgs/Lesson1/bubble.cpp") .hasCategory("C4101") @@ -98,11 +98,11 @@ void issue56193() { */ @Test void issue56030() { - Report warnings = parse("issue56030.log"); + var warnings = parse("issue56030.log"); assertThat(warnings).hasSize(2); - try (SoftAssertions softly = new SoftAssertions()) { + try (var softly = new SoftAssertions()) { softly.assertThat(warnings.get(0)) .hasFileName( "C:/DVR/workspace/_Branch_build_updates-SDSYGOEWO53Z6ASKV6W4GSRWQU4DXCNNDGKGTWMQJ4O7LTMGYQVQ/live555/transport/include/TransportRTCP.h") @@ -129,12 +129,12 @@ void issue56030() { */ @Test void issue38215() { - Report warnings = parse("issue38215.txt"); + var warnings = parse("issue38215.txt"); assertThat(warnings).hasSize(1); assertThatReportHasSeverities(warnings, 0, 0, 1, 0); - try (SoftAssertions softly = new SoftAssertions()) { + try (var softly = new SoftAssertions()) { softly.assertThat(warnings.get(0)) .hasFileName("C:/J/workspace/ci_windows/ws/build/rmw/test/test_error_handling.vcxproj") .hasCategory("D9002") @@ -156,12 +156,12 @@ void issue38215() { */ @Test void issue22386() { - Report warnings = parse("issue22386.txt"); + var warnings = parse("issue22386.txt"); assertThat(warnings).hasSize(2); assertThatReportHasSeverities(warnings, 0, 0, 2, 0); - try (SoftAssertions softly = new SoftAssertions()) { + try (var softly = new SoftAssertions()) { softly.assertThat(warnings.get(0)) .hasFileName("C:/solutiondir/projectdir/src/main.cpp") .hasCategory("C4996") @@ -197,12 +197,12 @@ void issue22386() { */ @Test void issue51485() { - Report warnings = parse("issue51485.txt"); + var warnings = parse("issue51485.txt"); assertThat(warnings).hasSize(2); assertThatReportHasSeverities(warnings, 0, 0, 2, 0); - try (SoftAssertions softly = new SoftAssertions()) { + try (var softly = new SoftAssertions()) { softly.assertThat(warnings.get(0)) .hasFileName("src/search-list.component.scss") .hasCategory("shorthand-values") @@ -228,12 +228,12 @@ void issue51485() { */ @Test void issue27914() { - Report warnings = parse("issue27914.txt"); + var warnings = parse("issue27914.txt"); assertThat(warnings).hasSize(3); assertThatReportHasSeverities(warnings, 0, 0, 3, 0); - try (SoftAssertions softly = new SoftAssertions()) { + try (var softly = new SoftAssertions()) { softly.assertThat(warnings.get(0)) .hasFileName("E:/workspace/TreeSize release nightly/DelphiLib/Jam.UI.Dialogs.pas") .hasCategory("H2164") @@ -279,7 +279,7 @@ void issue27914() { */ @Test void issue26441() { - Report warnings = parse("issue26441.txt"); + var warnings = parse("issue26441.txt"); assertThat(warnings).isEmpty(); } @@ -291,7 +291,7 @@ void issue26441() { */ @Test void issue20544() { - Report warnings = parse("issue20544.txt"); + var warnings = parse("issue20544.txt"); assertThat(warnings).isEmpty(); } @@ -303,12 +303,12 @@ void issue20544() { */ @Test void issue20154() { - Report warnings = parse("issue20154.txt"); + var warnings = parse("issue20154.txt"); assertThat(warnings).hasSize(2).hasDuplicatesSize(2); assertThatReportHasSeverities(warnings, 0, 0, 2, 0); - try (SoftAssertions softly = new SoftAssertions()) { + try (var softly = new SoftAssertions()) { softly.assertThat(warnings.get(0)) .hasFileName("I:/devel/projects/SampleCodeAnalysis/SampleCodeAnalysis/Program.cs") .hasCategory("CA1801") @@ -346,12 +346,12 @@ void issue20154() { */ @Test void issue14888() { - Report warnings = parse("issue14888.txt"); + var warnings = parse("issue14888.txt"); assertThat(warnings).hasSize(4); assertThatReportHasSeverities(warnings, 4, 0, 0, 0); - try (SoftAssertions softly = new SoftAssertions()) { + try (var softly = new SoftAssertions()) { softly.assertThat(warnings.get(0)) .hasFileName("F:/AC_working/new-wlanac/ac/np/capwap/source/capwap_data.c") .hasCategory("40") @@ -409,12 +409,12 @@ void issue14888() { */ @Test void issue10566() { - Report warnings = parse("issue10566.txt"); + var warnings = parse("issue10566.txt"); assertThat(warnings).hasSize(1); assertThatReportHasSeverities(warnings, 1, 0, 0, 0); - try (SoftAssertions softly = new SoftAssertions()) { + try (var softly = new SoftAssertions()) { softly.assertThat(warnings.get(0)) .hasFileName("..//..//..//xx_Source//file.c") .hasCategory("c1083") @@ -436,12 +436,12 @@ void issue10566() { */ @Test void issue3582() { - Report errors = parse("issue3582.txt"); + var errors = parse("issue3582.txt"); assertThat(errors).hasSize(1); assertThatReportHasSeverities(errors, 1, 0, 0, 0); - try (SoftAssertions softly = new SoftAssertions()) { + try (var softly = new SoftAssertions()) { softly.assertThat(errors.get(0)) .hasFileName("TestLib.lib") .hasCategory("LNK1181") @@ -463,12 +463,12 @@ void issue3582() { */ @Test void issue63580() { - Report warnings = parse("issue63580.txt"); + var warnings = parse("issue63580.txt"); assertThat(warnings).hasSize(1); assertThatReportHasSeverities(warnings, 0, 0, 1, 0); - try (SoftAssertions softly = new SoftAssertions()) { + try (var softly = new SoftAssertions()) { softly.assertThat(warnings.get(0)) .hasFileName("def.obj") .hasCategory("LNK4217") @@ -490,12 +490,12 @@ void issue63580() { */ @Test void issue8347() { - Report warnings = parse("issue8347.txt"); + var warnings = parse("issue8347.txt"); assertThat(warnings).hasSize(5); assertThatReportHasSeverities(warnings, 0, 0, 5, 0); - try (SoftAssertions softly = new SoftAssertions()) { + try (var softly = new SoftAssertions()) { softly.assertThat(warnings.get(0)) .hasFileName("C:/hudsonSlave/workspace/MyProject/Source/MoqExtensions.cs") .hasCategory("SA1210") @@ -566,12 +566,12 @@ void issue8347() { */ @Test void issue6709() { - Report warnings = parse("issue6709.txt"); + var warnings = parse("issue6709.txt"); assertThat(warnings).hasSize(1); assertThatReportHasSeverities(warnings, 0, 0, 1, 0); - try (SoftAssertions softly = new SoftAssertions()) { + try (var softly = new SoftAssertions()) { softly.assertThat(warnings.get(0)) .hasFileName("Rules/TaskRules.cs") .hasCategory("CS0168") @@ -593,12 +593,12 @@ void issue6709() { */ @Test void issue9926() { - Report warnings = parse("issue9926.txt"); + var warnings = parse("issue9926.txt"); assertThat(warnings).hasSize(1); assertThatReportHasSeverities(warnings, 0, 0, 1, 0); - try (SoftAssertions softly = new SoftAssertions()) { + try (var softly = new SoftAssertions()) { softly.assertThat(warnings.get(0)) .hasFileName( "C:/jci/jobs/external_nvtristrip/workspace/compiler/cl/config/debug/platform/win32/tfields/live/external/nvtristrip/nvtristrip.cpp") @@ -621,12 +621,12 @@ void issue9926() { */ @Test void issue4932() { - Report warnings = parse("issue4932.txt"); + var warnings = parse("issue4932.txt"); assertThat(warnings).hasSize(1); assertThatReportHasSeverities(warnings, 1, 0, 0, 0); - try (SoftAssertions softly = new SoftAssertions()) { + try (var softly = new SoftAssertions()) { softly.assertThat(warnings.get(0)) .hasFileName("SynchronisationHeure.obj") .hasCategory("LNK2001") @@ -648,12 +648,12 @@ void issue4932() { */ @Test void issue4731() { - Report warnings = parse("issue4731.txt"); + var warnings = parse("issue4731.txt"); assertThat(warnings).hasSize(11).hasDuplicatesSize(1); assertThatReportHasSeverities(warnings, 0, 0, 11, 0); - try (SoftAssertions softly = new SoftAssertions()) { + try (var softly = new SoftAssertions()) { softly.assertThat(warnings.get(0)) .hasFileName("C:/playpens/Catalyst/Platform/src/Ptc.Platform.Web/Package/Package.package") .hasCategory("SPT6") @@ -718,12 +718,12 @@ void issue4731() { */ @Test void shouldDetectKeywordsInRegexCaseInsensitive() { - Report warnings = parse("issue2383.txt"); + var warnings = parse("issue2383.txt"); assertThat(warnings).hasSize(2); assertThatReportHasSeverities(warnings, 1, 0, 1, 0); - try (SoftAssertions softly = new SoftAssertions()) { + try (var softly = new SoftAssertions()) { softly.assertThat(warnings.get(0)) .hasFileName("Src/Parser/CSharp/cs.ATG") .hasCategory("CS0168") @@ -757,12 +757,12 @@ void shouldDetectKeywordsInRegexCaseInsensitive() { */ @Test void issue48647() { - Report warnings = parse("issue48647.txt"); + var warnings = parse("issue48647.txt"); assertThat(warnings).hasSize(1); assertThatReportHasSeverities(warnings, 0, 0, 1, 0); - try (SoftAssertions softly = new SoftAssertions()) { + try (var softly = new SoftAssertions()) { softly.assertThat(warnings.get(0)) .hasFileName("Filters/FilterBuilder.cs") .hasCategory("CS0168") @@ -784,9 +784,9 @@ void issue48647() { */ @Test void issue56450() { - Report report = parse("issue56450.txt"); + var report = parse("issue56450.txt"); - try (SoftAssertions softly = new SoftAssertions()) { + try (var softly = new SoftAssertions()) { Iterator iterator = report.iterator(); softly.assertThat(report).hasSize(2); assertThatReportHasSeverities(report, 0, 0, 2, 0); @@ -821,7 +821,7 @@ void issue56450() { */ @Test void issue57365() { - Report warnings = parse("issue57365.txt"); + var warnings = parse("issue57365.txt"); assertThat(warnings).isEmpty(); } @@ -834,7 +834,7 @@ void issue57365() { */ @Test void issue66950() { - Report report = parse("issue66950.txt"); + var report = parse("issue66950.txt"); assertThat(report).isEmpty().doesNotHaveErrors(); } diff --git a/src/test/java/edu/hm/hafner/analysis/parser/NagFortranParserTest.java b/src/test/java/edu/hm/hafner/analysis/parser/NagFortranParserTest.java index 27fa3e659..76f79a317 100644 --- a/src/test/java/edu/hm/hafner/analysis/parser/NagFortranParserTest.java +++ b/src/test/java/edu/hm/hafner/analysis/parser/NagFortranParserTest.java @@ -22,12 +22,12 @@ class NagFortranParserTest extends AbstractParserTest { */ @Test void testInfoParser() { - Report warnings = parse("NagFortranInfo.txt"); + var warnings = parse("NagFortranInfo.txt"); assertThat(warnings).hasSize(1); assertThatReportHasSeverities(warnings, 0, 0, 0, 1); - try (SoftAssertions softly = new SoftAssertions()) { + try (var softly = new SoftAssertions()) { softly.assertThat(warnings.get(0)) .hasFileName("C:/file1.inc") .hasCategory("Info") @@ -42,12 +42,12 @@ void testInfoParser() { */ @Test void testWarningParser() { - Report warnings = parse("NagFortranWarning.txt"); + var warnings = parse("NagFortranWarning.txt"); assertThat(warnings).hasSize(1); assertThatReportHasSeverities(warnings, 0, 0, 1, 0); - try (SoftAssertions softly = new SoftAssertions()) { + try (var softly = new SoftAssertions()) { softly.assertThat(warnings.get(0)) .hasFileName("C:/file2.f90") .hasCategory("Warning") @@ -62,12 +62,12 @@ void testWarningParser() { */ @Test void testQuestionableParser() { - Report warnings = parse("NagFortranQuestionable.txt"); + var warnings = parse("NagFortranQuestionable.txt"); assertThat(warnings).hasSize(1); assertThatReportHasSeverities(warnings, 0, 0, 1, 0); - try (SoftAssertions softly = new SoftAssertions()) { + try (var softly = new SoftAssertions()) { softly.assertThat(warnings.get(0)) .hasFileName("/file3.f90") .hasCategory("Questionable") @@ -83,12 +83,12 @@ void testQuestionableParser() { */ @Test void testExtensionParser() { - Report warnings = parse("NagFortranExtension.txt"); + var warnings = parse("NagFortranExtension.txt"); assertThat(warnings).hasSize(1); assertThatReportHasSeverities(warnings, 0, 0, 1, 0); - try (SoftAssertions softly = new SoftAssertions()) { + try (var softly = new SoftAssertions()) { softly.assertThat(warnings.get(0)) .hasFileName("file4.f90") .hasCategory("Extension") @@ -103,12 +103,12 @@ void testExtensionParser() { */ @Test void testObsolescentParser() { - Report warnings = parse("NagFortranObsolescent.txt"); + var warnings = parse("NagFortranObsolescent.txt"); assertThat(warnings).hasSize(1); assertThatReportHasSeverities(warnings, 0, 0, 1, 0); - try (SoftAssertions softly = new SoftAssertions()) { + try (var softly = new SoftAssertions()) { softly.assertThat(warnings.get(0)) .hasFileName("file5.f") .hasCategory("Obsolescent") @@ -123,12 +123,12 @@ void testObsolescentParser() { */ @Test void testDeletedFeatureUsedParser() { - Report warnings = parse("NagFortranDeletedFeatureUsed.txt"); + var warnings = parse("NagFortranDeletedFeatureUsed.txt"); assertThat(warnings).hasSize(1); assertThatReportHasSeverities(warnings, 0, 0, 1, 0); - try (SoftAssertions softly = new SoftAssertions()) { + try (var softly = new SoftAssertions()) { softly.assertThat(warnings.get(0)) .hasFileName("file6.f90") .hasCategory("Deleted feature used") @@ -143,12 +143,12 @@ void testDeletedFeatureUsedParser() { */ @Test void testErrorParser() { - Report warnings = parse("NagFortranError.txt"); + var warnings = parse("NagFortranError.txt"); assertThat(warnings).hasSize(1); assertThatReportHasSeverities(warnings, 0, 1, 0, 0); - try (SoftAssertions softly = new SoftAssertions()) { + try (var softly = new SoftAssertions()) { softly.assertThat(warnings.get(0)) .hasFileName("file7.f90") .hasCategory("Error") @@ -164,12 +164,12 @@ void testErrorParser() { */ @Test void testRuntimeErrorParser() { - Report warnings = parse("NagFortranRuntimeError.txt"); + var warnings = parse("NagFortranRuntimeError.txt"); assertThat(warnings).hasSize(1); assertThatReportHasSeverities(warnings, 0, 1, 0, 0); - try (SoftAssertions softly = new SoftAssertions()) { + try (var softly = new SoftAssertions()) { softly.assertThat(warnings.get(0)) .hasFileName("file8.f90") .hasCategory("Runtime Error") @@ -184,12 +184,12 @@ void testRuntimeErrorParser() { */ @Test void testFatalErrorParser() { - Report warnings = parse("NagFortranFatalError.txt"); + var warnings = parse("NagFortranFatalError.txt"); assertThat(warnings).hasSize(1); assertThatReportHasSeverities(warnings, 0, 1, 0, 0); - try (SoftAssertions softly = new SoftAssertions()) { + try (var softly = new SoftAssertions()) { softly.assertThat(warnings.get(0)) .hasFileName("file9.f90") .hasCategory("Fatal Error") @@ -204,12 +204,12 @@ void testFatalErrorParser() { */ @Test void testPanicParser() { - Report warnings = parse("NagFortranPanic.txt"); + var warnings = parse("NagFortranPanic.txt"); assertThat(warnings).hasSize(1); assertThatReportHasSeverities(warnings, 0, 1, 0, 0); - try (SoftAssertions softly = new SoftAssertions()) { + try (var softly = new SoftAssertions()) { softly.assertThat(warnings.get(0)) .hasFileName("file10.f90") .hasCategory("Panic") @@ -224,12 +224,12 @@ void testPanicParser() { */ @Test void testNonStandardObsoleteParser() { - Report warnings = parse("NagFortranNonStandardObsolete.txt"); + var warnings = parse("NagFortranNonStandardObsolete.txt"); assertThat(warnings).hasSize(1); assertThatReportHasSeverities(warnings, 0, 0, 1, 0); - try (SoftAssertions softly = new SoftAssertions()) { + try (var softly = new SoftAssertions()) { softly.assertThat(warnings.get(0)) .hasFileName("msgs71.f90") .hasCategory("Non-standard(Obsolete)") @@ -244,12 +244,12 @@ void testNonStandardObsoleteParser() { */ @Test void testExtensionNAGParser() { - Report warnings = parse("NagFortranExtensionNAG.txt"); + var warnings = parse("NagFortranExtensionNAG.txt"); assertThat(warnings).hasSize(1); assertThatReportHasSeverities(warnings, 0, 0, 1, 0); - try (SoftAssertions softly = new SoftAssertions()) { + try (var softly = new SoftAssertions()) { softly.assertThat(warnings.get(0)) .hasFileName("msgs71.f90") .hasCategory("Extension(NAG)") @@ -264,12 +264,12 @@ void testExtensionNAGParser() { */ @Test void testExtensionF2018Parser() { - Report warnings = parse("NagFortranExtensionF2018.txt"); + var warnings = parse("NagFortranExtensionF2018.txt"); assertThat(warnings).hasSize(1); assertThatReportHasSeverities(warnings, 0, 0, 1, 0); - try (SoftAssertions softly = new SoftAssertions()) { + try (var softly = new SoftAssertions()) { softly.assertThat(warnings.get(0)) .hasFileName("msgs71.f90") .hasCategory("Extension(F2018)") @@ -284,12 +284,12 @@ void testExtensionF2018Parser() { */ @Test void testExtensionF2008Parser() { - Report warnings = parse("NagFortranExtensionF2008.txt"); + var warnings = parse("NagFortranExtensionF2008.txt"); assertThat(warnings).hasSize(1); assertThatReportHasSeverities(warnings, 0, 0, 1, 0); - try (SoftAssertions softly = new SoftAssertions()) { + try (var softly = new SoftAssertions()) { softly.assertThat(warnings.get(0)) .hasFileName("msgs71.f90") .hasCategory("Extension(F2008)") diff --git a/src/test/java/edu/hm/hafner/analysis/parser/ParserBenchmark.java b/src/test/java/edu/hm/hafner/analysis/parser/ParserBenchmark.java index dcb407093..25d641073 100644 --- a/src/test/java/edu/hm/hafner/analysis/parser/ParserBenchmark.java +++ b/src/test/java/edu/hm/hafner/analysis/parser/ParserBenchmark.java @@ -1,7 +1,7 @@ package edu.hm.hafner.analysis.parser; import java.net.URISyntaxException; -import java.nio.file.Paths; +import java.nio.file.Path; import java.util.Objects; import org.openjdk.jmh.annotations.Benchmark; @@ -40,7 +40,7 @@ public class ParserBenchmark extends AbstractBenchmark { */ @Benchmark public void benchmarkCheckStyleParser(final BenchmarkState state, final Blackhole blackhole) { - Report report = new CheckStyleParser().parse(state.getCheckstyleFileReaderFactory()); + var report = new CheckStyleParser().parse(state.getCheckstyleFileReaderFactory()); blackhole.consume(report); } @@ -55,7 +55,7 @@ public void benchmarkCheckStyleParser(final BenchmarkState state, final Blackhol */ @Benchmark public void benchmarkPmdParser(final BenchmarkState state, final Blackhole blackhole) { - Report report = new PmdParser().parse(state.getPmdFileReaderFactory()); + var report = new PmdParser().parse(state.getPmdFileReaderFactory()); blackhole.consume(report); } @@ -72,7 +72,7 @@ public static class BenchmarkState { private ReaderFactory createFileReaderFactory(final String fileName) throws URISyntaxException { return new FileReaderFactory( - Paths.get(Objects.requireNonNull(BenchmarkState.class.getResource(fileName)).toURI())); + Path.of(Objects.requireNonNull(BenchmarkState.class.getResource(fileName)).toURI())); } public ReaderFactory getCheckstyleFileReaderFactory() { diff --git a/src/test/java/edu/hm/hafner/analysis/parser/PerlCriticParserTest.java b/src/test/java/edu/hm/hafner/analysis/parser/PerlCriticParserTest.java index db4e8e256..3dbc3d5de 100644 --- a/src/test/java/edu/hm/hafner/analysis/parser/PerlCriticParserTest.java +++ b/src/test/java/edu/hm/hafner/analysis/parser/PerlCriticParserTest.java @@ -32,13 +32,13 @@ protected void assertThatIssuesArePresent(final Report report, final SoftAsserti */ @Test void testPerlCriticParserCreateWarning() { - Report warnings = parse("issue17792.txt"); + var warnings = parse("issue17792.txt"); assertThat(warnings).hasSize(3); Iterator iterator = warnings.iterator(); - try (SoftAssertions softly = new SoftAssertions()) { + try (var softly = new SoftAssertions()) { softly.assertThat(iterator.next()) .hasSeverity(Severity.WARNING_LOW) .hasCategory("33 of PBP") @@ -73,12 +73,12 @@ void testPerlCriticParserCreateWarning() { */ @Test void testPerlCriticParserCreateWarningNoFileName() { - Report warnings = parse("issue17792-nofilename.txt"); + var warnings = parse("issue17792-nofilename.txt"); assertThat(warnings).hasSize(3); Iterator iterator = warnings.iterator(); - try (SoftAssertions softly = new SoftAssertions()) { + try (var softly = new SoftAssertions()) { softly.assertThat(iterator.next()) .hasSeverity(Severity.WARNING_LOW) .hasCategory("Don't use whitespace at the end of lines") diff --git a/src/test/java/edu/hm/hafner/analysis/parser/PhpParserTest.java b/src/test/java/edu/hm/hafner/analysis/parser/PhpParserTest.java index 054e84585..6f3fc7f33 100644 --- a/src/test/java/edu/hm/hafner/analysis/parser/PhpParserTest.java +++ b/src/test/java/edu/hm/hafner/analysis/parser/PhpParserTest.java @@ -34,11 +34,11 @@ class PhpParserTest extends AbstractParserTest { */ @Test void issue27681() { - Report report = parse("issue27681.txt"); + var report = parse("issue27681.txt"); assertThat(report).hasSize(1); - try (SoftAssertions softly = new SoftAssertions()) { + try (var softly = new SoftAssertions()) { softly.assertThat(report.get(0)) .hasSeverity(Severity.WARNING_HIGH) .hasCategory(FATAL_ERROR_CATEGORY) diff --git a/src/test/java/edu/hm/hafner/analysis/parser/PmdParserTest.java b/src/test/java/edu/hm/hafner/analysis/parser/PmdParserTest.java index 63052bd37..94de714c6 100644 --- a/src/test/java/edu/hm/hafner/analysis/parser/PmdParserTest.java +++ b/src/test/java/edu/hm/hafner/analysis/parser/PmdParserTest.java @@ -30,7 +30,7 @@ protected PmdParser createParser() { protected void assertThatIssuesArePresent(final Report report, final SoftAssertions softly) { softly.assertThat(report).hasSize(4); - Report actionIssues = report.filter(Issue.byPackageName("com.avaloq.adt.env.internal.ui.actions")); + var actionIssues = report.filter(Issue.byPackageName("com.avaloq.adt.env.internal.ui.actions")); softly.assertThat(actionIssues).hasSize(1); softly.assertThat(report.filter(Issue.byPackageName("com.avaloq.adt.env.internal.ui.actions"))).hasSize(1); softly.assertThat(report.filter(Issue.byPackageName("com.avaloq.adt.env.internal.ui.dialogs"))).hasSize(2); @@ -51,7 +51,7 @@ protected void assertThatIssuesArePresent(final Report report, final SoftAsserti @Test void shouldCorrectlyMapLinesAndColumns() { - Report report = parseInPmdFolder("lines-columns.xml"); + var report = parseInPmdFolder("lines-columns.xml"); assertThat(report).hasSize(1); @@ -73,7 +73,7 @@ void shouldCorrectlyMapLinesAndColumns() { */ @Test void issue54736() { - Report report = parseInPmdFolder("issue54736.xml"); + var report = parseInPmdFolder("issue54736.xml"); assertThat(report).hasSize(4 + 21); assertThatReportHasSeverities(report, 21, 0, 4, 0); @@ -83,39 +83,40 @@ void issue54736() { .hasMessage( "Error while parsing /Users/jordillach/DemoTenants/Tenants/vhosts/pre.elperiodico.com/themes/default/articleTemplates/forceOpinion.s.jsp") .hasDescription( - "\"