From 7ba0e478ecf3935b6b6b5ed9d709dfd146af84b3 Mon Sep 17 00:00:00 2001 From: Marc Hermans Date: Mon, 4 Nov 2024 11:38:30 +0100 Subject: [PATCH] [Fix]: Dynamic project does not properly deal with detached configurations (#252) Tested locally so merging. --- .../platform/model/InstallerProfile.groovy | 5 --- .../platform/InstallerProfileTests.groovy | 42 +++++++++++++++++++ .../extensions/DynamicProjectExtension.java | 19 +++++---- 3 files changed, 52 insertions(+), 14 deletions(-) diff --git a/dsl/platform/src/main/groovy/net/neoforged/gradle/dsl/platform/model/InstallerProfile.groovy b/dsl/platform/src/main/groovy/net/neoforged/gradle/dsl/platform/model/InstallerProfile.groovy index 5fe27841..620bc6a2 100644 --- a/dsl/platform/src/main/groovy/net/neoforged/gradle/dsl/platform/model/InstallerProfile.groovy +++ b/dsl/platform/src/main/groovy/net/neoforged/gradle/dsl/platform/model/InstallerProfile.groovy @@ -143,11 +143,6 @@ abstract class InstallerProfile implements ConfigurableDSLElement getData(); - /** - * Track which tools were already added to avoid re-resolving the download URLs for the same tool over and over. - */ - private final Set toolLibrariesAdded = new HashSet<>() - void data(String key, @Nullable String client, @Nullable String server) { getData().put(key, getObjectFactory().newInstance(DataFile.class).configure { DataFile it -> if (client != null) diff --git a/platform/src/functionalTest/groovy/net/neoforged/gradle/platform/InstallerProfileTests.groovy b/platform/src/functionalTest/groovy/net/neoforged/gradle/platform/InstallerProfileTests.groovy index 3c9cf4dc..2568b196 100644 --- a/platform/src/functionalTest/groovy/net/neoforged/gradle/platform/InstallerProfileTests.groovy +++ b/platform/src/functionalTest/groovy/net/neoforged/gradle/platform/InstallerProfileTests.groovy @@ -33,6 +33,7 @@ class InstallerProfileTests extends BuilderBasedTestSpecification { private PublishingProjectSetup createPublishingProject(String projectId, String patchedBuildConfiguration) { def rootProject = create(projectId, { it.property(CachedExecutionService.DEBUG_CACHE_PROPERTY, 'true') + it.property("neogradle.runtime.platform.installer.debug", "true") it.settingsPlugin(pluginUnderTest) it.settings(""" dynamicProjects { @@ -64,6 +65,16 @@ class InstallerProfileTests extends BuilderBasedTestSpecification { it.file("server_files/args.txt", """ Something to Inject into """) + it.file("server_files/run.sh", """ + #!/bin/bash + echo "Test server starter script" + """) + it.file("server_files/run.bat", """ + echo "Test server starter script" + """) + it.file("server_files/user_jvm_args.txt", """ + -Xmx2G + """) //The following properties are needed as we do not have an abstract layer over the tokens needed. it.property("fancy_mod_loader_version", "1.0.0") it.enableGradleParallelRunning() @@ -373,5 +384,36 @@ class InstallerProfileTests extends BuilderBasedTestSpecification { jsonFile.text.contains("net.neoforged.installertools:binarypatcher:2.1.5:fatjar") !jsonFile.text.contains("net.neoforged.installertools:binarypatcher:2.1.7:fatjar") } + + def "a published installer can be invoked to install a server"() { + given: + def project = createPublishingProject("published-userdev", """ + tasks.register("installTestServer", JavaExec.class) { + classpath(tasks.named("signInstallerJar").flatMap { it.output }) + args("--installServer", file("build/testserverinstall").absolutePath) + dependsOn("signInstallerJar") + } + """) + + project.rootProject.run { it.tasks ':neoforge:setup' } + patch(project) + project.rootProject.run { it.tasks ':neoforge:unpackSourcePatches'} + project.rootProject.run { it.tasks ':neoforge:assemble' } + + when: + def publishingRun = project.rootProject.run { + it.tasks ':neoforge:installTestServer' + } + + then: + publishingRun.task(":neoforge:installTestServer").outcome == TaskOutcome.SUCCESS + + and: + def testServerDir = project.patchedProject.file("build/testserverinstall") + + then: + testServerDir.exists() + testServerDir.listFiles().size() > 0 + } } 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 7dfaf7fc..6b8d2953 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 @@ -391,7 +391,7 @@ public void runtime(final String neoFormVersion, Directory patches, Directory re project.getConfigurations(), "InstallerRuntimeLibraries" ); - installerRuntimeLibrariesConfiguration.extendsFrom(installerConfiguration); + ConfigurationUtils.extendsFrom(project, installerRuntimeLibrariesConfiguration, installerConfiguration); installerRuntimeLibrariesConfiguration.shouldResolveConsistentlyWith(runtimeClasspath); final ListProperty repoCollection = new RepositoryCollection(project.getProviders(), project.getObjects(), project.getRepositories()).getURLs(); @@ -525,7 +525,7 @@ public void runtime(final String neoFormVersion, Directory patches, Directory re project.getConfigurations(), "InstallerJsonInstallerLibraries" ); - installerJsonInstallerLibrariesConfiguration.extendsFrom(installerLibrariesConfiguration); + ConfigurationUtils.extendsFrom(project, installerJsonInstallerLibrariesConfiguration, installerLibrariesConfiguration); installerJsonInstallerLibrariesConfiguration.shouldResolveConsistentlyWith(runtimeClasspath); final TaskProvider createLegacyInstallerJson = project.getTasks().register("createLegacyInstallerJson", CreateLegacyInstallerJson.class, task -> { @@ -575,6 +575,7 @@ public void runtime(final String neoFormVersion, Directory patches, Directory re CommonRuntimeExtension.configureCommonRuntimeTaskParameters(task, runtimeDefinition, workingDirectory); }); + var projectVersion = project.getVersion().toString(); final TaskProvider installerJar = project.getTasks().register("legacyInstallerJar", CreateLegacyInstaller.class, task -> { task.getInstallerCore().set(downloadInstaller.flatMap(WithOutput::getOutput)); task.getInstallerJson().set(createLegacyInstallerJson.flatMap(WithOutput::getOutput)); @@ -589,8 +590,8 @@ public void runtime(final String neoFormVersion, Directory patches, Directory re 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())); - spec.rename(name -> String.format("neoforge-%s-universal.jar", project.getVersion())); + spec.into(String.format("/maven/net/neoforged/neoforge/%s/", projectVersion)); + spec.rename(name -> String.format("neoforge-%s-universal.jar", projectVersion)); }); } }); @@ -695,27 +696,27 @@ public void runtime(final String neoFormVersion, Directory patches, Directory re project.getConfigurations(), "userdevLibraries" ); - userdevJsonLibrariesConfiguration.extendsFrom( + ConfigurationUtils.extendsFrom(project, + userdevJsonLibrariesConfiguration, userdevCompileOnlyConfiguration, installerLibrariesConfiguration, gameLayerLibraryConfiguration, pluginLayerLibraryConfiguration, - moduleOnlyConfiguration - ); + moduleOnlyConfiguration); userdevJsonLibrariesConfiguration.shouldResolveConsistentlyWith(runtimeClasspath); final Configuration userdevJsonModuleOnlyConfiguration = ConfigurationUtils.temporaryUnhandledConfiguration( project.getConfigurations(), "userdevModuleOnly" ); - userdevJsonModuleOnlyConfiguration.extendsFrom(moduleOnlyConfiguration); + ConfigurationUtils.extendsFrom(project, userdevJsonModuleOnlyConfiguration, moduleOnlyConfiguration); userdevJsonLibrariesConfiguration.shouldResolveConsistentlyWith(runtimeClasspath); final Configuration userdevJsonUserdevTestImplementationConfiguration = ConfigurationUtils.temporaryUnhandledConfiguration( project.getConfigurations(), "userdevJsonUserdevTestImplementation" ); - userdevJsonUserdevTestImplementationConfiguration.extendsFrom(userdevTestImplementationConfiguration); + ConfigurationUtils.extendsFrom(project, userdevJsonUserdevTestImplementationConfiguration, userdevTestImplementationConfiguration); userdevJsonUserdevTestImplementationConfiguration.shouldResolveConsistentlyWith(runtimeClasspath); final TaskProvider createUserdevJson = project.getTasks().register("createUserdevJson", CreateUserdevJson.class, task -> {