migrate RemapJarTask and RemapSourcesJarTask over to getters/setters for fields; make RemapJarTask use input and output locations instead of in-place renaming fluff
This commit is contained in:
		
							parent
							
								
									1c56fb2eda
								
							
						
					
					
						commit
						788df9cfc7
					
				
					 11 changed files with 135 additions and 169 deletions
				
			
		
							
								
								
									
										13
									
								
								build.gradle
									
									
									
									
									
								
							
							
						
						
									
										13
									
								
								build.gradle
									
									
									
									
									
								
							|  | @ -11,7 +11,7 @@ targetCompatibility = 1.8 | |||
| 
 | ||||
| group = 'net.fabricmc' | ||||
| archivesBaseName = project.name | ||||
| version = '0.2.2-SNAPSHOT' | ||||
| version = '0.2.3-SNAPSHOT' | ||||
| 
 | ||||
| def build = "local" | ||||
| def ENV = System.getenv() | ||||
|  | @ -30,19 +30,28 @@ repositories { | |||
| dependencies { | ||||
| 	implementation gradleApi() | ||||
| 
 | ||||
| 	// libraries | ||||
| 	implementation ('commons-io:commons-io:2.6') | ||||
| 	implementation ('org.zeroturnaround:zt-zip:1.13') | ||||
| 	implementation ('com.google.code.gson:gson:2.8.5') | ||||
| 	implementation ('com.google.guava:guava:27.1-jre') | ||||
| 
 | ||||
| 	// game handling utils | ||||
| 	implementation ('net.fabricmc:stitch:0.1.2.50') { | ||||
| 		exclude module: 'enigma' | ||||
| 	} | ||||
| 
 | ||||
| 	// tinyfile management | ||||
| 	implementation ('net.fabricmc:tiny-remapper:0.1.0.33') { | ||||
| 		transitive = false | ||||
| 	} | ||||
| 	implementation ('org.jetbrains:intellij-fernflower:1.0.0.8') | ||||
| 	implementation ('net.fabricmc:fabric-mixin-compile-extensions:0.1.0.+') | ||||
| 
 | ||||
| 	// decompilers | ||||
| 	implementation ('net.fabricmc:procyon-fabric-compilertools:0.5.33.+') | ||||
| 	implementation ('org.jetbrains:intellij-fernflower:1.0.0.8') | ||||
| 
 | ||||
| 	// source code remapping | ||||
| 	implementation ('org.cadixdev:mercury:0.1.0.fabric-SNAPSHOT') | ||||
| 
 | ||||
| } | ||||
|  |  | |||
|  | @ -28,18 +28,15 @@ import com.google.common.collect.ImmutableMap; | |||
| import groovy.util.Node; | ||||
| import net.fabricmc.loom.providers.MappingsProvider; | ||||
| import net.fabricmc.loom.providers.MinecraftProvider; | ||||
| import net.fabricmc.loom.task.RemapJar; | ||||
| import net.fabricmc.loom.task.RemapSourcesJar; | ||||
| import net.fabricmc.loom.task.RemapJarTask; | ||||
| import net.fabricmc.loom.task.RemapSourcesJarTask; | ||||
| import net.fabricmc.loom.util.*; | ||||
| import org.gradle.api.*; | ||||
| import org.gradle.api.artifacts.Configuration; | ||||
| import org.gradle.api.artifacts.Dependency; | ||||
| import org.gradle.api.artifacts.component.ModuleComponentIdentifier; | ||||
| import org.gradle.api.artifacts.dsl.DependencyHandler; | ||||
| import org.gradle.api.artifacts.repositories.MavenArtifactRepository; | ||||
| import org.gradle.api.artifacts.result.DependencyResult; | ||||
| import org.gradle.api.artifacts.result.ResolvedArtifactResult; | ||||
| import org.gradle.api.artifacts.result.ResolvedComponentResult; | ||||
| import org.gradle.api.artifacts.result.ResolvedDependencyResult; | ||||
| import org.gradle.api.plugins.JavaPlugin; | ||||
| import org.gradle.api.plugins.JavaPluginConvention; | ||||
|  | @ -286,10 +283,15 @@ public class AbstractPlugin implements Plugin<Project> { | |||
| 			// Enables the default mod remapper | ||||
| 			if (extension.remapMod) { | ||||
| 				AbstractArchiveTask jarTask = (AbstractArchiveTask) project1.getTasks().getByName("jar"); | ||||
| 				RemapJarTask remapJarTask = (RemapJarTask) project1.getTasks().findByName("remapJar"); | ||||
| 
 | ||||
| 				RemapJar remapJarTask = (RemapJar) project1.getTasks().findByName("remapJar"); | ||||
| 				if (remapJarTask.jar==null) remapJarTask.jar = jarTask.getArchivePath(); | ||||
| 				remapJarTask.doLast(task -> project1.getArtifacts().add("archives", remapJarTask.jar)); | ||||
| 				if (remapJarTask.getInput() == null) { | ||||
| 					remapJarTask.setOutput(jarTask.getArchivePath()); | ||||
| 					jarTask.setClassifier("dev"); | ||||
| 					remapJarTask.setInput(jarTask.getArchivePath()); | ||||
| 				} | ||||
| 
 | ||||
| 				remapJarTask.doLast(task -> project1.getArtifacts().add("archives", remapJarTask.getOutput())); | ||||
| 				remapJarTask.dependsOn(project1.getTasks().getByName("jar")); | ||||
| 				project1.getTasks().getByName("build").dependsOn(remapJarTask); | ||||
| 
 | ||||
|  | @ -297,7 +299,7 @@ public class AbstractPlugin implements Plugin<Project> { | |||
| 				for (Map.Entry<Project, Set<Task>> entry : taskMap.entrySet()) { | ||||
| 					Set<Task> taskSet = entry.getValue(); | ||||
| 					for (Task task : taskSet) { | ||||
| 						if (task instanceof RemapJar && ((RemapJar) task).isNestJar()) { | ||||
| 						if (task instanceof RemapJarTask && ((RemapJarTask) task).isAddNestedDependencies()) { | ||||
| 							//Run all the sub project remap jars tasks before the root projects jar, this is to allow us to include projects | ||||
| 							NestedJars.getRequiredTasks(project1).forEach(task::dependsOn); | ||||
| 						} | ||||
|  | @ -307,9 +309,10 @@ public class AbstractPlugin implements Plugin<Project> { | |||
| 				try { | ||||
| 					AbstractArchiveTask sourcesTask = (AbstractArchiveTask) project1.getTasks().getByName("sourcesJar"); | ||||
| 
 | ||||
| 					RemapSourcesJar remapSourcesJarTask = (RemapSourcesJar) project1.getTasks().findByName("remapSourcesJar"); | ||||
| 					remapSourcesJarTask.jar = sourcesTask.getArchivePath(); | ||||
| 					remapSourcesJarTask.doLast(task -> project1.getArtifacts().add("archives", remapSourcesJarTask.jar)); | ||||
| 					RemapSourcesJarTask remapSourcesJarTask = (RemapSourcesJarTask) project1.getTasks().findByName("remapSourcesJar"); | ||||
| 					remapSourcesJarTask.setInput(sourcesTask.getArchivePath()); | ||||
| 					remapSourcesJarTask.setOutput(sourcesTask.getArchivePath()); | ||||
| 					remapSourcesJarTask.doLast(task -> project1.getArtifacts().add("archives", remapSourcesJarTask.getOutput())); | ||||
| 					remapSourcesJarTask.dependsOn(project1.getTasks().getByName("sourcesJar")); | ||||
| 					project1.getTasks().getByName("build").dependsOn(remapSourcesJarTask); | ||||
| 				} catch (UnknownTaskException e) { | ||||
|  | @ -317,7 +320,7 @@ public class AbstractPlugin implements Plugin<Project> { | |||
| 				} | ||||
| 			} else { | ||||
| 				AbstractArchiveTask jarTask = (AbstractArchiveTask) project1.getTasks().getByName("jar"); | ||||
| 				extension.addUnmappedMod(jarTask.getArchivePath()); | ||||
| 				extension.addUnmappedMod(jarTask.getArchivePath().toPath()); | ||||
| 			} | ||||
| 		}); | ||||
| 	} | ||||
|  |  | |||
|  | @ -40,6 +40,7 @@ import org.gradle.api.artifacts.result.ResolvedArtifactResult; | |||
| 
 | ||||
| import javax.annotation.Nullable; | ||||
| import java.io.File; | ||||
| import java.nio.file.Path; | ||||
| import java.util.*; | ||||
| import java.util.function.BiPredicate; | ||||
| import java.util.function.Function; | ||||
|  | @ -54,7 +55,7 @@ public class LoomGradleExtension { | |||
| 	public boolean autoGenIDERuns = true; | ||||
| 	public boolean extractJars = false; | ||||
| 
 | ||||
| 	private List<File> unmappedModsBuilt = new ArrayList<>(); | ||||
| 	private List<Path> unmappedModsBuilt = new ArrayList<>(); | ||||
| 
 | ||||
| 	//Not to be set in the build.gradle | ||||
| 	private Project project; | ||||
|  | @ -71,11 +72,11 @@ public class LoomGradleExtension { | |||
| 		this.project = project; | ||||
| 	} | ||||
| 
 | ||||
| 	public void addUnmappedMod(File file) { | ||||
| 	public void addUnmappedMod(Path file) { | ||||
| 		unmappedModsBuilt.add(file); | ||||
| 	} | ||||
| 
 | ||||
| 	public List<File> getUnmappedMods() { | ||||
| 	public List<Path> getUnmappedMods() { | ||||
| 		return Collections.unmodifiableList(unmappedModsBuilt); | ||||
| 	} | ||||
| 
 | ||||
|  |  | |||
|  | @ -64,7 +64,7 @@ public class LoomGradlePlugin extends AbstractPlugin { | |||
| 			t.getOutputs().upToDateWhen((o) -> false); | ||||
| 		}); | ||||
| 
 | ||||
| 		tasks.register("remapJar", RemapJar.class); | ||||
| 		tasks.register("remapJar", RemapJarTask.class); | ||||
| 
 | ||||
| 		tasks.register("genSourcesDecompile", FernFlowerTask.class, t -> { | ||||
| 			t.getOutputs().upToDateWhen((o) -> false); | ||||
|  | @ -136,7 +136,7 @@ public class LoomGradlePlugin extends AbstractPlugin { | |||
| 			t.setGroup("ide"); | ||||
| 		}); | ||||
| 
 | ||||
| 		tasks.register("remapSourcesJar", RemapSourcesJar.class); | ||||
| 		tasks.register("remapSourcesJar", RemapSourcesJarTask.class); | ||||
| 
 | ||||
| 		tasks.register("runClient", RunClientTask.class, t -> { | ||||
| 			t.dependsOn("buildNeeded", "downloadAssets"); | ||||
|  |  | |||
|  | @ -33,6 +33,8 @@ import org.gradle.api.Project; | |||
| import org.gradle.api.tasks.JavaExec; | ||||
| 
 | ||||
| import java.io.File; | ||||
| import java.nio.file.Files; | ||||
| import java.nio.file.Path; | ||||
| import java.util.ArrayList; | ||||
| import java.util.Arrays; | ||||
| import java.util.Collections; | ||||
|  | @ -63,9 +65,9 @@ public abstract class AbstractRunTask extends JavaExec { | |||
|         for (File file : getProject().getConfigurations().getByName("compile").getFiles()) { | ||||
|             libs.add(file.getAbsolutePath()); | ||||
|         } | ||||
|         for (File file : extension.getUnmappedMods()) { | ||||
|             if (file.isFile()) { | ||||
|                 libs.add(file.getAbsolutePath()); | ||||
|         for (Path file : extension.getUnmappedMods()) { | ||||
|             if (Files.isRegularFile(file)) { | ||||
|                 libs.add(file.toFile().getAbsolutePath()); | ||||
|             } | ||||
|         } | ||||
| 
 | ||||
|  |  | |||
|  | @ -1,65 +0,0 @@ | |||
| /* | ||||
|  * 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.task; | ||||
| 
 | ||||
| import net.fabricmc.loom.util.ModRemapper; | ||||
| import org.gradle.api.tasks.Input; | ||||
| 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.IOException; | ||||
| 
 | ||||
| public class RemapJar extends AbstractLoomTask { | ||||
| 	public File jar; | ||||
| 	public File destination; | ||||
| 	public boolean nestJar = true; | ||||
| 
 | ||||
| 	@InputFile | ||||
| 	public File getJar() { | ||||
| 		return jar; | ||||
| 	} | ||||
| 
 | ||||
| 	@Input | ||||
| 	public boolean isNestJar() { | ||||
| 		return nestJar; | ||||
| 	} | ||||
| 
 | ||||
| 	@OutputFile | ||||
| 	public File getDestination() { | ||||
| 		if (destination == null) { | ||||
| 			String s = jar.getAbsolutePath(); | ||||
| 			return new File(s.substring(0, s.length() - 4) + "-dev.jar"); | ||||
| 		} | ||||
| 
 | ||||
| 		return destination; | ||||
| 	} | ||||
| 
 | ||||
| 	@TaskAction | ||||
| 	public void remap() throws IOException { | ||||
| 		ModRemapper.remap(this, nestJar); | ||||
| 	} | ||||
| } | ||||
|  | @ -22,58 +22,56 @@ | |||
|  * SOFTWARE. | ||||
|  */ | ||||
| 
 | ||||
| package net.fabricmc.loom.util; | ||||
| package net.fabricmc.loom.task; | ||||
| 
 | ||||
| import com.google.common.io.Files; | ||||
| import net.fabricmc.loom.LoomGradleExtension; | ||||
| import net.fabricmc.loom.providers.MappingsProvider; | ||||
| import net.fabricmc.loom.task.RemapJar; | ||||
| import net.fabricmc.loom.util.Constants; | ||||
| import net.fabricmc.loom.util.MixinRefmapHelper; | ||||
| import net.fabricmc.loom.util.NestedJars; | ||||
| import net.fabricmc.loom.util.TinyRemapperMappingsHelper; | ||||
| import net.fabricmc.tinyremapper.OutputConsumerPath; | ||||
| import net.fabricmc.tinyremapper.TinyRemapper; | ||||
| import net.fabricmc.tinyremapper.TinyUtils; | ||||
| import org.gradle.api.Project; | ||||
| import org.gradle.api.tasks.Input; | ||||
| 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.FileNotFoundException; | ||||
| import java.io.IOException; | ||||
| import java.nio.file.Files; | ||||
| import java.nio.file.Path; | ||||
| import java.util.ArrayList; | ||||
| import java.util.Iterator; | ||||
| import java.util.List; | ||||
| 
 | ||||
| public class ModRemapper { | ||||
| public class RemapJarTask extends AbstractLoomTask { | ||||
| 	private Object input; | ||||
| 	private Object output; | ||||
| 	private boolean addNestedDependencies; | ||||
| 
 | ||||
| 	public static void remap(RemapJar task, boolean nest) throws IOException { | ||||
| 		Project project = task.getProject(); | ||||
| 	@TaskAction | ||||
| 	public void doTask() throws Throwable { | ||||
| 		Project project = getProject(); | ||||
| 		LoomGradleExtension extension = project.getExtensions().getByType(LoomGradleExtension.class); | ||||
| 		Path input = getInput().toPath(); | ||||
| 		Path output = getOutput().toPath(); | ||||
| 
 | ||||
| 		File modJar = task.getJar(); | ||||
| 
 | ||||
| 		if (!modJar.exists()) { | ||||
| 			project.getLogger().error("Source .JAR not found!"); | ||||
| 			return; | ||||
| 		if (!Files.exists(input)) { | ||||
| 			throw new FileNotFoundException(input.toString()); | ||||
| 		} | ||||
| 
 | ||||
| 		MappingsProvider mappingsProvider = extension.getMappingsProvider(); | ||||
| 
 | ||||
| 		Path mappings = mappingsProvider.MAPPINGS_TINY.toPath(); | ||||
| 
 | ||||
| 		String fromM = "named"; | ||||
| 		String toM = "intermediary"; | ||||
| 
 | ||||
| 		List<File> classpathFiles = new ArrayList<>(); | ||||
| 		classpathFiles.addAll(project.getConfigurations().getByName(Constants.COMPILE_MODS_MAPPED).getFiles()); | ||||
| 		classpathFiles.addAll(project.getConfigurations().getByName(Constants.MINECRAFT_NAMED).getFiles()); | ||||
| 		final Path modJarPath = modJar.toPath(); | ||||
| 		Path[] classpath = classpathFiles.stream().map(File::toPath).filter((p) -> !modJarPath.equals(p)).toArray(Path[]::new); | ||||
| 
 | ||||
| 		String s = modJar.getAbsolutePath(); | ||||
| 		File modJarOutput = new File(s.substring(0, s.length() - 4) + ".remapped.jar"); | ||||
| 		Path modJarOutputPath = modJarOutput.toPath(); | ||||
| 
 | ||||
| 		File modJarUnmappedCopy = task.getDestination(); | ||||
| 		if (modJarUnmappedCopy.exists()) { | ||||
| 			modJarUnmappedCopy.delete(); | ||||
| 		} | ||||
| 		Path[] classpath = classpathFiles.stream().map(File::toPath).filter((p) -> !input.equals(p)).toArray(Path[]::new); | ||||
| 
 | ||||
| 		File mixinMapFile = mappingsProvider.MAPPINGS_MIXIN_EXPORT; | ||||
| 		Path mixinMapPath = mixinMapFile.toPath(); | ||||
|  | @ -85,35 +83,40 @@ public class ModRemapper { | |||
| 			remapperBuilder = remapperBuilder.withMappings(TinyUtils.createTinyMappingProvider(mixinMapPath, fromM, toM)); | ||||
| 		} | ||||
| 
 | ||||
| 		project.getLogger().lifecycle("Remapping " + modJar.getName()); | ||||
| 		project.getLogger().lifecycle(":remapping " + input.getFileName()); | ||||
| 
 | ||||
| 		TinyRemapper remapper = remapperBuilder.build(); | ||||
| 
 | ||||
| 		try (OutputConsumerPath outputConsumer = new OutputConsumerPath(modJarOutputPath)) { | ||||
| 			outputConsumer.addNonClassFiles(modJarPath); | ||||
| 		try (OutputConsumerPath outputConsumer = new OutputConsumerPath(output)) { | ||||
| 			outputConsumer.addNonClassFiles(input); | ||||
| 			remapper.readClassPath(classpath); | ||||
| 			remapper.readInputs(modJarPath); | ||||
| 			remapper.readInputs(input); | ||||
| 			remapper.apply(outputConsumer); | ||||
| 		} catch (Exception e) { | ||||
| 			throw new RuntimeException("Failed to remap JAR", e); | ||||
| 			throw new RuntimeException("Failed to remap " + input + " to " + output, e); | ||||
| 		} finally { | ||||
| 			remapper.finish(); | ||||
| 		} | ||||
| 
 | ||||
| 		if (!modJarOutput.exists()){ | ||||
| 			throw new RuntimeException("Failed to reobfuscate JAR"); | ||||
| 		if (!Files.exists(output)) { | ||||
| 			throw new RuntimeException("Failed to remap " + input + " to " + output + " - file missing!"); | ||||
| 		} | ||||
| 
 | ||||
| 		if (MixinRefmapHelper.addRefmapName(extension.getRefmapName(), extension.getMixinJsonVersion(), modJarOutput)) { | ||||
| 		if (MixinRefmapHelper.addRefmapName(extension.getRefmapName(), extension.getMixinJsonVersion(), output)) { | ||||
| 			project.getLogger().debug("Transformed mixin reference maps in output JAR!"); | ||||
| 		} | ||||
| 
 | ||||
| 		if (nest) { | ||||
| 			if (NestedJars.addNestedJars(project, modJarOutput)) { | ||||
| 		if (addNestedDependencies) { | ||||
| 			if (NestedJars.addNestedJars(project, output)) { | ||||
| 				project.getLogger().debug("Added nested jar paths to mod json"); | ||||
| 			} | ||||
| 		} | ||||
| 
 | ||||
| 		extension.addUnmappedMod(input); | ||||
| 
 | ||||
| 		/** | ||||
| 		 * | ||||
| 
 | ||||
| 		 try { | ||||
| 		 if (modJar.exists()) { | ||||
| 		 Files.move(modJar, modJarUnmappedCopy); | ||||
|  | @ -124,6 +127,16 @@ public class ModRemapper { | |||
| 		 } catch (IOException e) { | ||||
| 		 throw new RuntimeException(e); | ||||
| 		 } | ||||
| 		 */ | ||||
| 	} | ||||
| 
 | ||||
| 	//@formatter:off | ||||
| 	// the null-check in getInput() is done to allow reconfiguration by AbstractPlugin | ||||
| 	@InputFile public File getInput() { return input == null ? null : getProject().file(input); } | ||||
| 	@OutputFile public File getOutput() { return getProject().file(output); } | ||||
| 	@Input public boolean isAddNestedDependencies() { return addNestedDependencies; } | ||||
| 	public void setAddNestedDependencies(boolean value) { this.addNestedDependencies = value; } | ||||
| 	public void setInput(Object input) { this.input = input; } | ||||
| 	public void setOutput(Object output) { this.output = output; } | ||||
| 	//@formatter:on | ||||
| } | ||||
|  | @ -31,27 +31,22 @@ import org.gradle.api.tasks.TaskAction; | |||
| 
 | ||||
| import java.io.File; | ||||
| 
 | ||||
| public class RemapSourcesJar extends AbstractLoomTask { | ||||
| 	public File jar; | ||||
| 	public File destinationJar; | ||||
| 	public String direction = "intermediary"; | ||||
| 
 | ||||
| 	@Input | ||||
| 	public File getJar() { | ||||
| 		return jar; | ||||
| 	} | ||||
| 
 | ||||
| 	@OutputFile | ||||
| 	public File getDestinationJar() { | ||||
| 		if (destinationJar == null) { | ||||
| 			return jar; | ||||
| 		} | ||||
| 
 | ||||
| 		return destinationJar; | ||||
| 	} | ||||
| public class RemapSourcesJarTask extends AbstractLoomTask { | ||||
| 	private Object input; | ||||
| 	private Object output; | ||||
| 	private String direction = "intermediary"; | ||||
| 
 | ||||
| 	@TaskAction | ||||
| 	public void remap() throws Exception { | ||||
| 		SourceRemapper.remapSources(getProject(), getJar(), getDestinationJar(), direction.equals("named")); | ||||
| 		SourceRemapper.remapSources(getProject(), getInput(), getOutput(), direction.equals("named")); | ||||
| 	} | ||||
| 
 | ||||
| 	//@formatter:off | ||||
| 	@Input public File getInput() { return getProject().file(input); } | ||||
| 	@OutputFile public File getOutput() { return getProject().file(output == null ? input : output); } | ||||
| 	@Input public String getTargetNamespace() { return direction; } | ||||
| 	public void setInput(Object input) { this.input = input; } | ||||
| 	public void setOutput(Object output) { this.output = output; } | ||||
| 	public void setTargetNamespace(String value) { this.direction = value; } | ||||
| 	//@formatter:on | ||||
| } | ||||
|  | @ -39,6 +39,7 @@ import java.io.File; | |||
| import java.io.IOException; | ||||
| import java.io.InputStreamReader; | ||||
| import java.lang.reflect.Field; | ||||
| import java.nio.file.Path; | ||||
| import java.util.HashSet; | ||||
| import java.util.Map; | ||||
| import java.util.Set; | ||||
|  | @ -50,7 +51,9 @@ public final class MixinRefmapHelper { | |||
|     private MixinRefmapHelper() { | ||||
| 
 | ||||
|     } | ||||
|     public static boolean addRefmapName(String filename, String mixinVersion, File output) { | ||||
| 
 | ||||
|     public static boolean addRefmapName(String filename, String mixinVersion, Path outputPath) { | ||||
|         File output = outputPath.toFile(); | ||||
|         Set<String> mixinFilenames = findMixins(output, true); | ||||
| 
 | ||||
|         if (mixinFilenames.size() > 0) { | ||||
|  |  | |||
|  | @ -29,7 +29,7 @@ import com.google.gson.GsonBuilder; | |||
| import com.google.gson.JsonArray; | ||||
| import com.google.gson.JsonObject; | ||||
| import net.fabricmc.loom.LoomGradleExtension; | ||||
| import net.fabricmc.loom.task.RemapJar; | ||||
| import net.fabricmc.loom.task.RemapJarTask; | ||||
| import org.apache.commons.io.FileUtils; | ||||
| import org.gradle.api.Project; | ||||
| import org.gradle.api.Task; | ||||
|  | @ -37,6 +37,7 @@ import org.gradle.api.artifacts.Configuration; | |||
| import org.gradle.api.artifacts.Dependency; | ||||
| import org.gradle.api.artifacts.DependencySet; | ||||
| import org.gradle.api.artifacts.ProjectDependency; | ||||
| import org.gradle.api.tasks.bundling.AbstractArchiveTask; | ||||
| import org.zeroturnaround.zip.FileSource; | ||||
| import org.zeroturnaround.zip.ZipEntrySource; | ||||
| import org.zeroturnaround.zip.ZipUtil; | ||||
|  | @ -45,21 +46,21 @@ import org.zeroturnaround.zip.transform.ZipEntryTransformerEntry; | |||
| 
 | ||||
| import java.io.File; | ||||
| import java.io.IOException; | ||||
| import java.util.ArrayList; | ||||
| import java.util.List; | ||||
| import java.util.Locale; | ||||
| import java.util.Set; | ||||
| import java.nio.file.Path; | ||||
| import java.util.*; | ||||
| import java.util.zip.ZipEntry; | ||||
| 
 | ||||
| public class NestedJars { | ||||
| 
 | ||||
| 	private static final Gson GSON = new GsonBuilder().setPrettyPrinting().create(); | ||||
| 
 | ||||
| 	public static boolean addNestedJars(Project project, File modJar) { | ||||
| 	public static boolean addNestedJars(Project project, Path modJarPath) { | ||||
| 		if (getContainedJars(project).isEmpty()) { | ||||
| 			return false; | ||||
| 		} | ||||
| 
 | ||||
| 		File modJar = modJarPath.toFile(); | ||||
| 
 | ||||
| 		ZipUtil.addEntries(modJar, getContainedJars(project).stream().map(file -> new FileSource("META-INF/jars/" + file.getName(), file)).toArray(ZipEntrySource[]::new)); | ||||
| 
 | ||||
| 		return ZipUtil.transformEntries(modJar, single(new ZipEntryTransformerEntry("fabric.mod.json", new StringZipEntryTransformer() { | ||||
|  | @ -85,7 +86,6 @@ public class NestedJars { | |||
| 	} | ||||
| 
 | ||||
| 	private static List<File> getContainedJars(Project project) { | ||||
| 
 | ||||
| 		List<File> fileList = new ArrayList<>(); | ||||
| 
 | ||||
| 		Configuration configuration = project.getConfigurations().getByName(Constants.INCLUDE); | ||||
|  | @ -96,9 +96,14 @@ public class NestedJars { | |||
| 				Project dependencyProject = projectDependency.getDependencyProject(); | ||||
| 
 | ||||
| 				//TODO change this to allow just normal jar tasks, so a project can have a none loom sub project | ||||
| 				for (Task task : dependencyProject.getTasksByName("remapJar", false)) { | ||||
| 					if (task instanceof RemapJar) { | ||||
| 						fileList.add(((RemapJar) task).jar); | ||||
| 				Collection<Task> remapJarTasks = dependencyProject.getTasksByName("remapJar", false); | ||||
| 				Collection<Task> jarTasks = dependencyProject.getTasksByName("jar", false); | ||||
| 
 | ||||
| 				for (Task task : remapJarTasks.isEmpty() ? jarTasks : remapJarTasks) { | ||||
| 					if (task instanceof RemapJarTask) { | ||||
| 						fileList.add(((RemapJarTask) task).getOutput()); | ||||
| 					} else if (task instanceof AbstractArchiveTask) { | ||||
| 						fileList.add(((AbstractArchiveTask) task).getArchivePath()); | ||||
| 					} | ||||
| 				} | ||||
| 			} else { | ||||
|  | @ -117,8 +122,8 @@ public class NestedJars { | |||
| 	} | ||||
| 
 | ||||
| 	//Looks for any deps that require a sub project to be built first | ||||
| 	public static List<RemapJar> getRequiredTasks(Project project){ | ||||
| 		List<RemapJar> remapTasks = new ArrayList<>(); | ||||
| 	public static List<RemapJarTask> getRequiredTasks(Project project){ | ||||
| 		List<RemapJarTask> remapTasks = new ArrayList<>(); | ||||
| 
 | ||||
| 		Configuration configuration = project.getConfigurations().getByName(Constants.INCLUDE); | ||||
| 		DependencySet dependencies = configuration.getDependencies(); | ||||
|  | @ -127,8 +132,8 @@ public class NestedJars { | |||
| 				ProjectDependency projectDependency = (ProjectDependency) dependency; | ||||
| 				Project dependencyProject = projectDependency.getDependencyProject(); | ||||
| 				for (Task task : dependencyProject.getTasksByName("remapJar", false)) { | ||||
| 					if (task instanceof RemapJar) { | ||||
| 						remapTasks.add((RemapJar) task); | ||||
| 					if (task instanceof RemapJarTask) { | ||||
| 						remapTasks.add((RemapJarTask) task); | ||||
| 					} | ||||
| 				} | ||||
| 			} | ||||
|  |  | |||
|  | @ -83,9 +83,9 @@ public class SourceRemapper { | |||
| 				mercury.getClassPath().add(file.toPath()); | ||||
| 			} | ||||
| 		} | ||||
| 		for (File file : extension.getUnmappedMods()) { | ||||
| 			if (file.isFile()) { | ||||
| 				mercury.getClassPath().add(file.toPath()); | ||||
| 		for (Path file : extension.getUnmappedMods()) { | ||||
| 			if (Files.isRegularFile(file)) { | ||||
| 				mercury.getClassPath().add(file); | ||||
| 			} | ||||
| 		} | ||||
| 
 | ||||
|  |  | |||
		Loading…
	
		Reference in a new issue