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

The following examples show how to use com.sun.tools.javac.file.RelativePath.RelativeFile. 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: ZipFileIndex.java    From javaide with GNU General Public License v3.0 6 votes vote down vote up
public synchronized int length(RelativeFile path) throws IOException {
    Entry entry = getZipIndexEntry(path);
    if (entry == null)
        throw new FileNotFoundException();

    if (entry.isDir) {
        return 0;
    }

    byte[] header = getHeader(entry);
    // entry is not compressed?
    if (get2ByteLittleEndian(header, 8) == 0) {
        return entry.compressedSize;
    } else {
        return entry.size;
    }
}
 
Example #2
Source File: JavacFileManager.java    From TencentKona-8 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 #3
Source File: ZipFileIndex.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
public synchronized int length(RelativeFile path) throws IOException {
    Entry entry = getZipIndexEntry(path);
    if (entry == null)
        throw new FileNotFoundException();

    if (entry.isDir) {
        return 0;
    }

    byte[] header = getHeader(entry);
    // entry is not compressed?
    if (get2ByteLittleEndian(header, 8) == 0) {
        return entry.compressedSize;
    } else {
        return entry.size;
    }
}
 
Example #4
Source File: ZipFileIndex.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
public synchronized int length(RelativeFile path) throws IOException {
    Entry entry = getZipIndexEntry(path);
    if (entry == null)
        throw new FileNotFoundException();

    if (entry.isDir) {
        return 0;
    }

    byte[] header = getHeader(entry);
    // entry is not compressed?
    if (get2ByteLittleEndian(header, 8) == 0) {
        return entry.compressedSize;
    } else {
        return entry.size;
    }
}
 
Example #5
Source File: JavacFileManager.java    From openjdk-8 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 #6
Source File: JavacFileManager.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
private JavaFileObject getFileForInput(Location location, RelativeFile name) throws IOException {
    Iterable<? extends File> path = getLocation(location);
    if (path == null)
        return null;

    for (File dir: path) {
        Archive a = archives.get(dir);
        if (a == null) {
            if (fsInfo.isDirectory(dir)) {
                File f = name.getFile(dir);
                if (f.exists())
                    return new RegularFileObject(this, f);
                continue;
            }
            // Not a directory, create the archive
            a = openArchive(dir);
        }
        // Process the archive
        if (a.contains(name)) {
            return a.getFileObject(name.dirname(), name.basename());
        }
    }
    return null;
}
 
Example #7
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 #8
Source File: JavacFileManager.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
private JavaFileObject getFileForInput(Location location, RelativeFile name) throws IOException {
    Iterable<? extends File> path = getLocation(location);
    if (path == null)
        return null;

    for (File dir: path) {
        Archive a = archives.get(dir);
        if (a == null) {
            if (fsInfo.isDirectory(dir)) {
                File f = name.getFile(dir);
                if (f.exists())
                    return new RegularFileObject(this, f);
                continue;
            }
            // Not a directory, create the archive
            a = openArchive(dir);
        }
        // Process the archive
        if (a.contains(name)) {
            return a.getFileObject(name.dirname(), name.basename());
        }
    }
    return null;
}
 
Example #9
Source File: T6725036.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
void run() throws Exception {
    RelativeFile TEST_ENTRY_NAME = new RelativeFile("java/lang/String.class");

    File testJar = createJar("test.jar", "java.lang.*");

    try (JarFile j = new JarFile(testJar)) {
        JarEntry je = j.getJarEntry(TEST_ENTRY_NAME.getPath());
        long jarEntryTime = je.getTime();

        Context context = new Context();
        JavacFileManager fm = new JavacFileManager(context, false, null);
        fm.setLocation(StandardLocation.CLASS_PATH, Collections.singletonList(testJar));
        FileObject fo =
            fm.getFileForInput(StandardLocation.CLASS_PATH, "", TEST_ENTRY_NAME.getPath());
        long jfoTime = fo.getLastModified();

        check(je, jarEntryTime, fo, jfoTime);

        if (errors > 0)
            throw new Exception(errors + " occurred");
    }
}
 
