langtools/src/share/classes/com/sun/tools/javadoc/DocletInvoker.java
changeset 4937 2fc03fb01efa
parent 2212 1d3dc0e0ba0c
child 5520 86e4b9a9da40
equal deleted inserted replaced
4936:abf1a22d9bcf 4937:2fc03fb01efa
    79 
    79 
    80         // do prepends to get correct ordering
    80         // do prepends to get correct ordering
    81         cpString = appendPath(System.getProperty("env.class.path"), cpString);
    81         cpString = appendPath(System.getProperty("env.class.path"), cpString);
    82         cpString = appendPath(System.getProperty("java.class.path"), cpString);
    82         cpString = appendPath(System.getProperty("java.class.path"), cpString);
    83         cpString = appendPath(docletPath, cpString);
    83         cpString = appendPath(docletPath, cpString);
    84         URL[] urls = pathToURLs(cpString);
    84         URL[] urls = com.sun.tools.javac.file.Paths.pathToURLs(cpString);
    85         if (docletParentClassLoader == null)
    85         if (docletParentClassLoader == null)
    86             appClassLoader = new URLClassLoader(urls, getDelegationClassLoader(docletClassName));
    86             appClassLoader = new URLClassLoader(urls, getDelegationClassLoader(docletClassName));
    87         else
    87         else
    88             appClassLoader = new URLClassLoader(urls, docletParentClassLoader);
    88             appClassLoader = new URLClassLoader(urls, docletParentClassLoader);
    89 
    89 
   311                 throw new DocletInvokeException();
   311                 throw new DocletInvokeException();
   312             } finally {
   312             } finally {
   313                 Thread.currentThread().setContextClassLoader(savedCCL);
   313                 Thread.currentThread().setContextClassLoader(savedCCL);
   314             }
   314             }
   315     }
   315     }
   316 
       
   317     /**
       
   318      * Utility method for converting a search path string to an array
       
   319      * of directory and JAR file URLs.
       
   320      *
       
   321      * @param path the search path string
       
   322      * @return the resulting array of directory and JAR file URLs
       
   323      */
       
   324     static URL[] pathToURLs(String path) {
       
   325         StringTokenizer st = new StringTokenizer(path, File.pathSeparator);
       
   326         URL[] urls = new URL[st.countTokens()];
       
   327         int count = 0;
       
   328         while (st.hasMoreTokens()) {
       
   329             URL url = fileToURL(new File(st.nextToken()));
       
   330             if (url != null) {
       
   331                 urls[count++] = url;
       
   332             }
       
   333         }
       
   334         if (urls.length != count) {
       
   335             URL[] tmp = new URL[count];
       
   336             System.arraycopy(urls, 0, tmp, 0, count);
       
   337             urls = tmp;
       
   338         }
       
   339         return urls;
       
   340     }
       
   341 
       
   342     /**
       
   343      * Returns the directory or JAR file URL corresponding to the specified
       
   344      * local file name.
       
   345      *
       
   346      * @param file the File object
       
   347      * @return the resulting directory or JAR file URL, or null if unknown
       
   348      */
       
   349     static URL fileToURL(File file) {
       
   350         String name;
       
   351         try {
       
   352             name = file.getCanonicalPath();
       
   353         } catch (IOException e) {
       
   354             name = file.getAbsolutePath();
       
   355         }
       
   356         name = name.replace(File.separatorChar, '/');
       
   357         if (!name.startsWith("/")) {
       
   358             name = "/" + name;
       
   359         }
       
   360         // If the file does not exist, then assume that it's a directory
       
   361         if (!file.isFile()) {
       
   362             name = name + "/";
       
   363         }
       
   364         try {
       
   365             return new URL("file", "", name);
       
   366         } catch (MalformedURLException e) {
       
   367             throw new IllegalArgumentException("file");
       
   368         }
       
   369     }
       
   370 }
   316 }