Skip to content

Commit d4c87ef

Browse files
committed
feat: Add column to jobs list
see JENKINS-69063
1 parent b50e660 commit d4c87ef

6 files changed

Lines changed: 99 additions & 0 deletions

File tree

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
package hudson.plugins.logparser;
2+
3+
import hudson.Extension;
4+
import hudson.model.Job;
5+
import hudson.model.Run;
6+
import hudson.views.ListViewColumn;
7+
import hudson.views.ListViewColumnDescriptor;
8+
import net.sf.json.JSONObject;
9+
import org.kohsuke.stapler.StaplerRequest;
10+
11+
public class LogParserColumn extends ListViewColumn {
12+
public int[] getResult(Job job) {
13+
if (job == null) {
14+
return null;
15+
}
16+
Run build = job.getLastCompletedBuild();
17+
if (build == null) {
18+
return null;
19+
}
20+
LogParserAction action = build.getAction(LogParserAction.class);
21+
if (action == null) {
22+
return null;
23+
}
24+
LogParserResult result = action.getResult();
25+
if (result == null) {
26+
return null;
27+
}
28+
29+
return new int[]{result.getTotalErrors(), result.getTotalWarnings(), result.getTotalInfos(), result.getTotalDebugs()};
30+
}
31+
32+
public String getUrl(Job job) {
33+
if (job == null) {
34+
return null;
35+
}
36+
Run build = job.getLastCompletedBuild();
37+
if (build == null) {
38+
return null;
39+
}
40+
return build.getUrl() + LogParserAction.getUrlNameStat();
41+
}
42+
43+
@Extension
44+
public static class LogParserColumnDescriptor extends ListViewColumnDescriptor {
45+
@Override
46+
public ListViewColumn newInstance(StaplerRequest req, JSONObject formData) throws FormException {
47+
return new LogParserColumn();
48+
}
49+
50+
@Override
51+
public String getDisplayName() {
52+
return Messages.LogParserColumn_Header();
53+
}
54+
55+
@Override
56+
public boolean shownByDefault() {
57+
return false;
58+
}
59+
}
60+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?xml version="1.0"?>
2+
<?jelly escape-by-default='true'?>
3+
<j:jelly xmlns:j="jelly:core">
4+
<j:set var="result" value="${it.getResult(job)}"/>
5+
<j:set var="url" value="${it.getUrl(job)}"/>
6+
<td style="font-weight: bold">
7+
<j:choose>
8+
<j:when test="${url == null}">
9+
</j:when>
10+
<j:when test="${result == null}">
11+
-
12+
</j:when>
13+
<j:otherwise>
14+
<a href="${rootURL}/${url}">
15+
<span style="color: ${%Error.color}">${%Error}${result[0]};</span>
16+
<span style="color: ${%Warning.color}">${%Warning}${result[1]};</span>
17+
<span style="color: ${%Info.color}">${%Info}${result[2]};</span>
18+
<span style="color: ${%Debug.color}">${%Debug}${result[3]}</span>
19+
</a>
20+
</j:otherwise>
21+
</j:choose>
22+
</td>
23+
</j:jelly>
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
Error=E:
2+
Warning=W:
3+
Info=I:
4+
Debug=D:
5+
6+
Error.color=red
7+
Warning.color=orange
8+
Info.color=green
9+
Debug.color=gray
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?xml version="1.0"?>
2+
<?jelly escape-by-default='true'?>
3+
<j:jelly xmlns:j="jelly:core">
4+
<th>${%LogParserColumn.Header}</th>
5+
</j:jelly>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
LogParserColumn.Header=Log parser
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
LogParserColumn.Header=Log parser

0 commit comments

Comments
 (0)