Example #10
Source File: JavacFileManager.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
private JavaFileObject getFileForInput(Location location, RelativeFile name) throws IOException {
    Iterable<? extends File> path = getLocation(location);
    if (path == null)
        return null;

    for (File dir: path) {
        Archive a = archives.get(dir);
        if (a == null) {
            if (fsInfo.isDirectory(dir)) {
                File f = name.getFile(dir);
                if (f.exists())
                    return new RegularFileObject(this, f);
                continue;
            }
            // Not a directory, create the archive
            a = openArchive(dir);
        }
        // Process the archive
        if (a.contains(name)) {
            return a.getFileObject(name.dirname(), name.basename());
        }
    }
    return null;
}
 
Example #11
Source File: ZipFileIndex.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
public synchronized int length(RelativeFile path) throws IOException {
    Entry entry = getZipIndexEntry(path);
    if (entry == null)
        throw new FileNotFoundException();

    if (entry.isDir) {
        return 0;
    }

    byte[] header = getHeader(entry);
    // entry is not compressed?
    if (get2ByteLittleEndian(header, 8) == 0) {
        return entry.compressedSize;
    } else {
        return entry.size;
    }
}
 
Example #12
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 #13
Source File: JavacFileManager.java    From javaide with GNU General Public License v3.0 6 votes vote down vote up
private JavaFileObject getFileForInput(Location location, RelativeFile name) throws IOException {
    Iterable<? extends File> path = getLocation(location);
    if (path == null)
        return null;

    for (File dir : path) {
        Archive a = archives.get(dir);
        if (a == null) {
            if (fsInfo.isDirectory(dir)) {
                File f = name.getFile(dir);
                if (f.exists())
                    return new RegularFileObject(this, f);
                continue;
            }
            // Not a directory, create the archive
            a = openArchive(dir);
        }
        // Process the archive
        if (a.contains(name)) {
            return a.getFileObject(name.dirname(), name.basename());
        }
    }
    return null;
}
 
