You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by mi...@apache.org on 2019/01/04 17:24:57 UTC

[maven-javadoc-plugin] branch MJAVADOC-527 updated (d9e037f -> 34fccfb)

This is an automated email from the ASF dual-hosted git repository.

michaelo pushed a change to branch MJAVADOC-527
in repository https://gitbox.apache.org/repos/asf/maven-javadoc-plugin.git.


 discard d9e037f  [MJAVADOC-527] detectLinks may pass invalid URLs to javadoc(1)
     new 34fccfb  [MJAVADOC-527] detectLinks may pass invalid URLs to javadoc(1)

This update added new revisions after undoing existing revisions.
That is to say, some revisions that were in the old version of the
branch are not in the new version.  This situation occurs
when a user --force pushes a change and generates a repository
containing something like this:

 * -- * -- B -- O -- O -- O   (d9e037f)
            \
             N -- N -- N   refs/heads/MJAVADOC-527 (34fccfb)

You should already have received notification emails for all of the O
revisions, and so the following emails describe only the N revisions
from the common base, B.

Any revisions marked "omit" are not gone; other references still
refer to them.  Any revisions marked "discard" are gone forever.

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:


[maven-javadoc-plugin] 01/01: [MJAVADOC-527] detectLinks may pass invalid URLs to javadoc(1)

Posted by mi...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

michaelo pushed a commit to branch MJAVADOC-527
in repository https://gitbox.apache.org/repos/asf/maven-javadoc-plugin.git

commit 34fccfb151ba0603556d57e1972ac897bce05a5e
Author: Roberto Benedetti <de...@users.noreply.github.com>
AuthorDate: Mon Jun 11 11:28:31 2018 +0200

    [MJAVADOC-527] detectLinks may pass invalid URLs to javadoc(1)
    
    This closes #4
---
 .../apache/maven/plugins/javadoc/JavadocUtil.java  | 63 ++++++++++++++--------
 .../plugins/javadoc/AbstractJavadocMojoTest.java   | 15 +++++-
 2 files changed, 53 insertions(+), 25 deletions(-)

diff --git a/src/main/java/org/apache/maven/plugins/javadoc/JavadocUtil.java b/src/main/java/org/apache/maven/plugins/javadoc/JavadocUtil.java
index e2f9b26..8c4f4f9 100644
--- a/src/main/java/org/apache/maven/plugins/javadoc/JavadocUtil.java
+++ b/src/main/java/org/apache/maven/plugins/javadoc/JavadocUtil.java
@@ -127,7 +127,7 @@ public class JavadocUtil
     public static Collection<Path> pruneDirs( MavenProject project, Collection<String> dirs )
     {
         final Path projectBasedir = project.getBasedir().toPath();
-        
+
         Set<Path> pruned = new LinkedHashSet<>( dirs.size() );
         for ( String dir : dirs )
         {
@@ -171,7 +171,7 @@ public class JavadocUtil
     /**
      * Determine whether a file should be excluded from the provided list of paths, based on whether it exists and is
      * already present in the list.
-     * 
+     *
      * @param f The files.
      * @param pruned The list of pruned files..
      * @return true if the file could be pruned false otherwise.
@@ -343,7 +343,7 @@ public class JavadocUtil
                                                     Collection<String> excludePackages )
     {
         List<String> files = new ArrayList<>();
-        
+
         List<Pattern> excludePackagePatterns = new ArrayList<>( excludePackages.size() );
         for ( String excludePackage :  excludePackages )
         {
@@ -365,7 +365,7 @@ public class JavadocUtil
                     break;
                 }
             }
-            
+
             if ( !excluded )
             {
                 files.add( file );
@@ -387,9 +387,9 @@ public class JavadocUtil
                                                              Collection<String> excludePackagenames )
     {
         final String regexFileSeparator = File.separator.replace( "\\", "\\\\" );
-        
+
         final Collection<String> fileList = new ArrayList<>();
-        
+
         try
         {
             Files.walkFileTree( sourceDirectory, new SimpleFileVisitor<Path>()
@@ -414,15 +414,15 @@ public class JavadocUtil
         List<String> files = new ArrayList<>();
         for ( String excludePackagename : excludePackagenames )
         {
-            // Usage of wildcard was bad specified and bad implemented, i.e. using String.contains() 
+            // Usage of wildcard was bad specified and bad implemented, i.e. using String.contains()
             //   without respecting surrounding context
-            // Following implementation should match requirements as defined in the examples:  
+            // Following implementation should match requirements as defined in the examples:
             // - A wildcard at the beginning should match 1 or more folders
             // - Any other wildcard must match exactly one folder
             Pattern p = Pattern.compile( excludePackagename.replace( ".", regexFileSeparator )
                                                            .replaceFirst( "^\\*", ".+" )
                                                            .replace( "*", "[^" + regexFileSeparator + "]+" ) );
-            
+
             for ( String aFileList : fileList )
             {
                 if ( p.matcher( aFileList ).matches() )
@@ -476,7 +476,7 @@ public class JavadocUtil
 
     /**
      * Call the Javadoc tool and parse its output to find its version, i.e.:
-     * 
+     *
      * <pre>
      * javadoc.exe( or.sh ) - J - version
      * </pre>
@@ -945,7 +945,7 @@ public class JavadocUtil
 
     /**
      * Split the given path with colon and semi-colon, to support Solaris and Windows path. Examples:
-     * 
+     *
      * <pre>
      * splitPath( "/home:/tmp" )     = ["/home", "/tmp"]
      * splitPath( "/home;/tmp" )     = ["/home", "/tmp"]
@@ -977,7 +977,7 @@ public class JavadocUtil
 
     /**
      * Unify the given path with the current System path separator, to be platform independent. Examples:
-     * 
+     *
      * <pre>
      * unifyPathSeparator( "/home:/tmp" ) = "/home:/tmp" (Solaris box)
      * unifyPathSeparator( "/home:/tmp" ) = "/home;/tmp" (Windows box)
@@ -1425,7 +1425,7 @@ public class JavadocUtil
 
     /**
      * Ignores line like 'Picked up JAVA_TOOL_OPTIONS: ...' as can happen on CI servers.
-     * 
+     *
      * @author Robert Scholte
      * @since 3.0.1
      */
@@ -1632,7 +1632,7 @@ public class JavadocUtil
             return true;
         }
     }
