Fallback to fabric's experimental version manifest for versions that are not in the launchermeta.

dev/0.11
modmuss50 2021-07-16 23:22:03 +01:00
parent d271dfadd0
commit 69caaccb07
3 changed files with 92 additions and 1 deletions

View File

@ -58,6 +58,7 @@ public class MinecraftProviderImpl extends DependencyProvider implements Minecra
private File minecraftServerJar;
private File minecraftMergedJar;
private File versionManifestJson;
private File experimentalVersionsJson;
public MinecraftProviderImpl(Project project) {
super(project);
@ -116,6 +117,7 @@ public class MinecraftProviderImpl extends DependencyProvider implements Minecra
minecraftServerJar = new File(getDirectories().getUserCache(), "minecraft-" + minecraftVersion + "-server.jar");
minecraftMergedJar = new File(getDirectories().getUserCache(), "minecraft-" + minecraftVersion + "-merged.jar");
versionManifestJson = new File(getDirectories().getUserCache(), "version_manifest.json");
experimentalVersionsJson = new File(getDirectories().getUserCache(), "experimental_version_manifest.json");
}
private void downloadMcJson(boolean offline) throws IOException {
@ -151,8 +153,12 @@ public class MinecraftProviderImpl extends DependencyProvider implements Minecra
getProject().getLogger().lifecycle("Using custom minecraft manifest");
}
if (!optionalVersion.isPresent()) {
if (optionalVersion.isEmpty()) {
optionalVersion = mcManifest.versions().stream().filter(versions -> versions.id.equalsIgnoreCase(minecraftVersion)).findFirst();
if (optionalVersion.isEmpty()) {
optionalVersion = findExperimentalVersion(offline);
}
}
if (optionalVersion.isPresent()) {
@ -182,6 +188,29 @@ public class MinecraftProviderImpl extends DependencyProvider implements Minecra
}
}
// This attempts to find the version from fabric's own fallback version manifest json.
private Optional<ManifestVersion.Versions> findExperimentalVersion(boolean offline) throws IOException {
if (offline) {
if (!experimentalVersionsJson.exists()) {
getProject().getLogger().warn("Skipping download of experimental versions jsons due to being offline.");
return Optional.empty();
}
} else {
DownloadUtil.downloadIfChanged(new URL(Constants.EXPERIMENTAL_VERSIONS), experimentalVersionsJson, getProject().getLogger());
}
String expVersionManifest = Files.asCharSource(experimentalVersionsJson, StandardCharsets.UTF_8).read();
ManifestVersion expManifest = LoomGradlePlugin.OBJECT_MAPPER.readValue(expVersionManifest, ManifestVersion.class);
var result = expManifest.versions().stream().filter(versions -> versions.id.equalsIgnoreCase(minecraftVersion)).findFirst();
if (result.isPresent()) {
getProject().getLogger().lifecycle("Using fallback experimental version {}", minecraftVersion);
}
return result;
}
private boolean hasRecentValidManifest() throws IOException {
if (getExtension().getCustomManifest() != null) {
return false;

View File

@ -36,6 +36,7 @@ public class Constants {
public static final String LIBRARIES_BASE = "https://libraries.minecraft.net/";
public static final String RESOURCES_BASE = "https://resources.download.minecraft.net/";
public static final String VERSION_MANIFESTS = "https://launchermeta.mojang.com/mc/game/version_manifest_v2.json";
public static final String EXPERIMENTAL_VERSIONS = "https://maven.fabricmc.net/net/minecraft/experimental_versions.json";
public static final String SYSTEM_ARCH = System.getProperty("os.arch").equals("64") ? "64" : "32";

View File

@ -0,0 +1,61 @@
/*
* This file is part of fabric-loom, licensed under the MIT License (MIT).
*
* Copyright (c) 2021 FabricMC
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package net.fabricmc.loom.test.integration
import net.fabricmc.loom.test.util.ProjectTestTrait
import spock.lang.Specification
import spock.lang.Unroll
import static org.gradle.testkit.runner.TaskOutcome.SUCCESS
class ExperimentalVersionsTest extends Specification implements ProjectTestTrait {
@Override
String name() {
"minimalBase"
}
@Override
def filesReady() {
buildGradle() << '''
dependencies {
minecraft "com.mojang:minecraft:1.18_experimental-snapshot-1"
mappings "net.fabricmc:yarn:1.18_experimental-snapshot-1+build.2:v2"
modImplementation "net.fabricmc:fabric-loader:0.11.6"
}
'''
}
@Unroll
def "experimental versions (gradle #gradle)"() {
when:
def result = create("build", gradle)
then:
result.task(":build").outcome == SUCCESS
where:
gradle | _
DEFAULT_GRADLE | _
PRE_RELEASE_GRADLE | _
}
}