From f841db11642f41952851cb89c5d3c693488dc92d Mon Sep 17 00:00:00 2001 From: aheritier Date: Sat, 14 Jan 2006 00:28:50 +0000 Subject: [PATCH] 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. git-svn-id: https://svn.apache.org/repos/asf/maven/maven-1/plugins/trunk@368935 13f79535-47bb-0310-9956-ffa450edef68 --- linkcheck/plugin.jelly | 47 ++- linkcheck/plugin.properties | 1 + linkcheck/project.properties | 9 + linkcheck/project.xml | 30 +- .../apache/maven/linkcheck/FileToCheck.java | 317 -------------- .../org/apache/maven/linkcheck/LinkCheck.java | 329 --------------- .../apache/maven/linkcheck/LinkCheckCli.java | 53 --- .../maven/linkcheck/LinkCheckResult.java | 84 ---- .../validation/FileLinkValidator.java | 79 ---- .../validation/HTTPLinkValidator.java | 183 --------- .../validation/LinkValidatorCache.java | 117 ------ .../validation/LinkValidatorManager.java | 173 -------- .../maven/plugin/linkcheck/FileToCheck.java | 327 +++++++++++++++ .../maven/plugin/linkcheck/LinkCheck.java | 385 ++++++++++++++++++ .../plugin/linkcheck/LinkCheckResult.java | 103 +++++ .../validation/FileLinkValidator.java | 77 ++++ .../validation/HTTPLinkValidator.java} | 35 +- .../validation/LinkValidationItem.java | 38 +- .../validation/LinkValidationResult.java | 65 ++- .../linkcheck/validation/LinkValidator.java | 18 +- .../validation/LinkValidatorManager.java | 253 ++++++++++++ .../validation/MailtoLinkValidator.java | 52 +++ .../validation/OfflineHTTPLinkValidator.java | 38 ++ .../validation/OnlineHTTPLinkValidator.java | 243 +++++++++++ .../images/icon_error_sml.gif | Bin 0 -> 1010 bytes .../images/icon_unknown_sml.gif | Bin 0 -> 1019 bytes .../images/icon_valid_sml.gif | Bin 0 -> 990 bytes .../images/icon_warning_sml.gif | Bin 0 -> 576 bytes .../src/plugin-resources/images/trans.gif | Bin 0 -> 43 bytes .../src/plugin-resources/linkcheck-temp.xml | 8 +- linkcheck/src/plugin-resources/linkcheck.jsl | 54 +-- linkcheck/src/plugin-test/maven.xml | 2 +- linkcheck/src/plugin-test/xdocs/test.html | 15 +- .../apache/maven/linkcheck/LinkCheckTest.java | 97 ----- .../validation/HTTPLinkValidatorTest.java | 47 --- .../maven/plugin/linkcheck/LinkCheckTest.java | 97 +++++ .../validation/HTTPLinkValidatorTest.java | 67 +++ linkcheck/xdocs/changes.xml | 6 + 38 files changed, 1849 insertions(+), 1600 deletions(-) delete mode 100644 linkcheck/src/main/org/apache/maven/linkcheck/FileToCheck.java delete mode 100644 linkcheck/src/main/org/apache/maven/linkcheck/LinkCheck.java delete mode 100644 linkcheck/src/main/org/apache/maven/linkcheck/LinkCheckCli.java delete mode 100644 linkcheck/src/main/org/apache/maven/linkcheck/LinkCheckResult.java delete mode 100644 linkcheck/src/main/org/apache/maven/linkcheck/validation/FileLinkValidator.java delete mode 100644 linkcheck/src/main/org/apache/maven/linkcheck/validation/HTTPLinkValidator.java delete mode 100644 linkcheck/src/main/org/apache/maven/linkcheck/validation/LinkValidatorCache.java delete mode 100644 linkcheck/src/main/org/apache/maven/linkcheck/validation/LinkValidatorManager.java create mode 100644 linkcheck/src/main/org/apache/maven/plugin/linkcheck/FileToCheck.java create mode 100644 linkcheck/src/main/org/apache/maven/plugin/linkcheck/LinkCheck.java create mode 100644 linkcheck/src/main/org/apache/maven/plugin/linkcheck/LinkCheckResult.java create mode 100644 linkcheck/src/main/org/apache/maven/plugin/linkcheck/validation/FileLinkValidator.java rename linkcheck/src/main/org/apache/maven/{linkcheck/validation/MailtoLinkValidator.java => plugin/linkcheck/validation/HTTPLinkValidator.java} (50%) rename linkcheck/src/main/org/apache/maven/{ => plugin}/linkcheck/validation/LinkValidationItem.java (91%) rename linkcheck/src/main/org/apache/maven/{ => plugin}/linkcheck/validation/LinkValidationResult.java (58%) rename linkcheck/src/main/org/apache/maven/{ => plugin}/linkcheck/validation/LinkValidator.java (77%) create mode 100644 linkcheck/src/main/org/apache/maven/plugin/linkcheck/validation/LinkValidatorManager.java create mode 100644 linkcheck/src/main/org/apache/maven/plugin/linkcheck/validation/MailtoLinkValidator.java create mode 100644 linkcheck/src/main/org/apache/maven/plugin/linkcheck/validation/OfflineHTTPLinkValidator.java create mode 100644 linkcheck/src/main/org/apache/maven/plugin/linkcheck/validation/OnlineHTTPLinkValidator.java create mode 100644 linkcheck/src/plugin-resources/images/icon_error_sml.gif create mode 100644 linkcheck/src/plugin-resources/images/icon_unknown_sml.gif create mode 100644 linkcheck/src/plugin-resources/images/icon_valid_sml.gif create mode 100644 linkcheck/src/plugin-resources/images/icon_warning_sml.gif create mode 100644 linkcheck/src/plugin-resources/images/trans.gif delete mode 100644 linkcheck/src/test/org/apache/maven/linkcheck/LinkCheckTest.java delete mode 100644 linkcheck/src/test/org/apache/maven/linkcheck/validation/HTTPLinkValidatorTest.java create mode 100644 linkcheck/src/test/org/apache/maven/plugin/linkcheck/LinkCheckTest.java create mode 100644 linkcheck/src/test/org/apache/maven/plugin/linkcheck/validation/HTTPLinkValidatorTest.java diff --git a/linkcheck/plugin.jelly b/linkcheck/plugin.jelly index add250ca..2e8c5734 100644 --- a/linkcheck/plugin.jelly +++ b/linkcheck/plugin.jelly @@ -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"> + org.apache.maven.plugin.linkcheck.Jelly + + LinkCheck report registred. + LinkCheck report unregistred. + LinkCheck taglib defined. @@ -56,28 +63,22 @@ --> - + + Fake LinkCheck report copied. + + + ${maven.mode.online} + + + + - - - - ${maven.mode.online} - - - - - - - - - - - + Begin to generate the linkcheck report. @@ -108,15 +109,21 @@ outputMode="xml" prettyPrint="true" /> - + + + + + + + + Cache cleared. - diff --git a/linkcheck/plugin.properties b/linkcheck/plugin.properties index 1b53180e..dcb6dfa9 100644 --- a/linkcheck/plugin.properties +++ b/linkcheck/plugin.properties @@ -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 diff --git a/linkcheck/project.properties b/linkcheck/project.properties index 4833d7d2..5bd71751 100644 --- a/linkcheck/project.properties +++ b/linkcheck/project.properties @@ -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 diff --git a/linkcheck/project.xml b/linkcheck/project.xml index c47530b3..18ae664d 100644 --- a/linkcheck/project.xml +++ b/linkcheck/project.xml @@ -1,5 +1,4 @@ - - - + ../plugin-parent/project.xml 3 maven-linkcheck-plugin @@ -77,6 +74,15 @@ Java Developer + + Arnaud Heritier + aheritier + aheritier@apache.org + Octo Technology + + Java Developer + + Carlos Sanchez carlos @@ -111,7 +117,16 @@ commons-httpclient commons-httpclient - 2.0.2 + 3.0 + + This library is already loaded by maven's core. Be careful to use the same version number as in the core. + + + + commons-codec + commons-codec + 1.2 + http://jakarta.apache.org/commons/codec/ This library is already loaded by maven's core. Be careful to use the same version number as in the core. @@ -137,6 +152,11 @@ commons-jelly-tags-jsl 1.0 + + commons-jelly + commons-jelly-tags-log + 1.0 + commons-jelly commons-jelly-tags-xml diff --git a/linkcheck/src/main/org/apache/maven/linkcheck/FileToCheck.java b/linkcheck/src/main/org/apache/maven/linkcheck/FileToCheck.java deleted file mode 100644 index dd95dc04..00000000 --- a/linkcheck/src/main/org/apache/maven/linkcheck/FileToCheck.java +++ /dev/null @@ -1,317 +0,0 @@ -package org.apache.maven.linkcheck; - -/* ==================================================================== - * Copyright 2001-2004 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. - * ==================================================================== - */ - -import java.io.BufferedInputStream; -import java.io.ByteArrayOutputStream; -import java.io.File; -import java.io.FileInputStream; -import java.io.FileNotFoundException; -import java.io.InputStream; -import java.io.OutputStream; -import java.io.PrintWriter; -import java.util.Iterator; -import java.util.LinkedList; -import java.util.List; -import java.util.Set; -import java.util.TreeSet; - -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.dom4j.Document; -import org.dom4j.Node; -import org.dom4j.io.DOMReader; -import org.w3c.tidy.Tidy; - -/** - * @author Ben Walding - * @version $Id$ - */ -public class FileToCheck -{ - /** - * Log for debug output - */ - private static Log LOG = LogFactory.getLog(FileToCheck.class); - - private String base; - private File fileToCheck; - private String status = STATUS_OK; - private String message = ""; - 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"; - - public FileToCheck(File baseFile, File fileToCheck) - { - this.base = baseFile.getAbsolutePath(); - this.fileToCheck = fileToCheck; - - } - - private void addResult(LinkCheckResult lcr) - { - this.links.add(lcr); - } - - public void check(LinkValidatorManager lvm) throws Exception - { - successful = 0; - unsuccessful = 0; - status = STATUS_OK; - message = ""; - - try - { - final Set hrefs; - try - { - hrefs = getLinks(); - } - catch (Throwable e) - { - //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()); - LinkCheckResult lcr = new LinkCheckResult(); - lcr.setStatus("PARSE FAILURE"); - lcr.setTarget("N/A"); - addResult(lcr); - return; - } - - 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()) - { - 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 - break; - case LinkValidationResult.UNKNOWN : - unsuccessful++; - lcr.setStatus("UNKNOWN REF"); - addResult(lcr); - break; - case LinkValidationResult.INVALID : - unsuccessful++; - lcr.setStatus("NOT FOUND"); - addResult(lcr); - break; - } - - } - } - catch (Exception e) - { - System.err.println(message); - throw (e); - } - } - - 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); - 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 - { - close(bin); - close(baos); - } - } - - private void close(InputStream is) - { - try - { - is.close(); - } - catch (Exception e) - { - //Don't really care. - } - } - - private void close(OutputStream os) - { - try - { - os.close(); - } - catch (Exception e) - { - //Don't really care. - } - } - - 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("//link/@href")); - - //