Coding conventions

git-svn-id: https://svn.apache.org/repos/asf/maven/maven-1/plugins/trunk@112820 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
bwalding 2003-02-03 14:14:16 +00:00
parent 66116a6418
commit 95e8a42f8c
13 changed files with 841 additions and 465 deletions

View File

@ -3,7 +3,7 @@ package org.apache.maven.linkcheck;
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2002 The Apache Software Foundation. All rights
* Copyright (c) 2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
@ -74,172 +74,184 @@ import com.meterware.httpunit.WebRequest;
import com.meterware.httpunit.WebResponse;
/**
* @author Ben Walding
* @author <a href="mailto:bwalding@apache.org">Ben Walding</a>
* @version $Id: FileToCheck.java,v 1.3 2003/02/03 14:13:54 bwalding Exp $
*
*/
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 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 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;
}
public FileToCheck(File base, File f)
{
this.base = base;
this.f = f;
}
private List links = new ArrayList();
private List links = new ArrayList();
public void check(LinkValidatorManager lvm) throws Exception {
successful = 0;
unsuccessful = 0;
status = STATUS_OK;
message = "";
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();
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);
}
uniqueLinks.put(href, href);
}
Iterator iter = uniqueLinks.keySet().iterator();
while (iter.hasNext()) {
String href = (String) iter.next();
Iterator iter = uniqueLinks.keySet().iterator();
while (iter.hasNext())
{
String href = (String) iter.next();
//System.out.println("Link Found: " + href);
//System.out.println("Link Found: " + href);
LinkCheckResult lcr = new LinkCheckResult();
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;
}
links.add(lcr);
}
} catch (Exception e) {
message = e.toString();
System.err.println(e.toString());
throw (e);
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;
}
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);
fileName = fileName.replace('\\', '/');
return fileName;
}
public String toXML()
{
StringBuffer buf = new StringBuffer();
buf.append(" <file>\n");
buf.append(" <name>" + 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());
}
/**
* Returns the message.
* @return String
*/
public String getMessage() {
return message;
}
buf.append(" </file>\n");
/**
* 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);
fileName = fileName.replace('\\', '/');
return fileName;
}
public String toXML() {
StringBuffer buf = new StringBuffer();
buf.append(" <file>\n");
buf.append(" <name>" + 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();
}
return buf.toString();
}
}

View File

@ -3,7 +3,7 @@ package org.apache.maven.linkcheck;
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2002 The Apache Software Foundation. All rights
* Copyright (c) 2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
@ -56,7 +56,6 @@ package org.apache.maven.linkcheck;
* ====================================================================
*/
// java imports
import java.io.File;
import java.io.FileOutputStream;
import java.io.FilenameFilter;
@ -74,222 +73,244 @@ 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 <a href="mailto:ben@walding.com">Ben Walding</a>
* @version $Id: LinkCheck.java,v 1.2 2003/01/30 15:34:26 bwalding Exp $
* The main bean to be called whenever a set of documents should have
* their links checked.
*
* @author <a href="mailto:bwalding@apache.org">Ben Walding</a>
* @version $Id: LinkCheck.java,v 1.3 2003/02/03 14:13:54 bwalding Exp $
*/
public class LinkCheck {
/** Log */
private static final Log LOG = LogFactory.getLog(LinkCheck.class);
public class LinkCheck
{
/** Log */
private static final Log LOG = LogFactory.getLog(LinkCheck.class);
/**
* Output file for xml document
*/
private File output;
/**
* Output file for xml document
*/
private File output;
/** output encoding for the xml document */
private String outputEncoding;
/** output encoding for the xml document */
private String outputEncoding;
private File baseDir;
private String cache;
private String exclude;
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;
/**
* 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();
}
}
/**
* Get the base directory for the change log generator.
*
* @return the base directory
*/
public File getBasedir() {
return baseDir;
}
createDocument(files);
lvm.saveCache(cache);
}
/**
* Set the output file for the log.
* @param output the output file
*/
public void setOutput(File output) {
this.output = output;
}
public List getFiles()
{
return filesToCheck;
}
/**
* 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");
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);
}
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();
}
else
{
allFiles.add(new FileToCheck(baseDir, file));
}
createDocument(files);
lvm.saveCache(cache);
}
}
}
public List getFiles() {
return filesToCheck;
/**
* 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("<?xml version=\"1.0\" encoding=\"").append(getOutputEncoding()).append("\" ?>\n");
out.write(buffer.toString());
out.write(toXML());
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;
}
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;
/**
* Returns the cacheFile.
* @return String
*/
public String getCache()
{
return cache;
}
if (name.endsWith(".html"))
return true;
/**
* Sets the cacheFile.
* @param cacheFile The cacheFile to set
*/
public void setCache(String cache)
{
this.cache = cache;
}
return false;
}
};
/**
* Returns the exclude.
* @return String
*/
public String getExclude()
{
return exclude;
}
File[] f = base.listFiles(ff);
/**
* Sets the exclude.
* @param exclude The exclude to set
*/
public void setExclude(String exclude)
{
this.exclude = exclude;
}
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("<?xml version=\"1.0\" encoding=\"")
.append(getOutputEncoding())
.append("\" ?>\n");
out.write(buffer.toString());
out.write(toXML());
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;
}
public String toXML() {
StringBuffer buf = new StringBuffer();
buf.append("<linkcheck>\n");
//buf.append(" <files>\n");
for (Iterator iter = getFiles().iterator(); iter.hasNext();) {
FileToCheck ftc = (FileToCheck) iter.next();
buf.append(ftc.toXML());
}
//buf.append(" </files>\n");
buf.append("</linkcheck>\n");
return buf.toString();
public String toXML()
{
StringBuffer buf = new StringBuffer();
buf.append("<linkcheck>\n");
//buf.append(" <files>\n");
for (Iterator iter = getFiles().iterator(); iter.hasNext();)
{
FileToCheck ftc = (FileToCheck) iter.next();
buf.append(ftc.toXML());
}
//buf.append(" </files>\n");
buf.append("</linkcheck>\n");
return buf.toString();
}
}

