From fa5ca2bd704226e634bdbcfc9b43fb377af55d64 Mon Sep 17 00:00:00 2001 From: bwalding Date: Thu, 30 Jan 2003 10:59:36 +0000 Subject: [PATCH] MAVEN-214: LinkChecker plugin git-svn-id: https://svn.apache.org/repos/asf/maven/maven-1/plugins/trunk@112777 13f79535-47bb-0310-9956-ffa450edef68 --- linkcheck/.cvsignore | 3 + linkcheck/maven.xml | 18 ++ linkcheck/plugin.jelly | 82 +++++ linkcheck/plugin.properties | 16 + linkcheck/project.properties | 5 + linkcheck/project.xml | 106 +++++++ .../maven/linkcheck/FileToCheck.betwixt | 10 + .../apache/maven/linkcheck/FileToCheck.java | 225 ++++++++++++++ .../apache/maven/linkcheck/LinkCheck.betwixt | 7 + .../org/apache/maven/linkcheck/LinkCheck.java | 288 ++++++++++++++++++ .../maven/linkcheck/LinkCheckResult.betwixt | 8 + .../maven/linkcheck/LinkCheckResult.java | 102 +++++++ .../org/apache/maven/linkcheck/linkcheck.xml | 7 + .../validation/FileLinkValidator.java | 55 ++++ .../validation/HTTPLinkValidator.java | 69 +++++ .../validation/LinkValidationItem.java | 80 +++++ .../validation/LinkValidationResult.java | 42 +++ .../linkcheck/validation/LinkValidator.java | 28 ++ .../validation/LinkValidatorCache.java | 156 ++++++++++ .../validation/LinkValidatorManager.java | 169 ++++++++++ .../validation/MailtoLinkValidator.java | 24 ++ .../validation/ValidationResult.java | 9 + .../src/plugin-resources/linkcheck-temp.xml | 15 + linkcheck/src/plugin-resources/linkcheck.jsl | 52 ++++ linkcheck/src/test-resources/nolink.html | 7 + .../test-resources/test-resources/nolink.html | 6 + .../test-resources/test1/test1.html | 0 .../test-resources/test1/test2.html | 0 linkcheck/src/test-resources/test1/test1.html | 0 linkcheck/src/test-resources/testA.html | 5 + .../apache/maven/linkcheck/LinkCheckTest.java | 95 ++++++ linkcheck/xdocs/.cvsignore | 1 + linkcheck/xdocs/goals.xml | 20 ++ linkcheck/xdocs/index.xml | 29 ++ linkcheck/xdocs/navigation.xml | 17 ++ linkcheck/xdocs/properties.xml | 83 +++++ 36 files changed, 1839 insertions(+) create mode 100644 linkcheck/.cvsignore create mode 100644 linkcheck/maven.xml create mode 100644 linkcheck/plugin.jelly create mode 100644 linkcheck/plugin.properties create mode 100644 linkcheck/project.properties create mode 100644 linkcheck/project.xml create mode 100644 linkcheck/src/main/org/apache/maven/linkcheck/FileToCheck.betwixt create mode 100644 linkcheck/src/main/org/apache/maven/linkcheck/FileToCheck.java create mode 100644 linkcheck/src/main/org/apache/maven/linkcheck/LinkCheck.betwixt create mode 100644 linkcheck/src/main/org/apache/maven/linkcheck/LinkCheck.java create mode 100644 linkcheck/src/main/org/apache/maven/linkcheck/LinkCheckResult.betwixt create mode 100644 linkcheck/src/main/org/apache/maven/linkcheck/LinkCheckResult.java create mode 100644 linkcheck/src/main/org/apache/maven/linkcheck/linkcheck.xml create mode 100644 linkcheck/src/main/org/apache/maven/linkcheck/validation/FileLinkValidator.java create mode 100644 linkcheck/src/main/org/apache/maven/linkcheck/validation/HTTPLinkValidator.java create mode 100644 linkcheck/src/main/org/apache/maven/linkcheck/validation/LinkValidationItem.java create mode 100644 linkcheck/src/main/org/apache/maven/linkcheck/validation/LinkValidationResult.java create mode 100644 linkcheck/src/main/org/apache/maven/linkcheck/validation/LinkValidator.java create mode 100644 linkcheck/src/main/org/apache/maven/linkcheck/validation/LinkValidatorCache.java create mode 100644 linkcheck/src/main/org/apache/maven/linkcheck/validation/LinkValidatorManager.java create mode 100644 linkcheck/src/main/org/apache/maven/linkcheck/validation/MailtoLinkValidator.java create mode 100644 linkcheck/src/main/org/apache/maven/linkcheck/validation/ValidationResult.java create mode 100644 linkcheck/src/plugin-resources/linkcheck-temp.xml create mode 100644 linkcheck/src/plugin-resources/linkcheck.jsl create mode 100644 linkcheck/src/test-resources/nolink.html create mode 100644 linkcheck/src/test-resources/test-resources/nolink.html create mode 100644 linkcheck/src/test-resources/test-resources/test1/test1.html create mode 100644 linkcheck/src/test-resources/test-resources/test1/test2.html create mode 100644 linkcheck/src/test-resources/test1/test1.html create mode 100644 linkcheck/src/test-resources/testA.html create mode 100644 linkcheck/src/test/org/apache/maven/linkcheck/LinkCheckTest.java create mode 100644 linkcheck/xdocs/.cvsignore create mode 100644 linkcheck/xdocs/goals.xml create mode 100644 linkcheck/xdocs/index.xml create mode 100644 linkcheck/xdocs/navigation.xml create mode 100644 linkcheck/xdocs/properties.xml diff --git a/linkcheck/.cvsignore b/linkcheck/.cvsignore new file mode 100644 index 00000000..e5e33942 --- /dev/null +++ b/linkcheck/.cvsignore @@ -0,0 +1,3 @@ +target +velocity.log +maven.log diff --git a/linkcheck/maven.xml b/linkcheck/maven.xml new file mode 100644 index 00000000..02a7408f --- /dev/null +++ b/linkcheck/maven.xml @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + diff --git a/linkcheck/plugin.jelly b/linkcheck/plugin.jelly new file mode 100644 index 00000000..7d1d3497 --- /dev/null +++ b/linkcheck/plugin.jelly @@ -0,0 +1,82 @@ + + + + + + + + + + + + + + + + + + + + + This run of linkcheck does nothing except create a template linkcheck file + + + + + + + + + BaseDir: ${basedir} + + + + + Generating the LinkCheck report + + + + + + maven.xdoc.src: ${maven.xdoc.src} + + + + LinkCheck not enabled as maven.linkcheck.enable is not defined. + + + + + + + + + + + diff --git a/linkcheck/plugin.properties b/linkcheck/plugin.properties new file mode 100644 index 00000000..972ba324 --- /dev/null +++ b/linkcheck/plugin.properties @@ -0,0 +1,16 @@ +# ------------------------------------------------------------------- +# P L U G I N P R O P E R I E S +# ------------------------------------------------------------------- +# LinkCheck report plugin. +# ------------------------------------------------------------------- + +maven.build.dir = ${basedir}/target + + +maven.linkcheck.cache=${maven.build.dir}/linkcheck/linkcheck.cache + + + + +maven.docs.dest = ${maven.build.dir}/docs +maven.docs.outputencoding = ISO-8859-1 diff --git a/linkcheck/project.properties b/linkcheck/project.properties new file mode 100644 index 00000000..5e723259 --- /dev/null +++ b/linkcheck/project.properties @@ -0,0 +1,5 @@ +# ------------------------------------------------------------------- +# P R O J E C T P R O P E R T I E S +# ------------------------------------------------------------------- +maven.xdoc.date=left +maven.xdoc.version=${pom.currentVersion} \ No newline at end of file diff --git a/linkcheck/project.xml b/linkcheck/project.xml new file mode 100644 index 00000000..37af1ba5 --- /dev/null +++ b/linkcheck/project.xml @@ -0,0 +1,106 @@ + + + + ${basedir}/../project.xml + 3 + maven-linkcheck-plugin + Maven LinkCheck Plug-in + 1.0 + + + + + Java Project Management Tools + + http://jakarta.apache.org/turbine/maven/reference/plugins/linkcheck/ + http://jira.werken.com/BrowseProject.jspa?id=10030 + jakarta.apache.org + /www/jakarta.apache.org/turbine/maven/reference/plugins/linkcheck/ + /www/jakarta.apache.org/builds/jakarta-turbine-maven/ + + + + + + + + commons-betwixt + 1.0-beta-1 + + root.maven + + + + + commons-collections + 2.1 + + root.maven + + + + + commons-digester + 1.3 + + root.maven + + + + + commons-jelly+tags-jsl + SNAPSHOT + + root.maven + + + + + commons-jelly + commons-jelly-tags-xml + SNAPSHOT + http://jakarta.apache.org/commons/sandbox/jelly/tags/xml/ + + root.maven + + + + + commons-logging + 1.0 + + root.maven + + + + + httpunit + 1.5.1 + + root.maven + + + + + jtidy + 4aug2000r7-dev + + root.maven + + + + + + + + + + + diff --git a/linkcheck/src/main/org/apache/maven/linkcheck/FileToCheck.betwixt b/linkcheck/src/main/org/apache/maven/linkcheck/FileToCheck.betwixt new file mode 100644 index 00000000..bb4d9e7a --- /dev/null +++ b/linkcheck/src/main/org/apache/maven/linkcheck/FileToCheck.betwixt @@ -0,0 +1,10 @@ + + + + + + + + + + \ No newline at end of file diff --git a/linkcheck/src/main/org/apache/maven/linkcheck/FileToCheck.java b/linkcheck/src/main/org/apache/maven/linkcheck/FileToCheck.java new file mode 100644 index 00000000..cae7cf7c --- /dev/null +++ b/linkcheck/src/main/org/apache/maven/linkcheck/FileToCheck.java @@ -0,0 +1,225 @@ +package org.apache.maven.linkcheck; + +/* ==================================================================== + * The Apache Software License, Version 1.1 + * + * Copyright (c) 2002 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, + * if any, must include the following acknowledgment: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, + * if and wherever such third-party acknowledgments normally appear. + * + * 4. The names "Apache" and "Apache Software Foundation" and + * "Apache Maven" must not be used to endorse or promote products + * derived from this software without prior written permission. For + * written permission, please contact apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", + * "Apache Maven", nor may "Apache" appear in their name, without + * prior written permission of the Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + * + * ==================================================================== + */ + +import java.io.File; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; + +import org.apache.maven.linkcheck.validation.LinkValidationItem; +import org.apache.maven.linkcheck.validation.LinkValidationResult; +import org.apache.maven.linkcheck.validation.LinkValidatorManager; + +import com.meterware.httpunit.GetMethodWebRequest; +import com.meterware.httpunit.WebConversation; +import com.meterware.httpunit.WebLink; +import com.meterware.httpunit.WebRequest; +import com.meterware.httpunit.WebResponse; + +/** + * @author Ben Walding + * + */ +public class FileToCheck { + private File base; + private File f; + private String status = STATUS_OK; + private String message = ""; + private LinkCheck linkcheck; + private int successful; + private int unsuccessful; + + 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 base, File f) { + this.base = base; + this.f = f; + } + + private List links = new ArrayList(); + + public void check(LinkValidatorManager lvm) throws Exception { + successful = 0; + unsuccessful = 0; + status = STATUS_OK; + message = ""; + + try { + WebConversation wc = new WebConversation(); + WebRequest req = new GetMethodWebRequest(f.toURL().toString()); + WebResponse resp = wc.getResponse(req); + WebLink[] wl = resp.getLinks(); + Map uniqueLinks = new HashMap(); + for (int i = 0; + i < wl.length; + i++) { //It puts the current URL in item 0 + WebLink link = wl[i]; + String href = + link + .getDOMSubtree() + .getAttributes() + .getNamedItem("href") + .getNodeValue(); + + uniqueLinks.put(href, href); + } + + Iterator iter = uniqueLinks.keySet().iterator(); + while (iter.hasNext()) { + String href = (String) iter.next(); + + //System.out.println("Link Found: " + href); + + LinkCheckResult lcr = new LinkCheckResult(); + + LinkValidationItem lvi = new LinkValidationItem(f, href); + LinkValidationResult result = lvm.validateLink(lvi); + lcr.setTarget(href); + + switch (result.getStatus()) { + case LinkValidationResult.UNKNOWN : + unsuccessful++; + lcr.setStatus("UNKNOWN REF"); + break; + case LinkValidationResult.VALID : + successful++; + lcr.setStatus("OK"); + break; + case LinkValidationResult.INVALID : + unsuccessful++; + lcr.setStatus("NOT FOUND"); + break; + } + + //FIXME: needs expanding and caching for remote links + + links.add(lcr); + } + } catch (Exception e) { + message = e.toString(); + System.err.println(e.toString()); + throw (e); + + } + } + + /** + * 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; + } + + /** + * Sets the status. + * @param status The status to set + */ + public void setStatus(String status) { + this.status = status; + } + + 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 baseName = base.getAbsolutePath(); + String fileName = f.getAbsolutePath(); + if (fileName.startsWith(baseName)) + fileName = fileName.substring(baseName.length() + 1); + return fileName; + } + +} diff --git a/linkcheck/src/main/org/apache/maven/linkcheck/LinkCheck.betwixt b/linkcheck/src/main/org/apache/maven/linkcheck/LinkCheck.betwixt new file mode 100644 index 00000000..9123b71e --- /dev/null +++ b/linkcheck/src/main/org/apache/maven/linkcheck/LinkCheck.betwixt @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/linkcheck/src/main/org/apache/maven/linkcheck/LinkCheck.java b/linkcheck/src/main/org/apache/maven/linkcheck/LinkCheck.java new file mode 100644 index 00000000..f82ea462 --- /dev/null +++ b/linkcheck/src/main/org/apache/maven/linkcheck/LinkCheck.java @@ -0,0 +1,288 @@ +package org.apache.maven.linkcheck; + +/* ==================================================================== + * The Apache Software License, Version 1.1 + * + * Copyright (c) 2002 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, + * if any, must include the following acknowledgment: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, + * if and wherever such third-party acknowledgments normally appear. + * + * 4. The names "Apache" and "Apache Software Foundation" and + * "Apache Maven" must not be used to endorse or promote products + * derived from this software without prior written permission. For + * written permission, please contact apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", + * "Apache Maven", nor may "Apache" appear in their name, without + * prior written permission of the Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + * + * ==================================================================== + */ + +// java imports +import java.io.File; +import java.io.FileOutputStream; +import java.io.FilenameFilter; +import java.io.OutputStreamWriter; +import java.io.PrintWriter; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + +import org.apache.commons.betwixt.io.BeanWriter; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +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; + +/** + * Change log task. It uses a ChangeLogGenerator and ChangeLogParser to create + * a Collection of ChangeLogEntry objects, which are used to produce an XML + * output that represents the list of changes. + * + * @author Ben Walding + * @version $Id: LinkCheck.java,v 1.1 2003/01/30 10:58:08 bwalding Exp $ + */ +public class LinkCheck { + /** Log */ + private static final Log LOG = LogFactory.getLog(LinkCheck.class); + + /** + * Output file for xml document + */ + private File output; + + /** output encoding for the xml document */ + private String outputEncoding; + + private File baseDir; + private String cache; + private String exclude; + + /** + * Set the base directory for the change log generator. + * @param base the base directory + */ + public void setBasedir(File base) { + this.baseDir = base; + } + + /** + * Get the base directory for the change log generator. + * + * @return the base directory + */ + public File getBasedir() { + return baseDir; + } + + /** + * Set the output file for the log. + * @param output the output file + */ + public void setOutput(File output) { + this.output = output; + } + + /** + * 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 + */ + List filesToCheck = null; //of FileToCheck + public void doExecute() + throws Exception { + if (output == null) { + throw new NullPointerException("output must be set"); + } + LinkValidatorManager lvm = getLinkValidatorManager(); + + filesToCheck = new ArrayList(); + lvm.loadCache(cache); + List files = new ArrayList(); + findFiles(files, baseDir); + Iterator fileIter = files.iterator(); + while (fileIter.hasNext()) { + FileToCheck flc = (FileToCheck) fileIter.next(); + try { + filesToCheck.add(flc); + flc.check(lvm); + } catch (Exception e) { + e.printStackTrace(); + } + } + + createDocument(files); + lvm.saveCache(cache); + } + + public List getFiles() { + LOG.info("About to write " + filesToCheck.size() + " file entries"); + return filesToCheck; + } + + public void findFiles(List allFiles, File base) { + FilenameFilter ff = new 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; + } + }; + + File[] f = base.listFiles(ff); + + if (f != null) { + for (int i = 0; i < f.length; i++) { + File file = f[i]; + if (file.isDirectory()) { + findFiles(allFiles, file); + } else { + allFiles.add(new FileToCheck(baseDir, file)); + } + } + } + } + + /** + * 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 + */ + private void createDocument(List files) throws Exception { + PrintWriter out = + new PrintWriter( + new OutputStreamWriter( + new FileOutputStream(output), + getOutputEncoding())); + StringBuffer buffer = new StringBuffer(); + buffer + .append("\n"); + + + BeanWriter bw = new BeanWriter(out); + bw.writeXmlDeclaration(buffer.toString()); + bw.setWriteIDs(false); + bw.enablePrettyPrint(); + bw.write(this); + out.close(); + } + + + + /** + * Returns the outputEncoding. + * @return String + */ + public String getOutputEncoding() { + return outputEncoding; + } + + /** + * Sets the outputEncoding. + * @param outputEncoding The outputEncoding to set + */ + public void setOutputEncoding(String outputEncoding) { + this.outputEncoding = outputEncoding; + } + + + LinkValidatorManager lvm = null; + public LinkValidatorManager getLinkValidatorManager() { + if (lvm == null) { + lvm = new LinkValidatorManager(); + lvm.setExclude(exclude); + lvm.addLinkValidator(new FileLinkValidator()); + lvm.addLinkValidator(new HTTPLinkValidator()); + lvm.addLinkValidator(new MailtoLinkValidator()); + lvm.loadCache(cache); + } + return lvm; + } + + /** + * Returns the cacheFile. + * @return String + */ + public String getCache() { + return cache; + } + + /** + * Sets the cacheFile. + * @param cacheFile The cacheFile to set + */ + public void setCache(String cache) { + this.cache = cache; + } + + /** + * Returns the exclude. + * @return String + */ + public String getExclude() { + return exclude; + } + + /** + * Sets the exclude. + * @param exclude The exclude to set + */ + public void setExclude(String exclude) { + this.exclude = exclude; + } + +} \ No newline at end of file diff --git a/linkcheck/src/main/org/apache/maven/linkcheck/LinkCheckResult.betwixt b/linkcheck/src/main/org/apache/maven/linkcheck/LinkCheckResult.betwixt new file mode 100644 index 00000000..b07048b8 --- /dev/null +++ b/linkcheck/src/main/org/apache/maven/linkcheck/LinkCheckResult.betwixt @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/linkcheck/src/main/org/apache/maven/linkcheck/LinkCheckResult.java b/linkcheck/src/main/org/apache/maven/linkcheck/LinkCheckResult.java new file mode 100644 index 00000000..b2d073e8 --- /dev/null +++ b/linkcheck/src/main/org/apache/maven/linkcheck/LinkCheckResult.java @@ -0,0 +1,102 @@ +package org.apache.maven.linkcheck; + +/* ==================================================================== + * The Apache Software License, Version 1.1 + * + * Copyright (c) 2002 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, + * if any, must include the following acknowledgment: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, + * if and wherever such third-party acknowledgments normally appear. + * + * 4. The names "Apache" and "Apache Software Foundation" and + * "Apache Maven" must not be used to endorse or promote products + * derived from this software without prior written permission. For + * written permission, please contact apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", + * "Apache Maven", nor may "Apache" appear in their name, without + * prior written permission of the Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + * + * ==================================================================== + */ + + +/** + * @author Ben Walding + * + */ +public class LinkCheckResult { + 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; + } + +} diff --git a/linkcheck/src/main/org/apache/maven/linkcheck/linkcheck.xml b/linkcheck/src/main/org/apache/maven/linkcheck/linkcheck.xml new file mode 100644 index 00000000..2dd9a342 --- /dev/null +++ b/linkcheck/src/main/org/apache/maven/linkcheck/linkcheck.xml @@ -0,0 +1,7 @@ + + + + + \ No newline at end of file diff --git a/linkcheck/src/main/org/apache/maven/linkcheck/validation/FileLinkValidator.java b/linkcheck/src/main/org/apache/maven/linkcheck/validation/FileLinkValidator.java new file mode 100644 index 00000000..dc76174a --- /dev/null +++ b/linkcheck/src/main/org/apache/maven/linkcheck/validation/FileLinkValidator.java @@ -0,0 +1,55 @@ +package org.apache.maven.linkcheck.validation; + +import java.io.File; + +/** + * @author Ben Walding + * + */ +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); + + /** + * @see org.apache.maven.linkcheck.LinkValidator#validateLink(org.apache.maven.linkcheck.LinkValidationItem) + */ + public LinkValidationResult validateLink(LinkValidationItem lvi) { + File f = getFile(lvi); + + if (f.exists()) + return LVR_VALID; + else + return LVR_INVALID; + } + + protected File getFile(LinkValidationItem lvi) { + String link = lvi.getLink(); + 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) + return lvi.getSource(); + } + + 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(); + } + +} diff --git a/linkcheck/src/main/org/apache/maven/linkcheck/validation/HTTPLinkValidator.java b/linkcheck/src/main/org/apache/maven/linkcheck/validation/HTTPLinkValidator.java new file mode 100644 index 00000000..da25706c --- /dev/null +++ b/linkcheck/src/main/org/apache/maven/linkcheck/validation/HTTPLinkValidator.java @@ -0,0 +1,69 @@ +package org.apache.maven.linkcheck.validation; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import com.meterware.httpunit.GetMethodWebRequest; +import com.meterware.httpunit.WebConversation; +import com.meterware.httpunit.WebRequest; +import com.meterware.httpunit.WebResponse; + +/** + * @author Ben Walding + * + */ +public class HTTPLinkValidator implements LinkValidator { + /** + * Log for debug output + */ + private static Log LOG = LogFactory.getLog(HTTPLinkValidator.class); + + private final static LinkValidationResult LVR_INVALID = + new LinkValidationResult(LinkValidationResult.INVALID, true); + + private final static LinkValidationResult LVR_VALID = + new LinkValidationResult(LinkValidationResult.VALID, true); + + /** + * @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); + WebConversation wc = new WebConversation(); + wc.setExceptionsThrownOnErrorStatus(false); + WebRequest req = new GetMethodWebRequest(link); + WebResponse resp = wc.getResponse(req); + + //FIXME: This constant is defined somewhere, but I can't remember where... + if (resp.getResponseCode() == 200) { + return LVR_VALID; + } else { + return LVR_INVALID; + } + } catch (Exception e) { + LOG.warn("Error accessing " + lvi.getLink(), e); + e.printStackTrace(); + return LVR_INVALID; + } + + } + + /** + * @see org.apache.maven.linkcheck.LinkValidator#getResourceKey(org.apache.maven.linkcheck.LinkValidationItem) + */ + public Object getResourceKey(LinkValidationItem lvi) { + String link = lvi.getLink(); + + if (!link.startsWith("http://")) + return null; + + int hashPos = link.indexOf("#"); + if (hashPos != -1) + link = link.substring(0, hashPos); + + return link; + } + +} diff --git a/linkcheck/src/main/org/apache/maven/linkcheck/validation/LinkValidationItem.java b/linkcheck/src/main/org/apache/maven/linkcheck/validation/LinkValidationItem.java new file mode 100644 index 00000000..d0359adf --- /dev/null +++ b/linkcheck/src/main/org/apache/maven/linkcheck/validation/LinkValidationItem.java @@ -0,0 +1,80 @@ +package org.apache.maven.linkcheck.validation; +import java.io.File; + +/** + * @author Ben Walding + * + */ +public class LinkValidationItem { + private File source; + private String link; + + public LinkValidationItem(File source, String link) { + if (source == null) { + throw new NullPointerException("source can't be null"); + } + + if (link == null) { + throw new NullPointerException("link can't be null"); + } + + this.source = source; + this.link = link; + } + + /** + * @see java.lang.Object#equals(java.lang.Object) + */ + public boolean equals(Object obj) { + LinkValidationItem lvi = (LinkValidationItem) obj; + + if (!lvi.link.equals(link)) + return false; + + if (!lvi.source.equals(source)) + return false; + return true; + } + + /** + * @see java.lang.Object#hashCode() + */ + 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; + } + + /** + * Sets the link. + * @param link The link to set + */ + public void setLink(String link) { + this.link = link; + } + + /** + * Sets the source. + * @param source The source to set + */ + public void setSource(File source) { + this.source = source; + } + + +} diff --git a/linkcheck/src/main/org/apache/maven/linkcheck/validation/LinkValidationResult.java b/linkcheck/src/main/org/apache/maven/linkcheck/validation/LinkValidationResult.java new file mode 100644 index 00000000..59647a76 --- /dev/null +++ b/linkcheck/src/main/org/apache/maven/linkcheck/validation/LinkValidationResult.java @@ -0,0 +1,42 @@ +package org.apache.maven.linkcheck.validation; + +/** + * @author Ben Walding + * + * This is an immutable class.
+ *

