Skip to content

Commit

Permalink
Merge branch 'NG_7.0' into NG_7.0
Browse files Browse the repository at this point in the history
  • Loading branch information
marchermans authored Apr 28, 2024
2 parents 0dbed1e + b483eb1 commit 06b7852
Show file tree
Hide file tree
Showing 15 changed files with 312 additions and 140 deletions.
1 change: 0 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ version = gradleutils.version.toString()

//We hard coded the version of the gradle wrapper here.
tasks.named('wrapper', Wrapper).configure { Wrapper wrapperTask ->
wrapperTask.gradleVersion = project.gradle_version
wrapperTask.distributionType = Wrapper.DistributionType.ALL
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ public AccessTransformer() {
@PathSensitive(PathSensitivity.NONE)
public abstract RegularFileProperty getInputFile();


@InputFiles
@PathSensitive(PathSensitivity.NONE)
public abstract ConfigurableFileCollection getTransformers();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ public DefaultRuntime() {
Map.Entry::getKey,
entry -> getNeoFormArchive()
.getAsFileTree()
.matching(archive -> archive.include(entry.getValue())
)))));
.matching(archive -> archive.include(entry.getValue()))
))));

getOutputDirectory().finalizeValueOnRead();
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import net.neoforged.gradle.dsl.common.util.CommonRuntimeUtils;
import net.neoforged.gradle.dsl.common.util.GameArtifact;
import net.neoforged.gradle.util.StringCapitalizationUtils;
import org.gradle.api.file.ConfigurableFileCollection;
import org.gradle.api.file.EmptyFileVisitor;
import org.gradle.api.file.FileTree;
import org.gradle.api.file.FileVisitDetails;
Expand All @@ -26,52 +27,22 @@ private CommonRuntimeTaskUtils() {
}

