Skip to content

Commit 152af13

Browse files
committed
Demonstrating usage of SetContextClassLoader
1 parent 831b1cd commit 152af13

File tree

3 files changed

+12
-20
lines changed

3 files changed

+12
-20
lines changed

pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
<parent>
2929
<groupId>org.jenkins-ci.plugins</groupId>
3030
<artifactId>plugin</artifactId>
31-
<version>4.41</version>
31+
<version>4.44</version>
3232
<relativePath />
3333
</parent>
3434
<artifactId>xcode-plugin</artifactId>
@@ -146,7 +146,7 @@
146146
<revision>2.0.17</revision>
147147
<changelist>999999-SNAPSHOT</changelist>
148148
<gitHubRepo>jenkinsci/xcode-plugin</gitHubRepo>
149-
<jenkins.version>2.319.1</jenkins.version>
149+
<jenkins.version>2.362-SNAPSHOT</jenkins.version>
150150
</properties>
151151
<build>
152152
<plugins>

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

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
import javax.xml.bind.JAXBContext;
4242
import javax.xml.bind.JAXBException;
4343
import javax.xml.bind.Marshaller;
44+
import jenkins.util.SetContextClassLoader;
4445

4546
import au.com.rayh.report.TestCase;
4647
import au.com.rayh.report.TestError;
@@ -176,16 +177,11 @@ private void requireTestCase(String name) {
176177

177178
private void writeTestReport() throws IOException, InterruptedException,
178179
JAXBException {
180+
JAXBContext jaxbContext;
181+
try (SetContextClassLoader sccl = new SetContextClassLoader()) {
182+
jaxbContext = JAXBContext.newInstance(TestSuite.class);
183+
}
179184
try (OutputStream testReportOutputStream = outputForSuite()) {
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-
}
189185
Marshaller marshaller = jaxbContext.createMarshaller();
190186
marshaller.marshal(currentTestSuite, testReportOutputStream);
191187
}

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

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import java.util.regex.Pattern;
88
import java.text.ParseException;
99
import hudson.FilePath;
10+
import jenkins.util.SetContextClassLoader;
1011

1112
import com.dd.plist.NSDictionary;
1213
import com.dd.plist.NSArray;
@@ -40,16 +41,11 @@ public XcodeTestSummariesParser(FilePath workspace) throws IOException, Interrup
4041

4142
private void writeTestReport(TestSuite currentTestSuite) throws IOException, InterruptedException,
4243
JAXBException {
44+
JAXBContext jaxbContext;
45+
try (SetContextClassLoader sccl = new SetContextClassLoader()) {
46+
jaxbContext = JAXBContext.newInstance(TestSuite.class);
47+
}
4348
try (OutputStream testReportOutputStream = outputForSuite(currentTestSuite)) {
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-
}
5349
Marshaller marshaller = jaxbContext.createMarshaller();
5450
marshaller.marshal(currentTestSuite, testReportOutputStream);
5551
}

0 commit comments

Comments
 (0)