31 import java.io.FileNotFoundException; |
31 import java.io.FileNotFoundException; |
32 import java.io.IOException; |
32 import java.io.IOException; |
33 import java.io.InputStream; |
33 import java.io.InputStream; |
34 import java.io.OutputStreamWriter; |
34 import java.io.OutputStreamWriter; |
35 import java.lang.ref.SoftReference; |
35 import java.lang.ref.SoftReference; |
|
36 import java.lang.reflect.Constructor; |
36 import java.net.MalformedURLException; |
37 import java.net.MalformedURLException; |
37 import java.net.URI; |
38 import java.net.URI; |
38 import java.net.URL; |
39 import java.net.URL; |
39 import java.net.URLClassLoader; |
40 import java.net.URLClassLoader; |
40 import java.nio.ByteBuffer; |
41 import java.nio.ByteBuffer; |
74 import com.sun.tools.javac.util.List; |
75 import com.sun.tools.javac.util.List; |
75 import com.sun.tools.javac.util.ListBuffer; |
76 import com.sun.tools.javac.util.ListBuffer; |
76 import com.sun.tools.javac.util.Log; |
77 import com.sun.tools.javac.util.Log; |
77 import com.sun.tools.javac.util.Options; |
78 import com.sun.tools.javac.util.Options; |
78 |
79 |
|
80 import java.io.Closeable; |
79 import static javax.tools.StandardLocation.*; |
81 import static javax.tools.StandardLocation.*; |
80 import static com.sun.tools.javac.main.OptionName.*; |
82 import static com.sun.tools.javac.main.OptionName.*; |
81 |
83 |
82 /** |
84 /** |
83 * This class provides access to the source, class and other files |
85 * This class provides access to the source, class and other files |
129 */ |
131 */ |
130 private File sourceOutDir = uninited; |
132 private File sourceOutDir = uninited; |
131 |
133 |
132 protected boolean mmappedIO; |
134 protected boolean mmappedIO; |
133 protected boolean ignoreSymbolFile; |
135 protected boolean ignoreSymbolFile; |
|
136 protected String classLoaderClass; |
134 |
137 |
135 /** |
138 /** |
136 * User provided charset (through javax.tools). |
139 * User provided charset (through javax.tools). |
137 */ |
140 */ |
138 protected Charset charset; |
141 protected Charset charset; |
178 |
181 |
179 useZipFileIndex = System.getProperty("useJavaUtilZip") == null;// TODO: options.get("useJavaUtilZip") == null; |
182 useZipFileIndex = System.getProperty("useJavaUtilZip") == null;// TODO: options.get("useJavaUtilZip") == null; |
180 |
183 |
181 mmappedIO = options.get("mmappedIO") != null; |
184 mmappedIO = options.get("mmappedIO") != null; |
182 ignoreSymbolFile = options.get("ignore.symbol.file") != null; |
185 ignoreSymbolFile = options.get("ignore.symbol.file") != null; |
|
186 classLoaderClass = options.get("procloader"); |
183 } |
187 } |
184 |
188 |
185 public JavaFileObject getFileForInput(String name) { |
189 public JavaFileObject getFileForInput(String name) { |
186 return getRegularFile(new File(name)); |
190 return getRegularFile(new File(name)); |
187 } |
191 } |
745 lb.append(f.toURI().toURL()); |
749 lb.append(f.toURI().toURL()); |
746 } catch (MalformedURLException e) { |
750 } catch (MalformedURLException e) { |
747 throw new AssertionError(e); |
751 throw new AssertionError(e); |
748 } |
752 } |
749 } |
753 } |
750 return new URLClassLoader(lb.toArray(new URL[lb.size()]), |
754 |
751 getClass().getClassLoader()); |
755 URL[] urls = lb.toArray(new URL[lb.size()]); |
|
756 ClassLoader thisClassLoader = getClass().getClassLoader(); |
|
757 |
|
758 // Bug: 6558476 |
|
759 // Ideally, ClassLoader should be Closeable, but before JDK7 it is not. |
|
760 // On older versions, try the following, to get a closeable classloader. |
|
761 |
|
762 // 1: Allow client to specify the class to use via hidden option |
|
763 if (classLoaderClass != null) { |
|
764 try { |
|
765 Class<? extends ClassLoader> loader = |
|
766 Class.forName(classLoaderClass).asSubclass(ClassLoader.class); |
|
767 Class<?>[] constrArgTypes = { URL[].class, ClassLoader.class }; |
|
768 Constructor<? extends ClassLoader> constr = loader.getConstructor(constrArgTypes); |
|
769 return constr.newInstance(new Object[] { urls, thisClassLoader }); |
|
770 } catch (Throwable t) { |
|
771 // ignore errors loading user-provided class loader, fall through |
|
772 } |
|
773 } |
|
774 |
|
775 // 2: If URLClassLoader implements Closeable, use that. |
|
776 if (Closeable.class.isAssignableFrom(URLClassLoader.class)) |
|
777 return new URLClassLoader(urls, thisClassLoader); |
|
778 |
|
779 // 3: Try using private reflection-based CloseableURLClassLoader |
|
780 try { |
|
781 return new CloseableURLClassLoader(urls, thisClassLoader); |
|
782 } catch (Throwable t) { |
|
783 // ignore errors loading workaround class loader, fall through |
|
784 } |
|
785 |
|
786 // 4: If all else fails, use plain old standard URLClassLoader |
|
787 return new URLClassLoader(urls, thisClassLoader); |
752 } |
788 } |
753 |
789 |
754 public Iterable<JavaFileObject> list(Location location, |
790 public Iterable<JavaFileObject> list(Location location, |
755 String packageName, |
791 String packageName, |
756 Set<JavaFileObject.Kind> kinds, |
792 Set<JavaFileObject.Kind> kinds, |