当前位置: 首页>>代码示例>>Java>>正文


Java BatchCompiler类代码示例

本文整理汇总了Java中org.eclipse.jdt.core.compiler.batch.BatchCompiler的典型用法代码示例。如果您正苦于以下问题:Java BatchCompiler类的具体用法?Java BatchCompiler怎么用?Java BatchCompiler使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


BatchCompiler类属于org.eclipse.jdt.core.compiler.batch包,在下文中一共展示了BatchCompiler类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: compileClass

import org.eclipse.jdt.core.compiler.batch.BatchCompiler; //导入依赖的package包/类
@Before
public void compileClass() throws IOException {
    Set<File> classes = searchFile(new SuffixFilter("class"), dir);
    Map<String, File> name2file = new Hashtable<>(classes.size());
    for (File classFile : classes) {
        name2file.put(classFile.getAbsolutePath(), classFile);
    }
    Set<File> srcs = searchFile(new SuffixFilter("java"), dir);
    StringBuilder names = new StringBuilder(), paths = new StringBuilder();
    for (File src : srcs) {
        String classLocation = src.getAbsolutePath().substring(0, src.getAbsolutePath().length() - "java".length()) + "class";
        if (name2file.containsKey(classLocation)) {
            if (name2file.get(classLocation).lastModified() > src.lastModified()) {
                System.out.println("Cached: " + src.getName());
                continue;
            }
        }
        names.append(" ").append(src.getName());
        paths.append(" ").append(src.getAbsolutePath());
    }
    String clazzes = paths.toString();
    if (!clazzes.equals("")) {
        System.out.println("Compile: " + names.toString());
        BatchCompiler.compile(
                "-classpath rt.jar -g -warn:-unused -noExit -1.8 " + clazzes + " -d " + dir.getAbsolutePath(),
                new PrintWriter(System.out),
                new PrintWriter(System.err), null);
    }
}
 
开发者ID:fxzjshm,项目名称:jvm-java,代码行数:30,代码来源:ClassFileTest.java

示例2: compile

import org.eclipse.jdt.core.compiler.batch.BatchCompiler; //导入依赖的package包/类
/**
 * Executes the compilation.
 */
public void compile() {
	final StringBuilder argumentBuilder = new StringBuilder();
	argumentBuilder.append("-d \"").append(this.targetFolder).append("\" ");
	for (final String segment : this.classPath) {
		argumentBuilder.append("-classpath \"").append(segment).append("\" ");
	}
	if (this.charset != null) {
		argumentBuilder.append("-encoding ").append(this.charset).append(" ");
	}
	argumentBuilder.append("\"").append(this.sourceFilesFolder).append("\" ");
	argumentBuilder.append("-").append(COMPLIANCE_LEVEL);

	final ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
	final boolean success = BatchCompiler.compile(argumentBuilder.toString(), new PrintWriter(outputStream),
		new PrintWriter(outputStream), null);

	if (!success) {
		final FailureReport<Void> failure = new FailureReport<Void>().message("The compilation failed")
			.details("Compilation Output: %s\n\nUsed command line options: %s\n", outputStream, argumentBuilder)
			.retryWith(this::compile);
		FAILURE_HANDLER.handle(failure);
	}
}
 
开发者ID:Beagle-PSE,项目名称:Beagle,代码行数:27,代码来源:EclipseCompiler.java

示例3: compile

import org.eclipse.jdt.core.compiler.batch.BatchCompiler; //导入依赖的package包/类
public static void compile(final String file) {
	clear();
	Content.editor.clearIcons();
	StatusBar.error.setForeground(Color.black);
	StatusBar.error.setText("Errors");
	StatusBar.warning.setForeground(Color.black);
	StatusBar.warning.setText("Warnings");
	errorCount = 0;
	warningCount = 0;
	consoleArea.append("Compiling... "+file+".java"+System.lineSeparator());
	final String buildArgs = Content.getProject()+"source/"+ file+".java"
			+" -cp "+classPath
			+" -d "+Content.getProject()+"bin"
			+" -1.7"
			+" -Xemacs";
	Thread t = new Thread(new Runnable(){
		@Override
		public void run() {
			BatchCompiler.compile(buildArgs, compilerWriter, compilerWriter, prog);
			consoleArea.append("Finished Compiling... "+file+".java"+System.lineSeparator());
			System.gc();
		}
	});
	t.start();
}
 
开发者ID:pyros2097,项目名称:GdxStudio,代码行数:26,代码来源:ConsolePanel.java

示例4: build

import org.eclipse.jdt.core.compiler.batch.BatchCompiler; //导入依赖的package包/类
public static void build() {
	clear();
	consoleArea.append("Building.. "+Content.getProject()+System.lineSeparator());
	final String buildArgs = Content.getProject()+"source/"
			+" -cp "+classPath
			+" -d "+Content.getProject()+"bin"
			+" -1.7"
			+" -Xemacs";
	Thread t = new Thread(new Runnable(){
		@Override
		public void run() {
			BatchCompiler.compile(buildArgs, compilerWriter, compilerWriter, prog);
			System.gc();
		}
	});
	t.start();
}
 
开发者ID:pyros2097,项目名称:GdxStudio,代码行数:18,代码来源:ConsolePanel.java

示例5: compile

