Skip to content

Commit

Permalink
Cleanup and task descriptions (#13)
Browse files Browse the repository at this point in the history
  • Loading branch information
Matyrobbrt authored Jun 8, 2024
1 parent 37cff59 commit e2bcd03
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 33 deletions.
10 changes: 0 additions & 10 deletions src/main/java/net/neoforged/moddevgradle/dsl/Parchment.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,6 @@ public Parchment(Project project) {
getMappingsVersion().convention(
project.getProviders().gradleProperty("neoForge.parchment.mappingsVersion")
);
getAddRepository().convention(
PropertyUtils.getBooleanProperty(project, "neoForge.parchment.addRepository").orElse(true)
);
getEnabled().convention(getParchmentArtifact()
.map(s -> !s.isEmpty()).orElse(PropertyUtils.getBooleanProperty(project, "neoForge.parchment.enabled").orElse(false)));
}
Expand Down Expand Up @@ -69,13 +66,6 @@ public Parchment(Project project) {
@Optional
public abstract Property<String> getMappingsVersion();

/**
* If enabled (the default), the parchment repository will automatically be added to the project,
* if {@link #getEnabled()} is true.
*/
@Internal
public abstract Property<Boolean> getAddRepository();

/**
* Enables or disables the system. It is enabled by default if a {@link #getParchmentArtifact()} is specified.
*/
Expand Down
53 changes: 30 additions & 23 deletions src/main/java/net/neoforged/moddevgradle/internal/ModDevPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.gradle.api.file.Directory;
import org.gradle.api.plugins.ExtensionAware;
import org.gradle.api.plugins.JavaLibraryPlugin;
import org.gradle.api.plugins.JavaPlugin;
import org.gradle.api.plugins.JavaPluginExtension;
import org.gradle.api.provider.Provider;
import org.gradle.api.tasks.SourceSetContainer;
Expand Down Expand Up @@ -71,6 +72,7 @@ public class ModDevPlugin implements Plugin<Project> {
private static final String JAR_JAR_GROUP = "jarjar";

private static final String TASK_GROUP = "mod development";
private static final String INTERNAL_TASK_GROUP = "mod development/internal";

/**
* Name of the configuration in which we place our generated artifacts for use in the runtime classpath,
Expand Down Expand Up @@ -120,6 +122,8 @@ public void apply(Project project) {
});

var createManifest = tasks.register("createArtifactManifest", CreateArtifactManifestTask.class, task -> {
task.setGroup(INTERNAL_TASK_GROUP);
task.setDescription("Creates the NFRT manifest file, containing all dependencies needed to setup the MC artifacts and downloading them in the process.");
configureArtifactManifestTask(task, extension);
task.getManifestFile().set(modDevBuildDir.map(dir -> dir.file("nfrt_artifact_manifest.properties")));
});
Expand Down Expand Up @@ -151,7 +155,6 @@ public void apply(Project project) {

// Add a filtered parchment repository automatically if enabled
var parchment = extension.getParchment();
configureParchmentRepository(project, parchment);
var parchmentData = configurations.create("parchmentData", spec -> {
spec.setDescription("Data used to add parameter names and javadoc to Minecraft sources");
spec.setCanBeResolved(true);
Expand All @@ -164,6 +167,9 @@ public void apply(Project project) {

// it has to contain client-extra to be loaded by FML, and it must be added to the legacy CP
var createArtifacts = tasks.register("createMinecraftArtifacts", CreateMinecraftArtifactsTask.class, task -> {
task.setGroup(INTERNAL_TASK_GROUP);
task.setDescription("Creates the NeoForge and Minecraft artifacts by invoking NFRT.");

var nfrtSettings = extension.getNeoFormRuntime();
task.getVerbose().set(nfrtSettings.getVerbose());
task.getEnableCache().set(nfrtSettings.getEnableCache());
Expand All @@ -183,6 +189,8 @@ public void apply(Project project) {
});

var downloadAssets = tasks.register("downloadAssets", DownloadAssetsTask.class, task -> {
task.setGroup(TASK_GROUP);
task.setDescription("Downloads the Minecraft assets and asset index needed to run a Minecraft client or generate client-side resources.");
task.getNeoForgeArtifact().set(extension.getVersion().map(version -> "net.neoforged:neoforge:" + version));
task.getNeoFormRuntime().from(neoFormRuntimeConfig);
task.getArtifactManifestFile().set(createManifest.get().getManifestFile());
Expand Down Expand Up @@ -211,13 +219,13 @@ public void apply(Project project) {
});
});

configurations.named("compileOnly").configure(configuration -> {
configurations.named(JavaPlugin.COMPILE_ONLY_CONFIGURATION_NAME).configure(configuration -> {
configuration.withDependencies(dependencies -> {
dependencies.addLater(minecraftClassesArtifact.map(dependencyFactory::create));
dependencies.addLater(neoForgeModDevLibrariesDependency);
});
});
var runtimeClasspath = configurations.named("runtimeClasspath");
var runtimeClasspath = configurations.named(JavaPlugin.RUNTIME_CLASSPATH_CONFIGURATION_NAME);
runtimeClasspath.configure(files -> files.extendsFrom(localRuntime));

// Try to give people at least a fighting chance to run on the correct java version
Expand All @@ -233,6 +241,7 @@ public void apply(Project project) {
// Let's try to get the userdev JSON out of the universal jar
// I don't like having to use a configuration for this...
var userDevConfigOnly = project.getConfigurations().create("neoForgeConfigOnly", spec -> {
spec.setDescription("Resolves exclusively the NeoForge userdev JSON for configuring runs");
spec.setCanBeResolved(true);
spec.setCanBeConsumed(false);
spec.setTransitive(false);
Expand All @@ -245,6 +254,7 @@ public void apply(Project project) {
});

var neoForgeModDevModules = project.getConfigurations().create("neoForgeModuleOnly", spec -> {
spec.setDescription("Libraries that should be placed on the JVMs boot module path.");
spec.setCanBeResolved(true);
spec.setCanBeConsumed(false);
spec.shouldResolveConsistentlyWith(runtimeClasspath.get());
Expand All @@ -270,6 +280,7 @@ public void apply(Project project) {
var sourceSet = ExtensionUtils.getExtension(project, "sourceSets", SourceSetContainer.class).getByName("main");

var legacyClasspathConfiguration = configurations.create(InternalModelHelper.nameOfRun(run, "", "legacyClasspath"), spec -> {
spec.setDescription("Contains all dependencies of the " + run.getName() + " run that should not be considered boot classpath modules.");
spec.setCanBeResolved(true);
spec.setCanBeConsumed(false);
spec.shouldResolveConsistentlyWith(runtimeClasspath.get());
Expand All @@ -285,12 +296,17 @@ public void apply(Project project) {
});

var writeLcpTask = tasks.register(InternalModelHelper.nameOfRun(run, "write", "legacyClasspath"), WriteLegacyClasspath.class, writeLcp -> {
writeLcp.setGroup(INTERNAL_TASK_GROUP);
writeLcp.setDescription("Writes the legacyClasspath file for the " + run.getName() + " Minecraft run, containing all dependencies that shouldn't be considered boot modules.");
writeLcp.getLegacyClasspathFile().convention(modDevBuildDir.map(dir -> dir.file(InternalModelHelper.nameOfRun(run, "", "legacyClasspath") + ".txt")));
writeLcp.getEntries().from(legacyClasspathConfiguration);
writeLcp.getEntries().from(createArtifacts.get().getResourcesArtifact());
});

var prepareRunTask = tasks.register(InternalModelHelper.nameOfRun(run, "prepare", "run"), PrepareRun.class, task -> {
task.setGroup(INTERNAL_TASK_GROUP);
task.setDescription("Prepares all files needed to launch the " + run.getName() + " Minecraft run.");

task.getGameDirectory().set(run.getGameDirectory());
task.getVmArgsFile().set(RunUtils.getArgFile(modDevBuildDir, run, RunUtils.RunArgFile.VMARGS));
task.getProgramArgsFile().set(RunUtils.getArgFile(modDevBuildDir, run, RunUtils.RunArgFile.PROGRAMARGS));
Expand All @@ -314,6 +330,7 @@ public void apply(Project project) {

tasks.register(InternalModelHelper.nameOfRun(run, "run", ""), RunGameTask.class, task -> {
task.setGroup(TASK_GROUP);
task.setDescription("Runs the " + run.getName() + " Minecraft run configuration.");

// Launch with the Java version used in the project
var toolchainService = ExtensionUtils.findExtension(project, "javaToolchains", JavaToolchainService.class);
Expand Down Expand Up @@ -438,22 +455,6 @@ private void configureArtifactManifestTask(CreateArtifactManifestTask task, NeoF
}
}

private static void configureParchmentRepository(Project project, Parchment parchment) {
project.afterEvaluate(p -> {
if (!parchment.getEnabled().get() || !parchment.getAddRepository().get()) {
return;
}
MavenArtifactRepository repo = p.getRepositories().maven(m -> {
m.setName("Parchment Data");
m.setUrl(URI.create("https://maven.parchmentmc.org/"));
m.mavenContent(mavenContent -> mavenContent.includeGroup("org.parchmentmc.data"));
});
// Make sure it comes first due to its filtered group, that should speed up resolution
p.getRepositories().remove(repo);
p.getRepositories().addFirst(repo);
});
}

private static boolean shouldUseCombinedSourcesAndClassesArtifact() {
return true;
// return Boolean.getBoolean("idea.active");
Expand Down Expand Up @@ -514,7 +515,7 @@ private void setupTesting(Project project,
var dependencyFactory = project.getDependencyFactory();

// Weirdly enough, testCompileOnly extends from compileOnlyApi, and not compileOnly
configurations.named("testCompileOnly").configure(configuration -> {
configurations.named(JavaPlugin.TEST_COMPILE_ONLY_CONFIGURATION_NAME).configure(configuration -> {
configuration.withDependencies(dependencies -> {
dependencies.addLater(minecraftClassesArtifact.map(dependencyFactory::create));
dependencies.addLater(neoForgeModDevLibrariesDependency);
Expand All @@ -535,12 +536,13 @@ private void setupTesting(Project project,
});
});

configurations.named("testRuntimeClasspath", files -> {
configurations.named(JavaPlugin.TEST_RUNTIME_CLASSPATH_CONFIGURATION_NAME, files -> {
files.extendsFrom(configurations.getByName(CONFIGURATION_GENERATED_ARTIFACTS));
files.extendsFrom(testLocalRuntime);
});

var legacyClasspathConfiguration = configurations.create("neoForgeTestLibraries", spec -> {
spec.setDescription("Contains the legacy classpath of the test run");
spec.setCanBeResolved(true);
spec.setCanBeConsumed(false);
spec.attributes(attributes -> {
Expand All @@ -556,6 +558,8 @@ private void setupTesting(Project project,
var runArgsDir = modDevDir.map(dir -> dir.dir("junit"));

var writeLcpTask = tasks.register("writeNeoForgeTestClasspath", WriteLegacyClasspath.class, writeLcp -> {
writeLcp.setGroup(INTERNAL_TASK_GROUP);
writeLcp.setDescription("Writes the legacyClasspath file for the test run, containing all dependencies that shouldn't be considered boot modules.");
writeLcp.getLegacyClasspathFile().convention(runArgsDir.map(dir -> dir.file("legacyClasspath.txt")));
writeLcp.getEntries().from(legacyClasspathConfiguration);
writeLcp.getEntries().from(createArtifacts.get().getResourcesArtifact());
Expand All @@ -565,6 +569,8 @@ private void setupTesting(Project project,
var programArgsFile = runArgsDir.map(dir -> dir.file("programArgs.txt"));
var log4j2ConfigFile = runArgsDir.map(dir -> dir.file("log4j2.xml"));
var prepareTask = tasks.register("prepareNeoForgeTestFiles", PrepareTest.class, task -> {
task.setGroup(INTERNAL_TASK_GROUP);
task.setDescription("Prepares all files needed to run the JUnit test task.");
task.getGameDirectory().set(unitTest.getGameDirectory());
task.getVmArgsFile().set(vmArgsFile);
task.getProgramArgsFile().set(programArgsFile);
Expand All @@ -579,7 +585,7 @@ private void setupTesting(Project project,
// Ensure the test files are written on sync so that users who use IDE-only tests can run them
ideSyncTask.configure(task -> task.dependsOn(prepareTask));

var testTask = tasks.named("test", Test.class, task -> {
var testTask = tasks.named(JavaPlugin.TEST_TASK_NAME, Test.class, task -> {
task.dependsOn(prepareTask);

// The FML JUnit plugin uses this system property to read a
Expand Down Expand Up @@ -642,11 +648,12 @@ private static void setupJarJar(Project project) {

var jarJarTask = project.getTasks().register(sourceSet.getTaskName(null, "jarJar"), JarJar.class, jarJar -> {
jarJar.setGroup(JAR_JAR_GROUP);
jarJar.setDescription("Create a combined JAR of project and selected dependencies");
jarJar.setDescription("Create a combined JAR of project and selected dependencies.");

jarJar.configuration(configuration);
});

// The task might not exist, and #named(String) requires the task to exist
project.getTasks().withType(AbstractArchiveTask.class).named(name -> name.equals(sourceSet.getJarTaskName())).configureEach(task -> {
task.from(jarJarTask.get().getOutputDirectory());
task.dependsOn(jarJarTask);
Expand Down

0 comments on commit e2bcd03

Please sign in to comment.