From 878a92a90bf4d5d6da7deef01b3e4a9cd734d6c1 Mon Sep 17 00:00:00 2001 From: Marc Hermans Date: Thu, 5 Sep 2024 19:55:13 +0200 Subject: [PATCH] [Fix] Clean up several issue found during upgrading neodev (#241) --- .../conventions/ConventionConfigurator.java | 12 - .../extensions/IdeManagementExtension.java | 3 +- .../gradle/common/runs/run/RunImpl.java | 26 +- .../common/runs/run/RunTypeManagerImpl.java | 9 +- .../dsl/common/runs/type/RunType.groovy | 37 +++ .../extensions/DynamicProjectExtension.java | 302 +++++++++--------- .../neoforged/gradle/userdev/RunTests.groovy | 2 - .../gradle/util/TransformerUtils.java | 2 +- 8 files changed, 218 insertions(+), 175 deletions(-) diff --git a/common/src/main/java/net/neoforged/gradle/common/conventions/ConventionConfigurator.java b/common/src/main/java/net/neoforged/gradle/common/conventions/ConventionConfigurator.java index 1e8c6e92..99620861 100644 --- a/common/src/main/java/net/neoforged/gradle/common/conventions/ConventionConfigurator.java +++ b/common/src/main/java/net/neoforged/gradle/common/conventions/ConventionConfigurator.java @@ -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); @@ -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; diff --git a/common/src/main/java/net/neoforged/gradle/common/extensions/IdeManagementExtension.java b/common/src/main/java/net/neoforged/gradle/common/extensions/IdeManagementExtension.java index 8abfbe09..04edda60 100644 --- a/common/src/main/java/net/neoforged/gradle/common/extensions/IdeManagementExtension.java +++ b/common/src/main/java/net/neoforged/gradle/common/extensions/IdeManagementExtension.java @@ -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. diff --git a/common/src/main/java/net/neoforged/gradle/common/runs/run/RunImpl.java b/common/src/main/java/net/neoforged/gradle/common/runs/run/RunImpl.java index ca91afff..0363637c 100644 --- a/common/src/main/java/net/neoforged/gradle/common/runs/run/RunImpl.java +++ b/common/src/main/java/net/neoforged/gradle/common/runs/run/RunImpl.java @@ -39,6 +39,7 @@ public abstract class RunImpl implements ConfigurableDSLElement, Run { private final Project project; private final String name; + private final ListProperty rawSpecifications; private final ListProperty specifications; private final RunSourceSets modSources; private final RunSourceSets unitTestSources; @@ -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); @@ -265,13 +269,13 @@ public Provider> 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 @@ -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> runSpecifications = specifications.map(l -> l.stream().filter(Run.class::isInstance).map(Run.class::cast).toList()); @@ -497,7 +511,7 @@ private void configureFromSDKs() { private void potentiallyAddRunTypeByName() { if (getConfigureFromTypeWithName().get()) { - specifications.addAll(getRunTypesByName(name)); + rawSpecifications.addAll(getRunTypesByName(name)); } } @@ -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 typeProvider) { getConfigureFromTypeWithName().set(false); // Don't re-configure - this.specifications.add(typeProvider); + this.rawSpecifications.add(typeProvider); } @NotNull diff --git a/common/src/main/java/net/neoforged/gradle/common/runs/run/RunTypeManagerImpl.java b/common/src/main/java/net/neoforged/gradle/common/runs/run/RunTypeManagerImpl.java index 1760fa32..fba7d20d 100644 --- a/common/src/main/java/net/neoforged/gradle/common/runs/run/RunTypeManagerImpl.java +++ b/common/src/main/java/net/neoforged/gradle/common/runs/run/RunTypeManagerImpl.java @@ -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; @@ -21,7 +22,13 @@ public class RunTypeManagerImpl extends DelegatingDomainObjectContainer private final List parsers = new ArrayList<>(); private static NamedDomainObjectContainer createAndRegisterContainer(Project project) { - final NamedDomainObjectContainer container = project.container(RunType.class, name -> project.getObjects().newInstance(RunType.class, name)); + final NamedDomainObjectContainer 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; } diff --git a/dsl/common/src/main/groovy/net/neoforged/gradle/dsl/common/runs/type/RunType.groovy b/dsl/common/src/main/groovy/net/neoforged/gradle/dsl/common/runs/type/RunType.groovy index 660558ff..49feae12 100644 --- a/dsl/common/src/main/groovy/net/neoforged/gradle/dsl/common/runs/type/RunType.groovy +++ b/dsl/common/src/main/groovy/net/neoforged/gradle/dsl/common/runs/type/RunType.groovy @@ -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 @@ -24,6 +30,8 @@ abstract class RunType implements ConfigurableDSLElement, NamedDSLEleme private final String name + private Run runTemplate; + @Inject RunType(String name) { this.name = name @@ -45,6 +53,35 @@ abstract class RunType implements ConfigurableDSLElement, 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. * diff --git a/platform/src/main/java/net/neoforged/gradle/platform/extensions/DynamicProjectExtension.java b/platform/src/main/java/net/neoforged/gradle/platform/extensions/DynamicProjectExtension.java index eb854865..62abe7cd 100644 --- a/platform/src/main/java/net/neoforged/gradle/platform/extensions/DynamicProjectExtension.java +++ b/platform/src/main/java/net/neoforged/gradle/platform/extensions/DynamicProjectExtension.java @@ -92,64 +92,64 @@ import static net.neoforged.gradle.dsl.common.util.Constants.DEFAULT_PARCHMENT_GROUP; public abstract class DynamicProjectExtension implements BaseDSLElement { - + private final Project project; - + @Nullable private DynamicProjectType type = null; - + @Inject public DynamicProjectExtension(Project project) { this.project = project; this.getIsUpdating().convention(getProviderFactory().gradleProperty("updating").map(Boolean::valueOf).orElse(false)); - + //All dynamic projects expose information from themselves as a library. Cause they are. project.getPlugins().apply("java-library"); } - + @ProjectGetter @Override public Project getProject() { return project; } - + public void clean() { clean("+"); } - + public void clean(final String minecraftVersion) { type = DynamicProjectType.CLEAN; - + project.getPlugins().apply(VanillaProjectPlugin.class); - + final JavaPluginExtension javaPluginExtension = getProject().getExtensions().getByType(JavaPluginExtension.class); final SourceSet mainSource = javaPluginExtension.getSourceSets().getByName("main"); - + final VanillaRuntimeExtension vanillaRuntimeExtension = project.getExtensions().getByType(VanillaRuntimeExtension.class); final VanillaRuntimeDefinition runtimeDefinition = vanillaRuntimeExtension.create(builder -> builder.withMinecraftVersion(minecraftVersion).withDistributionType(DistributionType.CLIENT).withFartVersion(vanillaRuntimeExtension.getFartVersion()).withForgeFlowerVersion(vanillaRuntimeExtension.getVineFlowerVersion()).withAccessTransformerApplierVersion(vanillaRuntimeExtension.getAccessTransformerApplierVersion())); - + project.getTasks().named(mainSource.getCompileJavaTaskName()).configure(task -> task.setEnabled(false)); - + configureSetupTasks(runtimeDefinition.getSourceJarTask().flatMap(WithOutput::getOutput), mainSource, runtimeDefinition.getMinecraftDependenciesConfiguration()); } - + public void neoform() { //Accept any version of NeoForm. Aka the latest will always work. neoform("+"); } - + public void neoform(final String neoFormVersion) { type = DynamicProjectType.NEO_FORM; - + project.getPlugins().apply(NeoFormProjectPlugin.class); - + final JavaPluginExtension javaPluginExtension = getProject().getExtensions().getByType(JavaPluginExtension.class); final SourceSet mainSource = javaPluginExtension.getSourceSets().getByName("main"); - + final NeoFormRuntimeExtension neoFormRuntimeExtension = project.getExtensions().getByType(NeoFormRuntimeExtension.class); final NeoFormRuntimeDefinition runtimeDefinition = neoFormRuntimeExtension.create(builder -> { builder.withNeoFormVersion(neoFormVersion).withDistributionType(DistributionType.JOINED); - + NeoFormRuntimeUtils.configureDefaultRuntimeSpecBuilder(project, builder); }); @@ -175,19 +175,19 @@ public void neoform(final String neoFormVersion) { null ); } - + configureSetupTasks(sourcesTask.flatMap(WithOutput::getOutput), mainSource, runtimeDefinition.getMinecraftDependenciesConfiguration()); } - + public void runtime(final String neoFormVersion) { runtime(neoFormVersion, project.getRootProject().getLayout().getProjectDirectory().dir("patches"), project.getRootProject().getLayout().getProjectDirectory().dir("rejects")); } - + public void runtime(final String neoFormVersion, Directory patches, Directory rejects) { type = DynamicProjectType.RUNTIME; - + project.getPlugins().apply(PlatformDevProjectPlugin.class); - + final JavaPluginExtension javaPluginExtension = getProject().getExtensions().getByType(JavaPluginExtension.class); final SourceSet mainSource = javaPluginExtension.getSourceSets().getByName("main"); @@ -219,15 +219,15 @@ public void runtime(final String neoFormVersion, Directory patches, Directory re .withParchment(parchmentArtifact) .isUpdating(getIsUpdating()); }); - + project.getExtensions().add("runtime", runtimeDefinition); - + final IdeManagementExtension ideManagementExtension = project.getExtensions().getByType(IdeManagementExtension.class); ideManagementExtension.registerTaskToRun(runtimeDefinition.getAssets()); ideManagementExtension.registerTaskToRun(runtimeDefinition.getNatives()); - + final File workingDirectory = getProject().getLayout().getBuildDirectory().dir(String.format("platform/%s", runtimeDefinition.getSpecification().getIdentifier())).get().getAsFile(); - + final Configuration clientExtraConfiguration = project.getConfigurations().create("clientExtra"); final Configuration serverExtraConfiguration = project.getConfigurations().create("serverExtra"); final Configuration installerConfiguration = project.getConfigurations().create("installer"); @@ -240,15 +240,15 @@ public void runtime(final String neoFormVersion, Directory patches, Directory re final Configuration jarJarConfiguration = project.getConfigurations().create("jarJar"); clientExtraConfiguration.getDependencies().add(project.getDependencies().create(ExtraJarDependencyManager.generateClientCoordinateFor(runtimeDefinition.getSpecification().getMinecraftVersion()))); - + serverExtraConfiguration.getDependencies().add(project.getDependencies().create(ExtraJarDependencyManager.generateServerCoordinateFor(runtimeDefinition.getSpecification().getMinecraftVersion()))); - + installerLibrariesConfiguration.extendsFrom(installerConfiguration); installerLibrariesConfiguration.getDependencies().add(project.getDependencyFactory().create(neoformDependency)); - + project.getConfigurations().getByName(mainSource.getApiConfigurationName()).extendsFrom(gameLayerLibraryConfiguration, pluginLayerLibraryConfiguration, installerConfiguration); project.getConfigurations().getByName(mainSource.getRuntimeClasspathConfigurationName()).extendsFrom(clientExtraConfiguration); - + project.getExtensions().configure(RunTypeManager.class, types -> types.configureEach(type -> configureRunType(project, type, moduleOnlyConfiguration, gameLayerLibraryConfiguration, pluginLayerLibraryConfiguration, runtimeDefinition))); project.getExtensions().configure(RunManager.class, runs -> runs.configureAll(run -> configureRun(run, runtimeDefinition))); @@ -260,13 +260,13 @@ public void runtime(final String neoFormVersion, Directory patches, Directory re final TaskProvider setupTask = configureSetupTasks(runtimeDefinition.getSourceJarTask().flatMap(WithOutput::getOutput), mainSource, runtimeDefinition.getMinecraftDependenciesConfiguration()); setupTask.configure(task -> task.getShouldLockDirectories().set(false)); - + project.afterEvaluate(evaledProject -> { final EnumMap> cleanProviders = new EnumMap<>(DistributionType.class); cleanProviders.put(DistributionType.CLIENT, createCleanProvider(runtimeDefinition.getGameArtifactProvidingTasks().get(GameArtifact.CLIENT_JAR), runtimeDefinition, workingDirectory)); cleanProviders.put(DistributionType.SERVER, createCleanProvider(runtimeDefinition.getJoinedNeoFormRuntimeDefinition().getTask("extractServer"), runtimeDefinition, workingDirectory)); cleanProviders.put(DistributionType.JOINED, runtimeDefinition.getJoinedNeoFormRuntimeDefinition().getTask("rename")); - + final EnumMap> obfToMojMappingProviders = new EnumMap<>(DistributionType.class); final TaskProvider clientInverseMappings = createFlippedMojMapProvider(runtimeDefinition.getGameArtifactProvidingTasks().get(GameArtifact.CLIENT_MAPPINGS), runtimeDefinition, workingDirectory); final TaskProvider serverInverseMappings = createFlippedMojMapProvider(runtimeDefinition.getGameArtifactProvidingTasks().get(GameArtifact.SERVER_MAPPINGS), runtimeDefinition, workingDirectory); @@ -275,24 +275,24 @@ public void runtime(final String neoFormVersion, Directory patches, Directory re obfToMojMappingProviders.put(DistributionType.JOINED, clientInverseMappings); final TaskProvider neoFormSources = runtimeDefinition.getJoinedNeoFormRuntimeDefinition().getSourceJarTask(); - + final TaskProvider packChanges = project.getTasks().register("packForgeChanges", PackJar.class, task -> { task.getInputFiles().from(SetupUtils.getSetupSourceTarget(getProject())); CommonRuntimeExtension.configureCommonRuntimeTaskParameters(task, runtimeDefinition, workingDirectory); }); - + final TaskProvider createPatches = project.getTasks().register("createSourcePatches", GenerateSourcePatches.class, task -> { task.getBase().set(runtimeDefinition.getPatchBase().flatMap(WithOutput::getOutput)); task.getModified().set(packChanges.flatMap(WithOutput::getOutput)); CommonRuntimeExtension.configureCommonRuntimeTaskParameters(task, runtimeDefinition, workingDirectory); }); - + final TaskProvider unpackZip = project.getTasks().register("unpackSourcePatches", UnpackZip.class, task -> { task.getInput().from(project.zipTree(createPatches.flatMap(WithOutput::getOutput))); task.getUnpackingTarget().set(patches); task.dependsOn(createPatches); - + CommonRuntimeExtension.configureCommonRuntimeTaskParameters(task, runtimeDefinition, workingDirectory); }); @@ -332,10 +332,10 @@ public void runtime(final String neoFormVersion, Directory patches, Directory re task.getDistributionType().set(distribution); task.getPatches().from(patches); task.getMappings().set(obfToMojMappingProviders.get(distribution).flatMap(WithOutput::getOutput)); - + task.mustRunAfter(unpackZip); task.mustRunAfter(setupTask); - + CommonRuntimeExtension.configureCommonRuntimeTaskParameters(task, runtimeDefinition, workingDirectory); }); binaryPatchGenerators.put(distribution, generateBinaryPatchesTask); @@ -353,15 +353,15 @@ public void runtime(final String neoFormVersion, Directory patches, Directory re profile.getType().set("release"); profile.getMainClass().set("cpw.mods.bootstraplauncher.BootstrapLauncher"); profile.getInheritsFrom().set(runtimeDefinition.getSpecification().getMinecraftVersion()); - + //TODO: Deal with logging when model for it stands profile.getLoggingConfiguration().set(project.getObjects().newInstance(LauncherProfile.LoggingConfiguration.class)); - + final LauncherProfile.Arguments arguments = launcherProfile.getArguments().get(); - + arguments.game("--launchTarget"); arguments.game("forgeclient"); - + arguments.jvm("-Djava.net.preferIPv6Addresses=system"); arguments.jvm(createIgnoreList(project, moduleOnlyConfiguration, gameLayerLibraryConfiguration, pluginLayerLibraryConfiguration).map(ignoreList -> "-DignoreList=" + ignoreList + ",${version_name}.jar")); arguments.jvm("-DmergeModules=jna-5.10.0.jar,jna-platform-5.10.0.jar"); @@ -369,9 +369,9 @@ public void runtime(final String neoFormVersion, Directory patches, Directory re arguments.jvm(collectFileNames(gameLayerLibraryConfiguration, project).map(gameLayerLibraries -> "-Dfml.gameLayerLibraries=" + gameLayerLibraries)); arguments.jvm("-DlibraryDirectory=${library_directory}"); arguments.jvm("-p"); - + arguments.jvm(collectFilePaths(moduleOnlyConfiguration, "${library_directory}/", "${classpath_separator}", project)); - + arguments.jvm("--add-modules"); arguments.jvm("ALL-MODULE-PATH"); arguments.jvm("--add-opens"); @@ -382,7 +382,7 @@ public void runtime(final String neoFormVersion, Directory patches, Directory re arguments.jvm("java.base/sun.security.util=cpw.mods.securejarhandler"); arguments.jvm("--add-exports"); arguments.jvm("jdk.naming.dns/com.sun.jndi.dns=java.naming"); - + launcherProfile.getArguments().set(arguments); }); @@ -401,10 +401,10 @@ public void runtime(final String neoFormVersion, Directory patches, Directory re task.getLibraries().from(gameLayerLibraryConfiguration); task.getLibraries().from(moduleOnlyConfiguration); task.getRepositoryURLs().set(repoCollection); - + CommonRuntimeExtension.configureCommonRuntimeTaskParameters(task, runtimeDefinition, workingDirectory); }); - + final TaskProvider joinedCleanProvider = cleanProviders.get(DistributionType.JOINED); final TaskProvider strippedJar = project.getTasks().register("stripBinaryPatchedClasses", StripBinPatchedClasses.class, task -> { task.getCompiled().set(project.getTasks().named(mainSource.getJarTaskName(), Jar.class).flatMap(Jar::getArchiveFile)); @@ -412,7 +412,7 @@ public void runtime(final String neoFormVersion, Directory patches, Directory re CommonRuntimeExtension.configureCommonRuntimeTaskParameters(task, runtimeDefinition, workingDirectory); }); - + final TaskProvider universalJar = project.getTasks().register("universalJar", JarJar.class, task -> { task.getArchiveClassifier().set("universal-unsigned"); task.getArchiveAppendix().set("universal-unsigned"); @@ -420,9 +420,9 @@ public void runtime(final String neoFormVersion, Directory patches, Directory re task.getArchiveBaseName().set(project.getName()); task.getDestinationDirectory().set(project.getLayout().getBuildDirectory().dir("libs")); task.getArchiveFileName().set(project.provider(() -> String.format("%s-%s-universal-unsigned.jar", project.getName(), project.getVersion()))); - + task.dependsOn(strippedJar); - + task.from(project.zipTree(strippedJar.flatMap(WithOutput::getOutput))); task.manifest(manifest -> { manifest.attributes(ImmutableMap.of("FML-System-Mods", "neoforge")); @@ -432,11 +432,11 @@ public void runtime(final String neoFormVersion, Directory patches, Directory re task.configuration(jarJarConfiguration); }); - + final TaskProvider signUniversalJar = project.getTasks().register("signUniversalJar", PotentiallySignJar.class, task -> { task.getInput().set(universalJar.flatMap(Jar::getArchiveFile)); task.getOutputFileName().set(project.provider(() -> String.format("%s-%s-universal.jar", project.getName(), project.getVersion()))); - + task.dependsOn(universalJar); }); @@ -458,15 +458,15 @@ public void runtime(final String neoFormVersion, Directory patches, Directory re profile.processor(project, Constants.INSTALLERTOOLS, processor -> { processor.server(); processor.getArguments().addAll("--task", "EXTRACT_FILES", "--archive", "{INSTALLER}", - + "--from", "data/run.sh", "--to", "{ROOT}/run.sh", "--exec", "{ROOT}/run.sh", - + "--from", "data/run.bat", "--to", "{ROOT}/run.bat", - + "--from", "data/user_jvm_args.txt", "--to", "{ROOT}/user_jvm_args.txt", "--optional", "{ROOT}/user_jvm_args.txt", - + "--from", "data/win_args.txt", "--to", String.format("{ROOT}/libraries/%s/%s/%s/win_args.txt", project.getGroup().toString().replaceAll("\\.", "/"), project.getName(), project.getVersion()), - + "--from", "data/unix_args.txt", "--to", String.format("{ROOT}/libraries/%s/%s/%s/unix_args.txt", project.getGroup().toString().replaceAll("\\.", "/"), project.getName(), project.getVersion())); }); profile.processor(project, Constants.INSTALLERTOOLS, processor -> { @@ -500,7 +500,7 @@ public void runtime(final String neoFormVersion, Directory patches, Directory re profile.processor(project, Constants.BINARYPATCHER, processor -> { processor.getArguments().addAll("--clean", "{MC_SRG}", "--output", "{PATCHED}", "--apply", "{BINPATCH}"); }); - + profile.getLibraries().add(Library.fromOutput(signUniversalJar, project, "net.neoforged", "neoforge", project.getVersion().toString(), "universal")); //TODO: Abstract this away to some kind of DSL property @@ -530,9 +530,9 @@ public void runtime(final String neoFormVersion, Directory patches, Directory re task.getProfile().set(installerProfile); task.getLibraries().from(installerJsonInstallerLibrariesConfiguration); task.getRepositoryURLs().set(repoCollection); - + task.dependsOn(signUniversalJar); - + CommonRuntimeExtension.configureCommonRuntimeTaskParameters(task, runtimeDefinition, workingDirectory); }); @@ -544,7 +544,7 @@ public void runtime(final String neoFormVersion, Directory patches, Directory re task.getInput().from(installerToolConfiguration); CommonRuntimeExtension.configureCommonRuntimeTaskParameters(task, runtimeDefinition, workingDirectory); }); - + final TaskProvider createWindowsServerArgsFile = project.getTasks().register("createWindowsServerArgsFile", CreateClasspathFiles.class, task -> { task.getModulePath().from(moduleOnlyConfiguration); task.getClasspath().from(installerRuntimeLibrariesConfiguration); @@ -553,12 +553,12 @@ public void runtime(final String neoFormVersion, Directory patches, Directory re task.getPathSeparator().set(";"); task.getServer().set(runtimeDefinition.getGameArtifactProvidingTasks().get(GameArtifact.SERVER_JAR).flatMap(WithOutput::getOutput)); task.getNeoFormVersion().set(neoFormVersion); - + configureInstallerTokens(task, runtimeDefinition, Lists.newArrayList(moduleOnlyConfiguration, gameLayerLibraryConfiguration, pluginLayerLibraryConfiguration), pluginLayerLibraryConfiguration, gameLayerLibraryConfiguration); - + CommonRuntimeExtension.configureCommonRuntimeTaskParameters(task, runtimeDefinition, workingDirectory); }); - + final TaskProvider createUnixServerArgsFile = project.getTasks().register("createUnixServerArgsFile", CreateClasspathFiles.class, task -> { task.getModulePath().from(moduleOnlyConfiguration); task.getClasspath().from(installerRuntimeLibrariesConfiguration); @@ -567,12 +567,12 @@ public void runtime(final String neoFormVersion, Directory patches, Directory re task.getPathSeparator().set(":"); task.getServer().set(runtimeDefinition.getGameArtifactProvidingTasks().get(GameArtifact.SERVER_JAR).flatMap(WithOutput::getOutput)); task.getNeoFormVersion().set(neoFormVersion); - + configureInstallerTokens(task, runtimeDefinition, Lists.newArrayList(moduleOnlyConfiguration, gameLayerLibraryConfiguration, pluginLayerLibraryConfiguration), pluginLayerLibraryConfiguration, gameLayerLibraryConfiguration); - + CommonRuntimeExtension.configureCommonRuntimeTaskParameters(task, runtimeDefinition, workingDirectory); }); - + final TaskProvider installerJar = project.getTasks().register("legacyInstallerJar", CreateLegacyInstaller.class, task -> { task.getInstallerCore().set(downloadInstaller.flatMap(WithOutput::getOutput)); task.getInstallerJson().set(createLegacyInstallerJson.flatMap(WithOutput::getOutput)); @@ -582,9 +582,9 @@ public void runtime(final String neoFormVersion, Directory patches, Directory re task.getWindowsServerArgs().set(createWindowsServerArgsFile.flatMap(WithOutput::getOutput)); task.getUnixServerArgs().set(createUnixServerArgsFile.flatMap(WithOutput::getOutput)); task.getData().from(project.getRootProject().fileTree("server_files/").exclude("args.txt")); - + configureInstallerTokens(task, runtimeDefinition, Lists.newArrayList(moduleOnlyConfiguration, gameLayerLibraryConfiguration, pluginLayerLibraryConfiguration), pluginLayerLibraryConfiguration, gameLayerLibraryConfiguration); - + if (project.getProperties().containsKey("neogradle.runtime.platform.installer.debug") && Boolean.parseBoolean(project.getProperties().get("neogradle.runtime.platform.installer.debug").toString())) { task.from(signUniversalJar.flatMap(WithOutput::getOutput), spec -> { spec.into(String.format("/maven/net/neoforged/neoforge/%s/", project.getVersion())); @@ -592,14 +592,14 @@ public void runtime(final String neoFormVersion, Directory patches, Directory re }); } }); - + TaskProvider signInstallerJar = project.getTasks().register("signInstallerJar", PotentiallySignJar.class, task -> { task.getInput().set(installerJar.flatMap(Zip::getArchiveFile)); task.getOutputFileName().set(project.provider(() -> String.format("%s-%s-installer.jar", project.getName(), project.getVersion()))); - + task.dependsOn(installerJar); }); - + //Note the following runtypes are for now hardcoded, in the future they should be pulled from the runtime definition //Note: We can not use a 'configureEach' here, because this causes issues with the config cache. userdevProfile.runType("client", type -> { @@ -608,7 +608,7 @@ public void runtime(final String neoFormVersion, Directory patches, Directory re type.getIsClient().set(true); type.getIsGameTest().set(true); type.getSystemProperties().put("neoforge.enableGameTest", "true"); - + type.getArguments().add("--launchTarget"); type.getArguments().add("forgeclientuserdev"); type.getArguments().add("--version"); @@ -617,7 +617,7 @@ public void runtime(final String neoFormVersion, Directory patches, Directory re type.getArguments().add("{asset_index}"); type.getArguments().add("--assetsDir"); type.getArguments().add("{assets_root}"); - + configureUserdevRunType(type, moduleOnlyConfiguration, gameLayerLibraryConfiguration, pluginLayerLibraryConfiguration, userdevCompileOnlyConfiguration, project); }); userdevProfile.runType("server", type -> { @@ -627,7 +627,7 @@ public void runtime(final String neoFormVersion, Directory patches, Directory re type.getArguments().add("--launchTarget"); type.getArguments().add("forgeserveruserdev"); - + configureUserdevRunType(type, moduleOnlyConfiguration, gameLayerLibraryConfiguration, pluginLayerLibraryConfiguration, userdevCompileOnlyConfiguration, project); }); userdevProfile.runType("gameTestServer", type -> { @@ -637,11 +637,11 @@ public void runtime(final String neoFormVersion, Directory patches, Directory re type.getIsGameTest().set(true); type.getSystemProperties().put("neoforge.enableGameTest", "true"); type.getSystemProperties().put("neoforge.gameTestServer", "true"); - - + + type.getArguments().add("--launchTarget"); type.getArguments().add("forgeserveruserdev"); - + configureUserdevRunType(type, moduleOnlyConfiguration, gameLayerLibraryConfiguration, pluginLayerLibraryConfiguration, userdevCompileOnlyConfiguration, project); }); userdevProfile.runType("data", type -> { @@ -655,7 +655,7 @@ public void runtime(final String neoFormVersion, Directory patches, Directory re type.getArguments().add("{asset_index}"); type.getArguments().add("--assetsDir"); type.getArguments().add("{assets_root}"); - + configureUserdevRunType(type, moduleOnlyConfiguration, gameLayerLibraryConfiguration, pluginLayerLibraryConfiguration, userdevCompileOnlyConfiguration, project); }); @@ -725,16 +725,16 @@ public void runtime(final String neoFormVersion, Directory patches, Directory re CommonRuntimeExtension.configureCommonRuntimeTaskParameters(task, runtimeDefinition, workingDirectory); }); - + final TaskProvider generateAts = project.getTasks().register("generateAccessTransformers", AccessTransformerFileGenerator.class, task -> { CommonRuntimeExtension.configureCommonRuntimeTaskParameters(task, runtimeDefinition, workingDirectory); }); - + final TaskProvider packPatches = project.getTasks().register("packPatches", PackJar.class, task -> { task.getInputFiles().from(project.fileTree(patches).matching(filterable -> { filterable.include("**/*.patch"); })); - + CommonRuntimeExtension.configureCommonRuntimeTaskParameters(task, runtimeDefinition, workingDirectory); }); @@ -767,9 +767,9 @@ public void runtime(final String neoFormVersion, Directory patches, Directory re CommonRuntimeExtension.configureCommonRuntimeTaskParameters(task, runtimeDefinition, workingDirectory); }); } - + final AccessTransformers accessTransformers = project.getExtensions().getByType(AccessTransformers.class); - + final TaskProvider userdevJar = project.getTasks().register("userdevJar", Jar.class, task -> { task.getArchiveClassifier().set("userdev"); task.getArchiveAppendix().set("userdev"); @@ -777,9 +777,9 @@ public void runtime(final String neoFormVersion, Directory patches, Directory re task.getArchiveBaseName().set(project.getName()); task.getDestinationDirectory().set(project.getLayout().getBuildDirectory().dir("libs")); task.getArchiveFileName().set(project.provider(() -> String.format("%s-%s-userdev.jar", project.getName(), project.getVersion()))); - + task.dependsOn(bakePatches); - + //We need to get a raw file tree here, because else we capture the task reference in copy spec. final FileTree bakedPatches = project.zipTree(bakePatches.get().getOutput().get().getAsFile()); task.from(createUserdevJson.flatMap(WithOutput::getOutput), spec -> { @@ -798,7 +798,7 @@ public void runtime(final String neoFormVersion, Directory patches, Directory re spec.into("patches/"); }); }); - + final TaskProvider assembleTask = project.getTasks().named("assemble"); assembleTask.configure(task -> { task.dependsOn(signInstallerJar); @@ -808,27 +808,27 @@ public void runtime(final String neoFormVersion, Directory patches, Directory re }); }); } - + private TaskProvider configureSetupTasks(Provider rawJarProvider, SourceSet mainSource, Configuration minecraftDependencies) { final IdeManagementExtension ideManagementExtension = project.getExtensions().getByType(IdeManagementExtension.class); - + final TaskProvider ideImportTask = ideManagementExtension.getOrCreateIdeImportTask(); - + final TaskProvider projectSetup = project.getTasks().register("setup", SetupProjectFromRuntime.class, task -> { task.getSourcesFile().set(rawJarProvider); task.dependsOn(ideImportTask); }); - + final Configuration apiConfiguration = project.getConfigurations().getByName(mainSource.getApiConfigurationName()); minecraftDependencies.getAllDependencies().forEach(dep -> apiConfiguration.getDependencies().add(dep)); - + final Project rootProject = project.getRootProject(); if (!rootProject.getTasks().getNames().contains("setup")) { rootProject.getTasks().create("setup"); } - + rootProject.getTasks().named("setup").configure(task -> task.dependsOn(projectSetup)); - + return projectSetup; } @@ -857,6 +857,62 @@ private void configureRunType(final Project project, final RunType runType, fina runType.getEnvironmentVariables().put("NEOFORGE_SPEC", project.getVersion().toString().substring(0, project.getVersion().toString().lastIndexOf("."))); runType.getClasspath().from(runtimeClasspath); + + runType.getRunTemplate().getArguments().addAll( + TransformerUtils.ifTrue(runType.getRunTemplate().getIsClient(), + "--username", "Dev", + "--version", project.getName(), + "--accessToken", "0", + "--launchTarget", "forgeclientdev") + + ); + + runType.getRunTemplate().getArguments().addAll( + TransformerUtils.ifTrue(runType.getRunTemplate().getIsServer(), + "--launchTarget", "forgeserverdev") + ); + + runType.getRunTemplate().getSystemProperties().putAll( + TransformerUtils.ifTrueMap(runType.getRunTemplate().getIsGameTest(), + "neoforge.enableGameTest", "true") + ); + + runType.getRunTemplate().getSystemProperties().putAll( + TransformerUtils.ifTrueMap( + runType.getRunTemplate().getIsGameTest().flatMap(TransformerUtils.and(runType.getRunTemplate().getIsServer())), + "neoforge.gameTestServer", "true") + ); + + runType.getRunTemplate().getArguments().addAll( + TransformerUtils.ifTrue(runType.getRunTemplate().getIsDataGenerator(), + "--launchTarget", "forgedatadev", + "--flat", "--all", "--validate", + "--output", project.getRootProject().file("src/generated/resources/").getAbsolutePath()) + ); + + mainSourceSet.getResources().getSrcDirs().forEach(file -> { + runType.getRunTemplate().getArguments().addAll( + TransformerUtils.ifTrue(runType.getRunTemplate().getIsDataGenerator(), + "--existing", file.getAbsolutePath()) + ); + }); + + Provider assetsDir = DownloadAssets.getAssetsDirectory(project).map(Directory::getAsFile).map(File::getAbsolutePath); + Provider assetIndex = runtimeDefinition.getAssets().flatMap(DownloadAssets::getAssetIndex); + + runType.getRunTemplate().getArguments().addAll( + TransformerUtils.ifTrue( + runType.getRunTemplate().getIsDataGenerator().flatMap(TransformerUtils.or(runType.getRunTemplate().getIsClient(), runType.getRunTemplate().getIsJUnit())), + project.provider(() -> "--assetsDir"), + assetsDir, + project.provider(() -> "--assetIndex"), + assetIndex) + ); + + runType.getRunTemplate().getArguments().addAll( + TransformerUtils.ifTrue(runType.getRunTemplate().getIsJUnit(), + "--launchTarget", "forgejunitdev") + ); } private static void configureInstallerTokens(final TokenizedTask tokenizedTask, final RuntimeDevRuntimeDefinition runtimeDefinition, final Collection ignoreConfigurations, final Configuration pluginLayerLibraries, final Configuration gameLayerLibraries) { @@ -916,62 +972,6 @@ private void configureRun(final Run run, final RuntimeDevRuntimeDefinition runti run.getDependsOn().addAll( TransformerUtils.ifTrue(run.getIsClient(), runtimeDefinition.getAssets(), runtimeDefinition.getNatives()) ); - - run.getArguments().addAll( - TransformerUtils.ifTrue(run.getIsClient(), - "--username", "Dev", - "--version", project.getName(), - "--accessToken", "0", - "--launchTarget", "forgeclientdev") - - ); - - run.getArguments().addAll( - TransformerUtils.ifTrue(run.getIsServer(), - "--launchTarget", "forgeserverdev") - ); - - run.getSystemProperties().putAll( - TransformerUtils.ifTrueMap(run.getIsGameTest(), - "neoforge.enableGameTest", "true") - ); - - run.getSystemProperties().putAll( - TransformerUtils.ifTrueMap( - run.getIsGameTest().flatMap(TransformerUtils.and(run.getIsServer())), - "neoforge.gameTestServer", "true") - ); - - run.getArguments().addAll( - TransformerUtils.ifTrue(run.getIsDataGenerator(), - "--launchTarget", "forgedatadev", - "--flat", "--all", "--validate", - "--output", project.getRootProject().file("src/generated/resources/").getAbsolutePath()) - ); - - mainSourceSet.getResources().getSrcDirs().forEach(file -> { - run.getArguments().addAll( - TransformerUtils.ifTrue(run.getIsDataGenerator(), - "--existing", file.getAbsolutePath()) - ); - }); - - Provider assetsDir = DownloadAssets.getAssetsDirectory(project).map(Directory::getAsFile).map(File::getAbsolutePath); - Provider assetIndex = runtimeDefinition.getAssets().flatMap(DownloadAssets::getAssetIndex); - - run.getArguments().addAll( - TransformerUtils.ifTrue( - run.getIsDataGenerator().flatMap(TransformerUtils.or(run.getIsClient(), run.getIsJUnit())), - project.provider(() -> "--assetsDir"), - assetsDir, - project.provider(() -> "--assetIndex"), - assetIndex) - ); - - run.getArguments().addAll( - TransformerUtils.ifTrue(run.getIsJUnit(), - "--launchTarget", "forgejunitdev") - ); } private TaskProvider createCleanProvider(final TaskProvider jarProvider, final RuntimeDevRuntimeDefinition runtimeDefinition, File workingDirectory) { diff --git a/userdev/src/functionalTest/groovy/net/neoforged/gradle/userdev/RunTests.groovy b/userdev/src/functionalTest/groovy/net/neoforged/gradle/userdev/RunTests.groovy index 2a3af8bf..f32b81cf 100644 --- a/userdev/src/functionalTest/groovy/net/neoforged/gradle/userdev/RunTests.groovy +++ b/userdev/src/functionalTest/groovy/net/neoforged/gradle/userdev/RunTests.groovy @@ -103,8 +103,6 @@ class RunTests extends BuilderBasedTestSpecification { it.tasks(':runData') //We are expecting this test to fail, since there is a mod without any files included so it is fine. it.shouldFail() - it.stacktrace() - it.debug() } then: diff --git a/utils/src/main/java/net/neoforged/gradle/util/TransformerUtils.java b/utils/src/main/java/net/neoforged/gradle/util/TransformerUtils.java index f19e780a..11cbfdee 100644 --- a/utils/src/main/java/net/neoforged/gradle/util/TransformerUtils.java +++ b/utils/src/main/java/net/neoforged/gradle/util/TransformerUtils.java @@ -308,7 +308,7 @@ public static Provider> ifTrue(Provider predicate Provider> zippedArray = whenTrue[0].zip(predicate, (v, p) -> p ? List.of(v) : List.of()); for (int i = 1; i < whenTrue.length; i++) { zippedArray = zippedArray.zip( - whenTrue[1].zip(predicate, (v, p) -> p ? List.of(v) : List.of()), + whenTrue[i].zip(predicate, (v, p) -> p ? List.of(v) : List.of()), (BiFunction, List, List>) (vs, objects) -> { final ArrayList ret = new ArrayList<>(vs); ret.addAll(objects);