Search in sources :

Example 6 with RelativeDirectory

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

the class JavacFileManager method listDirectory.

/**
     * 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 && isValidDirectory(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);
            }
        }
    }
}
Also used : RelativeDirectory(com.sun.tools.javac.file.RelativePath.RelativeDirectory) JavaFileObject(javax.tools.JavaFileObject) RelativeFile(com.sun.tools.javac.file.RelativePath.RelativeFile) ZipFile(java.util.zip.ZipFile) File(java.io.File)

Example 7 with RelativeDirectory

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

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(com.sun.tools.javac.file.RelativePath.RelativeDirectory)

Example 8 with RelativeDirectory

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

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(com.sun.tools.javac.file.RelativePath.RelativeDirectory)

Example 9 with RelativeDirectory

use of com.sun.tools.javac.file.RelativePath.RelativeDirectory in project groovy-cps by cloudbees.

the class Driver method run.

public void run(File dir) throws Exception {
    JavaCompiler javac = JavacTool.create();
    DiagnosticListener<JavaFileObject> errorListener = createErrorListener();
    try (StandardJavaFileManager fileManager = javac.getStandardFileManager(errorListener, Locale.getDefault(), Charset.defaultCharset())) {
        fileManager.setLocation(StandardLocation.CLASS_PATH, Collections.singleton(Which.jarFile(GroovyShell.class)));
        File groovySrcJar = Which.jarFile(Driver.class.getClassLoader().getResource("groovy/lang/GroovyShell.java"));
        // classes to translate
        // TODO include other classes mentioned in DgmConverter if they have any applicable methods; and certainly StringGroovyMethods which has some Closure-based methods
        List<String> fileNames = asList("DefaultGroovyMethods", "DefaultGroovyStaticMethods");
        List<JavaFileObject> src = new ArrayList<>();
        ZipArchive a = new ZipArchive((JavacFileManager) fileManager, new ZipFile(groovySrcJar));
        for (String name : fileNames) {
            src.add(a.getFileObject(new RelativeDirectory("org/codehaus/groovy/runtime"), name + ".java"));
        }
        // annotation processing appears to cause the source files to be reparsed
        // (even though I couldn't find exactly where it's done), which causes
        // Tree symbols created by the original JavacTask.parse() call to be thrown away,
        // which breaks later processing.
        // So for now, don't perform annotation processing
        List<String> options = asList("-proc:none");
        Translator t = new Translator(javac.getTask(null, fileManager, errorListener, options, null, src));
        for (String name : fileNames) {
            t.translate("org.codehaus.groovy.runtime." + name, "com.cloudbees.groovy.cps.Cps" + name, groovySrcJar.getName());
        }
        dir.mkdirs();
        t.generateTo(new FileCodeWriter(dir));
    }
}
Also used : RelativeDirectory(com.sun.tools.javac.file.RelativePath.RelativeDirectory) ArrayList(java.util.ArrayList) JavaCompiler(javax.tools.JavaCompiler) ZipArchive(com.sun.tools.javac.file.ZipArchive) FileCodeWriter(com.sun.codemodel.writer.FileCodeWriter) JavaFileObject(javax.tools.JavaFileObject) ZipFile(java.util.zip.ZipFile) StandardJavaFileManager(javax.tools.StandardJavaFileManager) File(java.io.File) ZipFile(java.util.zip.ZipFile)

Example 10 with RelativeDirectory

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

the class ZipFileIndex method readIndex.

private boolean readIndex() {
    if (triedToReadIndex || !usePreindexedCache) {
        return false;
    }
    boolean ret = false;
    synchronized (this) {
        triedToReadIndex = true;
        RandomAccessFile raf = null;
        try {
            File indexFileName = getIndexFile();
            raf = new RandomAccessFile(indexFileName, "r");
            long fileStamp = raf.readLong();
            if (zipFile.lastModified() != fileStamp) {
                ret = false;
            } else {
                directories = new HashMap<RelativeDirectory, DirectoryEntry>();
                int numDirs = raf.readInt();
                for (int nDirs = 0; nDirs < numDirs; nDirs++) {
                    int dirNameBytesLen = raf.readInt();
                    byte[] dirNameBytes = new byte[dirNameBytesLen];
                    raf.read(dirNameBytes);
                    RelativeDirectory dirNameStr = getRelativeDirectory(new String(dirNameBytes, "UTF-8"));
                    DirectoryEntry de = new DirectoryEntry(dirNameStr, this);
                    de.numEntries = raf.readInt();
                    de.writtenOffsetOffset = raf.readLong();
                    directories.put(dirNameStr, de);
                }
                ret = true;
                zipFileLastModified = fileStamp;
            }
        } catch (Throwable t) {
        // Do nothing
        } finally {
            if (raf != null) {
                try {
                    raf.close();
                } catch (Throwable tt) {
                // Do nothing
                }
            }
        }
        if (ret == true) {
            readFromIndex = true;
        }
    }
    return ret;
}
Also used : RelativeDirectory(com.sun.tools.javac.file.RelativePath.RelativeDirectory) RandomAccessFile(java.io.RandomAccessFile) RandomAccessFile(java.io.RandomAccessFile) RelativeFile(com.sun.tools.javac.file.RelativePath.RelativeFile) 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