public static TaskProvider<? extends AccessTransformer> createAccessTransformer(Definition<?> definition, String namePreFix, File workspaceDirectory, Consumer<TaskProvider<? extends Runtime>> dependentTaskConfigurationHandler, FileTree files, Collection<String> data) {
final Collection<TaskProvider<? extends WithOutput>> fileProducingTasks = new ArrayList<>();
final Map<String, Integer> indexes = new HashMap<>();

files.visit(new EmptyFileVisitor() {
@Override
public void visitFile(@NotNull FileVisitDetails fileDetails) {
indexes.compute(fileDetails.getName(), (s, index) -> index == null ? 0 : index + 1);
final int index = indexes.get(fileDetails.getName());

final String name = CommonRuntimeUtils.buildTaskName(definition.getSpecification(), namePreFix + "AccessTransformerProvider" + fileDetails.getName() + (index == 0 ? "" : "_" + index));

final TaskProvider<? extends WithOutput> provider = definition.getSpecification().getProject().getTasks().register(name, ArtifactProvider.class, task -> {
task.getInputFiles().from(
files.matching(f -> f.include(fileDetails.getPath()))
);
String outputFileName = fileDetails.getName();
if (index > 0) {
int extensionDot = outputFileName.lastIndexOf('.');
if (extensionDot == -1) {
outputFileName += "_" + index;
} else {
outputFileName = outputFileName.substring(0, extensionDot) + "_" + index + outputFileName.substring(extensionDot);
}
}
task.getOutputFileName().set(outputFileName);
task.getOutput().set(new File(workspaceDirectory, "accesstransformers/" + namePreFix + "/" + outputFileName));
});

fileProducingTasks.add(provider);
}
});

final TaskProvider<AccessTransformerFileGenerator> generator;
if (!data.isEmpty()) {
final TaskProvider<AccessTransformerFileGenerator> generator = definition.getSpecification().getProject().getTasks().register(CommonRuntimeUtils.buildTaskName(definition.getSpecification(), namePreFix + "AccessTransformerGenerator"), AccessTransformerFileGenerator.class, task -> {
generator = definition.getSpecification().getProject().getTasks().register(CommonRuntimeUtils.buildTaskName(definition.getSpecification(), namePreFix + "AccessTransformerGenerator"), AccessTransformerFileGenerator.class, task -> {
task.getOutput().set(new File(workspaceDirectory, "accesstransformers/" + namePreFix + "/_script-access-transformer.cfg"));
task.getAdditionalTransformers().set(data);
});
dependentTaskConfigurationHandler.accept(generator);
fileProducingTasks.add(generator);
} else {
generator = null;
}

return definition.getSpecification().getProject().getTasks().register(CommonRuntimeUtils.buildTaskName(definition.getSpecification(), String.format("apply%sAccessTransformer", StringCapitalizationUtils.capitalize(namePreFix))), AccessTransformer.class, task -> {
for (TaskProvider<? extends WithOutput> fileRemapTask : fileProducingTasks) {
task.getTransformers().from(fileRemapTask.flatMap(WithOutput::getOutput));
task.dependsOn(fileRemapTask);
task.getTransformers().from(files);
if (generator != null) {
task.getTransformers().from(generator.flatMap(WithOutput::getOutput));
task.dependsOn(generator);
}
});
}
Expand Down
3 changes: 0 additions & 3 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@ org.gradle.caching=true
# Default project properties.
group=net.neoforged.gradle

#Gradle properties
gradle_version=8.0

#Java properties
java_version=8

Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-all.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down
20 changes: 10 additions & 10 deletions gradlew.bat
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@ set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1
if %ERRORLEVEL% equ 0 goto execute

echo.
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
echo. 1>&2
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2
echo. 1>&2
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
echo location of your Java installation. 1>&2

goto fail

Expand All @@ -57,11 +57,11 @@ set JAVA_EXE=%JAVA_HOME%/bin/java.exe

if exist "%JAVA_EXE%" goto execute

echo.
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
echo. 1>&2
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2
echo. 1>&2
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
echo location of your Java installation. 1>&2

goto fail

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,9 @@ public Map<String, String> buildRunInterpolationData(RunImpl run) {
final Map<String, String> interpolationData = new HashMap<>(super.buildRunInterpolationData(run));

interpolationData.put("mcp_version", neoform.getVersion());
interpolationData.put("mcp_mappings", getSpecification().getNeoFormArchive()
.matching(artifact -> artifact.include("config/joined.srg"))
.getSingleFile().getAbsolutePath());
// NeoForge still references this in the environment variable MCP_MAPPINGS, which is unused since 1.20.2
// Remove this interpolation placeholder once NeoForge removes the environment variable from its config.json
interpolationData.put("mcp_mappings", "UNUSED_DEPRECATED");
return interpolationData;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ private static TaskProvider<? extends WithOutput> createBuiltIn(final NeoFormRun
}
})
);
fileTreeSource.getTreePrefix().set(task.getSymbolicDataSources().map(data -> data.get("inject")));
return fileTreeSource;
})
);
Expand Down Expand Up @@ -168,7 +169,7 @@ private static TaskProvider<? extends Runtime> createDecompile(NeoFormRuntimeSpe

// Filter out decompiler arguments that aren't related to its output (log-level and thread-count)
List<String> decompilerArgs = new ArrayList<>(function.getArgs());
decompilerArgs.removeIf(arg -> arg.startsWith("-log=") || arg.startsWith("-thr="));
decompilerArgs.removeIf(arg -> arg.startsWith("--log-level") || arg.startsWith("-log=") || arg.startsWith("--thread-count") || arg.startsWith("-thr="));

// Retrieve the default memory size from the JVM arguments configured in NeoForm
String defaultMaxMemory = "4g";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@
import net.neoforged.gradle.util.ZipBuildingFileTreeVisitor;
import org.gradle.api.file.ConfigurableFileCollection;
import org.gradle.api.file.FileTree;
import org.gradle.api.tasks.InputFiles;
import org.gradle.api.tasks.PathSensitive;
import org.gradle.api.tasks.PathSensitivity;
import org.gradle.api.file.FileVisitDetails;
import org.gradle.api.provider.Property;
import org.gradle.api.tasks.*;
import org.jetbrains.annotations.Nullable;

import java.io.IOException;
import java.nio.file.Files;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;

/**
Expand All @@ -22,10 +23,15 @@ public abstract class InjectFromFileTreeSource extends AbstractInjectSource {
@PathSensitive(PathSensitivity.NONE)
public abstract ConfigurableFileCollection getFiles();

@Optional
@Input
public abstract Property<String> getTreePrefix();

@Override
public byte @Nullable [] tryReadFile(String path) throws IOException {
final String lookupPath = buildTreePrefix() + path;
final FileTree matching = getFiles().getAsFileTree().matching(createFilter())
.matching(pattern -> pattern.include(path));
.matching(pattern -> pattern.include(lookupPath));
if (matching.isEmpty()) {
return null;
}
Expand All @@ -39,6 +45,42 @@ public void copyTo(ZipOutputStream out) throws IOException {
}

final FileTree source = getFiles().getAsFileTree().matching(createFilter());
source.visit(new ZipBuildingFileTreeVisitor(out));
source.visit(new ZipBuildingFileTreeVisitor(out) {
@Override
protected ZipEntry createDirectory(FileVisitDetails fileVisitDetails) {
String path = fileVisitDetails.getRelativePath().getPathString();
if (path.startsWith(buildTreePrefix())) {
path = path.substring(buildTreePrefix().length());
}

if (!path.endsWith("/")) {
path += "/";
}

return new ZipEntry(path);
}

@Override
protected ZipEntry createFile(FileVisitDetails fileVisitDetails) {
String path = fileVisitDetails.getRelativePath().getPathString();
if (path.startsWith(buildTreePrefix())) {
path = path.substring(buildTreePrefix().length());
}

return new ZipEntry(path);
}
});
}

private String buildTreePrefix() {
if (getTreePrefix().isPresent()) {
final String prefix = getTreePrefix().get();
if (!prefix.endsWith("/")) {
return prefix + "/";
}
return prefix;
}

return "";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -538,8 +538,7 @@ public void runtime(final String neoFormVersion, Directory patches, Directory re
//Note: We can not use a 'configureEach' here, because this causes issues with the config cache.
userdevProfile.runType("client", type -> {
type.getEnvironmentVariables().put("MOD_CLASSES", "{source_roots}");
type.getEnvironmentVariables().put("MCP_MAPPINGS", "{mcp_mappings}");


type.getIsClient().set(true);
type.getIsGameTest().set(true);
type.getSystemProperties().put("neoforge.enableGameTest", "true");
Expand All @@ -557,8 +556,7 @@ public void runtime(final String neoFormVersion, Directory patches, Directory re
});
userdevProfile.runType("server", type -> {
type.getEnvironmentVariables().put("MOD_CLASSES", "{source_roots}");
type.getEnvironmentVariables().put("MCP_MAPPINGS", "{mcp_mappings}");


type.getIsServer().set(true);

type.getArguments().add("--launchTarget");
Expand All @@ -568,8 +566,7 @@ public void runtime(final String neoFormVersion, Directory patches, Directory re
});
userdevProfile.runType("gameTestServer", type -> {
type.getEnvironmentVariables().put("MOD_CLASSES", "{source_roots}");
type.getEnvironmentVariables().put("MCP_MAPPINGS", "{mcp_mappings}");


type.getIsServer().set(true);
type.getIsGameTest().set(true);
type.getSystemProperties().put("neoforge.enableGameTest", "true");
Expand All @@ -583,8 +580,7 @@ public void runtime(final String neoFormVersion, Directory patches, Directory re
});
userdevProfile.runType("data", type -> {
type.getEnvironmentVariables().put("MOD_CLASSES", "{source_roots}");
type.getEnvironmentVariables().put("MCP_MAPPINGS", "{mcp_mappings}");


type.getIsDataGenerator().set(true);

type.getArguments().add("--launchTarget");
Expand Down
Loading

0 comments on commit 06b7852

Please sign in to comment.