+ * 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. + *

+ */ +public class LinkValidationResult { + public static final int NOTMINE = 0; + public static final int INVALID = 1; + public static final int VALID = 2; + public static final int UNKNOWN = 3; + + private int status = UNKNOWN; + + public LinkValidationResult(int status, boolean persistent) { + this.status = status; + this.persistent = persistent; + } + + boolean persistent; + public boolean isPersistent() { + return persistent; + } + + + /** + * Returns the status. + * @return int + */ + public int getStatus() { + return status; + } + + + +} diff --git a/linkcheck/src/main/org/apache/maven/linkcheck/validation/LinkValidator.java b/linkcheck/src/main/org/apache/maven/linkcheck/validation/LinkValidator.java new file mode 100644 index 00000000..27a343d6 --- /dev/null +++ b/linkcheck/src/main/org/apache/maven/linkcheck/validation/LinkValidator.java @@ -0,0 +1,28 @@ +package org.apache.maven.linkcheck.validation; + +import java.io.File; + +/** + * @author Ben Walding + * + */ +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; + + + /** + * The resource key is used by the cache to determine if it really needs to + * validate the link. No actual validation should be done at this point. + * @param lvi + * @return Object null if this validator should not be doing this work. + * @throws Exception + */ + public Object getResourceKey(LinkValidationItem lvi); +} diff --git a/linkcheck/src/main/org/apache/maven/linkcheck/validation/LinkValidatorCache.java b/linkcheck/src/main/org/apache/maven/linkcheck/validation/LinkValidatorCache.java new file mode 100644 index 00000000..06bbfc4c --- /dev/null +++ b/linkcheck/src/main/org/apache/maven/linkcheck/validation/LinkValidatorCache.java @@ -0,0 +1,156 @@ +package org.apache.maven.linkcheck.validation; + +/* ==================================================================== + * The Apache Software License, Version 1.1 + * + * Copyright (c) 2002 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, + * if any, must include the following acknowledgment: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, + * if and wherever such third-party acknowledgments normally appear. + * + * 4. The names "Apache" and "Apache Software Foundation" and + * "Apache Maven" must not be used to endorse or promote products + * derived from this software without prior written permission. For + * written permission, please contact apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", + * "Apache Maven", nor may "Apache" appear in their name, without + * prior written permission of the Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + * + * ==================================================================== + */ + +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.util.HashMap; +import java.util.Iterator; +import java.util.Map; +import java.util.Properties; + +/** + * @author Ben Walding + * + */ +public class LinkValidatorCache { + private LinkValidatorManager lvm; + private Map cache = new HashMap(); + + public LinkValidatorCache(LinkValidatorManager lvm) { + this.lvm = lvm; + } + public void setCachedResult(Object resourceKey, LinkValidationResult lvr) { + cache.put(resourceKey, lvr); + } + + /** + * + * @param lvi + * @return int Will return a status level, VALID, INVALID, UNKNOWN + */ + public LinkValidationResult getCachedResult(LinkValidationItem lvi) { + Iterator iter = lvm.getValidators().iterator(); + + while (iter.hasNext()) { + LinkValidator lv = (LinkValidator) iter.next(); + + Object resourceKey = lv.getResourceKey(lvi); + + if (resourceKey != null) { + return (LinkValidationResult) cache.get(resourceKey); + } + } + return null; + + } + + public void load(InputStream is) { + final LinkValidationResult LVR_VALID = + new LinkValidationResult(LinkValidationResult.VALID, true); + final LinkValidationResult LVR_INVALID = + new LinkValidationResult(LinkValidationResult.INVALID, true); + try { + Properties p = new Properties(); + p.load(is); + + Iterator iter = p.keySet().iterator(); + while (iter.hasNext()) { + String key = (String) iter.next(); + String value = (String) p.getProperty(key); + + if (value.equals("VALID")) + cache.put(key, LVR_VALID); + + if (value.equals("INVALID")) + cache.put(key, LVR_INVALID); + + } + } catch (IOException e) { + e.printStackTrace(); + } + + } + + public void save(OutputStream os) { + + try { + Properties p = new Properties(); + Iterator iter = cache.keySet().iterator(); + while (iter.hasNext()) { + String key = (String) iter.next(); + LinkValidationResult lvr = + (LinkValidationResult) cache.get(key); + if (lvr.isPersistent()) { + if (lvr.getStatus() == LinkValidationResult.VALID) { + p.setProperty(key, "VALID"); + } + + if (lvr.getStatus() == LinkValidationResult.INVALID) { + p.setProperty(key, "INVALID"); + } + } + } + + p.store(os, "LinkCheck Cache"); + } catch (IOException e) { + e.printStackTrace(); + } + } + +} diff --git a/linkcheck/src/main/org/apache/maven/linkcheck/validation/LinkValidatorManager.java b/linkcheck/src/main/org/apache/maven/linkcheck/validation/LinkValidatorManager.java new file mode 100644 index 00000000..9c6e252e --- /dev/null +++ b/linkcheck/src/main/org/apache/maven/linkcheck/validation/LinkValidatorManager.java @@ -0,0 +1,169 @@ +package org.apache.maven.linkcheck.validation; +/* ==================================================================== + * The Apache Software License, Version 1.1 + * + * Copyright (c) 2002 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, + * if any, must include the following acknowledgment: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, + * if and wherever such third-party acknowledgments normally appear. + * + * 4. The names "Apache" and "Apache Software Foundation" and + * "Apache Maven" must not be used to endorse or promote products + * derived from this software without prior written permission. For + * written permission, please contact apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", + * "Apache Maven", nor may "Apache" appear in their name, without + * prior written permission of the Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + * + * ==================================================================== + */ + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +/** + * @author Ben Walding + * + */ + +public class LinkValidatorManager { + /** + * Log for debug output + */ + private static Log LOG = LogFactory.getLog(LinkValidatorManager.class); + + private List validators = new ArrayList(); + private LinkValidatorCache cache = new LinkValidatorCache(this); + private String exclude; + + public LinkValidatorManager() { + + } + + public void addLinkValidator(LinkValidator lv) { + validators.add(lv); + } + + public List getValidators() { + return validators; + } + + public LinkValidationResult validateLink(LinkValidationItem lvi) + throws Exception { + { + LinkValidationResult status = cache.getCachedResult(lvi); + if (status != null) { + return status; + } + } + + if (exclude != null && lvi.getLink().startsWith(exclude)) { + 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) { + continue; + } + + cache.setCachedResult(resourceKey, lvr); + return lvr; + + } + + } + + LOG.info("Unable to validate link : " + lvi.getLink()); + return new LinkValidationResult(LinkValidationResult.UNKNOWN, false); + } + + public void loadCache(String cacheFilename) { + try { + File f = new File(cacheFilename); + if (f.exists()) { + this.cache.load(new FileInputStream(cacheFilename)); + } + } catch (FileNotFoundException e) { + e.printStackTrace(); + } + } + + public void saveCache(String cacheFilename) { + try { + this.cache.save(new FileOutputStream(cacheFilename)); + } catch (FileNotFoundException e) { + e.printStackTrace(); + } + } + + /** + * Returns the exclude. + * @return String + */ + public String getExclude() { + return exclude; + } + + /** + * Sets the exclude. + * @param exclude The exclude to set + */ + public void setExclude(String exclude) { + this.exclude = exclude; + } + +} diff --git a/linkcheck/src/main/org/apache/maven/linkcheck/validation/MailtoLinkValidator.java b/linkcheck/src/main/org/apache/maven/linkcheck/validation/MailtoLinkValidator.java new file mode 100644 index 00000000..8dfa592a --- /dev/null +++ b/linkcheck/src/main/org/apache/maven/linkcheck/validation/MailtoLinkValidator.java @@ -0,0 +1,24 @@ +package org.apache.maven.linkcheck.validation; + +/** + * @author Ben Walding + * + */ +public 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) + */ + public LinkValidationResult validateLink(LinkValidationItem lvi) + throws Exception { + return LVR; + } + /** + * @see org.apache.maven.linkcheck.validation.LinkValidator#getResourceKey(org.apache.maven.linkcheck.validation.LinkValidationItem) + */ + public Object getResourceKey(LinkValidationItem lvi) { + return lvi.getLink(); + } + +} diff --git a/linkcheck/src/main/org/apache/maven/linkcheck/validation/ValidationResult.java b/linkcheck/src/main/org/apache/maven/linkcheck/validation/ValidationResult.java new file mode 100644 index 00000000..27b7e8eb --- /dev/null +++ b/linkcheck/src/main/org/apache/maven/linkcheck/validation/ValidationResult.java @@ -0,0 +1,9 @@ +package org.apache.maven.linkcheck.validation; + +/** + * @author Ben Walding + * + */ +public class ValidationResult { + +} diff --git a/linkcheck/src/plugin-resources/linkcheck-temp.xml b/linkcheck/src/plugin-resources/linkcheck-temp.xml new file mode 100644 index 00000000..de2da9e6 --- /dev/null +++ b/linkcheck/src/plugin-resources/linkcheck-temp.xml @@ -0,0 +1,15 @@ + + + + Maven LinkCheck Plug-in + Ben Walding + + + +
+

