Java源码示例:com.sun.tools.javac.file.RelativePath.RelativeDirectory

示例1
ZipFileIndex(File zipFile, RelativeDirectory symbolFilePrefix, boolean writeIndex,
        boolean useCache, String cacheLocation) throws IOException {
    this.zipFile = zipFile;
    this.symbolFilePrefix = symbolFilePrefix;
    this.symbolFilePrefixLength = (symbolFilePrefix == null ? 0 :
        symbolFilePrefix.getPath().getBytes("UTF-8").length);
    this.writeIndex = writeIndex;
    this.usePreindexedCache = useCache;
    this.preindexedCacheLocation = cacheLocation;

    if (zipFile != null) {
        this.zipFileLastModified = zipFile.lastModified();
    }

    // Validate integrity of the zip file
    checkIndex();
}
 
示例2
@Override
@DefinedBy(Api.COMPILER)
public FileObject getFileForOutput(Location location,
                                   String packageName,
                                   String relativeName,
                                   FileObject sibling)
        throws IOException {
    checkOutputLocation(location);
    // validatePackageName(packageName);
    nullCheck(packageName);
    if (!isRelativeUri(relativeName))
        throw new IllegalArgumentException("Invalid relative name: " + relativeName);
    RelativeFile name = packageName.length() == 0
            ? new RelativeFile(relativeName)
            : new RelativeFile(RelativeDirectory.forPackage(packageName), relativeName);
    return getFileForOutput(location, name, sibling);
}
 
示例3
/**
 * Returns a javac List of filenames within a directory in the ZipFileIndex.
 */
public synchronized com.sun.tools.javac.util.List<String> getFiles(RelativeDirectory path) {
    try {
        checkIndex();

        DirectoryEntry de = directories.get(path);
        com.sun.tools.javac.util.List<String> ret = de == null ? null : de.getFiles();

        if (ret == null) {
            return com.sun.tools.javac.util.List.<String>nil();
        }
        return ret;
    }
    catch (IOException e) {
        return com.sun.tools.javac.util.List.<String>nil();
    }
}
 
示例4
/**
 * Returns a javac List of filenames within a directory in the ZipFileIndex.
 */
public synchronized com.sun.tools.javac.util.List<String> getFiles(RelativeDirectory path) {
    try {
        checkIndex();

        DirectoryEntry de = directories.get(path);
        com.sun.tools.javac.util.List<String> ret = de == null ? null : de.getFiles();

        if (ret == null) {
            return com.sun.tools.javac.util.List.<String>nil();
        }
        return ret;
    }
    catch (IOException e) {
        return com.sun.tools.javac.util.List.<String>nil();
    }
}
 
示例5
ZipFileIndex(File zipFile, RelativeDirectory symbolFilePrefix, boolean writeIndex,
        boolean useCache, String cacheLocation) throws IOException {
    this.zipFile = zipFile;
    this.symbolFilePrefix = symbolFilePrefix;
    this.symbolFilePrefixLength = (symbolFilePrefix == null ? 0 :
        symbolFilePrefix.getPath().getBytes("UTF-8").length);
    this.writeIndex = writeIndex;
    this.usePreindexedCache = useCache;
    this.preindexedCacheLocation = cacheLocation;

    if (zipFile != null) {
        this.zipFileLastModified = zipFile.lastModified();
    }

    // Validate integrity of the zip file
    checkIndex();
}
 
示例6
@Override
void addZipEntry(ZipEntry entry) {
    String name = entry.getName();
    if (!name.startsWith(prefix.path)) {
        return;
    }
    name = name.substring(prefix.path.length());
    int i = name.lastIndexOf('/');
    RelativeDirectory dirname = new RelativeDirectory(name.substring(0, i+1));
    String basename = name.substring(i + 1);
    if (basename.length() == 0) {
        return;
    }
    List<String> list = map.get(dirname);
    if (list == null)
        list = List.nil();
    list = list.prepend(basename);
    map.put(dirname, list);
}
 
