Skip to content

Commit 0435e04

Browse files
authored
Merge pull request #3 from ldtteam/feature/dynamic-data-runs
2 parents 297871c + a764f91 commit 0435e04

3 files changed

Lines changed: 105 additions & 43 deletions

File tree

modules/neogradle/src/main/java/com/ldtteam/tableau/extensions/NeoGradleExtension.java

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,18 @@
22

33
import com.ldtteam.tableau.common.extensions.ProjectExtension;
44
import com.ldtteam.tableau.common.extensions.VersioningExtension;
5-
import com.ldtteam.tableau.neogradle.NeoGradlePlugin;
65
import com.ldtteam.tableau.scripting.extensions.TableauScriptingExtension;
76
import org.gradle.api.Project;
87
import org.gradle.api.file.ConfigurableFileCollection;
98
import org.gradle.api.plugins.ExtensionAware;
109
import org.gradle.api.provider.ListProperty;
1110
import org.gradle.api.provider.Property;
1211
import org.gradle.api.tasks.bundling.Jar;
12+
import org.jetbrains.annotations.NotNull;
1313

1414
import javax.inject.Inject;
1515
import java.util.ArrayList;
16+
import java.util.Arrays;
1617
import java.util.List;
1718
import java.util.Map;
1819

@@ -84,6 +85,13 @@ public NeoGradleExtension(final Project project) {
8485

8586
//Default to no additional data gen mods.
8687
getAdditionalDataGenMods().convention(new ArrayList<>());
88+
89+
//Default to the data generation runs defined in the property, if not set default to the current modern Minecraft run configuration.
90+
getDataGenerationRuns().convention(
91+
project.getProviders().gradleProperty("neoforge.data.runs").map(
92+
s -> Arrays.stream(s.split(",")).toList()
93+
).orElse(List.of("clientData", "serverData"))
94+
);
8795
}
8896

8997
/**
@@ -123,28 +131,28 @@ public void interfaceInjection(Object file) {
123131
*
124132
* @return The version of NeoForge to use.
125133
*/
126-
public abstract Property<String> getNeoForgeVersion();
134+
public abstract Property<@NotNull String> getNeoForgeVersion();
127135

128136
/**
129137
* The classifier to use for the primary jar.
130138
*
131139
* @return The classifier for the primary jar.
132140
*/
133-
public abstract Property<String> getPrimaryJarClassifier();
141+
public abstract Property<@NotNull String> getPrimaryJarClassifier();
134142

135143
/**
136144
* Whether, to use random player names, when starting the client.
137145
*
138146
* @return Indicates whether the project should use random player names.
139147
*/
140-
public abstract Property<Boolean> getUseRandomPlayerNames();
148+
public abstract Property<@NotNull Boolean> getUseRandomPlayerNames();
141149

142150
/**
143151
* The additional data gen mods to use.
144152
*
145153
* @return The additional data gen mods to use.
146154
*/
147-
public abstract ListProperty<String> getAdditionalDataGenMods();
155+
public abstract ListProperty<@NotNull String> getAdditionalDataGenMods();
148156

149157
/**
150158
* Adds a data gen mod to the project.
@@ -160,5 +168,15 @@ public void additionalDataGenMod(String mod) {
160168
*
161169
* @return Indicates whether the project is an FML library.
162170
*/
163-
public abstract Property<Boolean> getIsLibrary();
171+
public abstract Property<@NotNull Boolean> getIsLibrary();
172+
173+
/**
174+
* Defines the data generation runs to configure.
175+
* Generally match up with the run types exposed by neoforge.
176+
* <p>
177+
* This is by default read from a gradle property `neoforge.runs.data`, if that is not supplied it is currently by default to clientData and serverData.
178+
* </p>
179+
* @return The data generation run.
180+
*/
181+
public abstract ListProperty<@NotNull String> getDataGenerationRuns();
164182
}

modules/neogradle/src/main/java/com/ldtteam/tableau/neogradle/NeoGradleProjectPlugin.java

Lines changed: 48 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@
1212

1313
import javax.inject.Inject;
1414

