8071617: move pathToURLs from javac.file.Locations to javadoc.DocletInvoker
authorjjg
Thu, 29 Jan 2015 14:43:19 -0800
changeset 28707 2ec91c67b30b
parent 28706 a724585645ce
child 28708 ac59fe6cd98f
8071617: move pathToURLs from javac.file.Locations to javadoc.DocletInvoker Reviewed-by: ksrini
langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/file/Locations.java
langtools/src/jdk.javadoc/share/classes/com/sun/tools/javadoc/DocletInvoker.java
--- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/file/Locations.java	Tue Jan 27 19:50:41 2015 -0800
+++ b/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/file/Locations.java	Thu Jan 29 14:43:19 2015 -0800
@@ -783,45 +783,4 @@
                 && (n.endsWith(".jar") || n.endsWith(".zip"));
     }
 
-    /**
-     * Utility method for converting a search path string to an array of directory and JAR file
-     * URLs.
-     *
-     * Note that this method is called by the DocletInvoker.
-     *
-     * @param path the search path string
-     * @return the resulting array of directory and JAR file URLs
-     */
-    public static URL[] pathToURLs(String path) {
-        java.util.List<URL> urls = new ArrayList<>();
-        for (String s: path.split(Pattern.quote(File.pathSeparator))) {
-            if (!s.isEmpty()) {
-                URL url = fileToURL(Paths.get(s));
-                if (url != null) {
-                    urls.add(url);
-                }
-            }
-        }
-        return urls.toArray(new URL[urls.size()]);
-    }
-
-    /**
-     * Returns the directory or JAR file URL corresponding to the specified local file name.
-     *
-     * @param file the Path object
-     * @return the resulting directory or JAR file URL, or null if unknown
-     */
-    private static URL fileToURL(Path file) {
-        Path p;
-        try {
-            p = file.toRealPath();
-        } catch (IOException e) {
-            p = file.toAbsolutePath();
-        }
-        try {
-            return p.normalize().toUri().toURL();
-        } catch (MalformedURLException e) {
-            return null;
-        }
-    }
 }
--- a/langtools/src/jdk.javadoc/share/classes/com/sun/tools/javadoc/DocletInvoker.java	Tue Jan 27 19:50:41 2015 -0800
+++ b/langtools/src/jdk.javadoc/share/classes/com/sun/tools/javadoc/DocletInvoker.java	Thu Jan 29 14:43:19 2015 -0800
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1998, 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1998, 2015, 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
@@ -26,19 +26,25 @@
 package com.sun.tools.javadoc;
 
 import java.io.File;
+import java.io.IOException;
 import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Method;
 import java.lang.reflect.Modifier;
+import java.net.MalformedURLException;
 import java.net.URL;
 import java.net.URLClassLoader;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.ArrayList;
+import java.util.regex.Pattern;
 
 import javax.tools.DocumentationTool;
 import javax.tools.JavaFileManager;
 
 import com.sun.javadoc.*;
-import com.sun.tools.javac.file.Locations;
 import com.sun.tools.javac.util.ClientCodeException;
 import com.sun.tools.javac.util.List;
+
 import static com.sun.javadoc.LanguageVersion.*;
 
 
@@ -108,7 +114,7 @@
             cpString = appendPath(System.getProperty("env.class.path"), cpString);
             cpString = appendPath(System.getProperty("java.class.path"), cpString);
             cpString = appendPath(docletPath, cpString);
-            URL[] urls = Locations.pathToURLs(cpString);
+            URL[] urls = pathToURLs(cpString);
             if (docletParentClassLoader == null)
                 appClassLoader = new URLClassLoader(urls, getDelegationClassLoader(docletClassName));
             else
@@ -191,7 +197,7 @@
             return false;
         }
         if (retVal instanceof Boolean) {
-            return ((Boolean)retVal).booleanValue();
+            return ((Boolean)retVal);
         } else {
             messager.error(Messager.NOPOS, "main.must_return_boolean",
                            docletClassName, methodName);
@@ -215,7 +221,7 @@
             return -1;
         }
         if (retVal instanceof Integer) {
-            return ((Integer)retVal).intValue();
+            return ((Integer)retVal);
         } else {
             messager.error(Messager.NOPOS, "main.must_return_int",
                            docletClassName, methodName);
@@ -240,7 +246,7 @@
             return false;
         }
         if (retVal instanceof Boolean) {
-            return ((Boolean)retVal).booleanValue();
+            return ((Boolean)retVal);
         } else {
             messager.error(Messager.NOPOS, "main.must_return_boolean",
                            docletClassName, methodName);
@@ -326,11 +332,53 @@
                 } else {
                     messager.error(Messager.NOPOS, "main.exception_thrown",
                                docletClassName, methodName, exc.toString());
-                    exc.getTargetException().printStackTrace();
+                    exc.getTargetException().printStackTrace(System.err);
                 }
                 throw new DocletInvokeException();
             } finally {
                 Thread.currentThread().setContextClassLoader(savedCCL);
             }
     }
+
+    /**
+     * Utility method for converting a search path string to an array of directory and JAR file
+     * URLs.
+     *
+     * Note that this method is called by the DocletInvoker.
+     *
+     * @param path the search path string
+     * @return the resulting array of directory and JAR file URLs
+     */
+    private static URL[] pathToURLs(String path) {
+        java.util.List<URL> urls = new ArrayList<>();
+        for (String s: path.split(Pattern.quote(File.pathSeparator))) {
+            if (!s.isEmpty()) {
+                URL url = fileToURL(Paths.get(s));
+                if (url != null) {
+                    urls.add(url);
+                }
+            }
+        }
+        return urls.toArray(new URL[urls.size()]);
+    }
+
+    /**
+     * Returns the directory or JAR file URL corresponding to the specified local file name.
+     *
+     * @param file the Path object
+     * @return the resulting directory or JAR file URL, or null if unknown
+     */
+    private static URL fileToURL(Path file) {
+        Path p;
+        try {
+            p = file.toRealPath();
+        } catch (IOException e) {
+            p = file.toAbsolutePath();
+        }
+        try {
+            return p.normalize().toUri().toURL();
+        } catch (MalformedURLException e) {
+            return null;
+        }
+    }
 }