Skip to content

Commit

Permalink
Fix convention configuration not properly having been updated to pare…
Browse files Browse the repository at this point in the history
…nt based resolution

Fix IDE Management not using parent based resolution for post sync task registration
Make run types have a run template which is applied when its type is selected.
Configure runs in runtime projects through the runtype template
Fix transformer utils not properly chaining multiple providers in an ifTrue chain
  • Loading branch information
marchermans committed Aug 31, 2024
1 parent 4f8be00 commit e1a8016
Show file tree
Hide file tree
Showing 7 changed files with 209 additions and 167 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,6 @@ public class ConventionConfigurator {

public static void configureConventions(Project project) {
final Conventions conventions = project.getExtensions().getByType(Subsystems.class).getConventions();
if (!conventions.getIsEnabled().get())
return;

configureRunConventions(project, conventions);
configureSourceSetConventions(project, conventions);
configureIDEConventions(project, conventions);
Expand Down Expand Up @@ -74,24 +71,15 @@ private static void configureRunConventions(Project project, Conventions convent

private static void configureIDEConventions(Project project, Conventions conventions) {
final IDE ideConventions = conventions.getIde();
if (!ideConventions.getIsEnabled().get())
return;

configureIDEAIDEConventions(project, ideConventions);
}

private static void configureIDEAIDEConventions(Project project, IDE ideConventions) {
final IDEA ideaConventions = ideConventions.getIdea();
if (!ideaConventions.getIsEnabled().get())
return;

//We need to configure the tasks to run during sync.
final IdeManagementExtension ideManagementExtension = project.getExtensions().getByType(IdeManagementExtension.class);
ideManagementExtension
.onIdea((innerProject, rootProject, idea, ideaExtension) -> {
if (!ideaConventions.getIsEnabled().get())
return;

if (ideaConventions.getShouldUsePostSyncTask().get())
return;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,7 @@ public void idea(Project project, Project rootProject, IdeaModel idea, ProjectSe
final Conventions conventions = project.getExtensions().getByType(Subsystems.class).getConventions();
final IDE ideConventions = conventions.getIde();
final IDEA ideaConventions = ideConventions.getIdea();
if (!ideaConventions.getShouldUsePostSyncTask().get() &&
ideaConventions.getIsEnabled().get())
if (!ideaConventions.getShouldUsePostSyncTask().get())
return;

//Register the task to run after the IDEA import is complete, via its custom extension.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -282,11 +282,22 @@ public RunTestScope getTestScope() {
@Override
public final void configure() {
potentiallyAddRunTypeByName();
potentiallyAddRunTemplateFromType();
configureRunSpecification();
configureFromSDKs();
configureFromRuns();
}

private void potentiallyAddRunTemplateFromType() {
List<RunType> runTypes = specifications.map(l -> l.stream().filter(RunType.class::isInstance).map(RunType.class::cast).toList()).get();

specifications.addAll(
runTypes.stream()
.map(RunType::getRunTemplate)
.filter(Objects::nonNull)
.toList());
}

private void configureFromRuns() {
Provider<List<Run>> runSpecifications = specifications.map(l -> l.stream().filter(Run.class::isInstance).map(Run.class::cast).toList());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import net.neoforged.gradle.dsl.common.runs.run.Run;
import net.neoforged.gradle.dsl.common.runs.type.RunType;
import net.neoforged.gradle.dsl.common.runs.type.RunTypeManager;
import org.apache.commons.lang3.StringUtils;
import org.gradle.api.NamedDomainObjectContainer;
import org.gradle.api.Project;

Expand All @@ -21,7 +22,13 @@ public class RunTypeManagerImpl extends DelegatingDomainObjectContainer<RunType>
private final List<Parser> parsers = new ArrayList<>();

private static NamedDomainObjectContainer<RunType> createAndRegisterContainer(Project project) {
final NamedDomainObjectContainer<RunType> container = project.container(RunType.class, name -> project.getObjects().newInstance(RunType.class, name));
final NamedDomainObjectContainer<RunType> container = project.container(RunType.class, name -> {
final Run template = project.getObjects().newInstance(RunImpl.class, project, "template" + StringUtils.capitalize(name));
final RunType type = project.getObjects().newInstance(RunType.class, name);
type.setRunTemplate(template);

return type;
});
project.getExtensions().add("runTypes", container);
return container;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,15 @@ import com.google.gson.*
import groovy.transform.CompileStatic
import net.minecraftforge.gdi.ConfigurableDSLElement
import net.minecraftforge.gdi.NamedDSLElement
import net.minecraftforge.gdi.annotations.DSLProperty
import net.neoforged.gradle.dsl.common.runs.RunSpecification
import net.neoforged.gradle.dsl.common.runs.run.Run
import org.gradle.api.Named
import org.gradle.api.model.ObjectFactory
import org.gradle.api.tasks.Internal
import org.gradle.api.tasks.Nested
import org.gradle.api.tasks.Optional
import org.jetbrains.annotations.Nullable

import javax.inject.Inject
import java.lang.reflect.Type
Expand All @@ -24,6 +30,8 @@ abstract class RunType implements ConfigurableDSLElement<RunType>, NamedDSLEleme

private final String name

private Run runTemplate;

@Inject
RunType(String name) {
this.name = name
Expand All @@ -45,6 +53,35 @@ abstract class RunType implements ConfigurableDSLElement<RunType>, NamedDSLEleme
return name
}

/**
* A run template provides an ability for common projects that define their own run to define a template
*
* @return The run template
*/
@Internal
@DSLProperty
Run getRunTemplate() {
return runTemplate
}

void setRunTemplate(Run runTemplate) {
this.runTemplate = runTemplate

if (this.runTemplate != null) {
runTemplate.getConfigureAutomatically().set(false)
runTemplate.getConfigureFromDependencies().set(false)
runTemplate.getConfigureFromTypeWithName().set(false)

runTemplate.configure(this);

runTemplate.isClient.set(isClient)
runTemplate.isServer.set(isServer)
runTemplate.isDataGenerator.set(isDataGenerator)
runTemplate.isGameTest.set(isGameTest)
runTemplate.isJUnit.set(isJUnit)
}
}

/**
* Copies this run type into a new instance.
*
Expand Down
Loading

0 comments on commit e1a8016

Please sign in to comment.