use of org.eclipse.ceylon.javax.tools.FileObject in project ceylon by eclipse.
the class JNIWriter method write.
/**
* Emit a class file for a given class.
* @param c The class from which a class file is generated.
*/
public FileObject write(ClassSymbol c) throws IOException {
String className = c.flatName().toString();
FileObject outFile = fileManager.getFileForOutput(StandardLocation.NATIVE_HEADER_OUTPUT, "", className.replaceAll("[.$]", "_") + ".h", null);
Writer out = outFile.openWriter();
try {
write(out, c);
if (verbose)
log.printVerbose("wrote.file", outFile);
out.close();
out = null;
} finally {
if (out != null) {
// if we are propogating an exception, delete the file
out.close();
outFile.delete();
outFile = null;
}
}
// may be null if write failed
return outFile;
}
use of org.eclipse.ceylon.javax.tools.FileObject in project ceylon by eclipse.
the class LanguageCompiler method addResources.
private void addResources() throws Abort {
HashSet<String> written = new HashSet<String>();
try {
for (JavaFileObject fo : resourceFileObjects) {
CeyloncFileManager dfm = (CeyloncFileManager) fileManager;
String jarFileName = JarUtils.toPlatformIndependentPath(dfm.getLocation(CeylonLocation.RESOURCE_PATH), fo.getName());
if (!written.contains(jarFileName)) {
dfm.setModule(modelLoader.findModuleForFile(new File(jarFileName)));
FileObject outFile = dfm.getFileForOutput(StandardLocation.CLASS_OUTPUT, "", jarFileName, null);
OutputStream out = outFile.openOutputStream();
try {
InputStream in = new FileInputStream(new File(fo.getName()));
try {
JarUtils.copy(in, out);
} finally {
in.close();
}
} finally {
out.close();
}
written.add(jarFileName);
}
}
} catch (IOException ex) {
throw new Abort(ex);
}
}
Aggregations