Skip to content

Commit

Permalink
Add updateMappings task to userdev (#628)
Browse files Browse the repository at this point in the history
Add warning message when using official mappings from Mojang
  • Loading branch information
JDLogic authored and LexManos committed Oct 15, 2019
1 parent c5779b6 commit 1b7bd5e
Show file tree
Hide file tree
Showing 9 changed files with 83 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
* USA
*/

package net.minecraftforge.gradle.patcher.task;
package net.minecraftforge.gradle.common.task;

import java.io.File;
import java.io.FileOutputStream;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
* USA
*/

package net.minecraftforge.gradle.patcher.task;
package net.minecraftforge.gradle.common.task;

import org.gradle.api.tasks.Input;
import org.gradle.api.tasks.InputFile;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
* USA
*/

package net.minecraftforge.gradle.patcher.task;
package net.minecraftforge.gradle.common.task;

import java.io.File;
import java.io.FileOutputStream;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
* USA
*/

package net.minecraftforge.gradle.patcher.task;
package net.minecraftforge.gradle.common.task;

import org.gradle.api.file.FileCollection;
import org.gradle.api.tasks.Input;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,11 @@ public class Utils {
public static final String INSTALLERTOOLS = "net.minecraftforge:installertools:1.1.7:fatjar";
public static final long ZIPTIME = 628041600000L;
public static final TimeZone GMT = TimeZone.getTimeZone("GMT");
public static final String OFFICIAL_MAPPING_USAGE =
"These mapping files are licensed as All Rights Reserved with permission to use the contents for INTERNAL, "
+ "REFERENCE purposes. Please avoid publishing any source code referencing these mappings. A full copy of "
+ "the license can be found at the top of the mapping file itself and in the 19w36a snapshot article at: "
+ "https://www.minecraft.net/en-us/article/minecraft-snapshot-19w36a.";

public static void extractFile(ZipFile zip, String name, File output) throws IOException {
extractFile(zip, zip.getEntry(name), output);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
* USA
*/

package net.minecraftforge.gradle.patcher.task;
package net.minecraftforge.gradle.mcp.task;

import net.minecraftforge.gradle.common.util.MavenArtifactDownloader;
import net.minecraftforge.gradle.mcp.MCPRepo;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,15 @@
import net.minecraftforge.gradle.mcp.task.DownloadMCPConfigTask;
import net.minecraftforge.gradle.mcp.task.SetupMCPTask;
import net.minecraftforge.gradle.patcher.task.CreateFakeSASPatches;
import net.minecraftforge.gradle.patcher.task.DownloadMCPMappingsTask;
import net.minecraftforge.gradle.mcp.task.DownloadMCPMappingsTask;
import net.minecraftforge.gradle.patcher.task.GenerateBinPatches;
import net.minecraftforge.gradle.patcher.task.TaskApplyMappings;
import net.minecraftforge.gradle.common.task.TaskApplyMappings;
import net.minecraftforge.gradle.patcher.task.TaskApplyPatches;
import net.minecraftforge.gradle.patcher.task.TaskApplyRangeMap;
import net.minecraftforge.gradle.common.task.TaskApplyRangeMap;
import net.minecraftforge.gradle.patcher.task.TaskCreateExc;
import net.minecraftforge.gradle.patcher.task.TaskCreateSrg;
import net.minecraftforge.gradle.patcher.task.TaskExtractExistingFiles;
import net.minecraftforge.gradle.patcher.task.TaskExtractRangeMap;
import net.minecraftforge.gradle.common.task.TaskExtractExistingFiles;
import net.minecraftforge.gradle.common.task.TaskExtractRangeMap;
import net.minecraftforge.gradle.patcher.task.TaskFilterNewJar;
import net.minecraftforge.gradle.patcher.task.TaskGeneratePatches;
import net.minecraftforge.gradle.patcher.task.TaskGenerateUserdevConfig;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@
import net.minecraftforge.gradle.common.util.Utils;
import net.minecraftforge.gradle.common.util.VersionJson;
import net.minecraftforge.gradle.mcp.MCPRepo;
import net.minecraftforge.gradle.mcp.task.DownloadMCPMappingsTask;
import net.minecraftforge.gradle.common.task.TaskApplyMappings;
import net.minecraftforge.gradle.common.task.TaskApplyRangeMap;
import net.minecraftforge.gradle.common.task.TaskExtractExistingFiles;
import net.minecraftforge.gradle.common.task.TaskExtractRangeMap;
import net.minecraftforge.gradle.userdev.tasks.GenerateSRG;
import net.minecraftforge.gradle.userdev.tasks.RenameJarInPlace;
import net.minecraftforge.gradle.userdev.util.DeobfuscatingRepo;
Expand All @@ -40,11 +45,13 @@
import org.gradle.api.plugins.JavaPluginConvention;
import org.gradle.api.tasks.TaskProvider;
import org.gradle.api.tasks.bundling.Jar;
import org.gradle.api.tasks.compile.JavaCompile;

import javax.annotation.Nonnull;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Set;
import java.util.concurrent.TimeUnit;

public class UserDevPlugin implements Plugin<Project> {
Expand Down Expand Up @@ -159,7 +166,65 @@ public RenameJarInPlace create(String jarName) {
task.setMeta(downloadMCMeta.get().getOutput());
});

if (project.hasProperty("UPDATE_MAPPINGS")) {
String version = (String)project.property("UPDATE_MAPPINGS");
String channel = project.hasProperty("UPDATE_MAPPINGS_CHANNEL") ? (String)project.property("UPDATE_MAPPINGS_CHANNEL") : "snapshot";

logger.lifecycle("This process uses Srg2Source for java source file renaming. Please forward relevant bug reports to https://github.com/MinecraftForge/Srg2Source/issues.");
if ("official".equals(channel)) {
String warning = "WARNING: This project will be updated to use the official obfuscation mappings provided by Mojang. " + Utils.OFFICIAL_MAPPING_USAGE;
logger.warn(warning);
}

JavaCompile javaCompile = (JavaCompile) project.getTasks().getByName("compileJava");
JavaPluginConvention javaConv = (JavaPluginConvention) project.getConvention().getPlugins().get("java");
Set<File> srcDirs = javaConv.getSourceSets().getByName("main").getJava().getSrcDirs();

TaskProvider<DownloadMCPMappingsTask> dlMappingsNew = project.getTasks().register("downloadMappingsNew", DownloadMCPMappingsTask.class);
TaskProvider<TaskExtractRangeMap> extractRangeConfig = project.getTasks().register("extractRangeMap", TaskExtractRangeMap.class);
TaskProvider<TaskApplyRangeMap> applyRangeConfig = project.getTasks().register("applyRangeMap", TaskApplyRangeMap.class);
TaskProvider<TaskApplyMappings> toMCPNew = project.getTasks().register("srg2mcpNew", TaskApplyMappings.class);
TaskProvider<TaskExtractExistingFiles> extractMappedNew = project.getTasks().register("extractMappedNew", TaskExtractExistingFiles.class);

extractRangeConfig.configure(task -> {
task.addSources(srcDirs);
task.addDependencies(javaCompile.getClasspath());
});

applyRangeConfig.configure(task -> {
task.dependsOn(extractRangeConfig, createMcpToSrg);
task.setRangeMap(extractRangeConfig.get().getOutput());
task.setSrgFiles(createMcpToSrg.get().getOutput());
task.setSources(srcDirs);
});

dlMappingsNew.configure(task -> {
task.setMappings(channel + "_" + version);
task.setOutput(project.file("build/mappings_new.zip"));
});

toMCPNew.configure(task -> {
task.dependsOn(dlMappingsNew, applyRangeConfig);
task.setInput(applyRangeConfig.get().getOutput());
task.setMappings(dlMappingsNew.get().getOutput());
});

extractMappedNew.configure(task -> {
task.dependsOn(toMCPNew);
task.setArchive(toMCPNew.get().getOutput());
srcDirs.forEach(task::addTarget);
});

TaskProvider<DefaultTask> updateMappings = project.getTasks().register("updateMappings", DefaultTask.class);
updateMappings.get().dependsOn(extractMappedNew);
}

project.afterEvaluate(p -> {
if ("official".equals(extension.getMappingChannel())) {
String warning = "WARNING: This project is configured to use the official obfuscation mappings provided by Mojang. " + Utils.OFFICIAL_MAPPING_USAGE;
logger.warn(warning);
}

MinecraftUserRepo mcrepo = null;
DeobfuscatingRepo deobfrepo = null;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
package net.minecraftforge.gradle.userdev.util;

import net.minecraftforge.gradle.common.util.*;
import net.minecraftforge.gradle.mcp.MCPRepo;
import net.minecraftforge.gradle.userdev.tasks.RenameJarSrg2Mcp;

import org.apache.commons.io.IOUtils;
Expand Down Expand Up @@ -190,7 +191,7 @@ private File findMapping(String mapping) {
int idx = mapping.lastIndexOf('_');
String channel = mapping.substring(0, idx);
String version = mapping.substring(idx + 1);
String desc = "de.oceanlabs.mcp:mcp_" + channel + ":" + version + "@zip";
return MavenArtifactDownloader.manual(project, desc, false);
String desc = MCPRepo.getMappingDep(channel, version);
return MavenArtifactDownloader.generate(project, desc, false);
}
}

0 comments on commit 1b7bd5e

Please sign in to comment.