Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[JENKINS-65161] remove commons-digester2 from core and upgrade plugins to commons-digester3 #24

Merged
merged 1 commit into from
Apr 30, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@
<artifactId>clover</artifactId>
<version>4.4.1</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-digester3</artifactId>
<version>3.2</version>
</dependency>
<!--Build breaks without these:-->
<dependency>
<groupId>jfree</groupId>
Expand Down
54 changes: 36 additions & 18 deletions src/main/java/hudson/plugins/clover/CloverCoverageParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import org.apache.commons.digester.Digester;
import org.xml.sax.SAXException;

import javax.xml.parsers.ParserConfigurationException;


/**
Expand Down Expand Up @@ -63,30 +64,47 @@ public static ProjectCoverage parse(File inFile, String pathPrefix) throws IOExc
}
}

private static Digester createDigester(boolean secure) throws SAXException {
Digester digester = new Digester();
if (secure) {
digester.setXIncludeAware(false);
try {
digester.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true);
digester.setFeature("http://xml.org/sax/features/external-general-entities", false);
digester.setFeature("http://xml.org/sax/features/external-parameter-entities", false);
digester.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false);
} catch (ParserConfigurationException ex) {
throw new SAXException("Failed to securely configure xml digester parser", ex);
}
}
return digester;
}

public static ProjectCoverage parse(InputStream in) throws IOException {
if (in == null) throw new NullPointerException();
Digester digester = new Digester();
digester.setClassLoader(CloverCoverageParser.class.getClassLoader());
digester.addObjectCreate("coverage/project", ProjectCoverage.class);
digester.addSetProperties("coverage/project");
digester.addSetProperties("coverage/project/metrics");
try {
boolean secure = (!Boolean.getBoolean(CloverCoverageParser.class.getName() + ".UNSAFE"));
Digester digester = createDigester(secure);
digester.setClassLoader(CloverCoverageParser.class.getClassLoader());
digester.addObjectCreate("coverage/project", ProjectCoverage.class);
digester.addSetProperties("coverage/project");
digester.addSetProperties("coverage/project/metrics");

digester.addObjectCreate("coverage/project/package", PackageCoverage.class);
digester.addSetProperties("coverage/project/package");
digester.addSetProperties("coverage/project/package/metrics");
digester.addSetNext("coverage/project/package", "addPackageCoverage", PackageCoverage.class.getName());
digester.addObjectCreate("coverage/project/package", PackageCoverage.class);
digester.addSetProperties("coverage/project/package");
digester.addSetProperties("coverage/project/package/metrics");
digester.addSetNext("coverage/project/package", "addPackageCoverage", PackageCoverage.class.getName());

digester.addObjectCreate("coverage/project/package/file", FileCoverage.class);
digester.addSetProperties("coverage/project/package/file");
digester.addSetProperties("coverage/project/package/file/metrics");
digester.addSetNext("coverage/project/package/file", "addFileCoverage", FileCoverage.class.getName());
digester.addObjectCreate("coverage/project/package/file", FileCoverage.class);
digester.addSetProperties("coverage/project/package/file");
digester.addSetProperties("coverage/project/package/file/metrics");
digester.addSetNext("coverage/project/package/file", "addFileCoverage", FileCoverage.class.getName());

digester.addObjectCreate("coverage/project/package/file/class", ClassCoverage.class);
digester.addSetProperties("coverage/project/package/file/class");
digester.addSetProperties("coverage/project/package/file/class/metrics");
digester.addSetNext("coverage/project/package/file/class", "addClassCoverage", ClassCoverage.class.getName());
digester.addObjectCreate("coverage/project/package/file/class", ClassCoverage.class);
digester.addSetProperties("coverage/project/package/file/class");
digester.addSetProperties("coverage/project/package/file/class/metrics");
digester.addSetNext("coverage/project/package/file/class", "addClassCoverage", ClassCoverage.class.getName());

try {
return (ProjectCoverage) digester.parse(in);
} catch (SAXException e) {
throw new IOException2("Cannot parse coverage results", e);
Expand Down