8038976: javadoc requires a trailing / for links where java 7's javadoc didn't
authorksrini
Wed, 16 Apr 2014 19:21:59 -0700
changeset 23974 d53628eda3d1
parent 23973 4b5f3a297142
child 23975 c7c81595aea9
8038976: javadoc requires a trailing / for links where java 7's javadoc didn't Reviewed-by: jjg
langtools/src/share/classes/com/sun/tools/doclets/internal/toolkit/util/Extern.java
langtools/test/com/sun/javadoc/testLinkOption/TestLinkOption.java
--- a/langtools/src/share/classes/com/sun/tools/doclets/internal/toolkit/util/Extern.java	Wed Apr 16 18:15:48 2014 -0700
+++ b/langtools/src/share/classes/com/sun/tools/doclets/internal/toolkit/util/Extern.java	Wed Apr 16 19:21:59 2014 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1998, 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1998, 2014, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -177,7 +177,7 @@
         try {
             url = adjustEndFileSeparator(url);
             if (isUrl(pkglisturl)) {
-                readPackageListFromURL(url, toURL(pkglisturl));
+                readPackageListFromURL(url, toURL(adjustEndFileSeparator(pkglisturl)));
             } else {
                 readPackageListFromFile(url, DocFile.createFileForInput(configuration, pkglisturl));
             }
--- a/langtools/test/com/sun/javadoc/testLinkOption/TestLinkOption.java	Wed Apr 16 18:15:48 2014 -0700
+++ b/langtools/test/com/sun/javadoc/testLinkOption/TestLinkOption.java	Wed Apr 16 19:21:59 2014 -0700
@@ -23,18 +23,20 @@
 
 /*
  * @test
- * @bug 4720957 5020118 8026567
+ * @bug 4720957 5020118 8026567 8038976
  * @summary Test to make sure that -link and -linkoffline link to
- * right files.
+ * right files, and URLs with and without trailing slash are accepted.
  * @author jamieh
  * @library ../lib/
  * @build JavadocTester TestLinkOption
  * @run main TestLinkOption
  */
 
+import java.io.File;
+
 public class TestLinkOption extends JavadocTester {
 
-    private static final String BUG_ID = "4720957-5020118";
+    private static final String BUG_ID = "4720957-5020118-8038976";
 
     //Generate the documentation using -linkoffline and a URL as the first parameter.
     private static final String[] ARGS1 = new String[] {
@@ -85,7 +87,34 @@
         }
     };
     private static final String[][] NEGATED_TEST2 = NO_TEST;
-
+    /*
+     * Create the documentation using the -link option, vary the behavior with
+     * both trailing and no trailing slash. We are only interested in ensuring
+     * that the command executes with no errors or related warnings.
+     */
+    static String[] createArguments(boolean withTrailingSlash) {
+        String packagePath = new File(BUG_ID + "-1").getAbsolutePath();
+        String outputDirName = BUG_ID;
+        if (withTrailingSlash) {
+            // add the trailing slash, if it is not present!
+            if (!packagePath.endsWith(FS)) {
+                packagePath = packagePath + FS;
+            }
+            outputDirName = outputDirName + "-3";
+        } else {
+            // remove the trailing slash, if it is present!
+            if (packagePath.endsWith(FS)) {
+                packagePath = packagePath.substring(0, packagePath.length() - 1);
+            }
+            outputDirName = outputDirName + "-4";
+        }
+        String args[] = {
+            "-d", outputDirName, "-sourcepath", SRC_DIR,
+            "-link", "file:///" + packagePath, "-package", "pkg2"
+        };
+        System.out.println("packagePath: " + packagePath);
+        return args;
+    }
     /**
      * The entry point of the test.
      * @param args the array of command line arguments.
@@ -94,6 +123,12 @@
         TestLinkOption tester = new TestLinkOption();
         run(tester, ARGS1, TEST1, NEGATED_TEST1);
         run(tester, ARGS2, TEST2, NEGATED_TEST2);
+        tester.runJavadoc(createArguments(true));  // with trailing slash
+        tester.runJavadoc(createArguments(false)); // without trailing slash
+        tester.printSummary();
+        if (tester.getWarningOutput().contains("warning - Error fetching URL")) {
+            throw new Error("URL rejected ?");
+        }
         tester.printSummary();
     }