mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2025-08-16 08:15:50 +00:00
remove unnecessary classpath injections
This commit is contained in:
parent
0648cfd3fa
commit
a610d0a7a9
@ -21,13 +21,10 @@ package com.volmit.iris.core.tools;
|
||||
import com.volmit.iris.core.loader.IrisData;
|
||||
import com.volmit.iris.engine.object.*;
|
||||
import com.volmit.iris.engine.platform.BukkitChunkGenerator;
|
||||
import com.volmit.iris.util.reflect.WrappedField;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.WorldCreator;
|
||||
import org.bukkit.WorldType;
|
||||
import org.bukkit.generator.ChunkGenerator;
|
||||
import sun.misc.Unsafe;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
|
@ -19,6 +19,7 @@
|
||||
package com.volmit.iris.util.collection;
|
||||
|
||||
import com.google.common.util.concurrent.AtomicDoubleArray;
|
||||
import com.volmit.iris.util.function.NastyFunction;
|
||||
import com.volmit.iris.util.json.JSONArray;
|
||||
import com.volmit.iris.util.math.M;
|
||||
import com.volmit.iris.util.math.RNG;
|
||||
@ -306,6 +307,18 @@ public class KList<T> extends ArrayList<T> implements List<T> {
|
||||
return v;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert this list into another list type. Such as GList<Integer> to
|
||||
* GList<String>. list.convertNasty((i) -> "" + i);
|
||||
*/
|
||||
public <V> KList<V> convertNasty(NastyFunction<T, V> converter) throws Throwable {
|
||||
KList<V> v = new KList<V>(size());
|
||||
for (final var t : this) {
|
||||
v.addNonNull(converter.run(t));
|
||||
}
|
||||
return v;
|
||||
}
|
||||
|
||||
public KList<T> removeWhere(Predicate<T> t) {
|
||||
for (T i : copy()) {
|
||||
if (t.test(i)) {
|
||||
|
@ -18,6 +18,7 @@
|
||||
|
||||
package com.volmit.iris.util.function;
|
||||
|
||||
@FunctionalInterface
|
||||
public interface NastyFunction<T, R> {
|
||||
R run(T t);
|
||||
R run(T t) throws Throwable;
|
||||
}
|
||||
|
@ -2,13 +2,11 @@ package com.volmit.iris.util.misc;
|
||||
|
||||
import com.volmit.iris.Iris;
|
||||
import com.volmit.iris.core.nms.container.Pair;
|
||||
import com.volmit.iris.util.collection.KList;
|
||||
import io.github.slimjar.app.builder.ApplicationBuilder;
|
||||
import io.github.slimjar.exceptions.InjectorException;
|
||||
import io.github.slimjar.injector.loader.Injectable;
|
||||
import io.github.slimjar.injector.loader.IsolatedInjectableClassLoader;
|
||||
import io.github.slimjar.injector.loader.factory.InjectableFactory;
|
||||
import io.github.slimjar.logging.ProcessLogger;
|
||||
import io.github.slimjar.resolver.data.Repository;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@ -31,7 +29,6 @@ public class SlimJar {
|
||||
|
||||
private static final ReentrantLock lock = new ReentrantLock();
|
||||
private static final AtomicBoolean loaded = new AtomicBoolean();
|
||||
private static final InjectableFactory FACTORY = InjectableFactory.selecting(InjectableFactory.ERROR, InjectableFactory.INJECTABLE, InjectableFactory.WRAPPED, InjectableFactory.UNSAFE);
|
||||
|
||||
public static void load(@Nullable File localRepository) {
|
||||
if (loaded.get()) return;
|
||||
@ -74,7 +71,7 @@ public class SlimJar {
|
||||
} catch (Throwable e) {
|
||||
Iris.warn("Failed to inject the library loader, falling back to application builder");
|
||||
ApplicationBuilder.appending(NAME)
|
||||
.injectableFactory(FACTORY)
|
||||
.injectableFactory(InjectableFactory.selecting(InjectableFactory.ERROR, InjectableFactory.INJECTABLE, InjectableFactory.WRAPPED, InjectableFactory.UNSAFE))
|
||||
.downloadDirectoryPath(downloadPath)
|
||||
.logger(logger)
|
||||
.build();
|
||||
@ -91,37 +88,18 @@ public class SlimJar {
|
||||
final var pair = findRemapper();
|
||||
final var remapper = pair.getA();
|
||||
final var factory = pair.getB();
|
||||
final var classpath = new KList<URL>();
|
||||
|
||||
final var libraries = factory.apply(new URL[0], libraryLoader == null ? current.getParent() : libraryLoader);
|
||||
final var injecting = FACTORY.create(downloadPath, List.of(Repository.central()), libraries);
|
||||
|
||||
ApplicationBuilder.injecting(NAME, new Injectable() {
|
||||
@Override
|
||||
public void inject(@NotNull URL url) throws InjectorException {
|
||||
try {
|
||||
final List<Path> mapped;
|
||||
synchronized (remapper) {
|
||||
mapped = remapper.apply(List.of(Path.of(url.toURI())));
|
||||
}
|
||||
|
||||
for (final Path path : mapped) {
|
||||
injecting.inject(path.toUri().toURL());
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
throw new InjectorException("Failed to inject " + url, e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isThreadSafe() {
|
||||
return injecting.isThreadSafe();
|
||||
}
|
||||
})
|
||||
ApplicationBuilder.injecting(NAME, classpath::add)
|
||||
.downloadDirectoryPath(downloadPath)
|
||||
.logger(logger)
|
||||
.build();
|
||||
|
||||
libraryLoaderField.set(current, libraries);
|
||||
final var urls = remapper.andThen(KList::new)
|
||||
.apply(classpath.convertNasty(url -> Path.of(url.toURI())))
|
||||
.convertNasty(path -> path.toUri().toURL())
|
||||
.toArray(URL[]::new);
|
||||
libraryLoaderField.set(current, factory.apply(urls, libraryLoader == null ? current.getParent() : libraryLoader));
|
||||
}
|
||||
|
||||
private static Pair<Function<List<Path>, List<Path>>, BiFunction<URL[], ClassLoader, URLClassLoader>> findRemapper() {
|
||||
|
Loading…
x
Reference in New Issue
Block a user