--- a/langtools/src/share/classes/com/sun/tools/doclets/internal/toolkit/Configuration.java Thu Oct 25 13:33:27 2012 -0700
+++ b/langtools/src/share/classes/com/sun/tools/doclets/internal/toolkit/Configuration.java Fri Oct 26 13:10:56 2012 -0700
@@ -408,11 +408,11 @@
group.checkPackageGroups(os[1], os[2]);
} else if (opt.equals("-link")) {
String url = os[1];
- extern.url(url, url, root, false);
+ extern.link(url, url, root, false);
} else if (opt.equals("-linkoffline")) {
String url = os[1];
String pkglisturl = os[2];
- extern.url(url, pkglisturl, root, true);
+ extern.link(url, pkglisturl, root, true);
}
}
if (sourcepath.length() == 0) {
--- a/langtools/src/share/classes/com/sun/tools/doclets/internal/toolkit/util/Extern.java Thu Oct 25 13:33:27 2012 -0700
+++ b/langtools/src/share/classes/com/sun/tools/doclets/internal/toolkit/util/Extern.java Fri Oct 26 13:10:56 2012 -0700
@@ -167,17 +167,38 @@
* @param pkglisturl This can be another URL for "package-list" or ordinary
* file.
* @param reporter The <code>DocErrorReporter</code> used to report errors.
- * @param linkoffline True if -linkoffline isused and false if -link is used.
+ * @param linkoffline True if -linkoffline is used and false if -link is used.
*/
- public boolean url(String url, String pkglisturl,
+ public boolean link(String url, String pkglisturl,
DocErrorReporter reporter, boolean linkoffline) {
this.linkoffline = linkoffline;
- String errMsg = composeExternPackageList(url, pkglisturl);
- if (errMsg != null) {
- reporter.printWarning(errMsg);
+ try {
+ url = adjustEndFileSeparator(url);
+ if (isUrl(pkglisturl)) {
+ readPackageListFromURL(url, toURL(pkglisturl));
+ } else {
+ readPackageListFromFile(url, new File(pkglisturl));
+ }
+ return true;
+ } catch (Fault f) {
+ reporter.printWarning(f.getMessage());
return false;
- } else {
- return true;
+ }
+ }
+
+ private URL toURL(String url) throws Fault {
+ try {
+ return new URL(url);
+ } catch (MalformedURLException e) {
+ throw new Fault(configuration.getText("doclet.MalformedURL", url), e);
+ }
+ }
+
+ private class Fault extends Exception {
+ private static final long serialVersionUID = 0;
+
+ Fault(String msg, Exception cause) {
+ super(msg, cause);
}
}
@@ -194,31 +215,10 @@
}
/**
- * Adjusts the end file separator if it is missing from the URL or the
- * directory path and depending upon the URL or file path, fetch or
- * read the "package-list" file.
- *
- * @param urlOrDirPath URL or the directory path.
- * @param pkgListUrlOrDirPath URL or directory path for the "package-list" file or the "package-list"
- * file itself.
- */
- private String composeExternPackageList(String urlOrDirPath, String pkgListUrlOrDirPath) {
- urlOrDirPath = adjustEndFileSeparator(urlOrDirPath);
- pkgListUrlOrDirPath = adjustEndFileSeparator(pkgListUrlOrDirPath);
- return isUrl(pkgListUrlOrDirPath) ?
- fetchURLComposeExternPackageList(urlOrDirPath, pkgListUrlOrDirPath) :
- readFileComposeExternPackageList(urlOrDirPath, pkgListUrlOrDirPath);
- }
-
- /**
* If the URL or Directory path is missing end file separator, add that.
*/
private String adjustEndFileSeparator(String url) {
- String filesep = "/";
- if (!url.endsWith(filesep)) {
- url += filesep;
- }
- return url;
+ return url.endsWith("/") ? url : url + '/';
}
/**
@@ -227,17 +227,18 @@
* @param urlpath Path to the packages.
* @param pkglisturlpath URL or the path to the "package-list" file.
*/
- private String fetchURLComposeExternPackageList(String urlpath,
- String pkglisturlpath) {
- String link = pkglisturlpath + "package-list";
+ private void readPackageListFromURL(String urlpath, URL pkglisturlpath)
+ throws Fault {
try {
- readPackageList((new URL(link)).openStream(), urlpath, false);
+ URL link = pkglisturlpath.toURI().resolve(DocPaths.PACKAGE_LIST.getPath()).toURL();
+ readPackageList(link.openStream(), urlpath, false);
+ } catch (URISyntaxException exc) {
+ throw new Fault(configuration.getText("doclet.MalformedURL", pkglisturlpath.toString()), exc);
} catch (MalformedURLException exc) {
- return configuration.getText("doclet.MalformedURL", link);
+ throw new Fault(configuration.getText("doclet.MalformedURL", pkglisturlpath.toString()), exc);
} catch (IOException exc) {
- return configuration.getText("doclet.URL_error", link);
+ throw new Fault(configuration.getText("doclet.URL_error", pkglisturlpath.toString()), exc);
}
- return null;
}
/**
@@ -246,27 +247,22 @@
* @param path URL or directory path to the packages.
* @param pkgListPath Path to the local "package-list" file.
*/
- private String readFileComposeExternPackageList(String path,
- String pkgListPath) {
-
- String link = pkgListPath + "package-list";
- if (! ((new File(pkgListPath)).isAbsolute() || linkoffline)){
- link = configuration.destDirName + link;
+ private void readPackageListFromFile(String path, File pkgListPath)
+ throws Fault {
+ File file = new File(pkgListPath, "package-list");
+ if (! (file.isAbsolute() || linkoffline)){
+ file = new File(configuration.destDirName, file.getPath());
}
try {
- File file = new File(link);
if (file.exists() && file.canRead()) {
readPackageList(new FileInputStream(file), path,
! ((new File(path)).isAbsolute() || isUrl(path)));
} else {
- return configuration.getText("doclet.File_error", link);
+ throw new Fault(configuration.getText("doclet.File_error", file.getPath()), null);
}
- } catch (FileNotFoundException exc) {
- return configuration.getText("doclet.File_error", link);
} catch (IOException exc) {
- return configuration.getText("doclet.File_error", link);
+ throw new Fault(configuration.getText("doclet.File_error", file.getPath()), exc);
}
- return null;
}
/**