maven-doxia-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ltheu...@apache.org
Subject svn commit: r1002602 - /maven/doxia/doxia-tools/trunk/doxia-linkcheck/src/main/java/org/apache/maven/doxia/linkcheck/DefaultLinkCheck.java
Date Wed, 29 Sep 2010 13:09:26 GMT
Author: ltheussl
Date: Wed Sep 29 13:09:25 2010
New Revision: 1002602

URL: http://svn.apache.org/viewvc?rev=1002602&view=rev
Log:
[DOXIA-412] Linkcheck: Add support for wildcards in excludedPages

Modified:
    maven/doxia/doxia-tools/trunk/doxia-linkcheck/src/main/java/org/apache/maven/doxia/linkcheck/DefaultLinkCheck.java

Modified: maven/doxia/doxia-tools/trunk/doxia-linkcheck/src/main/java/org/apache/maven/doxia/linkcheck/DefaultLinkCheck.java
URL: http://svn.apache.org/viewvc/maven/doxia/doxia-tools/trunk/doxia-linkcheck/src/main/java/org/apache/maven/doxia/linkcheck/DefaultLinkCheck.java?rev=1002602&r1=1002601&r2=1002602&view=diff
==============================================================================
--- maven/doxia/doxia-tools/trunk/doxia-linkcheck/src/main/java/org/apache/maven/doxia/linkcheck/DefaultLinkCheck.java
(original)
+++ maven/doxia/doxia-tools/trunk/doxia-linkcheck/src/main/java/org/apache/maven/doxia/linkcheck/DefaultLinkCheck.java
Wed Sep 29 13:09:25 2010
@@ -20,7 +20,6 @@ package org.apache.maven.doxia.linkcheck
  */
 
 import java.io.File;
-import java.io.FilenameFilter;
 import java.io.IOException;
 import java.io.Writer;
 import java.nio.charset.Charset;
@@ -28,11 +27,11 @@ import java.nio.charset.UnsupportedChars
 import java.util.Arrays;
 import java.util.Iterator;
 import java.util.LinkedList;
-import java.util.Locale;
 import java.util.Set;
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
+
 import org.apache.maven.doxia.linkcheck.model.LinkcheckFile;
 import org.apache.maven.doxia.linkcheck.model.LinkcheckFileResult;
 import org.apache.maven.doxia.linkcheck.model.LinkcheckModel;
@@ -45,6 +44,8 @@ import org.apache.maven.doxia.linkcheck.
 import org.apache.maven.doxia.linkcheck.validation.MailtoLinkValidator;
 import org.apache.maven.doxia.linkcheck.validation.OfflineHTTPLinkValidator;
 import org.apache.maven.doxia.linkcheck.validation.OnlineHTTPLinkValidator;
+
+import org.codehaus.plexus.util.FileUtils;
 import org.codehaus.plexus.util.IOUtil;
 import org.codehaus.plexus.util.ReaderFactory;
 import org.codehaus.plexus.util.StringUtils;
@@ -67,9 +68,6 @@ public final class DefaultLinkCheck
     /** Log. */
     private static final Log LOG = LogFactory.getLog( DefaultLinkCheck.class );
 
-    /** FilenameFilter. */
-    private static final FilenameFilter CUSTOM_FF = new DefaultLinkCheck.CustomFilenameFilter();
-
     /** One MegaByte. */
     private static final long MEG = 1024 * 1024;
 
@@ -229,7 +227,14 @@ public final class DefaultLinkCheck
 
         LOG.info( "Begin to check links in files..." );
 
-        findAndCheckFiles( this.basedir, model );
+        try
+        {
+            findAndCheckFiles( this.basedir, model );
+        }
+        catch ( IOException e )
+        {
+            throw new LinkCheckException( "Could not scan base directory: " + basedir.getAbsolutePath(),
e );
+        }
 
         LOG.info( "Links checked." );
 
@@ -292,16 +297,6 @@ public final class DefaultLinkCheck
     }
 
     /**
-     * Get the base directory for the files to be linkchecked.
-     *
-     * @return the base directory
-     */
-    private File getBasedir()
-    {
-        return this.basedir;
-    }
-
-    /**
      * Returns the excluded links.
      * Could contains a link, i.e. <code>http:&#47;&#47;maven.apache.org/</code>,
      * or pattern links i.e. <code>http:&#47;&#47;maven.apache.org&#47;**&#47;*.html</code>
@@ -314,13 +309,30 @@ public final class DefaultLinkCheck
     }
 
     /**
-     * Returns the excluded pages.
+     * Gets the comma separated list of effective exclude patterns.
      *
-     * @return String[]
+     * @return The comma separated list of effective exclude patterns, never <code>null</code>.
      */
