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);
}
}
}
}
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);
}
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);
}
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));
}
}
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;
}
Aggregations