+ This file is used as a placeholder until the final link check can occur. +

+
+ +
diff --git a/linkcheck/src/plugin-resources/linkcheck.jsl b/linkcheck/src/plugin-resources/linkcheck.jsl new file mode 100644 index 00000000..13fc9bfc --- /dev/null +++ b/linkcheck/src/plugin-resources/linkcheck.jsl @@ -0,0 +1,52 @@ + + + + + + + + + Link Check Report + + +
+ + + + + + + + + + + + + +
URL
+ + ${file.attribute('name').value} + + ${name} +
+ + + + + ${status} - ${target} +
+
+
+
+
+ +
+
+
diff --git a/linkcheck/src/test-resources/nolink.html b/linkcheck/src/test-resources/nolink.html new file mode 100644 index 00000000..8abca041 --- /dev/null +++ b/linkcheck/src/test-resources/nolink.html @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/linkcheck/src/test-resources/test-resources/nolink.html b/linkcheck/src/test-resources/test-resources/nolink.html new file mode 100644 index 00000000..d44382c6 --- /dev/null +++ b/linkcheck/src/test-resources/test-resources/nolink.html @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/linkcheck/src/test-resources/test-resources/test1/test1.html b/linkcheck/src/test-resources/test-resources/test1/test1.html new file mode 100644 index 00000000..e69de29b diff --git a/linkcheck/src/test-resources/test-resources/test1/test2.html b/linkcheck/src/test-resources/test-resources/test1/test2.html new file mode 100644 index 00000000..e69de29b diff --git a/linkcheck/src/test-resources/test1/test1.html b/linkcheck/src/test-resources/test1/test1.html new file mode 100644 index 00000000..e69de29b diff --git a/linkcheck/src/test-resources/testA.html b/linkcheck/src/test-resources/testA.html new file mode 100644 index 00000000..257a66ce --- /dev/null +++ b/linkcheck/src/test-resources/testA.html @@ -0,0 +1,5 @@ +test2 + + + +test that isn't here \ No newline at end of file diff --git a/linkcheck/src/test/org/apache/maven/linkcheck/LinkCheckTest.java b/linkcheck/src/test/org/apache/maven/linkcheck/LinkCheckTest.java new file mode 100644 index 00000000..5a24fa55 --- /dev/null +++ b/linkcheck/src/test/org/apache/maven/linkcheck/LinkCheckTest.java @@ -0,0 +1,95 @@ +package org.apache.maven.linkcheck; + +/* ==================================================================== + * The Apache Software License, Version 1.1 + * + * Copyright (c) 2002 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, + * if any, must include the following acknowledgment: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, + * if and wherever such third-party acknowledgments normally appear. + * + * 4. The names "Apache" and "Apache Software Foundation" and + * "Apache Maven" must not be used to endorse or promote products + * derived from this software without prior written permission. For + * written permission, please contact apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", + * "Apache Maven", nor may "Apache" appear in their name, without + * prior written permission of the Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + * + * ==================================================================== + */ +import java.io.File; +import java.util.Iterator; + +import junit.framework.TestCase; + +/** + * @author Ben Walding + * + */ +public class LinkCheckTest extends TestCase { + 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.doExecute(); + + + Iterator iter = lc.getFiles().iterator(); + while (iter.hasNext()) { + FileToCheck ftc = (FileToCheck) iter.next(); + System.out.println(ftc.getName()); + } + + //Iterator iter = Collections.EMPTY_LIST.iterator(); + + } + +} diff --git a/linkcheck/xdocs/.cvsignore b/linkcheck/xdocs/.cvsignore new file mode 100644 index 00000000..cb6131bb --- /dev/null +++ b/linkcheck/xdocs/.cvsignore @@ -0,0 +1 @@ +stylesheets diff --git a/linkcheck/xdocs/goals.xml b/linkcheck/xdocs/goals.xml new file mode 100644 index 00000000..0fe1ce1a --- /dev/null +++ b/linkcheck/xdocs/goals.xml @@ -0,0 +1,20 @@ + + + + + Maven Link Check Plug-in Goals + Ben Walding + + + + + linkcheck + + + + report + + + + + \ No newline at end of file diff --git a/linkcheck/xdocs/index.xml b/linkcheck/xdocs/index.xml new file mode 100644 index 00000000..12cbd526 --- /dev/null +++ b/linkcheck/xdocs/index.xml @@ -0,0 +1,29 @@ + + + + Maven LinkCheck Plug-in + Ben Walding + + + +
+

