📄 paths.java
字号:
addFile(new File(file), warn); return this; } public void addFile(File file, boolean warn) { boolean foundInCache = false; PathEntry pe = null; if (!NON_BATCH_MODE) { pe = pathExistanceCache.get(file); if (pe != null) { foundInCache = true; } else { pe = new PathEntry(); } } else { pe = new PathEntry(); } File canonFile; try { if (!foundInCache) { pe.cannonicalPath = file.getCanonicalFile(); } else { canonFile = pe.cannonicalPath; } } catch (IOException e) { pe.cannonicalPath = canonFile = file; } if (contains(file) || canonicalValues.contains(pe.cannonicalPath)) { /* Discard duplicates and avoid infinite recursion */ return; } if (!foundInCache) { pe.exists = file.exists(); pe.isFile = file.isFile(); if (!NON_BATCH_MODE) { pathExistanceCache.put(file, pe); } } if (! pe.exists) { /* No such file or directory exists */ if (warn) log.warning("path.element.not.found", file); } else if (pe.isFile) { /* File is an ordinary file. */ if (!isArchive(file)) { /* Not a recognized extension; open it to see if it looks like a valid zip file. */ try { ZipFile z = new ZipFile(file); z.close(); if (warn) log.warning("unexpected.archive.file", file); } catch (IOException e) { // FIXME: include e.getLocalizedMessage in warning if (warn) log.warning("invalid.archive.file", file); return; } } } /* Now what we have left is either a directory or a file name confirming to archive naming convention */ super.add(file); canonicalValues.add(pe.cannonicalPath); if (expandJarClassPaths && file.exists() && file.isFile()) addJarClassPath(file, warn); } // Adds referenced classpath elements from a jar's Class-Path // Manifest entry. In some future release, we may want to // update this code to recognize URLs rather than simple // filenames, but if we do, we should redo all path-related code. private void addJarClassPath(File jarFile, boolean warn) { try { java.util.List<String> manifestsList = manifestEntries.get(jarFile); if (!NON_BATCH_MODE) { lock.lock(); try { if (manifestsList != null) { for (String entr : manifestsList) { addFile(new File(entr), warn); } return; } } finally { lock.unlock(); } } if (!NON_BATCH_MODE) { manifestsList = new ArrayList<String>(); manifestEntries.put(jarFile, manifestsList); } String jarParent = jarFile.getParent(); JarFile jar = new JarFile(jarFile); try { Manifest man = jar.getManifest(); if (man == null) return; Attributes attr = man.getMainAttributes(); if (attr == null) return; String path = attr.getValue(Attributes.Name.CLASS_PATH); if (path == null) return; for (StringTokenizer st = new StringTokenizer(path); st.hasMoreTokens();) { String elt = st.nextToken(); File f = (jarParent == null ? new File(elt) : new File(jarParent, elt)); addFile(f, warn); if (!NON_BATCH_MODE) { lock.lock(); try { manifestsList.add(elt); } finally { lock.unlock(); } } } } finally { jar.close(); } } catch (IOException e) { log.error("error.reading.file", jarFile, e.getLocalizedMessage()); } } } private Path computeBootClassPath() { bootClassPathRtJar = null; String optionValue; Path path = new Path(); path.addFiles(options.get(XBOOTCLASSPATH_PREPEND)); if ((optionValue = options.get(ENDORSEDDIRS)) != null) path.addDirectories(optionValue); else path.addDirectories(System.getProperty("java.endorsed.dirs"), false); if ((optionValue = options.get(BOOTCLASSPATH)) != null) { path.addFiles(optionValue); } else { // Standard system classes for this compiler's release. String files = System.getProperty("sun.boot.class.path"); path.addFiles(files, false); File rt_jar = new File("rt.jar"); for (String file : new PathIterator(files, null)) { File f = new File(file); if (new File(f.getName()).equals(rt_jar)) bootClassPathRtJar = f; } } path.addFiles(options.get(XBOOTCLASSPATH_APPEND)); // Strictly speaking, standard extensions are not bootstrap // classes, but we treat them identically, so we'll pretend // that they are. if ((optionValue = options.get(EXTDIRS)) != null) path.addDirectories(optionValue); else path.addDirectories(System.getProperty("java.ext.dirs"), false); return path; } private Path computeUserClassPath() { String cp = options.get(CLASSPATH); // CLASSPATH environment variable when run from `javac'. if (cp == null) cp = System.getProperty("env.class.path"); // If invoked via a java VM (not the javac launcher), use the // platform class path if (cp == null && System.getProperty("application.home") == null) cp = System.getProperty("java.class.path"); // Default to current working directory. if (cp == null) cp = "."; return new Path() .expandJarClassPaths(true) // Only search user jars for Class-Paths .emptyPathDefault(".") // Empty path elt ==> current directory .addFiles(cp); } private Path computeSourcePath() { String sourcePathArg = options.get(SOURCEPATH); if (sourcePathArg == null) return null; return new Path().addFiles(sourcePathArg); } private Path computeAnnotationProcessorPath() { String processorPathArg = options.get(PROCESSORPATH); if (processorPathArg == null) return null; return new Path().addFiles(processorPathArg); } /** The actual effective locations searched for sources */ private Path sourceSearchPath; public Collection<File> sourceSearchPath() { if (sourceSearchPath == null) { lazy(); Path sourcePath = getPathForLocation(SOURCE_PATH); Path userClassPath = getPathForLocation(CLASS_PATH); sourceSearchPath = sourcePath != null ? sourcePath : userClassPath; } return Collections.unmodifiableCollection(sourceSearchPath); } /** The actual effective locations searched for classes */ private Path classSearchPath; public Collection<File> classSearchPath() { if (classSearchPath == null) { lazy(); Path bootClassPath = getPathForLocation(PLATFORM_CLASS_PATH); Path userClassPath = getPathForLocation(CLASS_PATH); classSearchPath = new Path(); classSearchPath.addAll(bootClassPath); classSearchPath.addAll(userClassPath); } return Collections.unmodifiableCollection(classSearchPath); } /** The actual effective locations for non-source, non-class files */ private Path otherSearchPath; Collection<File> otherSearchPath() { if (otherSearchPath == null) { lazy(); Path userClassPath = getPathForLocation(CLASS_PATH); Path sourcePath = getPathForLocation(SOURCE_PATH); if (sourcePath == null) otherSearchPath = userClassPath; else { otherSearchPath = new Path(); otherSearchPath.addAll(userClassPath); otherSearchPath.addAll(sourcePath); } } return Collections.unmodifiableCollection(otherSearchPath); } /** Is this the name of an archive file? */ private static boolean isArchive(File file) { String n = file.getName().toLowerCase(); boolean isFile = false; if (!NON_BATCH_MODE) { Boolean isf = isDirectory.get(file); if (isf == null) { isFile = file.isFile(); isDirectory.put(file, isFile); } else { isFile = isf; } } else { isFile = file.isFile(); } return isFile && (n.endsWith(".jar") || n.endsWith(".zip")); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -