debloat, fix fabric-base
This commit is contained in:
		
							parent
							
								
									f32359d7c3
								
							
						
					
					
						commit
						bd5d306a9a
					
				
					 17 changed files with 214 additions and 116 deletions
				
			
		
							
								
								
									
										20
									
								
								build.gradle
									
									
									
									
									
								
							
							
						
						
									
										20
									
								
								build.gradle
									
									
									
									
									
								
							|  | @ -43,30 +43,14 @@ configurations { | |||
| dependencies { | ||||
|     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 '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 ('net.fabricmc:weave:0.2.0.+'){ | ||||
|         transitive = false | ||||
|     } | ||||
|     shade ('net.fabricmc:stitch:0.1.0.+'){ | ||||
|         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.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') { | ||||
|         exclude module: 'launchwrapper' | ||||
|  |  | |||
|  | @ -42,8 +42,10 @@ import org.gradle.api.plugins.JavaPluginConvention; | |||
| import org.gradle.api.tasks.SourceSet; | ||||
| import org.gradle.api.tasks.compile.JavaCompile; | ||||
| 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.idea.model.IdeaModel; | ||||
| import org.gradle.plugins.ide.internal.IdePlugin; | ||||
| 
 | ||||
| import java.io.File; | ||||
| import java.io.FileNotFoundException; | ||||
|  | @ -88,12 +90,15 @@ public class AbstractPlugin implements Plugin<Project> { | |||
| 		configureIDEs(); | ||||
| 		configureCompile(); | ||||
| 
 | ||||
| 
 | ||||
| 		Map<Project, Set<Task>> taskMap = project.getAllTasks(true); | ||||
| 		for (Map.Entry<Project, Set<Task>> entry : taskMap.entrySet()) { | ||||
| 			Project project = entry.getKey(); | ||||
| 			Set<Task> taskSet = entry.getValue(); | ||||
| 			for (Task task : taskSet) { | ||||
| 				if (task instanceof GeneratorTask) { | ||||
| 					task.dependsOn("setup"); | ||||
| 				} | ||||
| 
 | ||||
| 				if (task instanceof JavaCompile | ||||
| 					&& !(task.getName().contains("Test")) && !(task.getName().contains("test"))) { | ||||
| 					JavaCompile javaCompileTask = (JavaCompile) task; | ||||
|  | @ -164,17 +169,17 @@ public class AbstractPlugin implements Plugin<Project> { | |||
| 	 */ | ||||
| 	protected void configureIDEs() { | ||||
| 		// 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()); | ||||
| 		ideaModule.getModule().setDownloadJavadoc(true); | ||||
| 		ideaModule.getModule().setDownloadSources(true); | ||||
| 		ideaModule.getModule().setInheritOutputDirs(true); | ||||
| 		ideaModule.getModule().getScopes().get("COMPILE").get("plus").add(project.getConfigurations().getByName(Constants.CONFIG_MINECRAFT)); | ||||
| 		ideaModel.getModule().getExcludeDirs().addAll(project.files(".gradle", "build", ".idea", "out").getFiles()); | ||||
| 		ideaModel.getModule().setDownloadJavadoc(true); | ||||
| 		ideaModel.getModule().setDownloadSources(true); | ||||
| 		ideaModel.getModule().setInheritOutputDirs(true); | ||||
| 		ideaModel.getModule().getScopes().get("COMPILE").get("plus").add(project.getConfigurations().getByName(Constants.CONFIG_MINECRAFT)); | ||||
| 
 | ||||
| 		// ECLIPSE | ||||
| 		EclipseModel eclipseModule = (EclipseModel) project.getExtensions().getByName("eclipse"); | ||||
| 		eclipseModule.getClasspath().getPlusConfigurations().add(project.getConfigurations().getByName(Constants.CONFIG_MINECRAFT)); | ||||
| 		EclipseModel eclipseModel = (EclipseModel) project.getExtensions().getByName("eclipse"); | ||||
| 		eclipseModel.getClasspath().getPlusConfigurations().add(project.getConfigurations().getByName(Constants.CONFIG_MINECRAFT)); | ||||
| 	} | ||||
| 
 | ||||
| 	/** | ||||
|  |  | |||
|  | @ -35,8 +35,7 @@ public class LoomGradlePlugin extends AbstractPlugin { | |||
| 		makeTask("download", DownloadTask.class); | ||||
| 		makeTask("mergeJars", MergeJarsTask.class).dependsOn("download"); | ||||
| 		makeTask("mapJars", MapJarsTask.class).dependsOn("mergeJars"); | ||||
| 		makeTask("finaliseJars", FinaliseJar.class).dependsOn("mapJars"); | ||||
| 		makeTask("setup", SetupTask.class).dependsOn("finaliseJars").setGroup("fabric"); | ||||
| 		makeTask("setup", SetupTask.class).dependsOn("mapJars").setGroup("fabric"); | ||||
| 
 | ||||
| 		makeTask("extractNatives", ExtractNativesTask.class).dependsOn("download"); | ||||
| 		makeTask("genIdeaWorkspace", GenIdeaProjectTask.class).dependsOn("idea").setGroup("ide"); | ||||
|  |  | |||
|  | @ -57,8 +57,6 @@ public class MixinMappingProviderTiny extends MappingProvider { | |||
| 
 | ||||
| 	@Override | ||||
| 	public MappingMethod getMethodMapping(MappingMethod method) { | ||||
| 		System.out.println("processing " + method.getName() + method.getDesc()); | ||||
| 
 | ||||
| 		MappingMethod mapped = this.methodMap.get(method); | ||||
| 		if (mapped != null) | ||||
| 			return mapped; | ||||
|  | @ -96,8 +94,6 @@ public class MixinMappingProviderTiny extends MappingProvider { | |||
| 
 | ||||
| 	@Override | ||||
| 	public MappingField getFieldMapping(MappingField field) { | ||||
| 		System.out.println("processing " + field.getOwner() + "/" + field.getName() + field.getDesc()); | ||||
| 
 | ||||
| 		MappingField mapped = this.fieldMap.get(field); | ||||
| 		if (mapped != null) | ||||
| 			return mapped; | ||||
|  |  | |||
|  | @ -41,7 +41,6 @@ public class MixinServiceGradle extends MixinServiceLaunchWrapper implements ICl | |||
| 
 | ||||
| 	private static List<JarFile> jars = new ArrayList<>(); | ||||
| 
 | ||||
| 
 | ||||
| 	@Override | ||||
| 	public String getName() { | ||||
| 		return "FabricGradle"; | ||||
|  |  | |||
|  | @ -39,9 +39,8 @@ public class ObfuscationEnvironmentFabric extends ObfuscationEnvironment { | |||
| 
 | ||||
| 	@Override | ||||
| 	protected IMappingProvider getMappingProvider(Messager messager, Filer filer) { | ||||
| 		String from = type.getKey().split(":")[0]; | ||||
| 		String to = type.getKey().split(":")[1]; | ||||
| 		return new MixinMappingProviderTiny(messager, filer, from, to); | ||||
| 		String[] key = type.getKey().split(":"); | ||||
| 		return new MixinMappingProviderTiny(messager, filer, key[0], key[1]); | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
|  |  | |||
|  | @ -25,7 +25,7 @@ | |||
| package net.fabricmc.loom.mixin; | ||||
| 
 | ||||
| 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.ObfuscationTypeDescriptor; | ||||
| 
 | ||||
|  | @ -38,7 +38,7 @@ public class ObfuscationServiceFabric implements IObfuscationService { | |||
| 	public static final String OUT_MAP_FILE = "outMapFile"; | ||||
| 
 | ||||
| 	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) { | ||||
|  | @ -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_EXTRA_FILES, from, to)); | ||||
| 		builder.add(asSuffixed(ObfuscationServiceFabric.OUT_MAP_FILE, from, to)); | ||||
|  | @ -59,8 +59,12 @@ public class ObfuscationServiceFabric implements IObfuscationService { | |||
| 
 | ||||
| 	@Override | ||||
| 	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, "pomf", "mojang"); | ||||
| 		addSupportedOptions(builder, "pomf", "intermediary"); | ||||
| 		return builder.build(); | ||||
| 	} | ||||
|  | @ -68,8 +72,12 @@ public class ObfuscationServiceFabric implements IObfuscationService { | |||
| 	@Override | ||||
| 	public Collection<ObfuscationTypeDescriptor> getObfuscationTypes() { | ||||
| 		return ImmutableSet.of( | ||||
| 			createObfuscationType("intermediary", "pomf"), | ||||
| 			createObfuscationType("pomf", "intermediary") | ||||
| 				createObfuscationType("mojang", "intermediary"), | ||||
| 				createObfuscationType("mojang", "pomf"), | ||||
| 				createObfuscationType("intermediary", "mojang"), | ||||
| 				createObfuscationType("intermediary", "pomf"), | ||||
| 				createObfuscationType("pomf", "mojang"), | ||||
| 				createObfuscationType("pomf", "intermediary") | ||||
| 		); | ||||
| 	} | ||||
| } | ||||
|  |  | |||
|  | @ -24,6 +24,8 @@ | |||
| 
 | ||||
| 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.GsonBuilder; | ||||
| import net.fabricmc.loom.LoomGradleExtension; | ||||
|  | @ -43,7 +45,9 @@ import org.gradle.api.tasks.TaskAction; | |||
| 
 | ||||
| import java.io.*; | ||||
| import java.net.URL; | ||||
| import java.util.HashMap; | ||||
| import java.util.Map; | ||||
| import java.util.Objects; | ||||
| import java.util.Optional; | ||||
| import java.util.zip.GZIPInputStream; | ||||
| 
 | ||||
|  | @ -145,6 +149,20 @@ public class DownloadTask extends DefaultTask { | |||
| 
 | ||||
| 			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); | ||||
| 			if (!assets.exists()) { | ||||
| 				assets.mkdirs(); | ||||
|  | @ -166,7 +184,18 @@ public class DownloadTask extends DefaultTask { | |||
| 			for (Map.Entry<String, AssetObject> entry : parent.entrySet()) { | ||||
| 				AssetObject object = entry.getValue(); | ||||
| 				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)) { | ||||
| 					this.getLogger().debug(":downloading asset " + entry.getKey()); | ||||
| 					FileUtils.copyURLToFile(new URL(Constants.RESOURCES_BASE + sha1.substring(0, 2) + "/" + sha1), file); | ||||
|  |  | |||
|  | @ -25,23 +25,14 @@ | |||
| package net.fabricmc.loom.task; | ||||
| 
 | ||||
| import net.fabricmc.loom.LoomGradleExtension; | ||||
| import net.fabricmc.loom.util.Constants; | ||||
| import org.apache.commons.io.FileUtils; | ||||
| import net.fabricmc.loom.util.delayed.IDelayed; | ||||
| import org.gradle.api.DefaultTask; | ||||
| import org.gradle.api.tasks.TaskAction; | ||||
| 
 | ||||
| import java.io.IOException; | ||||
| import java.io.File; | ||||
| 
 | ||||
| public class FinaliseJar extends DefaultTask { | ||||
| 
 | ||||
| 	@TaskAction | ||||
| 	public void finaliseJar() throws IOException { | ||||
| 		//What is the point to this? | ||||
| public class LoomBaseTask extends DefaultTask { | ||||
| 	protected final File getFile(IDelayed<File> file) { | ||||
| 		LoomGradleExtension extension = this.getProject().getExtensions().getByType(LoomGradleExtension.class); | ||||
| 		if(!Constants.MINECRAFT_FINAL_JAR.get(extension).exists()){ | ||||
| 			FileUtils.copyFile(Constants.MINECRAFT_MAPPED_JAR.get(extension), Constants.MINECRAFT_FINAL_JAR.get(extension)); | ||||
| 		} | ||||
| 		return file.get(extension); | ||||
| 	} | ||||
| 
 | ||||
| 
 | ||||
| } | ||||
|  | @ -25,13 +25,13 @@ | |||
| package net.fabricmc.loom.task; | ||||
| 
 | ||||
| 
 | ||||
| import cuchaz.enigma.Deobfuscator; | ||||
| /* import cuchaz.enigma.Deobfuscator; | ||||
| import cuchaz.enigma.TranslatingTypeLoader; | ||||
| import cuchaz.enigma.mapping.MappingsEnigmaReader; | ||||
| import cuchaz.enigma.mapping.TranslationDirection; | ||||
| import cuchaz.enigma.mapping.Translator; | ||||
| 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.util.Constants; | ||||
| import net.fabricmc.tinyremapper.OutputConsumerPath; | ||||
|  | @ -48,7 +48,11 @@ import java.nio.file.Path; | |||
| import java.util.jar.JarFile; | ||||
| 
 | ||||
| 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 { | ||||
| 		LoomGradleExtension extension = task.getProject().getExtensions().getByType(LoomGradleExtension.class); | ||||
|  | @ -114,5 +118,5 @@ public class MapJarsEnigma { | |||
| 		public void onProgress(int i, String s) { | ||||
| 
 | ||||
| 		} | ||||
| 	} | ||||
| 	} */ | ||||
| } | ||||
|  |  | |||
|  | @ -27,38 +27,72 @@ package net.fabricmc.loom.task; | |||
| import net.fabricmc.loom.LoomGradleExtension; | ||||
| import net.fabricmc.loom.util.Constants; | ||||
| import org.gradle.api.DefaultTask; | ||||
| import org.gradle.api.tasks.TaskAction; | ||||
| import org.gradle.api.tasks.*; | ||||
| 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 static final boolean ALWAYS_REMAP = false; | ||||
| public class MapJarsTask extends LoomBaseTask { | ||||
| 	@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 | ||||
| 	public void mapJars() throws Exception { | ||||
| 		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()) { | ||||
| 				this.getLogger().lifecycle("Mapping version not set, skipping mapping!"); | ||||
| 				FileUtils.copyFile(Constants.MINECRAFT_MERGED_JAR.get(extension), Constants.MINECRAFT_MAPPED_JAR.get(extension)); | ||||
| 				return; | ||||
| 			} | ||||
| 		if (getMappedJar().exists()){ | ||||
| 			getMappedJar().delete(); | ||||
| 		} | ||||
| 
 | ||||
| 			if (Constants.JAR_MAPPER_ENIGMA.equals(extension.jarMapper)) { | ||||
| 				new MapJarsEnigma().mapJars(this); | ||||
| 			} else if (Constants.JAR_MAPPER_TINY.equals(extension.jarMapper)) { | ||||
| 				new MapJarsTiny().mapJars(this); | ||||
| 			} else { | ||||
| 				throw new RuntimeException("Unknown JAR mapper type: " + extension.jarMapper); | ||||
| 			} | ||||
| 		if (!extension.hasPomf()) { | ||||
| 			this.getLogger().lifecycle("Mapping version not set, skipping mapping!"); | ||||
| 			FileUtils.copyFile(Constants.MINECRAFT_MERGED_JAR.get(extension), getMappedJar()); | ||||
| 			return; | ||||
| 		} | ||||
| 
 | ||||
| 		if (Constants.JAR_MAPPER_ENIGMA.equals(jarMapper())) { | ||||
| 			new MapJarsEnigma().mapJars(this); | ||||
| 		} else if (Constants.JAR_MAPPER_TINY.equals(jarMapper())) { | ||||
| 			new MapJarsTiny().mapJars(this); | ||||
| 		} else { | ||||
| 			this.getLogger().lifecycle(Constants.MINECRAFT_MAPPED_JAR.get(extension).getAbsolutePath()); | ||||
| 			this.getLogger().lifecycle(":mapped jar found, skipping mapping"); | ||||
| 			throw new RuntimeException("Unknown JAR mapper type: " + jarMapper()); | ||||
| 		} | ||||
| 	} | ||||
| } | ||||
|  |  | |||
|  | @ -25,6 +25,7 @@ | |||
| package net.fabricmc.loom.task; | ||||
| 
 | ||||
| 
 | ||||
| import com.google.common.base.Joiner; | ||||
| import net.fabricmc.loom.LoomGradleExtension; | ||||
| import net.fabricmc.loom.util.Constants; | ||||
| import net.fabricmc.tinyremapper.OutputConsumerPath; | ||||
|  | @ -38,13 +39,11 @@ import java.nio.file.Path; | |||
| public class MapJarsTiny { | ||||
| 
 | ||||
| 	public void mapJars(MapJarsTask task) throws IOException { | ||||
| 		LoomGradleExtension extension = task.getProject().getExtensions().getByType(LoomGradleExtension.class); | ||||
| 
 | ||||
| 		String fromM = "mojang"; | ||||
| 		String toM = "pomf"; | ||||
| 
 | ||||
| 		Path mappings = Constants.MAPPINGS_TINY.get(extension).toPath(); | ||||
| 		Path[] classpath = task.getProject().getConfigurations().getByName(Constants.CONFIG_MINECRAFT).getFiles().stream() | ||||
| 		Path mappings = task.getMappingFile().toPath(); | ||||
| 		Path[] classpath = task.getMapperPaths().stream() | ||||
| 				.map(File::toPath) | ||||
| 				.toArray(Path[]::new); | ||||
| 
 | ||||
|  | @ -54,12 +53,15 @@ public class MapJarsTiny { | |||
| 				.withMappings(TinyUtils.createTinyMappingProvider(mappings, fromM, toM)) | ||||
| 				.build(); | ||||
| 
 | ||||
| 		Path input = task.getInputJar().toPath(); | ||||
| 		Path output = task.getMappedJar().toPath(); | ||||
| 
 | ||||
| 		try { | ||||
| 			OutputConsumerPath outputConsumer = new OutputConsumerPath(Constants.MINECRAFT_MAPPED_JAR.get(extension).toPath()); | ||||
| 			outputConsumer.addNonClassFiles(Constants.MINECRAFT_MERGED_JAR.get(extension).toPath()); | ||||
| 			remapper.read(Constants.MINECRAFT_MERGED_JAR.get(extension).toPath()); | ||||
| 			OutputConsumerPath outputConsumer = new OutputConsumerPath(output); | ||||
| 			outputConsumer.addNonClassFiles(input); | ||||
| 			remapper.read(input); | ||||
| 			remapper.read(classpath); | ||||
| 			remapper.apply(Constants.MINECRAFT_MERGED_JAR.get(extension).toPath(), outputConsumer); | ||||
| 			remapper.apply(input, outputConsumer); | ||||
| 			outputConsumer.finish(); | ||||
| 			remapper.finish(); | ||||
| 		} catch (Exception e){ | ||||
|  |  | |||
|  | @ -26,37 +26,49 @@ package net.fabricmc.loom.task; | |||
| 
 | ||||
| import net.fabricmc.loom.LoomGradleExtension; | ||||
| import net.fabricmc.loom.util.Constants; | ||||
| import net.fabricmc.loom.util.delayed.IDelayed; | ||||
| import net.fabricmc.stitch.merge.JarMerger; | ||||
| import org.gradle.api.DefaultTask; | ||||
| import org.gradle.api.tasks.InputFile; | ||||
| import org.gradle.api.tasks.OutputFile; | ||||
| import org.gradle.api.tasks.TaskAction; | ||||
| 
 | ||||
| import java.io.File; | ||||
| import java.io.FileInputStream; | ||||
| import java.io.FileOutputStream; | ||||
| 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 | ||||
| 	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()) { | ||||
| 			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(); | ||||
| 
 | ||||
| 			jarMerger.merge(); | ||||
| 			jarMerger.close(); | ||||
| 
 | ||||
| 			client.close(); | ||||
| 			server.close(); | ||||
| 			merged.close(); | ||||
| 		} else { | ||||
| 			this.getLogger().lifecycle(":merged jar found, skipping"); | ||||
| 		} | ||||
| 		client.close(); | ||||
| 		server.close(); | ||||
| 		merged.close(); | ||||
| 	} | ||||
| 
 | ||||
| } | ||||
|  |  | |||
|  | @ -27,7 +27,6 @@ package net.fabricmc.loom.task; | |||
| import net.fabricmc.loom.LoomGradleExtension; | ||||
| import net.fabricmc.loom.util.Constants; | ||||
| import net.fabricmc.loom.util.ModProccessor; | ||||
| import org.apache.commons.lang3.Validate; | ||||
| import org.gradle.api.DefaultTask; | ||||
| import org.gradle.api.artifacts.Configuration; | ||||
| import org.gradle.api.tasks.TaskAction; | ||||
|  | @ -53,7 +52,9 @@ public class SetupTask extends DefaultTask { | |||
| 					output.mkdirs(); | ||||
| 				} | ||||
| 				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())); | ||||
| 			}); | ||||
| 	} | ||||
|  |  | |||
|  | @ -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_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_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_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 = MINECRAFT_MAPPED_JAR; | ||||
| 
 | ||||
| 	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")); | ||||
|  |  | |||
							
								
								
									
										35
									
								
								src/main/java/net/fabricmc/loom/util/LoomUtil.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										35
									
								
								src/main/java/net/fabricmc/loom/util/LoomUtil.java
									
									
									
									
									
										Normal 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); | ||||
| 	} | ||||
| } | ||||
|  | @ -39,9 +39,8 @@ public class DelayedFile implements IDelayed<File> { | |||
| 
 | ||||
| 	@Override | ||||
| 	public File get(LoomGradleExtension extension) { | ||||
| 		if (this.file == null) { | ||||
| 			this.file = this.function.apply(extension); | ||||
| 		} | ||||
| 		// TODO: Figure out caching issues | ||||
| 		this.file = this.function.apply(extension); | ||||
| 		return this.file; | ||||
| 	} | ||||
| } | ||||
|  |  | |||
		Loading…
	
		Reference in a new issue