mirror of
https://github.com/architectury/architectury-loom.git
synced 2026-03-28 04:07:01 -05:00
@@ -36,13 +36,16 @@ import java.util.function.Function;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import org.gradle.api.Action;
|
||||
import org.gradle.api.Named;
|
||||
import org.gradle.api.NamedDomainObjectContainer;
|
||||
import org.gradle.api.Project;
|
||||
import org.gradle.api.provider.Property;
|
||||
import org.gradle.api.tasks.SourceSet;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
|
||||
import net.fabricmc.loom.LoomGradleExtension;
|
||||
import net.fabricmc.loom.api.ModSettings;
|
||||
import net.fabricmc.loom.configuration.providers.forge.ForgeRunTemplate;
|
||||
import net.fabricmc.loom.configuration.providers.forge.ForgeRunsProvider;
|
||||
import net.fabricmc.loom.configuration.providers.minecraft.MinecraftSourceSets;
|
||||
@@ -116,8 +119,11 @@ public class RunConfigSettings implements Named {
|
||||
|
||||
private final Project project;
|
||||
private final LoomGradleExtension extension;
|
||||
|
||||
// Architectury
|
||||
private final List<Runnable> evaluateLater = new ArrayList<>();
|
||||
private boolean evaluated = false;
|
||||
private final NamedDomainObjectContainer<ModSettings> mods;
|
||||
|
||||
@Inject
|
||||
public RunConfigSettings(Project project, String name) {
|
||||
@@ -130,6 +136,7 @@ public class RunConfigSettings implements Named {
|
||||
Objects.requireNonNull(defaultMainClass, "Run config " + name + " must specify default main class");
|
||||
return RunConfig.getMainClass(environment, extension, defaultMainClass);
|
||||
}));
|
||||
this.mods = project.getObjects().domainObjectContainer(ModSettings.class);
|
||||
|
||||
setSource(p -> {
|
||||
final String sourceSetName = MinecraftSourceSets.get(p).getSourceSetForEnv(getEnvironment());
|
||||
@@ -385,7 +392,7 @@ public class RunConfigSettings implements Named {
|
||||
ForgeRunTemplate template = runsProvider.getTemplates().findByName(templateName);
|
||||
|
||||
if (template != null) {
|
||||
template.applyTo(this, runsProvider);
|
||||
template.applyTo(this, runsProvider.getResolver(this));
|
||||
} else {
|
||||
project.getLogger().warn("Could not find Forge run template with name '{}'", templateName);
|
||||
}
|
||||
@@ -422,4 +429,29 @@ public class RunConfigSettings implements Named {
|
||||
public void setIdeConfigGenerated(boolean ideConfigGenerated) {
|
||||
this.ideConfigGenerated = ideConfigGenerated;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return a container of mod settings for this run configuration}
|
||||
*
|
||||
* <p>If non-empty, this container will override the
|
||||
* {@linkplain net.fabricmc.loom.api.LoomGradleExtensionAPI#getMods global container}
|
||||
* declared in the {@code loom} extension.
|
||||
*
|
||||
* <p>This method is currently only available on Forge.
|
||||
*/
|
||||
@ApiStatus.Experimental
|
||||
public NamedDomainObjectContainer<ModSettings> getMods() {
|
||||
ModPlatform.assertPlatform(project, ModPlatform.FORGE);
|
||||
return mods;
|
||||
}
|
||||
|
||||
/**
|
||||
* Configures the {@linkplain #getMods mods} of this run configuration.
|
||||
*
|
||||
* <p>This method is currently only available on Forge.
|
||||
*/
|
||||
@ApiStatus.Experimental
|
||||
public void mods(Action<NamedDomainObjectContainer<ModSettings>> action) {
|
||||
action.execute(getMods());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
* This file is part of fabric-loom, licensed under the MIT License (MIT).
|
||||
*
|
||||
* Copyright (c) 2022 FabricMC
|
||||
* Copyright (c) 2022-2023 FabricMC
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
@@ -39,17 +39,20 @@ import com.google.common.collect.Multimap;
|
||||
import com.google.common.collect.MultimapBuilder;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import org.gradle.api.NamedDomainObjectContainer;
|
||||
import org.gradle.api.NamedDomainObjectSet;
|
||||
import org.gradle.api.Project;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import net.fabricmc.loom.LoomGradleExtension;
|
||||
import net.fabricmc.loom.api.ModSettings;
|
||||
import net.fabricmc.loom.configuration.ide.RunConfigSettings;
|
||||
import net.fabricmc.loom.util.Constants;
|
||||
import net.fabricmc.loom.util.DependencyDownloader;
|
||||
import net.fabricmc.loom.util.gradle.SourceSetHelper;
|
||||
import net.fabricmc.loom.util.gradle.SourceSetReference;
|
||||
|
||||
public class ForgeRunsProvider implements ConfigValue.Resolver {
|
||||
public class ForgeRunsProvider {
|
||||
private final Project project;
|
||||
private final LoomGradleExtension extension;
|
||||
private final JsonObject json;
|
||||
@@ -79,8 +82,11 @@ public class ForgeRunsProvider implements ConfigValue.Resolver {
|
||||
return new ForgeRunsProvider(project, json);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String resolve(ConfigValue.Variable variable) {
|
||||
public ConfigValue.Resolver getResolver(@Nullable RunConfigSettings runConfig) {
|
||||
return variable -> resolve(runConfig, variable);
|
||||
}
|
||||
|
||||
private String resolve(@Nullable RunConfigSettings runConfig, ConfigValue.Variable variable) {
|
||||
String key = variable.name();
|
||||
String string = '{' + key + '}';
|
||||
|
||||
@@ -128,8 +134,13 @@ public class ForgeRunsProvider implements ConfigValue.Resolver {
|
||||
} else if (key.equals("source_roots")) {
|
||||
// Use a set-valued multimap for deduplicating paths.
|
||||
Multimap<String, String> modClasses = MultimapBuilder.hashKeys().linkedHashSetValues().build();
|
||||
NamedDomainObjectContainer<ModSettings> mods = extension.getMods();
|
||||
|
||||
for (ModSettings mod : extension.getMods()) {
|
||||
if (runConfig != null && !runConfig.getMods().isEmpty()) {
|
||||
mods = runConfig.getMods();
|
||||
}
|
||||
|
||||
for (ModSettings mod : mods) {
|
||||
// Note: In Forge 1.16.5, resources have to come first to find mods.toml
|
||||
for (SourceSetReference modSourceSet : mod.getModSourceSets().get()) {
|
||||
File resourcesDir = modSourceSet.sourceSet().getOutput().getResourcesDir();
|
||||
|
||||
@@ -142,14 +142,15 @@ public abstract class GenerateDLIConfigTask extends AbstractLoomTask {
|
||||
}
|
||||
|
||||
ForgeRunsProvider forgeRunsProvider = getExtension().getForgeRunsProvider();
|
||||
ConfigValue.Resolver configResolver = forgeRunsProvider.getResolver(null);
|
||||
|
||||
for (ForgeRunTemplate template : forgeRunsProvider.getTemplates()) {
|
||||
for (ConfigValue argument : template.args()) {
|
||||
launchConfig.argument(template.name(), argument.resolve(forgeRunsProvider));
|
||||
launchConfig.argument(template.name(), argument.resolve(configResolver));
|
||||
}
|
||||
|
||||
for (Map.Entry<String, ConfigValue> property : template.props().entrySet()) {
|
||||
launchConfig.property(template.name(), property.getKey(), property.getValue().resolve(forgeRunsProvider));
|
||||
launchConfig.property(template.name(), property.getKey(), property.getValue().resolve(configResolver));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -69,4 +69,55 @@ class ForgeRunConfigTest extends Specification implements GradleProjectTestTrait
|
||||
'1.16.5' | "36.2.4" | 'net.minecraftforge.userdev.LaunchTesting'
|
||||
'1.14.4' | "28.2.23" | 'net.minecraftforge.userdev.LaunchTesting'
|
||||
}
|
||||
|
||||
def "verify mod classes"() {
|
||||
setup:
|
||||
def gradle = gradleProject(project: "forge/simple", version: DEFAULT_GRADLE)
|
||||
gradle.buildGradle.text = gradle.buildGradle.text.replace('@MCVERSION@', '1.19.4')
|
||||
.replace('@FORGEVERSION@', "45.0.43")
|
||||
.replace('@MAPPINGS@', 'loom.officialMojangMappings()')
|
||||
gradle.buildGradle << '''
|
||||
sourceSets {
|
||||
testMod {}
|
||||
}
|
||||
|
||||
loom {
|
||||
runs {
|
||||
testMod {
|
||||
client()
|
||||
mods {
|
||||
main { sourceSet 'main' }
|
||||
testMod { sourceSet 'testMod' }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
tasks.register('verifyRunConfigs') {
|
||||
doLast {
|
||||
def client = loom.runs.client
|
||||
client.evaluateNow()
|
||||
def clientClasses = client.environmentVariables.get('MOD_CLASSES')
|
||||
if (!clientClasses.contains('main%%')) {
|
||||
throw new AssertionError("MOD_CLASSES=clientClasses missing main classes")
|
||||
} else if (clientClasses.contains('testMod%%')) {
|
||||
throw new AssertionError("MOD_CLASSES=$clientClasses containing test mod classes")
|
||||
}
|
||||
|
||||
def testMod = loom.runs.testMod
|
||||
testMod.evaluateNow()
|
||||
def testModClasses = testMod.environmentVariables.get('MOD_CLASSES')
|
||||
if (!testModClasses.contains('main%%') || !testModClasses.contains('testMod%%')) {
|
||||
throw new AssertionError("MOD_CLASSES=$testModClasses missing required entries")
|
||||
}
|
||||
}
|
||||
}
|
||||
'''.stripIndent()
|
||||
|
||||
when:
|
||||
def result = gradle.run(task: "verifyRunConfigs")
|
||||
|
||||
then:
|
||||
result.task(":verifyRunConfigs").outcome == SUCCESS
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user