Package javax.tools

Examples of javax.tools.StandardJavaFileManager

Whereas these are not (reason in parentheses): @author Peter von der Ahé @since 1.6

  protected void compile(List<File> sourceFiles) throws Exception {
    List<String> options = createJavaOptions();

    JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
    DiagnosticCollector<JavaFileObject> diagnostics = new DiagnosticCollector<JavaFileObject>();
    StandardJavaFileManager fileManager = compiler.getStandardFileManager( diagnostics, null, null );
    Iterable<? extends JavaFileObject> compilationUnits = fileManager.getJavaFileObjectsFromFiles(
        sourceFiles
    );

    compileSources( options, compiler, diagnostics, fileManager, compilationUnits );
    compilationDiagnostics.addAll( diagnostics.getDiagnostics() );
    fileManager.close();
  }
View Full Code Here


    // space out dots to avoid accidental replace on System DOT out search
    PrintStream sysOut = System . out;
    PrintStream sysErr = System . err;

    StandardJavaFileManager sjfm = null;
   
    if( compile ) {
      try {
        String compilerOpts = tmps.get( Property.main_ExternalCompilerOptions );

        if( !JavaUtil.hasClassPathArg(compilerOpts) ) {
          compilerOpts
            = JavaUtil.ARG_classpath + Standard.SPACE
            + JavaUtil.makeClassPath( tmps )
            + Standard.SPACE
            + compilerOpts
            ;
        }

        String   argstr = compilerOpts + Standard.SPACE + sourceFiles;
        String[] args   = ArgUtil.splitQuoted( argstr );

        mUserMessageHandler.debug( UserText.get(UserText.TXT_compiling), "javax.tools.JavaCompiler" + Standard.SPACE + argstr );

        ByteArrayOutputStream outbaos = new ByteArrayOutputStream();   
        System.setOut( new PrintStream( outbaos ) );

        ByteArrayOutputStream errbaos = new ByteArrayOutputStream();   
        System.setErr( new PrintStream( errbaos ) );
   
        sjfm = sJavaCompiler.getStandardFileManager(null, null, null);
       
        Iterable javafiles = sjfm.getJavaFileObjectsFromStrings( sourceFilesList );
        String[] options   = ArgUtil.splitQuoted( compilerOpts );
       
        boolean compileResult = sJavaCompiler.getTask(null, null, null, Arrays.asList(options), null, javafiles).call();
       
        if( !compileResult ) {
          throw ProcessException.CODE_compile_errors( argstr + Standard.NEWLINE
                                                      + outbaos.toString() + Standard.NEWLINE
                                                      + errbaos.toString() + Standard.NEWLINE );
        }
        else {
          String outstr = outbaos.toString();
          if( null != outstr && !"".equals( outstr ) ) {
            mUserMessageHandler.info( outstr );
          }

          String errstr = errbaos.toString();
          if( null != errstr && !"".equals( errstr ) ) {
            mUserMessageHandler.error( errstr );
          }
        }
      }
      catch( Exception e ) {
        e.printStackTrace();
        if( e instanceof ProcessException ) {
          throw (ProcessException) e;
        }
        else {
          throw ProcessException.CODE_compile_failed( new String[] { "sourcefiles", sourceFiles }, e );
        }
      }
      finally {
        if( null != sysOut ) { System.setOut( sysOut ); }
        if( null != sysErr ) { System.setErr( sysErr ); }
        if( null != sjfm ) {
          try {
            sjfm.close();
          }
          catch( Exception e ) {
            throw new RuntimeException(e);
          }
        }
View Full Code Here

    for (OutputFile o : outputs) {
      javaFiles.add(o.writeToDestination(dstDir));
    }

    JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
    StandardJavaFileManager fileManager =
      compiler.getStandardFileManager(null, null, null);
   
    CompilationTask cTask = compiler.getTask(null, fileManager, null, null,
        null,
        fileManager.getJavaFileObjects(
            javaFiles.toArray(new File[javaFiles.size()])));
    assertTrue(cTask.call());
  }
View Full Code Here

  private static void createTestJar(OutputStream outStream, String dummyClassName)
      throws URISyntaxException, IOException {
    JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
    JavaFileObject srcFileObject = new SimpleJavaFileObjectImpl(
        URI.create("string:///" + dummyClassName + Kind.SOURCE.extension), Kind.SOURCE);
    StandardJavaFileManager fileManager = compiler.getStandardFileManager(null, null, null);
    compiler.getTask(null, fileManager, null, null, null, Collections.singletonList(srcFileObject))
        .call();

    JavaFileObject javaFileObject = fileManager.getJavaFileForOutput(StandardLocation.CLASS_OUTPUT,
        dummyClassName, Kind.CLASS, null);

    File classFile = new File(dummyClassName + Kind.CLASS.extension);

    JarOutputStream jarOutputStream = new JarOutputStream(outStream);
View Full Code Here

   */
  private void parseSourceCode(String filename) throws Exception
  {
     System.out.println("parseSourceCode " + filename);
    JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
    StandardJavaFileManager fileManager = compiler.getStandardFileManager(null, null, null);
    Iterable<? extends JavaFileObject> fileobject = fileManager.getJavaFileObjects(new File(filename));
    CompilationTask parsingTask =  compiler.getTask(null, fileManager, null, null, null, fileobject);
    ArrayList<AbstractProcessor> processor = new ArrayList<AbstractProcessor>(1);
    processor.add(this);
    parsingTask.setProcessorsprocessor);
    parsingTask.call();
    fileManager.close();
   
  }
View Full Code Here

     */
    private Iterator<Processor> handleServiceLoaderUnavailability(String key, Exception e) {
        JavaFileManager fileManager = context.get(JavaFileManager.class);

        if (fileManager instanceof JavacFileManager) {
            StandardJavaFileManager standardFileManager = (JavacFileManager) fileManager;
            Iterable<? extends File> workingPath = fileManager.hasLocation(ANNOTATION_PROCESSOR_PATH)
                ? standardFileManager.getLocation(ANNOTATION_PROCESSOR_PATH)
                : standardFileManager.getLocation(CLASS_PATH);

            if (needClassLoader(options.get("-processor"), workingPath) )
                handleException(key, e);

        } else {
View Full Code Here

                        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();
                            }
                        }

                    }
                }
