@@ -27,8 +27,11 @@ import org.apache.commons.compress.archivers.tar.TarArchiveOutputStream
2727import org.apache.commons.compress.compressors.gzip.GzipCompressorInputStream
2828import org.apache.commons.compress.compressors.gzip.GzipCompressorOutputStream
2929
30+ import java.nio.file.FileVisitResult
3031import java.nio.file.Files
3132import java.nio.file.Path
33+ import java.nio.file.SimpleFileVisitor
34+ import java.nio.file.attribute.BasicFileAttributes
3235import java.util.stream.Stream
3336import java.util.zip.ZipEntry
3437import java.util.zip.ZipInputStream
@@ -136,22 +139,28 @@ class ModuleStorage {
136139
137140 List<InstalledModule > modules = []
138141
139- try ( final walkStream = Files . walk(modulesDir) ) {
140- walkStream
141- .filter { Path path -> Files . isDirectory(path) }
142- .filter { Path path -> Files . exists(path. resolve(MODULE_INFO_FILE )) }
143- .each { Path moduleDir ->
144- try {
145- def rel = modulesDir. relativize(moduleDir)
146- if ( rel. nameCount < 2 ) return // Need at least scope/name
147- def reference = ModuleReference . parse(rel. toString())
148- def installed = getInstalledModule(reference)
149- if ( installed ) modules. add(installed)
150- } catch (Exception e){
151- // Catching exception to go on inspecting other valid folders
152- log. debug(" Not a valid module reference - $e. message " )
142+ try {
143+ Files . walkFileTree(modulesDir, new SimpleFileVisitor<Path > () {
144+ @Override
145+ FileVisitResult preVisitDirectory (Path dir , BasicFileAttributes attrs ) {
146+ if ( dir == modulesDir ) return FileVisitResult . CONTINUE
147+ if ( Files . exists(dir. resolve(MODULE_INFO_FILE )) ) {
148+ try {
149+ def rel = modulesDir. relativize(dir)
150+ if ( rel. nameCount >= 2 ) {
151+ def reference = ModuleReference . parse(rel. toString())
152+ def installed = getInstalledModule(reference)
153+ if ( installed ) modules. add(installed)
154+ }
155+ } catch (Exception e) {
156+ // Catching exception to go on inspecting other valid folders
157+ log. debug(" Not a valid module reference - $e. message " )
158+ }
159+ return FileVisitResult . SKIP_SUBTREE
153160 }
161+ return FileVisitResult . CONTINUE
154162 }
163+ })
155164 } catch (IOException e) {
156165 log. warn " Failed to scan modules directory ${ modulesDir} : ${ e.message} "
157166 }
0 commit comments