38 import java.nio.charset.CoderResult;
39 import java.nio.charset.CodingErrorAction;
40 import java.nio.charset.IllegalCharsetNameException;
41 import java.nio.charset.UnsupportedCharsetException;
42 import java.nio.file.NoSuchFileException;
43 import java.nio.file.Path;
44 import java.util.Collection;
45 import java.util.HashMap;
46 import java.util.HashSet;
47 import java.util.Iterator;
48 import java.util.Map;
49 import java.util.Objects;
50 import java.util.Set;
51
52 import javax.tools.JavaFileManager;
53 import javax.tools.JavaFileObject;
54 import javax.tools.JavaFileObject.Kind;
55
56 import com.sun.tools.javac.code.Lint;
57 import com.sun.tools.javac.code.Lint.LintCategory;
58 import com.sun.tools.javac.main.Option;
59 import com.sun.tools.javac.main.OptionHelper;
60 import com.sun.tools.javac.main.OptionHelper.GrumpyHelper;
61 import com.sun.tools.javac.resources.CompilerProperties.Errors;
62 import com.sun.tools.javac.resources.CompilerProperties.LintWarnings;
63 import com.sun.tools.javac.resources.CompilerProperties.Warnings;
64 import com.sun.tools.javac.util.Context;
65 import com.sun.tools.javac.util.DefinedBy;
66 import com.sun.tools.javac.util.DefinedBy.Api;
67 import com.sun.tools.javac.util.Log;
68 import com.sun.tools.javac.util.Options;
69
70 /**
71 * Utility methods for building a file manager.
72 * There are no references here to file-system specific objects such as
73 * java.io.File or java.nio.file.Path.
74 */
75 public abstract class BaseFileManager implements JavaFileManager {
76
77 private static final byte[] EMPTY_ARRAY = new byte[0];
174 }
175 };
176 t.setDaemon(true);
177 t.start();
178 }
179
180 synchronized void updateLastUsedTime() {
181 if (deferredCloseTimeout > 0) { // avoid updating the time unnecessarily
182 lastUsedTime = System.currentTimeMillis();
183 }
184 }
185
186 private long lastUsedTime = System.currentTimeMillis();
187 protected long deferredCloseTimeout = 0;
188
189 public void clear() {
190 new HashSet<>(options.keySet()).forEach(k -> options.remove(k));
191 }
192
193 protected ClassLoader getClassLoader(URL[] urls) {
194 ClassLoader thisClassLoader = getClass().getClassLoader();
195
196 // Allow the following to specify a closeable classloader
197 // other than URLClassLoader.
198
199 // 1: Allow client to specify the class to use via hidden option
200 String classLoaderClass = options.get("procloader");
201 if (classLoaderClass != null) {
202 try {
203 Class<? extends ClassLoader> loader =
204 Class.forName(classLoaderClass).asSubclass(ClassLoader.class);
205 Class<?>[] constrArgTypes = { URL[].class, ClassLoader.class };
206 Constructor<? extends ClassLoader> constr = loader.getConstructor(constrArgTypes);
207 return constr.newInstance(urls, thisClassLoader);
208 } catch (ReflectiveOperationException t) {
209 // ignore errors loading user-provided class loader, fall through
210 }
211 }
212 return new URLClassLoader(urls, thisClassLoader);
213 }
214
|
38 import java.nio.charset.CoderResult;
39 import java.nio.charset.CodingErrorAction;
40 import java.nio.charset.IllegalCharsetNameException;
41 import java.nio.charset.UnsupportedCharsetException;
42 import java.nio.file.NoSuchFileException;
43 import java.nio.file.Path;
44 import java.util.Collection;
45 import java.util.HashMap;
46 import java.util.HashSet;
47 import java.util.Iterator;
48 import java.util.Map;
49 import java.util.Objects;
50 import java.util.Set;
51
52 import javax.tools.JavaFileManager;
53 import javax.tools.JavaFileObject;
54 import javax.tools.JavaFileObject.Kind;
55
56 import com.sun.tools.javac.code.Lint;
57 import com.sun.tools.javac.code.Lint.LintCategory;
58 import com.sun.tools.javac.main.JavaCompiler;
59 import com.sun.tools.javac.main.JavaCompiler.CodeReflectionSupport;
60 import com.sun.tools.javac.main.Option;
61 import com.sun.tools.javac.main.OptionHelper;
62 import com.sun.tools.javac.main.OptionHelper.GrumpyHelper;
63 import com.sun.tools.javac.resources.CompilerProperties.Errors;
64 import com.sun.tools.javac.resources.CompilerProperties.LintWarnings;
65 import com.sun.tools.javac.resources.CompilerProperties.Warnings;
66 import com.sun.tools.javac.util.Context;
67 import com.sun.tools.javac.util.DefinedBy;
68 import com.sun.tools.javac.util.DefinedBy.Api;
69 import com.sun.tools.javac.util.Log;
70 import com.sun.tools.javac.util.Options;
71
72 /**
73 * Utility methods for building a file manager.
74 * There are no references here to file-system specific objects such as
75 * java.io.File or java.nio.file.Path.
76 */
77 public abstract class BaseFileManager implements JavaFileManager {
78
79 private static final byte[] EMPTY_ARRAY = new byte[0];
176 }
177 };
178 t.setDaemon(true);
179 t.start();
180 }
181
182 synchronized void updateLastUsedTime() {
183 if (deferredCloseTimeout > 0) { // avoid updating the time unnecessarily
184 lastUsedTime = System.currentTimeMillis();
185 }
186 }
187
188 private long lastUsedTime = System.currentTimeMillis();
189 protected long deferredCloseTimeout = 0;
190
191 public void clear() {
192 new HashSet<>(options.keySet()).forEach(k -> options.remove(k));
193 }
194
195 protected ClassLoader getClassLoader(URL[] urls) {
196 ClassLoader thisClassLoader = CodeReflectionSupport.CODE_LAYER != null ?
197 CodeReflectionSupport.CODE_LAYER.findLoader("jdk.incubator.code") :
198 getClass().getClassLoader();
199
200 // Allow the following to specify a closeable classloader
201 // other than URLClassLoader.
202
203 // 1: Allow client to specify the class to use via hidden option
204 String classLoaderClass = options.get("procloader");
205 if (classLoaderClass != null) {
206 try {
207 Class<? extends ClassLoader> loader =
208 Class.forName(classLoaderClass).asSubclass(ClassLoader.class);
209 Class<?>[] constrArgTypes = { URL[].class, ClassLoader.class };
210 Constructor<? extends ClassLoader> constr = loader.getConstructor(constrArgTypes);
211 return constr.newInstance(urls, thisClassLoader);
212 } catch (ReflectiveOperationException t) {
213 // ignore errors loading user-provided class loader, fall through
214 }
215 }
216 return new URLClassLoader(urls, thisClassLoader);
217 }
218
|