author | jjg |
Mon, 15 Feb 2016 14:02:57 -0800 | |
changeset 36037 | 688096b6bcc4 |
parent 25874 | 83c19f00452c |
child 36526 | 3b41f1c69604 |
permissions | -rw-r--r-- |
14544 | 1 |
/* |
36037
688096b6bcc4
8149773: StandardDocFileFactory should be converted to use java.nio.file.Path
jjg
parents:
25874
diff
changeset
|
2 |
* Copyright (c) 1998, 2016, Oracle and/or its affiliates. All rights reserved. |
14544 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
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 |
|
7 |
* published by the Free Software Foundation. Oracle designates this |
|
8 |
* particular file as subject to the "Classpath" exception as provided |
|
9 |
* by Oracle in the LICENSE file that accompanied this code. |
|
10 |
* |
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
24 |
*/ |
|
25 |
||
26 |
package com.sun.tools.doclets.internal.toolkit.util; |
|
27 |
||
28 |
import java.io.BufferedInputStream; |
|
29 |
import java.io.BufferedOutputStream; |
|
30 |
import java.io.BufferedWriter; |
|
31 |
import java.io.IOException; |
|
32 |
import java.io.InputStream; |
|
33 |
import java.io.OutputStream; |
|
34 |
import java.io.OutputStreamWriter; |
|
35 |
import java.io.UnsupportedEncodingException; |
|
36 |
import java.io.Writer; |
|
36037
688096b6bcc4
8149773: StandardDocFileFactory should be converted to use java.nio.file.Path
jjg
parents:
25874
diff
changeset
|
37 |
import java.nio.file.DirectoryStream; |
688096b6bcc4
8149773: StandardDocFileFactory should be converted to use java.nio.file.Path
jjg
parents:
25874
diff
changeset
|
38 |
import java.nio.file.Files; |
688096b6bcc4
8149773: StandardDocFileFactory should be converted to use java.nio.file.Path
jjg
parents:
25874
diff
changeset
|
39 |
import java.nio.file.Path; |
688096b6bcc4
8149773: StandardDocFileFactory should be converted to use java.nio.file.Path
jjg
parents:
25874
diff
changeset
|
40 |
import java.nio.file.Paths; |
14544 | 41 |
import java.util.ArrayList; |
42 |
import java.util.Arrays; |
|
43 |
import java.util.LinkedHashSet; |
|
44 |
import java.util.List; |
|
45 |
import java.util.Set; |
|
46 |
||
14545
2e7bab0639b8
6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
14544
diff
changeset
|
47 |
import javax.tools.DocumentationTool; |
14544 | 48 |
import javax.tools.FileObject; |
49 |
import javax.tools.JavaFileManager.Location; |
|
50 |
import javax.tools.JavaFileObject; |
|
51 |
import javax.tools.StandardJavaFileManager; |
|
52 |
import javax.tools.StandardLocation; |
|
53 |
||
54 |
import com.sun.tools.doclets.internal.toolkit.Configuration; |
|
55 |
import com.sun.tools.javac.util.Assert; |
|
56 |
||
57 |
/** |
|
58 |
* Implementation of DocFileFactory using a {@link StandardJavaFileManager}. |
|
59 |
* |
|
60 |
* <p><b>This is NOT part of any supported API. |
|
61 |
* If you write code that depends on this, you do so at your own risk. |
|
62 |
* This code and its internal interfaces are subject to change or |
|
63 |
* deletion without notice.</b> |
|
64 |
* |
|
65 |
* @since 1.8 |
|
66 |
*/ |
|
67 |
class StandardDocFileFactory extends DocFileFactory { |
|
68 |
private final StandardJavaFileManager fileManager; |
|
36037
688096b6bcc4
8149773: StandardDocFileFactory should be converted to use java.nio.file.Path
jjg
parents:
25874
diff
changeset
|
69 |
private Path destDir; |
14544 | 70 |
|
71 |
public StandardDocFileFactory(Configuration configuration) { |
|
72 |
super(configuration); |
|
73 |
fileManager = (StandardJavaFileManager) configuration.getFileManager(); |
|
14545
2e7bab0639b8
6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
14544
diff
changeset
|
74 |
} |
14544 | 75 |
|
36037
688096b6bcc4
8149773: StandardDocFileFactory should be converted to use java.nio.file.Path
jjg
parents:
25874
diff
changeset
|
76 |
private Path getDestDir() { |
14545
2e7bab0639b8
6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
14544
diff
changeset
|
77 |
if (destDir == null) { |
2e7bab0639b8
6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
14544
diff
changeset
|
78 |
if (!configuration.destDirName.isEmpty() |
2e7bab0639b8
6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
14544
diff
changeset
|
79 |
|| !fileManager.hasLocation(DocumentationTool.Location.DOCUMENTATION_OUTPUT)) { |
2e7bab0639b8
6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
14544
diff
changeset
|
80 |
try { |
2e7bab0639b8
6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
14544
diff
changeset
|
81 |
String dirName = configuration.destDirName.isEmpty() ? "." : configuration.destDirName; |
36037
688096b6bcc4
8149773: StandardDocFileFactory should be converted to use java.nio.file.Path
jjg
parents:
25874
diff
changeset
|
82 |
Path dir = Paths.get(dirName); |
688096b6bcc4
8149773: StandardDocFileFactory should be converted to use java.nio.file.Path
jjg
parents:
25874
diff
changeset
|
83 |
fileManager.setLocationFromPaths(DocumentationTool.Location.DOCUMENTATION_OUTPUT, Arrays.asList(dir)); |
14545
2e7bab0639b8
6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
14544
diff
changeset
|
84 |
} catch (IOException e) { |
19667
fdfce85627a9
8001669: javadoc internal DocletAbortException should set cause when appropriate
jjg
parents:
14545
diff
changeset
|
85 |
throw new DocletAbortException(e); |
14545
2e7bab0639b8
6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
14544
diff
changeset
|
86 |
} |
14544 | 87 |
} |
14545
2e7bab0639b8
6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
14544
diff
changeset
|
88 |
|
36037
688096b6bcc4
8149773: StandardDocFileFactory should be converted to use java.nio.file.Path
jjg
parents:
25874
diff
changeset
|
89 |
destDir = fileManager.getLocationAsPaths(DocumentationTool.Location.DOCUMENTATION_OUTPUT).iterator().next(); |
14544 | 90 |
} |
14545
2e7bab0639b8
6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
14544
diff
changeset
|
91 |
return destDir; |
14544 | 92 |
} |
93 |
||
94 |
public DocFile createFileForDirectory(String file) { |
|
36037
688096b6bcc4
8149773: StandardDocFileFactory should be converted to use java.nio.file.Path
jjg
parents:
25874
diff
changeset
|
95 |
return new StandardDocFile(Paths.get(file)); |
14544 | 96 |
} |
97 |
||
98 |
public DocFile createFileForInput(String file) { |
|
36037
688096b6bcc4
8149773: StandardDocFileFactory should be converted to use java.nio.file.Path
jjg
parents:
25874
diff
changeset
|
99 |
return new StandardDocFile(Paths.get(file)); |
14544 | 100 |
} |
101 |
||
102 |
public DocFile createFileForOutput(DocPath path) { |
|
14545
2e7bab0639b8
6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
14544
diff
changeset
|
103 |
return new StandardDocFile(DocumentationTool.Location.DOCUMENTATION_OUTPUT, path); |
14544 | 104 |
} |
105 |
||
106 |
@Override |
|
107 |
Iterable<DocFile> list(Location location, DocPath path) { |
|
108 |
if (location != StandardLocation.SOURCE_PATH) |
|
109 |
throw new IllegalArgumentException(); |
|
110 |
||
22163 | 111 |
Set<DocFile> files = new LinkedHashSet<>(); |
14545
2e7bab0639b8
6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
14544
diff
changeset
|
112 |
Location l = fileManager.hasLocation(StandardLocation.SOURCE_PATH) |
2e7bab0639b8
6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
14544
diff
changeset
|
113 |
? StandardLocation.SOURCE_PATH : StandardLocation.CLASS_PATH; |
36037
688096b6bcc4
8149773: StandardDocFileFactory should be converted to use java.nio.file.Path
jjg
parents:
25874
diff
changeset
|
114 |
for (Path f: fileManager.getLocationAsPaths(l)) { |
688096b6bcc4
8149773: StandardDocFileFactory should be converted to use java.nio.file.Path
jjg
parents:
25874
diff
changeset
|
115 |
if (Files.isDirectory(f)) { |
688096b6bcc4
8149773: StandardDocFileFactory should be converted to use java.nio.file.Path
jjg
parents:
25874
diff
changeset
|
116 |
f = f.resolve(path.getPath()); |
688096b6bcc4
8149773: StandardDocFileFactory should be converted to use java.nio.file.Path
jjg
parents:
25874
diff
changeset
|
117 |
if (Files.exists(f)) |
14545
2e7bab0639b8
6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
14544
diff
changeset
|
118 |
files.add(new StandardDocFile(f)); |
14544 | 119 |
} |
120 |
} |
|
121 |
return files; |
|
122 |
} |
|
123 |
||
36037
688096b6bcc4
8149773: StandardDocFileFactory should be converted to use java.nio.file.Path
jjg
parents:
25874
diff
changeset
|
124 |
private static Path newFile(Path dir, String path) { |
688096b6bcc4
8149773: StandardDocFileFactory should be converted to use java.nio.file.Path
jjg
parents:
25874
diff
changeset
|
125 |
return (dir == null) ? Paths.get(path) : dir.resolve(path); |
14544 | 126 |
} |
127 |
||
128 |
class StandardDocFile extends DocFile { |
|
36037
688096b6bcc4
8149773: StandardDocFileFactory should be converted to use java.nio.file.Path
jjg
parents:
25874
diff
changeset
|
129 |
private Path file; |
14544 | 130 |
|
131 |
/** Create a StandardDocFile for a given file. */ |
|
36037
688096b6bcc4
8149773: StandardDocFileFactory should be converted to use java.nio.file.Path
jjg
parents:
25874
diff
changeset
|
132 |
private StandardDocFile(Path file) { |
14544 | 133 |
super(configuration); |
134 |
this.file = file; |
|
135 |
} |
|
136 |
||
137 |
/** Create a StandardDocFile for a given location and relative path. */ |
|
138 |
private StandardDocFile(Location location, DocPath path) { |
|
139 |
super(configuration, location, path); |
|
14545
2e7bab0639b8
6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
14544
diff
changeset
|
140 |
Assert.check(location == DocumentationTool.Location.DOCUMENTATION_OUTPUT); |
2e7bab0639b8
6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
14544
diff
changeset
|
141 |
this.file = newFile(getDestDir(), path.getPath()); |
14544 | 142 |
} |
143 |
||
144 |
/** Open an input stream for the file. */ |
|
145 |
public InputStream openInputStream() throws IOException { |
|
146 |
JavaFileObject fo = getJavaFileObjectForInput(file); |
|
147 |
return new BufferedInputStream(fo.openInputStream()); |
|
148 |
} |
|
149 |
||
150 |
/** |
|
151 |
* Open an output stream for the file. |
|
152 |
* The file must have been created with a location of |
|
14545
2e7bab0639b8
6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
14544
diff
changeset
|
153 |
* {@link DocumentationTool.Location#DOCUMENTATION_OUTPUT} and a corresponding relative path. |
14544 | 154 |
*/ |
155 |
public OutputStream openOutputStream() throws IOException, UnsupportedEncodingException { |
|
14545
2e7bab0639b8
6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
14544
diff
changeset
|
156 |
if (location != DocumentationTool.Location.DOCUMENTATION_OUTPUT) |
14544 | 157 |
throw new IllegalStateException(); |
158 |
||
159 |
OutputStream out = getFileObjectForOutput(path).openOutputStream(); |
|
160 |
return new BufferedOutputStream(out); |
|
161 |
} |
|
162 |
||
163 |
/** |
|
164 |
* Open an writer for the file, using the encoding (if any) given in the |
|
165 |
* doclet configuration. |
|
166 |
* The file must have been created with a location of |
|
14545
2e7bab0639b8
6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
14544
diff
changeset
|
167 |
* {@link DocumentationTool.Location#DOCUMENTATION_OUTPUT} and a corresponding relative path. |
14544 | 168 |
*/ |
169 |
public Writer openWriter() throws IOException, UnsupportedEncodingException { |
|
14545
2e7bab0639b8
6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
14544
diff
changeset
|
170 |
if (location != DocumentationTool.Location.DOCUMENTATION_OUTPUT) |
14544 | 171 |
throw new IllegalStateException(); |
172 |
||
173 |
OutputStream out = getFileObjectForOutput(path).openOutputStream(); |
|
174 |
if (configuration.docencoding == null) { |
|
175 |
return new BufferedWriter(new OutputStreamWriter(out)); |
|
176 |
} else { |
|
177 |
return new BufferedWriter(new OutputStreamWriter(out, configuration.docencoding)); |
|
178 |
} |
|
179 |
} |
|
180 |
||
181 |
/** Return true if the file can be read. */ |
|
182 |
public boolean canRead() { |
|
36037
688096b6bcc4
8149773: StandardDocFileFactory should be converted to use java.nio.file.Path
jjg
parents:
25874
diff
changeset
|
183 |
return Files.isReadable(file); |
14544 | 184 |
} |
185 |
||
186 |
/** Return true if the file can be written. */ |
|
187 |
public boolean canWrite() { |
|
36037
688096b6bcc4
8149773: StandardDocFileFactory should be converted to use java.nio.file.Path
jjg
parents:
25874
diff
changeset
|
188 |
return Files.isWritable(file); |
14544 | 189 |
} |
190 |
||
191 |
/** Return true if the file exists. */ |
|
192 |
public boolean exists() { |
|
36037
688096b6bcc4
8149773: StandardDocFileFactory should be converted to use java.nio.file.Path
jjg
parents:
25874
diff
changeset
|
193 |
return Files.exists(file); |
14544 | 194 |
} |
195 |
||
196 |
/** Return the base name (last component) of the file name. */ |
|
197 |
public String getName() { |
|
36037
688096b6bcc4
8149773: StandardDocFileFactory should be converted to use java.nio.file.Path
jjg
parents:
25874
diff
changeset
|
198 |
return file.getFileName().toString(); |
14544 | 199 |
} |
200 |
||
201 |
/** Return the file system path for this file. */ |
|
202 |
public String getPath() { |
|
36037
688096b6bcc4
8149773: StandardDocFileFactory should be converted to use java.nio.file.Path
jjg
parents:
25874
diff
changeset
|
203 |
return file.toString(); |
14544 | 204 |
} |
205 |
||
206 |
/** Return true is file has an absolute path name. */ |
|
207 |
public boolean isAbsolute() { |
|
208 |
return file.isAbsolute(); |
|
209 |
} |
|
210 |
||
211 |
/** Return true is file identifies a directory. */ |
|
212 |
public boolean isDirectory() { |
|
36037
688096b6bcc4
8149773: StandardDocFileFactory should be converted to use java.nio.file.Path
jjg
parents:
25874
diff
changeset
|
213 |
return Files.isDirectory(file); |
14544 | 214 |
} |
215 |
||
216 |
/** Return true is file identifies a file. */ |
|
217 |
public boolean isFile() { |
|
36037
688096b6bcc4
8149773: StandardDocFileFactory should be converted to use java.nio.file.Path
jjg
parents:
25874
diff
changeset
|
218 |
return Files.isRegularFile(file); |
14544 | 219 |
} |
220 |
||
221 |
/** Return true if this file is the same as another. */ |
|
222 |
public boolean isSameFile(DocFile other) { |
|
223 |
if (!(other instanceof StandardDocFile)) |
|
224 |
return false; |
|
225 |
||
226 |
try { |
|
36037
688096b6bcc4
8149773: StandardDocFileFactory should be converted to use java.nio.file.Path
jjg
parents:
25874
diff
changeset
|
227 |
return Files.isSameFile(file, ((StandardDocFile) other).file); |
14544 | 228 |
} catch (IOException e) { |
229 |
return false; |
|
230 |
} |
|
231 |
} |
|
232 |
||
233 |
/** If the file is a directory, list its contents. */ |
|
36037
688096b6bcc4
8149773: StandardDocFileFactory should be converted to use java.nio.file.Path
jjg
parents:
25874
diff
changeset
|
234 |
public Iterable<DocFile> list() throws IOException { |
688096b6bcc4
8149773: StandardDocFileFactory should be converted to use java.nio.file.Path
jjg
parents:
25874
diff
changeset
|
235 |
List<DocFile> files = new ArrayList<DocFile>(); |
688096b6bcc4
8149773: StandardDocFileFactory should be converted to use java.nio.file.Path
jjg
parents:
25874
diff
changeset
|
236 |
try (DirectoryStream<Path> ds = Files.newDirectoryStream(file)) { |
688096b6bcc4
8149773: StandardDocFileFactory should be converted to use java.nio.file.Path
jjg
parents:
25874
diff
changeset
|
237 |
for (Path f: ds) { |
688096b6bcc4
8149773: StandardDocFileFactory should be converted to use java.nio.file.Path
jjg
parents:
25874
diff
changeset
|
238 |
files.add(new StandardDocFile(f)); |
688096b6bcc4
8149773: StandardDocFileFactory should be converted to use java.nio.file.Path
jjg
parents:
25874
diff
changeset
|
239 |
} |
14544 | 240 |
} |
241 |
return files; |
|
242 |
} |
|
243 |
||
244 |
/** Create the file as a directory, including any parent directories. */ |
|
245 |
public boolean mkdirs() { |
|
36037
688096b6bcc4
8149773: StandardDocFileFactory should be converted to use java.nio.file.Path
jjg
parents:
25874
diff
changeset
|
246 |
try { |
688096b6bcc4
8149773: StandardDocFileFactory should be converted to use java.nio.file.Path
jjg
parents:
25874
diff
changeset
|
247 |
Files.createDirectories(file); |
688096b6bcc4
8149773: StandardDocFileFactory should be converted to use java.nio.file.Path
jjg
parents:
25874
diff
changeset
|
248 |
return true; |
688096b6bcc4
8149773: StandardDocFileFactory should be converted to use java.nio.file.Path
jjg
parents:
25874
diff
changeset
|
249 |
} catch (IOException e) { |
688096b6bcc4
8149773: StandardDocFileFactory should be converted to use java.nio.file.Path
jjg
parents:
25874
diff
changeset
|
250 |
return false; |
688096b6bcc4
8149773: StandardDocFileFactory should be converted to use java.nio.file.Path
jjg
parents:
25874
diff
changeset
|
251 |
} |
14544 | 252 |
} |
253 |
||
254 |
/** |
|
255 |
* Derive a new file by resolving a relative path against this file. |
|
256 |
* The new file will inherit the configuration and location of this file |
|
257 |
* If this file has a path set, the new file will have a corresponding |
|
258 |
* new path. |
|
259 |
*/ |
|
260 |
public DocFile resolve(DocPath p) { |
|
261 |
return resolve(p.getPath()); |
|
262 |
} |
|
263 |
||
264 |
/** |
|
265 |
* Derive a new file by resolving a relative path against this file. |
|
266 |
* The new file will inherit the configuration and location of this file |
|
267 |
* If this file has a path set, the new file will have a corresponding |
|
268 |
* new path. |
|
269 |
*/ |
|
270 |
public DocFile resolve(String p) { |
|
271 |
if (location == null && path == null) { |
|
36037
688096b6bcc4
8149773: StandardDocFileFactory should be converted to use java.nio.file.Path
jjg
parents:
25874
diff
changeset
|
272 |
return new StandardDocFile(file.resolve(p)); |
14544 | 273 |
} else { |
274 |
return new StandardDocFile(location, path.resolve(p)); |
|
275 |
} |
|
276 |
} |
|
277 |
||
278 |
/** |
|
279 |
* Resolve a relative file against the given output location. |
|
14545
2e7bab0639b8
6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
14544
diff
changeset
|
280 |
* @param locn Currently, only |
36037
688096b6bcc4
8149773: StandardDocFileFactory should be converted to use java.nio.file.Path
jjg
parents:
25874
diff
changeset
|
281 |
* {@link DocumentationTool.Location.DOCUMENTATION_OUTPUT} is supported. |
14544 | 282 |
*/ |
14545
2e7bab0639b8
6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
14544
diff
changeset
|
283 |
public DocFile resolveAgainst(Location locn) { |
2e7bab0639b8
6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
14544
diff
changeset
|
284 |
if (locn != DocumentationTool.Location.DOCUMENTATION_OUTPUT) |
14544 | 285 |
throw new IllegalArgumentException(); |
36037
688096b6bcc4
8149773: StandardDocFileFactory should be converted to use java.nio.file.Path
jjg
parents:
25874
diff
changeset
|
286 |
return new StandardDocFile(getDestDir().resolve(file)); |
14544 | 287 |
} |
288 |
||
289 |
/** Return a string to identify the contents of this object, |
|
290 |
* for debugging purposes. |
|
291 |
*/ |
|
292 |
@Override |
|
293 |
public String toString() { |
|
294 |
StringBuilder sb = new StringBuilder(); |
|
36037
688096b6bcc4
8149773: StandardDocFileFactory should be converted to use java.nio.file.Path
jjg
parents:
25874
diff
changeset
|
295 |
sb.append("PathDocFile["); |
14544 | 296 |
if (location != null) |
297 |
sb.append("locn:").append(location).append(","); |
|
298 |
if (path != null) |
|
299 |
sb.append("path:").append(path.getPath()).append(","); |
|
300 |
sb.append("file:").append(file); |
|
301 |
sb.append("]"); |
|
302 |
return sb.toString(); |
|
303 |
} |
|
304 |
||
36037
688096b6bcc4
8149773: StandardDocFileFactory should be converted to use java.nio.file.Path
jjg
parents:
25874
diff
changeset
|
305 |
private JavaFileObject getJavaFileObjectForInput(Path file) { |
14544 | 306 |
return fileManager.getJavaFileObjects(file).iterator().next(); |
307 |
} |
|
308 |
||
309 |
private FileObject getFileObjectForOutput(DocPath path) throws IOException { |
|
310 |
// break the path into a package-part and the rest, by finding |
|
311 |
// the position of the last '/' before an invalid character for a |
|
312 |
// package name, such as the "." before an extension or the "-" |
|
313 |
// in filenames like package-summary.html, doc-files or src-html. |
|
314 |
String p = path.getPath(); |
|
315 |
int lastSep = -1; |
|
316 |
for (int i = 0; i < p.length(); i++) { |
|
317 |
char ch = p.charAt(i); |
|
318 |
if (ch == '/') { |
|
319 |
lastSep = i; |
|
320 |
} else if (i == lastSep + 1 && !Character.isJavaIdentifierStart(ch) |
|
321 |
|| !Character.isJavaIdentifierPart(ch)) { |
|
322 |
break; |
|
323 |
} |
|
324 |
} |
|
325 |
String pkg = (lastSep == -1) ? "" : p.substring(0, lastSep); |
|
326 |
String rest = p.substring(lastSep + 1); |
|
327 |
return fileManager.getFileForOutput(location, pkg, rest, null); |
|
328 |
} |
|
329 |
} |
|
330 |
} |