import org.eclipse.jdt.core.compiler.batch.BatchCompiler; //导入依赖的package包/类
/**
 * Invokes the ECJ compiler with the given arguments.
 * 
 * @param args
 *            the arguments passed through to the compiler
 * @param out
 *            get the output from System.out
 * @param err
 *            get the output from System.err
 * @return a return code as defined by this class
 */
public int compile(String[] args, PrintWriter out, PrintWriter err) {

    /* Give me something to do, or print usage message */
    if (args == null || args.length == 0) {
        BatchCompiler.compile("-help", out, err, null); //$NON-NLS-1$
        return RC_USAGE_ERROR;
    }

    /* Add in the base class library code to compile against */
    String[] newArgs = addLocalArgs(args);

    /* Invoke the compiler */
    boolean success = BatchCompiler.compile(newArgs, out, err, null);
    return success ? RC_SUCCESS : RC_COMPILE_ERROR;
}
 
开发者ID:shannah,项目名称:cn1,代码行数:27,代码来源:Main.java

示例6: compile

import org.eclipse.jdt.core.compiler.batch.BatchCompiler; //导入依赖的package包/类
@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 (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;
}
 
开发者ID:eclipse,项目名称:xtext-extras,代码行数:30,代码来源:EclipseJavaCompiler.java

示例7: run

import org.eclipse.jdt.core.compiler.batch.BatchCompiler; //导入依赖的package包/类
@Override
public final void run() {
	String command = getCommand();
	CompilationProgress progress = getProgress(); // instantiate your subclass
	compiled = BatchCompiler.compile(command, new PrintWriter(out), new PrintWriter(err), progress);

}
 
开发者ID:callakrsos,项目名称:Gargoyle,代码行数:8,代码来源:EclipseClasspathJavaCompiler.java

示例8: compile

import org.eclipse.jdt.core.compiler.batch.BatchCompiler; //导入依赖的package包/类
private boolean compile(String warnOpt, String annotOpt, String fileStr) {
	String cpStr = Strings.toSimpleString(File.pathSeparator, classpath);
	String cmd = String.format("-%s -classpath %s %s %s -d %s %s", javaVer, cpStr, warnOpt, annotOpt, outDir,
			fileStr);
	log.info("Executing => {}", cmd);
	CompilationProgress progress = new LogCompilationProgress();
	StringWriter stdOut = new StringWriter();
	PrintWriter out = new PrintWriter(stdOut);
	StringWriter errorOut = new StringWriter();
	PrintWriter err = new PrintWriter(errorOut);
	boolean result = BatchCompiler.compile(cmd, out, err, progress);
	log.info("Result => [{}] {} {}", result ? "OK" : "FAIL", stdOut, errorOut);
	messages = parseMessages(errorOut);
	return result;
}
 
开发者ID:xafero,项目名称:dynjc,代码行数:16,代码来源:EclipseCompiler.java

示例9: main

import org.eclipse.jdt.core.compiler.batch.BatchCompiler; //导入依赖的package包/类
public static void main(String[] args) {
    CompilationProgress progress = null;

    boolean ret = BatchCompiler.compile(
            "/Users/tudesheng/projects/haogrgr/haogrgr-test/src/test/java/com/haogrgr/test/main/Temp.java",
            new PrintWriter(System.out), new PrintWriter(System.err), progress);

    System.out.println(ret);
}
 
开发者ID:haogrgr,项目名称:haogrgr-test,代码行数:10,代码来源:ECJCompiler.java

示例10: javac

import org.eclipse.jdt.core.compiler.batch.BatchCompiler; //导入依赖的package包/类
public static void javac(final Procedure1<? super JavaCompilerParams> init) {
  final JavaCompilerParams params = new JavaCompilerParams();
  init.apply(params);
  final ArrayList<String> list = CollectionLiterals.<String>newArrayList();
  File _destination = params.getDestination();
  boolean _equals = Objects.equal(_destination, null);
  if (_equals) {
    list.add("-d");
    list.add("none");
  } else {
    list.add("-d");
    File _destination_1 = params.getDestination();
    String _string = _destination_1.toString();
    list.add(_string);
  }
  Collection<File> _classpath = params.getClasspath();
  boolean _isEmpty = _classpath.isEmpty();
  boolean _not = (!_isEmpty);
  if (_not) {
    list.add("-classpath");
    Collection<File> _classpath_1 = params.getClasspath();
    String _join = IterableExtensions.join(_classpath_1, ":");
    list.add(_join);
  }
  Collection<File> _sources = params.getSources();
  final Function1<File, String> _function = new Function1<File, String>() {
    public String apply(final File it) {
      return it.toString();
    }
  };
  Iterable<String> _map = IterableExtensions.<File, String>map(_sources, _function);
  Iterables.<String>addAll(list, _map);
  InputOutput.<String>print("compiling Java files...");
  PrintWriter _printWriter = new PrintWriter(System.out);
  PrintWriter _printWriter_1 = new PrintWriter(System.err);
  final boolean result = BatchCompiler.compile(((String[]) ((String[])Conversions.unwrapArray(list, String.class))), _printWriter, _printWriter_1, null);
  if (result) {
    InputOutput.<String>println("success.");
  } else {
    InputOutput.<String>println("failed.");
  }
}
 
开发者ID:oehme,项目名称:xtext-maven-example,代码行数:43,代码来源:JavaCompiler.java


注:本文中的org.eclipse.jdt.core.compiler.batch.BatchCompiler类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。