From 5da73c87f899a986612761b1d3493b85d5ce5f91 Mon Sep 17 00:00:00 2001 From: modmuss50 Date: Sat, 10 Sep 2016 13:09:15 +0100 Subject: [PATCH] Use pomf releases, build against gradle 3 --- build.gradle | 4 +- gradle/wrapper/gradle-wrapper.properties | 4 +- .../net/fabricmc/loom/AbstractPlugin.java | 10 ++-- .../fabricmc/loom/LoomGradleExtension.java | 1 + .../net/fabricmc/loom/task/DownloadTask.java | 13 +++-- .../loom/task/GenIdeaProjectTask.java | 2 +- .../net/fabricmc/loom/task/MapJarsTask.java | 51 +++++++++---------- .../net/fabricmc/loom/task/MergeJarsTask.java | 25 +++++---- .../net/fabricmc/loom/util/Constants.java | 10 ++-- 9 files changed, 63 insertions(+), 57 deletions(-) diff --git a/build.gradle b/build.gradle index 3ec78cd..28daa93 100644 --- a/build.gradle +++ b/build.gradle @@ -14,7 +14,7 @@ targetCompatibility = 1.8 group = 'net.fabricmc' archivesBaseName = project.name.toLowerCase() -version = '0.0.1-SNAPSHOT' +version = '0.0.2-SNAPSHOT' repositories { mavenCentral() @@ -126,5 +126,5 @@ uploadArchives { } task wrapper(type: Wrapper) { - gradleVersion = '2.14.1' + gradleVersion = '3.0' } diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index eb6d7d2..7e88482 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ -#Tue Aug 16 23:25:19 BST 2016 +#Sat Sep 10 13:02:22 BST 2016 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-3.0-all.zip diff --git a/src/main/java/net/fabricmc/loom/AbstractPlugin.java b/src/main/java/net/fabricmc/loom/AbstractPlugin.java index a35d64a..f089b9d 100644 --- a/src/main/java/net/fabricmc/loom/AbstractPlugin.java +++ b/src/main/java/net/fabricmc/loom/AbstractPlugin.java @@ -209,21 +209,21 @@ public class AbstractPlugin implements Plugin { } - protected void readModJson(LoomGradleExtension extension){ + protected void readModJson(LoomGradleExtension extension) { File resDir = new File(project.getProjectDir(), "src" + File.separator + "main" + File.separator + "resources"); File modJson = new File(resDir, "mod.json"); - if(modJson.exists()){ + if (modJson.exists()) { Gson gson = new Gson(); try { JsonElement jsonElement = gson.fromJson(new FileReader(modJson), JsonElement.class); JsonObject jsonObject = jsonElement.getAsJsonObject(); - if((extension.version == null || extension.version.isEmpty()) && jsonObject.has("version")){ + if ((extension.version == null || extension.version.isEmpty()) && jsonObject.has("version")) { project.setVersion(jsonObject.get("version").getAsString()); } - if(jsonObject.has("group")){ + if (jsonObject.has("group")) { project.setGroup(jsonObject.get("group").getAsString()); } - if(jsonObject.has("description")){ + if (jsonObject.has("description")) { project.setDescription(jsonObject.get("description").getAsString()); } //TODO load deps diff --git a/src/main/java/net/fabricmc/loom/LoomGradleExtension.java b/src/main/java/net/fabricmc/loom/LoomGradleExtension.java index ad8cea5..eb3e696 100644 --- a/src/main/java/net/fabricmc/loom/LoomGradleExtension.java +++ b/src/main/java/net/fabricmc/loom/LoomGradleExtension.java @@ -32,6 +32,7 @@ public class LoomGradleExtension { public String version; public String runDir = "run"; public String fabricVersion; + public String pomf; //Not to be set in the build.gradle public Project project; diff --git a/src/main/java/net/fabricmc/loom/task/DownloadTask.java b/src/main/java/net/fabricmc/loom/task/DownloadTask.java index a8a8df8..ebecb16 100644 --- a/src/main/java/net/fabricmc/loom/task/DownloadTask.java +++ b/src/main/java/net/fabricmc/loom/task/DownloadTask.java @@ -45,6 +45,7 @@ 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; @@ -69,12 +70,14 @@ public class DownloadTask extends DefaultTask { FileUtils.copyURLToFile(new URL(version.downloads.get("server").url), Constants.MINECRAFT_SERVER_JAR.get(extension)); } - if (Constants.MAPPINGS_ZIP.exists()) { - Constants.MAPPINGS_ZIP.delete(); + if (!Constants.POMF_DIR.get(extension).exists()) { + Constants.POMF_DIR.get(extension).mkdir(); } - this.getLogger().lifecycle(":downloading mappings"); - FileUtils.copyURLToFile(new URL("https://github.com/FabricMC/pomf/archive/" + extension.version + ".zip"), Constants.MAPPINGS_ZIP); + if (!Constants.MAPPINGS_ZIP.get(extension).exists()) { + this.getLogger().lifecycle(":downloading mappings"); + FileUtils.copyURLToFile(new URL("http://asie.pl:8080/job/pomf/" + extension.pomf + "/artifact/build/libs/pomf-enigma-" + extension.version + "." + extension.pomf + ".zip"), Constants.MAPPINGS_ZIP.get(extension)); + } DependencyHandler dependencyHandler = getProject().getDependencies(); @@ -144,7 +147,7 @@ public class DownloadTask extends DefaultTask { if (!Constants.MINECRAFT_JSON.get(extension).exists()) { logger.lifecycle(":downloading minecraft json"); FileUtils.copyURLToFile(new URL("https://launchermeta.mojang.com/mc/game/version_manifest.json"), Constants.VERSION_MANIFEST.get(extension)); - ManifestVersion mcManifest = new GsonBuilder().create().fromJson(FileUtils.readFileToString(Constants.VERSION_MANIFEST.get(extension)), ManifestVersion.class); + ManifestVersion mcManifest = new GsonBuilder().create().fromJson(FileUtils.readFileToString(Constants.VERSION_MANIFEST.get(extension), Charset.defaultCharset()), ManifestVersion.class); Optional optionalVersion = mcManifest.versions.stream().filter(versions -> versions.id.equalsIgnoreCase(extension.version)).findFirst(); if (optionalVersion.isPresent()) { diff --git a/src/main/java/net/fabricmc/loom/task/GenIdeaProjectTask.java b/src/main/java/net/fabricmc/loom/task/GenIdeaProjectTask.java index b388b40..809adc6 100644 --- a/src/main/java/net/fabricmc/loom/task/GenIdeaProjectTask.java +++ b/src/main/java/net/fabricmc/loom/task/GenIdeaProjectTask.java @@ -156,7 +156,7 @@ public class GenIdeaProjectTask extends DefaultTask { ideaClient.projectName = getProject().getName(); ideaClient.configName = "Minecraft Client"; ideaClient.runDir = "file://$PROJECT_DIR$/" + extension.runDir; - ideaClient.vmArgs = "-Djava.library.path=" + Constants.MINECRAFT_NATIVES.get(extension).getAbsolutePath() + " -Dfabric.development=true"; + ideaClient.vmArgs = "-Djava.library.path=" + Constants.MINECRAFT_NATIVES.get(extension).getAbsolutePath() + " -Dfabric.development=true"; ideaClient.programArgs = "--tweakClass net.fabricmc.base.launch.FabricClientTweaker --assetIndex " + version.assetIndex.id + " --assetsDir " + new File(extension.getFabricUserCache(), "assets-" + extension.version).getAbsolutePath(); runManager.appendChild(ideaClient.genRuns(runManager)); diff --git a/src/main/java/net/fabricmc/loom/task/MapJarsTask.java b/src/main/java/net/fabricmc/loom/task/MapJarsTask.java index a5e74e6..ca57243 100644 --- a/src/main/java/net/fabricmc/loom/task/MapJarsTask.java +++ b/src/main/java/net/fabricmc/loom/task/MapJarsTask.java @@ -26,7 +26,6 @@ package net.fabricmc.loom.task; import cuchaz.enigma.Deobfuscator; import cuchaz.enigma.TranslatingTypeLoader; -import cuchaz.enigma.bytecode.ClassPublifier; import cuchaz.enigma.mapping.MappingsEnigmaReader; import cuchaz.enigma.mapping.TranslationDirection; import cuchaz.enigma.throwables.MappingParseException; @@ -37,7 +36,6 @@ import javassist.bytecode.AccessFlag; import javassist.bytecode.InnerClassesAttribute; import net.fabricmc.loom.LoomGradleExtension; import net.fabricmc.loom.util.Constants; -import org.apache.commons.io.FileUtils; import org.gradle.api.DefaultTask; import org.gradle.api.tasks.TaskAction; import org.zeroturnaround.zip.ZipUtil; @@ -53,33 +51,33 @@ public class MapJarsTask extends DefaultTask { @TaskAction public void mapJars() throws IOException, MappingParseException { LoomGradleExtension extension = this.getProject().getExtensions().getByType(LoomGradleExtension.class); - this.getLogger().lifecycle(":unpacking mappings"); - if (Constants.MAPPINGS_DIR.exists()) { - FileUtils.deleteDirectory(Constants.MAPPINGS_DIR); - } - if (Constants.MINECRAFT_MAPPED_JAR.get(extension).exists()) { - Constants.MINECRAFT_MAPPED_JAR.get(extension).delete(); - } - ZipUtil.unpack(Constants.MAPPINGS_ZIP, Constants.MAPPINGS_DIR); - - this.getLogger().lifecycle(":remapping jar"); - deobfuscator = new Deobfuscator(new JarFile(Constants.MINECRAFT_MERGED_JAR.get(extension))); - this.deobfuscator.setMappings(new MappingsEnigmaReader().read(new File(Constants.MAPPINGS_DIR, "pomf-" + extension.version + File.separator + "mappings"))); - writeJar(Constants.MINECRAFT_MAPPED_JAR.get(extension), new ProgressListener(), deobfuscator); - - File tempAssests = new File(Constants.CACHE_FILES, "tempAssets"); - - ZipUtil.unpack(Constants.MINECRAFT_CLIENT_JAR.get(extension), tempAssests, name -> { - if (name.startsWith("assets") || name.startsWith("log4j2.xml") || name.startsWith("pack.png")) { - return name; - } else { - return null; + if (!Constants.MINECRAFT_MAPPED_JAR.get(extension).exists()) { + this.getLogger().lifecycle(":unpacking mappings"); + if (!Constants.MAPPINGS_DIR.get(extension).exists()) { + ZipUtil.unpack(Constants.MAPPINGS_ZIP.get(extension), Constants.MAPPINGS_DIR.get(extension)); } - }); - ZipUtil.unpack(Constants.MINECRAFT_MAPPED_JAR.get(extension), tempAssests); - ZipUtil.pack(tempAssests, Constants.MINECRAFT_MAPPED_JAR.get(extension)); + this.getLogger().lifecycle(":remapping jar"); + deobfuscator = new Deobfuscator(new JarFile(Constants.MINECRAFT_MERGED_JAR.get(extension))); + this.deobfuscator.setMappings(new MappingsEnigmaReader().read(Constants.MAPPINGS_DIR.get(extension))); + writeJar(Constants.MINECRAFT_MAPPED_JAR.get(extension), new ProgressListener(), deobfuscator); + + File tempAssests = new File(Constants.CACHE_FILES, "tempAssets"); + + ZipUtil.unpack(Constants.MINECRAFT_CLIENT_JAR.get(extension), tempAssests, name -> { + if (name.startsWith("assets") || name.startsWith("log4j2.xml") || name.startsWith("pack.png")) { + return name; + } else { + return null; + } + }); + ZipUtil.unpack(Constants.MINECRAFT_MAPPED_JAR.get(extension), tempAssests); + + ZipUtil.pack(tempAssests, Constants.MINECRAFT_MAPPED_JAR.get(extension)); + } else { + this.getLogger().lifecycle(":mapped jar found, skipping mapping"); + } } public void writeJar(File out, Deobfuscator.ProgressListener progress, Deobfuscator deobfuscator) { @@ -127,7 +125,6 @@ public class MapJarsTask extends DefaultTask { return flags; } - public static class ProgressListener implements Deobfuscator.ProgressListener { @Override public void init(int i, String s) { diff --git a/src/main/java/net/fabricmc/loom/task/MergeJarsTask.java b/src/main/java/net/fabricmc/loom/task/MergeJarsTask.java index 6001058..52209cf 100644 --- a/src/main/java/net/fabricmc/loom/task/MergeJarsTask.java +++ b/src/main/java/net/fabricmc/loom/task/MergeJarsTask.java @@ -38,22 +38,25 @@ public class MergeJarsTask extends DefaultTask { @TaskAction public void mergeJars() throws IOException { - this.getLogger().lifecycle(":merging jars"); LoomGradleExtension extension = this.getProject().getExtensions().getByType(LoomGradleExtension.class); - FileInputStream client = new FileInputStream(Constants.MINECRAFT_CLIENT_JAR.get(extension)); - FileInputStream server = new FileInputStream(Constants.MINECRAFT_SERVER_JAR.get(extension)); - FileOutputStream merged = new FileOutputStream(Constants.MINECRAFT_MERGED_JAR.get(extension)); + if(!Constants.MINECRAFT_MERGED_JAR.get(extension).exists()){ + this.getLogger().lifecycle(":merging jars"); + FileInputStream client = new FileInputStream(Constants.MINECRAFT_CLIENT_JAR.get(extension)); + FileInputStream server = new FileInputStream(Constants.MINECRAFT_SERVER_JAR.get(extension)); + FileOutputStream merged = new FileOutputStream(Constants.MINECRAFT_MERGED_JAR.get(extension)); - JarMerger jarMerger = new JarMerger(client, server, merged); + JarMerger jarMerger = new JarMerger(client, server, merged); - jarMerger.merge(); - jarMerger.close(); - - client.close(); - server.close(); - merged.close(); + jarMerger.merge(); + jarMerger.close(); + client.close(); + server.close(); + merged.close(); + } else { + this.getLogger().lifecycle(":merged jar found, skipping"); + } } } diff --git a/src/main/java/net/fabricmc/loom/util/Constants.java b/src/main/java/net/fabricmc/loom/util/Constants.java index 82a6197..1ca9785 100644 --- a/src/main/java/net/fabricmc/loom/util/Constants.java +++ b/src/main/java/net/fabricmc/loom/util/Constants.java @@ -39,11 +39,13 @@ public class Constants { public static final IDelayed MINECRAFT_CLIENT_JAR = new DelayedFile(extension -> new File(extension.getFabricUserCache(), extension.version + "-client.jar")); 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(CACHE_FILES, extension.version + "-merged.jar")); - public static final IDelayed MINECRAFT_MAPPED_JAR = new DelayedFile(extension -> new File(CACHE_FILES, extension.getVersionString() + "-mapped.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.pomf + ".jar")); - public static final File MAPPINGS_ZIP = new File(CACHE_FILES, "mappings.zip"); - public static final File MAPPINGS_DIR = new File(CACHE_FILES, "mappings"); + //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")); + public static final IDelayed MAPPINGS_ZIP = new DelayedFile(extension -> new File(POMF_DIR.get(extension), "pomf-enigma-" + extension.version + "." + extension.pomf + ".zip")); + public static final IDelayed MAPPINGS_DIR = new DelayedFile(extension -> new File(POMF_DIR.get(extension), "pomf-enigma-" + extension.version + "." + extension.pomf + "")); public static final IDelayed MINECRAFT_LIBS = new DelayedFile(extension -> new File(extension.getFabricUserCache(), extension.version + "-libs")); public static final IDelayed MINECRAFT_NATIVES = new DelayedFile(extension -> new File(extension.getFabricUserCache(), extension.version + "-natives"));