debloat, fix fabric-base

dev/0.11
Adrian Siekierka 2018-11-01 12:15:09 +01:00
parent f32359d7c3
commit bd5d306a9a
17 changed files with 214 additions and 116 deletions

View File

@ -43,30 +43,14 @@ configurations {
dependencies { dependencies {
compile gradleApi() compile gradleApi()
shade 'org.zeroturnaround:zt-zip:1.13'
shade 'org.slf4j:slf4j-api:1.7.25'
shade 'org.slf4j:slf4j-simple:1.7.25'
shade 'com.google.code.gson:gson:2.8.5'
shade 'commons-io:commons-io:2.6' shade 'commons-io:commons-io:2.6'
shade 'org.apache.commons:commons-lang3:3.8.1' shade 'org.zeroturnaround:zt-zip:1.13'
shade 'com.google.code.gson:gson:2.8.5'
shade 'com.google.guava:guava:27.0-jre' shade 'com.google.guava:guava:27.0-jre'
shade ('net.fabricmc:weave:0.2.0.+'){
transitive = false
}
shade ('net.fabricmc:stitch:0.1.0.+'){ shade ('net.fabricmc:stitch:0.1.0.+'){
transitive = false transitive = false
} }
shade ('cuchaz:enigma:0.12.0.+:lib'){
exclude group: 'org.ow2.asm'
}
shade 'net.fabricmc:tiny-remapper:0.1.0.14' shade 'net.fabricmc:tiny-remapper:0.1.0.14'
shade 'net.sf.jopt-simple:jopt-simple:5.0.4'
shade 'org.apache.logging.log4j:log4j-api:2.11.1'
shade 'org.apache.logging.log4j:log4j-core:2.11.1'
shade ('net.minecraft:launchwrapper:1.12') {
transitive = false
}
shade('org.spongepowered:mixin:0.7.11-SNAPSHOT') { shade('org.spongepowered:mixin:0.7.11-SNAPSHOT') {
exclude module: 'launchwrapper' exclude module: 'launchwrapper'

View File

@ -42,8 +42,10 @@ import org.gradle.api.plugins.JavaPluginConvention;
import org.gradle.api.tasks.SourceSet; import org.gradle.api.tasks.SourceSet;
import org.gradle.api.tasks.compile.JavaCompile; import org.gradle.api.tasks.compile.JavaCompile;
import org.gradle.api.tasks.javadoc.Javadoc; import org.gradle.api.tasks.javadoc.Javadoc;
import org.gradle.plugins.ide.api.GeneratorTask;
import org.gradle.plugins.ide.eclipse.model.EclipseModel; import org.gradle.plugins.ide.eclipse.model.EclipseModel;
import org.gradle.plugins.ide.idea.model.IdeaModel; import org.gradle.plugins.ide.idea.model.IdeaModel;
import org.gradle.plugins.ide.internal.IdePlugin;
import java.io.File; import java.io.File;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
@ -88,12 +90,15 @@ public class AbstractPlugin implements Plugin<Project> {
configureIDEs(); configureIDEs();
configureCompile(); configureCompile();
Map<Project, Set<Task>> taskMap = project.getAllTasks(true); Map<Project, Set<Task>> taskMap = project.getAllTasks(true);
for (Map.Entry<Project, Set<Task>> entry : taskMap.entrySet()) { for (Map.Entry<Project, Set<Task>> entry : taskMap.entrySet()) {
Project project = entry.getKey(); Project project = entry.getKey();
Set<Task> taskSet = entry.getValue(); Set<Task> taskSet = entry.getValue();
for (Task task : taskSet) { for (Task task : taskSet) {
if (task instanceof GeneratorTask) {
task.dependsOn("setup");
}
if (task instanceof JavaCompile if (task instanceof JavaCompile
&& !(task.getName().contains("Test")) && !(task.getName().contains("test"))) { && !(task.getName().contains("Test")) && !(task.getName().contains("test"))) {
JavaCompile javaCompileTask = (JavaCompile) task; JavaCompile javaCompileTask = (JavaCompile) task;
@ -164,17 +169,17 @@ public class AbstractPlugin implements Plugin<Project> {
*/ */
protected void configureIDEs() { protected void configureIDEs() {
// IDEA // IDEA
IdeaModel ideaModule = (IdeaModel) project.getExtensions().getByName("idea"); IdeaModel ideaModel = (IdeaModel) project.getExtensions().getByName("idea");
ideaModule.getModule().getExcludeDirs().addAll(project.files(".gradle", "build", ".idea", "out").getFiles()); ideaModel.getModule().getExcludeDirs().addAll(project.files(".gradle", "build", ".idea", "out").getFiles());
ideaModule.getModule().setDownloadJavadoc(true); ideaModel.getModule().setDownloadJavadoc(true);
ideaModule.getModule().setDownloadSources(true); ideaModel.getModule().setDownloadSources(true);
ideaModule.getModule().setInheritOutputDirs(true); ideaModel.getModule().setInheritOutputDirs(true);
ideaModule.getModule().getScopes().get("COMPILE").get("plus").add(project.getConfigurations().getByName(Constants.CONFIG_MINECRAFT)); ideaModel.getModule().getScopes().get("COMPILE").get("plus").add(project.getConfigurations().getByName(Constants.CONFIG_MINECRAFT));
// ECLIPSE // ECLIPSE
EclipseModel eclipseModule = (EclipseModel) project.getExtensions().getByName("eclipse"); EclipseModel eclipseModel = (EclipseModel) project.getExtensions().getByName("eclipse");
eclipseModule.getClasspath().getPlusConfigurations().add(project.getConfigurations().getByName(Constants.CONFIG_MINECRAFT)); eclipseModel.getClasspath().getPlusConfigurations().add(project.getConfigurations().getByName(Constants.CONFIG_MINECRAFT));
} }
/** /**

View File

@ -35,8 +35,7 @@ public class LoomGradlePlugin extends AbstractPlugin {
makeTask("download", DownloadTask.class); makeTask("download", DownloadTask.class);
makeTask("mergeJars", MergeJarsTask.class).dependsOn("download"); makeTask("mergeJars", MergeJarsTask.class).dependsOn("download");
makeTask("mapJars", MapJarsTask.class).dependsOn("mergeJars"); makeTask("mapJars", MapJarsTask.class).dependsOn("mergeJars");
makeTask("finaliseJars", FinaliseJar.class).dependsOn("mapJars"); makeTask("setup", SetupTask.class).dependsOn("mapJars").setGroup("fabric");
makeTask("setup", SetupTask.class).dependsOn("finaliseJars").setGroup("fabric");
makeTask("extractNatives", ExtractNativesTask.class).dependsOn("download"); makeTask("extractNatives", ExtractNativesTask.class).dependsOn("download");
makeTask("genIdeaWorkspace", GenIdeaProjectTask.class).dependsOn("idea").setGroup("ide"); makeTask("genIdeaWorkspace", GenIdeaProjectTask.class).dependsOn("idea").setGroup("ide");

View File

@ -57,8 +57,6 @@ public class MixinMappingProviderTiny extends MappingProvider {
@Override @Override
public MappingMethod getMethodMapping(MappingMethod method) { public MappingMethod getMethodMapping(MappingMethod method) {
System.out.println("processing " + method.getName() + method.getDesc());
MappingMethod mapped = this.methodMap.get(method); MappingMethod mapped = this.methodMap.get(method);
if (mapped != null) if (mapped != null)
return mapped; return mapped;
@ -96,8 +94,6 @@ public class MixinMappingProviderTiny extends MappingProvider {
@Override @Override
public MappingField getFieldMapping(MappingField field) { public MappingField getFieldMapping(MappingField field) {
System.out.println("processing " + field.getOwner() + "/" + field.getName() + field.getDesc());
MappingField mapped = this.fieldMap.get(field); MappingField mapped = this.fieldMap.get(field);
if (mapped != null) if (mapped != null)
return mapped; return mapped;

View File

@ -41,7 +41,6 @@ public class MixinServiceGradle extends MixinServiceLaunchWrapper implements ICl
private static List<JarFile> jars = new ArrayList<>(); private static List<JarFile> jars = new ArrayList<>();
@Override @Override
public String getName() { public String getName() {
return "FabricGradle"; return "FabricGradle";

View File

@ -39,9 +39,8 @@ public class ObfuscationEnvironmentFabric extends ObfuscationEnvironment {
@Override @Override
protected IMappingProvider getMappingProvider(Messager messager, Filer filer) { protected IMappingProvider getMappingProvider(Messager messager, Filer filer) {
String from = type.getKey().split(":")[0]; String[] key = type.getKey().split(":");
String to = type.getKey().split(":")[1]; return new MixinMappingProviderTiny(messager, filer, key[0], key[1]);
return new MixinMappingProviderTiny(messager, filer, from, to);
} }
@Override @Override

View File

@ -25,7 +25,7 @@
package net.fabricmc.loom.mixin; package net.fabricmc.loom.mixin;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
import org.apache.commons.lang3.StringUtils; import net.fabricmc.loom.util.LoomUtil;
import org.spongepowered.tools.obfuscation.service.IObfuscationService; import org.spongepowered.tools.obfuscation.service.IObfuscationService;
import org.spongepowered.tools.obfuscation.service.ObfuscationTypeDescriptor; import org.spongepowered.tools.obfuscation.service.ObfuscationTypeDescriptor;
@ -38,7 +38,7 @@ public class ObfuscationServiceFabric implements IObfuscationService {
public static final String OUT_MAP_FILE = "outMapFile"; public static final String OUT_MAP_FILE = "outMapFile";
private String asSuffixed(String arg, String from, String to) { private String asSuffixed(String arg, String from, String to) {
return arg + StringUtils.capitalize(from) + StringUtils.capitalize(to); return arg + LoomUtil.capitalize(from) + LoomUtil.capitalize(to);
} }
private ObfuscationTypeDescriptor createObfuscationType(String from, String to) { private ObfuscationTypeDescriptor createObfuscationType(String from, String to) {
@ -51,7 +51,7 @@ public class ObfuscationServiceFabric implements IObfuscationService {
); );
} }
private void addSupportedOptions(ImmutableSet.Builder builder, String from, String to) { private void addSupportedOptions(ImmutableSet.Builder<String> builder, String from, String to) {
builder.add(asSuffixed(ObfuscationServiceFabric.IN_MAP_FILE, from, to)); builder.add(asSuffixed(ObfuscationServiceFabric.IN_MAP_FILE, from, to));
builder.add(asSuffixed(ObfuscationServiceFabric.IN_MAP_EXTRA_FILES, from, to)); builder.add(asSuffixed(ObfuscationServiceFabric.IN_MAP_EXTRA_FILES, from, to));
builder.add(asSuffixed(ObfuscationServiceFabric.OUT_MAP_FILE, from, to)); builder.add(asSuffixed(ObfuscationServiceFabric.OUT_MAP_FILE, from, to));
@ -59,8 +59,12 @@ public class ObfuscationServiceFabric implements IObfuscationService {
@Override @Override
public Set<String> getSupportedOptions() { public Set<String> getSupportedOptions() {
ImmutableSet.Builder builder = new ImmutableSet.Builder(); ImmutableSet.Builder<String> builder = new ImmutableSet.Builder<>();
addSupportedOptions(builder, "mojang", "intermediary");
addSupportedOptions(builder, "mojang", "pomf");
addSupportedOptions(builder, "intermediary", "mojang");
addSupportedOptions(builder, "intermediary", "pomf"); addSupportedOptions(builder, "intermediary", "pomf");
addSupportedOptions(builder, "pomf", "mojang");
addSupportedOptions(builder, "pomf", "intermediary"); addSupportedOptions(builder, "pomf", "intermediary");
return builder.build(); return builder.build();
} }
@ -68,8 +72,12 @@ public class ObfuscationServiceFabric implements IObfuscationService {
@Override @Override
public Collection<ObfuscationTypeDescriptor> getObfuscationTypes() { public Collection<ObfuscationTypeDescriptor> getObfuscationTypes() {
return ImmutableSet.of( return ImmutableSet.of(
createObfuscationType("intermediary", "pomf"), createObfuscationType("mojang", "intermediary"),
createObfuscationType("pomf", "intermediary") createObfuscationType("mojang", "pomf"),
createObfuscationType("intermediary", "mojang"),
createObfuscationType("intermediary", "pomf"),
createObfuscationType("pomf", "mojang"),
createObfuscationType("pomf", "intermediary")
); );
} }
} }

View File

@ -24,6 +24,8 @@
package net.fabricmc.loom.task; package net.fabricmc.loom.task;
import com.google.common.collect.HashMultimap;
import com.google.common.collect.Multimap;
import com.google.gson.Gson; import com.google.gson.Gson;
import com.google.gson.GsonBuilder; import com.google.gson.GsonBuilder;
import net.fabricmc.loom.LoomGradleExtension; import net.fabricmc.loom.LoomGradleExtension;
@ -43,7 +45,9 @@ import org.gradle.api.tasks.TaskAction;
import java.io.*; import java.io.*;
import java.net.URL; import java.net.URL;
import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.Objects;
import java.util.Optional; import java.util.Optional;
import java.util.zip.GZIPInputStream; import java.util.zip.GZIPInputStream;
@ -145,6 +149,20 @@ public class DownloadTask extends DefaultTask {
Version.AssetIndex assetIndex = version.assetIndex; Version.AssetIndex assetIndex = version.assetIndex;
// get existing cache files
this.getLogger().lifecycle(":checking for existing asset files");
Multimap<String, File> assetFilenameToFile = HashMultimap.create();
for (File assetDir : Objects.requireNonNull(extension.getUserCache().listFiles((f) -> f.isDirectory() && f.getName().startsWith("assets-")))) {
File objectsDir = new File(assetDir, "objects");
if (objectsDir.exists() && objectsDir.isDirectory()) {
for (File subDir : Objects.requireNonNull(objectsDir.listFiles(File::isDirectory))) {
for (File subFile : Objects.requireNonNull(subDir.listFiles(File::isFile))) {
assetFilenameToFile.put("objects" + File.separator + subDir.getName() + File.separator + subFile.getName(), subFile);
}
}
}
}
File assets = new File(extension.getUserCache(), "assets-" + extension.version); File assets = new File(extension.getUserCache(), "assets-" + extension.version);
if (!assets.exists()) { if (!assets.exists()) {
assets.mkdirs(); assets.mkdirs();
@ -166,7 +184,18 @@ public class DownloadTask extends DefaultTask {
for (Map.Entry<String, AssetObject> entry : parent.entrySet()) { for (Map.Entry<String, AssetObject> entry : parent.entrySet()) {
AssetObject object = entry.getValue(); AssetObject object = entry.getValue();
String sha1 = object.getHash(); String sha1 = object.getHash();
File file = new File(assets, "objects" + File.separator + sha1.substring(0, 2) + File.separator + sha1); String filename = "objects" + File.separator + sha1.substring(0, 2) + File.separator + sha1;
File file = new File(assets, filename);
if (!file.exists() && assetFilenameToFile.containsKey(filename)) {
this.getLogger().debug(":copying asset " + entry.getKey());
for (File srcFile : assetFilenameToFile.get(filename)) {
if (Checksum.equals(srcFile, sha1)) {
FileUtils.copyFile(srcFile, file);
break;
}
}
}
if (!file.exists() || !Checksum.equals(file, sha1)) { if (!file.exists() || !Checksum.equals(file, sha1)) {
this.getLogger().debug(":downloading asset " + entry.getKey()); this.getLogger().debug(":downloading asset " + entry.getKey());
FileUtils.copyURLToFile(new URL(Constants.RESOURCES_BASE + sha1.substring(0, 2) + "/" + sha1), file); FileUtils.copyURLToFile(new URL(Constants.RESOURCES_BASE + sha1.substring(0, 2) + "/" + sha1), file);

View File

@ -25,23 +25,14 @@
package net.fabricmc.loom.task; package net.fabricmc.loom.task;
import net.fabricmc.loom.LoomGradleExtension; import net.fabricmc.loom.LoomGradleExtension;
import net.fabricmc.loom.util.Constants; import net.fabricmc.loom.util.delayed.IDelayed;
import org.apache.commons.io.FileUtils;
import org.gradle.api.DefaultTask; import org.gradle.api.DefaultTask;
import org.gradle.api.tasks.TaskAction;
import java.io.IOException; import java.io.File;
public class FinaliseJar extends DefaultTask { public class LoomBaseTask extends DefaultTask {
protected final File getFile(IDelayed<File> file) {
@TaskAction
public void finaliseJar() throws IOException {
//What is the point to this?
LoomGradleExtension extension = this.getProject().getExtensions().getByType(LoomGradleExtension.class); LoomGradleExtension extension = this.getProject().getExtensions().getByType(LoomGradleExtension.class);
if(!Constants.MINECRAFT_FINAL_JAR.get(extension).exists()){ return file.get(extension);
FileUtils.copyFile(Constants.MINECRAFT_MAPPED_JAR.get(extension), Constants.MINECRAFT_FINAL_JAR.get(extension));
}
} }
} }

View File

@ -25,13 +25,13 @@
package net.fabricmc.loom.task; package net.fabricmc.loom.task;
import cuchaz.enigma.Deobfuscator; /* import cuchaz.enigma.Deobfuscator;
import cuchaz.enigma.TranslatingTypeLoader; import cuchaz.enigma.TranslatingTypeLoader;
import cuchaz.enigma.mapping.MappingsEnigmaReader; import cuchaz.enigma.mapping.MappingsEnigmaReader;
import cuchaz.enigma.mapping.TranslationDirection; import cuchaz.enigma.mapping.TranslationDirection;
import cuchaz.enigma.mapping.Translator; import cuchaz.enigma.mapping.Translator;
import cuchaz.enigma.mapping.entry.ReferencedEntryPool; import cuchaz.enigma.mapping.entry.ReferencedEntryPool;
import cuchaz.enigma.throwables.MappingParseException; import cuchaz.enigma.throwables.MappingParseException; */
import net.fabricmc.loom.LoomGradleExtension; import net.fabricmc.loom.LoomGradleExtension;
import net.fabricmc.loom.util.Constants; import net.fabricmc.loom.util.Constants;
import net.fabricmc.tinyremapper.OutputConsumerPath; import net.fabricmc.tinyremapper.OutputConsumerPath;
@ -48,7 +48,11 @@ import java.nio.file.Path;
import java.util.jar.JarFile; import java.util.jar.JarFile;
public class MapJarsEnigma { public class MapJarsEnigma {
Deobfuscator deobfuscator; public void mapJars(MapJarsTask task) {
throw new RuntimeException("Currently unsupported!");
}
/* Deobfuscator deobfuscator;
public void mapJars(MapJarsTask task) throws IOException, MappingParseException { public void mapJars(MapJarsTask task) throws IOException, MappingParseException {
LoomGradleExtension extension = task.getProject().getExtensions().getByType(LoomGradleExtension.class); LoomGradleExtension extension = task.getProject().getExtensions().getByType(LoomGradleExtension.class);
@ -114,5 +118,5 @@ public class MapJarsEnigma {
public void onProgress(int i, String s) { public void onProgress(int i, String s) {
} }
} } */
} }

View File

@ -27,38 +27,72 @@ package net.fabricmc.loom.task;
import net.fabricmc.loom.LoomGradleExtension; import net.fabricmc.loom.LoomGradleExtension;
import net.fabricmc.loom.util.Constants; import net.fabricmc.loom.util.Constants;
import org.gradle.api.DefaultTask; import org.gradle.api.DefaultTask;
import org.gradle.api.tasks.TaskAction; import org.gradle.api.tasks.*;
import org.zeroturnaround.zip.commons.FileUtils; import org.zeroturnaround.zip.commons.FileUtils;
public class MapJarsTask extends DefaultTask { import java.io.File;
import java.util.Collection;
//Set to to true if you want to always remap the jar, useful for when working on the gradle plugin public class MapJarsTask extends LoomBaseTask {
public static final boolean ALWAYS_REMAP = false; @InputFiles
@Classpath
public Collection<File> getMapperPaths() {
return this.getProject().getConfigurations().getByName(Constants.CONFIG_MC_DEPENDENCIES).getFiles();
}
@InputFile
public File getMappingFile() {
return getFile(Constants.MAPPINGS_TINY);
}
@InputFile
public File getInputJar() {
return getFile(Constants.MINECRAFT_MERGED_JAR);
}
@OutputFile
public File getMappedJar() {
return getFile(Constants.MINECRAFT_MAPPED_JAR);
}
@Input
public boolean localMappings() {
LoomGradleExtension extension = this.getProject().getExtensions().getByType(LoomGradleExtension.class);
return extension.localMappings;
}
@Input
public String pomfVersion() {
LoomGradleExtension extension = this.getProject().getExtensions().getByType(LoomGradleExtension.class);
return extension.pomfVersion;
}
@Input
public String jarMapper() {
LoomGradleExtension extension = this.getProject().getExtensions().getByType(LoomGradleExtension.class);
return extension.jarMapper;
}
@TaskAction @TaskAction
public void mapJars() throws Exception { public void mapJars() throws Exception {
LoomGradleExtension extension = this.getProject().getExtensions().getByType(LoomGradleExtension.class); LoomGradleExtension extension = this.getProject().getExtensions().getByType(LoomGradleExtension.class);
if (!Constants.MINECRAFT_MAPPED_JAR.get(extension).exists() || extension.localMappings || ALWAYS_REMAP) {
if(Constants.MINECRAFT_MAPPED_JAR.get(extension).exists()){
Constants.MINECRAFT_MAPPED_JAR.get(extension).delete();
}
if (!extension.hasPomf()) { if (getMappedJar().exists()){
this.getLogger().lifecycle("Mapping version not set, skipping mapping!"); getMappedJar().delete();
FileUtils.copyFile(Constants.MINECRAFT_MERGED_JAR.get(extension), Constants.MINECRAFT_MAPPED_JAR.get(extension)); }
return;
}
if (Constants.JAR_MAPPER_ENIGMA.equals(extension.jarMapper)) { if (!extension.hasPomf()) {
new MapJarsEnigma().mapJars(this); this.getLogger().lifecycle("Mapping version not set, skipping mapping!");
} else if (Constants.JAR_MAPPER_TINY.equals(extension.jarMapper)) { FileUtils.copyFile(Constants.MINECRAFT_MERGED_JAR.get(extension), getMappedJar());
new MapJarsTiny().mapJars(this); return;
} else { }
throw new RuntimeException("Unknown JAR mapper type: " + extension.jarMapper);
} if (Constants.JAR_MAPPER_ENIGMA.equals(jarMapper())) {
new MapJarsEnigma().mapJars(this);
} else if (Constants.JAR_MAPPER_TINY.equals(jarMapper())) {
new MapJarsTiny().mapJars(this);
} else { } else {
this.getLogger().lifecycle(Constants.MINECRAFT_MAPPED_JAR.get(extension).getAbsolutePath()); throw new RuntimeException("Unknown JAR mapper type: " + jarMapper());
this.getLogger().lifecycle(":mapped jar found, skipping mapping");
} }
} }
} }

View File

@ -25,6 +25,7 @@
package net.fabricmc.loom.task; package net.fabricmc.loom.task;
import com.google.common.base.Joiner;
import net.fabricmc.loom.LoomGradleExtension; import net.fabricmc.loom.LoomGradleExtension;
import net.fabricmc.loom.util.Constants; import net.fabricmc.loom.util.Constants;
import net.fabricmc.tinyremapper.OutputConsumerPath; import net.fabricmc.tinyremapper.OutputConsumerPath;
@ -38,13 +39,11 @@ import java.nio.file.Path;
public class MapJarsTiny { public class MapJarsTiny {
public void mapJars(MapJarsTask task) throws IOException { public void mapJars(MapJarsTask task) throws IOException {
LoomGradleExtension extension = task.getProject().getExtensions().getByType(LoomGradleExtension.class);
String fromM = "mojang"; String fromM = "mojang";
String toM = "pomf"; String toM = "pomf";
Path mappings = Constants.MAPPINGS_TINY.get(extension).toPath(); Path mappings = task.getMappingFile().toPath();
Path[] classpath = task.getProject().getConfigurations().getByName(Constants.CONFIG_MINECRAFT).getFiles().stream() Path[] classpath = task.getMapperPaths().stream()
.map(File::toPath) .map(File::toPath)
.toArray(Path[]::new); .toArray(Path[]::new);
@ -54,12 +53,15 @@ public class MapJarsTiny {
.withMappings(TinyUtils.createTinyMappingProvider(mappings, fromM, toM)) .withMappings(TinyUtils.createTinyMappingProvider(mappings, fromM, toM))
.build(); .build();
Path input = task.getInputJar().toPath();
Path output = task.getMappedJar().toPath();
try { try {
OutputConsumerPath outputConsumer = new OutputConsumerPath(Constants.MINECRAFT_MAPPED_JAR.get(extension).toPath()); OutputConsumerPath outputConsumer = new OutputConsumerPath(output);
outputConsumer.addNonClassFiles(Constants.MINECRAFT_MERGED_JAR.get(extension).toPath()); outputConsumer.addNonClassFiles(input);
remapper.read(Constants.MINECRAFT_MERGED_JAR.get(extension).toPath()); remapper.read(input);
remapper.read(classpath); remapper.read(classpath);
remapper.apply(Constants.MINECRAFT_MERGED_JAR.get(extension).toPath(), outputConsumer); remapper.apply(input, outputConsumer);
outputConsumer.finish(); outputConsumer.finish();
remapper.finish(); remapper.finish();
} catch (Exception e){ } catch (Exception e){

View File

@ -26,37 +26,49 @@ package net.fabricmc.loom.task;
import net.fabricmc.loom.LoomGradleExtension; import net.fabricmc.loom.LoomGradleExtension;
import net.fabricmc.loom.util.Constants; import net.fabricmc.loom.util.Constants;
import net.fabricmc.loom.util.delayed.IDelayed;
import net.fabricmc.stitch.merge.JarMerger; import net.fabricmc.stitch.merge.JarMerger;
import org.gradle.api.DefaultTask; import org.gradle.api.DefaultTask;
import org.gradle.api.tasks.InputFile;
import org.gradle.api.tasks.OutputFile;
import org.gradle.api.tasks.TaskAction; import org.gradle.api.tasks.TaskAction;
import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
public class MergeJarsTask extends DefaultTask { public class MergeJarsTask extends LoomBaseTask {
@InputFile
public File getClientJar() {
return getFile(Constants.MINECRAFT_CLIENT_JAR);
}
@InputFile
public File getServerJar() {
return getFile(Constants.MINECRAFT_SERVER_JAR);
}
@OutputFile
public File getMergedJar() {
return getFile(Constants.MINECRAFT_MERGED_JAR);
}
@TaskAction @TaskAction
public void mergeJars() throws IOException { public void mergeJars() throws IOException {
LoomGradleExtension extension = this.getProject().getExtensions().getByType(LoomGradleExtension.class); this.getLogger().lifecycle(":merging jars");
FileInputStream client = new FileInputStream(getClientJar());
FileInputStream server = new FileInputStream(getServerJar());
FileOutputStream merged = new FileOutputStream(getMergedJar());
if (!Constants.MINECRAFT_MERGED_JAR.get(extension).exists()) { JarMerger jarMerger = new JarMerger(client, server, merged);
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.merge();
jarMerger.close();
jarMerger.merge(); client.close();
jarMerger.close(); server.close();
merged.close();
client.close();
server.close();
merged.close();
} else {
this.getLogger().lifecycle(":merged jar found, skipping");
}
} }
} }

View File

@ -27,7 +27,6 @@ package net.fabricmc.loom.task;
import net.fabricmc.loom.LoomGradleExtension; import net.fabricmc.loom.LoomGradleExtension;
import net.fabricmc.loom.util.Constants; import net.fabricmc.loom.util.Constants;
import net.fabricmc.loom.util.ModProccessor; import net.fabricmc.loom.util.ModProccessor;
import org.apache.commons.lang3.Validate;
import org.gradle.api.DefaultTask; import org.gradle.api.DefaultTask;
import org.gradle.api.artifacts.Configuration; import org.gradle.api.artifacts.Configuration;
import org.gradle.api.tasks.TaskAction; import org.gradle.api.tasks.TaskAction;
@ -53,7 +52,9 @@ public class SetupTask extends DefaultTask {
output.mkdirs(); output.mkdirs();
} }
ModProccessor.handleMod(input, output, getProject()); ModProccessor.handleMod(input, output, getProject());
Validate.isTrue(output.exists()); if (!output.exists()) {
throw new RuntimeException("Output does not exist!");
}
getProject().getDependencies().add(Constants.CONFIG_MINECRAFT, getProject().files(output.getPath())); getProject().getDependencies().add(Constants.CONFIG_MINECRAFT, getProject().files(output.getPath()));
}); });
} }

View File

@ -44,8 +44,9 @@ public class Constants {
public static final IDelayed<File> MINECRAFT_SERVER_JAR = new DelayedFile(extension -> new File(extension.getUserCache(), extension.version + "-server.jar")); public static final IDelayed<File> MINECRAFT_SERVER_JAR = new DelayedFile(extension -> new File(extension.getUserCache(), extension.version + "-server.jar"));
public static final IDelayed<File> MINECRAFT_MERGED_JAR = new DelayedFile(extension -> new File(extension.getUserCache(), extension.version + "-merged.jar")); public static final IDelayed<File> MINECRAFT_MERGED_JAR = new DelayedFile(extension -> new File(extension.getUserCache(), extension.version + "-merged.jar"));
public static final IDelayed<File> MINECRAFT_MAPPED_JAR = new DelayedFile(extension -> new File(extension.getUserCache(), extension.version + "-mapped-" + extension.pomfVersion + ".jar")); public static final IDelayed<File> MINECRAFT_MAPPED_JAR = new DelayedFile(extension -> new File(extension.getUserCache(), extension.version + "-mapped-" + extension.pomfVersion + ".jar"));
public static final IDelayed<File> MINECRAFT_PARTIAL_ENIGMA_JAR = new DelayedFile(extension -> new File(extension.getUserCache(), extension.version + "-partial-enigma-" + extension.pomfVersion + ".jar")); // public static final IDelayed<File> MINECRAFT_PARTIAL_ENIGMA_JAR = new DelayedFile(extension -> new File(extension.getUserCache(), extension.version + "-partial-enigma-" + extension.pomfVersion + ".jar"));
public static final IDelayed<File> MINECRAFT_FINAL_JAR = new DelayedFile(extension -> new File(CACHE_FILES, extension.version + "-final-" + extension.pomfVersion + ".jar")); // public static final IDelayed<File> MINECRAFT_FINAL_JAR = new DelayedFile(extension -> new File(CACHE_FILES, extension.version + "-final-" + extension.pomfVersion + ".jar"));
public static final IDelayed<File> MINECRAFT_FINAL_JAR = MINECRAFT_MAPPED_JAR;
public static final IDelayed<File> POMF_DIR = new DelayedFile(extension -> new File(extension.getUserCache(), "pomf")); public static final IDelayed<File> POMF_DIR = new DelayedFile(extension -> new File(extension.getUserCache(), "pomf"));
public static IDelayed<File> MAPPINGS_TINY_GZ = new DelayedFile(extension -> new File(POMF_DIR.get(extension), "pomf-tiny-" + extension.version + "." + extension.pomfVersion + ".gz")); public static IDelayed<File> MAPPINGS_TINY_GZ = new DelayedFile(extension -> new File(POMF_DIR.get(extension), "pomf-tiny-" + extension.version + "." + extension.pomfVersion + ".gz"));

View File

@ -0,0 +1,35 @@
/*
* 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;
public final class LoomUtil {
private LoomUtil() {
}
public static String capitalize(String s) {
return s.substring(0, 1).toUpperCase() + s.substring(1);
}
}

View File

@ -39,9 +39,8 @@ public class DelayedFile implements IDelayed<File> {
@Override @Override
public File get(LoomGradleExtension extension) { public File get(LoomGradleExtension extension) {
if (this.file == null) { // TODO: Figure out caching issues
this.file = this.function.apply(extension); this.file = this.function.apply(extension);
}
return this.file; return this.file;
} }
} }