Author: vsiveton
Date: Tue Jan 29 04:06:29 2008
New Revision: 616277
URL: http://svn.apache.org/viewvc?rev=616277&view=rev
Log:
o added LinkCheck interface and used Plexus
o improved readingness
o updated test case and doc
Added:
maven/sandbox/trunk/doxia/doxia-linkcheck/src/main/java/org/apache/maven/doxia/linkcheck/LinkCheck.java
(with props)
Modified:
maven/sandbox/trunk/doxia/doxia-linkcheck/pom.xml
maven/sandbox/trunk/doxia/doxia-linkcheck/src/main/java/org/apache/maven/doxia/linkcheck/DefaultLinkCheck.java
maven/sandbox/trunk/doxia/doxia-linkcheck/src/site/xdoc/usage.xml
maven/sandbox/trunk/doxia/doxia-linkcheck/src/test/java/org/apache/maven/doxia/linkcheck/LinkCheckTest.java
Modified: maven/sandbox/trunk/doxia/doxia-linkcheck/pom.xml
URL:
http://svn.apache.org/viewvc/maven/sandbox/trunk/doxia/doxia-linkcheck/pom.xml?rev=616277&r1=616276&r2=616277&view=diff
==============================================================================
--- maven/sandbox/trunk/doxia/doxia-linkcheck/pom.xml (original)
+++ maven/sandbox/trunk/doxia/doxia-linkcheck/pom.xml Tue Jan 29 04:06:29 2008
@@ -45,7 +45,12 @@
<version>1.1</version>
</dependency>
- <!-- misc -->
+ <!-- Plexus -->
+ <dependency>
+ <groupId>org.codehaus.plexus</groupId>
+ <artifactId>plexus-container-default</artifactId>
+ <version>1.0-alpha-9</version>
+ </dependency>
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-utils</artifactId>
Modified:
maven/sandbox/trunk/doxia/doxia-linkcheck/src/main/java/org/apache/maven/doxia/linkcheck/DefaultLinkCheck.java
URL:
http://svn.apache.org/viewvc/maven/sandbox/trunk/doxia/doxia-linkcheck/src/main/java/org/apache/maven/doxia/linkcheck/DefaultLinkCheck.java?rev=616277&r1=616276&r2=616277&view=diff
==============================================================================
---
maven/sandbox/trunk/doxia/doxia-linkcheck/src/main/java/org/apache/maven/doxia/linkcheck/DefaultLinkCheck.java
(original)
+++
maven/sandbox/trunk/doxia/doxia-linkcheck/src/main/java/org/apache/maven/doxia/linkcheck/DefaultLinkCheck.java
Tue Jan 29 04:06:29 2008
@@ -54,8 +54,11 @@
* @author <a href="mailto:[EMAIL PROTECTED]">Arnaud Heritier</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Vincent Siveton</a>
* @version $Id$
+ *
+ * @plexus.component role="org.apache.maven.doxia.linkcheck.LinkCheck"
role-hint="default"
*/
public final class DefaultLinkCheck
+ implements LinkCheck
{
/** Log. */
private static final Log LOG = LogFactory.getLog( DefaultLinkCheck.class );
@@ -113,115 +116,163 @@
/** The base URL for links that start with '/'. */
private String baseURL;
- /** The level to report, used in toXML(). */
- private int reportLevel = LinkcheckFileResult.WARNING_LEVEL;
-
/** The linkcheck model */
private LinkcheckModel model = new LinkcheckModel();
- /**
- * The current report level. Defaults to
<code>LinkcheckFileResult#WARNING_LEVEL</code>.
- *
- * @return int
- * @see LinkcheckFileResult#WARNING_LEVEL
- */
- public int getReportLevel()
+ // ----------------------------------------------------------------------
+ // Public methods
+ // ----------------------------------------------------------------------
+
+ /** [EMAIL PROTECTED] */
+ public void setBasedir( File base )
{
- return this.reportLevel;
+ this.basedir = base;
}
- /**
- * Set the report level.
- *
- * @param level the level to set.
- */
- public void setReportLevel( int level )
+ /** [EMAIL PROTECTED] */
+ public void setBaseURL( String url )
{
- this.reportLevel = level;
+ this.baseURL = url;
}
- /**
- * Whether links are checked in online mode.
- *
- * @return online
- */
- public boolean isOnline()
+ /** [EMAIL PROTECTED] */
+ public void setExcludedHttpStatusErrors( int[] excl )
{
- return this.online;
+ this.excludedHttpStatusErrors = excl;
}
- /**
- * Set the online mode.
- *
- * @param onLine online mode.
- */
+ /** [EMAIL PROTECTED] */
+ public void setExcludedHttpStatusWarnings( int[] excl )
+ {
+ this.excludedHttpStatusWarnings = excl;
+ }
+
+ /** [EMAIL PROTECTED] */
+ public void setExcludedLinks( String[] excl )
+ {
+ this.excludedLinks = excl;
+ }
+
+ /** [EMAIL PROTECTED] */
+ public void setExcludedPages( String[] excl )
+ {
+ this.excludedPages = excl;
+ }
+
+ /** [EMAIL PROTECTED] */
+ public void setHttp( HttpBean http )
+ {
+ this.http = http;
+ }
+
+ /** [EMAIL PROTECTED] */
+ public void setLinkCheckCache( File cacheFile )
+ {
+ this.linkCheckCache = cacheFile;
+ }
+
+ /** [EMAIL PROTECTED] */
public void setOnline( boolean onLine )
{
this.online = onLine;
}
- /**
- * Get the base directory for the files to be linkchecked.
- *
- * @return the base directory
- */
- public File getBasedir()
+ /** [EMAIL PROTECTED] */
+ public void setReportOutput( File file )
{
- return this.basedir;
+ this.reportOutput = file;
}
- /**
- * Set the base directory for the files to be linkchecked.
- *
- * @param base the base directory
- */
- public void setBasedir( File base )
+ /** [EMAIL PROTECTED] */
+ public void setReportOutputEncoding( String encoding )
{
- this.basedir = base;
+ this.reportOutputEncoding = encoding;
}
- /**
- * Returns the cache File.
- *
- * @return File
- */
- public File getLinkCheckCache()
+ /** [EMAIL PROTECTED] */
+ public LinkcheckModel execute()
{
- return this.linkCheckCache;
+ if ( this.basedir == null )
+ {
+ LOG.error( "No base directory specified!" );
+
+ throw new NullPointerException( "The basedir can't be null!" );
+ }
+
+ if ( this.reportOutput == null )
+ {
+ LOG.warn( "No output file specified! Results will not be written!"
);
+ }
+
+ model = new LinkcheckModel();
+ model.setModelEncoding( reportOutputEncoding );
+ model.setFiles( new LinkedList() );
+
+ displayMemoryConsumption();
+
+ LinkValidatorManager validator = getLinkValidatorManager();
+ validator.loadCache( this.linkCheckCache );
+
+ displayMemoryConsumption();
+
+ LOG.info( "Begin to check links in files..." );
+
+ findAndCheckFiles( this.basedir );
+
+ LOG.info( "Links checked." );
+
+ displayMemoryConsumption();
+
+ try
+ {
+ createDocument();
+ }
+ catch ( IOException e )
+ {
+ LOG.error( "Could not write to output file, results will be
lost!", e );
+ }
+
+ validator.saveCache( this.linkCheckCache );
+
+ displayMemoryConsumption();
+
+ return model;
}
+ // ----------------------------------------------------------------------
+ // Private methods
+ // ----------------------------------------------------------------------
+
/**
- * Sets the cache File.
+ * Whether links are checked in online mode.
*
- * @param cacheFile The cacheFile to set. Set this to null to ignore
storing the cache.
+ * @return online
*/
- public void setLinkCheckCache( File cacheFile )
+ private boolean isOnline()
{
- this.linkCheckCache = cacheFile;
+ return this.online;
}
/**
- * Returns the excluded links.
- * Could contains a link, i.e.
<code>http://maven.apache.org/</code>,
- * or pattern links i.e.
<code>http://maven.apache.org/**/*.html</code>
+ * Get the base directory for the files to be linkchecked.
*
- * @return String[]
+ * @return the base directory
*/
- public String[] getExcludedLinks()
+ private File getBasedir()
{
- return this.excludedLinks;
+ return this.basedir;
}
/**
- * Sets the excluded links, a String[] with excluded locations.
+ * Returns the excluded links.
* Could contains a link, i.e.
<code>http://maven.apache.org/</code>,
* or pattern links i.e.
<code>http://maven.apache.org/**/*.html</code>
*
- * @param excl The excludes to set
+ * @return String[]
*/
- public void setExcludedLinks( String[] excl )
+ private String[] getExcludedLinks()
{
- this.excludedLinks = excl;
+ return this.excludedLinks;
}
/**
@@ -229,63 +280,41 @@
*
* @return String[]
*/
- public String[] getExcludedPages()
+ private String[] getExcludedPages()
{
return this.excludedPages;
}
/**
- * Sets the excluded pages, a String[] with excluded locations.
- *
- * @param excl The excludes to set
- */
- public void setExcludedPages( String[] excl )
- {
- this.excludedPages = excl;
- }
-
- /**
* Returns the excluded HTTP errors, i.e. <code>404</code>.
*
* @return int[]
* @see [EMAIL PROTECTED] HttpStatus} for all possible values.
*/
- public int[] getExcludedHttpStatusErrors()
+ private int[] getExcludedHttpStatusErrors()
{
return this.excludedHttpStatusErrors;
}
/**
- * Sets the excluded HTTP errors, i.e. <code>404</code>, a int[] with
excluded errors.
- *
- * @param excl The excludes to set
- * @see [EMAIL PROTECTED] HttpStatus} for all possible values.
- */
- public void setExcludedHttpStatusErrors( int[] excl )
- {
- this.excludedHttpStatusErrors = excl;
- }
-
- /**
* Returns the excluded HTTP warnings, i.e. <code>301</code>.
*
* @return int[]
* @see [EMAIL PROTECTED] HttpStatus} for all possible values.
*/
- public int[] getExcludedHttpStatusWarnings()
+ private int[] getExcludedHttpStatusWarnings()
{
return this.excludedHttpStatusWarnings;
}
/**
- * Sets the excluded HTTP warnings, i.e. <code>301</code>, a int[] with
excluded errors.
+ * The model.
*
- * @param excl The excludes to set
- * @see [EMAIL PROTECTED] HttpStatus} for all possible values.
+ * @return the model.
*/
- public void setExcludedHttpStatusWarnings( int[] excl )
+ private LinkcheckModel getModel()
{
- this.excludedHttpStatusWarnings = excl;
+ return model;
}
/**
@@ -293,7 +322,7 @@
*
* @param validator the LinkValidatorManager to set
*/
- public void setLinkValidatorManager( LinkValidatorManager validator )
+ private void setLinkValidatorManager( LinkValidatorManager validator )
{
this.lvm = validator;
}
@@ -305,7 +334,7 @@
*
* @return the LinkValidatorManager
*/
- public LinkValidatorManager getLinkValidatorManager()
+ private LinkValidatorManager getLinkValidatorManager()
{
if ( this.lvm == null )
{
@@ -349,97 +378,6 @@
}
/**
- * Set the output file for the results.
- * If this is null, no output will be written.
- *
- * @param file the output file.
- */
- public void setReportOutput( File file )
- {
- this.reportOutput = file;
- }
-
- /**
- * Returns the output file.
- *
- * @return File
- */
- public File getReportOutput()
- {
- return this.reportOutput;
- }
-
- /**
- * Returns the outputEncoding.
- *
- * @return String
- */
- public String getReportOutputEncoding()
- {
- return this.reportOutputEncoding;
- }
-
- /**
- * Sets the outputEncoding.
- *
- * @param encoding The outputEncoding to set.
- */
- public void setReportOutputEncoding( String encoding )
- {
- this.reportOutputEncoding = encoding;
- }
-
- /**
- * The base URL.
- *
- * @return the base URL.
- */
- public String getBaseURL()
- {
- return this.baseURL;
- }
-
- /**
- * Sets the base URL. This is pre-pended to links that start with '/'.
- *
- * @param url the base URL.
- */
- public void setBaseURL( String url )
- {
- this.baseURL = url;
- }
-
- /**
- * The model.
- *
- * @return the model.
- */
- public LinkcheckModel getModel()
- {
- return model;
- }
-
- /**
- * The http parameters bean.
- *
- * @return the http parameters bean.
- */
- public HttpBean getHttp()
- {
- return http;
- }
-
- /**
- * Sets the http parameters bean.
- *
- * @param http parameters bean.
- */
- public void setHttp( HttpBean http )
- {
- this.http = http;
- }
-
- /**
* Recurses through the given base directory and adds/checks
* files to the model that pass through the current filter.
*
@@ -628,7 +566,6 @@
toStringArray(
getExcludedHttpStatusWarnings() ) ) >= 0 )
{
ignoredWarning = true;
- System.out.println("IGNORED
"+httpResult.getHttpStatusCode());
}
}
@@ -662,56 +599,6 @@
lcr = null;
lvi = null;
result = null;
- }
-
- /**
- * Execute task.
- */
- public void doExecute()
- {
- if ( this.basedir == null )
- {
- LOG.error( "No base directory specified!" );
-
- throw new NullPointerException( "The basedir can't be null!" );
- }
-
- if ( this.reportOutput == null )
- {
- LOG.warn( "No output file specified! Results will not be written!"
);
- }
-
- model = new LinkcheckModel();
- model.setModelEncoding( reportOutputEncoding );
- model.setFiles( new LinkedList() );
-
- displayMemoryConsumption();
-
- LinkValidatorManager validator = getLinkValidatorManager();
- validator.loadCache( this.linkCheckCache );
-
- displayMemoryConsumption();
-
- LOG.info( "Begin to check links in files..." );
-
- findAndCheckFiles( this.basedir );
-
- LOG.info( "Links checked." );
-
- displayMemoryConsumption();
-
- try
- {
- createDocument();
- }
- catch ( IOException e )
- {
- LOG.error( "Could not write to output file, results will be
lost!", e );
- }
-
- validator.saveCache( this.linkCheckCache );
-
- displayMemoryConsumption();
}
/**
Added:
maven/sandbox/trunk/doxia/doxia-linkcheck/src/main/java/org/apache/maven/doxia/linkcheck/LinkCheck.java
URL:
http://svn.apache.org/viewvc/maven/sandbox/trunk/doxia/doxia-linkcheck/src/main/java/org/apache/maven/doxia/linkcheck/LinkCheck.java?rev=616277&view=auto
==============================================================================
---
maven/sandbox/trunk/doxia/doxia-linkcheck/src/main/java/org/apache/maven/doxia/linkcheck/LinkCheck.java
(added)
+++
maven/sandbox/trunk/doxia/doxia-linkcheck/src/main/java/org/apache/maven/doxia/linkcheck/LinkCheck.java
Tue Jan 29 04:06:29 2008
@@ -0,0 +1,126 @@
+package org.apache.maven.doxia.linkcheck;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.io.File;
+
+import org.apache.commons.httpclient.HttpStatus;
+import org.apache.maven.doxia.linkcheck.model.LinkcheckModel;
+
+/**
+ * Tool to check links from html files in a given directory.
+ *
+ * @author <a href="mailto:[EMAIL PROTECTED]">Vincent Siveton</a>
+ * @version $Id$
+ */
+public interface LinkCheck
+{
+ /** Plexus Role */
+ String ROLE = LinkCheck.class.getName();
+
+ /**
+ * Set the base directory for the files to be linkchecked.
+ *
+ * @param base the base directory
+ */
+ public void setBasedir( File base );
+
+ /**
+ * Sets the base URL. This is pre-pended to links that start with '/'.
+ *
+ * @param url the base URL.
+ */
+ public void setBaseURL( String url );
+
+ /**
+ * Sets the excluded HTTP errors, i.e. <code>404</code>, a int[] with
excluded errors.
+ *
+ * @param excl The excludes to set
+ * @see [EMAIL PROTECTED] HttpStatus} for all possible values.
+ */
+ public void setExcludedHttpStatusErrors( int[] excl );
+
+ /**
+ * Sets the excluded HTTP warnings, i.e. <code>301</code>, a int[] with
excluded errors.
+ *
+ * @param excl The excludes to set
+ * @see [EMAIL PROTECTED] HttpStatus} for all possible values.
+ */
+ public void setExcludedHttpStatusWarnings( int[] excl );
+
+ /**
+ * Sets the excluded links, a String[] with excluded locations.
+ * Could contains a link, i.e.
<code>http://maven.apache.org/</code>,
+ * or pattern links i.e.
<code>http://maven.apache.org/**/*.html</code>
+ *
+ * @param excl The excludes to set
+ */
+ public void setExcludedLinks( String[] excl );
+
+ /**
+ * Sets the excluded pages, a String[] with excluded locations.
+ *
+ * @param excl The excludes to set
+ */
+ public void setExcludedPages( String[] excl );
+
+ /**
+ * Sets the http parameters bean.
+ *
+ * @param http parameters bean.
+ */
+ public void setHttp( HttpBean http );
+
+ /**
+ * Sets the cache File.
+ *
+ * @param cacheFile The cacheFile to set. Set this to null to ignore
storing the cache.
+ */
+ public void setLinkCheckCache( File cacheFile );
+
+ /**
+ * Set the online mode.
+ *
+ * @param onLine online mode.
+ */
+ public void setOnline( boolean onLine );
+
+ /**
+ * Set the output file for the results.
+ * If this is null, no output will be written.
+ *
+ * @param file the output file.
+ */
+ public void setReportOutput( File file );
+
+ /**
+ * Sets the outputEncoding.
+ *
+ * @param encoding The outputEncoding to set.
+ */
+ public void setReportOutputEncoding( String encoding );
+
+ /**
+ * Execute the link check.
+ *
+ * @return the analysis in a <code>LinkCheck</code> model.
+ */
+ public LinkcheckModel execute();
+}
Propchange:
maven/sandbox/trunk/doxia/doxia-linkcheck/src/main/java/org/apache/maven/doxia/linkcheck/LinkCheck.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
maven/sandbox/trunk/doxia/doxia-linkcheck/src/main/java/org/apache/maven/doxia/linkcheck/LinkCheck.java
------------------------------------------------------------------------------
svn:keywords = "Author Date Id Revision"
Modified: maven/sandbox/trunk/doxia/doxia-linkcheck/src/site/xdoc/usage.xml
URL:
http://svn.apache.org/viewvc/maven/sandbox/trunk/doxia/doxia-linkcheck/src/site/xdoc/usage.xml?rev=616277&r1=616276&r2=616277&view=diff
==============================================================================
--- maven/sandbox/trunk/doxia/doxia-linkcheck/src/site/xdoc/usage.xml (original)
+++ maven/sandbox/trunk/doxia/doxia-linkcheck/src/site/xdoc/usage.xml Tue Jan
29 04:06:29 2008
@@ -28,11 +28,15 @@
<body>
<section name="Usage">
<p>
- Here's an example:
+ Here's a simple Java example:
</p>
<source>
- LinkCheck lc = new LinkCheck();
+ LinkCheck lc = new DefaultLinkCheck();
+ /*
+ * If you are using Plexus:
+ * LinkCheck lc = (LinkCheck) lookup( LinkCheck.ROLE );
+ */
lc.setOnline( true );
@@ -47,10 +51,9 @@
"http://cvs.apache.org/viewcvs.cgi/maven-pluginszz/",
"http://cvs.apache.org/viewcvs.cgi/mavenzz/"
};
-
lc.setExcludedLinks( excludes );
- lc.doExecute();
+ LinkcheckModel result = lc.execute();
</source>
<p>
Modified:
maven/sandbox/trunk/doxia/doxia-linkcheck/src/test/java/org/apache/maven/doxia/linkcheck/LinkCheckTest.java
URL:
http://svn.apache.org/viewvc/maven/sandbox/trunk/doxia/doxia-linkcheck/src/test/java/org/apache/maven/doxia/linkcheck/LinkCheckTest.java?rev=616277&r1=616276&r2=616277&view=diff
==============================================================================
---
maven/sandbox/trunk/doxia/doxia-linkcheck/src/test/java/org/apache/maven/doxia/linkcheck/LinkCheckTest.java
(original)
+++
maven/sandbox/trunk/doxia/doxia-linkcheck/src/test/java/org/apache/maven/doxia/linkcheck/LinkCheckTest.java
Tue Jan 29 04:06:29 2008
@@ -25,19 +25,25 @@
import java.util.Map;
import org.apache.maven.doxia.linkcheck.model.LinkcheckFile;
-
-import junit.framework.TestCase;
+import org.apache.maven.doxia.linkcheck.model.LinkcheckModel;
+import org.codehaus.plexus.PlexusTestCase;
/**
* @author Ben Walding
* @author <a href="mailto:[EMAIL PROTECTED]">Carlos Sanchez</a>
* @version $Id$
*/
-public class LinkCheckTest extends TestCase
+public class LinkCheckTest
+ extends PlexusTestCase
{
- public void testScan() throws Exception
+ /**
+ * @throws Exception
+ */
+ public void testScan()
+ throws Exception
{
- DefaultLinkCheck lc = new DefaultLinkCheck();
+ LinkCheck lc = (LinkCheck) lookup( LinkCheck.ROLE );
+ assertNotNull( lc );
lc.setOnline( true ); // TODO: check if online
@@ -49,17 +55,15 @@
lc.setLinkCheckCache( new File( "target/linkcheck/linkcheck.cache" )
); // TODO
- String[] excludes = new String[]
- {
- "http://cvs.apache.org/viewcvs.cgi/maven-pluginszz/",
- "http://cvs.apache.org/viewcvs.cgi/mavenzz/"
- };
+ String[] excludes = new String[] {
+ "http://cvs.apache.org/viewcvs.cgi/maven-pluginszz/",
+ "http://cvs.apache.org/viewcvs.cgi/mavenzz/" };
lc.setExcludedLinks( excludes );
- lc.doExecute();
+ LinkcheckModel result = lc.execute();
- Iterator iter = lc.getModel().getFiles().iterator();
+ Iterator iter = result.getFiles().iterator();
Map map = new HashMap();
@@ -69,7 +73,7 @@
map.put( ftc.getRelativePath(), ftc );
}
- assertEquals( "files.size()", 8, lc.getModel().getFiles().size() );
+ assertEquals( "files.size()", 8, result.getFiles().size() );
check( map, "nolink.html", 0 );
check( map, "test-resources/nolink.html", 0 );
@@ -99,5 +103,4 @@
assertEquals( name + ".getResults().size()", linkCount,
ftc.getResults().size() );
}
-
}