migrate RemapJarTask and RemapSourcesJarTask over to getters/setters for fields; make RemapJarTask use input and output locations instead of in-place renaming fluff

dev/0.11
asie 2019-05-11 00:53:50 +02:00
parent 1c56fb2eda
commit 788df9cfc7
11 changed files with 135 additions and 169 deletions

View File

@ -11,7 +11,7 @@ targetCompatibility = 1.8
group = 'net.fabricmc' group = 'net.fabricmc'
archivesBaseName = project.name archivesBaseName = project.name
version = '0.2.2-SNAPSHOT' version = '0.2.3-SNAPSHOT'
def build = "local" def build = "local"
def ENV = System.getenv() def ENV = System.getenv()
@ -30,19 +30,28 @@ repositories {
dependencies { dependencies {
implementation gradleApi() implementation gradleApi()
// libraries
implementation ('commons-io:commons-io:2.6') implementation ('commons-io:commons-io:2.6')
implementation ('org.zeroturnaround:zt-zip:1.13') implementation ('org.zeroturnaround:zt-zip:1.13')
implementation ('com.google.code.gson:gson:2.8.5') implementation ('com.google.code.gson:gson:2.8.5')
implementation ('com.google.guava:guava:27.1-jre') implementation ('com.google.guava:guava:27.1-jre')
// game handling utils
implementation ('net.fabricmc:stitch:0.1.2.50') { implementation ('net.fabricmc:stitch:0.1.2.50') {
exclude module: 'enigma' exclude module: 'enigma'
} }
// tinyfile management
implementation ('net.fabricmc:tiny-remapper:0.1.0.33') { implementation ('net.fabricmc:tiny-remapper:0.1.0.33') {
transitive = false transitive = false
} }
implementation ('org.jetbrains:intellij-fernflower:1.0.0.8')
implementation ('net.fabricmc:fabric-mixin-compile-extensions:0.1.0.+') 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') implementation ('org.cadixdev:mercury:0.1.0.fabric-SNAPSHOT')
} }

View File

@ -28,18 +28,15 @@ import com.google.common.collect.ImmutableMap;
import groovy.util.Node; import groovy.util.Node;
import net.fabricmc.loom.providers.MappingsProvider; import net.fabricmc.loom.providers.MappingsProvider;
import net.fabricmc.loom.providers.MinecraftProvider; import net.fabricmc.loom.providers.MinecraftProvider;
import net.fabricmc.loom.task.RemapJar; import net.fabricmc.loom.task.RemapJarTask;
import net.fabricmc.loom.task.RemapSourcesJar; import net.fabricmc.loom.task.RemapSourcesJarTask;
import net.fabricmc.loom.util.*; import net.fabricmc.loom.util.*;
import org.gradle.api.*; import org.gradle.api.*;
import org.gradle.api.artifacts.Configuration; import org.gradle.api.artifacts.Configuration;
import org.gradle.api.artifacts.Dependency; import org.gradle.api.artifacts.Dependency;
import org.gradle.api.artifacts.component.ModuleComponentIdentifier; 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.repositories.MavenArtifactRepository;
import org.gradle.api.artifacts.result.DependencyResult; 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.artifacts.result.ResolvedDependencyResult;
import org.gradle.api.plugins.JavaPlugin; import org.gradle.api.plugins.JavaPlugin;
import org.gradle.api.plugins.JavaPluginConvention; import org.gradle.api.plugins.JavaPluginConvention;
@ -286,10 +283,15 @@ public class AbstractPlugin implements Plugin<Project> {
// Enables the default mod remapper // Enables the default mod remapper
if (extension.remapMod) { if (extension.remapMod) {
AbstractArchiveTask jarTask = (AbstractArchiveTask) project1.getTasks().getByName("jar"); AbstractArchiveTask jarTask = (AbstractArchiveTask) project1.getTasks().getByName("jar");
RemapJarTask remapJarTask = (RemapJarTask) project1.getTasks().findByName("remapJar");
RemapJar remapJarTask = (RemapJar) project1.getTasks().findByName("remapJar"); if (remapJarTask.getInput() == null) {
if (remapJarTask.jar==null) remapJarTask.jar = jarTask.getArchivePath(); remapJarTask.setOutput(jarTask.getArchivePath());
remapJarTask.doLast(task -> project1.getArtifacts().add("archives", remapJarTask.jar)); jarTask.setClassifier("dev");
remapJarTask.setInput(jarTask.getArchivePath());
}
remapJarTask.doLast(task -> project1.getArtifacts().add("archives", remapJarTask.getOutput()));
remapJarTask.dependsOn(project1.getTasks().getByName("jar")); remapJarTask.dependsOn(project1.getTasks().getByName("jar"));
project1.getTasks().getByName("build").dependsOn(remapJarTask); 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()) { for (Map.Entry<Project, Set<Task>> entry : taskMap.entrySet()) {
Set<Task> taskSet = entry.getValue(); Set<Task> taskSet = entry.getValue();
for (Task task : taskSet) { 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 //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); NestedJars.getRequiredTasks(project1).forEach(task::dependsOn);
} }
@ -307,9 +309,10 @@ public class AbstractPlugin implements Plugin<Project> {
try { try {
AbstractArchiveTask sourcesTask = (AbstractArchiveTask) project1.getTasks().getByName("sourcesJar"); AbstractArchiveTask sourcesTask = (AbstractArchiveTask) project1.getTasks().getByName("sourcesJar");
RemapSourcesJar remapSourcesJarTask = (RemapSourcesJar) project1.getTasks().findByName("remapSourcesJar"); RemapSourcesJarTask remapSourcesJarTask = (RemapSourcesJarTask) project1.getTasks().findByName("remapSourcesJar");
remapSourcesJarTask.jar = sourcesTask.getArchivePath(); remapSourcesJarTask.setInput(sourcesTask.getArchivePath());
remapSourcesJarTask.doLast(task -> project1.getArtifacts().add("archives", remapSourcesJarTask.jar)); remapSourcesJarTask.setOutput(sourcesTask.getArchivePath());
remapSourcesJarTask.doLast(task -> project1.getArtifacts().add("archives", remapSourcesJarTask.getOutput()));
remapSourcesJarTask.dependsOn(project1.getTasks().getByName("sourcesJar")); remapSourcesJarTask.dependsOn(project1.getTasks().getByName("sourcesJar"));
project1.getTasks().getByName("build").dependsOn(remapSourcesJarTask); project1.getTasks().getByName("build").dependsOn(remapSourcesJarTask);
} catch (UnknownTaskException e) { } catch (UnknownTaskException e) {
@ -317,7 +320,7 @@ public class AbstractPlugin implements Plugin<Project> {
} }
} else { } else {
AbstractArchiveTask jarTask = (AbstractArchiveTask) project1.getTasks().getByName("jar"); AbstractArchiveTask jarTask = (AbstractArchiveTask) project1.getTasks().getByName("jar");
extension.addUnmappedMod(jarTask.getArchivePath()); extension.addUnmappedMod(jarTask.getArchivePath().toPath());
} }
}); });
} }

