Skip to content

Commit

Permalink
Remove Digester dep (#259)
Browse files Browse the repository at this point in the history
  • Loading branch information
jglick authored Jun 15, 2021
1 parent 70427e6 commit d2926d0
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 60 deletions.
21 changes: 0 additions & 21 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -178,12 +178,6 @@ THE SOFTWARE.
<artifactId>json</artifactId>
<version>20190722</version>
</dependency>
<dependency>
<groupId>commons-beanutils</groupId>
<artifactId>commons-beanutils</artifactId>
<!-- 1.9.4 when this merged https://github.com/stapler/stapler/pull/211 -->
<version>1.9.3</version>
</dependency>
</dependencies>
</dependencyManagement>

Expand All @@ -210,21 +204,6 @@ THE SOFTWARE.
<artifactId>mapdb-api</artifactId>
<version>1.0.9.0</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-digester3</artifactId>
<version>3.2</version>
<exclusions>
<exclusion>
<groupId>asm</groupId>
<artifactId>asm</artifactId>
</exclusion>
<exclusion>
<groupId>commons-beanutils</groupId>
<artifactId>commons-beanutils</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>credentials</artifactId>
Expand Down
91 changes: 57 additions & 34 deletions src/main/java/hudson/scm/SubversionChangeLogParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,23 +23,22 @@
*/
package hudson.scm;

import hudson.Util;
import hudson.model.Run;
import hudson.scm.SubversionChangeLogSet.LogEntry;
import hudson.scm.SubversionChangeLogSet.Path;
import org.apache.commons.digester3.Digester;
import org.xml.sax.SAXException;

import javax.xml.parsers.ParserConfigurationException;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;
import jenkins.util.xml.XMLUtils;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.SAXException;

/**
* {@link ChangeLogParser} for Subversion.
*
* @author Kohsuke Kawaguchi
*/
public class SubversionChangeLogParser extends ChangeLogParser {
private static Logger LOGGER = Logger.getLogger(SubversionChangeLogParser.class.getName());
Expand All @@ -58,40 +57,64 @@ public SubversionChangeLogParser(boolean ignoreDirPropChanges) {
@Override public SubversionChangeLogSet parse(@SuppressWarnings("rawtypes") Run build, RepositoryBrowser<?> browser, File changelogFile) throws IOException, SAXException {
// http://svn.apache.org/repos/asf/subversion/trunk/subversion/svn/schema/log.rnc

Digester digester = new Digester();
if (!Boolean.getBoolean(SubversionChangeLogParser.class.getName() + ".UNSAFE")) {
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) {
LOGGER.log(Level.WARNING, "Failed to securely configure Subversion changelog parser", ex);
throw new SAXException("Failed to securely configure Subversion changelog parser", ex);
}
digester.setXIncludeAware(false);
}
ArrayList<LogEntry> r = new ArrayList<>();
digester.push(r);

digester.addObjectCreate("*/logentry", LogEntry.class);
digester.addSetProperties("*/logentry");
digester.addBeanPropertySetter("*/logentry/author","user");
digester.addBeanPropertySetter("*/logentry/date");
digester.addBeanPropertySetter("*/logentry/msg");
digester.addSetNext("*/logentry","add");

digester.addObjectCreate("*/logentry/paths/path", Path.class);
digester.addSetProperties("*/logentry/paths/path");
digester.addBeanPropertySetter("*/logentry/paths/path","value");
digester.addSetNext("*/logentry/paths/path","addPath");

Element logE;
try {
digester.parse(changelogFile);
logE = XMLUtils.parse(changelogFile, "UTF-8").getDocumentElement();
} catch (IOException | SAXException e) {
throw new IOException("Failed to parse " + changelogFile,e);
}

NodeList logNL = logE.getChildNodes();
for (int i = 0; i < logNL.getLength(); i++) {
if (logNL.item(i).getNodeType() != Node.ELEMENT_NODE) {
continue;
}
Element logentryE = (Element) logNL.item(i);
LogEntry e = new LogEntry();
e.setRevision(Integer.parseInt(logentryE.getAttribute("revision")));
NodeList logentryNL = logentryE.getChildNodes();
for (int j = 0; j < logentryNL.getLength(); j++) {
if (logentryNL.item(j).getNodeType() != Node.ELEMENT_NODE) {
continue;
}
Element otherE = (Element) logentryNL.item(j);
String text = otherE.getTextContent();
switch (otherE.getTagName()) {
case "msg":
e.setMsg(text);
break;
case "date":
e.setDate(text);
break;
case "author":
e.setUser(text);
break;
case "paths":
NodeList pathsNL = otherE.getChildNodes();
for (int k = 0; k < pathsNL.getLength(); k++) {
if (pathsNL.item(k).getNodeType() != Node.ELEMENT_NODE) {
continue;
}
Element pathE = (Element) pathsNL.item(k);
Path path = new Path();
path.setValue(pathE.getTextContent());
path.setAction(pathE.getAttribute("action"));
path.setLocalPath(Util.fixEmpty(pathE.getAttribute("localPath")));
path.setKind(Util.fixEmpty(pathE.getAttribute("kind")));
e.addPath(path);
}
break;
/* If known to be exhaustive (above schema suggests not):
default:
throw new IOException(otherE.getTagName());
*/
}
}
r.add(e);
}

for (LogEntry e : r) {
e.finish();
}
Expand Down
7 changes: 2 additions & 5 deletions src/main/java/hudson/scm/SubversionChangeLogSet.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,6 @@

import jenkins.triggers.SCMTriggerItem;

import org.kohsuke.accmod.Restricted;
import org.kohsuke.accmod.restrictions.NoExternalUse;
import org.kohsuke.stapler.export.Exported;
import org.kohsuke.stapler.export.ExportedBean;
import org.tmatesoft.svn.core.internal.util.SVNDate;
Expand Down Expand Up @@ -308,7 +306,7 @@ public void setUser(String author) {
}

@Exported
public String getUser() {// digester wants read/write property, even though it never reads. Duh.
public String getUser() {
return author!=null ? author.getDisplayName() : "unknown";
}

Expand Down Expand Up @@ -460,8 +458,7 @@ public String getPath() {
return localPath;
}

@Restricted(NoExternalUse.class)
public void setLocalPath(String path) {
void setLocalPath(String path) {
this.localPath = path;
}

Expand Down

0 comments on commit d2926d0

Please sign in to comment.