View File

@ -1,11 +1,9 @@
package org.apache.maven.linkcheck;
import org.apache.commons.util.XmlUtils;
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2002 The Apache Software Foundation. All rights
* Copyright (c) 2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
@ -57,55 +55,64 @@ import org.apache.commons.util.XmlUtils;
*
* ====================================================================
*/
import org.apache.commons.util.XmlUtils;
/**
* @author Ben Walding
*
* An class containing the results of a single check of a link.
* @author <a href="mailto:bwalding@apache.org">Ben Walding</a>
* @version $Id: LinkCheckResult.java,v 1.3 2003/02/03 14:13:54 bwalding Exp $
*/
public class LinkCheckResult {
private String status;
private String target;
public class LinkCheckResult
{
private String status;
private String target;
/**
* Returns the status.
* @return String
*/
public String getStatus() {
return status;
}
/**
* 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;
}
/**
* 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;
}
/**
* 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;
}
/**
* Sets the target.
* @param target The target to set
*/
public void setTarget(String target)
{
this.target = target;
}
public String toXML() {
StringBuffer buf = new StringBuffer();
public String toXML()
{
StringBuffer buf = new StringBuffer();
buf.append(" <result>\n");
buf.append(" <target>" + XmlUtils.escapeXml(getTarget()) + "</target>\n");
buf.append(" <status>" + getStatus() + "</status>\n");
buf.append(" </result>\n");
return buf.toString();
}
buf.append(" <result>\n");
buf.append(" <target>" + XmlUtils.escapeXml(getTarget()) + "</target>\n");
buf.append(" <status>" + getStatus() + "</status>\n");
buf.append(" </result>\n");
return buf.toString();
}
}

View File

@ -1,10 +1,68 @@
package org.apache.maven.linkcheck.validation;
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2003 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
* <http://www.apache.org/>.
*
* ====================================================================
*/
import java.io.File;
/**
* @author Ben Walding
*
* A link validator solely for files on the local filesystem.
*
* @author <a href="mailto:bwalding@apache.org">Ben Walding</a>
* @version $Id: FileLinkValidator.java,v 1.2 2003/02/03 14:13:54 bwalding Exp $
*/
public class FileLinkValidator implements LinkValidator {
private final static LinkValidationResult LVR_INVALID =
@ -25,6 +83,11 @@ public class FileLinkValidator implements LinkValidator {
return LVR_INVALID;
}
/**
*
* @param lvi
* @return File
*/
protected File getFile(LinkValidationItem lvi) {
String link = lvi.getLink();
if (link.indexOf('#') != -1) {

View File

@ -1,5 +1,61 @@
package org.apache.maven.linkcheck.validation;
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2003 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
* <http://www.apache.org/>.
*
* ====================================================================
*/
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@ -9,8 +65,9 @@ import com.meterware.httpunit.WebRequest;
import com.meterware.httpunit.WebResponse;
/**
* @author Ben Walding
*
* Checks links which are normal URLs
* @author <a href="mailto:bwalding@apache.org">Ben Walding</a>
* @version $Id: HTTPLinkValidator.java,v 1.2 2003/02/03 14:13:54 bwalding Exp $
*/
public class HTTPLinkValidator implements LinkValidator {
/**

View File

@ -1,9 +1,66 @@
package org.apache.maven.linkcheck.validation;
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2003 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
* <http://www.apache.org/>.
*
* ====================================================================
*/
import java.io.File;
/**
* @author Ben Walding
*
* @author <a href="mailto:bwalding@apache.org">Ben Walding</a>
* @version $Id: LinkValidationItem.java,v 1.2 2003/02/03 14:13:54 bwalding Exp $
*/
public class LinkValidationItem {
private File source;

View File

@ -1,8 +1,64 @@
package org.apache.maven.linkcheck.validation;
/**
* @author Ben Walding
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2003 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
* <http://www.apache.org/>.
*
* ====================================================================
*/
/**
* @author <a href="mailto:bwalding@apache.org">Ben Walding</a>
* @version $Id: LinkValidationResult.java,v 1.2 2003/02/03 14:13:54 bwalding Exp $
* <b>This is an immutable class.</b><br/>
* <p>
* This class is used to return status responses from the

View File

@ -1,10 +1,64 @@
package org.apache.maven.linkcheck.validation;
import java.io.File;
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2003 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
* <http://www.apache.org/>.
*
* ====================================================================
*/
/**
* @author Ben Walding
*
* @author <a href="mailto:bwalding@apache.org">Ben Walding</a>
* @version $Id: LinkValidator.java,v 1.2 2003/02/03 14:13:54 bwalding Exp $
*/
public interface LinkValidator {

View File

@ -3,7 +3,7 @@ package org.apache.maven.linkcheck.validation;
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2002 The Apache Software Foundation. All rights
* Copyright (c) 2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
@ -65,8 +65,8 @@ import java.util.Map;
import java.util.Properties;
/**
* @author Ben Walding
*
* @author <a href="mailto:bwalding@apache.org">Ben Walding</a>
* @version $Id: LinkValidatorCache.java,v 1.2 2003/02/03 14:13:54 bwalding Exp $
*/
public class LinkValidatorCache {
private LinkValidatorManager lvm;

View File

@ -1,8 +1,9 @@
package org.apache.maven.linkcheck.validation;
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2002 The Apache Software Foundation. All rights
* Copyright (c) 2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
@ -67,8 +68,8 @@ import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
/**
* @author Ben Walding
*
* @author <a href="mailto:bwalding@apache.org">Ben Walding</a>
* @version $Id: LinkValidatorManager.java,v 1.2 2003/02/03 14:13:54 bwalding Exp $
*/
public class LinkValidatorManager {

View File

@ -1,8 +1,66 @@
package org.apache.maven.linkcheck.validation;
/**
* @author Ben Walding
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2003 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
* <http://www.apache.org/>.
*
* ====================================================================
*/
/**
* @author <a href="mailto:bwalding@apache.org">Ben Walding</a>
* @version $Id: MailtoLinkValidator.java,v 1.2 2003/02/03 14:13:54 bwalding Exp $
*
* Validates mailto links
*/
public class MailtoLinkValidator implements LinkValidator {
private static final LinkValidationResult LVR =

View File

@ -1,9 +0,0 @@
package org.apache.maven.linkcheck.validation;
/**
* @author Ben Walding
*
*/
public class ValidationResult {
}

View File

@ -60,8 +60,6 @@ import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import org.apache.maven.linkcheck.validation.FileLinkValidator;
import org.apache.maven.linkcheck.validation.LinkValidatorManager;
import junit.framework.TestCase;
@ -69,55 +67,56 @@ import junit.framework.TestCase;
* @author Ben Walding
*
*/
public class LinkCheckTest extends TestCase {
String baseDir;
public class LinkCheckTest extends TestCase
{
String baseDir;
public void setUp() {
baseDir = System.getProperty("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();
Map map = new HashMap();
while (iter.hasNext())
{
FileToCheck ftc = (FileToCheck) iter.next();
map.put(ftc.getName(), ftc);
}
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();
assertEquals("files.size()", 6, lc.getFiles().size());
Iterator iter = lc.getFiles().iterator();
Map map = new HashMap();
while (iter.hasNext()) {
FileToCheck ftc = (FileToCheck) iter.next();
map.put(ftc.getName(), ftc);
}
check(map, "nolink.html", 0);
check(map, "test-resources/nolink.html", 0);
check(map, "test-resources/test1/test1.html", 1);
check(map, "test-resources/test1/test2.html", 0);
check(map, "test1/test1.html", 1);
check(map, "testA.html", 2);
assertEquals("files.size()", 6, lc.getFiles().size());
}
check(map, "nolink.html", 0);
check(map, "test-resources/nolink.html", 0);
check(map, "test-resources/test1/test1.html", 1);
check(map, "test-resources/test1/test2.html", 0);
check(map, "test1/test1.html", 1);
check(map, "testA.html", 2);
private void check(Map map, String name, int linkCount)
{
FileToCheck ftc;
}
ftc = (FileToCheck) map.get(name);
assertNotNull(name, ftc);
private void check(Map map, String name, int linkCount) {
FileToCheck ftc;
ftc = (FileToCheck) map.get(name);
assertNotNull(name, ftc);
/*if (ftc.getResults().size() != linkCount) {
/*if (ftc.getResults().size() != linkCount) {
}*/
assertEquals(
name + ".getLinks().size()",
linkCount,
ftc.getResults().size());
}
}*/
assertEquals(name + ".getLinks().size()", linkCount, ftc.getResults().size());
}
}