Example #14
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 FileObject getFileForInput(Location location,
                                  String packageName,
                                  String relativeName)
    throws IOException
{
    checkNotModuleOrientedLocation(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 #15
Source File: JavacFileManager.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
private JavaFileObject getFileForInput(Location location, RelativeFile name) throws IOException {
    Iterable<? extends File> path = getLocation(location);
    if (path == null)
        return null;

    for (File dir: path) {
        Archive a = archives.get(dir);
        if (a == null) {
            if (fsInfo.isDirectory(dir)) {
                File f = name.getFile(dir);
                if (f.exists())
                    return new RegularFileObject(this, f);
                continue;
            }
            // Not a directory, create the archive
            a = openArchive(dir);
        }
        // Process the archive
        if (a.contains(name)) {
            return a.getFileObject(name.dirname(), name.basename());
        }
    }
    return null;
}
 
Example #16
Source File: JavacFileManager.java    From openjdk-jdk8u-backup 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 #17
Source File: JavacFileManager.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
private JavaFileObject getFileForInput(Location location, RelativeFile name) throws IOException {
    Iterable<? extends File> path = getLocation(location);
    if (path == null)
        return null;

    for (File dir: path) {
        Archive a = archives.get(dir);
        if (a == null) {
            if (fsInfo.isDirectory(dir)) {
                File f = name.getFile(dir);
                if (f.exists())
                    return new RegularFileObject(this, f);
                continue;
            }
            // Not a directory, create the archive
            a = openArchive(dir);
        }
        // Process the archive
        if (a.contains(name)) {
            return a.getFileObject(name.dirname(), name.basename());
        }
    }
    return null;
}
 
Example #18
Source File: JavacFileManager.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
public JavaFileObject getJavaFileForOutput(Location location,
                                           String className,
                                           JavaFileObject.Kind kind,
                                           FileObject sibling)
    throws IOException
{
    nullCheck(location);
    // validateClassName(className);
    nullCheck(className);
    nullCheck(kind);
    if (!sourceOrClass.contains(kind))
        throw new IllegalArgumentException("Invalid kind: " + kind);
    return getFileForOutput(location, RelativeFile.forClass(className, kind), sibling);
}
 
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: JavacFileManager.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public JavaFileObject getFileObject(Path userPath, RelativeFile name) throws IOException {
    JRTIndex.Entry e = getJRTIndex().getEntry(name.dirname());
    if (symbolFileEnabled && e.ctSym.hidden)
        return null;
    Path p = e.files.get(name.basename());
    if (p != null) {
        return PathFileObject.forJRTPath(JavacFileManager.this, p);
    } else {
        return null;
    }
}
 
Example #21
Source File: JavacFileManager.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
public JavaFileObject getJavaFileForInput(Location location,
                                          String className,
                                          JavaFileObject.Kind kind)
    throws IOException
{
    nullCheck(location);
    // validateClassName(className);
    nullCheck(className);
    nullCheck(kind);
    if (!sourceOrClass.contains(kind))
        throw new IllegalArgumentException("Invalid kind: " + kind);
    return getFileForInput(location, RelativeFile.forClass(className, kind));
}
 
Example #22
Source File: JavacFileManager.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
public JavaFileObject getJavaFileForOutput(Location location,
                                           String className,
                                           JavaFileObject.Kind kind,
                                           FileObject sibling)
    throws IOException
{
    nullCheck(location);
    // validateClassName(className);
    nullCheck(className);
    nullCheck(kind);
    if (!sourceOrClass.contains(kind))
        throw new IllegalArgumentException("Invalid kind: " + kind);
    return getFileForOutput(location, RelativeFile.forClass(className, kind), sibling);
}
 
Example #23
Source File: JavacFileManager.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public JavaFileObject getFileObject(File userPath, RelativeFile name) throws IOException {
    RelativeDirectory root = name.dirname();
    File packagepath = packages.get(root);
    if (packagepath != null) {
        File relpath = FileUtils.resolve(packagepath,name.basename());
        if (relpath.exists()) {
            return PathFileObject.forJarPath(JavacFileManager.this, relpath, archivePath,name);
        }
    }
    return null;
}
 
Example #24
Source File: JavacFileManager.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public JavaFileObject getFileObject(File userPath, RelativeFile name) throws IOException {
    try {
        File f = name.resolveAgainst(userPath);
        if (f.exists())
            return PathFileObject.forSimplePath(JavacFileManager.this,
                    fsInfo.getCanonicalFile(f), f);
    } catch (Exception ignore) {
    }
    return null;
}
 
Example #25
Source File: PathFileObject.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
PathFileObject getSibling(String baseName) {
    return new DirectoryFileObject(fileManager,
            FileUtils.resolveSibling(path,baseName),
            userPackageRootDir,
            new RelativeFile(relativePath.dirname(), baseName)
    );
}
 
Example #26
Source File: JavacFileManager.java    From hottub 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 #27
Source File: JavacFileManager.java    From openjdk-jdk8u 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 #28
Source File: JavacFileManager.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
public JavaFileObject getJavaFileForInput(Location location,
                                          String className,
                                          JavaFileObject.Kind kind)
    throws IOException
{
    nullCheck(location);
    // validateClassName(className);
    nullCheck(className);
    nullCheck(kind);
    if (!sourceOrClass.contains(kind))
        throw new IllegalArgumentException("Invalid kind: " + kind);
    return getFileForInput(location, RelativeFile.forClass(className, kind));
}
 
Example #29
Source File: JavacFileManager.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
public JavaFileObject getJavaFileForOutput(Location location,
                                           String className,
                                           JavaFileObject.Kind kind,
                                           FileObject sibling)
    throws IOException
{
    nullCheck(location);
    // validateClassName(className);
    nullCheck(className);
    nullCheck(kind);
    if (!sourceOrClass.contains(kind))
        throw new IllegalArgumentException("Invalid kind: " + kind);
    return getFileForOutput(location, RelativeFile.forClass(className, kind), sibling);
}
 
Example #30
Source File: JavacFileManager.java    From openjdk-8-source 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);
}