From b90a6acdd4b6e1e418bd56d5ce5a354b8941c28c Mon Sep 17 00:00:00 2001 From: Marc Hermans Date: Tue, 14 May 2024 13:57:09 +0200 Subject: [PATCH] Test all conventions and fix bugs. --- README.md | 9 +- .../gradle/common/CommonProjectPlugin.java | 27 +- .../subsystems/ConventionsExtension.java | 2 +- .../convention/IDEAIDEConventionTests.groovy | 216 +++++++ .../convention/RunConventionTests.groovy | 442 +++++++++++++++ .../SourceSetConventionTests.groovy | 529 ++++++++++++++++++ .../extension/UserDevRuntimeExtension.java | 9 +- 7 files changed, 1217 insertions(+), 17 deletions(-) create mode 100644 userdev/src/functionalTest/groovy/net/neoforged/gradle/userdev/convention/IDEAIDEConventionTests.groovy create mode 100644 userdev/src/functionalTest/groovy/net/neoforged/gradle/userdev/convention/RunConventionTests.groovy create mode 100644 userdev/src/functionalTest/groovy/net/neoforged/gradle/userdev/convention/SourceSetConventionTests.groovy diff --git a/README.md b/README.md index 9362c9cdb..55db16ba6 100644 --- a/README.md +++ b/README.md @@ -248,9 +248,11 @@ Globally the following configurations are added: #### LocalRuntime (Per SourceSet) This configuration is used to add dependencies to your local projects runtime only, without exposing them to the runtime of other projects. +Requires source set conventions to be enabled #### LocalRunRuntime (Per SourceSet) This configuration is used to add dependencies to the local runtime of the runs you add the SourceSets too, without exposing them to the runtime of other runs. +Requires source set conventions to be enabled #### Run (Per Run) This configuration is used to add dependencies to the runtime of a specific run only, without exposing them to the runtime of other runs. @@ -267,14 +269,14 @@ This configuration is used to add dependencies (and their dependencies), straigh ### Sourceset Management To disable the sourceset management, you can set the following property in your gradle.properties: ```properties -neogradle.subsystems.conventions.sourceset.enabled=false +neogradle.subsystems.conventions.sourcesets.enabled=false ``` #### Automatic inclusion of the current project in its runs By default, the current project is automatically included in its runs. If you want to disable this, you can set the following property in your gradle.properties: ```properties -neogradle.subsystems.conventions.sourceset.automatic-inclusion=false +neogradle.subsystems.conventions.sourcesets.automatic-inclusion=false ``` This is equivalent to setting the following in your build.gradle: @@ -289,13 +291,12 @@ runs { By default, the local run runtime configuration of a sourceset is automatically included in the runs configuration of the run. If you want to disable this, you can set the following property in your gradle.properties: ```properties -neogradle.subsystems.conventions.sourceset.automatic-inclusion-local-run-runtime=false +neogradle.subsystems.conventions.sourcesets.automatic-inclusion-local-run-runtime=false ``` This is equivalent to setting the following in your build.gradle: ```groovy runs { configureEach { run -> - run.modSource sourceSets.main run.dependencies { runtime sourceSets.main.configurations.localRunRuntime } diff --git a/common/src/main/java/net/neoforged/gradle/common/CommonProjectPlugin.java b/common/src/main/java/net/neoforged/gradle/common/CommonProjectPlugin.java index 8b7f75ef8..0ca6f3c07 100644 --- a/common/src/main/java/net/neoforged/gradle/common/CommonProjectPlugin.java +++ b/common/src/main/java/net/neoforged/gradle/common/CommonProjectPlugin.java @@ -204,8 +204,14 @@ private void configureSourceSetConventions(Project project, Conventions conventi project.getExtensions().getByType(SourceSetContainer.class).configureEach(sourceSet -> { final NamedDomainObjectCollection sourceSetConfigurations = (NamedDomainObjectCollection) sourceSet.getExtensions().getByName("configurations"); - sourceSetConfigurations.add(project.getConfigurations().create(ConfigurationUtils.getSourceSetName(sourceSet, configurations.getLocalRuntimeConfigurationPostFix().get()))); - sourceSetConfigurations.add(project.getConfigurations().create(ConfigurationUtils.getSourceSetName(sourceSet, configurations.getRunRuntimeConfigurationPostFix().get()))); + final Configuration sourceSetLocalRuntimeConfiguration = project.getConfigurations().create(ConfigurationUtils.getSourceSetName(sourceSet, configurations.getLocalRuntimeConfigurationPostFix().get())); + sourceSetConfigurations.add(sourceSetLocalRuntimeConfiguration); + + final Configuration sourceSetRunRuntimeConfiguration = project.getConfigurations().create(ConfigurationUtils.getSourceSetName(sourceSet, configurations.getRunRuntimeConfigurationPostFix().get())); + sourceSetConfigurations.add(sourceSetRunRuntimeConfiguration); + + final Configuration sourceSetRuntimeClasspath = project.getConfigurations().maybeCreate(sourceSet.getRuntimeClasspathConfigurationName()); + sourceSetRuntimeClasspath.extendsFrom(sourceSetLocalRuntimeConfiguration); }); } @@ -228,14 +234,13 @@ private void configureRunConventions(Project project, Conventions conventions) { final Configurations configurations = conventions.getConfigurations(); final Runs runs = conventions.getRuns(); - if (!configurations.getIsEnabled().get()) + if (!runs.getIsEnabled().get()) return; - final Configuration runRuntimeConfiguration = project.getConfigurations().create(configurations.getRunRuntimeConfigurationName().get()); - final Configuration runModsConfiguration = project.getConfigurations().create(configurations.getRunModsConfigurationName().get()); - if (runs.getShouldDefaultRunsBeCreated().get()) { - project.getExtensions().configure(RunsConstants.Extensions.RUN_TYPES, (Action>) runTypesContainer -> runTypesContainer.configureEach(runType -> { + final NamedDomainObjectContainer runTypes = (NamedDomainObjectContainer) project.getExtensions().getByName(RunsConstants.Extensions.RUN_TYPES); + //Force none lazy resolve here. + runTypes.whenObjectAdded(runType -> { project.getExtensions().configure(RunsConstants.Extensions.RUNS, (Action>) runContainer -> { if (runContainer.getAsMap().containsKey(runType.getName())) return; @@ -244,9 +249,15 @@ private void configureRunConventions(Project project, Conventions conventions) { run.configure(runType); }); }); - })); + }); } + if (!configurations.getIsEnabled().get()) + return; + + final Configuration runRuntimeConfiguration = project.getConfigurations().create(configurations.getRunRuntimeConfigurationName().get()); + final Configuration runModsConfiguration = project.getConfigurations().create(configurations.getRunModsConfigurationName().get()); + project.getExtensions().configure(RunsConstants.Extensions.RUNS, (Action>) runContainer -> runContainer.configureEach(run -> { final Configuration runSpecificRuntimeConfiguration = project.getConfigurations().create(ConfigurationUtils.getRunName(run, configurations.getPerRunRuntimeConfigurationPostFix().get())); final Configuration runSpecificModsConfiguration = project.getConfigurations().create(ConfigurationUtils.getRunName(run, configurations.getPerRunModsConfigurationPostFix().get())); diff --git a/common/src/main/java/net/neoforged/gradle/common/extensions/subsystems/ConventionsExtension.java b/common/src/main/java/net/neoforged/gradle/common/extensions/subsystems/ConventionsExtension.java index 8d68cc23f..e98422ceb 100644 --- a/common/src/main/java/net/neoforged/gradle/common/extensions/subsystems/ConventionsExtension.java +++ b/common/src/main/java/net/neoforged/gradle/common/extensions/subsystems/ConventionsExtension.java @@ -69,7 +69,7 @@ public static abstract class SourceSetsExtension extends WithEnabledProperty imp @Inject public SourceSetsExtension(WithEnabledProperty parent) { - super(parent, "sourceSets"); + super(parent, "sourcesets"); getShouldMainSourceSetBeAutomaticallyAddedToRuns().convention(getBooleanProperty("automatic-inclusion").orElse(true)); getShouldSourceSetsLocalRunRuntimesBeAutomaticallyAddedToRuns().convention(getBooleanProperty("automatic-inclusion-local-run-runtime").orElse(true)); diff --git a/userdev/src/functionalTest/groovy/net/neoforged/gradle/userdev/convention/IDEAIDEConventionTests.groovy b/userdev/src/functionalTest/groovy/net/neoforged/gradle/userdev/convention/IDEAIDEConventionTests.groovy new file mode 100644 index 000000000..35ea12486 --- /dev/null +++ b/userdev/src/functionalTest/groovy/net/neoforged/gradle/userdev/convention/IDEAIDEConventionTests.groovy @@ -0,0 +1,216 @@ +package net.neoforged.gradle.userdev.convention + +import net.neoforged.trainingwheels.gradle.functional.BuilderBasedTestSpecification + +class IDEAIDEConventionTests extends BuilderBasedTestSpecification { + + @Override + protected void configurePluginUnderTest() { + pluginUnderTest = "net.neoforged.gradle.userdev"; + injectIntoAllProject = true; + } + + def "disabling conventions globally forces auto detection to be false"() { + given: + def project = create("disable_globally_disables_auto_detection", { + it.property('neogradle.subsystems.conventions.enabled', 'false') + //Force NeoGradle to think build with IDEA is enabled. + it.file(".idea/gradle.xml", """ +