src/share/classes/com/sun/tools/javac/file/Paths.java

changeset 497
16b9b7f45933
parent 450
4011f49b4af8
child 510
72833a8a6086
equal deleted inserted replaced
496:631a273dac0f 497:16b9b7f45933
25 25
26 package com.sun.tools.javac.file; 26 package com.sun.tools.javac.file;
27 27
28 import java.io.File; 28 import java.io.File;
29 import java.io.IOException; 29 import java.io.IOException;
30 import java.net.MalformedURLException;
31 import java.net.URL;
30 import java.util.HashMap; 32 import java.util.HashMap;
31 import java.util.HashSet; 33 import java.util.HashSet;
32 import java.util.Map; 34 import java.util.Map;
33 import java.util.Set; 35 import java.util.Set;
34 import java.util.Collection; 36 import java.util.Collection;
35 import java.util.Collections; 37 import java.util.Collections;
36 import java.util.LinkedHashSet; 38 import java.util.LinkedHashSet;
39 import java.util.StringTokenizer;
37 import java.util.zip.ZipFile; 40 import java.util.zip.ZipFile;
38 import javax.tools.JavaFileManager.Location; 41 import javax.tools.JavaFileManager.Location;
39 42
40 import com.sun.tools.javac.code.Lint; 43 import com.sun.tools.javac.code.Lint;
41 import com.sun.tools.javac.util.Context; 44 import com.sun.tools.javac.util.Context;
447 private boolean isArchive(File file) { 450 private boolean isArchive(File file) {
448 String n = file.getName().toLowerCase(); 451 String n = file.getName().toLowerCase();
449 return fsInfo.isFile(file) 452 return fsInfo.isFile(file)
450 && (n.endsWith(".jar") || n.endsWith(".zip")); 453 && (n.endsWith(".jar") || n.endsWith(".zip"));
451 } 454 }
455
456 /**
457 * Utility method for converting a search path string to an array
458 * of directory and JAR file URLs.
459 *
460 * Note that this method is called by apt and the DocletInvoker.
461 *
462 * @param path the search path string
463 * @return the resulting array of directory and JAR file URLs
464 */
465 public static URL[] pathToURLs(String path) {
466 StringTokenizer st = new StringTokenizer(path, File.pathSeparator);
467 URL[] urls = new URL[st.countTokens()];
468 int count = 0;
469 while (st.hasMoreTokens()) {
470 URL url = fileToURL(new File(st.nextToken()));
471 if (url != null) {
472 urls[count++] = url;
473 }
474 }
475 if (urls.length != count) {
476 URL[] tmp = new URL[count];
477 System.arraycopy(urls, 0, tmp, 0, count);
478 urls = tmp;
479 }
480 return urls;
481 }
482
483 /**
484 * Returns the directory or JAR file URL corresponding to the specified
485 * local file name.
486 *
487 * @param file the File object
488 * @return the resulting directory or JAR file URL, or null if unknown
489 */
490 private static URL fileToURL(File file) {
491 String name;
492 try {
493 name = file.getCanonicalPath();
494 } catch (IOException e) {
495 name = file.getAbsolutePath();
496 }
497 name = name.replace(File.separatorChar, '/');
498 if (!name.startsWith("/")) {
499 name = "/" + name;
500 }
501 // If the file does not exist, then assume that it's a directory
502 if (!file.isFile()) {
503 name = name + "/";
504 }
505 try {
506 return new URL("file", "", name);
507 } catch (MalformedURLException e) {
508 throw new IllegalArgumentException(file.toString());
509 }
510 }
452 } 511 }

mercurial