View File

@ -40,6 +40,7 @@ import org.gradle.api.artifacts.result.ResolvedArtifactResult;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import java.io.File; import java.io.File;
import java.nio.file.Path;
import java.util.*; import java.util.*;
import java.util.function.BiPredicate; import java.util.function.BiPredicate;
import java.util.function.Function; import java.util.function.Function;
@ -54,7 +55,7 @@ public class LoomGradleExtension {
public boolean autoGenIDERuns = true; public boolean autoGenIDERuns = true;
public boolean extractJars = false; public boolean extractJars = false;
private List<File> unmappedModsBuilt = new ArrayList<>(); private List<Path> unmappedModsBuilt = new ArrayList<>();
//Not to be set in the build.gradle //Not to be set in the build.gradle
private Project project; private Project project;
@ -71,11 +72,11 @@ public class LoomGradleExtension {
this.project = project; this.project = project;
} }
public void addUnmappedMod(File file) { public void addUnmappedMod(Path file) {
unmappedModsBuilt.add(file); unmappedModsBuilt.add(file);
} }
public List<File> getUnmappedMods() { public List<Path> getUnmappedMods() {
return Collections.unmodifiableList(unmappedModsBuilt); return Collections.unmodifiableList(unmappedModsBuilt);
} }

View File

@ -64,7 +64,7 @@ public class LoomGradlePlugin extends AbstractPlugin {
t.getOutputs().upToDateWhen((o) -> false); t.getOutputs().upToDateWhen((o) -> false);
}); });
tasks.register("remapJar", RemapJar.class); tasks.register("remapJar", RemapJarTask.class);
tasks.register("genSourcesDecompile", FernFlowerTask.class, t -> { tasks.register("genSourcesDecompile", FernFlowerTask.class, t -> {
t.getOutputs().upToDateWhen((o) -> false); t.getOutputs().upToDateWhen((o) -> false);
@ -136,7 +136,7 @@ public class LoomGradlePlugin extends AbstractPlugin {
t.setGroup("ide"); t.setGroup("ide");
}); });
tasks.register("remapSourcesJar", RemapSourcesJar.class); tasks.register("remapSourcesJar", RemapSourcesJarTask.class);
tasks.register("runClient", RunClientTask.class, t -> { tasks.register("runClient", RunClientTask.class, t -> {
t.dependsOn("buildNeeded", "downloadAssets"); t.dependsOn("buildNeeded", "downloadAssets");

View File

@ -33,6 +33,8 @@ import org.gradle.api.Project;
import org.gradle.api.tasks.JavaExec; import org.gradle.api.tasks.JavaExec;
import java.io.File; import java.io.File;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
@ -63,9 +65,9 @@ public abstract class AbstractRunTask extends JavaExec {
for (File file : getProject().getConfigurations().getByName("compile").getFiles()) { for (File file : getProject().getConfigurations().getByName("compile").getFiles()) {
libs.add(file.getAbsolutePath()); libs.add(file.getAbsolutePath());
} }
for (File file : extension.getUnmappedMods()) { for (Path file : extension.getUnmappedMods()) {
if (file.isFile()) { if (Files.isRegularFile(file)) {
libs.add(file.getAbsolutePath()); libs.add(file.toFile().getAbsolutePath());
} }
} }

View File

@ -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);
}
}

View File

@ -22,58 +22,56 @@
* SOFTWARE. * 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.LoomGradleExtension;
import net.fabricmc.loom.providers.MappingsProvider; 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.OutputConsumerPath;
import net.fabricmc.tinyremapper.TinyRemapper; import net.fabricmc.tinyremapper.TinyRemapper;
import net.fabricmc.tinyremapper.TinyUtils; import net.fabricmc.tinyremapper.TinyUtils;
import org.gradle.api.Project; 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.File;
import java.io.FileNotFoundException;
import java.io.IOException; import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path; import java.nio.file.Path;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Iterator;
import java.util.List; 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 { @TaskAction
Project project = task.getProject(); public void doTask() throws Throwable {
Project project = getProject();
LoomGradleExtension extension = project.getExtensions().getByType(LoomGradleExtension.class); LoomGradleExtension extension = project.getExtensions().getByType(LoomGradleExtension.class);
Path input = getInput().toPath();
Path output = getOutput().toPath();
File modJar = task.getJar(); if (!Files.exists(input)) {
throw new FileNotFoundException(input.toString());
if (!modJar.exists()) {
project.getLogger().error("Source .JAR not found!");
return;
} }
MappingsProvider mappingsProvider = extension.getMappingsProvider(); MappingsProvider mappingsProvider = extension.getMappingsProvider();
Path mappings = mappingsProvider.MAPPINGS_TINY.toPath();
String fromM = "named"; String fromM = "named";
String toM = "intermediary"; String toM = "intermediary";
List<File> classpathFiles = new ArrayList<>(); List<File> classpathFiles = new ArrayList<>();
classpathFiles.addAll(project.getConfigurations().getByName(Constants.COMPILE_MODS_MAPPED).getFiles()); classpathFiles.addAll(project.getConfigurations().getByName(Constants.COMPILE_MODS_MAPPED).getFiles());
classpathFiles.addAll(project.getConfigurations().getByName(Constants.MINECRAFT_NAMED).getFiles()); classpathFiles.addAll(project.getConfigurations().getByName(Constants.MINECRAFT_NAMED).getFiles());
final Path modJarPath = modJar.toPath(); Path[] classpath = classpathFiles.stream().map(File::toPath).filter((p) -> !input.equals(p)).toArray(Path[]::new);
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();
}
File mixinMapFile = mappingsProvider.MAPPINGS_MIXIN_EXPORT; File mixinMapFile = mappingsProvider.MAPPINGS_MIXIN_EXPORT;
Path mixinMapPath = mixinMapFile.toPath(); Path mixinMapPath = mixinMapFile.toPath();
@ -85,45 +83,60 @@ public class ModRemapper {
remapperBuilder = remapperBuilder.withMappings(TinyUtils.createTinyMappingProvider(mixinMapPath, fromM, toM)); remapperBuilder = remapperBuilder.withMappings(TinyUtils.createTinyMappingProvider(mixinMapPath, fromM, toM));
} }
project.getLogger().lifecycle("Remapping " + modJar.getName()); project.getLogger().lifecycle(":remapping " + input.getFileName());
TinyRemapper remapper = remapperBuilder.build(); TinyRemapper remapper = remapperBuilder.build();
try (OutputConsumerPath outputConsumer = new OutputConsumerPath(modJarOutputPath)) { try (OutputConsumerPath outputConsumer = new OutputConsumerPath(output)) {
outputConsumer.addNonClassFiles(modJarPath); outputConsumer.addNonClassFiles(input);
remapper.readClassPath(classpath); remapper.readClassPath(classpath);
remapper.readInputs(modJarPath); remapper.readInputs(input);
remapper.apply(outputConsumer); remapper.apply(outputConsumer);
} catch (Exception e) { } catch (Exception e) {
throw new RuntimeException("Failed to remap JAR", e); throw new RuntimeException("Failed to remap " + input + " to " + output, e);
} finally { } finally {
remapper.finish(); remapper.finish();
} }
if (!modJarOutput.exists()){ if (!Files.exists(output)) {
throw new RuntimeException("Failed to reobfuscate JAR"); 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!"); project.getLogger().debug("Transformed mixin reference maps in output JAR!");
} }
if (nest) { if (addNestedDependencies) {
if (NestedJars.addNestedJars(project, modJarOutput)) { if (NestedJars.addNestedJars(project, output)) {
project.getLogger().debug("Added nested jar paths to mod json"); project.getLogger().debug("Added nested jar paths to mod json");
} }
} }
try { extension.addUnmappedMod(input);
if (modJar.exists()) {
Files.move(modJar, modJarUnmappedCopy);
extension.addUnmappedMod(modJarUnmappedCopy);
}
Files.move(modJarOutput, modJar); /**
} catch (IOException e) { *
throw new RuntimeException(e);
} try {
if (modJar.exists()) {
Files.move(modJar, modJarUnmappedCopy);
extension.addUnmappedMod(modJarUnmappedCopy);
}
Files.move(modJarOutput, modJar);
} 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
} }

View File

@ -31,27 +31,22 @@ import org.gradle.api.tasks.TaskAction;
import java.io.File; import java.io.File;
public class RemapSourcesJar extends AbstractLoomTask { public class RemapSourcesJarTask extends AbstractLoomTask {
public File jar; private Object input;
public File destinationJar; private Object output;
public String direction = "intermediary"; private String direction = "intermediary";
@Input
public File getJar() {
return jar;
}
@OutputFile
public File getDestinationJar() {
if (destinationJar == null) {
return jar;
}
return destinationJar;
}
@TaskAction @TaskAction
public void remap() throws Exception { 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
} }

View File

@ -39,6 +39,7 @@ import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.nio.file.Path;
import java.util.HashSet; import java.util.HashSet;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
@ -50,7 +51,9 @@ public final class MixinRefmapHelper {
private 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); Set<String> mixinFilenames = findMixins(output, true);
if (mixinFilenames.size() > 0) { if (mixinFilenames.size() > 0) {

View File

@ -29,7 +29,7 @@ import com.google.gson.GsonBuilder;
import com.google.gson.JsonArray; import com.google.gson.JsonArray;
import com.google.gson.JsonObject; import com.google.gson.JsonObject;
import net.fabricmc.loom.LoomGradleExtension; 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.apache.commons.io.FileUtils;
import org.gradle.api.Project; import org.gradle.api.Project;
import org.gradle.api.Task; 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.Dependency;
import org.gradle.api.artifacts.DependencySet; import org.gradle.api.artifacts.DependencySet;
import org.gradle.api.artifacts.ProjectDependency; import org.gradle.api.artifacts.ProjectDependency;
import org.gradle.api.tasks.bundling.AbstractArchiveTask;
import org.zeroturnaround.zip.FileSource; import org.zeroturnaround.zip.FileSource;
import org.zeroturnaround.zip.ZipEntrySource; import org.zeroturnaround.zip.ZipEntrySource;
import org.zeroturnaround.zip.ZipUtil; import org.zeroturnaround.zip.ZipUtil;
@ -45,21 +46,21 @@ import org.zeroturnaround.zip.transform.ZipEntryTransformerEntry;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.nio.file.Path;
import java.util.List; import java.util.*;
import java.util.Locale;
import java.util.Set;
import java.util.zip.ZipEntry; import java.util.zip.ZipEntry;
public class NestedJars { public class NestedJars {
private static final Gson GSON = new GsonBuilder().setPrettyPrinting().create(); 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()) { if (getContainedJars(project).isEmpty()) {
return false; 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)); 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() { 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) { private static List<File> getContainedJars(Project project) {
List<File> fileList = new ArrayList<>(); List<File> fileList = new ArrayList<>();
Configuration configuration = project.getConfigurations().getByName(Constants.INCLUDE); Configuration configuration = project.getConfigurations().getByName(Constants.INCLUDE);
@ -96,9 +96,14 @@ public class NestedJars {
Project dependencyProject = projectDependency.getDependencyProject(); Project dependencyProject = projectDependency.getDependencyProject();
//TODO change this to allow just normal jar tasks, so a project can have a none loom sub project //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)) { Collection<Task> remapJarTasks = dependencyProject.getTasksByName("remapJar", false);
if (task instanceof RemapJar) { Collection<Task> jarTasks = dependencyProject.getTasksByName("jar", false);
fileList.add(((RemapJar) task).jar);
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 { } else {
@ -117,8 +122,8 @@ public class NestedJars {
} }
//Looks for any deps that require a sub project to be built first //Looks for any deps that require a sub project to be built first
public static List<RemapJar> getRequiredTasks(Project project){ public static List<RemapJarTask> getRequiredTasks(Project project){
List<RemapJar> remapTasks = new ArrayList<>(); List<RemapJarTask> remapTasks = new ArrayList<>();
Configuration configuration = project.getConfigurations().getByName(Constants.INCLUDE); Configuration configuration = project.getConfigurations().getByName(Constants.INCLUDE);
DependencySet dependencies = configuration.getDependencies(); DependencySet dependencies = configuration.getDependencies();
@ -127,8 +132,8 @@ public class NestedJars {
ProjectDependency projectDependency = (ProjectDependency) dependency; ProjectDependency projectDependency = (ProjectDependency) dependency;
Project dependencyProject = projectDependency.getDependencyProject(); Project dependencyProject = projectDependency.getDependencyProject();
for (Task task : dependencyProject.getTasksByName("remapJar", false)) { for (Task task : dependencyProject.getTasksByName("remapJar", false)) {
if (task instanceof RemapJar) { if (task instanceof RemapJarTask) {
remapTasks.add((RemapJar) task); remapTasks.add((RemapJarTask) task);
} }
} }
} }

View File

@ -83,9 +83,9 @@ public class SourceRemapper {
mercury.getClassPath().add(file.toPath()); mercury.getClassPath().add(file.toPath());
} }
} }
for (File file : extension.getUnmappedMods()) { for (Path file : extension.getUnmappedMods()) {
if (file.isFile()) { if (Files.isRegularFile(file)) {
mercury.getClassPath().add(file.toPath()); mercury.getClassPath().add(file);
} }
} }