From d840bf4c2aef1d420c7bb98008e7b4952070e669 Mon Sep 17 00:00:00 2001 From: carlos Date: Mon, 26 Jul 2004 16:16:35 +0000 Subject: [PATCH] Added maven.linkcheck.exclude property git-svn-id: https://svn.apache.org/repos/asf/maven/maven-1/plugins/trunk@115892 13f79535-47bb-0310-9956-ffa450edef68 --- linkcheck/plugin.jelly | 2 +- linkcheck/plugin.properties | 1 + linkcheck/project.xml | 2 +- .../org/apache/maven/linkcheck/LinkCheck.java | 21 ++++++++--- .../validation/LinkValidatorManager.java | 36 +++++++++++++++---- .../src/test-resources/testExcludes.html | 26 ++++++++++++++ .../apache/maven/linkcheck/LinkCheckTest.java | 13 +++++-- linkcheck/xdocs/changes.xml | 3 ++ linkcheck/xdocs/index.xml | 3 +- linkcheck/xdocs/properties.xml | 9 +++++ 10 files changed, 101 insertions(+), 15 deletions(-) create mode 100644 linkcheck/src/test-resources/testExcludes.html diff --git a/linkcheck/plugin.jelly b/linkcheck/plugin.jelly index 13abacd2..add250ca 100644 --- a/linkcheck/plugin.jelly +++ b/linkcheck/plugin.jelly @@ -84,7 +84,7 @@ 3 maven-linkcheck-plugin Maven LinkCheck Plug-in - 1.3.2 + 1.4-SNAPSHOT Check xdoc links. Requires Maven 1.0 RC2. Check xdoc links http://maven.apache.org/reference/plugins/linkcheck/ diff --git a/linkcheck/src/main/org/apache/maven/linkcheck/LinkCheck.java b/linkcheck/src/main/org/apache/maven/linkcheck/LinkCheck.java index 705849d1..3f3f286d 100644 --- a/linkcheck/src/main/org/apache/maven/linkcheck/LinkCheck.java +++ b/linkcheck/src/main/org/apache/maven/linkcheck/LinkCheck.java @@ -25,6 +25,7 @@ import java.io.PrintWriter; import java.util.ArrayList; import java.util.Iterator; import java.util.List; +import java.util.StringTokenizer; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -40,7 +41,8 @@ import org.apache.maven.project.Project; * their links checked. * * @author Ben Walding - * @version $Id: LinkCheck.java,v 1.12 2004/03/02 15:09:17 evenisse Exp $ + * @author Carlos Sanchez + * @version $Id: LinkCheck.java,v 1.13 2004/07/26 16:16:35 carlos Exp $ */ public class LinkCheck { @@ -228,7 +230,14 @@ public class LinkCheck if (lvm == null) { lvm = new LinkValidatorManager(); - lvm.setExclude(exclude); + if (exclude != null) { + StringTokenizer st = new StringTokenizer(exclude, " ,\t\n\r\f"); + String[] tokens = new String[st.countTokens()]; + for (int i = 0; i < tokens.length; i++) { + tokens[i] = st.nextToken(); + } + lvm.setExcludes(tokens); + } lvm.addLinkValidator(new FileLinkValidator()); MavenJellyContext ctx; if (getProject() == null) { @@ -274,8 +283,12 @@ public class LinkCheck } /** - * Sets the exclude. - * @param exclude The exclude to set + * Sets the exclude, a string with exclude locations delimited by the space + * character, the comma character, the tab character, the newline character, + * the carriage-return character, and the form-feed character. + * + * @param exclude + * The exclude to set */ public void setExclude(String exclude) { diff --git a/linkcheck/src/main/org/apache/maven/linkcheck/validation/LinkValidatorManager.java b/linkcheck/src/main/org/apache/maven/linkcheck/validation/LinkValidatorManager.java index 8c3dde25..2b9dae42 100644 --- a/linkcheck/src/main/org/apache/maven/linkcheck/validation/LinkValidatorManager.java +++ b/linkcheck/src/main/org/apache/maven/linkcheck/validation/LinkValidatorManager.java @@ -30,7 +30,8 @@ import org.apache.commons.logging.LogFactory; /** * @author Ben Walding - * @version $Id: LinkValidatorManager.java,v 1.5 2004/03/02 15:09:17 evenisse Exp $ + * @author Carlos Sanchez + * @version $Id: LinkValidatorManager.java,v 1.6 2004/07/26 16:16:34 carlos Exp $ */ public class LinkValidatorManager { @@ -41,7 +42,7 @@ public class LinkValidatorManager { private List validators = new ArrayList(); private LinkValidatorCache cache = new LinkValidatorCache(this); - private String exclude; + private String[] excludes = new String[0]; public LinkValidatorManager() { @@ -64,8 +65,13 @@ public class LinkValidatorManager { } } - if (exclude != null && lvi.getLink().startsWith(exclude)) { - return new LinkValidationResult(LinkValidationResult.VALID, false); + for (int i = 0; i < excludes.length; i++) { + if (excludes[i] != null && lvi.getLink().startsWith(excludes[i])) { + if (LOG.isDebugEnabled()) { + LOG.debug("Excluded " + lvi.getLink()); + } + return new LinkValidationResult(LinkValidationResult.VALID, false); + } } Iterator iter = validators.iterator(); @@ -120,17 +126,35 @@ public class LinkValidatorManager { /** * Returns the exclude. * @return String + * @deprecated use getExcludes() */ public String getExclude() { - return exclude; + return excludes[0]; } /** * Sets the exclude. * @param exclude The exclude to set + * @deprecated use setExcludes() */ public void setExclude(String exclude) { - this.exclude = exclude; + this.excludes = new String[] {exclude}; + } + + /** + * Returns the excludes. + * @return String[] + */ + public String[] getExcludes() { + return excludes; + } + + /** + * Sets the excludes. + * @param excludes The excludes to set + */ + public void setExcludes(String[] excludes) { + this.excludes = excludes; } } diff --git a/linkcheck/src/test-resources/testExcludes.html b/linkcheck/src/test-resources/testExcludes.html new file mode 100644 index 00000000..b65ec6cc --- /dev/null +++ b/linkcheck/src/test-resources/testExcludes.html @@ -0,0 +1,26 @@ + + + + +this will be excluded +this will be excluded + + + + \ 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 index 02618fb5..c8da45a1 100644 --- a/linkcheck/src/test/org/apache/maven/linkcheck/LinkCheckTest.java +++ b/linkcheck/src/test/org/apache/maven/linkcheck/LinkCheckTest.java @@ -28,7 +28,7 @@ import junit.framework.TestCase; /** * @author Ben Walding - * + * @author Carlos Sanchez */ public class LinkCheckTest extends TestCase { @@ -47,6 +47,8 @@ public class LinkCheckTest extends TestCase lc.setOutput(new File(baseDir + "/target/linkcheck.xml")); lc.setOutputEncoding("ISO8859-1"); lc.setCache(baseDir + "/target/linkcheck-cache.xml"); + lc.setExclude("http://cvs.apache.org/viewcvs.cgi/maven-pluginszz/," + + "http://cvs.apache.org/viewcvs.cgi/mavenzz/"); lc.doExecute(); Iterator iter = lc.getFiles().iterator(); @@ -57,7 +59,7 @@ public class LinkCheckTest extends TestCase map.put(ftc.getName(), ftc); } - assertEquals("files.size()", 7, lc.getFiles().size()); + assertEquals("files.size()", 8, lc.getFiles().size()); check(map, "nolink.html", 0); check(map, "test-resources/nolink.html", 0); @@ -65,6 +67,13 @@ public class LinkCheckTest extends TestCase check(map, "test-resources/test1/test2.html", 0); check(map, "test1/test1.html", 1); check(map, "testA.html", 3); + + /* test excludes */ + String fileName = "testExcludes.html"; + check(map, fileName, 2); + + FileToCheck ftc = (FileToCheck) map.get(fileName); + assertEquals("Excluded links", 2, ftc.getSuccessful()); //index-all.html should get parsed, but is currently having problems. //check(map, "index-all.html", 1); diff --git a/linkcheck/xdocs/changes.xml b/linkcheck/xdocs/changes.xml index 2626c528..ac8e91f6 100644 --- a/linkcheck/xdocs/changes.xml +++ b/linkcheck/xdocs/changes.xml @@ -25,6 +25,9 @@ Vincent Massol + + Added maven.linkcheck.exclude property + Only log exception in debug mode on connection refused Update commons-* diff --git a/linkcheck/xdocs/index.xml b/linkcheck/xdocs/index.xml index b6fee76b..1ff9fe81 100644 --- a/linkcheck/xdocs/index.xml +++ b/linkcheck/xdocs/index.xml @@ -26,7 +26,8 @@

- This plug-in validates the HTML that is produced as part of the site + This plug-in validates the HTML that is produced as part of the site. + Just add the maven-linkcheck-plugin report to your project.

diff --git a/linkcheck/xdocs/properties.xml b/linkcheck/xdocs/properties.xml index e95ecf50..92994274 100644 --- a/linkcheck/xdocs/properties.xml +++ b/linkcheck/xdocs/properties.xml @@ -50,6 +50,15 @@ Defaults to false. + + maven.linkcheck.exclude + Yes + + List of urls to exclude from check, delimited by comma, space or tab. + Those urls in files that start with one of the excluded urls will be ignored. + Defaults to pom.repository.url. + +