Skip to content

Commit

Permalink
get classpath from urlclassloader logic added
Browse files Browse the repository at this point in the history
  • Loading branch information
pfmiles committed Aug 15, 2013
1 parent 76f3626 commit 5bcc7d3
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions src/main/java/com/github/pfmiles/dropincc/impl/util/Util.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

import java.io.File;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
Expand Down Expand Up @@ -222,15 +223,14 @@ public static String join(String joint, List<String> elements) {
}

/**
* build the classpath using all properties with suffix 'class.path'; to
* make some software setting its own class path variables happy(like
* maven-surfire plugin). XXX dirty classpath hacking to make java compiler
* API happy...
* Analyze class path for hot compilation
*
* @return
*/
public static String getClassPath() {
StringBuilder sb = new StringBuilder();

// include classpath system properties
for (Map.Entry<Object, Object> e : System.getProperties().entrySet()) {
String k = (String) e.getKey();
if (k.endsWith("class.path")) {
Expand All @@ -239,6 +239,21 @@ public static String getClassPath() {
sb.append(e.getValue());
}
}

// if url class loader, include all classpath urls
ClassLoader loader = getParentClsLoader();
if (loader instanceof URLClassLoader) {
for (URL url : ((URLClassLoader) loader).getURLs()) {
String dropinccPath = url.getPath();
if (dropinccPath != null && !"".equals(dropinccPath) && sb.indexOf(dropinccPath) == -1) {
if (sb.length() != 0)
sb.append(File.pathSeparator);
sb.append(dropinccPath);
}
}
}

// include paths analyzed from file system
URL url = Util.class.getResource("Util.class");
if (url != null) {
String dropinccPath = null;
Expand Down

0 comments on commit 5bcc7d3

Please sign in to comment.