Skip to content
Merged
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 build-logic/src/main/kotlin/codebook.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ repositories {

java {
toolchain {
languageVersion = JavaLanguageVersion.of(17)
languageVersion = JavaLanguageVersion.of(21)
}
withSourcesJar()
}
Expand Down
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ dependencies {
implementation(libs.bundles.asm)

implementation(libs.unpick.format)
implementation(libs.unpick.cli)
implementation(libs.unpick)

implementation(platform(libs.hypo.platform))
implementation(libs.bundles.hypo.full)
Expand Down
47 changes: 2 additions & 45 deletions codebook-cli/src/main/java/io/papermc/codebook/cli/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -175,10 +175,7 @@ static final class ParamMappingsOptions {
private @Nullable UnpickOptions unpick;

static final class UnpickOptions {
@CommandLine.ArgGroup(
heading =
"%n%nUnpick requires unpick definitions. When specifying unpick definitions, unpick constants are also required.%n",
multiplicity = "1")
@CommandLine.ArgGroup(heading = "%n%nUnpick requires unpick definitions.%n", multiplicity = "1")
private @Nullable UnpickDefinitionsOptions unpickDefinitions;

static final class UnpickDefinitionsOptions {
Expand All @@ -200,32 +197,6 @@ static final class UnpickDefinitionsOptions {
description = "A download URL for the unpick definitions to use for the unpick process.")
private @Nullable URI unpickUri;
}

@CommandLine.ArgGroup(
heading =
"%n%nUnpick requires a constants jar. When specifying unpick constants, unpick definitions are also required.%n",
multiplicity = "1")
private @Nullable ConstantsJarOptions constantsJar;

static final class ConstantsJarOptions {
@CommandLine.Option(
names = "--constants-coords",
paramLabel = "<constants-coords>",
description = "The Maven coordinates for the constants jar to use for the unpick process.")
private @Nullable String constantsCoords;

@CommandLine.Option(
names = {"--constants-file"},
paramLabel = "<constants-jar-file>",
description = "The constants jar to use for the unpick process.")
private @Nullable Path constantsFile;

@CommandLine.Option(
names = "--constants-uri",
paramLabel = "<constants-uri>",
description = "A download URL for the constants jar to use for the unpick process.")
private @Nullable URI constantsUri;
}
}

@CommandLine.Option(
Expand Down Expand Up @@ -440,7 +411,7 @@ private CodeBookContext createContext() {
p -> new Coords(p.paramsCoords, null, "zip", this.paramsMavenBaseUrl));

final @Nullable CodeBookResource unpickDefinitions = this.getResource(
"unpick_definitions.jar",
"definitions.unpick",
this.unpick != null ? this.unpick.unpickDefinitions : null,
d -> d.unpickFile,
d -> d.unpickUri,
Expand All @@ -452,19 +423,6 @@ private CodeBookContext createContext() {
return new Coords(d.unpickCoords, "constants", null, this.unpickMavenBaseUrl);
});

final @Nullable CodeBookResource constantJar = this.getResource(
"unpick_constants.jar",
this.unpick != null ? this.unpick.constantsJar : null,
c -> c.constantsFile,
c -> c.constantsUri,
c -> {
if (this.unpickMavenBaseUrl == null) {
throw new UserErrorException(
"Cannot define unpick constants Maven coordinates without also setting --unpick-maven-base-url");
}
return new Coords(c.constantsCoords, "constants", null, this.unpickMavenBaseUrl);
});

@Nullable Reports reports = null;
if (this.reports != null && this.reports.reportsDir != null) {
final Set<ReportType> reportsToGenerate;
Expand All @@ -488,7 +446,6 @@ private CodeBookContext createContext() {
.mappings(mappings)
.paramMappings(paramMappings)
.unpickDefinitions(unpickDefinitions)
.constantsJar(constantJar)
.outputJar(this.outputJar)
.overwrite(this.forceWrite)
.input(input)
Expand Down
4 changes: 2 additions & 2 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ palantir = "2.50.0"
indra = "4.0.0"
slf4j = "2.0.7"
lorenz = "0.5.7"
unpick = "2.3.0"
unpick = "3.0.0-beta.13"
asm = "9.9"
feather = "1.1.0"
recordBuilder = "37"
Expand Down Expand Up @@ -40,7 +40,7 @@ asm-util = { module = "org.ow2.asm:asm-util", version.ref = "asm" }
asm-tree = { module = "org.ow2.asm:asm-tree", version.ref = "asm" }

unpick-format = { module = "net.fabricmc.unpick:unpick-format-utils", version.ref = "unpick" }
unpick-cli = { module = "net.fabricmc.unpick:unpick-cli", version.ref = "unpick" }
unpick = { module = "net.fabricmc.unpick:unpick", version.ref = "unpick" }

hypo-platform = "dev.denwav.hypo:hypo-platform:2.3.0"
hypo-model = { module = "dev.denwav.hypo:hypo-model" }
Expand Down
21 changes: 6 additions & 15 deletions src/main/java/io/papermc/codebook/CodeBook.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ private void exec(final Path tempDir) {
final var book = List.of(
ExtractVanillaJarPage.class,
RemapJarPage.class,
UnpickPage.class,
InspectJarPage.class,
UnpickPage.class,
FixJarPage.class,
RemapLvtPage.class);

Expand Down Expand Up @@ -144,18 +144,15 @@ private Module createInitialModule(final Path tempDir) {

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

final @Nullable Path constantsJar;
if (this.ctx.constantsJar() != null) {
constantsJar = this.ctx.constantsJar().resolveResourceFile(tempDir);
} else {
constantsJar = null;
}

return new AbstractModule() {
@Override
protected void configure() {
Expand All @@ -177,12 +174,6 @@ protected void configure() {
this.bind(CodeBookPage.UnpickDefinitions.KEY).toProvider(Providers.of(null));
}

if (constantsJar != null) {
this.bind(CodeBookPage.ConstantsJar.KEY).toInstance(constantsJar);
} else {
this.bind(CodeBookPage.ConstantsJar.KEY).toProvider(Providers.of(null));
}

if (CodeBook.this.ctx.reports() != null) {
this.bind(CodeBookPage.Report.KEY).toInstance(CodeBook.this.ctx.reports());
this.install(CodeBook.this.ctx.reports());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ public record CodeBookContext(
@Nullable @org.jetbrains.annotations.Nullable CodeBookResource mappings,
@Nullable @org.jetbrains.annotations.Nullable CodeBookResource paramMappings,
@Nullable @org.jetbrains.annotations.Nullable CodeBookResource unpickDefinitions,
@Nullable @org.jetbrains.annotations.Nullable CodeBookResource constantsJar,
@NotNull Path outputJar,
boolean overwrite,
@NotNull CodeBookInput input,
Expand Down
73 changes: 73 additions & 0 deletions src/main/java/io/papermc/codebook/pages/AsmProcessorPage.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/*
* codebook is a remapper utility for the PaperMC project.
*
* Copyright (c) 2023 Kyle Wood (DenWav)
* Contributors
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation;
* version 3 only, no later versions.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
* USA
*/

package io.papermc.codebook.pages;

import dev.denwav.hypo.asm.AsmClassData;
import dev.denwav.hypo.core.HypoContext;
import dev.denwav.hypo.model.HypoModelUtil;
import dev.denwav.hypo.model.data.ClassData;
import io.papermc.codebook.exceptions.UnexpectedException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;

public abstract class AsmProcessorPage extends CodeBookPage {

protected final HypoContext context;

protected AsmProcessorPage(final HypoContext context) {
this.context = context;
}

@Override
public void exec() {
this.processClasses();
}

protected void processClasses() {
final var tasks = new ArrayList<Future<?>>();
for (final ClassData classData : this.context.getProvider().allClasses()) {
final var task = this.context.getExecutor().submit(() -> {
try {
this.processClass((AsmClassData) classData);
} catch (final Exception e) {
throw HypoModelUtil.rethrow(e);
}
});
tasks.add(task);
}

try {
for (final Future<?> task : tasks) {
task.get();
}
} catch (final ExecutionException e) {
throw new UnexpectedException("Failed to process classes", e.getCause());
} catch (final InterruptedException e) {
throw new UnexpectedException("Class processing interrupted", e);
}
}

protected abstract void processClass(final AsmClassData classData) throws IOException;
}
7 changes: 0 additions & 7 deletions src/main/java/io/papermc/codebook/pages/CodeBookPage.java
Original file line number Diff line number Diff line change
Expand Up @@ -138,13 +138,6 @@ public void to(final @Nullable T value) {
Key<Path> KEY = Key.get(Path.class, UnpickDefinitions.class);
}

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

@Qualifier
@Target(ElementType.PARAMETER)
@Retention(RetentionPolicy.RUNTIME)
Expand Down
44 changes: 3 additions & 41 deletions src/main/java/io/papermc/codebook/pages/FixJarPage.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,69 +28,31 @@
import dev.denwav.hypo.asm.AsmMethodData;
import dev.denwav.hypo.core.HypoContext;
import dev.denwav.hypo.hydrate.generic.HypoHydration;
import dev.denwav.hypo.model.HypoModelUtil;
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 io.papermc.codebook.exceptions.UnexpectedException;
import jakarta.inject.Inject;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
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 CodeBookPage {

private final HypoContext context;
public final class FixJarPage extends AsmProcessorPage {

@Inject
public FixJarPage(@Hypo final HypoContext context) {
this.context = context;
super(context);
}

@Override
public void exec() {
try {
this.fixJar();
} catch (final IOException e) {
throw new UnexpectedException("Failed to fix jar", e);
}
}

private void fixJar() throws IOException {
final var tasks = new ArrayList<Future<?>>();
for (final ClassData classData : this.context.getProvider().allClasses()) {
final var task = this.context.getExecutor().submit(() -> {
try {
this.processClass((AsmClassData) classData);
} catch (final IOException e) {
throw HypoModelUtil.rethrow(e);
}
});
tasks.add(task);
}

try {
for (final Future<?> task : tasks) {
task.get();
}
} catch (final ExecutionException e) {
throw new UnexpectedException("Failed to fix jar", e.getCause());
} catch (final InterruptedException e) {
throw new UnexpectedException("Jar fixing interrupted", e);
}
}

private void processClass(final AsmClassData classData) throws IOException {
protected void processClass(final AsmClassData classData) throws IOException {
OverrideAnnotationAdder.addAnnotations(classData);
EmptyRecordFixer.fixClass(classData);
RecordFieldAccessFixer.fixClass(classData);
Expand Down
Loading