blackdrag commented on a change in pull request #1171: GROOVY-9416: Avoid 
unnecessary looking up non default import classes …
URL: https://github.com/apache/groovy/pull/1171#discussion_r382998864
 
 

 ##########
 File path: src/main/java/org/codehaus/groovy/vmplugin/v9/Java9.java
 ##########
 @@ -81,15 +91,40 @@
         result.putAll(doFindClasses(URI.create("jrt:/modules/java.base/"), 
"java", javaPns));
 
         try {
-            URI gsLocation = 
DefaultGroovyMethods.getLocation(GroovySystem.class).toURI();
-            result.putAll(doFindClasses(gsLocation, "groovy", groovyPns));
+            List<URI> foundURIList = new LinkedList<>();
+            result.putAll(doFindGroovyClasses("groovy.lang.GroovySystem", 
groovyPns, foundURIList));
+
+            // in user production environment, Groovy core classes, e.g. 
`GroovySystem`(java class) and `GrapeIvy`(groovy class) are all packaged in the 
groovy core jar file,
+            // but in Groovy development environment, Groovy core classes are 
distributed in different directories
+            result.putAll(doFindGroovyClasses("groovy.grape.GrapeIvy", 
groovyPns, foundURIList));
         } catch (Exception e) {
-            System.err.println("[WARNING] Failed to get default imported 
groovy classes: " + e.getMessage());
+            throw new GroovyBugError("Failed to get default imported groovy 
classes", e);
         }
 
         return result;
     }
 
+    private Map<String, Set<String>> doFindGroovyClasses(String cn, 
List<String> groovyPns, List<URI> foundURIList) throws URISyntaxException {
+        GroovyClassLoader groovyClassLoader = new GroovyClassLoader();
+        URI classpathEntryURI;
+        try {
+            Class<?> clazz = groovyClassLoader.loadClass(cn);
+            classpathEntryURI = 
DefaultGroovyMethods.getLocation(clazz).toURI();
 
 Review comment:
   > As 2 groovy elders worry about the impact of the PR, I close it now.
   > Thanks for your revewing ;-)
   
   I think the general idea is good, just I think we cannot rely on the cache 
in case of a miss. Could we forbid people putting classes in groovy.lang? In 
theory if we want to take the module system seriously then all the packages we 
use in core should be taboo for the users or else they would get the split 
package problem. But that also means to not allow people to fallback to the 
classpath environment / anonymous module Groovy actually needs atm. Such a 
decision should be done on the list.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to