Add the language providers to the main classloader as well, so
their resources are available to other classes.. Signed-off-by: cpw <cpw+github@weeksfamily.ca>
This commit is contained in:
parent
2ec74e5c22
commit
78455ac3c0
2 changed files with 12 additions and 7 deletions
|
@ -68,8 +68,8 @@ public abstract class FMLCommonLaunchHandler
|
||||||
|
|
||||||
public void configureTransformationClassLoader(final ITransformingClassLoaderBuilder builder) {
|
public void configureTransformationClassLoader(final ITransformingClassLoaderBuilder builder) {
|
||||||
builder.addTransformationPath(FMLLoader.getForgePath());
|
builder.addTransformationPath(FMLLoader.getForgePath());
|
||||||
for (Path path : FMLLoader.getMCPaths())
|
Arrays.stream(FMLLoader.getMCPaths()).forEach(builder::addTransformationPath);
|
||||||
builder.addTransformationPath(path);
|
FMLLoader.getLanguageLoadingProvider().getLibraries().forEach(builder::addTransformationPath);
|
||||||
builder.setClassBytesLocator(getClassLoaderLocatorFunction());
|
builder.setClassBytesLocator(getClassLoaderLocatorFunction());
|
||||||
builder.setManifestLocator(getClassLoaderManifestLocatorFunction());
|
builder.setManifestLocator(getClassLoaderManifestLocatorFunction());
|
||||||
}
|
}
|
||||||
|
|
|
@ -51,6 +51,7 @@ public class LanguageLoadingProvider
|
||||||
private final List<IModLanguageProvider> languageProviders = new ArrayList<>();
|
private final List<IModLanguageProvider> languageProviders = new ArrayList<>();
|
||||||
private final ServiceLoader<IModLanguageProvider> serviceLoader;
|
private final ServiceLoader<IModLanguageProvider> serviceLoader;
|
||||||
private final Map<String, ModLanguageWrapper> languageProviderMap = new HashMap<>();
|
private final Map<String, ModLanguageWrapper> languageProviderMap = new HashMap<>();
|
||||||
|
private List<Path> languagePaths = new ArrayList<>();
|
||||||
|
|
||||||
public void forEach(final Consumer<IModLanguageProvider> consumer)
|
public void forEach(final Consumer<IModLanguageProvider> consumer)
|
||||||
{
|
{
|
||||||
|
@ -60,13 +61,13 @@ public class LanguageLoadingProvider
|
||||||
private static class ModLanguageWrapper {
|
private static class ModLanguageWrapper {
|
||||||
|
|
||||||
private final IModLanguageProvider modLanguageProvider;
|
private final IModLanguageProvider modLanguageProvider;
|
||||||
|
|
||||||
private final ArtifactVersion version;
|
private final ArtifactVersion version;
|
||||||
public ModLanguageWrapper(IModLanguageProvider modLanguageProvider, ArtifactVersion version)
|
public ModLanguageWrapper(IModLanguageProvider modLanguageProvider, ArtifactVersion version)
|
||||||
{
|
{
|
||||||
this.modLanguageProvider = modLanguageProvider;
|
this.modLanguageProvider = modLanguageProvider;
|
||||||
this.version = version;
|
this.version = version;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ArtifactVersion getVersion()
|
public ArtifactVersion getVersion()
|
||||||
{
|
{
|
||||||
return version;
|
return version;
|
||||||
|
@ -77,14 +78,15 @@ public class LanguageLoadingProvider
|
||||||
return modLanguageProvider;
|
return modLanguageProvider;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
private static class LanguageClassLoader extends URLClassLoader
|
private static class LanguageClassLoader extends URLClassLoader
|
||||||
{
|
{
|
||||||
|
|
||||||
public LanguageClassLoader() {
|
public LanguageClassLoader() {
|
||||||
super(new URL[0]);
|
super(new URL[0]);
|
||||||
}
|
}
|
||||||
@Override
|
|
||||||
|
@Override
|
||||||
public void addURL(final URL url) {
|
public void addURL(final URL url) {
|
||||||
LOGGER.debug(CORE, "Adding {} to languageloader classloader", url);
|
LOGGER.debug(CORE, "Adding {} to languageloader classloader", url);
|
||||||
super.addURL(url);
|
super.addURL(url);
|
||||||
|
@ -96,7 +98,6 @@ public class LanguageLoadingProvider
|
||||||
serviceLoader = ServiceLoader.load(IModLanguageProvider.class, languageClassLoader);
|
serviceLoader = ServiceLoader.load(IModLanguageProvider.class, languageClassLoader);
|
||||||
loadLanguageProviders();
|
loadLanguageProviders();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void loadLanguageProviders() {
|
private void loadLanguageProviders() {
|
||||||
LOGGER.debug(CORE, "Found {} language providers", ServiceLoaderStreamUtils.toList(serviceLoader).size());
|
LOGGER.debug(CORE, "Found {} language providers", ServiceLoaderStreamUtils.toList(serviceLoader).size());
|
||||||
serviceLoader.forEach(languageProviders::add);
|
serviceLoader.forEach(languageProviders::add);
|
||||||
|
@ -133,7 +134,7 @@ public class LanguageLoadingProvider
|
||||||
private void addLanguagePaths(final Stream<Path> langPaths) {
|
private void addLanguagePaths(final Stream<Path> langPaths) {
|
||||||
languageProviders.clear();
|
languageProviders.clear();
|
||||||
languageProviderMap.clear();
|
languageProviderMap.clear();
|
||||||
langPaths.map(Path::toFile).map(File::toURI).map(rethrowFunction(URI::toURL)).forEach(languageClassLoader::addURL);
|
langPaths.peek(languagePaths::add).map(Path::toFile).map(File::toURI).map(rethrowFunction(URI::toURL)).forEach(languageClassLoader::addURL);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addAdditionalLanguages(List<ModFile> modFiles)
|
public void addAdditionalLanguages(List<ModFile> modFiles)
|
||||||
|
@ -145,6 +146,10 @@ public class LanguageLoadingProvider
|
||||||
loadLanguageProviders();
|
loadLanguageProviders();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Stream<Path> getLibraries() {
|
||||||
|
return languagePaths.stream();
|
||||||
|
}
|
||||||
|
|
||||||
public IModLanguageProvider findLanguage(ModFile mf, String modLoader, VersionRange modLoaderVersion) {
|
public IModLanguageProvider findLanguage(ModFile mf, String modLoader, VersionRange modLoaderVersion) {
|
||||||
final String languageFileName = mf.getLocator() instanceof ExplodedDirectoryLocator ? "in-development" : mf.getFileName();
|
final String languageFileName = mf.getLocator() instanceof ExplodedDirectoryLocator ? "in-development" : mf.getFileName();
|
||||||
final ModLanguageWrapper mlw = languageProviderMap.get(modLoader);
|
final ModLanguageWrapper mlw = languageProviderMap.get(modLoader);
|
||||||
|
|
Loading…
Reference in a new issue