org.eclipse.jdt.core.compiler.batch.BatchCompiler Java Examples

The following examples show how to use org.eclipse.jdt.core.compiler.batch.BatchCompiler. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AARLibraries.java    From appinventor-extensions with Apache License 2.0 5 votes vote down vote up
/**
 * Writes out the R.class files for all of the ARR libraries as well as an R.class file for the
 * main app being compiled.
 *
 * @param outputDir the output directory to write the R.class files to.
 * @param appPackageName The package name of the currently compiling app.
 * @param appRTxt The app's R.txt file containing a list of resources.
 * @return 0 if the operation completes successfully, or 1 if an error occurs.
 * @throws IOException if the program is unable to read any R.txt files or write R.java or
 *                     R.class files
 * @throws InterruptedException if the compiler thread is interrupted.
 */
public int writeRClasses(File outputDir, String appPackageName, File appRTxt) throws IOException, InterruptedException {
  this.outputDir = outputDir;
  SymbolLoader baseSymbolTable = new SymbolLoader(appRTxt, LOG);
  baseSymbolTable.load();

  // aggregate symbols into one writer per package
  Map<String, SymbolWriter> writers = new HashMap<>();
  for (String packageName : symbols.keys()) {
    Collection<SymbolLoader> loaders = symbols.get(packageName);
    SymbolWriter writer = new SymbolWriter(generated, packageName, baseSymbolTable);
    for (SymbolLoader loader : loaders) {
      writer.addSymbolsToWrite(loader);
    }
    writers.put(packageName, writer);
    writer.write();
  }

  // construct compiler command line
  List<String> args = new ArrayList<>();
  args.add("-1.7");
  args.add("-d");
  args.add(outputDir.getAbsolutePath());
  args.add(generated);

  // compile R classes using ECJ batch compiler
  PrintWriter out = new PrintWriter(System.out);
  PrintWriter err = new PrintWriter(System.err);
  if (BatchCompiler.compile(args.toArray(new String[0]), out, err, new NOPCompilationProgress())) {
    return 0;
  } else {
    return 1;
  }
}
 
Example #2
Source File: EclipseJavaCompiler.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public CompilationResult compile(Iterable<String> sourceRoots, File outputClassDirectory) {
	Iterable<String> validSourceRoots = IterableExtensions.filter(sourceRoots, new EmptyOrMissingFilter());
	if (!containsJavaFiles(validSourceRoots)) {
		return CompilationResult.SKIPPED;
	}
	List<String> commandLine = Lists.newArrayList();
	if (configuration.isVerbose()) {
		commandLine.add("-verbose");
	}
	if (configuration.isSkipAnnotationProcessing()) {
		commandLine.add("-proc:none");
	}
	if (configuration.isPreserveInformationAboutFormalParameters()) {
		commandLine.add("-parameters");
	}
	if (classPath != null) {
		Iterable<String> validClasspath = IterableExtensions.filter(classPath, new EmptyOrMissingFilter());
		if (validClasspath.iterator().hasNext()) {
			commandLine.add("-cp \"" + concat(File.pathSeparator, Lists.newArrayList(validClasspath)) + "\"");
		}
	}
	commandLine.add("-d \"" + outputClassDirectory.toString() + "\"");
	commandLine.add("-source " + configuration.getSourceLevel());
	commandLine.add("-target " + configuration.getTargetLevel());
	commandLine.add("-proceedOnError");
	for (String src : validSourceRoots) {
		commandLine.add("\"" + src + "\"");
	}
	String cmdLine = concat(" ", commandLine);
	debugLog("invoke batch compiler with '" + cmdLine + "'");
	boolean result = BatchCompiler.compile(cmdLine, new PrintWriter(getOutputWriter()), new PrintWriter(
			getErrorWriter()), null);
	return result ? CompilationResult.SUCCEEDED : CompilationResult.FAILED;
}
 
Example #3
Source File: XtendBatchCompiler.java    From xtext-xtend with Eclipse Public License 2.0 4 votes vote down vote up
/**
 * @since 2.8
 */
protected boolean preCompile(File classDirectory, Iterable<String> sourcePathDirectories, Iterable<String> classPathEntries) {
	List<String> commandLine = Lists.newArrayList();
	// todo args
	if (isVerbose()) {
		commandLine.add("-verbose");
	}
	if (getJavaSourceVersion() != null) {
		JavaVersion version = JavaVersion.fromQualifier(getJavaSourceVersion());
		if (!version.isAtLeast(JavaVersion.JAVA9)) {
			List<String> bootClassPathEntries = getBootClassPathEntries();
			if (!isEmpty(bootClassPathEntries)) {
				commandLine.add("-bootclasspath \"" + concat(File.pathSeparator, bootClassPathEntries) + "\"");
			}
		}
	}
	if (!isEmpty(classPathEntries)) {
		commandLine.add("-cp \"" + Joiner.on(File.pathSeparator).join(classPathEntries) + "\"");
	}
	commandLine.add("-d \"" + classDirectory.toString() + "\"");
	commandLine.add("-" + getComplianceLevel());
	commandLine.add("-proceedOnError");
	if (encodingProvider.getDefaultEncoding() != null) {
		commandLine.add("-encoding \"" + encodingProvider.getDefaultEncoding() + "\"");
	}
	if (additionalPreCompileArgs != null) {
		commandLine.add(additionalPreCompileArgs);
	}
	List<String> sourceDirectories = newArrayList(sourcePathDirectories);
	commandLine.add(concat(" ", transform(sourceDirectories, new Function<String, String>() {
		@Override
		public String apply(String path) {
			return "\"" + path + "\"";
		}
	})));
	if (log.isDebugEnabled()) {
		log.debug("invoke batch compiler with '" + concat(" ", commandLine) + "'");
	}
	PrintWriter outWriter = getStubCompilerOutputWriter();
	return BatchCompiler.compile(concat(" ", commandLine), outWriter, outWriter, null);
}