Package javax.tools

Examples of javax.tools.FileObject


    protected void processFile(String packageName, String scheme, String fileName, Func1<PrintWriter, Void> handler) {
        PrintWriter writer = null;
        try {
            Writer out = null;
            Filer filer = processingEnv.getFiler();
            FileObject resource;
            try {
                resource = filer.getResource(StandardLocation.CLASS_OUTPUT, packageName, fileName);
            } catch (Throwable e) {
                //resource = filer.createResource(StandardLocation.CLASS_OUTPUT, "org.apache.camel", "CamelAPT2.txt", rootElements.toArray(new Element[rootElements.size()]));
                resource = filer.createResource(StandardLocation.CLASS_OUTPUT, packageName, fileName, new Element[0]);
            }
            URI uri = resource.toUri();
            File file = null;
            if (uri != null) {
                try {
                    file = new File(uri.getPath());
                } catch (Exception e) {
View Full Code Here


  public static void writeFile(MetaEntity entity, Context context) {
    try {
      String metaModelPackage = entity.getPackageName();
      StringBuffer body = generateBody( entity, context );

      FileObject fo = context.getProcessingEnvironment().getFiler().createSourceFile(
          metaModelPackage + "." + entity.getSimpleName() + "_"
      );
      OutputStream os = fo.openOutputStream();
      PrintWriter pw = new PrintWriter( os );

      pw.println( "package " + metaModelPackage + ";" );
      pw.println();
      pw.println( entity.generateImports() );
View Full Code Here

    String pkg = getPackage( resource );
    String name = getRelativeName( resource );
    context.logMessage( Diagnostic.Kind.OTHER, "Reading resource " + resource );
    InputStream ormStream;
    try {
      FileObject fileObject = context.getProcessingEnvironment()
          .getFiler()
          .getResource( StandardLocation.CLASS_OUTPUT, pkg, name );
      ormStream = fileObject.openInputStream();
    }
    catch ( IOException e1 ) {
      // TODO
      // unfortunately, the Filer.getResource API seems not to be able to load from /META-INF. One gets a
      // FilerException with the message with "Illegal name /META-INF". This means that we have to revert to
View Full Code Here

      IOException, TransformerException {
    Writer writer = null;
    try {
      final String path = "checkstyle-tobago.xml";
      final String name = (StringUtils.isNotBlank(targetCheckstyle) ? targetCheckstyle + '/' : "") + path;
      final FileObject resource = processingEnv.getFiler().createResource(StandardLocation.SOURCE_OUTPUT, "", name);
      info("Writing to file: " + resource.toUri());
      writer = resource.openWriter();

      TransformerFactory transFactory = TransformerFactory.newInstance();
      transFactory.setAttribute("indent-number", 2);
      Transformer transformer = transFactory.newTransformer();
      transformer.setOutputProperty(OutputKeys.DOCTYPE_PUBLIC, "-//Puppy Crawl//DTD Check Configuration 1.2//EN");
View Full Code Here

  }

  private void writeFile(ClassInfo info, StringTemplate stringTemplate) throws IOException {
    Writer writer = null;
    try {
      final FileObject resource = processingEnv.getFiler().createSourceFile(
          info.getPackageName() + '.' + info.getClassName());
      info("Writing to file: " + resource.toUri());
      writer = resource.openWriter();

      writer.append(stringTemplate.toString());
    } finally {
      IOUtils.closeQuietly(writer);
    }
View Full Code Here

    // writing the XML document

    Writer writer = null;
    try {
      String name = type.filename(targetTaglib, packageElement.getQualifiedName().toString(), taglibAnnotation.name());
      FileObject resource = processingEnv.getFiler().createResource(StandardLocation.SOURCE_OUTPUT, "", name);
      info("Writing to file: " + resource.toUri());
      writer = resource.openWriter();

      TransformerFactory transFactory = TransformerFactory.newInstance();
      transFactory.setAttribute("indent-number", 2);
      Transformer transformer = transFactory.newTransformer();
      transformer.setOutputProperty(OutputKeys.INDENT, "yes");
View Full Code Here

        rootElement.addContent(lastIndex, newConverters);
      }
      if (!newValidators.isEmpty()) {
        rootElement.addContent(newValidators);
      }
      final FileObject resource = processingEnv.getFiler().createResource(
          StandardLocation.SOURCE_OUTPUT, "", targetFacesConfigFile);
      info("Writing to file: " + resource.toUri());
      writer = resource.openWriter();

      StringWriter facesConfig = new StringWriter(1024);
      Format format = Format.getPrettyFormat();
      format.setLineSeparator(SEPARATOR);
      XMLOutputter out = new XMLOutputter(format);
View Full Code Here

            throw e;
        }
    }

    private void write(TypeElement c) throws IOException {
        FileObject f = processingEnv.getFiler().createResource(StandardLocation.CLASS_OUTPUT,
                "", "META-INF/services/hudson.Plugin");
        Writer w = new OutputStreamWriter(f.openOutputStream(),"UTF-8");
        try {
            w.write(c.getQualifiedName().toString());
        } finally {
            w.close();
        }
View Full Code Here

        try {
            Map<String, Object> model = new HashMap<>();
            model.put("modules", modules);
            model.put("properties", gwtConfigProps);

            FileObject sourceFile = filer.createResource(StandardLocation.SOURCE_OUTPUT, MODULE_PACKAGENAME,
                    MODULE_FILENAME);
            OutputStream output = sourceFile.openOutputStream();
            new TemplateProcessor().process(MODULE_TEMPLATE, model, output);
            output.flush();
            output.close();
            System.out.println("Written GWT module to " + sourceFile.toUri().toString());
        } catch (IOException e) {
            throw new RuntimeException("Failed to create file", e);
        }
    }
View Full Code Here

        try {
            Map<String, Object> model = new HashMap<>();
            model.put("modules", modules);
            model.put("properties", gwtConfigProps);

            FileObject sourceFile = filer.createResource(StandardLocation.SOURCE_OUTPUT, MODULE_PACKAGENAME,
                    MODULE_DEV_FILENAME);
            OutputStream output = sourceFile.openOutputStream();
            new TemplateProcessor().process(MODULE_DEV_TEMPLATE, model, output);
            output.flush();
            output.close();
            System.out.println("Written GWT dev module to " + sourceFile.toUri().toString());
        } catch (IOException e) {
            throw new RuntimeException("Failed to create file", e);
        }
    }
View Full Code Here

TOP

Related Classes of javax.tools.FileObject

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.