2012-03-30 14:11:13 +00:00
|
|
|
/*
|
2013-03-08 00:25:48 +00:00
|
|
|
* Forge Mod Loader
|
|
|
|
* Copyright (c) 2012-2013 cpw.
|
|
|
|
* All rights reserved. This program and the accompanying materials
|
|
|
|
* are made available under the terms of the GNU Lesser Public License v2.1
|
|
|
|
* which accompanies this distribution, and is available at
|
|
|
|
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
2013-06-14 21:21:49 +00:00
|
|
|
*
|
2013-03-08 00:25:48 +00:00
|
|
|
* Contributors:
|
|
|
|
* cpw - implementation
|
2012-03-30 14:11:13 +00:00
|
|
|
*/
|
2013-03-08 00:25:48 +00:00
|
|
|
|
2014-09-23 05:01:24 +00:00
|
|
|
package net.minecraftforge.fml.common;
|
2012-03-30 14:11:13 +00:00
|
|
|
|
|
|
|
import java.io.File;
|
|
|
|
import java.net.MalformedURLException;
|
2015-02-03 11:21:27 +00:00
|
|
|
import java.net.URI;
|
2012-04-06 13:59:58 +00:00
|
|
|
import java.net.URISyntaxException;
|
2012-03-30 14:11:13 +00:00
|
|
|
import java.net.URL;
|
|
|
|
import java.net.URLClassLoader;
|
2015-02-03 11:21:27 +00:00
|
|
|
import java.util.ArrayList;
|
2015-12-01 18:08:35 +00:00
|
|
|
import java.util.Arrays;
|
2012-07-06 19:59:16 +00:00
|
|
|
import java.util.List;
|
2013-09-25 15:46:11 +00:00
|
|
|
import java.util.Set;
|
2014-09-23 05:01:24 +00:00
|
|
|
|
2013-07-02 22:40:23 +00:00
|
|
|
import net.minecraft.launchwrapper.IClassTransformer;
|
2013-06-14 21:21:49 +00:00
|
|
|
import net.minecraft.launchwrapper.LaunchClassLoader;
|
2014-09-23 05:01:24 +00:00
|
|
|
import net.minecraftforge.fml.common.asm.transformers.ModAPITransformer;
|
|
|
|
import net.minecraftforge.fml.common.discovery.ASMDataTable;
|
2013-06-14 21:21:49 +00:00
|
|
|
|
2015-02-03 11:21:27 +00:00
|
|
|
import org.apache.logging.log4j.Level;
|
|
|
|
|
2012-07-23 19:03:17 +00:00
|
|
|
import com.google.common.collect.ImmutableList;
|
2015-12-01 18:08:35 +00:00
|
|
|
import com.google.common.collect.Lists;
|
2012-07-23 19:03:17 +00:00
|
|
|
|
2012-04-05 20:22:47 +00:00
|
|
|
/**
|
|
|
|
* A simple delegating class loader used to load mods into the system
|
2012-07-06 19:59:16 +00:00
|
|
|
*
|
|
|
|
*
|
2012-04-05 20:22:47 +00:00
|
|
|
* @author cpw
|
|
|
|
*
|
|
|
|
*/
|
2012-04-05 14:07:52 +00:00
|
|
|
public class ModClassLoader extends URLClassLoader
|
|
|
|
{
|
2014-08-02 00:13:53 +00:00
|
|
|
private static final List<String> STANDARD_LIBRARIES = ImmutableList.of("jinput.jar", "lwjgl.jar", "lwjgl_util.jar", "rt.jar");
|
2013-06-14 21:21:49 +00:00
|
|
|
private LaunchClassLoader mainClassLoader;
|
2015-12-01 18:08:35 +00:00
|
|
|
private List<File> sources;
|
2012-03-30 14:11:13 +00:00
|
|
|
|
2012-05-17 19:11:21 +00:00
|
|
|
public ModClassLoader(ClassLoader parent) {
|
|
|
|
super(new URL[0], null);
|
2013-06-14 21:21:49 +00:00
|
|
|
this.mainClassLoader = (LaunchClassLoader)parent;
|
2015-12-30 04:15:03 +00:00
|
|
|
this.sources = Lists.newArrayList();
|
2012-05-17 19:11:21 +00:00
|
|
|
}
|
2012-07-06 19:59:16 +00:00
|
|
|
|
2012-04-05 14:07:52 +00:00
|
|
|
public void addFile(File modFile) throws MalformedURLException
|
|
|
|
{
|
2013-06-26 18:52:56 +00:00
|
|
|
URL url = modFile.toURI().toURL();
|
2012-07-06 19:59:16 +00:00
|
|
|
mainClassLoader.addURL(url);
|
2015-12-01 18:08:35 +00:00
|
|
|
this.sources.add(modFile);
|
2012-07-06 19:59:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public Class<?> loadClass(String name) throws ClassNotFoundException
|
|
|
|
{
|
|
|
|
return mainClassLoader.loadClass(name);
|
2012-04-05 14:07:52 +00:00
|
|
|
}
|
2012-07-06 19:59:16 +00:00
|
|
|
|
2012-04-06 18:23:14 +00:00
|
|
|
public File[] getParentSources() {
|
2012-07-06 19:59:16 +00:00
|
|
|
try
|
|
|
|
{
|
2015-02-03 11:21:27 +00:00
|
|
|
List<File> files=new ArrayList<File>();
|
|
|
|
for(URL url : mainClassLoader.getSources())
|
2012-04-06 13:59:58 +00:00
|
|
|
{
|
2015-02-03 11:21:27 +00:00
|
|
|
URI uri = url.toURI();
|
2015-02-14 02:17:14 +00:00
|
|
|
if(uri.getScheme().equals("file"))
|
2015-02-03 11:21:27 +00:00
|
|
|
{
|
|
|
|
files.add(new File(uri));
|
|
|
|
}
|
2012-04-06 13:59:58 +00:00
|
|
|
}
|
2015-02-03 11:21:27 +00:00
|
|
|
return files.toArray(new File[]{});
|
2012-07-06 19:59:16 +00:00
|
|
|
}
|
|
|
|
catch (URISyntaxException e)
|
|
|
|
{
|
2013-12-16 16:47:48 +00:00
|
|
|
FMLLog.log(Level.ERROR, e, "Unable to process our input to locate the minecraft code");
|
2012-07-06 19:59:16 +00:00
|
|
|
throw new LoaderException(e);
|
2012-04-06 13:59:58 +00:00
|
|
|
}
|
|
|
|
}
|
2012-07-23 19:03:17 +00:00
|
|
|
|
|
|
|
public List<String> getDefaultLibraries()
|
|
|
|
{
|
|
|
|
return STANDARD_LIBRARIES;
|
|
|
|
}
|
2012-08-26 01:57:25 +00:00
|
|
|
|
2015-02-16 01:30:18 +00:00
|
|
|
public boolean isDefaultLibrary(File file)
|
|
|
|
{
|
|
|
|
// Should really pull this from the json somehow, but we dont have that at runtime.
|
|
|
|
String name = file.getName();
|
|
|
|
if (!name.endsWith(".jar")) return false;
|
|
|
|
String[] prefixes =
|
|
|
|
{
|
|
|
|
"launchwrapper-",
|
|
|
|
"asm-all-",
|
|
|
|
"akka-actor_2.11-",
|
|
|
|
"config-",
|
|
|
|
"scala-",
|
|
|
|
"jopt-simple-",
|
|
|
|
"lzma-",
|
|
|
|
"realms-",
|
|
|
|
"httpclient-",
|
|
|
|
"httpcore-",
|
|
|
|
"vecmath-",
|
|
|
|
"trove4j-",
|
|
|
|
"icu4j-core-mojang-",
|
|
|
|
"codecjorbis-",
|
|
|
|
"codecwav-",
|
|
|
|
"libraryjavawound-",
|
|
|
|
"librarylwjglopenal-",
|
|
|
|
"soundsystem-",
|
|
|
|
"netty-all-",
|
2015-12-02 06:01:21 +00:00
|
|
|
"guava-",
|
2015-02-16 01:30:18 +00:00
|
|
|
"commons-lang3-",
|
|
|
|
"commons-compress-",
|
|
|
|
"commons-logging-",
|
|
|
|
"commons-io-",
|
|
|
|
"commons-codec-",
|
|
|
|
"jinput-",
|
|
|
|
"jutils-",
|
|
|
|
"gson-",
|
|
|
|
"authlib-",
|
|
|
|
"log4j-api-",
|
|
|
|
"log4j-core-",
|
|
|
|
"lwjgl-",
|
|
|
|
"lwjgl_util-",
|
|
|
|
"twitch-"
|
|
|
|
};
|
|
|
|
for (String s : prefixes)
|
|
|
|
{
|
|
|
|
if (name.startsWith(s)) return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-09-25 15:46:11 +00:00
|
|
|
public void clearNegativeCacheFor(Set<String> classList)
|
|
|
|
{
|
|
|
|
mainClassLoader.clearNegativeEntries(classList);
|
|
|
|
}
|
2013-10-04 21:20:05 +00:00
|
|
|
|
|
|
|
public ModAPITransformer addModAPITransformer(ASMDataTable dataTable)
|
|
|
|
{
|
2014-09-23 05:01:24 +00:00
|
|
|
mainClassLoader.registerTransformer("net.minecraftforge.fml.common.asm.transformers.ModAPITransformer");
|
2013-10-04 21:20:05 +00:00
|
|
|
List<IClassTransformer> transformers = mainClassLoader.getTransformers();
|
|
|
|
ModAPITransformer modAPI = (ModAPITransformer) transformers.get(transformers.size()-1);
|
|
|
|
modAPI.initTable(dataTable);
|
|
|
|
return modAPI;
|
|
|
|
}
|
2015-12-01 18:08:35 +00:00
|
|
|
|
|
|
|
List<URL> parentURLs = null;
|
|
|
|
public boolean containsSource(File source)
|
|
|
|
{
|
|
|
|
if (parentURLs == null) {
|
|
|
|
parentURLs = Arrays.asList(mainClassLoader.getURLs());
|
|
|
|
}
|
|
|
|
try
|
|
|
|
{
|
|
|
|
return parentURLs.contains(source.toURI().toURL());
|
|
|
|
} catch (MalformedURLException e)
|
|
|
|
{
|
|
|
|
// shouldn't happen
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2012-03-30 14:11:13 +00:00
|
|
|
}
|