Skip to content
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Init v2
  • Loading branch information
jpenilla committed Nov 6, 2025
commit dffedabf9af92f61bde39483ccf841f392bacf0b
2 changes: 1 addition & 1 deletion .github/workflows/deploy-snapshot.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: Deploy Snapshot
on:
push:
branches: ['main']
branches: ['main', 'dev/v2']
paths-ignore:
- '.idea/**'
- 'license.txt'
Expand Down
3 changes: 2 additions & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

114 changes: 0 additions & 114 deletions codebook-cli/src/main/java/io/papermc/codebook/cli/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -96,81 +96,6 @@ static final class SelectedReports {
}
}

@CommandLine.ArgGroup(
multiplicity = "1",
heading = "%n%nThe remapper must be an executable tiny-remapper jar. "
+ "This is the 'fat' classifier when downloading from Maven. It can be provided several different ways, the simplest being to just "
+ "specify the Maven coordinates (with no classifier).%n")
private RemapperOptions remapper;

static final class RemapperOptions {
@CommandLine.Option(
names = {"-r", "--remapper-coords"},
paramLabel = "<art-coords>",
description =
"The Maven coordinates for the executable AutoRenamingTool jar to use for the remapping process.")
private @Nullable String remapperCoords;

@CommandLine.Option(
names = {"--remapper-file"},
paramLabel = "<art-file>",
description = "The executable AutoRenamingTool jar to use for the remapping process.")
private @Nullable Path remapperFile;

@CommandLine.Option(
names = "--remapper-uri",
paramLabel = "<art-uri>",
description =
"A download URL for the executable AutoRenamingTool jar to use for the remapping process.")
private @Nullable URI remapperUri;
}

@CommandLine.ArgGroup(
heading =
"%n%nMappings are required when not using the --mc-version option to automatically download a version. "
+ "They can still be optionally provided using one of the 2 mappings options below, "
+ "but one of either --mappings-file or --mappings-uri is required when using --input to manually specify a jar file.%n")
private @Nullable MappingsOptions mappings;

static final class MappingsOptions {
@CommandLine.Option(
names = {"-m", "--mappings-file"},
paramLabel = "<mappings-file>",
description = "The ProGuard mojmap mappings to use for base remapping.")
private @Nullable Path mappingsFile;

@CommandLine.Option(
names = "--mappings-uri",
paramLabel = "<mappings-uri>",
description = "A download URL for the ProGuard mojmap mappings to use for base remapping.")
private @Nullable URI mappingsUri;
}

@CommandLine.ArgGroup(
heading = "%n%nParameter mappings are always optional, and can be specified several different ways.%n")
private @Nullable ParamMappingsOptions paramMappings;

static final class ParamMappingsOptions {
@CommandLine.Option(
names = {"-p", "--params-coords"},
paramLabel = "<param-mappings-coords>",
description =
"The Maven coordinates for TinyV2 mappings to use for parameter remapping. This is the preferred option, as it allows omitting other details.")
private @Nullable String paramsCoords;

@CommandLine.Option(
names = {"--params-file"},
paramLabel = "<param-mappings-file>",
description = "The TinyV2 mappings to use for parameter remapping.")
private @Nullable Path paramsFile;

@CommandLine.Option(
names = "--params-uri",
paramLabel = "<param-mappings-uri>",
description = "A download URL for the TinyV2 mappings to use for parameter remapping.")
private @Nullable URI paramsUri;
}

@CommandLine.ArgGroup(exclusive = false)
private @Nullable UnpickOptions unpick;

Expand Down Expand Up @@ -348,10 +273,6 @@ public Integer call() {
}