-    
+
     protected static boolean isValidElementList( URL url, Settings settings, boolean validateContent )
                     throws IOException
     {
@@ -1651,7 +1651,7 @@ public class JavadocUtil
                     {
                         continue;
                     }
-                        
+
                     if ( !isValidPackageName( line ) )
                     {
                         return false;
@@ -1661,11 +1661,11 @@ public class JavadocUtil
             return true;
         }
     }
-    
+
     private static BufferedReader getReader( URL url, Settings settings ) throws IOException
     {
         BufferedReader reader = null;
-        
+
         if ( "file".equals( url.getProtocol() ) )
         {
             // Intentionally using the platform default encoding here since this is what Javadoc uses internally.
@@ -1677,16 +1677,17 @@ public class JavadocUtil
             final HttpClient httpClient = createHttpClient( settings, url );
 
             final HttpGet httpMethod = new HttpGet( url.toString() );
-            
+
             HttpResponse response;
+            HttpClientContext httpContext = HttpClientContext.create();
             try
             {
-                response = httpClient.execute( httpMethod );
+                response = httpClient.execute( httpMethod, httpContext );
             }
             catch ( SocketTimeoutException e )
             {
                 // could be a sporadic failure, one more retry before we give up
-                response = httpClient.execute( httpMethod );
+                response = httpClient.execute( httpMethod, httpContext );
             }
 
             int status = response.getStatusLine().getStatusCode();
@@ -1695,16 +1696,32 @@ public class JavadocUtil
                 throw new FileNotFoundException( "Unexpected HTTP status code " + status + " getting resource "
                     + url.toExternalForm() + "." );
             }
+            else
+            {
+                int pos = url.getPath().lastIndexOf( '/' );
+                List<URI> redirects = httpContext.getRedirectLocations();
+                if ( pos >= 0 && isNotEmpty( redirects ) )
+                {
+                    URI location = redirects.get( redirects.size() - 1 );
+                    String suffix = url.getPath().substring( pos );
+                    // Redirections shall point to the same file, e.g. /package-list
+                    if ( !location.getPath().endsWith( suffix ) )
+                    {
+                        throw new FileNotFoundException( url.toExternalForm() + " redirects to "
+                                + location.toURL().toExternalForm() + "." );
+                    }
+                }
+            }
 
             // Intentionally using the platform default encoding here since this is what Javadoc uses internally.
-            reader = new BufferedReader( new InputStreamReader( response.getEntity().getContent() ) ) 
+            reader = new BufferedReader( new InputStreamReader( response.getEntity().getContent() ) )
             {
                 @Override
                 public void close()
                     throws IOException
                 {
                     super.close();
-                    
+
                     if ( httpMethod != null )
                     {
                         httpMethod.releaseConnection();
@@ -1716,7 +1733,7 @@ public class JavadocUtil
                 }
             };
         }
-        
+
         return reader;
     }
 
diff --git a/src/test/java/org/apache/maven/plugins/javadoc/AbstractJavadocMojoTest.java b/src/test/java/org/apache/maven/plugins/javadoc/AbstractJavadocMojoTest.java
index 56988f7..1432492 100644
--- a/src/test/java/org/apache/maven/plugins/javadoc/AbstractJavadocMojoTest.java
+++ b/src/test/java/org/apache/maven/plugins/javadoc/AbstractJavadocMojoTest.java
@@ -39,7 +39,7 @@ public class AbstractJavadocMojoTest
     extends TestCase
 {
     AbstractJavadocMojo mojo;
-    
+
     @Override
     protected void setUp()
         throws Exception
@@ -54,7 +54,7 @@ public class AbstractJavadocMojoTest
             }
         };
     }
-    
+
     public void testMJAVADOC432_DetectLinksMessages()
     {
         Log log = mock( Log.class );
@@ -76,4 +76,15 @@ public class AbstractJavadocMojoTest
         verify( log, times( 4 ) ).error( anyString() );
         verify( log, times( 4 ) ).warn( anyString() ); // no extra warnings
     }
+
+    public void testMJAVADOC527_DetectLinksRecursion()
+    {
+        Log log = mock( Log.class );
+        when( log.isErrorEnabled() ).thenReturn( true );
+        mojo.setLog( log );
+        mojo.outputDirectory = new File( "target/test-classes" );
+
+        assertFalse( mojo.isValidJavadocLink( "http://javamail.java.net/mailapi/apidocs", false ) );
+        assertTrue( mojo.isValidJavadocLink( "http://commons.apache.org/proper/commons-lang/apidocs", false ) );
+    }
 }