Java Code Examples for javax.tools.ToolProvider#getSystemDocumentationTool()
The following examples show how to use
javax.tools.ToolProvider#getSystemDocumentationTool() .
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: JavadocTaskImplTest.java From TencentKona-8 with GNU General Public License v2.0 | 6 votes |
@Test public void testRawCall() throws Exception { JavaFileObject srcFile = createSimpleJavaFileObject(); DocumentationTool tool = ToolProvider.getSystemDocumentationTool(); StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null); File outDir = getOutDir(); fm.setLocation(DocumentationTool.Location.DOCUMENTATION_OUTPUT, Arrays.asList(outDir)); Iterable<? extends JavaFileObject> files = Arrays.asList(srcFile); @SuppressWarnings("rawtypes") Callable t = tool.getTask(null, fm, null, null, null, files); if (t.call() == Boolean.TRUE) { System.err.println("task succeeded"); } else { throw new Exception("task failed"); } }
Example 2
Source File: GetTask_FileObjectsTest.java From TencentKona-8 with GNU General Public License v2.0 | 6 votes |
/** * Verify that expected output files are written via the file manager, * for a source file read from the file system with StandardJavaFileManager. */ @Test public void testStandardFileObject() throws Exception { File testSrc = new File(System.getProperty("test.src")); File srcFile = new File(testSrc, "pkg/C.java"); DocumentationTool tool = ToolProvider.getSystemDocumentationTool(); StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null); File outDir = getOutDir(); fm.setLocation(DocumentationTool.Location.DOCUMENTATION_OUTPUT, Arrays.asList(outDir)); Iterable<? extends JavaFileObject> files = fm.getJavaFileObjects(srcFile); DocumentationTask t = tool.getTask(null, fm, null, null, null, files); if (t.call()) { System.err.println("task succeeded"); checkFiles(outDir, standardExpectFiles); } else { throw new Exception("task failed"); } }
Example 3
Source File: GetTask_FileObjectsTest.java From TencentKona-8 with GNU General Public License v2.0 | 6 votes |
/** * Verify that expected output files are written via the file manager, * for an in-memory file object. */ @Test public void testMemoryFileObject() throws Exception { JavaFileObject srcFile = createSimpleJavaFileObject(); DocumentationTool tool = ToolProvider.getSystemDocumentationTool(); StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null); File outDir = getOutDir(); fm.setLocation(DocumentationTool.Location.DOCUMENTATION_OUTPUT, Arrays.asList(outDir)); Iterable<? extends JavaFileObject> files = Arrays.asList(srcFile); DocumentationTask t = tool.getTask(null, fm, null, null, null, files); if (t.call()) { System.err.println("task succeeded"); checkFiles(outDir, standardExpectFiles); } else { throw new Exception("task failed"); } }
Example 4
Source File: GetTask_FileObjectsTest.java From TencentKona-8 with GNU General Public License v2.0 | 6 votes |
/** * Verify bad file object is handled correctly. */ @Test public void testBadFileObject() throws Exception { File testSrc = new File(System.getProperty("test.src")); File srcFile = new File(testSrc, "pkg/C.class"); // unacceptable file kind DocumentationTool tool = ToolProvider.getSystemDocumentationTool(); StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null); File outDir = getOutDir(); fm.setLocation(DocumentationTool.Location.DOCUMENTATION_OUTPUT, Arrays.asList(outDir)); Iterable<? extends JavaFileObject> files = fm.getJavaFileObjects(srcFile); try { DocumentationTask t = tool.getTask(null, fm, null, null, null, files); error("getTask succeeded, no exception thrown"); } catch (IllegalArgumentException e) { System.err.println("exception caught as expected: " + e); } }
Example 5
Source File: GetTask_WriterTest.java From TencentKona-8 with GNU General Public License v2.0 | 6 votes |
/** * Verify that a writer can be provided. */ @Test public void testWriter() throws Exception { JavaFileObject srcFile = createSimpleJavaFileObject(); DocumentationTool tool = ToolProvider.getSystemDocumentationTool(); StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null); File outDir = getOutDir(); fm.setLocation(DocumentationTool.Location.DOCUMENTATION_OUTPUT, Arrays.asList(outDir)); Iterable<? extends JavaFileObject> files = Arrays.asList(srcFile); StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter(sw); DocumentationTask t = tool.getTask(pw, fm, null, null, null, files); if (t.call()) { System.err.println("task succeeded"); checkFiles(outDir, standardExpectFiles); String out = sw.toString(); System.err.println(">>" + out + "<<"); for (String f: standardExpectFiles) { String f1 = f.replace('/', File.separatorChar); if (f1.endsWith(".html") && !out.contains(f1)) throw new Exception("expected string not found: " + f1); } } else { throw new Exception("task failed"); } }
Example 6
Source File: GetTask_FileManagerTest.java From TencentKona-8 with GNU General Public License v2.0 | 6 votes |
/** * Verify that an alternate file manager can be specified: * in this case, a PathFileManager. */ @Test public void testFileManager() throws Exception { JavaFileObject srcFile = createSimpleJavaFileObject(); DocumentationTool tool = ToolProvider.getSystemDocumentationTool(); PathFileManager fm = new JavacPathFileManager(new Context(), false, null); Path outDir = getOutDir().toPath(); fm.setLocation(DocumentationTool.Location.DOCUMENTATION_OUTPUT, Arrays.asList(outDir)); Iterable<? extends JavaFileObject> files = Arrays.asList(srcFile); DocumentationTask t = tool.getTask(null, fm, null, null, null, files); if (t.call()) { System.err.println("task succeeded"); checkFiles(outDir, standardExpectFiles); } else { throw new Exception("task failed"); } }
Example 7
Source File: GetTask_DocletClassTest.java From TencentKona-8 with GNU General Public License v2.0 | 6 votes |
/** * Verify that exceptions from a doclet are thrown as expected. */ @Test public void testBadDoclet() throws Exception { JavaFileObject srcFile = createSimpleJavaFileObject(); DocumentationTool tool = ToolProvider.getSystemDocumentationTool(); StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null); File outDir = getOutDir(); fm.setLocation(DocumentationTool.Location.DOCUMENTATION_OUTPUT, Arrays.asList(outDir)); Iterable<? extends JavaFileObject> files = Arrays.asList(srcFile); DocumentationTask t = tool.getTask(null, fm, null, BadDoclet.class, null, files); try { t.call(); error("call completed without exception"); } catch (RuntimeException e) { Throwable c = e.getCause(); if (c.getClass() == UnexpectedError.class) System.err.println("exception caught as expected: " + c); else throw e; } }
Example 8
Source File: GetTask_DocletClassTest.java From TencentKona-8 with GNU General Public License v2.0 | 6 votes |
/** * Verify that an alternate doclet can be specified. * * There is no standard interface or superclass for a doclet; * the only requirement is that it provides static methods that * can be invoked via reflection. So, for now, the doclet is * specified as a class. * Because we cannot create and use a unique instance of the class, * we verify that the doclet has been called by having it record * (in a static field!) the comment from the last time it was invoked, * which is randomly generated each time the test is run. */ @Test public void testDoclet() throws Exception { Random r = new Random(); int key = r.nextInt(); JavaFileObject srcFile = createSimpleJavaFileObject( "pkg/C", "package pkg; /** " + key + "*/ public class C { }"); DocumentationTool tool = ToolProvider.getSystemDocumentationTool(); StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null); File outDir = getOutDir(); fm.setLocation(DocumentationTool.Location.DOCUMENTATION_OUTPUT, Arrays.asList(outDir)); Iterable<? extends JavaFileObject> files = Arrays.asList(srcFile); DocumentationTask t = tool.getTask(null, fm, null, TestDoclet.class, null, files); if (t.call()) { System.err.println("task succeeded"); if (TestDoclet.lastCaller.equals(String.valueOf(key))) System.err.println("found expected key: " + key); else error("Expected key not found"); checkFiles(outDir, Collections.<String>emptySet()); } else { throw new Exception("task failed"); } }
Example 9
Source File: GetTask_OptionsTest.java From TencentKona-8 with GNU General Public License v2.0 | 6 votes |
/** * Verify null is handled correctly. */ @Test public void testNull() throws Exception { JavaFileObject srcFile = createSimpleJavaFileObject(); DocumentationTool tool = ToolProvider.getSystemDocumentationTool(); StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null); File outDir = getOutDir(); fm.setLocation(DocumentationTool.Location.DOCUMENTATION_OUTPUT, Arrays.asList(outDir)); Iterable<String> options = Arrays.asList((String) null); Iterable<? extends JavaFileObject> files = Arrays.asList(srcFile); try { DocumentationTask t = tool.getTask(null, fm, null, null, options, files); error("getTask succeeded, no exception thrown"); } catch (NullPointerException e) { System.err.println("exception caught as expected: " + e); } }
Example 10
Source File: GetTask_OptionsTest.java From TencentKona-8 with GNU General Public License v2.0 | 6 votes |
/** * Verify that expected output files are written for given options. */ @Test public void testNoIndex() throws Exception { JavaFileObject srcFile = createSimpleJavaFileObject(); DocumentationTool tool = ToolProvider.getSystemDocumentationTool(); StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null); File outDir = getOutDir(); fm.setLocation(DocumentationTool.Location.DOCUMENTATION_OUTPUT, Arrays.asList(outDir)); Iterable<? extends JavaFileObject> files = Arrays.asList(srcFile); Iterable<String> options = Arrays.asList("-noindex"); DocumentationTask t = tool.getTask(null, fm, null, null, options, files); if (t.call()) { System.err.println("task succeeded"); Set<String> expectFiles = new TreeSet<String>(standardExpectFiles); expectFiles.remove("index-all.html"); checkFiles(outDir, expectFiles); } else { error("task failed"); } }
Example 11
Source File: RunTest.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
/** * Verify that run method can be invoked. */ @Test public void testRunOK() throws Exception { File testSrc = new File(System.getProperty("test.src")); File srcFile = new File(testSrc, "pkg/C.java"); File outDir = getOutDir(); String[] args = { "-d", outDir.getPath(), srcFile.getPath() }; ByteArrayOutputStream stdout = new ByteArrayOutputStream(); ByteArrayOutputStream stderr = new ByteArrayOutputStream(); DocumentationTool tool = ToolProvider.getSystemDocumentationTool(); int rc = tool.run(null, stdout, stderr, args); System.err.println("stdout >>" + stdout.toString() + "<<"); System.err.println("stderr >>" + stderr.toString() + "<<"); if (rc == 0) { System.err.println("call succeeded"); checkFiles(outDir, standardExpectFiles); String out = stdout.toString(); for (String f: standardExpectFiles) { String f1 = f.replace('/', File.separatorChar); if (f1.endsWith(".html") && !out.contains(f1)) error("expected string not found: " + f1); } } else { error("call failed"); } }
Example 12
Source File: GetTask_FileManagerTest.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
/** * Verify that exceptions from a bad file manager are thrown as expected. */ @Test public void testBadFileManager() throws Exception { JavaFileObject srcFile = createSimpleJavaFileObject(); DocumentationTool tool = ToolProvider.getSystemDocumentationTool(); PathFileManager fm = new JavacPathFileManager(new Context(), false, null) { @Override public Iterable<JavaFileObject> list(Location location, String packageName, Set<Kind> kinds, boolean recurse) throws IOException { throw new UnexpectedError(); } }; Path outDir = getOutDir().toPath(); fm.setLocation(DocumentationTool.Location.DOCUMENTATION_OUTPUT, Arrays.asList(outDir)); Iterable<? extends JavaFileObject> files = Arrays.asList(srcFile); DocumentationTask t = tool.getTask(null, fm, null, null, null, files); try { t.call(); error("call completed without exception"); } catch (RuntimeException e) { Throwable c = e.getCause(); if (c.getClass() == UnexpectedError.class) System.err.println("exception caught as expected: " + c); else throw e; } }
Example 13
Source File: IsSupportedOptionTest.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
/** * Verify that isSupportedOption method can be invoked. */ @Test public void test() throws Exception { DocumentationTool tool = ToolProvider.getSystemDocumentationTool(); check(tool, "-sourcepath", 1); check(tool, "-verbose", 0); check(tool, "-ZZZ", -1); try { check(tool, null, -1); error("null was accepted without exception"); } catch (NullPointerException e) { } }
Example 14
Source File: GetTask_DiagListenerTest.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
/** * Verify that a diagnostic listener can be specified. * Note that messages from the tool and doclet are imperfectly modeled * because the DocErrorReporter API works in terms of localized strings * and file:line positions. Therefore, messages reported via DocErrorReporter * and simply wrapped and passed through. */ @Test public void testDiagListener() throws Exception { JavaFileObject srcFile = createSimpleJavaFileObject("pkg/C", "package pkg; public error { }"); DocumentationTool tool = ToolProvider.getSystemDocumentationTool(); StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null); File outDir = getOutDir(); fm.setLocation(DocumentationTool.Location.DOCUMENTATION_OUTPUT, Arrays.asList(outDir)); Iterable<? extends JavaFileObject> files = Arrays.asList(srcFile); DiagnosticCollector<JavaFileObject> dc = new DiagnosticCollector<JavaFileObject>(); DocumentationTask t = tool.getTask(null, fm, dc, null, null, files); if (t.call()) { throw new Exception("task succeeded unexpectedly"); } else { List<String> diagCodes = new ArrayList<String>(); for (Diagnostic d: dc.getDiagnostics()) { System.err.println(d); diagCodes.add(d.getCode()); } List<String> expect = Arrays.asList( "javadoc.note.msg", // Loading source file "compiler.err.expected3", // class, interface, or enum expected "javadoc.note.msg"); // 1 error if (!diagCodes.equals(expect)) throw new Exception("unexpected diagnostics occurred"); System.err.println("diagnostics received as expected"); } }
Example 15
Source File: GetSourceVersionsTest.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
/** * Verify getSourceVersions. */ @Test public void testRun() throws Exception { DocumentationTool tool = ToolProvider.getSystemDocumentationTool(); Set<SourceVersion> found = tool.getSourceVersions(); Set<SourceVersion> expect = EnumSet.range(SourceVersion.RELEASE_3, SourceVersion.latest()); if (!expect.equals(found)) { System.err.println("expect: " + expect); System.err.println(" found: " + expect); error("unexpected versions"); } }
Example 16
Source File: Task_reuseTest.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
private DocumentationTask getAndRunTask() throws Exception { JavaFileObject srcFile = createSimpleJavaFileObject(); DocumentationTool tool = ToolProvider.getSystemDocumentationTool(); StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null); File outDir = getOutDir(); fm.setLocation(DocumentationTool.Location.DOCUMENTATION_OUTPUT, Arrays.asList(outDir)); Iterable<? extends JavaFileObject> files = Arrays.asList(srcFile); DocumentationTask t = tool.getTask(null, fm, null, null, null, files); if (t.call()) { System.err.println("task succeeded"); return t; } else { throw new Exception("task failed"); } }
Example 17
Source File: DocletPathTest.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
/** * Verify that an alternate doclet can be specified, and located via * the file manager's DOCLET_PATH. */ @Test public void testDocletPath() throws Exception { JavaFileObject docletSrc = createSimpleJavaFileObject("DocletOnDocletPath", docletSrcText); File docletDir = getOutDir("classes"); JavaCompiler compiler = ToolProvider.getSystemJavaCompiler(); StandardJavaFileManager cfm = compiler.getStandardFileManager(null, null, null); cfm.setLocation(StandardLocation.CLASS_OUTPUT, Arrays.asList(docletDir)); Iterable<? extends JavaFileObject> cfiles = Arrays.asList(docletSrc); if (!compiler.getTask(null, cfm, null, null, null, cfiles).call()) throw new Exception("cannot compile doclet"); JavaFileObject srcFile = createSimpleJavaFileObject(); DocumentationTool tool = ToolProvider.getSystemDocumentationTool(); StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null); File outDir = getOutDir("api"); fm.setLocation(DocumentationTool.Location.DOCUMENTATION_OUTPUT, Arrays.asList(outDir)); fm.setLocation(DocumentationTool.Location.DOCLET_PATH, Arrays.asList(docletDir)); Iterable<? extends JavaFileObject> files = Arrays.asList(srcFile); Iterable<String> options = Arrays.asList("-doclet", "DocletOnDocletPath"); StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter(sw); DocumentationTask t = tool.getTask(pw, fm, null, null, options, files); boolean ok = t.call(); String out = sw.toString(); System.err.println(">>" + out + "<<"); if (ok) { if (out.contains(TEST_STRING)) { System.err.println("doclet executed as expected"); } else { error("test string not found in doclet output"); } } else { error("task failed"); } }
Example 18
Source File: GetTask_FileObjectsTest.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
/** * Verify null is handled correctly. */ @Test public void testNull() throws Exception { DocumentationTool tool = ToolProvider.getSystemDocumentationTool(); StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null); File outDir = getOutDir(); fm.setLocation(DocumentationTool.Location.DOCUMENTATION_OUTPUT, Arrays.asList(outDir)); Iterable<? extends JavaFileObject> files = Arrays.asList((JavaFileObject) null); try { DocumentationTask t = tool.getTask(null, fm, null, null, null, files); error("getTask succeeded, no exception thrown"); } catch (NullPointerException e) { System.err.println("exception caught as expected: " + e); } }
Example 19
Source File: TagletPathTest.java From TencentKona-8 with GNU General Public License v2.0 | 4 votes |
/** * Verify that a taglet can be specified, and located via * the file manager's TAGLET_PATH. */ @Test public void testTagletPath() throws Exception { File testSrc = new File(System.getProperty("test.src")); File tagletSrcFile = new File(testSrc, "taglets/UnderlineTaglet.java"); File tagletDir = getOutDir("classes"); JavaCompiler compiler = ToolProvider.getSystemJavaCompiler(); StandardJavaFileManager cfm = compiler.getStandardFileManager(null, null, null); cfm.setLocation(StandardLocation.CLASS_OUTPUT, Arrays.asList(tagletDir)); Iterable<? extends JavaFileObject> cfiles = cfm.getJavaFileObjects(tagletSrcFile); if (!compiler.getTask(null, cfm, null, null, null, cfiles).call()) throw new Exception("cannot compile taglet"); JavaFileObject srcFile = createSimpleJavaFileObject("pkg/C", testSrcText); DocumentationTool tool = ToolProvider.getSystemDocumentationTool(); StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null); File outDir = getOutDir("api"); fm.setLocation(DocumentationTool.Location.DOCUMENTATION_OUTPUT, Arrays.asList(outDir)); fm.setLocation(DocumentationTool.Location.TAGLET_PATH, Arrays.asList(tagletDir)); Iterable<? extends JavaFileObject> files = Arrays.asList(srcFile); Iterable<String> options = Arrays.asList("-taglet", "UnderlineTaglet"); StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter(sw); DocumentationTask t = tool.getTask(pw, fm, null, null, options, files); boolean ok = t.call(); String out = sw.toString(); System.err.println(">>" + out + "<<"); if (ok) { File f = new File(outDir, "pkg/C.html"); List<String> doc = Files.readAllLines(f.toPath(), Charset.defaultCharset()); for (String line: doc) { if (line.contains("<u>" + TEST_STRING + "</u>")) { System.err.println("taglet executed as expected"); return; } } error("expected text not found in output " + f); } else { error("task failed"); } }
Example 20
Source File: DocLintTest.java From TencentKona-8 with GNU General Public License v2.0 | 4 votes |
void run() throws Exception { javadoc = ToolProvider.getSystemDocumentationTool(); fm = javadoc.getStandardFileManager(null, null, null); fm.setLocation(StandardLocation.CLASS_OUTPUT, Arrays.asList(new File("."))); file = new SimpleJavaFileObject(URI.create("Test.java"), JavaFileObject.Kind.SOURCE) { @Override public CharSequence getCharContent(boolean ignoreEncoding) { return code; } }; test(Collections.<String>emptyList(), Main.Result.ERROR, EnumSet.of(Message.DL_ERR9A, Message.DL_WRN12A)); test(Arrays.asList(rawDiags), Main.Result.ERROR, EnumSet.of(Message.DL_ERR9, Message.DL_WRN12)); test(Arrays.asList("-Xdoclint:none"), Main.Result.OK, EnumSet.of(Message.JD_WRN10, Message.JD_WRN13)); test(Arrays.asList(rawDiags, "-Xdoclint"), Main.Result.ERROR, EnumSet.of(Message.DL_ERR9, Message.DL_WRN12)); test(Arrays.asList(rawDiags, "-Xdoclint:all/public"), Main.Result.ERROR, EnumSet.of(Message.OPT_BADQUAL)); test(Arrays.asList(rawDiags, "-Xdoclint:all", "-public"), Main.Result.OK, EnumSet.of(Message.DL_WRN12)); test(Arrays.asList(rawDiags, "-Xdoclint:syntax"), Main.Result.OK, EnumSet.of(Message.DL_WRN12)); test(Arrays.asList(rawDiags, "-private"), Main.Result.ERROR, EnumSet.of(Message.DL_ERR6, Message.DL_ERR9, Message.DL_WRN12)); test(Arrays.asList(rawDiags, "-Xdoclint:syntax", "-private"), Main.Result.ERROR, EnumSet.of(Message.DL_ERR6, Message.DL_WRN12)); test(Arrays.asList(rawDiags, "-Xdoclint:reference"), Main.Result.ERROR, EnumSet.of(Message.DL_ERR9)); test(Arrays.asList(rawDiags, "-Xdoclint:badarg"), Main.Result.ERROR, EnumSet.of(Message.OPT_BADARG)); if (errors > 0) throw new Exception(errors + " errors occurred"); }