Skip to content

Commit

Permalink
Add configurable mirror support for Paper library loader system
Browse files Browse the repository at this point in the history
  • Loading branch information
Dreeam-qwq committed Jul 31, 2024
1 parent 801a2bf commit 2234099
Showing 1 changed file with 52 additions and 7 deletions.
59 changes: 52 additions & 7 deletions patches/api/0010-Configurable-LibraryLoader-maven-repos.patch
Original file line number Diff line number Diff line change
Expand Up @@ -8,34 +8,79 @@ 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 72b20fa06b461d89f0eeff7b2fbbbe89bae0027c..1e8720e1bf492e2cf1a1638071514e62ac66391d 100644
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,7 @@ public class LibraryLoader
@@ -46,6 +46,9 @@ public class LibraryLoader
private final RepositorySystem repository;
private final DefaultRepositorySystemSession session;
private final List<RemoteRepository> repositories;
+ private final String repositoryAddress = System.getProperty("Leaf.library-download-repo") != null ? System.getProperty("Leaf.library-download-repo") : "https://repo.maven.apache.org/maven2"; // Leaf - Configurable maven repos
+ 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 +80,17 @@ public class LibraryLoader
@@ -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( new RemoteRepository.Builder( "central", "default", repositoryAddress ).build() ) );
+ 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();
+ }
+}

0 comments on commit 2234099

Please sign in to comment.