You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by pa...@apache.org on 2015/09/01 19:14:46 UTC

incubator-groovy git commit: Fix Groovysh Test failure under Java9, due to new virtual Filesystem structure (closes #107)

Repository: incubator-groovy
Updated Branches:
  refs/heads/master ed469e6cf -> 82430d76a


Fix Groovysh Test failure under Java9, due to new virtual Filesystem structure (closes #107)


Project: http://git-wip-us.apache.org/repos/asf/incubator-groovy/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-groovy/commit/82430d76
Tree: http://git-wip-us.apache.org/repos/asf/incubator-groovy/tree/82430d76
Diff: http://git-wip-us.apache.org/repos/asf/incubator-groovy/diff/82430d76

Branch: refs/heads/master
Commit: 82430d76ac96777f6c73c6bcdb7c099163ae738d
Parents: ed469e6
Author: Thibault Kruse <th...@gmx.de>
Authored: Tue Sep 1 12:28:18 2015 +0200
Committer: pascalschumacher <pa...@gmx.net>
Committed: Tue Sep 1 19:14:01 2015 +0200

----------------------------------------------------------------------
 .../tools/shell/util/PackageHelperImpl.groovy   | 38 +++++++++++---------
 1 file changed, 21 insertions(+), 17 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-groovy/blob/82430d76/subprojects/groovy-groovysh/src/main/groovy/org/codehaus/groovy/tools/shell/util/PackageHelperImpl.groovy
----------------------------------------------------------------------
diff --git a/subprojects/groovy-groovysh/src/main/groovy/org/codehaus/groovy/tools/shell/util/PackageHelperImpl.groovy b/subprojects/groovy-groovysh/src/main/groovy/org/codehaus/groovy/tools/shell/util/PackageHelperImpl.groovy
index f049270..659a16c 100644
--- a/subprojects/groovy-groovysh/src/main/groovy/org/codehaus/groovy/tools/shell/util/PackageHelperImpl.groovy
+++ b/subprojects/groovy-groovysh/src/main/groovy/org/codehaus/groovy/tools/shell/util/PackageHelperImpl.groovy
@@ -108,8 +108,9 @@ class PackageHelperImpl implements PreferenceChangeListener, PackageHelper {
             }
         }
         if (jigsaw) {
-            Set<String> jigsawPackages = getPackagesAndClassesFromJigsaw()
-            mergeNewPackages(jigsawPackages,URI.create("jrt:/").toURL(), rootPackages)
+            URL jigsawURL = URI.create("jrt:/").toURL()
+            Set<String> jigsawPackages = getPackagesAndClassesFromJigsaw(jigsawURL)  { isPackage, name -> isPackage && name }
+            mergeNewPackages(jigsawPackages, jigsawURL, rootPackages)
         }
         return rootPackages
     }
@@ -120,23 +121,26 @@ class PackageHelperImpl implements PreferenceChangeListener, PackageHelper {
      * to JDK 7+ when building the Groovysh module (uses nio2)
      * @return
      */
-    private static Set<String> getPackagesAndClassesFromJigsaw(Closure<Boolean> predicate = { isPackage, name -> isPackage && name }) {
+    private static Set<String> getPackagesAndClassesFromJigsaw(URL jigsawURL, Closure<Boolean> predicate) {
         def shell = new GroovyShell()
         shell.setProperty('predicate', predicate)
+        String jigsawURLString = jigsawURL.toString()
+        shell.setProperty('jigsawURLString', jigsawURLString)
         shell.evaluate '''import java.nio.file.*
 
-def fs = FileSystems.newFileSystem(URI.create("jrt:/"), [:])
+def fs = FileSystems.newFileSystem(URI.create(jigsawURLString), [:])
 
 result = [] as Set
 
 def filterPackageName(Path path) {
     def elems = "$path".split('/')
 
-    if (elems) {
+    if (elems && elems.length > 2) {
+        // remove e.g. 'modules/java.base/
         elems = elems[2..<elems.length]
 
         def name = elems.join('.')
-        if (predicate(true,name)) {
+        if (predicate(true, name)) {
             result << name
         }
     }
@@ -145,26 +149,26 @@ def filterPackageName(Path path) {
 def filterClassName(Path path) {
     def elems = "$path".split('/')
 
-    if (elems) {
+    if (elems && elems.length > 2) {
+        // remove e.g. 'modules/java.base/
         elems = elems[2..<elems.length]
 
         def name = elems.join('.')
         if (name.endsWith('.class')) {
-            name = name.substring(0,name.lastIndexOf('.'))
-            if (predicate(false,name)) {
+            name = name.substring(0, name.lastIndexOf('.'))
+            if (predicate(false, name)) {
                 result << name
             }
         }
     }
 }
 
-fs.rootDirectories.each {
-    Files.walkFileTree(it,
-            [preVisitDirectory: { dir, attrs -> filterPackageName(dir); FileVisitResult.CONTINUE },
-             visitFile: { file, attrs -> filterClassName(file); FileVisitResult.CONTINUE}
-            ]
-                    as SimpleFileVisitor)
-}
+// walk each file and directory, possibly storing directories as packages, and files as classes
+Files.walkFileTree(fs.getPath('modules'),
+        [preVisitDirectory: { dir, attrs -> filterPackageName(dir); FileVisitResult.CONTINUE },
+         visitFile: { file, attrs -> filterClassName(file); FileVisitResult.CONTINUE}
+        ]
+            as SimpleFileVisitor)
 '''
 
         Set<String> jigsawPackages = (Set<String>) shell.getProperty('result')
@@ -374,7 +378,7 @@ fs.rootDirectories.each {
         for (Iterator it = urls.iterator(); it.hasNext();) {
             URL url = (URL) it.next()
             if (url.protocol=='jrt') {
-                getPackagesAndClassesFromJigsaw { boolean isPackage, String name ->
+                getPackagesAndClassesFromJigsaw(url) { boolean isPackage, String name ->
                     !isPackage && name.startsWith(packagename)
                 }.collect(classes) { it - "${packagename}." }
             } else {