示例#1
0
 @Override
 protected void initializeAnnotationProcessorManager() {
   super.initializeAnnotationProcessorManager();
   if (this.batchCompiler.annotationProcessorManager != null && this.processors != null) {
     this.batchCompiler.annotationProcessorManager.setProcessors(this.processors);
   } else if (this.processors != null) {
     throw new UnsupportedOperationException("Cannot handle annotation processing"); // $NON-NLS-1$
   }
 }
示例#2
0
 @Override
 @SuppressWarnings("unchecked")
 protected void initialize(
     PrintWriter outWriter,
     PrintWriter errWriter,
     boolean systemExit,
     Map customDefaultOptions,
     CompilationProgress compilationProgress) {
   super.initialize(outWriter, errWriter, systemExit, customDefaultOptions, compilationProgress);
   this.javaFileObjectMap = new HashMap<CompilationUnit, JavaFileObject>();
 }
示例#3
0
  @Override
  public boolean compileInputSources() {
    initInputClassLoader();
    factory.getEnvironment().debugMessage("compiling input sources: " + sources.getAllJavaFiles());
    long t = System.currentTimeMillis();
    javaCompliance = factory.getEnvironment().getComplianceLevel();

    Main batchCompiler = createBatchCompiler(false);
    List<String> args = new ArrayList<String>();
    args.add("-1." + javaCompliance);
    if (encoding != null) {
      args.add("-encoding");
      args.add(encoding);
    }
    args.add("-preserveAllLocals");
    args.add("-enableJavadoc");
    args.add("-noExit");
    args.add("-proc:none");
    if (getBinaryOutputDirectory() != null) {
      args.add("-d");
      args.add(getBinaryOutputDirectory().getAbsolutePath());
    } else {
      args.add("-d");
      args.add("none");
    }

    String finalClassPath = null;
    if (getSourceClasspath() != null) {
      finalClassPath = computeJdtClassPath();
    } else {
      ClassLoader currentClassLoader = Thread.currentThread().getContextClassLoader();
      if (currentClassLoader instanceof URLClassLoader) {
        URL[] urls = ((URLClassLoader) currentClassLoader).getURLs();
        if (urls != null && urls.length > 0) {
          String classpath = ".";
          for (URL url : urls) {
            classpath += File.pathSeparator + url.getFile();
          }
          if (classpath != null) {
            finalClassPath = classpath;
          }
        }
      }
    }

    args.add("-cp");
    args.add(finalClassPath);

    // Set<String> paths = new HashSet<String>();
    // for (SpoonFile file : sources.getAllJavaFiles()) {
    // paths.add(file.getParent().getPath());
    // }
    // args.addAll(paths);

    args.addAll(toStringList(sources.getAllJavaFiles()));

    // configure(args.toArray(new String[0]));

    batchCompiler.compile(args.toArray(new String[0]));

    factory
        .getEnvironment()
        .debugMessage("compiled in " + (System.currentTimeMillis() - t) + " ms");
    return probs.size() == 0;
  }
 @Override
 public int run(InputStream in, OutputStream out, OutputStream err, String... arguments) {
   Main compiler = new Main(createPrintWriter(out), createPrintWriter(err), true, null, null);
   boolean succeed = compiler.compile(arguments);
   return succeed ? 0 : -1;
 }