Skip to content

Commit 606f747

Browse files
committed
[JENKINS-64917] Xcode Plugin fails to generate unit test report on macOS Catalina: JAXB-API issue
1 parent 83ccd19 commit 606f747

File tree

3 files changed

+20
-3
lines changed

3 files changed

+20
-3
lines changed

src/main/java/au/com/rayh/JenkinsXCodeBuildOutputParser.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
package au.com.rayh;
3131

3232
import hudson.FilePath;
33+
import hudson.Functions;
3334
import hudson.model.TaskListener;
3435

3536
import java.io.BufferedOutputStream;
@@ -113,7 +114,7 @@ public void write(int b) throws IOException {
113114
handleLine(buffer.toString());
114115
buffer = new StringBuilder();
115116
} catch(Exception e) { // Very fugly
116-
buildListener.fatalError(e.getMessage(), e);
117+
Functions.printStackTrace(e, buildListener.fatalError(e.getMessage()));
117118
throw new IOException(e);
118119
}
119120
} else {

src/main/java/au/com/rayh/XCodeBuildOutputParser.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,15 @@ private void requireTestCase(String name) {
177177
private void writeTestReport() throws IOException, InterruptedException,
178178
JAXBException {
179179
try (OutputStream testReportOutputStream = outputForSuite()) {
180-
JAXBContext jaxbContext = JAXBContext.newInstance(TestSuite.class);
180+
JAXBContext jaxbContext;
181+
Thread t = Thread.currentThread();
182+
ClassLoader orig = t.getContextClassLoader();
183+
t.setContextClassLoader(XCodeBuildOutputParser.class.getClassLoader());
184+
try {
185+
jaxbContext = JAXBContext.newInstance(TestSuite.class);
186+
} finally {
187+
t.setContextClassLoader(orig);
188+
}
181189
Marshaller marshaller = jaxbContext.createMarshaller();
182190
marshaller.marshal(currentTestSuite, testReportOutputStream);
183191
}

src/main/java/au/com/rayh/XcodeTestSummariesParser.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,15 @@ public XcodeTestSummariesParser(FilePath workspace) throws IOException, Interrup
4141
private void writeTestReport(TestSuite currentTestSuite) throws IOException, InterruptedException,
4242
JAXBException {
4343
try (OutputStream testReportOutputStream = outputForSuite(currentTestSuite)) {
44-
JAXBContext jaxbContext = JAXBContext.newInstance(TestSuite.class);
44+
JAXBContext jaxbContext;
45+
Thread t = Thread.currentThread();
46+
ClassLoader orig = t.getContextClassLoader();
47+
t.setContextClassLoader(XcodeTestSummariesParser.class.getClassLoader());
48+
try {
49+
jaxbContext = JAXBContext.newInstance(TestSuite.class);
50+
} finally {
51+
t.setContextClassLoader(orig);
52+
}
4553
Marshaller marshaller = jaxbContext.createMarshaller();
4654
marshaller.marshal(currentTestSuite, testReportOutputStream);
4755
}

0 commit comments

Comments
 (0)