diff --git a/src/main/java/com/thalesgroup/hudson/plugins/cppcheck/parser/CppcheckParser.java b/src/main/java/com/thalesgroup/hudson/plugins/cppcheck/parser/CppcheckParser.java index c18d132..070e83d 100644 --- a/src/main/java/com/thalesgroup/hudson/plugins/cppcheck/parser/CppcheckParser.java +++ b/src/main/java/com/thalesgroup/hudson/plugins/cppcheck/parser/CppcheckParser.java @@ -56,11 +56,18 @@ public CppcheckReport parse(final File file) throws IOException { CppcheckReport report; AtomicReference jc = new AtomicReference(); try { - jc.set(JAXBContext.newInstance( - org.jenkinsci.plugins.cppcheck.model.Error.class, - org.jenkinsci.plugins.cppcheck.model.Errors.class, - org.jenkinsci.plugins.cppcheck.model.Cppcheck.class, - org.jenkinsci.plugins.cppcheck.model.Results.class)); + Thread t = Thread.currentThread(); + ClassLoader orig = t.getContextClassLoader(); + t.setContextClassLoader(CppcheckParser.class.getClassLoader()); + try { + jc.set(JAXBContext.newInstance( + org.jenkinsci.plugins.cppcheck.model.Error.class, + org.jenkinsci.plugins.cppcheck.model.Errors.class, + org.jenkinsci.plugins.cppcheck.model.Cppcheck.class, + org.jenkinsci.plugins.cppcheck.model.Results.class)); + } finally { + t.setContextClassLoader(orig); + } Unmarshaller unmarshaller = jc.get().createUnmarshaller(); org.jenkinsci.plugins.cppcheck.model.Results results = (org.jenkinsci.plugins.cppcheck.model.Results) unmarshaller.unmarshal(file); if (results.getCppcheck() == null) { @@ -69,7 +76,14 @@ public CppcheckReport parse(final File file) throws IOException { report = getReportVersion2(results); } catch (JAXBException jxe) { try { - jc.set(JAXBContext.newInstance(com.thalesgroup.jenkinsci.plugins.cppcheck.model.Error.class, com.thalesgroup.jenkinsci.plugins.cppcheck.model.Results.class)); + Thread t = Thread.currentThread(); + ClassLoader orig = t.getContextClassLoader(); + t.setContextClassLoader(CppcheckParser.class.getClassLoader()); + try { + jc.set(JAXBContext.newInstance(com.thalesgroup.jenkinsci.plugins.cppcheck.model.Error.class, com.thalesgroup.jenkinsci.plugins.cppcheck.model.Results.class)); + } finally { + t.setContextClassLoader(orig); + } Unmarshaller unmarshaller = jc.get().createUnmarshaller(); com.thalesgroup.jenkinsci.plugins.cppcheck.model.Results results = (com.thalesgroup.jenkinsci.plugins.cppcheck.model.Results) unmarshaller.unmarshal(file); report = getReportVersion1(results); diff --git a/src/main/java/org/jenkinsci/plugins/cppcheck/parser/CppcheckParser.java b/src/main/java/org/jenkinsci/plugins/cppcheck/parser/CppcheckParser.java index 850e463..e6308b3 100644 --- a/src/main/java/org/jenkinsci/plugins/cppcheck/parser/CppcheckParser.java +++ b/src/main/java/org/jenkinsci/plugins/cppcheck/parser/CppcheckParser.java @@ -37,11 +37,18 @@ public CppcheckReport parse(final File file, TaskListener listener) throws IOExc CppcheckReport report; AtomicReference jc = new AtomicReference(); try { - jc.set(JAXBContext.newInstance( - org.jenkinsci.plugins.cppcheck.model.Error.class, - org.jenkinsci.plugins.cppcheck.model.Errors.class, - org.jenkinsci.plugins.cppcheck.model.Cppcheck.class, - org.jenkinsci.plugins.cppcheck.model.Results.class)); + Thread t = Thread.currentThread(); + ClassLoader orig = t.getContextClassLoader(); + t.setContextClassLoader(CppcheckParser.class.getClassLoader()); + try { + jc.set(JAXBContext.newInstance( + org.jenkinsci.plugins.cppcheck.model.Error.class, + org.jenkinsci.plugins.cppcheck.model.Errors.class, + org.jenkinsci.plugins.cppcheck.model.Cppcheck.class, + org.jenkinsci.plugins.cppcheck.model.Results.class)); + } finally { + t.setContextClassLoader(orig); + } Unmarshaller unmarshaller = jc.get().createUnmarshaller(); org.jenkinsci.plugins.cppcheck.model.Results results = (org.jenkinsci.plugins.cppcheck.model.Results) unmarshaller.unmarshal(file); if (results.getCppcheck() == null) { @@ -50,7 +57,14 @@ public CppcheckReport parse(final File file, TaskListener listener) throws IOExc report = getReportVersion2(results); } catch (JAXBException jxe) { try { - jc.set(JAXBContext.newInstance(com.thalesgroup.jenkinsci.plugins.cppcheck.model.Error.class, com.thalesgroup.jenkinsci.plugins.cppcheck.model.Results.class)); + Thread t = Thread.currentThread(); + ClassLoader orig = t.getContextClassLoader(); + t.setContextClassLoader(CppcheckParser.class.getClassLoader()); + try { + jc.set(JAXBContext.newInstance(com.thalesgroup.jenkinsci.plugins.cppcheck.model.Error.class, com.thalesgroup.jenkinsci.plugins.cppcheck.model.Results.class)); + } finally { + t.setContextClassLoader(orig); + } Unmarshaller unmarshaller = jc.get().createUnmarshaller(); com.thalesgroup.jenkinsci.plugins.cppcheck.model.Results results = (com.thalesgroup.jenkinsci.plugins.cppcheck.model.Results) unmarshaller.unmarshal(file); report = getReportVersion1(results); @@ -60,11 +74,7 @@ public CppcheckReport parse(final File file, TaskListener listener) throws IOExc + "It often detects and reports more issues with the new format, " + "so its usage is highly recommended."); } catch (JAXBException jxe1) { - // Since Java 1.6 - // throw new IOException(jxe1); - - // Legacy constructor for compatibility with Java 1.5 - throw (IOException) new IOException(jxe1.toString()).initCause(jxe1); + throw new IOException(jxe1); } } return report;