Skip to content
This repository was archived by the owner on Mar 27, 2025. It is now read-only.

Commit 5f24629

Browse files
nbhoskisameagen-MWtsharmaMWmw-hrastega
authored
Release 2.13.0 (#306)
* Initial fix * Added support for build visualization (Latest) (#268) * Added support for build visualization * Fixed findbug issues * Fixed findbug issues * Fixed findbug issues * Deleted failuresummary.jelly * Refactored tests * Refactored jelly file * Updated as per review comments * updated jelly as per review comment * Using overide plugin method to generate json file * Updated as per review comment * Updated as per review comment * Added log updater plugin * Added log link support * Fixed spotbug issue * Renamed plugin packages * Changed data types for artifact data * empty * Fixed test failure * Fixed Merge conflicts * Fixed spotbug issue * Updated as per review comments * Updated as per review comments * Updated as per review comments * Updated as per review comments * Build visulization support for pipeline (#278) * Fixed issue 281 (#284) * Update the maven release (#286) * [maven-release-plugin] prepare release matlab-2.12.0 * [maven-release-plugin] prepare for next development iteration * Added summary page warnning * Updated summary warnning * Fixed Summary page issues * Fixed issue 292 * Fixed 289 as per comment * Fixed error message issue 288 * Fixed 289 * 2.11.2 snapshot qualification (#296) * Fixed issue 281 (#284) * Update the maven release (#286) * [maven-release-plugin] prepare release matlab-2.12.0 * [maven-release-plugin] prepare for next development iteration * Added summary page warnning * Updated summary warnning * Fixed Summary page issues * Fixed issue 292 * Fixed 289 as per comment * Fixed error message issue 288 * Fixed 289 * Add build options (#294) * add build options * update gitignore * add tests for build options * add fixes and more tests * fix tests * modify help text * fix help text * minor text fix * fix null error and formatting * remove buildOptions check from EnvVarSupport test * add env variables support for build options and formatting fixes * minor fixes * documenting MATLAB build options and MATLAB build result * Fixed issue 298 (#300) * adding a new screenshot for build results and minor updates (#304) --------- Co-authored-by: sameagen <[email protected]> Co-authored-by: sameagen-MW <[email protected]> Co-authored-by: Tushar Sharma <[email protected]> Co-authored-by: mw-hrastega <[email protected]>
1 parent 248e90b commit 5f24629

30 files changed

+1228
-106
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ work
44

55
# Binaries and downloaded resources
66
src/main/resources/matlab-script-generator.zip
7-
src/main/resources/run_matlab_command.*
7+
src/main/resources/**/run-matlab-command*
88
src/main/resources/license.txt
99

1010
**/.DS_Store

CONFIGDOC.md

Lines changed: 73 additions & 66 deletions
Large diffs are not rendered by default.

pom.xml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
<relativePath />
99
</parent>
1010
<artifactId>matlab</artifactId>
11-
<version>2.11.2-SNAPSHOT</version>
11+
<version>2.12.1-SNAPSHOT</version>
1212
<packaging>hpi</packaging>
1313
<developers>
1414
<developer>
@@ -60,6 +60,12 @@
6060
</dependencies>
6161
</dependencyManagement>
6262
<dependencies>
63+
<!-- JSON Parser -->
64+
<dependency>
65+
<groupId>com.googlecode.json-simple</groupId>
66+
<artifactId>json-simple</artifactId>
67+
<version>1.1.1</version>
68+
</dependency>
6369
<!-- Pipeline Step dependencies -->
6470
<dependency>
6571
<groupId>org.jenkins-ci.plugins</groupId>
Lines changed: 220 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,220 @@
1+
package com.mathworks.ci;
2+
3+
import hudson.FilePath;
4+
import hudson.model.Action;
5+
import hudson.model.Run;
6+
import java.io.File;
7+
import java.io.FileInputStream;
8+
import java.io.IOException;
9+
import java.io.InputStreamReader;
10+
import java.util.ArrayList;
11+
import java.util.Iterator;
12+
import java.util.List;
13+
import java.util.Map;
14+
import java.util.Map.Entry;
15+
import javax.annotation.CheckForNull;
16+
import org.json.simple.JSONArray;
17+
import org.json.simple.JSONObject;
18+
import org.json.simple.parser.JSONParser;
19+
import org.json.simple.parser.ParseException;
20+
21+
22+
public class BuildArtifactAction implements Action {
23+
private Run<?, ?> build;
24+
private FilePath workspace;
25+
private int totalCount;
26+
private int skipCount;
27+
private int failCount;
28+
private static final String ROOT_ELEMENT = "taskDetails";
29+
private static final String BUILD_ARTIFACT_FILE = "buildArtifact.json";
30+
31+
public BuildArtifactAction(Run<?, ?> build, FilePath workspace) {
32+
this.build = build;
33+
this.workspace = workspace;
34+
35+
// Setting the counts of task when Action is created.
36+
try{
37+
setCounts();
38+
} catch (ParseException e) {
39+
throw new RuntimeException(e);
40+
} catch (InterruptedException e){
41+
throw new RuntimeException(e);
42+
}
43+
}
44+
45+
@CheckForNull
46+
@Override
47+
public String getIconFileName() {
48+
return "document.png";
49+
}
50+
51+
@CheckForNull
52+
@Override
53+
public String getDisplayName() {
54+
return "MATLAB Build Results";
55+
}
56+
57+
@CheckForNull
58+
@Override
59+
public String getUrlName() {
60+
return "buildresults";
61+
}
62+
63+
public List<BuildArtifactData> getBuildArtifact() throws ParseException, InterruptedException, IOException {
64+
List<BuildArtifactData> artifactData = new ArrayList<BuildArtifactData>();
65+
FilePath fl = new FilePath(new File(build.getRootDir().getAbsolutePath() + "/" + BUILD_ARTIFACT_FILE));
66+
try (InputStreamReader reader = new InputStreamReader(new FileInputStream(new File(fl.toURI())), "UTF-8")) {
67+
Object obj = new JSONParser().parse(reader);
68+
JSONObject jo = (JSONObject) obj;
69+
if (jo.get(ROOT_ELEMENT) instanceof JSONArray) {
70+
JSONArray ja = (JSONArray) jo.get(ROOT_ELEMENT);
71+
Iterator itr2 = ja.iterator();
72+
Iterator<Entry> itr1;
73+
while (itr2.hasNext()) {
74+
BuildArtifactData data = new BuildArtifactData();
75+
itr1 = ((Map) itr2.next()).entrySet().iterator();
76+
while (itr1.hasNext()) {
77+
Entry pair = itr1.next();
78+
iterateAllTaskAttributes(pair, data);
79+
}
80+
artifactData.add(data);
81+
}
82+
} else {
83+
Map ja = ((Map) jo.get(ROOT_ELEMENT));
84+
Iterator<Entry> itr1 = ja.entrySet().iterator();
85+
BuildArtifactData data = new BuildArtifactData();
86+
while (itr1.hasNext()) {
87+
Entry pair = itr1.next();
88+
iterateAllTaskAttributes(pair, data);
89+
}
90+
artifactData.add(data);
91+
}
92+
} catch (IOException e) {
93+
throw new IOException(e.getLocalizedMessage());
94+
}
95+
return artifactData;
96+
}
97+
98+
public void setTotalcount(int totalCount) {
99+
this.totalCount = totalCount;
100+
}
101+
102+
public void setSkipCount(int skipCount) {
103+
this.skipCount = skipCount;
104+
}
105+
106+
public int getTotalCount() {
107+
return this.totalCount;
108+
}
109+
110+
public int getFailCount() {
111+
return this.failCount;
112+
}
113+
114+
public void setFailCount(int failCount) {
115+
this.failCount = failCount;
116+
}
117+
118+
public int getSkipCount() {
119+
return this.skipCount;
120+
}
121+
122+
public Run getOwner() {
123+
return this.build;
124+
}
125+
126+
/**
127+
* @param owner the owner to set
128+
*/
129+
public void setOwner(Run owner) {
130+
this.build = owner;
131+
}
132+
133+
public FilePath getWorkspace() {
134+
return this.workspace;
135+
}
136+
137+
private void setCounts() throws InterruptedException, ParseException {
138+
List<BuildArtifactData> artifactData = new ArrayList<BuildArtifactData>();
139+
FilePath fl = new FilePath(new File(build.getRootDir().getAbsolutePath() + "/" + BUILD_ARTIFACT_FILE));
140+
try (InputStreamReader reader = new InputStreamReader(new FileInputStream(new File(fl.toURI())), "UTF-8")) {
141+
Object obj = new JSONParser().parse(reader);
142+
JSONObject jo = (JSONObject) obj;
143+
144+
// getting taskDetails
145+
if (jo.get(ROOT_ELEMENT) instanceof JSONArray) {
146+
JSONArray ja = (JSONArray) jo.get(ROOT_ELEMENT);
147+
Iterator itr2 = ja.iterator();
148+
Iterator<Entry> itr1;
149+
while (itr2.hasNext()) {
150+
BuildArtifactData data = new BuildArtifactData();
151+
itr1 = ((Map) itr2.next()).entrySet().iterator();
152+
while (itr1.hasNext()) {
153+
Entry pair = itr1.next();
154+
iterateFailedSkipped(pair, data);
155+
}
156+
artifactData.add(data);
157+
setTotalcount(artifactData.size());
158+
}
159+
} else {
160+
Map ja = ((Map) jo.get(ROOT_ELEMENT));
161+
Iterator<Entry> itr1 = ja.entrySet().iterator();
162+
BuildArtifactData data = new BuildArtifactData();
163+
while (itr1.hasNext()) {
164+
Entry pair = itr1.next();
165+
iterateFailedSkipped(pair, data);
166+
}
167+
artifactData.add(data);
168+
setTotalcount(artifactData.size());
169+
}
170+
} catch (IOException e) {
171+
e.printStackTrace();
172+
}
173+
174+
// Update the FAILED and SKIPPED task count
175+
int failCount = 0;
176+
int skipCount = 0;
177+
for (BuildArtifactData data : artifactData) {
178+
if (data.getTaskFailed()) {
179+
failCount = failCount + 1;
180+
} else if (data.getTaskSkipped()) {
181+
skipCount = skipCount + 1;
182+
}
183+
}
184+
// Set count for each failed and skipped tasks
185+
setFailCount(failCount);
186+
setSkipCount(skipCount);
187+
}
188+
189+
private void iterateAllTaskAttributes(Entry pair, BuildArtifactData data) {
190+
// Iterates across all task attributes and updates
191+
String key = pair.getKey().toString();
192+
switch(key.toLowerCase()){
193+
case "duration":
194+
data.setTaskDuration(pair.getValue().toString());
195+
break;
196+
case "name" :
197+
data.setTaskName(pair.getValue().toString());
198+
break;
199+
case "description":
200+
data.setTaskDescription(pair.getValue().toString());
201+
break;
202+
case "failed":
203+
data.setTaskFailed((Boolean) pair.getValue());
204+
break;
205+
case "skipped":
206+
data.setTaskSkipped((Boolean) pair.getValue());
207+
break;
208+
default :
209+
break;
210+
}
211+
}
212+
213+
private void iterateFailedSkipped(Entry pair, BuildArtifactData data) {
214+
if (pair.getKey().toString().equalsIgnoreCase("failed")) {
215+
data.setTaskFailed((Boolean) pair.getValue());
216+
} else if (pair.getKey().toString().equalsIgnoreCase("skipped")) {
217+
data.setTaskSkipped((Boolean) pair.getValue());
218+
}
219+
}
220+
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
package com.mathworks.ci;
2+
3+
public class BuildArtifactData {
4+
5+
private String taskName;
6+
private String taskDuration;
7+
private boolean taskFailed;
8+
9+
private String taskDescription;
10+
private boolean taskSkipped;
11+
12+
public BuildArtifactData() {
13+
}
14+
15+
16+
public String getTaskDuration() {
17+
return this.taskDuration;
18+
}
19+
20+
public void setTaskDuration(String taskDuration) {
21+
this.taskDuration = taskDuration;
22+
}
23+
24+
public String getTaskName() {
25+
return this.taskName;
26+
}
27+
28+
public void setTaskName(String taskName) {
29+
this.taskName = taskName;
30+
}
31+
32+
public boolean getTaskSkipped() {
33+
return this.taskSkipped;
34+
}
35+
36+
public void setTaskSkipped(boolean taskSkipped) {
37+
this.taskSkipped = taskSkipped;
38+
}
39+
40+
public boolean getTaskFailed() {
41+
return this.taskFailed;
42+
}
43+
44+
public void setTaskFailed(boolean taskFailed) {
45+
this.taskFailed = taskFailed;
46+
}
47+
48+
public String getTaskDescription() {
49+
return this.taskDescription;
50+
}
51+
52+
public void setTaskDescription(String taskDescription) {
53+
this.taskDescription = taskDescription;
54+
}
55+
}
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
package com.mathworks.ci;
2+
3+
import com.google.common.base.Charsets;
4+
import hudson.console.ConsoleLogFilter;
5+
import hudson.console.LineTransformationOutputStream;
6+
import hudson.model.Run;
7+
import java.io.ByteArrayOutputStream;
8+
import java.io.IOException;
9+
import java.io.OutputStream;
10+
import java.io.Serializable;
11+
import java.nio.ByteBuffer;
12+
import java.nio.charset.Charset;
13+
import jenkins.util.JenkinsJVM;
14+
15+
public class BuildConsoleAnnotator extends LineTransformationOutputStream {
16+
private final OutputStream out;
17+
private final Charset charset;
18+
19+
private final byte[][] antNotes;
20+
21+
public BuildConsoleAnnotator(OutputStream out, Charset charset) {
22+
this(out, charset, createBuildNotes());
23+
}
24+
25+
private BuildConsoleAnnotator(OutputStream out, Charset charset, byte[][] antNotes) {
26+
this.out = out;
27+
this.charset = charset;
28+
this.antNotes = antNotes;
29+
}
30+
31+
private static byte[][] createBuildNotes() {
32+
JenkinsJVM.checkJenkinsJVM();
33+
try {
34+
ByteArrayOutputStream targetNote = new ByteArrayOutputStream();
35+
new BuildTargetNote().encodeTo(targetNote);
36+
ByteArrayOutputStream outcomeNote = new ByteArrayOutputStream();
37+
return new byte[][]{targetNote.toByteArray(), outcomeNote.toByteArray()};
38+
} catch (IOException e) {
39+
throw new RuntimeException(e);
40+
}
41+
42+
}
43+
44+
@Override
45+
protected void eol(byte[] b, int len) throws IOException {
46+
String line = charset.decode(ByteBuffer.wrap(b, 0, len)).toString();
47+
// trim off CR/LF from the end
48+
line = trimEOL(line);
49+
if (line.contains("[MATLAB-Build-"))
50+
out.write(antNotes[0]);
51+
52+
out.write(b, 0, len);
53+
}
54+
55+
@Override
56+
public void flush() throws IOException {
57+
out.flush();
58+
}
59+
60+
@Override
61+
public void close() throws IOException {
62+
super.close();
63+
out.close();
64+
}
65+
66+
private static class ConsoleLogFilterImpl extends ConsoleLogFilter implements Serializable {
67+
private static final long serialVersionUID = 1;
68+
private byte[][] buildNotes = createBuildNotes();
69+
70+
//Taking care of old MATLAB build actions.
71+
private Object readResolve() {
72+
if (buildNotes == null) {
73+
buildNotes = createBuildNotes();
74+
}
75+
return this;
76+
}
77+
78+
@Override
79+
public OutputStream decorateLogger(Run build, OutputStream logger) throws IOException, InterruptedException {
80+
return new BuildConsoleAnnotator(logger, Charsets.UTF_8, buildNotes);
81+
}
82+
}
83+
}

0 commit comments

Comments
 (0)