You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by ah...@apache.org on 2006/01/14 01:29:28 UTC
svn commit: r368935 [1/2] - in /maven/maven-1/plugins/trunk/linkcheck: ./
src/main/org/apache/maven/linkcheck/ src/main/org/apache/maven/plugin/
src/main/org/apache/maven/plugin/linkcheck/
src/main/org/apache/maven/plugin/linkcheck/validation/ src/plug...
Author: aheritier
Date: Fri Jan 13 16:28:50 2006
New Revision: 368935
URL: http://svn.apache.org/viewcvs?rev=368935&view=rev
Log:
PR: MPLINKCHECK-10, MPLINKCHECK-24, MAVEN-1739, MPLINKCHECK-25
- "Moved Permanently" sites are reported as a warning and not as an error.
- Speed and stability enhancement [better usage of httpClient].
- Upgrade to HttpClient 3.0.
- 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.
Added:
maven/maven-1/plugins/trunk/linkcheck/src/main/org/apache/maven/plugin/
maven/maven-1/plugins/trunk/linkcheck/src/main/org/apache/maven/plugin/linkcheck/
maven/maven-1/plugins/trunk/linkcheck/src/main/org/apache/maven/plugin/linkcheck/FileToCheck.java
- copied, changed from r365457, maven/maven-1/plugins/trunk/linkcheck/src/main/org/apache/maven/linkcheck/FileToCheck.java
maven/maven-1/plugins/trunk/linkcheck/src/main/org/apache/maven/plugin/linkcheck/LinkCheck.java
- copied, changed from r365457, maven/maven-1/plugins/trunk/linkcheck/src/main/org/apache/maven/linkcheck/LinkCheck.java
maven/maven-1/plugins/trunk/linkcheck/src/main/org/apache/maven/plugin/linkcheck/LinkCheckResult.java
- copied, changed from r365457, maven/maven-1/plugins/trunk/linkcheck/src/main/org/apache/maven/linkcheck/LinkCheckResult.java
maven/maven-1/plugins/trunk/linkcheck/src/main/org/apache/maven/plugin/linkcheck/validation/
- copied from r365457, maven/maven-1/plugins/trunk/linkcheck/src/main/org/apache/maven/linkcheck/validation/
maven/maven-1/plugins/trunk/linkcheck/src/main/org/apache/maven/plugin/linkcheck/validation/FileLinkValidator.java
- copied, changed from r368923, maven/maven-1/plugins/trunk/linkcheck/src/main/org/apache/maven/linkcheck/validation/FileLinkValidator.java
maven/maven-1/plugins/trunk/linkcheck/src/main/org/apache/maven/plugin/linkcheck/validation/HTTPLinkValidator.java
- copied, changed from r368923, maven/maven-1/plugins/trunk/linkcheck/src/main/org/apache/maven/linkcheck/validation/HTTPLinkValidator.java
maven/maven-1/plugins/trunk/linkcheck/src/main/org/apache/maven/plugin/linkcheck/validation/LinkValidationItem.java
- copied, changed from r368923, maven/maven-1/plugins/trunk/linkcheck/src/main/org/apache/maven/linkcheck/validation/LinkValidationItem.java
maven/maven-1/plugins/trunk/linkcheck/src/main/org/apache/maven/plugin/linkcheck/validation/LinkValidationResult.java
- copied, changed from r368923, maven/maven-1/plugins/trunk/linkcheck/src/main/org/apache/maven/linkcheck/validation/LinkValidationResult.java
maven/maven-1/plugins/trunk/linkcheck/src/main/org/apache/maven/plugin/linkcheck/validation/LinkValidator.java
- copied, changed from r368923, maven/maven-1/plugins/trunk/linkcheck/src/main/org/apache/maven/linkcheck/validation/LinkValidator.java
maven/maven-1/plugins/trunk/linkcheck/src/main/org/apache/maven/plugin/linkcheck/validation/LinkValidatorManager.java
- copied, changed from r368923, maven/maven-1/plugins/trunk/linkcheck/src/main/org/apache/maven/linkcheck/validation/LinkValidatorManager.java
maven/maven-1/plugins/trunk/linkcheck/src/main/org/apache/maven/plugin/linkcheck/validation/MailtoLinkValidator.java
- copied, changed from r368923, maven/maven-1/plugins/trunk/linkcheck/src/main/org/apache/maven/linkcheck/validation/MailtoLinkValidator.java
maven/maven-1/plugins/trunk/linkcheck/src/main/org/apache/maven/plugin/linkcheck/validation/OfflineHTTPLinkValidator.java
maven/maven-1/plugins/trunk/linkcheck/src/main/org/apache/maven/plugin/linkcheck/validation/OnlineHTTPLinkValidator.java
maven/maven-1/plugins/trunk/linkcheck/src/plugin-resources/images/
maven/maven-1/plugins/trunk/linkcheck/src/plugin-resources/images/icon_error_sml.gif (with props)
maven/maven-1/plugins/trunk/linkcheck/src/plugin-resources/images/icon_unknown_sml.gif (with props)
maven/maven-1/plugins/trunk/linkcheck/src/plugin-resources/images/icon_valid_sml.gif (with props)
maven/maven-1/plugins/trunk/linkcheck/src/plugin-resources/images/icon_warning_sml.gif (with props)
maven/maven-1/plugins/trunk/linkcheck/src/plugin-resources/images/trans.gif (with props)
maven/maven-1/plugins/trunk/linkcheck/src/test/org/apache/maven/plugin/
maven/maven-1/plugins/trunk/linkcheck/src/test/org/apache/maven/plugin/linkcheck/
- copied from r366009, maven/maven-1/plugins/trunk/linkcheck/src/test/org/apache/maven/linkcheck/
maven/maven-1/plugins/trunk/linkcheck/src/test/org/apache/maven/plugin/linkcheck/LinkCheckTest.java
- copied, changed from r368923, maven/maven-1/plugins/trunk/linkcheck/src/test/org/apache/maven/linkcheck/LinkCheckTest.java
maven/maven-1/plugins/trunk/linkcheck/src/test/org/apache/maven/plugin/linkcheck/validation/
- copied from r368923, maven/maven-1/plugins/trunk/linkcheck/src/test/org/apache/maven/linkcheck/validation/
Removed:
maven/maven-1/plugins/trunk/linkcheck/src/main/org/apache/maven/linkcheck/
maven/maven-1/plugins/trunk/linkcheck/src/main/org/apache/maven/plugin/linkcheck/validation/LinkValidatorCache.java
maven/maven-1/plugins/trunk/linkcheck/src/test/org/apache/maven/linkcheck/
Modified:
maven/maven-1/plugins/trunk/linkcheck/plugin.jelly
maven/maven-1/plugins/trunk/linkcheck/plugin.properties
maven/maven-1/plugins/trunk/linkcheck/project.properties
maven/maven-1/plugins/trunk/linkcheck/project.xml
maven/maven-1/plugins/trunk/linkcheck/src/plugin-resources/linkcheck-temp.xml
maven/maven-1/plugins/trunk/linkcheck/src/plugin-resources/linkcheck.jsl
maven/maven-1/plugins/trunk/linkcheck/src/plugin-test/maven.xml
maven/maven-1/plugins/trunk/linkcheck/src/plugin-test/xdocs/test.html
maven/maven-1/plugins/trunk/linkcheck/src/test/org/apache/maven/plugin/linkcheck/validation/HTTPLinkValidatorTest.java
maven/maven-1/plugins/trunk/linkcheck/xdocs/changes.xml
Modified: maven/maven-1/plugins/trunk/linkcheck/plugin.jelly
URL: http://svn.apache.org/viewcvs/maven/maven-1/plugins/trunk/linkcheck/plugin.jelly?rev=368935&r1=368934&r2=368935&view=diff
==============================================================================
--- maven/maven-1/plugins/trunk/linkcheck/plugin.jelly (original)
+++ maven/maven-1/plugins/trunk/linkcheck/plugin.jelly Fri Jan 13 16:28:50 2006
@@ -23,28 +23,35 @@
xmlns:define="jelly:define"
xmlns:linkcheck="linkcheck"
xmlns:maven="jelly:maven"
+ xmlns:ant="jelly:ant"
xmlns:x="jelly:xml"
xmlns:util="jelly:util"
+ xmlns:log="jelly:log"
xmlns:doc="doc">
+ <j:set var="loggerName">org.apache.maven.plugin.linkcheck.Jelly</j:set>
+
<goal name="maven-linkcheck-plugin:register">
<doc:registerReport
name="Link Check Report"
pluginName="maven-linkcheck-plugin"
link="linkcheck"
description="Report on the validity of all links in the documentation."/>
+ <log:debug name="${loggerName}">LinkCheck report registred.</log:debug>
</goal>
<goal name="maven-linkcheck-plugin:deregister">
<doc:deregisterReport name="Link Check Report"/>
+ <log:debug name="${loggerName}">LinkCheck report unregistred.</log:debug>
</goal>
<define:taglib uri="linkcheck">
<define:jellybean
name="linkcheck"
- className="org.apache.maven.linkcheck.LinkCheck"
+ className="org.apache.maven.plugin.linkcheck.LinkCheck"
method="doExecute"
/>
+ <log:debug name="${loggerName}">LinkCheck taglib defined.</log:debug>
</define:taglib>
<!-- ================================================================== -->
@@ -56,28 +63,22 @@
-->
<goal name="maven-linkcheck-plugin:report">
- <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"/>
+ <log:debug name="${loggerName}">Fake LinkCheck report copied.</log:debug>
+ <postGoal name="xdoc:jelly-transform">
+ <!-- The linkcheck plugin must be called after any other one.-->
+ <j:set var="online">${maven.mode.online}</j:set>
+ <j:if test="${online.trim().length() > 0}">
+ <attainGoal name="maven-linkcheck-plugin:report-real"/>
+ </j:if>
+ </postGoal>
</goal>
- <postGoal name="xdoc:jelly-transform">
- <maven:pluginVar var="reports" plugin="maven-xdoc-plugin" property="reports" />
-
- <j:set var="online">${maven.mode.online}</j:set>
-
- <j:if test="${online.trim().length() > 0}">
- <j:forEach var="report" items="${reports}">
- <!-- FIXME: Why special case linkcheck - fix it! -->
- <j:if test="${report.get('pluginName').equals('maven-linkcheck-plugin')}">
- <attainGoal name="maven-linkcheck-plugin:report-real"/>
- </j:if>
- </j:forEach>
- </j:if>
- </postGoal>
-
<goal
name="maven-linkcheck-plugin:report-real"
description="Generate link check results and then transform to HTML">
+ <log:debug name="${loggerName}">Begin to generate the linkcheck report.</log:debug>
<mkdir dir="${maven.build.dir}/linkcheck"/>
<mkdir dir="${maven.build.dir}/linkcheck/docs"/>
@@ -108,15 +109,21 @@
outputMode="xml"
prettyPrint="true"
/>
-
+
<doc:jslToSite srcdir="${maven.build.dir}/linkcheck/docs"/>
+
+ <!-- copy images used in the report -->
+ <mkdir dir="${maven.docs.dest}/images"/>
+ <copy todir="${maven.docs.dest}/images">
+ <fileset dir="${plugin.resources}/images"/>
+ </copy>
</goal>
<goal name="maven-linkcheck-plugin:clearcache"
description="Removes the cache file">
<delete file="${maven.linkcheck.cache}"/>
+ <log:info name="${loggerName}">Cache cleared.</log:info>
</goal>
-
</project>
Modified: maven/maven-1/plugins/trunk/linkcheck/plugin.properties
URL: http://svn.apache.org/viewcvs/maven/maven-1/plugins/trunk/linkcheck/plugin.properties?rev=368935&r1=368934&r2=368935&view=diff
==============================================================================
--- maven/maven-1/plugins/trunk/linkcheck/plugin.properties (original)
+++ maven/maven-1/plugins/trunk/linkcheck/plugin.properties Fri Jan 13 16:28:50 2006
@@ -20,3 +20,4 @@
maven.linkcheck.cache=${maven.build.dir}/linkcheck/linkcheck.cache
maven.linkcheck.failonerror=false
maven.linkcheck.exclude=${pom.repository.url}
+maven.linkcheck.timeout=30000
Modified: maven/maven-1/plugins/trunk/linkcheck/project.properties
URL: http://svn.apache.org/viewcvs/maven/maven-1/plugins/trunk/linkcheck/project.properties?rev=368935&r1=368934&r2=368935&view=diff
==============================================================================
--- maven/maven-1/plugins/trunk/linkcheck/project.properties (original)
+++ maven/maven-1/plugins/trunk/linkcheck/project.properties Fri Jan 13 16:28:50 2006
@@ -18,6 +18,15 @@
# P R O J E C T P R O P E R T I E S
# -------------------------------------------------------------------
maven.junit.fork=yes
+# Properties required for the unit tests
+maven.junit.sysproperties = \
+ maven.proxy.host \
+ maven.proxy.port \
+ maven.proxy.username \
+ maven.proxy.password \
+ maven.mode.online
maven.jar.override = on
maven.jar.maven = ${maven.home}/lib/maven.jar
+
+log4j.logger.org.apache.maven.plugin.linkcheck=INFO
\ No newline at end of file
Modified: maven/maven-1/plugins/trunk/linkcheck/project.xml
URL: http://svn.apache.org/viewcvs/maven/maven-1/plugins/trunk/linkcheck/project.xml?rev=368935&r1=368934&r2=368935&view=diff
==============================================================================
--- maven/maven-1/plugins/trunk/linkcheck/project.xml (original)
+++ maven/maven-1/plugins/trunk/linkcheck/project.xml Fri Jan 13 16:28:50 2006
@@ -1,5 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
-
<!--
/*
* Copyright 2001-2005 The Apache Software Foundation.
@@ -17,9 +16,7 @@
* limitations under the License.
*/
-->
-
-<project xmlns="http://maven.apache.org/POM/3.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://maven.apache.org/POM/3.0.0 http://maven.apache.org/maven-v3_0_0.xsd">
+<project xmlns="http://maven.apache.org/POM/3.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/3.0.0 http://maven.apache.org/maven-v3_0_0.xsd">
<extend>../plugin-parent/project.xml</extend>
<pomVersion>3</pomVersion>
<id>maven-linkcheck-plugin</id>
@@ -78,6 +75,15 @@
</roles>
</developer>
<developer>
+ <name>Arnaud Heritier</name>
+ <id>aheritier</id>
+ <email>aheritier@apache.org</email>
+ <organization>Octo Technology</organization>
+ <roles>
+ <role>Java Developer</role>
+ </roles>
+ </developer>
+ <developer>
<name>Carlos Sanchez</name>
<id>carlos</id>
<email>carlos@apache.org</email>
@@ -111,7 +117,16 @@
<dependency>
<groupId>commons-httpclient</groupId>
<artifactId>commons-httpclient</artifactId>
- <version>2.0.2</version>
+ <version>3.0</version>
+ <properties>
+ <comment>This library is already loaded by maven's core. Be careful to use the same version number as in the core.</comment>
+ </properties>
+ </dependency>
+ <dependency>
+ <groupId>commons-codec</groupId>
+ <artifactId>commons-codec</artifactId>
+ <version>1.2</version>
+ <url>http://jakarta.apache.org/commons/codec/</url>
<properties>
<comment>This library is already loaded by maven's core. Be careful to use the same version number as in the core.</comment>
</properties>
@@ -135,6 +150,11 @@
<dependency>
<groupId>commons-jelly</groupId>
<artifactId>commons-jelly-tags-jsl</artifactId>
+ <version>1.0</version>
+ </dependency>
+ <dependency>
+ <groupId>commons-jelly</groupId>
+ <artifactId>commons-jelly-tags-log</artifactId>
<version>1.0</version>
</dependency>
<dependency>
Copied: maven/maven-1/plugins/trunk/linkcheck/src/main/org/apache/maven/plugin/linkcheck/FileToCheck.java (from r365457, maven/maven-1/plugins/trunk/linkcheck/src/main/org/apache/maven/linkcheck/FileToCheck.java)
URL: http://svn.apache.org/viewcvs/maven/maven-1/plugins/trunk/linkcheck/src/main/org/apache/maven/plugin/linkcheck/FileToCheck.java?p2=maven/maven-1/plugins/trunk/linkcheck/src/main/org/apache/maven/plugin/linkcheck/FileToCheck.java&p1=maven/maven-1/plugins/trunk/linkcheck/src/main/org/apache/maven/linkcheck/FileToCheck.java&r1=365457&r2=368935&rev=368935&view=diff
==============================================================================
--- maven/maven-1/plugins/trunk/linkcheck/src/main/org/apache/maven/linkcheck/FileToCheck.java (original)
+++ maven/maven-1/plugins/trunk/linkcheck/src/main/org/apache/maven/plugin/linkcheck/FileToCheck.java Fri Jan 13 16:28:50 2006
@@ -1,7 +1,7 @@
-package org.apache.maven.linkcheck;
+package org.apache.maven.plugin.linkcheck;
/* ====================================================================
- * 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.
@@ -33,9 +33,9 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import org.apache.maven.linkcheck.validation.LinkValidationItem;
-import org.apache.maven.linkcheck.validation.LinkValidationResult;
-import org.apache.maven.linkcheck.validation.LinkValidatorManager;
+import org.apache.maven.plugin.linkcheck.validation.LinkValidationItem;
+import org.apache.maven.plugin.linkcheck.validation.LinkValidationResult;
+import org.apache.maven.plugin.linkcheck.validation.LinkValidatorManager;
import org.dom4j.Document;
import org.dom4j.Node;
import org.dom4j.io.DOMReader;
@@ -43,46 +43,130 @@
/**
* @author <a href="mailto:bwalding@apache.org">Ben Walding</a>
+ * @author <a href="mailto:aheritier@apache.org">Arnaud Heritier</a>
* @version $Id$
*/
-public class FileToCheck
+public final class FileToCheck
{
/**
* Log for debug output
*/
- private static Log LOG = LogFactory.getLog(FileToCheck.class);
+ private static final Log LOG = LogFactory.getLog( FileToCheck.class );
+
+ public static final String STATUS_UNKNOWN = null;
+
+ public static final String STATUS_JTIDY_FAILURE = "Unable to tidy source";
+
+ public static final String STATUS_OK = "OK";
private String base;
+
private File fileToCheck;
- private String status = STATUS_OK;
+
+ private List links = new LinkedList();
+
private String message = "";
+
+ private String status = STATUS_OK;
+
private int successful;
+
private int unsuccessful;
- private List links = new LinkedList();
- public static final String STATUS_UNKNOWN = null;
- public static final String STATUS_JTIDY_FAILURE = "Unable to tidy source";
- public static final String STATUS_OK = "OK";
+ private Set getLinks()
+ throws FileNotFoundException
+ {
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ PrintWriter errOut = new PrintWriter( baos );
+ BufferedInputStream bin = new BufferedInputStream( new FileInputStream( fileToCheck ) );
+ try
+ {
+ Tidy tidy = getTidy();
+ tidy.setErrout( errOut );
+ org.w3c.dom.Document domDocument = tidy.parseDOM( bin, null );
+ // now read a dom4j document from
+ // JTidy's W3C DOM object
+ final DOMReader domReader = new DOMReader();
+ final Document doc = domReader.read( domDocument );
+ return findUniqueLinks( doc );
+ }
+ finally
+ {
+ close( bin );
+ close( baos );
+ }
+ }
- public FileToCheck(File baseFile, File fileToCheck)
+ /**
+ * Returns the message.
+ * @return String
+ */
+ public String getMessage()
{
- this.base = baseFile.getAbsolutePath();
- this.fileToCheck = fileToCheck;
+ return message;
+ }
+
+ public String getName()
+ {
+ String fileName = fileToCheck.getAbsolutePath();
+ if ( fileName.startsWith( base ) )
+ {
+ fileName = fileName.substring( base.length() + 1 );
+ }
+
+ fileName = fileName.replace( '\\', '/' );
+ return fileName;
+ }
+
+ public List getResults()
+ {
+ return links;
+ }
+
+ /**
+ * Returns the status.
+ * @return int
+ */
+ public String getStatus()
+ {
+ return status;
+ }
+
+ /**
+ * Returns the successful.
+ * @return int
+ */
+ public int getSuccessful()
+ {
+ return successful;
+ }
+ /**
+ * Returns the unsuccessful.
+ * @return int
+ */
+ public int getUnsuccessful()
+ {
+ return unsuccessful;
}
- private void addResult(LinkCheckResult lcr)
+ public FileToCheck( File baseFile, File fileToCheck )
{
- this.links.add(lcr);
+ this.base = baseFile.getAbsolutePath();
+ this.fileToCheck = fileToCheck;
}
- public void check(LinkValidatorManager lvm) throws Exception
+ public void check( LinkValidatorManager lvm )
+ throws Exception
{
successful = 0;
unsuccessful = 0;
status = STATUS_OK;
message = "";
-
+ if ( LOG.isDebugEnabled() )
+ {
+ LOG.debug( "Validating " + getName() );
+ }
try
{
final Set hrefs;
@@ -90,228 +174,154 @@
{
hrefs = getLinks();
}
- catch (Throwable e)
+ catch ( Throwable t )
{
//We catch Throwable, because there is a chance that the domReader will throw
//a stack overflow exception for some files
- LOG.info("Caught " + e.toString() + " processing " + getName());
- LOG.info("Exception Message: " + e.getLocalizedMessage());
+ if ( LOG.isDebugEnabled() )
+ LOG.error( "Received: [" + t + "] in page [" + getName() + "]", t );
+ else
+ LOG.error( "Received: [" + t + "] in page [" + getName() + "]" );
LinkCheckResult lcr = new LinkCheckResult();
- lcr.setStatus("PARSE FAILURE");
- lcr.setTarget("N/A");
- addResult(lcr);
+ lcr.setStatus( "PARSE FAILURE" );
+ lcr.setTarget( "N/A" );
+ addResult( lcr );
return;
}
-
- for (Iterator iter = hrefs.iterator(); iter.hasNext(); )
+ String href;
+ LinkCheckResult lcr;
+ LinkValidationItem lvi;
+ LinkValidationResult result;
+ for ( Iterator iter = hrefs.iterator(); iter.hasNext(); )
{
- String href = (String) iter.next();
-
- LOG.debug("Link Found: " + href);
-
- LinkCheckResult lcr = new LinkCheckResult();
-
- LinkValidationItem lvi = new LinkValidationItem(fileToCheck, href);
- LinkValidationResult result = lvm.validateLink(lvi);
- lcr.setTarget(href);
-
- switch (result.getStatus())
+ href = (String) iter.next();
+ lcr = new LinkCheckResult();
+ lvi = new LinkValidationItem( fileToCheck, href );
+ result = lvm.validateLink( lvi );
+ lcr.setTarget( href );
+ lcr.setErrorMessage( result.getErrorMessage() );
+ switch ( result.getStatus() )
{
- case LinkValidationResult.VALID :
+ case LinkValidationResult.VALID:
successful++;
- lcr.setStatus("OK");
- addResult(lcr); //At some point we won't want to store valid links. The tests require that we do at present
+ lcr.setStatus( "valid" );
+ addResult( lcr ); //At some point we won't want to store valid links. The tests require that we do at present
break;
- case LinkValidationResult.UNKNOWN :
+ case LinkValidationResult.UNKNOWN:
unsuccessful++;
- lcr.setStatus("UNKNOWN REF");
- addResult(lcr);
+ lcr.setStatus( "unknown" );
+ addResult( lcr );
break;
- case LinkValidationResult.INVALID :
+ case LinkValidationResult.ERROR:
unsuccessful++;
- lcr.setStatus("NOT FOUND");
- addResult(lcr);
+ lcr.setStatus( "error" );
+ addResult( lcr );
+ break;
+ case LinkValidationResult.WARNING:
+ unsuccessful++;
+ lcr.setStatus( "warning" );
+ addResult( lcr );
break;
}
-
}
+ href = null;
+ lcr = null;
+ lvi = null;
+ result = null;
+
}
- catch (Exception e)
+ catch ( Exception e )
{
- System.err.println(message);
- throw (e);
+ LOG.error( message );
+ throw ( e );
}
}
- private Set getLinks() throws FileNotFoundException
+ public String toXML()
{
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- PrintWriter errOut = new PrintWriter(baos);
- BufferedInputStream bin = new BufferedInputStream(new FileInputStream(fileToCheck));
- try
- {
- Tidy tidy = getTidy();
- tidy.setErrout(errOut);
- LOG.debug("Processing:" + fileToCheck);
- org.w3c.dom.Document domDocument = tidy.parseDOM(bin, null);
-
- // now read a dom4j document from
- // JTidy's W3C DOM object
- final DOMReader domReader = new DOMReader();
- final Document doc = domReader.read(domDocument);
-
- LOG.debug(baos.toString());
-
- return findUniqueLinks(doc);
- }
- finally
+ StringBuffer buf = new StringBuffer();
+ buf.append( " <file>\n" );
+ buf.append( " <name><![CDATA[" + getName() + "]]></name>\n" );
+ buf.append( " <successful>" + getSuccessful() + "</successful>\n" );
+ buf.append( " <unsuccessful>" + getUnsuccessful() + "</unsuccessful>\n" );
+ Iterator iter = getResults().iterator();
+ LinkCheckResult result;
+ while ( iter.hasNext() )
{
- close(bin);
- close(baos);
+ result = (LinkCheckResult) iter.next();
+ buf.append( result.toXML() );
}
+ buf.append( " </file>\n" );
+ return buf.toString();
}
- private void close(InputStream is)
+ private void addResult( LinkCheckResult lcr )
+ {
+ this.links.add( lcr );
+ }
+
+ private void close( InputStream is )
{
try
{
is.close();
}
- catch (Exception e)
+ catch ( Exception e )
{
//Don't really care.
}
}
- private void close(OutputStream os)
+ private void close( OutputStream os )
{
try
{
os.close();
}
- catch (Exception e)
+ catch ( Exception e )
{
//Don't really care.
}
}
- private Set findUniqueLinks(Document doc)
+ private Set findUniqueLinks( Document doc )
{
List xpathResults = new LinkedList();
- xpathResults.addAll(doc.selectNodes("//a/@href"));
- xpathResults.addAll(doc.selectNodes("//img/@src"));
+ xpathResults.addAll( doc.selectNodes( "//a/@href" ) );
+ xpathResults.addAll( doc.selectNodes( "//img/@src" ) );
- //<link rel="stylesheet" href="...">
- xpathResults.addAll(doc.selectNodes("//link/@href"));
+ xpathResults.addAll( doc.selectNodes( "//link/@href" ) );
- //<script src="http://ar.atwola.com/file/adsWrapper.js">
- xpathResults.addAll(doc.selectNodes("//script/@src"));
+ xpathResults.addAll( doc.selectNodes( "//script/@src" ) );
Set results = new TreeSet();
Iterator linkIter = xpathResults.iterator();
- while (linkIter.hasNext())
+ Node node = null;
+ String href = null;
+ while ( linkIter.hasNext() )
{
- Node node = (Node) linkIter.next();
- String href = node.getText();
- results.add(href);
- }
-
+ node = (Node) linkIter.next();
+ href = node.getText();
+ results.add( href );
+ }
+ xpathResults = null;
+ linkIter = null;
+ node = null;
+ href = null;
return results;
}
private Tidy getTidy()
{
Tidy tidy = new Tidy();
- tidy.setMakeClean(true);
- tidy.setXmlTags(true);
- tidy.setXmlOut(true);
- tidy.setXHTML(true);
- tidy.setQuiet(true);
- tidy.setShowWarnings(false);
+ tidy.setMakeClean( true );
+ tidy.setXmlTags( true );
+ tidy.setXmlOut( true );
+ tidy.setXHTML( true );
+ tidy.setQuiet( true );
+ tidy.setShowWarnings( false );
return tidy;
- }
-
- /**
- * Returns the message.
- * @return String
- */
- public String getMessage()
- {
- return message;
- }
-
- /**
- * Returns the status.
- * @return int
- */
- public String getStatus()
- {
- return status;
- }
-
- /**
- * Sets the message.
- * @param message The message to set
- */
- public void setMessage(String message)
- {
- this.message = message;
- }
-
- public List getResults()
- {
- return links;
- }
-
- /**
- * Returns the successful.
- * @return int
- */
- public int getSuccessful()
- {
- return successful;
- }
-
- /**
- * Returns the unsuccessful.
- * @return int
- */
- public int getUnsuccessful()
- {
- return unsuccessful;
- }
-
- public String getName()
- {
- String fileName = fileToCheck.getAbsolutePath();
- if (fileName.startsWith(base)) {
- fileName = fileName.substring(base.length() + 1);
- }
-
- fileName = fileName.replace('\\', '/');
- return fileName;
- }
-
- public String toXML()
- {
- StringBuffer buf = new StringBuffer();
-
- buf.append(" <file>\n");
- buf.append(" <name><![CDATA[" + getName() + "]]></name>\n");
- buf.append(" <successful>" + getSuccessful() + "</successful>\n");
- buf.append(" <unsuccessful>" + getUnsuccessful() + "</unsuccessful>\n");
-
- Iterator iter = getResults().iterator();
- while (iter.hasNext())
- {
- LinkCheckResult result = (LinkCheckResult) iter.next();
- buf.append(result.toXML());
- }
-
- buf.append(" </file>\n");
-
- return buf.toString();
}
}
Copied: maven/maven-1/plugins/trunk/linkcheck/src/main/org/apache/maven/plugin/linkcheck/LinkCheck.java (from r365457, maven/maven-1/plugins/trunk/linkcheck/src/main/org/apache/maven/linkcheck/LinkCheck.java)
URL: http://svn.apache.org/viewcvs/maven/maven-1/plugins/trunk/linkcheck/src/main/org/apache/maven/plugin/linkcheck/LinkCheck.java?p2=maven/maven-1/plugins/trunk/linkcheck/src/main/org/apache/maven/plugin/linkcheck/LinkCheck.java&p1=maven/maven-1/plugins/trunk/linkcheck/src/main/org/apache/maven/linkcheck/LinkCheck.java&r1=365457&r2=368935&rev=368935&view=diff
==============================================================================
--- maven/maven-1/plugins/trunk/linkcheck/src/main/org/apache/maven/linkcheck/LinkCheck.java (original)
+++ maven/maven-1/plugins/trunk/linkcheck/src/main/org/apache/maven/plugin/linkcheck/LinkCheck.java Fri Jan 13 16:28:50 2006
@@ -1,7 +1,7 @@
-package org.apache.maven.linkcheck;
+package org.apache.maven.plugin.linkcheck;
/* ====================================================================
- * 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.
@@ -18,10 +18,13 @@
*/
import java.io.File;
+import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FilenameFilter;
+import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
+import java.io.UnsupportedEncodingException;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
@@ -30,10 +33,11 @@
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.plugin.linkcheck.validation.FileLinkValidator;
+import org.apache.maven.plugin.linkcheck.validation.LinkValidatorManager;
+import org.apache.maven.plugin.linkcheck.validation.MailtoLinkValidator;
+import org.apache.maven.plugin.linkcheck.validation.OfflineHTTPLinkValidator;
+import org.apache.maven.plugin.linkcheck.validation.OnlineHTTPLinkValidator;
import org.apache.maven.project.Project;
/**
@@ -42,32 +46,39 @@
*
* @author <a href="mailto:bwalding@apache.org">Ben Walding</a>
* @author <a href="mailto:carlos@apache.org">Carlos Sanchez</a>
+ * @author <a href="mailto:aheritier@apache.org">Arnaud Heritier</a>
* @version $Id$
*/
-public class LinkCheck
+public final class LinkCheck
{
/** Log */
- private static final Log LOG = LogFactory.getLog(LinkCheck.class);
+ private static final Log LOG = LogFactory.getLog( LinkCheck.class );
- /** Output file for xml document */
- private File output;
+ private static final FilenameFilter CUSTOM_FF = new LinkCheck.CustomFilenameFilter();
- /** Output encoding for the xml document */
- private String outputEncoding;
+ private static final long MEG = 1024 * 1024;
+
+ private File basedir;
- private File baseDir;
private String cache;
+
private String exclude;
- private Project project;
+
+ private List filesToCheck = null;
+
+ private LinkValidatorManager lvm = null;
/**
- * Set the base directory for the change log generator.
- * @param base the base directory
+ * Output file for xml document
*/
- public void setBasedir(File base)
- {
- this.baseDir = base;
- }
+ private File output;
+
+ /**
+ * Output encoding for the xml document
+ */
+ private String outputEncoding;
+
+ private Project project;
/**
* Get the base directory for the change log generator.
@@ -76,58 +87,56 @@
*/
public File getBasedir()
{
- return baseDir;
+ return basedir;
}
/**
- * Set the output file for the log.
- * @param output the output file
+ * Set the base directory for the change log generator.
+ * @param base the base directory
*/
- public void setOutput(File output)
+ public void setBasedir( File base )
{
- this.output = output;
+ this.basedir = base;
}
/**
- * Execute task.
- * @throws FileNotFoundException if {@link ChangeLog#base} doesn't exist
- * @throws IOException if there are problems running CVS
- * @throws UnsupportedEncodingException if the underlying platform doesn't
- * support ISO-8859-1 encoding
+ * Returns the cacheFile.
+ * @return String
*/
- private List filesToCheck = null; //of FileToCheck
- public void doExecute() throws Exception
+ public String getCache()
{
- if (output == null)
- {
- throw new NullPointerException("output must be set");
- }
- LinkValidatorManager validator = getLinkValidatorManager();
+ return cache;
+ }
- filesToCheck = new LinkedList();
- validator.loadCache(cache);
- List files = new LinkedList();
- LOG.debug("Locating all files to be checked...");
- findFiles(files, baseDir);
- LOG.debug("Located all files to be checked.");
- Iterator fileIter = files.iterator();
- while (fileIter.hasNext())
- {
- FileToCheck flc = (FileToCheck) fileIter.next();
- try
- {
- filesToCheck.add(flc);
- LOG.info("Validating " + flc.getName());
- flc.check(validator);
- }
- catch (Exception e)
- {
- e.printStackTrace();
- }
- }
+ /**
+ * Sets the cacheFile.
+ * @param cacheFile The cacheFile to set
+ */
+ public void setCache( String cache )
+ {
+ this.cache = cache;
+ }
- createDocument(files);
- validator.saveCache(cache);
+ /**
+ * Returns the exclude.
+ * @return String
+ */
+ public String getExclude()
+ {
+ return exclude;
+ }
+
+ /**
+ * Sets the exclude, a string with exclude locations delimited by the space
+ * character, the comma character, the tab character, the newline character,
+ * the carriage-return character, and the form-feed character.
+ *
+ * @param exclude
+ * The exclude to set
+ */
+ public void setExclude( String exclude )
+ {
+ this.exclude = exclude;
}
public List getFiles()
@@ -135,75 +144,52 @@
return filesToCheck;
}
- public void findFiles(List allFiles, File base)
+ public LinkValidatorManager getLinkValidatorManager()
{
- FilenameFilter ff = new FilenameFilter()
+ if ( lvm == null )
{
- /**
- * @see java.io.FilenameFilter#accept(java.io.File, java.lang.String)
- */
- public boolean accept(File dir, String name)
+ lvm = new LinkValidatorManager();
+ if ( exclude != null )
{
- File n = new File(dir, name);
- if (n.isDirectory())
- return true;
-
- if (name.endsWith(".html"))
- return true;
-
- return false;
+ StringTokenizer st = new StringTokenizer( exclude, " ,\t\n\r\f" );
+ String[] tokens = new String[st.countTokens()];
+ for ( int i = 0; i < tokens.length; i++ )
+ {
+ tokens[i] = st.nextToken();
+ }
+ lvm.setExcludes( tokens );
+ tokens = null;
+ st = null;
}
- };
-
- File[] f = base.listFiles(ff);
-
- if (f != null)
- {
- for (int i = 0; i < f.length; i++)
+ lvm.addLinkValidator( new FileLinkValidator() );
+ // Project is only null in test cases
+ if ( getProject() != null )
{
- File file = f[i];
- if (file.isDirectory())
+ MavenJellyContext ctx = ( (Project) getProject() ).getContext();
+ if ( ctx.getOnline().booleanValue() )
{
- findFiles(allFiles, file);
+ lvm.addLinkValidator( new OnlineHTTPLinkValidator( ctx.getProxyHost(), ctx.getProxyPort(), ctx
+ .getProxyUserName(), ctx.getProxyPassword() ) );
}
else
{
- if (allFiles.size() % 1000 == 0) {
- LOG.info("Found " + allFiles.size() + " files so far.");
- final long MEG = 1024 * 1024;
- Runtime r = Runtime.getRuntime();
- LOG.info( " Memory: " + ((r.totalMemory() - r.freeMemory()) / MEG) + "M/" + (r.totalMemory() / MEG) + "M");
- }
- //LOG.info(" File - " + file);
- allFiles.add(new FileToCheck(baseDir, file));
+ lvm.addLinkValidator( new OfflineHTTPLinkValidator() );
+
}
+ ctx = null;
}
+ lvm.addLinkValidator( new MailtoLinkValidator() );
}
+ return lvm;
}
/**
- * Create the XML document from the currently available details
- * @throws FileNotFoundException when the output file previously provided
- * does not exist
- * @throws UnsupportedEncodingException when the platform doesn't support
- * ISO-8859-1 encoding
+ * Set the output file for the log.
+ * @param output the output file
*/
- private void createDocument(List files) throws Exception
+ public void setOutput( File output )
{
- File dir = output.getParentFile();
- if (dir != null)
- {
- dir.mkdirs();
- }
- PrintWriter out = new PrintWriter(new OutputStreamWriter(new FileOutputStream(output), getOutputEncoding()));
-
- StringBuffer buffer = new StringBuffer();
- buffer.append("<?xml version=\"1.0\" encoding=\"").append(getOutputEncoding()).append("\" ?>\n");
-
- out.write(buffer.toString());
-
- out.write(toXML());
- out.close();
+ this.output = output;
}
/**
@@ -219,111 +205,181 @@
* Sets the outputEncoding.
* @param outputEncoding The outputEncoding to set
*/
- public void setOutputEncoding(String outputEncoding)
+ public void setOutputEncoding( String outputEncoding )
{
this.outputEncoding = outputEncoding;
}
- LinkValidatorManager lvm = null;
- public LinkValidatorManager getLinkValidatorManager()
- {
- if (lvm == null)
- {
- lvm = new LinkValidatorManager();
- if (exclude != null) {
- StringTokenizer st = new StringTokenizer(exclude, " ,\t\n\r\f");
- String[] tokens = new String[st.countTokens()];
- for (int i = 0; i < tokens.length; i++) {
- tokens[i] = st.nextToken();
- }
- lvm.setExcludes(tokens);
- }
- lvm.addLinkValidator(new FileLinkValidator());
- // Project is only null in test cases
- if (getProject() != null) {
- MavenJellyContext ctx = ((Project) getProject()).getContext();
- lvm.addLinkValidator(new HTTPLinkValidator(ctx.getProxyHost(), ctx.getProxyPort(), ctx.getProxyUserName(), ctx.getProxyPassword()));
- }
-
- lvm.addLinkValidator(new MailtoLinkValidator());
- lvm.loadCache(cache);
- }
- return lvm;
- }
-
/**
- * Returns the cacheFile.
- * @return String
+ * @return Project
*/
- public String getCache()
+ public Object getProject()
{
- return cache;
+ return project;
}
/**
- * Sets the cacheFile.
- * @param cacheFile The cacheFile to set
+ * Sets the project.
+ * @param project The project to set
*/
- public void setCache(String cache)
+ public void setProject( Object project )
{
- this.cache = cache;
+ this.project = (Project) project;
}
- /**
- * Returns the exclude.
- * @return String
- */
- public String getExclude()
+ public void findFiles( List allFiles, File base )
{
- return exclude;
+ File[] f = base.listFiles( CUSTOM_FF );
+ if ( f != null )
+ {
+ File file;
+ for ( int i = 0; i < f.length; i++ )
+ {
+ file = f[i];
+ if ( file.isDirectory() )
+ {
+ findFiles( allFiles, file );
+ }
+ else
+ {
+ if ( LOG.isDebugEnabled() )
+ {
+ LOG.debug( " File - " + file );
+ }
+ allFiles.add( new FileToCheck( basedir, file ) );
+ if ( allFiles.size() % 100 == 0 )
+ {
+ LOG.info( "Found " + allFiles.size() + " files so far." );
+ }
+ }
+ }
+ file = null;
+ }
+ f = null;
}
/**
- * Sets the exclude, a string with exclude locations delimited by the space
- * character, the comma character, the tab character, the newline character,
- * the carriage-return character, and the form-feed character.
- *
- * @param exclude
- * The exclude to set
+ * Execute task.
+ * @throws FileNotFoundException if {@link ChangeLog#base} doesn't exist
+ * @throws IOException if there are problems running CVS
+ * @throws UnsupportedEncodingException if the underlying platform doesn't
+ * support ISO-8859-1 encoding
*/
- public void setExclude(String exclude)
+
+ public void doExecute()
+ throws FileNotFoundException, IOException, UnsupportedEncodingException
{
- this.exclude = exclude;
+ if ( output == null )
+ {
+ throw new NullPointerException( "output must be set" );
+ }
+ if ( LOG.isDebugEnabled() )
+ {
+ displayMemoryConsumption();
+ }
+ LinkValidatorManager validator = getLinkValidatorManager();
+ filesToCheck = new LinkedList();
+ validator.loadCache( cache );
+ List files = new LinkedList();
+ LOG.debug( "Locating all files to be checked..." );
+ findFiles( files, basedir );
+ LOG.debug( "Located all files to be checked." );
+ LOG.info( "Found " + files.size() + " files to check." );
+ displayMemoryConsumption();
+ LOG.info( "Begin to check links in files..." );
+ Iterator fileIter = files.iterator();
+ FileToCheck flc;
+ while ( fileIter.hasNext() )
+ {
+ flc = (FileToCheck) fileIter.next();
+ try
+ {
+ filesToCheck.add( flc );
+ flc.check( validator );
+ }
+ catch ( Exception e )
+ {
+ LOG.error( "Error while checking : " + flc.getName(), e );
+ }
+ }
+ flc = null;
+ LOG.info( "Links checked." );
+ displayMemoryConsumption();
+ createDocument( files );
+ validator.saveCache( cache );
+ displayMemoryConsumption();
}
public String toXML()
{
StringBuffer buf = new StringBuffer();
-
- buf.append("<linkcheck>\n");
-
- //buf.append(" <files>\n");
- for (Iterator iter = getFiles().iterator(); iter.hasNext();)
+ buf.append( "<linkcheck>\n" );
+ FileToCheck ftc;
+ for ( Iterator iter = getFiles().iterator(); iter.hasNext(); )
{
- FileToCheck ftc = (FileToCheck) iter.next();
- buf.append(ftc.toXML());
+ ftc = (FileToCheck) iter.next();
+ buf.append( ftc.toXML() );
}
- //buf.append(" </files>\n");
- buf.append("</linkcheck>\n");
+ ftc = null;
+ buf.append( "</linkcheck>\n" );
return buf.toString();
}
- /**
- * @return Project
- */
- public Object getProject()
+ private void displayMemoryConsumption()
{
- return project;
+ if ( LOG.isDebugEnabled() )
+ {
+ Runtime r = Runtime.getRuntime();
+ LOG.debug( "Memory: " + ( ( r.totalMemory() - r.freeMemory() ) / MEG ) + "M/" + ( r.totalMemory() / MEG )
+ + "M" );
+ }
}
/**
- * Sets the project.
- * @param project The project to set
+ * Create the XML document from the currently available details
+ * @throws FileNotFoundException when the output file previously provided
+ * does not exist
+ * @throws UnsupportedEncodingException when the platform doesn't support
+ * ISO-8859-1 encoding
*/
- public void setProject(Object project)
+ private void createDocument( List files )
+ throws FileNotFoundException, UnsupportedEncodingException
+
{
- //System.out.println("Setting project: " + project);
- this.project = (Project) project;
+ File dir = output.getParentFile();
+ if ( dir != null )
+ {
+ dir.mkdirs();
+ }
+ PrintWriter out = new PrintWriter( new OutputStreamWriter( new FileOutputStream( output ), getOutputEncoding() ) );
+ StringBuffer buffer = new StringBuffer();
+ buffer.append( "<?xml version=\"1.0\" encoding=\"" ).append( getOutputEncoding() ).append( "\" ?>\n" );
+ out.write( buffer.toString() );
+ out.write( toXML() );
+ out.close();
+ out = null;
+ buffer = null;
+ dir = null;
+ }
+
+ /** Custom FilenameFilter used to search html files */
+ static class CustomFilenameFilter
+ implements FilenameFilter
+ {
+ /**
+ * @see java.io.FilenameFilter#accept(java.io.File, java.lang.String)
+ */
+ public boolean accept( File dir, String name )
+ {
+ File n = new File( dir, name );
+ if ( n.isDirectory() )
+ return true;
+ if ( name.endsWith( ".html" ) )
+ {
+ return true;
+ }
+ return false;
+ }
}
}
Copied: maven/maven-1/plugins/trunk/linkcheck/src/main/org/apache/maven/plugin/linkcheck/LinkCheckResult.java (from r365457, maven/maven-1/plugins/trunk/linkcheck/src/main/org/apache/maven/linkcheck/LinkCheckResult.java)
URL: http://svn.apache.org/viewcvs/maven/maven-1/plugins/trunk/linkcheck/src/main/org/apache/maven/plugin/linkcheck/LinkCheckResult.java?p2=maven/maven-1/plugins/trunk/linkcheck/src/main/org/apache/maven/plugin/linkcheck/LinkCheckResult.java&p1=maven/maven-1/plugins/trunk/linkcheck/src/main/org/apache/maven/linkcheck/LinkCheckResult.java&r1=365457&r2=368935&rev=368935&view=diff
==============================================================================
--- maven/maven-1/plugins/trunk/linkcheck/src/main/org/apache/maven/linkcheck/LinkCheckResult.java (original)
+++ maven/maven-1/plugins/trunk/linkcheck/src/main/org/apache/maven/plugin/linkcheck/LinkCheckResult.java Fri Jan 13 16:28:50 2006
@@ -1,7 +1,7 @@
-package org.apache.maven.linkcheck;
+package org.apache.maven.plugin.linkcheck;
/* ====================================================================
- * 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.
@@ -18,67 +18,86 @@
*/
import org.apache.commons.lang.StringEscapeUtils;
-
+
/**
* An class containing the results of a single check of a link.
* @author <a href="mailto:bwalding@apache.org">Ben Walding</a>
+ * @author <a href="mailto:aheritier@apache.org">Arnaud Heritier</a>
* @version $Id$
*/
-public class LinkCheckResult
+public final class LinkCheckResult
{
- private String status;
- private String target;
+ private String status;
+
+ private String target;
- /**
- * Returns the status.
- * @return String
- */
- public String getStatus()
- {
- return status;
- }
-
- /**
- * Sets the status.
- * @param status The status to set
- */
- public void setStatus(String status)
- {
- this.status = status;
- }
-
- /**
- * Returns the target.
- * @return String
- */
- public String getTarget()
- {
- return target;
- }
-
- /**
- * Sets the target.
- * @param target The target to set
- */
- public void setTarget(String target)
- {
- this.target = target;
- }
-
- /**
- * Creates an XML representation of this link check result
- * @return xml fragment representation of this result
- */
- public String toXML()
- {
- StringBuffer buf = new StringBuffer();
-
- buf.append(" <result>\n");
- buf.append(" <target>" + StringEscapeUtils.escapeXml(getTarget()) + "</target>\n");
- buf.append(" <status>" + getStatus() + "</status>\n");
- buf.append(" </result>\n");
+ private String errorMessage;
- return buf.toString();
- }
+ /**
+ * Returns the status.
+ * @return String
+ */
+ public String getStatus()
+ {
+ return status;
+ }
+
+ /**
+ * Sets the status.
+ * @param status The status to set
+ */
+ public void setStatus( String status )
+ {
+ this.status = status;
+ }
+
+ /**
+ * Returns the target.
+ * @return String
+ */
+ public String getTarget()
+ {
+ return target;
+ }
+
+ /**
+ * Sets the target.
+ * @param target The target to set
+ */
+ public void setTarget( String target )
+ {
+ this.target = target;
+ }
+
+ /**
+ * @return Returns the errorMessage.
+ */
+ public String getErrorMessage()
+ {
+ return errorMessage;
+ }
+
+ /**
+ * @param errorMessage The errorMessage to set.
+ */
+ public void setErrorMessage( String errorMessage )
+ {
+ this.errorMessage = errorMessage;
+ }
+
+ /**
+ * Creates an XML representation of this link check result
+ * @return xml fragment representation of this result
+ */
+ public String toXML()
+ {
+ StringBuffer buf = new StringBuffer();
+ buf.append( " <result>\n" );
+ buf.append( " <target>" + StringEscapeUtils.escapeXml( getTarget() ) + "</target>\n" );
+ buf.append( " <status>" + getStatus() + "</status>\n" );
+ buf.append( " <errorMessage>" + StringEscapeUtils.escapeXml( getErrorMessage() ) + "</errorMessage>\n" );
+ buf.append( " </result>\n" );
+ return buf.toString();
+ }
}
Copied: maven/maven-1/plugins/trunk/linkcheck/src/main/org/apache/maven/plugin/linkcheck/validation/FileLinkValidator.java (from r368923, maven/maven-1/plugins/trunk/linkcheck/src/main/org/apache/maven/linkcheck/validation/FileLinkValidator.java)
URL: http://svn.apache.org/viewcvs/maven/maven-1/plugins/trunk/linkcheck/src/main/org/apache/maven/plugin/linkcheck/validation/FileLinkValidator.java?p2=maven/maven-1/plugins/trunk/linkcheck/src/main/org/apache/maven/plugin/linkcheck/validation/FileLinkValidator.java&p1=maven/maven-1/plugins/trunk/linkcheck/src/main/org/apache/maven/linkcheck/validation/FileLinkValidator.java&r1=368923&r2=368935&rev=368935&view=diff
==============================================================================
--- maven/maven-1/plugins/trunk/linkcheck/src/main/org/apache/maven/linkcheck/validation/FileLinkValidator.java (original)
+++ maven/maven-1/plugins/trunk/linkcheck/src/main/org/apache/maven/plugin/linkcheck/validation/FileLinkValidator.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.
@@ -16,32 +16,41 @@
* limitations under the License.
* ====================================================================
*/
-
+
import java.io.File;
/**
* A link validator solely for files on the local filesystem.
*
* @author <a href="mailto:bwalding@apache.org">Ben Walding</a>
+ * @author <a href="mailto:aheritier@apache.org">Arnaud Heritier</a>
* @version $Id$
*/
-public class FileLinkValidator implements LinkValidator {
- private final static LinkValidationResult LVR_INVALID =
- new LinkValidationResult(LinkValidationResult.INVALID, false);
-
- private final static LinkValidationResult LVR_VALID =
- new LinkValidationResult(LinkValidationResult.VALID, false);
-
+public final class FileLinkValidator
+ implements LinkValidator
+{
/**
- * @see org.apache.maven.linkcheck.LinkValidator#validateLink(org.apache.maven.linkcheck.LinkValidationItem)
+ * @see org.apache.maven.plugin.linkcheck.LinkValidator#validateLink(org.apache.maven.plugin.linkcheck.LinkValidationItem)
*/
- public LinkValidationResult validateLink(LinkValidationItem lvi) {
- File f = getFile(lvi);
-
- if (f.exists())
- return LVR_VALID;
+ public LinkValidationResult validateLink( LinkValidationItem lvi )
+ {
+ File f = getFile( lvi );
+ if ( f.exists() )
+ return new LinkValidationResult( LinkValidationResult.VALID, false, "" );
else
- return LVR_INVALID;
+ return new LinkValidationResult( LinkValidationResult.ERROR, false, "doesn't exist." );
+ }
+
+ /**
+ * @see org.apache.maven.plugin.linkcheck.LinkValidator#getResourceKey(org.apache.maven.plugin.linkcheck.LinkValidationItem)
+ */
+ public Object getResourceKey( LinkValidationItem lvi )
+ {
+ 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();
}
/**
@@ -49,31 +58,20 @@
* @param lvi
* @return File
*/
- protected File getFile(LinkValidationItem lvi) {
+ protected File getFile( LinkValidationItem lvi )
+ {
String link = lvi.getLink();
- if (link.indexOf('#') != -1) {
- link = link.substring(0, link.indexOf('#'));
+ if ( link.indexOf( '#' ) != -1 )
+ {
+ 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 (link.trim().length() == 0)
+ if ( link.trim().length() == 0 )
return lvi.getSource();
}
-
- File f = new File(lvi.getSource().getParentFile(), link);
+ File f = new File( lvi.getSource().getParentFile(), link );
return f;
- }
-
- /**
- * @see org.apache.maven.linkcheck.LinkValidator#getResourceKey(org.apache.maven.linkcheck.LinkValidationItem)
- */
- public Object getResourceKey(LinkValidationItem lvi) {
- String link = lvi.getLink();
-
- if (link.indexOf(':') != -1)
- return null;
-
- return getFile(lvi).getAbsolutePath();
}
}
Copied: maven/maven-1/plugins/trunk/linkcheck/src/main/org/apache/maven/plugin/linkcheck/validation/HTTPLinkValidator.java (from r368923, maven/maven-1/plugins/trunk/linkcheck/src/main/org/apache/maven/linkcheck/validation/HTTPLinkValidator.java)
URL: http://svn.apache.org/viewcvs/maven/maven-1/plugins/trunk/linkcheck/src/main/org/apache/maven/plugin/linkcheck/validation/HTTPLinkValidator.java?p2=maven/maven-1/plugins/trunk/linkcheck/src/main/org/apache/maven/plugin/linkcheck/validation/HTTPLinkValidator.java&p1=maven/maven-1/plugins/trunk/linkcheck/src/main/org/apache/maven/linkcheck/validation/HTTPLinkValidator.java&r1=368923&r2=368935&rev=368935&view=diff
==============================================================================
--- maven/maven-1/plugins/trunk/linkcheck/src/main/org/apache/maven/linkcheck/validation/HTTPLinkValidator.java (original)
+++ maven/maven-1/plugins/trunk/linkcheck/src/main/org/apache/maven/plugin/linkcheck/validation/HTTPLinkValidator.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.
@@ -17,166 +17,27 @@
* ====================================================================
*/
-import org.apache.commons.httpclient.Header;
-import org.apache.commons.httpclient.HostConfiguration;
-import org.apache.commons.httpclient.HttpClient;
-import org.apache.commons.httpclient.HttpState;
-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:bwalding@apache.org">Ben Walding</a>
+ * @author <a href="mailto:aheritier@apache.org">Arnaud Heritier</a>
* @version $Id$
*/
-public class HTTPLinkValidator implements LinkValidator
+public abstract class HTTPLinkValidator
+ implements LinkValidator
{
/**
- * Log for debug output
+ * @see org.apache.maven.plugin.linkcheck.LinkValidator#getResourceKey(org.apache.maven.plugin.linkcheck.LinkValidationItem)
*/
- private static Log LOG = LogFactory.getLog(HTTPLinkValidator.class);
-
- private static final LinkValidationResult LVR_INVALID =
- new LinkValidationResult(LinkValidationResult.INVALID, true);
-
- private static final LinkValidationResult LVR_VALID = new LinkValidationResult(LinkValidationResult.VALID, true);
-
- 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 || proxyHost.trim().equals(""))
- {
- LOG.info("maven-linkcheck-plugin: Not using a proxy");
- this.proxyHost = null;
- }
- else
- {
- this.proxyHost = proxyHost;
- try{
- this.proxyPort = Integer.parseInt(proxyPort);
- }catch(NumberFormatException e){
- LOG.warn("maven-linkcheck-plugin: Invalid number for Proxy Port:" + proxyPort);
- LOG.warn("maven-linkcheck-plugin: Proxy Port won't be used.");
- this.proxyPort = 0;
- }
- this.proxyUser = proxyUser;
- this.proxyPass = proxyPass;
- LOG.info("maven-linkcheck-plugin: Proxy Host:" + proxyHost);
- LOG.info("maven-linkcheck-plugin: Proxy Port:" + proxyPort);
- LOG.info("maven-linkcheck-plugin: Proxy User:" + proxyUser);
- }
- }
-
- /**
- * @see org.apache.maven.linkcheck.LinkValidator#validateLink(org.apache.maven.linkcheck.LinkValidationItem)
- */
- public LinkValidationResult validateLink(LinkValidationItem lvi)
- {
- try
- {
- String link = lvi.getLink();
- LOG.debug("Checking web link:" + link);
-
- HttpClient cl = new HttpClient();
- HostConfiguration hc = new HostConfiguration();
-
- if (proxyHost != null)
- {
- hc.setProxy(proxyHost, proxyPort);
- }
- HttpState state = new HttpState();
-
- if (proxyUser != null && proxyPass != null)
- {
- state.setProxyCredentials(null, null, new UsernamePasswordCredentials(proxyUser, proxyPass));
- }
-
- cl.setHostConfiguration(hc);
- cl.setState(state);
-
- // execute the GET
- HeadMethod hm = checkLink(cl, link);
- StatusLine sl = hm.getStatusLine();
-
- if (sl == null) {
- LOG.info("Unknown error validating link : " + link);
- return LVR_INVALID;
- }
-
- if (hm.getStatusCode() == 302)
- {
- Header locationHeader = hm.getResponseHeader("Location");
- if (locationHeader == null) {
- LOG.info("Site sent redirect, but did not set Location header");
- } else {
- String newLink = locationHeader.getValue();
- LOG.debug("Following 1 redirect to " + newLink);
- hm = checkLink(cl, newLink);
- }
- }
-
- //FIXME: This constant is defined somewhere, but I can't remember where...
- if (hm.getStatusCode() == 200)
- {
- return LVR_VALID;
- }
- else
- {
- String msg = "Received: [" + hm.getStatusCode() + "] for " + link;
- LOG.info(msg);
- System.out.println(msg);
- return LVR_INVALID;
- }
-
- }
- catch (Exception e)
- {
- LOG.warn("Error accessing " + lvi.getLink(), e);
- e.printStackTrace();
- return LVR_INVALID;
- }
-
- }
-
- private HeadMethod checkLink(HttpClient cl, String link)
- {
- HeadMethod hm = new HeadMethod(link);
- try
- {
- LOG.info("Checking link " + link);
- hm.setFollowRedirects(true);
- cl.executeMethod(hm);
- LOG.debug("Checked link " + link);
- }
- catch (Exception e)
- {
- LOG.warn("Error validating " + link + ": " + e);
- LOG.debug("Exception was", e);
- }
- return hm;
- }
-
- /**
- * @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://"))
+ if ( !link.startsWith( "http://" ) && !link.startsWith( "https://" ) )
return null;
-
- int hashPos = link.indexOf("#");
- if (hashPos != -1)
- link = link.substring(0, hashPos);
-
+ int hashPos = link.indexOf( "#" );
+ if ( hashPos != -1 )
+ link = link.substring( 0, hashPos );
return link;
}
Copied: maven/maven-1/plugins/trunk/linkcheck/src/main/org/apache/maven/plugin/linkcheck/validation/LinkValidationItem.java (from r368923, maven/maven-1/plugins/trunk/linkcheck/src/main/org/apache/maven/linkcheck/validation/LinkValidationItem.java)
URL: http://svn.apache.org/viewcvs/maven/maven-1/plugins/trunk/linkcheck/src/main/org/apache/maven/plugin/linkcheck/validation/LinkValidationItem.java?p2=maven/maven-1/plugins/trunk/linkcheck/src/main/org/apache/maven/plugin/linkcheck/validation/LinkValidationItem.java&p1=maven/maven-1/plugins/trunk/linkcheck/src/main/org/apache/maven/linkcheck/validation/LinkValidationItem.java&r1=368923&r2=368935&rev=368935&view=diff
==============================================================================
--- maven/maven-1/plugins/trunk/linkcheck/src/main/org/apache/maven/linkcheck/validation/LinkValidationItem.java (original)
+++ maven/maven-1/plugins/trunk/linkcheck/src/main/org/apache/maven/plugin/linkcheck/validation/LinkValidationItem.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-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.
@@ -21,6 +21,7 @@
/**
* @author <a href="mailto:bwalding@apache.org">Ben Walding</a>
+ * @author <a href="mailto:aheritier@apache.org">Arnaud Heritier</a>
* @version $Id$
*/
public class LinkValidationItem {
@@ -41,6 +42,22 @@
}
/**
+ * Returns the link.
+ * @return String
+ */
+ public String getLink() {
+ return link;
+ }
+
+ /**
+ * Returns the source.
+ * @return File
+ */
+ public File getSource() {
+ return source;
+ }
+
+ /**
* @see java.lang.Object#equals(java.lang.Object)
*/
public boolean equals(Object obj) {
@@ -60,23 +77,6 @@
*/
public int hashCode() {
return source.hashCode() ^ link.hashCode();
- }
-
-
- /**
- * Returns the link.
- * @return String
- */
- public String getLink() {
- return link;
- }
-
- /**
- * Returns the source.
- * @return File
- */
- public File getSource() {
- return source;
}
}
Copied: maven/maven-1/plugins/trunk/linkcheck/src/main/org/apache/maven/plugin/linkcheck/validation/LinkValidationResult.java (from r368923, maven/maven-1/plugins/trunk/linkcheck/src/main/org/apache/maven/linkcheck/validation/LinkValidationResult.java)
URL: http://svn.apache.org/viewcvs/maven/maven-1/plugins/trunk/linkcheck/src/main/org/apache/maven/plugin/linkcheck/validation/LinkValidationResult.java?p2=maven/maven-1/plugins/trunk/linkcheck/src/main/org/apache/maven/plugin/linkcheck/validation/LinkValidationResult.java&p1=maven/maven-1/plugins/trunk/linkcheck/src/main/org/apache/maven/linkcheck/validation/LinkValidationResult.java&r1=368923&r2=368935&rev=368935&view=diff
==============================================================================
--- maven/maven-1/plugins/trunk/linkcheck/src/main/org/apache/maven/linkcheck/validation/LinkValidationResult.java (original)
+++ maven/maven-1/plugins/trunk/linkcheck/src/main/org/apache/maven/plugin/linkcheck/validation/LinkValidationResult.java Fri Jan 13 16:28:50 2006
@@ -1,7 +1,9 @@
-package org.apache.maven.linkcheck.validation;
+package org.apache.maven.plugin.linkcheck.validation;
+
+import java.io.Serializable;
/* ====================================================================
- * 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.
@@ -18,42 +20,69 @@
*/
/**
- * <b>This is an immutable class.</b><br/>
* <p>
* 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.
* </p>
* @author <a href="mailto:bwalding@apache.org">Ben Walding</a>
+ * @author <a href="mailto:aheritier@apache.org">Arnaud Heritier</a>
* @version $Id$
*/
-public class LinkValidationResult {
+public class LinkValidationResult
+ implements Serializable
+{
public static final int NOTMINE = 0;
- public static final int INVALID = 1;
- public static final int VALID = 2;
+
+ public static final int ERROR = 1;
+
+ public static final int VALID = 2;
+
public static final int UNKNOWN = 3;
-
+
+ public static final int WARNING = 4;
+
private final boolean persistent;
+
private final int status;
-
- public LinkValidationResult(int status, boolean persistent) {
- this.status = status;
- this.persistent = persistent;
- }
-
- public boolean isPersistent() {
+
+ private final String errorMessage;
+
+ public boolean isPersistent()
+ {
return persistent;
}
-
-
+
/**
* Returns the status.
* @return int
*/
- public int getStatus() {
+ public int getStatus()
+ {
return status;
}
-
+ /**
+ * @return Returns the errorMessage.
+ */
+ public String getErrorMessage()
+ {
+ return errorMessage;
+ }
+
+ public LinkValidationResult( int status, boolean persistent, String errorMessage )
+ {
+ this.status = status;
+ this.persistent = persistent;
+ this.errorMessage = errorMessage;
+ }
+
+ /* (non-Javadoc)
+ * @see java.lang.Object#toString()
+ */
+ public String toString()
+ {
+ return persistent + "/" + status + "/" + errorMessage;
+ }
}
Copied: maven/maven-1/plugins/trunk/linkcheck/src/main/org/apache/maven/plugin/linkcheck/validation/LinkValidator.java (from r368923, maven/maven-1/plugins/trunk/linkcheck/src/main/org/apache/maven/linkcheck/validation/LinkValidator.java)
URL: http://svn.apache.org/viewcvs/maven/maven-1/plugins/trunk/linkcheck/src/main/org/apache/maven/plugin/linkcheck/validation/LinkValidator.java?p2=maven/maven-1/plugins/trunk/linkcheck/src/main/org/apache/maven/plugin/linkcheck/validation/LinkValidator.java&p1=maven/maven-1/plugins/trunk/linkcheck/src/main/org/apache/maven/linkcheck/validation/LinkValidator.java&r1=368923&r2=368935&rev=368935&view=diff
==============================================================================
--- maven/maven-1/plugins/trunk/linkcheck/src/main/org/apache/maven/linkcheck/validation/LinkValidator.java (original)
+++ maven/maven-1/plugins/trunk/linkcheck/src/main/org/apache/maven/plugin/linkcheck/validation/LinkValidator.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-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,19 +19,21 @@
/**
* @author <a href="mailto:bwalding@apache.org">Ben Walding</a>
+ * @author <a href="mailto:aheritier@apache.org">Arnaud Heritier</a>
* @version $Id$
*/
-public interface LinkValidator {
-
+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.
@@ -39,5 +41,5 @@
* @return Object null if this validator should not be doing this work.
* @throws Exception
*/
- public Object getResourceKey(LinkValidationItem lvi);
+ public Object getResourceKey( LinkValidationItem lvi );
}
Copied: maven/maven-1/plugins/trunk/linkcheck/src/main/org/apache/maven/plugin/linkcheck/validation/LinkValidatorManager.java (from r368923, maven/maven-1/plugins/trunk/linkcheck/src/main/org/apache/maven/linkcheck/validation/LinkValidatorManager.java)
URL: http://svn.apache.org/viewcvs/maven/maven-1/plugins/trunk/linkcheck/src/main/org/apache/maven/plugin/linkcheck/validation/LinkValidatorManager.java?p2=maven/maven-1/plugins/trunk/linkcheck/src/main/org/apache/maven/plugin/linkcheck/validation/LinkValidatorManager.java&p1=maven/maven-1/plugins/trunk/linkcheck/src/main/org/apache/maven/linkcheck/validation/LinkValidatorManager.java&r1=368923&r2=368935&rev=368935&view=diff
==============================================================================
--- maven/maven-1/plugins/trunk/linkcheck/src/main/org/apache/maven/linkcheck/validation/LinkValidatorManager.java (original)
+++ maven/maven-1/plugins/trunk/linkcheck/src/main/org/apache/maven/plugin/linkcheck/validation/LinkValidatorManager.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-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.
@@ -16,17 +16,19 @@
* limitations under the License.
* ====================================================================
*/
-
-import java.io.BufferedInputStream;
-import java.io.BufferedOutputStream;
+
import java.io.File;
import java.io.FileInputStream;
-import java.io.FileNotFoundException;
import java.io.FileOutputStream;
-import java.io.IOException;
+import java.io.InvalidClassException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.io.Serializable;
+import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
+import java.util.Map;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -34,140 +36,218 @@
/**
* @author <a href="mailto:bwalding@apache.org">Ben Walding</a>
* @author <a href="mailto:carlos@apache.org">Carlos Sanchez</a>
+ * @author <a href="mailto:aheritier@apache.org">Arnaud Heritier</a>
* @version $Id$
*/
-public class LinkValidatorManager {
+public class LinkValidatorManager
+ implements Serializable
+{
/**
* Log for debug output
*/
- private static Log LOG = LogFactory.getLog(LinkValidatorManager.class);
+ private static Log LOG = LogFactory.getLog( LinkValidatorManager.class );
private List validators = new LinkedList();
- private LinkValidatorCache cache = new LinkValidatorCache(this);
+
private String[] excludes = new String[0];
- public LinkValidatorManager() {
+ private Map cache = new HashMap();
+ public LinkValidatorManager()
+ {
}
- public void addLinkValidator(LinkValidator lv) {
- validators.add(lv);
+ public List getValidators()
+ {
+ return validators;
}
- public List getValidators() {
- return validators;
+ /**
+ * Returns the exclude.
+ * @return String
+ * @deprecated use getExcludes()
+ */
+ public String getExclude()
+ {
+ return excludes[0];
}
- public LinkValidationResult validateLink(LinkValidationItem lvi)
- throws Exception {
+ /**
+ * Sets the exclude.
+ * @param exclude The exclude to set
+ * @deprecated use setExcludes()
+ */
+ public void setExclude( String exclude )
+ {
+ this.excludes = new String[] { exclude };
+ }
+
+ /**
+ * Returns the excludes.
+ * @return String[]
+ */
+ public String[] getExcludes()
+ {
+ return excludes;
+ }
+
+ /**
+ * Sets the excludes.
+ * @param excludes The excludes to set
+ */
+ public void setExcludes( String[] excludes )
+ {
+ this.excludes = excludes;
+ }
+
+ public void addLinkValidator( LinkValidator lv )
+ {
+ validators.add( lv );
+ }
+
+ public LinkValidationResult validateLink( LinkValidationItem lvi )
+ throws Exception
+ {
{
- LinkValidationResult status = cache.getCachedResult(lvi);
- if (status != null) {
+ LinkValidationResult status = getCachedResult( lvi );
+ if ( status != null )
+ {
return status;
}
}
- for (int i = 0; i < excludes.length; i++) {
- if (excludes[i] != null && lvi.getLink().startsWith(excludes[i])) {
- if (LOG.isDebugEnabled()) {
- LOG.debug("Excluded " + lvi.getLink());
+ for ( int i = 0; i < excludes.length; i++ )
+ {
+ if ( excludes[i] != null && lvi.getLink().startsWith( excludes[i] ) )
+ {
+ if ( LOG.isDebugEnabled() )
+ {
+ LOG.debug( "Excluded " + lvi.getLink() );
}
- return new LinkValidationResult(LinkValidationResult.VALID, false);
+ return new LinkValidationResult( LinkValidationResult.VALID, false, "" );
}
}
-
Iterator iter = validators.iterator();
- while (iter.hasNext()) {
- LinkValidator lv = (LinkValidator) iter.next();
-
- Object resourceKey = lv.getResourceKey(lvi);
-
- if (resourceKey != null) {
-
- LinkValidationResult lvr = lv.validateLink(lvi);
-
- if (lvr.getStatus() == LinkValidationResult.NOTMINE) {
+ LinkValidator lv;
+ Object resourceKey;
+ LinkValidationResult lvr;
+ while ( iter.hasNext() )
+ {
+ lv = (LinkValidator) iter.next();
+ resourceKey = lv.getResourceKey( lvi );
+ if ( resourceKey != null )
+ {
+ if ( LOG.isDebugEnabled() )
+ LOG.debug( lv.getClass().getName() + " - Checking link " + lvi.getLink() );
+ lvr = lv.validateLink( lvi );
+ if ( lvr.getStatus() == LinkValidationResult.NOTMINE )
+ {
continue;
}
-
- cache.setCachedResult(resourceKey, lvr);
+ setCachedResult( resourceKey, lvr );
return lvr;
-
}
-
}
-
- LOG.info("Unable to validate link : " + lvi.getLink());
- return new LinkValidationResult(LinkValidationResult.UNKNOWN, false);
+ lv = null;
+ resourceKey = null;
+ lvr = null;
+ LOG.error( "Unable to validate link : " + lvi.getLink() );
+ return new LinkValidationResult( LinkValidationResult.UNKNOWN, false, "No validator found for this link" );
}
- public void loadCache(String cacheFilename) {
- try {
- File f = new File(cacheFilename);
- if (f.exists()) {
- BufferedInputStream is = new BufferedInputStream(
- new FileInputStream(cacheFilename));
- this.cache.load(is);
+ public void loadCache( String cacheFilename )
+ {
+ try
+ {
+ File f = new File( cacheFilename );
+ if ( f.exists() )
+ {
+ ObjectInputStream is = new ObjectInputStream( new FileInputStream( cacheFilename ) );
+ this.cache = (Map) is.readObject();
is.close();
}
- } catch (FileNotFoundException e) {
- e.printStackTrace();
- } catch (IOException e) {
- e.printStackTrace();
+ }
+ catch ( InvalidClassException e )
+ {
+ LOG.warn( "Your cache is incompatible with this new release of the plugin. It will be recreated." );
+ }
+ catch ( Throwable t )
+ {
+ LOG.error( "Unable to load the cache", t );
}
}
- public void saveCache(String cacheFilename) {
- try {
- File cacheFile = new File(cacheFilename);
+ public void saveCache( String cacheFilename )
+ {
+ try
+ {
+ // Remove non-persistent items from cache
+ Map persistentCache = new HashMap();
+ Iterator iter = this.cache.keySet().iterator();
+ Object resourceKey;
+ while ( iter.hasNext() )
+ {
+ resourceKey = iter.next();
+ if ( ( (LinkValidationResult) cache.get( resourceKey ) ).isPersistent() )
+ {
+ persistentCache.put( resourceKey, cache.get( resourceKey ) );
+ if ( LOG.isDebugEnabled() )
+ LOG.debug( "[" + resourceKey + "] with result [" + cache.get( resourceKey )
+ + "] is stored in the cache." );
+ }
+ }
+ File cacheFile = new File( cacheFilename );
File dir = cacheFile.getParentFile();
- if (dir != null) {
+ if ( dir != null )
+ {
dir.mkdirs();
}
- BufferedOutputStream os = new BufferedOutputStream(
- new FileOutputStream(cacheFilename));
- this.cache.save(os);
+ ObjectOutputStream os = new ObjectOutputStream( new FileOutputStream( cacheFilename ) );
+ os.writeObject( persistentCache );
os.close();
- } catch (FileNotFoundException e) {
- e.printStackTrace();
- } catch (IOException e) {
- e.printStackTrace();
+ persistentCache = null;
+ iter = null;
+ resourceKey = null;
+ cacheFile = null;
+ dir = null;
+ os = null;
+ }
+ catch ( Throwable t )
+ {
+ LOG.error( "Unable to save the cache", t );
}
}
/**
- * Returns the exclude.
- * @return String
- * @deprecated use getExcludes()
- */
- public String getExclude() {
- return excludes[0];
- }
-
- /**
- * Sets the exclude.
- * @param exclude The exclude to set
- * @deprecated use setExcludes()
- */
- public void setExclude(String exclude) {
- this.excludes = new String[] {exclude};
- }
-
- /**
- * Returns the excludes.
- * @return String[]
+ *
+ * @param lvi
+ * @return int Will return a status level, VALID, ERROR, UNKNOWN, WARNING
*/
- public String[] getExcludes() {
- return excludes;
+ public LinkValidationResult getCachedResult( LinkValidationItem lvi )
+ {
+ Iterator iter = getValidators().iterator();
+ LinkValidator lv;
+ Object resourceKey;
+ while ( iter.hasNext() )
+ {
+ lv = (LinkValidator) iter.next();
+ resourceKey = lv.getResourceKey( lvi );
+ if ( resourceKey != null && cache.containsKey( resourceKey ) )
+ {
+ if ( LOG.isDebugEnabled() )
+ LOG.debug( "The cache returns for [" + resourceKey + "] the result [" + cache.get( resourceKey )
+ + "]." );
+ return (LinkValidationResult) cache.get( resourceKey );
+ }
+ }
+ lv = null;
+ resourceKey = null;
+ return null;
}
- /**
- * Sets the excludes.
- * @param excludes The excludes to set
- */
- public void setExcludes(String[] excludes) {
- this.excludes = excludes;
+ public void setCachedResult( Object resourceKey, LinkValidationResult lvr )
+ {
+ cache.put( resourceKey, lvr );
}
-
}
Copied: maven/maven-1/plugins/trunk/linkcheck/src/main/org/apache/maven/plugin/linkcheck/validation/MailtoLinkValidator.java (from r368923, maven/maven-1/plugins/trunk/linkcheck/src/main/org/apache/maven/linkcheck/validation/MailtoLinkValidator.java)
URL: http://svn.apache.org/viewcvs/maven/maven-1/plugins/trunk/linkcheck/src/main/org/apache/maven/plugin/linkcheck/validation/MailtoLinkValidator.java?p2=maven/maven-1/plugins/trunk/linkcheck/src/main/org/apache/maven/plugin/linkcheck/validation/MailtoLinkValidator.java&p1=maven/maven-1/plugins/trunk/linkcheck/src/main/org/apache/maven/linkcheck/validation/MailtoLinkValidator.java&r1=368923&r2=368935&rev=368935&view=diff
==============================================================================
--- maven/maven-1/plugins/trunk/linkcheck/src/main/org/apache/maven/linkcheck/validation/MailtoLinkValidator.java (original)
+++ maven/maven-1/plugins/trunk/linkcheck/src/main/org/apache/maven/plugin/linkcheck/validation/MailtoLinkValidator.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.
@@ -19,25 +19,34 @@
/**
* @author <a href="mailto:bwalding@apache.org">Ben Walding</a>
+ * @author <a href="mailto:aheritier@apache.org">Arnaud Heritier</a>
* @version $Id$
*
* Validates mailto links
*/
-public class MailtoLinkValidator implements LinkValidator {
- private static final LinkValidationResult LVR =
- new LinkValidationResult(LinkValidationResult.VALID, false);
+public final class MailtoLinkValidator
+ implements LinkValidator
+{
+ private static final LinkValidationResult LVR = new LinkValidationResult( LinkValidationResult.VALID, false, "" );
+
/**
- * @see org.apache.maven.linkcheck.validation.LinkValidator#validateLink(org.apache.maven.linkcheck.validation.LinkValidationItem)
+ * @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;
}
+
/**
- * @see org.apache.maven.linkcheck.validation.LinkValidator#getResourceKey(org.apache.maven.linkcheck.validation.LinkValidationItem)
+ * @see org.apache.maven.plugin.linkcheck.validation.LinkValidator#getResourceKey(org.apache.maven.plugin.linkcheck.validation.LinkValidationItem)
*/
- public Object getResourceKey(LinkValidationItem lvi) {
- return lvi.getLink();
+ public Object getResourceKey( LinkValidationItem lvi )
+ {
+ if ( lvi.getLink().indexOf( '@' ) != -1 )
+ return lvi.getLink();
+ else
+ return null;
}
}