You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by rf...@apache.org on 2019/04/29 18:48:27 UTC

[maven-javadoc-plugin] branch MJAVADOC-539 created (now 58c0c6d)

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

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


      at 58c0c6d  [MJAVADOC-539] Strip index.html from redirect URLs

This branch includes the following new commits:

     new 58c0c6d  [MJAVADOC-539] Strip index.html from redirect URLs

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-539] Strip index.html from redirect URLs

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

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

commit 58c0c6da6f23df9f48b319734dd87b1ce5106fd1
Author: rfscholte <rf...@apache.org>
AuthorDate: Mon Apr 29 20:48:25 2019 +0200

    [MJAVADOC-539] Strip index.html from redirect URLs
---
 pom.xml                                            |  3 +++
 .../apache/maven/plugins/javadoc/JavadocUtil.java  | 29 +++++++++++++++++++++-
 2 files changed, 31 insertions(+), 1 deletion(-)

diff --git a/pom.xml b/pom.xml
index 4d81bb9..6f22e87 100644
--- a/pom.xml
+++ b/pom.xml
@@ -119,6 +119,9 @@ under the License.
     <contributor>
       <name>Michael Stumpf</name>
     </contributor>
+    <contributor>
+      <name>Julian Reschke</name>
+    </contributor>
   </contributors>
 
   <dependencies>
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 636bf32..7767b31 100644
--- a/src/main/java/org/apache/maven/plugins/javadoc/JavadocUtil.java
+++ b/src/main/java/org/apache/maven/plugins/javadoc/JavadocUtil.java
@@ -32,6 +32,7 @@ import java.io.UnsupportedEncodingException;
 import java.lang.reflect.Modifier;
 import java.net.SocketTimeoutException;
 import java.net.URI;
+import java.net.URISyntaxException;
 import java.net.URL;
 import java.net.URLClassLoader;
 import java.nio.charset.Charset;
@@ -1554,7 +1555,33 @@ public class JavadocUtil
             }
 
             List<URI> redirects = httpContext.getRedirectLocations();
-            return isEmpty( redirects ) ? url : redirects.get( redirects.size() - 1 ).toURL();
+
+            if ( isEmpty( redirects ) )
+            {
+                return url;
+            }
+            else
+            {
+                URI last = redirects.get( redirects.size() - 1 );
+
+                // URI must refer to directory, so prevent redirects to index.html
+                // see https://issues.apache.org/jira/browse/MJAVADOC-539
+                String truncate = "index.html";
+                if ( last.getPath().endsWith( "/" + truncate ) )
+                {
+                    try
+                    {
+                        String fixedPath = last.getPath().substring( 0, last.getPath().length() - truncate.length() );
+                        last = new URI( last.getScheme(), last.getAuthority(), fixedPath, last.getQuery(),
+                                last.getFragment() );
+                    }
+                    catch ( URISyntaxException ex )
+                    {
+                        // not supposed to happen, but when it does just keep the last URI
+                    }
+                }
+                return last.toURL();
+            }
         }
     }