-
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement support for split datagen (MC 1.21.4+) (#187)
- Loading branch information
1 parent
703cf83
commit c32dc0b
Showing
8 changed files
with
183 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
src/main/java/net/neoforged/moddevgradle/internal/utils/VersionUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package net.neoforged.moddevgradle.internal.utils; | ||
|
||
import java.util.Objects; | ||
import java.util.regex.Pattern; | ||
|
||
public final class VersionUtils { | ||
private VersionUtils() {} | ||
|
||
private static final Pattern RELEASE_PATTERN = Pattern.compile("1\\.(\\d+)(?:.(\\d+))?(?:-.*)?$"); | ||
|
||
/** | ||
* Checks whether the provided NeoForm version should have split client and server data runs. | ||
*/ | ||
public static boolean hasSplitDataRuns(String neoFormVersion) { | ||
// Snapshots starting from 24w45a | ||
if (neoFormVersion.length() >= 5 && neoFormVersion.charAt(2) == 'w') { | ||
try { | ||
var year = Integer.parseInt(neoFormVersion.substring(0, 2)); | ||
var week = Integer.parseInt(neoFormVersion.substring(3, 5)); | ||
|
||
return year > 24 || (year == 24 && week >= 45); | ||
} catch (NumberFormatException ignored) {} | ||
} | ||
// Releases starting from 1.21.4 | ||
var matcher = RELEASE_PATTERN.matcher(neoFormVersion); | ||
if (matcher.find()) { | ||
try { | ||
int minor = Integer.parseInt(matcher.group(1)); | ||
// If there is no patch version, the second group has a null value | ||
int patch = Integer.parseInt(Objects.requireNonNullElse(matcher.group(2), "0")); | ||
|
||
return minor > 21 || (minor == 21 && patch >= 4); | ||
} catch (NumberFormatException ignored) {} | ||
} | ||
// Assume other version patterns are newer and therefore split | ||
return true; | ||
} | ||
} |
49 changes: 49 additions & 0 deletions
49
src/test/java/net/neoforged/moddevgradle/internal/VersionUtilsTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package net.neoforged.moddevgradle.internal; | ||
|
||
import net.neoforged.moddevgradle.internal.utils.VersionUtils; | ||
import org.junit.jupiter.params.ParameterizedTest; | ||
import org.junit.jupiter.params.provider.CsvSource; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
public class VersionUtilsTest { | ||
@ParameterizedTest() | ||
@CsvSource({ | ||
"1.21.4,true", | ||
"1.21.4-pre1-20241120.190508,true", | ||
"1.21.3,false", | ||
"24w45a,true", | ||
"24w44a,false", | ||
"1.21.3-pre1,false", | ||
"25w01a,true", | ||
"23w07a,false", | ||
"1.20,false", | ||
"1.20-pre1,false", | ||
"1.21,false", | ||
"1.21-pre1-20240529.150918,false", | ||
"1.21-pre1,false", | ||
"1.22,true", | ||
"1.22-pre1,true" | ||
}) | ||
public void testSplitDataRunsCorrectness(String neoFormVersion, boolean splitDataRuns) { | ||
assertThat(VersionUtils.hasSplitDataRuns(neoFormVersion)) | ||
.isEqualTo(splitDataRuns); | ||
} | ||
|
||
@ParameterizedTest | ||
@CsvSource({ | ||
"1", | ||
"1.", | ||
"1.21.", | ||
"test", | ||
"24w", | ||
"24w5", | ||
"24w50", | ||
"2aw50", | ||
"24242", | ||
}) | ||
public void testSplitDataRunsDoesNotCrash(String neoFormVersion) { | ||
assertThat(VersionUtils.hasSplitDataRuns(neoFormVersion)) | ||
.isTrue(); | ||
} | ||
} |