From 3f24ce02893e55bef4be4d06d2bc544336afa4df Mon Sep 17 00:00:00 2001 From: modmuss50 Date: Fri, 7 Oct 2016 13:17:04 +0100 Subject: [PATCH] Initial work on pre baking mixins Downloading of fabric base + deps needs fixing, I may do it a different way. This is mainly moving pc commit as a lot of stuff here isn't final. --- build.gradle | 20 +++-- .../net/fabricmc/loom/AbstractPlugin.java | 12 +-- .../net/fabricmc/loom/LoomGradlePlugin.java | 3 +- .../net/fabricmc/loom/task/DownloadTask.java | 1 - .../loom/task/GenVSCodeProjectTask.java | 3 +- .../net/fabricmc/loom/task/MapJarsTask.java | 2 +- .../fabricmc/loom/task/ProcessModsTask.java | 90 +++++++++++++++++++ .../net/fabricmc/loom/task/RunClientTask.java | 2 +- .../net/fabricmc/loom/task/RunServerTask.java | 2 +- .../net/fabricmc/loom/util/Constants.java | 2 + .../loom/util/proccessing/PreBakeMixins.java | 53 +++++++++++ 11 files changed, 172 insertions(+), 18 deletions(-) create mode 100644 src/main/java/net/fabricmc/loom/task/ProcessModsTask.java create mode 100644 src/main/java/net/fabricmc/loom/util/proccessing/PreBakeMixins.java diff --git a/build.gradle b/build.gradle index 0df6822a..b222764a 100644 --- a/build.gradle +++ b/build.gradle @@ -31,6 +31,14 @@ repositories { name "RX14 Repository" url 'http://mvn.rx14.co.uk/local/' } + maven { + name = 'Mojang' + url = 'https://libraries.minecraft.net/' + } + maven { + name = 'SpongePowered' + url = 'http://repo.spongepowered.org/maven' + } } configurations { @@ -50,6 +58,10 @@ dependencies { shade 'com.google.guava:guava:19.0' shade 'net.fabricmc:weave:0.1.0.6' shade 'cuchaz:enigma:0.11.0.5:lib' + shade 'org.jboss.shrinkwrap.resolver:shrinkwrap-resolver-depchain:2.2.4' + + + compile 'net.fabricmc:fabric-base:16w38a-0.0.4-SNAPSHOT' } sourceSets { @@ -60,11 +72,9 @@ sourceSets { } jar { - configurations.shade.each { dep -> - from(project.zipTree(dep)) { - exclude 'META-INF', 'META-INF/**' - } - } + from { + configurations.shade.collect { it.isDirectory() ? it : zipTree(it) } + } } diff --git a/src/main/java/net/fabricmc/loom/AbstractPlugin.java b/src/main/java/net/fabricmc/loom/AbstractPlugin.java index 9fbcfc81..fcfa9f5e 100644 --- a/src/main/java/net/fabricmc/loom/AbstractPlugin.java +++ b/src/main/java/net/fabricmc/loom/AbstractPlugin.java @@ -31,7 +31,6 @@ import com.google.gson.JsonObject; import net.fabricmc.loom.task.DownloadTask; import net.fabricmc.loom.util.Constants; import net.fabricmc.loom.util.Version; -import org.gradle.api.Action; import org.gradle.api.Plugin; import org.gradle.api.Project; import org.gradle.api.Task; @@ -76,6 +75,7 @@ public class AbstractPlugin implements Plugin { project.getConfigurations().maybeCreate(Constants.CONFIG_MC_DEPENDENCIES); project.getConfigurations().maybeCreate(Constants.CONFIG_MC_DEPENDENCIES_CLIENT); project.getConfigurations().maybeCreate(Constants.CONFIG_NATIVES); + project.getConfigurations().maybeCreate(Constants.COMPILE_MODS); // Common libraries extends from client libraries, CONFIG_MC_DEPENDENCIES will contains all MC dependencies project.getConfigurations().getByName(Constants.CONFIG_MC_DEPENDENCIES).extendsFrom(project.getConfigurations().getByName(Constants.CONFIG_MC_DEPENDENCIES_CLIENT)); @@ -84,12 +84,12 @@ public class AbstractPlugin implements Plugin { configureCompile(); //TODO other languages? - Map> taskMap = project.getAllTasks(true); - for(Map.Entry> entry : taskMap.entrySet()) { + Map> taskMap = project.getAllTasks(true); + for (Map.Entry> entry : taskMap.entrySet()) { Project project = entry.getKey(); Set taskSet = entry.getValue(); - for(Task task : taskSet){ - if(task instanceof JavaCompile){ + for (Task task : taskSet) { + if (task instanceof JavaCompile) { JavaCompile javaCompileTask = (JavaCompile) task; javaCompileTask.doFirst(task1 -> { project.getLogger().lifecycle(":setting java compiler args"); @@ -227,7 +227,7 @@ public class AbstractPlugin implements Plugin { } catch (IOException e) { e.printStackTrace(); } - project1.getDependencies().add(Constants.CONFIG_MC_DEPENDENCIES, "net.minecraft:" + Constants.MINECRAFT_MAPPED_JAR.get(extension).getName().replace(".jar", "")); + project1.getDependencies().add(Constants.CONFIG_MC_DEPENDENCIES, "net.minecraft:" + Constants.MINECRAFT_FINAL_JAR.get(extension).getName().replace(".jar", "")); if (extension.fabricVersion != null && !extension.fabricVersion.isEmpty()) { //only add this when not in a fabric dev env diff --git a/src/main/java/net/fabricmc/loom/LoomGradlePlugin.java b/src/main/java/net/fabricmc/loom/LoomGradlePlugin.java index fd39b4e0..a9fba59d 100644 --- a/src/main/java/net/fabricmc/loom/LoomGradlePlugin.java +++ b/src/main/java/net/fabricmc/loom/LoomGradlePlugin.java @@ -36,7 +36,8 @@ public class LoomGradlePlugin extends AbstractPlugin { makeTask("download", DownloadTask.class); makeTask("mergeJars", MergeJarsTask.class).dependsOn("download"); makeTask("mapJars", MapJarsTask.class).dependsOn("mergeJars"); - makeTask("setupFabric", DefaultTask.class).dependsOn("mapJars"); + makeTask("processMods", ProcessModsTask.class).dependsOn("mapJars"); + makeTask("setupFabric", DefaultTask.class).dependsOn("processMods"); makeTask("extractNatives", ExtractNativesTask.class).dependsOn("download"); makeTask("genIdeaRuns", GenIdeaProjectTask.class).dependsOn("cleanIdea").dependsOn("idea").dependsOn("extractNatives"); diff --git a/src/main/java/net/fabricmc/loom/task/DownloadTask.java b/src/main/java/net/fabricmc/loom/task/DownloadTask.java index c2043a48..2a54623d 100644 --- a/src/main/java/net/fabricmc/loom/task/DownloadTask.java +++ b/src/main/java/net/fabricmc/loom/task/DownloadTask.java @@ -45,7 +45,6 @@ import java.io.File; import java.io.FileReader; import java.io.IOException; import java.net.URL; -import java.nio.charset.Charset; import java.util.Map; import java.util.Optional; diff --git a/src/main/java/net/fabricmc/loom/task/GenVSCodeProjectTask.java b/src/main/java/net/fabricmc/loom/task/GenVSCodeProjectTask.java index 37df9e20..98e3a37c 100644 --- a/src/main/java/net/fabricmc/loom/task/GenVSCodeProjectTask.java +++ b/src/main/java/net/fabricmc/loom/task/GenVSCodeProjectTask.java @@ -35,7 +35,6 @@ import org.gradle.api.tasks.TaskAction; import java.io.File; import java.io.FileReader; import java.io.IOException; -import java.nio.charset.Charset; import java.util.ArrayList; import java.util.List; @@ -59,7 +58,7 @@ public class GenVSCodeProjectTask extends DefaultTask { libs.add(library.getFile(extension).getAbsolutePath()); } } - libs.add(Constants.MINECRAFT_MAPPED_JAR.get(extension).getAbsolutePath()); + libs.add(Constants.MINECRAFT_FINAL_JAR.get(extension).getAbsolutePath()); for (File file : getProject().getConfigurations().getByName("compile").getFiles()) { libs.add(file.getAbsolutePath()); } diff --git a/src/main/java/net/fabricmc/loom/task/MapJarsTask.java b/src/main/java/net/fabricmc/loom/task/MapJarsTask.java index ca57243a..25afc2d7 100644 --- a/src/main/java/net/fabricmc/loom/task/MapJarsTask.java +++ b/src/main/java/net/fabricmc/loom/task/MapJarsTask.java @@ -51,7 +51,6 @@ public class MapJarsTask extends DefaultTask { @TaskAction public void mapJars() throws IOException, MappingParseException { LoomGradleExtension extension = this.getProject().getExtensions().getByType(LoomGradleExtension.class); - if (!Constants.MINECRAFT_MAPPED_JAR.get(extension).exists()) { this.getLogger().lifecycle(":unpacking mappings"); if (!Constants.MAPPINGS_DIR.get(extension).exists()) { @@ -76,6 +75,7 @@ public class MapJarsTask extends DefaultTask { ZipUtil.pack(tempAssests, Constants.MINECRAFT_MAPPED_JAR.get(extension)); } else { + this.getLogger().lifecycle(Constants.MINECRAFT_MAPPED_JAR.get(extension).getAbsolutePath()); this.getLogger().lifecycle(":mapped jar found, skipping mapping"); } } diff --git a/src/main/java/net/fabricmc/loom/task/ProcessModsTask.java b/src/main/java/net/fabricmc/loom/task/ProcessModsTask.java new file mode 100644 index 00000000..f9d856ee --- /dev/null +++ b/src/main/java/net/fabricmc/loom/task/ProcessModsTask.java @@ -0,0 +1,90 @@ +/* + * This file is part of fabric-loom, licensed under the MIT License (MIT). + * + * Copyright (c) 2016 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.task; + +import net.fabricmc.loom.LoomGradleExtension; +import net.fabricmc.loom.util.Constants; +import net.fabricmc.loom.util.proccessing.PreBakeMixins; +import org.apache.commons.io.FileUtils; +import org.gradle.api.DefaultTask; +import org.gradle.api.artifacts.Configuration; +import org.gradle.api.artifacts.ResolvedArtifact; +import org.gradle.api.tasks.TaskAction; +import org.jboss.shrinkwrap.resolver.api.maven.ConfigurableMavenResolverSystem; +import org.jboss.shrinkwrap.resolver.api.maven.Maven; + +import java.io.File; +import java.io.IOException; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.net.MalformedURLException; +import java.net.URL; +import java.net.URLClassLoader; +import java.util.ArrayList; +import java.util.List; + +public class ProcessModsTask extends DefaultTask { + @TaskAction + public void mix() throws InvocationTargetException, NoSuchMethodException, IllegalAccessException, IOException { + LoomGradleExtension extension = this.getProject().getExtensions().getByType(LoomGradleExtension.class); + Configuration configuration = getProject().getConfigurations().getByName(Constants.COMPILE_MODS); + List mods = new ArrayList<>(); + for (ResolvedArtifact artifact : configuration.getResolvedConfiguration().getResolvedArtifacts()) { + getProject().getLogger().lifecycle(":found mod to mix:" + artifact.getFile().getName()); + mods.add(artifact.getFile()); + } + if (Constants.MINECRAFT_FINAL_JAR.get(extension).exists()) { + Constants.MINECRAFT_FINAL_JAR.get(extension).delete(); + } + if (mods.size() == 0) { + FileUtils.copyFile(Constants.MINECRAFT_MAPPED_JAR.get(extension), Constants.MINECRAFT_FINAL_JAR.get(extension)); + } else { + //TODO figure out a way to specify what deps do what + //TODO download deps when needed + downloadRequiredDeps(extension); + new PreBakeMixins().proccess(getProject(), extension, mods); + } + } + + public void downloadRequiredDeps(LoomGradleExtension extension) { + ConfigurableMavenResolverSystem mavenResolver = Maven.configureResolver().withRemoteRepo("Fabric", "http://maven.fabricmc.net/", "default").withRemoteRepo("SpongePowered", "http://repo.spongepowered.org/maven/", "default").withRemoteRepo("Mojang", "https://libraries.minecraft.net/", "default"); + File[] files = mavenResolver.resolve("net.fabricmc:fabric-base:16w38a-0.0.4-SNAPSHOT").withTransitivity().asFile(); + for (File file : files) { + addFile(file, this); + } + } + + public static void addFile(File file, Object object) { + try { + URLClassLoader classLoader = (URLClassLoader) object.getClass().getClassLoader(); + Class urlClassLoaderClass = URLClassLoader.class; + Method method = urlClassLoaderClass.getDeclaredMethod("addURL", URL.class); + method.setAccessible(true); + method.invoke(classLoader, file.toURI().toURL()); + } catch (NoSuchMethodException | IllegalAccessException | MalformedURLException | InvocationTargetException e) { + e.printStackTrace(); + } + } +} diff --git a/src/main/java/net/fabricmc/loom/task/RunClientTask.java b/src/main/java/net/fabricmc/loom/task/RunClientTask.java index bcb18400..4f71979b 100644 --- a/src/main/java/net/fabricmc/loom/task/RunClientTask.java +++ b/src/main/java/net/fabricmc/loom/task/RunClientTask.java @@ -65,7 +65,7 @@ public class RunClientTask extends JavaExec { libs.add(file.getAbsolutePath()); } } - libs.add(Constants.MINECRAFT_MAPPED_JAR.get(extension).getAbsolutePath()); + libs.add(Constants.MINECRAFT_FINAL_JAR.get(extension).getAbsolutePath()); classpath(libs); args("--tweakClass", "net.fabricmc.base.launch.FabricClientTweaker", "--assetIndex", version.assetIndex.id, "--assetsDir", new File(extension.getFabricUserCache(), "assets-" + extension.version).getAbsolutePath()); diff --git a/src/main/java/net/fabricmc/loom/task/RunServerTask.java b/src/main/java/net/fabricmc/loom/task/RunServerTask.java index 1d895b22..43bbf5f4 100644 --- a/src/main/java/net/fabricmc/loom/task/RunServerTask.java +++ b/src/main/java/net/fabricmc/loom/task/RunServerTask.java @@ -62,7 +62,7 @@ public class RunServerTask extends JavaExec { libs.add(file.getAbsolutePath()); } } - libs.add(Constants.MINECRAFT_MAPPED_JAR.get(extension).getAbsolutePath()); + libs.add(Constants.MINECRAFT_FINAL_JAR.get(extension).getAbsolutePath()); classpath(libs); args("--tweakClass", "net.fabricmc.base.launch.FabricServerTweaker"); diff --git a/src/main/java/net/fabricmc/loom/util/Constants.java b/src/main/java/net/fabricmc/loom/util/Constants.java index 56217911..602abb21 100644 --- a/src/main/java/net/fabricmc/loom/util/Constants.java +++ b/src/main/java/net/fabricmc/loom/util/Constants.java @@ -41,6 +41,7 @@ public class Constants { public static final IDelayed MINECRAFT_SERVER_JAR = new DelayedFile(extension -> new File(extension.getFabricUserCache(), extension.version + "-server.jar")); public static final IDelayed MINECRAFT_MERGED_JAR = new DelayedFile(extension -> new File(extension.getFabricUserCache(), extension.version + "-merged.jar")); public static final IDelayed MINECRAFT_MAPPED_JAR = new DelayedFile(extension -> new File(extension.getFabricUserCache(), extension.getVersionString() + "-mapped-" + extension.pomfVersion + ".jar")); + public static final IDelayed MINECRAFT_FINAL_JAR = new DelayedFile(extension -> new File(CACHE_FILES, extension.getVersionString() + "-mixed-" + extension.pomfVersion + ".jar")); //http://asie.pl:8080/job/pomf/1/artifact/build/libs/pomf-enigma-16w33a.1.zip public static final IDelayed POMF_DIR = new DelayedFile(extension -> new File(extension.getFabricUserCache(), "pomf")); @@ -65,6 +66,7 @@ public class Constants { public static final String CONFIG_MC_DEPENDENCIES = "MC_DEPENDENCIES"; public static final String CONFIG_MC_DEPENDENCIES_CLIENT = "MC_DEPENDENCIES_CLIENT"; public static final String SYSTEM_ARCH = System.getProperty("os.arch").equals("64") ? "64" : "32"; + public static final String COMPILE_MODS = "modCompile"; public static List getClassPath() { URL[] urls = ((URLClassLoader) Constants.class.getClassLoader()).getURLs(); diff --git a/src/main/java/net/fabricmc/loom/util/proccessing/PreBakeMixins.java b/src/main/java/net/fabricmc/loom/util/proccessing/PreBakeMixins.java new file mode 100644 index 00000000..f934062e --- /dev/null +++ b/src/main/java/net/fabricmc/loom/util/proccessing/PreBakeMixins.java @@ -0,0 +1,53 @@ +/* + * This file is part of fabric-loom, licensed under the MIT License (MIT). + * + * Copyright (c) 2016 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.proccessing; + +import net.fabricmc.base.util.MixinPrebaker; +import net.fabricmc.loom.LoomGradleExtension; +import net.fabricmc.loom.task.ProcessModsTask; +import net.fabricmc.loom.util.Constants; +import org.apache.logging.log4j.LogManager; +import org.gradle.api.Project; + +import java.io.File; +import java.util.List; + +public class PreBakeMixins { + + public void proccess(Project project, LoomGradleExtension extension, List mods) { + project.getLogger().lifecycle(":Found " + mods.size() + " mods to prebake"); + String[] args = new String[mods.size() + 2]; + args[0] = Constants.MINECRAFT_MAPPED_JAR.get(extension).getAbsolutePath(); + args[1] = Constants.MINECRAFT_FINAL_JAR.get(extension).getAbsolutePath(); + for (int i = 0; i < mods.size(); i++) { + args[i + 2] = mods.get(i).getAbsolutePath(); + } + project.getLogger().lifecycle(":preBaking mixins"); + ProcessModsTask.addFile(Constants.MINECRAFT_MAPPED_JAR.get(extension), this); + LogManager.getFormatterLogger("test"); + MixinPrebaker.main(args); + } + +}