示例7
@Override
void addZipEntry(ZipEntry entry) {
    String name = entry.getName();
    if (!name.startsWith(prefix.path)) {
        return;
    }
    name = name.substring(prefix.path.length());
    int i = name.lastIndexOf('/');
    RelativeDirectory dirname = new RelativeDirectory(name.substring(0, i+1));
    String basename = name.substring(i + 1);
    if (basename.length() == 0) {
        return;
    }
    List<String> list = map.get(dirname);
    if (list == null)
        list = List.nil();
    list = list.prepend(basename);
    map.put(dirname, list);
}
 
示例8
public ArchiveContainer(Path archivePath) throws IOException, ProviderNotFoundException, SecurityException {
    this.archivePath = archivePath;
    if (multiReleaseValue != null && archivePath.toString().endsWith(".jar")) {
        Map<String,String> env = Collections.singletonMap("multi-release", multiReleaseValue);
        FileSystemProvider jarFSProvider = fsInfo.getJarFSProvider();
        Assert.checkNonNull(jarFSProvider, "should have been caught before!");
        this.fileSystem = jarFSProvider.newFileSystem(archivePath, env);
    } else {
        this.fileSystem = FileSystems.newFileSystem(archivePath, null);
    }
    packages = new HashMap<>();
    for (Path root : fileSystem.getRootDirectories()) {
        Files.walkFileTree(root, EnumSet.noneOf(FileVisitOption.class), Integer.MAX_VALUE,
                new SimpleFileVisitor<Path>() {
                    @Override
                    public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) {
                        if (isValid(dir.getFileName())) {
                            packages.put(new RelativeDirectory(root.relativize(dir).toString()), dir);
                            return FileVisitResult.CONTINUE;
                        } else {
                            return FileVisitResult.SKIP_SUBTREE;
                        }
                    }
                });
    }
}
 
示例9
/**
 * Returns a javac List of filenames within a directory in the ZipFileIndex.
 */
public synchronized com.sun.tools.javac.util.List<String> getFiles(RelativeDirectory path) {
    try {
        checkIndex();

        DirectoryEntry de = directories.get(path);
        com.sun.tools.javac.util.List<String> ret = de == null ? null : de.getFiles();

        if (ret == null) {
            return com.sun.tools.javac.util.List.<String>nil();
        }
        return ret;
    }
    catch (IOException e) {
        return com.sun.tools.javac.util.List.<String>nil();
    }
}
 
示例10
public synchronized List<String> getDirectories(RelativeDirectory path) {
    try {
        checkIndex();

        DirectoryEntry de = directories.get(path);
        com.sun.tools.javac.util.List<String> ret = de == null ? null : de.getDirectories();

        if (ret == null) {
            return com.sun.tools.javac.util.List.<String>nil();
        }

        return ret;
    }
    catch (IOException e) {
        return com.sun.tools.javac.util.List.<String>nil();
    }
}
 
示例11
public FileObject getFileForOutput(Location location,
                                   String packageName,
                                   String relativeName,
                                   FileObject sibling)
    throws IOException
{
    nullCheck(location);
    // validatePackageName(packageName);
    nullCheck(packageName);
    if (!isRelativeUri(relativeName))
        throw new IllegalArgumentException("Invalid relative name: " + relativeName);
    RelativeFile name = packageName.length() == 0
        ? new RelativeFile(relativeName)
        : new RelativeFile(RelativeDirectory.forPackage(packageName), relativeName);
    return getFileForOutput(location, name, sibling);
}
 
