Search in sources :

Example 1 with FileObject

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;
}
Also used : FileObject(org.eclipse.ceylon.javax.tools.FileObject) Writer(java.io.Writer)

Example 2 with FileObject

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);
    }
}
Also used : JavaFileObject(org.eclipse.ceylon.javax.tools.JavaFileObject) Abort(org.eclipse.ceylon.langtools.tools.javac.util.Abort) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) OutputStream(java.io.OutputStream) JavaFileObject(org.eclipse.ceylon.javax.tools.JavaFileObject) FileObject(org.eclipse.ceylon.javax.tools.FileObject) CeylonFileObject(org.eclipse.ceylon.compiler.java.codegen.CeylonFileObject) IOException(java.io.IOException) VirtualFile(org.eclipse.ceylon.compiler.typechecker.io.VirtualFile) File(java.io.File) FileInputStream(java.io.FileInputStream) HashSet(java.util.HashSet)

Aggregations

FileObject (org.eclipse.ceylon.javax.tools.FileObject)2 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 OutputStream (java.io.OutputStream)1 Writer (java.io.Writer)1 HashSet (java.util.HashSet)1 CeylonFileObject (org.eclipse.ceylon.compiler.java.codegen.CeylonFileObject)1 VirtualFile (org.eclipse.ceylon.compiler.typechecker.io.VirtualFile)1 JavaFileObject (org.eclipse.ceylon.javax.tools.JavaFileObject)1 Abort (org.eclipse.ceylon.langtools.tools.javac.util.Abort)1