mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2025-07-03 00:15:35 +00:00
fix bootstrap addon class referencing from addons
This commit is contained in:
parent
ffc884384c
commit
83baf377e0
@ -1,32 +0,0 @@
|
|||||||
/*
|
|
||||||
* This file is part of Terra.
|
|
||||||
*
|
|
||||||
* Terra is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* Terra is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with Terra. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.dfsek.terra.addon;
|
|
||||||
|
|
||||||
import java.net.URL;
|
|
||||||
import java.net.URLClassLoader;
|
|
||||||
|
|
||||||
|
|
||||||
public class AddonClassLoader extends URLClassLoader {
|
|
||||||
static {
|
|
||||||
ClassLoader.registerAsParallelCapable();
|
|
||||||
}
|
|
||||||
|
|
||||||
public AddonClassLoader(URL[] urls, ClassLoader parent) {
|
|
||||||
super(urls, parent);
|
|
||||||
}
|
|
||||||
}
|
|
@ -44,7 +44,7 @@ public class BootstrapAddonLoader implements BootstrapBaseAddon<BootstrapBaseAdd
|
|||||||
|
|
||||||
public BootstrapAddonLoader() { }
|
public BootstrapAddonLoader() { }
|
||||||
|
|
||||||
private BootstrapBaseAddon<?> loadAddon(Path addonPath, ClassLoader parent) {
|
private BootstrapBaseAddon<?> loadAddon(Path addonPath, BootstrapAddonClassLoader parent) {
|
||||||
logger.debug("Loading bootstrap addon from JAR {}", addonPath);
|
logger.debug("Loading bootstrap addon from JAR {}", addonPath);
|
||||||
try(JarFile jar = new JarFile(addonPath.toFile())) {
|
try(JarFile jar = new JarFile(addonPath.toFile())) {
|
||||||
String entry = jar.getManifest().getMainAttributes().getValue("Terra-Bootstrap-Addon-Entry-Point");
|
String entry = jar.getManifest().getMainAttributes().getValue("Terra-Bootstrap-Addon-Entry-Point");
|
||||||
@ -55,10 +55,8 @@ public class BootstrapAddonLoader implements BootstrapBaseAddon<BootstrapBaseAdd
|
|||||||
|
|
||||||
//noinspection NestedTryStatement
|
//noinspection NestedTryStatement
|
||||||
try {
|
try {
|
||||||
@SuppressWarnings({ "resource", "IOResourceOpenedButNotSafelyClosed" })
|
parent.addURL(addonPath.toUri().toURL());
|
||||||
AddonClassLoader loader = new AddonClassLoader(new URL[]{ addonPath.toUri().toURL() }, parent);
|
Object addonObject = parent.loadClass(entry).getConstructor().newInstance();
|
||||||
|
|
||||||
Object addonObject = loader.loadClass(entry).getConstructor().newInstance();
|
|
||||||
|
|
||||||
if(!(addonObject instanceof BootstrapBaseAddon<?> addon)) {
|
if(!(addonObject instanceof BootstrapBaseAddon<?> addon)) {
|
||||||
throw new AddonLoadException(
|
throw new AddonLoadException(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user