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
dev/0.11
modmuss50 2020-06-23 19:22:36 +01:00 committed by GitHub
parent 2f6071991c
commit 2d7421d4ed
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 84 additions and 36 deletions

View File

@ -51,6 +51,7 @@ import org.gradle.plugins.ide.idea.model.IdeaModel;
import net.fabricmc.loom.providers.LaunchProvider; import net.fabricmc.loom.providers.LaunchProvider;
import net.fabricmc.loom.providers.MappingsProvider; import net.fabricmc.loom.providers.MappingsProvider;
import net.fabricmc.loom.providers.MinecraftProvider; import net.fabricmc.loom.providers.MinecraftProvider;
import net.fabricmc.loom.providers.MappingsCache;
import net.fabricmc.loom.task.RemapJarTask; import net.fabricmc.loom.task.RemapJarTask;
import net.fabricmc.loom.task.RemapSourcesJarTask; import net.fabricmc.loom.task.RemapSourcesJarTask;
import net.fabricmc.loom.util.Constants; 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.KaptApInvoker;
import net.fabricmc.loom.util.mixin.ScalaApInvoker; import net.fabricmc.loom.util.mixin.ScalaApInvoker;
import net.fabricmc.loom.util.FabricApiExtension; import net.fabricmc.loom.util.FabricApiExtension;
import net.fabricmc.loom.util.DownloadUtil;
public class AbstractPlugin implements Plugin<Project> { public class AbstractPlugin implements Plugin<Project> {
protected Project project; protected Project project;
@ -81,6 +83,14 @@ public class AbstractPlugin implements Plugin<Project> {
project.getLogger().lifecycle("Fabric Loom: " + AbstractPlugin.class.getPackage().getImplementationVersion()); 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 // Apply default plugins
project.apply(ImmutableMap.of("plugin", "java")); project.apply(ImmutableMap.of("plugin", "java"));
project.apply(ImmutableMap.of("plugin", "eclipse")); project.apply(ImmutableMap.of("plugin", "eclipse"));
@ -135,33 +145,9 @@ public class AbstractPlugin implements Plugin<Project> {
configureIDEs(); configureIDEs();
configureCompile(); configureCompile();
configureMixin();
configureMaven(); 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() { public Project getProject() {
return project; return project;
} }
@ -298,7 +284,25 @@ public class AbstractPlugin implements Plugin<Project> {
AbstractArchiveTask jarTask = (AbstractArchiveTask) project1.getTasks().getByName("jar"); AbstractArchiveTask jarTask = (AbstractArchiveTask) project1.getTasks().getByName("jar");
extension.addUnmappedMod(jarTask.getArchivePath().toPath()); 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() { protected void configureMaven() {

View File

@ -50,7 +50,7 @@ public class MinecraftProcessedProvider extends MinecraftMappedProvider {
@Override @Override
protected void addDependencies(DependencyInfo dependency, Consumer<Runnable> postPopulationScheduler) { protected void addDependencies(DependencyInfo dependency, Consumer<Runnable> postPopulationScheduler) {
if (jarProcessorManager.isInvalid(projectMappedJar)) { if (jarProcessorManager.isInvalid(projectMappedJar) || isRefreshDeps()) {
getProject().getLogger().lifecycle(":processing mapped jar"); getProject().getLogger().lifecycle(":processing mapped jar");
invalidateJars(); invalidateJars();

View File

@ -47,6 +47,8 @@ public class ModDependencyInfo {
public final RemapData remapData; 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) { public ModDependencyInfo(String group, String name, String version, String classifier, File inputFile, File sourcesFile, Configuration targetConfig, RemapData remapData) {
this.group = group; this.group = group;
this.name = name; this.name = name;
@ -75,13 +77,17 @@ public class ModDependencyInfo {
} }
public boolean requiresRemapping() { 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() { public void finaliseRemapping() {
getRemappedOutput().setLastModified(inputFile.lastModified()); getRemappedOutput().setLastModified(inputFile.lastModified());
} }
public void forceRemap() {
forceRemap = true;
}
@Override @Override
public String toString() { public String toString() {
return String.format("%s:%s:%s:%s", group, name, version, classifier); return String.format("%s:%s:%s:%s", group, name, version, classifier);

View File

@ -62,4 +62,8 @@ public final class MappingsCache {
} }
} }
} }
public void invalidate() {
mappingsCache.clear();
}
} }

View File

@ -113,6 +113,10 @@ public class MappingsProvider extends DependencyProvider {
initFiles(); initFiles();
if (isRefreshDeps()) {
cleanFiles();
}
Files.createDirectories(mappingsDir); Files.createDirectories(mappingsDir);
Files.createDirectories(mappingsStepsDir); Files.createDirectories(mappingsStepsDir);
@ -126,11 +130,11 @@ public class MappingsProvider extends DependencyProvider {
tinyMappings = mappingsDir.resolve(StringUtils.removeSuffix(mappingsJar.getName(), ".jar") + ".tiny").toFile(); tinyMappings = mappingsDir.resolve(StringUtils.removeSuffix(mappingsJar.getName(), ".jar") + ".tiny").toFile();
tinyMappingsJar = new File(getExtension().getUserCache(), mappingsJar.getName().replace(".jar", "-" + jarClassifier + ".jar")); tinyMappingsJar = new File(getExtension().getUserCache(), mappingsJar.getName().replace(".jar", "-" + jarClassifier + ".jar"));
if (!tinyMappings.exists()) { if (!tinyMappings.exists() || isRefreshDeps()) {
storeMappings(getProject(), minecraftProvider, mappingsJar.toPath()); storeMappings(getProject(), minecraftProvider, mappingsJar.toPath());
} }
if (!tinyMappingsJar.exists()) { if (!tinyMappingsJar.exists() || isRefreshDeps()) {
ZipUtil.pack(new ZipEntrySource[] {new FileSource("mappings/mappings.tiny", tinyMappings)}, tinyMappingsJar); ZipUtil.pack(new ZipEntrySource[] {new FileSource("mappings/mappings.tiny", tinyMappings)}, tinyMappingsJar);
} }
@ -273,11 +277,23 @@ public class MappingsProvider extends DependencyProvider {
public void cleanFiles() { public void cleanFiles() {
try { try {
Files.walkFileTree(mappingsStepsDir, new DeletingFileVisitor()); if (Files.exists(mappingsStepsDir)) {
Files.deleteIfExists(baseTinyMappings); Files.walkFileTree(mappingsStepsDir, new DeletingFileVisitor());
}
if (Files.exists(baseTinyMappings)) {
Files.deleteIfExists(baseTinyMappings);
}
mappingsMixinExport.delete(); mappingsMixinExport.delete();
tinyMappings.delete();
tinyMappingsJar.delete(); if (tinyMappings != null) {
tinyMappings.delete();
}
if (tinyMappingsJar != null) {
tinyMappingsJar.delete();
}
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} }

View File

@ -59,7 +59,7 @@ public class MinecraftMappedProvider extends DependencyProvider {
throw new RuntimeException("input merged jar not found"); throw new RuntimeException("input merged jar not found");
} }
if (!minecraftMappedJar.exists() || !getIntermediaryJar().exists()) { if (!minecraftMappedJar.exists() || !getIntermediaryJar().exists() || isRefreshDeps()) {
if (minecraftMappedJar.exists()) { if (minecraftMappedJar.exists()) {
minecraftMappedJar.delete(); minecraftMappedJar.delete();
} }

View File

@ -97,7 +97,7 @@ public class MinecraftProvider extends DependencyProvider {
libraryProvider = new MinecraftLibraryProvider(); libraryProvider = new MinecraftLibraryProvider();
libraryProvider.provide(this, getProject()); libraryProvider.provide(this, getProject());
if (!minecraftMergedJar.exists()) { if (!minecraftMergedJar.exists() || isRefreshDeps()) {
try { try {
mergeJars(getProject().getLogger()); mergeJars(getProject().getLogger());
} catch (ZipError e) { } catch (ZipError e) {
@ -160,7 +160,7 @@ public class MinecraftProvider extends DependencyProvider {
throw new GradleException("Minecraft " + minecraftVersion + " manifest not found at " + minecraftJson.getAbsolutePath()); throw new GradleException("Minecraft " + minecraftVersion + " manifest not found at " + minecraftJson.getAbsolutePath());
} }
} else { } else {
if (StaticPathWatcher.INSTANCE.hasFileChanged(minecraftJson.toPath())) { if (StaticPathWatcher.INSTANCE.hasFileChanged(minecraftJson.toPath()) || isRefreshDeps()) {
getProject().getLogger().debug("Downloading Minecraft {} manifest", minecraftVersion); getProject().getLogger().debug("Downloading Minecraft {} manifest", minecraftVersion);
DownloadUtil.downloadIfChanged(new URL(optionalVersion.get().url), minecraftJson, getProject().getLogger()); DownloadUtil.downloadIfChanged(new URL(optionalVersion.get().url), minecraftJson, getProject().getLogger());
} }

View File

@ -91,6 +91,10 @@ public abstract class DependencyProvider {
return extension; return extension;
} }
public boolean isRefreshDeps() {
return getProject().getGradle().getStartParameter().isRefreshDependencies();
}
public static class DependencyInfo { public static class DependencyInfo {
final Project project; final Project project;
final Dependency dependency; final Dependency dependency;

View File

@ -36,6 +36,8 @@ import org.gradle.api.Project;
import org.gradle.api.logging.Logger; import org.gradle.api.logging.Logger;
public class DownloadUtil { 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. * 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 { public static void downloadIfChanged(URL from, File to, Logger logger, boolean quiet) throws IOException {
HttpURLConnection connection = (HttpURLConnection) from.openConnection(); 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 the output already exists we'll use it's last modified time
if (to.exists()) { if (to.exists()) {
connection.setIfModifiedSince(to.lastModified()); connection.setIfModifiedSince(to.lastModified());

View File

@ -53,6 +53,7 @@ public class ModCompileRemapper {
public static void remapDependencies(Project project, String mappingsSuffix, LoomGradleExtension extension, SourceRemapper sourceRemapper) { public static void remapDependencies(Project project, String mappingsSuffix, LoomGradleExtension extension, SourceRemapper sourceRemapper) {
Logger logger = project.getLogger(); Logger logger = project.getLogger();
DependencyHandler dependencies = project.getDependencies(); DependencyHandler dependencies = project.getDependencies();
boolean refreshDeps = project.getGradle().getStartParameter().isRefreshDependencies();
final File modStore = extension.getRemappedModCache(); final File modStore = extension.getRemappedModCache();
final RemapData remapData = new RemapData(mappingsSuffix, modStore); final RemapData remapData = new RemapData(mappingsSuffix, modStore);
@ -90,6 +91,11 @@ public class ModCompileRemapper {
File sources = findSources(dependencies, artifact); File sources = findSources(dependencies, artifact);
ModDependencyInfo info = new ModDependencyInfo(group, name, version, classifierSuffix, artifact.getFile(), sources, remappedConfig, remapData); ModDependencyInfo info = new ModDependencyInfo(group, name, version, classifierSuffix, artifact.getFile(), sources, remappedConfig, remapData);
if (refreshDeps) {
info.forceRemap();
}
modDependencies.add(info); modDependencies.add(info);
String remappedLog = group + ":" + name + ":" + version + classifierSuffix + " (" + mappingsSuffix + ")"; 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) { private static void scheduleSourcesRemapping(Project project, SourceRemapper sourceRemapper, File sources, String remappedLog, String remappedFilename, File modStore) {
project.getLogger().info(":providing " + remappedLog + " sources"); project.getLogger().info(":providing " + remappedLog + " sources");
File remappedSources = new File(modStore, remappedFilename + "-sources.jar"); 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 { try {
sourceRemapper.scheduleRemapSources(sources, remappedSources); sourceRemapper.scheduleRemapSources(sources, remappedSources);