com.sun.tools.javac.file.RelativePath.RelativeDirectory Java Examples

The following examples show how to use com.sun.tools.javac.file.RelativePath.RelativeDirectory. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: JavacFileManager.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
@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();
}
 
Example #2
Source File: ZipFileIndex.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
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();
    }
}
 
Example #3
Source File: ZipFileIndex.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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();
    }
}
 
Example #4
Source File: ZipFileIndex.java    From java-n-IDE-for-Android with Apache License 2.0 6 votes vote down vote up
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();
}
 
Example #5
Source File: ZipFileIndex.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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();
    }
}
 
Example #6
Source File: JavacFileManager.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@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);
}
 
Example #7
Source File: SymbolArchive.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
@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);
}
 
Example #8
Source File: ZipFileIndex.java    From javaide with GNU General Public License v3.0 6 votes vote down vote up
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();
}
 
Example #9
Source File: SymbolArchive.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
@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);
}
 
Example #10
Source File: SymbolArchive.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
@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);
}
 
Example #11
Source File: JavacFileManager.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
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;
                        }
                    }
                });
    }
}
 
Example #12
Source File: JavacFileManager.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
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);
}
 
Example #13
Source File: ZipFileIndex.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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();
    }
}
 
Example #14
Source File: JavacFileManager.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
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);
}
 
Example #15
Source File: ZipFileIndex.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
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();
    }
}
 
Example #16
Source File: ZipFileIndex.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
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();
}
 
Example #17
Source File: ZipFileIndexCache.java    From javaide with GNU General Public License v3.0 5 votes vote down vote up
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;
}
 
Example #18
Source File: ZipArchive.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
void addZipEntry(ZipEntry entry) {
    String name = entry.getName();
    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);
}
 
Example #19
Source File: JavacFileManager.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
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);
}
 
Example #20
Source File: ZipFileIndex.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
private void buildIndex() throws IOException {
    int len = zipDir.length;

    // Add each of the files
    if (len > 0) {
        directories = new LinkedHashMap<RelativeDirectory, DirectoryEntry>();
        ArrayList<Entry> entryList = new ArrayList<Entry>();
        for (int pos = 0; pos < len; ) {
            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();
    }
}
 
Example #21
Source File: ZipArchive.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
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();
}
 
Example #22
Source File: ZipFileIndex.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
private void buildIndex() throws IOException {
    int len = zipDir.length;

    // Add each of the files
    if (len > 0) {
        directories = new LinkedHashMap<RelativeDirectory, DirectoryEntry>();
        ArrayList<Entry> entryList = new ArrayList<Entry>();
        for (int pos = 0; pos < len; ) {
            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();
    }
}
 
Example #23
Source File: ZipFileIndex.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
private void buildIndex() throws IOException {
    int len = zipDir.length;

    // Add each of the files
    if (len > 0) {
        directories = new LinkedHashMap<RelativeDirectory, DirectoryEntry>();
        ArrayList<Entry> entryList = new ArrayList<Entry>();
        for (int pos = 0; pos < len; ) {
            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();
    }
}
 
Example #24
Source File: ZipArchive.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
public boolean contains(RelativePath name) {
    RelativeDirectory dirname = name.dirname();
    String basename = name.basename();
    if (basename.length() == 0)
        return false;
    List<String> list = map.get(dirname);
    return (list != null && list.contains(basename));
}
 
Example #25
Source File: ZipArchive.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
public boolean contains(RelativePath name) {
    RelativeDirectory dirname = name.dirname();
    String basename = name.basename();
    if (basename.length() == 0)
        return false;
    List<String> list = map.get(dirname);
    return (list != null && list.contains(basename));
}
 
Example #26
Source File: ZipArchive.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
public boolean contains(RelativePath name) {
    RelativeDirectory dirname = name.dirname();
    String basename = name.basename();
    if (basename.length() == 0)
        return false;
    List<String> list = map.get(dirname);
    return (list != null && list.contains(basename));
}
 
Example #27
Source File: ZipFileIndex.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Here we need to make sure that the ZipFileIndex is valid. Check the timestamp of the file and
 * if its the same as the one at the time the index was build we don't need to reopen anything.
 */
private void checkIndex() throws IOException {
    boolean isUpToDate = true;
    if (!isUpToDate()) {
        closeFile();
        isUpToDate = false;
    }

    if (zipRandomFile != null || isUpToDate) {
        lastReferenceTimeStamp = System.currentTimeMillis();
        return;
    }

    hasPopulatedData = true;

    if (readIndex()) {
        lastReferenceTimeStamp = System.currentTimeMillis();
        return;
    }

    directories = Collections.<RelativeDirectory, DirectoryEntry>emptyMap();
    allDirs = Collections.<RelativeDirectory>emptySet();

    try {
        openFile();
        long totalLength = zipRandomFile.length();
        ZipDirectory directory = new ZipDirectory(zipRandomFile, 0L, totalLength, this);
        directory.buildIndex();
    } finally {
        if (zipRandomFile != null) {
            closeFile();
        }
    }

    lastReferenceTimeStamp = System.currentTimeMillis();
}
 
Example #28
Source File: JavacFileManager.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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);
            }
        }
    }
}
 
Example #29
Source File: JavacFileManager.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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);
            }
        }
    }
}
 
Example #30
Source File: ZipFileIndex.java    From java-n-IDE-for-Android with Apache License 2.0 5 votes vote down vote up
/**
 * Here we need to make sure that the ZipFileIndex is valid. Check the timestamp of the file and
 * if its the same as the one at the time the index was build we don't need to reopen anything.
 */
private void checkIndex() throws IOException {
    boolean isUpToDate = true;
    if (!isUpToDate()) {
        closeFile();
        isUpToDate = false;
    }

    if (zipRandomFile != null || isUpToDate) {
        lastReferenceTimeStamp = System.currentTimeMillis();
        return;
    }

    hasPopulatedData = true;

    if (readIndex()) {
        lastReferenceTimeStamp = System.currentTimeMillis();
        return;
    }

    directories = Collections.<RelativeDirectory, DirectoryEntry>emptyMap();
    allDirs = Collections.<RelativeDirectory>emptySet();

    try {
        openFile();
        long totalLength = zipRandomFile.length();
        ZipDirectory directory = new ZipDirectory(zipRandomFile, 0L, totalLength, this);
        directory.buildIndex();
    } finally {
        if (zipRandomFile != null) {
            closeFile();
        }
    }

    lastReferenceTimeStamp = System.currentTimeMillis();
}