You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by jd...@apache.org on 2006/04/21 22:40:21 UTC

svn commit: r395999 - /maven/sandbox/plugins/maven-docck-plugin/src/main/java/org/apache/maven/plugin/docck/AbstractCheckDocumentationMojo.java

Author: jdcasey
Date: Fri Apr 21 13:40:19 2006
New Revision: 395999

URL: http://svn.apache.org/viewcvs?rev=395999&view=rev
Log:
Fixing some problems with license URL handling.

Modified:
    maven/sandbox/plugins/maven-docck-plugin/src/main/java/org/apache/maven/plugin/docck/AbstractCheckDocumentationMojo.java

Modified: maven/sandbox/plugins/maven-docck-plugin/src/main/java/org/apache/maven/plugin/docck/AbstractCheckDocumentationMojo.java
URL: http://svn.apache.org/viewcvs/maven/sandbox/plugins/maven-docck-plugin/src/main/java/org/apache/maven/plugin/docck/AbstractCheckDocumentationMojo.java?rev=395999&r1=395998&r2=395999&view=diff
==============================================================================
--- maven/sandbox/plugins/maven-docck-plugin/src/main/java/org/apache/maven/plugin/docck/AbstractCheckDocumentationMojo.java (original)
+++ maven/sandbox/plugins/maven-docck-plugin/src/main/java/org/apache/maven/plugin/docck/AbstractCheckDocumentationMojo.java Fri Apr 21 13:40:19 2006
@@ -3,6 +3,8 @@
 import java.io.File;
 import java.io.FileWriter;
 import java.io.IOException;
+import java.net.MalformedURLException;
+import java.net.URL;
 import java.util.ArrayList;
 import java.util.Iterator;
 import java.util.LinkedHashMap;
@@ -179,6 +181,8 @@
 
     private List checkProject( MavenProject project )
     {
+        getLog().info( "Checking project: " + project.getName() );
+        
         List errors = new ArrayList();
 
         // check for licenses
@@ -195,33 +199,64 @@
                 License license = (License) it.next();
 
                 String url = license.getUrl();
-
-                HeadMethod headMethod = new HeadMethod( url );
-                headMethod.setFollowRedirects( true );
-                headMethod.setDoAuthentication( false );
-
+                
+                String protocol = null;
+                
                 try
                 {
-                    if ( httpClient.executeMethod( headMethod ) != 200 )
+                    URL licenseUrl = new URL( url );
+                    
+                    protocol = licenseUrl.getProtocol();
+                    
+                    if ( protocol != null )
                     {
-                        errors.add( "Cannot reach license: " + license.getName() + " with URL: \'" + url + "\'." );
+                        protocol = protocol.toLowerCase();
                     }
                 }
-                catch ( HttpException e )
+                catch ( MalformedURLException e )
                 {
-                    errors.add( "Cannot reach license: " + license.getName() + " with URL: \'" + url + "\'.\nError: "
-                        + e.getMessage() );
+                    getLog().debug( "License: " + license.getName() + " with appears to have an invalid URL: \'" + url + "\'.\nError: "
+                                + e.getMessage() + "\n\nTrying to access it as a file instead." );
                 }
-                catch ( IOException e )
+
+                if ( protocol != null && protocol.startsWith( "http" ) )
                 {
-                    errors.add( "Cannot reach license: " + license.getName() + " with URL: \'" + url + "\'.\nError: "
-                        + e.getMessage() );
+                    HeadMethod headMethod = new HeadMethod( url );
+                    headMethod.setFollowRedirects( true );
+                    headMethod.setDoAuthentication( false );
+                    
+                    try
+                    {
+                        if ( httpClient.executeMethod( headMethod ) != 200 )
+                        {
+                            errors.add( "Cannot reach license: " + license.getName() + " with URL: \'" + url + "\'." );
+                        }
+                    }
+                    catch ( HttpException e )
+                    {
+                        errors.add( "Cannot reach license: " + license.getName() + " with URL: \'" + url
+                            + "\'.\nError: " + e.getMessage() );
+                    }
+                    catch ( IOException e )
+                    {
+                        errors.add( "Cannot reach license: " + license.getName() + " with URL: \'" + url
+                            + "\'.\nError: " + e.getMessage() );
+                    }
+                    finally
+                    {
+                        if ( headMethod != null )
+                        {
+                            headMethod.releaseConnection();
+                        }
+                    }
                 }
-                finally
+                else
                 {
-                    if ( headMethod != null )
+                    // try looking for the file.
+                    File licenseFile = new File( url );
+                    if ( !licenseFile.exists() )
                     {
-                        headMethod.releaseConnection();
+                        errors.add( "License file: \'" + licenseFile.getPath() + " does not exist." );
                     }
                 }
             }