Package javax.tools

Examples of javax.tools.FileObject


    }

    private void writeServices() {
        try {
            FileObject out = processingEnv.getFiler().createResource(StandardLocation.CLASS_OUTPUT, "", "META-INF/one",new Element[0]);
            OutputStream os = out.openOutputStream();
            OutputStream os2 = processingEnv.getFiler().createSourceFile("org.Milos", new Element[0]).openOutputStream();
            OutputStreamWriter osr = new OutputStreamWriter(os2);
            try {
                PrintWriter w = new PrintWriter(new OutputStreamWriter(os, "UTF-8"));
                w.write("test");
View Full Code Here


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

      final TransformerFactory transFactory = TransformerFactory.newInstance();
      transFactory.setAttribute("indent-number", 2);
      final 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();

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

  }

  private void writeFile(final ClassInfo info, final 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

  protected void writeCheckstyleConfig(final Document document) throws 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();

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

        // printwriter for writing list of MISO plugins
        processingEnv.getMessager().printMessage(
            Diagnostic.Kind.NOTE,
            "Generating services for MISO plugins");

        FileObject fo = processingEnv.getFiler().createResource(
            StandardLocation.CLASS_OUTPUT,
            "",
            "META-INF/miso/plugins");

        Writer w = fo.openWriter();
        writer = new PrintWriter(w);

        for (TypeElement misoElement : misoElements) {
          writer.println(misoElement.getQualifiedName());
        }
View Full Code Here

            Filer filer = processingEnv.getFiler();

            JAXBContext context = JAXBContext.newInstance(MountPoint.class);
            MountPoint mountPoint = readExistingData(filer, context);

            FileObject file = createXmlFile(filer, messager, elementList);
            setupMountPoint(mountPoint, pathList);
            writeMountPoint(context, file, mountPoint);
        } catch (JAXBException ex) {
            messager.printMessage(Diagnostic.Kind.ERROR, "Can not create a java source file");
            LOGGER.error("Can not create a java source file", ex);
View Full Code Here

    }

    public static final String XML_FILE_NAME = "META-INF/mountpath/MountPoints.xml";

    private MountPoint readExistingData(Filer filer, JAXBContext context) throws IOException, JAXBException {
        FileObject file = filer.getResource(StandardLocation.CLASS_OUTPUT, "", XML_FILE_NAME);
        InputStream stream = null;

        MountPoint mountPoint = null;
        try {
            stream = new BufferedInputStream(file.openInputStream());
            Unmarshaller unmarshaller = context.createUnmarshaller();
            LOGGER.info("XML file exists.");

            Object unmarshalled = unmarshaller.unmarshal(stream);
            if (unmarshalled != null) {
View Full Code Here

        if(mountPoint == null) mountPoint = new MountPoint();
        return mountPoint;
    }

    private FileObject createXmlFile(Filer filer, Messager messager, Collection<? extends Element> annotations) throws IOException {
        FileObject file = filer.createResource(
                StandardLocation.CLASS_OUTPUT,
                "",
                XML_FILE_NAME,
                annotations.toArray(new Element[0]));
        return file;
View Full Code Here

        try {
          // would like to be able to print the full path
          // before we attempt to get the resource in case the behavior
          // of filer.getResource does change to match the spec, but there's
          // no good way to resolve CLASS_OUTPUT without first getting a resource.
          FileObject existingFile = filer.getResource(StandardLocation.CLASS_OUTPUT, "",
              resourceFile);
          log("Looking for existing resource file at " + existingFile.toUri());
          Set<String> oldServices = ServicesFiles.readServiceFile(existingFile.openInputStream());
          log("Existing service entries: " + oldServices);
          allServices.addAll(oldServices);
        } catch (IOException e) {
          // According to the javadoc, Filer.getResource throws an exception
          // if the file doesn't already exist.  In practice this doesn't
          // appear to be the case.  Filer.getResource will happily return a
          // FileObject that refers to a non-existent file but will throw
          // IOException if you try to open an input stream for it.
          log("Resource file did not already exist.");
        }

        Set<String> newServices = new HashSet<String>(providers.get(providerInterface));
        if (allServices.containsAll(newServices)) {
          log("No new service entries being added.");
          return;
        }

        allServices.addAll(newServices);
        log("New service file contents: " + allServices);
        FileObject fileObject = filer.createResource(StandardLocation.CLASS_OUTPUT, "",
            resourceFile);
        OutputStream out = fileObject.openOutputStream();
        ServicesFiles.writeServiceFile(allServices, out);
        out.close();
        log("Wrote to: " + fileObject.toUri());
      } catch (IOException e) {
        fatalError("Unable to create " + resourceFile + ", " + e);
        return;
      }
    }
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.