+ This plug-in validates the HTML that is produced as part of the site +

+
+ +
+

+ This section holds a list of possible future features that might be nice + to have implemented. (In decreasing order of importance) +

+ +

+

    +
  1. The ability to include exclude parts of the tree
  2. +
  3. Persists remote url checks across runs
  4. +
+

+
+ +
diff --git a/linkcheck/xdocs/navigation.xml b/linkcheck/xdocs/navigation.xml new file mode 100644 index 00000000..a87161fa --- /dev/null +++ b/linkcheck/xdocs/navigation.xml @@ -0,0 +1,17 @@ + + + + Maven junit-report Plugin + + + + + + + + + + + + + \ No newline at end of file diff --git a/linkcheck/xdocs/properties.xml b/linkcheck/xdocs/properties.xml new file mode 100644 index 00000000..3d7ae89c --- /dev/null +++ b/linkcheck/xdocs/properties.xml @@ -0,0 +1,83 @@ + + + + + junit-report Properties + dIon Gillard + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
PropertyOptional?Description
maven.linkcheck.enableYesIf defined, the report is enabled +

Default value is + undefined.

+
maven.linkcheck.baseurlNoUsed to create links to live documents +
maven.conf.dirYes +

Default value is + ${basedir}/conf.

+
maven.gen.docsYes +

Default value is + ${maven.build.dir}/generated-xdocs.

+
maven.docs.srcYes +

Default value is + ${basedir}/xdocs.

+
maven.build.dirYes +

Default value is + ${basedir}/target.

+
maven.docs.destYes +

Default value is + ${maven.build.dir}/docs.

+
maven.docs.outputencodingYes +

Default value is + ISO-8859-1.

+
+
+ +
\ No newline at end of file