Skip to content

Commit

Permalink
Merge branch 'release/2.2'
Browse files Browse the repository at this point in the history
  • Loading branch information
hypery2k committed Dec 17, 2021
2 parents 13dbf9e + 7ceac0b commit 1d6f18d
Show file tree
Hide file tree
Showing 13 changed files with 70 additions and 72 deletions.
6 changes: 3 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# (2019-07-01)
# (2021-12-17)


### Bug Fixes

* docker-compose up doesn't support --rm ([d613f5e](https://github.com/jenkinsci/log-parser-plugin/commit/d613f5e))
* Now Jenkins is available on port 8081 and boots ([f269c53](https://github.com/jenkinsci/log-parser-plugin/commit/f269c53))
* docker-compose up doesn't support --rm ([d613f5e](https://github.com/jenkinsci/log-parser-plugin/commit/d613f5ef8a166edc518f580165a8367746a463c0))
* Now Jenkins is available on port 8081 and boots ([f269c53](https://github.com/jenkinsci/log-parser-plugin/commit/f269c53fa0ddb5ae28ae3719afe6d6ee3ccc9d8e))



2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<artifactId>log-parser</artifactId>
<packaging>hpi</packaging>
<name>Log Parser Plugin</name>
<version>2.1</version>
<version>2.2</version>
<url>https://wiki.jenkins-ci.org/display/JENKINS/Log+Parser+Plugin</url>
<description>Parses the console log generated by a build</description>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class CompiledPatterns {
public CompiledPatterns() {
this.errorMsg = null;
this.compiledPatterns = null;
this.extraTags = new ArrayList<String>();
this.extraTags = new ArrayList<>();
}

public String getError() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ private Area calcDefaultSize() {

private CategoryDataset buildDataSet() {

DataSetBuilder<String, ChartUtil.NumberOnlyBuildLabel> dsb = new DataSetBuilder<String, ChartUtil.NumberOnlyBuildLabel>();
DataSetBuilder<String, ChartUtil.NumberOnlyBuildLabel> dsb = new DataSetBuilder<>();

for (LogParserAction a = this; a != null; a = a.getPreviousAction()) {
dsb.add(a.result.getTotalErrors(), "errors",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public class LogParserConsts {
public static final List<String> STATUSES_WITH_SECTIONS_IN_LINK_FILES = Arrays.asList(ERROR, WARNING, DEBUG);

public static String getHtmlOpeningTags() {
final String hudsonRoot = Jenkins.getActiveInstance().getRootUrl();
final String hudsonRoot = Jenkins.get().getRootUrl();
return "<!DOCTYPE html>\n" + "<html>\n" + "\t<head>\n"
+ "\t\t<title>log-parser plugin page</title>\n"
+ "\t\t<link type=\"text/css\" rel=\"stylesheet\" href=\""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@

public class LogParserDisplayConsts {

final private HashMap<String, String> colorTable = new HashMap<String, String>();
final private HashMap<String, String> iconTable = new HashMap<String, String>();
final private HashMap<String, String> linkListDisplay = new HashMap<String, String>();
final private HashMap<String, String> linkListDisplayPlural = new HashMap<String, String>();
final private HashMap<String, String> colorTable = new HashMap<>();
final private HashMap<String, String> iconTable = new HashMap<>();
final private HashMap<String, String> linkListDisplay = new HashMap<>();
final private HashMap<String, String> linkListDisplayPlural = new HashMap<>();

public static final String DEFAULT_COLOR = "blue";
public static final String DEFAULT_ICON = "blue.gif";
Expand Down
48 changes: 24 additions & 24 deletions src/main/java/hudson/plugins/logparser/LogParserParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,18 @@

public class LogParserParser {

final private HashMap<String, Integer> statusCount = new HashMap<String, Integer>();
final private HashMap<String, BufferedWriter> writers = new HashMap<String, BufferedWriter>();
final private HashMap<String, String> linkFiles = new HashMap<String, String>();
final private HashMap<String, Integer> statusCount = new HashMap<>();
final private HashMap<String, BufferedWriter> writers = new HashMap<>();
final private HashMap<String, String> linkFiles = new HashMap<>();

final private String[] parsingRulesArray;
final private Pattern[] compiledPatterns;
final private CompiledPatterns compiledPatternsPlusError;
final private List<String> extraTags;

// if key is 3-ERROR it shows how many errors are in section 3
final private HashMap<String, Integer> statusCountPerSection = new HashMap<String, Integer>();
final private ArrayList<String> headerForSection = new ArrayList<String>();
final private HashMap<String, Integer> statusCountPerSection = new HashMap<>();
final private ArrayList<String> headerForSection = new ArrayList<>();
private int sectionCounter = 0;

final private LogParserDisplayConsts displayConstants = new LogParserDisplayConsts();
Expand Down Expand Up @@ -79,7 +79,7 @@ public LogParserParser(final FilePath parsingRulesFile,
* errorLinks.html, warningLinks.html, infoLinks.html
*/
@Deprecated
public LogParserResult parseLog(final AbstractBuild build) throws IOException, InterruptedException {
public LogParserResult parseLog(final AbstractBuild<?, ?> build) throws IOException, InterruptedException {
return this.parseLog((Run<?, ?>) build);
}

Expand All @@ -98,7 +98,7 @@ public LogParserResult parseLog(final Run<?, ?> build) throws IOException, Inter
final String warningLinksFilePath = logDirectory + "/logwarningLinks.html";
final String infoLinksFilePath = logDirectory + "/loginfoLinks.html";
final String debugLinksFilePath = logDirectory + "/logdebugLinks.html";
final Map<String, String> linksFilePathByExtraTags = new HashMap<String, String>();
final Map<String, String> linksFilePathByExtraTags = new HashMap<>();
for (String extraTag : this.extraTags) {
linksFilePathByExtraTags.put(extraTag, logDirectory + "/log" + extraTag + "Links.html");
}
Expand Down Expand Up @@ -170,12 +170,12 @@ public LogParserResult parseLog(final Run<?, ?> build) throws IOException, Inter
writer.write(LogParserConsts.getHtmlClosingTags());
writer.close(); // Close to unlock and flush to disk.

((BufferedWriter) writers.get(LogParserConsts.ERROR)).close();
((BufferedWriter) writers.get(LogParserConsts.WARNING)).close();
((BufferedWriter) writers.get(LogParserConsts.INFO)).close();
((BufferedWriter) writers.get(LogParserConsts.DEBUG)).close();
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) {
((BufferedWriter) writers.get(extraTag)).close();
writers.get(extraTag).close();
}

// Build the reference html from the warnings/errors/info html files
Expand All @@ -195,12 +195,12 @@ public LogParserResult parseLog(final Run<?, ?> build) throws IOException, Inter
// Create result class
final LogParserResult result = new LogParserResult();
result.setHtmlLogFile(parsedFilePath);
result.setTotalErrors((Integer) statusCount.get(LogParserConsts.ERROR));
result.setTotalWarnings((Integer) statusCount.get(LogParserConsts.WARNING));
result.setTotalInfos((Integer) statusCount.get(LogParserConsts.INFO));
result.setTotalDebugs((Integer) statusCount.get(LogParserConsts.DEBUG));
result.setTotalErrors(statusCount.get(LogParserConsts.ERROR));
result.setTotalWarnings(statusCount.get(LogParserConsts.WARNING));
result.setTotalInfos(statusCount.get(LogParserConsts.INFO));
result.setTotalDebugs(statusCount.get(LogParserConsts.DEBUG));
for (String extraTag : this.extraTags) {
result.putTotalCountsByExtraTag(extraTag, (Integer) statusCount.get(extraTag));
result.putTotalCountsByExtraTag(extraTag, statusCount.get(extraTag));
}
result.setErrorLinksFile(errorLinksFilePath);
result.setWarningLinksFile(warningLinksFilePath);
Expand Down Expand Up @@ -260,25 +260,25 @@ public String parseLine(final String line, final String status)
}

public void incrementCounter(final String status) {
final int currentVal = (Integer) statusCount.get(status);
final int currentVal = statusCount.get(status);
statusCount.put(status, currentVal + 1);
}

public void incrementCounterPerSection(final String status,
final int sectionNumber) {
final String key = LogParserUtils.getSectionCountKey(status,
sectionNumber);
Integer currentValInteger = (Integer) statusCountPerSection.get(key);
Integer currentValInteger = statusCountPerSection.get(key);
// No value - entered yet - initialize with 0
if (currentValInteger == null) {
currentValInteger = new Integer(0);
currentValInteger = 0;
}
final int newVal = currentValInteger + 1;
statusCountPerSection.put(key, newVal);
}

private String colorLine(final String line, final String status) {
String color = (String) displayConstants.getColorTable().get(status);
String color = displayConstants.getColorTable().get(status);
if (color == null) {
color = LogParserDisplayConsts.DEFAULT_COLOR;
}
Expand All @@ -296,8 +296,8 @@ private String addMarkerAndLink(final String line,
final String effectiveStatus, final String status)
throws IOException {
// Add marker
final String statusCountStr = ((Integer) statusCount
.get(effectiveStatus)).toString();
final String statusCountStr = statusCount
.get(effectiveStatus).toString();
final String marker = effectiveStatus + statusCountStr;

// Add link
Expand Down Expand Up @@ -361,7 +361,7 @@ private void parseLogBody(final Run<?, ?> build, final BufferedWriter writer, fi
String status;
int line_num = 0;
while ((line = reader.readLine()) != null) {
status = (String) lineStatusMatches.get(String.valueOf(line_num));
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@
import hudson.Launcher;
import hudson.Util;
import hudson.model.Action;
import hudson.model.BuildListener;
import hudson.model.Result;
import hudson.model.AbstractBuild;
import hudson.model.AbstractProject;
import hudson.model.Run;
import hudson.model.TaskListener;
Expand Down Expand Up @@ -149,14 +147,14 @@ public void perform(Run<?, ?> build, FilePath workspace, Launcher launcher, Task

@Override
public BuildStepDescriptor<Publisher> getDescriptor() {
return Jenkins.getInstance().getDescriptorByType(LogParserPublisher.DescriptorImpl.class);
return Jenkins.get().getDescriptorByType(LogParserPublisher.DescriptorImpl.class);
}

@Extension @Symbol("logParser")
public static final class DescriptorImpl extends
BuildStepDescriptor<Publisher> {

private List<ParserRuleFile> parsingRulesGlobal = new ArrayList<ParserRuleFile>();
private List<ParserRuleFile> parsingRulesGlobal = new ArrayList<>();
private boolean useLegacyFormatting = false;

public DescriptorImpl() {
Expand Down Expand Up @@ -202,7 +200,7 @@ public void setLegacyFormatting(boolean useLegacyFormatting) {
public boolean configure(final StaplerRequest req, final JSONObject json)
throws FormException {
useLegacyFormatting = false;
parsingRulesGlobal = new ArrayList();
parsingRulesGlobal = new ArrayList<>();
req.bindJSON(this, json);
save();
return true;
Expand Down
13 changes: 10 additions & 3 deletions src/main/java/hudson/plugins/logparser/LogParserResult.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,29 @@ public class LogParserResult {
private int totalWarnings = 0;
private int totalInfos = 0;
private int totalDebugs = 0;
private Map<String, Integer> totalCountsByExtraTag = new HashMap<String, Integer>();
private final Map<String, Integer> totalCountsByExtraTag = new HashMap<>();

private String htmlLogFile;
private String errorLinksFile;
private String warningLinksFile;
private String infoLinksFile;
private String debugLinksFile;
private Map<String, String> linkedFilesByExtraTag = new HashMap<String, String>();
private Set<String> extraTags = new HashSet<String>();
private final Map<String, String> linkedFilesByExtraTag = new HashMap<>();
private Set<String> extraTags = new HashSet<>();

private String parsedLogURL;
private String htmlLogPath;

private String failedToParseError;
private String badParsingRulesError;

protected Object readResolve() {
if (extraTags == null) { // avoid NPE when deserializing old results
extraTags = new HashSet<>();
}
return this;
}

public String getBadParsingRulesError() {
return badParsingRulesError;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package hudson.plugins.logparser;

import hudson.FilePath;
import hudson.remoting.VirtualChannel;
import hudson.remoting.RemoteInputStream;
import jenkins.security.MasterToSlaveCallable;

Expand Down Expand Up @@ -74,7 +75,7 @@ private HashMap<String, String> computeStatusMatches(
tempFilePath.read()));
int threadCounter = 0;

final ArrayList<LogParserThread> runners = new ArrayList<LogParserThread>();
final ArrayList<LogParserThread> runners = new ArrayList<>();
final LogParserReader logParserReader = new LogParserReader(reader);

//ExecutorService execSvc = Executors.newFixedThreadPool(
Expand Down Expand Up @@ -116,7 +117,7 @@ private HashMap<String, String> computeStatusMatches(
}
}

final HashMap<String, String> result = new HashMap<String, String>();
final HashMap<String, String> result = new HashMap<>();
HashMap<String, String> moreLineStatusMatches;
for (int i = 0; i < runnersSize; i++) {
final LogParserThread logParserThread = sortedRunners[i];
Expand All @@ -138,7 +139,7 @@ private HashMap<String, String> computeStatusMatches(

private HashMap<String, String> getLineStatusMatches(
final String[] statuses, final int logPart) {
final HashMap<String, String> result = new HashMap<String, String>();
final HashMap<String, String> result = new HashMap<>();
String status;
int line_num;
final int linesPerThread = LogParserUtils.getLinesPerThread();
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/hudson/plugins/logparser/LogParserUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public static CompiledPatterns compilePatterns(

Pattern[] result = new Pattern[parsingRulesArray.length];
final StringBuffer badParsingRules = new StringBuffer();
List<String> extraTags = new ArrayList<String>();
List<String> extraTags = new ArrayList<>();

for (int i = 0; i < parsingRulesArray.length; i++) {
final String parsingRule = parsingRulesArray[i];
Expand Down Expand Up @@ -109,7 +109,7 @@ public static CompiledPatterns compilePatterns(

public static String getSectionCountKey(final String status,
final int sectionNumber) {
return Integer.toString(sectionNumber) + "-" + status;
return sectionNumber + "-" + status;
}

public static int getNumThreads() {
Expand All @@ -118,7 +118,7 @@ public static int getNumThreads() {
.getenv("HUDSON_LOG_PARSER_THREADS");
if (maxThreadsByEnvStr != null) {
try {
result = (Integer.valueOf(maxThreadsByEnvStr)).intValue();
result = Integer.parseInt(maxThreadsByEnvStr);
} catch (Exception e) {
// Do nothing - use the default;
Logger.getLogger("getNumThreads").log(Level.FINEST,
Expand All @@ -134,7 +134,7 @@ public static int getLinesPerThread() {
.getenv("HUDSON_LOG_PARSER_LINES_PER_THREAD");
if (linesByEnvStr != null) {
try {
result = (Integer.valueOf(linesByEnvStr)).intValue();
result = Integer.parseInt(linesByEnvStr);
} catch (Exception e) {
// Do nothing - use the default;
Logger.getLogger("getLinesPerThread").log(Level.FINEST,
Expand Down
Loading

0 comments on commit 1d6f18d

Please sign in to comment.