40 import java.util.Arrays; |
40 import java.util.Arrays; |
41 import java.util.LinkedHashSet; |
41 import java.util.LinkedHashSet; |
42 import java.util.List; |
42 import java.util.List; |
43 import java.util.Set; |
43 import java.util.Set; |
44 |
44 |
|
45 import javax.tools.DocumentationTool; |
45 import javax.tools.FileObject; |
46 import javax.tools.FileObject; |
46 import javax.tools.JavaFileManager.Location; |
47 import javax.tools.JavaFileManager.Location; |
47 import javax.tools.JavaFileObject; |
48 import javax.tools.JavaFileObject; |
48 import javax.tools.StandardLocation; |
49 import javax.tools.StandardLocation; |
49 |
50 |
68 public PathDocFileFactory(Configuration configuration) { |
69 public PathDocFileFactory(Configuration configuration) { |
69 super(configuration); |
70 super(configuration); |
70 fileManager = (PathFileManager) configuration.getFileManager(); |
71 fileManager = (PathFileManager) configuration.getFileManager(); |
71 |
72 |
72 if (!configuration.destDirName.isEmpty() |
73 if (!configuration.destDirName.isEmpty() |
73 || !fileManager.hasLocation(StandardLocation.CLASS_OUTPUT)) { |
74 || !fileManager.hasLocation(DocumentationTool.Location.DOCUMENTATION_OUTPUT)) { |
74 try { |
75 try { |
75 String dirName = configuration.destDirName.isEmpty() ? "." : configuration.destDirName; |
76 String dirName = configuration.destDirName.isEmpty() ? "." : configuration.destDirName; |
76 Path dir = fileManager.getDefaultFileSystem().getPath(dirName); |
77 Path dir = fileManager.getDefaultFileSystem().getPath(dirName); |
77 fileManager.setLocation(StandardLocation.CLASS_OUTPUT, Arrays.asList(dir)); |
78 fileManager.setLocation(DocumentationTool.Location.DOCUMENTATION_OUTPUT, Arrays.asList(dir)); |
78 } catch (IOException e) { |
79 } catch (IOException e) { |
79 throw new DocletAbortException(); |
80 throw new DocletAbortException(); |
80 } |
81 } |
81 } |
82 } |
82 |
83 |
83 destDir = fileManager.getLocation(StandardLocation.CLASS_OUTPUT).iterator().next(); |
84 destDir = fileManager.getLocation(DocumentationTool.Location.DOCUMENTATION_OUTPUT).iterator().next(); |
84 } |
85 } |
85 |
86 |
86 public DocFile createFileForDirectory(String file) { |
87 public DocFile createFileForDirectory(String file) { |
87 return new StandardDocFile(fileManager.getDefaultFileSystem().getPath(file)); |
88 return new StandardDocFile(fileManager.getDefaultFileSystem().getPath(file)); |
88 } |
89 } |
90 public DocFile createFileForInput(String file) { |
91 public DocFile createFileForInput(String file) { |
91 return new StandardDocFile(fileManager.getDefaultFileSystem().getPath(file)); |
92 return new StandardDocFile(fileManager.getDefaultFileSystem().getPath(file)); |
92 } |
93 } |
93 |
94 |
94 public DocFile createFileForOutput(DocPath path) { |
95 public DocFile createFileForOutput(DocPath path) { |
95 return new StandardDocFile(StandardLocation.CLASS_OUTPUT, path); |
96 return new StandardDocFile(DocumentationTool.Location.DOCUMENTATION_OUTPUT, path); |
96 } |
97 } |
97 |
98 |
98 @Override |
99 @Override |
99 Iterable<DocFile> list(Location location, DocPath path) { |
100 Iterable<DocFile> list(Location location, DocPath path) { |
100 if (location != StandardLocation.SOURCE_PATH) |
101 if (location != StandardLocation.SOURCE_PATH) |
135 } |
136 } |
136 |
137 |
137 /** |
138 /** |
138 * Open an output stream for the file. |
139 * Open an output stream for the file. |
139 * The file must have been created with a location of |
140 * The file must have been created with a location of |
140 * {@link StandardLocation#CLASS_OUTPUT} and a corresponding relative path. |
141 * {@link DocumentationTool.Location#DOCUMENTATION_OUTPUT} and a corresponding relative path. |
141 */ |
142 */ |
142 public OutputStream openOutputStream() throws IOException, UnsupportedEncodingException { |
143 public OutputStream openOutputStream() throws IOException, UnsupportedEncodingException { |
143 if (location != StandardLocation.CLASS_OUTPUT) |
144 if (location != DocumentationTool.Location.DOCUMENTATION_OUTPUT) |
144 throw new IllegalStateException(); |
145 throw new IllegalStateException(); |
145 |
146 |
146 OutputStream out = getFileObjectForOutput(path).openOutputStream(); |
147 OutputStream out = getFileObjectForOutput(path).openOutputStream(); |
147 return new BufferedOutputStream(out); |
148 return new BufferedOutputStream(out); |
148 } |
149 } |
149 |
150 |
150 /** |
151 /** |
151 * Open an writer for the file, using the encoding (if any) given in the |
152 * Open an writer for the file, using the encoding (if any) given in the |
152 * doclet configuration. |
153 * doclet configuration. |
153 * The file must have been created with a location of |
154 * The file must have been created with a location of |
154 * {@link StandardLocation#CLASS_OUTPUT} and a corresponding relative path. |
155 * {@link DocumentationTool.Location#DOCUMENTATION_OUTPUT} and a corresponding relative path. |
155 */ |
156 */ |
156 public Writer openWriter() throws IOException, UnsupportedEncodingException { |
157 public Writer openWriter() throws IOException, UnsupportedEncodingException { |
157 if (location != StandardLocation.CLASS_OUTPUT) |
158 if (location != DocumentationTool.Location.DOCUMENTATION_OUTPUT) |
158 throw new IllegalStateException(); |
159 throw new IllegalStateException(); |
159 |
160 |
160 OutputStream out = getFileObjectForOutput(path).openOutputStream(); |
161 OutputStream out = getFileObjectForOutput(path).openOutputStream(); |
161 if (configuration.docencoding == null) { |
162 if (configuration.docencoding == null) { |
162 return new BufferedWriter(new OutputStreamWriter(out)); |
163 return new BufferedWriter(new OutputStreamWriter(out)); |
260 } |
261 } |
261 } |
262 } |
262 |
263 |
263 /** |
264 /** |
264 * Resolve a relative file against the given output location. |
265 * Resolve a relative file against the given output location. |
265 * @param locn Currently, only SOURCE_OUTPUT is supported. |
266 * @param locn Currently, only |
266 */ |
267 * {@link DocumentationTool.Location.DOCUMENTATION_OUTPUT} is supported. |
267 public DocFile resolveAgainst(StandardLocation locn) { |
268 */ |
268 if (locn != StandardLocation.CLASS_OUTPUT) |
269 public DocFile resolveAgainst(Location locn) { |
|
270 if (locn != DocumentationTool.Location.DOCUMENTATION_OUTPUT) |
269 throw new IllegalArgumentException(); |
271 throw new IllegalArgumentException(); |
270 return new StandardDocFile(destDir.resolve(file)); |
272 return new StandardDocFile(destDir.resolve(file)); |
271 } |
273 } |
272 |
274 |
273 /** Return a string to identify the contents of this object, |
275 /** Return a string to identify the contents of this object, |