RFR: 8059976 Convert JavacFileManager to use java.nio.file internally
Jonathan Gibbons
jonathan.gibbons at oracle.com
Tue Aug 25 23:42:37 UTC 2015
I've posted a fix to convert JavacFileManager to use java.nio.file.Path
internally for accessing jar files, instead of using javac's old
internal code to access zip files.
There's more cleanup that can be done eventually, such as merging or all
of PathFileObject, RegularFileObject and BaseFileObject, but the goal
for this round of work has been leave existing behavior unchanged as
much as possible.
Bug: https://bugs.openjdk.java.net/browse/JDK-8059976
Webrev: http://cr.openjdk.java.net/~jjg/8059976/webrev.00/
I'd be particularly interested in feedback from folk developing custom
file managers based on top of nio FileSystems.
-- Jon
On 07/10/2015 03:24 PM, Jonathan Gibbons wrote:
> Now tracked as https://bugs.openjdk.java.net/browse/JDK-8130944
>
> -- Jon
>
> On 07/10/2015 02:57 PM, Jonathan Gibbons wrote:
>> FWIW, the scary big deal about fixing 8059976 is that clients will
>> need to be more careful to ensure that file managers are closed after
>> use, so that the file manager can close any file systems that have
>> been opened internally (primarily meaning, jar file systems). Right
>> now, with the old fashioned support for jar files, that is not the case.
>>
>> -- Jon
>>
>>
>> On 07/10/2015 02:53 PM, Jonathan Gibbons wrote:
>>> Liam,
>>>
>>> Thanks for the feedback. Obviously the intent is that you should be
>>> able to use Paths that don't rely on the use of the default
>>> filesystem, so this needs to be fixed.
>>>
>>> -- Jon
>>>
>>>
>>> On 07/10/2015 02:24 PM, Liam Miller-Cushon wrote:
>>>> I've been using JavacPathFileManager and an in-memory filesystem
>>>> (github.com/google/jimfs <http://github.com/google/jimfs>) for
>>>> testing some code that uses the compiler API.
>>>>
>>>> I noticed that JDK-8076420 deleted JavacPathFileManager and moved
>>>> the Path-based methods into the regular JavacFileManager. I think
>>>> that's great, but I'm having trouble using the Path-based API in
>>>> JavacFileManager. The implementation uses Path#toFile(), which only
>>>> works with the default filesystem.
>>>>
>>>> Is this a known issue? JDK-8059976 looks like it would probably fix it.
>>>>
>>>> Repro:
>>>>
>>>> ===
>>>> import com.google.common.jimfs.Configuration;
>>>> import com.google.common.jimfs.Jimfs;
>>>>
>>>> import static java.nio.charset.StandardCharsets.UTF_8;
>>>>
>>>> import com.sun.tools.javac.file.JavacFileManager;
>>>> import com.sun.tools.javac.util.Context;
>>>> import com.sun.tools.javac.util.Log;
>>>>
>>>> import java.nio.file.FileSystem;
>>>> import java.io.OutputStreamWriter;
>>>> import java.io.PrintWriter;
>>>> import java.io.IOException;
>>>> import java.nio.file.Files;
>>>> import java.nio.file.Path;
>>>> import java.util.Arrays;
>>>> import java.util.Locale;
>>>>
>>>> import javax.tools.StandardLocation;
>>>>
>>>> public class Test {
>>>> public static void main(String[] args) throws IOException {
>>>> FileSystem fs = Jimfs.newFileSystem(Configuration.unix());
>>>>
>>>> Path foo = fs.getPath("/foo");
>>>> Files.createDirectory(foo);
>>>> Path hello = foo.resolve("hello.jar");
>>>> Files.write(hello, Arrays.asList("hello world"), UTF_8);
>>>>
>>>> Context context = new Context();
>>>> context.put(Log.outKey, new PrintWriter(new
>>>> OutputStreamWriter(System.err, UTF_8), true));
>>>> JavacFileManager jfm = new JavacFileManager(context, true, UTF_8);
>>>>
>>>> jfm.setLocationFromPaths(StandardLocation.CLASS_PATH,
>>>> Arrays.asList(hello));
>>>> }
>>>> }
>>>> ===
>>>>
>>>> $ javac -cp jimfs.jar:javac.jar Test.java
>>>> $ java -cp jimfs.jar:javac.jar:guava.jar:. Test
>>>> Exception in thread "main" java.lang.UnsupportedOperationException
>>>> at com.google.common.jimfs.JimfsPath.toFile(JimfsPath.java:397)
>>>> at
>>>> com.sun.tools.javac.file.FSInfo.getJarClassPath(FSInfo.java:69)
>>>> at
>>>> com.sun.tools.javac.file.Locations$SearchPath.addJarClassPath(Locations.java:321)
>>>> at
>>>> com.sun.tools.javac.file.Locations$SearchPath.addFile(Locations.java:311)
>>>> at
>>>> com.sun.tools.javac.file.Locations$SearchPath.addFiles(Locations.java:250)
>>>> at
>>>> com.sun.tools.javac.file.Locations$SearchPath.addFiles(Locations.java:257)
>>>> at
>>>> com.sun.tools.javac.file.Locations$SimpleLocationHandler.setLocation(Locations.java:463)
>>>> at
>>>> com.sun.tools.javac.file.Locations.setLocation(Locations.java:783)
>>>> at
>>>> com.sun.tools.javac.file.JavacFileManager.setLocationFromPaths(JavacFileManager.java:914)
>>>> at Test.main(Test.java:34)
>>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.openjdk.java.net/pipermail/compiler-dev/attachments/20150825/e381cc11/attachment.html>
More information about the compiler-dev
mailing list