forked from I2P_Developers/i2p.i2p
Console: Java 9 fixes for classloader (ticket #1870)
May not be sufficient for plugins Unlinkify viewmtn links on /jars, site is down
This commit is contained in:
@ -33,22 +33,26 @@ public class FileDumpHelper extends HelperBase {
|
||||
"<th>JDK</th><th>Built</th><th>By</th><th>Mods</th></tr>");
|
||||
|
||||
// jars added in wrapper.config
|
||||
URLClassLoader urlClassLoader = (URLClassLoader) ClassLoader.getSystemClassLoader();
|
||||
URL[] urls = urlClassLoader.getURLs();
|
||||
List<File> flist = new ArrayList<File>();
|
||||
for (int i = 0; i < urls.length; i++) {
|
||||
String p = urls[i].toString();
|
||||
if (p.startsWith("file:") && p.endsWith(".jar")) {
|
||||
p = p.substring(5);
|
||||
if (!(p.startsWith(_context.getBaseDir().getAbsolutePath()) ||
|
||||
p.startsWith(_context.getConfigDir().getAbsolutePath()))) {
|
||||
flist.add(new File(p));
|
||||
ClassLoader loader = ClassLoader.getSystemClassLoader();
|
||||
if (loader instanceof URLClassLoader) {
|
||||
// through Java 8, not available in Java 9
|
||||
URLClassLoader urlClassLoader = (URLClassLoader) loader;
|
||||
URL[] urls = urlClassLoader.getURLs();
|
||||
List<File> flist = new ArrayList<File>();
|
||||
for (int i = 0; i < urls.length; i++) {
|
||||
String p = urls[i].toString();
|
||||
if (p.startsWith("file:") && p.endsWith(".jar")) {
|
||||
p = p.substring(5);
|
||||
if (!(p.startsWith(_context.getBaseDir().getAbsolutePath()) ||
|
||||
p.startsWith(_context.getConfigDir().getAbsolutePath()))) {
|
||||
flist.add(new File(p));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Collections.sort(flist);
|
||||
for (File f : flist) {
|
||||
dumpFile(buf, f);
|
||||
Collections.sort(flist);
|
||||
for (File f : flist) {
|
||||
dumpFile(buf, f);
|
||||
}
|
||||
}
|
||||
|
||||
// our jars
|
||||
@ -123,11 +127,13 @@ public class FileDumpHelper extends HelperBase {
|
||||
if (s != null && s.length() > 20) {
|
||||
if (iv != null)
|
||||
buf.append("<br>");
|
||||
buf.append("<a href=\"http://killyourtv.i2p/viewmtn/revision/info/").append(s)
|
||||
.append("\">" +
|
||||
"<tt>").append(s.substring(0, 20)).append("</tt>" +
|
||||
// fix and uncomment if a reliable viewmtn host appears
|
||||
//buf.append("<a href=\"http://killyourtv.i2p/viewmtn/revision/info/").append(s)
|
||||
// .append("\">");
|
||||
buf.append("<tt>").append(s.substring(0, 20)).append("</tt>" +
|
||||
"<br>" +
|
||||
"<tt>").append(s.substring(20)).append("</tt></a>");
|
||||
"<tt>").append(s.substring(20)).append("</tt>");
|
||||
//buf.append("</tt>");
|
||||
}
|
||||
buf.append("</td><td>");
|
||||
s = getAtt(att, "Created-By");
|
||||
|
@ -434,8 +434,12 @@ public class PluginStarter implements Runnable {
|
||||
if (f.getName().endsWith(".jar")) {
|
||||
try {
|
||||
addPath(f.toURI().toURL());
|
||||
log.error("INFO: Adding translation plugin to classpath: " + f);
|
||||
log.info("INFO: Adding translation plugin to classpath: " + f);
|
||||
added = true;
|
||||
} catch (ClassCastException e) {
|
||||
log.logAlways(Log.WARN, "Java version: " + System.getProperty("java.version") +
|
||||
" does not support adding classpath element: " + f +
|
||||
" for plugin " + appName);
|
||||
} catch (RuntimeException e) {
|
||||
log.error("Plugin " + appName + " bad classpath element: " + f, e);
|
||||
}
|
||||
@ -987,6 +991,8 @@ public class PluginStarter implements Runnable {
|
||||
|
||||
/**
|
||||
* http://jimlife.wordpress.com/2007/12/19/java-adding-new-classpath-at-runtime/
|
||||
*
|
||||
* @throws ClassCastException in Java 9
|
||||
*/
|
||||
private static void addPath(URL u) throws Exception {
|
||||
URLClassLoader urlClassLoader = (URLClassLoader) ClassLoader.getSystemClassLoader();
|
||||
|
@ -110,7 +110,7 @@ public class WebAppConfiguration implements Configuration {
|
||||
return;
|
||||
StringTokenizer tok = new StringTokenizer(cp, " ,");
|
||||
StringBuilder buf = new StringBuilder();
|
||||
Set<URI> systemCP = getSystemClassPath();
|
||||
Set<URI> systemCP = getSystemClassPath(i2pContext);
|
||||
while (tok.hasMoreTokens()) {
|
||||
if (buf.length() > 0)
|
||||
buf.append(',');
|
||||
@ -159,14 +159,28 @@ public class WebAppConfiguration implements Configuration {
|
||||
* but keep findbugs happy.
|
||||
* @since 0.9
|
||||
*/
|
||||
private static Set<URI> getSystemClassPath() {
|
||||
URLClassLoader urlClassLoader = (URLClassLoader) ClassLoader.getSystemClassLoader();
|
||||
URL urls[] = urlClassLoader.getURLs();
|
||||
private static Set<URI> getSystemClassPath(I2PAppContext ctx) {
|
||||
Set<URI> rv = new HashSet<URI>(32);
|
||||
for (int i = 0; i < urls.length; i++) {
|
||||
try {
|
||||
rv.add(urls[i].toURI());
|
||||
} catch (URISyntaxException use) {}
|
||||
ClassLoader loader = ClassLoader.getSystemClassLoader();
|
||||
if (loader instanceof URLClassLoader) {
|
||||
// through Java 8, not available in Java 9
|
||||
URLClassLoader urlClassLoader = (URLClassLoader) loader;
|
||||
URL urls[] = urlClassLoader.getURLs();
|
||||
for (int i = 0; i < urls.length; i++) {
|
||||
try {
|
||||
rv.add(urls[i].toURI());
|
||||
} catch (URISyntaxException use) {}
|
||||
}
|
||||
} else {
|
||||
// Java 9 - assume everything in lib/ is in the classpath
|
||||
File libDir = new File(ctx.getBaseDir(), "lib");
|
||||
File[] files = libDir.listFiles();
|
||||
if (files != null) {
|
||||
for (int i = 0; i < files.length; i++) {
|
||||
if (files[i].getName().endsWith(".jar"))
|
||||
rv.add(files[i].toURI());
|
||||
}
|
||||
}
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
Reference in New Issue
Block a user