author | erikj |
Tue, 12 Sep 2017 19:03:39 +0200 | |
changeset 47216 | 71c04702a3d5 |
parent 42827 | langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/file/CacheFSInfo.java@36468b5fa7f4 |
child 54296 | dc66ada06693 |
permissions | -rw-r--r-- |
1208 | 1 |
/* |
27852
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27226
diff
changeset
|
2 |
* Copyright (c) 2005, 2014, Oracle and/or its affiliates. All rights reserved. |
1208 | 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 |
|
5520 | 7 |
* published by the Free Software Foundation. Oracle designates this |
1208 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5520 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
1208 | 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 |
* |
|
5520 | 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. |
|
1208 | 24 |
*/ |
25 |
||
26 |
package com.sun.tools.javac.file; |
|
27 |
||
28 |
import java.io.IOException; |
|
27852
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27226
diff
changeset
|
29 |
import java.nio.file.Path; |
1208 | 30 |
import java.util.List; |
8223
638daa596494
6988106: javac report 'java.lang.IllegalMonitorStateException'
jjg
parents:
5847
diff
changeset
|
31 |
import java.util.Map; |
638daa596494
6988106: javac report 'java.lang.IllegalMonitorStateException'
jjg
parents:
5847
diff
changeset
|
32 |
import java.util.concurrent.ConcurrentHashMap; |
1208 | 33 |
|
34 |
import com.sun.tools.javac.util.Context; |
|
42827
36468b5fa7f4
8181370: Convert anonymous inner classes into lambdas/method references
mcimadamore
parents:
27852
diff
changeset
|
35 |
import com.sun.tools.javac.util.Context.Factory; |
1208 | 36 |
|
37 |
/** |
|
3380
a6c2bcab0fec
6865399: some javac files are missing Sun internal API comment
jjg
parents:
1208
diff
changeset
|
38 |
* Caching implementation of FSInfo. |
a6c2bcab0fec
6865399: some javac files are missing Sun internal API comment
jjg
parents:
1208
diff
changeset
|
39 |
* |
5847
1908176fd6e3
6944312: Potential rebranding issues in openjdk/langtools repository sources
jjg
parents:
5520
diff
changeset
|
40 |
* <p><b>This is NOT part of any supported API. |
3380
a6c2bcab0fec
6865399: some javac files are missing Sun internal API comment
jjg
parents:
1208
diff
changeset
|
41 |
* If you write code that depends on this, you do so at your own risk. |
a6c2bcab0fec
6865399: some javac files are missing Sun internal API comment
jjg
parents:
1208
diff
changeset
|
42 |
* This code and its internal interfaces are subject to change or |
a6c2bcab0fec
6865399: some javac files are missing Sun internal API comment
jjg
parents:
1208
diff
changeset
|
43 |
* deletion without notice.</b> |
1208 | 44 |
*/ |
45 |
public class CacheFSInfo extends FSInfo { |
|
46 |
||
47 |
/** |
|
8614 | 48 |
* Register a Context.Factory to create a CacheFSInfo. |
1208 | 49 |
*/ |
8614 | 50 |
public static void preRegister(Context context) { |
42827
36468b5fa7f4
8181370: Convert anonymous inner classes into lambdas/method references
mcimadamore
parents:
27852
diff
changeset
|
51 |
context.put(FSInfo.class, (Factory<FSInfo>)c -> { |
8422 | 52 |
FSInfo instance = new CacheFSInfo(); |
8614 | 53 |
c.put(FSInfo.class, instance); |
8422 | 54 |
return instance; |
42827
36468b5fa7f4
8181370: Convert anonymous inner classes into lambdas/method references
mcimadamore
parents:
27852
diff
changeset
|
55 |
}); |
1208 | 56 |
} |
57 |
||
58 |
public void clearCache() { |
|
59 |
cache.clear(); |
|
60 |
} |
|
61 |
||
62 |
@Override |
|
27852
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27226
diff
changeset
|
63 |
public Path getCanonicalFile(Path file) { |
1208 | 64 |
Entry e = getEntry(file); |
65 |
return e.canonicalFile; |
|
66 |
} |
|
67 |
||
68 |
@Override |
|
27852
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27226
diff
changeset
|
69 |
public boolean exists(Path file) { |
1208 | 70 |
Entry e = getEntry(file); |
71 |
return e.exists; |
|
72 |
} |
|
73 |
||
74 |
@Override |
|
27852
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27226
diff
changeset
|
75 |
public boolean isDirectory(Path file) { |
1208 | 76 |
Entry e = getEntry(file); |
77 |
return e.isDirectory; |
|
78 |
} |
|
79 |
||
80 |
@Override |
|
27852
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27226
diff
changeset
|
81 |
public boolean isFile(Path file) { |
1208 | 82 |
Entry e = getEntry(file); |
83 |
return e.isFile; |
|
84 |
} |
|
85 |
||
86 |
@Override |
|
27852
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27226
diff
changeset
|
87 |
public List<Path> getJarClassPath(Path file) throws IOException { |
1208 | 88 |
// don't bother to lock the cache, because it is thread-safe, and |
89 |
// because the worst that can happen would be to create two identical |
|
90 |
// jar class paths together and have one overwrite the other. |
|
91 |
Entry e = getEntry(file); |
|
92 |
if (e.jarClassPath == null) |
|
93 |
e.jarClassPath = super.getJarClassPath(file); |
|
94 |
return e.jarClassPath; |
|
95 |
} |
|
96 |
||
27852
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27226
diff
changeset
|
97 |
private Entry getEntry(Path file) { |
1208 | 98 |
// don't bother to lock the cache, because it is thread-safe, and |
99 |
// because the worst that can happen would be to create two identical |
|
100 |
// entries together and have one overwrite the other. |
|
101 |
Entry e = cache.get(file); |
|
102 |
if (e == null) { |
|
103 |
e = new Entry(); |
|
104 |
e.canonicalFile = super.getCanonicalFile(file); |
|
105 |
e.exists = super.exists(file); |
|
106 |
e.isDirectory = super.isDirectory(file); |
|
107 |
e.isFile = super.isFile(file); |
|
108 |
cache.put(file, e); |
|
109 |
} |
|
110 |
return e; |
|
111 |
} |
|
112 |
||
113 |
// could also be a Map<File,SoftReference<Entry>> ? |
|
27852
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27226
diff
changeset
|
114 |
private final Map<Path,Entry> cache = new ConcurrentHashMap<>(); |
1208 | 115 |
|
116 |
private static class Entry { |
|
27852
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27226
diff
changeset
|
117 |
Path canonicalFile; |
1208 | 118 |
boolean exists; |
119 |
boolean isFile; |
|
120 |
boolean isDirectory; |
|
27852
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27226
diff
changeset
|
121 |
List<Path> jarClassPath; |
1208 | 122 |
} |
123 |
} |