|
39 | 39 | import org.gradle.api.Task; |
40 | 40 | import org.gradle.api.plugins.JavaPluginConvention; |
41 | 41 | import org.gradle.api.tasks.TaskProvider; |
| 42 | +import org.gradle.util.GradleVersion; |
42 | 43 |
|
43 | 44 | import javax.annotation.Nonnull; |
44 | 45 | import javax.annotation.Nullable; |
|
87 | 88 |
|
88 | 89 | public class Utils { |
89 | 90 | private static final boolean ENABLE_TEST_CERTS = Boolean.parseBoolean(System.getProperty("net.minecraftforge.gradle.test_certs", "true")); |
| 91 | + private static final boolean ENABLE_TEST_GRADLE = Boolean.parseBoolean(System.getProperty("net.minecraftforge.gradle.test_gradle", "true")); |
90 | 92 | private static final boolean ENABLE_TEST_JAVA = Boolean.parseBoolean(System.getProperty("net.minecraftforge.gradle.test_java", "true")); |
91 | 93 |
|
92 | 94 | public static final Gson GSON = new GsonBuilder() |
@@ -500,23 +502,38 @@ public static final String capitalize(@Nonnull final String toCapitalize) { |
500 | 502 | return toCapitalize.length() > 1 ? toCapitalize.substring(0, 1).toUpperCase() + toCapitalize.substring(1) : toCapitalize; |
501 | 503 | } |
502 | 504 |
|
503 | | - public static void checkJavaRange( @Nullable JavaVersionParser.JavaVersion minVersionInclusive, @Nullable JavaVersionParser.JavaVersion maxVersionExclusive) { |
504 | | - JavaVersionParser.JavaVersion currentJavaVersion = JavaVersionParser.getCurrentJavaVersion(); |
505 | | - if (minVersionInclusive != null && currentJavaVersion.compareTo(minVersionInclusive) < 0) |
506 | | - throw new RuntimeException(String.format("Found java version %s. Minimum required is %s.", currentJavaVersion, minVersionInclusive)); |
507 | | - if (maxVersionExclusive != null && currentJavaVersion.compareTo(maxVersionExclusive) >= 0) |
508 | | - throw new RuntimeException(String.format("Found java version %s. Versions %s and newer are not supported yet.", currentJavaVersion, maxVersionExclusive)); |
| 505 | + public static void checkJavaRange(@Nullable JavaVersionParser.JavaVersion minVersionInclusive, @Nullable JavaVersionParser.JavaVersion maxVersionExclusive) { |
| 506 | + checkRange("java", JavaVersionParser.getCurrentJavaVersion(), minVersionInclusive, maxVersionExclusive, "."); |
| 507 | + } |
| 508 | + |
| 509 | + public static void checkGradleRange(@Nullable GradleVersion minVersionInclusive, @Nullable GradleVersion maxVersionExclusive) { |
| 510 | + checkRange("Gradle", GradleVersion.current(), minVersionInclusive, maxVersionExclusive, " in FG3, FG4 however supports Versions 6.8.1 and newer. Consider upgrading."); |
| 511 | + } |
| 512 | + |
| 513 | + private static <T> void checkRange(String name, Comparable<T> current, @Nullable T minVersionInclusive, @Nullable T maxVersionExclusive, String additional) { |
| 514 | + if (minVersionInclusive != null && current.compareTo(minVersionInclusive) < 0) |
| 515 | + throw new RuntimeException(String.format("Found %s version %s. Minimum required is %s.", name, current, minVersionInclusive)); |
| 516 | + |
| 517 | + if (maxVersionExclusive != null && current.compareTo(maxVersionExclusive) >= 0) |
| 518 | + throw new RuntimeException(String.format("Found %s version %s. Versions %s and newer are not supported%s", name, current, maxVersionExclusive, additional)); |
509 | 519 | } |
510 | 520 |
|
511 | 521 | public static void checkJavaVersion() { |
512 | 522 | if (ENABLE_TEST_JAVA) { |
513 | 523 | checkJavaRange( |
514 | | - // Mininum must be update 101 as it's the first one to include Let's Encrypt certificates. |
| 524 | + // Minimum must be update 101 as it's the first one to include Let's Encrypt certificates. |
515 | 525 | JavaVersionParser.parseJavaVersion("1.8.0_101"), |
516 | 526 | null //TODO: Add JDK range check to MCPConfig? |
517 | 527 | ); |
518 | 528 | } |
519 | 529 |
|
| 530 | + if (ENABLE_TEST_GRADLE) { |
| 531 | + checkGradleRange( |
| 532 | + GradleVersion.version("4.9"), |
| 533 | + GradleVersion.version("6.0.0") |
| 534 | + ); |
| 535 | + } |
| 536 | + |
520 | 537 | if (ENABLE_TEST_CERTS) { |
521 | 538 | testServerConnection(FORGE_MAVEN); |
522 | 539 | testServerConnection(MOJANG_MAVEN); |
|
0 commit comments