本文整理汇总了Java中com.sun.tools.javac.main.Main类的典型用法代码示例。如果您正苦于以下问题:Java Main类的具体用法?Java Main怎么用?Java Main使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Main类属于com.sun.tools.javac.main包,在下文中一共展示了Main类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: compileJava
import com.sun.tools.javac.main.Main; //导入依赖的package包/类
public static int compileJava(Context context, JavaProjectFolder projectFile, @Nullable DiagnosticListener listener) {
try {
String[] args = new String[]{
"-verbose",
"-cp", projectFile.getJavaClassPath(context),
"-sourcepath", projectFile.getSourcePath(), //sourcepath
"-d", projectFile.getDirBuildClasses().getPath(), //output dir
projectFile.getMainClass().getPath(projectFile) //main class
};
DLog.d(TAG, "compileJava args = " + Arrays.toString(args));
int compileStatus;
compileStatus = Javac.compile(args, listener);
return compileStatus;
} catch (Throwable e) {
e.printStackTrace();
}
return Main.EXIT_ERROR;
}
示例2: Log
import com.sun.tools.javac.main.Main; //导入依赖的package包/类
/** Construct a log with given I/O redirections.
*/
protected Log(Context context, PrintWriter errWriter, PrintWriter warnWriter, PrintWriter noticeWriter) {
super(JCDiagnostic.Factory.instance(context));
context.put(logKey, this);
this.errWriter = errWriter;
this.warnWriter = warnWriter;
this.noticeWriter = noticeWriter;
@SuppressWarnings("unchecked") // FIXME
DiagnosticListener<? super JavaFileObject> dl =
context.get(DiagnosticListener.class);
this.diagListener = dl;
diagnosticHandler = new DefaultDiagnosticHandler();
messages = JavacMessages.instance(context);
messages.add(Main.javacBundleName);
final Options options = Options.instance(context);
initOptions(options);
options.addListener(new Runnable() {
public void run() {
initOptions(options);
}
});
}
示例3: Log
import com.sun.tools.javac.main.Main; //导入依赖的package包/类
/**
* Creates a log.
* @param context the context in which the log should be registered
* @param writers a map of writers that can be accessed by the kind of writer required
*/
private Log(Context context, Map<WriterKind, PrintWriter> writers) {
super(JCDiagnostic.Factory.instance(context));
context.put(logKey, this);
this.writers = writers;
@SuppressWarnings("unchecked") // FIXME
DiagnosticListener<? super JavaFileObject> dl =
context.get(DiagnosticListener.class);
this.diagListener = dl;
diagnosticHandler = new DefaultDiagnosticHandler();
messages = JavacMessages.instance(context);
messages.add(Main.javacBundleName);
final Options options = Options.instance(context);
initOptions(options);
options.addListener(() -> initOptions(options));
}
示例4: testSourceTarget
import com.sun.tools.javac.main.Main; //导入依赖的package包/类
@Test
void testSourceTarget() throws IOException {
String v = System.getProperty("java.specification.version");
String[] va = v.split("\\.");
int major = Integer.parseInt(va[0]);
boolean newVersion = major > 8;
String latest = (newVersion) ? va[0] : va[1];
String prev = String.valueOf(Integer.valueOf(latest) - 1);
writeFile("C.java", "class C { }");
String[] opts = { "-source", latest, "-target", prev };
String[] files = { "C.java" };
runMain(opts, files)
.checkResult(Main.Result.CMDERR.exitCode);
runCall(opts, files)
.checkIllegalStateException();
runParse(opts, files)
.checkIllegalStateException();
}
示例5: testProfileBootClassPath
import com.sun.tools.javac.main.Main; //导入依赖的package包/类
@OptionModesTester.Test
void testProfileBootClassPath() throws IOException {
writeFile("C.java", "class C { }");
String javaHome = System.getProperty("java.home");
String rt_jar = new File(javaHome, "jre/lib/rt.jar").getPath();
String[] opts = { "-profile", "compact1", "-bootclasspath", rt_jar };
String[] files = { "C.java" };
runMain(opts, files)
.checkResult(Main.Result.CMDERR.exitCode);
// The API tests are disabled (for now) because Args.validate does
// not have an easy way to access/validate file manager options,
// which are handled directly by the file manager
// runCall(opts, files)
// .checkIllegalStateException();
// runParse(opts, files)
// .checkIllegalStateException();
}
示例6: testXstdout
import com.sun.tools.javac.main.Main; //导入依赖的package包/类
@Test
void testXstdout() throws IOException {
String[] args = { "-Xstdout", "out.txt" };
String[] files = { "src/Bad.java" };
// verify messages get written to the specified file
runMain(args, files)
.checkResult(Main.Result.ERROR.exitCode);
if (!Files.exists(Paths.get("out.txt"))) {
error("expected file not found");
}
runCall(args, files)
.checkIllegalArgumentException();
runParse(args, files)
.checkIllegalArgumentException();
}
示例7: testProfileTarget
import com.sun.tools.javac.main.Main; //导入依赖的package包/类
@Test
void testProfileTarget() throws IOException {
writeFile("C.java", "class C { }");
String[] opts = { "-profile", "compact1", "-source", "7", "-target", "7" };
String[] files = { "C.java" };
runMain(opts, files)
.checkResult(Main.Result.CMDERR.exitCode);
runCall(opts, files)
.checkIllegalStateException();
runParse(opts, files)
.checkIllegalStateException();
}
示例8: testDocLint
import com.sun.tools.javac.main.Main; //导入依赖的package包/类
@Test
void testDocLint() throws IOException {
writeFile("src/C.java", "/** & */ class C { }");
mkdirs("classes");
String[] opts = { "-d", "classes", "-Xdoclint" };
String[] files = { "src/C.java" };
runMain(opts, files)
.checkResult(Main.Result.ERROR.exitCode);
runCall(opts, files)
.checkResult(false);
// 1. doclint runs at the beginning of analyze
// 2. the analyze call itself succeeds, so we check for errors being reported
runAnalyze(opts, files)
.checkResult(true)
.checkLog(Log.DIRECT, "^");
}
示例9: testOutputDir
import com.sun.tools.javac.main.Main; //导入依赖的package包/类
void testOutputDir(String opt) {
String[] opts = { opt, "does-not-exist"};
String[] files = { "src/C.java" };
runMain(opts, files)
.checkResult(Main.Result.OK.exitCode);
// The API tests are disabled (for now) because Args.validate does
// not have an easy way to access/validate file manager options,
// which are handled directly by the file manager
// runCall(opts, files)
// .checkIllegalStateException();
// runParse(opts, files)
// .checkIllegalStateException();
}
示例10: compileClass
import com.sun.tools.javac.main.Main; //导入依赖的package包/类
public PrintWriter compileClass(String src, String out) {
List<String> options = new ArrayList<>();
options.add("-Xstdout");
options.add(out);
options.add(src);
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
Main compiler = new Main("javac", pw);
compiler.compile(options.toArray(new String[options.size()]));
pw.flush();
if (sw.getBuffer().length() > 0) {
System.err.println(sw.toString());
}
return compiler.log.getWriter(Log.WriterKind.NOTICE);
}
示例11: main
import com.sun.tools.javac.main.Main; //导入依赖的package包/类
public static void main(String... args) {
if (args.length < 2)
throw new IllegalArgumentException("insufficient args");
int expected_rc = getReturnCode(args[0]);
List<String> javacArgs = new ArrayList<>();
javacArgs.addAll(Arrays.asList(
"-d", "."
));
File testSrc = new File(System.getProperty("test.src"));
for (int i = 1; i < args.length; i++) { // skip first arg
String arg = args[i];
if (arg.endsWith(".java"))
javacArgs.add(new File(testSrc, arg).getPath());
else
javacArgs.add(arg);
}
int rc = com.sun.tools.javac.Main.compile(
javacArgs.toArray(new String[javacArgs.size()]));
if (rc != expected_rc)
throw new Error("unexpected exit code: " + rc
+ ", expected: " + expected_rc);
}
示例12: testProfileBootClassPath
import com.sun.tools.javac.main.Main; //导入依赖的package包/类
@Tester.Test
void testProfileBootClassPath() throws IOException {
writeFile("C.java", "class C { }");
String javaHome = System.getProperty("java.home");
String rt_jar = new File(javaHome, "jre/lib/rt.jar").getPath();
String[] opts = { "-profile", "compact1", "-bootclasspath", rt_jar };
String[] files = { "C.java" };
runMain(opts, files)
.checkResult(Main.Result.CMDERR.exitCode);
// The API tests are disabled (for now) because Args.validate does
// not have an easy way to access/validate file manager options,
// which are handled directly by the file manager
// runCall(opts, files)
// .checkIllegalStateException();
// runParse(opts, files)
// .checkIllegalStateException();
}
示例13: run
import com.sun.tools.javac.main.Main; //导入依赖的package包/类
public int run(InputStream in, OutputStream out, OutputStream err, String... arguments) {
if (err == null)
err = System.err;
for (String argument : arguments)
argument.getClass(); // null check
return com.sun.tools.javac.Main.compile(arguments, new PrintWriter(err, true));
}
示例14: buildJarAchieve
import com.sun.tools.javac.main.Main; //导入依赖的package包/类
@Nullable
public static File buildJarAchieve(Context context, JavaProjectFolder projectFile,
DiagnosticListener listener) throws IOException {
int status = compileJava(context, projectFile, listener);
if (status != Main.EXIT_OK) {
throw new RuntimeException("Compile time error... Exit code(" + status + ")");
}
//now create normal jar file
Jar.createJarArchive(projectFile);
return projectFile.getOutJarArchive();
}
示例15: build
import com.sun.tools.javac.main.Main; //导入依赖的package包/类
public static void build(Context context, AndroidProjectFolder projectFile,
@NonNull DiagnosticCollector diagnosticCollector) throws Exception {
AndroidBuilder.extractLibrary(projectFile);
//create R.java
System.out.println("Run aidl");
AndroidBuilder.runAidl(projectFile);
System.out.println("Run aapt");
AndroidBuilder.runAapt(context, projectFile);
//compile java
System.out.println("Compile Java file");
int status = CompileHelper.compileJava(context, projectFile, diagnosticCollector);
System.gc();
if (status != Main.EXIT_OK) {
System.out.println("Compile error");
throw new RuntimeException("Compile time error!");
}
//classes to dex
System.out.println("Convert classes to dex");
CompileHelper.convertToDexFormat(context, projectFile);
//zip apk
System.out.println("Build apk");
AndroidBuilder.buildApk(projectFile);
System.out.println("Zip sign");
AndroidBuilder.zipSign(projectFile);
System.out.println("Zip align");
AndroidBuilder.zipAlign();
System.out.println("Publish apk");
AndroidBuilder.publishApk();
}