You are viewing a plain text version of this content. The canonical link for it is here.
Posted to doxia-commits@maven.apache.org by vs...@apache.org on 2008/11/01 15:21:42 UTC

svn commit: r709699 - in /maven/doxia/doxia-tools/trunk/doxia-linkcheck/src/main/java/org/apache/maven/doxia/linkcheck: DefaultLinkCheck.java LinkCheck.java LinkCheckException.java validation/LinkValidatorManager.java

Author: vsiveton
Date: Sat Nov  1 07:21:40 2008
New Revision: 709699

URL: http://svn.apache.org/viewvc?rev=709699&view=rev
Log:
o added a new exception class to encapsulate Linkcheck exception
o review IOExceptions

Added:
    maven/doxia/doxia-tools/trunk/doxia-linkcheck/src/main/java/org/apache/maven/doxia/linkcheck/LinkCheckException.java   (with props)
Modified:
    maven/doxia/doxia-tools/trunk/doxia-linkcheck/src/main/java/org/apache/maven/doxia/linkcheck/DefaultLinkCheck.java
    maven/doxia/doxia-tools/trunk/doxia-linkcheck/src/main/java/org/apache/maven/doxia/linkcheck/LinkCheck.java
    maven/doxia/doxia-tools/trunk/doxia-linkcheck/src/main/java/org/apache/maven/doxia/linkcheck/validation/LinkValidatorManager.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=709699&r1=709698&r2=709699&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 Sat Nov  1 07:21:40 2008
@@ -198,6 +198,7 @@
 
     /** {@inheritDoc} */
     public LinkcheckModel execute()
