From 13ae0ae26391f39e01926903ca67fbdd81b00fda Mon Sep 17 00:00:00 2001 From: modmuss50 Date: Tue, 22 Oct 2019 20:28:00 +0100 Subject: [PATCH] Initial gradle 6.0 rc1 fixes, ugly but works. Closes #131 --- .../net/fabricmc/loom/task/RemapJarTask.java | 3 +- .../net/fabricmc/loom/util/GradleSupport.java | 57 +++++++++++++++++++ .../loom/util/ModCompileRemapper.java | 6 +- 3 files changed, 62 insertions(+), 4 deletions(-) create mode 100644 src/main/java/net/fabricmc/loom/util/GradleSupport.java diff --git a/src/main/java/net/fabricmc/loom/task/RemapJarTask.java b/src/main/java/net/fabricmc/loom/task/RemapJarTask.java index 065ed62..7a7bfcb 100644 --- a/src/main/java/net/fabricmc/loom/task/RemapJarTask.java +++ b/src/main/java/net/fabricmc/loom/task/RemapJarTask.java @@ -26,6 +26,7 @@ package net.fabricmc.loom.task; import net.fabricmc.loom.LoomGradleExtension; import net.fabricmc.loom.providers.MappingsProvider; +import net.fabricmc.loom.util.GradleSupport; import net.fabricmc.loom.util.MixinRefmapHelper; import net.fabricmc.loom.util.NestedJars; import net.fabricmc.loom.util.TinyRemapperMappingsHelper; @@ -54,7 +55,7 @@ public class RemapJarTask extends Jar { public RemapJarTask() { super(); - input = getProject().getLayout().fileProperty(); + input = GradleSupport.getfileProperty(getProject()); addNestedDependencies = getProject().getObjects().property(Boolean.class); } diff --git a/src/main/java/net/fabricmc/loom/util/GradleSupport.java b/src/main/java/net/fabricmc/loom/util/GradleSupport.java new file mode 100644 index 0000000..92c9a63 --- /dev/null +++ b/src/main/java/net/fabricmc/loom/util/GradleSupport.java @@ -0,0 +1,57 @@ +/* + * 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.util; + +import org.gradle.api.Project; +import org.gradle.api.file.RegularFileProperty; +import org.gradle.api.model.ObjectFactory; + +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; + +//This is used to bridge the gap over large gradle api changes. +public class GradleSupport { + + public static RegularFileProperty getfileProperty(Project project){ + try { + //First try the new method, if that fails fall back. + return getfilePropertyModern(project); + } catch (Exception e){ + //Nope + } + return getfilePropertyLegacy(project); + } + + private static RegularFileProperty getfilePropertyModern(Project project) throws NoSuchMethodException, InvocationTargetException, IllegalAccessException { + ObjectFactory objectFactory = project.getObjects(); + Method method = objectFactory.getClass().getDeclaredMethod("fileProperty"); + method.setAccessible(true); + return (RegularFileProperty) method.invoke(objectFactory); + } + + private static RegularFileProperty getfilePropertyLegacy(Project project){ + return project.getLayout().fileProperty(); + } +} diff --git a/src/main/java/net/fabricmc/loom/util/ModCompileRemapper.java b/src/main/java/net/fabricmc/loom/util/ModCompileRemapper.java index 6b3fa2d..1433230 100644 --- a/src/main/java/net/fabricmc/loom/util/ModCompileRemapper.java +++ b/src/main/java/net/fabricmc/loom/util/ModCompileRemapper.java @@ -78,7 +78,7 @@ public class ModCompileRemapper { String remappedLog = group + ":" + name + ":" + version + classifierSuffix + " (" + mappingsPrefix + ")"; String remappedNotation = "net.fabricmc.mapped:" + mappingsPrefix + "." + group + "." + name + ":" + version + classifierSuffix; String remappedFilename = mappingsPrefix + "." + group + "." + name + "-" + version + classifierSuffix.replace(':', '-'); - project.getLogger().lifecycle(":providing " + remappedLog); + project.getLogger().info(":providing " + remappedLog); File modStore = extension.getRemappedModCache(); @@ -109,7 +109,7 @@ public class ModCompileRemapper { } private static void addToRegularCompile(Project project, Configuration regularCompile, String notation) { - project.getLogger().lifecycle(":providing " + notation); + project.getLogger().info(":providing " + notation); DependencyHandler dependencies = project.getDependencies(); Dependency dep = dependencies.module(notation); if (dep instanceof ModuleDependency) { @@ -158,7 +158,7 @@ public class ModCompileRemapper { private static void scheduleSourcesRemapping(Project project, Consumer postPopulationScheduler, File sources, String remappedLog, String remappedFilename, File modStore) { postPopulationScheduler.accept(() -> { - project.getLogger().lifecycle(":providing " + remappedLog + " sources"); + project.getLogger().info(":providing " + remappedLog + " sources"); File remappedSources = new File(modStore, remappedFilename + "-sources.jar"); if (!remappedSources.exists() || sources.lastModified() <= 0 || sources.lastModified() > remappedSources.lastModified()) {