Skip to content
This repository has been archived by the owner on Apr 6, 2022. It is now read-only.

Commit

Permalink
[ FIXED JENKINS-20070] Clear SAX system property afterwards.
Browse files Browse the repository at this point in the history
  • Loading branch information
uhafner committed Jan 30, 2014
1 parent 04d18b8 commit c28a396
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 24 deletions.
20 changes: 10 additions & 10 deletions plugin/src/main/java/hudson/plugins/findbugs/FindBugsPlugin.java
Expand Up @@ -2,9 +2,9 @@

import java.io.IOException;

import hudson.plugins.analysis.util.SaxSetup;
import org.apache.commons.lang.StringUtils;
import org.apache.maven.plugin.MojoExecution;
import org.apache.xerces.parsers.SAXParser;
import org.xml.sax.SAXException;

import hudson.Plugin;
Expand All @@ -18,24 +18,24 @@
* @author Ulli Hafner
*/
public class FindBugsPlugin extends Plugin {
/** Property of SAX parser factory. */
static final String SAX_DRIVER_PROPERTY = "org.xml.sax.driver";

@Override
public void start() throws IOException, SAXException {
String oldProperty = System.getProperty(SAX_DRIVER_PROPERTY);
System.setProperty(SAX_DRIVER_PROPERTY, SAXParser.class.getName());
SaxSetup sax = new SaxSetup();
try {
initializeMessages();
}
finally {
sax.cleanup();
}
}

private void initializeMessages() throws IOException, SAXException {
FindBugsMessages.getInstance().initialize();
FindBugsDetailFactory detailBuilder = new FindBugsDetailFactory();
DetailFactory.addDetailBuilder(FindBugsResultAction.class, detailBuilder);
if (PluginDescriptor.isMavenPluginInstalled()) {
MavenInitialization.run(detailBuilder);
}

if (oldProperty != null) {
System.setProperty(SAX_DRIVER_PROPERTY, oldProperty);
}
}

/**
Expand Down
Expand Up @@ -16,6 +16,7 @@
import java.util.logging.Logger;
import java.util.regex.Pattern;

import hudson.plugins.analysis.util.SaxSetup;
import org.apache.commons.digester3.Digester;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang.StringUtils;
Expand Down Expand Up @@ -52,9 +53,6 @@ public class FindBugsParser implements AnnotationParser {
/** Unique ID of this class. */
private static final long serialVersionUID = 8306319007761954027L;

/** Property of SAX parser factory. */
static final String SAX_DRIVER_PROPERTY = "org.xml.sax.driver";

private static final String DOT = ".";
private static final String SLASH = "/";
private static final String CLOUD_DETAILS_URL_PROPERTY = "detailsUrl";
Expand Down Expand Up @@ -365,19 +363,18 @@ private Priority getPriority(final BugInstance warning) {
}

private SortedBugCollection readXml(final InputStream file) throws IOException, DocumentException {
String oldProperty = System.getProperty(SAX_DRIVER_PROPERTY);
if (oldProperty != null) {
System.setProperty(SAX_DRIVER_PROPERTY, SAXParser.class.getName());
}
SaxSetup sax = new SaxSetup();
ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
Thread.currentThread().setContextClassLoader(FindBugsParser.class.getClassLoader());
SortedBugCollection collection = new SortedBugCollection();
collection.readXML(file);
Thread.currentThread().setContextClassLoader(contextClassLoader);
if (oldProperty != null) {
System.setProperty(SAX_DRIVER_PROPERTY, oldProperty);
try {
Thread.currentThread().setContextClassLoader(FindBugsParser.class.getClassLoader());
SortedBugCollection collection = new SortedBugCollection();
collection.readXML(file);
return collection;
}
finally {
Thread.currentThread().setContextClassLoader(contextClassLoader);
sax.cleanup();
}
return collection;
}

/**
Expand Down

0 comments on commit c28a396

Please sign in to comment.