author | jlahoda |
Tue, 24 Sep 2019 15:40:26 +0200 | |
branch | JDK-8226585-branch |
changeset 58290 | d885633d9de4 |
parent 54390 | 3326be37cd9a |
permissions | -rw-r--r-- |
4548 | 1 |
/* |
35807
2eb1d877da0f
8147801: java.nio.file.ClosedFileSystemException when using Javadoc API's in JDK9
jjg
parents:
29780
diff
changeset
|
2 |
* Copyright (c) 2009, 2016, Oracle and/or its affiliates. All rights reserved. |
4548 | 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 |
4548 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5520 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
4548 | 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. |
|
4548 | 24 |
*/ |
25 |
||
29780
8f8e54a1fa20
8076420: Consolidate javac file handling in javac.file package
jjg
parents:
29291
diff
changeset
|
26 |
package com.sun.tools.javac.file; |
4548 | 27 |
|
28 |
import java.io.IOException; |
|
29 |
import java.io.InputStream; |
|
30 |
import java.lang.ref.SoftReference; |
|
31 |
import java.lang.reflect.Constructor; |
|
42407
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41637
diff
changeset
|
32 |
import java.lang.reflect.InvocationTargetException; |
36526 | 33 |
import java.lang.reflect.Method; |
4548 | 34 |
import java.net.URL; |
35 |
import java.net.URLClassLoader; |
|
36 |
import java.nio.ByteBuffer; |
|
37 |
import java.nio.CharBuffer; |
|
38 |
import java.nio.charset.Charset; |
|
39 |
import java.nio.charset.CharsetDecoder; |
|
40 |
import java.nio.charset.CoderResult; |
|
41 |
import java.nio.charset.CodingErrorAction; |
|
42 |
import java.nio.charset.IllegalCharsetNameException; |
|
43 |
import java.nio.charset.UnsupportedCharsetException; |
|
27579 | 44 |
import java.nio.file.Path; |
4548 | 45 |
import java.util.Collection; |
46 |
import java.util.HashMap; |
|
58290 | 47 |
import java.util.HashSet; |
4548 | 48 |
import java.util.Iterator; |
49 |
import java.util.Map; |
|
29291
076c277565f7
8073550: java* tools: replace obj.getClass hacks with Assert.checkNonNull or Objects.requireNonNull
mcimadamore
parents:
27579
diff
changeset
|
50 |
import java.util.Objects; |
11314 | 51 |
import java.util.Set; |
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
52 |
|
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
53 |
import javax.tools.JavaFileManager; |
4548 | 54 |
import javax.tools.JavaFileObject; |
55 |
import javax.tools.JavaFileObject.Kind; |
|
56 |
||
11314 | 57 |
import com.sun.tools.javac.main.Option; |
58 |
import com.sun.tools.javac.main.OptionHelper; |
|
59 |
import com.sun.tools.javac.main.OptionHelper.GrumpyHelper; |
|
36526 | 60 |
import com.sun.tools.javac.resources.CompilerProperties.Errors; |
61 |
import com.sun.tools.javac.util.Abort; |
|
29780
8f8e54a1fa20
8076420: Consolidate javac file handling in javac.file package
jjg
parents:
29291
diff
changeset
|
62 |
import com.sun.tools.javac.util.Context; |
8f8e54a1fa20
8076420: Consolidate javac file handling in javac.file package
jjg
parents:
29291
diff
changeset
|
63 |
import com.sun.tools.javac.util.DefinedBy; |
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
64 |
import com.sun.tools.javac.util.DefinedBy.Api; |
29780
8f8e54a1fa20
8076420: Consolidate javac file handling in javac.file package
jjg
parents:
29291
diff
changeset
|
65 |
import com.sun.tools.javac.util.Log; |
8f8e54a1fa20
8076420: Consolidate javac file handling in javac.file package
jjg
parents:
29291
diff
changeset
|
66 |
import com.sun.tools.javac.util.Options; |
10813
95b39a692cd0
7101146: Paths should more directly managed by BaseFileManager
jjg
parents:
10461
diff
changeset
|
67 |
|
4548 | 68 |
/** |
69 |
* Utility methods for building a filemanager. |
|
70 |
* There are no references here to file-system specific objects such as |
|
71 |
* java.io.File or java.nio.file.Path. |
|
72 |
*/ |
|
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
73 |
public abstract class BaseFileManager implements JavaFileManager { |
4548 | 74 |
protected BaseFileManager(Charset charset) { |
75 |
this.charset = charset; |
|
76 |
byteBufferCache = new ByteBufferCache(); |
|
10818 | 77 |
locations = createLocations(); |
4548 | 78 |
} |
79 |
||
80 |
/** |
|
81 |
* Set the context for JavacPathFileManager. |
|
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
82 |
* @param context the context containing items to be associated with the file manager |
4548 | 83 |
*/ |
10813
95b39a692cd0
7101146: Paths should more directly managed by BaseFileManager
jjg
parents:
10461
diff
changeset
|
84 |
public void setContext(Context context) { |
4548 | 85 |
log = Log.instance(context); |
86 |
options = Options.instance(context); |
|
87 |
classLoaderClass = options.get("procloader"); |
|
41637 | 88 |
|
89 |
// Avoid initializing Lint |
|
90 |
boolean warn = options.isLintSet("path"); |
|
91 |
locations.update(log, warn, FSInfo.instance(context)); |
|
35807
2eb1d877da0f
8147801: java.nio.file.ClosedFileSystemException when using Javadoc API's in JDK9
jjg
parents:
29780
diff
changeset
|
92 |
|
2eb1d877da0f
8147801: java.nio.file.ClosedFileSystemException when using Javadoc API's in JDK9
jjg
parents:
29780
diff
changeset
|
93 |
// Setting this option is an indication that close() should defer actually closing |
2eb1d877da0f
8147801: java.nio.file.ClosedFileSystemException when using Javadoc API's in JDK9
jjg
parents:
29780
diff
changeset
|
94 |
// the file manager until after a specified period of inactivity. |
2eb1d877da0f
8147801: java.nio.file.ClosedFileSystemException when using Javadoc API's in JDK9
jjg
parents:
29780
diff
changeset
|
95 |
// This is to accomodate clients which save references to Symbols created for use |
2eb1d877da0f
8147801: java.nio.file.ClosedFileSystemException when using Javadoc API's in JDK9
jjg
parents:
29780
diff
changeset
|
96 |
// within doclets or annotation processors, and which then attempt to use those |
2eb1d877da0f
8147801: java.nio.file.ClosedFileSystemException when using Javadoc API's in JDK9
jjg
parents:
29780
diff
changeset
|
97 |
// references after the tool exits, having closed any internally managed file manager. |
2eb1d877da0f
8147801: java.nio.file.ClosedFileSystemException when using Javadoc API's in JDK9
jjg
parents:
29780
diff
changeset
|
98 |
// Ideally, such clients should run the tool via the javax.tools API, providing their |
2eb1d877da0f
8147801: java.nio.file.ClosedFileSystemException when using Javadoc API's in JDK9
jjg
parents:
29780
diff
changeset
|
99 |
// own file manager, which can be closed by the client when all use of that file |
2eb1d877da0f
8147801: java.nio.file.ClosedFileSystemException when using Javadoc API's in JDK9
jjg
parents:
29780
diff
changeset
|
100 |
// manager is complete. |
2eb1d877da0f
8147801: java.nio.file.ClosedFileSystemException when using Javadoc API's in JDK9
jjg
parents:
29780
diff
changeset
|
101 |
// If the option has a numeric value, it will be interpreted as the duration, |
2eb1d877da0f
8147801: java.nio.file.ClosedFileSystemException when using Javadoc API's in JDK9
jjg
parents:
29780
diff
changeset
|
102 |
// in seconds, of the period of inactivity to wait for, before the file manager |
2eb1d877da0f
8147801: java.nio.file.ClosedFileSystemException when using Javadoc API's in JDK9
jjg
parents:
29780
diff
changeset
|
103 |
// is actually closed. |
2eb1d877da0f
8147801: java.nio.file.ClosedFileSystemException when using Javadoc API's in JDK9
jjg
parents:
29780
diff
changeset
|
104 |
// See also deferredClose(). |
2eb1d877da0f
8147801: java.nio.file.ClosedFileSystemException when using Javadoc API's in JDK9
jjg
parents:
29780
diff
changeset
|
105 |
String s = options.get("fileManager.deferClose"); |
2eb1d877da0f
8147801: java.nio.file.ClosedFileSystemException when using Javadoc API's in JDK9
jjg
parents:
29780
diff
changeset
|
106 |
if (s != null) { |
2eb1d877da0f
8147801: java.nio.file.ClosedFileSystemException when using Javadoc API's in JDK9
jjg
parents:
29780
diff
changeset
|
107 |
try { |
2eb1d877da0f
8147801: java.nio.file.ClosedFileSystemException when using Javadoc API's in JDK9
jjg
parents:
29780
diff
changeset
|
108 |
deferredCloseTimeout = (int) (Float.parseFloat(s) * 1000); |
2eb1d877da0f
8147801: java.nio.file.ClosedFileSystemException when using Javadoc API's in JDK9
jjg
parents:
29780
diff
changeset
|
109 |
} catch (NumberFormatException e) { |
2eb1d877da0f
8147801: java.nio.file.ClosedFileSystemException when using Javadoc API's in JDK9
jjg
parents:
29780
diff
changeset
|
110 |
deferredCloseTimeout = 60 * 1000; // default: one minute, in millis |
2eb1d877da0f
8147801: java.nio.file.ClosedFileSystemException when using Javadoc API's in JDK9
jjg
parents:
29780
diff
changeset
|
111 |
} |
2eb1d877da0f
8147801: java.nio.file.ClosedFileSystemException when using Javadoc API's in JDK9
jjg
parents:
29780
diff
changeset
|
112 |
} |
10813
95b39a692cd0
7101146: Paths should more directly managed by BaseFileManager
jjg
parents:
10461
diff
changeset
|
113 |
} |
95b39a692cd0
7101146: Paths should more directly managed by BaseFileManager
jjg
parents:
10461
diff
changeset
|
114 |
|
10818 | 115 |
protected Locations createLocations() { |
116 |
return new Locations(); |
|
4548 | 117 |
} |
118 |
||
119 |
/** |
|
120 |
* The log to be used for error reporting. |
|
121 |
*/ |
|
122 |
public Log log; |
|
123 |
||
124 |
/** |
|
125 |
* User provided charset (through javax.tools). |
|
126 |
*/ |
|
127 |
protected Charset charset; |
|
128 |
||
129 |
protected Options options; |
|
130 |
||
131 |
protected String classLoaderClass; |
|
132 |
||
42407
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41637
diff
changeset
|
133 |
protected final Locations locations; |
10813
95b39a692cd0
7101146: Paths should more directly managed by BaseFileManager
jjg
parents:
10461
diff
changeset
|
134 |
|
27379
5ae894733e09
8062579: JavacTask, DocumentationTask impls should close file manager when possible
jjg
parents:
27318
diff
changeset
|
135 |
/** |
5ae894733e09
8062579: JavacTask, DocumentationTask impls should close file manager when possible
jjg
parents:
27318
diff
changeset
|
136 |
* A flag for clients to use to indicate that this file manager should |
5ae894733e09
8062579: JavacTask, DocumentationTask impls should close file manager when possible
jjg
parents:
27318
diff
changeset
|
137 |
* be closed when it is no longer required. |
5ae894733e09
8062579: JavacTask, DocumentationTask impls should close file manager when possible
jjg
parents:
27318
diff
changeset
|
138 |
*/ |
5ae894733e09
8062579: JavacTask, DocumentationTask impls should close file manager when possible
jjg
parents:
27318
diff
changeset
|
139 |
public boolean autoClose; |
5ae894733e09
8062579: JavacTask, DocumentationTask impls should close file manager when possible
jjg
parents:
27318
diff
changeset
|
140 |
|
35807
2eb1d877da0f
8147801: java.nio.file.ClosedFileSystemException when using Javadoc API's in JDK9
jjg
parents:
29780
diff
changeset
|
141 |
/** |
2eb1d877da0f
8147801: java.nio.file.ClosedFileSystemException when using Javadoc API's in JDK9
jjg
parents:
29780
diff
changeset
|
142 |
* Wait for a period of inactivity before calling close(). |
2eb1d877da0f
8147801: java.nio.file.ClosedFileSystemException when using Javadoc API's in JDK9
jjg
parents:
29780
diff
changeset
|
143 |
* The length of the period of inactivity is given by {@code deferredCloseTimeout} |
2eb1d877da0f
8147801: java.nio.file.ClosedFileSystemException when using Javadoc API's in JDK9
jjg
parents:
29780
diff
changeset
|
144 |
*/ |
2eb1d877da0f
8147801: java.nio.file.ClosedFileSystemException when using Javadoc API's in JDK9
jjg
parents:
29780
diff
changeset
|
145 |
protected void deferredClose() { |
2eb1d877da0f
8147801: java.nio.file.ClosedFileSystemException when using Javadoc API's in JDK9
jjg
parents:
29780
diff
changeset
|
146 |
Thread t = new Thread(getClass().getName() + " DeferredClose") { |
2eb1d877da0f
8147801: java.nio.file.ClosedFileSystemException when using Javadoc API's in JDK9
jjg
parents:
29780
diff
changeset
|
147 |
@Override |
2eb1d877da0f
8147801: java.nio.file.ClosedFileSystemException when using Javadoc API's in JDK9
jjg
parents:
29780
diff
changeset
|
148 |
public void run() { |
2eb1d877da0f
8147801: java.nio.file.ClosedFileSystemException when using Javadoc API's in JDK9
jjg
parents:
29780
diff
changeset
|
149 |
try { |
2eb1d877da0f
8147801: java.nio.file.ClosedFileSystemException when using Javadoc API's in JDK9
jjg
parents:
29780
diff
changeset
|
150 |
synchronized (BaseFileManager.this) { |
2eb1d877da0f
8147801: java.nio.file.ClosedFileSystemException when using Javadoc API's in JDK9
jjg
parents:
29780
diff
changeset
|
151 |
long now = System.currentTimeMillis(); |
2eb1d877da0f
8147801: java.nio.file.ClosedFileSystemException when using Javadoc API's in JDK9
jjg
parents:
29780
diff
changeset
|
152 |
while (now < lastUsedTime + deferredCloseTimeout) { |
2eb1d877da0f
8147801: java.nio.file.ClosedFileSystemException when using Javadoc API's in JDK9
jjg
parents:
29780
diff
changeset
|
153 |
BaseFileManager.this.wait(lastUsedTime + deferredCloseTimeout - now); |
2eb1d877da0f
8147801: java.nio.file.ClosedFileSystemException when using Javadoc API's in JDK9
jjg
parents:
29780
diff
changeset
|
154 |
now = System.currentTimeMillis(); |
2eb1d877da0f
8147801: java.nio.file.ClosedFileSystemException when using Javadoc API's in JDK9
jjg
parents:
29780
diff
changeset
|
155 |
} |
2eb1d877da0f
8147801: java.nio.file.ClosedFileSystemException when using Javadoc API's in JDK9
jjg
parents:
29780
diff
changeset
|
156 |
deferredCloseTimeout = 0; |
2eb1d877da0f
8147801: java.nio.file.ClosedFileSystemException when using Javadoc API's in JDK9
jjg
parents:
29780
diff
changeset
|
157 |
close(); |
2eb1d877da0f
8147801: java.nio.file.ClosedFileSystemException when using Javadoc API's in JDK9
jjg
parents:
29780
diff
changeset
|
158 |
} |
2eb1d877da0f
8147801: java.nio.file.ClosedFileSystemException when using Javadoc API's in JDK9
jjg
parents:
29780
diff
changeset
|
159 |
} catch (InterruptedException e) { |
2eb1d877da0f
8147801: java.nio.file.ClosedFileSystemException when using Javadoc API's in JDK9
jjg
parents:
29780
diff
changeset
|
160 |
} catch (IOException e) { |
2eb1d877da0f
8147801: java.nio.file.ClosedFileSystemException when using Javadoc API's in JDK9
jjg
parents:
29780
diff
changeset
|
161 |
} |
2eb1d877da0f
8147801: java.nio.file.ClosedFileSystemException when using Javadoc API's in JDK9
jjg
parents:
29780
diff
changeset
|
162 |
} |
2eb1d877da0f
8147801: java.nio.file.ClosedFileSystemException when using Javadoc API's in JDK9
jjg
parents:
29780
diff
changeset
|
163 |
}; |
2eb1d877da0f
8147801: java.nio.file.ClosedFileSystemException when using Javadoc API's in JDK9
jjg
parents:
29780
diff
changeset
|
164 |
t.setDaemon(true); |
2eb1d877da0f
8147801: java.nio.file.ClosedFileSystemException when using Javadoc API's in JDK9
jjg
parents:
29780
diff
changeset
|
165 |
t.start(); |
2eb1d877da0f
8147801: java.nio.file.ClosedFileSystemException when using Javadoc API's in JDK9
jjg
parents:
29780
diff
changeset
|
166 |
} |
2eb1d877da0f
8147801: java.nio.file.ClosedFileSystemException when using Javadoc API's in JDK9
jjg
parents:
29780
diff
changeset
|
167 |
|
2eb1d877da0f
8147801: java.nio.file.ClosedFileSystemException when using Javadoc API's in JDK9
jjg
parents:
29780
diff
changeset
|
168 |
synchronized void updateLastUsedTime() { |
2eb1d877da0f
8147801: java.nio.file.ClosedFileSystemException when using Javadoc API's in JDK9
jjg
parents:
29780
diff
changeset
|
169 |
if (deferredCloseTimeout > 0) { // avoid updating the time unnecessarily |
2eb1d877da0f
8147801: java.nio.file.ClosedFileSystemException when using Javadoc API's in JDK9
jjg
parents:
29780
diff
changeset
|
170 |
lastUsedTime = System.currentTimeMillis(); |
2eb1d877da0f
8147801: java.nio.file.ClosedFileSystemException when using Javadoc API's in JDK9
jjg
parents:
29780
diff
changeset
|
171 |
} |
2eb1d877da0f
8147801: java.nio.file.ClosedFileSystemException when using Javadoc API's in JDK9
jjg
parents:
29780
diff
changeset
|
172 |
} |
2eb1d877da0f
8147801: java.nio.file.ClosedFileSystemException when using Javadoc API's in JDK9
jjg
parents:
29780
diff
changeset
|
173 |
|
2eb1d877da0f
8147801: java.nio.file.ClosedFileSystemException when using Javadoc API's in JDK9
jjg
parents:
29780
diff
changeset
|
174 |
private long lastUsedTime = System.currentTimeMillis(); |
2eb1d877da0f
8147801: java.nio.file.ClosedFileSystemException when using Javadoc API's in JDK9
jjg
parents:
29780
diff
changeset
|
175 |
protected long deferredCloseTimeout = 0; |
2eb1d877da0f
8147801: java.nio.file.ClosedFileSystemException when using Javadoc API's in JDK9
jjg
parents:
29780
diff
changeset
|
176 |
|
58290 | 177 |
public void clear() { |
178 |
new HashSet<>(options.keySet()).forEach(k -> options.remove(k)); |
|
179 |
} |
|
180 |
||
4548 | 181 |
protected ClassLoader getClassLoader(URL[] urls) { |
182 |
ClassLoader thisClassLoader = getClass().getClassLoader(); |
|
183 |
||
16796
53060909017b
7059170: Assume availablility of URLClassLoader.close
darcy
parents:
14801
diff
changeset
|
184 |
// Allow the following to specify a closeable classloader |
53060909017b
7059170: Assume availablility of URLClassLoader.close
darcy
parents:
14801
diff
changeset
|
185 |
// other than URLClassLoader. |
4548 | 186 |
|
187 |
// 1: Allow client to specify the class to use via hidden option |
|
188 |
if (classLoaderClass != null) { |
|
189 |
try { |
|
190 |
Class<? extends ClassLoader> loader = |
|
191 |
Class.forName(classLoaderClass).asSubclass(ClassLoader.class); |
|
192 |
Class<?>[] constrArgTypes = { URL[].class, ClassLoader.class }; |
|
193 |
Constructor<? extends ClassLoader> constr = loader.getConstructor(constrArgTypes); |
|
44458
cf6145299178
8175116: jtreg agentvms uses more virtual address space in langtool/test :tier1 runs
redestad
parents:
42408
diff
changeset
|
194 |
return constr.newInstance(urls, thisClassLoader); |
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
195 |
} catch (ReflectiveOperationException t) { |
4548 | 196 |
// ignore errors loading user-provided class loader, fall through |
197 |
} |
|
198 |
} |
|
44458
cf6145299178
8175116: jtreg agentvms uses more virtual address space in langtool/test :tier1 runs
redestad
parents:
42408
diff
changeset
|
199 |
return new URLClassLoader(urls, thisClassLoader); |
4548 | 200 |
} |
201 |
||
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
202 |
public boolean isDefaultBootClassPath() { |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
203 |
return locations.isDefaultBootClassPath(); |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
204 |
} |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
205 |
|
4548 | 206 |
// <editor-fold defaultstate="collapsed" desc="Option handling"> |
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
207 |
@Override @DefinedBy(Api.COMPILER) |
4548 | 208 |
public boolean handleOption(String current, Iterator<String> remaining) { |
11314 | 209 |
OptionHelper helper = new GrumpyHelper(log) { |
210 |
@Override |
|
211 |
public String get(Option option) { |
|
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
39362
diff
changeset
|
212 |
return options.get(option); |
11314 | 213 |
} |
214 |
||
215 |
@Override |
|
216 |
public void put(String name, String value) { |
|
217 |
options.put(name, value); |
|
218 |
} |
|
219 |
||
220 |
@Override |
|
221 |
public void remove(String name) { |
|
222 |
options.remove(name); |
|
223 |
} |
|
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
224 |
|
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
225 |
@Override |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
226 |
public boolean handleFileManagerOption(Option option, String value) { |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
227 |
return handleOption(option, value); |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
228 |
} |
11314 | 229 |
}; |
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
230 |
|
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
39362
diff
changeset
|
231 |
Option o = Option.lookup(current, javacFileManagerOptions); |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
39362
diff
changeset
|
232 |
if (o == null) { |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
39362
diff
changeset
|
233 |
return false; |
4548 | 234 |
} |
235 |
||
42260
2b4da2bf6660
8169676: boolean result of Option.process is often ignored
jjg
parents:
41637
diff
changeset
|
236 |
try { |
2b4da2bf6660
8169676: boolean result of Option.process is often ignored
jjg
parents:
41637
diff
changeset
|
237 |
o.handleOption(helper, current, remaining); |
2b4da2bf6660
8169676: boolean result of Option.process is often ignored
jjg
parents:
41637
diff
changeset
|
238 |
} catch (Option.InvalidValueException e) { |
2b4da2bf6660
8169676: boolean result of Option.process is often ignored
jjg
parents:
41637
diff
changeset
|
239 |
throw new IllegalArgumentException(e.getMessage(), e); |
2b4da2bf6660
8169676: boolean result of Option.process is often ignored
jjg
parents:
41637
diff
changeset
|
240 |
} |
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
39362
diff
changeset
|
241 |
|
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
39362
diff
changeset
|
242 |
return true; |
4548 | 243 |
} |
244 |
// where |
|
54390
3326be37cd9a
8220792: Performance bottleneck in JavacFileManager.list()
ronsh
parents:
47446
diff
changeset
|
245 |
protected static final Set<Option> javacFileManagerOptions = |
11314 | 246 |
Option.getJavacFileManagerOptions(); |
4548 | 247 |
|
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
248 |
@Override @DefinedBy(Api.COMPILER) |
4548 | 249 |
public int isSupportedOption(String option) { |
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
39362
diff
changeset
|
250 |
Option o = Option.lookup(option, javacFileManagerOptions); |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
39362
diff
changeset
|
251 |
return (o == null) ? -1 : o.hasArg() ? 1 : 0; |
4548 | 252 |
} |
7335
8b390fd27190
6900037: javac should warn if earlier -source is used and bootclasspath not set
jjg
parents:
5520
diff
changeset
|
253 |
|
37394
c36230ee15d9
8149757: Implement Multi-Release JAR aware JavacFileManager for javac
jjg
parents:
36526
diff
changeset
|
254 |
protected String multiReleaseValue; |
c36230ee15d9
8149757: Implement Multi-Release JAR aware JavacFileManager for javac
jjg
parents:
36526
diff
changeset
|
255 |
|
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
256 |
/** |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
257 |
* Common back end for OptionHelper handleFileManagerOption. |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
258 |
* @param option the option whose value to be set |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
259 |
* @param value the value for the option |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
260 |
* @return true if successful, and false otherwise |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
261 |
*/ |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
262 |
public boolean handleOption(Option option, String value) { |
36155
1555ce1fcb4f
8149772: cleanup handling of -encoding in JavacFileManager
jjg
parents:
35807
diff
changeset
|
263 |
switch (option) { |
1555ce1fcb4f
8149772: cleanup handling of -encoding in JavacFileManager
jjg
parents:
35807
diff
changeset
|
264 |
case ENCODING: |
1555ce1fcb4f
8149772: cleanup handling of -encoding in JavacFileManager
jjg
parents:
35807
diff
changeset
|
265 |
encodingName = value; |
1555ce1fcb4f
8149772: cleanup handling of -encoding in JavacFileManager
jjg
parents:
35807
diff
changeset
|
266 |
return true; |
1555ce1fcb4f
8149772: cleanup handling of -encoding in JavacFileManager
jjg
parents:
35807
diff
changeset
|
267 |
|
37394
c36230ee15d9
8149757: Implement Multi-Release JAR aware JavacFileManager for javac
jjg
parents:
36526
diff
changeset
|
268 |
case MULTIRELEASE: |
c36230ee15d9
8149757: Implement Multi-Release JAR aware JavacFileManager for javac
jjg
parents:
36526
diff
changeset
|
269 |
multiReleaseValue = value; |
41155
93dad90c22c1
8156568: Update javac to support compiling against a modular JAR that is a multi-release JAR
sadayapalam
parents:
40308
diff
changeset
|
270 |
locations.setMultiReleaseValue(value); |
37394
c36230ee15d9
8149757: Implement Multi-Release JAR aware JavacFileManager for javac
jjg
parents:
36526
diff
changeset
|
271 |
return true; |
c36230ee15d9
8149757: Implement Multi-Release JAR aware JavacFileManager for javac
jjg
parents:
36526
diff
changeset
|
272 |
|
36155
1555ce1fcb4f
8149772: cleanup handling of -encoding in JavacFileManager
jjg
parents:
35807
diff
changeset
|
273 |
default: |
1555ce1fcb4f
8149772: cleanup handling of -encoding in JavacFileManager
jjg
parents:
35807
diff
changeset
|
274 |
return locations.handleOption(option, value); |
1555ce1fcb4f
8149772: cleanup handling of -encoding in JavacFileManager
jjg
parents:
35807
diff
changeset
|
275 |
} |
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
276 |
} |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
277 |
|
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
278 |
/** |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
279 |
* Call handleOption for collection of options and corresponding values. |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
280 |
* @param map a collection of options and corresponding values |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
281 |
* @return true if all the calls are successful |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
282 |
*/ |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
283 |
public boolean handleOptions(Map<Option, String> map) { |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
284 |
boolean ok = true; |
36526 | 285 |
for (Map.Entry<Option, String> e: map.entrySet()) { |
286 |
try { |
|
287 |
ok = ok & handleOption(e.getKey(), e.getValue()); |
|
288 |
} catch (IllegalArgumentException ex) { |
|
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
39362
diff
changeset
|
289 |
log.error(Errors.IllegalArgumentForOption(e.getKey().getPrimaryName(), ex.getMessage())); |
36526 | 290 |
ok = false; |
291 |
} |
|
292 |
} |
|
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
293 |
return ok; |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
294 |
} |
7335
8b390fd27190
6900037: javac should warn if earlier -source is used and bootclasspath not set
jjg
parents:
5520
diff
changeset
|
295 |
|
4548 | 296 |
// </editor-fold> |
297 |
||
298 |
// <editor-fold defaultstate="collapsed" desc="Encoding"> |
|
36155
1555ce1fcb4f
8149772: cleanup handling of -encoding in JavacFileManager
jjg
parents:
35807
diff
changeset
|
299 |
private String encodingName; |
4548 | 300 |
private String defaultEncodingName; |
301 |
private String getDefaultEncodingName() { |
|
302 |
if (defaultEncodingName == null) { |
|
39362
5ac5af2acb57
8132857: Historical name of default encoding shown on encoding mismatch
jlahoda
parents:
38511
diff
changeset
|
303 |
defaultEncodingName = Charset.defaultCharset().name(); |
4548 | 304 |
} |
305 |
return defaultEncodingName; |
|
306 |
} |
|
307 |
||
308 |
public String getEncodingName() { |
|
36155
1555ce1fcb4f
8149772: cleanup handling of -encoding in JavacFileManager
jjg
parents:
35807
diff
changeset
|
309 |
return (encodingName != null) ? encodingName : getDefaultEncodingName(); |
4548 | 310 |
} |
311 |
||
312 |
public CharBuffer decode(ByteBuffer inbuf, boolean ignoreEncodingErrors) { |
|
42407
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41637
diff
changeset
|
313 |
String encName = getEncodingName(); |
4548 | 314 |
CharsetDecoder decoder; |
315 |
try { |
|
42407
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41637
diff
changeset
|
316 |
decoder = getDecoder(encName, ignoreEncodingErrors); |
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
317 |
} catch (IllegalCharsetNameException | UnsupportedCharsetException e) { |
45504
ea7475564d07
8170326: Inconsistencies between code, compiler.properties and comments
jlahoda
parents:
44458
diff
changeset
|
318 |
log.error(Errors.UnsupportedEncoding(encName)); |
47446
fd458b0b7749
8062385: Remove @SuppressWarnings("cast") and casts for NIO related usages when JDK 9 becomes the bootstrap JDK
darcy
parents:
47216
diff
changeset
|
319 |
return CharBuffer.allocate(1).flip(); |
4548 | 320 |
} |
321 |
||
322 |
// slightly overestimate the buffer size to avoid reallocation. |
|
323 |
float factor = |
|
324 |
decoder.averageCharsPerByte() * 0.8f + |
|
325 |
decoder.maxCharsPerByte() * 0.2f; |
|
326 |
CharBuffer dest = CharBuffer. |
|
327 |
allocate(10 + (int)(inbuf.remaining()*factor)); |
|
328 |
||
329 |
while (true) { |
|
330 |
CoderResult result = decoder.decode(inbuf, dest, true); |
|
331 |
dest.flip(); |
|
332 |
||
333 |
if (result.isUnderflow()) { // done reading |
|
334 |
// make sure there is at least one extra character |
|
335 |
if (dest.limit() == dest.capacity()) { |
|
336 |
dest = CharBuffer.allocate(dest.capacity()+1).put(dest); |
|
337 |
dest.flip(); |
|
338 |
} |
|
339 |
return dest; |
|
340 |
} else if (result.isOverflow()) { // buffer too small; expand |
|
341 |
int newCapacity = |
|
342 |
10 + dest.capacity() + |
|
343 |
(int)(inbuf.remaining()*decoder.maxCharsPerByte()); |
|
344 |
dest = CharBuffer.allocate(newCapacity).put(dest); |
|
345 |
} else if (result.isMalformed() || result.isUnmappable()) { |
|
346 |
// bad character in input |
|
38511
d934635453ad
8078559: Update error message to indicate illegal character when encoding set to ascii
jlahoda
parents:
37394
diff
changeset
|
347 |
StringBuilder unmappable = new StringBuilder(); |
d934635453ad
8078559: Update error message to indicate illegal character when encoding set to ascii
jlahoda
parents:
37394
diff
changeset
|
348 |
int len = result.length(); |
4548 | 349 |
|
38511
d934635453ad
8078559: Update error message to indicate illegal character when encoding set to ascii
jlahoda
parents:
37394
diff
changeset
|
350 |
for (int i = 0; i < len; i++) { |
d934635453ad
8078559: Update error message to indicate illegal character when encoding set to ascii
jlahoda
parents:
37394
diff
changeset
|
351 |
unmappable.append(String.format("%02X", inbuf.get())); |
d934635453ad
8078559: Update error message to indicate illegal character when encoding set to ascii
jlahoda
parents:
37394
diff
changeset
|
352 |
} |
4548 | 353 |
|
42407
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41637
diff
changeset
|
354 |
String charsetName = charset == null ? encName : charset.name(); |
38511
d934635453ad
8078559: Update error message to indicate illegal character when encoding set to ascii
jlahoda
parents:
37394
diff
changeset
|
355 |
|
d934635453ad
8078559: Update error message to indicate illegal character when encoding set to ascii
jlahoda
parents:
37394
diff
changeset
|
356 |
log.error(dest.limit(), |
d934635453ad
8078559: Update error message to indicate illegal character when encoding set to ascii
jlahoda
parents:
37394
diff
changeset
|
357 |
Errors.IllegalCharForEncoding(unmappable.toString(), charsetName)); |
4548 | 358 |
|
359 |
// undo the flip() to prepare the output buffer |
|
360 |
// for more translation |
|
361 |
dest.position(dest.limit()); |
|
362 |
dest.limit(dest.capacity()); |
|
363 |
dest.put((char)0xfffd); // backward compatible |
|
364 |
} else { |
|
365 |
throw new AssertionError(result); |
|
366 |
} |
|
367 |
} |
|
368 |
// unreached |
|
369 |
} |
|
370 |
||
371 |
public CharsetDecoder getDecoder(String encodingName, boolean ignoreEncodingErrors) { |
|
372 |
Charset cs = (this.charset == null) |
|
373 |
? Charset.forName(encodingName) |
|
374 |
: this.charset; |
|
375 |
CharsetDecoder decoder = cs.newDecoder(); |
|
376 |
||
377 |
CodingErrorAction action; |
|
378 |
if (ignoreEncodingErrors) |
|
379 |
action = CodingErrorAction.REPLACE; |
|
380 |
else |
|
381 |
action = CodingErrorAction.REPORT; |
|
382 |
||
383 |
return decoder |
|
384 |
.onMalformedInput(action) |
|
385 |
.onUnmappableCharacter(action); |
|
386 |
} |
|
387 |
// </editor-fold> |
|
388 |
||
389 |
// <editor-fold defaultstate="collapsed" desc="ByteBuffers"> |
|
390 |
/** |
|
391 |
* Make a byte buffer from an input stream. |
|
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
392 |
* @param in the stream |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
393 |
* @return a byte buffer containing the contents of the stream |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
394 |
* @throws IOException if an error occurred while reading the stream |
4548 | 395 |
*/ |
396 |
public ByteBuffer makeByteBuffer(InputStream in) |
|
397 |
throws IOException { |
|
398 |
int limit = in.available(); |
|
399 |
if (limit < 1024) limit = 1024; |
|
400 |
ByteBuffer result = byteBufferCache.get(limit); |
|
401 |
int position = 0; |
|
402 |
while (in.available() != 0) { |
|
403 |
if (position >= limit) |
|
404 |
// expand buffer |
|
405 |
result = ByteBuffer. |
|
406 |
allocate(limit <<= 1). |
|
47446
fd458b0b7749
8062385: Remove @SuppressWarnings("cast") and casts for NIO related usages when JDK 9 becomes the bootstrap JDK
darcy
parents:
47216
diff
changeset
|
407 |
put(result.flip()); |
4548 | 408 |
int count = in.read(result.array(), |
409 |
position, |
|
410 |
limit - position); |
|
411 |
if (count < 0) break; |
|
412 |
result.position(position += count); |
|
413 |
} |
|
47446
fd458b0b7749
8062385: Remove @SuppressWarnings("cast") and casts for NIO related usages when JDK 9 becomes the bootstrap JDK
darcy
parents:
47216
diff
changeset
|
414 |
return result.flip(); |
4548 | 415 |
} |
416 |
||
417 |
public void recycleByteBuffer(ByteBuffer bb) { |
|
418 |
byteBufferCache.put(bb); |
|
419 |
} |
|
420 |
||
421 |
/** |
|
422 |
* A single-element cache of direct byte buffers. |
|
423 |
*/ |
|
424 |
private static class ByteBufferCache { |
|
425 |
private ByteBuffer cached; |
|
426 |
ByteBuffer get(int capacity) { |
|
427 |
if (capacity < 20480) capacity = 20480; |
|
428 |
ByteBuffer result = |
|
429 |
(cached != null && cached.capacity() >= capacity) |
|
47446
fd458b0b7749
8062385: Remove @SuppressWarnings("cast") and casts for NIO related usages when JDK 9 becomes the bootstrap JDK
darcy
parents:
47216
diff
changeset
|
430 |
? cached.clear() |
4548 | 431 |
: ByteBuffer.allocate(capacity + capacity>>1); |
432 |
cached = null; |
|
433 |
return result; |
|
434 |
} |
|
435 |
void put(ByteBuffer x) { |
|
436 |
cached = x; |
|
437 |
} |
|
438 |
} |
|
439 |
||
440 |
private final ByteBufferCache byteBufferCache; |
|
441 |
// </editor-fold> |
|
442 |
||
443 |
// <editor-fold defaultstate="collapsed" desc="Content cache"> |
|
444 |
public CharBuffer getCachedContent(JavaFileObject file) { |
|
10461
998e642f9811
7068451: Regression: javac compiles fixed sources against previous, not current, version of generated sources
jjg
parents:
7681
diff
changeset
|
445 |
ContentCacheEntry e = contentCache.get(file); |
998e642f9811
7068451: Regression: javac compiles fixed sources against previous, not current, version of generated sources
jjg
parents:
7681
diff
changeset
|
446 |
if (e == null) |
998e642f9811
7068451: Regression: javac compiles fixed sources against previous, not current, version of generated sources
jjg
parents:
7681
diff
changeset
|
447 |
return null; |
998e642f9811
7068451: Regression: javac compiles fixed sources against previous, not current, version of generated sources
jjg
parents:
7681
diff
changeset
|
448 |
|
998e642f9811
7068451: Regression: javac compiles fixed sources against previous, not current, version of generated sources
jjg
parents:
7681
diff
changeset
|
449 |
if (!e.isValid(file)) { |
998e642f9811
7068451: Regression: javac compiles fixed sources against previous, not current, version of generated sources
jjg
parents:
7681
diff
changeset
|
450 |
contentCache.remove(file); |
998e642f9811
7068451: Regression: javac compiles fixed sources against previous, not current, version of generated sources
jjg
parents:
7681
diff
changeset
|
451 |
return null; |
998e642f9811
7068451: Regression: javac compiles fixed sources against previous, not current, version of generated sources
jjg
parents:
7681
diff
changeset
|
452 |
} |
998e642f9811
7068451: Regression: javac compiles fixed sources against previous, not current, version of generated sources
jjg
parents:
7681
diff
changeset
|
453 |
|
998e642f9811
7068451: Regression: javac compiles fixed sources against previous, not current, version of generated sources
jjg
parents:
7681
diff
changeset
|
454 |
return e.getValue(); |
4548 | 455 |
} |
456 |
||
457 |
public void cache(JavaFileObject file, CharBuffer cb) { |
|
10461
998e642f9811
7068451: Regression: javac compiles fixed sources against previous, not current, version of generated sources
jjg
parents:
7681
diff
changeset
|
458 |
contentCache.put(file, new ContentCacheEntry(file, cb)); |
998e642f9811
7068451: Regression: javac compiles fixed sources against previous, not current, version of generated sources
jjg
parents:
7681
diff
changeset
|
459 |
} |
998e642f9811
7068451: Regression: javac compiles fixed sources against previous, not current, version of generated sources
jjg
parents:
7681
diff
changeset
|
460 |
|
998e642f9811
7068451: Regression: javac compiles fixed sources against previous, not current, version of generated sources
jjg
parents:
7681
diff
changeset
|
461 |
public void flushCache(JavaFileObject file) { |
998e642f9811
7068451: Regression: javac compiles fixed sources against previous, not current, version of generated sources
jjg
parents:
7681
diff
changeset
|
462 |
contentCache.remove(file); |
4548 | 463 |
} |
464 |
||
22163 | 465 |
protected final Map<JavaFileObject, ContentCacheEntry> contentCache = new HashMap<>(); |
10461
998e642f9811
7068451: Regression: javac compiles fixed sources against previous, not current, version of generated sources
jjg
parents:
7681
diff
changeset
|
466 |
|
998e642f9811
7068451: Regression: javac compiles fixed sources against previous, not current, version of generated sources
jjg
parents:
7681
diff
changeset
|
467 |
protected static class ContentCacheEntry { |
998e642f9811
7068451: Regression: javac compiles fixed sources against previous, not current, version of generated sources
jjg
parents:
7681
diff
changeset
|
468 |
final long timestamp; |
998e642f9811
7068451: Regression: javac compiles fixed sources against previous, not current, version of generated sources
jjg
parents:
7681
diff
changeset
|
469 |
final SoftReference<CharBuffer> ref; |
998e642f9811
7068451: Regression: javac compiles fixed sources against previous, not current, version of generated sources
jjg
parents:
7681
diff
changeset
|
470 |
|
998e642f9811
7068451: Regression: javac compiles fixed sources against previous, not current, version of generated sources
jjg
parents:
7681
diff
changeset
|
471 |
ContentCacheEntry(JavaFileObject file, CharBuffer cb) { |
998e642f9811
7068451: Regression: javac compiles fixed sources against previous, not current, version of generated sources
jjg
parents:
7681
diff
changeset
|
472 |
this.timestamp = file.getLastModified(); |
22163 | 473 |
this.ref = new SoftReference<>(cb); |
10461
998e642f9811
7068451: Regression: javac compiles fixed sources against previous, not current, version of generated sources
jjg
parents:
7681
diff
changeset
|
474 |
} |
998e642f9811
7068451: Regression: javac compiles fixed sources against previous, not current, version of generated sources
jjg
parents:
7681
diff
changeset
|
475 |
|
998e642f9811
7068451: Regression: javac compiles fixed sources against previous, not current, version of generated sources
jjg
parents:
7681
diff
changeset
|
476 |
boolean isValid(JavaFileObject file) { |
998e642f9811
7068451: Regression: javac compiles fixed sources against previous, not current, version of generated sources
jjg
parents:
7681
diff
changeset
|
477 |
return timestamp == file.getLastModified(); |
998e642f9811
7068451: Regression: javac compiles fixed sources against previous, not current, version of generated sources
jjg
parents:
7681
diff
changeset
|
478 |
} |
998e642f9811
7068451: Regression: javac compiles fixed sources against previous, not current, version of generated sources
jjg
parents:
7681
diff
changeset
|
479 |
|
998e642f9811
7068451: Regression: javac compiles fixed sources against previous, not current, version of generated sources
jjg
parents:
7681
diff
changeset
|
480 |
CharBuffer getValue() { |
998e642f9811
7068451: Regression: javac compiles fixed sources against previous, not current, version of generated sources
jjg
parents:
7681
diff
changeset
|
481 |
return ref.get(); |
998e642f9811
7068451: Regression: javac compiles fixed sources against previous, not current, version of generated sources
jjg
parents:
7681
diff
changeset
|
482 |
} |
998e642f9811
7068451: Regression: javac compiles fixed sources against previous, not current, version of generated sources
jjg
parents:
7681
diff
changeset
|
483 |
} |
4548 | 484 |
// </editor-fold> |
485 |
||
27579 | 486 |
public static Kind getKind(Path path) { |
487 |
return getKind(path.getFileName().toString()); |
|
488 |
} |
|
489 |
||
4548 | 490 |
public static Kind getKind(String name) { |
491 |
if (name.endsWith(Kind.CLASS.extension)) |
|
492 |
return Kind.CLASS; |
|
493 |
else if (name.endsWith(Kind.SOURCE.extension)) |
|
494 |
return Kind.SOURCE; |
|
495 |
else if (name.endsWith(Kind.HTML.extension)) |
|
496 |
return Kind.HTML; |
|
497 |
else |
|
498 |
return Kind.OTHER; |
|
499 |
} |
|
500 |
||
501 |
protected static <T> T nullCheck(T o) { |
|
29291
076c277565f7
8073550: java* tools: replace obj.getClass hacks with Assert.checkNonNull or Objects.requireNonNull
mcimadamore
parents:
27579
diff
changeset
|
502 |
return Objects.requireNonNull(o); |
4548 | 503 |
} |
504 |
||
505 |
protected static <T> Collection<T> nullCheck(Collection<T> it) { |
|
506 |
for (T t : it) |
|
29291
076c277565f7
8073550: java* tools: replace obj.getClass hacks with Assert.checkNonNull or Objects.requireNonNull
mcimadamore
parents:
27579
diff
changeset
|
507 |
Objects.requireNonNull(t); |
4548 | 508 |
return it; |
509 |
} |
|
510 |
} |