Avoid trying to download things offline (#87)
parent
88796b3c0f
commit
1dd8e47122
|
@ -33,23 +33,22 @@ import net.fabricmc.loom.util.MinecraftVersionInfo;
|
||||||
import net.fabricmc.loom.util.assets.AssetIndex;
|
import net.fabricmc.loom.util.assets.AssetIndex;
|
||||||
import net.fabricmc.loom.util.assets.AssetObject;
|
import net.fabricmc.loom.util.assets.AssetObject;
|
||||||
import net.fabricmc.loom.util.progress.ProgressLogger;
|
import net.fabricmc.loom.util.progress.ProgressLogger;
|
||||||
|
|
||||||
|
import org.gradle.api.GradleException;
|
||||||
import org.gradle.api.Project;
|
import org.gradle.api.Project;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileReader;
|
import java.io.FileReader;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.lang.ref.SoftReference;
|
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.Date;
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
public class MinecraftAssetsProvider {
|
public class MinecraftAssetsProvider {
|
||||||
public static void provide(MinecraftProvider minecraftProvider, Project project) throws IOException {
|
public static void provide(MinecraftProvider minecraftProvider, Project project) throws IOException {
|
||||||
LoomGradleExtension extension = project.getExtensions().getByType(LoomGradleExtension.class);
|
LoomGradleExtension extension = project.getExtensions().getByType(LoomGradleExtension.class);
|
||||||
MinecraftVersionInfo versionInfo = minecraftProvider.versionInfo;
|
boolean offline = project.getGradle().getStartParameter().isOffline();
|
||||||
|
|
||||||
|
MinecraftVersionInfo versionInfo = minecraftProvider.versionInfo;
|
||||||
MinecraftVersionInfo.AssetIndex assetIndex = versionInfo.assetIndex;
|
MinecraftVersionInfo.AssetIndex assetIndex = versionInfo.assetIndex;
|
||||||
|
|
||||||
// get existing cache files
|
// get existing cache files
|
||||||
|
@ -61,8 +60,18 @@ public class MinecraftAssetsProvider {
|
||||||
File assetsInfo = new File(assets, "indexes" + File.separator + assetIndex.getFabricId(minecraftProvider.minecraftVersion) + ".json");
|
File assetsInfo = new File(assets, "indexes" + File.separator + assetIndex.getFabricId(minecraftProvider.minecraftVersion) + ".json");
|
||||||
if (!assetsInfo.exists() || !Checksum.equals(assetsInfo, assetIndex.sha1)) {
|
if (!assetsInfo.exists() || !Checksum.equals(assetsInfo, assetIndex.sha1)) {
|
||||||
project.getLogger().lifecycle(":downloading asset index");
|
project.getLogger().lifecycle(":downloading asset index");
|
||||||
|
if (offline) {
|
||||||
|
if (assetsInfo.exists()) {
|
||||||
|
//We know it's outdated but can't do anything about it, oh well
|
||||||
|
project.getLogger().warn("Asset index outdated");
|
||||||
|
} else {
|
||||||
|
//We don't know what assets we need, just that we don't have any
|
||||||
|
throw new GradleException("Asset index not found at " + assetsInfo.getAbsolutePath());
|
||||||
|
}
|
||||||
|
} else {
|
||||||
DownloadUtil.downloadIfChanged(new URL(assetIndex.url), assetsInfo, project.getLogger());
|
DownloadUtil.downloadIfChanged(new URL(assetIndex.url), assetsInfo, project.getLogger());
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
ProgressLogger progressLogger = ProgressLogger.getProgressFactory(project, MinecraftAssetsProvider.class.getName());
|
ProgressLogger progressLogger = ProgressLogger.getProgressFactory(project, MinecraftAssetsProvider.class.getName());
|
||||||
progressLogger.start("Downloading assets...", "assets");
|
progressLogger.start("Downloading assets...", "assets");
|
||||||
|
@ -81,9 +90,17 @@ public class MinecraftAssetsProvider {
|
||||||
File file = new File(assets, filename);
|
File file = new File(assets, filename);
|
||||||
|
|
||||||
if (!file.exists() || !Checksum.equals(file, sha1)) {
|
if (!file.exists() || !Checksum.equals(file, sha1)) {
|
||||||
|
if (offline) {
|
||||||
|
if (file.exists()) {
|
||||||
|
project.getLogger().warn("Outdated asset " + entry.getKey());
|
||||||
|
} else {
|
||||||
|
throw new GradleException("Asset " + entry.getKey() + " not found at " + file.getAbsolutePath());
|
||||||
|
}
|
||||||
|
} else {
|
||||||
project.getLogger().debug(":downloading asset " + entry.getKey());
|
project.getLogger().debug(":downloading asset " + entry.getKey());
|
||||||
DownloadUtil.downloadIfChanged(new URL(Constants.RESOURCES_BASE + sha1.substring(0, 2) + "/" + sha1), file, project.getLogger(), true);
|
DownloadUtil.downloadIfChanged(new URL(Constants.RESOURCES_BASE + sha1.substring(0, 2) + "/" + sha1), file, project.getLogger(), true);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
String assetName = entry.getKey();
|
String assetName = entry.getKey();
|
||||||
int end = assetName.lastIndexOf("/") + 1;
|
int end = assetName.lastIndexOf("/") + 1;
|
||||||
if (end > 0) {
|
if (end > 0) {
|
||||||
|
|
|
@ -1,72 +0,0 @@
|
||||||
/*
|
|
||||||
* This file is part of fabric-loom, licensed under the MIT License (MIT).
|
|
||||||
*
|
|
||||||
* Copyright (c) 2016, 2017, 2018 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.providers;
|
|
||||||
|
|
||||||
import net.fabricmc.loom.LoomGradleExtension;
|
|
||||||
import net.fabricmc.loom.util.MapJarsTiny;
|
|
||||||
import net.fabricmc.stitch.merge.JarMerger;
|
|
||||||
import org.gradle.api.Project;
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.FileInputStream;
|
|
||||||
import java.io.FileOutputStream;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.Collection;
|
|
||||||
|
|
||||||
public class MinecraftJarProvider {
|
|
||||||
public File MINECRAFT_MERGED_JAR;
|
|
||||||
|
|
||||||
MinecraftProvider minecraftProvider;
|
|
||||||
|
|
||||||
public MinecraftJarProvider(Project project, MinecraftProvider minecraftProvider) throws IOException {
|
|
||||||
this.minecraftProvider = minecraftProvider;
|
|
||||||
initFiles(project, minecraftProvider);
|
|
||||||
process(project, minecraftProvider);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void process(Project project, MinecraftProvider minecraftProvider) throws IOException {
|
|
||||||
if (!MINECRAFT_MERGED_JAR.exists()) {
|
|
||||||
mergeJars(project);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void mergeJars(Project project) throws IOException {
|
|
||||||
project.getLogger().lifecycle(":merging jars");
|
|
||||||
try (JarMerger jarMerger = new JarMerger(minecraftProvider.MINECRAFT_CLIENT_JAR, minecraftProvider.MINECRAFT_SERVER_JAR, minecraftProvider.MINECRAFT_MERGED_JAR)) {
|
|
||||||
jarMerger.enableSyntheticParamsOffset();
|
|
||||||
jarMerger.merge();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void initFiles(Project project, MinecraftProvider minecraftProvider) {
|
|
||||||
LoomGradleExtension extension = project.getExtensions().getByType(LoomGradleExtension.class);
|
|
||||||
MINECRAFT_MERGED_JAR = new File(extension.getUserCache(), "minecraft-" + minecraftProvider.minecraftVersion + "-merged.jar");
|
|
||||||
}
|
|
||||||
|
|
||||||
public File getMergedJar() {
|
|
||||||
return MINECRAFT_MERGED_JAR;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -46,7 +46,7 @@ public class MinecraftMappedProvider extends DependencyProvider {
|
||||||
throw new RuntimeException("mappings file not found");
|
throw new RuntimeException("mappings file not found");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!extension.getMinecraftProvider().jarProvider.getMergedJar().exists()) {
|
if (!extension.getMinecraftProvider().getMergedJar().exists()) {
|
||||||
throw new RuntimeException("input merged jar not found");
|
throw new RuntimeException("input merged jar not found");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -57,7 +57,7 @@ public class MinecraftMappedProvider extends DependencyProvider {
|
||||||
if (getIntermediaryJar().exists()) {
|
if (getIntermediaryJar().exists()) {
|
||||||
getIntermediaryJar().delete();
|
getIntermediaryJar().delete();
|
||||||
}
|
}
|
||||||
new MapJarsTiny().mapJars(minecraftProvider.jarProvider, this, project);
|
new MapJarsTiny().mapJars(minecraftProvider, this, project);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!MINECRAFT_MAPPED_JAR.exists()) {
|
if (!MINECRAFT_MAPPED_JAR.exists()) {
|
||||||
|
|
|
@ -29,7 +29,9 @@ import com.google.gson.Gson;
|
||||||
import com.google.gson.GsonBuilder;
|
import com.google.gson.GsonBuilder;
|
||||||
import net.fabricmc.loom.LoomGradleExtension;
|
import net.fabricmc.loom.LoomGradleExtension;
|
||||||
import net.fabricmc.loom.util.*;
|
import net.fabricmc.loom.util.*;
|
||||||
|
import net.fabricmc.stitch.merge.JarMerger;
|
||||||
|
|
||||||
|
import org.gradle.api.GradleException;
|
||||||
import org.gradle.api.Project;
|
import org.gradle.api.Project;
|
||||||
import org.gradle.api.logging.Logger;
|
import org.gradle.api.logging.Logger;
|
||||||
|
|
||||||
|
@ -47,7 +49,6 @@ public class MinecraftProvider extends DependencyProvider {
|
||||||
|
|
||||||
public MinecraftVersionInfo versionInfo;
|
public MinecraftVersionInfo versionInfo;
|
||||||
public MinecraftLibraryProvider libraryProvider;
|
public MinecraftLibraryProvider libraryProvider;
|
||||||
public MinecraftJarProvider jarProvider;
|
|
||||||
|
|
||||||
File MINECRAFT_JSON;
|
File MINECRAFT_JSON;
|
||||||
File MINECRAFT_CLIENT_JAR;
|
File MINECRAFT_CLIENT_JAR;
|
||||||
|
@ -59,10 +60,11 @@ public class MinecraftProvider extends DependencyProvider {
|
||||||
@Override
|
@Override
|
||||||
public void provide(DependencyInfo dependency, Project project, LoomGradleExtension extension, Consumer<Runnable> postPopulationScheduler) throws Exception {
|
public void provide(DependencyInfo dependency, Project project, LoomGradleExtension extension, Consumer<Runnable> postPopulationScheduler) throws Exception {
|
||||||
minecraftVersion = dependency.getDependency().getVersion();
|
minecraftVersion = dependency.getDependency().getVersion();
|
||||||
|
boolean offline = project.getGradle().getStartParameter().isOffline();
|
||||||
|
|
||||||
initFiles(project);
|
initFiles(project);
|
||||||
|
|
||||||
downloadMcJson(project);
|
downloadMcJson(project, offline);
|
||||||
try (FileReader reader = new FileReader(MINECRAFT_JSON)) {
|
try (FileReader reader = new FileReader(MINECRAFT_JSON)) {
|
||||||
versionInfo = gson.fromJson(reader, MinecraftVersionInfo.class);
|
versionInfo = gson.fromJson(reader, MinecraftVersionInfo.class);
|
||||||
}
|
}
|
||||||
|
@ -70,11 +72,25 @@ public class MinecraftProvider extends DependencyProvider {
|
||||||
// Add Loom as an annotation processor
|
// Add Loom as an annotation processor
|
||||||
addDependency(project.files(this.getClass().getProtectionDomain().getCodeSource().getLocation()), project, "compileOnly");
|
addDependency(project.files(this.getClass().getProtectionDomain().getCodeSource().getLocation()), project, "compileOnly");
|
||||||
|
|
||||||
|
if (offline) {
|
||||||
|
if (MINECRAFT_CLIENT_JAR.exists() && MINECRAFT_SERVER_JAR.exists()) {
|
||||||
|
project.getLogger().debug("Found client and server jars, presuming up-to-date");
|
||||||
|
} else if (MINECRAFT_MERGED_JAR.exists()) {
|
||||||
|
//Strictly we don't need the split jars if the merged one exists, let's try go on
|
||||||
|
project.getLogger().warn("Missing game jar but merged jar present, things might end badly");
|
||||||
|
} else {
|
||||||
|
throw new GradleException("Missing jar(s); Client: " + MINECRAFT_CLIENT_JAR.exists() + ", Server: " + MINECRAFT_SERVER_JAR.exists());
|
||||||
|
}
|
||||||
|
} else {
|
||||||
downloadJars(project.getLogger());
|
downloadJars(project.getLogger());
|
||||||
|
}
|
||||||
|
|
||||||
libraryProvider = new MinecraftLibraryProvider();
|
libraryProvider = new MinecraftLibraryProvider();
|
||||||
libraryProvider.provide(this, project);
|
libraryProvider.provide(this, project);
|
||||||
jarProvider = new MinecraftJarProvider(project, this);
|
|
||||||
|
if (!MINECRAFT_MERGED_JAR.exists()) {
|
||||||
|
mergeJars(project.getLogger());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initFiles(Project project) {
|
private void initFiles(Project project) {
|
||||||
|
@ -86,19 +102,40 @@ public class MinecraftProvider extends DependencyProvider {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void downloadMcJson(Project project) throws IOException {
|
private void downloadMcJson(Project project, boolean offline) throws IOException {
|
||||||
LoomGradleExtension extension = project.getExtensions().getByType(LoomGradleExtension.class);
|
LoomGradleExtension extension = project.getExtensions().getByType(LoomGradleExtension.class);
|
||||||
File manifests = new File(extension.getUserCache(), "version_manifest.json");
|
File manifests = new File(extension.getUserCache(), "version_manifest.json");
|
||||||
|
|
||||||
|
if (offline) {
|
||||||
|
if (manifests.exists()) {
|
||||||
|
//If there is the manifests already we'll presume that's good enough
|
||||||
|
project.getLogger().debug("Found version manifests, presuming up-to-date");
|
||||||
|
} else {
|
||||||
|
//If we don't have the manifests then there's nothing more we can do
|
||||||
|
throw new GradleException("Version manifests not found at " + manifests.getAbsolutePath());
|
||||||
|
}
|
||||||
|
} else {
|
||||||
project.getLogger().debug("Downloading version manifests");
|
project.getLogger().debug("Downloading version manifests");
|
||||||
DownloadUtil.downloadIfChanged(new URL("https://launchermeta.mojang.com/mc/game/version_manifest.json"), manifests, project.getLogger());
|
DownloadUtil.downloadIfChanged(new URL("https://launchermeta.mojang.com/mc/game/version_manifest.json"), manifests, project.getLogger());
|
||||||
|
}
|
||||||
|
|
||||||
String versionManifest = Files.asCharSource(manifests, StandardCharsets.UTF_8).read();
|
String versionManifest = Files.asCharSource(manifests, StandardCharsets.UTF_8).read();
|
||||||
ManifestVersion mcManifest = new GsonBuilder().create().fromJson(versionManifest, ManifestVersion.class);
|
ManifestVersion mcManifest = new GsonBuilder().create().fromJson(versionManifest, ManifestVersion.class);
|
||||||
|
|
||||||
Optional<ManifestVersion.Versions> optionalVersion = mcManifest.versions.stream().filter(versions -> versions.id.equalsIgnoreCase(minecraftVersion)).findFirst();
|
Optional<ManifestVersion.Versions> optionalVersion = mcManifest.versions.stream().filter(versions -> versions.id.equalsIgnoreCase(minecraftVersion)).findFirst();
|
||||||
if (optionalVersion.isPresent()) {
|
if (optionalVersion.isPresent()) {
|
||||||
|
if (offline) {
|
||||||
|
if (MINECRAFT_JSON.exists()) {
|
||||||
|
//If there is the manifest already we'll presume that's good enough
|
||||||
|
project.getLogger().debug("Found Minecraft {} manifest, presuming up-to-date", minecraftVersion);
|
||||||
|
} else {
|
||||||
|
//If we don't have the manifests then there's nothing more we can do
|
||||||
|
throw new GradleException("Minecraft " + minecraftVersion + " manifest not found at " + MINECRAFT_JSON.getAbsolutePath());
|
||||||
|
}
|
||||||
|
} else {
|
||||||
project.getLogger().debug("Downloading Minecraft {} manifest", minecraftVersion);
|
project.getLogger().debug("Downloading Minecraft {} manifest", minecraftVersion);
|
||||||
DownloadUtil.downloadIfChanged(new URL(optionalVersion.get().url), MINECRAFT_JSON, project.getLogger());
|
DownloadUtil.downloadIfChanged(new URL(optionalVersion.get().url), MINECRAFT_JSON, project.getLogger());
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
throw new RuntimeException("Failed to find minecraft version: " + minecraftVersion);
|
throw new RuntimeException("Failed to find minecraft version: " + minecraftVersion);
|
||||||
}
|
}
|
||||||
|
@ -117,6 +154,18 @@ public class MinecraftProvider extends DependencyProvider {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void mergeJars(Logger logger) throws IOException {
|
||||||
|
logger.lifecycle(":merging jars");
|
||||||
|
try (JarMerger jarMerger = new JarMerger(MINECRAFT_CLIENT_JAR, MINECRAFT_SERVER_JAR, MINECRAFT_MERGED_JAR)) {
|
||||||
|
jarMerger.enableSyntheticParamsOffset();
|
||||||
|
jarMerger.merge();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public File getMergedJar() {
|
||||||
|
return MINECRAFT_MERGED_JAR;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getTargetConfig() {
|
public String getTargetConfig() {
|
||||||
return Constants.MINECRAFT;
|
return Constants.MINECRAFT;
|
||||||
|
|
|
@ -33,7 +33,7 @@ public class CleanLoomBinaries extends DefaultLoomTask {
|
||||||
public void run() {
|
public void run() {
|
||||||
Project project = this.getProject();
|
Project project = this.getProject();
|
||||||
LoomGradleExtension extension = project.getExtensions().getByType(LoomGradleExtension.class);
|
LoomGradleExtension extension = project.getExtensions().getByType(LoomGradleExtension.class);
|
||||||
extension.getMinecraftProvider().jarProvider.getMergedJar().delete();
|
extension.getMinecraftProvider().getMergedJar().delete();
|
||||||
extension.getMinecraftMappedProvider().getIntermediaryJar().delete();
|
extension.getMinecraftMappedProvider().getIntermediaryJar().delete();
|
||||||
extension.getMinecraftMappedProvider().getMappedJar().delete();
|
extension.getMinecraftMappedProvider().getMappedJar().delete();
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,8 +26,8 @@ package net.fabricmc.loom.util;
|
||||||
|
|
||||||
|
|
||||||
import net.fabricmc.loom.LoomGradleExtension;
|
import net.fabricmc.loom.LoomGradleExtension;
|
||||||
import net.fabricmc.loom.providers.MinecraftJarProvider;
|
|
||||||
import net.fabricmc.loom.providers.MinecraftMappedProvider;
|
import net.fabricmc.loom.providers.MinecraftMappedProvider;
|
||||||
|
import net.fabricmc.loom.providers.MinecraftProvider;
|
||||||
import net.fabricmc.loom.providers.MappingsProvider;
|
import net.fabricmc.loom.providers.MappingsProvider;
|
||||||
import net.fabricmc.tinyremapper.OutputConsumerPath;
|
import net.fabricmc.tinyremapper.OutputConsumerPath;
|
||||||
import net.fabricmc.tinyremapper.TinyRemapper;
|
import net.fabricmc.tinyremapper.TinyRemapper;
|
||||||
|
@ -41,7 +41,7 @@ import java.util.Arrays;
|
||||||
|
|
||||||
public class MapJarsTiny {
|
public class MapJarsTiny {
|
||||||
|
|
||||||
public void mapJars(MinecraftJarProvider jarProvider, MinecraftMappedProvider mapProvider, Project project) throws IOException {
|
public void mapJars(MinecraftProvider jarProvider, MinecraftMappedProvider mapProvider, Project project) throws IOException {
|
||||||
String fromM = "official";
|
String fromM = "official";
|
||||||
|
|
||||||
LoomGradleExtension extension = project.getExtensions().getByType(LoomGradleExtension.class);
|
LoomGradleExtension extension = project.getExtensions().getByType(LoomGradleExtension.class);
|
||||||
|
|
Loading…
Reference in New Issue