+        throws LinkCheckException
     {
         if ( this.basedir == null )
         {
@@ -224,7 +225,14 @@
         displayMemoryConsumption();
 
         LinkValidatorManager validator = getLinkValidatorManager();
-        validator.loadCache( this.linkCheckCache );
+        try
+        {
+            validator.loadCache( this.linkCheckCache );
+        }
+        catch ( IOException e )
+        {
+            throw new LinkCheckException( "Could not load cache: " + e.getMessage(), e );
+        }
 
         displayMemoryConsumption();
 
@@ -246,16 +254,19 @@
         {
             createDocument();
         }
-        catch ( Exception e )
+        catch ( IOException e )
         {
-            if ( LOG.isErrorEnabled() )
-            {
-                LOG.error( "Could not write to output file. Maybe try to specify an other encoding instead of '"
-                    + encoding + "'.", e );
-            }
+            throw new LinkCheckException( "Could not write the linkcheck document: " + e.getMessage(), e );
         }
 
-        validator.saveCache( this.linkCheckCache );
+        try
+        {
+            validator.saveCache( this.linkCheckCache );
+        }
+        catch ( IOException e )
+        {
+            throw new LinkCheckException( "Could not save cache: " + e.getMessage(), e );
+        }
 
         displayMemoryConsumption();
 
@@ -683,6 +694,14 @@
             writer = WriterFactory.newXmlWriter( this.reportOutput );
             xpp3Writer.write( writer, getModel() );
         }
+        catch ( IllegalStateException e )
+        {
+            IOException ioe =
+                new IOException( e.getMessage() + " Maybe try to specify an other encoding instead of '" + encoding
+                    + "'." );
+            ioe.initCause( e );
+            throw ioe;
+        }
         finally
         {
             IOUtil.close( writer );

Modified: maven/doxia/doxia-tools/trunk/doxia-linkcheck/src/main/java/org/apache/maven/doxia/linkcheck/LinkCheck.java
URL: http://svn.apache.org/viewvc/maven/doxia/doxia-tools/trunk/doxia-linkcheck/src/main/java/org/apache/maven/doxia/linkcheck/LinkCheck.java?rev=709699&r1=709698&r2=709699&view=diff
==============================================================================
--- maven/doxia/doxia-tools/trunk/doxia-linkcheck/src/main/java/org/apache/maven/doxia/linkcheck/LinkCheck.java (original)
+++ maven/doxia/doxia-tools/trunk/doxia-linkcheck/src/main/java/org/apache/maven/doxia/linkcheck/LinkCheck.java Sat Nov  1 07:21:40 2008
@@ -117,11 +117,14 @@
     public void setReportOutputEncoding( String encoding );
 
     /**
-     * Execute the link check.
+     * Execute the link check. The basedir <b>should</b> be set before.
      *
      * @return the analysis in a <code>LinkCheck</code> model.
+     * @throws LinkCheckException if any
+     * @see #setBasedir(File)
      */
-    public LinkcheckModel execute();
+    public LinkcheckModel execute()
+        throws LinkCheckException;
 
     /**
      * Set the encoding to use when processing files.

Added: maven/doxia/doxia-tools/trunk/doxia-linkcheck/src/main/java/org/apache/maven/doxia/linkcheck/LinkCheckException.java
URL: http://svn.apache.org/viewvc/maven/doxia/doxia-tools/trunk/doxia-linkcheck/src/main/java/org/apache/maven/doxia/linkcheck/LinkCheckException.java?rev=709699&view=auto
==============================================================================
--- maven/doxia/doxia-tools/trunk/doxia-linkcheck/src/main/java/org/apache/maven/doxia/linkcheck/LinkCheckException.java (added)
+++ maven/doxia/doxia-tools/trunk/doxia-linkcheck/src/main/java/org/apache/maven/doxia/linkcheck/LinkCheckException.java Sat Nov  1 07:21:40 2008
@@ -0,0 +1,60 @@
+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.
+ */
+
+/**
+ * Encapsulate a Link check exception.
+ *
+ * @author <a href="mailto:vincent.siveton@gmail.com">Vincent Siveton</a>
+ * @version $Id$
+ * @since 1.0
+ */
+public class LinkCheckException
+    extends Exception
+{
+    /** serialVersionUID */
+    private static final long serialVersionUID = -9132581894367552403L;
+
+    /**
+     * Construct a new <code>LinkCheckException</code> with the specified detail message.
+     *
+     * @param message The detailed message.
+     * This can later be retrieved by the <code>Throwable.getMessage()</code> method.
+     */
+    public LinkCheckException( String message )
+    {
+        super( message );
+    }
+
+    /**
+     * Construct a new <code>LinkCheckException</code> with the specified
+     * detail message and cause.
+     *
+     * @param message The detailed message.
+     * This can later be retrieved by the <code>Throwable.getMessage()</code> method.
+     * @param cause the cause. This can be retrieved later by the
+     * <code>Throwable.getCause()</code> method. (A null value is permitted, and indicates
+     * that the cause is nonexistent or unknown.)
+     */
+    public LinkCheckException( String message, Throwable cause )
+    {
+        super( message, cause );
+    }
+}

Propchange: maven/doxia/doxia-tools/trunk/doxia-linkcheck/src/main/java/org/apache/maven/doxia/linkcheck/LinkCheckException.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/doxia/doxia-tools/trunk/doxia-linkcheck/src/main/java/org/apache/maven/doxia/linkcheck/LinkCheckException.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Modified: maven/doxia/doxia-tools/trunk/doxia-linkcheck/src/main/java/org/apache/maven/doxia/linkcheck/validation/LinkValidatorManager.java
URL: http://svn.apache.org/viewvc/maven/doxia/doxia-tools/trunk/doxia-linkcheck/src/main/java/org/apache/maven/doxia/linkcheck/validation/LinkValidatorManager.java?rev=709699&r1=709698&r2=709699&view=diff
==============================================================================
--- maven/doxia/doxia-tools/trunk/doxia-linkcheck/src/main/java/org/apache/maven/doxia/linkcheck/validation/LinkValidatorManager.java (original)
+++ maven/doxia/doxia-tools/trunk/doxia-linkcheck/src/main/java/org/apache/maven/doxia/linkcheck/validation/LinkValidatorManager.java Sat Nov  1 07:21:40 2008
@@ -41,13 +41,16 @@
 import java.util.Map;
 
 /**
+ * A LinkValidator manager which manages validators with a cache.
+ *
  * @author <a href="mailto:bwalding@apache.org">Ben Walding</a>
  * @author <a href="mailto:carlos@apache.org">Carlos Sanchez</a>
  * @author <a href="mailto:aheritier@apache.org">Arnaud Heritier</a>
+ * @author <a href="mailto:vincent.siveton@gmail.com">Vincent Siveton</a>
  * @version $Id$
  */
-
-public class LinkValidatorManager implements Serializable
+public class LinkValidatorManager
+    implements Serializable
 {
     /** serialVersionUID. */
     private static final long serialVersionUID = 2467928182206500945L;
@@ -189,8 +192,10 @@
      *
      * @param cacheFile The cache file.
      * May be null, in which case the request is ignored.
+     * @throws IOException if any
      */
     public void loadCache( File cacheFile )
+        throws IOException
     {
         if ( cacheFile == null )
         {
@@ -210,8 +215,16 @@
             return;
         }
 
-        ObjectInputStream is = null;
+        if ( cacheFile.isDirectory() )
+        {
+            if ( LOG.isDebugEnabled() )
+            {
+                LOG.debug( "Cache file is a directory! Ignoring request to load." );
+            }
+            return;
+        }
 
+        ObjectInputStream is = null;
         try
         {
             is = new ObjectInputStream( new FileInputStream( cacheFile ) );
@@ -237,13 +250,6 @@
                 LOG.error( "Unable to load the cache: " + cacheFile.getAbsolutePath(), e );
             }
         }
-        catch ( IOException t )
-        {
-            if ( LOG.isErrorEnabled() )
-            {
-                LOG.error( "Unable to load the cache: " + cacheFile.getAbsolutePath(), t );
-            }
-        }
         finally
         {
             IOUtil.close( is );
@@ -255,8 +261,10 @@
      *
      * @param cacheFile The name of the cache file.
      * May be null, in which case the request is ignored.
+     * @throws IOException if any
      */
     public void saveCache( File cacheFile )
+        throws IOException
     {
         if ( cacheFile == null )
         {
@@ -267,6 +275,15 @@
             return;
         }
 
+        if ( cacheFile.isDirectory() )
+        {
+            if ( LOG.isDebugEnabled() )
+            {
+                LOG.debug( "Cache file is a directory! Ignoring request to load." );
+            }
+            return;
+        }
+
         // Remove non-persistent items from cache
         Map persistentCache = new HashMap();
 
@@ -291,27 +308,18 @@
         }
 
         File dir = cacheFile.getParentFile();
-
         if ( dir != null )
         {
             dir.mkdirs();
         }
 
         ObjectOutputStream os = null;
-
         try
         {
             os = new ObjectOutputStream( new FileOutputStream( cacheFile ) );
 
             os.writeObject( persistentCache );
         }
-        catch ( IOException e )
-        {
-            if ( LOG.isErrorEnabled() )
-            {
-                LOG.error( "Unable to save the cache: " + cacheFile.getAbsolutePath(), e );
-            }
-        }
         finally
         {
             persistentCache = null;