+ * Link matcher. Reads the contents of a file and tries to match the following:
* link|a|img|script)[^>]*?(?>href|src)\\s*?=\\s*?[\\\"'](.*?)[\\\"'][^>]*?",
- Pattern.CASE_INSENSITIVE );
+ private final static Pattern p =
+ Pattern.compile( "<(?>link|a|img|script)[^>]*?(?>href|src)\\s*?=\\s*?[\\\"'](.*?)[\\\"'][^>]*?",
+ Pattern.CASE_INSENSITIVE );
/**
- * No need to create a new object each time a file is processed. Just clear
- * it.
+ * No need to create a new object each time a file is processed. Just clear it.
*/
private final static Set linkList = new TreeSet();
@@ -65,8 +63,7 @@ class LinkMatcher
* @return a StringBuffer with file's contents.
* @throws IOException
*/
- private static StringBuffer fileToStringBuffer( File file )
- throws IOException
+ private static StringBuffer fileToStringBuffer( File file ) throws IOException
{
BufferedReader reader = null;
final StringBuffer pageBuffer = new StringBuffer();
@@ -94,8 +91,7 @@ class LinkMatcher
* @return a set with all links to check
* @throws IOException
*/
- static Set match( File file )
- throws IOException
+ static Set match( File file ) throws IOException
{
linkList.clear();
final Matcher m = p.matcher( fileToStringBuffer( file ) );
diff --git a/linkcheck/src/main/org/apache/maven/plugin/linkcheck/validation/FileLinkValidator.java b/linkcheck/src/main/org/apache/maven/plugin/linkcheck/validation/FileLinkValidator.java
index d1e054e6..3ab73618 100644
--- a/linkcheck/src/main/org/apache/maven/plugin/linkcheck/validation/FileLinkValidator.java
+++ b/linkcheck/src/main/org/apache/maven/plugin/linkcheck/validation/FileLinkValidator.java
@@ -26,8 +26,7 @@ import java.io.File;
* @author Arnaud Heritier
* @version $Id$
*/
-public final class FileLinkValidator
- implements LinkValidator
+public final class FileLinkValidator implements LinkValidator
{
/**
* @see org.apache.maven.plugin.linkcheck.LinkValidator#validateLink(org.apache.maven.plugin.linkcheck.LinkValidationItem)
@@ -36,9 +35,13 @@ public final class FileLinkValidator
{
File f = getFile( lvi );
if ( f.exists() )
+ {
return new LinkValidationResult( LinkValidationResult.VALID, false, "" );
+ }
else
+ {
return new LinkValidationResult( LinkValidationResult.ERROR, false, "doesn't exist." );
+ }
}
/**
@@ -49,7 +52,9 @@ public final class FileLinkValidator
String link = lvi.getLink();
// If we find an http(s) link or a mail link, it's not good
if ( link.startsWith( "http://" ) || link.startsWith( "https://" ) || link.indexOf( '@' ) != -1 )
+ {
return null;
+ }
return getFile( lvi ).getAbsolutePath();
}
@@ -65,19 +70,23 @@ public final class FileLinkValidator
{
link = link.substring( 0, link.indexOf( '#' ) );
- //If the link was just #fred or similar, then the file is the file it came from
- //XXX: Theoretically we could even validate the anchor tag?
+ // If the link was just #fred or similar, then the file is the file it came from
+ // XXX: Theoretically we could even validate the anchor tag?
if ( link.trim().length() == 0 )
+ {
return lvi.getSource();
+ }
}
if ( link.indexOf( '?' ) != -1 )
{
link = link.substring( 0, link.indexOf( '?' ) );
- //If the link was just ?param=something or similar, then the file is the file it came from
- //XXX: Theoretically we could even validate the anchor tag?
+ // If the link was just ?param=something or similar, then the file is the file it came from
+ // XXX: Theoretically we could even validate the anchor tag?
if ( link.trim().length() == 0 )
+ {
return lvi.getSource();
+ }
}
File f = new File( lvi.getSource().getParentFile(), link );
return f;
diff --git a/linkcheck/src/main/org/apache/maven/plugin/linkcheck/validation/HTTPLinkValidator.java b/linkcheck/src/main/org/apache/maven/plugin/linkcheck/validation/HTTPLinkValidator.java
index 7d7edd49..edf275c4 100644
--- a/linkcheck/src/main/org/apache/maven/plugin/linkcheck/validation/HTTPLinkValidator.java
+++ b/linkcheck/src/main/org/apache/maven/plugin/linkcheck/validation/HTTPLinkValidator.java
@@ -17,15 +17,14 @@ package org.apache.maven.plugin.linkcheck.validation;
* ====================================================================
*/
-
/**
* Checks links which are normal URLs
+ *
* @author Ben Walding
* @author Arnaud Heritier
* @version $Id$
*/
-public abstract class HTTPLinkValidator
- implements LinkValidator
+public abstract class HTTPLinkValidator implements LinkValidator
{
/**
* @see org.apache.maven.plugin.linkcheck.LinkValidator#getResourceKey(org.apache.maven.plugin.linkcheck.LinkValidationItem)
@@ -34,10 +33,14 @@ public abstract class HTTPLinkValidator
{
String link = lvi.getLink();
if ( !link.startsWith( "http://" ) && !link.startsWith( "https://" ) )
+ {
return null;
+ }
int hashPos = link.indexOf( "#" );
if ( hashPos != -1 )
+ {
link = link.substring( 0, hashPos );
+ }
return link;
}
diff --git a/linkcheck/src/main/org/apache/maven/plugin/linkcheck/validation/LinkValidationItem.java b/linkcheck/src/main/org/apache/maven/plugin/linkcheck/validation/LinkValidationItem.java
index 6b584538..39a9798a 100644
--- a/linkcheck/src/main/org/apache/maven/plugin/linkcheck/validation/LinkValidationItem.java
+++ b/linkcheck/src/main/org/apache/maven/plugin/linkcheck/validation/LinkValidationItem.java
@@ -16,7 +16,7 @@ package org.apache.maven.plugin.linkcheck.validation;
* limitations under the License.
* ====================================================================
*/
-
+
import java.io.File;
/**
@@ -24,59 +24,74 @@ import java.io.File;
* @author Arnaud Heritier
* @version $Id$
*/
-public class LinkValidationItem {
+public class LinkValidationItem
+{
private final File source;
+
private final String link;
-
- public LinkValidationItem(File source, String link) {
- if (source == null) {
- throw new NullPointerException("source can't be null");
+
+ public LinkValidationItem( File source, String link )
+ {
+ if ( source == null )
+ {
+ throw new NullPointerException( "source can't be null" );
}
-
- if (link == null) {
- throw new NullPointerException("link can't be null");
+
+ if ( link == null )
+ {
+ throw new NullPointerException( "link can't be null" );
}
-
+
this.source = source;
this.link = link;
}
/**
* Returns the link.
+ *
* @return String
*/
- public String getLink() {
- return link;
+ public String getLink()
+ {
+ return this.link;
}
/**
* Returns the source.
+ *
* @return File
*/
- public File getSource() {
- return source;
+ public File getSource()
+ {
+ return this.source;
}
/**
* @see java.lang.Object#equals(java.lang.Object)
*/
- public boolean equals(Object obj) {
+ public boolean equals( Object obj )
+ {
LinkValidationItem lvi = (LinkValidationItem) obj;
-
- if (!lvi.link.equals(link))
+
+ if ( !lvi.link.equals( this.link ) )
+ {
return false;
-
- if (!lvi.source.equals(source))
+ }
+
+ if ( !lvi.source.equals( this.source ) )
+ {
return false;
-
+ }
+
return true;
}
/**
* @see java.lang.Object#hashCode()
*/
- public int hashCode() {
- return source.hashCode() ^ link.hashCode();
+ public int hashCode()
+ {
+ return this.source.hashCode() ^ this.link.hashCode();
}
-
+
}
diff --git a/linkcheck/src/main/org/apache/maven/plugin/linkcheck/validation/LinkValidationResult.java b/linkcheck/src/main/org/apache/maven/plugin/linkcheck/validation/LinkValidationResult.java
index bc08d8ab..5ea876d6 100644
--- a/linkcheck/src/main/org/apache/maven/plugin/linkcheck/validation/LinkValidationResult.java
+++ b/linkcheck/src/main/org/apache/maven/plugin/linkcheck/validation/LinkValidationResult.java
@@ -21,17 +21,21 @@ import java.io.Serializable;
/**
*
- * 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.
+ * 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.
*
+ *
* @author Ben Walding
* @author Arnaud Heritier
* @version $Id$
*/
-public class LinkValidationResult
- implements Serializable
+public class LinkValidationResult implements Serializable
{
+ /**
+ *
+ */
+ private static final long serialVersionUID = -8346824125135406813L;
+
public static final int NOTMINE = 0;
public static final int ERROR = 1;
@@ -50,16 +54,17 @@ public class LinkValidationResult
public boolean isPersistent()
{
- return persistent;
+ return this.persistent;
}
/**
* Returns the status.
+ *
* @return int
*/
public int getStatus()
{
- return status;
+ return this.status;
}
/**
@@ -67,7 +72,7 @@ public class LinkValidationResult
*/
public String getErrorMessage()
{
- return errorMessage;
+ return this.errorMessage;
}
public LinkValidationResult( int status, boolean persistent, String errorMessage )
@@ -77,12 +82,14 @@ public class LinkValidationResult
this.errorMessage = errorMessage;
}
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
+ *
* @see java.lang.Object#toString()
*/
public String toString()
{
- return persistent + "/" + status + "/" + errorMessage;
+ return this.persistent + "/" + this.status + "/" + this.errorMessage;
}
}
diff --git a/linkcheck/src/main/org/apache/maven/plugin/linkcheck/validation/LinkValidator.java b/linkcheck/src/main/org/apache/maven/plugin/linkcheck/validation/LinkValidator.java
index 808de93b..fde44528 100644
--- a/linkcheck/src/main/org/apache/maven/plugin/linkcheck/validation/LinkValidator.java
+++ b/linkcheck/src/main/org/apache/maven/plugin/linkcheck/validation/LinkValidator.java
@@ -27,16 +27,17 @@ public interface LinkValidator
/**
* If getResource(lvi) returned null, this will NOT be called.
+ *
* @param lvi
* @return int
* @throws Exception
*/
- public LinkValidationResult validateLink( LinkValidationItem lvi )
- throws Exception;
+ public LinkValidationResult validateLink( LinkValidationItem lvi ) throws Exception;
/**
- * The resource key is used by the cache to determine if it really needs to
- * validate the link. No actual validation should be done at this point.
+ * The resource key is used by the cache to determine if it really needs to validate the link. No actual validation
+ * should be done at this point.
+ *
* @param lvi
* @return Object null if this validator should not be doing this work.
* @throws Exception
diff --git a/linkcheck/src/main/org/apache/maven/plugin/linkcheck/validation/LinkValidatorManager.java b/linkcheck/src/main/org/apache/maven/plugin/linkcheck/validation/LinkValidatorManager.java
index 71a7b374..6176cda4 100644
--- a/linkcheck/src/main/org/apache/maven/plugin/linkcheck/validation/LinkValidatorManager.java
+++ b/linkcheck/src/main/org/apache/maven/plugin/linkcheck/validation/LinkValidatorManager.java
@@ -17,6 +17,9 @@ package org.apache.maven.plugin.linkcheck.validation;
* ====================================================================
*/
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
@@ -30,9 +33,6 @@ import java.util.LinkedList;
import java.util.List;
import java.util.Map;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
/**
* @author Ben Walding
* @author Carlos Sanchez
@@ -40,9 +40,13 @@ import org.apache.commons.logging.LogFactory;
* @version $Id$
*/
-public class LinkValidatorManager
- implements Serializable
+public class LinkValidatorManager implements Serializable
{
+ /**
+ *
+ */
+ private static final long serialVersionUID = 2467928182206500945L;
+
/**
* Log for debug output
*/
@@ -60,22 +64,25 @@ public class LinkValidatorManager
public List getValidators()
{
- return validators;
+ return this.validators;
}
/**
* Returns the exclude.
+ *
* @return String
* @deprecated use getExcludes()
*/
public String getExclude()
{
- return excludes[0];
+ return this.excludes[0];
}
/**
* Sets the exclude.
- * @param exclude The exclude to set
+ *
+ * @param exclude
+ * The exclude to set
* @deprecated use setExcludes()
*/
public void setExclude( String exclude )
@@ -85,16 +92,19 @@ public class LinkValidatorManager
/**
* Returns the excludes.
+ *
* @return String[]
*/
public String[] getExcludes()
{
- return excludes;
+ return this.excludes;
}
/**
* Sets the excludes.
- * @param excludes The excludes to set
+ *
+ * @param excludes
+ * The excludes to set
*/
public void setExcludes( String[] excludes )
{
@@ -103,11 +113,10 @@ public class LinkValidatorManager
public void addLinkValidator( LinkValidator lv )
{
- validators.add( lv );
+ this.validators.add( lv );
}
- public LinkValidationResult validateLink( LinkValidationItem lvi )
- throws Exception
+ public LinkValidationResult validateLink( LinkValidationItem lvi ) throws Exception
{
{
LinkValidationResult status = getCachedResult( lvi );
@@ -117,9 +126,9 @@ public class LinkValidatorManager
}
}
- for ( int i = 0; i < excludes.length; i++ )
+ for ( int i = 0; i < this.excludes.length; i++ )
{
- if ( excludes[i] != null && lvi.getLink().startsWith( excludes[i] ) )
+ if ( this.excludes[i] != null && lvi.getLink().startsWith( this.excludes[i] ) )
{
if ( LOG.isDebugEnabled() )
{
@@ -128,7 +137,7 @@ public class LinkValidatorManager
return new LinkValidationResult( LinkValidationResult.VALID, false, "" );
}
}
- Iterator iter = validators.iterator();
+ Iterator iter = this.validators.iterator();
LinkValidator lv;
Object resourceKey;
LinkValidationResult lvr;
@@ -139,7 +148,9 @@ public class LinkValidatorManager
if ( resourceKey != null )
{
if ( LOG.isDebugEnabled() )
+ {
LOG.debug( lv.getClass().getName() + " - Checking link " + lvi.getLink() );
+ }
lvr = lv.validateLink( lvi );
if ( lvr.getStatus() == LinkValidationResult.NOTMINE )
{
@@ -189,12 +200,14 @@ public class LinkValidatorManager
while ( iter.hasNext() )
{
resourceKey = iter.next();
- if ( ( (LinkValidationResult) cache.get( resourceKey ) ).isPersistent() )
+ if ( ( (LinkValidationResult) this.cache.get( resourceKey ) ).isPersistent() )
{
- persistentCache.put( resourceKey, cache.get( resourceKey ) );
+ persistentCache.put( resourceKey, this.cache.get( resourceKey ) );
if ( LOG.isDebugEnabled() )
- LOG.debug( "[" + resourceKey + "] with result [" + cache.get( resourceKey )
- + "] is stored in the cache." );
+ {
+ LOG.debug( "[" + resourceKey + "] with result [" + this.cache.get( resourceKey )
+ + "] is stored in the cache." );
+ }
}
}
File cacheFile = new File( cacheFilename );
@@ -233,12 +246,14 @@ public class LinkValidatorManager
{
lv = (LinkValidator) iter.next();
resourceKey = lv.getResourceKey( lvi );
- if ( resourceKey != null && cache.containsKey( resourceKey ) )
+ if ( resourceKey != null && this.cache.containsKey( resourceKey ) )
{
if ( LOG.isDebugEnabled() )
- LOG.debug( "The cache returns for [" + resourceKey + "] the result [" + cache.get( resourceKey )
- + "]." );
- return (LinkValidationResult) cache.get( resourceKey );
+ {
+ LOG.debug( "The cache returns for [" + resourceKey + "] the result [" + this.cache.get( resourceKey )
+ + "]." );
+ }
+ return (LinkValidationResult) this.cache.get( resourceKey );
}
}
lv = null;
@@ -248,6 +263,6 @@ public class LinkValidatorManager
public void setCachedResult( Object resourceKey, LinkValidationResult lvr )
{
- cache.put( resourceKey, lvr );
+ this.cache.put( resourceKey, lvr );
}
}
diff --git a/linkcheck/src/main/org/apache/maven/plugin/linkcheck/validation/MailtoLinkValidator.java b/linkcheck/src/main/org/apache/maven/plugin/linkcheck/validation/MailtoLinkValidator.java
index 79806d22..ead6d459 100644
--- a/linkcheck/src/main/org/apache/maven/plugin/linkcheck/validation/MailtoLinkValidator.java
+++ b/linkcheck/src/main/org/apache/maven/plugin/linkcheck/validation/MailtoLinkValidator.java
@@ -24,16 +24,14 @@ package org.apache.maven.plugin.linkcheck.validation;
*
* Validates mailto links
*/
-public final class MailtoLinkValidator
- implements LinkValidator
+public final class MailtoLinkValidator implements LinkValidator
{
private static final LinkValidationResult LVR = new LinkValidationResult( LinkValidationResult.VALID, false, "" );
/**
* @see org.apache.maven.plugin.linkcheck.validation.LinkValidator#validateLink(org.apache.maven.plugin.linkcheck.validation.LinkValidationItem)
*/
- public LinkValidationResult validateLink( LinkValidationItem lvi )
- throws Exception
+ public LinkValidationResult validateLink( LinkValidationItem lvi ) throws Exception
{
return LVR;
}
@@ -44,9 +42,13 @@ public final class MailtoLinkValidator
public Object getResourceKey( LinkValidationItem lvi )
{
if ( lvi.getLink().indexOf( '@' ) != -1 )
+ {
return lvi.getLink();
+ }
else
+ {
return null;
+ }
}
}
diff --git a/linkcheck/src/main/org/apache/maven/plugin/linkcheck/validation/OfflineHTTPLinkValidator.java b/linkcheck/src/main/org/apache/maven/plugin/linkcheck/validation/OfflineHTTPLinkValidator.java
index ec31b668..7aef4953 100644
--- a/linkcheck/src/main/org/apache/maven/plugin/linkcheck/validation/OfflineHTTPLinkValidator.java
+++ b/linkcheck/src/main/org/apache/maven/plugin/linkcheck/validation/OfflineHTTPLinkValidator.java
@@ -19,12 +19,11 @@ package org.apache.maven.plugin.linkcheck.validation;
/**
* Fake links check when maven is offline
+ *
* @author Arnaud Heritier
* @version $Id: HTTPLinkValidator.java 155277 2005-02-24 23:23:29Z aheritier $
*/
-public final class OfflineHTTPLinkValidator
- extends HTTPLinkValidator
- implements LinkValidator
+public final class OfflineHTTPLinkValidator extends HTTPLinkValidator implements LinkValidator
{
/**
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 10a1f38d..1df44aa6 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
@@ -3,9 +3,6 @@
*/
package org.apache.maven.plugin.linkcheck.validation;
-import java.io.IOException;
-import java.net.URL;
-
import org.apache.commons.httpclient.Credentials;
import org.apache.commons.httpclient.Header;
import org.apache.commons.httpclient.HostConfiguration;
@@ -23,14 +20,17 @@ import org.apache.commons.httpclient.methods.HeadMethod;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import java.io.IOException;
+import java.net.URL;
+
/**
* Checks links which are normal URLs
+ *
* @author Ben Walding
* @author Arnaud Heritier
* @version $Id: HTTPLinkValidator.java 155277 2005-02-24 23:23:29Z aheritier $
*/
-public final class OnlineHTTPLinkValidator
- extends HTTPLinkValidator
+public final class OnlineHTTPLinkValidator extends HTTPLinkValidator
{
/**
* Log for debug output
@@ -66,7 +66,9 @@ public final class OnlineHTTPLinkValidator
String proxyPass, String proxyNtlmHost, String proxyNtlmDomain )
{
if ( LOG.isDebugEnabled() )
+ {
LOG.debug( "Will use method : [" + method + "]" );
+ }
this.method = method;
if ( proxyHost == null || proxyHost.trim().equals( "" ) )
{
@@ -104,56 +106,58 @@ public final class OnlineHTTPLinkValidator
*/
public LinkValidationResult validateLink( LinkValidationItem lvi )
{
- if ( cl == null )
+ if ( this.cl == null )
+ {
initHttpClient();
+ }
try
{
String link = lvi.getLink();
HttpMethod hm = null;
try
{
- hm = checkLink( cl, link, 0 );
+ hm = checkLink( this.cl, link, 0 );
}
catch ( Throwable t )
{
if ( LOG.isDebugEnabled() )
{
- LOG
- .error( "Received: [" + t + "] for [" + lvi.getLink() + "] in page [" + lvi.getSource() + "]",
- t );
+ LOG.error( "Received: [" + t + "] for [" + lvi.getLink() + "] in page [" + lvi.getSource() + "]", t );
}
else
{
LOG.error( "Received: [" + t + "] for [" + lvi.getLink() + "] in page [" + lvi.getSource() + "]" );
}
return new LinkValidationResult( LinkValidationResult.ERROR, false, t.getClass().getName() + " : "
- + t.getMessage() );
+ + t.getMessage() );
}
if ( hm == null )
+ {
return new LinkValidationResult( LinkValidationResult.ERROR, false, "Cannot retreive HTTP Status" );
+ }
if ( hm.getStatusCode() == HttpStatus.SC_OK )
{
return new LinkValidationResult( LinkValidationResult.VALID, true, hm.getStatusCode() + " "
- + hm.getStatusText() );
+ + hm.getStatusText() );
}
else
{
// If there's a redirection ... add a warning
if ( hm.getStatusCode() == HttpStatus.SC_MOVED_PERMANENTLY
- || hm.getStatusCode() == HttpStatus.SC_MOVED_TEMPORARILY
- || hm.getStatusCode() == HttpStatus.SC_TEMPORARY_REDIRECT )
+ || hm.getStatusCode() == HttpStatus.SC_MOVED_TEMPORARILY
+ || hm.getStatusCode() == HttpStatus.SC_TEMPORARY_REDIRECT )
{
LOG.warn( "Received: [" + hm.getStatusCode() + "] for [" + lvi.getLink() + "] in page ["
- + lvi.getSource() + "]" );
+ + lvi.getSource() + "]" );
return new LinkValidationResult( LinkValidationResult.WARNING, true, hm.getStatusCode() + " "
- + hm.getStatusText() );
+ + hm.getStatusText() );
}
else
{
LOG.error( "Received: [" + hm.getStatusCode() + "] for [" + lvi.getLink() + "] in page ["
- + lvi.getSource() + "]" );
+ + lvi.getSource() + "]" );
return new LinkValidationResult( LinkValidationResult.ERROR, false, hm.getStatusCode() + " "
- + hm.getStatusText() );
+ + hm.getStatusText() );
}
}
@@ -161,9 +165,13 @@ public final class OnlineHTTPLinkValidator
catch ( Throwable t )
{
if ( LOG.isDebugEnabled() )
+ {
LOG.error( "Received: [" + t + "] for [" + lvi.getLink() + "] in page [" + lvi.getSource() + "]", t );
+ }
else
+ {
LOG.error( "Received: [" + t + "] for [" + lvi.getLink() + "] in page [" + lvi.getSource() + "]" );
+ }
return new LinkValidationResult( LinkValidationResult.ERROR, false, t.getMessage() );
}
}
@@ -173,7 +181,7 @@ public final class OnlineHTTPLinkValidator
LOG.debug( "A new HttpClient instance is needed ..." );
// Some web servers doesn't allow the default user-agent sent by httpClient
System.setProperty( "httpclient.useragent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)" );
- cl = new HttpClient( new MultiThreadedHttpConnectionManager() );
+ this.cl = new HttpClient( new MultiThreadedHttpConnectionManager() );
HostConfiguration hc = new HostConfiguration();
HttpState state = new HttpState();
if ( this.proxyHost != null )
@@ -181,18 +189,20 @@ public final class OnlineHTTPLinkValidator
hc.setProxy( this.proxyHost, this.proxyPort );
if ( LOG.isDebugEnabled() )
{
- LOG.debug( "Proxy Host:" + proxyHost );
- LOG.debug( "Proxy Port:" + proxyPort );
+ LOG.debug( "Proxy Host:" + this.proxyHost );
+ LOG.debug( "Proxy Port:" + this.proxyPort );
}
if ( this.proxyUser != null && this.proxyPass != null )
{
if ( LOG.isDebugEnabled() )
- LOG.debug( "Proxy User:" + proxyUser );
+ {
+ LOG.debug( "Proxy User:" + this.proxyUser );
+ }
Credentials credentials;
if ( this.proxyNtlmHost != null )
{
- credentials = new NTCredentials( this.proxyUser, this.proxyPass, this.proxyNtlmHost,
- this.proxyNtlmDomain );
+ credentials =
+ new NTCredentials( this.proxyUser, this.proxyPass, this.proxyNtlmHost, this.proxyNtlmDomain );
}
else
{
@@ -206,23 +216,26 @@ public final class OnlineHTTPLinkValidator
{
LOG.debug( "Not using a proxy" );
}
- cl.setHostConfiguration( hc );
- cl.setState( state );
+ this.cl.setHostConfiguration( hc );
+ this.cl.setState( state );
LOG.debug( "New HttpClient instance created." );
}
- private HttpMethod checkLink( HttpClient cl, String link, int nbRedirect )
- throws HttpException, IOException
+ private HttpMethod checkLink( HttpClient cl, String link, int nbRedirect ) throws HttpException, IOException
{
if ( nbRedirect > MAX_NB_REDIRECT )
{
throw new HttpException( "Maximum number of redirections (" + MAX_NB_REDIRECT + ") exceeded" );
}
HttpMethod hm;
- if ( HEAD_METHOD.equals( method ) )
+ if ( HEAD_METHOD.equals( this.method ) )
+ {
hm = new HeadMethod( link );
+ }
else
+ {
hm = new GetMethod( link );
+ }
try
{
// We want to do it manually
@@ -239,8 +252,8 @@ public final class OnlineHTTPLinkValidator
}
if ( hm.getStatusCode() == HttpStatus.SC_MOVED_PERMANENTLY
- || hm.getStatusCode() == HttpStatus.SC_MOVED_TEMPORARILY
- || hm.getStatusCode() == HttpStatus.SC_TEMPORARY_REDIRECT )
+ || hm.getStatusCode() == HttpStatus.SC_MOVED_TEMPORARILY
+ || hm.getStatusCode() == HttpStatus.SC_TEMPORARY_REDIRECT )
{
Header locationHeader = hm.getResponseHeader( "location" );
if ( locationHeader == null )
@@ -257,8 +270,9 @@ public final class OnlineHTTPLinkValidator
if ( newLink.startsWith( "/" ) )
{
URL oldUrl = new URL( link );
- newLink = oldUrl.getProtocol() + "://" + oldUrl.getHost()
- + ( oldUrl.getPort() > 0 ? ":" + oldUrl.getPort() : "" ) + newLink;
+ newLink =
+ oldUrl.getProtocol() + "://" + oldUrl.getHost()
+ + ( oldUrl.getPort() > 0 ? ":" + oldUrl.getPort() : "" ) + newLink;
}
else
{
@@ -269,9 +283,9 @@ public final class OnlineHTTPLinkValidator
LOG.info( "[" + link + "] is redirected to [" + newLink + "]" );
oldHm.releaseConnection();
hm = checkLink( cl, newLink, nbRedirect + 1 );
- // Restore the hm to "Moved permanently" | "Moved temporarily" | "Temporary redirect"
+ // Restore the hm to "Moved permanently" | "Moved temporarily" | "Temporary redirect"
// if the new location is found to allow us to report it
- if ( hm.getStatusCode() == HttpStatus.SC_OK && nbRedirect == 0)
+ if ( hm.getStatusCode() == HttpStatus.SC_OK && nbRedirect == 0 )
{
return oldHm;
}
diff --git a/linkcheck/src/test/org/apache/maven/plugin/linkcheck/LinkCheckTest.java b/linkcheck/src/test/org/apache/maven/plugin/linkcheck/LinkCheckTest.java
index e08463e8..f028d1fd 100644
--- a/linkcheck/src/test/org/apache/maven/plugin/linkcheck/LinkCheckTest.java
+++ b/linkcheck/src/test/org/apache/maven/plugin/linkcheck/LinkCheckTest.java
@@ -17,6 +17,10 @@ package org.apache.maven.plugin.linkcheck;
* ====================================================================
*/
+import org.apache.log4j.BasicConfigurator;
+import org.apache.log4j.Level;
+import org.apache.log4j.Logger;
+
import java.io.File;
import java.util.HashMap;
import java.util.Iterator;
@@ -24,10 +28,6 @@ import java.util.Map;
import junit.framework.TestCase;
-import org.apache.log4j.BasicConfigurator;
-import org.apache.log4j.Level;
-import org.apache.log4j.Logger;
-
/**
* @author Ben Walding
* @author Carlos Sanchez
@@ -44,7 +44,7 @@ public class LinkCheckTest extends TestCase
protected void setUp() throws Exception
{
super.setUp();
- baseDir = System.getProperty( "basedir" );
+ this.baseDir = System.getProperty( "basedir" );
// Setup log4J (We are in a forked JVM for tests)
BasicConfigurator.configure();
Logger.getLogger( "org.apache.maven.plugin.linkcheck" ).setLevel( Level.DEBUG );
@@ -52,10 +52,10 @@ public class LinkCheckTest extends TestCase
public void testScan() throws Exception
{
- File f = new File( baseDir + "/src/test-resources" );
+ File f = new File( this.baseDir + "/src/test-resources" );
LinkCheck lc = new LinkCheck();
lc.setBasedir( f );
- lc.setOutput( new File( baseDir + "/target/linkcheck.xml" ) );
+ lc.setOutput( new File( this.baseDir + "/target/linkcheck.xml" ) );
lc.setOutputEncoding( "ISO8859-1" );
lc.setCache( System.getProperty( "maven.linkcheck.cache" ) );
lc.setExclude( "http://cvs.apache.org/viewcvs.cgi/maven-pluginszz/,"
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 0b850f2e..963c312c 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
@@ -17,14 +17,14 @@ package org.apache.maven.plugin.linkcheck.validation;
* ====================================================================
*/
-import java.io.File;
-
-import junit.framework.TestCase;
-
import org.apache.log4j.BasicConfigurator;
import org.apache.log4j.Level;
import org.apache.log4j.Logger;
+import java.io.File;
+
+import junit.framework.TestCase;
+
/**
* @author Ben Walding
* @author Arnaud Heritier
@@ -51,9 +51,9 @@ public class HTTPLinkValidatorTest extends TestCase
public void testValidateLink() throws Exception
{
- if ( mavenOnline )
+ if ( this.mavenOnline )
{
- hlv =
+ this.hlv =
new OnlineHTTPLinkValidator( System.getProperty( "maven.linkcheck.method" ),
System.getProperty( "maven.linkcheck.proxy.host" ),
System.getProperty( "maven.linkcheck.proxy.port" ),
@@ -67,7 +67,7 @@ public class HTTPLinkValidatorTest extends TestCase
}
else
{
- hlv = new OfflineHTTPLinkValidator();
+ this.hlv = new OfflineHTTPLinkValidator();
assertEquals( LinkValidationResult.WARNING, checkLink( "http://www.apache.org" ).getStatus() );
assertEquals( LinkValidationResult.WARNING, checkLink( "http://www.example.com>);" ).getStatus() );
@@ -79,7 +79,7 @@ public class HTTPLinkValidatorTest extends TestCase
{
LinkValidationItem lvi = new LinkValidationItem( new File( "." ), link );
- return hlv.validateLink( lvi );
+ return this.hlv.validateLink( lvi );
}
}