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 14:46:01 UTC

[maven-javadoc-plugin] branch MJAVADOC-527 created (now a93b279)

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.


      at a93b279  [MJAVADOC-527] - detectLinks may pass invalid urls to javadoc

This branch includes the following new commits:

     new a93b279  [MJAVADOC-527] - detectLinks may pass invalid urls to javadoc

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.



[maven-javadoc-plugin] 01/01: [MJAVADOC-527] - detectLinks may pass invalid urls to javadoc

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 a93b27970e0d2df4781b16b827bf7f16f46e20e4
Author: dedabob <de...@users.noreply.github.com>
AuthorDate: Mon Jun 11 11:28:31 2018 +0200

    [MJAVADOC-527] - detectLinks may pass invalid urls to javadoc
---
 .../apache/maven/plugins/javadoc/JavadocUtil.java  | 25 ++++++++++++++++++++--
 .../plugins/javadoc/AbstractJavadocMojoTest.java   | 11 ++++++++++
 2 files changed, 34 insertions(+), 2 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..7b21981 100644
--- a/src/main/java/org/apache/maven/plugins/javadoc/JavadocUtil.java
+++ b/src/main/java/org/apache/maven/plugins/javadoc/JavadocUtil.java
@@ -33,10 +33,13 @@ import org.apache.http.client.params.CookiePolicy;
 import org.apache.http.client.protocol.HttpClientContext;
 import org.apache.http.conn.params.ConnRoutePNames;
 import org.apache.http.impl.client.DefaultHttpClient;
+import org.apache.http.impl.client.RedirectLocations;
 import org.apache.http.impl.conn.PoolingClientConnectionManager;
 import org.apache.http.message.BasicHeader;
 import org.apache.http.params.CoreConnectionPNames;
 import org.apache.http.params.CoreProtocolPNames;
+import org.apache.http.protocol.BasicHttpContext;
+import org.apache.http.protocol.HttpContext;
 import org.apache.maven.plugin.logging.Log;
 import org.apache.maven.project.MavenProject;
 import org.apache.maven.settings.Proxy;
@@ -1679,14 +1682,15 @@ public class JavadocUtil
             final HttpGet httpMethod = new HttpGet( url.toString() );
             
             HttpResponse response;
+            HttpContext context = new BasicHttpContext();
             try
             {
-                response = httpClient.execute( httpMethod );
+                response = httpClient.execute( httpMethod, context );
             }
             catch ( SocketTimeoutException e )
             {
                 // could be a sporadic failure, one more retry before we give up
-                response = httpClient.execute( httpMethod );
+                response = httpClient.execute( httpMethod, context );
             }
 
             int status = response.getStatusLine().getStatusCode();
@@ -1695,6 +1699,23 @@ public class JavadocUtil
                 throw new FileNotFoundException( "Unexpected HTTP status code " + status + " getting resource "
                     + url.toExternalForm() + "." );
             }
+            else
+            {
+                int pos = url.getPath().lastIndexOf( '/' );
+                RedirectLocations redirects = (RedirectLocations)
+                        context.getAttribute( "http.protocol.redirect-locations" );
+                if ( pos >= 0 && redirects != null )
+                {
+                    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.toURL().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() ) ) 
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..83dbb3d 100644
--- a/src/test/java/org/apache/maven/plugins/javadoc/AbstractJavadocMojoTest.java
+++ b/src/test/java/org/apache/maven/plugins/javadoc/AbstractJavadocMojoTest.java
@@ -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 ) );
+    }
 }