author | sadayapalam |
Tue, 20 Sep 2016 12:12:18 +0530 | |
changeset 41155 | 93dad90c22c1 |
parent 40308 | 274367a99f98 |
child 41637 | 7b24b4c32ee6 |
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; |
|
36526 | 32 |
import java.lang.reflect.Method; |
4548 | 33 |
import java.net.URL; |
34 |
import java.net.URLClassLoader; |
|
35 |
import java.nio.ByteBuffer; |
|
36 |
import java.nio.CharBuffer; |
|
37 |
import java.nio.charset.Charset; |
|
38 |
import java.nio.charset.CharsetDecoder; |
|
39 |
import java.nio.charset.CoderResult; |
|
40 |
import java.nio.charset.CodingErrorAction; |
|
41 |
import java.nio.charset.IllegalCharsetNameException; |
|
42 |
import java.nio.charset.UnsupportedCharsetException; |
|
27579 | 43 |
import java.nio.file.Path; |
4548 | 44 |
import java.util.Collection; |
45 |
import java.util.HashMap; |
|
46 |
import java.util.Iterator; |
|
47 |
import java.util.Map; |
|
29291
076c277565f7
8073550: java* tools: replace obj.getClass hacks with Assert.checkNonNull or Objects.requireNonNull
mcimadamore
parents:
27579
diff
changeset
|
48 |
import java.util.Objects; |
11314 | 49 |
import java.util.Set; |
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
50 |
|
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
51 |
import javax.tools.JavaFileManager; |
4548 | 52 |
import javax.tools.JavaFileObject; |
53 |
import javax.tools.JavaFileObject.Kind; |
|
54 |
||
10813
95b39a692cd0
7101146: Paths should more directly managed by BaseFileManager
jjg
parents:
10461
diff
changeset
|
55 |
import com.sun.tools.javac.code.Lint; |
95b39a692cd0
7101146: Paths should more directly managed by BaseFileManager
jjg
parents:
10461
diff
changeset
|
56 |
import com.sun.tools.javac.code.Source; |
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"); |
|
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
88 |
locations.update(log, Lint.instance(context), FSInfo.instance(context)); |
35807
2eb1d877da0f
8147801: java.nio.file.ClosedFileSystemException when using Javadoc API's in JDK9
jjg
parents:
29780
diff
changeset
|
89 |
|
2eb1d877da0f
8147801: java.nio.file.ClosedFileSystemException when using Javadoc API's in JDK9
jjg
parents:
29780
diff
changeset
|
90 |
// 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
|
91 |
// 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
|
92 |
// 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
|
93 |
// 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
|
94 |
// 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
|
95 |
// 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
|
96 |
// 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
|
97 |
// manager is complete. |
2eb1d877da0f
8147801: java.nio.file.ClosedFileSystemException when using Javadoc API's in JDK9
jjg
parents:
29780
diff
changeset
|
98 |
// 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
|
99 |
// 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
|
100 |
// is actually closed. |
2eb1d877da0f
8147801: java.nio.file.ClosedFileSystemException when using Javadoc API's in JDK9
jjg
parents:
29780
diff
changeset
|
101 |
// See also deferredClose(). |
2eb1d877da0f
8147801: java.nio.file.ClosedFileSystemException when using Javadoc API's in JDK9
jjg
parents:
29780
diff
changeset
|
102 |
String s = options.get("fileManager.deferClose"); |
2eb1d877da0f
8147801: java.nio.file.ClosedFileSystemException when using Javadoc API's in JDK9
jjg
parents:
29780
diff
changeset
|
103 |
if (s != null) { |
2eb1d877da0f
8147801: java.nio.file.ClosedFileSystemException when using Javadoc API's in JDK9
jjg
parents:
29780
diff
changeset
|
104 |
try { |
2eb1d877da0f
8147801: java.nio.file.ClosedFileSystemException when using Javadoc API's in JDK9
jjg
parents:
29780
diff
changeset
|
105 |
deferredCloseTimeout = (int) (Float.parseFloat(s) * 1000); |
2eb1d877da0f
8147801: java.nio.file.ClosedFileSystemException when using Javadoc API's in JDK9
jjg
parents:
29780
diff
changeset
|
106 |
} catch (NumberFormatException e) { |
2eb1d877da0f
8147801: java.nio.file.ClosedFileSystemException when using Javadoc API's in JDK9
jjg
parents:
29780
diff
changeset
|
107 |
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
|
108 |
} |
2eb1d877da0f
8147801: java.nio.file.ClosedFileSystemException when using Javadoc API's in JDK9
jjg
parents:
29780
diff
changeset
|
109 |
} |
10813
95b39a692cd0
7101146: Paths should more directly managed by BaseFileManager
jjg
parents:
10461
diff
changeset
|
110 |
} |
95b39a692cd0
7101146: Paths should more directly managed by BaseFileManager
jjg
parents:
10461
diff
changeset
|
111 |
|
10818 | 112 |
protected Locations createLocations() { |
113 |
return new Locations(); |
|
4548 | 114 |
} |
115 |
||
116 |
/** |
|
117 |
* The log to be used for error reporting. |
|
118 |
*/ |
|
119 |
public Log log; |
|
120 |
||
121 |
/** |
|
122 |
* User provided charset (through javax.tools). |
|
123 |
*/ |
|
124 |
protected Charset charset; |
|
125 |
||
126 |
protected Options options; |
|
127 |
||
128 |
protected String classLoaderClass; |
|
129 |
||
10818 | 130 |
protected Locations locations; |
10813
95b39a692cd0
7101146: Paths should more directly managed by BaseFileManager
jjg
parents:
10461
diff
changeset
|
131 |
|
27379
5ae894733e09
8062579: JavacTask, DocumentationTask impls should close file manager when possible
jjg
parents:
27318
diff
changeset
|
132 |
/** |
5ae894733e09
8062579: JavacTask, DocumentationTask impls should close file manager when possible
jjg
parents:
27318
diff
changeset
|
133 |
* 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
|
134 |
* be closed when it is no longer required. |
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 |
public boolean autoClose; |
5ae894733e09
8062579: JavacTask, DocumentationTask impls should close file manager when possible
jjg
parents:
27318
diff
changeset
|
137 |
|
35807
2eb1d877da0f
8147801: java.nio.file.ClosedFileSystemException when using Javadoc API's in JDK9
jjg
parents:
29780
diff
changeset
|
138 |
/** |
2eb1d877da0f
8147801: java.nio.file.ClosedFileSystemException when using Javadoc API's in JDK9
jjg
parents:
29780
diff
changeset
|
139 |
* 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
|
140 |
* 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
|
141 |
*/ |
2eb1d877da0f
8147801: java.nio.file.ClosedFileSystemException when using Javadoc API's in JDK9
jjg
parents:
29780
diff
changeset
|
142 |
protected void deferredClose() { |
2eb1d877da0f
8147801: java.nio.file.ClosedFileSystemException when using Javadoc API's in JDK9
jjg
parents:
29780
diff
changeset
|
143 |
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
|
144 |
@Override |
2eb1d877da0f
8147801: java.nio.file.ClosedFileSystemException when using Javadoc API's in JDK9
jjg
parents:
29780
diff
changeset
|
145 |
public void run() { |
2eb1d877da0f
8147801: java.nio.file.ClosedFileSystemException when using Javadoc API's in JDK9
jjg
parents:
29780
diff
changeset
|
146 |
try { |
2eb1d877da0f
8147801: java.nio.file.ClosedFileSystemException when using Javadoc API's in JDK9
jjg
parents:
29780
diff
changeset
|
147 |
synchronized (BaseFileManager.this) { |
2eb1d877da0f
8147801: java.nio.file.ClosedFileSystemException when using Javadoc API's in JDK9
jjg
parents:
29780
diff
changeset
|
148 |
long now = System.currentTimeMillis(); |
2eb1d877da0f
8147801: java.nio.file.ClosedFileSystemException when using Javadoc API's in JDK9
jjg
parents:
29780
diff
changeset
|
149 |
while (now < lastUsedTime + deferredCloseTimeout) { |
2eb1d877da0f
8147801: java.nio.file.ClosedFileSystemException when using Javadoc API's in JDK9
jjg
parents:
29780
diff
changeset
|
150 |
BaseFileManager.this.wait(lastUsedTime + deferredCloseTimeout - now); |
2eb1d877da0f
8147801: java.nio.file.ClosedFileSystemException when using Javadoc API's in JDK9
jjg
parents:
29780
diff
changeset
|
151 |
now = System.currentTimeMillis(); |
2eb1d877da0f
8147801: java.nio.file.ClosedFileSystemException when using Javadoc API's in JDK9
jjg
parents:
29780
diff
changeset
|
152 |
} |
2eb1d877da0f
8147801: java.nio.file.ClosedFileSystemException when using Javadoc API's in JDK9
jjg
parents:
29780
diff
changeset
|
153 |
deferredCloseTimeout = 0; |
2eb1d877da0f
8147801: java.nio.file.ClosedFileSystemException when using Javadoc API's in JDK9
jjg
parents:
29780
diff
changeset
|
154 |
close(); |
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 |
} catch (InterruptedException e) { |
2eb1d877da0f
8147801: java.nio.file.ClosedFileSystemException when using Javadoc API's in JDK9
jjg
parents:
29780
diff
changeset
|
157 |
} catch (IOException e) { |
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 |
} |
2eb1d877da0f
8147801: java.nio.file.ClosedFileSystemException when using Javadoc API's in JDK9
jjg
parents:
29780
diff
changeset
|
160 |
}; |
2eb1d877da0f
8147801: java.nio.file.ClosedFileSystemException when using Javadoc API's in JDK9
jjg
parents:
29780
diff
changeset
|
161 |
t.setDaemon(true); |
2eb1d877da0f
8147801: java.nio.file.ClosedFileSystemException when using Javadoc API's in JDK9
jjg
parents:
29780
diff
changeset
|
162 |
t.start(); |
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 |
|
2eb1d877da0f
8147801: java.nio.file.ClosedFileSystemException when using Javadoc API's in JDK9
jjg
parents:
29780
diff
changeset
|
165 |
synchronized void updateLastUsedTime() { |
2eb1d877da0f
8147801: java.nio.file.ClosedFileSystemException when using Javadoc API's in JDK9
jjg
parents:
29780
diff
changeset
|
166 |
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
|
167 |
lastUsedTime = System.currentTimeMillis(); |
2eb1d877da0f
8147801: java.nio.file.ClosedFileSystemException when using Javadoc API's in JDK9
jjg
parents:
29780
diff
changeset
|
168 |
} |
2eb1d877da0f
8147801: java.nio.file.ClosedFileSystemException when using Javadoc API's in JDK9
jjg
parents:
29780
diff
changeset
|
169 |
} |
2eb1d877da0f
8147801: java.nio.file.ClosedFileSystemException when using Javadoc API's in JDK9
jjg
parents:
29780
diff
changeset
|
170 |
|
2eb1d877da0f
8147801: java.nio.file.ClosedFileSystemException when using Javadoc API's in JDK9
jjg
parents:
29780
diff
changeset
|
171 |
private long lastUsedTime = System.currentTimeMillis(); |
2eb1d877da0f
8147801: java.nio.file.ClosedFileSystemException when using Javadoc API's in JDK9
jjg
parents:
29780
diff
changeset
|
172 |
protected long deferredCloseTimeout = 0; |
2eb1d877da0f
8147801: java.nio.file.ClosedFileSystemException when using Javadoc API's in JDK9
jjg
parents:
29780
diff
changeset
|
173 |
|
4548 | 174 |
protected Source getSource() { |
11314 | 175 |
String sourceName = options.get(Option.SOURCE); |
4548 | 176 |
Source source = null; |
177 |
if (sourceName != null) |
|
178 |
source = Source.lookup(sourceName); |
|
179 |
return (source != null ? source : Source.DEFAULT); |
|
180 |
} |
|
181 |
||
182 |
protected ClassLoader getClassLoader(URL[] urls) { |
|
183 |
ClassLoader thisClassLoader = getClass().getClassLoader(); |
|
184 |
||
16796
53060909017b
7059170: Assume availablility of URLClassLoader.close
darcy
parents:
14801
diff
changeset
|
185 |
// Allow the following to specify a closeable classloader |
53060909017b
7059170: Assume availablility of URLClassLoader.close
darcy
parents:
14801
diff
changeset
|
186 |
// other than URLClassLoader. |
4548 | 187 |
|
188 |
// 1: Allow client to specify the class to use via hidden option |
|
189 |
if (classLoaderClass != null) { |
|
190 |
try { |
|
191 |
Class<? extends ClassLoader> loader = |
|
192 |
Class.forName(classLoaderClass).asSubclass(ClassLoader.class); |
|
193 |
Class<?>[] constrArgTypes = { URL[].class, ClassLoader.class }; |
|
194 |
Constructor<? extends ClassLoader> constr = loader.getConstructor(constrArgTypes); |
|
36526 | 195 |
return ensureReadable(constr.newInstance(urls, thisClassLoader)); |
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
196 |
} catch (ReflectiveOperationException t) { |
4548 | 197 |
// ignore errors loading user-provided class loader, fall through |
198 |
} |
|
199 |
} |
|
36526 | 200 |
return ensureReadable(new URLClassLoader(urls, thisClassLoader)); |
201 |
} |
|
202 |
||
203 |
/** |
|
204 |
* Ensures that the unnamed module of the given classloader is readable to this |
|
205 |
* module. |
|
206 |
*/ |
|
207 |
private ClassLoader ensureReadable(ClassLoader targetLoader) { |
|
208 |
try { |
|
209 |
Method getModuleMethod = Class.class.getMethod("getModule"); |
|
210 |
Object thisModule = getModuleMethod.invoke(this.getClass()); |
|
211 |
Method getUnnamedModuleMethod = ClassLoader.class.getMethod("getUnnamedModule"); |
|
212 |
Object targetModule = getUnnamedModuleMethod.invoke(targetLoader); |
|
213 |
||
214 |
Class<?> moduleClass = getModuleMethod.getReturnType(); |
|
215 |
Method addReadsMethod = moduleClass.getMethod("addReads", moduleClass); |
|
216 |
addReadsMethod.invoke(thisModule, targetModule); |
|
217 |
} catch (NoSuchMethodException e) { |
|
218 |
// ignore |
|
219 |
} catch (Exception e) { |
|
220 |
throw new Abort(e); |
|
221 |
} |
|
222 |
return targetLoader; |
|
4548 | 223 |
} |
224 |
||
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
225 |
public boolean isDefaultBootClassPath() { |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
226 |
return locations.isDefaultBootClassPath(); |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
227 |
} |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
228 |
|
4548 | 229 |
// <editor-fold defaultstate="collapsed" desc="Option handling"> |
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
230 |
@Override @DefinedBy(Api.COMPILER) |
4548 | 231 |
public boolean handleOption(String current, Iterator<String> remaining) { |
11314 | 232 |
OptionHelper helper = new GrumpyHelper(log) { |
233 |
@Override |
|
234 |
public String get(Option option) { |
|
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
39362
diff
changeset
|
235 |
return options.get(option); |
11314 | 236 |
} |
237 |
||
238 |
@Override |
|
239 |
public void put(String name, String value) { |
|
240 |
options.put(name, value); |
|
241 |
} |
|
242 |
||
243 |
@Override |
|
244 |
public void remove(String name) { |
|
245 |
options.remove(name); |
|
246 |
} |
|
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
247 |
|
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
248 |
@Override |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
249 |
public boolean handleFileManagerOption(Option option, String value) { |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
250 |
return handleOption(option, value); |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
251 |
} |
11314 | 252 |
}; |
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
253 |
|
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
39362
diff
changeset
|
254 |
Option o = Option.lookup(current, javacFileManagerOptions); |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
39362
diff
changeset
|
255 |
if (o == null) { |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
39362
diff
changeset
|
256 |
return false; |
4548 | 257 |
} |
258 |
||
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
39362
diff
changeset
|
259 |
if (!o.handleOption(helper, current, remaining)) |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
39362
diff
changeset
|
260 |
throw new IllegalArgumentException(current); |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
39362
diff
changeset
|
261 |
|
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
39362
diff
changeset
|
262 |
return true; |
4548 | 263 |
} |
264 |
// where |
|
14801
d66cab4ef397
8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents:
11314
diff
changeset
|
265 |
private static final Set<Option> javacFileManagerOptions = |
11314 | 266 |
Option.getJavacFileManagerOptions(); |
4548 | 267 |
|
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
268 |
@Override @DefinedBy(Api.COMPILER) |
4548 | 269 |
public int isSupportedOption(String option) { |
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
39362
diff
changeset
|
270 |
Option o = Option.lookup(option, javacFileManagerOptions); |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
39362
diff
changeset
|
271 |
return (o == null) ? -1 : o.hasArg() ? 1 : 0; |
4548 | 272 |
} |
7335
8b390fd27190
6900037: javac should warn if earlier -source is used and bootclasspath not set
jjg
parents:
5520
diff
changeset
|
273 |
|
37394
c36230ee15d9
8149757: Implement Multi-Release JAR aware JavacFileManager for javac
jjg
parents:
36526
diff
changeset
|
274 |
protected String multiReleaseValue; |
c36230ee15d9
8149757: Implement Multi-Release JAR aware JavacFileManager for javac
jjg
parents:
36526
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 |
* Common back end for OptionHelper handleFileManagerOption. |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
278 |
* @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
|
279 |
* @param value the value for the option |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
280 |
* @return true if successful, and false otherwise |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
281 |
*/ |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
282 |
public boolean handleOption(Option option, String value) { |
36155
1555ce1fcb4f
8149772: cleanup handling of -encoding in JavacFileManager
jjg
parents:
35807
diff
changeset
|
283 |
switch (option) { |
1555ce1fcb4f
8149772: cleanup handling of -encoding in JavacFileManager
jjg
parents:
35807
diff
changeset
|
284 |
case ENCODING: |
1555ce1fcb4f
8149772: cleanup handling of -encoding in JavacFileManager
jjg
parents:
35807
diff
changeset
|
285 |
encodingName = value; |
1555ce1fcb4f
8149772: cleanup handling of -encoding in JavacFileManager
jjg
parents:
35807
diff
changeset
|
286 |
return true; |
1555ce1fcb4f
8149772: cleanup handling of -encoding in JavacFileManager
jjg
parents:
35807
diff
changeset
|
287 |
|
37394
c36230ee15d9
8149757: Implement Multi-Release JAR aware JavacFileManager for javac
jjg
parents:
36526
diff
changeset
|
288 |
case MULTIRELEASE: |
c36230ee15d9
8149757: Implement Multi-Release JAR aware JavacFileManager for javac
jjg
parents:
36526
diff
changeset
|
289 |
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
|
290 |
locations.setMultiReleaseValue(value); |
37394
c36230ee15d9
8149757: Implement Multi-Release JAR aware JavacFileManager for javac
jjg
parents:
36526
diff
changeset
|
291 |
return true; |
c36230ee15d9
8149757: Implement Multi-Release JAR aware JavacFileManager for javac
jjg
parents:
36526
diff
changeset
|
292 |
|
36155
1555ce1fcb4f
8149772: cleanup handling of -encoding in JavacFileManager
jjg
parents:
35807
diff
changeset
|
293 |
default: |
1555ce1fcb4f
8149772: cleanup handling of -encoding in JavacFileManager
jjg
parents:
35807
diff
changeset
|
294 |
return locations.handleOption(option, value); |
1555ce1fcb4f
8149772: cleanup handling of -encoding in JavacFileManager
jjg
parents:
35807
diff
changeset
|
295 |
} |
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
296 |
} |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
297 |
|
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
298 |
/** |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
299 |
* 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
|
300 |
* @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
|
301 |
* @return true if all the calls are successful |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
302 |
*/ |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
303 |
public boolean handleOptions(Map<Option, String> map) { |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
304 |
boolean ok = true; |
36526 | 305 |
for (Map.Entry<Option, String> e: map.entrySet()) { |
306 |
try { |
|
307 |
ok = ok & handleOption(e.getKey(), e.getValue()); |
|
308 |
} catch (IllegalArgumentException ex) { |
|
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
39362
diff
changeset
|
309 |
log.error(Errors.IllegalArgumentForOption(e.getKey().getPrimaryName(), ex.getMessage())); |
36526 | 310 |
ok = false; |
311 |
} |
|
312 |
} |
|
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
313 |
return ok; |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
314 |
} |
7335
8b390fd27190
6900037: javac should warn if earlier -source is used and bootclasspath not set
jjg
parents:
5520
diff
changeset
|
315 |
|
4548 | 316 |
// </editor-fold> |
317 |
||
318 |
// <editor-fold defaultstate="collapsed" desc="Encoding"> |
|
36155
1555ce1fcb4f
8149772: cleanup handling of -encoding in JavacFileManager
jjg
parents:
35807
diff
changeset
|
319 |
private String encodingName; |
4548 | 320 |
private String defaultEncodingName; |
321 |
private String getDefaultEncodingName() { |
|
322 |
if (defaultEncodingName == null) { |
|
39362
5ac5af2acb57
8132857: Historical name of default encoding shown on encoding mismatch
jlahoda
parents:
38511
diff
changeset
|
323 |
defaultEncodingName = Charset.defaultCharset().name(); |
4548 | 324 |
} |
325 |
return defaultEncodingName; |
|
326 |
} |
|
327 |
||
328 |
public String getEncodingName() { |
|
36155
1555ce1fcb4f
8149772: cleanup handling of -encoding in JavacFileManager
jjg
parents:
35807
diff
changeset
|
329 |
return (encodingName != null) ? encodingName : getDefaultEncodingName(); |
4548 | 330 |
} |
331 |
||
27318
4660a5da7d90
8062376: Suppress cast warnings when using NIO buffers
rwarburton
parents:
26266
diff
changeset
|
332 |
@SuppressWarnings("cast") |
4548 | 333 |
public CharBuffer decode(ByteBuffer inbuf, boolean ignoreEncodingErrors) { |
334 |
String encodingName = getEncodingName(); |
|
335 |
CharsetDecoder decoder; |
|
336 |
try { |
|
337 |
decoder = getDecoder(encodingName, ignoreEncodingErrors); |
|
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
338 |
} catch (IllegalCharsetNameException | UnsupportedCharsetException e) { |
4548 | 339 |
log.error("unsupported.encoding", encodingName); |
340 |
return (CharBuffer)CharBuffer.allocate(1).flip(); |
|
341 |
} |
|
342 |
||
343 |
// slightly overestimate the buffer size to avoid reallocation. |
|
344 |
float factor = |
|
345 |
decoder.averageCharsPerByte() * 0.8f + |
|
346 |
decoder.maxCharsPerByte() * 0.2f; |
|
347 |
CharBuffer dest = CharBuffer. |
|
348 |
allocate(10 + (int)(inbuf.remaining()*factor)); |
|
349 |
||
350 |
while (true) { |
|
351 |
CoderResult result = decoder.decode(inbuf, dest, true); |
|
352 |
dest.flip(); |
|
353 |
||
354 |
if (result.isUnderflow()) { // done reading |
|
355 |
// make sure there is at least one extra character |
|
356 |
if (dest.limit() == dest.capacity()) { |
|
357 |
dest = CharBuffer.allocate(dest.capacity()+1).put(dest); |
|
358 |
dest.flip(); |
|
359 |
} |
|
360 |
return dest; |
|
361 |
} else if (result.isOverflow()) { // buffer too small; expand |
|
362 |
int newCapacity = |
|
363 |
10 + dest.capacity() + |
|
364 |
(int)(inbuf.remaining()*decoder.maxCharsPerByte()); |
|
365 |
dest = CharBuffer.allocate(newCapacity).put(dest); |
|
366 |
} else if (result.isMalformed() || result.isUnmappable()) { |
|
367 |
// bad character in input |
|
38511
d934635453ad
8078559: Update error message to indicate illegal character when encoding set to ascii
jlahoda
parents:
37394
diff
changeset
|
368 |
StringBuilder unmappable = new StringBuilder(); |
d934635453ad
8078559: Update error message to indicate illegal character when encoding set to ascii
jlahoda
parents:
37394
diff
changeset
|
369 |
int len = result.length(); |
4548 | 370 |
|
38511
d934635453ad
8078559: Update error message to indicate illegal character when encoding set to ascii
jlahoda
parents:
37394
diff
changeset
|
371 |
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
|
372 |
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
|
373 |
} |
4548 | 374 |
|
38511
d934635453ad
8078559: Update error message to indicate illegal character when encoding set to ascii
jlahoda
parents:
37394
diff
changeset
|
375 |
String charsetName = charset == null ? encodingName : charset.name(); |
d934635453ad
8078559: Update error message to indicate illegal character when encoding set to ascii
jlahoda
parents:
37394
diff
changeset
|
376 |
|
d934635453ad
8078559: Update error message to indicate illegal character when encoding set to ascii
jlahoda
parents:
37394
diff
changeset
|
377 |
log.error(dest.limit(), |
d934635453ad
8078559: Update error message to indicate illegal character when encoding set to ascii
jlahoda
parents:
37394
diff
changeset
|
378 |
Errors.IllegalCharForEncoding(unmappable.toString(), charsetName)); |
4548 | 379 |
|
380 |
// undo the flip() to prepare the output buffer |
|
381 |
// for more translation |
|
382 |
dest.position(dest.limit()); |
|
383 |
dest.limit(dest.capacity()); |
|
384 |
dest.put((char)0xfffd); // backward compatible |
|
385 |
} else { |
|
386 |
throw new AssertionError(result); |
|
387 |
} |
|
388 |
} |
|
389 |
// unreached |
|
390 |
} |
|
391 |
||
392 |
public CharsetDecoder getDecoder(String encodingName, boolean ignoreEncodingErrors) { |
|
393 |
Charset cs = (this.charset == null) |
|
394 |
? Charset.forName(encodingName) |
|
395 |
: this.charset; |
|
396 |
CharsetDecoder decoder = cs.newDecoder(); |
|
397 |
||
398 |
CodingErrorAction action; |
|
399 |
if (ignoreEncodingErrors) |
|
400 |
action = CodingErrorAction.REPLACE; |
|
401 |
else |
|
402 |
action = CodingErrorAction.REPORT; |
|
403 |
||
404 |
return decoder |
|
405 |
.onMalformedInput(action) |
|
406 |
.onUnmappableCharacter(action); |
|
407 |
} |
|
408 |
// </editor-fold> |
|
409 |
||
410 |
// <editor-fold defaultstate="collapsed" desc="ByteBuffers"> |
|
411 |
/** |
|
412 |
* 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
|
413 |
* @param in the stream |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
414 |
* @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
|
415 |
* @throws IOException if an error occurred while reading the stream |
4548 | 416 |
*/ |
27318
4660a5da7d90
8062376: Suppress cast warnings when using NIO buffers
rwarburton
parents:
26266
diff
changeset
|
417 |
@SuppressWarnings("cast") |
4548 | 418 |
public ByteBuffer makeByteBuffer(InputStream in) |
419 |
throws IOException { |
|
420 |
int limit = in.available(); |
|
421 |
if (limit < 1024) limit = 1024; |
|
422 |
ByteBuffer result = byteBufferCache.get(limit); |
|
423 |
int position = 0; |
|
424 |
while (in.available() != 0) { |
|
425 |
if (position >= limit) |
|
426 |
// expand buffer |
|
427 |
result = ByteBuffer. |
|
428 |
allocate(limit <<= 1). |
|
429 |
put((ByteBuffer)result.flip()); |
|
430 |
int count = in.read(result.array(), |
|
431 |
position, |
|
432 |
limit - position); |
|
433 |
if (count < 0) break; |
|
434 |
result.position(position += count); |
|
435 |
} |
|
436 |
return (ByteBuffer)result.flip(); |
|
437 |
} |
|
438 |
||
439 |
public void recycleByteBuffer(ByteBuffer bb) { |
|
440 |
byteBufferCache.put(bb); |
|
441 |
} |
|
442 |
||
443 |
/** |
|
444 |
* A single-element cache of direct byte buffers. |
|
445 |
*/ |
|
27318
4660a5da7d90
8062376: Suppress cast warnings when using NIO buffers
rwarburton
parents:
26266
diff
changeset
|
446 |
@SuppressWarnings("cast") |
4548 | 447 |
private static class ByteBufferCache { |
448 |
private ByteBuffer cached; |
|
449 |
ByteBuffer get(int capacity) { |
|
450 |
if (capacity < 20480) capacity = 20480; |
|
451 |
ByteBuffer result = |
|
452 |
(cached != null && cached.capacity() >= capacity) |
|
453 |
? (ByteBuffer)cached.clear() |
|
454 |
: ByteBuffer.allocate(capacity + capacity>>1); |
|
455 |
cached = null; |
|
456 |
return result; |
|
457 |
} |
|
458 |
void put(ByteBuffer x) { |
|
459 |
cached = x; |
|
460 |
} |
|
461 |
} |
|
462 |
||
463 |
private final ByteBufferCache byteBufferCache; |
|
464 |
// </editor-fold> |
|
465 |
||
466 |
// <editor-fold defaultstate="collapsed" desc="Content cache"> |
|
467 |
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
|
468 |
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
|
469 |
if (e == null) |
998e642f9811
7068451: Regression: javac compiles fixed sources against previous, not current, version of generated sources
jjg
parents:
7681
diff
changeset
|
470 |
return null; |
998e642f9811
7068451: Regression: javac compiles fixed sources against previous, not current, version of generated sources
jjg
parents:
7681
diff
changeset
|
471 |
|
998e642f9811
7068451: Regression: javac compiles fixed sources against previous, not current, version of generated sources
jjg
parents:
7681
diff
changeset
|
472 |
if (!e.isValid(file)) { |
998e642f9811
7068451: Regression: javac compiles fixed sources against previous, not current, version of generated sources
jjg
parents:
7681
diff
changeset
|
473 |
contentCache.remove(file); |
998e642f9811
7068451: Regression: javac compiles fixed sources against previous, not current, version of generated sources
jjg
parents:
7681
diff
changeset
|
474 |
return null; |
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 |
|
998e642f9811
7068451: Regression: javac compiles fixed sources against previous, not current, version of generated sources
jjg
parents:
7681
diff
changeset
|
477 |
return e.getValue(); |
4548 | 478 |
} |
479 |
||
480 |
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
|
481 |
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
|
482 |
} |
998e642f9811
7068451: Regression: javac compiles fixed sources against previous, not current, version of generated sources
jjg
parents:
7681
diff
changeset
|
483 |
|
998e642f9811
7068451: Regression: javac compiles fixed sources against previous, not current, version of generated sources
jjg
parents:
7681
diff
changeset
|
484 |
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
|
485 |
contentCache.remove(file); |
4548 | 486 |
} |
487 |
||
22163 | 488 |
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
|
489 |
|
998e642f9811
7068451: Regression: javac compiles fixed sources against previous, not current, version of generated sources
jjg
parents:
7681
diff
changeset
|
490 |
protected static class ContentCacheEntry { |
998e642f9811
7068451: Regression: javac compiles fixed sources against previous, not current, version of generated sources
jjg
parents:
7681
diff
changeset
|
491 |
final long timestamp; |
998e642f9811
7068451: Regression: javac compiles fixed sources against previous, not current, version of generated sources
jjg
parents:
7681
diff
changeset
|
492 |
final SoftReference<CharBuffer> ref; |
998e642f9811
7068451: Regression: javac compiles fixed sources against previous, not current, version of generated sources
jjg
parents:
7681
diff
changeset
|
493 |
|
998e642f9811
7068451: Regression: javac compiles fixed sources against previous, not current, version of generated sources
jjg
parents:
7681
diff
changeset
|
494 |
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
|
495 |
this.timestamp = file.getLastModified(); |
22163 | 496 |
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
|
497 |
} |
998e642f9811
7068451: Regression: javac compiles fixed sources against previous, not current, version of generated sources
jjg
parents:
7681
diff
changeset
|
498 |
|
998e642f9811
7068451: Regression: javac compiles fixed sources against previous, not current, version of generated sources
jjg
parents:
7681
diff
changeset
|
499 |
boolean isValid(JavaFileObject file) { |
998e642f9811
7068451: Regression: javac compiles fixed sources against previous, not current, version of generated sources
jjg
parents:
7681
diff
changeset
|
500 |
return timestamp == file.getLastModified(); |
998e642f9811
7068451: Regression: javac compiles fixed sources against previous, not current, version of generated sources
jjg
parents:
7681
diff
changeset
|
501 |
} |
998e642f9811
7068451: Regression: javac compiles fixed sources against previous, not current, version of generated sources
jjg
parents:
7681
diff
changeset
|
502 |
|
998e642f9811
7068451: Regression: javac compiles fixed sources against previous, not current, version of generated sources
jjg
parents:
7681
diff
changeset
|
503 |
CharBuffer getValue() { |
998e642f9811
7068451: Regression: javac compiles fixed sources against previous, not current, version of generated sources
jjg
parents:
7681
diff
changeset
|
504 |
return ref.get(); |
998e642f9811
7068451: Regression: javac compiles fixed sources against previous, not current, version of generated sources
jjg
parents:
7681
diff
changeset
|
505 |
} |
998e642f9811
7068451: Regression: javac compiles fixed sources against previous, not current, version of generated sources
jjg
parents:
7681
diff
changeset
|
506 |
} |
4548 | 507 |
// </editor-fold> |
508 |
||
27579 | 509 |
public static Kind getKind(Path path) { |
510 |
return getKind(path.getFileName().toString()); |
|
511 |
} |
|
512 |
||
4548 | 513 |
public static Kind getKind(String name) { |
514 |
if (name.endsWith(Kind.CLASS.extension)) |
|
515 |
return Kind.CLASS; |
|
516 |
else if (name.endsWith(Kind.SOURCE.extension)) |
|
517 |
return Kind.SOURCE; |
|
518 |
else if (name.endsWith(Kind.HTML.extension)) |
|
519 |
return Kind.HTML; |
|
520 |
else |
|
521 |
return Kind.OTHER; |
|
522 |
} |
|
523 |
||
524 |
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
|
525 |
return Objects.requireNonNull(o); |
4548 | 526 |
} |
527 |
||
528 |
protected static <T> Collection<T> nullCheck(Collection<T> it) { |
|
529 |
for (T t : it) |
|
29291
076c277565f7
8073550: java* tools: replace obj.getClass hacks with Assert.checkNonNull or Objects.requireNonNull
mcimadamore
parents:
27579
diff
changeset
|
530 |
Objects.requireNonNull(t); |
4548 | 531 |
return it; |
532 |
} |
|
533 |
} |