示例12
public FileObject getFileForOutput(Location location,
                                   String packageName,
                                   String relativeName,
                                   FileObject sibling)
    throws IOException
{
    nullCheck(location);
    // validatePackageName(packageName);
    nullCheck(packageName);
    if (!isRelativeUri(relativeName))
        throw new IllegalArgumentException("Invalid relative name: " + relativeName);
    RelativeFile name = packageName.length() == 0
        ? new RelativeFile(relativeName)
        : new RelativeFile(RelativeDirectory.forPackage(packageName), relativeName);
    return getFileForOutput(location, name, sibling);
}
 
示例13
ZipFileIndex(File zipFile, RelativeDirectory symbolFilePrefix, boolean writeIndex,
        boolean useCache, String cacheLocation) throws IOException {
    this.zipFile = zipFile;
    this.symbolFilePrefix = symbolFilePrefix;
    this.symbolFilePrefixLength = (symbolFilePrefix == null ? 0 :
        symbolFilePrefix.getPath().getBytes("UTF-8").length);
    this.writeIndex = writeIndex;
    this.usePreindexedCache = useCache;
    this.preindexedCacheLocation = cacheLocation;

    if (zipFile != null) {
        this.zipFileLastModified = zipFile.lastModified();
    }

    // Validate integrity of the zip file
    checkIndex();
}
 
示例14
@Override
void addZipEntry(ZipEntry entry) {
    String name = entry.getName();
    if (!name.startsWith(prefix.path)) {
        return;
    }
    name = name.substring(prefix.path.length());
    int i = name.lastIndexOf('/');
    RelativeDirectory dirname = new RelativeDirectory(name.substring(0, i+1));
    String basename = name.substring(i + 1);
    if (basename.length() == 0) {
        return;
    }
    List<String> list = map.get(dirname);
    if (list == null)
        list = List.nil();
    list = list.prepend(basename);
    map.put(dirname, list);
}
 
示例15
public synchronized List<String> getDirectories(RelativeDirectory path) {
    try {
        checkIndex();

        DirectoryEntry de = directories.get(path);
        com.sun.tools.javac.util.List<String> ret = de == null ? null : de.getDirectories();

        if (ret == null) {
            return com.sun.tools.javac.util.List.<String>nil();
        }

        return ret;
    }
    catch (IOException e) {
        return com.sun.tools.javac.util.List.<String>nil();
    }
}
 
示例16
@Override @DefinedBy(Api.COMPILER)
public Iterable<JavaFileObject> list(Location location,
                                     String packageName,
                                     Set<JavaFileObject.Kind> kinds,
                                     boolean recurse)
    throws IOException
{
    checkNotModuleOrientedLocation(location);
    // validatePackageName(packageName);
    nullCheck(packageName);
    nullCheck(kinds);

    Iterable<? extends Path> path = getLocationAsPaths(location);
    if (path == null)
        return List.nil();
    RelativeDirectory subdirectory = RelativeDirectory.forPackage(packageName);
    ListBuffer<JavaFileObject> results = new ListBuffer<>();

    for (Path directory : path) {
        Container container = getContainer(directory);

        container.list(directory, subdirectory, kinds, recurse, results);
    }

    return results.toList();
}
 
示例17
private void cleanupState() {
    // Make sure there is a valid but empty index if the file doesn't exist
    entries = Entry.EMPTY_ARRAY;
    directories = Collections.<RelativeDirectory, DirectoryEntry>emptyMap();
    zipFileLastModified = NOT_MODIFIED;
    allDirs = Collections.<RelativeDirectory>emptySet();
}
 
示例18
private void buildIndex() throws IOException {
    int entryCount = get2ByteLittleEndian(zipDir, 0);

    // Add each of the files
    if (entryCount > 0) {
        directories = new LinkedHashMap<RelativeDirectory, DirectoryEntry>();
        ArrayList<Entry> entryList = new ArrayList<Entry>();
        int pos = 2;
        for (int i = 0; i < entryCount; i++) {
            pos = readEntry(pos, entryList, directories);
        }

        // Add the accumulated dirs into the same list
        for (RelativeDirectory d: directories.keySet()) {
            // use shared RelativeDirectory objects for parent dirs
            RelativeDirectory parent = getRelativeDirectory(d.dirname().getPath());
            String file = d.basename();
            Entry zipFileIndexEntry = new Entry(parent, file);
            zipFileIndexEntry.isDir = true;
            entryList.add(zipFileIndexEntry);
        }

        entries = entryList.toArray(new Entry[entryList.size()]);
        Arrays.sort(entries);
    } else {
        cleanupState();
    }
}
 
