9
0
mirror of https://github.com/Winds-Studio/Leaf.git synced 2025-12-21 16:09:19 +00:00
Files
Leaf/patches/api/0009-Configurable-LibraryLoader-maven-repos.patch
2024-09-03 15:27:31 -04:00

87 lines
5.0 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
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 70f352630de71f575d1aea5a3126da19a94791ab..c04f2cd1aa4fb0d77932ac76d9905b27e1c64f51 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,6 +105,13 @@ public class MavenLibraryResolver implements ClassPathLibrary {
* dependencies from
*/
public void addRepository(@NotNull RemoteRepository remoteRepository) {
+ if (org.dreeam.leaf.plugin.loader.MavenCentralMirror.MAVEN_CENTRAL_MIRROR_REPO != null
+ && org.dreeam.leaf.plugin.loader.MavenCentralMirror.isMavenCentral(remoteRepository.getUrl())) {
+ remoteRepository = org.dreeam.leaf.plugin.loader.MavenCentralMirror.getCentralMirrorRepo(
+ org.dreeam.leaf.plugin.loader.MavenCentralMirror.MAVEN_CENTRAL_MIRROR_REPO
+ );
+ }
+
this.repositories.add(remoteRepository);
}
diff --git a/src/main/java/org/bukkit/plugin/java/LibraryLoader.java b/src/main/java/org/bukkit/plugin/java/LibraryLoader.java
index 211c093ce2253e918cd40725ebf1ef172d1b9bdf..d24d504e92b8a7a8b689605fa164a27fa3b323f6 100644
--- a/src/main/java/org/bukkit/plugin/java/LibraryLoader.java
+++ b/src/main/java/org/bukkit/plugin/java/LibraryLoader.java
@@ -46,6 +46,9 @@ public class LibraryLoader
private final RepositorySystem repository;
private final DefaultRepositorySystemSession session;
private final List<RemoteRepository> repositories;
+ private final String repositoryAddress = org.dreeam.leaf.plugin.loader.MavenCentralMirror.MAVEN_CENTRAL_MIRROR_REPO != null
+ ? org.dreeam.leaf.plugin.loader.MavenCentralMirror.MAVEN_CENTRAL_MIRROR_REPO
+ : org.dreeam.leaf.plugin.loader.MavenCentralMirror.MAVEN_CENTRAL_REPO; // Leaf - Configurable maven repos
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
@@ -79,7 +82,19 @@ public class LibraryLoader
session.setSystemProperties( System.getProperties() );
session.setReadOnly();
- this.repositories = repository.newResolutionRepositories( session, Arrays.asList( new RemoteRepository.Builder( "central", "default", "https://repo.maven.apache.org/maven2" ).build() ) );
+ // Leaf start - Configurable maven repos
+ this.repositories = repository.newResolutionRepositories(
+ session,
+ List.of( org.dreeam.leaf.plugin.loader.MavenCentralMirror.getCentralMirrorRepo(repositoryAddress) )
+ );
+ /* // 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 maven repos
}
@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..8d5ad681b66baeb19ac50bb81818b8955113217f
--- /dev/null
+++ b/src/main/java/org/dreeam/leaf/plugin/loader/MavenCentralMirror.java
@@ -0,0 +1,17 @@
+package org.dreeam.leaf.plugin.loader;
+
+import org.eclipse.aether.repository.RemoteRepository;
+
+public class MavenCentralMirror {
+
+ public static final String MAVEN_CENTRAL_REPO = "https://repo.maven.apache.org/maven2";
+ public static final String MAVEN_CENTRAL_MIRROR_REPO = System.getProperty("Leaf.library-download-repo");
+
+ public static boolean isMavenCentral(String repo) {
+ return repo.contains("repo.maven.apache.org/maven2");
+ }
+
+ public static RemoteRepository getCentralMirrorRepo(String repo) {
+ return new RemoteRepository.Builder("central", "default", repo).build();
+ }
+}