diff --git a/linkcheck/plugin.jelly b/linkcheck/plugin.jelly index 2e8c5734..19610174 100644 --- a/linkcheck/plugin.jelly +++ b/linkcheck/plugin.jelly @@ -89,6 +89,7 @@ basedir="${maven.docs.dest}" output="${maven.build.dir}/linkcheck/linkcheck-results.xml" outputEncoding="${maven.docs.outputencoding}" + method="${maven.linkcheck.method}" /> diff --git a/linkcheck/plugin.properties b/linkcheck/plugin.properties index 00587d20..4431a607 100644 --- a/linkcheck/plugin.properties +++ b/linkcheck/plugin.properties @@ -26,3 +26,4 @@ maven.linkcheck.proxy.username=${maven.proxy.username} maven.linkcheck.proxy.password=${maven.proxy.password} maven.linkcheck.proxy.ntlm.host=${maven.proxy.ntlm.host} maven.linkcheck.proxy.ntlm.domain=${maven.proxy.ntlm.domain} +maven.linkcheck.method=head diff --git a/linkcheck/project.properties b/linkcheck/project.properties index 21a54044..409659a1 100644 --- a/linkcheck/project.properties +++ b/linkcheck/project.properties @@ -20,6 +20,7 @@ maven.junit.fork=yes # Properties required for the unit tests maven.junit.sysproperties = \ + maven.linkcheck.method \ maven.linkcheck.proxy.host \ maven.linkcheck.proxy.port \ maven.linkcheck.proxy.username \ diff --git a/linkcheck/src/main/org/apache/maven/plugin/linkcheck/LinkCheck.java b/linkcheck/src/main/org/apache/maven/plugin/linkcheck/LinkCheck.java index 514c5374..46b53bfb 100644 --- a/linkcheck/src/main/org/apache/maven/plugin/linkcheck/LinkCheck.java +++ b/linkcheck/src/main/org/apache/maven/plugin/linkcheck/LinkCheck.java @@ -76,6 +76,8 @@ public final class LinkCheck private String exclude; + private String method; + private List filesToCheck = null; private LinkValidatorManager lvm = null; @@ -151,6 +153,22 @@ public final class LinkCheck this.exclude = exclude; } + /** + * @return the method + */ + public String getMethod() + { + return method; + } + + /** + * @param method the method to set + */ + public void setMethod( String method ) + { + this.method = method; + } + public List getFiles() { return filesToCheck; @@ -182,6 +200,7 @@ public final class LinkCheck { lvm .addLinkValidator( new OnlineHTTPLinkValidator( + getMethod(), (String) ctx.getVariable( MAVEN_PROXY_HOST ), (String) ctx.getVariable( MAVEN_PROXY_PORT ), (String) ctx.getVariable( MAVEN_PROXY_USERNAME ), diff --git a/linkcheck/src/main/org/apache/maven/plugin/linkcheck/validation/OnlineHTTPLinkValidator.java b/linkcheck/src/main/org/apache/maven/plugin/linkcheck/validation/OnlineHTTPLinkValidator.java index d46d8362..7a01e124 100644 --- a/linkcheck/src/main/org/apache/maven/plugin/linkcheck/validation/OnlineHTTPLinkValidator.java +++ b/linkcheck/src/main/org/apache/maven/plugin/linkcheck/validation/OnlineHTTPLinkValidator.java @@ -18,6 +18,7 @@ import org.apache.commons.httpclient.MultiThreadedHttpConnectionManager; import org.apache.commons.httpclient.NTCredentials; import org.apache.commons.httpclient.StatusLine; import org.apache.commons.httpclient.UsernamePasswordCredentials; +import org.apache.commons.httpclient.methods.GetMethod; import org.apache.commons.httpclient.methods.HeadMethod; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -39,6 +40,12 @@ public final class OnlineHTTPLinkValidator /** The maximum number of redirections for a link */ private final static int MAX_NB_REDIRECT = 10; + /** Use the get method to test pages. */ + private final static String GET_METHOD = "GET"; + + /** Use the head method to test pages. */ + private final static String HEAD_METHOD = "HEAD"; + private String proxyHost; private int proxyPort; @@ -51,11 +58,16 @@ public final class OnlineHTTPLinkValidator private String proxyNtlmDomain; + private String method = HEAD_METHOD; + private transient HttpClient cl; - public OnlineHTTPLinkValidator( String proxyHost, String proxyPort, String proxyUser, String proxyPass, - String proxyNtlmHost, String proxyNtlmDomain ) + public OnlineHTTPLinkValidator( String method, String proxyHost, String proxyPort, String proxyUser, + String proxyPass, String proxyNtlmHost, String proxyNtlmDomain ) { + if ( LOG.isDebugEnabled() ) + LOG.debug( "Will use method : [" + method + "]" ); + this.method = method; if ( proxyHost == null || proxyHost.trim().equals( "" ) ) { this.proxyHost = null; @@ -203,8 +215,11 @@ public final class OnlineHTTPLinkValidator { throw new HttpException( "Maximum number of redirections (" + MAX_NB_REDIRECT + ") exceeded" ); } - // execute the HEAD (a GET without the body returned) - HttpMethod hm = new HeadMethod( link ); + HttpMethod hm; + if ( HEAD_METHOD.equals( method ) ) + hm = new HeadMethod( link ); + else + hm = new GetMethod( link ); try { // We want to do it manually diff --git a/linkcheck/src/test/org/apache/maven/plugin/linkcheck/validation/HTTPLinkValidatorTest.java b/linkcheck/src/test/org/apache/maven/plugin/linkcheck/validation/HTTPLinkValidatorTest.java index 91adb4bd..804101ec 100644 --- a/linkcheck/src/test/org/apache/maven/plugin/linkcheck/validation/HTTPLinkValidatorTest.java +++ b/linkcheck/src/test/org/apache/maven/plugin/linkcheck/validation/HTTPLinkValidatorTest.java @@ -39,7 +39,7 @@ public class HTTPLinkValidatorTest System.err.println( "maven.mode.online : " + mavenOnline ); if ( mavenOnline ) { - hlv = new OnlineHTTPLinkValidator( System.getProperty( "maven.linkcheck.proxy.host" ), System + hlv = new OnlineHTTPLinkValidator( System.getProperty( "maven.linkcheck.method" ), System.getProperty( "maven.linkcheck.proxy.host" ), System .getProperty( "maven.linkcheck.proxy.port" ), System.getProperty( "maven.linkcheck.proxy.username" ), System.getProperty( "maven.linkcheck.proxy.password" ), System .getProperty( "maven.linkcheck.proxy.ntlm.host" ), System diff --git a/linkcheck/xdocs/changes.xml b/linkcheck/xdocs/changes.xml index 078ab9ae..cabffae4 100644 --- a/linkcheck/xdocs/changes.xml +++ b/linkcheck/xdocs/changes.xml @@ -25,6 +25,7 @@ + Add the property "maven.linkcheck.method" to select the method to use to do the tests (head -by default-,or get). Display for each file the number of links and the number of errors. New counters to report how many files and links are checked and how many errors are found. Display a more verbose message than the "NOT FOUND" error. diff --git a/linkcheck/xdocs/properties.xml b/linkcheck/xdocs/properties.xml index 980941cb..3569307e 100644 --- a/linkcheck/xdocs/properties.xml +++ b/linkcheck/xdocs/properties.xml @@ -109,6 +109,15 @@ Defaults to maven.proxy.ntlm.domain. + + maven.linkcheck.method + Yes + + The method to use to test pages. The value should be 'head' or 'get'. + In some cases (particularly with some proxies) the head method doesn't work witl all servers. + The get method is slower but safe. Defaults to head. + +