Search in sources :

Example 91 with FileObject

use of javax.tools.FileObject in project ceylon-compiler by ceylon.

the class ClassDocImpl method containingPackage.

/**
 * Return the package that this class is contained in.
 */
@Override
public PackageDoc containingPackage() {
    PackageDocImpl p = env.getPackageDoc(tsym.packge());
    if (p.setDocPath == false) {
        FileObject docPath;
        try {
            Location location = env.fileManager.hasLocation(StandardLocation.SOURCE_PATH) ? StandardLocation.SOURCE_PATH : StandardLocation.CLASS_PATH;
            docPath = env.fileManager.getFileForInput(location, p.qualifiedName(), "package.html");
        } catch (IOException e) {
            docPath = null;
        }
        if (docPath == null) {
            // fall back on older semantics of looking in same directory as
            // source file for this class
            SourcePosition po = position();
            if (env.fileManager instanceof StandardJavaFileManager && po instanceof SourcePositionImpl) {
                URI uri = ((SourcePositionImpl) po).filename.toUri();
                if ("file".equals(uri.getScheme())) {
                    File f = new File(uri);
                    File dir = f.getParentFile();
                    if (dir != null) {
                        File pf = new File(dir, "package.html");
                        if (pf.exists()) {
                            StandardJavaFileManager sfm = (StandardJavaFileManager) env.fileManager;
                            docPath = sfm.getJavaFileObjects(pf).iterator().next();
                        }
                    }
                }
            }
        }
        p.setDocPath(docPath);
    }
    return p;
}
Also used : StandardJavaFileManager(javax.tools.StandardJavaFileManager) FileObject(javax.tools.FileObject) IOException(java.io.IOException) URI(java.net.URI) File(java.io.File) StandardLocation(javax.tools.StandardLocation) Location(javax.tools.JavaFileManager.Location)

Example 92 with FileObject

use of javax.tools.FileObject in project ceylon-compiler by ceylon.

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(javax.tools.JavaFileObject) Abort(com.sun.tools.javac.util.Abort) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) OutputStream(java.io.OutputStream) FileObject(javax.tools.FileObject) JavaFileObject(javax.tools.JavaFileObject) CeylonFileObject(com.redhat.ceylon.compiler.java.codegen.CeylonFileObject) IOException(java.io.IOException) VirtualFile(com.redhat.ceylon.compiler.typechecker.io.VirtualFile) File(java.io.File) FileInputStream(java.io.FileInputStream) HashSet(java.util.HashSet)

Example 93 with FileObject

use of javax.tools.FileObject in project pentaho-kettle by pentaho.

the class PDI_6976_Test method testVerifyNoPreviousStep.

@Test
public void testVerifyNoPreviousStep() {
    LoadFileInputMeta spy = spy(new LoadFileInputMeta());
    FileInputList fileInputList = mock(FileInputList.class);
    List<FileObject> files = when(mock(List.class).size()).thenReturn(1).getMock();
    doReturn(files).when(fileInputList).getFiles();
    doReturn(fileInputList).when(spy).getFiles(any(VariableSpace.class));
    @SuppressWarnings("unchecked") List<CheckResultInterface> validationResults = mock(List.class);
    // Check we do not get validation errors
    doAnswer(new Answer<Object>() {

        @Override
        public Object answer(InvocationOnMock invocation) throws Throwable {
            if (((CheckResultInterface) invocation.getArguments()[0]).getType() != CheckResultInterface.TYPE_RESULT_OK) {
                TestCase.fail("We've got validation error");
            }
            return null;
        }
    }).when(validationResults).add(any(CheckResultInterface.class));
    spy.check(validationResults, mock(TransMeta.class), mock(StepMeta.class), mock(RowMetaInterface.class), new String[] {}, new String[] { "File content", "File size" }, mock(RowMetaInterface.class), mock(VariableSpace.class), mock(Repository.class), mock(IMetaStore.class));
}
Also used : VariableSpace(org.pentaho.di.core.variables.VariableSpace) TransMeta(org.pentaho.di.trans.TransMeta) RowMetaInterface(org.pentaho.di.core.row.RowMetaInterface) StepMeta(org.pentaho.di.trans.step.StepMeta) IMetaStore(org.pentaho.metastore.api.IMetaStore) Repository(org.pentaho.di.repository.Repository) InvocationOnMock(org.mockito.invocation.InvocationOnMock) FileObject(javax.tools.FileObject) FileObject(javax.tools.FileObject) CheckResultInterface(org.pentaho.di.core.CheckResultInterface) FileInputList(org.pentaho.di.core.fileinput.FileInputList) Test(org.junit.Test)

Example 94 with FileObject

use of javax.tools.FileObject in project lombok by rzwitserloot.

the class SpiProcessorPersistence method write.

void write(String serviceName, String value) throws IOException {
    FileObject output = filer.createResource(StandardLocation.CLASS_OUTPUT, "", path + serviceName);
    Writer writer = output.openWriter();
    writer.write("# Generated by " + name + "\n");
    writer.write("# " + new SimpleDateFormat("EEE, d MMM yyyy HH:mm:ss Z", Locale.US).format(new Date()) + "\n");
    writer.write(value);
    writer.close();
}
Also used : FileObject(javax.tools.FileObject) SimpleDateFormat(java.text.SimpleDateFormat) Writer(java.io.Writer) Date(java.util.Date)

Example 95 with FileObject

use of javax.tools.FileObject in project lombok by rzwitserloot.

the class SpiProcessorCollector method readInitialData.

private CharSequence readInitialData(String serviceName) {
    String pathName = SpiProcessor.getRootPathOfServiceFiles() + serviceName;
    FileObject resource;
    try {
        resource = filer.getResource(StandardLocation.CLASS_OUTPUT, "", pathName);
    } catch (Exception e) {
        logger.printMessage(Kind.ERROR, SpiProcessor.toErrorMsg(e, pathName));
        return null;
    }
    return SpiProcessorPersistence.readFilerResource(resource, logger, pathName);
}
Also used : FileObject(javax.tools.FileObject)

Aggregations

FileObject (javax.tools.FileObject)98 IOException (java.io.IOException)61 File (java.io.File)21 TypeElement (javax.lang.model.element.TypeElement)19 PrintWriter (java.io.PrintWriter)17 Writer (java.io.Writer)16 Filer (javax.annotation.processing.Filer)14 Element (javax.lang.model.element.Element)14 BufferedWriter (java.io.BufferedWriter)12 ArrayList (java.util.ArrayList)12 OutputStream (java.io.OutputStream)11 JavaFileObject (javax.tools.JavaFileObject)11 OutputStreamWriter (java.io.OutputStreamWriter)10 URI (java.net.URI)10 Properties (java.util.Properties)10 InputStream (java.io.InputStream)8 FileWriter (java.io.FileWriter)7 FilerException (javax.annotation.processing.FilerException)7 MainInfo (com.predic8.membrane.annot.model.MainInfo)6 BufferedReader (java.io.BufferedReader)6