mirror of
https://github.com/architectury/architectury-loom.git
synced 2026-03-28 04:07:01 -05:00
NestJarsAction improvements (#1438)
This commit is contained in:
@@ -353,7 +353,7 @@ public abstract class LoomGradleExtensionImpl extends LoomGradleExtensionApiImpl
|
|||||||
remapJarTask.getNestedJars().from(jars);
|
remapJarTask.getNestedJars().from(jars);
|
||||||
} else {
|
} else {
|
||||||
// For regular Jar tasks (non-remap mode), add a NestJarsAction with the FileCollection
|
// For regular Jar tasks (non-remap mode), add a NestJarsAction with the FileCollection
|
||||||
task.doLast(new NestJarsAction(jars));
|
NestJarsAction.addToTask(task, jars);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,14 +26,24 @@ package net.fabricmc.loom.task;
|
|||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.util.ArrayList;
|
import java.util.Set;
|
||||||
import java.util.List;
|
|
||||||
|
import javax.inject.Inject;
|
||||||
|
|
||||||
import org.gradle.api.Action;
|
import org.gradle.api.Action;
|
||||||
import org.gradle.api.Task;
|
import org.gradle.api.Task;
|
||||||
|
import org.gradle.api.file.ConfigurableFileCollection;
|
||||||
import org.gradle.api.file.FileCollection;
|
import org.gradle.api.file.FileCollection;
|
||||||
|
import org.gradle.api.file.RegularFileProperty;
|
||||||
|
import org.gradle.api.tasks.InputFiles;
|
||||||
import org.gradle.jvm.tasks.Jar;
|
import org.gradle.jvm.tasks.Jar;
|
||||||
|
import org.gradle.workers.WorkAction;
|
||||||
|
import org.gradle.workers.WorkParameters;
|
||||||
|
import org.gradle.workers.WorkQueue;
|
||||||
|
import org.gradle.workers.WorkerExecutor;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import net.fabricmc.loom.build.nesting.JarNester;
|
import net.fabricmc.loom.build.nesting.JarNester;
|
||||||
|
|
||||||
@@ -42,23 +52,50 @@ import net.fabricmc.loom.build.nesting.JarNester;
|
|||||||
* Uses a FileCollection to avoid capturing task references at configuration time.
|
* Uses a FileCollection to avoid capturing task references at configuration time.
|
||||||
* Do NOT turn me into a record!
|
* Do NOT turn me into a record!
|
||||||
*/
|
*/
|
||||||
public class NestJarsAction implements Action<Task>, Serializable {
|
public abstract class NestJarsAction implements Action<Task>, Serializable {
|
||||||
private final FileCollection jars;
|
@InputFiles
|
||||||
|
public abstract ConfigurableFileCollection getJars();
|
||||||
|
|
||||||
public NestJarsAction(FileCollection jars) {
|
@Inject
|
||||||
this.jars = jars;
|
protected abstract WorkerExecutor getWorkerExecutor();
|
||||||
|
|
||||||
|
public static void addToTask(Jar task, FileCollection jars) {
|
||||||
|
NestJarsAction nestJarsAction = task.getProject().getObjects().newInstance(NestJarsAction.class);
|
||||||
|
nestJarsAction.getJars().from(jars);
|
||||||
|
task.getInputs().files(nestJarsAction.getJars()); // I don't think @InputFiles works, so to be sure add the jars to the task input anyway.
|
||||||
|
task.doLast(nestJarsAction);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void execute(@NotNull Task t) {
|
public void execute(@NotNull Task t) {
|
||||||
final Jar jarTask = (Jar) t;
|
final Jar jarTask = (Jar) t;
|
||||||
final File jarFile = jarTask.getArchiveFile().get().getAsFile();
|
|
||||||
final List<File> allJars = new ArrayList<>(jars.getFiles());
|
|
||||||
|
|
||||||
// Nest all collected jars
|
final WorkQueue workQueue = getWorkerExecutor().noIsolation();
|
||||||
if (!allJars.isEmpty()) {
|
|
||||||
JarNester.nestJars(allJars, jarFile, jarTask.getLogger());
|
workQueue.submit(NestAction.class, p -> {
|
||||||
jarTask.getLogger().lifecycle("Nested {} jar(s) into {}", allJars.size(), jarFile.getName());
|
p.getArchiveFile().set(jarTask.getArchiveFile());
|
||||||
|
p.getJars().setFrom(getJars());
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public interface NestJarsParameters extends WorkParameters {
|
||||||
|
RegularFileProperty getArchiveFile();
|
||||||
|
ConfigurableFileCollection getJars();
|
||||||
|
}
|
||||||
|
|
||||||
|
public abstract static class NestAction implements WorkAction<NestJarsParameters> {
|
||||||
|
private static final Logger LOGGER = LoggerFactory.getLogger(NestJarsAction.class);
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void execute() {
|
||||||
|
final File jarFile = getParameters().getArchiveFile().get().getAsFile();
|
||||||
|
final Set<File> jars = getParameters().getJars().getFiles();
|
||||||
|
|
||||||
|
// Nest all collected jars
|
||||||
|
if (!jars.isEmpty()) {
|
||||||
|
JarNester.nestJars(jars, jarFile, LOGGER);
|
||||||
|
LOGGER.info("Nested {} jar(s) into {}", jars.size(), jarFile.getName());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -65,8 +65,8 @@ public class NonRemappedJarTaskConfiguration {
|
|||||||
project.getTasks().named(JavaPlugin.JAR_TASK_NAME, Jar.class).configure(task -> {
|
project.getTasks().named(JavaPlugin.JAR_TASK_NAME, Jar.class).configure(task -> {
|
||||||
task.dependsOn(processIncludeJarsTask);
|
task.dependsOn(processIncludeJarsTask);
|
||||||
|
|
||||||
task.doLast(new NestJarsAction(project.fileTree(processIncludeJarsTask.flatMap(NestableJarGenerationTask::getOutputDirectory))
|
NestJarsAction.addToTask(task, project.fileTree(processIncludeJarsTask.flatMap(NestableJarGenerationTask::getOutputDirectory))
|
||||||
.matching(pattern -> pattern.include("*.jar"))));
|
.matching(pattern -> pattern.include("*.jar")));
|
||||||
|
|
||||||
task.doLast(new ManifestModificationAction(
|
task.doLast(new ManifestModificationAction(
|
||||||
manifestServiceProvider,
|
manifestServiceProvider,
|
||||||
|
|||||||
Reference in New Issue
Block a user