Search in sources :

Example 1 with RelativeDirectory

use of com.sun.tools.javac.file.RelativePath.RelativeDirectory in project ceylon-compiler by ceylon.

the class ZipFileIndex method getRelativeDirectory.

private RelativeDirectory getRelativeDirectory(String path) {
    RelativeDirectory rd;
    SoftReference<RelativeDirectory> ref = relativeDirectoryCache.get(path);
    if (ref != null) {
        rd = ref.get();
        if (rd != null)
            return rd;
    }
    rd = new RelativeDirectory(path);
    relativeDirectoryCache.put(path, new SoftReference<RelativeDirectory>(rd));
    return rd;
}
Also used : RelativeDirectory(com.sun.tools.javac.file.RelativePath.RelativeDirectory)

Example 2 with RelativeDirectory

use of com.sun.tools.javac.file.RelativePath.RelativeDirectory in project ceylon-compiler by ceylon.

the class ZipFileIndex method writeIndex.

private boolean writeIndex() {
    boolean ret = false;
    if (readFromIndex || !usePreindexedCache) {
        return true;
    }
    if (!writeIndex) {
        return true;
    }
    File indexFile = getIndexFile();
    if (indexFile == null) {
        return false;
    }
    RandomAccessFile raf = null;
    long writtenSoFar = 0;
    try {
        raf = new RandomAccessFile(indexFile, "rw");
        raf.writeLong(zipFileLastModified);
        writtenSoFar += 8;
        List<DirectoryEntry> directoriesToWrite = new ArrayList<DirectoryEntry>();
        Map<RelativeDirectory, Long> offsets = new HashMap<RelativeDirectory, Long>();
        raf.writeInt(directories.keySet().size());
        writtenSoFar += 4;
        for (RelativeDirectory dirName : directories.keySet()) {
            DirectoryEntry dirEntry = directories.get(dirName);
            directoriesToWrite.add(dirEntry);
            // Write the dir name bytes
            byte[] dirNameBytes = dirName.getPath().getBytes("UTF-8");
            int dirNameBytesLen = dirNameBytes.length;
            raf.writeInt(dirNameBytesLen);
            writtenSoFar += 4;
            raf.write(dirNameBytes);
            writtenSoFar += dirNameBytesLen;
            // Write the number of files in the dir
            List<Entry> dirEntries = dirEntry.getEntriesAsCollection();
            raf.writeInt(dirEntries.size());
            writtenSoFar += 4;
            offsets.put(dirName, new Long(writtenSoFar));
            // Write the offset of the file's data in the dir
            dirEntry.writtenOffsetOffset = 0L;
            raf.writeLong(0L);
            writtenSoFar += 8;
        }
        for (DirectoryEntry de : directoriesToWrite) {
            // Fix up the offset in the directory table
            long currFP = raf.getFilePointer();
            long offsetOffset = offsets.get(de.dirName).longValue();
            raf.seek(offsetOffset);
            raf.writeLong(writtenSoFar);
            raf.seek(currFP);
            // Now write each of the files in the DirectoryEntry
            List<Entry> list = de.getEntriesAsCollection();
            for (Entry zfie : list) {
                // Write the name bytes
                byte[] zfieNameBytes = zfie.name.getBytes("UTF-8");
                int zfieNameBytesLen = zfieNameBytes.length;
                raf.writeInt(zfieNameBytesLen);
                writtenSoFar += 4;
                raf.write(zfieNameBytes);
                writtenSoFar += zfieNameBytesLen;
                // Write isDir
                raf.writeByte(zfie.isDir ? (byte) 1 : (byte) 0);
                writtenSoFar += 1;
                // Write offset of bytes in the real Jar/Zip file
                raf.writeInt(zfie.offset);
                writtenSoFar += 4;
                // Write size of the file in the real Jar/Zip file
                raf.writeInt(zfie.size);
                writtenSoFar += 4;
                // Write compressed size of the file in the real Jar/Zip file
                raf.writeInt(zfie.compressedSize);
                writtenSoFar += 4;
                // Write java time stamp of the file in the real Jar/Zip file
                raf.writeLong(zfie.getLastModified());
                writtenSoFar += 8;
            }
        }
    } catch (Throwable t) {
    // Do nothing
    } finally {
        try {
            if (raf != null) {
                raf.close();
            }
        } catch (IOException ioe) {
        // Do nothing
        }
    }
    return ret;
}
Also used : RelativeDirectory(com.sun.tools.javac.file.RelativePath.RelativeDirectory) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) IOException(java.io.IOException) RandomAccessFile(java.io.RandomAccessFile) RandomAccessFile(java.io.RandomAccessFile) RelativeFile(com.sun.tools.javac.file.RelativePath.RelativeFile) File(java.io.File)

