Search in sources :

Example 1 with RelativeDirectory

use of org.eclipse.ceylon.langtools.tools.javac.file.RelativePath.RelativeDirectory in project ceylon by eclipse.

the class SymbolArchive method addZipEntry.

@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);
}
Also used : RelativeDirectory(org.eclipse.ceylon.langtools.tools.javac.file.RelativePath.RelativeDirectory)

Example 2 with RelativeDirectory

use of org.eclipse.ceylon.langtools.tools.javac.file.RelativePath.RelativeDirectory in project ceylon by eclipse.

the class ZipArchive method addZipEntry.

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);
}
Also used : RelativeDirectory(org.eclipse.ceylon.langtools.tools.javac.file.RelativePath.RelativeDirectory)

Example 3 with RelativeDirectory

use of org.eclipse.ceylon.langtools.tools.javac.file.RelativePath.RelativeDirectory in project ceylon by eclipse.

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(org.eclipse.ceylon.langtools.tools.javac.file.RelativePath.RelativeDirectory)

Example 4 with RelativeDirectory

use of org.eclipse.ceylon.langtools.tools.javac.file.RelativePath.RelativeDirectory in project ceylon by eclipse.

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(org.eclipse.ceylon.langtools.tools.javac.file.RelativePath.RelativeDirectory) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) ArrayList(java.util.ArrayList) IOException(java.io.IOException) RandomAccessFile(java.io.RandomAccessFile) RandomAccessFile(java.io.RandomAccessFile) File(java.io.File) RelativeFile(org.eclipse.ceylon.langtools.tools.javac.file.RelativePath.RelativeFile)

Example 5 with RelativeDirectory

use of org.eclipse.ceylon.langtools.tools.javac.file.RelativePath.RelativeDirectory in project ceylon by eclipse.

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(org.eclipse.ceylon.langtools.tools.javac.file.RelativePath.RelativeDirectory) JavaFileObject(org.eclipse.ceylon.javax.tools.JavaFileObject) ListBuffer(org.eclipse.ceylon.langtools.tools.javac.util.ListBuffer) RelativeFile(org.eclipse.ceylon.langtools.tools.javac.file.RelativePath.RelativeFile) ZipFile(java.util.zip.ZipFile) File(java.io.File)

Aggregations

RelativeDirectory (org.eclipse.ceylon.langtools.tools.javac.file.RelativePath.RelativeDirectory)9 RelativeFile (org.eclipse.ceylon.langtools.tools.javac.file.RelativePath.RelativeFile)5 File (java.io.File)4 RandomAccessFile (java.io.RandomAccessFile)2 ZipFile (java.util.zip.ZipFile)2 JavaFileObject (org.eclipse.ceylon.javax.tools.JavaFileObject)2 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 ZipEntry (java.util.zip.ZipEntry)1 ListBuffer (org.eclipse.ceylon.langtools.tools.javac.util.ListBuffer)1