Skip to content

Commit

Permalink
Test all conventions and fix bugs.
Browse files Browse the repository at this point in the history
  • Loading branch information
marchermans committed May 14, 2024
1 parent c2eca1e commit b90a6ac
Show file tree
Hide file tree
Showing 7 changed files with 1,217 additions and 17 deletions.
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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:
Expand All @@ -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
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,8 +204,14 @@ private void configureSourceSetConventions(Project project, Conventions conventi
project.getExtensions().getByType(SourceSetContainer.class).configureEach(sourceSet -> {
final NamedDomainObjectCollection<Configuration> sourceSetConfigurations = (NamedDomainObjectCollection<Configuration>) 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);
});
}

Expand All @@ -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<NamedDomainObjectContainer<RunType>>) runTypesContainer -> runTypesContainer.configureEach(runType -> {
final NamedDomainObjectContainer<RunType> runTypes = (NamedDomainObjectContainer<RunType>) project.getExtensions().getByName(RunsConstants.Extensions.RUN_TYPES);
//Force none lazy resolve here.
runTypes.whenObjectAdded(runType -> {
project.getExtensions().configure(RunsConstants.Extensions.RUNS, (Action<NamedDomainObjectContainer<Run>>) runContainer -> {
if (runContainer.getAsMap().containsKey(runType.getName()))
return;
Expand All @@ -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<NamedDomainObjectContainer<Run>>) 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()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
Original file line number Diff line number Diff line change
@@ -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", """
<option name=\"delegatedBuild\" value=\"false\" />
""")
it.build("""
java {
toolchain {
languageVersion = JavaLanguageVersion.of(21)
}
}
repositories {
mavenCentral()
}
afterEvaluate {
logger.lifecycle("IDEA Run with IDEA: \${project.idea.project.runs.runWithIdea.get()}")
}
""")
it.withToolchains()
})

when:
def run = project.run {
it.tasks(':dependencies')
}

then:
run.output.contains("IDEA Run with IDEA: false")
}

def "disabling ide conventions forces auto detection to be false"() {
given:
def project = create("disable_ide_disables_auto_detection", {
it.property('neogradle.subsystems.conventions.ide.enabled', 'false')
//Force NeoGradle to think build with IDEA is enabled.
it.file(".idea/gradle.xml", """
<option name=\"delegatedBuild\" value=\"false\" />
""")
it.build("""
java {
toolchain {
languageVersion = JavaLanguageVersion.of(21)
}
}
repositories {
mavenCentral()
}
afterEvaluate {
logger.lifecycle("IDEA Run with IDEA: \${project.idea.project.runs.runWithIdea.get()}")
}
""")
it.withToolchains()
})

when:
def run = project.run {
it.tasks(':dependencies')
}

then:
run.output.contains("IDEA Run with IDEA: false")
}

def "disabling idea ide conventions forces auto detection to be false"() {
given:
def project = create("disable_idea_ide_disables_auto_detection", {
it.property('neogradle.subsystems.conventions.ide.idea.enabled', 'false')
//Force NeoGradle to think build with IDEA is enabled.
it.file(".idea/gradle.xml", """
<option name=\"delegatedBuild\" value=\"false\" />
""")
it.build("""
java {
toolchain {
languageVersion = JavaLanguageVersion.of(21)
}
}
repositories {
mavenCentral()
}
afterEvaluate {
logger.lifecycle("IDEA Run with IDEA: \${project.idea.project.runs.runWithIdea.get()}")
}
""")
it.withToolchains()
})

when:
def run = project.run {
it.tasks(':dependencies')
}

then:
run.output.contains("IDEA Run with IDEA: false")
}

def "disabling compiler auto-detection conventions forces auto detection to be false"() {
given:
def project = create("disable_compiler_idea_ide_disables_auto_detection", {
it.property('neogradle.subsystems.conventions.ide.idea.compiler-detection', 'false')
//Force NeoGradle to think build with IDEA is enabled.
it.file(".idea/gradle.xml", """
<option name=\"delegatedBuild\" value=\"false\" />
""")
it.build("""
java {
toolchain {
languageVersion = JavaLanguageVersion.of(21)
}
}
repositories {
mavenCentral()
}
afterEvaluate {
logger.lifecycle("IDEA Run with IDEA: \${project.idea.project.runs.runWithIdea.get()}")
}
""")
it.withToolchains()
})

when:
def run = project.run {
it.tasks(':dependencies')
}

then:
run.output.contains("IDEA Run with IDEA: false")
}

def "enabling compiler auto-detection conventions detects idea compiler"() {
given:
def project = create("disable_compiler_idea_ide_disables_auto_detection", {
//Force NeoGradle to think build with IDEA is enabled.
it.file(".idea/gradle.xml", """
<option name=\"delegatedBuild\" value=\"false\" />
""")
it.build("""
java {
toolchain {
languageVersion = JavaLanguageVersion.of(21)
}
}
repositories {
mavenCentral()
}
afterEvaluate {
logger.lifecycle("IDEA Run with IDEA: \${project.idea.project.runs.runWithIdea.get()}")
}
""")
it.withToolchains()
})

when:
def run = project.run {
it.tasks(':dependencies')
}

then:
run.output.contains("IDEA Run with IDEA: true")
}

def "enabling compiler auto-detection conventions detects gradle compiler"() {
given:
def project = create("disable_compiler_idea_ide_disables_auto_detection", {
it.build("""
java {
toolchain {
languageVersion = JavaLanguageVersion.of(21)
}
}
repositories {
mavenCentral()
}
afterEvaluate {
logger.lifecycle("IDEA Run with IDEA: \${project.idea.project.runs.runWithIdea.get()}")
}
""")
it.withToolchains()
})

when:
def run = project.run {
it.tasks(':dependencies')
}

then:
run.output.contains("IDEA Run with IDEA: false")
}
}
Loading

0 comments on commit b90a6ac

Please sign in to comment.