Skip to content

Commit

Permalink
[Fix] Clean up several issue found during upgrading neodev (#241)
Browse files Browse the repository at this point in the history
  • Loading branch information
marchermans committed Sep 5, 2024
1 parent b32c6f0 commit 878a92a
Show file tree
Hide file tree
Showing 8 changed files with 218 additions and 175 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 @@ -39,6 +39,7 @@ public abstract class RunImpl implements ConfigurableDSLElement<Run>, Run {

private final Project project;
private final String name;
private final ListProperty<RunSpecification> rawSpecifications;
private final ListProperty<RunSpecification> specifications;
private final RunSourceSets modSources;
private final RunSourceSets unitTestSources;
Expand Down Expand Up @@ -68,7 +69,10 @@ public RunImpl(final Project project, final String name) {
this.environmentVariables = this.project.getObjects().mapProperty(String.class, String.class);
this.programArguments = this.project.getObjects().listProperty(String.class);
this.systemProperties = this.project.getObjects().mapProperty(String.class, String.class);

this.rawSpecifications = this.project.getObjects().listProperty(RunSpecification.class);
this.specifications = this.project.getObjects().listProperty(RunSpecification.class);
this.specifications.addAll(rawSpecifications);

getIsSingleInstance().convention(true);
getIsClient().convention(false);
Expand Down Expand Up @@ -265,13 +269,13 @@ public Provider<Set<FileSystemLocation>> getSdkClasspathElements() {
@Override
public void runType(@NotNull String name) {
getConfigureFromTypeWithName().set(false); // Don't re-configure
specifications.addAll(getRunTypesByName(name));
rawSpecifications.addAll(getRunTypesByName(name));
}

@Override
public void run(@NotNull String name) {
getConfigureFromTypeWithName().set(false); // Don't re-configure
specifications.addAll(getRunByName(name));
rawSpecifications.addAll(getRunByName(name));
}

@Override
Expand All @@ -282,11 +286,21 @@ public RunTestScope getTestScope() {
@Override
public final void configure() {
potentiallyAddRunTypeByName();
potentiallyAddRunTemplateFromType();
configureRunSpecification();
configureFromSDKs();
configureFromRuns();
}

private void potentiallyAddRunTemplateFromType() {
specifications.addAll(
rawSpecifications.map(l -> l.stream().filter(RunType.class::isInstance).map(RunType.class::cast)
.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 Expand Up @@ -497,7 +511,7 @@ private void configureFromSDKs() {

private void potentiallyAddRunTypeByName() {
if (getConfigureFromTypeWithName().get()) {
specifications.addAll(getRunTypesByName(name));
rawSpecifications.addAll(getRunTypesByName(name));
}
}

Expand Down Expand Up @@ -581,19 +595,19 @@ public final void configure(final @NotNull String name) {
);

getConfigureFromTypeWithName().set(false); // Don't re-configure
specifications.addAll(getRunTypesByName(name));
rawSpecifications.addAll(getRunTypesByName(name));
}

@Override
public final void configure(final @NotNull RunSpecification runType) {
getConfigureFromTypeWithName().set(false); // Don't re-configure
this.specifications.add(project.provider(() -> runType));
this.rawSpecifications.add(project.provider(() -> runType));
}

@Override
public void configure(@NotNull Provider<? extends RunSpecification> typeProvider) {
getConfigureFromTypeWithName().set(false); // Don't re-configure
this.specifications.add(typeProvider);
this.rawSpecifications.add(typeProvider);
}

@NotNull
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 878a92a

Please sign in to comment.