You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@maven.apache.org by bw...@apache.org on 2003/09/13 23:48:08 UTC
cvs commit: maven/src/plugins-build/linkcheck project.xml .cvsignore maven.xml
bwalding 2003/09/13 14:48:08
Modified: src/plugins-build/linkcheck/src/main/org/apache/maven/linkcheck/validation
LinkValidationResult.java LinkValidationItem.java
LinkValidatorCache.java HTTPLinkValidator.java
src/plugins-build/linkcheck/src/main/org/apache/maven/linkcheck
FileToCheck.java LinkCheck.java
LinkCheckResult.java
src/plugins-build/linkcheck/src/plugin-resources
linkcheck-temp.xml
src/plugins-build/linkcheck project.xml .cvsignore maven.xml
Log:
o Now follow 302 redirects (one level only)
o Cleaned up logging a little bit and added more logging
o Doesn't address the MacOSX bug (test failure bug), but the logging increase might help
Revision Changes Path
1.3 +4 -4 maven/src/plugins-build/linkcheck/src/main/org/apache/maven/linkcheck/validation/LinkValidationResult.java
Index: LinkValidationResult.java
===================================================================
RCS file: /home/cvs/maven/src/plugins-build/linkcheck/src/main/org/apache/maven/linkcheck/validation/LinkValidationResult.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- LinkValidationResult.java 3 Feb 2003 14:13:54 -0000 1.2
+++ LinkValidationResult.java 13 Sep 2003 21:48:08 -0000 1.3
@@ -57,14 +57,14 @@
*/
/**
- * @author <a href="mailto:bwalding@apache.org">Ben Walding</a>
- * @version $Id$
* <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>
+ * @author <a href="mailto:bwalding@apache.org">Ben Walding</a>
+ * @version $Id$
*/
public class LinkValidationResult {
public static final int NOTMINE = 0;
@@ -72,14 +72,14 @@
public static final int VALID = 2;
public static final int UNKNOWN = 3;
- private int status = UNKNOWN;
+ private final boolean persistent;
+ private final int status;
public LinkValidationResult(int status, boolean persistent) {
this.status = status;
this.persistent = persistent;
}
- boolean persistent;
public boolean isPersistent() {
return persistent;
}
1.3 +5 -21 maven/src/plugins-build/linkcheck/src/main/org/apache/maven/linkcheck/validation/LinkValidationItem.java
Index: LinkValidationItem.java
===================================================================
RCS file: /home/cvs/maven/src/plugins-build/linkcheck/src/main/org/apache/maven/linkcheck/validation/LinkValidationItem.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- LinkValidationItem.java 3 Feb 2003 14:13:54 -0000 1.2
+++ LinkValidationItem.java 13 Sep 2003 21:48:08 -0000 1.3
@@ -63,8 +63,8 @@
* @version $Id$
*/
public class LinkValidationItem {
- private File source;
- private String link;
+ private final File source;
+ private final String link;
public LinkValidationItem(File source, String link) {
if (source == null) {
@@ -89,7 +89,8 @@
return false;
if (!lvi.source.equals(source))
- return false;
+ return false;
+
return true;
}
@@ -116,22 +117,5 @@
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;
- }
-
}
1.3 +6 -6 maven/src/plugins-build/linkcheck/src/main/org/apache/maven/linkcheck/validation/LinkValidatorCache.java
Index: LinkValidatorCache.java
===================================================================
RCS file: /home/cvs/maven/src/plugins-build/linkcheck/src/main/org/apache/maven/linkcheck/validation/LinkValidatorCache.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- LinkValidatorCache.java 3 Feb 2003 14:13:54 -0000 1.2
+++ LinkValidatorCache.java 13 Sep 2003 21:48:08 -0000 1.3
@@ -70,7 +70,7 @@
*/
public class LinkValidatorCache {
private LinkValidatorManager lvm;
- private Map cache = new HashMap();
+ private final Map cache = new HashMap();
public LinkValidatorCache(LinkValidatorManager lvm) {
this.lvm = lvm;
@@ -80,10 +80,10 @@
}
/**
- *
- * @param lvi
- * @return int Will return a status level, VALID, INVALID, UNKNOWN
- */
+ *
+ * @param lvi
+ * @return int Will return a status level, VALID, INVALID, UNKNOWN
+ */
public LinkValidationResult getCachedResult(LinkValidationItem lvi) {
Iterator iter = lvm.getValidators().iterator();
1.8 +40 -22 maven/src/plugins-build/linkcheck/src/main/org/apache/maven/linkcheck/validation/HTTPLinkValidator.java
Index: HTTPLinkValidator.java
===================================================================
RCS file: /home/cvs/maven/src/plugins-build/linkcheck/src/main/org/apache/maven/linkcheck/validation/HTTPLinkValidator.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- HTTPLinkValidator.java 17 Apr 2003 13:07:03 -0000 1.7
+++ HTTPLinkValidator.java 13 Sep 2003 21:48:08 -0000 1.8
@@ -56,6 +56,7 @@
* ====================================================================
*/
+import org.apache.commons.httpclient.Header;
import org.apache.commons.httpclient.HostConfiguration;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpState;
@@ -81,7 +82,6 @@
private static final LinkValidationResult LVR_VALID = new LinkValidationResult(LinkValidationResult.VALID, true);
- private boolean proxy;
private String proxyHost;
private int proxyPort;
private String proxyUser;
@@ -91,19 +91,18 @@
{
if (proxyHost == null)
{
- proxy = false;
- System.out.println("maven-linkcheck-plugin: Not using a proxy");
+ LOG.info("maven-linkcheck-plugin: Not using a proxy");
+ this.proxyHost = null;
}
else
{
- proxy = true;
this.proxyHost = proxyHost;
this.proxyPort = Integer.parseInt(proxyPort);
this.proxyUser = proxyUser;
this.proxyPass = proxyPass;
- System.out.println("maven-linkcheck-plugin: Proxy Host:" + proxyHost);
- System.out.println("maven-linkcheck-plugin: Proxy Port:" + proxyPort);
- System.out.println("maven-linkcheck-plugin: Proxy User:" + proxyUser);
+ LOG.info("maven-linkcheck-plugin: Proxy Host:" + proxyHost);
+ LOG.info("maven-linkcheck-plugin: Proxy Port:" + proxyPort);
+ LOG.info("maven-linkcheck-plugin: Proxy User:" + proxyUser);
}
}
@@ -125,36 +124,38 @@
hc.setProxy(proxyHost, proxyPort);
}
HttpState state = new HttpState();
-
+
if (proxyUser != null && proxyPass != null)
{
- state.setProxyCredentials(null, new UsernamePasswordCredentials(proxyUser, proxyPass));
+ state.setProxyCredentials(null, null, new UsernamePasswordCredentials(proxyUser, proxyPass));
}
- GetMethod get = new GetMethod(link);
cl.setHostConfiguration(hc);
cl.setState(state);
- get.setFollowRedirects(true);
-
+
// execute the GET
- int status = 404;
- try
- {
- status = cl.executeMethod(get);
- }
- catch (Exception e)
+ GetMethod gm = checkLink(cl, link);
+
+ if (gm.getStatusCode() == 302)
{
- System.out.println(e);
+ Header locationHeader = gm.getResponseHeader("Location");
+ if (locationHeader == null) {
+ LOG.info("Site sent redirect, but did not set Location header");
+ } else {
+ String newLink = locationHeader.getValue();
+ LOG.debug("Following 1 redirect to " + newLink);
+ gm = checkLink(cl, newLink);
+ }
}
//FIXME: This constant is defined somewhere, but I can't remember where...
- if (status == 200)
+ if (gm.getStatusCode() == 200)
{
return LVR_VALID;
}
else
{
- String msg = "Received: [" + status + "] for " + link;
+ String msg = "Received: [" + gm.getStatusCode() + "] for " + link;
LOG.info(msg);
System.out.println(msg);
return LVR_INVALID;
@@ -168,6 +169,23 @@
return LVR_INVALID;
}
+ }
+
+ private GetMethod checkLink(HttpClient cl, String link)
+ {
+ GetMethod gm = new GetMethod(link);
+ try
+ {
+ LOG.info("Checking link " + link);
+ gm.setFollowRedirects(true);
+ cl.executeMethod(gm);
+ LOG.debug("Checked link " + link);
+ }
+ catch (Exception e)
+ {
+ LOG.warn("Error validating " + link, e);
+ }
+ return gm;
}
/**
1.12 +12 -10 maven/src/plugins-build/linkcheck/src/main/org/apache/maven/linkcheck/FileToCheck.java
Index: FileToCheck.java
===================================================================
RCS file: /home/cvs/maven/src/plugins-build/linkcheck/src/main/org/apache/maven/linkcheck/FileToCheck.java,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -r1.11 -r1.12
--- FileToCheck.java 7 Mar 2003 22:46:39 -0000 1.11
+++ FileToCheck.java 13 Sep 2003 21:48:08 -0000 1.12
@@ -146,9 +146,8 @@
{
//We catch Throwable, because there is a chance that the domReader will throw
//a stack overflow exception for some files
- if (!(e instanceof Exception)) {
- LOG.info("Caught " + e.toString());
- }
+ LOG.info("Caught " + e.toString() + " processing " + getName());
+ LOG.info("Exception Message: " + e.getLocalizedMessage());
LinkCheckResult lcr = new LinkCheckResult();
lcr.setStatus("PARSE FAILURE");
lcr.setTarget("N/A");
@@ -179,7 +178,7 @@
{
String href = (String) iter.next();
- //System.out.println("Link Found: " + href);
+ LOG.debug("Link Found: " + href);
LinkCheckResult lcr = new LinkCheckResult();
@@ -189,21 +188,24 @@
switch (result.getStatus())
{
- case LinkValidationResult.UNKNOWN :
- unsuccessful++;
- lcr.setStatus("UNKNOWN REF");
- break;
case LinkValidationResult.VALID :
successful++;
lcr.setStatus("OK");
+ this.links.add(lcr); //At some point we won't want to store valid links. The tests require that we do at present
+ break;
+ case LinkValidationResult.UNKNOWN :
+ unsuccessful++;
+ lcr.setStatus("UNKNOWN REF");
+ this.links.add(lcr);
break;
case LinkValidationResult.INVALID :
unsuccessful++;
lcr.setStatus("NOT FOUND");
+ this.links.add(lcr);
break;
}
- this.links.add(lcr);
+
}
}
catch (Exception e)
1.10 +11 -12 maven/src/plugins-build/linkcheck/src/main/org/apache/maven/linkcheck/LinkCheck.java
Index: LinkCheck.java
===================================================================
RCS file: /home/cvs/maven/src/plugins-build/linkcheck/src/main/org/apache/maven/linkcheck/LinkCheck.java,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- LinkCheck.java 17 Apr 2003 12:58:33 -0000 1.9
+++ LinkCheck.java 13 Sep 2003 21:48:08 -0000 1.10
@@ -86,12 +86,10 @@
/** Log */
private static final Log LOG = LogFactory.getLog(LinkCheck.class);
- /**
- * Output file for xml document
- */
+ /** Output file for xml document */
private File output;
- /** output encoding for the xml document */
+ /** Output encoding for the xml document */
private String outputEncoding;
private File baseDir;
@@ -134,21 +132,21 @@
* @throws UnsupportedEncodingException if the underlying platform doesn't
* support ISO-8859-1 encoding
*/
- List filesToCheck = null; //of FileToCheck
+ private List filesToCheck = null; //of FileToCheck
public void doExecute() throws Exception
{
-
-
if (output == null)
{
throw new NullPointerException("output must be set");
}
- LinkValidatorManager lvm = getLinkValidatorManager();
+ LinkValidatorManager validator = getLinkValidatorManager();
filesToCheck = new ArrayList();
- lvm.loadCache(cache);
+ validator.loadCache(cache);
List files = new ArrayList();
+ LOG.debug("Locating all files to be checked...");
findFiles(files, baseDir);
+ LOG.debug("Located all files to be checked.");
Iterator fileIter = files.iterator();
while (fileIter.hasNext())
{
@@ -156,7 +154,8 @@
try
{
filesToCheck.add(flc);
- flc.check(lvm);
+ LOG.info("Validating " + flc.getName());
+ flc.check(validator);
}
catch (Exception e)
{
@@ -165,7 +164,7 @@
}
createDocument(files);
- lvm.saveCache(cache);
+ validator.saveCache(cache);
}
public List getFiles()
1.4 +6 -1 maven/src/plugins-build/linkcheck/src/main/org/apache/maven/linkcheck/LinkCheckResult.java
Index: LinkCheckResult.java
===================================================================
RCS file: /home/cvs/maven/src/plugins-build/linkcheck/src/main/org/apache/maven/linkcheck/LinkCheckResult.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- LinkCheckResult.java 3 Feb 2003 14:13:54 -0000 1.3
+++ LinkCheckResult.java 13 Sep 2003 21:48:08 -0000 1.4
@@ -104,6 +104,10 @@
this.target = target;
}
+ /**
+ * Creates an XML representation of this link check result
+ * @return xml fragment representation of this result
+ */
public String toXML()
{
StringBuffer buf = new StringBuffer();
@@ -112,6 +116,7 @@
buf.append(" <target>" + XmlUtils.escapeXml(getTarget()) + "</target>\n");
buf.append(" <status>" + getStatus() + "</status>\n");
buf.append(" </result>\n");
+
return buf.toString();
}
1.3 +0 -6 maven/src/plugins-build/linkcheck/src/plugin-resources/linkcheck-temp.xml
Index: linkcheck-temp.xml
===================================================================
RCS file: /home/cvs/maven/src/plugins-build/linkcheck/src/plugin-resources/linkcheck-temp.xml,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- linkcheck-temp.xml 4 Feb 2003 06:37:34 -0000 1.2
+++ linkcheck-temp.xml 13 Sep 2003 21:48:08 -0000 1.3
@@ -10,12 +10,6 @@
<p>
This file is used as a placeholder until the final link check can occur.
</p>
-
- <p>
- At present, you MUST set maven.linkcheck.enable=true in your project properties
- to have the linkchecker run. Once it has stabilised, it will be turned on by default
- (except in offline mode).
- </p>
</section>
</body>
</document>
1.31 +2 -2 maven/src/plugins-build/linkcheck/project.xml
Index: project.xml
===================================================================
RCS file: /home/cvs/maven/src/plugins-build/linkcheck/project.xml,v
retrieving revision 1.30
retrieving revision 1.31
diff -u -r1.30 -r1.31
--- project.xml 6 Sep 2003 07:28:55 -0000 1.30
+++ project.xml 13 Sep 2003 21:48:08 -0000 1.31
@@ -39,7 +39,7 @@
</dependency>
<dependency>
<id>commons-httpclient</id>
- <version>2.0-alpha3</version>
+ <version>2.0-rc1</version>
</dependency>
<dependency>
<id>commons-jelly</id>
@@ -132,7 +132,7 @@
</dependency>
<dependency>
<id>werkz</id>
- <version>1.0-beta-7</version>
+ <version>1.0-beta-10</version>
<url>http://werkz.sourceforge.net/</url>
<properties>
<classloader>root.maven</classloader>
1.2 +2 -0 maven/src/plugins-build/linkcheck/.cvsignore
Index: .cvsignore
===================================================================
RCS file: /home/cvs/maven/src/plugins-build/linkcheck/.cvsignore,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- .cvsignore 30 Jan 2003 10:59:05 -0000 1.1
+++ .cvsignore 13 Sep 2003 21:48:08 -0000 1.2
@@ -1,3 +1,5 @@
target
velocity.log
maven.log
+.classpath
+.project
1.4 +0 -11 maven/src/plugins-build/linkcheck/maven.xml
Index: maven.xml
===================================================================
RCS file: /home/cvs/maven/src/plugins-build/linkcheck/maven.xml,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- maven.xml 31 Jul 2003 05:39:57 -0000 1.3
+++ maven.xml 13 Sep 2003 21:48:08 -0000 1.4
@@ -1,14 +1,3 @@
<project default="jar:jar">
-
-
- <postGoal name="java:compile">
- <copy toDir="target/classes">
- <fileset dir="src/main">
- <includes name="**/*"/>
- <excludes name="**/*.java"/>
- </fileset>
- </copy>
- </postGoal>
-
</project>
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@maven.apache.org
For additional commands, e-mail: dev-help@maven.apache.org