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;
modClassLoader = new ModClassLoader();
log.fine("Attempting to load mods contained in the minecraft jar file");
File minecraftSource=modClassLoader.getParentSource();
if (minecraftSource.isFile()) {
log.fine(String.format("Minecraft is a file at %s, loading",minecraftSource.getName()));
attemptFileLoad(minecraftSource);
} else if (minecraftSource.isDirectory()) {
log.fine(String.format("Minecraft is a directory at %s, loading",minecraftSource.getName()));
attemptDirLoad(minecraftSource);
log.fine("Attempting to load mods contained in the minecraft jar file and associated classes");
File[] minecraftSources=modClassLoader.getParentSources();
if (minecraftSources.length==1 && minecraftSources[0].isFile()) {
log.fine(String.format("Minecraft is a file at %s, loading",minecraftSources[0].getAbsolutePath()));
attemptFileLoad(minecraftSources[0]);
} else {
log.severe(String.format("Unable to locate minecraft data at %s\n",minecraftSource.getName()));
throw new LoaderException();
for (int i=0; i<minecraftSources.length; i++) {
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");

View file

@ -52,18 +52,22 @@ public class ModClassLoader extends URLClassLoader
}
}
public File getParentSource() {
public File[] getParentSources() {
ClassLoader cl=getParent();
if (cl instanceof URLClassLoader) {
URLClassLoader ucl=(URLClassLoader) cl;
URL pUrl=ucl.getURLs()[0];
URL[] pUrl=ucl.getURLs();
File[] sources=new File[pUrl.length];
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)
{
// NOOP
Loader.log.throwing("ModClassLoader", "getParentSources", e);
}
}
Loader.log.severe("Unable to process our input to locate the minecraft code");