View Full Code Here

     */
    private JavaFileObject getOverviewPath() {
        for (String[] opt : options) {
            if (opt[0].equals("-overview")) {
                if (env.fileManager instanceof StandardJavaFileManager) {
                    StandardJavaFileManager fm = (StandardJavaFileManager) env.fileManager;
                    return fm.getJavaFileObjects(opt[1]).iterator().next();
                }
            }
        }
        return null;
    }
View Full Code Here

        ListBuffer<String> names = new ListBuffer<String>();
        ListBuffer<JCCompilationUnit> classTrees = new ListBuffer<JCCompilationUnit>();
        ListBuffer<JCCompilationUnit> packTrees = new ListBuffer<JCCompilationUnit>();

        try {
            StandardJavaFileManager fm = (StandardJavaFileManager) docenv.fileManager;
            for (List<String> it = javaNames; it.nonEmpty(); it = it.tail) {
                String name = it.head;
                if (!docClasses && name.endsWith(".java") && new File(name).exists()) {
                    JavaFileObject fo = fm.getJavaFileObjects(name).iterator().next();
                    docenv.notice("main.Loading_source_file", name);
                    JCCompilationUnit tree = parse(fo);
                    classTrees.append(tree);
                } else if (isValidPackageName(name)) {
                    names = names.append(name);
View Full Code Here

            legacyProprietary.remove(name);
            documented.add(name);
        }

        JavaCompiler tool = ToolProvider.getSystemJavaCompiler();
        StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null);
        Location jarLocation = StandardLocation.locationFor(jarName);
        File jarFile = new File(jarName);
        fm.setLocation(jarLocation, List.of(jarFile));
        fm.setLocation(StandardLocation.CLASS_PATH, List.<File>nil());
        fm.setLocation(StandardLocation.SOURCE_PATH, List.<File>nil());
        {
            ArrayList<File> bootClassPath = new ArrayList<File>();
            bootClassPath.add(jarFile);
            for (File path : fm.getLocation(StandardLocation.PLATFORM_CLASS_PATH)) {
                if (!new File(path.getName()).equals(new File("rt.jar")))
                    bootClassPath.add(path);
            }
            System.err.println("Using boot class path = " + bootClassPath);
            fm.setLocation(StandardLocation.PLATFORM_CLASS_PATH, bootClassPath);
        }
        // System.out.println(fm.getLocation(StandardLocation.PLATFORM_CLASS_PATH));
        File destDir = new File(destName);
        if (!destDir.exists())
            if (!destDir.mkdirs())
                throw new RuntimeException("Could not create " + destDir);
        fm.setLocation(StandardLocation.CLASS_OUTPUT, List.of(destDir));
        Set<String> hiddenPackages = new HashSet<String>();
        Set<String> crisp = new HashSet<String>();
        List<String> options = List.of("-XDdev");
        // options = options.prepend("-doe");
        // options = options.prepend("-verbose");
        JavacTaskImpl task = (JavacTaskImpl)
            tool.getTask(null, fm, null, options, null, null);
        com.sun.tools.javac.main.JavaCompiler compiler =
            com.sun.tools.javac.main.JavaCompiler.instance(task.getContext());
        ClassReader reader = ClassReader.instance(task.getContext());
        ClassWriter writer = ClassWriter.instance(task.getContext());
        Symtab syms = Symtab.instance(task.getContext());
        Attribute.Compound proprietary =
            new Attribute.Compound(syms.proprietaryType,
                                   List.<Pair<Symbol.MethodSymbol,Attribute>>nil());

        Type.moreInfo = true;
        Pool pool = new Pool();
        for (JavaFileObject file : fm.list(jarLocation, "", EnumSet.of(CLASS), true)) {
            String className = fm.inferBinaryName(jarLocation, file);
            int index = className.lastIndexOf('.');
            String pckName = index == -1 ? "" : className.substring(0, index);
            boolean addLegacyAnnotation = false;
            if (documented.contains(pckName)) {
                if (!legacy.contains(pckName))
View Full Code Here

TOP

Related Classes of javax.tools.StandardJavaFileManager

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.