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

Commit

Permalink
[FIXED JENKINS-12516] Upgrade to Digester 3.2 which is more robust in
Browse files Browse the repository at this point in the history
parsing CDATA elements.
  • Loading branch information
uhafner committed Feb 7, 2012
1 parent 43dfde3 commit c26adbd
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 4 deletions.
9 changes: 8 additions & 1 deletion pom.xml
@@ -1,4 +1,5 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
Expand Down Expand Up @@ -33,6 +34,12 @@
<artifactId>analysis-core</artifactId>
<version>1.36</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-digester3</artifactId>
<version>3.2</version>
<classifier>with-deps</classifier>
</dependency>
<dependency>
<groupId>de.java2html</groupId>
<artifactId>java2html</artifactId>
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/hudson/plugins/dry/parser/cpd/CpdParser.java
Expand Up @@ -11,7 +11,7 @@
import java.util.Collection;
import java.util.List;

import org.apache.commons.digester.Digester;
import org.apache.commons.digester3.Digester;
import org.xml.sax.SAXException;

/**
Expand Down Expand Up @@ -40,7 +40,7 @@ public CpdParser(final int highThreshold, final int normalThreshold) {
public boolean accepts(final InputStream file) {
try {
Digester digester = new Digester();
digester.setValidating(false);
digester.setValidating(true);
digester.setClassLoader(CpdParser.class.getClassLoader());

String duplicationXPath = "*/pmd-cpd";
Expand Down
17 changes: 16 additions & 1 deletion src/test/java/hudson/plugins/dry/parser/cpd/CpdParserTest.java
Expand Up @@ -64,6 +64,21 @@ private InputStream getResource(final String fileName) {
return CpdParserTest.class.getResourceAsStream(fileName);
}

/**
* Checks whether we correctly detect a duplication.
*
* @throws InvocationTargetException
* Signals a test failure
*/
@Test
public void issue12516() throws InvocationTargetException {
String fileName = "issue12516.xml";
assertTrue(VALID_CPD_FILE, acceptsFile(fileName));
Collection<DuplicateCode> annotations = parseFile(fileName);

assertEquals(ERROR_MESSAGE, 2, annotations.size());
}

/**
* Checks whether we correctly detect all 2 duplications (i.e., 4 warnings).
*
Expand Down Expand Up @@ -133,7 +148,7 @@ private void assertDuplication(final int expectedLine, final String expectedFile
*/
@Test
public void scanOtherFile() {
assertFalse("Parser does accept invalid CPD file.", acceptsFile("other.xml"));
assertFalse("Parser does accept invalid CPD file.", acceptsFile("otherfile.xml"));
}
}

Expand Down
54 changes: 54 additions & 0 deletions src/test/resources/hudson/plugins/dry/parser/cpd/issue12516.xml
@@ -0,0 +1,54 @@
<?xml version="1.0" encoding="ANSI_X3.4-1968"?>
<pmd-cpd>
<duplication lines="68" tokens="1586">
<file line="19" path="csci07/csc60/remote_copy.sh"/>
<file line="19" path="csci08/csc90/remote_copy.sh"/>
<codefragment>
<![CDATA[
#
ERROR HANDLING: N/A
#
REMARKS: N/A
#
****************************** END HEADER *************************************
#
***************************** BEGIN PDL ***************************************
#
****************************** END PDL ****************************************
#
***************************** BEGIN CODE **************************************
**
*******************************************************************************
*******************************************************************************
*******************************************************************************
if [ $# -lt 3 ]
then
exit 1
fi
*******************************************************************************
initialize local variables
shift input parameter (twice) to leave only files to copy
*******************************************************************************
files=""
shift
shift
*******************************************************************************
*******************************************************************************
for i in $*
do
files="$files $directory/$i"
done
]]>
</codefragment>
</duplication>
</pmd-cpd>

0 comments on commit c26adbd

Please sign in to comment.