Refactor RemapJarTask to extend from Jar
It may now be used in places that require AbstractArchiveTask such as Maven publicationsdev/0.11
parent
a12fd8e6eb
commit
9e690f489f
|
@ -31,7 +31,10 @@ import net.fabricmc.loom.providers.MinecraftProvider;
|
|||
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.Plugin;
|
||||
import org.gradle.api.Project;
|
||||
import org.gradle.api.Task;
|
||||
import org.gradle.api.UnknownTaskException;
|
||||
import org.gradle.api.artifacts.Configuration;
|
||||
import org.gradle.api.artifacts.Dependency;
|
||||
import org.gradle.api.artifacts.component.ModuleComponentIdentifier;
|
||||
|
@ -61,6 +64,10 @@ import java.util.function.Predicate;
|
|||
public class AbstractPlugin implements Plugin<Project> {
|
||||
protected Project project;
|
||||
|
||||
public static boolean isRootProject(Project project) {
|
||||
return project.getRootProject() == project;
|
||||
}
|
||||
|
||||
private void extendsFrom(String a, String b) {
|
||||
project.getConfigurations().getByName(a).extendsFrom(project.getConfigurations().getByName(b));
|
||||
}
|
||||
|
@ -302,15 +309,15 @@ public class AbstractPlugin implements Plugin<Project> {
|
|||
AbstractArchiveTask jarTask = (AbstractArchiveTask) project1.getTasks().getByName("jar");
|
||||
RemapJarTask remapJarTask = (RemapJarTask) project1.getTasks().findByName("remapJar");
|
||||
|
||||
if (remapJarTask.getInput() == null) {
|
||||
remapJarTask.setOutput(jarTask.getArchivePath());
|
||||
jarTask.setClassifier("dev");
|
||||
remapJarTask.setInput(jarTask.getArchivePath());
|
||||
assert remapJarTask != null;
|
||||
if (!remapJarTask.getInput().isPresent()) {
|
||||
remapJarTask.getArchiveClassifier().set("remapped");
|
||||
remapJarTask.getInput().set(jarTask.getArchiveFile());
|
||||
}
|
||||
|
||||
remapJarTask.setAddNestedDependencies(true);
|
||||
remapJarTask.getAddNestedDependencies().set(true);
|
||||
|
||||
remapJarTask.doLast(task -> project1.getArtifacts().add("archives", remapJarTask.getOutput()));
|
||||
remapJarTask.doLast(task -> project1.getArtifacts().add("archives", remapJarTask.getArchiveFile()));
|
||||
remapJarTask.dependsOn(project1.getTasks().getByName("jar"));
|
||||
project1.getTasks().getByName("build").dependsOn(remapJarTask);
|
||||
|
||||
|
@ -318,7 +325,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 RemapJarTask && ((RemapJarTask) task).isAddNestedDependencies()) {
|
||||
if (task instanceof RemapJarTask && ((RemapJarTask) task).getAddNestedDependencies().get()) {
|
||||
//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);
|
||||
}
|
||||
|
@ -394,8 +401,4 @@ public class AbstractPlugin implements Plugin<Project> {
|
|||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static boolean isRootProject(Project project){
|
||||
return project.getRootProject() == project;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -26,7 +26,6 @@ package net.fabricmc.loom.task;
|
|||
|
||||
import net.fabricmc.loom.LoomGradleExtension;
|
||||
import net.fabricmc.loom.providers.MappingsProvider;
|
||||
import net.fabricmc.loom.util.Constants;
|
||||
import net.fabricmc.loom.util.MixinRefmapHelper;
|
||||
import net.fabricmc.loom.util.NestedJars;
|
||||
import net.fabricmc.loom.util.TinyRemapperMappingsHelper;
|
||||
|
@ -34,29 +33,36 @@ import net.fabricmc.tinyremapper.OutputConsumerPath;
|
|||
import net.fabricmc.tinyremapper.TinyRemapper;
|
||||
import net.fabricmc.tinyremapper.TinyUtils;
|
||||
import org.gradle.api.Project;
|
||||
import org.gradle.api.file.RegularFileProperty;
|
||||
import org.gradle.api.provider.Property;
|
||||
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 org.gradle.jvm.tasks.Jar;
|
||||
|
||||
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.*;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.Set;
|
||||
|
||||
public class RemapJarTask extends AbstractLoomTask {
|
||||
private Object input;
|
||||
private Object output;
|
||||
private boolean addNestedDependencies;
|
||||
public class RemapJarTask extends Jar {
|
||||
private RegularFileProperty input;
|
||||
private Property<Boolean> addNestedDependencies;
|
||||
|
||||
public RemapJarTask() {
|
||||
super();
|
||||
input = getProject().getObjects().fileProperty();
|
||||
addNestedDependencies = getProject().getObjects().property(Boolean.class);
|
||||
}
|
||||
|
||||
@TaskAction
|
||||
public void doTask() throws Throwable {
|
||||
Project project = getProject();
|
||||
LoomGradleExtension extension = project.getExtensions().getByType(LoomGradleExtension.class);
|
||||
Path input = getInput().toPath();
|
||||
Path output = getOutput().toPath();
|
||||
Path input = this.getInput().getAsFile().get().toPath();
|
||||
Path output = this.getArchiveFile().get().getAsFile().toPath();
|
||||
|
||||
if (!Files.exists(input)) {
|
||||
throw new FileNotFoundException(input.toString());
|
||||
|
@ -67,9 +73,9 @@ public class RemapJarTask extends AbstractLoomTask {
|
|||
String fromM = "named";
|
||||
String toM = "intermediary";
|
||||
|
||||
Set<File> classpathFiles = new LinkedHashSet<>();
|
||||
//noinspection CollectionAddAllCanBeReplacedWithConstructor
|
||||
classpathFiles.addAll(project.getConfigurations().getByName("compileClasspath").getFiles());
|
||||
Set<File> classpathFiles = new LinkedHashSet<>(
|
||||
project.getConfigurations().getByName("compileClasspath").getFiles()
|
||||
);
|
||||
Path[] classpath = classpathFiles.stream().map(File::toPath).filter((p) -> !input.equals(p)).toArray(Path[]::new);
|
||||
|
||||
File mixinMapFile = mappingsProvider.MAPPINGS_MIXIN_EXPORT;
|
||||
|
@ -111,7 +117,7 @@ public class RemapJarTask extends AbstractLoomTask {
|
|||
project.getLogger().debug("Transformed mixin reference maps in output JAR!");
|
||||
}
|
||||
|
||||
if (addNestedDependencies) {
|
||||
if (getAddNestedDependencies().get()) {
|
||||
if (NestedJars.addNestedJars(project, output)) {
|
||||
project.getLogger().debug("Added nested jar paths to mod json");
|
||||
}
|
||||
|
@ -119,10 +125,7 @@ public class RemapJarTask extends AbstractLoomTask {
|
|||
|
||||
extension.addUnmappedMod(input);
|
||||
|
||||
/**
|
||||
*
|
||||
|
||||
try {
|
||||
/*try {
|
||||
if (modJar.exists()) {
|
||||
Files.move(modJar, modJarUnmappedCopy);
|
||||
extension.addUnmappedMod(modJarUnmappedCopy);
|
||||
|
@ -131,17 +134,16 @@ public class RemapJarTask extends AbstractLoomTask {
|
|||
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
|
||||
@InputFile
|
||||
public RegularFileProperty getInput() {
|
||||
return input;
|
||||
}
|
||||
|
||||
@Input
|
||||
public Property<Boolean> getAddNestedDependencies() {
|
||||
return addNestedDependencies;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -28,8 +28,10 @@ import com.google.gson.Gson;
|
|||
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.RemapJarTask;
|
||||
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.gradle.api.Project;
|
||||
import org.gradle.api.Task;
|
||||
|
@ -47,7 +49,11 @@ import org.zeroturnaround.zip.transform.ZipEntryTransformerEntry;
|
|||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Path;
|
||||
import java.util.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Set;
|
||||
import java.util.zip.ZipEntry;
|
||||
|
||||
public class NestedJars {
|
||||
|
@ -101,7 +107,7 @@ public class NestedJars {
|
|||
|
||||
for (Task task : remapJarTasks.isEmpty() ? jarTasks : remapJarTasks) {
|
||||
if (task instanceof RemapJarTask) {
|
||||
fileList.add(((RemapJarTask) task).getOutput());
|
||||
fileList.add(((RemapJarTask) task).getArchiveFile().get().getAsFile());
|
||||
} else if (task instanceof AbstractArchiveTask) {
|
||||
fileList.add(((AbstractArchiveTask) task).getArchivePath());
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue