Skip to content

Commit

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

Bump edu.hm.hafner:codingstyle-pom from 4.16.0 to 5.5.0
  • Loading branch information
uhafner authored Nov 19, 2024
2 parents 93964a0 + e71ffeb commit 4a5e98d
Show file tree
Hide file tree
Showing 342 changed files with 2,098 additions and 1,887 deletions.
2 changes: 1 addition & 1 deletion etc/Jenkinsfile.declarative
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@ pipeline {
recordIssues enabledForFailure: true, tool: taskScanner(includePattern:'**/*.java', highTags:'FIXME', normalTags:'TODO')
}
}
}
}
2 changes: 1 addition & 1 deletion etc/Jenkinsfile.fullBuild
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,4 @@ node {
stage ('Collect Maven Warnings') {
recordIssues tool: mavenConsole()
}
}
}
2 changes: 1 addition & 1 deletion etc/Jenkinsfile.local
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,4 @@ node {
stage ('Collect Maven Warnings') {
recordIssues tool: mavenConsole()
}
}
}
6 changes: 3 additions & 3 deletions etc/Jenkinsfile.parallel.declarative
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ pipeline {
}
post {
always {
recordIssues tools: [[tool: java()],
[tool: javaDoc()],
recordIssues tools: [[tool: java()],
[tool: javaDoc()],
[tool: taskScanner(includePattern:'**/*.java', highTags:'FIXME', normalTags:'TODO')]]
}
}
}
}
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>edu.hm.hafner</groupId>
<artifactId>codingstyle-pom</artifactId>
<version>4.16.0</version>
<version>5.5.0</version>
<relativePath />
</parent>

Expand Down Expand Up @@ -53,7 +53,7 @@

<properties>
<scmTag>HEAD</scmTag>
<revision>12.10.0</revision>
<revision>13.0.0</revision>
<changelist>-SNAPSHOT</changelist>

