Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
5 changes: 3 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -157,9 +157,10 @@ immaculate {
}
}

//Replace any FQN versions of javax.annotation.Nullable with the jetbrains variant
//Replace any FQN versions of javax/jetbrains @Nullable with the jspecify variant
custom 'jetbrainsNullablePatches', { String fileContents ->
fileContents.replace('@javax.annotation.Nullable', '@org.jetbrains.annotations.Nullable')
fileContents.replace('@javax.annotation.Nullable', '@org.jspecify.annotations.Nullable')
fileContents.replace('@org.jetbrains.annotations.Nullable', '@org.jspecify.annotations.Nullable')
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,14 @@ immaculate {
}

custom 'noNotNull', { String fileContents ->
if (fileContents.contains('@NotNull') || fileContents.contains('@Nonnull')) {
throw new GradleException('@NotNull and @Nonnull are disallowed.')
if (fileContents.contains('@NotNull') || fileContents.contains('@Nonnull') || fileContents.contains('@NonNull')) {
throw new GradleException('Non-nullability annotations are disallowed.')
}
}

custom 'jetbrainsNullable', { String fileContents ->
fileContents.replace('javax.annotation.Nullable', 'org.jetbrains.annotations.Nullable')
custom 'jspecifyNullable', { String fileContents ->
fileContents.replace('javax.annotation.Nullable', 'org.jspecify.annotations.Nullable')
fileContents.replace('org.jetbrains.annotations.Nullable', 'org.jspecify.annotations.Nullable')
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ abstract class CreateCleanArtifacts extends CreateMinecraftArtifacts {
@OutputFile
abstract RegularFileProperty getMergedMappings();

@OutputFile
abstract RegularFileProperty getClientMappings();

@Inject
public CreateCleanArtifacts() {
getAdditionalResults().put("node.downloadClient.output.output", getRawClientJar().getAsFile());
Expand All @@ -38,8 +41,6 @@ public CreateCleanArtifacts() {
getAdditionalResults().put("node.stripServer.output.output", getCleanServerJar().getAsFile());
getAdditionalResults().put("node.rename.output.output", getCleanJoinedJar().getAsFile());
getAdditionalResults().put("node.mergeMappings.output.output", getMergedMappings().getAsFile());

// TODO: does anyone care about this? they should be contained in the client mappings
//"--write-result", "node.downloadServerMappings.output.output:" + getServerMappings().get().getAsFile().getAbsolutePath()
getAdditionalResults().put("node.downloadClientMappings.output.output", getClientMappings().getAsFile());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import org.gradle.api.tasks.InputFile;
import org.gradle.api.tasks.OutputFile;
import org.gradle.api.tasks.TaskAction;
import org.jetbrains.annotations.Nullable;
import org.jspecify.annotations.Nullable;
import org.objectweb.asm.Opcodes;

/**
Expand Down
58 changes: 58 additions & 0 deletions buildSrc/src/main/java/net/neoforged/neodev/GenerateBaseJar.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package net.neoforged.neodev;

import javax.inject.Inject;
import org.gradle.api.file.ConfigurableFileCollection;
import org.gradle.api.file.RegularFileProperty;
import org.gradle.api.tasks.InputFile;
import org.gradle.api.tasks.InputFiles;
import org.gradle.api.tasks.JavaExec;
import org.gradle.api.tasks.Optional;
import org.gradle.api.tasks.OutputFile;
import org.gradle.api.tasks.PathSensitive;
import org.gradle.api.tasks.PathSensitivity;

/**
* Create the base jar file that will be diffed against the modified jar to create binary patch files.
*/
abstract class GenerateBaseJar extends JavaExec {
@Inject
public GenerateBaseJar() {}

@InputFiles
@PathSensitive(PathSensitivity.NONE)
abstract ConfigurableFileCollection getMinecraft();

/**
* The official Mojang mappings file.
*/
@InputFile
@PathSensitive(PathSensitivity.NONE)
@Optional
abstract RegularFileProperty getMappings();

/**
* The NeoForm mappings (either LZMA or ZIP data file), this can be empty to not apply NeoForm mappings.
*/
@InputFiles
@PathSensitive(PathSensitivity.NONE)
abstract ConfigurableFileCollection getNeoFormMappings();

@OutputFile
abstract RegularFileProperty getOutput();

@Override
public void exec() {
args("--task", "PROCESS_MINECRAFT_JAR");
for (var file : getMinecraft().getFiles()) {
args("--input", file.getAbsolutePath());
}
if (getMappings().isPresent()) {
args("--input-mappings", getMappings().get().getAsFile().getAbsolutePath());
}
args("--output", getOutput().get().getAsFile().getAbsolutePath());
if (!getNeoFormMappings().isEmpty()) {
args("--neoform-data", getNeoFormMappings().getSingleFile().getAbsolutePath());
}
super.exec();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,74 +6,90 @@
import java.io.IOException;
import javax.inject.Inject;
import org.gradle.api.GradleException;
import org.gradle.api.file.DirectoryProperty;
import org.gradle.api.file.RegularFileProperty;
import org.gradle.api.tasks.InputDirectory;
import org.gradle.api.provider.ListProperty;
import org.gradle.api.tasks.Input;
import org.gradle.api.tasks.InputFile;
import org.gradle.api.tasks.JavaExec;
import org.gradle.api.tasks.Optional;
import org.gradle.api.tasks.OutputFile;

abstract class GenerateBinaryPatches extends JavaExec {
@Inject
public GenerateBinaryPatches() {}

/**
* The jar file containing classes in the base state.
* The base against which the patches should be created for the client distribution.
*/
@InputFile
abstract RegularFileProperty getCleanJar();
abstract RegularFileProperty getBaseClientJar();

/**
* The jar file containing classes in the desired target state.
* The target jar that will be diffed against {@link #getBaseClientJar()} to create the patches for the
* client distribution.
*/
@InputFile
abstract RegularFileProperty getPatchedJar();
abstract RegularFileProperty getModifiedClientJar();

/**
* The base against which the patches should be created for the server distribution.
*/
@InputFile
abstract RegularFileProperty getMappings();
abstract RegularFileProperty getBaseServerJar();

/**
* The files in this optional directory are used to filter which binary patches should be created.
* <p>A binary patch is only created for a file from {@link #getPatchedJar()}, if a source patch (A corresponding file
* with {@code .java.patch} extension) is present in this directory, or if a class with the same path is present in
* {@link #getIncludeClassesJar()} (if set).
* <p>For inner classes, only the outermost class is checked against the filters.
* <p>If neither this nor {@link #getIncludeClassesJar()} are set, no filtering is applied.
* The target jar that will be diffed against {@link #getBaseServerJar()} to create the patches for the
* server distribution.
*/
@InputDirectory
@Optional
abstract DirectoryProperty getSourcePatchesFolder();
@InputFile
abstract RegularFileProperty getModifiedServerJar();

/**
* The base against which the patches should be created for the combined client+server distribution.
*/
@InputFile
abstract RegularFileProperty getBaseJoinedJar();

/**
* The list of files included in this optional Jar file is used to filter for which files binary patches should be created.
* <p>A binary patch is only created for a file from {@link #getPatchedJar()}, if a file with the same path is
* either present in this jar, or if a corresponding source patch is present in {@link #getSourcePatchesFolder()} (if set).
* <p>For inner classes, only the outermost class is checked against the filters.
* <p>If neither this nor {@link #getSourcePatchesFolder()} are set, no filtering is applied.
* The target jar that will be diffed against {@link #getBaseServerJar()} to create the patches for the
* combined client+server distribution.
*/
@InputFile
@Optional
abstract RegularFileProperty getIncludeClassesJar();
abstract RegularFileProperty getModifiedJoinedJar();

/**
* Ant-Style path patterns for paths to include in diffing.
*/
@Input
abstract ListProperty<String> getInclude();

/**
* Ant-Style path patterns for paths to exclude from diffing.
*/
@Input
abstract ListProperty<String> getExclude();

/**
* The location where the LZMA compressed binary patches are written to.
* Where the created patch bundle should be written to.
*/
@OutputFile
abstract RegularFileProperty getOutputFile();

@Override
public void exec() {
args("--clean", getCleanJar().get().getAsFile().getAbsolutePath());
args("--dirty", getPatchedJar().get().getAsFile().getAbsolutePath());
args("--srg", getMappings().get().getAsFile().getAbsolutePath());
args("--minimize");
if (getSourcePatchesFolder().isPresent()) {
args("--patches", getSourcePatchesFolder().get().getAsFile().getAbsolutePath());
args("--diff");
args("--base-client", getBaseClientJar().get().getAsFile().getAbsolutePath());
args("--base-server", getBaseServerJar().get().getAsFile().getAbsolutePath());
args("--base-joined", getBaseJoinedJar().get().getAsFile().getAbsolutePath());
args("--modified-client", getModifiedClientJar().get().getAsFile().getAbsolutePath());
args("--modified-server", getModifiedServerJar().get().getAsFile().getAbsolutePath());
args("--modified-joined", getModifiedJoinedJar().get().getAsFile().getAbsolutePath());
for (String pattern : getInclude().get()) {
args("--include", pattern);
}
if (getIncludeClassesJar().isPresent()) {
args("--include-classes", getIncludeClassesJar().get().getAsFile().getAbsolutePath());
for (String pattern : getExclude().get()) {
args("--exclude", pattern);
}
args("--optimize-constantpool");
args("--output", getOutputFile().get().getAsFile().getAbsolutePath());

var logFile = new File(getTemporaryDir(), "console.log");
Expand Down
47 changes: 47 additions & 0 deletions buildSrc/src/main/java/net/neoforged/neodev/ListBinaryPatches.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package net.neoforged.neodev;

import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import javax.inject.Inject;
import org.gradle.api.GradleException;
import org.gradle.api.file.RegularFileProperty;
import org.gradle.api.tasks.InputFile;
import org.gradle.api.tasks.JavaExec;
import org.gradle.api.tasks.OutputFile;

/**
* A debugging task for helping with analyzing how the patches were de-duped, and what is being patched.
*/
abstract class ListBinaryPatches extends JavaExec {
@Inject
public ListBinaryPatches() {}

/**
* The patch bundle to report on.
*/
@InputFile
public abstract RegularFileProperty getPatchBundle();

/**
* Where the created patch bundle report should be written to.
*/
@OutputFile
abstract RegularFileProperty getOutputFile();

@Override
public void exec() {
args("--list", "--patches", getPatchBundle().get().getAsFile().getAbsolutePath());

File reportFile = getOutputFile().getAsFile().get();
try (var out = new BufferedOutputStream(new FileOutputStream(reportFile))) {
setStandardOutput(out);
super.exec();
} catch (IOException e) {
throw new GradleException("Failed to list binary patches.", e);
}

getLogger().lifecycle("Wrote contents of patch bundle to " + reportFile.getAbsolutePath());
}
}
Loading
Loading