Added: maven/maven-1/plugins/trunk/linkcheck/src/main/org/apache/maven/plugin/linkcheck/validation/OfflineHTTPLinkValidator.java URL: http://svn.apache.org/viewcvs/maven/maven-1/plugins/trunk/linkcheck/src/main/org/apache/maven/plugin/linkcheck/validation/OfflineHTTPLinkValidator.java?rev=368935&view=auto ============================================================================== --- maven/maven-1/plugins/trunk/linkcheck/src/main/org/apache/maven/plugin/linkcheck/validation/OfflineHTTPLinkValidator.java (added) +++ maven/maven-1/plugins/trunk/linkcheck/src/main/org/apache/maven/plugin/linkcheck/validation/OfflineHTTPLinkValidator.java Fri Jan 13 16:28:50 2006 @@ -0,0 +1,38 @@ +package org.apache.maven.plugin.linkcheck.validation; + +/* ==================================================================== + * Copyright 2001-2006 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ==================================================================== + */ + +/** + * Fake links check when maven is offline + * @author <a href="mailto:[EMAIL PROTECTED]">Arnaud Heritier</a> + * @version $Id: HTTPLinkValidator.java 155277 2005-02-24 23:23:29Z aheritier $ + */ +public final class OfflineHTTPLinkValidator + extends HTTPLinkValidator + implements LinkValidator +{ + + /** + * @see org.apache.maven.plugin.linkcheck.LinkValidator#validateLink(org.apache.maven.plugin.linkcheck.LinkValidationItem) + */ + public LinkValidationResult validateLink( LinkValidationItem lvi ) + { + return new LinkValidationResult( LinkValidationResult.WARNING, false, "Maven is offline. Link not checked." ); + } + +}
Added: maven/maven-1/plugins/trunk/linkcheck/src/main/org/apache/maven/plugin/linkcheck/validation/OnlineHTTPLinkValidator.java URL: http://svn.apache.org/viewcvs/maven/maven-1/plugins/trunk/linkcheck/src/main/org/apache/maven/plugin/linkcheck/validation/OnlineHTTPLinkValidator.java?rev=368935&view=auto ============================================================================== --- maven/maven-1/plugins/trunk/linkcheck/src/main/org/apache/maven/plugin/linkcheck/validation/OnlineHTTPLinkValidator.java (added) +++ maven/maven-1/plugins/trunk/linkcheck/src/main/org/apache/maven/plugin/linkcheck/validation/OnlineHTTPLinkValidator.java Fri Jan 13 16:28:50 2006 @@ -0,0 +1,243 @@ +/** + * + */ +package org.apache.maven.plugin.linkcheck.validation; + +import java.io.IOException; +import java.net.URL; + +import org.apache.commons.httpclient.Header; +import org.apache.commons.httpclient.HostConfiguration; +import org.apache.commons.httpclient.HttpClient; +import org.apache.commons.httpclient.HttpException; +import org.apache.commons.httpclient.HttpMethod; +import org.apache.commons.httpclient.HttpState; +import org.apache.commons.httpclient.HttpStatus; +import org.apache.commons.httpclient.StatusLine; +import org.apache.commons.httpclient.UsernamePasswordCredentials; +import org.apache.commons.httpclient.methods.HeadMethod; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +/** + * Checks links which are normal URLs + * @author <a href="mailto:[EMAIL PROTECTED]">Ben Walding</a> + * @author <a href="mailto:[EMAIL PROTECTED]">Arnaud Heritier</a> + * @version $Id: HTTPLinkValidator.java 155277 2005-02-24 23:23:29Z aheritier $ + */ +public final class OnlineHTTPLinkValidator + extends HTTPLinkValidator +{ + /** + * Log for debug output + */ + private final static Log LOG = LogFactory.getLog( OnlineHTTPLinkValidator.class ); + + private String proxyHost; + + private int proxyPort; + + private String proxyUser; + + private String proxyPass; + + private transient HttpClient cl; + + public OnlineHTTPLinkValidator( String proxyHost, String proxyPort, String proxyUser, String proxyPass ) + { + if ( proxyHost == null || proxyHost.trim().equals( "" ) ) + { + this.proxyHost = null; + } + else + { + this.proxyHost = proxyHost; + if ( proxyPort != null ) + { + try + { + this.proxyPort = Integer.parseInt( proxyPort ); + } + catch ( NumberFormatException e ) + { + LOG.warn( "Invalid number for Proxy Port:" + proxyPort ); + LOG.warn( "Proxy Port won't be used." ); + this.proxyPort = -1; + } + } + this.proxyUser = proxyUser; + this.proxyPass = proxyPass; + } + initHttpClient(); + } + + /** + * @see org.apache.maven.plugin.linkcheck.LinkValidator#validateLink(org.apache.maven.plugin.linkcheck.LinkValidationItem) + */ + public LinkValidationResult validateLink( LinkValidationItem lvi ) + { + if ( cl == null ) + initHttpClient(); + try + { + String link = lvi.getLink(); + HttpMethod hm = null; + try + { + hm = checkLink( cl, link ); + } + 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.getClass().getName() + " : " + + 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() ); + } + else + { + if ( hm.getStatusCode() == HttpStatus.SC_MOVED_PERMANENTLY ) + { + LOG.warn( "Received: [" + hm.getStatusCode() + "] for [" + lvi.getLink() + "] in page [" + + lvi.getSource() + "]" ); + return new LinkValidationResult( LinkValidationResult.WARNING, true, hm.getStatusCode() + " " + + hm.getStatusText() ); + } + else + { + LOG.error( "Received: [" + hm.getStatusCode() + "] for [" + lvi.getLink() + "] in page [" + + lvi.getSource() + "]" ); + return new LinkValidationResult( LinkValidationResult.ERROR, false, hm.getStatusCode() + " " + + hm.getStatusText() ); + } + } + + } + 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() ); + } + + } + + private void initHttpClient() + { + 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() ); + cl = new HttpClient(); + HostConfiguration hc = new HostConfiguration(); + HttpState state = new HttpState(); + if ( this.proxyHost != null ) + { + hc.setProxy( this.proxyHost, this.proxyPort ); + if ( LOG.isDebugEnabled() ) + { + LOG.debug( "Proxy Host:" + proxyHost ); + LOG.debug( "Proxy Port:" + proxyPort ); + } + if ( this.proxyUser != null && this.proxyPass != null ) + { + if ( LOG.isDebugEnabled() ) + LOG.debug( "Proxy User:" + proxyUser ); + state + .setProxyCredentials( null, null, new UsernamePasswordCredentials( this.proxyUser, this.proxyPass ) ); + } + + } + else + { + LOG.debug( "Not using a proxy" ); + } + cl.setHostConfiguration( hc ); + cl.setState( state ); + LOG.debug( "New HttpClient instance created." ); + } + + private HttpMethod checkLink( HttpClient cl, String link ) + throws HttpException, IOException + { + // execute the HEAD (a GET without the body returned) + HttpMethod hm = new HeadMethod( link ); + try + { + // We want to do it manually + hm.setFollowRedirects( false ); + URL url = new URL( link ); + cl.getHostConfiguration().setHost( url.getHost(), url.getPort(), url.getProtocol() ); + cl.executeMethod( hm ); + StatusLine sl = hm.getStatusLine(); + + if ( sl == null ) + { + LOG.error( "Unknown error validating link : " + link ); + return null; + } + + if ( hm.getStatusCode() == HttpStatus.SC_MOVED_PERMANENTLY + || hm.getStatusCode() == HttpStatus.SC_MOVED_TEMPORARILY + || hm.getStatusCode() == HttpStatus.SC_TEMPORARY_REDIRECT ) + { + Header locationHeader = hm.getResponseHeader( "location" ); + if ( locationHeader == null ) + { + LOG.error( "Site sent redirect, but did not set Location header" ); + return hm; + } + else + { + String newLink = locationHeader.getValue(); + // Be careful to absolute/relative links + if ( !newLink.startsWith( "http://" ) && !newLink.startsWith( "https://" ) ) + { + if ( newLink.startsWith( "/" ) ) + { + URL oldUrl = new URL( link ); + newLink = oldUrl.getProtocol() + "://" + oldUrl.getHost() + + ( oldUrl.getPort() > 0 ? ":" + oldUrl.getPort() : "" ) + newLink; + } + else + { + newLink = link + newLink; + } + } + HttpMethod oldHm = hm; + LOG.info( "[" + link + "] is redirected to [" + newLink + "]" ); + hm = checkLink( cl, newLink ); + // Restore the hm to "Moved permanently" if the new location is found to allow us to report it + if ( oldHm.getStatusCode() == HttpStatus.SC_MOVED_PERMANENTLY + && hm.getStatusCode() == HttpStatus.SC_OK ) + { + return oldHm; + } + } + } + + } + finally + { + hm.releaseConnection(); + } + return hm; + } + +} Added: maven/maven-1/plugins/trunk/linkcheck/src/plugin-resources/images/icon_error_sml.gif URL: http://svn.apache.org/viewcvs/maven/maven-1/plugins/trunk/linkcheck/src/plugin-resources/images/icon_error_sml.gif?rev=368935&view=auto ============================================================================== Binary file - no diff available. Propchange: maven/maven-1/plugins/trunk/linkcheck/src/plugin-resources/images/icon_error_sml.gif ------------------------------------------------------------------------------ svn:mime-type = application/octet-stream Added: maven/maven-1/plugins/trunk/linkcheck/src/plugin-resources/images/icon_unknown_sml.gif URL: http://svn.apache.org/viewcvs/maven/maven-1/plugins/trunk/linkcheck/src/plugin-resources/images/icon_unknown_sml.gif?rev=368935&view=auto ============================================================================== Binary file - no diff available. Propchange: maven/maven-1/plugins/trunk/linkcheck/src/plugin-resources/images/icon_unknown_sml.gif ------------------------------------------------------------------------------ svn:mime-type = application/octet-stream Added: maven/maven-1/plugins/trunk/linkcheck/src/plugin-resources/images/icon_valid_sml.gif URL: http://svn.apache.org/viewcvs/maven/maven-1/plugins/trunk/linkcheck/src/plugin-resources/images/icon_valid_sml.gif?rev=368935&view=auto ============================================================================== Binary file - no diff available. Propchange: maven/maven-1/plugins/trunk/linkcheck/src/plugin-resources/images/icon_valid_sml.gif ------------------------------------------------------------------------------ svn:mime-type = application/octet-stream Added: maven/maven-1/plugins/trunk/linkcheck/src/plugin-resources/images/icon_warning_sml.gif URL: http://svn.apache.org/viewcvs/maven/maven-1/plugins/trunk/linkcheck/src/plugin-resources/images/icon_warning_sml.gif?rev=368935&view=auto ============================================================================== Binary file - no diff available. Propchange: maven/maven-1/plugins/trunk/linkcheck/src/plugin-resources/images/icon_warning_sml.gif ------------------------------------------------------------------------------ svn:mime-type = application/octet-stream Added: maven/maven-1/plugins/trunk/linkcheck/src/plugin-resources/images/trans.gif URL: http://svn.apache.org/viewcvs/maven/maven-1/plugins/trunk/linkcheck/src/plugin-resources/images/trans.gif?rev=368935&view=auto ============================================================================== Binary file - no diff available. Propchange: maven/maven-1/plugins/trunk/linkcheck/src/plugin-resources/images/trans.gif ------------------------------------------------------------------------------ svn:mime-type = application/octet-stream Modified: maven/maven-1/plugins/trunk/linkcheck/src/plugin-resources/linkcheck-temp.xml URL: http://svn.apache.org/viewcvs/maven/maven-1/plugins/trunk/linkcheck/src/plugin-resources/linkcheck-temp.xml?rev=368935&r1=368934&r2=368935&view=diff ============================================================================== --- maven/maven-1/plugins/trunk/linkcheck/src/plugin-resources/linkcheck-temp.xml (original) +++ maven/maven-1/plugins/trunk/linkcheck/src/plugin-resources/linkcheck-temp.xml Fri Jan 13 16:28:50 2006 @@ -1,7 +1,7 @@ <?xml version="1.0"?> <!-- /* - * Copyright 2001-2004 The Apache Software Foundation. + * Copyright 2001-2005 The Apache Software Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,14 +20,10 @@ <document> <properties> <title>Maven LinkCheck Plug-in</title> - <author email="[EMAIL PROTECTED]">Ben Walding</author> </properties> - <body> <section name="Maven LinkCheck Temporary File"> - <p> - This file is used as a placeholder until the final link check can occur. - </p> + <p>This file is used as a placeholder until the final link check can occur.</p> </section> </body> </document> Modified: maven/maven-1/plugins/trunk/linkcheck/src/plugin-resources/linkcheck.jsl URL: http://svn.apache.org/viewcvs/maven/maven-1/plugins/trunk/linkcheck/src/plugin-resources/linkcheck.jsl?rev=368935&r1=368934&r2=368935&view=diff ============================================================================== --- maven/maven-1/plugins/trunk/linkcheck/src/plugin-resources/linkcheck.jsl (original) +++ maven/maven-1/plugins/trunk/linkcheck/src/plugin-resources/linkcheck.jsl Fri Jan 13 16:28:50 2006 @@ -1,9 +1,8 @@ <?xml version="1.0"?> - <!-- * ======================================================================== * - * Copyright 2004 The Apache Software Foundation. + * Copyright 2005 The Apache Software Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,7 +18,6 @@ * * ======================================================================== --> - <jsl:stylesheet select="$doc" xmlns:j="jelly:core" @@ -31,38 +29,48 @@ <jsl:template match="linkcheck"> <document> - <properties> <title>Link Check Report</title> </properties> <body> <section name="Link Check Report"> + <p><b><span style="color:#00AA00;text-align:right"><x:expr select="count(file)"/> </span></b> file(s) and <b><span style="color:#00AA00;text-align:right"><x:expr select="sum(file/unsuccessful)+sum(file/successful)"/> </span></b> link(s) checked. <b><span style="color:#FF0000;text-align:right"><x:expr select="count(file/result[status='error'])"/></span></b> error(s) and <b><span style="color:#FFA916;text-align:right"><x:expr select="count(file/result[status='warning'])"/></span></b> warning(s) reported in <b><span style="color:#00AA00;text-align:right"><x:expr select="count(file[unsuccessful!=0])"/> </span></b> file(s).</p> <table summary="Link Check summary"> <thead> - <tr> - <th>URL</th> - </tr> + <tr> + <th rowspan="2">Document</th> + <th colspan="4">links</th> + </tr> + <tr> + <th width="50">total</th> + <th width="50"><img align="right" src="images/icon_valid_sml.gif" alt="success"/></th> + <th width="50"><img align="right" src="images/icon_warning_sml.gif" alt="warning"/></th> + <th width="50"><img align="right" src="images/icon_error_sml.gif" alt="error"/></th> + </tr> </thead> <tbody> <x:forEach var="file" select="file[unsuccessful != 0]"> + <util:replace var="name" oldChar="\\" newChar="/"> + <x:expr select="$file/name"/> + </util:replace> <tr> - <td colspan="2"> - <util:replace var="name" oldChar="\\" newChar="/"> - <x:expr select="$file/name"/> - </util:replace> - <a href="${name}">${name}</a> - </td> + <td><a href="${name.trim()}">${name.trim()}</a></td> + <td width="50" style="text-align:right" nowrap="nowrap"><b><x:expr select="$file/successful + $file/unsuccessful"/></b></td> + <td width="50" style="text-align:right"><b><span style="color:#00AA00;text-align:right"><x:expr select="$file/successful"/></span></b></td> + <td width="50" style="text-align:right"><b><span style="color:#FFA916;text-align:right"><x:expr select="count($file/result[status='warning'])"/></span></b></td> + <td width="50" style="text-align:right"><b><span style="color:#FF0000;text-align:right"><x:expr select="count($file/result[status='error'])"/></span></b></td> </tr> <tr> - <td> - <x:forEach var="result" select="$file/result"> - <j:set var="status"><x:expr select="$result/status"/></j:set> - <j:set var="target"><x:expr select="$result/target"/></j:set> - <j:if test="${status != 'OK'}"> - <p>${status} - ${target}</p> - </j:if> - </x:forEach> - </td> + <td colspan="5"> + <x:forEach var="result" select="$file/result"> + <j:set var="status"><x:expr select="$result/status"/></j:set> + <j:set var="target"><x:expr select="$result/target"/></j:set> + <j:set var="errorMessage"><x:expr select="$result/errorMessage"/></j:set> + <j:if test="${status != 'valid'}"> + <img src="images/trans.gif" alt="trans" width="20" height="5" border="0"/><img src="images/icon_${status}_sml.gif" alt="${status}"/><img src="images/trans.gif" alt="trans" width="5" height="5" border="0"/> ${target} - <j:if test="${errorMessage != ''}"><span style="font-style:italic">${errorMessage}</span></j:if><br/> + </j:if> + </x:forEach> + </td> </tr> </x:forEach> </tbody> @@ -71,4 +79,4 @@ </body> </document> </jsl:template> -</jsl:stylesheet> +</jsl:stylesheet> \ No newline at end of file Modified: maven/maven-1/plugins/trunk/linkcheck/src/plugin-test/maven.xml URL: http://svn.apache.org/viewcvs/maven/maven-1/plugins/trunk/linkcheck/src/plugin-test/maven.xml?rev=368935&r1=368934&r2=368935&view=diff ============================================================================== --- maven/maven-1/plugins/trunk/linkcheck/src/plugin-test/maven.xml (original) +++ maven/maven-1/plugins/trunk/linkcheck/src/plugin-test/maven.xml Fri Jan 13 16:28:50 2006 @@ -21,8 +21,8 @@ </goal> <goal name="test-linkcheck"> - <attainGoal name="site"/> <attainGoal name="clean"/> + <attainGoal name="site"/> </goal> </project> Modified: maven/maven-1/plugins/trunk/linkcheck/src/plugin-test/xdocs/test.html URL: http://svn.apache.org/viewcvs/maven/maven-1/plugins/trunk/linkcheck/src/plugin-test/xdocs/test.html?rev=368935&r1=368934&r2=368935&view=diff ============================================================================== --- maven/maven-1/plugins/trunk/linkcheck/src/plugin-test/xdocs/test.html (original) +++ maven/maven-1/plugins/trunk/linkcheck/src/plugin-test/xdocs/test.html Fri Jan 13 16:28:50 2006 @@ -16,8 +16,15 @@ */ --> <html> -<body> -<a href="#bumpkin">test2</a> -</body> - + <head> + <title>test</title> + </head> + <body> + <a href="#bumpkin">test2</a><br/> + <a href="http://www.seoconsultants.com/w3c/status-codes/301.asp">301 Moved Permanently</a><br/> + <a href="http://www.seoconsultants.com/w3c/status-codes/302.asp">302 Found</a><br/> + <a href="http://www.seoconsultants.com/w3c/status-codes/307.asp">307 Temporary Redirect</a><br/> + <a href="http://www.seoconsultants.com/w3c/status-codes/404.asp">404 Not Found</a><br/> + <a href="http://www.seoconsultants.com/w3c/status-codes/410.asp">410 Gone</a><br/> + </body> </html> Copied: maven/maven-1/plugins/trunk/linkcheck/src/test/org/apache/maven/plugin/linkcheck/LinkCheckTest.java (from r368923, maven/maven-1/plugins/trunk/linkcheck/src/test/org/apache/maven/linkcheck/LinkCheckTest.java) URL: http://svn.apache.org/viewcvs/maven/maven-1/plugins/trunk/linkcheck/src/test/org/apache/maven/plugin/linkcheck/LinkCheckTest.java?p2=maven/maven-1/plugins/trunk/linkcheck/src/test/org/apache/maven/plugin/linkcheck/LinkCheckTest.java&p1=maven/maven-1/plugins/trunk/linkcheck/src/test/org/apache/maven/linkcheck/LinkCheckTest.java&r1=368923&r2=368935&rev=368935&view=diff ============================================================================== --- maven/maven-1/plugins/trunk/linkcheck/src/test/org/apache/maven/linkcheck/LinkCheckTest.java (original) +++ maven/maven-1/plugins/trunk/linkcheck/src/test/org/apache/maven/plugin/linkcheck/LinkCheckTest.java Fri Jan 13 16:28:50 2006 @@ -1,4 +1,4 @@ -package org.apache.maven.linkcheck; +package org.apache.maven.plugin.linkcheck; /* ==================================================================== * Copyright 2001-2004 The Apache Software Foundation. @@ -22,76 +22,76 @@ import java.util.Iterator; import java.util.Map; - - import junit.framework.TestCase; /** * @author Ben Walding * @author <a href="mailto:[EMAIL PROTECTED]">Carlos Sanchez</a> */ -public class LinkCheckTest extends TestCase +public class LinkCheckTest + extends TestCase { - String baseDir; + String baseDir; - public void setUp() - { - baseDir = System.getProperty("basedir"); - } - - public void testScan() throws Exception - { - File f = new File(baseDir + "/src/test-resources"); - LinkCheck lc = new LinkCheck(); - lc.setBasedir(f); - lc.setOutput(new File(baseDir + "/target/linkcheck.xml")); - lc.setOutputEncoding("ISO8859-1"); - lc.setCache(baseDir + "/target/linkcheck-cache.xml"); - lc.setExclude("http://cvs.apache.org/viewcvs.cgi/maven-pluginszz/," - + "http://cvs.apache.org/viewcvs.cgi/mavenzz/"); - lc.doExecute(); - - Iterator iter = lc.getFiles().iterator(); - Map map = new HashMap(); - while (iter.hasNext()) + public void setUp() { - FileToCheck ftc = (FileToCheck) iter.next(); - map.put(ftc.getName(), ftc); + baseDir = System.getProperty( "basedir" ); } - assertEquals("files.size()", 8, lc.getFiles().size()); + public void testScan() + throws Exception + { + File f = new File( baseDir + "/src/test-resources" ); + LinkCheck lc = new LinkCheck(); + lc.setBasedir( f ); + lc.setOutput( new File( baseDir + "/target/linkcheck.xml" ) ); + lc.setOutputEncoding( "ISO8859-1" ); + lc.setCache( baseDir + "/target/linkcheck-cache.xml" ); + lc.setExclude( "http://cvs.apache.org/viewcvs.cgi/maven-pluginszz/," + + "http://cvs.apache.org/viewcvs.cgi/mavenzz/" ); + lc.doExecute(); + + Iterator iter = lc.getFiles().iterator(); + Map map = new HashMap(); + while ( iter.hasNext() ) + { + FileToCheck ftc = (FileToCheck) iter.next(); + map.put( ftc.getName(), ftc ); + } + + assertEquals( "files.size()", 8, lc.getFiles().size() ); + + check( map, "nolink.html", 0 ); + check( map, "test-resources/nolink.html", 0 ); + check( map, "test-resources/test1/test1.html", 2 ); + check( map, "test-resources/test1/test2.html", 0 ); + check( map, "test1/test1.html", 1 ); + check( map, "testA.html", 3 ); + + /* test excludes */ + String fileName = "testExcludes.html"; + check( map, fileName, 2 ); + + FileToCheck ftc = (FileToCheck) map.get( fileName ); + assertEquals( "Excluded links", 2, ftc.getSuccessful() ); + + //index-all.html should get parsed, but is currently having problems. + //check(map, "index-all.html", 1); - check(map, "nolink.html", 0); - check(map, "test-resources/nolink.html", 0); - check(map, "test-resources/test1/test1.html", 2); - check(map, "test-resources/test1/test2.html", 0); - check(map, "test1/test1.html", 1); - check(map, "testA.html", 3); - - /* test excludes */ - String fileName = "testExcludes.html"; - check(map, fileName, 2); - - FileToCheck ftc = (FileToCheck) map.get(fileName); - assertEquals("Excluded links", 2, ftc.getSuccessful()); - - //index-all.html should get parsed, but is currently having problems. - //check(map, "index-all.html", 1); - - } - - private void check(Map map, String name, int linkCount) - { - FileToCheck ftc; - - ftc = (FileToCheck) map.get(name); - assertNotNull(name, ftc); - - /*if (ftc.getResults().size() != linkCount) { - - }*/ + } - assertEquals(name + ".getLinks().size()", linkCount, ftc.getResults().size()); - } + private void check( Map map, String name, int linkCount ) + { + FileToCheck ftc; + + ftc = (FileToCheck) map.get( name ); + assertNotNull( name, ftc ); + + /*if (ftc.getResults().size() != linkCount) { + + }*/ + + assertEquals( name + ".getLinks().size()", linkCount, ftc.getResults().size() ); + } } Modified: maven/maven-1/plugins/trunk/linkcheck/src/test/org/apache/maven/plugin/linkcheck/validation/HTTPLinkValidatorTest.java URL: http://svn.apache.org/viewcvs/maven/maven-1/plugins/trunk/linkcheck/src/test/org/apache/maven/plugin/linkcheck/validation/HTTPLinkValidatorTest.java?rev=368935&r1=368923&r2=368935&view=diff ============================================================================== --- maven/maven-1/plugins/trunk/linkcheck/src/test/org/apache/maven/plugin/linkcheck/validation/HTTPLinkValidatorTest.java (original) +++ maven/maven-1/plugins/trunk/linkcheck/src/test/org/apache/maven/plugin/linkcheck/validation/HTTPLinkValidatorTest.java Fri Jan 13 16:28:50 2006 @@ -1,7 +1,7 @@ -package org.apache.maven.linkcheck.validation; +package org.apache.maven.plugin.linkcheck.validation; /* ==================================================================== - * Copyright 2001-2004 The Apache Software Foundation. + * Copyright 2001-2006 The Apache Software Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -23,25 +23,45 @@ /** * @author <a href="[EMAIL PROTECTED]">Ben Walding</a> + * @author <a href="[EMAIL PROTECTED]">Arnaud Heritier</a> * @version $Id$ */ -public class HTTPLinkValidatorTest extends TestCase +public class HTTPLinkValidatorTest + extends TestCase { + private LinkValidator hlv; + + private boolean mavenOnline = Boolean.getBoolean( "maven.mode.online" ); public void testValidateLink() + throws Exception { - //I've disabled these as they require access to the net. Ultimately - //I'd like to setup a temporary internal webserver during testing. - //Probably a test repository so it can be used for a variety of things. - //checkLink("http://www.example.com"); - //checkLink("http://www.example.com>);"); + System.err.println( "maven.mode.online : " + mavenOnline ); + if ( mavenOnline ) + { + hlv = new OnlineHTTPLinkValidator( System.getProperty( "maven.proxy.host" ), System + .getProperty( "maven.proxy.port" ), System.getProperty( "maven.proxy.username" ), System + .getProperty( "maven.proxy.password" ) ); + + assertEquals( LinkValidationResult.VALID, checkLink( "http://www.apache.org" ).getStatus() ); + assertEquals( LinkValidationResult.ERROR, checkLink( "http://www.example.com>);" ).getStatus() ); + } + else + { + hlv = new OfflineHTTPLinkValidator(); + + assertEquals( LinkValidationResult.WARNING, checkLink( "http://www.apache.org" ).getStatus() ); + assertEquals( LinkValidationResult.WARNING, checkLink( "http://www.example.com>);" ).getStatus() ); + + } } - protected LinkValidationResult checkLink(String link) + protected LinkValidationResult checkLink( String link ) + throws Exception { - HTTPLinkValidator hlv = new HTTPLinkValidator(null, null, null, null); - LinkValidationItem lvi = new LinkValidationItem(new File("."), link); - return hlv.validateLink(lvi); + + LinkValidationItem lvi = new LinkValidationItem( new File( "." ), link ); + return hlv.validateLink( lvi ); } } Modified: maven/maven-1/plugins/trunk/linkcheck/xdocs/changes.xml URL: http://svn.apache.org/viewcvs/maven/maven-1/plugins/trunk/linkcheck/xdocs/changes.xml?rev=368935&r1=368934&r2=368935&view=diff ============================================================================== --- maven/maven-1/plugins/trunk/linkcheck/xdocs/changes.xml (original) +++ maven/maven-1/plugins/trunk/linkcheck/xdocs/changes.xml Fri Jan 13 16:28:50 2006 @@ -26,6 +26,12 @@ </properties> <body> <release version="1.4-SNAPSHOT" date="in SVN"> + <action dev="aheritier" type="update" issue="MPLINKCHECK-10">"Moved Permanently" sites are reported as a warning and not as an error.</action> + <action dev="aheritier" type="update" issue="MPLINKCHECK-24">Speed and stability enhancement [better usage of httpClient].</action> + <action dev="aheritier" type="update" issue="MPLINKCHECK-24,MAVEN-1739">Upgrade to HttpClient 3.0.</action> + <action dev="aheritier" type="add" issue="MPLINKCHECK-25">Display for each file the number of links and the number of errors.</action> + <action dev="aheritier" type="add" issue="MPLINKCHECK-25">New counters to report how many files and links are checked and how many errors are found.</action> + <action dev="aheritier" type="update" issue="MPLINKCHECK-25">Display a more verbose message than the "NOT FOUND" error.</action> <action dev="aheritier" type="update" issue="MAVEN-1712">Update dependencies to match ones in maven 1.1 core and to unify them between plugins. The following dependencies are updated : <ul> <li>commons-collections v2.1 -> v3.0</li>