o MAVEN-286: Now enabled by default. Recognises proxies, not as many spurious messages.
git-svn-id: https://svn.apache.org/repos/asf/maven/maven-1/plugins/trunk@112971 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
1 parent
a649b56599
commit
aa891b3d5f
6 files changed
+179
-55
No files matched your search
@@ -75,7 +75,7 @@ import com.meterware.httpunit.WebResponse;
|
||||
|
||||
/**
|
||||
* @author <a href="mailto:bwalding@apache.org">Ben Walding</a>
|
||||
* @version $Id: FileToCheck.java,v 1.4 2003/02/15 08:03:23 bwalding Exp $
|
||||
* @version $Id: FileToCheck.java,v 1.5 2003/02/22 00:37:31 bwalding Exp $
|
||||
*
|
||||
*/
|
||||
public class FileToCheck
|
||||
@@ -106,6 +106,8 @@ public class FileToCheck
|
||||
status = STATUS_OK;
|
||||
message = "";
|
||||
|
||||
|
||||
|
||||
try
|
||||
{
|
||||
WebConversation wc = new WebConversation();
|
||||
|
||||
@@ -67,10 +67,12 @@ import java.util.List;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.apache.maven.jelly.MavenJellyContext;
|
||||
import org.apache.maven.linkcheck.validation.FileLinkValidator;
|
||||
import org.apache.maven.linkcheck.validation.HTTPLinkValidator;
|
||||
import org.apache.maven.linkcheck.validation.LinkValidatorManager;
|
||||
import org.apache.maven.linkcheck.validation.MailtoLinkValidator;
|
||||
import org.apache.maven.project.Project;
|
||||
|
||||
import com.meterware.httpunit.HttpUnitOptions;
|
||||
|
||||
@@ -79,7 +81,7 @@ import com.meterware.httpunit.HttpUnitOptions;
|
||||
* their links checked.
|
||||
*
|
||||
* @author <a href="mailto:bwalding@apache.org">Ben Walding</a>
|
||||
* @version $Id: LinkCheck.java,v 1.5 2003/02/15 08:04:20 bwalding Exp $
|
||||
* @version $Id: LinkCheck.java,v 1.6 2003/02/22 00:37:31 bwalding Exp $
|
||||
*/
|
||||
public class LinkCheck
|
||||
{
|
||||
@@ -97,6 +99,7 @@ public class LinkCheck
|
||||
private File baseDir;
|
||||
private String cache;
|
||||
private String exclude;
|
||||
private Project project;
|
||||
|
||||
/**
|
||||
* Set the base directory for the change log generator.
|
||||
@@ -261,7 +264,16 @@ public class LinkCheck
|
||||
lvm = new LinkValidatorManager();
|
||||
lvm.setExclude(exclude);
|
||||
lvm.addLinkValidator(new FileLinkValidator());
|
||||
lvm.addLinkValidator(new HTTPLinkValidator());
|
||||
MavenJellyContext ctx;
|
||||
if (getProject() == null) {
|
||||
System.out.println("No project set.");
|
||||
ctx = new MavenJellyContext();
|
||||
} else {
|
||||
System.out.println("Project set:" + getProject());
|
||||
ctx = ((Project) getProject()).getContext();
|
||||
}
|
||||
|
||||
lvm.addLinkValidator(new HTTPLinkValidator(ctx.getProxyHost(), ctx.getProxyPort(), ctx.getProxyUserName(), ctx.getProxyPassword()));
|
||||
lvm.addLinkValidator(new MailtoLinkValidator());
|
||||
lvm.loadCache(cache);
|
||||
}
|
||||
@@ -321,4 +333,22 @@ public class LinkCheck
|
||||
return buf.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Project
|
||||
*/
|
||||
public Object getProject()
|
||||
{
|
||||
return project;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the project.
|
||||
* @param project The project to set
|
||||
*/
|
||||
public void setProject(Object project)
|
||||
{
|
||||
System.out.println("Setting project: " + project);
|
||||
this.project = (Project) project;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -55,10 +55,11 @@ package org.apache.maven.linkcheck.validation;
|
||||
*
|
||||
* ====================================================================
|
||||
*/
|
||||
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import com.meterware.httpunit.Base64;
|
||||
import com.meterware.httpunit.GetMethodWebRequest;
|
||||
import com.meterware.httpunit.WebConversation;
|
||||
import com.meterware.httpunit.WebRequest;
|
||||
@@ -67,9 +68,10 @@ import com.meterware.httpunit.WebResponse;
|
||||
/**
|
||||
* Checks links which are normal URLs
|
||||
* @author <a href="mailto:bwalding@apache.org">Ben Walding</a>
|
||||
* @version $Id: HTTPLinkValidator.java,v 1.2 2003/02/03 14:13:54 bwalding Exp $
|
||||
* @version $Id: HTTPLinkValidator.java,v 1.3 2003/02/22 00:37:31 bwalding Exp $
|
||||
*/
|
||||
public class HTTPLinkValidator implements LinkValidator {
|
||||
public class HTTPLinkValidator implements LinkValidator
|
||||
{
|
||||
/**
|
||||
* Log for debug output
|
||||
*/
|
||||
@@ -78,28 +80,73 @@ public class HTTPLinkValidator implements LinkValidator {
|
||||
private final static LinkValidationResult LVR_INVALID =
|
||||
new LinkValidationResult(LinkValidationResult.INVALID, true);
|
||||
|
||||
private final static LinkValidationResult LVR_VALID =
|
||||
new LinkValidationResult(LinkValidationResult.VALID, true);
|
||||
private final static LinkValidationResult LVR_VALID = new LinkValidationResult(LinkValidationResult.VALID, true);
|
||||
|
||||
private boolean proxy;
|
||||
private String proxyHost;
|
||||
private int proxyPort;
|
||||
private String proxyUser;
|
||||
private String proxyPass;
|
||||
|
||||
public HTTPLinkValidator(String proxyHost, String proxyPort, String proxyUser, String proxyPass)
|
||||
{
|
||||
if (proxyHost == null)
|
||||
{
|
||||
proxy = false;
|
||||
LOG.info("Not using a proxy");
|
||||
}
|
||||
else
|
||||
{
|
||||
proxy = true;
|
||||
this.proxyHost = proxyHost;
|
||||
this.proxyPass = proxyPass;
|
||||
this.proxyUser = proxyUser;
|
||||
this.proxyPort = Integer.parseInt(proxyPort);
|
||||
LOG.info("Using Proxy Host:" + proxyHost);
|
||||
LOG.info("Using Proxy Port:" + proxyPort);
|
||||
LOG.info("Using Proxy User:" + proxyUser);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.apache.maven.linkcheck.LinkValidator#validateLink(org.apache.maven.linkcheck.LinkValidationItem)
|
||||
*/
|
||||
public LinkValidationResult validateLink(LinkValidationItem lvi) {
|
||||
try {
|
||||
public LinkValidationResult validateLink(LinkValidationItem lvi)
|
||||
{
|
||||
try
|
||||
{
|
||||
String link = lvi.getLink();
|
||||
LOG.debug("Checking web link:" + link);
|
||||
WebConversation wc = new WebConversation();
|
||||
if (proxy)
|
||||
{
|
||||
wc.setProxyServer(proxyHost, proxyPort);
|
||||
if (proxyUser != null)
|
||||
{
|
||||
String auth = proxyUser + ":" + proxyPass;
|
||||
wc.setHeaderField("Proxy-Authorization", "Basic " + Base64.encode(auth));
|
||||
}
|
||||
}
|
||||
|
||||
wc.setExceptionsThrownOnErrorStatus(false);
|
||||
WebRequest req = new GetMethodWebRequest(link);
|
||||
WebResponse resp = wc.getResponse(req);
|
||||
|
||||
//FIXME: This constant is defined somewhere, but I can't remember where...
|
||||
if (resp.getResponseCode() == 200) {
|
||||
if (resp.getResponseCode() == 200)
|
||||
{
|
||||
return LVR_VALID;
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
String msg = "Received: [" + resp.getResponseCode() + "] \"" + resp.getResponseMessage() + "\" for " + link;
|
||||
LOG.info(msg);
|
||||
System.out.println(msg);
|
||||
return LVR_INVALID;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
LOG.warn("Error accessing " + lvi.getLink(), e);
|
||||
e.printStackTrace();
|
||||
return LVR_INVALID;
|
||||
@@ -110,7 +157,8 @@ public class HTTPLinkValidator implements LinkValidator {
|
||||
/**
|
||||
* @see org.apache.maven.linkcheck.LinkValidator#getResourceKey(org.apache.maven.linkcheck.LinkValidationItem)
|
||||
*/
|
||||
public Object getResourceKey(LinkValidationItem lvi) {
|
||||
public Object getResourceKey(LinkValidationItem lvi)
|
||||
{
|
||||
String link = lvi.getLink();
|
||||
|
||||
if (!link.startsWith("http://"))
|
||||
|
||||
@@ -61,6 +61,7 @@ import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
/**
|
||||
@@ -73,7 +74,7 @@ public class LinkCheckTest extends TestCase
|
||||
|
||||
public void setUp()
|
||||
{
|
||||
baseDir = System.getProperty("basedir");
|
||||
baseDir = System.getProperty("basedir");
|
||||
}
|
||||
|
||||
public void testScan() throws Exception
|
||||
|
||||
Reference in new issue
Block a user