示例19
public FileObject getFileForInput(Location location,
                                  String packageName,
                                  String relativeName)
        throws IOException {
    nullCheck(location);
    // validatePackageName(packageName);
    nullCheck(packageName);
    if (!isRelativeUri(relativeName))
        throw new IllegalArgumentException("Invalid relative name: " + relativeName);
    RelativeFile name = packageName.length() == 0
            ? new RelativeFile(relativeName)
            : new RelativeFile(RelativeDirectory.forPackage(packageName), relativeName);
    return getFileForInput(location, name);
}
 
示例20
/**
 * Insert all files in subdirectory subdirectory of directory directory
 * which match fileKinds into resultList
 */
private void listDirectory(File directory,
                           RelativeDirectory subdirectory,
                           Set<JavaFileObject.Kind> fileKinds,
                           boolean recurse,
                           ListBuffer<JavaFileObject> resultList) {
    File d = subdirectory.getFile(directory);
    if (!caseMapCheck(d, subdirectory))
        return;

    File[] files = d.listFiles();
    if (files == null)
        return;

    if (sortFiles != null)
        Arrays.sort(files, sortFiles);

    for (File f: files) {
        String fname = f.getName();
        if (f.isDirectory()) {
            if (recurse && SourceVersion.isIdentifier(fname)) {
                listDirectory(directory,
                              new RelativeDirectory(subdirectory, fname),
                              fileKinds,
                              recurse,
                              resultList);
            }
        } else {
            if (isValidFile(fname, fileKinds)) {
                JavaFileObject fe =
                    new RegularFileObject(this, fname, new File(d, fname));
                resultList.append(fe);
            }
        }
    }
}
 
示例21
/**
 * Insert all files in subdirectory subdirectory of directory directory
 * which match fileKinds into resultList
 */
private void listDirectory(File directory,
                           RelativeDirectory subdirectory,
                           Set<JavaFileObject.Kind> fileKinds,
                           boolean recurse,
                           ListBuffer<JavaFileObject> resultList) {
    File d = subdirectory.getFile(directory);
    if (!caseMapCheck(d, subdirectory))
        return;

    File[] files = d.listFiles();
    if (files == null)
        return;

    if (sortFiles != null)
        Arrays.sort(files, sortFiles);

    for (File f : files) {
        String fname = f.getName();
        if (f.isDirectory()) {
            if (recurse && SourceVersion.isIdentifier(fname)) {
                listDirectory(directory,
                        new RelativeDirectory(subdirectory, fname),
                        fileKinds,
                        recurse,
                        resultList);
            }
        } else {
            if (isValidFile(fname, fileKinds)) {
                JavaFileObject fe =
                        new RegularFileObject(this, fname, new File(d, fname));
                resultList.append(fe);
            }
        }
    }
}
 
示例22
DirectoryEntry(RelativeDirectory dirName, ZipFileIndex index) {
    filesInited = false;
    directoriesInited = false;
    entriesInited = false;

    this.dirName = dirName;
    this.zipFileIndex = index;
}
 
示例23
public FileObject getFileForInput(Location location,
                                  String packageName,
                                  String relativeName)
    throws IOException
{
    nullCheck(location);
    // validatePackageName(packageName);
    nullCheck(packageName);
    if (!isRelativeUri(relativeName))
        throw new IllegalArgumentException("Invalid relative name: " + relativeName);
    RelativeFile name = packageName.length() == 0
        ? new RelativeFile(relativeName)
        : new RelativeFile(RelativeDirectory.forPackage(packageName), relativeName);
    return getFileForInput(location, name);
}
 