Example 3 with RelativeDirectory

use of com.sun.tools.javac.file.RelativePath.RelativeDirectory in project ceylon-compiler by ceylon.

the class SymbolArchive method getFileObject.

@Override
public JavaFileObject getFileObject(RelativeDirectory subdirectory, String file) {
    RelativeDirectory prefix_subdir = new RelativeDirectory(prefix, subdirectory.path);
    ZipEntry ze = new RelativeFile(prefix_subdir, file).getZipEntry(zfile);
    return new SymbolFileObject(this, file, ze);
}
Also used : RelativeDirectory(com.sun.tools.javac.file.RelativePath.RelativeDirectory) RelativeFile(com.sun.tools.javac.file.RelativePath.RelativeFile) ZipEntry(java.util.zip.ZipEntry)

Example 4 with RelativeDirectory

use of com.sun.tools.javac.file.RelativePath.RelativeDirectory in project ceylon-compiler by ceylon.

the class ZipArchive method contains.

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));
}
Also used : RelativeDirectory(com.sun.tools.javac.file.RelativePath.RelativeDirectory)

Example 5 with RelativeDirectory

use of com.sun.tools.javac.file.RelativePath.RelativeDirectory in project ceylon-compiler by ceylon.

the class JavacFileManager method list.

public Iterable<JavaFileObject> list(Location location, String packageName, Set<JavaFileObject.Kind> kinds, boolean recurse) throws IOException {
    // validatePackageName(packageName);
    nullCheck(packageName);
    nullCheck(kinds);
    Iterable<? extends File> path = getLocation(location);
    if (path == null)
        return List.nil();
    RelativeDirectory subdirectory = RelativeDirectory.forPackage(packageName);
    ListBuffer<JavaFileObject> results = new ListBuffer<JavaFileObject>();
    for (File directory : path) listContainer(directory, subdirectory, kinds, recurse, results);
    return results.toList();
}
Also used : RelativeDirectory(com.sun.tools.javac.file.RelativePath.RelativeDirectory) JavaFileObject(javax.tools.JavaFileObject) ListBuffer(com.sun.tools.javac.util.ListBuffer) RelativeFile(com.sun.tools.javac.file.RelativePath.RelativeFile) ZipFile(java.util.zip.ZipFile) File(java.io.File)

Aggregations

RelativeDirectory (com.sun.tools.javac.file.RelativePath.RelativeDirectory)10 RelativeFile (com.sun.tools.javac.file.RelativePath.RelativeFile)5 File (java.io.File)5 ZipFile (java.util.zip.ZipFile)3 JavaFileObject (javax.tools.JavaFileObject)3 RandomAccessFile (java.io.RandomAccessFile)2 ArrayList (java.util.ArrayList)2 FileCodeWriter (com.sun.codemodel.writer.FileCodeWriter)1 ZipArchive (com.sun.tools.javac.file.ZipArchive)1 ListBuffer (com.sun.tools.javac.util.ListBuffer)1 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 ZipEntry (java.util.zip.ZipEntry)1 JavaCompiler (javax.tools.JavaCompiler)1 StandardJavaFileManager (javax.tools.StandardJavaFileManager)1