MAVEN-214: LinkChecker plugin
git-svn-id: https://svn.apache.org/repos/asf/maven/maven-1/plugins/trunk@112777 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
1 parent
17b604c9d2
commit
fa5ca2bd70
36 files changed
+1839
No files matched your search
@@ -0,0 +1,10 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
|
||||
<info>
|
||||
<element name="file">
|
||||
<attribute name="name" property="name"/>
|
||||
<attribute name="successful" property="successful"/>
|
||||
<attribute name="unsuccessful" property="unsuccessful"/>
|
||||
<element name="result" property="results"/>
|
||||
</element>
|
||||
</info>
|
||||
@@ -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
|
||||
* <http://www.apache.org/>.
|
||||
*
|
||||
* ====================================================================
|
||||
*/
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
|
||||
<info>
|
||||
<element name="linkcheck">
|
||||
<element name="file" property="files"/>
|
||||
</element>
|
||||
</info>
|
||||
@@ -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
|
||||
* <http://www.apache.org/>.
|
||||
*
|
||||
* ====================================================================
|
||||
*/
|
||||
|
||||
// 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 <a href="mailto:ben@walding.com">Ben Walding</a>
|
||||
* @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("<?xml version=\"1.0\" encoding=\"")
|
||||
.append(getOutputEncoding())
|
||||
.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;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
|
||||
<info>
|
||||
<element name="result">
|
||||
<attribute name="status" property="status"/>
|
||||
<attribute name="target" property="target"/>
|
||||
</element>
|
||||
</info>
|
||||
@@ -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
|
||||
* <http://www.apache.org/>.
|
||||
*
|
||||
* ====================================================================
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @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;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
<linkcheck>
|
||||
<file name="asd.html">
|
||||
<link
|
||||
url="bob"
|
||||
status="OK"/>
|
||||
</file>
|
||||
</linkcheck>
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
package org.apache.maven.linkcheck.validation;
|
||||
|
||||
/**
|
||||
* @author Ben Walding
|
||||
*
|
||||
* <b>This is an immutable class.</b><br/>
|
||||
* <p>
|
||||
* This class is used to return status responses from the
|
||||
* validation handlers. A persistent result means that it
|
||||
* can be stored in the persistent cache and used across runs.
|
||||
* </p>
|
||||
*/
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
@@ -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
|
||||
* <http://www.apache.org/>.
|
||||
*
|
||||
* ====================================================================
|
||||
*/
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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
|
||||
* <http://www.apache.org/>.
|
||||
*
|
||||
* ====================================================================
|
||||
*/
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package org.apache.maven.linkcheck.validation;
|
||||
|
||||
/**
|
||||
* @author Ben Walding
|
||||
*
|
||||
*/
|
||||
public class ValidationResult {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
<?xml version="1.0"?>
|
||||
<document>
|
||||
<properties>
|
||||
<title>Maven LinkCheck Plug-in</title>
|
||||
<author email="ben@walding.com">Ben Walding</author>
|
||||
</properties>
|
||||
|
||||
<body>
|
||||
<section name="Maven LinkCheck Temporary File">
|
||||
<p>
|
||||
This file is used as a placeholder until the final link check can occur.
|
||||
</p>
|
||||
</section>
|
||||
</body>
|
||||
</document>
|
||||
@@ -0,0 +1,52 @@
|
||||
<?xml version="1.0"?>
|
||||
|
||||
<jsl:stylesheet
|
||||
select="$doc"
|
||||
xmlns:j="jelly:core"
|
||||
xmlns:util="jelly:util"
|
||||
xmlns:jsl="jelly:jsl"
|
||||
xmlns:x="jelly:xml"
|
||||
xmlns="dummy"
|
||||
trim="false">
|
||||
|
||||
<jsl:template match="linkcheck">
|
||||
<document>
|
||||
|
||||
<properties>
|
||||
<title>Link Check Report</title>
|
||||
</properties>
|
||||
<body>
|
||||
<section name="Link Check Report">
|
||||
<table>
|
||||
<tr>
|
||||
<th>URL</th>
|
||||
</tr>
|
||||
<x:set var="files" select="file[@unsuccessful!=0]"/>
|
||||
<j:forEach var="file" items="${files}">
|
||||
<tr>
|
||||
<td colspan="2">
|
||||
<util:replace var="name" oldChar="\\" newChar="/">
|
||||
${file.attribute('name').value}
|
||||
</util:replace>
|
||||
<a href="${name}">${name}</a>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<x:forEach var="result" select="$file/result">
|
||||
<j:set var="status"><x:expr select="$result/@status"/></j:set>
|
||||
<j:set var="target"><x:expr select="$result/@target"/></j:set>
|
||||
<j:if test="${status != 'OK'}">
|
||||
<span style="pad-left:60px">${status} - ${target}</span>
|
||||
<br/>
|
||||
</j:if>
|
||||
</x:forEach>
|
||||
</td>
|
||||
</tr>
|
||||
</j:forEach>
|
||||
</table>
|
||||
</section>
|
||||
</body>
|
||||
</document>
|
||||
</jsl:template>
|
||||
</jsl:stylesheet>
|
||||
@@ -0,0 +1,7 @@
|
||||
<html>
|
||||
<body>
|
||||
|
||||
|
||||
</body>
|
||||
|
||||
</html>
|
||||
@@ -0,0 +1,6 @@
|
||||
<html>
|
||||
<body>
|
||||
|
||||
|
||||
</body>
|
||||
</html>
|
||||
Whitespace-only changes.
Whitespace-only changes.
Whitespace-only changes.
@@ -0,0 +1,5 @@
|
||||
<a href="#bumpkin">test2</a>
|
||||
|
||||
|
||||
|
||||
<a href="testnothere.html">test that isn't here</a>
|
||||
@@ -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
|
||||
* <http://www.apache.org/>.
|
||||
*
|
||||
* ====================================================================
|
||||
*/
|
||||
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();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user