Skip to content

Commit

Permalink
Fix enable on Java 16+ (lucko#98)
Browse files Browse the repository at this point in the history
  • Loading branch information
lucko committed May 13, 2021
1 parent 86274e4 commit 7506662
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions helper/src/main/java/me/lucko/helper/maven/LibraryLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@

package me.lucko.helper.maven;

import com.google.common.base.Supplier;
import com.google.common.base.Suppliers;

import me.lucko.helper.internal.LoaderUtils;
import me.lucko.helper.utils.Log;
import me.lucko.helper.utils.annotation.NonnullByDefault;
Expand All @@ -44,15 +47,17 @@
*/
@NonnullByDefault
public final class LibraryLoader {
private static final Method ADD_URL_METHOD;
static {

@SuppressWarnings("Guava")
private static final Supplier<Method> ADD_URL_METHOD = Suppliers.memoize(() -> {
try {
ADD_URL_METHOD = URLClassLoader.class.getDeclaredMethod("addURL", URL.class);
ADD_URL_METHOD.setAccessible(true);
Method addUrlMethod = URLClassLoader.class.getDeclaredMethod("addURL", URL.class);
addUrlMethod.setAccessible(true);
return addUrlMethod;
} catch (NoSuchMethodException e) {
throw new RuntimeException(e);
}
}
});

/**
* Resolves all {@link MavenLibrary} annotations on the given object.
Expand Down Expand Up @@ -115,7 +120,7 @@ public static void load(Dependency d) {

URLClassLoader classLoader = (URLClassLoader) LoaderUtils.getPlugin().getClass().getClassLoader();
try {
ADD_URL_METHOD.invoke(classLoader, saveLocation.toURI().toURL());
ADD_URL_METHOD.get().invoke(classLoader, saveLocation.toURI().toURL());
} catch (Exception e) {
throw new RuntimeException("Unable to load dependency: " + saveLocation.toString(), e);
}
Expand Down

0 comments on commit 7506662

Please sign in to comment.