author | ksrini |
Thu, 07 Dec 2017 14:15:14 -0800 | |
changeset 48213 | 59696a3595bd |
parent 48029 | e9dab2492924 |
permissions | -rw-r--r-- |
14544 | 1 |
/* |
45417 | 2 |
* Copyright (c) 1998, 2017, 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 |
||
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
25874
diff
changeset
|
26 |
package jdk.javadoc.internal.doclets.toolkit.util; |
14544 | 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:
35426
diff
changeset
|
37 |
import java.nio.file.DirectoryStream; |
688096b6bcc4
8149773: StandardDocFileFactory should be converted to use java.nio.file.Path
jjg
parents:
35426
diff
changeset
|
38 |
import java.nio.file.Files; |
688096b6bcc4
8149773: StandardDocFileFactory should be converted to use java.nio.file.Path
jjg
parents:
35426
diff
changeset
|
39 |
import java.nio.file.Path; |
688096b6bcc4
8149773: StandardDocFileFactory should be converted to use java.nio.file.Path
jjg
parents:
35426
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; |
|
40587 | 45 |
import java.util.Objects; |
14544 | 46 |
import java.util.Set; |
47 |
||
14545
2e7bab0639b8
6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
14544
diff
changeset
|
48 |
import javax.tools.DocumentationTool; |
14544 | 49 |
import javax.tools.FileObject; |
50 |
import javax.tools.JavaFileManager.Location; |
|
51 |
import javax.tools.JavaFileObject; |
|
52 |
import javax.tools.StandardJavaFileManager; |
|
53 |
import javax.tools.StandardLocation; |
|
54 |
||
36037
688096b6bcc4
8149773: StandardDocFileFactory should be converted to use java.nio.file.Path
jjg
parents:
35426
diff
changeset
|
55 |
import com.sun.tools.javac.util.Assert; |
45417 | 56 |
import jdk.javadoc.internal.doclets.toolkit.BaseConfiguration; |
14544 | 57 |
|
58 |
/** |
|
59 |
* Implementation of DocFileFactory using a {@link StandardJavaFileManager}. |
|
60 |
* |
|
61 |
* <p><b>This is NOT part of any supported API. |
|
62 |
* If you write code that depends on this, you do so at your own risk. |
|
63 |
* This code and its internal interfaces are subject to change or |
|
64 |
* deletion without notice.</b> |
|
65 |
* |
|
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:
35426
diff
changeset
|
69 |
private Path destDir; |
14544 | 70 |
|
45417 | 71 |
public StandardDocFileFactory(BaseConfiguration configuration) { |
14544 | 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 |
|
40587 | 76 |
@Override |
77 |
public void setDestDir(String destDirName) throws SimpleDocletException { |
|
78 |
if (destDir != null) |
|
79 |
throw new AssertionError("destDir already initialized: " + destDir); |
|
80 |
||
81 |
if (!destDirName.isEmpty() |
|
82 |
|| !fileManager.hasLocation(DocumentationTool.Location.DOCUMENTATION_OUTPUT)) { |
|
83 |
try { |
|
84 |
String dirName = destDirName.isEmpty() ? "." : destDirName; |
|
85 |
Path dir = Paths.get(dirName); |
|
86 |
fileManager.setLocationFromPaths(DocumentationTool.Location.DOCUMENTATION_OUTPUT, Arrays.asList(dir)); |
|
87 |
} catch (IOException e) { |
|
88 |
// generic IOException from file manager, setting location, e.g. file not a directory |
|
89 |
String message = configuration.getResources().getText("doclet.error.initializing.dest.dir", e); |
|
90 |
throw new SimpleDocletException(message, e); |
|
91 |
} |
|
92 |
} |
|
93 |
||
94 |
destDir = fileManager.getLocationAsPaths(DocumentationTool.Location.DOCUMENTATION_OUTPUT).iterator().next(); |
|
95 |
} |
|
96 |
||
36037
688096b6bcc4
8149773: StandardDocFileFactory should be converted to use java.nio.file.Path
jjg
parents:
35426
diff
changeset
|
97 |
private Path getDestDir() { |
40587 | 98 |
Objects.requireNonNull(destDir, "destDir not initialized"); |
14545
2e7bab0639b8
6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
14544
diff
changeset
|
99 |
return destDir; |
14544 | 100 |
} |
101 |
||
40587 | 102 |
@Override |
14544 | 103 |
public DocFile createFileForDirectory(String file) { |
36037
688096b6bcc4
8149773: StandardDocFileFactory should be converted to use java.nio.file.Path
jjg
parents:
35426
diff
changeset
|
104 |
return new StandardDocFile(Paths.get(file)); |
14544 | 105 |
} |
106 |
||
40587 | 107 |
@Override |
14544 | 108 |
public DocFile createFileForInput(String file) { |
36037
688096b6bcc4
8149773: StandardDocFileFactory should be converted to use java.nio.file.Path
jjg
parents:
35426
diff
changeset
|
109 |
return new StandardDocFile(Paths.get(file)); |
14544 | 110 |
} |
111 |
||
40587 | 112 |
@Override |
14544 | 113 |
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
|
114 |
return new StandardDocFile(DocumentationTool.Location.DOCUMENTATION_OUTPUT, path); |
14544 | 115 |
} |
116 |
||
117 |
@Override |
|
118 |
Iterable<DocFile> list(Location location, DocPath path) { |
|
36526 | 119 |
Location l = ((location == StandardLocation.SOURCE_PATH) |
120 |
&& !fileManager.hasLocation(StandardLocation.SOURCE_PATH)) |
|
121 |
? StandardLocation.CLASS_PATH |
|
122 |
: location; |
|
14544 | 123 |
|
22163 | 124 |
Set<DocFile> files = new LinkedHashSet<>(); |
36037
688096b6bcc4
8149773: StandardDocFileFactory should be converted to use java.nio.file.Path
jjg
parents:
35426
diff
changeset
|
125 |
for (Path f: fileManager.getLocationAsPaths(l)) { |
688096b6bcc4
8149773: StandardDocFileFactory should be converted to use java.nio.file.Path
jjg
parents:
35426
diff
changeset
|
126 |
if (Files.isDirectory(f)) { |
688096b6bcc4
8149773: StandardDocFileFactory should be converted to use java.nio.file.Path
jjg
parents:
35426
diff
changeset
|
127 |
f = f.resolve(path.getPath()); |
688096b6bcc4
8149773: StandardDocFileFactory should be converted to use java.nio.file.Path
jjg
parents:
35426
diff
changeset
|
128 |
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
|
129 |
files.add(new StandardDocFile(f)); |
14544 | 130 |
} |
131 |
} |
|
132 |
return files; |
|
133 |
} |
|
134 |
||
36037
688096b6bcc4
8149773: StandardDocFileFactory should be converted to use java.nio.file.Path
jjg
parents:
35426
diff
changeset
|
135 |
private static Path newFile(Path dir, String path) { |
688096b6bcc4
8149773: StandardDocFileFactory should be converted to use java.nio.file.Path
jjg
parents:
35426
diff
changeset
|
136 |
return (dir == null) ? Paths.get(path) : dir.resolve(path); |
14544 | 137 |
} |
138 |
||
139 |
class StandardDocFile extends DocFile { |
|
40587 | 140 |
private final Path file; |
14544 | 141 |
|
142 |
/** Create a StandardDocFile for a given file. */ |
|
36037
688096b6bcc4
8149773: StandardDocFileFactory should be converted to use java.nio.file.Path
jjg
parents:
35426
diff
changeset
|
143 |
private StandardDocFile(Path file) { |
14544 | 144 |
this.file = file; |
145 |
} |
|
146 |
||
147 |
/** Create a StandardDocFile for a given location and relative path. */ |
|
148 |
private StandardDocFile(Location location, DocPath path) { |
|
40587 | 149 |
super(location, path); |
36037
688096b6bcc4
8149773: StandardDocFileFactory should be converted to use java.nio.file.Path
jjg
parents:
35426
diff
changeset
|
150 |
Assert.check(location == DocumentationTool.Location.DOCUMENTATION_OUTPUT); |
14545
2e7bab0639b8
6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
14544
diff
changeset
|
151 |
this.file = newFile(getDestDir(), path.getPath()); |
14544 | 152 |
} |
153 |
||
48029
e9dab2492924
8185985: Html files in doc-files directories should be wrapped with standard header and footer
ksrini
parents:
47216
diff
changeset
|
154 |
@Override |
e9dab2492924
8185985: Html files in doc-files directories should be wrapped with standard header and footer
ksrini
parents:
47216
diff
changeset
|
155 |
public FileObject getFileObject() { |
e9dab2492924
8185985: Html files in doc-files directories should be wrapped with standard header and footer
ksrini
parents:
47216
diff
changeset
|
156 |
return getJavaFileObjectForInput(file); |
e9dab2492924
8185985: Html files in doc-files directories should be wrapped with standard header and footer
ksrini
parents:
47216
diff
changeset
|
157 |
} |
e9dab2492924
8185985: Html files in doc-files directories should be wrapped with standard header and footer
ksrini
parents:
47216
diff
changeset
|
158 |
|
40587 | 159 |
/** |
160 |
* Open an input stream for the file. |
|
161 |
* |
|
162 |
* @throws DocFileIOException if there is a problem while opening stream |
|
163 |
*/ |
|
164 |
@Override |
|
165 |
public InputStream openInputStream() throws DocFileIOException { |
|
166 |
try { |
|
167 |
JavaFileObject fo = getJavaFileObjectForInput(file); |
|
168 |
return new BufferedInputStream(fo.openInputStream()); |
|
169 |
} catch (IOException e) { |
|
170 |
throw new DocFileIOException(this, DocFileIOException.Mode.READ, e); |
|
171 |
} |
|
14544 | 172 |
} |
173 |
||
174 |
/** |
|
175 |
* Open an output stream for the file. |
|
176 |
* 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
|
177 |
* {@link DocumentationTool.Location#DOCUMENTATION_OUTPUT} and a corresponding relative path. |
40587 | 178 |
* |
179 |
* @throws DocFileIOException if there is a problem while opening stream |
|
14544 | 180 |
*/ |
40587 | 181 |
@Override |
182 |
public OutputStream openOutputStream() throws DocFileIOException { |
|
14545
2e7bab0639b8
6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
14544
diff
changeset
|
183 |
if (location != DocumentationTool.Location.DOCUMENTATION_OUTPUT) |
14544 | 184 |
throw new IllegalStateException(); |
185 |
||
40587 | 186 |
try { |
187 |
OutputStream out = getFileObjectForOutput(path).openOutputStream(); |
|
188 |
return new BufferedOutputStream(out); |
|
189 |
} catch (IOException e) { |
|
190 |
throw new DocFileIOException(this, DocFileIOException.Mode.WRITE, e); |
|
191 |
} |
|
14544 | 192 |
} |
193 |
||
194 |
/** |
|
195 |
* Open an writer for the file, using the encoding (if any) given in the |
|
196 |
* doclet configuration. |
|
197 |
* 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
|
198 |
* {@link DocumentationTool.Location#DOCUMENTATION_OUTPUT} and a corresponding relative path. |
40587 | 199 |
* |
200 |
* @throws DocFileIOException if there is a problem while opening stream |
|
201 |
* @throws UnsupportedEncodingException if the configured encoding is not supported |
|
14544 | 202 |
*/ |
40587 | 203 |
@Override |
204 |
public Writer openWriter() throws DocFileIOException, UnsupportedEncodingException { |
|
14545
2e7bab0639b8
6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
14544
diff
changeset
|
205 |
if (location != DocumentationTool.Location.DOCUMENTATION_OUTPUT) |
14544 | 206 |
throw new IllegalStateException(); |
207 |
||
40587 | 208 |
try { |
209 |
OutputStream out = getFileObjectForOutput(path).openOutputStream(); |
|
46080
65ccd412049b
8183582: Rationalize doclet -docencoding and -charset options
pmuthuswamy
parents:
45417
diff
changeset
|
210 |
return new BufferedWriter(new OutputStreamWriter(out, configuration.docencoding)); |
40587 | 211 |
} catch (IOException e) { |
212 |
throw new DocFileIOException(this, DocFileIOException.Mode.WRITE, e); |
|
14544 | 213 |
} |
214 |
} |
|
215 |
||
216 |
/** Return true if the file can be read. */ |
|
40587 | 217 |
@Override |
14544 | 218 |
public boolean canRead() { |
36037
688096b6bcc4
8149773: StandardDocFileFactory should be converted to use java.nio.file.Path
jjg
parents:
35426
diff
changeset
|
219 |
return Files.isReadable(file); |
14544 | 220 |
} |
221 |
||
222 |
/** Return true if the file can be written. */ |
|
40587 | 223 |
@Override |
14544 | 224 |
public boolean canWrite() { |
36037
688096b6bcc4
8149773: StandardDocFileFactory should be converted to use java.nio.file.Path
jjg
parents:
35426
diff
changeset
|
225 |
return Files.isWritable(file); |
14544 | 226 |
} |
227 |
||
228 |
/** Return true if the file exists. */ |
|
40587 | 229 |
@Override |
14544 | 230 |
public boolean exists() { |
36037
688096b6bcc4
8149773: StandardDocFileFactory should be converted to use java.nio.file.Path
jjg
parents:
35426
diff
changeset
|
231 |
return Files.exists(file); |
14544 | 232 |
} |
233 |
||
234 |
/** Return the base name (last component) of the file name. */ |
|
40587 | 235 |
@Override |
14544 | 236 |
public String getName() { |
36037
688096b6bcc4
8149773: StandardDocFileFactory should be converted to use java.nio.file.Path
jjg
parents:
35426
diff
changeset
|
237 |
return file.getFileName().toString(); |
14544 | 238 |
} |
239 |
||
240 |
/** Return the file system path for this file. */ |
|
40587 | 241 |
@Override |
14544 | 242 |
public String getPath() { |
36037
688096b6bcc4
8149773: StandardDocFileFactory should be converted to use java.nio.file.Path
jjg
parents:
35426
diff
changeset
|
243 |
return file.toString(); |
14544 | 244 |
} |
245 |
||
246 |
/** Return true is file has an absolute path name. */ |
|
40587 | 247 |
@Override |
14544 | 248 |
public boolean isAbsolute() { |
249 |
return file.isAbsolute(); |
|
250 |
} |
|
251 |
||
252 |
/** Return true is file identifies a directory. */ |
|
40587 | 253 |
@Override |
14544 | 254 |
public boolean isDirectory() { |
36037
688096b6bcc4
8149773: StandardDocFileFactory should be converted to use java.nio.file.Path
jjg
parents:
35426
diff
changeset
|
255 |
return Files.isDirectory(file); |
14544 | 256 |
} |
257 |
||
258 |
/** Return true is file identifies a file. */ |
|
40587 | 259 |
@Override |
14544 | 260 |
public boolean isFile() { |
36037
688096b6bcc4
8149773: StandardDocFileFactory should be converted to use java.nio.file.Path
jjg
parents:
35426
diff
changeset
|
261 |
return Files.isRegularFile(file); |
14544 | 262 |
} |
263 |
||
264 |
/** Return true if this file is the same as another. */ |
|
40587 | 265 |
@Override |
14544 | 266 |
public boolean isSameFile(DocFile other) { |
267 |
if (!(other instanceof StandardDocFile)) |
|
268 |
return false; |
|
269 |
||
270 |
try { |
|
36037
688096b6bcc4
8149773: StandardDocFileFactory should be converted to use java.nio.file.Path
jjg
parents:
35426
diff
changeset
|
271 |
return Files.isSameFile(file, ((StandardDocFile) other).file); |
14544 | 272 |
} catch (IOException e) { |
273 |
return false; |
|
274 |
} |
|
275 |
} |
|
276 |
||
277 |
/** If the file is a directory, list its contents. */ |
|
40587 | 278 |
@Override |
279 |
public Iterable<DocFile> list() throws DocFileIOException { |
|
280 |
List<DocFile> files = new ArrayList<>(); |
|
36037
688096b6bcc4
8149773: StandardDocFileFactory should be converted to use java.nio.file.Path
jjg
parents:
35426
diff
changeset
|
281 |
try (DirectoryStream<Path> ds = Files.newDirectoryStream(file)) { |
688096b6bcc4
8149773: StandardDocFileFactory should be converted to use java.nio.file.Path
jjg
parents:
35426
diff
changeset
|
282 |
for (Path f: ds) { |
688096b6bcc4
8149773: StandardDocFileFactory should be converted to use java.nio.file.Path
jjg
parents:
35426
diff
changeset
|
283 |
files.add(new StandardDocFile(f)); |
688096b6bcc4
8149773: StandardDocFileFactory should be converted to use java.nio.file.Path
jjg
parents:
35426
diff
changeset
|
284 |
} |
40587 | 285 |
} catch (IOException e) { |
286 |
throw new DocFileIOException(this, DocFileIOException.Mode.READ, e); |
|
14544 | 287 |
} |
288 |
return files; |
|
289 |
} |
|
290 |
||
291 |
/** Create the file as a directory, including any parent directories. */ |
|
40587 | 292 |
@Override |
14544 | 293 |
public boolean mkdirs() { |
36037
688096b6bcc4
8149773: StandardDocFileFactory should be converted to use java.nio.file.Path
jjg
parents:
35426
diff
changeset
|
294 |
try { |
688096b6bcc4
8149773: StandardDocFileFactory should be converted to use java.nio.file.Path
jjg
parents:
35426
diff
changeset
|
295 |
Files.createDirectories(file); |
688096b6bcc4
8149773: StandardDocFileFactory should be converted to use java.nio.file.Path
jjg
parents:
35426
diff
changeset
|
296 |
return true; |
688096b6bcc4
8149773: StandardDocFileFactory should be converted to use java.nio.file.Path
jjg
parents:
35426
diff
changeset
|
297 |
} catch (IOException e) { |
688096b6bcc4
8149773: StandardDocFileFactory should be converted to use java.nio.file.Path
jjg
parents:
35426
diff
changeset
|
298 |
return false; |
688096b6bcc4
8149773: StandardDocFileFactory should be converted to use java.nio.file.Path
jjg
parents:
35426
diff
changeset
|
299 |
} |
14544 | 300 |
} |
301 |
||
302 |
/** |
|
303 |
* Derive a new file by resolving a relative path against this file. |
|
304 |
* The new file will inherit the configuration and location of this file |
|
305 |
* If this file has a path set, the new file will have a corresponding |
|
306 |
* new path. |
|
307 |
*/ |
|
40587 | 308 |
@Override |
14544 | 309 |
public DocFile resolve(DocPath p) { |
310 |
return resolve(p.getPath()); |
|
311 |
} |
|
312 |
||
313 |
/** |
|
314 |
* Derive a new file by resolving a relative path against this file. |
|
315 |
* The new file will inherit the configuration and location of this file |
|
316 |
* If this file has a path set, the new file will have a corresponding |
|
317 |
* new path. |
|
318 |
*/ |
|
40587 | 319 |
@Override |
14544 | 320 |
public DocFile resolve(String p) { |
321 |
if (location == null && path == null) { |
|
36037
688096b6bcc4
8149773: StandardDocFileFactory should be converted to use java.nio.file.Path
jjg
parents:
35426
diff
changeset
|
322 |
return new StandardDocFile(file.resolve(p)); |
14544 | 323 |
} else { |
324 |
return new StandardDocFile(location, path.resolve(p)); |
|
325 |
} |
|
326 |
} |
|
327 |
||
328 |
/** |
|
329 |
* 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
|
330 |
* @param locn Currently, only |
36037
688096b6bcc4
8149773: StandardDocFileFactory should be converted to use java.nio.file.Path
jjg
parents:
35426
diff
changeset
|
331 |
* {@link DocumentationTool.Location.DOCUMENTATION_OUTPUT} is supported. |
14544 | 332 |
*/ |
40587 | 333 |
@Override |
14545
2e7bab0639b8
6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
14544
diff
changeset
|
334 |
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
|
335 |
if (locn != DocumentationTool.Location.DOCUMENTATION_OUTPUT) |
14544 | 336 |
throw new IllegalArgumentException(); |
36037
688096b6bcc4
8149773: StandardDocFileFactory should be converted to use java.nio.file.Path
jjg
parents:
35426
diff
changeset
|
337 |
return new StandardDocFile(getDestDir().resolve(file)); |
14544 | 338 |
} |
339 |
||
340 |
/** Return a string to identify the contents of this object, |
|
341 |
* for debugging purposes. |
|
342 |
*/ |
|
343 |
@Override |
|
344 |
public String toString() { |
|
345 |
StringBuilder sb = new StringBuilder(); |
|
346 |
sb.append("StandardDocFile["); |
|
347 |
if (location != null) |
|
348 |
sb.append("locn:").append(location).append(","); |
|
349 |
if (path != null) |
|
350 |
sb.append("path:").append(path.getPath()).append(","); |
|
351 |
sb.append("file:").append(file); |
|
352 |
sb.append("]"); |
|
353 |
return sb.toString(); |
|
354 |
} |
|
355 |
||
36037
688096b6bcc4
8149773: StandardDocFileFactory should be converted to use java.nio.file.Path
jjg
parents:
35426
diff
changeset
|
356 |
private JavaFileObject getJavaFileObjectForInput(Path file) { |
14544 | 357 |
return fileManager.getJavaFileObjects(file).iterator().next(); |
358 |
} |
|
359 |
||
360 |
private FileObject getFileObjectForOutput(DocPath path) throws IOException { |
|
361 |
// break the path into a package-part and the rest, by finding |
|
362 |
// the position of the last '/' before an invalid character for a |
|
363 |
// package name, such as the "." before an extension or the "-" |
|
364 |
// in filenames like package-summary.html, doc-files or src-html. |
|
365 |
String p = path.getPath(); |
|
366 |
int lastSep = -1; |
|
367 |
for (int i = 0; i < p.length(); i++) { |
|
368 |
char ch = p.charAt(i); |
|
369 |
if (ch == '/') { |
|
370 |
lastSep = i; |
|
371 |
} else if (i == lastSep + 1 && !Character.isJavaIdentifierStart(ch) |
|
372 |
|| !Character.isJavaIdentifierPart(ch)) { |
|
373 |
break; |
|
374 |
} |
|
375 |
} |
|
376 |
String pkg = (lastSep == -1) ? "" : p.substring(0, lastSep); |
|
377 |
String rest = p.substring(lastSep + 1); |
|
378 |
return fileManager.getFileForOutput(location, pkg, rest, null); |
|
379 |
} |
|
380 |
} |
|
381 |
} |