From: Andy Clement Date: Wed, 27 Sep 2017 21:46:47 +0000 (-0700) Subject: Smarter classpath detection on Java9 X-Git-Tag: V1_9_0_RC3~2^2~49 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=23ee46988073b56e041aaabc05ff9d436732d6fe;p=aspectj.git Smarter classpath detection on Java9 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. --- diff --git a/weaver/src/org/aspectj/weaver/tools/WeavingAdaptor.java b/weaver/src/org/aspectj/weaver/tools/WeavingAdaptor.java index d0e24f8b2..c372afc83 100644 --- a/weaver/src/org/aspectj/weaver/tools/WeavingAdaptor.java +++ b/weaver/src/org/aspectj/weaver/tools/WeavingAdaptor.java @@ -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 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; }