10 * 11 * This code is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 22 * CA 95054 USA or visit www.sun.com if you need additional information or 23 * have any questions. 24 */ 25 26 package com.sun.tools.javac.file; 27 28 import java.io.File; 29 import java.io.IOException; 30 import java.util.HashMap; 31 import java.util.HashSet; 32 import java.util.Map; 33 import java.util.Set; 34 import java.util.Collection; 35 import java.util.Collections; 36 import java.util.LinkedHashSet; 37 import java.util.zip.ZipFile; 38 import javax.tools.JavaFileManager.Location; 39 40 import com.sun.tools.javac.code.Lint; 41 import com.sun.tools.javac.util.Context; 42 import com.sun.tools.javac.util.ListBuffer; 43 import com.sun.tools.javac.util.Log; 44 import com.sun.tools.javac.util.Options; 45 46 import static javax.tools.StandardLocation.*; 47 import static com.sun.tools.javac.main.OptionName.*; 48 49 /** This class converts command line arguments, environment variables 50 * and system properties (in File.pathSeparator-separated String form) 51 * into a boot class path, user class path, and source path (in 52 * Collection<String> form). 53 * 54 * <p><b>This is NOT part of any API supported by Sun Microsystems. If 55 * you write code that depends on this, you do so at your own risk. 56 * This code and its internal interfaces are subject to change or 432 lazy(); 433 Path userClassPath = getPathForLocation(CLASS_PATH); 434 Path sourcePath = getPathForLocation(SOURCE_PATH); 435 if (sourcePath == null) 436 otherSearchPath = userClassPath; 437 else { 438 otherSearchPath = new Path(); 439 otherSearchPath.addAll(userClassPath); 440 otherSearchPath.addAll(sourcePath); 441 } 442 } 443 return Collections.unmodifiableCollection(otherSearchPath); 444 } 445 446 /** Is this the name of an archive file? */ 447 private boolean isArchive(File file) { 448 String n = file.getName().toLowerCase(); 449 return fsInfo.isFile(file) 450 && (n.endsWith(".jar") || n.endsWith(".zip")); 451 } 452 } | 10 * 11 * This code is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 22 * CA 95054 USA or visit www.sun.com if you need additional information or 23 * have any questions. 24 */ 25 26 package com.sun.tools.javac.file; 27 28 import java.io.File; 29 import java.io.IOException; 30 import java.net.MalformedURLException; 31 import java.net.URL; 32 import java.util.HashMap; 33 import java.util.HashSet; 34 import java.util.Map; 35 import java.util.Set; 36 import java.util.Collection; 37 import java.util.Collections; 38 import java.util.LinkedHashSet; 39 import java.util.StringTokenizer; 40 import java.util.zip.ZipFile; 41 import javax.tools.JavaFileManager.Location; 42 43 import com.sun.tools.javac.code.Lint; 44 import com.sun.tools.javac.util.Context; 45 import com.sun.tools.javac.util.ListBuffer; 46 import com.sun.tools.javac.util.Log; 47 import com.sun.tools.javac.util.Options; 48 49 import static javax.tools.StandardLocation.*; 50 import static com.sun.tools.javac.main.OptionName.*; 51 52 /** This class converts command line arguments, environment variables 53 * and system properties (in File.pathSeparator-separated String form) 54 * into a boot class path, user class path, and source path (in 55 * Collection<String> form). 56 * 57 * <p><b>This is NOT part of any API supported by Sun Microsystems. If 58 * you write code that depends on this, you do so at your own risk. 59 * This code and its internal interfaces are subject to change or 435 lazy(); 436 Path userClassPath = getPathForLocation(CLASS_PATH); 437 Path sourcePath = getPathForLocation(SOURCE_PATH); 438 if (sourcePath == null) 439 otherSearchPath = userClassPath; 440 else { 441 otherSearchPath = new Path(); 442 otherSearchPath.addAll(userClassPath); 443 otherSearchPath.addAll(sourcePath); 444 } 445 } 446 return Collections.unmodifiableCollection(otherSearchPath); 447 } 448 449 /** Is this the name of an archive file? */ 450 private boolean isArchive(File file) { 451 String n = file.getName().toLowerCase(); 452 return fsInfo.isFile(file) 453 && (n.endsWith(".jar") || n.endsWith(".zip")); 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 } 511 } |