Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
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
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
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
group = io.papermc.codebook
version = 1.0.19-SNAPSHOT
version = 2.0.0-SNAPSHOT
43 changes: 2 additions & 41 deletions src/main/java/io/papermc/codebook/CodeBook.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,14 @@
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;
import io.papermc.codebook.exceptions.UnexpectedException;
import io.papermc.codebook.exceptions.UserErrorException;
import io.papermc.codebook.pages.CodeBookPage;
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 +72,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 @@ -113,11 +103,6 @@ private static Injector injector(final Module module) {
}

private Module createInitialModule(final Path tempDir) {
final @Nullable CodeBookResource mappings = this.ctx.input().resolveMappings(this.ctx, tempDir);
if (mappings == null) {
throw new IllegalStateException("No mappings file could be determined for the given configuration");
}

final Path inputJar = this.ctx.input().resolveInputFile(tempDir);
final @Nullable List<Path> classpathJars;
if (this.ctx.input() instanceof final CodeBookJarInput input) {
Expand All @@ -126,30 +111,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 +129,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
10 changes: 0 additions & 10 deletions src/main/java/io/papermc/codebook/config/CodeBookInput.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
package io.papermc.codebook.config;

import java.nio.file.Path;
import org.checkerframework.checker.nullness.qual.Nullable;

public sealed interface CodeBookInput permits CodeBookVersionInput, CodeBookJarInput {

Expand All @@ -36,13 +35,4 @@ static CodeBookJarInputBuilder ofJar() {
}

Path resolveInputFile(final Path tempDir);

// 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;
}
}
16 changes: 0 additions & 16 deletions src/main/java/io/papermc/codebook/config/CodeBookVersionInput.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,9 @@
package io.papermc.codebook.config;

import io.papermc.codebook.mojangapi.MinecraftManifest;
import io.papermc.codebook.mojangapi.MinecraftVersionDownload;
import io.papermc.codebook.mojangapi.MinecraftVersionManifest;
import io.papermc.codebook.util.Downloader;
import java.nio.file.Path;
import org.checkerframework.checker.nullness.qual.Nullable;

public record CodeBookVersionInput(String mcVersion) implements CodeBookInput {

Expand All @@ -44,18 +42,4 @@ public Path resolveInputFile(final Path tempDir) {
Downloader.downloadFile(versionManifest.serverDownload(), targetJar);
return targetJar;
}

@Override
public CodeBookResource resolveMappings(final CodeBookContext ctx, final Path tempDir) {
final @Nullable CodeBookResource mappings = CodeBookInput.super.resolveMappings(ctx, tempDir);
if (mappings != null) {
return mappings;
}

final var manifest = MinecraftManifest.getManifest();
final var versionManifest = MinecraftVersionManifest.getManifestForVersion(manifest, this.mcVersion);

final MinecraftVersionDownload mappingsDownload = versionManifest.serverMappingsDownload();
return new CodeBookUriResource("server_mappings.txt", mappingsDownload.uri(), mappingsDownload.sha1());
}
}
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
Loading