|
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; |
|
90 | 91 |
|
91 | 92 | public class Utils { |
92 | 93 | private static final boolean ENABLE_TEST_CERTS = Boolean.parseBoolean(System.getProperty("net.minecraftforge.gradle.test_certs", "true")); |
| 94 | + private static final boolean ENABLE_TEST_GRADLE = Boolean.parseBoolean(System.getProperty("net.minecraftforge.gradle.test_gradle", "true")); |
93 | 95 | private static final boolean ENABLE_TEST_JAVA = Boolean.parseBoolean(System.getProperty("net.minecraftforge.gradle.test_java", "true")); |
94 | 96 |
|
95 | 97 | public static final Gson GSON = new GsonBuilder() |
@@ -512,23 +514,46 @@ public static final String capitalize(@Nonnull final String toCapitalize) { |
512 | 514 | return toCapitalize.length() > 1 ? toCapitalize.substring(0, 1).toUpperCase() + toCapitalize.substring(1) : toCapitalize; |
513 | 515 | } |
514 | 516 |
|
515 | | - public static void checkJavaRange( @Nullable JavaVersionParser.JavaVersion minVersionInclusive, @Nullable JavaVersionParser.JavaVersion maxVersionExclusive) { |
516 | | - JavaVersionParser.JavaVersion currentJavaVersion = JavaVersionParser.getCurrentJavaVersion(); |
517 | | - if (minVersionInclusive != null && currentJavaVersion.compareTo(minVersionInclusive) < 0) |
518 | | - throw new RuntimeException(String.format("Found java version %s. Minimum required is %s.", currentJavaVersion, minVersionInclusive)); |
519 | | - if (maxVersionExclusive != null && currentJavaVersion.compareTo(maxVersionExclusive) >= 0) |
520 | | - throw new RuntimeException(String.format("Found java version %s. Versions %s and newer are not supported yet.", currentJavaVersion, maxVersionExclusive)); |
| 517 | + public static void checkJavaRange(@Nullable JavaVersionParser.JavaVersion minVersionInclusive, @Nullable JavaVersionParser.JavaVersion maxVersionExclusive) { |
| 518 | + checkRange("java", JavaVersionParser.getCurrentJavaVersion(), minVersionInclusive, maxVersionExclusive, ""); |
521 | 519 | } |
522 | 520 |
|
| 521 | + public static void checkGradleRange(@Nullable GradleVersion minVersionInclusive, @Nullable GradleVersion maxVersionExclusive) { |
| 522 | + checkRange("Gradle", GradleVersion.current(), minVersionInclusive, maxVersionExclusive, "\nNote: Upgrade your gradle version first before trying to switch to FG4."); |
| 523 | + } |
| 524 | + |
| 525 | + private static <T> void checkRange(String name, Comparable<T> current, @Nullable T minVersionInclusive, @Nullable T maxVersionExclusive, String additional) { |
| 526 | + if (minVersionInclusive != null && current.compareTo(minVersionInclusive) < 0) |
| 527 | + throw new RuntimeException(String.format("Found %s version %s. Minimum required is %s.%s", name, current, minVersionInclusive, additional)); |
| 528 | + |
| 529 | + if (maxVersionExclusive != null && current.compareTo(maxVersionExclusive) >= 0) |
| 530 | + throw new RuntimeException(String.format("Found %s version %s. Versions %s and newer are not supported yet.", name, current, maxVersionExclusive)); |
| 531 | + } |
| 532 | + |
| 533 | + /** |
| 534 | + * @deprecated To be removed in FG 4.2, see {@link #checkEnvironment()} |
| 535 | + */ |
| 536 | + @Deprecated |
523 | 537 | public static void checkJavaVersion() { |
| 538 | + checkEnvironment(); |
| 539 | + } |
| 540 | + |
| 541 | + public static void checkEnvironment() { |
524 | 542 | if (ENABLE_TEST_JAVA) { |
525 | 543 | checkJavaRange( |
526 | | - // Mininum must be update 101 as it's the first one to include Let's Encrypt certificates. |
| 544 | + // Minimum must be update 101 as it's the first one to include Let's Encrypt certificates. |
527 | 545 | JavaVersionParser.parseJavaVersion("1.8.0_101"), |
528 | 546 | null //TODO: Add JDK range check to MCPConfig? |
529 | 547 | ); |
530 | 548 | } |
531 | 549 |
|
| 550 | + if (ENABLE_TEST_GRADLE) { |
| 551 | + checkGradleRange( |
| 552 | + GradleVersion.version("6.8.1"), |
| 553 | + null |
| 554 | + ); |
| 555 | + } |
| 556 | + |
532 | 557 | if (ENABLE_TEST_CERTS) { |
533 | 558 | testServerConnection(FORGE_MAVEN); |
534 | 559 | testServerConnection(MOJANG_MAVEN); |
|
0 commit comments