Package javax.tools

Examples of javax.tools.FileObject


      if (roundEnv.processingOver())
      {
         // Testsuite
         try
         {
            FileObject file = filer.createResource(StandardLocation.CLASS_OUTPUT, "", "suite.properties");
            OutputStream out = file.openOutputStream();
            all.store(out, null);
            out.close();
         }
         catch (IOException e)
         {
            processingEnv.getMessager().printMessage(Diagnostic.Kind.ERROR, "Could not create test case for package " + e.getMessage());
         }
      }

      //
      reporter.process(annotations, roundEnv);

      //
      Map<PackageElement, List<TypeElement>> map = new HashMap<PackageElement, List<TypeElement>>();
      for (Element annotated : roundEnv.getElementsAnnotatedWith(TestCase.class))
      {
         TestCase tc = annotated.getAnnotation(TestCase.class);
         if (tc.enabled())
         {
            if (annotated instanceof TypeElement)
            {
               PackageElement pkg = processingEnv.getElementUtils().getPackageOf(annotated);
               List<TypeElement> types = map.get(pkg);
               if (types == null)
               {
                  map.put(pkg, types = new ArrayList<TypeElement>());
               }
               types.add((TypeElement)annotated);
            }
         }
      }

      // Generate tests
      for (Map.Entry<PackageElement, List<TypeElement>> entry : map.entrySet())
      {
         PackageElement pkg = entry.getKey();
         Matcher m = P.matcher(pkg.getQualifiedName());
         if (m.matches())
         {
            String version = m.group(1);
            String type = m.group(2);
            String suite = m.group(3);
            String testPkg = version + '.' + type + '.' + suite;

            //
            ClassLoader old = Thread.currentThread().getContextClassLoader();
            try
            {
               Thread.currentThread().setContextClassLoader(WebArchive.class.getClassLoader());
               WebArchive archive = AbstractWarTestCase.createDeployment(version,  type, suite);
               FileObject file = filer.createResource(StandardLocation.CLASS_OUTPUT, testPkg, "suite.war");
               OutputStream out = file.openOutputStream();
               archive.as(ZipExporter.class).exportTo(out);
               out.close();
            }
            catch (Exception e)
            {
               processingEnv.getMessager().printMessage(Diagnostic.Kind.ERROR, "Could not create war file for package " + e.getMessage(), pkg);
            }
            finally
            {
               Thread.currentThread().setContextClassLoader(old);
            }

            // Suite properties
            try
            {
               FileObject file = filer.createResource(StandardLocation.CLASS_OUTPUT, testPkg, "suite.properties");
               OutputStream out = file.openOutputStream();
               Properties props = new Properties();
               for (TypeElement annotated : entry.getValue())
               {
                  props.put(annotated.getQualifiedName().toString(), "testcase");
               }
               props.store(out, null);
               out.close();
            }
            catch (IOException e)
            {
               processingEnv.getMessager().printMessage(Diagnostic.Kind.ERROR, "Could not create test case for package " + e.getMessage(), pkg);
            }

            // Ear test cases
            for (TypeElement annotated : entry.getValue())
            {
               String name = annotated.getSimpleName().toString();
               try
               {
                  String baseFQN = testPkg + "." + name;

                  //
                  all.put(baseFQN, "fqn");

                  //
                  JavaFileObject file = filer.createSourceFile(baseFQN + "EarTestCase");
                  PrintWriter writer = new PrintWriter(file.openWriter());

                  // Package
                  writer.append("package ").append(testPkg).println(";");

                  // Open class
                  writer.append('@').append(RunWith.class.getName()).append('(').append(Arquillian.class.getName()).println(".class)");
                  writer.append("public class ").append(name).println("EarTestCase extends org.gatein.pc.test.unit.AbstractEarTestCase {");

                  // List of deployments
                  List<String[]> deployments = new ArrayList<String[]>();

                  // Add implicit deployment
                  deployments.add(new String[]{version,type,suite});

                  // Additional deployment
                  TestCase annotation = annotated.getAnnotation(TestCase.class);
                  for (Archive deployment : annotation.deployments())
                  {
                     deployments.add(deployment.value());
                  }

                  //
                  writer.append('@').append(Deployment.class.getName()).append("(name = \"deployment").println("\", testable = false)");
                  writer.append("public static ").append(EnterpriseArchive.class.getName()).append(" createDeployment").println("() throws Exception {");
                  writer.append("return ").append(AbstractEarTestCase.class.getName()).append(".createDeployment(");
                  for (int i = 0;i < deployments.size();i++)
                  {
                     if (i > 0)
                     {
                        writer.append(',');
                     }
                     writer.append("new String[]{");
                     String[] deployment = deployments.get(i);
                     for (int j = 0;j < deployment.length;j++)
                     {
                        if (j > 0)
                        {
                           writer.append(',');
                        }
                        writer.append('"').append(deployment[j]).append('"');
                     }
                     writer.append("}");
                  }
                  writer.println(");");
                  writer.println("}");

                  // Constructor
                  writer.append("public ").append(name).println("EarTestCase() {");
                  writer.append("super(\"").append(version).append("\",\"").append(type).append("\",\"").append(suite).append("").append("\",\"").append(name).println("\");");
                  writer.println("}");

                  // URL
                  writer.append('@').append(ArquillianResource.class.getName()).append("(").append(PortalTestServlet.class.getName()).println(".class)");
                  writer.println("java.net.URL deploymentURL;");
                  writer.println("protected java.net.URL getBaseURL() {");
                  writer.println("return deploymentURL;");
                  writer.println("}");

                  // Close class
                  writer.println("}");

                  // Close writer
                  writer.close();
               }
               catch (IOException e)
               {
                  processingEnv.getMessager().printMessage(Diagnostic.Kind.ERROR, "Could not create test case for package " + e.getMessage(), pkg);
               }
            }

            // War test cases
            for (TypeElement annotated : entry.getValue())
            {
               String name = annotated.getSimpleName().toString();
               try
               {
                  JavaFileObject file = filer.createSourceFile(testPkg + "." + name + "WarTestCase");
                  PrintWriter writer = new PrintWriter(file.openWriter());

                  // Package
                  writer.append("package ").append(testPkg).println(";");

                  // Open class
View Full Code Here


        String strPkg = pkg.toString();
        if (strPkg.length() > 0)
            checkName(strPkg);

        FileObject fileObject =
            fileManager.getFileForOutput(location, strPkg,
                                         relativeName.toString(), null);
        checkFileReopening(fileObject, true);

        if (fileObject instanceof JavaFileObject)
View Full Code Here

            checkName(strPkg);

        // TODO: Only support reading resources in selected output
        // locations?  Only allow reading of non-source, non-class
        // files from the supported input locations?
        FileObject fileObject = fileManager.getFileForOutput(location,
                                                             pkg.toString(),
                                                             relativeName.toString(),
                                                             null);
        // If the path was already opened for writing, throw an exception.
        checkFileReopening(fileObject, false);
View Full Code Here

     * Return the package that this class is contained in.
     */
    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(
View Full Code Here

            if (sp == null)
                return;
            Reader r;
            // temp hack until we can update SourcePosition API.
            if (sp instanceof com.sun.tools.javadoc.SourcePositionImpl) {
                FileObject fo = ((com.sun.tools.javadoc.SourcePositionImpl) sp).fileObject();
                if (fo == null)
                    return;
                r = fo.openReader(true);
            } else {
                File file = sp.file();
                if (file == null)
                    return;
                r = new FileReader(file);
View Full Code Here

     */
    protected InputStream getInputStream(String filename, boolean loadingPersistenceXML) {
        InputStream inputStream = null;
       
        try {
            FileObject fileObject = getFileObject(filename, processingEnv);
            inputStream = fileObject.openInputStream();
        } catch (Exception ioe) {
            // If we can't find the persistence.xml from the class output
            // we'll try from the current directory using regular IO.
            try {
                inputStream = new FileInputStream(filename);
View Full Code Here

        {
            Map<String, Object> model = new HashMap<String, Object>();
            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

        {
            Map<String, Object> model = new HashMap<String, Object>();
            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

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

            FileObject sourceFile = filer.createResource(StandardLocation.SOURCE_OUTPUT, MODULE_PACKAGENAME,
                    MODULE_PRODUCT_FILENAME);
            OutputStream output = sourceFile.openOutputStream();
            new TemplateProcessor().process(MODULE_PRODUCT_TEMPLATE, model, output);
            output.flush();
            output.close();
        }
        catch (IOException e)
View Full Code Here

                    gwtConfigProps.get("console.dev.host") : "127.0.0.1";

            Map<String, Object> model = new HashMap<String, Object>();
            model.put("devHost", devHostUrl);

            FileObject sourceFile = filer.createResource(
                    StandardLocation.SOURCE_OUTPUT, "", "gwt-proxy.properties");
            OutputStream output1 = sourceFile.openOutputStream();

            FileObject sourceFile2 = filer.createResource(
                    StandardLocation.SOURCE_OUTPUT, "", "upload-proxy.properties");
            OutputStream output2 = sourceFile2.openOutputStream();

            FileObject sourceFile3 = filer.createResource(
                    StandardLocation.SOURCE_OUTPUT, "", "logout.properties");
            OutputStream output3 = sourceFile3.openOutputStream();

            new TemplateProcessor().process("gwt.proxy.tmpl", model, output1);
            new TemplateProcessor().process("gwt.proxy.upload.tmpl", model, output2);
            new TemplateProcessor().process("gwt.proxy.logout.tmpl", model, output3);
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.