Skip to content

Commit 88cefc6

Browse files
committed
Implement support for handling 26.1 versions of NeoForm and Userdev
1 parent 20cd897 commit 88cefc6

14 files changed

Lines changed: 212 additions & 34 deletions

File tree

common/src/main/java/net/neoforged/gradle/common/runtime/naming/tasks/ApplyOfficialMappingsToCompiledJar.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public abstract class ApplyOfficialMappingsToCompiledJar extends DefaultExecute
2626
public ApplyOfficialMappingsToCompiledJar() {
2727
super();
2828

29-
getExecutingJar().fileProvider(ToolUtilities.resolveTool(getProject(), Tools::getAutoRenamingTool));
29+
getExecutingClasspath().from(ToolUtilities.resolveTool(getProject(), Tools::getAutoRenamingTool));
3030
getProgramArguments().set(getShouldReverseMappings().map(shouldReverse -> {
3131
final List<String> result = Lists.newArrayList(RenameConstants.DEFAULT_PROGRAMM_ARGS);
3232
if (shouldReverse) {

common/src/main/java/net/neoforged/gradle/common/runtime/tasks/BinaryAccessTransformer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public BinaryAccessTransformer() {
2626

2727
setDescription("Runs the access transformer on the decompiled sources.");
2828

29-
getExecutingJar().fileProvider(ToolUtilities.resolveTool(getProject(), Tools::getAccessTransformer));
29+
getExecutingClasspath().from(ToolUtilities.resolveTool(getProject(), Tools::getAccessTransformer));
3030
getRuntimeProgramArguments().convention(
3131
getInputFile().map(inputFile -> {
3232
final List<String> args = Lists.newArrayList();

common/src/main/java/net/neoforged/gradle/common/runtime/tasks/DefaultExecute.java

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import net.neoforged.gradle.common.services.caching.jobs.ICacheableJob;
55
import net.neoforged.gradle.dsl.common.tasks.Execute;
66
import net.neoforged.gradle.util.TransformerUtils;
7+
import org.gradle.api.file.RegularFile;
78
import org.gradle.api.file.RegularFileProperty;
89
import org.gradle.api.provider.ListProperty;
910
import org.gradle.api.provider.Property;
@@ -33,10 +34,20 @@ public DefaultExecute() {
3334
getConsoleLogFileName().convention(getArguments().getOrDefault("console.log", getProviderFactory().provider(() -> "console.log")));
3435
getConsoleLogFile().convention(getOutputDirectory().flatMap(d -> getConsoleLogFileName().map(d::file)));
3536

36-
getMainClass().convention(getExecutingJar().map(TransformerUtils.guardWithResource(
37-
jarFile -> jarFile.getManifest().getMainAttributes().getValue(Attributes.Name.MAIN_CLASS),
38-
f -> new JarFile(f.getAsFile())
39-
)));
37+
getMainClass().convention(
38+
getExecutingClasspath().getElements()
39+
.map(e -> {
40+
if (e.isEmpty())
41+
return null;
42+
43+
return e.iterator().next();
44+
})
45+
.filter(fsl -> fsl != null && fsl.getAsFile().isFile())
46+
.map(TransformerUtils.guardWithResource(
47+
jarFile -> jarFile.getManifest().getMainAttributes().getValue(Attributes.Name.MAIN_CLASS),
48+
f -> new JarFile(f.getAsFile())
49+
))
50+
);
4051

4152
getRuntimeProgramArguments().convention(getProgramArguments());
4253
getMultiRuntimeArguments().convention(getMultiArguments().AsMap());

common/src/main/java/net/neoforged/gradle/common/runtime/tasks/JavaSourceTransformer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public JavaSourceTransformer() {
3131
getStubs().convention(getOutputDirectory().map(dir -> dir.file("stubs.jar")));
3232
getParchmentConflictPrefix().convention("p_");
3333

34-
getExecutingJar().set(ToolUtilities.resolveTool(getProject(), getProject().getExtensions().getByType(Subsystems.class).getTools().getJST().get()));
34+
getExecutingClasspath().from(ToolUtilities.resolveTool(getProject(), getProject().getExtensions().getByType(Subsystems.class).getTools().getJST().get()));
3535

3636
getTransformed().convention(getOutputDirectory().map(output -> output.dir("transformed")));
3737

dsl/common/src/main/groovy/net/neoforged/gradle/dsl/common/tasks/Execute.groovy

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ interface Execute extends WithWorkspace, WithOutput, WithJavaVersion, ExecuteSpe
3636
Provider<String> argument = runtimeArguments.get(argName)
3737
if (argument != null) {
3838
try {
39-
return Lists.newArrayList(argument.get())
39+
return Lists.newArrayList(matcher.replaceAll(argument.get()))
4040
} catch (Exception e) {
4141
throw new RuntimeException("Failed to get runtime argument " + argName, e)
4242
}
@@ -101,7 +101,7 @@ interface Execute extends WithWorkspace, WithOutput, WithJavaVersion, ExecuteSpe
101101
final List<String> jvmArgs,
102102
final List<String> runArgs,
103103
String executable,
104-
String classPath,
104+
final Set<File> classPath,
105105
String workingDirectory,
106106
String mainClass
107107
) {
@@ -113,7 +113,7 @@ interface Execute extends WithWorkspace, WithOutput, WithJavaVersion, ExecuteSpe
113113
final List<String> jvmArgs,
114114
final List<String> runArgs,
115115
String executable,
116-
String classPath,
116+
final Set<File> classPath,
117117
String workingDirectory,
118118
String mainClass
119119
) {
@@ -127,7 +127,7 @@ interface Execute extends WithWorkspace, WithOutput, WithJavaVersion, ExecuteSpe
127127
for (String arg : jvmArgs) {
128128
script.append(" ").append('"').append(arg.replace("\"", "\\\"")).append('"')
129129
}
130-
script.append(" -cp \"").append(classPath).append("\"")
130+
script.append(" -cp \"").append(classPath.join(":")).append("\"")
131131
script.append(" ").append(mainClass)
132132
for (String arg : runArgs) {
133133
script.append(" ").append('"').append(arg.replace("\"", "\\\"")).append('"')
@@ -143,7 +143,7 @@ interface Execute extends WithWorkspace, WithOutput, WithJavaVersion, ExecuteSpe
143143
final List<String> jvmArgs,
144144
final List<String> runArgs,
145145
String executable,
146-
String classPath,
146+
final Set<File> classPath,
147147
String workingDirectory,
148148
String mainClass
149149
) {
@@ -157,7 +157,7 @@ interface Execute extends WithWorkspace, WithOutput, WithJavaVersion, ExecuteSpe
157157
for (String arg : jvmArgs) {
158158
script.append(' "').append(arg.replace('"', '""')).append('"')
159159
}
160-
script.append(" -cp \"").append(classPath).append("\"")
160+
script.append(" -cp \"").append(classPath.join(";")).append("\"")
161161
script.append(" ").append(mainClass)
162162
for (String arg : runArgs) {
163163
script.append(' "').append(arg.replace('"', '""')).append('"')
@@ -197,7 +197,7 @@ interface Execute extends WithWorkspace, WithOutput, WithJavaVersion, ExecuteSpe
197197
writer.println("JVM Args: " + jvmArgs.get().stream().map(quote).collect(Collectors.joining(", ")))
198198
writer.println("Run Args: " + programArgs.get().stream().map(quote).collect(Collectors.joining(", ")))
199199
writer.println("JVM: " + executable.get())
200-
writer.println("Classpath: " + me.getExecutingJar().get().getAsFile().getAbsolutePath())
200+
writer.println("Classpath: " + me.getExecutingClasspath().getFiles().join(", "))
201201
writer.println("Working Dir: " + me.getOutputDirectory().get().getAsFile().getAbsolutePath())
202202
writer.println("Main Class: " + mainClass.get())
203203
writer.println("Program log file: " + logFile.getAbsolutePath())
@@ -208,15 +208,15 @@ interface Execute extends WithWorkspace, WithOutput, WithJavaVersion, ExecuteSpe
208208
jvmArgs.get(),
209209
programArgs.get(),
210210
executable.get(),
211-
me.getExecutingJar().get().getAsFile().getAbsolutePath(),
211+
me.getExecutingClasspath().getFiles(),
212212
me.getOutputDirectory().get().getAsFile().getAbsolutePath(),
213213
mainClass.get()
214214
)
215215

216216
java.executable(executable.get())
217217
java.setJvmArgs(jvmArgs.get())
218218
java.setArgs(programArgs.get())
219-
java.setClasspath(me.getObjectFactory().fileCollection().from(me.getExecutingJar().get()))
219+
java.setClasspath(me.getExecutingClasspath())
220220
java.setWorkingDir(me.getOutputDirectory().get())
221221
java.getMainClass().set(mainClass)
222222
java.setStandardOutput(standard_out)

dsl/common/src/main/groovy/net/neoforged/gradle/dsl/common/tasks/specifications/ExecuteSpecification.groovy

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package net.neoforged.gradle.dsl.common.tasks.specifications
22

33
import net.neoforged.gdi.annotations.DSLProperty
4+
import org.gradle.api.file.ConfigurableFileCollection
45
import org.gradle.api.file.DirectoryProperty
56
import org.gradle.api.file.FileTree
67
import org.gradle.api.file.RegularFileProperty
@@ -33,14 +34,14 @@ interface ExecuteSpecification extends ProjectSpecification, OutputSpecification
3334
ListProperty<String> getJvmArguments();
3435

3536
/**
36-
* Defines the path to the jar that will be executed.
37+
* Defines the paths to the jars that will be executed.
3738
*
38-
* @return The path to the jar.
39+
* @return The paths to the jars.
3940
*/
40-
@InputFile
41+
@InputFiles
4142
@PathSensitive(PathSensitivity.NONE)
4243
@DSLProperty
43-
RegularFileProperty getExecutingJar();
44+
ConfigurableFileCollection getExecutingClasspath();
4445

4546
/**
4647
* Defines the main class that will be executed.

dsl/common/src/main/groovy/net/neoforged/gradle/dsl/common/util/RegexUtils.groovy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,5 @@ import static java.util.regex.Pattern.compile
99
@CompileStatic
1010
class RegexUtils {
1111

12-
public static final Pattern REPLACE_PATTERN = compile('^\\{(\\w+)}$')
12+
public static final Pattern REPLACE_PATTERN = compile('\\{(\\w+)}')
1313
}

dsl/neoform/src/main/groovy/net/neoforged/gradle/dsl/neoform/configuration/NeoFormConfigConfigurationSpecV1.java

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
import com.google.gson.*;
2424

25+
import groovy.lang.GString;
2526
import net.neoforged.gradle.dsl.common.configuration.VersionedConfiguration;
2627
import net.neoforged.gradle.util.UrlConstants;
2728
import org.gradle.api.tasks.Input;
@@ -100,6 +101,11 @@ public Map<String, List<Step>> getSteps() {
100101
}
101102

102103
public List<Step> getSteps(String side) {
104+
if (spec >= 6 && steps != null && !steps.containsKey(side) && steps.size() == 1) {
105+
//From v6 on forward there is only one steps list, does not matter what you want.
106+
return steps.values().iterator().next();
107+
}
108+
103109
List<Step> ret = steps == null ? null : steps.get(side);
104110
return ret == null ? Collections.emptyList() : ret;
105111
}
@@ -175,9 +181,15 @@ public static class Function {
175181
@Nullable
176182
protected String repo; //Maven repo to download the jar from
177183
@Nullable
184+
protected List<String> classpath;
185+
@Nullable
178186
protected List<String> args;
179187
@Nullable
180188
protected List<String> jvmargs;
189+
@Nullable
190+
protected String main_class;
191+
@Nullable
192+
protected Integer java_version;
181193

182194
public Function()
183195
{
@@ -233,5 +245,38 @@ public List<String> getJvmArgs() {
233245
public void setJvmArgs(List<String> value) {
234246
this.jvmargs = value;
235247
}
248+
249+
@Nullable
250+
public List<String> getClasspath()
251+
{
252+
return classpath;
253+
}
254+
255+
public void setClasspath(@Nullable final List<String> classpath)
256+
{
257+
this.classpath = classpath;
258+
}
259+
260+
@Nullable
261+
public String getMain_class()
262+
{
263+
return main_class;
264+
}
265+
266+
public void setMain_class(@Nullable final String main_class)
267+
{
268+
this.main_class = main_class;
269+
}
270+
271+
@Nullable
272+
public Integer getJava_version()
273+
{
274+
return java_version;
275+
}
276+
277+
public void setJava_version(@Nullable final Integer java_version)
278+
{
279+
this.java_version = java_version;
280+
}
236281
}
237282
}

neoform/src/functionalTest/groovy/net/neoforged/gradle/neoform/FunctionalTests.groovy

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import org.gradle.testkit.runner.TaskOutcome
66

77
class FunctionalTests extends BuilderBasedTestSpecification {
88

9-
private static final String NEOFORM_VERSION = "1.20.2-20230921.152923"
9+
private static final String NEOFORM_VERSION = "26.1-snapshot-1-3"
1010

1111
@Override
1212
protected void configurePluginUnderTest() {
@@ -18,10 +18,10 @@ class FunctionalTests extends BuilderBasedTestSpecification {
1818
given:
1919
def project = create "neoform-can-run-clean-build", {
2020
it.build("""
21-
java.toolchain.languageVersion = JavaLanguageVersion.of(21)
21+
java.toolchain.languageVersion = JavaLanguageVersion.of(25)
2222
2323
dependencies {
24-
implementation 'net.minecraft:neoform_client:${NEOFORM_VERSION}'
24+
implementation 'net.minecraft:neoform_joined:${NEOFORM_VERSION}'
2525
}
2626
""")
2727
it.withToolchains()
@@ -31,6 +31,8 @@ class FunctionalTests extends BuilderBasedTestSpecification {
3131
when:
3232
def run = project.run {
3333
it.tasks(':clean', ':build')
34+
it.stacktrace()
35+
it.debug()
3436
}
3537

3638
then:
@@ -42,12 +44,12 @@ class FunctionalTests extends BuilderBasedTestSpecification {
4244
given:
4345
def project = create "neoform-compile-with-ats", {
4446
it.build("""
45-
java.toolchain.languageVersion = JavaLanguageVersion.of(21)
47+
java.toolchain.languageVersion = JavaLanguageVersion.of(25)
4648
4749
minecraft.accessTransformers.file rootProject.file('src/main/resources/META-INF/accesstransformer.cfg')
4850
4951
dependencies {
50-
implementation 'net.minecraft:neoform_client:${NEOFORM_VERSION}'
52+
implementation 'net.minecraft:neoform_joined:${NEOFORM_VERSION}'
5153
}
5254
""")
5355
it.file("src/main/resources/META-INF/accesstransformer.cfg", """public-f net.minecraft.client.Minecraft LOGGER""")
@@ -79,10 +81,10 @@ class FunctionalTests extends BuilderBasedTestSpecification {
7981
given:
8082
def project = create "neoform-compile-with-ats", {
8183
it.build("""
82-
java.toolchain.languageVersion = JavaLanguageVersion.of(21)
84+
java.toolchain.languageVersion = JavaLanguageVersion.of(25)
8385
8486
dependencies {
85-
implementation 'net.minecraft:neoform_client:${NEOFORM_VERSION}'
87+
implementation 'net.minecraft:neoform_joined:${NEOFORM_VERSION}'
8688
}
8789
""")
8890

neoform/src/main/java/net/neoforged/gradle/neoform/dependency/NeoFormDependencyManager.java

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import java.util.Collections;
1717
import java.util.Objects;
1818
import java.util.Optional;
19+
import java.util.regex.Pattern;
1920

2021
/**
2122
* This class installs a dependency replacement handler that replaces the following dependencies with the outputs
@@ -102,7 +103,11 @@ private static NeoFormTarget getNeoFormTargetFromDependency(ModuleDependency dep
102103
return null;
103104
}
104105

105-
return new NeoFormTarget(dependency.getVersion(), distributionType);
106+
var target = new NeoFormTarget(dependency.getVersion(), distributionType);
107+
if (target.isValid())
108+
return target;
109+
110+
return null;
106111
}
107112

108113
private static boolean hasMatchingArtifact(ModuleDependency externalModuleDependency) {
@@ -130,6 +135,21 @@ public NeoFormTarget(String version, DistributionType distribution) {
130135
this.version = version;
131136
this.distribution = distribution;
132137
}
138+
139+
public boolean isValid() {
140+
//Check if we are minecraft 26.x or later.
141+
if (Objects.equals(version.substring(2, 3), ".")) {
142+
var mcYear = version.substring(0, 2);
143+
try {
144+
var yearParsed = Integer.parseInt(mcYear);
145+
return yearParsed >= 26 && this.distribution == DistributionType.JOINED;
146+
} catch (Exception ignored) {
147+
return true;
148+
}
149+
}
150+
151+
return true;
152+
}
133153
}
134-
154+
135155
}

0 commit comments

Comments
 (0)