Try multiple "jar" sources- for eclipse testing

This commit is contained in:
Christian Weeks 2012-04-06 14:23:14 -04:00
parent a858478b92
commit 040a1d8cf7
2 changed files with 22 additions and 14 deletions

View file

@ -326,17 +326,21 @@ public class Loader
state = State.LOADING; state = State.LOADING;
modClassLoader = new ModClassLoader(); modClassLoader = new ModClassLoader();
log.fine("Attempting to load mods contained in the minecraft jar file"); log.fine("Attempting to load mods contained in the minecraft jar file and associated classes");
File minecraftSource=modClassLoader.getParentSource(); File[] minecraftSources=modClassLoader.getParentSources();
if (minecraftSource.isFile()) { if (minecraftSources.length==1 && minecraftSources[0].isFile()) {
log.fine(String.format("Minecraft is a file at %s, loading",minecraftSource.getName())); log.fine(String.format("Minecraft is a file at %s, loading",minecraftSources[0].getAbsolutePath()));
attemptFileLoad(minecraftSource); attemptFileLoad(minecraftSources[0]);
} else if (minecraftSource.isDirectory()) {
log.fine(String.format("Minecraft is a directory at %s, loading",minecraftSource.getName()));
attemptDirLoad(minecraftSource);
} else { } else {
log.severe(String.format("Unable to locate minecraft data at %s\n",minecraftSource.getName())); for (int i=0; i<minecraftSources.length; i++) {
throw new LoaderException(); if (minecraftSources[i].isFile()) {
log.fine(String.format("Found a minecraft related file at %s, loading",minecraftSources[i].getAbsolutePath()));
attemptFileLoad(minecraftSources[i]);
} else if (minecraftSources[i].isDirectory()) {
log.fine(String.format("Found a minecraft related directory at %s, loading",minecraftSources[i].getAbsolutePath()));
attemptDirLoad(minecraftSources[i]);
}
}
} }
log.fine("Minecraft jar mods loaded successfully"); log.fine("Minecraft jar mods loaded successfully");

View file

@ -52,18 +52,22 @@ public class ModClassLoader extends URLClassLoader
} }
} }
public File getParentSource() { public File[] getParentSources() {
ClassLoader cl=getParent(); ClassLoader cl=getParent();
if (cl instanceof URLClassLoader) { if (cl instanceof URLClassLoader) {
URLClassLoader ucl=(URLClassLoader) cl; URLClassLoader ucl=(URLClassLoader) cl;
URL pUrl=ucl.getURLs()[0]; URL[] pUrl=ucl.getURLs();
File[] sources=new File[pUrl.length];
try try
{ {
return new File(pUrl.toURI()); for (int i=0; i<pUrl.length; i++) {
sources[i]=new File(pUrl[i].toURI());
}
return sources;
} }
catch (URISyntaxException e) catch (URISyntaxException e)
{ {
// NOOP Loader.log.throwing("ModClassLoader", "getParentSources", e);
} }
} }
Loader.log.severe("Unable to process our input to locate the minecraft code"); Loader.log.severe("Unable to process our input to locate the minecraft code");