author | briangoetz |
Wed, 18 Dec 2013 16:05:18 -0500 | |
changeset 22163 | 3651128c74eb |
parent 14801 | d66cab4ef397 |
permissions | -rw-r--r-- |
14544 | 1 |
/* |
2 |
* Copyright (c) 1998, 2012, Oracle and/or its affiliates. All rights reserved. |
|
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.util.Map; |
|
29 |
import java.util.WeakHashMap; |
|
30 |
||
31 |
import javax.tools.JavaFileManager; |
|
32 |
import javax.tools.JavaFileManager.Location; |
|
33 |
import javax.tools.StandardJavaFileManager; |
|
34 |
import javax.tools.StandardLocation; |
|
35 |
||
36 |
import com.sun.tools.doclets.internal.toolkit.Configuration; |
|
37 |
||
38 |
/** |
|
39 |
* Factory for DocFile objects. |
|
40 |
* |
|
41 |
* <p><b>This is NOT part of any supported API. |
|
42 |
* If you write code that depends on this, you do so at your own risk. |
|
43 |
* This code and its internal interfaces are subject to change or |
|
44 |
* deletion without notice.</b> |
|
45 |
* |
|
46 |
* @since 1.8 |
|
47 |
*/ |
|
48 |
abstract class DocFileFactory { |
|
22163 | 49 |
private static final Map<Configuration, DocFileFactory> factories = new WeakHashMap<>(); |
14544 | 50 |
|
51 |
/** |
|
52 |
* Get the appropriate factory, based on the file manager given in the |
|
53 |
* configuration. |
|
54 |
*/ |
|
55 |
static synchronized DocFileFactory getFactory(Configuration configuration) { |
|
56 |
DocFileFactory f = factories.get(configuration); |
|
57 |
if (f == null) { |
|
58 |
JavaFileManager fm = configuration.getFileManager(); |
|
59 |
if (fm instanceof StandardJavaFileManager) |
|
60 |
f = new StandardDocFileFactory(configuration); |
|
61 |
else { |
|
62 |
try { |
|
63 |
Class<?> pathFileManagerClass = |
|
64 |
Class.forName("com.sun.tools.javac.nio.PathFileManager"); |
|
65 |
if (pathFileManagerClass.isAssignableFrom(fm.getClass())) |
|
66 |
f = new PathDocFileFactory(configuration); |
|
67 |
} catch (Throwable t) { |
|
68 |
throw new IllegalStateException(t); |
|
69 |
} |
|
70 |
} |
|
14545
2e7bab0639b8
6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
14544
diff
changeset
|
71 |
factories.put(configuration, f); |
14544 | 72 |
} |
73 |
return f; |
|
74 |
} |
|
75 |
||
76 |
protected Configuration configuration; |
|
77 |
||
78 |
protected DocFileFactory(Configuration configuration) { |
|
79 |
this.configuration = configuration; |
|
80 |
} |
|
81 |
||
82 |
/** Create a DocFile for a directory. */ |
|
83 |
abstract DocFile createFileForDirectory(String file); |
|
84 |
||
85 |
/** Create a DocFile for a file that will be opened for reading. */ |
|
86 |
abstract DocFile createFileForInput(String file); |
|
87 |
||
88 |
/** Create a DocFile for a file that will be opened for writing. */ |
|
89 |
abstract DocFile createFileForOutput(DocPath path); |
|
90 |
||
91 |
/** |
|
92 |
* List the directories and files found in subdirectories along the |
|
93 |
* elements of the given location. |
|
94 |
* @param location currently, only {@link StandardLocation#SOURCE_PATH} is supported. |
|
95 |
* @param path the subdirectory of the directories of the location for which to |
|
96 |
* list files |
|
97 |
*/ |
|
98 |
abstract Iterable<DocFile> list(Location location, DocPath path); |
|
99 |
} |