Package javax.tools

Examples of javax.tools.JavaFileManager


                                                   final long compilationVersion) {
    // compile java
    DiagnosticCollector<JavaFileObject> diagnosticCollector
        = new DiagnosticCollector<JavaFileObject>();

    JavaFileManager javaFileManager
        = new JavaFileManagerImpl(javaCompiler.getStandardFileManager(diagnosticCollector,
                                                                      Locale.US,
                                                                      Charsets.US_ASCII),
                                  outFs);
    String className = classBase + compilationVersion;

    try {
      JavaFileObject compilationUnit = javaFileManager.getJavaFileForInput(
          StandardLocation.SOURCE_PATH, className, JavaFileObject.Kind.SOURCE);

      Iterable<JavaFileObject> compilationUnits = ImmutableList.of(compilationUnit);

      javaCompiler.getTask(null, javaFileManager, diagnosticCollector,
                           null, null, compilationUnits).call();

      List<Diagnostic<? extends JavaFileObject>> diagnostics =
          filterErrors(diagnosticCollector.getDiagnostics());

      if (!diagnostics.isEmpty()) {
        throw new GxpCompilationException.Java(diagnostics);
      }

      List<byte[]> classFiles = Lists.newArrayList();
      for (FileRef fileRef : outFs.getManifest()) {
        if (fileRef.getKind().equals(JavaFileObject.Kind.CLASS)) {
          String outputClassName = javaFileManager.inferBinaryName(StandardLocation.CLASS_OUTPUT,
                                                                   new JavaFileRef(fileRef));
          if (outputClassName.equals(className) || outputClassName.startsWith(className + "$")) {
            classFiles.add(ByteStreams.toByteArray(fileRef.openInputStream()));
          }
        }
View Full Code Here


    String relativedName = className.substring(className.lastIndexOf('.') + 1, className.length());
    String patName = relativedName.replace("*", "(\\w+)");
    Pattern pat = Pattern.compile(patName);

    JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
    JavaFileManager fm = compiler.getStandardFileManager(
        new DiagnosticCollector<JavaFileObject>(), null, null);
    HashSet<JavaFileObject.Kind> kind = new HashSet<JavaFileObject.Kind>(){{
        add(JavaFileObject.Kind.CLASS);
    }};

    for (JavaFileObject f : fm.list(StandardLocation.PLATFORM_CLASS_PATH, packageName, kind, false)) {
      String relatived0 = f.getName();
      String name0 = relatived0.substring(0, relatived0.length() - ".class".length());
      Matcher m = pat.matcher(name0);
      if (m.matches()) {
        String name = packageName + '.' + name0;
View Full Code Here

   * @throws FileNotFoundException
   * @throws IOException
   */
  public void saveToJar(String packageName, Class<?> clazz, Class<?> mainClazz, OutputStream outStream,
      boolean recursive) throws IOException {
    JavaFileManager manager = fileManagerCache.get(clazz);
    List<JavaFileObject> list = new ArrayList<JavaFileObject>();
   
    for(JavaFileObject obj : manager.list(StandardLocation.CLASS_PATH, packageName,
      Collections.singleton(JavaFileObject.Kind.CLASS), false))
      list.add(obj);

   
    if (list.iterator().hasNext()) {
View Full Code Here

         throw new IllegalStateException("Cannot find the system Java compiler. "
               + "Check that your class path includes tools.jar");
      }
      classLoader = new ClassLoaderImpl(loader);
      diagnostics = new DiagnosticCollector<JavaFileObject>();
      final JavaFileManager fileManager;
      if (parentFileManager == null) {
        fileManager = compiler.getStandardFileManager(diagnostics, null, null);
      }
      else {
        fileManager = parentFileManager;
View Full Code Here

        if (compiler == null) {
            throw new RuntimeException("No java compiler in class path");
        }

        final JavaFileManager fileManager = new JciJavaFileManager(units, pStore);
        final DiagnosticCollector<JavaFileObject> diagnostics = new DiagnosticCollector<JavaFileObject>();

        CompilationTask task = compiler.getTask(null, fileManager, diagnostics, null, null, units);

        if (task.call().booleanValue()) {
View Full Code Here

        DiagnosticCollector<JavaFileObject> diagnostics =
                new DiagnosticCollector<JavaFileObject>();

        //the generated bytecode is fed to the class loader
        JavaFileManager jfm = new
                ForwardingJavaFileManager<StandardJavaFileManager>(
                        compiler.getStandardFileManager(diagnostics, null, null)) {

                    @Override
                    public JavaFileObject getJavaFileForOutput(Location location,
View Full Code Here

    // compile java
    DiagnosticCollector<JavaFileObject> diagnosticCollector
        = new DiagnosticCollector<JavaFileObject>();

    JavaFileManager javaFileManager
        = new JavaFileManagerImpl(SYSTEM_JAVA_COMPILER.getStandardFileManager(diagnosticCollector,
                                                                              Locale.US,
                                                                              Charsets.US_ASCII),
                                  fs);

    JavaFileObject compilationUnit = javaFileManager.getJavaFileForInput(
        StandardLocation.SOURCE_PATH, className, Kind.SOURCE);

    Iterable<JavaFileObject> compilationUnits = Collections.singleton(compilationUnit);

    SYSTEM_JAVA_COMPILER.getTask(null, javaFileManager, diagnosticCollector,
View Full Code Here

    if (jc == null)
    {
      throw new FileSystemException("No java compiler in the current Java. This must be run on a JDK rather on a JRE");
    }

    JavaFileManager fm = new TestClassFileManager<JavaFileManager>(jc.getStandardFileManager(null, null, null), targetDir, Thread.currentThread().getContextClassLoader());

    if (!jc.getTask(null, fm, null, null, null, Collections.singletonList(new JavaSourceFromString(className, s))).call().booleanValue())
    {
      System.out.println(s);
      fail();
View Full Code Here

        DiagnosticCollector<JavaFileObject> diagnostics =
                new DiagnosticCollector<JavaFileObject>();

        //the generated bytecode is fed to the class loader
        JavaFileManager jfm = new
                ForwardingJavaFileManager<StandardJavaFileManager>(
                        compiler.getStandardFileManager(diagnostics, null, null)) {

                    @Override
                    public JavaFileObject getJavaFileForOutput(Location location,
View Full Code Here

    }

    public void compile(String target, JavaSourceFromString... sources) {
        LOG.info("compiling java classes to "+target);
        JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
        JavaFileManager fileManager = compiler.getStandardFileManager(null, null, null);
        DiagnosticCollector<JavaFileObject> diagnostics = new DiagnosticCollector<JavaFileObject>();

        List<String> optionList = Lists.newArrayList();
        // Adds the current classpath to the compiler along with our generated code
        optionList.add("-classpath");
View Full Code Here

TOP

Related Classes of javax.tools.JavaFileManager

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.