コード例 #1
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;
  }
コード例 #2
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;
 }