From 9c34fac4f31c20d6eab986c21f42b7d76c8bc281 Mon Sep 17 00:00:00 2001 From: Mark Waite Date: Sat, 23 Dec 2023 07:49:04 -0700 Subject: [PATCH 1/9] Remove unnecessary parentheses --- src/main/java/hudson/plugins/logparser/LogParserLogPart.java | 2 +- src/main/java/hudson/plugins/logparser/LogParserReader.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/hudson/plugins/logparser/LogParserLogPart.java b/src/main/java/hudson/plugins/logparser/LogParserLogPart.java index ad9c7eb..fe79309 100755 --- a/src/main/java/hudson/plugins/logparser/LogParserLogPart.java +++ b/src/main/java/hudson/plugins/logparser/LogParserLogPart.java @@ -26,7 +26,7 @@ public void setLogPartNum(final int logPartNum) { } public boolean isEmpty() { - return (lines[0] == null); + return lines[0] == null; } } diff --git a/src/main/java/hudson/plugins/logparser/LogParserReader.java b/src/main/java/hudson/plugins/logparser/LogParserReader.java index fd575f7..d380673 100755 --- a/src/main/java/hudson/plugins/logparser/LogParserReader.java +++ b/src/main/java/hudson/plugins/logparser/LogParserReader.java @@ -24,7 +24,7 @@ public synchronized LogParserLogPart readLogPart(final int threadNum) throws IOE int counter = 0; String line; - while (counter < numLines && ((line = reader.readLine()) != null)) { + while (counter < numLines && (line = reader.readLine()) != null) { lines[counter++] = line; } logger.log(Level.INFO, "Done reading log part " + logPartNum); From 5ea347fd7e7f80c547eb09dd29ee5127b44540b1 Mon Sep 17 00:00:00 2001 From: Mark Waite Date: Sat, 23 Dec 2023 07:50:02 -0700 Subject: [PATCH 2/9] Remove unnecessary final on resource usage Resources are final already --- src/main/java/hudson/plugins/logparser/LogParserParser.java | 6 +++--- src/main/java/hudson/plugins/logparser/LogParserUtils.java | 2 +- src/main/java/hudson/plugins/logparser/LogParserWriter.java | 6 +++--- .../java/hudson/plugins/logparser/ReadWriteTextFile.java | 4 ++-- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/main/java/hudson/plugins/logparser/LogParserParser.java b/src/main/java/hudson/plugins/logparser/LogParserParser.java index 8cac814..17dc153 100755 --- a/src/main/java/hudson/plugins/logparser/LogParserParser.java +++ b/src/main/java/hudson/plugins/logparser/LogParserParser.java @@ -116,7 +116,7 @@ public LogParserResult parseLog(final Run build) throws IOException, Inter } // Open console log for reading and all other files for writing - try (final BufferedWriter writer = new BufferedWriter(new FileWriter(parsedFilePath))) { + try (BufferedWriter writer = new BufferedWriter(new FileWriter(parsedFilePath))) { // Record writers to links files in hash writers.put(LogParserConsts.ERROR, new BufferedWriter(new FileWriter( @@ -350,8 +350,8 @@ private void parseLogBody(final Run build, final BufferedWriter writer, fi // Read log file from start - line by line and apply the statuses as // found by the threads. - try (final InputStreamReader streamReader = new InputStreamReader(build.getLogInputStream(), charset); - final BufferedReader reader = new BufferedReader(streamReader)) { + try (InputStreamReader streamReader = new InputStreamReader(build.getLogInputStream(), charset); + BufferedReader reader = new BufferedReader(streamReader)) { String line; String status; int line_num = 0; diff --git a/src/main/java/hudson/plugins/logparser/LogParserUtils.java b/src/main/java/hudson/plugins/logparser/LogParserUtils.java index 74bf91c..033c1bd 100755 --- a/src/main/java/hudson/plugins/logparser/LogParserUtils.java +++ b/src/main/java/hudson/plugins/logparser/LogParserUtils.java @@ -145,7 +145,7 @@ public static int getLinesPerThread() { } public static int countLines(final String filename) throws IOException { - try (final LineNumberReader reader = new LineNumberReader(new FileReader(filename))) { + try (LineNumberReader reader = new LineNumberReader(new FileReader(filename))) { int count = 0; while (reader.readLine() != null) { // Read the whole file to count the lines. diff --git a/src/main/java/hudson/plugins/logparser/LogParserWriter.java b/src/main/java/hudson/plugins/logparser/LogParserWriter.java index 10f86f0..aa8ce84 100755 --- a/src/main/java/hudson/plugins/logparser/LogParserWriter.java +++ b/src/main/java/hudson/plugins/logparser/LogParserWriter.java @@ -36,7 +36,7 @@ public static void writeWrapperHtml(final String buildWrapperPath) + "build log\n" + "\n" + "\n"; - try (final BufferedWriter writer = new BufferedWriter(new FileWriter(buildWrapperPath))) { + try (BufferedWriter writer = new BufferedWriter(new FileWriter(buildWrapperPath))) { writer.write(wrapperHtml); } } @@ -57,7 +57,7 @@ public static void writeReferenceHtml(final String buildRefPath, + "\t\telement.display == 'none' ? element.display='block' : element.display='none';\n" + "\t}\n" + "\n"; - try (final BufferedWriter writer = new BufferedWriter(new FileWriter(buildRefPath))) { + try (BufferedWriter writer = new BufferedWriter(new FileWriter(buildRefPath))) { // Hudson stylesheets writer.write(LogParserConsts.getHtmlOpeningTags()); writer.write(refStart); // toggle links javascript @@ -131,7 +131,7 @@ private static void writeLinks(final BufferedWriter writer, writer.write(linksStart); // Read the links file and insert here - try (final BufferedReader reader = new BufferedReader(new FileReader(linkFiles.get(status)))) { + try (BufferedReader reader = new BufferedReader(new FileReader(linkFiles.get(status)))) { final String summaryLine = "
(SUMMARY_INT_HERE LINK_LIST_DISPLAY_STR in this section)
"; final String headerTemplateRegexp = "HEADER HERE:"; diff --git a/src/main/java/hudson/plugins/logparser/ReadWriteTextFile.java b/src/main/java/hudson/plugins/logparser/ReadWriteTextFile.java index ca57c46..b825215 100755 --- a/src/main/java/hudson/plugins/logparser/ReadWriteTextFile.java +++ b/src/main/java/hudson/plugins/logparser/ReadWriteTextFile.java @@ -20,7 +20,7 @@ private ReadWriteTextFile() { static public String getContents(final File aFile) { final StringBuilder contents = new StringBuilder(); - try (final BufferedReader input = new BufferedReader(new FileReader(aFile))) { + try (BufferedReader input = new BufferedReader(new FileReader(aFile))) { String line = null; // not declared within while loop while ((line = input.readLine()) != null) { contents.append(line).append("\n"); @@ -55,7 +55,7 @@ static public void setContents(final File aFile, final String aContents) } // use buffering - try (final Writer output = new BufferedWriter(new FileWriter(aFile))) { + try (Writer output = new BufferedWriter(new FileWriter(aFile))) { // FileWriter always assumes default encoding is OK! output.write(aContents); } From 72c893eda394f6b984304419bc5074871d8e14f6 Mon Sep 17 00:00:00 2001 From: Mark Waite Date: Sat, 23 Dec 2023 07:50:48 -0700 Subject: [PATCH 3/9] Combine nested if statements into single statement Quiets another pmd warning --- .../plugins/logparser/LogParserUtils.java | 23 ++++++++----------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/src/main/java/hudson/plugins/logparser/LogParserUtils.java b/src/main/java/hudson/plugins/logparser/LogParserUtils.java index 033c1bd..57c6d13 100755 --- a/src/main/java/hudson/plugins/logparser/LogParserUtils.java +++ b/src/main/java/hudson/plugins/logparser/LogParserUtils.java @@ -24,16 +24,12 @@ public static String[] readParsingRules(final FilePath parsingRulesFile) throws } public static boolean skipParsingRule(final String parsingRule) { - boolean skip = false; - if (parsingRule == null || parsingRule.equals("") - || parsingRule.charAt(0) == '#' - || parsingRule.startsWith("\\s") - || parsingRule.startsWith("\r") || // Carriage return - parsingRule.contains("$header")) { // for now - disregard rules - // with header in them - skip = true; - } - return skip; + return parsingRule == null || parsingRule.equals("") + || parsingRule.charAt(0) == '#' + || parsingRule.startsWith("\\s") + || parsingRule.startsWith("\r") // Carriage return + || parsingRule.contains("$header"); // for now - disregard rules + // with header in them } public static String standardizeStatus(final String status) { @@ -75,10 +71,9 @@ public static CompiledPatterns compilePatterns( final String ruleParts[] = parsingRule.split("\\s"); String regexp = ruleParts[1]; String tag = ruleParts[0]; - if (!LogParserConsts.LEGAL_STATUS.contains(tag.toUpperCase(Locale.ENGLISH))) { - if (!Arrays.asList("OK", "END", "WARN").contains(tag.toUpperCase(Locale.ENGLISH))) { - extraTags.add(tag); - } + if (!LogParserConsts.LEGAL_STATUS.contains(tag.toUpperCase(Locale.ENGLISH)) + && !Arrays.asList("OK", "END", "WARN").contains(tag.toUpperCase(Locale.ENGLISH))) { + extraTags.add(tag); } final int firstDash = parsingRule.indexOf('/'); From b59c0d240b25787301bfd480bf5cc530661ebe19 Mon Sep 17 00:00:00 2001 From: Mark Waite Date: Sat, 23 Dec 2023 07:51:23 -0700 Subject: [PATCH 4/9] Remove unused import --- src/main/java/hudson/plugins/logparser/LogParserWriter.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/hudson/plugins/logparser/LogParserWriter.java b/src/main/java/hudson/plugins/logparser/LogParserWriter.java index aa8ce84..f7d95dc 100755 --- a/src/main/java/hudson/plugins/logparser/LogParserWriter.java +++ b/src/main/java/hudson/plugins/logparser/LogParserWriter.java @@ -1,6 +1,5 @@ package hudson.plugins.logparser; -import hudson.Functions; import jenkins.model.Jenkins; import java.io.BufferedReader; From 62624f561efb25e7afe7ce3987a12336fa883b4f Mon Sep 17 00:00:00 2001 From: Mark Waite Date: Sat, 23 Dec 2023 07:53:07 -0700 Subject: [PATCH 5/9] Use simpler reference to field --- src/main/java/hudson/plugins/logparser/LogParserWriter.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/hudson/plugins/logparser/LogParserWriter.java b/src/main/java/hudson/plugins/logparser/LogParserWriter.java index f7d95dc..3d4f90e 100755 --- a/src/main/java/hudson/plugins/logparser/LogParserWriter.java +++ b/src/main/java/hudson/plugins/logparser/LogParserWriter.java @@ -109,7 +109,7 @@ private static void writeLinks(final BufferedWriter writer, final String linkListCount = statusCount.get(status).toString(); final String hudsonRoot = Jenkins.get().getRootUrl(); - final String iconLocation = String.format("%s/plugin/log-parser/images/", jenkins.model.Jenkins.RESOURCE_PATH).substring(1); + final String iconLocation = String.format("%s/plugin/log-parser/images/", Jenkins.RESOURCE_PATH).substring(1); final String styles = "