"Scanning" module contents

Cédric Champeau cedric.champeau at gmail.com
Tue Dec 30 16:32:24 UTC 2014


Thanks, this is similar to what I managed to do a few minutes ago, but 
written in Groovy of course. I am putting it here for reference:

|import java.nio.file.FileSystems||
||import java.nio.file.Files||
||import java.nio.file.Path||
||import java.nio.file.SimpleFileVisitor||
||import java.nio.file.FileVisitResult||
||
||def fs = FileSystems.newFileSystem(URI.create("jrt:/"), [:])||
||
||fs.rootDirectories.each {||
||   Files.walkFileTree(it,[preVisitDirectory:{dir, attrs -> println 
dir; FileVisitResult.CONTINUE }] as SimpleFileVisitor)||
||}||
|
So given the path it dumps, I should be able to extract all package names.

Thanks!


On 30/12/2014 17:15, Remi Forax wrote:
> Hi Cedric,
> You can scan the module repository using a virtual FileSystem (NIO2) 
> that you can get with the prefix "jrt:/",
> so you can write a code like this
>
> FileSystem jrtFs = FileSystems.getFileSystem(new URI("jrt:/"));
> for(Path root: jrtFs.getRootDirectories()) {
>   try(DirectoryStream<Path> directoryStream = 
> Files.newDirectoryStream(root)) {
>     for(Path path: directoryStream) {
>       System.out.println(path);
>     }
>   }
> }
>
> cheers,
> Rémi
>
> On 12/30/2014 01:57 PM, Cédric Champeau wrote:
>> Hi guys!
>>
>> Sorry if it is a dumb question but finding information about Jigsaw 
>> is not easy :) I was leveraging this end of year to adapt the Groovy 
>> language build for JDK 9. The good news is that we seem to have very 
>> little issues with Jigsaw. One of them is in a tool called "groovysh" 
>> which is a REPL providing completion, like an IDE would. For example, 
>> if you start typing jav<TAB> it would start completing the package 
>> name. So far, the list of suggestions was based on elements on 
>> classpath, and classes from the JDK were found thanks to scanning JAR 
>> files.
>>
>> The problem is that we now have a new (unsupported) URLConnection 
>> type, which is JavaRuntimeURLConnection. I can see it can give me a 
>> module name, but I have absolutely no idea what to do with that. For 
>> a JAR it was easy because we could scan the entries, but now... Do 
>> you have any pointer for code I could look at? It is made a bit 
>> harder by the fact that even my IDE doesn't support JDK 9 so I cannot 
>> have completion or whatever tools I used to work with when dealing 
>> with new APIs ;)
>>
>> Once this will be fixed, Groovy will officially support 
>> building/running on JDK 9, which would be a nice New Year present :)
>>
>> Thanks!
>>
>


-- 
Cédric Champeau
Groovy language developer
http://twitter.com/CedricChampeau
http://melix.github.io/blog



More information about the jigsaw-dev mailing list