dsb = new DataSetBuilder<>();
for (LogParserAction a = this; a != null; a = a.getPreviousAction()) {
- dsb.add(a.result.getTotalErrors(), "errors",
+ dsb.add(a.result.getTotalErrors(), "0",
new ChartUtil.NumberOnlyBuildLabel(a.getOwner()));
- dsb.add(a.result.getTotalWarnings(), "warnings",
+ dsb.add(a.result.getTotalWarnings(), "1",
new ChartUtil.NumberOnlyBuildLabel(a.getOwner()));
- dsb.add(a.result.getTotalInfos(), "infos",
+ dsb.add(a.result.getTotalInfos(), "2",
new ChartUtil.NumberOnlyBuildLabel(a.getOwner()));
- dsb.add(a.result.getTotalDebugs(), "debugs",
+ dsb.add(a.result.getTotalDebugs(), "3",
new ChartUtil.NumberOnlyBuildLabel(a.getOwner()));
for (String extraTag : a.result.getExtraTags()) {
dsb.add(a.result.getTotalCountsByExtraTag(extraTag), extraTag,
@@ -212,22 +212,25 @@ public String generateURL(CategoryDataset dataset, int row,
@Override
public String generateToolTip(CategoryDataset dataset, int row,
int column) {
+ ChartUtil.NumberOnlyBuildLabel label = (ChartUtil.NumberOnlyBuildLabel) dataset
+ .getColumnKey(column);
+ LogParserResult result = label.build.getAction(LogParserAction.class).getResult();
switch (row) {
case 0:
return "Errors: " + result.getTotalErrors();
case 1:
return "Warnings: " + result.getTotalWarnings();
case 2:
- return "Debugs: " + result.getTotalDebugs();
- default:
return "Infos: " + result.getTotalInfos();
+ default:
+ return "Debugs: " + result.getTotalDebugs();
}
}
};
plot.setRenderer(ar);
ar.setSeriesPaint(0, ColorPalette.RED); // error
- ar.setSeriesPaint(1, ColorPalette.BLUE); // info
- ar.setSeriesPaint(2, ColorPalette.YELLOW); // warning
+ ar.setSeriesPaint(1, ColorPalette.YELLOW); // warning
+ ar.setSeriesPaint(2, ColorPalette.BLUE); // info
ar.setSeriesPaint(3, ColorPalette.GREY); // debug
// crop extra space around the graph
diff --git a/src/main/java/hudson/plugins/logparser/LogParserDisplayConsts.java b/src/main/java/hudson/plugins/logparser/LogParserDisplayConsts.java
index 21c5468..651f21e 100755
--- a/src/main/java/hudson/plugins/logparser/LogParserDisplayConsts.java
+++ b/src/main/java/hudson/plugins/logparser/LogParserDisplayConsts.java
@@ -33,7 +33,7 @@ public LogParserDisplayConsts() {
iconTable.put(LogParserConsts.ERROR, "red.gif");
iconTable.put(LogParserConsts.WARNING, "yellow.gif");
iconTable.put(LogParserConsts.INFO, "blue.gif");
- iconTable.put(LogParserConsts.DEBUG, "grey.gif");
+ iconTable.put(LogParserConsts.DEBUG, "gray.gif");
// How to display in link summary html
linkListDisplay.put(LogParserConsts.ERROR, "Error");
diff --git a/src/main/java/hudson/plugins/logparser/LogParserParser.java b/src/main/java/hudson/plugins/logparser/LogParserParser.java
index 47be62b..7fcdb7a 100755
--- a/src/main/java/hudson/plugins/logparser/LogParserParser.java
+++ b/src/main/java/hudson/plugins/logparser/LogParserParser.java
@@ -115,67 +115,62 @@ public LogParserResult parseLog(final Run, ?> build) throws IOException, Inter
}
// Open console log for reading and all other files for writing
- final BufferedWriter writer = new BufferedWriter(new FileWriter(
- parsedFilePath));
-
- // Record writers to links files in hash
- writers.put(LogParserConsts.ERROR, new BufferedWriter(new FileWriter(
- errorLinksFilePath)));
- writers.put(LogParserConsts.WARNING, new BufferedWriter(new FileWriter(
- warningLinksFilePath)));
- writers.put(LogParserConsts.INFO, new BufferedWriter(new FileWriter(
- infoLinksFilePath)));
- writers.put(LogParserConsts.DEBUG, new BufferedWriter(new FileWriter(
- debugLinksFilePath)));
- for (String extraTag : this.extraTags) {
- writers.put(extraTag, new BufferedWriter(new FileWriter(
- linksFilePathByExtraTags.get(extraTag))));
- }
-
- // Loop on the console log as long as there are input lines and parse
- // line by line
- // At the end of this loop, we will have:
- // - a parsed log with colored lines
- // - 4 links files which will be consolidated into one referencing html
- // file.
-
- // Create dummy header and section for beginning of log
- final String shortLink = " Beginning of log";
- LogParserWriter.writeHeaderTemplateToAllLinkFiles(writers, sectionCounter); // This enters a line which will later be
- // replaced by the actual header and count for
- // this header
- headerForSection.add(shortLink);
- writer.write(LogParserConsts.getHtmlOpeningTags());
-
- // write styles for log body
- final String styles = "\n";
- writer.write(styles);
-
- if (this.preformattedHtml)
- writer.write("");
- // Read bulks of lines, parse
- parseLogBody(build, writer, log,
- logger);
-
- // Write parsed output, links, etc.
- //writeLogBody();
-
- // Close html footer
- if (this.preformattedHtml)
- writer.write("
");
- writer.write(LogParserConsts.getHtmlClosingTags());
- writer.close(); // Close to unlock and flush to disk.
-
- writers.get(LogParserConsts.ERROR).close();
- writers.get(LogParserConsts.WARNING).close();
- writers.get(LogParserConsts.INFO).close();
- writers.get(LogParserConsts.DEBUG).close();
- for (String extraTag : this.extraTags) {
- writers.get(extraTag).close();
+ try (final BufferedWriter writer = new BufferedWriter(new FileWriter(parsedFilePath))) {
+
+ // Record writers to links files in hash
+ writers.put(LogParserConsts.ERROR, new BufferedWriter(new FileWriter(
+ errorLinksFilePath)));
+ writers.put(LogParserConsts.WARNING, new BufferedWriter(new FileWriter(
+ warningLinksFilePath)));
+ writers.put(LogParserConsts.INFO, new BufferedWriter(new FileWriter(
+ infoLinksFilePath)));
+ writers.put(LogParserConsts.DEBUG, new BufferedWriter(new FileWriter(
+ debugLinksFilePath)));
+ for (String extraTag : this.extraTags) {
+ writers.put(extraTag, new BufferedWriter(new FileWriter(
+ linksFilePathByExtraTags.get(extraTag))));
+ }
+
+ // Loop on the console log as long as there are input lines and parse
+ // line by line
+ // At the end of this loop, we will have:
+ // - a parsed log with colored lines
+ // - 4 links files which will be consolidated into one referencing html
+ // file.
+
+ // Create dummy header and section for beginning of log
+ final String shortLink = " Beginning of log";
+ LogParserWriter.writeHeaderTemplateToAllLinkFiles(writers, sectionCounter); // This enters a line which will later be
+ // replaced by the actual header and count for
+ // this header
+ headerForSection.add(shortLink);
+ writer.write(LogParserConsts.getHtmlOpeningTags());
+
+ // write styles for log body
+ final String styles = "\n";
+ writer.write(styles);
+
+ if (this.preformattedHtml)
+ writer.write("");
+ // Read bulks of lines, parse
+ parseLogBody(build, writer, log,
+ logger);
+
+ // Write parsed output, links, etc.
+ //writeLogBody();
+
+ // Close html footer
+ if (this.preformattedHtml)
+ writer.write("
");
+ writer.write(LogParserConsts.getHtmlClosingTags());
+ } finally {
+ for (BufferedWriter writer : writers.values()) {
+ writer.close();
+ }
}
// Build the reference html from the warnings/errors/info html files
@@ -353,22 +348,20 @@ 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.
- final InputStreamReader streamReader = new InputStreamReader(
- build.getLogInputStream(),
- build.getCharset() );
- final BufferedReader reader = new BufferedReader( streamReader );
- String line;
- String status;
- int line_num = 0;
- while ((line = reader.readLine()) != null) {
- status = lineStatusMatches.get(String.valueOf(line_num));
- final String parsedLine = parseLine(line, status);
- // This is for displaying sections in the links part
- writer.write(parsedLine);
- writer.newLine(); // Write system dependent end of line.
- line_num++;
+ try (final InputStreamReader streamReader = new InputStreamReader(build.getLogInputStream(), build.getCharset());
+ final BufferedReader reader = new BufferedReader(streamReader)) {
+ String line;
+ String status;
+ int line_num = 0;
+ while ((line = reader.readLine()) != null) {
+ status = lineStatusMatches.get(String.valueOf(line_num));
+ final String parsedLine = parseLine(line, status);
+ // This is for displaying sections in the links part
+ writer.write(parsedLine);
+ writer.newLine(); // Write system dependent end of line.
+ line_num++;
+ }
}
- reader.close();
// Logging information - end
final Calendar calendarEnd = Calendar.getInstance();
diff --git a/src/main/java/hudson/plugins/logparser/LogParserStatusComputer.java b/src/main/java/hudson/plugins/logparser/LogParserStatusComputer.java
index 6d47214..46965f7 100755
--- a/src/main/java/hudson/plugins/logparser/LogParserStatusComputer.java
+++ b/src/main/java/hudson/plugins/logparser/LogParserStatusComputer.java
@@ -71,69 +71,66 @@ private HashMap computeStatusMatches(
logger.log(Level.INFO, "Local temp file:" + tempFileLocation);
- final BufferedReader reader = new BufferedReader(new InputStreamReader(
- tempFilePath.read()));
- int threadCounter = 0;
-
- final ArrayList runners = new ArrayList<>();
- final LogParserReader logParserReader = new LogParserReader(reader);
-
- //ExecutorService execSvc = Executors.newFixedThreadPool(
- // LogParserUtils.getNumThreads() );
- final ExecutorService execSvc = Executors.newCachedThreadPool();
- int linesInLog = LogParserUtils.countLines(tempFileLocation);
- final int threadsNeeded = linesInLog
- / LogParserUtils.getLinesPerThread() + 1;
-
- // Read and parse the log parts. Keep the threads and results in an
- // array for future reference when writing
- for (int i = 0; i < threadsNeeded; i++) {
- //logger.log(Level.INFO,"LogParserParser: Open thread #"+threadCounter);
- final LogParserThread logParserThread = new LogParserThread(
- logParserReader, parsingRulesArray, compiledPatterns,
- threadCounter);
- //logParserThread.start();
- runners.add(logParserThread);
- execSvc.execute(logParserThread);
- threadCounter++;
- }
+ try (final BufferedReader reader = new BufferedReader(new InputStreamReader(tempFilePath.read()))) {
+ int threadCounter = 0;
+
+ final ArrayList runners = new ArrayList<>();
+ final LogParserReader logParserReader = new LogParserReader(reader);
+
+ //ExecutorService execSvc = Executors.newFixedThreadPool(
+ // LogParserUtils.getNumThreads() );
+ final ExecutorService execSvc = Executors.newCachedThreadPool();
+ int linesInLog = LogParserUtils.countLines(tempFileLocation);
+ final int threadsNeeded = linesInLog
+ / LogParserUtils.getLinesPerThread() + 1;
+
+ // Read and parse the log parts. Keep the threads and results in an
+ // array for future reference when writing
+ for (int i = 0; i < threadsNeeded; i++) {
+ //logger.log(Level.INFO,"LogParserParser: Open thread #"+threadCounter);
+ final LogParserThread logParserThread = new LogParserThread(
+ logParserReader, parsingRulesArray, compiledPatterns,
+ threadCounter);
+ //logParserThread.start();
+ runners.add(logParserThread);
+ execSvc.execute(logParserThread);
+ threadCounter++;
+ }
- // Wait for all threads to finish before sequentially writing the
- // outcome
- execSvc.shutdown();
- execSvc.awaitTermination(3600, TimeUnit.SECONDS);
-
- // Sort the threads in the order of the log parts they read
- // It could be that thread #1 read log part #2 and thread #2 read log
- // part #1
-
- final int runnersSize = runners.size();
- LogParserThread[] sortedRunners = new LogParserThread[runnersSize];
- for (LogParserThread logParserThread : runners) {
- final LogParserLogPart logPart = logParserThread.getLogPart();
- if (logPart != null) {
- final int logPartNum = logPart.getLogPartNum();
- sortedRunners[logPartNum] = logParserThread;
+ // Wait for all threads to finish before sequentially writing the
+ // outcome
+ execSvc.shutdown();
+ execSvc.awaitTermination(3600, TimeUnit.SECONDS);
+
+ // Sort the threads in the order of the log parts they read
+ // It could be that thread #1 read log part #2 and thread #2 read log
+ // part #1
+
+ final int runnersSize = runners.size();
+ LogParserThread[] sortedRunners = new LogParserThread[runnersSize];
+ for (LogParserThread logParserThread : runners) {
+ final LogParserLogPart logPart = logParserThread.getLogPart();
+ if (logPart != null) {
+ final int logPartNum = logPart.getLogPartNum();
+ sortedRunners[logPartNum] = logParserThread;
+ }
}
- }
- final HashMap result = new HashMap<>();
- HashMap moreLineStatusMatches;
- for (int i = 0; i < runnersSize; i++) {
- final LogParserThread logParserThread = sortedRunners[i];
- if (logParserThread != null) {
- moreLineStatusMatches = getLineStatusMatches(
- logParserThread.getLineStatuses(), i);
- result.putAll(moreLineStatusMatches);
+ final HashMap result = new HashMap<>();
+ HashMap moreLineStatusMatches;
+ for (int i = 0; i < runnersSize; i++) {
+ final LogParserThread logParserThread = sortedRunners[i];
+ if (logParserThread != null) {
+ moreLineStatusMatches = getLineStatusMatches(
+ logParserThread.getLineStatuses(), i);
+ result.putAll(moreLineStatusMatches);
+ }
}
+ return result;
+ } finally {
+ // Delete temp file
+ tempFilePath.delete();
}
-
- reader.close(); // Close to unlock.
-
- // Delete temp file
- tempFilePath.delete();
-
- return result;
// SLAVE PART END
}
diff --git a/src/main/java/hudson/plugins/logparser/LogParserUtils.java b/src/main/java/hudson/plugins/logparser/LogParserUtils.java
index d8b4fb8..74bf91c 100755
--- a/src/main/java/hudson/plugins/logparser/LogParserUtils.java
+++ b/src/main/java/hudson/plugins/logparser/LogParserUtils.java
@@ -145,16 +145,15 @@ public static int getLinesPerThread() {
}
public static int countLines(final String filename) throws IOException {
- final LineNumberReader reader = new LineNumberReader(new FileReader(
- filename));
- int count = 0;
- while (reader.readLine() != null) {
- // Read the whole file to count the lines.
- count++;
+ try (final LineNumberReader reader = new LineNumberReader(new FileReader(filename))) {
+ int count = 0;
+ while (reader.readLine() != null) {
+ // Read the whole file to count the lines.
+ count++;
+ }
+ count = reader.getLineNumber();
+ return count;
}
- count = reader.getLineNumber();
- reader.close();
- return count;
}
private LogParserUtils() {
diff --git a/src/main/java/hudson/plugins/logparser/LogParserWriter.java b/src/main/java/hudson/plugins/logparser/LogParserWriter.java
index d7fe719..10f86f0 100755
--- a/src/main/java/hudson/plugins/logparser/LogParserWriter.java
+++ b/src/main/java/hudson/plugins/logparser/LogParserWriter.java
@@ -18,14 +18,9 @@ public static void writeHeaderTemplateToAllLinkFiles(
final HashMap writers,
final int sectionCounter) throws IOException {
final List statuses = LogParserConsts.STATUSES_WITH_SECTIONS_IN_LINK_FILES;
- final int statusesSize = statuses.size();
- for (int i = 0; i < statusesSize; i++) {
- final String currentStatus = (String) statuses.get(i);
- final BufferedWriter linkWriter = (BufferedWriter) writers
- .get(currentStatus);
- String str = "HEADER HERE: #NUMBER";
- str = str.replaceFirst("NUMBER",
- ((Integer) sectionCounter).toString());
+ for (String status : statuses) {
+ final BufferedWriter linkWriter = writers.get(status);
+ String str = "HEADER HERE: #" + sectionCounter;
linkWriter.write(str + "\n");
}
@@ -41,10 +36,9 @@ public static void writeWrapperHtml(final String buildWrapperPath)
+ "build log\n" + "\n"
+ "\n";
- final BufferedWriter writer = new BufferedWriter(new FileWriter(
- buildWrapperPath));
- writer.write(wrapperHtml);
- writer.close();
+ try (final BufferedWriter writer = new BufferedWriter(new FileWriter(buildWrapperPath))) {
+ writer.write(wrapperHtml);
+ }
}
public static void writeReferenceHtml(final String buildRefPath,
@@ -63,36 +57,34 @@ public static void writeReferenceHtml(final String buildRefPath,
+ "\t\telement.display == 'none' ? element.display='block' : element.display='none';\n"
+ "\t}\n" + "\n";
- final BufferedWriter writer = new BufferedWriter(new FileWriter(
- buildRefPath));
- // Hudson stylesheets
- writer.write(LogParserConsts.getHtmlOpeningTags());
- writer.write(refStart); // toggle links javascript
- // Write Errors
- writeLinks(writer, LogParserConsts.ERROR, headerForSection,
- statusCountPerSection, iconTable, linkListDisplay,
- linkListDisplayPlural, statusCount, linkFiles);
- // Write Warnings
- writeLinks(writer, LogParserConsts.WARNING, headerForSection,
- statusCountPerSection, iconTable, linkListDisplay,
- linkListDisplayPlural, statusCount, linkFiles);
- // Write Infos
- writeLinks(writer, LogParserConsts.INFO, headerForSection,
- statusCountPerSection, iconTable, linkListDisplay,
- linkListDisplayPlural, statusCount, linkFiles);
- // Write Debugs
- writeLinks(writer, LogParserConsts.DEBUG, headerForSection,
- statusCountPerSection, iconTable, linkListDisplay,
- linkListDisplayPlural, statusCount, linkFiles);
- // Write extra tags
- for (String extraTag : extraTags) {
- writeLinks(writer, extraTag, headerForSection,
+ try (final BufferedWriter writer = new BufferedWriter(new FileWriter(buildRefPath))) {
+ // Hudson stylesheets
+ writer.write(LogParserConsts.getHtmlOpeningTags());
+ writer.write(refStart); // toggle links javascript
+ // Write Errors
+ writeLinks(writer, LogParserConsts.ERROR, headerForSection,
+ statusCountPerSection, iconTable, linkListDisplay,
+ linkListDisplayPlural, statusCount, linkFiles);
+ // Write Warnings
+ writeLinks(writer, LogParserConsts.WARNING, headerForSection,
+ statusCountPerSection, iconTable, linkListDisplay,
+ linkListDisplayPlural, statusCount, linkFiles);
+ // Write Infos
+ writeLinks(writer, LogParserConsts.INFO, headerForSection,
+ statusCountPerSection, iconTable, linkListDisplay,
+ linkListDisplayPlural, statusCount, linkFiles);
+ // Write Debugs
+ writeLinks(writer, LogParserConsts.DEBUG, headerForSection,
statusCountPerSection, iconTable, linkListDisplay,
linkListDisplayPlural, statusCount, linkFiles);
+ // Write extra tags
+ for (String extraTag : extraTags) {
+ writeLinks(writer, extraTag, headerForSection,
+ statusCountPerSection, iconTable, linkListDisplay,
+ linkListDisplayPlural, statusCount, linkFiles);
+ }
+ writer.write(LogParserConsts.getHtmlClosingTags());
}
- writer.write(LogParserConsts.getHtmlClosingTags());
- writer.close(); // Close to unlock and flush to disk.
-
}
private static void writeLinks(final BufferedWriter writer,
@@ -118,7 +110,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/images/16x16/", Functions.getResourcePath());
+ final String iconLocation = String.format("%s/plugin/log-parser/images/", jenkins.model.Jenkins.RESOURCE_PATH).substring(1);
final String styles =
"\n";
writer.write(styles);
- final String linksStart = "\n"
+ ""
+ linkListDisplayStr + " (" + linkListCount + ")
\n"
@@ -139,49 +131,48 @@ private static void writeLinks(final BufferedWriter writer,
writer.write(linksStart);
// Read the links file and insert here
- final 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:";
- final String headerTemplateSplitBy = "#";
-
- // If it's a header line - put the header of the section
- String line;
- while ((line = reader.readLine()) != null) {
- String curSummaryLine = null;
- if (line.startsWith(headerTemplateRegexp)) {
- final int headerNum = Integer.parseInt(line.split(headerTemplateSplitBy)[1]);
- line = headerForSection.get(headerNum);
- final String key = LogParserUtils.getSectionCountKey(status, headerNum);
- final Integer summaryInt = statusCountPerSection.get(key);
- if (summaryInt == null || summaryInt == 0) {
- // Don't write the header if there are no relevant lines for
- // this section
- line = null;
- } else {
- String linkListDisplayStrWithPlural = linkListDisplayStr;
- if (summaryInt > 1) {
- linkListDisplayStrWithPlural = linkListDisplayStrPlural;
+ try (final 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:";
+ final String headerTemplateSplitBy = "#";
+
+ // If it's a header line - put the header of the section
+ String line;
+ while ((line = reader.readLine()) != null) {
+ String curSummaryLine = null;
+ if (line.startsWith(headerTemplateRegexp)) {
+ final int headerNum = Integer.parseInt(line.split(headerTemplateSplitBy)[1]);
+ line = headerForSection.get(headerNum);
+ final String key = LogParserUtils.getSectionCountKey(status, headerNum);
+ final Integer summaryInt = statusCountPerSection.get(key);
+ if (summaryInt == null || summaryInt == 0) {
+ // Don't write the header if there are no relevant lines for
+ // this section
+ line = null;
+ } else {
+ String linkListDisplayStrWithPlural = linkListDisplayStr;
+ if (summaryInt > 1) {
+ linkListDisplayStrWithPlural = linkListDisplayStrPlural;
+ }
+ curSummaryLine = summaryLine.replace("SUMMARY_INT_HERE",
+ summaryInt.toString()).replace(
+ "LINK_LIST_DISPLAY_STR",
+ linkListDisplayStrWithPlural);
}
- curSummaryLine = summaryLine.replace("SUMMARY_INT_HERE",
- summaryInt.toString()).replace(
- "LINK_LIST_DISPLAY_STR",
- linkListDisplayStrWithPlural);
- }
- }
+ }
- if (line != null) {
- writer.write(line);
- writer.newLine(); // Write system dependent end of line.
- }
- if (curSummaryLine != null) {
- writer.write(curSummaryLine);
- writer.newLine(); // Write system dependent end of line.
+ if (line != null) {
+ writer.write(line);
+ writer.newLine(); // Write system dependent end of line.
+ }
+ if (curSummaryLine != null) {
+ writer.write(curSummaryLine);
+ writer.newLine(); // Write system dependent end of line.
+ }
}
}
- reader.close(); // Close to unlock.
final String linksEnd = "\n";
writer.write(linksEnd);
diff --git a/src/main/java/hudson/plugins/logparser/ReadWriteTextFile.java b/src/main/java/hudson/plugins/logparser/ReadWriteTextFile.java
index 03e7891..ca57c46 100755
--- a/src/main/java/hudson/plugins/logparser/ReadWriteTextFile.java
+++ b/src/main/java/hudson/plugins/logparser/ReadWriteTextFile.java
@@ -8,8 +8,10 @@
import java.io.FileWriter;
import java.io.IOException;
import java.io.Writer;
+import java.util.logging.Logger;
public final class ReadWriteTextFile {
+ private static final Logger LOGGER = Logger.getLogger(ReadWriteTextFile.class.getName());
private ReadWriteTextFile() {
// to suppress PMD warning
@@ -18,19 +20,13 @@ private ReadWriteTextFile() {
static public String getContents(final File aFile) {
final StringBuilder contents = new StringBuilder();
- try {
- final BufferedReader input = new BufferedReader(new FileReader(
- aFile));
- try {
- String line = null; // not declared within while loop
- while ((line = input.readLine()) != null) {
- contents.append(line + "\n");
- }
- } finally {
- input.close();
+ try (final 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");
}
} catch (IOException ex) {
- ex.printStackTrace();
+ LOGGER.warning("Failure reading from " + aFile.getPath());
}
return contents.toString();
@@ -42,7 +38,12 @@ static public void setContents(final File aFile, final String aContents)
throw new IllegalArgumentException("File should not be null.");
}
if (!aFile.exists()) {
- aFile.createNewFile();
+ boolean created = aFile.createNewFile();
+ if (created) {
+ LOGGER.fine(aFile.getPath() + " created");
+ } else {
+ LOGGER.fine(aFile.getPath() + " already exists");
+ }
}
if (!aFile.isFile()) {
throw new IllegalArgumentException("Should not be a directory: "
@@ -54,12 +55,9 @@ static public void setContents(final File aFile, final String aContents)
}
// use buffering
- final Writer output = new BufferedWriter(new FileWriter(aFile));
- try {
+ try (final Writer output = new BufferedWriter(new FileWriter(aFile))) {
// FileWriter always assumes default encoding is OK!
output.write(aContents);
- } finally {
- output.close();
}
}
diff --git a/src/main/resources/index.jelly b/src/main/resources/index.jelly
new file mode 100644
index 0000000..331c7fd
--- /dev/null
+++ b/src/main/resources/index.jelly
@@ -0,0 +1,4 @@
+
+
+Parses the console log generated by a build
+
diff --git a/src/test/java/org/jenkinsci/plugins/logparser/BlockSlaveToMasterFileCallable.java b/src/test/java/org/jenkinsci/plugins/logparser/BlockSlaveToMasterFileCallable.java
deleted file mode 100644
index 00cfd8a..0000000
--- a/src/test/java/org/jenkinsci/plugins/logparser/BlockSlaveToMasterFileCallable.java
+++ /dev/null
@@ -1,52 +0,0 @@
-/*
- * The MIT License
- *
- * Copyright 2021 CloudBees, Inc.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- */
-
-package org.jenkinsci.plugins.logparser;
-
-import edu.umd.cs.findbugs.annotations.Nullable;
-import hudson.Extension;
-import hudson.remoting.ChannelBuilder;
-import java.io.File;
-import jenkins.ReflectiveFilePathFilter;
-import jenkins.SlaveToMasterFileCallable;
-import jenkins.security.ChannelConfigurator;
-
-/**
- * Prevents all {@link SlaveToMasterFileCallable}s from running during tests, to make sure we do not rely on them.
- */
-public class BlockSlaveToMasterFileCallable extends ReflectiveFilePathFilter {
-
- @Override protected boolean op(String name, File path) throws SecurityException {
- throw new SecurityException("refusing to " + name + " on " + path);
- }
-
- @Extension public static class ChannelConfiguratorImpl extends ChannelConfigurator {
-
- @Override public void onChannelBuilding(ChannelBuilder builder, @Nullable Object context) {
- new BlockSlaveToMasterFileCallable().installTo(builder, 1000); // higher priority than, say, AdminFilePathFilter or even DefaultFilePathFilter
- }
-
- }
-
-}
diff --git a/src/test/java/org/jenkinsci/plugins/logparser/LogParserWorkflowTest.java b/src/test/java/org/jenkinsci/plugins/logparser/LogParserWorkflowTest.java
index 50b6fcc..f152d58 100644
--- a/src/test/java/org/jenkinsci/plugins/logparser/LogParserWorkflowTest.java
+++ b/src/test/java/org/jenkinsci/plugins/logparser/LogParserWorkflowTest.java
@@ -10,12 +10,15 @@
import org.jenkinsci.plugins.workflow.job.WorkflowJob;
import org.junit.BeforeClass;
import org.junit.ClassRule;
-import org.junit.Ignore;
import org.junit.Test;
import org.jvnet.hudson.test.JenkinsRule;
import org.jvnet.hudson.test.ToolInstallations;
+import java.io.File;
+import java.net.URL;
+
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
/**
* In this test suite we initialize the Job workspaces with a resource (maven-project1.zip) that contains a Maven
@@ -34,7 +37,10 @@ public static void init() throws Exception {
WorkflowJob job = jenkinsRule.jenkins.createProject(WorkflowJob.class, "logParserPublisherWorkflowStep");
DumbSlave agent = jenkinsRule.createOnlineSlave();
FilePath workspace = agent.getWorkspaceFor(job);
- workspace.unzipFrom(LogParserWorkflowTest.class.getResourceAsStream("./maven-project1.zip"));
+ assertNotNull(workspace);
+ URL mavenProject = LogParserWorkflowTest.class.getResource("./maven-project1");
+ assertNotNull(mavenProject);
+ new FilePath(new File(mavenProject.toURI())).copyRecursiveTo(workspace);
job.setDefinition(new CpsFlowDefinition(""
+ "node('" + agent.getNodeName() + "') {\n"
+ " def mvnHome = tool '" + mavenInstallation.getName() + "'\n"
diff --git a/src/test/resources/org/jenkinsci/plugins/logparser/maven-project1.zip b/src/test/resources/org/jenkinsci/plugins/logparser/maven-project1.zip
deleted file mode 100644
index 8bbe46c..0000000
Binary files a/src/test/resources/org/jenkinsci/plugins/logparser/maven-project1.zip and /dev/null differ
diff --git a/src/test/resources/org/jenkinsci/plugins/logparser/maven-project1/.gitignore b/src/test/resources/org/jenkinsci/plugins/logparser/maven-project1/.gitignore
new file mode 100644
index 0000000..67cf78c
--- /dev/null
+++ b/src/test/resources/org/jenkinsci/plugins/logparser/maven-project1/.gitignore
@@ -0,0 +1,61 @@
+# Created by .ignore support plugin (hsz.mobi)
+### Maven template
+target/
+pom.xml.tag
+pom.xml.releaseBackup
+pom.xml.versionsBackup
+pom.xml.next
+release.properties
+dependency-reduced-pom.xml
+buildNumber.properties
+.mvn/timing.properties
+
+
+### JetBrains template
+# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio
+
+*.iml
+
+## Directory-based project format:
+.idea/
+# if you remove the above rule, at least ignore the following:
+
+# User-specific stuff:
+# .idea/workspace.xml
+# .idea/tasks.xml
+# .idea/dictionaries
+
+# Sensitive or high-churn files:
+# .idea/dataSources.ids
+# .idea/dataSources.xml
+# .idea/sqlDataSources.xml
+# .idea/dynamic.xml
+# .idea/uiDesigner.xml
+
+# Gradle:
+# .idea/gradle.xml
+# .idea/libraries
+
+# Mongo Explorer plugin:
+# .idea/mongoSettings.xml
+
+## File-based project format:
+*.ipr
+*.iws
+
+## Plugin-specific files:
+
+# IntelliJ
+/out/
+
+# mpeltonen/sbt-idea plugin
+.idea_modules/
+
+# JIRA plugin
+atlassian-ide-plugin.xml
+
+# Crashlytics plugin (for Android Studio and IntelliJ)
+com_crashlytics_export_strings.xml
+crashlytics.properties
+crashlytics-build.properties
+
diff --git a/src/test/resources/org/jenkinsci/plugins/logparser/maven-project1/Jenkinsfile b/src/test/resources/org/jenkinsci/plugins/logparser/maven-project1/Jenkinsfile
new file mode 100644
index 0000000..6ab173a
--- /dev/null
+++ b/src/test/resources/org/jenkinsci/plugins/logparser/maven-project1/Jenkinsfile
@@ -0,0 +1,3 @@
+node {
+ echo 'Hello World 6'
+}
diff --git a/src/test/resources/org/jenkinsci/plugins/logparser/maven-project1/doc.txt b/src/test/resources/org/jenkinsci/plugins/logparser/maven-project1/doc.txt
new file mode 100644
index 0000000..c372db4
--- /dev/null
+++ b/src/test/resources/org/jenkinsci/plugins/logparser/maven-project1/doc.txt
@@ -0,0 +1 @@
+test9
diff --git a/src/test/resources/org/jenkinsci/plugins/logparser/maven-project1/logparser-rules.txt b/src/test/resources/org/jenkinsci/plugins/logparser/maven-project1/logparser-rules.txt
new file mode 100644
index 0000000..2207fc7
--- /dev/null
+++ b/src/test/resources/org/jenkinsci/plugins/logparser/maven-project1/logparser-rules.txt
@@ -0,0 +1,5 @@
+warn /\[WARNING\]/
+
+jenkins /JENKINS/
+
+logParserPublisherWorkflowStep /\[Pipeline\] logParser/
\ No newline at end of file
diff --git a/src/test/resources/org/jenkinsci/plugins/logparser/maven-project1/pom.xml b/src/test/resources/org/jenkinsci/plugins/logparser/maven-project1/pom.xml
new file mode 100644
index 0000000..ba0fe6e
--- /dev/null
+++ b/src/test/resources/org/jenkinsci/plugins/logparser/maven-project1/pom.xml
@@ -0,0 +1,98 @@
+
+ 4.0.0
+ com.cloudbees.manticore
+ example
+ jar
+ 1.0-SNAPSHOT
+ example
+ http://maven.apache.org
+
+
+ com.opencsv
+ opencsv
+ 3.5
+
+
+ org.apache.struts
+ struts2-core
+ 2.3.20
+
+
+ junit
+ junit
+ 3.8.1
+ test
+
+
+
+
+ UTF-8
+ UTF-8
+ UTF-8
+ 1.8
+ 1.8
+
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-pmd-plugin
+ 3.5
+
+
+ verify-cpd
+
+
+ cpd-check
+
+
+
+
+ true
+ 25
+ true
+ false
+
+
+
+
+
diff --git a/src/test/resources/org/jenkinsci/plugins/logparser/maven-project1/src/main/java/com/cloudbees/manticore/App.java b/src/test/resources/org/jenkinsci/plugins/logparser/maven-project1/src/main/java/com/cloudbees/manticore/App.java
new file mode 100644
index 0000000..12a7206
--- /dev/null
+++ b/src/test/resources/org/jenkinsci/plugins/logparser/maven-project1/src/main/java/com/cloudbees/manticore/App.java
@@ -0,0 +1,55 @@
+package com.cloudbees.manticore;
+
+/**
+ * Hello world!
+ *
+ */
+public class App
+{
+ public static void main( String[] args ) {
+ System.out.println( "Hello World!" );
+ }
+
+ private int partition(int arr[], int left, int right) {
+ int i = left, j = right;
+ int tmp;
+ int pivot = arr[(left + right) / 2];
+
+ while (i <= j) {
+ while (arr[i] < pivot) {
+ i++;
+ }
+ while (arr[j] > pivot) {
+ j--;
+ }
+ if (i <= j) {
+ tmp = arr[i];
+ arr[i] = arr[j];
+ arr[j] = tmp;
+ i++;
+ j--;
+ }
+ };
+ return i;
+ }
+
+ private void quickSort(int arr[], int left, int right) {
+ int index = partition(arr, left, right);
+ if (left < index - 1) {
+ this.quickSort(arr, left, index - 1);
+ }
+ if (index < right) {
+ this.quickSort(arr, index, right);
+ }
+ }
+
+ private void quickSort2(int arr[], int left, int right) {
+ int index = partition(arr, left, right);
+ if (left < index - 1) {
+ this.quickSort(arr, left, index - 1);
+ }
+ if (index < right) {
+ this.quickSort(arr, index, right);
+ }
+ }
+}
diff --git a/src/test/resources/org/jenkinsci/plugins/logparser/maven-project1/src/test/java/com/cloudbees/manticore/AppTest.java b/src/test/resources/org/jenkinsci/plugins/logparser/maven-project1/src/test/java/com/cloudbees/manticore/AppTest.java
new file mode 100644
index 0000000..cdd09be
--- /dev/null
+++ b/src/test/resources/org/jenkinsci/plugins/logparser/maven-project1/src/test/java/com/cloudbees/manticore/AppTest.java
@@ -0,0 +1,38 @@
+package com.cloudbees.manticore;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+/**
+ * Unit test for simple App.
+ */
+public class AppTest
+ extends TestCase
+{
+ /**
+ * Create the test case
+ *
+ * @param testName name of the test case
+ */
+ public AppTest( String testName )
+ {
+ super( testName );
+ }
+
+ /**
+ * @return the suite of tests being tested
+ */
+ public static Test suite()
+ {
+ return new TestSuite( AppTest.class );
+ }
+
+ /**
+ * Rigourous Test :-)
+ */
+ public void testApp()
+ {
+ assertTrue( true );
+ }
+}