groovy-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pascalschumac...@apache.org
Subject incubator-groovy git commit: Fix Groovysh Test failure under Java9, due to new virtual Filesystem structure (closes #107)
Date Tue, 01 Sep 2015 17:16:04 GMT
Repository: incubator-groovy
Updated Branches:
  refs/heads/GROOVY_2_4_X 070a43df7 -> 6fb797a3f


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/6fb797a3
Tree: http://git-wip-us.apache.org/repos/asf/incubator-groovy/tree/6fb797a3
Diff: http://git-wip-us.apache.org/repos/asf/incubator-groovy/diff/6fb797a3

Branch: refs/heads/GROOVY_2_4_X
Commit: 6fb797a3f054a02b8dac5d2458fca6519f0ae0e0
Parents: 070a43d
Author: Thibault Kruse <thibault.kruse@gmx.de>
Authored: Tue Sep 1 12:28:18 2015 +0200
Committer: pascalschumacher <pascalschumacher@gmx.net>
Committed: Tue Sep 1 19:15:38 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/6fb797a3/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 {


Mime
View raw message