private CodeBookContext createContext() {
if (this.remapper.remapperFile != null) {
this.verifyJarFile("Remapper", this.remapper.remapperFile);
}

if (this.inputs.inputFile != null) {
this.verifyJarFile("Input", this.inputs.inputFile.inputJar);

Expand All @@ -362,18 +283,6 @@ private CodeBookContext createContext() {
}
}

if (this.mappings == null && this.inputs.mcVersion == null) {
throw new UserErrorException("No base mappings file was provided, and no MC version was provided. "
+ "When not specifying an MC version, the base mappings file must be manually specified.");
}
if (this.mappings != null && this.mappings.mappingsFile != null) {
this.verifyFileExists("Mappings file", this.mappings.mappingsFile);
}

if (this.paramMappings != null && this.paramMappings.paramsFile != null) {
this.verifyFileExists("Param mappings file", this.paramMappings.paramsFile);
}

if (Files.isRegularFile(this.outputJar) && !this.forceWrite) {
throw new UserErrorException(
"Output jar file exists, will not overwrite because --force option was not provided: "
Expand All @@ -390,26 +299,6 @@ private CodeBookContext createContext() {
input = new CodeBookJarInput(this.inputs.inputFile.inputJar, classpath);
}

final @Nullable CodeBookResource remapper = this.getResource(
"AutoRenamingTool.jar",
this.remapper,
r -> r.remapperFile,
r -> r.remapperUri,
r -> new Coords(r.remapperCoords, "all", null, this.remapperMavenBaseUrl));
if (remapper == null) {
throw new UserErrorException("No remapper provided");
}

final @Nullable CodeBookResource mappings =
this.getResource("server_mappings.txt", this.mappings, m -> m.mappingsFile, m -> m.mappingsUri, null);

final @Nullable CodeBookResource paramMappings = this.getResource(
"parchment.zip",
this.paramMappings,
p -> p.paramsFile,
p -> p.paramsUri,
p -> new Coords(p.paramsCoords, null, "zip", this.paramsMavenBaseUrl));

final @Nullable CodeBookResource unpickDefinitions = this.getResource(
"definitions.unpick",
this.unpick != null ? this.unpick.unpickDefinitions : null,
Expand Down Expand Up @@ -442,9 +331,6 @@ private CodeBookContext createContext() {

return CodeBookContext.builder()
.tempDir(this.tempDir)
.remapperJar(remapper)
.mappings(mappings)
.paramMappings(paramMappings)
.unpickDefinitions(unpickDefinitions)
.outputJar(this.outputJar)
.overwrite(this.forceWrite)
Expand Down
37 changes: 2 additions & 35 deletions src/main/java/io/papermc/codebook/CodeBook.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
import dev.denwav.hypo.asm.AsmOutputWriter;
import dev.denwav.hypo.core.HypoConfig;
import dev.denwav.hypo.core.HypoContext;
import io.papermc.codebook.config.CodeBookClasspathResource;
import io.papermc.codebook.config.CodeBookContext;
import io.papermc.codebook.config.CodeBookJarInput;
import io.papermc.codebook.config.CodeBookResource;
Expand All @@ -40,8 +39,6 @@
import io.papermc.codebook.pages.ExtractVanillaJarPage;
import io.papermc.codebook.pages.FixJarPage;
import io.papermc.codebook.pages.InspectJarPage;
import io.papermc.codebook.pages.RemapJarPage;
import io.papermc.codebook.pages.RemapLvtPage;
import io.papermc.codebook.pages.UnpickPage;
import io.papermc.codebook.report.Reports;
import io.papermc.codebook.util.IOUtil;
Expand Down Expand Up @@ -76,13 +73,7 @@ public void exec() {
private void exec(final Path tempDir) {
this.deleteOutputFile();

final var book = List.of(
ExtractVanillaJarPage.class,
RemapJarPage.class,
InspectJarPage.class,
UnpickPage.class,
FixJarPage.class,
RemapLvtPage.class);
final var book = List.of(ExtractVanillaJarPage.class, InspectJarPage.class, UnpickPage.class, FixJarPage.class);

Module module = this.createInitialModule(tempDir);
for (final var page : book) {
Expand Down Expand Up @@ -126,30 +117,9 @@ private Module createInitialModule(final Path tempDir) {
classpathJars = null;
}

final Path mappingsFile = mappings.resolveResourceFile(tempDir);
final @Nullable Path paramMappingsFile;
if (this.ctx.paramMappings() != null) {
paramMappingsFile = this.ctx.paramMappings().resolveResourceFile(tempDir);
} else {
paramMappingsFile = null;
}

final List<Path> remapperJars;
if (this.ctx.remapperJar() instanceof final CodeBookResource resource) {
remapperJars = List.of(resource.resolveResourceFile(tempDir));
} else if (this.ctx.remapperJar() instanceof final CodeBookClasspathResource resource) {
remapperJars = resource.jars();
} else {
throw new LinkageError();
}

final @Nullable Path unpickDefinitions;
if (this.ctx.unpickDefinitions() != null) {
if (this.ctx.unpickDefinitions().equals(this.ctx.paramMappings())) {
unpickDefinitions = paramMappingsFile;
} else {
unpickDefinitions = this.ctx.unpickDefinitions().resolveResourceFile(tempDir);
}
unpickDefinitions = this.ctx.unpickDefinitions().resolveResourceFile(tempDir);
} else {
unpickDefinitions = null;
}
Expand All @@ -165,9 +135,6 @@ protected void configure() {
this.bind(CodeBookPage.ClasspathJars.KEY).toProvider(Providers.of(null));
}
this.bind(CodeBookPage.TempDir.KEY).toInstance(tempDir);
this.bind(CodeBookPage.MojangMappings.PATH_KEY).toInstance(mappingsFile);
this.bind(CodeBookPage.ParamMappings.PATH_KEY).toProvider(Providers.of(paramMappingsFile));
this.bind(CodeBookPage.RemapperJar.KEY).toInstance(remapperJars);

if (unpickDefinitions != null) {
this.bind(CodeBookPage.UnpickDefinitions.KEY).toInstance(unpickDefinitions);
Expand Down
3 changes: 0 additions & 3 deletions src/main/java/io/papermc/codebook/config/CodeBookContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,6 @@
@RecordBuilder.Options(interpretNotNulls = true)
public record CodeBookContext(
@Nullable @org.jetbrains.annotations.Nullable Path tempDir,
@NotNull CodeBookRemapper remapperJar,
@Nullable @org.jetbrains.annotations.Nullable CodeBookResource mappings,
@Nullable @org.jetbrains.annotations.Nullable CodeBookResource paramMappings,
@Nullable @org.jetbrains.annotations.Nullable CodeBookResource unpickDefinitions,
@NotNull Path outputJar,
boolean overwrite,
Expand Down
4 changes: 0 additions & 4 deletions src/main/java/io/papermc/codebook/config/CodeBookInput.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,6 @@ static CodeBookJarInputBuilder ofJar() {

// It's a bit odd for mappings to be here, but the MC version input can specify its own mappings
default @Nullable CodeBookResource resolveMappings(final CodeBookContext ctx, final Path tempDir) {
if (ctx.mappings() != null) {
return ctx.mappings();
}

return null;
}
}
23 changes: 0 additions & 23 deletions src/main/java/io/papermc/codebook/pages/CodeBookPage.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
import java.nio.file.Path;
import java.util.IdentityHashMap;
import java.util.List;
import org.cadixdev.lorenz.MappingSet;
import org.checkerframework.checker.nullness.qual.Nullable;

public abstract class CodeBookPage {
Expand Down Expand Up @@ -95,13 +94,6 @@ public void to(final @Nullable T value) {
Key<CodeBookContext> KEY = Key.get(CodeBookContext.class, Context.class);
}

@Qualifier
@Target(ElementType.PARAMETER)
@Retention(RetentionPolicy.RUNTIME)
public @interface RemapperJar {
Key<List<Path>> KEY = Key.get(new TypeLiteral<>() {}, RemapperJar.class);
}

@Qualifier
@Target(ElementType.PARAMETER)
@Retention(RetentionPolicy.RUNTIME)
Expand All @@ -116,21 +108,6 @@ public void to(final @Nullable T value) {
Key<List<Path>> KEY = Key.get(new TypeLiteral<>() {}, ClasspathJars.class);
}

@Qualifier
@Target(ElementType.PARAMETER)
@Retention(RetentionPolicy.RUNTIME)
public @interface MojangMappings {
Key<Path> PATH_KEY = Key.get(Path.class, MojangMappings.class);
}

@Qualifier
@Target(ElementType.PARAMETER)
@Retention(RetentionPolicy.RUNTIME)
public @interface ParamMappings {
Key<Path> PATH_KEY = Key.get(Path.class, ParamMappings.class);
Key<MappingSet> KEY = Key.get(MappingSet.class, ParamMappings.class);
}

@Qualifier
@Target(ElementType.PARAMETER)
@Retention(RetentionPolicy.RUNTIME)
Expand Down
47 changes: 0 additions & 47 deletions src/main/java/io/papermc/codebook/pages/FixJarPage.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,9 @@

import com.google.common.collect.Iterables;
import dev.denwav.hypo.asm.AsmClassData;
import dev.denwav.hypo.asm.AsmFieldData;
import dev.denwav.hypo.asm.AsmMethodData;
import dev.denwav.hypo.core.HypoContext;
import dev.denwav.hypo.hydrate.generic.HypoHydration;
import dev.denwav.hypo.model.data.ClassData;
import dev.denwav.hypo.model.data.ClassKind;
import dev.denwav.hypo.model.data.FieldData;
import dev.denwav.hypo.model.data.MethodData;
import dev.denwav.hypo.model.data.Visibility;
import jakarta.inject.Inject;
Expand All @@ -41,7 +37,6 @@
import org.checkerframework.checker.nullness.qual.Nullable;
import org.objectweb.asm.Opcodes;
import org.objectweb.asm.tree.AnnotationNode;
import org.objectweb.asm.tree.FieldNode;
import org.objectweb.asm.tree.MethodNode;

public final class FixJarPage extends AsmProcessorPage {
Expand All @@ -54,8 +49,6 @@ public FixJarPage(@Hypo final HypoContext context) {
@Override
protected void processClass(final AsmClassData classData) throws IOException {
OverrideAnnotationAdder.addAnnotations(classData);
EmptyRecordFixer.fixClass(classData);
RecordFieldAccessFixer.fixClass(classData);
DeprecatedAnnotationAdder.addAnnotations(classData);
}

Expand Down Expand Up @@ -123,46 +116,6 @@ private static void addAnnotations(final AsmClassData classData) {
}
}

private static final class EmptyRecordFixer {

private EmptyRecordFixer() {}

private static void fixClass(final AsmClassData classData) throws IOException {
if (classData.is(ClassKind.RECORD)) {
return;
}

final @Nullable ClassData superClass = classData.superClass();
if (superClass == null) {
return;
}

if (superClass.name().equals("java/lang/Record")) {
// extends record, but is not marked as such
classData.getNode().access |= Opcodes.ACC_RECORD;
}
}
}

private static final class RecordFieldAccessFixer {
private static final int RESET_ACCESS = ~(Opcodes.ACC_PUBLIC | Opcodes.ACC_PRIVATE | Opcodes.ACC_PROTECTED);

private RecordFieldAccessFixer() {}

private static void fixClass(final AsmClassData classData) {
if (classData.isNot(ClassKind.RECORD)) {
return;
}

for (final FieldData field : classData.fields()) {
if (!field.isStatic() && field.visibility() != Visibility.PRIVATE && field.isFinal()) {
final FieldNode node = ((AsmFieldData) field).getNode();
node.access = (node.access & RESET_ACCESS) | Opcodes.ACC_PRIVATE;
}
}
}
}

private static <T> List<T> appendToList(final @Nullable List<T> list, final T value) {
if (list != null) {
list.add(value);
Expand Down
Loading