<module.name>edu.hm.hafner.analysis.model</module.name>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ abstract class AbstractPackageDetector {
*/
public String detectPackageName(final String fileName, final Charset charset) {
if (accepts(fileName)) {

Check warning on line 48 in src/main/java/edu/hm/hafner/analysis/AbstractPackageDetector.java

View workflow job for this annotation

GitHub Actions / Quality Monitor

Partially covered line

Line 48 is only partially covered, one branch is missing
try (InputStream stream = fileSystem.openFile(fileName)) {
try (var stream = fileSystem.openFile(fileName)) {
return detectPackageName(stream, charset);
}
catch (IOException | InvalidPathException ignore) {
Expand All @@ -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());
}
}
Expand All @@ -73,7 +73,7 @@ String detectPackageName(final InputStream stream, final Charset charset) throws
* @return the detected package or namespace name
*/
String detectPackageName(final Stream<String> lines) {
Pattern pattern = getPattern();
var pattern = getPattern();
return lines.map(pattern::matcher)
.filter(Matcher::matches)
.findFirst()
Expand Down
7 changes: 3 additions & 4 deletions src/main/java/edu/hm/hafner/analysis/AntModuleDetector.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package edu.hm.hafner.analysis;

import java.io.IOException;
import java.io.InputStream;
import java.nio.file.InvalidPathException;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -44,15 +43,15 @@ void collectProjects(final Map<String, String> mapping, final List<String> 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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,3 @@ Pattern getPattern() {
return NAMESPACE_PATTERN;
}
}

3 changes: 1 addition & 2 deletions src/main/java/edu/hm/hafner/analysis/Categories.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -60,4 +60,3 @@ private Categories() {
// prevents instantiation
}
}

2 changes: 2 additions & 0 deletions src/main/java/edu/hm/hafner/analysis/DuplicationGroup.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package edu.hm.hafner.analysis;

import java.io.Serial;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
Expand All @@ -15,6 +16,7 @@
* detector like CPD, DupFinder, or Simian.
*/
public final class DuplicationGroup implements Serializable {
@Serial
private static final long serialVersionUID = -5005784523279541971L;

private final List<Issue> occurrences = new ArrayList<>();
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/edu/hm/hafner/analysis/FileNameResolver.java
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
7 changes: 3 additions & 4 deletions src/main/java/edu/hm/hafner/analysis/FileReaderFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import java.nio.file.Files;
import java.nio.file.InvalidPathException;
import java.nio.file.Path;
import javax.xml.stream.XMLStreamReader;

import org.apache.commons.io.input.BOMInputStream;

Expand Down Expand Up @@ -80,9 +79,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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
7 changes: 3 additions & 4 deletions src/main/java/edu/hm/hafner/analysis/FullTextFingerprint.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -83,7 +83,7 @@ String getFallbackFingerprint(final String fileName) {

@VisibleForTesting
String createFingerprint(final int line, final Stream<String> lines, final Charset charset) {
String context = extractContext(line, lines.iterator());
var context = extractContext(line, lines.iterator());
lines.close();
digest.update(context.getBytes(charset));

Expand Down Expand Up @@ -137,8 +137,7 @@ static class FileSystem {
@MustBeClosed
Stream<String> readLinesFromFile(final String fileName, final Charset charset)
throws IOException, InvalidPathException {
return Files.lines(Paths.get(fileName), charset);
return Files.lines(Path.of(fileName), charset);

Check warning on line 140 in src/main/java/edu/hm/hafner/analysis/FullTextFingerprint.java

View workflow job for this annotation

GitHub Actions / Quality Monitor

Not covered line

Line 140 is not covered by tests
}
}
}

12 changes: 6 additions & 6 deletions src/main/java/edu/hm/hafner/analysis/GradleModuleDetector.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package edu.hm.hafner.analysis;

import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import java.nio.file.InvalidPathException;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -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);
}

Expand All @@ -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, StandardCharsets.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);
Expand Down
11 changes: 7 additions & 4 deletions src/main/java/edu/hm/hafner/analysis/Issue.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package edu.hm.hafner.analysis;

import java.io.Serial;
import java.io.Serializable;
import java.lang.reflect.InvocationTargetException;
import java.util.Locale;
Expand All @@ -26,6 +27,7 @@
*/
@SuppressWarnings({"PMD.TooManyFields", "PMD.GodClass", "PMD.CyclomaticComplexity", "NoFunctionalReturnType"})
public class Issue implements Serializable {
@Serial
private static final long serialVersionUID = 1L; // release 1.0.0

private static final PathUtil PATH_UTIL = new PathUtil();
Expand Down Expand Up @@ -486,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;
}
Expand Down Expand Up @@ -832,6 +834,7 @@ void setReference(@CheckForNull final String reference) {
* Returns the fingerprint for this issue. Used to decide if two issues are equal even if the equals method returns
* {@code false} since some properties differ due to code refactorings. The fingerprint is created by
* analyzing the content of the affected file.
*
* <p>
* Note: the fingerprint is not part of the equals method since the fingerprint might change due to an unrelated
* refactoring of the source code.
Expand Down Expand Up @@ -902,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;
Expand Down Expand Up @@ -934,8 +937,8 @@ public boolean equals(@CheckForNull final Object o) {
if (!description.equals(issue.description)) {
return false;
}
if (additionalProperties != null ? !additionalProperties.equals(issue.additionalProperties) :
issue.additionalProperties != null) {
if (additionalProperties != null ? !additionalProperties.equals(issue.additionalProperties)
: issue.additionalProperties != null) {
return false;
}
if (!origin.equals(issue.origin)) {
Expand Down
17 changes: 9 additions & 8 deletions src/main/java/edu/hm/hafner/analysis/IssueBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

import com.google.errorprone.annotations.CanIgnoreReturnValue;

import edu.hm.hafner.util.LineRange;
import edu.hm.hafner.util.LineRangeList;
import edu.hm.hafner.util.PathUtil;
import edu.hm.hafner.util.TreeString;
Expand All @@ -21,7 +20,9 @@
/**
* Creates new {@link Issue issues} using the builder pattern. All properties that have not been set in the builder will
* be set to their default value.
*
* <p>Example:</p>
*
* <blockquote><pre>
* Issue issue = new IssueBuilder()
* .setFileName("affected.file")
Expand All @@ -45,10 +46,10 @@ public class IssueBuilder implements AutoCloseable {
private final TreeStringBuilder packageNameBuilder = new TreeStringBuilder();
private final TreeStringBuilder messageBuilder = new TreeStringBuilder();

private int lineStart = 0;
private int lineEnd = 0;
private int columnStart = 0;
private int columnEnd = 0;
private int lineStart;
private int lineEnd;
private int columnStart;
private int columnEnd;

@CheckForNull
private LineRangeList lineRanges;
Expand Down Expand Up @@ -532,7 +533,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;
}
Expand All @@ -544,7 +545,7 @@ public Issue build() {
* @return the created issue
*/
public Issue buildAndClean() {
Issue issue = buildWithConstructor();
var issue = buildWithConstructor();
clean();
return issue;
}
Expand All @@ -564,7 +565,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();
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/edu/hm/hafner/analysis/IssueDifference.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public IssueDifference(final Report currentIssues, final String referenceId,
}

List<UUID> removed = matchIssuesByEquals(currentIssues);
Report secondPass = currentIssues.copy();
var secondPass = currentIssues.copy();
removed.forEach(secondPass::remove);
matchIssuesByFingerprint(secondPass);

Expand Down Expand Up @@ -128,8 +128,8 @@ private <K> void removeIssueFromMap(final Map<K, List<Issue>> 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());
Expand Down
Loading

0 comments on commit 4a5e98d

Please sign in to comment.