15+
import net.neoforged.gradle.common.runs.run.RunImpl;
1516
import net.neoforged.gradle.dsl.common.extensions.sourceset.RunnableSourceSet;
17+
import net.neoforged.gradle.dsl.common.runs.run.Run;
1618
import org.gradle.api.Plugin;
1719
import org.gradle.api.Project;
1820
import org.gradle.api.Rule;
@@ -210,43 +212,12 @@ private void configureRuns(@NotNull Project target) {
210212
//Ensure a server run is created.
211213
runManager.maybeCreate("server");
212214

213-
//Ensure a data gen run is created.
214-
runManager.maybeCreate("data");
215-
216-
//Configure the data run to have the correct arguments.
217-
runManager.named("data", run -> {
218-
//Add the arguments for the data gen run.
219-
//By default, these are the arguments for the main mod, its output directory, and the default existing resources' directory.
220-
run.getArguments().addAll(
221-
projectExtension.getModId().map(modId -> {
222-
List<String> dataRunArguments = new ArrayList<>();
223-
dataRunArguments.add("--mod");
224-
dataRunArguments.add(modId);
225-
dataRunArguments.add("--all");
226-
dataRunArguments.add("--output");
227-
dataRunArguments.add(target.file("src/datagen/generated/%s".formatted(modId)).getAbsolutePath());
228-
dataRunArguments.add("--existing");
229-
dataRunArguments.add(target.file("src/main/resources/").getAbsolutePath());
230-
return dataRunArguments;
231-
})
232-
);
233-
234-
//Add the arguments for the additional data gen mods.
235-
run.getArguments().addAll(
236-
extension.getAdditionalDataGenMods().map(mods -> {
237-
if (mods.isEmpty()) {
238-
//When no additional data gen mods are set, we don't need to add any arguments.
239-
return new ArrayList<>();
240-
}
241-
242-
//When additional data gen mods are set, we need to add the arguments for each mod.
243-
//Per mod, we need to add the "--existing-mod" argument followed by the mod id.
244-
return mods.stream()
245-
.flatMap(modId -> Stream.of("--existing-mod", modId))
246-
.collect(Collectors.toList());
247-
})
248-
);
249-
});
215+
//Ensure that all configured data runs are created.
216+
runManager.addAllLater(
217+
extension.getDataGenerationRuns().map(names -> names.stream()
218+
.map(name -> createDataRun(target, runManager, projectExtension, extension, name))
219+
.toList())
220+
);
250221

251222
//Ensure a game test server run is created.
252223
runManager.maybeCreate("gameTestServer");
@@ -291,6 +262,46 @@ private void configureRuns(@NotNull Project target) {
291262
});
292263
}
293264

265+
private static Run createDataRun(final @NotNull Project target, final RunManager runManager, final ProjectExtension projectExtension, final NeoGradleExtension extension,
266+
final String runName)
267+
{
268+
final Run run = target.getObjects().newInstance(RunImpl.class, target, runName);
269+
270+
//Add the arguments for the data gen run.
271+
//By default, these are the arguments for the main mod, its output directory, and the default existing resources' directory.
272+
run.getArguments().addAll(
273+
projectExtension.getModId().map(modId -> {
274+
List<String> dataRunArguments = new ArrayList<>();
275+
dataRunArguments.add("--mod");
276+
dataRunArguments.add(modId);
277+
dataRunArguments.add("--all");
278+
dataRunArguments.add("--output");
279+
dataRunArguments.add(target.file("src/datagen/generated/%s".formatted(modId)).getAbsolutePath());
280+
dataRunArguments.add("--existing");
281+
dataRunArguments.add(target.file("src/main/resources/").getAbsolutePath());
282+
return dataRunArguments;
283+
})
284+
);
285+
286+
//Add the arguments for the additional data gen mods.
287+
run.getArguments().addAll(
288+
extension.getAdditionalDataGenMods().map(mods -> {
289+
if (mods.isEmpty()) {
290+
//When no additional data gen mods are set, we don't need to add any arguments.
291+
return new ArrayList<>();
292+
}
293+
294+
//When additional data gen mods are set, we need to add the arguments for each mod.
295+
//Per mod, we need to add the "--existing-mod" argument followed by the mod id.
296+
return mods.stream()
297+
.flatMap(modId -> Stream.of("--existing-mod", modId))
298+
.collect(Collectors.toList());
299+
})
300+
);
301+
302+
return run;
303+
}
304+
294305
/**
295306
* Gets the library configuration for the given source set.
296307
* <p>

website/docs/03-guides/01-neoforge-configuration.mdx

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,3 +247,36 @@ tableau {
247247
```
248248
</TabItem>
249249
</Tabs>
250+
251+
## Configuring the runs which are used for data generation
252+
Different versions of minecraft use different way of running data generation.
253+
To be compatible with this, you can configure the data runs Tableau configures so it sets up the correct run types.
254+
255+
<Tabs groupId="gradle-code">
256+
<TabItem value="groovy" label="Groovy">
257+
```groovy title="build.gradle"
258+
tableau {
259+
neogradle {
260+
//Any value is possible
261+
dataGenerationRuns = ['data'] // for older versions of minecraft.
262+
dataGenerationRuns = ['clientData'] // for newer versions of minecraft, when you only want a client data run.
263+
dataGenerationRuns = ['clientData', 'serverData'] // for newer versions of minecraft, is also the default.
264+
}
265+
}
266+
```
267+
</TabItem>
268+
<TabItem value="kotlin" label="Kotlin">
269+
```kotlin title="build.gradle.kts"
270+
tableau {
271+
neogradle {
272+
//Any value is possible
273+
dataGenerationRuns.add("data") // for older versions of minecraft.
274+
dataGenerationRuns.add("clientData") // for newer versions of minecraft, when you only want a client data run.
275+
276+
dataGenerationRuns.add("clientData") // for newer versions of minecraft, is also the default.
277+
dataGenerationRuns.add("serverData") // for newer versions of minecraft, is also the default.
278+
}
279+
}
280+
```
281+
</TabItem>
282+
</Tabs>

0 commit comments

Comments
 (0)