Skip to content

Commit c3ea69b

Browse files
authored
Update for unpick v3/4 API (#57)
* Update for unpick v3/4 * Support unpick definitions in jars at extras/definitions.unpick Also reuse the jar if it's the same one as for param mappings * Move class resolver * Fix error from missing client classes * spotless * Update unpick * Fix filtering * Update unpick * Rename version catalog entry
1 parent 6bf424b commit c3ea69b

11 files changed

Lines changed: 242 additions & 172 deletions

File tree

build-logic/src/main/kotlin/codebook.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ repositories {
3434

3535
java {
3636
toolchain {
37-
languageVersion = JavaLanguageVersion.of(17)
37+
languageVersion = JavaLanguageVersion.of(21)
3838
}
3939
withSourcesJar()
4040
}

build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ dependencies {
2121
implementation(libs.bundles.asm)
2222

2323
implementation(libs.unpick.format)
24-
implementation(libs.unpick.cli)
24+
implementation(libs.unpick)
2525

2626
implementation(platform(libs.hypo.platform))
2727
implementation(libs.bundles.hypo.full)

codebook-cli/src/main/java/io/papermc/codebook/cli/Main.java

Lines changed: 2 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -175,10 +175,7 @@ static final class ParamMappingsOptions {
175175
private @Nullable UnpickOptions unpick;
176176

177177
static final class UnpickOptions {
178-
@CommandLine.ArgGroup(
179-
heading =
180-
"%n%nUnpick requires unpick definitions. When specifying unpick definitions, unpick constants are also required.%n",
181-
multiplicity = "1")
178+
@CommandLine.ArgGroup(heading = "%n%nUnpick requires unpick definitions.%n", multiplicity = "1")
182179
private @Nullable UnpickDefinitionsOptions unpickDefinitions;
183180

184181
static final class UnpickDefinitionsOptions {
@@ -200,32 +197,6 @@ static final class UnpickDefinitionsOptions {
200197
description = "A download URL for the unpick definitions to use for the unpick process.")
201198
private @Nullable URI unpickUri;
202199
}
203-
204-
@CommandLine.ArgGroup(
205-
heading =
206-
"%n%nUnpick requires a constants jar. When specifying unpick constants, unpick definitions are also required.%n",
207-
multiplicity = "1")
208-
private @Nullable ConstantsJarOptions constantsJar;
209-
210-
static final class ConstantsJarOptions {
211-
@CommandLine.Option(
212-
names = "--constants-coords",
213-
paramLabel = "<constants-coords>",
214-
description = "The Maven coordinates for the constants jar to use for the unpick process.")
215-
private @Nullable String constantsCoords;
216-
217-
@CommandLine.Option(
218-
names = {"--constants-file"},
219-
paramLabel = "<constants-jar-file>",
220-
description = "The constants jar to use for the unpick process.")
221-
private @Nullable Path constantsFile;
222-
223-
@CommandLine.Option(
224-
names = "--constants-uri",
225-
paramLabel = "<constants-uri>",
226-
description = "A download URL for the constants jar to use for the unpick process.")
227-
private @Nullable URI constantsUri;
228-
}
229200
}
230201

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

442413
final @Nullable CodeBookResource unpickDefinitions = this.getResource(
443-
"unpick_definitions.jar",
414+
"definitions.unpick",
444415
this.unpick != null ? this.unpick.unpickDefinitions : null,
445416
d -> d.unpickFile,
446417
d -> d.unpickUri,
@@ -452,19 +423,6 @@ private CodeBookContext createContext() {
452423
return new Coords(d.unpickCoords, "constants", null, this.unpickMavenBaseUrl);
453424
});
454425

455-
final @Nullable CodeBookResource constantJar = this.getResource(
456-
"unpick_constants.jar",
457-
this.unpick != null ? this.unpick.constantsJar : null,
458-
c -> c.constantsFile,
459-
c -> c.constantsUri,
460-
c -> {
461-
if (this.unpickMavenBaseUrl == null) {
462-
throw new UserErrorException(
463-
"Cannot define unpick constants Maven coordinates without also setting --unpick-maven-base-url");
464-
}
465-
return new Coords(c.constantsCoords, "constants", null, this.unpickMavenBaseUrl);
466-
});
467-
468426
@Nullable Reports reports = null;
469427
if (this.reports != null && this.reports.reportsDir != null) {
470428
final Set<ReportType> reportsToGenerate;
@@ -488,7 +446,6 @@ private CodeBookContext createContext() {
488446
.mappings(mappings)
489447
.paramMappings(paramMappings)
490448
.unpickDefinitions(unpickDefinitions)
491-
.constantsJar(constantJar)
492449
.outputJar(this.outputJar)
493450
.overwrite(this.forceWrite)
494451
.input(input)

gradle/libs.versions.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ palantir = "2.50.0"
44
indra = "4.0.0"
55
slf4j = "2.0.7"
66
lorenz = "0.5.7"
7-
unpick = "2.3.0"
7+
unpick = "3.0.0-beta.13"
88
asm = "9.9"
99
feather = "1.1.0"
1010
recordBuilder = "37"
@@ -40,7 +40,7 @@ asm-util = { module = "org.ow2.asm:asm-util", version.ref = "asm" }
4040
asm-tree = { module = "org.ow2.asm:asm-tree", version.ref = "asm" }
4141

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

4545
hypo-platform = "dev.denwav.hypo:hypo-platform:2.3.0"
4646
hypo-model = { module = "dev.denwav.hypo:hypo-model" }

src/main/java/io/papermc/codebook/CodeBook.java

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,8 @@ private void exec(final Path tempDir) {
7878
final var book = List.of(
7979
ExtractVanillaJarPage.class,
8080
RemapJarPage.class,
81-
UnpickPage.class,
8281
InspectJarPage.class,
82+
UnpickPage.class,
8383
FixJarPage.class,
8484
RemapLvtPage.class);
8585

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

145145
final @Nullable Path unpickDefinitions;
146146
if (this.ctx.unpickDefinitions() != null) {
147-
unpickDefinitions = this.ctx.unpickDefinitions().resolveResourceFile(tempDir);
147+
if (this.ctx.unpickDefinitions().equals(this.ctx.paramMappings())) {
148+
unpickDefinitions = paramMappingsFile;
149+
} else {
150+
unpickDefinitions = this.ctx.unpickDefinitions().resolveResourceFile(tempDir);
151+
}
148152
} else {
149153
unpickDefinitions = null;
150154
}
151155

152-
final @Nullable Path constantsJar;
153-
if (this.ctx.constantsJar() != null) {
154-
constantsJar = this.ctx.constantsJar().resolveResourceFile(tempDir);
155-
} else {
156-
constantsJar = null;
157-
}
158-
159156
return new AbstractModule() {
160157
@Override
161158
protected void configure() {
@@ -177,12 +174,6 @@ protected void configure() {
177174
this.bind(CodeBookPage.UnpickDefinitions.KEY).toProvider(Providers.of(null));
178175
}
179176

180-
if (constantsJar != null) {
181-
this.bind(CodeBookPage.ConstantsJar.KEY).toInstance(constantsJar);
182-
} else {
183-
this.bind(CodeBookPage.ConstantsJar.KEY).toProvider(Providers.of(null));
184-
}
185-
186177
if (CodeBook.this.ctx.reports() != null) {
187178
this.bind(CodeBookPage.Report.KEY).toInstance(CodeBook.this.ctx.reports());
188179
this.install(CodeBook.this.ctx.reports());

src/main/java/io/papermc/codebook/config/CodeBookContext.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ public record CodeBookContext(
3939
@Nullable @org.jetbrains.annotations.Nullable CodeBookResource mappings,
4040
@Nullable @org.jetbrains.annotations.Nullable CodeBookResource paramMappings,
4141
@Nullable @org.jetbrains.annotations.Nullable CodeBookResource unpickDefinitions,
42-
@Nullable @org.jetbrains.annotations.Nullable CodeBookResource constantsJar,
4342
@NotNull Path outputJar,
4443
boolean overwrite,
4544
@NotNull CodeBookInput input,
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
/*
2+
* codebook is a remapper utility for the PaperMC project.
3+
*
4+
* Copyright (c) 2023 Kyle Wood (DenWav)
5+
* Contributors
6+
*
7+
* This library is free software; you can redistribute it and/or
8+
* modify it under the terms of the GNU Lesser General Public
9+
* License as published by the Free Software Foundation;
10+
* version 3 only, no later versions.
11+
*
12+
* This library is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15+
* Lesser General Public License for more details.
16+
*
17+
* You should have received a copy of the GNU Lesser General Public
18+
* License along with this library; if not, write to the Free Software
19+
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
20+
* USA
21+
*/
22+
23+
package io.papermc.codebook.pages;
24+
25+
import dev.denwav.hypo.asm.AsmClassData;
26+
import dev.denwav.hypo.core.HypoContext;
27+
import dev.denwav.hypo.model.HypoModelUtil;
28+
import dev.denwav.hypo.model.data.ClassData;
29+
import io.papermc.codebook.exceptions.UnexpectedException;
30+
import java.io.IOException;
31+
import java.util.ArrayList;
32+
import java.util.concurrent.ExecutionException;
33+
import java.util.concurrent.Future;
34+
35+
public abstract class AsmProcessorPage extends CodeBookPage {
36+
37+
protected final HypoContext context;
38+
39+
protected AsmProcessorPage(final HypoContext context) {
40+
this.context = context;
41+
}
42+
43+
@Override
44+
public void exec() {
45+
this.processClasses();
46+
}
47+
48+
protected void processClasses() {
49+
final var tasks = new ArrayList<Future<?>>();
50+
for (final ClassData classData : this.context.getProvider().allClasses()) {
51+
final var task = this.context.getExecutor().submit(() -> {
52+
try {
53+
this.processClass((AsmClassData) classData);
54+
} catch (final Exception e) {
55+
throw HypoModelUtil.rethrow(e);
56+
}
57+
});
58+
tasks.add(task);
59+
}
60+
61+
try {
62+
for (final Future<?> task : tasks) {
63+
task.get();
64+
}
65+
} catch (final ExecutionException e) {
66+
throw new UnexpectedException("Failed to process classes", e.getCause());
67+
} catch (final InterruptedException e) {
68+
throw new UnexpectedException("Class processing interrupted", e);
69+
}
70+
}
71+
72+
protected abstract void processClass(final AsmClassData classData) throws IOException;
73+
}

src/main/java/io/papermc/codebook/pages/CodeBookPage.java

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -138,13 +138,6 @@ public void to(final @Nullable T value) {
138138
Key<Path> KEY = Key.get(Path.class, UnpickDefinitions.class);
139139
}
140140

141-
@Qualifier
142-
@Target(ElementType.PARAMETER)
143-
@Retention(RetentionPolicy.RUNTIME)
144-
public @interface ConstantsJar {
145-
Key<Path> KEY = Key.get(Path.class, ConstantsJar.class);
146-
}
147-
148141
@Qualifier
149142
@Target(ElementType.PARAMETER)
150143
@Retention(RetentionPolicy.RUNTIME)

src/main/java/io/papermc/codebook/pages/FixJarPage.java

Lines changed: 3 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -28,69 +28,31 @@
2828
import dev.denwav.hypo.asm.AsmMethodData;
2929
import dev.denwav.hypo.core.HypoContext;
3030
import dev.denwav.hypo.hydrate.generic.HypoHydration;
31-
import dev.denwav.hypo.model.HypoModelUtil;
3231
import dev.denwav.hypo.model.data.ClassData;
3332
import dev.denwav.hypo.model.data.ClassKind;
3433
import dev.denwav.hypo.model.data.FieldData;
3534
import dev.denwav.hypo.model.data.MethodData;
3635
import dev.denwav.hypo.model.data.Visibility;
37-
import io.papermc.codebook.exceptions.UnexpectedException;
3836
import jakarta.inject.Inject;
3937
import java.io.IOException;
4038
import java.util.ArrayList;
4139
import java.util.List;
4240
import java.util.Set;
43-
import java.util.concurrent.ExecutionException;
44-
import java.util.concurrent.Future;
4541
import org.checkerframework.checker.nullness.qual.Nullable;
4642
import org.objectweb.asm.Opcodes;
4743
import org.objectweb.asm.tree.AnnotationNode;
4844
import org.objectweb.asm.tree.FieldNode;
4945
import org.objectweb.asm.tree.MethodNode;
5046

51-
public final class FixJarPage extends CodeBookPage {
52-
53-
private final HypoContext context;
47+
public final class FixJarPage extends AsmProcessorPage {
5448

5549
@Inject
5650
public FixJarPage(@Hypo final HypoContext context) {
57-
this.context = context;
51+
super(context);
5852
}
5953

6054
@Override
61-
public void exec() {
62-
try {
63-
this.fixJar();
64-
} catch (final IOException e) {
65-
throw new UnexpectedException("Failed to fix jar", e);
66-
}
67-
}
68-
69-
private void fixJar() throws IOException {
70-
final var tasks = new ArrayList<Future<?>>();
71-
for (final ClassData classData : this.context.getProvider().allClasses()) {
72-
final var task = this.context.getExecutor().submit(() -> {
73-
try {
74-
this.processClass((AsmClassData) classData);
75-
} catch (final IOException e) {
76-
throw HypoModelUtil.rethrow(e);
77-
}
78-
});
79-
tasks.add(task);
80-
}
81-
82-
try {
83-
for (final Future<?> task : tasks) {
84-
task.get();
85-
}
86-
} catch (final ExecutionException e) {
87-
throw new UnexpectedException("Failed to fix jar", e.getCause());
88-
} catch (final InterruptedException e) {
89-
throw new UnexpectedException("Jar fixing interrupted", e);
90-
}
91-
}
92-
93-
private void processClass(final AsmClassData classData) throws IOException {
55+
protected void processClass(final AsmClassData classData) throws IOException {
9456
OverrideAnnotationAdder.addAnnotations(classData);
9557
EmptyRecordFixer.fixClass(classData);
9658
RecordFieldAccessFixer.fixClass(classData);

0 commit comments

Comments
 (0)