o MAVEN-313: Catch files that don't parse properly and throw Throwable exceptions rather than Exception exceptions!

git-svn-id: https://svn.apache.org/repos/asf/maven/maven-1/plugins/trunk@113079 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
bwalding committed 2003-03-07 22:44:54 +00:00
1 parent afd9267093
commit e1d398ad12
3 files changed
+2378 -12

No files matched your search

@@ -59,7 +59,6 @@ package org.apache.maven.linkcheck;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.HashMap;
@@ -79,7 +78,7 @@ import org.w3c.tidy.Tidy;
/**
* @author <a href="mailto:bwalding@apache.org">Ben Walding</a>
* @version $Id: FileToCheck.java,v 1.9 2003/03/07 22:09:56 bwalding Exp $
* @version $Id: FileToCheck.java,v 1.10 2003/03/07 22:44:54 bwalding Exp $
*
*/
public class FileToCheck
@@ -131,34 +130,41 @@ public class FileToCheck
ByteArrayOutputStream baos = new ByteArrayOutputStream();
PrintWriter errOut = new PrintWriter(baos);
tidy.setErrout(errOut);
System.out.println("Processing:" + fileToCheck);
tidy.setXHTML(true);
org.w3c.dom.Document domDocument = tidy.parseDOM(in, null);
// now read a dom4j document from
// JTidy's W3C DOM object
DOMReader domReader = new DOMReader();
doc = domReader.read(domDocument);
LOG.debug(baos.toString());
}
catch (IOException e)
catch (Throwable e)
{
System.out.println("While processing " + fileToCheck + " : " + e.toString());
//We catch Throwable, because there is a chance that the domReader will throw
//a stack overflow exception for some files
if (!(e instanceof Exception)) {
LOG.info("Caught " + e.toString());
}
LinkCheckResult lcr = new LinkCheckResult();
lcr.setStatus("PARSE FAILURE");
lcr.setTarget("N/A");
this.links.add(lcr);
return;
}
List xpathResults = new ArrayList();
xpathResults.addAll(doc.selectNodes("//a/@href"));
xpathResults.addAll(doc.selectNodes("//img/@src"));
//<link rel="stylesheet" href="...">
xpathResults.addAll(doc.selectNodes("//link/@href"));
//<script src="http://ar.atwola.com/file/adsWrapper.js">
xpathResults.addAll(doc.selectNodes("//script/@src"));
Map uniqueLinks = new HashMap();
Iterator linkIter = xpathResults.iterator();
while (linkIter.hasNext())
File diff suppressed because it is too large. Load diff
@@ -95,7 +95,7 @@ public class LinkCheckTest extends TestCase
map.put(ftc.getName(), ftc);
}
assertEquals("files.size()", 6, lc.getFiles().size());
assertEquals("files.size()", 7, lc.getFiles().size());
check(map, "nolink.html", 0);
check(map, "test-resources/nolink.html", 0);
@@ -103,6 +103,9 @@ public class LinkCheckTest extends TestCase
check(map, "test-resources/test1/test2.html", 0);
check(map, "test1/test1.html", 1);
check(map, "testA.html", 3);
//index-all.html should get parsed, but is currently having problems.
//check(map, "index-all.html", 1);
}