9
0
mirror of https://github.com/Winds-Studio/Leaf.git synced 2025-12-28 03:19:21 +00:00

Better warning message for discouraging Maven Central as CDN

This commit is contained in:
Dreeam
2025-07-16 10:25:06 +08:00
parent 4aa095c396
commit 7d2ed096e1
2 changed files with 19 additions and 38 deletions

View File

@@ -1,36 +1,24 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Dreeam <61569423+Dreeam-qwq@users.noreply.github.com>
Date: Mon, 30 Jun 2025 02:41:48 +0800
Subject: [PATCH] Use warning instead of direct throw
Subject: [PATCH] Better warning message for discouraging Maven Central as CDN
Dreeam's Note:
We use soft warning which in Paper is directly exception throw,
Only print warning to avoid break plugins directly.
Also see `Configurable LibraryLoader maven repos` patch,
able to match googleapi mirror urls, to replace to repo url we custom defined.
This able to switch back to maven central repo, to prevent
situation that dependencies exist in maven central, but not in mirror.
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 c1fccd64b1329e31ccf7e6a11853ce3a749b7ea4..b0069a05c322e058f0df668908f0918c0b85a814 100644
index c1fccd64b1329e31ccf7e6a11853ce3a749b7ea4..6e0be8c43502aece01371554c3ff60cb97f12944 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
@@ -121,10 +121,13 @@ public class MavenLibraryResolver implements ClassPathLibrary {
*/
@@ -122,7 +122,7 @@ public class MavenLibraryResolver implements ClassPathLibrary {
public void addRepository(final RemoteRepository remoteRepository) {
if (MAVEN_CENTRAL_URLS.stream().anyMatch(remoteRepository.getUrl()::startsWith)) {
- LOGGER.warn(
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 start - Use warning instead of direct throw
+ try {
+ throw new RuntimeException("Plugin used Maven Central for library resolution");
+ } catch (RuntimeException e) {
+ LOGGER.error("Use of Maven Central as a CDN is against the Maven Central Terms of Service. Use MavenLibraryResolver.MAVEN_CENTRAL_DEFAULT_MIRROR instead. Please contact plugin's support for help.", e);
+ }
+ // Leaf end - Use warning instead of direct throw
+ "Use of Maven Central as a CDN is against the Maven Central Terms of Service. Use MavenLibraryResolver.MAVEN_CENTRAL_DEFAULT_MIRROR instead. DO NOT report it to Paper or Leaf! Please contact plugin's support to adapt this change.", // Leaf - Better warning message for discouraging Maven Central as CDN
new RuntimeException("Plugin used Maven Central for library resolution")
);
}
this.repositories.add(remoteRepository);
}

View File

@@ -7,7 +7,7 @@ Add JVM flag `-DLeaf.library-download-repo=link` to choose library download repo
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 b0069a05c322e058f0df668908f0918c0b85a814..b899e9cbb2658c7f08343b2e6500fb34427fc238 100644
index 6e0be8c43502aece01371554c3ff60cb97f12944..ab239c0ea1b63b6b8455f11b4c7ec089969c049f 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
@@ -59,12 +59,25 @@ public class MavenLibraryResolver implements ClassPathLibrary {
@@ -38,16 +38,11 @@ index b0069a05c322e058f0df668908f0918c0b85a814..b899e9cbb2658c7f08343b2e6500fb34
private static final Logger LOGGER = LoggerFactory.getLogger("MavenLibraryResolver");
private final RepositorySystem repository;
@@ -120,15 +133,34 @@ public class MavenLibraryResolver implements ClassPathLibrary {
@@ -120,12 +133,33 @@ public class MavenLibraryResolver implements ClassPathLibrary {
* dependencies from
*/
public void addRepository(final RemoteRepository remoteRepository) {
- if (MAVEN_CENTRAL_URLS.stream().anyMatch(remoteRepository.getUrl()::startsWith)) {
- // Leaf start - Use warning instead of direct throw
- try {
- throw new RuntimeException("Plugin used Maven Central for library resolution");
- } catch (RuntimeException e) {
- LOGGER.error("Use of Maven Central as a CDN is against the Maven Central Terms of Service. Use MavenLibraryResolver.MAVEN_CENTRAL_DEFAULT_MIRROR instead. Please contact plugin's support for help.", e);
+ // Leaf start - Configurable LibraryLoader maven repos
+ for (String url : MAVEN_CENTRAL_URLS) {
+ if (remoteRepository.getUrl().startsWith(url)) {
@@ -56,16 +51,14 @@ index b0069a05c322e058f0df668908f0918c0b85a814..b899e9cbb2658c7f08343b2e6500fb34
+ this.repositories.add(mirrorRepo);
+ return;
+ }
+ // Leaf start - Use warning instead of direct throw
+ try {
+ throw new RuntimeException("Plugin used Maven Central for library resolution");
+ } catch (RuntimeException e) {
+ LOGGER.error("Use of Maven Central as a CDN is against the Maven Central Terms of Service. Use MavenLibraryResolver.MAVEN_CENTRAL_DEFAULT_MIRROR instead. Please contact plugin's support for help.", e);
+ }
+ // Leaf end - Use warning instead of direct throw
}
- // Leaf end - Use warning instead of direct throw
}
+ // Leaf end - Configurable LibraryLoader maven repos
LOGGER.warn(
"Use of Maven Central as a CDN is against the Maven Central Terms of Service. Use MavenLibraryResolver.MAVEN_CENTRAL_DEFAULT_MIRROR instead. DO NOT report it to Paper or Leaf! Please contact plugin's support to adapt this change.", // Leaf - Better warning message for discouraging Maven Central as CDN
new RuntimeException("Plugin used Maven Central for library resolution")
);
+ // Leaf start - Configurable LibraryLoader maven repos
+ }
+ }
+ // Match google api maven central mirror urls
+ for (String url : MAVEN_CENTRAL_GOOGLE_MIRROR_URLS) {
+ if (remoteRepository.getUrl().startsWith(url)) {
@@ -75,12 +68,12 @@ index b0069a05c322e058f0df668908f0918c0b85a814..b899e9cbb2658c7f08343b2e6500fb34
+ return;
+ }
+ }
+ }
}
+ // Leaf end - Configurable LibraryLoader maven repos
this.repositories.add(remoteRepository);
}
@@ -165,4 +197,15 @@ public class MavenLibraryResolver implements ClassPathLibrary {
@@ -162,4 +196,15 @@ public class MavenLibraryResolver implements ClassPathLibrary {
}
return central;
}