]> source.dussan.org Git - aspectj.git/commitdiff
Smarter classpath detection on Java9
authorAndy Clement <aclement@pivotal.io>
Wed, 27 Sep 2017 21:46:47 +0000 (14:46 -0700)
committerAndy Clement <aclement@pivotal.io>
Wed, 27 Sep 2017 21:46:47 +0000 (14:46 -0700)
On Java9 cannot rely on URLClassLoader being found from which
to determine classpath so use the environment variable. This may
have issues if loaders are being constructed that specifically
deviate from the java.class.path.

weaver/src/org/aspectj/weaver/tools/WeavingAdaptor.java

index d0e24f8b27a27c30c252f6b229fe3a6a2958ed0e..c372afc83b44dfe57b11e5ffb34c7b0662245c64 100644 (file)
@@ -20,7 +20,17 @@ import java.io.PrintWriter;
 import java.net.URL;
 import java.net.URLClassLoader;
 import java.security.ProtectionDomain;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+import java.util.Set;
+import java.util.StringTokenizer;
 
 import org.aspectj.bridge.AbortException;
 import org.aspectj.bridge.IMessage;
@@ -134,11 +144,20 @@ public class WeavingAdaptor implements IMessageContext {
                                warn("cannot determine classpath");
                        }
                }
-               list.addAll(0, makeClasspath(System.getProperty("sun.boot.class.path")));
-               // On Java9 the sun.boot.class.path won't be set. System classes accessible through JRT filesystem 
+               // On Java9 it is possible to fail to find a URLClassLoader from which to derive a suitable classpath
+               // For now we can determine it from the java.class.path:
         if (LangUtil.is19VMOrGreater()) {
-                       list.add(0, LangUtil.getJrtFsFilePath());
+                       list.add(0, LangUtil.getJrtFsFilePath());
+                       List<String> javaClassPathEntries = makeClasspath(System.getProperty("java.class.path"));
+                       for (int i=javaClassPathEntries.size()-1;i>=0;i--) {
+                               String javaClassPathEntry = javaClassPathEntries.get(i);
+                               if (!list.contains(javaClassPathEntry)) {
+                                       list.add(0,javaClassPathEntry);
+                               }
+                       }
         }
+               // On Java9 the sun.boot.class.path won't be set. System classes accessible through JRT filesystem 
+               list.addAll(0, makeClasspath(System.getProperty("sun.boot.class.path")));
                return list;
        }