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:
@@ -7,18 +7,15 @@
|
||||
xmlns:doc="doc">
|
||||
|
||||
<property name="maven.linkcheck.cache" value="${pom.getPluginContext('maven-linkcheck-plugin').getVariable('maven.linkcheck.cache')}"/>
|
||||
<j:if test="${context.getVariable('maven.linkcheck.enable') != null}">
|
||||
<j:set var="maven.linkcheck.enable" value="true"/>
|
||||
</j:if>
|
||||
|
||||
<property name="maven.gen.docs" value="${pom.getPluginContext('maven-xdoc-plugin').getVariable('maven.gen.docs')}"/>
|
||||
|
||||
|
||||
<goal name="maven-linkcheck-plugin:register">
|
||||
<doc:registerReport
|
||||
name="Link Check Report"
|
||||
link="linkcheck"
|
||||
description="Report on the validity of all links in the documentation."/>
|
||||
<j:if test="${context.getVariable('maven.mode.online') == null}">
|
||||
<doc:registerReport
|
||||
name="Link Check Report"
|
||||
link="linkcheck"
|
||||
description="Report on the validity of all links in the documentation."/>
|
||||
</j:if>
|
||||
</goal>
|
||||
|
||||
<define:taglib uri="linkcheck">
|
||||
@@ -38,8 +35,8 @@
|
||||
-->
|
||||
|
||||
<goal name="maven-linkcheck-plugin:report">
|
||||
<echo>This run of linkcheck does nothing except create a template linkcheck file</echo>
|
||||
<copy file="${plugin.resources}/linkcheck-temp.xml" toFile="${maven.gen.docs}/linkcheck.xml"/>
|
||||
<copy file="${plugin.resources}/linkcheck-temp.xml"
|
||||
toFile="${maven.gen.docs}/linkcheck.xml"/>
|
||||
</goal>
|
||||
|
||||
<postGoal name="xdoc:jelly-transform">
|
||||
@@ -48,39 +45,30 @@
|
||||
|
||||
<goal
|
||||
name="maven-linkcheck-plugin:report-real"
|
||||
description="Generate a report from the link check results">
|
||||
<echo>BaseDir: ${basedir}</echo>
|
||||
description="Generate link check results and then transform to HTML">
|
||||
<mkdir dir="${maven.build.dir}/linkcheck"/>
|
||||
<mkdir dir="${maven.build.dir}/linkcheck/docs"/>
|
||||
<j:choose>
|
||||
<j:when test="${maven.linkcheck.enable}">
|
||||
<echo>Generating the LinkCheck report</echo>
|
||||
<linkcheck:linkcheck
|
||||
cache="${maven.linkcheck.cache}"
|
||||
exclude="${pom.repository.url}"
|
||||
basedir="${maven.docs.dest}"
|
||||
output="${maven.build.dir}/linkcheck/linkcheck-results.xml"
|
||||
outputEncoding="${maven.docs.outputencoding}"
|
||||
/>
|
||||
|
||||
<linkcheck:linkcheck
|
||||
project="${pom}"
|
||||
cache="${maven.linkcheck.cache}"
|
||||
exclude="${pom.repository.url}"
|
||||
basedir="${maven.docs.dest}"
|
||||
output="${maven.build.dir}/linkcheck/linkcheck-results.xml"
|
||||
outputEncoding="${maven.docs.outputencoding}"
|
||||
/>
|
||||
|
||||
<doc:jsl
|
||||
input="${maven.build.dir}/linkcheck/linkcheck-results.xml"
|
||||
output="../linkcheck/docs/linkcheck.xml"
|
||||
stylesheet="${plugin.resources}/linkcheck.jsl"
|
||||
omitXmlDeclaration="true"
|
||||
outputMode="xml"
|
||||
prettyPrint="true"
|
||||
/>
|
||||
<doc:jsl
|
||||
input="${maven.build.dir}/linkcheck/linkcheck-results.xml"
|
||||
output="../linkcheck/docs/linkcheck.xml"
|
||||
stylesheet="${plugin.resources}/linkcheck.jsl"
|
||||
omitXmlDeclaration="true"
|
||||
outputMode="xml"
|
||||
prettyPrint="true"
|
||||
/>
|
||||
|
||||
<j:set var="maven.xdoc.src" value="${maven.build.dir}/linkcheck/docs"/>
|
||||
<echo>maven.xdoc.src: ${maven.xdoc.src}</echo>
|
||||
<attainGoal name="xdoc:performJSL"/>
|
||||
</j:when>
|
||||
<j:otherwise>
|
||||
<echo>LinkCheck not enabled as maven.linkcheck.enable is not defined.</echo>
|
||||
</j:otherwise>
|
||||
</j:choose>
|
||||
|
||||
<j:set var="maven.xdoc.src" value="${maven.build.dir}/linkcheck/docs"/>
|
||||
<attainGoal name="xdoc:performJSL"/>
|
||||
</goal>
|
||||
|
||||
<goal name="maven-linkcheck-plugin:clearcache"
|
||||
|
||||
@@ -15,6 +15,27 @@
|
||||
<distributionDirectory>/www/jakarta.apache.org/builds/jakarta-turbine-maven/</distributionDirectory>
|
||||
<developers/>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<id>commons-beanutils</id>
|
||||
<version>1.6</version>
|
||||
<properties>
|
||||
<classloader>root.maven</classloader>
|
||||
</properties>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<id>commons-collections</id>
|
||||
<version>2.1</version>
|
||||
<properties>
|
||||
<classloader>root.maven</classloader>
|
||||
</properties>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<id>commons-jelly</id>
|
||||
<version>20030211.141339</version>
|
||||
<properties>
|
||||
<classloader>root.maven</classloader>
|
||||
</properties>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<id>commons-util</id>
|
||||
<version>final</version>
|
||||
@@ -46,6 +67,15 @@
|
||||
<classloader>root.maven</classloader>
|
||||
</properties>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>commons-jelly</groupId>
|
||||
<artifactId>commons-jelly-tags-ant</artifactId>
|
||||
<version>20030211.142045</version>
|
||||
<url>http://jakarta.apache.org/commons/jelly/tags/ant/</url>
|
||||
<properties>
|
||||
<classloader>root.maven</classloader>
|
||||
</properties>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<id>commons-logging</id>
|
||||
<version>1.0</version>
|
||||
@@ -53,6 +83,13 @@
|
||||
<classloader>root.maven</classloader>
|
||||
</properties>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<id>dom4j</id>
|
||||
<version>1.4-dev-8</version>
|
||||
<properties>
|
||||
<classloader>root.maven</classloader>
|
||||
</properties>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<id>httpunit</id>
|
||||
<version>1.5.1</version>
|
||||
@@ -67,6 +104,15 @@
|
||||
<classloader>root.maven</classloader>
|
||||
</properties>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<id>maven</id>
|
||||
<version></version>
|
||||
<jar>maven.jar</jar>
|
||||
<properties>
|
||||
<classloader>root.maven</classloader>
|
||||
</properties>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<id>rhino</id>
|
||||
<version>1.5R4-RC3</version>
|
||||
@@ -75,6 +121,15 @@
|
||||
<classloader>root.maven</classloader>
|
||||
</properties>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<id>werkz</id>
|
||||
<version>1.0-beta-7</version>
|
||||
<url>http://werkz.sourceforge.net/</url>
|
||||
<properties>
|
||||
<classloader>root.maven</classloader>
|
||||
</properties>
|
||||
</dependency>
|
||||
|
||||
|
||||
</dependencies>
|
||||
</project>
|
||||
|
||||
@@ -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