-    private String[] getExcludedPages()
+    private String getExcludedPages()
     {
-        return this.excludedPages;
+        LinkedList patternList = new LinkedList( FileUtils.getDefaultExcludesAsList() );
+
+        if ( excludedPages != null )
+        {
+            patternList.addAll( Arrays.asList( excludedPages ) );
+        }
+
+        return StringUtils.join( patternList.iterator(), "," );
+    }
+
+    /**
+     * Gets the comma separated list of effective include patterns.
+     *
+     * @return The comma separated list of effective include patterns, never <code>null</code>.
+     */
+    private String getIncludedPages()
+    {
+        return "**/*.html,**/*.htm";
     }
 
     /**
@@ -346,16 +358,6 @@ public final class DefaultLinkCheck
     }
 
     /**
-     * Sets the LinkValidatorManager.
-     *
-     * @param validator the LinkValidatorManager to set
-     */
-    private void setLinkValidatorManager( LinkValidatorManager validator )
-    {
-        this.lvm = validator;
-    }
-
-    /**
      * Returns the LinkValidatorManager.
      * If this hasn't been set before with {@link #setLinkValidatorManager(LinkValidatorManager)}
      * a default LinkValidatorManager will be returned.
@@ -412,77 +414,44 @@ public final class DefaultLinkCheck
      * @param base the base directory to traverse.
      */
     private void findAndCheckFiles( File base, LinkcheckModel model )
+        throws IOException
     {
-        File[] f = base.listFiles( CUSTOM_FF );
+        Iterator files = FileUtils.getFiles( base, getIncludedPages(), getExcludedPages()
).iterator();
 
-        if ( f != null )
+        while( files.hasNext() )
         {
-            File file;
-            for ( int i = 0; i < f.length; i++ )
-            {
-                file = f[i];
-
-                if ( file.isDirectory() )
-                {
-                    findAndCheckFiles( file, model );
-                }
-                else
-                {
-                    if ( LOG.isDebugEnabled() )
-                    {
-                        LOG.debug( " File - " + file );
-                    }
-
-                    if ( getExcludedPages() != null )
-                    {
-                        String diff =
-                            StringUtils.difference( getBasedir().getAbsolutePath(), file.getAbsolutePath()
);
-                        if ( diff.startsWith( File.separator ) )
-                        {
-                            diff = diff.substring( 1 );
-                        }
+            checkFile( (File) files.next(), model );
+        }
+    }
 
-                        if ( Arrays.binarySearch( getExcludedPages(), diff ) >= 0 )
-                        {
-                            if ( LOG.isDebugEnabled() )
-                            {
-                                LOG.debug( " Ignored analysis of " + file );
-                            }
+    private void checkFile( File file, LinkcheckModel model )
+    {
+        if ( LOG.isDebugEnabled() )
+        {
+            LOG.debug( " File - " + file );
+        }
 
-                            continue;
-                        }
-                    }
+        String fileRelativePath = file.getAbsolutePath();
 
-                    String fileRelativePath = file.getAbsolutePath();
-                    if ( fileRelativePath.startsWith( this.basedir.getAbsolutePath() ) )
-                    {
-                        fileRelativePath =
-                            fileRelativePath.substring( this.basedir.getAbsolutePath().length()
+ 1 );
-                    }
-                    fileRelativePath = fileRelativePath.replace( '\\', '/' );
+        if ( fileRelativePath.startsWith( this.basedir.getAbsolutePath() ) )
+        {
+            fileRelativePath = fileRelativePath.substring( this.basedir.getAbsolutePath().length()
+ 1 );
+        }
 
-                    LinkcheckFile linkcheckFile = new LinkcheckFile();
-                    linkcheckFile.setAbsolutePath( file.getAbsolutePath() );
-                    linkcheckFile.setRelativePath( fileRelativePath );
+        fileRelativePath = fileRelativePath.replace( '\\', '/' );
 
-                    check( linkcheckFile );
+        LinkcheckFile linkcheckFile = new LinkcheckFile();
+        linkcheckFile.setAbsolutePath( file.getAbsolutePath() );
+        linkcheckFile.setRelativePath( fileRelativePath );
 
-                    model.addFile( linkcheckFile );
+        check( linkcheckFile );
 
-                    if ( model.getFiles().size() % 100 == 0 )
-                    {
-                        if ( LOG.isInfoEnabled() )
-                        {
-                            LOG.info( "Found " + model.getFiles().size() + " files so far."
);
-                        }
-                    }
-                }
-            }
+        model.addFile( linkcheckFile );
 
-            file = null;
+        if ( ( model.getFiles().size() % 100 == 0 ) && LOG.isInfoEnabled() )
+        {
+            LOG.info( "Found " + model.getFiles().size() + " files so far." );
         }
-
-        f = null;
     }
 
     /**
@@ -697,28 +666,4 @@ public final class DefaultLinkCheck
         }
         return result;
     }
-
-    /** Custom FilenameFilter used to search html files */
-    static class CustomFilenameFilter
-        implements FilenameFilter
-    {
-        /** {@inheritDoc} */
-        public boolean accept( File dir, String name )
-        {
-            File n = new File( dir, name );
-
-            if ( n.isDirectory() )
-            {
-                return true;
-            }
-
-            if ( name.toLowerCase( Locale.ENGLISH ).endsWith( ".html" )
-                || name.toLowerCase( Locale.ENGLISH ).endsWith( ".htm" ) )
-            {
-                return true;
-            }
-
-            return false;
-        }
-    }
 }



Mime
View raw message