o Now follow 302 redirects (one level only)
o Cleaned up logging a little bit and added more logging o Doesn't address the MacOSX bug (test failure bug), but the logging increase might help git-svn-id: https://svn.apache.org/repos/asf/maven/maven-1/plugins/trunk@114004 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
1 parent
deecc44eed
commit
8c83124f3e
11 files changed
+88
-95
No files matched your search
@@ -1,3 +1,5 @@
|
||||
target
|
||||
velocity.log
|
||||
maven.log
|
||||
.classpath
|
||||
.project
|
||||
@@ -1,14 +1,3 @@
|
||||
<project default="jar:jar">
|
||||
|
||||
|
||||
<postGoal name="java:compile">
|
||||
<copy toDir="target/classes">
|
||||
<fileset dir="src/main">
|
||||
<includes name="**/*"/>
|
||||
<excludes name="**/*.java"/>
|
||||
</fileset>
|
||||
</copy>
|
||||
</postGoal>
|
||||
|
||||
|
||||
</project>
|
||||
@@ -39,7 +39,7 @@
|
||||
</dependency>
|
||||
<dependency>
|
||||
<id>commons-httpclient</id>
|
||||
<version>2.0-alpha3</version>
|
||||
<version>2.0-rc1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<id>commons-jelly</id>
|
||||
@@ -132,7 +132,7 @@
|
||||
</dependency>
|
||||
<dependency>
|
||||
<id>werkz</id>
|
||||
<version>1.0-beta-7</version>
|
||||
<version>1.0-beta-10</version>
|
||||
<url>http://werkz.sourceforge.net/</url>
|
||||
<properties>
|
||||
<classloader>root.maven</classloader>
|
||||
|
||||
@@ -78,7 +78,7 @@ import org.w3c.tidy.Tidy;
|
||||
|
||||
/**
|
||||
* @author <a href="mailto:bwalding@apache.org">Ben Walding</a>
|
||||
* @version $Id: FileToCheck.java,v 1.11 2003/03/07 22:46:39 bwalding Exp $
|
||||
* @version $Id: FileToCheck.java,v 1.12 2003/09/13 21:48:08 bwalding Exp $
|
||||
*
|
||||
*/
|
||||
public class FileToCheck
|
||||
@@ -146,9 +146,8 @@ public class FileToCheck
|
||||
{
|
||||
//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());
|
||||
}
|
||||
LOG.info("Caught " + e.toString() + " processing " + getName());
|
||||
LOG.info("Exception Message: " + e.getLocalizedMessage());
|
||||
LinkCheckResult lcr = new LinkCheckResult();
|
||||
lcr.setStatus("PARSE FAILURE");
|
||||
lcr.setTarget("N/A");
|
||||
@@ -179,7 +178,7 @@ public class FileToCheck
|
||||
{
|
||||
String href = (String) iter.next();
|
||||
|
||||
//System.out.println("Link Found: " + href);
|
||||
LOG.debug("Link Found: " + href);
|
||||
|
||||
LinkCheckResult lcr = new LinkCheckResult();
|
||||
|
||||
@@ -189,21 +188,24 @@ public class FileToCheck
|
||||
|
||||
switch (result.getStatus())
|
||||
{
|
||||
case LinkValidationResult.UNKNOWN :
|
||||
unsuccessful++;
|
||||
lcr.setStatus("UNKNOWN REF");
|
||||
break;
|
||||
case LinkValidationResult.VALID :
|
||||
successful++;
|
||||
lcr.setStatus("OK");
|
||||
this.links.add(lcr); //At some point we won't want to store valid links. The tests require that we do at present
|
||||
break;
|
||||
case LinkValidationResult.UNKNOWN :
|
||||
unsuccessful++;
|
||||
lcr.setStatus("UNKNOWN REF");
|
||||
this.links.add(lcr);
|
||||
break;
|
||||
case LinkValidationResult.INVALID :
|
||||
unsuccessful++;
|
||||
lcr.setStatus("NOT FOUND");
|
||||
this.links.add(lcr);
|
||||
break;
|
||||
}
|
||||
|
||||
this.links.add(lcr);
|
||||
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
|
||||
@@ -79,19 +79,17 @@ import org.apache.maven.project.Project;
|
||||
* their links checked.
|
||||
*
|
||||
* @author <a href="mailto:bwalding@apache.org">Ben Walding</a>
|
||||
* @version $Id: LinkCheck.java,v 1.9 2003/04/17 12:58:33 bwalding Exp $
|
||||
* @version $Id: LinkCheck.java,v 1.10 2003/09/13 21:48:08 bwalding Exp $
|
||||
*/
|
||||
public class LinkCheck
|
||||
{
|
||||
/** Log */
|
||||
private static final Log LOG = LogFactory.getLog(LinkCheck.class);
|
||||
|
||||
/**
|
||||
* Output file for xml document
|
||||
*/
|
||||
/** Output file for xml document */
|
||||
private File output;
|
||||
|
||||
/** output encoding for the xml document */
|
||||
/** Output encoding for the xml document */
|
||||
private String outputEncoding;
|
||||
|
||||
private File baseDir;
|
||||
@@ -134,21 +132,21 @@ public class LinkCheck
|
||||
* @throws UnsupportedEncodingException if the underlying platform doesn't
|
||||
* support ISO-8859-1 encoding
|
||||
*/
|
||||
List filesToCheck = null; //of FileToCheck
|
||||
private List filesToCheck = null; //of FileToCheck
|
||||
public void doExecute() throws Exception
|
||||
{
|
||||
|
||||
|
||||
if (output == null)
|
||||
{
|
||||
throw new NullPointerException("output must be set");
|
||||
}
|
||||
LinkValidatorManager lvm = getLinkValidatorManager();
|
||||
LinkValidatorManager validator = getLinkValidatorManager();
|
||||
|
||||
filesToCheck = new ArrayList();
|
||||
lvm.loadCache(cache);
|
||||
validator.loadCache(cache);
|
||||
List files = new ArrayList();
|
||||
LOG.debug("Locating all files to be checked...");
|
||||
findFiles(files, baseDir);
|
||||
LOG.debug("Located all files to be checked.");
|
||||
Iterator fileIter = files.iterator();
|
||||
while (fileIter.hasNext())
|
||||
{
|
||||
@@ -156,7 +154,8 @@ public class LinkCheck
|
||||
try
|
||||
{
|
||||
filesToCheck.add(flc);
|
||||
flc.check(lvm);
|
||||
LOG.info("Validating " + flc.getName());
|
||||
flc.check(validator);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
@@ -165,7 +164,7 @@ public class LinkCheck
|
||||
}
|
||||
|
||||
createDocument(files);
|
||||
lvm.saveCache(cache);
|
||||
validator.saveCache(cache);
|
||||
}
|
||||
|
||||
public List getFiles()
|
||||
|
||||
@@ -61,7 +61,7 @@ import org.apache.commons.util.XmlUtils;
|
||||
/**
|
||||
* An class containing the results of a single check of a link.
|
||||
* @author <a href="mailto:bwalding@apache.org">Ben Walding</a>
|
||||
* @version $Id: LinkCheckResult.java,v 1.3 2003/02/03 14:13:54 bwalding Exp $
|
||||
* @version $Id: LinkCheckResult.java,v 1.4 2003/09/13 21:48:08 bwalding Exp $
|
||||
*/
|
||||
public class LinkCheckResult
|
||||
{
|
||||
@@ -104,6 +104,10 @@ public class LinkCheckResult
|
||||
this.target = target;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an XML representation of this link check result
|
||||
* @return xml fragment representation of this result
|
||||
*/
|
||||
public String toXML()
|
||||
{
|
||||
StringBuffer buf = new StringBuffer();
|
||||
@@ -112,6 +116,7 @@ public class LinkCheckResult
|
||||
buf.append(" <target>" + XmlUtils.escapeXml(getTarget()) + "</target>\n");
|
||||
buf.append(" <status>" + getStatus() + "</status>\n");
|
||||
buf.append(" </result>\n");
|
||||
|
||||
return buf.toString();
|
||||
}
|
||||
|
||||
|
||||
@@ -56,6 +56,7 @@ package org.apache.maven.linkcheck.validation;
|
||||
* ====================================================================
|
||||
*/
|
||||
|
||||
import org.apache.commons.httpclient.Header;
|
||||
import org.apache.commons.httpclient.HostConfiguration;
|
||||
import org.apache.commons.httpclient.HttpClient;
|
||||
import org.apache.commons.httpclient.HttpState;
|
||||
@@ -67,7 +68,7 @@ import org.apache.commons.logging.LogFactory;
|
||||
/**
|
||||
* Checks links which are normal URLs
|
||||
* @author <a href="mailto:bwalding@apache.org">Ben Walding</a>
|
||||
* @version $Id: HTTPLinkValidator.java,v 1.7 2003/04/17 13:07:03 bwalding Exp $
|
||||
* @version $Id: HTTPLinkValidator.java,v 1.8 2003/09/13 21:48:08 bwalding Exp $
|
||||
*/
|
||||
public class HTTPLinkValidator implements LinkValidator
|
||||
{
|
||||
@@ -81,7 +82,6 @@ public class HTTPLinkValidator implements LinkValidator
|
||||
|
||||
private static final LinkValidationResult LVR_VALID = new LinkValidationResult(LinkValidationResult.VALID, true);
|
||||
|
||||
private boolean proxy;
|
||||
private String proxyHost;
|
||||
private int proxyPort;
|
||||
private String proxyUser;
|
||||
@@ -91,19 +91,18 @@ public class HTTPLinkValidator implements LinkValidator
|
||||
{
|
||||
if (proxyHost == null)
|
||||
{
|
||||
proxy = false;
|
||||
System.out.println("maven-linkcheck-plugin: Not using a proxy");
|
||||
LOG.info("maven-linkcheck-plugin: Not using a proxy");
|
||||
this.proxyHost = null;
|
||||
}
|
||||
else
|
||||
{
|
||||
proxy = true;
|
||||
this.proxyHost = proxyHost;
|
||||
this.proxyPort = Integer.parseInt(proxyPort);
|
||||
this.proxyUser = proxyUser;
|
||||
this.proxyPass = proxyPass;
|
||||
System.out.println("maven-linkcheck-plugin: Proxy Host:" + proxyHost);
|
||||
System.out.println("maven-linkcheck-plugin: Proxy Port:" + proxyPort);
|
||||
System.out.println("maven-linkcheck-plugin: Proxy User:" + proxyUser);
|
||||
LOG.info("maven-linkcheck-plugin: Proxy Host:" + proxyHost);
|
||||
LOG.info("maven-linkcheck-plugin: Proxy Port:" + proxyPort);
|
||||
LOG.info("maven-linkcheck-plugin: Proxy User:" + proxyUser);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -125,36 +124,38 @@ public class HTTPLinkValidator implements LinkValidator
|
||||
hc.setProxy(proxyHost, proxyPort);
|
||||
}
|
||||
HttpState state = new HttpState();
|
||||
|
||||
|
||||
if (proxyUser != null && proxyPass != null)
|
||||
{
|
||||
state.setProxyCredentials(null, new UsernamePasswordCredentials(proxyUser, proxyPass));
|
||||
state.setProxyCredentials(null, null, new UsernamePasswordCredentials(proxyUser, proxyPass));
|
||||
}
|
||||
|
||||
GetMethod get = new GetMethod(link);
|
||||
cl.setHostConfiguration(hc);
|
||||
cl.setState(state);
|
||||
get.setFollowRedirects(true);
|
||||
|
||||
|
||||
// execute the GET
|
||||
int status = 404;
|
||||
try
|
||||
GetMethod gm = checkLink(cl, link);
|
||||
|
||||
if (gm.getStatusCode() == 302)
|
||||
{
|
||||
status = cl.executeMethod(get);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
System.out.println(e);
|
||||
Header locationHeader = gm.getResponseHeader("Location");
|
||||
if (locationHeader == null) {
|
||||
LOG.info("Site sent redirect, but did not set Location header");
|
||||
} else {
|
||||
String newLink = locationHeader.getValue();
|
||||
LOG.debug("Following 1 redirect to " + newLink);
|
||||
gm = checkLink(cl, newLink);
|
||||
}
|
||||
}
|
||||
|
||||
//FIXME: This constant is defined somewhere, but I can't remember where...
|
||||
if (status == 200)
|
||||
if (gm.getStatusCode() == 200)
|
||||
{
|
||||
return LVR_VALID;
|
||||
}
|
||||
else
|
||||
{
|
||||
String msg = "Received: [" + status + "] for " + link;
|
||||
String msg = "Received: [" + gm.getStatusCode() + "] for " + link;
|
||||
LOG.info(msg);
|
||||
System.out.println(msg);
|
||||
return LVR_INVALID;
|
||||
@@ -170,6 +171,23 @@ public class HTTPLinkValidator implements LinkValidator
|
||||
|
||||
}
|
||||
|
||||
private GetMethod checkLink(HttpClient cl, String link)
|
||||
{
|
||||
GetMethod gm = new GetMethod(link);
|
||||
try
|
||||
{
|
||||
LOG.info("Checking link " + link);
|
||||
gm.setFollowRedirects(true);
|
||||
cl.executeMethod(gm);
|
||||
LOG.debug("Checked link " + link);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
LOG.warn("Error validating " + link, e);
|
||||
}
|
||||
return gm;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.apache.maven.linkcheck.LinkValidator#getResourceKey(org.apache.maven.linkcheck.LinkValidationItem)
|
||||
*/
|
||||
|
||||
@@ -60,11 +60,11 @@ import java.io.File;
|
||||
|
||||
/**
|
||||
* @author <a href="mailto:bwalding@apache.org">Ben Walding</a>
|
||||
* @version $Id: LinkValidationItem.java,v 1.2 2003/02/03 14:13:54 bwalding Exp $
|
||||
* @version $Id: LinkValidationItem.java,v 1.3 2003/09/13 21:48:08 bwalding Exp $
|
||||
*/
|
||||
public class LinkValidationItem {
|
||||
private File source;
|
||||
private String link;
|
||||
private final File source;
|
||||
private final String link;
|
||||
|
||||
public LinkValidationItem(File source, String link) {
|
||||
if (source == null) {
|
||||
@@ -89,7 +89,8 @@ public class LinkValidationItem {
|
||||
return false;
|
||||
|
||||
if (!lvi.source.equals(source))
|
||||
return false;
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -116,22 +117,5 @@ public class LinkValidationItem {
|
||||
public File getSource() {
|
||||
return source;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the link.
|
||||
* @param link The link to set
|
||||
*/
|
||||
public void setLink(String link) {
|
||||
this.link = link;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the source.
|
||||
* @param source The source to set
|
||||
*/
|
||||
public void setSource(File source) {
|
||||
this.source = source;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -57,14 +57,14 @@ package org.apache.maven.linkcheck.validation;
|
||||
*/
|
||||
|
||||
/**
|
||||
* @author <a href="mailto:bwalding@apache.org">Ben Walding</a>
|
||||
* @version $Id: LinkValidationResult.java,v 1.2 2003/02/03 14:13:54 bwalding Exp $
|
||||
* <b>This is an immutable class.</b><br/>
|
||||
* <p>
|
||||
* This class is used to return status responses from the
|
||||
* validation handlers. A persistent result means that it
|
||||
* can be stored in the persistent cache and used across runs.
|
||||
* </p>
|
||||
* @author <a href="mailto:bwalding@apache.org">Ben Walding</a>
|
||||
* @version $Id: LinkValidationResult.java,v 1.3 2003/09/13 21:48:08 bwalding Exp $
|
||||
*/
|
||||
public class LinkValidationResult {
|
||||
public static final int NOTMINE = 0;
|
||||
@@ -72,14 +72,14 @@ public class LinkValidationResult {
|
||||
public static final int VALID = 2;
|
||||
public static final int UNKNOWN = 3;
|
||||
|
||||
private int status = UNKNOWN;
|
||||
private final boolean persistent;
|
||||
private final int status;
|
||||
|
||||
public LinkValidationResult(int status, boolean persistent) {
|
||||
this.status = status;
|
||||
this.persistent = persistent;
|
||||
}
|
||||
|
||||
boolean persistent;
|
||||
public boolean isPersistent() {
|
||||
return persistent;
|
||||
}
|
||||
|
||||
@@ -66,11 +66,11 @@ import java.util.Properties;
|
||||
|
||||
/**
|
||||
* @author <a href="mailto:bwalding@apache.org">Ben Walding</a>
|
||||
* @version $Id: LinkValidatorCache.java,v 1.2 2003/02/03 14:13:54 bwalding Exp $
|
||||
* @version $Id: LinkValidatorCache.java,v 1.3 2003/09/13 21:48:08 bwalding Exp $
|
||||
*/
|
||||
public class LinkValidatorCache {
|
||||
private LinkValidatorManager lvm;
|
||||
private Map cache = new HashMap();
|
||||
private final Map cache = new HashMap();
|
||||
|
||||
public LinkValidatorCache(LinkValidatorManager lvm) {
|
||||
this.lvm = lvm;
|
||||
@@ -80,10 +80,10 @@ public class LinkValidatorCache {
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param lvi
|
||||
* @return int Will return a status level, VALID, INVALID, UNKNOWN
|
||||
*/
|
||||
*
|
||||
* @param lvi
|
||||
* @return int Will return a status level, VALID, INVALID, UNKNOWN
|
||||
*/
|
||||
public LinkValidationResult getCachedResult(LinkValidationItem lvi) {
|
||||
Iterator iter = lvm.getValidators().iterator();
|
||||
|
||||
|
||||
@@ -10,12 +10,6 @@
|
||||
<p>
|
||||
This file is used as a placeholder until the final link check can occur.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
At present, you MUST set maven.linkcheck.enable=true in your project properties
|
||||
to have the linkchecker run. Once it has stabilised, it will be turned on by default
|
||||
(except in offline mode).
|
||||
</p>
|
||||
</section>
|
||||
</body>
|
||||
</document>
|
||||
Reference in new issue
Block a user