1 /* |
1 /* |
2 * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 2012, 2014, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * |
4 * |
5 * This code is free software; you can redistribute it and/or modify it |
5 * This code is free software; you can redistribute it and/or modify it |
6 * under the terms of the GNU General Public License version 2 only, as |
6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. |
7 * published by the Free Software Foundation. |
52 @Test |
52 @Test |
53 public void testStandardFileObject() throws Exception { |
53 public void testStandardFileObject() throws Exception { |
54 File testSrc = new File(System.getProperty("test.src")); |
54 File testSrc = new File(System.getProperty("test.src")); |
55 File srcFile = new File(testSrc, "pkg/C.java"); |
55 File srcFile = new File(testSrc, "pkg/C.java"); |
56 DocumentationTool tool = ToolProvider.getSystemDocumentationTool(); |
56 DocumentationTool tool = ToolProvider.getSystemDocumentationTool(); |
57 StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null); |
57 try (StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null)) { |
58 File outDir = getOutDir(); |
58 File outDir = getOutDir(); |
59 fm.setLocation(DocumentationTool.Location.DOCUMENTATION_OUTPUT, Arrays.asList(outDir)); |
59 fm.setLocation(DocumentationTool.Location.DOCUMENTATION_OUTPUT, Arrays.asList(outDir)); |
60 Iterable<? extends JavaFileObject> files = fm.getJavaFileObjects(srcFile); |
60 Iterable<? extends JavaFileObject> files = fm.getJavaFileObjects(srcFile); |
61 DocumentationTask t = tool.getTask(null, fm, null, null, null, files); |
61 DocumentationTask t = tool.getTask(null, fm, null, null, null, files); |
62 if (t.call()) { |
62 if (t.call()) { |
63 System.err.println("task succeeded"); |
63 System.err.println("task succeeded"); |
64 checkFiles(outDir, standardExpectFiles); |
64 checkFiles(outDir, standardExpectFiles); |
65 } else { |
65 } else { |
66 throw new Exception("task failed"); |
66 throw new Exception("task failed"); |
|
67 } |
67 } |
68 } |
68 } |
69 } |
69 |
70 |
70 /** |
71 /** |
71 * Verify that expected output files are written via the file manager, |
72 * Verify that expected output files are written via the file manager, |
73 */ |
74 */ |
74 @Test |
75 @Test |
75 public void testMemoryFileObject() throws Exception { |
76 public void testMemoryFileObject() throws Exception { |
76 JavaFileObject srcFile = createSimpleJavaFileObject(); |
77 JavaFileObject srcFile = createSimpleJavaFileObject(); |
77 DocumentationTool tool = ToolProvider.getSystemDocumentationTool(); |
78 DocumentationTool tool = ToolProvider.getSystemDocumentationTool(); |
78 StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null); |
79 try (StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null)) { |
79 File outDir = getOutDir(); |
80 File outDir = getOutDir(); |
80 fm.setLocation(DocumentationTool.Location.DOCUMENTATION_OUTPUT, Arrays.asList(outDir)); |
81 fm.setLocation(DocumentationTool.Location.DOCUMENTATION_OUTPUT, Arrays.asList(outDir)); |
81 Iterable<? extends JavaFileObject> files = Arrays.asList(srcFile); |
82 Iterable<? extends JavaFileObject> files = Arrays.asList(srcFile); |
82 DocumentationTask t = tool.getTask(null, fm, null, null, null, files); |
83 DocumentationTask t = tool.getTask(null, fm, null, null, null, files); |
83 if (t.call()) { |
84 if (t.call()) { |
84 System.err.println("task succeeded"); |
85 System.err.println("task succeeded"); |
85 checkFiles(outDir, standardExpectFiles); |
86 checkFiles(outDir, standardExpectFiles); |
86 } else { |
87 } else { |
87 throw new Exception("task failed"); |
88 throw new Exception("task failed"); |
|
89 } |
88 } |
90 } |
89 } |
91 } |
90 |
92 |
91 /** |
93 /** |
92 * Verify bad file object is handled correctly. |
94 * Verify bad file object is handled correctly. |
94 @Test |
96 @Test |
95 public void testBadFileObject() throws Exception { |
97 public void testBadFileObject() throws Exception { |
96 File testSrc = new File(System.getProperty("test.src")); |
98 File testSrc = new File(System.getProperty("test.src")); |
97 File srcFile = new File(testSrc, "pkg/C.class"); // unacceptable file kind |
99 File srcFile = new File(testSrc, "pkg/C.class"); // unacceptable file kind |
98 DocumentationTool tool = ToolProvider.getSystemDocumentationTool(); |
100 DocumentationTool tool = ToolProvider.getSystemDocumentationTool(); |
99 StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null); |
101 try (StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null)) { |
100 File outDir = getOutDir(); |
102 File outDir = getOutDir(); |
101 fm.setLocation(DocumentationTool.Location.DOCUMENTATION_OUTPUT, Arrays.asList(outDir)); |
103 fm.setLocation(DocumentationTool.Location.DOCUMENTATION_OUTPUT, Arrays.asList(outDir)); |
102 Iterable<? extends JavaFileObject> files = fm.getJavaFileObjects(srcFile); |
104 Iterable<? extends JavaFileObject> files = fm.getJavaFileObjects(srcFile); |
103 try { |
105 try { |
104 DocumentationTask t = tool.getTask(null, fm, null, null, null, files); |
106 DocumentationTask t = tool.getTask(null, fm, null, null, null, files); |
105 error("getTask succeeded, no exception thrown"); |
107 error("getTask succeeded, no exception thrown"); |
106 } catch (IllegalArgumentException e) { |
108 } catch (IllegalArgumentException e) { |
107 System.err.println("exception caught as expected: " + e); |
109 System.err.println("exception caught as expected: " + e); |
|
110 } |
108 } |
111 } |
109 } |
112 } |
110 |
113 |
111 /** |
114 /** |
112 * Verify null is handled correctly. |
115 * Verify null is handled correctly. |
113 */ |
116 */ |
114 @Test |
117 @Test |
115 public void testNull() throws Exception { |
118 public void testNull() throws Exception { |
116 DocumentationTool tool = ToolProvider.getSystemDocumentationTool(); |
119 DocumentationTool tool = ToolProvider.getSystemDocumentationTool(); |
117 StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null); |
120 try (StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null)) { |
118 File outDir = getOutDir(); |
121 File outDir = getOutDir(); |
119 fm.setLocation(DocumentationTool.Location.DOCUMENTATION_OUTPUT, Arrays.asList(outDir)); |
122 fm.setLocation(DocumentationTool.Location.DOCUMENTATION_OUTPUT, Arrays.asList(outDir)); |
120 Iterable<? extends JavaFileObject> files = Arrays.asList((JavaFileObject) null); |
123 Iterable<? extends JavaFileObject> files = Arrays.asList((JavaFileObject) null); |
121 try { |
124 try { |
122 DocumentationTask t = tool.getTask(null, fm, null, null, null, files); |
125 DocumentationTask t = tool.getTask(null, fm, null, null, null, files); |
123 error("getTask succeeded, no exception thrown"); |
126 error("getTask succeeded, no exception thrown"); |
124 } catch (NullPointerException e) { |
127 } catch (NullPointerException e) { |
125 System.err.println("exception caught as expected: " + e); |
128 System.err.println("exception caught as expected: " + e); |
|
129 } |
126 } |
130 } |
127 } |
131 } |
128 |
132 |
129 } |
133 } |
130 |
134 |