Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Fix]: Dynamic project does not properly deal with detached configurations #252

Merged
merged 2 commits into from
Nov 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -143,11 +143,6 @@ abstract class InstallerProfile implements ConfigurableDSLElement<InstallerProfi
@Optional
abstract MapProperty<String, DataFile> getData();

/**
* Track which tools were already added to avoid re-resolving the download URLs for the same tool over and over.
*/
private final Set<String> 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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -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<URI> repoCollection = new RepositoryCollection(project.getProviders(), project.getObjects(), project.getRepositories()).getURLs();
Expand Down Expand Up @@ -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> createLegacyInstallerJson = project.getTasks().register("createLegacyInstallerJson", CreateLegacyInstallerJson.class, task -> {
Expand Down Expand Up @@ -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<CreateLegacyInstaller> installerJar = project.getTasks().register("legacyInstallerJar", CreateLegacyInstaller.class, task -> {
task.getInstallerCore().set(downloadInstaller.flatMap(WithOutput::getOutput));
task.getInstallerJson().set(createLegacyInstallerJson.flatMap(WithOutput::getOutput));
Expand All @@ -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));
});
}
});
Expand Down Expand Up @@ -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> createUserdevJson = project.getTasks().register("createUserdevJson", CreateUserdevJson.class, task -> {
Expand Down
Loading