54 |
54 |
55 @Test |
55 @Test |
56 public void testRawCall() throws Exception { |
56 public void testRawCall() throws Exception { |
57 JavaFileObject srcFile = createSimpleJavaFileObject(); |
57 JavaFileObject srcFile = createSimpleJavaFileObject(); |
58 DocumentationTool tool = ToolProvider.getSystemDocumentationTool(); |
58 DocumentationTool tool = ToolProvider.getSystemDocumentationTool(); |
59 StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null); |
59 try (StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null)) { |
60 File outDir = getOutDir(); |
60 File outDir = getOutDir(); |
61 fm.setLocation(DocumentationTool.Location.DOCUMENTATION_OUTPUT, Arrays.asList(outDir)); |
61 fm.setLocation(DocumentationTool.Location.DOCUMENTATION_OUTPUT, Arrays.asList(outDir)); |
62 Iterable<? extends JavaFileObject> files = Arrays.asList(srcFile); |
62 Iterable<? extends JavaFileObject> files = Arrays.asList(srcFile); |
63 |
63 |
64 @SuppressWarnings("rawtypes") |
64 @SuppressWarnings("rawtypes") |
65 Callable t = tool.getTask(null, fm, null, null, null, files); |
65 Callable t = tool.getTask(null, fm, null, null, null, files); |
66 |
66 |
67 if (t.call() == Boolean.TRUE) { |
67 if (t.call() == Boolean.TRUE) { |
68 System.err.println("task succeeded"); |
68 System.err.println("task succeeded"); |
69 } else { |
69 } else { |
70 throw new Exception("task failed"); |
70 throw new Exception("task failed"); |
|
71 } |
71 } |
72 } |
72 } |
73 } |
73 |
74 |
74 @Test |
75 @Test |
75 public void testDirectAccess1() throws Exception { |
76 public void testDirectAccess1() throws Exception { |
76 JavaFileObject srcFile = createSimpleJavaFileObject(); |
77 JavaFileObject srcFile = createSimpleJavaFileObject(); |
77 Iterable<? extends JavaFileObject> files = Arrays.asList(srcFile); |
78 Iterable<? extends JavaFileObject> files = Arrays.asList(srcFile); |
78 Context c = new Context(); |
79 Context c = new Context(); |
79 Messager.preRegister(c, "javadoc"); |
80 Messager.preRegister(c, "javadoc"); |
80 StandardJavaFileManager fm = new JavacFileManager(c, true, null); |
81 try (StandardJavaFileManager fm = new JavacFileManager(c, true, null)) { |
81 File outDir = getOutDir(); |
82 File outDir = getOutDir(); |
82 fm.setLocation(DocumentationTool.Location.DOCUMENTATION_OUTPUT, Arrays.asList(outDir)); |
83 fm.setLocation(DocumentationTool.Location.DOCUMENTATION_OUTPUT, Arrays.asList(outDir)); |
83 DocumentationTask t = new JavadocTaskImpl(c, null, null, files); |
84 DocumentationTask t = new JavadocTaskImpl(c, null, null, files); |
84 if (t.call()) { |
85 if (t.call()) { |
85 System.err.println("task succeeded"); |
86 System.err.println("task succeeded"); |
86 } else { |
87 } else { |
87 throw new Exception("task failed"); |
88 throw new Exception("task failed"); |
|
89 } |
88 } |
90 } |
89 } |
91 } |
90 |
92 |
91 @Test |
93 @Test |
92 public void testDirectAccess2() throws Exception { |
94 public void testDirectAccess2() throws Exception { |
93 JavaFileObject srcFile = null; // error, provokes NPE |
95 JavaFileObject srcFile = null; // error, provokes NPE |
94 Iterable<? extends JavaFileObject> files = Arrays.asList(srcFile); |
96 Iterable<? extends JavaFileObject> files = Arrays.asList(srcFile); |
95 Context c = new Context(); |
97 Context c = new Context(); |
96 Messager.preRegister(c, "javadoc"); |
98 Messager.preRegister(c, "javadoc"); |
97 StandardJavaFileManager fm = new JavacFileManager(c, true, null); |
99 try (StandardJavaFileManager fm = new JavacFileManager(c, true, null)) { |
98 File outDir = getOutDir(); |
100 File outDir = getOutDir(); |
99 fm.setLocation(DocumentationTool.Location.DOCUMENTATION_OUTPUT, Arrays.asList(outDir)); |
101 fm.setLocation(DocumentationTool.Location.DOCUMENTATION_OUTPUT, Arrays.asList(outDir)); |
100 try { |
102 try { |
101 DocumentationTask t = new JavadocTaskImpl(c, null, null, files);; |
103 DocumentationTask t = new JavadocTaskImpl(c, null, null, files);; |
102 error("getTask succeeded, no exception thrown"); |
104 error("getTask succeeded, no exception thrown"); |
103 } catch (NullPointerException e) { |
105 } catch (NullPointerException e) { |
104 System.err.println("exception caught as expected: " + e); |
106 System.err.println("exception caught as expected: " + e); |
|
107 } |
105 } |
108 } |
106 } |
109 } |
107 } |
110 } |
108 |
111 |