From 2d7421d4ed5b0256aa25108de06af814e78a3007 Mon Sep 17 00:00:00 2001 From: modmuss50 Date: Tue, 23 Jun 2020 19:22:36 +0100 Subject: [PATCH] Rengenerate and download all files with --refresh-dependencies (#227) * Re generate all files with --refresh-dependencies * Always re-process jar processors * Update mixin compile extensions --- .../net/fabricmc/loom/AbstractPlugin.java | 52 ++++++++++--------- .../MinecraftProcessedProvider.java | 2 +- .../dependency/ModDependencyInfo.java | 8 ++- .../loom/providers/MappingsCache.java | 4 ++ .../loom/providers/MappingsProvider.java | 28 +++++++--- .../providers/MinecraftMappedProvider.java | 2 +- .../loom/providers/MinecraftProvider.java | 4 +- .../loom/util/DependencyProvider.java | 4 ++ .../net/fabricmc/loom/util/DownloadUtil.java | 7 +++ .../loom/util/ModCompileRemapper.java | 9 +++- 10 files changed, 84 insertions(+), 36 deletions(-) diff --git a/src/main/java/net/fabricmc/loom/AbstractPlugin.java b/src/main/java/net/fabricmc/loom/AbstractPlugin.java index 9134a02..e0641a0 100644 --- a/src/main/java/net/fabricmc/loom/AbstractPlugin.java +++ b/src/main/java/net/fabricmc/loom/AbstractPlugin.java @@ -51,6 +51,7 @@ import org.gradle.plugins.ide.idea.model.IdeaModel; import net.fabricmc.loom.providers.LaunchProvider; import net.fabricmc.loom.providers.MappingsProvider; import net.fabricmc.loom.providers.MinecraftProvider; +import net.fabricmc.loom.providers.MappingsCache; import net.fabricmc.loom.task.RemapJarTask; import net.fabricmc.loom.task.RemapSourcesJarTask; import net.fabricmc.loom.util.Constants; @@ -63,6 +64,7 @@ import net.fabricmc.loom.util.mixin.JavaApInvoker; import net.fabricmc.loom.util.mixin.KaptApInvoker; import net.fabricmc.loom.util.mixin.ScalaApInvoker; import net.fabricmc.loom.util.FabricApiExtension; +import net.fabricmc.loom.util.DownloadUtil; public class AbstractPlugin implements Plugin { protected Project project; @@ -81,6 +83,14 @@ public class AbstractPlugin implements Plugin { project.getLogger().lifecycle("Fabric Loom: " + AbstractPlugin.class.getPackage().getImplementationVersion()); + boolean refreshDeps = project.getGradle().getStartParameter().isRefreshDependencies(); + DownloadUtil.refreshDeps = refreshDeps; + + if (refreshDeps) { + MappingsCache.INSTANCE.invalidate(); + project.getLogger().lifecycle("Refresh dependencies is in use, loom will be significantly slower."); + } + // Apply default plugins project.apply(ImmutableMap.of("plugin", "java")); project.apply(ImmutableMap.of("plugin", "eclipse")); @@ -135,33 +145,9 @@ public class AbstractPlugin implements Plugin { configureIDEs(); configureCompile(); - configureMixin(); configureMaven(); } - private void configureMixin() { - if (project.getPluginManager().hasPlugin("org.jetbrains.kotlin.kapt")) { - // If loom is applied after kapt, then kapt will use the AP arguments too early for loom to pass the arguments we need for mixin. - throw new IllegalArgumentException("fabric-loom must be applied BEFORE kapt in the plugins { } block."); - } - - // Full plugin and mappings information is only available after evaluation - project.afterEvaluate((project) -> { - project.getLogger().lifecycle("Configuring compiler arguments for Java"); - new JavaApInvoker(project).configureMixin(); - - if (project.getPluginManager().hasPlugin("scala")) { - project.getLogger().lifecycle("Configuring compiler arguments for Scala"); - new ScalaApInvoker(project).configureMixin(); - } - - if (project.getPluginManager().hasPlugin("org.jetbrains.kotlin.kapt")) { - project.getLogger().lifecycle("Configuring compiler arguments for Kapt plugin"); - new KaptApInvoker(project).configureMixin(); - } - }); - } - public Project getProject() { return project; } @@ -298,7 +284,25 @@ public class AbstractPlugin implements Plugin { AbstractArchiveTask jarTask = (AbstractArchiveTask) project1.getTasks().getByName("jar"); extension.addUnmappedMod(jarTask.getArchivePath().toPath()); } + + project.getLogger().lifecycle("Configuring compiler arguments for Java"); + new JavaApInvoker(project).configureMixin(); + + if (project.getPluginManager().hasPlugin("scala")) { + project.getLogger().lifecycle("Configuring compiler arguments for Scala"); + new ScalaApInvoker(project).configureMixin(); + } + + if (project.getPluginManager().hasPlugin("org.jetbrains.kotlin.kapt")) { + project.getLogger().lifecycle("Configuring compiler arguments for Kapt plugin"); + new KaptApInvoker(project).configureMixin(); + } }); + + if (project.getPluginManager().hasPlugin("org.jetbrains.kotlin.kapt")) { + // If loom is applied after kapt, then kapt will use the AP arguments too early for loom to pass the arguments we need for mixin. + throw new IllegalArgumentException("fabric-loom must be applied BEFORE kapt in the plugins { } block."); + } } protected void configureMaven() { diff --git a/src/main/java/net/fabricmc/loom/processors/MinecraftProcessedProvider.java b/src/main/java/net/fabricmc/loom/processors/MinecraftProcessedProvider.java index d4c9665..af9eba2 100644 --- a/src/main/java/net/fabricmc/loom/processors/MinecraftProcessedProvider.java +++ b/src/main/java/net/fabricmc/loom/processors/MinecraftProcessedProvider.java @@ -50,7 +50,7 @@ public class MinecraftProcessedProvider extends MinecraftMappedProvider { @Override protected void addDependencies(DependencyInfo dependency, Consumer postPopulationScheduler) { - if (jarProcessorManager.isInvalid(projectMappedJar)) { + if (jarProcessorManager.isInvalid(projectMappedJar) || isRefreshDeps()) { getProject().getLogger().lifecycle(":processing mapped jar"); invalidateJars(); diff --git a/src/main/java/net/fabricmc/loom/processors/dependency/ModDependencyInfo.java b/src/main/java/net/fabricmc/loom/processors/dependency/ModDependencyInfo.java index 85f6b99..1965845 100644 --- a/src/main/java/net/fabricmc/loom/processors/dependency/ModDependencyInfo.java +++ b/src/main/java/net/fabricmc/loom/processors/dependency/ModDependencyInfo.java @@ -47,6 +47,8 @@ public class ModDependencyInfo { public final RemapData remapData; + private boolean forceRemap = false; + public ModDependencyInfo(String group, String name, String version, String classifier, File inputFile, File sourcesFile, Configuration targetConfig, RemapData remapData) { this.group = group; this.name = name; @@ -75,13 +77,17 @@ public class ModDependencyInfo { } public boolean requiresRemapping() { - return !getRemappedOutput().exists() || inputFile.lastModified() <= 0 || inputFile.lastModified() > getRemappedOutput().lastModified(); + return !getRemappedOutput().exists() || inputFile.lastModified() <= 0 || inputFile.lastModified() > getRemappedOutput().lastModified() || forceRemap; } public void finaliseRemapping() { getRemappedOutput().setLastModified(inputFile.lastModified()); } + public void forceRemap() { + forceRemap = true; + } + @Override public String toString() { return String.format("%s:%s:%s:%s", group, name, version, classifier); diff --git a/src/main/java/net/fabricmc/loom/providers/MappingsCache.java b/src/main/java/net/fabricmc/loom/providers/MappingsCache.java index fbcec82..2db3b5e 100644 --- a/src/main/java/net/fabricmc/loom/providers/MappingsCache.java +++ b/src/main/java/net/fabricmc/loom/providers/MappingsCache.java @@ -62,4 +62,8 @@ public final class MappingsCache { } } } + + public void invalidate() { + mappingsCache.clear(); + } } diff --git a/src/main/java/net/fabricmc/loom/providers/MappingsProvider.java b/src/main/java/net/fabricmc/loom/providers/MappingsProvider.java index 426ebd5..17b4daa 100644 --- a/src/main/java/net/fabricmc/loom/providers/MappingsProvider.java +++ b/src/main/java/net/fabricmc/loom/providers/MappingsProvider.java @@ -113,6 +113,10 @@ public class MappingsProvider extends DependencyProvider { initFiles(); + if (isRefreshDeps()) { + cleanFiles(); + } + Files.createDirectories(mappingsDir); Files.createDirectories(mappingsStepsDir); @@ -126,11 +130,11 @@ public class MappingsProvider extends DependencyProvider { tinyMappings = mappingsDir.resolve(StringUtils.removeSuffix(mappingsJar.getName(), ".jar") + ".tiny").toFile(); tinyMappingsJar = new File(getExtension().getUserCache(), mappingsJar.getName().replace(".jar", "-" + jarClassifier + ".jar")); - if (!tinyMappings.exists()) { + if (!tinyMappings.exists() || isRefreshDeps()) { storeMappings(getProject(), minecraftProvider, mappingsJar.toPath()); } - if (!tinyMappingsJar.exists()) { + if (!tinyMappingsJar.exists() || isRefreshDeps()) { ZipUtil.pack(new ZipEntrySource[] {new FileSource("mappings/mappings.tiny", tinyMappings)}, tinyMappingsJar); } @@ -273,11 +277,23 @@ public class MappingsProvider extends DependencyProvider { public void cleanFiles() { try { - Files.walkFileTree(mappingsStepsDir, new DeletingFileVisitor()); - Files.deleteIfExists(baseTinyMappings); + if (Files.exists(mappingsStepsDir)) { + Files.walkFileTree(mappingsStepsDir, new DeletingFileVisitor()); + } + + if (Files.exists(baseTinyMappings)) { + Files.deleteIfExists(baseTinyMappings); + } + mappingsMixinExport.delete(); - tinyMappings.delete(); - tinyMappingsJar.delete(); + + if (tinyMappings != null) { + tinyMappings.delete(); + } + + if (tinyMappingsJar != null) { + tinyMappingsJar.delete(); + } } catch (IOException e) { e.printStackTrace(); } diff --git a/src/main/java/net/fabricmc/loom/providers/MinecraftMappedProvider.java b/src/main/java/net/fabricmc/loom/providers/MinecraftMappedProvider.java index 52f9f9d..75eda8b 100644 --- a/src/main/java/net/fabricmc/loom/providers/MinecraftMappedProvider.java +++ b/src/main/java/net/fabricmc/loom/providers/MinecraftMappedProvider.java @@ -59,7 +59,7 @@ public class MinecraftMappedProvider extends DependencyProvider { throw new RuntimeException("input merged jar not found"); } - if (!minecraftMappedJar.exists() || !getIntermediaryJar().exists()) { + if (!minecraftMappedJar.exists() || !getIntermediaryJar().exists() || isRefreshDeps()) { if (minecraftMappedJar.exists()) { minecraftMappedJar.delete(); } diff --git a/src/main/java/net/fabricmc/loom/providers/MinecraftProvider.java b/src/main/java/net/fabricmc/loom/providers/MinecraftProvider.java index 8984619..4deed46 100644 --- a/src/main/java/net/fabricmc/loom/providers/MinecraftProvider.java +++ b/src/main/java/net/fabricmc/loom/providers/MinecraftProvider.java @@ -97,7 +97,7 @@ public class MinecraftProvider extends DependencyProvider { libraryProvider = new MinecraftLibraryProvider(); libraryProvider.provide(this, getProject()); - if (!minecraftMergedJar.exists()) { + if (!minecraftMergedJar.exists() || isRefreshDeps()) { try { mergeJars(getProject().getLogger()); } catch (ZipError e) { @@ -160,7 +160,7 @@ public class MinecraftProvider extends DependencyProvider { throw new GradleException("Minecraft " + minecraftVersion + " manifest not found at " + minecraftJson.getAbsolutePath()); } } else { - if (StaticPathWatcher.INSTANCE.hasFileChanged(minecraftJson.toPath())) { + if (StaticPathWatcher.INSTANCE.hasFileChanged(minecraftJson.toPath()) || isRefreshDeps()) { getProject().getLogger().debug("Downloading Minecraft {} manifest", minecraftVersion); DownloadUtil.downloadIfChanged(new URL(optionalVersion.get().url), minecraftJson, getProject().getLogger()); } diff --git a/src/main/java/net/fabricmc/loom/util/DependencyProvider.java b/src/main/java/net/fabricmc/loom/util/DependencyProvider.java index bb998e7..668164e 100644 --- a/src/main/java/net/fabricmc/loom/util/DependencyProvider.java +++ b/src/main/java/net/fabricmc/loom/util/DependencyProvider.java @@ -91,6 +91,10 @@ public abstract class DependencyProvider { return extension; } + public boolean isRefreshDeps() { + return getProject().getGradle().getStartParameter().isRefreshDependencies(); + } + public static class DependencyInfo { final Project project; final Dependency dependency; diff --git a/src/main/java/net/fabricmc/loom/util/DownloadUtil.java b/src/main/java/net/fabricmc/loom/util/DownloadUtil.java index 35f17d0..1dc1d2a 100644 --- a/src/main/java/net/fabricmc/loom/util/DownloadUtil.java +++ b/src/main/java/net/fabricmc/loom/util/DownloadUtil.java @@ -36,6 +36,8 @@ import org.gradle.api.Project; import org.gradle.api.logging.Logger; public class DownloadUtil { + public static boolean refreshDeps = false; + /** * Download from the given {@link URL} to the given {@link File} so long as there are differences between them. * @@ -60,6 +62,11 @@ public class DownloadUtil { public static void downloadIfChanged(URL from, File to, Logger logger, boolean quiet) throws IOException { HttpURLConnection connection = (HttpURLConnection) from.openConnection(); + if (refreshDeps) { + getETagFile(to).delete(); + to.delete(); + } + //If the output already exists we'll use it's last modified time if (to.exists()) { connection.setIfModifiedSince(to.lastModified()); diff --git a/src/main/java/net/fabricmc/loom/util/ModCompileRemapper.java b/src/main/java/net/fabricmc/loom/util/ModCompileRemapper.java index d140e3e..4020f07 100644 --- a/src/main/java/net/fabricmc/loom/util/ModCompileRemapper.java +++ b/src/main/java/net/fabricmc/loom/util/ModCompileRemapper.java @@ -53,6 +53,7 @@ public class ModCompileRemapper { public static void remapDependencies(Project project, String mappingsSuffix, LoomGradleExtension extension, SourceRemapper sourceRemapper) { Logger logger = project.getLogger(); DependencyHandler dependencies = project.getDependencies(); + boolean refreshDeps = project.getGradle().getStartParameter().isRefreshDependencies(); final File modStore = extension.getRemappedModCache(); final RemapData remapData = new RemapData(mappingsSuffix, modStore); @@ -90,6 +91,11 @@ public class ModCompileRemapper { File sources = findSources(dependencies, artifact); ModDependencyInfo info = new ModDependencyInfo(group, name, version, classifierSuffix, artifact.getFile(), sources, remappedConfig, remapData); + + if (refreshDeps) { + info.forceRemap(); + } + modDependencies.add(info); String remappedLog = group + ":" + name + ":" + version + classifierSuffix + " (" + mappingsSuffix + ")"; @@ -162,8 +168,9 @@ public class ModCompileRemapper { private static void scheduleSourcesRemapping(Project project, SourceRemapper sourceRemapper, File sources, String remappedLog, String remappedFilename, File modStore) { project.getLogger().info(":providing " + remappedLog + " sources"); File remappedSources = new File(modStore, remappedFilename + "-sources.jar"); + boolean refreshDeps = project.getGradle().getStartParameter().isRefreshDependencies(); - if (!remappedSources.exists() || sources.lastModified() <= 0 || sources.lastModified() > remappedSources.lastModified()) { + if (!remappedSources.exists() || sources.lastModified() <= 0 || sources.lastModified() > remappedSources.lastModified() || refreshDeps) { try { sourceRemapper.scheduleRemapSources(sources, remappedSources);