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

The following examples show how to use com.sun.tools.javac.file.RelativePath.RelativeDirectory. These examples are extracted from open source projects. 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 Project: TencentKona-8   Source File: ZipFileIndex.java    License: 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 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);
}
 
Example 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();
    }
}
 
Example 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();
    }
}
 
Example 5
Source Project: javaide   Source File: ZipFileIndex.java    License: 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 6
Source Project: hottub   Source File: SymbolArchive.java    License: 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 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);
}
 
Example 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;
                        }
                    }
                });
    }
}
 
Example 9
Source Project: hottub   Source File: ZipFileIndex.java    License: 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 10
Source Project: openjdk-jdk8u   Source File: ZipFileIndex.java    License: 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 11
Source Project: hottub   Source File: JavacFileManager.java    License: 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 12
Source Project: jdk8u60   Source File: JavacFileManager.java    License: 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 Project: java-n-IDE-for-Android   Source File: ZipFileIndex.java    License: 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 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);
}
 
Example 15
Source Project: openjdk-8   Source File: ZipFileIndex.java    License: 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
@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 17
Source Project: TencentKona-8   Source File: ZipFileIndex.java    License: GNU General Public License v2.0 5 votes vote down vote up
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();
}
 
Example 18
Source Project: javaide   Source File: ZipFileIndex.java    License: GNU General Public License v3.0 5 votes vote down vote up
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();
    }
}
 
Example 19
Source Project: java-n-IDE-for-Android   Source File: JavacFileManager.java    License: Apache License 2.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
/**
 * 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 21
Source Project: javaide   Source File: JavacFileManager.java    License: GNU General Public License v3.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 22
Source Project: openjdk-8   Source File: ZipFileIndex.java    License: GNU General Public License v2.0 5 votes vote down vote up
DirectoryEntry(RelativeDirectory dirName, ZipFileIndex index) {
    filesInited = false;
    directoriesInited = false;
    entriesInited = false;

    this.dirName = dirName;
    this.zipFileIndex = index;
}
 
Example 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);
}
 
Example 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);
}
 
Example 25
Source Project: openjdk-jdk8u   Source File: ZipFileIndex.java    License: GNU General Public License v2.0 5 votes vote down vote up
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();
}
 
Example 26
Source Project: hottub   Source File: ZipArchive.java    License: 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 27
Source Project: javaide   Source File: ZipFileIndex.java    License: GNU General Public License v3.0 5 votes vote down vote up
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);
}
 
Example 28
Source Project: java-n-IDE-for-Android   Source File: JavacFileManager.java    License: Apache License 2.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 Project: java-n-IDE-for-Android   Source File: ZipFileIndexCache.java    License: Apache License 2.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 30
Source Project: openjdk-8   Source File: JavacFileManager.java    License: 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);
}