示例24
public FileObject getFileForInput(Location location,
                                  String packageName,
                                  String relativeName)
    throws IOException
{
    nullCheck(location);
    // validatePackageName(packageName);
    nullCheck(packageName);
    if (!isRelativeUri(relativeName))
        throw new IllegalArgumentException("Invalid relative name: " + relativeName);
    RelativeFile name = packageName.length() == 0
        ? new RelativeFile(relativeName)
        : new RelativeFile(RelativeDirectory.forPackage(packageName), relativeName);
    return getFileForInput(location, name);
}
 
示例25
private void cleanupState() {
    // Make sure there is a valid but empty index if the file doesn't exist
    entries = Entry.EMPTY_ARRAY;
    directories = Collections.<RelativeDirectory, DirectoryEntry>emptyMap();
    zipFileLastModified = NOT_MODIFIED;
    allDirs = Collections.<RelativeDirectory>emptySet();
}
 
示例26
protected ZipArchive(JavacFileManager fm, ZipFile zfile, boolean initMap) throws IOException {
    this.fileManager = fm;
    this.zfile = zfile;
    this.map = new HashMap<RelativeDirectory,List<String>>();
    if (initMap)
        initMap();
}
 
示例27
public int compareTo(Entry other) {
    RelativeDirectory otherD = other.dir;
    if (dir != otherD) {
        int c = dir.compareTo(otherD);
        if (c != 0)
            return c;
    }
    return name.compareTo(other.name);
}
 
示例28
/**
 * Insert all files in subdirectory subdirectory of directory directory
 * which match fileKinds into resultList
 */
private void listDirectory(File directory,
                           RelativeDirectory subdirectory,
                           Set<JavaFileObject.Kind> fileKinds,
                           boolean recurse,
                           ListBuffer<JavaFileObject> resultList) {
    File d = subdirectory.getFile(directory);
    if (!caseMapCheck(d, subdirectory))
        return;

    File[] files = d.listFiles();
    if (files == null)
        return;

    if (sortFiles != null)
        Arrays.sort(files, sortFiles);

    for (File f : files) {
        String fname = f.getName();
        if (f.isDirectory()) {
            if (recurse && SourceVersion.isIdentifier(fname)) {
                listDirectory(directory,
                        new RelativeDirectory(subdirectory, fname),
                        fileKinds,
                        recurse,
                        resultList);
            }
        } else {
            if (isValidFile(fname, fileKinds)) {
                JavaFileObject fe =
                        new RegularFileObject(this, fname, new File(d, fname));
                resultList.append(fe);
            }
        }
    }
}
 
示例29
public synchronized ZipFileIndex getZipFileIndex(File zipFile,
        RelativeDirectory symbolFilePrefix,
        boolean useCache, String cacheLocation,
        boolean writeIndex) throws IOException {
    ZipFileIndex zi = getExistingZipIndex(zipFile);

    if (zi == null || (zi != null && zipFile.lastModified() != zi.zipFileLastModified)) {
        zi = new ZipFileIndex(zipFile, symbolFilePrefix, writeIndex,
                useCache, cacheLocation);
        map.put(zipFile, zi);
    }
    return zi;
}
 
示例30
public FileObject getFileForInput(Location location,
                                  String packageName,
                                  String relativeName)
    throws IOException
{
    nullCheck(location);
    // validatePackageName(packageName);
    nullCheck(packageName);
    if (!isRelativeUri(relativeName))
        throw new IllegalArgumentException("Invalid relative name: " + relativeName);
    RelativeFile name = packageName.length() == 0
        ? new RelativeFile(relativeName)
        : new RelativeFile(RelativeDirectory.forPackage(packageName), relativeName);
    return getFileForInput(location, name);
}