use of javax.tools.FileObject in project graal by oracle.
the class MatchProcessor method getLog.
/**
* Logging facility for debugging the annotation processor.
*/
private PrintWriter getLog() {
if (log == null) {
try {
// Create the log file within the generated source directory so it's easy to find.
// /tmp isn't platform independent and java.io.tmpdir can map anywhere, particularly
// on the mac.
FileObject file = processingEnv.getFiler().createResource(StandardLocation.SOURCE_OUTPUT, "", getClass().getSimpleName() + "log");
log = new PrintWriter(new FileWriter(file.toUri().getPath(), true));
} catch (IOException e) {
// Do nothing
}
}
return log;
}
use of javax.tools.FileObject in project syndesis by syndesisio.
the class ActionProcessor method obtainResourceFile.
// *****************************************
// Helpers
// *****************************************
/**
* Helper method to produce class output text file using the given handler
*/
@SuppressFBWarnings("RV_RETURN_VALUE_IGNORED_BAD_PRACTICE")
private File obtainResourceFile(Element element) throws IOException, NoSuchMethodException, InvocationTargetException, IllegalAccessException {
TypeElement classElement;
if (element instanceof TypeElement) {
classElement = (TypeElement) element;
} else if (element instanceof ExecutableElement) {
classElement = (TypeElement) element.getEnclosingElement();
} else {
warning("Unsupported element kind: " + element.getKind());
return null;
}
final String javaTypeName = canonicalClassName(classElement.getQualifiedName().toString());
final String packageName = javaTypeName.substring(0, javaTypeName.lastIndexOf('.'));
final Annotation annotation = element.getAnnotation(annotationClass);
if (annotation == null) {
error("Annotation SyndesisExtensionAction not found processing element " + element);
}
final String actionId = (String) annotationClass.getMethod("id").invoke(annotation);
final String fileName = new StringBuilder().append(classElement.getSimpleName().toString()).append('-').append(Names.sanitize(actionId)).append(".json").toString();
File result = null;
Filer filer = processingEnv.getFiler();
FileObject resource;
try {
resource = filer.getResource(StandardLocation.SOURCE_OUTPUT, packageName, fileName);
} catch (Exception e) {
resource = filer.createResource(StandardLocation.SOURCE_OUTPUT, packageName, fileName);
}
URI uri = resource.toUri();
if (uri != null) {
try {
result = new File(uri.getPath());
} catch (Exception e) {
warning("Cannot convert output directory resource URI to a file " + e);
}
}
if (result == null) {
warning("No class output directory could be found!");
} else {
result.getParentFile().mkdirs();
}
return result;
}
use of javax.tools.FileObject in project fabric8 by fabric8io.
the class AbstractKubernetesAnnotationProcessor method getFileObject.
private FileObject getFileObject(String fileName) throws IOException {
FileObject fileObject = processingEnv.getFiler().getResource(StandardLocation.CLASS_OUTPUT, "", fileName);
Path path = Paths.get(fileObject.toUri());
File file = path.toFile();
if (file.exists() && !file.delete()) {
throw new IOException("Failed to delete old kubernetes json file: " + fileName);
}
fileObject = processingEnv.getFiler().createResource(StandardLocation.CLASS_OUTPUT, "", fileName);
return fileObject;
}
use of javax.tools.FileObject in project mule by mulesoft.
the class AnnotationProcessorResourceGenerator method write.
@Override
protected void write(GeneratedResource resource) {
FileObject file;
try {
file = processingEnv.getFiler().createResource(SOURCE_OUTPUT, EMPTY, resource.getPath());
} catch (IOException e) {
throw wrapException(e, resource);
}
try (OutputStream out = file.openOutputStream()) {
out.write(resource.getContent());
out.flush();
} catch (IOException e) {
throw wrapException(e, resource);
}
}
use of javax.tools.FileObject in project mule by mulesoft.
the class AnnotationProcessorResourceGeneratorTestCase method write.
@Test
public void write() throws Exception {
FileObject file = mock(FileObject.class);
when(processingEnvironment.getFiler().createResource(SOURCE_OUTPUT, EMPTY, RESOURCE_PATH)).thenReturn(file);
OutputStream out = mock(OutputStream.class, RETURNS_DEEP_STUBS);
when(file.openOutputStream()).thenReturn(out);
generator.generateFor(extensionModel);
verify(out).write(RESOURCE_CONTENT);
verify(out).flush();
}
Aggregations