mirror of
https://github.com/Winds-Studio/Leaf.git
synced 2025-12-22 08:29:28 +00:00
Update changes from ver/1.21.4 branch
This commit is contained in:
@@ -3,76 +3,91 @@ From: Dreeam <61569423+Dreeam-qwq@users.noreply.github.com>
|
||||
Date: Sat, 3 Feb 2024 18:45:53 -0500
|
||||
Subject: [PATCH] Configurable LibraryLoader maven repos
|
||||
|
||||
TODO - Dreeam: Support multi maven repos for lib downloading.
|
||||
|
||||
Add JVM flag `-DLeaf.library-download-repo=link` to choose library download repo link.
|
||||
e.g. `-DLeaf.library-download-repo=https://maven.aliyun.com/repository/public`
|
||||
|
||||
diff --git a/src/main/java/io/papermc/paper/plugin/loader/library/impl/MavenLibraryResolver.java b/src/main/java/io/papermc/paper/plugin/loader/library/impl/MavenLibraryResolver.java
|
||||
index 107705db2d82b7c191e5e625ec888e0bc3b03831..77a58fc7c173b1724d44b0eeaf23b4a1b22b5fcb 100644
|
||||
index 107705db2d82b7c191e5e625ec888e0bc3b03831..d7dc6ff0b372de04c956cae6fc27d2679b88e0f7 100644
|
||||
--- a/src/main/java/io/papermc/paper/plugin/loader/library/impl/MavenLibraryResolver.java
|
||||
+++ b/src/main/java/io/papermc/paper/plugin/loader/library/impl/MavenLibraryResolver.java
|
||||
@@ -105,7 +105,7 @@ public class MavenLibraryResolver implements ClassPathLibrary {
|
||||
* dependencies from
|
||||
@@ -3,9 +3,11 @@ package io.papermc.paper.plugin.loader.library.impl;
|
||||
import io.papermc.paper.plugin.loader.library.ClassPathLibrary;
|
||||
import io.papermc.paper.plugin.loader.library.LibraryLoadingException;
|
||||
import io.papermc.paper.plugin.loader.library.LibraryStore;
|
||||
+
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
+
|
||||
import org.apache.maven.repository.internal.MavenRepositorySystemUtils;
|
||||
import org.eclipse.aether.DefaultRepositorySystemSession;
|
||||
import org.eclipse.aether.RepositorySystem;
|
||||
@@ -57,6 +59,13 @@ public class MavenLibraryResolver implements ClassPathLibrary {
|
||||
private final List<RemoteRepository> repositories = new ArrayList<>();
|
||||
private final List<Dependency> dependencies = new ArrayList<>();
|
||||
|
||||
+ // Leaf start - Configurable LibraryLoader maven repos
|
||||
+ @org.jspecify.annotations.Nullable
|
||||
+ public static final RemoteRepository MAVEN_CENTRAL_MIRROR_REPO = getCentralMirrorRepo();
|
||||
+ private static final String[] MAVEN_CENTRAL_URLS = new String[]{
|
||||
+ };
|
||||
+ // Leaf end - Configurable LibraryLoader maven repos
|
||||
+
|
||||
/**
|
||||
* Creates a new maven library resolver instance.
|
||||
* <p>
|
||||
@@ -102,9 +111,24 @@ public class MavenLibraryResolver implements ClassPathLibrary {
|
||||
* repository.
|
||||
*
|
||||
* @param remoteRepository the configuration that defines the maven repository this library resolver should fetch
|
||||
- * dependencies from
|
||||
+ * dependencies from
|
||||
*/
|
||||
public void addRepository(final RemoteRepository remoteRepository) {
|
||||
- this.repositories.add(remoteRepository);
|
||||
+ this.repositories.add(org.dreeam.leaf.plugin.loader.MavenCentralMirror.getCentralRepo(remoteRepository)); // Leaf - Configurable LibraryLoader maven repos
|
||||
+ // Leaf start - Configurable LibraryLoader maven repos
|
||||
+ for (String url : MAVEN_CENTRAL_URLS) {
|
||||
+ if (remoteRepository.getUrl().startsWith(url)) {
|
||||
+ RemoteRepository mirrorRepo = MAVEN_CENTRAL_MIRROR_REPO;
|
||||
+ if (mirrorRepo != null) {
|
||||
+ this.repositories.add(mirrorRepo);
|
||||
+ return;
|
||||
+ }
|
||||
+ LOGGER.warn(
|
||||
+ "Use of Maven Central as a CDN is against the Maven Central Terms of Service. Use MavenLibraryResolver.MAVEN_CENTRAL_DEFAULT_MIRROR instead.",
|
||||
+ new RuntimeException("Plugin used Maven Central for library resolution")
|
||||
+ );
|
||||
+ }
|
||||
+ }
|
||||
+ // Leaf end - Configurable LibraryLoader maven repos
|
||||
this.repositories.add(remoteRepository);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -130,4 +154,15 @@ public class MavenLibraryResolver implements ClassPathLibrary {
|
||||
store.addLibrary(file.toPath());
|
||||
}
|
||||
}
|
||||
+
|
||||
+ // Leaf start - Configurable LibraryLoader maven repos
|
||||
+ @org.jspecify.annotations.Nullable
|
||||
+ private static RemoteRepository getCentralMirrorRepo() {
|
||||
+ String mirrorAddr = System.getProperty("Leaf.library-download-repo");
|
||||
+ if (mirrorAddr != null) {
|
||||
+ new RemoteRepository.Builder("central", "default", mirrorAddr).build();
|
||||
+ }
|
||||
+ return null;
|
||||
+ }
|
||||
+ // Leaf end - Configurable LibraryLoader maven repos
|
||||
}
|
||||
diff --git a/src/main/java/org/bukkit/plugin/java/LibraryLoader.java b/src/main/java/org/bukkit/plugin/java/LibraryLoader.java
|
||||
index cfe41c0a67c8d729b6bd23b0cfa32db3c9db9f74..9f167a9cb4a93a79b8ed709b61214ce0138a875d 100644
|
||||
index cfe41c0a67c8d729b6bd23b0cfa32db3c9db9f74..05d3b793bf9cb320774f9f488a3b78bedab6a9d4 100644
|
||||
--- a/src/main/java/org/bukkit/plugin/java/LibraryLoader.java
|
||||
+++ b/src/main/java/org/bukkit/plugin/java/LibraryLoader.java
|
||||
@@ -74,7 +74,19 @@ public class LibraryLoader {
|
||||
session.setSystemProperties(System.getProperties());
|
||||
session.setReadOnly();
|
||||
@@ -47,6 +47,8 @@ public class LibraryLoader {
|
||||
public static java.util.function.BiFunction<URL[], ClassLoader, URLClassLoader> LIBRARY_LOADER_FACTORY; // Paper - rewrite reflection in libraries
|
||||
public static java.util.function.Function<List<java.nio.file.Path>, List<java.nio.file.Path>> REMAPPER; // Paper - remap libraries
|
||||
|
||||
- this.repositories = repository.newResolutionRepositories(session, Arrays.asList(new RemoteRepository.Builder("central", "default", "https://repo.maven.apache.org/maven2").build()));
|
||||
+ // Leaf start - Configurable LibraryLoader maven repos
|
||||
+ this.repositories = repository.newResolutionRepositories(
|
||||
+ session,
|
||||
+ List.of(org.dreeam.leaf.plugin.loader.MavenCentralMirror.getCentralRepo("https://repo.maven.apache.org/maven2"))
|
||||
+ );
|
||||
+ /* // Dreeam TODO
|
||||
+ this.repositories = repository.newResolutionRepositories(session, List.of(
|
||||
+ new RemoteRepository.Builder("central", "default", "https://repo.maven.apache.org/maven2").build(),
|
||||
+ new RemoteRepository.Builder("aliyun", "default", "https://maven.aliyun.com/repository/public").build(),
|
||||
+ new RemoteRepository.Builder("tencentclound", "default", "https://mirrors.cloud.tencent.com/nexus/repository/maven-public/").build(),
|
||||
+ new RemoteRepository.Builder("huaweicloud", "default", "https://repo.huaweicloud.com/repository/maven/").build()
|
||||
+ ));*/
|
||||
+ // Leaf end - Configurable LibraryLoader maven repos
|
||||
}
|
||||
+ if (io.papermc.paper.plugin.loader.library.impl.MavenLibraryResolver.MAVEN_CENTRAL_MIRROR_REPO != null) return List.of(io.papermc.paper.plugin.loader.library.impl.MavenLibraryResolver.MAVEN_CENTRAL_MIRROR_REPO); // Leaf - Configurable LibraryLoader maven repos
|
||||
+
|
||||
public LibraryLoader(@NotNull Logger logger) {
|
||||
this.logger = logger;
|
||||
|
||||
@Nullable
|
||||
diff --git a/src/main/java/org/dreeam/leaf/plugin/loader/MavenCentralMirror.java b/src/main/java/org/dreeam/leaf/plugin/loader/MavenCentralMirror.java
|
||||
new file mode 100644
|
||||
index 0000000000000000000000000000000000000000..95534cb6d771a0fe288e7c843c41b0036bdc7095
|
||||
--- /dev/null
|
||||
+++ b/src/main/java/org/dreeam/leaf/plugin/loader/MavenCentralMirror.java
|
||||
@@ -0,0 +1,24 @@
|
||||
+package org.dreeam.leaf.plugin.loader;
|
||||
+
|
||||
+import org.eclipse.aether.repository.RemoteRepository;
|
||||
+
|
||||
+public class MavenCentralMirror {
|
||||
+
|
||||
+ public static final String MAVEN_CENTRAL_MIRROR_REPO = System.getProperty("Leaf.library-download-repo");
|
||||
+
|
||||
+ public static RemoteRepository getCentralRepo(RemoteRepository repo) {
|
||||
+ if (MAVEN_CENTRAL_MIRROR_REPO != null && repo.getUrl().contains("repo.maven.apache.org/maven2")) {
|
||||
+ repo = new RemoteRepository.Builder("central", "default", MAVEN_CENTRAL_MIRROR_REPO).build();
|
||||
+ }
|
||||
+
|
||||
+ return repo;
|
||||
+ }
|
||||
+
|
||||
+ public static RemoteRepository getCentralRepo(String repo) {
|
||||
+ if (MAVEN_CENTRAL_MIRROR_REPO != null) {
|
||||
+ repo = MAVEN_CENTRAL_MIRROR_REPO;
|
||||
+ }
|
||||
+
|
||||
+ return new RemoteRepository.Builder("central", "default", repo).build();
|
||||
+ }
|
||||
+}
|
||||
|
||||
Reference in New Issue
Block a user