Java Code Examples for com.sun.tools.javac.main.Main#Result
The following examples show how to use
com.sun.tools.javac.main.Main#Result .
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: T7021650.java From openjdk-8 with GNU General Public License v2.0 | 5 votes |
void compile(Context context, String... args) throws Exception { StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter(sw); Main m = new Main("javac", pw); Main.Result res = m.compile(args, context); pw.close(); String out = sw.toString(); if (!out.isEmpty()) System.err.println(out); if (!res.isOK()) throw new Exception("compilation failed unexpectedly: result=" + res); }
Example 2
Source File: DocLintTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
void test(List<String> opts, Main.Result expectResult, Set<Message> expectMessages) { System.err.println("test: " + opts); StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter(sw); try { DocumentationTask t = javadoc.getTask(pw, fm, null, null, opts, files); boolean ok = t.call(); pw.close(); String out = sw.toString().replaceAll("[\r\n]+", "\n"); if (!out.isEmpty()) System.err.println(out); if (ok && expectResult != Main.Result.OK) { error("Compilation succeeded unexpectedly"); } else if (!ok && expectResult != Main.Result.ERROR) { error("Compilation failed unexpectedly"); } else check(out, expectMessages); } catch (IllegalArgumentException e) { System.err.println(e); String expectOut = expectMessages.iterator().next().text; if (expectResult != Main.Result.CMDERR) error("unexpected exception caught"); else if (!e.getMessage().equals(expectOut)) { error("unexpected exception message: " + e.getMessage() + " expected: " + expectOut); } } // if (errors > 0) // throw new Error("stop"); }
Example 3
Source File: IncludePackagesTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
void test(List<String> opts, Main.Result expectResult, Set<Message> expectMessages) { System.err.println("test: " + opts); StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter(sw); try { JavacTask t = (JavacTask) javac.getTask(pw, fm, null, opts, null, files); boolean ok = t.call(); pw.close(); String out = sw.toString().replaceAll("[\r\n]+", "\n"); if (!out.isEmpty()) System.err.println(out); if (ok && expectResult != Main.Result.OK) { error("Compilation succeeded unexpectedly"); } else if (!ok && expectResult != Main.Result.ERROR) { error("Compilation failed unexpectedly"); } else check(out, expectMessages); } catch (IllegalArgumentException e) { System.err.println(e); String expectOut = expectMessages.iterator().next().text; if (expectResult != Main.Result.CMDERR) error("unexpected exception caught"); else if (!e.getMessage().equals(expectOut)) { error("unexpected exception message: " + e.getMessage() + " expected: " + expectOut); } } }
Example 4
Source File: DocLintTest.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 5 votes |
void test(List<String> opts, Main.Result expectResult, Set<Message> expectMessages) { System.err.println("test: " + opts); StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter(sw); List<JavaFileObject> files = Arrays.asList(file); try { JavacTask t = (JavacTask) javac.getTask(pw, fm, null, opts, null, files); boolean ok = t.call(); pw.close(); String out = sw.toString().replaceAll("[\r\n]+", "\n"); if (!out.isEmpty()) System.err.println(out); if (ok && expectResult != Main.Result.OK) { error("Compilation succeeded unexpectedly"); } else if (!ok && expectResult != Main.Result.ERROR) { error("Compilation failed unexpectedly"); } else check(out, expectMessages); } catch (IllegalArgumentException e) { System.err.println(e); String expectOut = expectMessages.iterator().next().text; if (expectResult != Main.Result.CMDERR) error("unexpected exception caught"); else if (!e.getMessage().equals(expectOut)) { error("unexpected exception message: " + e.getMessage() + " expected: " + expectOut); } } // if (errors > 0) // throw new Error("stop"); }
Example 5
Source File: Example.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 5 votes |
@Override boolean run(PrintWriter out, Set<String> keys, boolean raw, List<String> opts, List<File> files) { if (out != null && keys != null) throw new IllegalArgumentException(); if (verbose) System.err.println("run_simple: " + opts + " " + files); List<String> args = new ArrayList<String>(); if (out != null && raw) args.add("-XDrawDiagnostics"); args.addAll(opts); for (File f: files) args.add(f.getPath()); StringWriter sw = null; PrintWriter pw; if (keys != null) { sw = new StringWriter(); pw = new PrintWriter(sw); } else pw = out; Context c = new Context(); JavacFileManager.preRegister(c); // can't create it until Log has been set up MessageTracker.preRegister(c, keys); Main m = new Main("javac", pw); Main.Result rc = m.compile(args.toArray(new String[args.size()]), c); if (keys != null) { pw.close(); } return rc.isOK(); }
Example 6
Source File: DocLintTest.java From openjdk-8-source with GNU General Public License v2.0 | 5 votes |
void test(List<String> opts, Main.Result expectResult, Set<Message> expectMessages) { System.err.println("test: " + opts); StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter(sw); List<JavaFileObject> files = Arrays.asList(file); try { DocumentationTask t = javadoc.getTask(pw, fm, null, null, opts, files); boolean ok = t.call(); pw.close(); String out = sw.toString().replaceAll("[\r\n]+", "\n"); if (!out.isEmpty()) System.err.println(out); if (ok && expectResult != Main.Result.OK) { error("Compilation succeeded unexpectedly"); } else if (!ok && expectResult != Main.Result.ERROR) { error("Compilation failed unexpectedly"); } else check(out, expectMessages); } catch (IllegalArgumentException e) { System.err.println(e); String expectOut = expectMessages.iterator().next().text; if (expectResult != Main.Result.CMDERR) error("unexpected exception caught"); else if (!e.getMessage().equals(expectOut)) { error("unexpected exception message: " + e.getMessage() + " expected: " + expectOut); } } // if (errors > 0) // throw new Error("stop"); }
Example 7
Source File: T7021650.java From openjdk-8-source with GNU General Public License v2.0 | 5 votes |
void compile(Context context, String... args) throws Exception { StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter(sw); Main m = new Main("javac", pw); Main.Result res = m.compile(args, context); pw.close(); String out = sw.toString(); if (!out.isEmpty()) System.err.println(out); if (!res.isOK()) throw new Exception("compilation failed unexpectedly: result=" + res); }
Example 8
Source File: Example.java From hottub with GNU General Public License v2.0 | 5 votes |
@Override boolean run(PrintWriter out, Set<String> keys, boolean raw, List<String> opts, List<File> files) { if (out != null && keys != null) throw new IllegalArgumentException(); if (verbose) System.err.println("run_simple: " + opts + " " + files); List<String> args = new ArrayList<String>(); if (out != null && raw) args.add("-XDrawDiagnostics"); args.addAll(opts); for (File f: files) args.add(f.getPath()); StringWriter sw = null; PrintWriter pw; if (keys != null) { sw = new StringWriter(); pw = new PrintWriter(sw); } else pw = out; Context c = new Context(); JavacFileManager.preRegister(c); // can't create it until Log has been set up MessageTracker.preRegister(c, keys); Main m = new Main("javac", pw); Main.Result rc = m.compile(args.toArray(new String[args.size()]), c); if (keys != null) { pw.close(); } return rc.isOK(); }
Example 9
Source File: DocLintTest.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
void test(List<String> opts, Main.Result expectResult, Set<Message> expectMessages) { System.err.println("test: " + opts); StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter(sw); List<JavaFileObject> files = Arrays.asList(file); try { JavacTask t = (JavacTask) javac.getTask(pw, fm, null, opts, null, files); boolean ok = t.call(); pw.close(); String out = sw.toString().replaceAll("[\r\n]+", "\n"); if (!out.isEmpty()) System.err.println(out); if (ok && expectResult != Main.Result.OK) { error("Compilation succeeded unexpectedly"); } else if (!ok && expectResult != Main.Result.ERROR) { error("Compilation failed unexpectedly"); } else check(out, expectMessages); } catch (IllegalArgumentException e) { System.err.println(e); String expectOut = expectMessages.iterator().next().text; if (expectResult != Main.Result.CMDERR) error("unexpected exception caught"); else if (!e.getMessage().equals(expectOut)) { error("unexpected exception message: " + e.getMessage() + " expected: " + expectOut); } } // if (errors > 0) // throw new Error("stop"); }
Example 10
Source File: Example.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
@Override boolean run(PrintWriter out, Set<String> keys, boolean raw, List<String> opts, List<File> files) { if (out != null && keys != null) throw new IllegalArgumentException(); if (verbose) System.err.println("run_simple: " + opts + " " + files); List<String> args = new ArrayList<String>(); if (out != null && raw) args.add("-XDrawDiagnostics"); args.addAll(opts); for (File f: files) args.add(f.getPath()); StringWriter sw = null; PrintWriter pw; if (keys != null) { sw = new StringWriter(); pw = new PrintWriter(sw); } else pw = out; Context c = new Context(); JavacFileManager.preRegister(c); // can't create it until Log has been set up MessageTracker.preRegister(c, keys); Main m = new Main("javac", pw); Main.Result rc = m.compile(args.toArray(new String[args.size()]), c); if (keys != null) { pw.close(); } return rc.isOK(); }
Example 11
Source File: DocLintTest.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
void test(List<String> opts, Main.Result expectResult, Set<Message> expectMessages) { System.err.println("test: " + opts); StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter(sw); List<JavaFileObject> files = Arrays.asList(file); try { DocumentationTask t = javadoc.getTask(pw, fm, null, null, opts, files); boolean ok = t.call(); pw.close(); String out = sw.toString().replaceAll("[\r\n]+", "\n"); if (!out.isEmpty()) System.err.println(out); if (ok && expectResult != Main.Result.OK) { error("Compilation succeeded unexpectedly"); } else if (!ok && expectResult != Main.Result.ERROR) { error("Compilation failed unexpectedly"); } else check(out, expectMessages); } catch (IllegalArgumentException e) { System.err.println(e); String expectOut = expectMessages.iterator().next().text; if (expectResult != Main.Result.CMDERR) error("unexpected exception caught"); else if (!e.getMessage().equals(expectOut)) { error("unexpected exception message: " + e.getMessage() + " expected: " + expectOut); } } // if (errors > 0) // throw new Error("stop"); }
Example 12
Source File: T7021650.java From jdk8u60 with GNU General Public License v2.0 | 5 votes |
void compile(Context context, String... args) throws Exception { StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter(sw); Main m = new Main("javac", pw); Main.Result res = m.compile(args, context); pw.close(); String out = sw.toString(); if (!out.isEmpty()) System.err.println(out); if (!res.isOK()) throw new Exception("compilation failed unexpectedly: result=" + res); }
Example 13
Source File: DocLintTest.java From jdk8u60 with GNU General Public License v2.0 | 5 votes |
void test(List<String> opts, Main.Result expectResult, Set<Message> expectMessages) { System.err.println("test: " + opts); StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter(sw); List<JavaFileObject> files = Arrays.asList(file); try { JavacTask t = (JavacTask) javac.getTask(pw, fm, null, opts, null, files); boolean ok = t.call(); pw.close(); String out = sw.toString().replaceAll("[\r\n]+", "\n"); if (!out.isEmpty()) System.err.println(out); if (ok && expectResult != Main.Result.OK) { error("Compilation succeeded unexpectedly"); } else if (!ok && expectResult != Main.Result.ERROR) { error("Compilation failed unexpectedly"); } else check(out, expectMessages); } catch (IllegalArgumentException e) { System.err.println(e); String expectOut = expectMessages.iterator().next().text; if (expectResult != Main.Result.CMDERR) error("unexpected exception caught"); else if (!e.getMessage().equals(expectOut)) { error("unexpected exception message: " + e.getMessage() + " expected: " + expectOut); } } // if (errors > 0) // throw new Error("stop"); }
Example 14
Source File: DocLintTest.java From hottub with GNU General Public License v2.0 | 5 votes |
void test(List<String> opts, Main.Result expectResult, Set<Message> expectMessages) { System.err.println("test: " + opts); StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter(sw); List<JavaFileObject> files = Arrays.asList(file); try { JavacTask t = (JavacTask) javac.getTask(pw, fm, null, opts, null, files); boolean ok = t.call(); pw.close(); String out = sw.toString().replaceAll("[\r\n]+", "\n"); if (!out.isEmpty()) System.err.println(out); if (ok && expectResult != Main.Result.OK) { error("Compilation succeeded unexpectedly"); } else if (!ok && expectResult != Main.Result.ERROR) { error("Compilation failed unexpectedly"); } else check(out, expectMessages); } catch (IllegalArgumentException e) { System.err.println(e); String expectOut = expectMessages.iterator().next().text; if (expectResult != Main.Result.CMDERR) error("unexpected exception caught"); else if (!e.getMessage().equals(expectOut)) { error("unexpected exception message: " + e.getMessage() + " expected: " + expectOut); } } // if (errors > 0) // throw new Error("stop"); }
Example 15
Source File: DocLintTest.java From jdk8u60 with GNU General Public License v2.0 | 5 votes |
void test(List<String> opts, Main.Result expectResult, Set<Message> expectMessages) { System.err.println("test: " + opts); StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter(sw); List<JavaFileObject> files = Arrays.asList(file); try { DocumentationTask t = javadoc.getTask(pw, fm, null, null, opts, files); boolean ok = t.call(); pw.close(); String out = sw.toString().replaceAll("[\r\n]+", "\n"); if (!out.isEmpty()) System.err.println(out); if (ok && expectResult != Main.Result.OK) { error("Compilation succeeded unexpectedly"); } else if (!ok && expectResult != Main.Result.ERROR) { error("Compilation failed unexpectedly"); } else check(out, expectMessages); } catch (IllegalArgumentException e) { System.err.println(e); String expectOut = expectMessages.iterator().next().text; if (expectResult != Main.Result.CMDERR) error("unexpected exception caught"); else if (!e.getMessage().equals(expectOut)) { error("unexpected exception message: " + e.getMessage() + " expected: " + expectOut); } } // if (errors > 0) // throw new Error("stop"); }
Example 16
Source File: T7021650.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
void compile(Context context, String... args) throws Exception { StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter(sw); Main m = new Main("javac", pw); Main.Result res = m.compile(args, context); pw.close(); String out = sw.toString(); if (!out.isEmpty()) System.err.println(out); if (!res.isOK()) throw new Exception("compilation failed unexpectedly: result=" + res); }
Example 17
Source File: T7021650.java From hottub with GNU General Public License v2.0 | 5 votes |
void compile(Context context, String... args) throws Exception { StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter(sw); Main m = new Main("javac", pw); Main.Result res = m.compile(args, context); pw.close(); String out = sw.toString(); if (!out.isEmpty()) System.err.println(out); if (!res.isOK()) throw new Exception("compilation failed unexpectedly: result=" + res); }
Example 18
Source File: Example.java From openjdk-8-source with GNU General Public License v2.0 | 5 votes |
@Override boolean run(PrintWriter out, Set<String> keys, boolean raw, List<String> opts, List<File> files) { if (out != null && keys != null) throw new IllegalArgumentException(); if (verbose) System.err.println("run_simple: " + opts + " " + files); List<String> args = new ArrayList<String>(); if (out != null && raw) args.add("-XDrawDiagnostics"); args.addAll(opts); for (File f: files) args.add(f.getPath()); StringWriter sw = null; PrintWriter pw; if (keys != null) { sw = new StringWriter(); pw = new PrintWriter(sw); } else pw = out; Context c = new Context(); JavacFileManager.preRegister(c); // can't create it until Log has been set up MessageTracker.preRegister(c, keys); Main m = new Main("javac", pw); Main.Result rc = m.compile(args.toArray(new String[args.size()]), c); if (keys != null) { pw.close(); } return rc.isOK(); }
Example 19
Source File: RequestHandler.java From openjdk-jdk9 with GNU General Public License v2.0 | 4 votes |
@Override public void run() { try (BufferedReader in = new BufferedReader(new InputStreamReader(socket.getInputStream())); PrintWriter out = new PrintWriter(socket.getOutputStream(), true)) { // Set up logging for this thread. Stream back logging messages to // client on the format format "level:msg". Log.setLogForCurrentThread(new Log(out, out) { @Override protected boolean isLevelLogged(Level l) { // Make sure it is up to the client to decide whether or // not this message should be displayed. return true; } @Override protected void printLogMsg(Level msgLevel, String msg) { // Follow sjavac server/client protocol: Send one line // at a time and prefix with message with "level:". Util.getLines(msg) .map(line -> msgLevel + ":" + line) .forEach(line -> super.printLogMsg(msgLevel, line)); } }); // Read argument array int n = Integer.parseInt(in.readLine()); String[] args = new String[n]; for (int i = 0; i < n; i++) { args[i] = in.readLine(); } // If there has been any internal errors, notify client checkInternalErrorLog(); // Perform compilation Main.Result rc = sjavac.compile(args); // Send return code back to client out.println(LINE_TYPE_RC + ":" + rc.name()); // Check for internal errors again. checkInternalErrorLog(); } catch (Exception ex) { // Not much to be done at this point. The client side request // code will most likely throw an IOException and the // compilation will fail. Log.error(ex); } finally { Log.setLogForCurrentThread(null); } }
Example 20
Source File: Example.java From openjdk-jdk9 with GNU General Public License v2.0 | 4 votes |
@Override boolean run(PrintWriter out, Set<String> keys, boolean raw, List<String> opts, List<File> files) { if (out != null && keys != null) throw new IllegalArgumentException(); if (verbose) System.err.println("run_simple: " + opts + " " + files); List<String> args = new ArrayList<String>(); if (out != null && raw) args.add("-XDrawDiagnostics"); args.addAll(opts); for (File f: files) args.add(f.getPath()); StringWriter sw = null; PrintWriter pw; if (keys != null) { sw = new StringWriter(); pw = new PrintWriter(sw); } else pw = out; Context c = new Context(); JavacFileManager.preRegister(c); // can't create it until Log has been set up MessageTracker.preRegister(c, keys); try { Main m = new Main("javac", pw); Main.Result rc = m.compile(args.toArray(new String[args.size()]), c); if (keys != null) { pw.close(); } return rc.isOK(); } finally { close(c.get(JavaFileManager.class)); } }