From 0e485dcf550849023a72a9df50e6edab2be5121d Mon Sep 17 00:00:00 2001 From: Jake Potrebic Date: Sun, 6 Aug 2023 10:43:47 -0700 Subject: [PATCH 1/2] add report system --- build.gradle.kts | 1 + .../java/io/papermc/codebook/cli/Main.java | 56 ++++++++++++--- codebook-lvt/build.gradle.kts | 1 + .../io/papermc/codebook/lvt/LvtNamer.java | 10 +-- .../codebook/lvt/RootLvtSuggester.java | 23 +++---- codebook-reports/build.gradle.kts | 28 ++++++++ .../papermc/codebook/report/ReportType.java | 28 ++++++++ .../io/papermc/codebook/report/Reports.java | 68 +++++++++++++++++++ .../type/MissingMethodLvtSuggestion.java | 53 +++++++++++++++ .../papermc/codebook/report/type/Report.java | 28 ++++++++ settings.gradle.kts | 1 + .../java/io/papermc/codebook/CodeBook.java | 15 ++++ .../codebook/config/CodeBookContext.java | 3 +- .../papermc/codebook/pages/CodeBookPage.java | 8 +++ .../papermc/codebook/pages/RemapLvtPage.java | 21 ++---- .../lvt/LvtAssignmentSuggesterTest.java | 7 +- 16 files changed, 303 insertions(+), 48 deletions(-) create mode 100644 codebook-reports/build.gradle.kts create mode 100644 codebook-reports/src/main/java/io/papermc/codebook/report/ReportType.java create mode 100644 codebook-reports/src/main/java/io/papermc/codebook/report/Reports.java create mode 100644 codebook-reports/src/main/java/io/papermc/codebook/report/type/MissingMethodLvtSuggestion.java create mode 100644 codebook-reports/src/main/java/io/papermc/codebook/report/type/Report.java diff --git a/build.gradle.kts b/build.gradle.kts index ff4a773..af3cc3a 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -10,6 +10,7 @@ dependencies { api(libs.checker) implementation(projects.codebookLvt) + api(projects.codebookReports) implementation(libs.guice) implementation(libs.inject) diff --git a/codebook-cli/src/main/java/io/papermc/codebook/cli/Main.java b/codebook-cli/src/main/java/io/papermc/codebook/cli/Main.java index eb21871..1170e7d 100644 --- a/codebook-cli/src/main/java/io/papermc/codebook/cli/Main.java +++ b/codebook-cli/src/main/java/io/papermc/codebook/cli/Main.java @@ -32,12 +32,15 @@ import io.papermc.codebook.config.CodeBookUriResource; import io.papermc.codebook.config.CodeBookVersionInput; import io.papermc.codebook.exceptions.UserErrorException; +import io.papermc.codebook.report.ReportType; +import io.papermc.codebook.report.Reports; import io.papermc.codebook.util.Downloader; import java.io.IOException; import java.net.URI; import java.nio.file.Files; import java.nio.file.Path; import java.util.List; +import java.util.Set; import java.util.concurrent.Callable; import java.util.function.Function; import java.util.zip.ZipFile; @@ -59,6 +62,39 @@ usageHelpAutoWidth = true) public final class Main implements Callable { + @CommandLine.ArgGroup(multiplicity = "1", exclusive = false) + private @Nullable ReportOptions reports; + + static final class ReportOptions { + + @CommandLine.Option( + names = "--reports-dir", + paramLabel = "", + description = "Parent directory to output any generated reports", + hidden = true) + private @Nullable Path reportsDir; + + @CommandLine.ArgGroup(multiplicity = "1") + private SelectedReports selectedReports; + + static final class SelectedReports { + + @CommandLine.Option( + names = "--report", + paramLabel = "", + description = "Set of report types to generate", + hidden = true) + private Set reports; + + @CommandLine.Option( + names = "--all-reports", + paramLabel = "", + description = "Generate all reports", + hidden = true) + private boolean allReports; + } + } + @CommandLine.ArgGroup( multiplicity = "1", heading = "%n%nThe remapper must be an executable tiny-remapper jar. " @@ -86,13 +122,6 @@ static final class RemapperOptions { description = "A download URL for the executable AutoRenamingTool jar to use for the remapping process.") private @Nullable URI remapperUri; - - @CommandLine.Option( - names = "--log-missing-lvt-suggestions", - paramLabel = "", - description = "Include a report of missing lvt name suggestions in the remapping log", - hidden = true) - private boolean logMissingLvtSuggestions; } @CommandLine.ArgGroup( @@ -421,6 +450,17 @@ private CodeBookContext createContext() { return new Coords(c.constantsCoords, "constants", null, this.unpickMavenBaseUrl); }); + @Nullable Reports reports = null; + if (this.reports != null && this.reports.reportsDir != null) { + final Set reportsToGenerate; + if (this.reports.selectedReports.allReports) { + reportsToGenerate = Set.of(ReportType.values()); + } else { + reportsToGenerate = this.reports.selectedReports.reports; + } + reports = new Reports(this.reports.reportsDir, reportsToGenerate); + } + return CodeBookContext.builder() .remapperJar(remapper) .mappings(mappings) @@ -430,7 +470,7 @@ private CodeBookContext createContext() { .outputJar(this.outputJar) .overwrite(this.forceWrite) .input(input) - .logMissingLvtSuggestions(this.remapper.logMissingLvtSuggestions) + .reports(reports) .build(); } diff --git a/codebook-lvt/build.gradle.kts b/codebook-lvt/build.gradle.kts index fa82705..ffd0c5f 100644 --- a/codebook-lvt/build.gradle.kts +++ b/codebook-lvt/build.gradle.kts @@ -5,6 +5,7 @@ plugins { dependencies { implementation(platform(libs.hypo.platform)) + implementation(projects.codebookReports) api(libs.checker) api(libs.bundles.hypo.base) diff --git a/codebook-lvt/src/main/java/io/papermc/codebook/lvt/LvtNamer.java b/codebook-lvt/src/main/java/io/papermc/codebook/lvt/LvtNamer.java index 66c8302..270ef66 100644 --- a/codebook-lvt/src/main/java/io/papermc/codebook/lvt/LvtNamer.java +++ b/codebook-lvt/src/main/java/io/papermc/codebook/lvt/LvtNamer.java @@ -34,17 +34,15 @@ import dev.denwav.hypo.model.data.MethodData; import dev.denwav.hypo.model.data.types.JvmType; import dev.denwav.hypo.model.data.types.PrimitiveType; +import io.papermc.codebook.report.Reports; import java.io.IOException; import java.util.ArrayList; import java.util.Arrays; import java.util.HashSet; import java.util.LinkedHashSet; import java.util.List; -import java.util.Map; import java.util.Optional; import java.util.Set; -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.atomic.AtomicInteger; import org.cadixdev.lorenz.MappingSet; import org.cadixdev.lorenz.model.Mapping; import org.cadixdev.lorenz.model.MethodMapping; @@ -61,12 +59,10 @@ public class LvtNamer { private final LvtTypeSuggester lvtTypeSuggester; private final RootLvtSuggester lvtAssignSuggester; - public final Map missedNameSuggestions = new ConcurrentHashMap<>(); - - public LvtNamer(final HypoContext context, final MappingSet mappings) throws IOException { + public LvtNamer(final HypoContext context, final MappingSet mappings, final Reports reports) throws IOException { this.mappings = mappings; this.lvtTypeSuggester = new LvtTypeSuggester(context); - this.lvtAssignSuggester = new RootLvtSuggester(context, this.lvtTypeSuggester, this.missedNameSuggestions); + this.lvtAssignSuggester = new RootLvtSuggester(context, this.lvtTypeSuggester, reports); } public void processClass(final AsmClassData classData) throws IOException { diff --git a/codebook-lvt/src/main/java/io/papermc/codebook/lvt/RootLvtSuggester.java b/codebook-lvt/src/main/java/io/papermc/codebook/lvt/RootLvtSuggester.java index 24f4c69..e4fd22f 100644 --- a/codebook-lvt/src/main/java/io/papermc/codebook/lvt/RootLvtSuggester.java +++ b/codebook-lvt/src/main/java/io/papermc/codebook/lvt/RootLvtSuggester.java @@ -49,11 +49,11 @@ import io.papermc.codebook.lvt.suggestion.context.method.MethodInsnContext; import io.papermc.codebook.lvt.suggestion.numbers.MthRandomSuggester; import io.papermc.codebook.lvt.suggestion.numbers.RandomSourceSuggester; +import io.papermc.codebook.report.Reports; +import io.papermc.codebook.report.type.MissingMethodLvtSuggestion; import java.io.IOException; import java.util.List; -import java.util.Map; import java.util.Set; -import java.util.concurrent.atomic.AtomicInteger; import org.checkerframework.checker.nullness.qual.Nullable; import org.objectweb.asm.Opcodes; import org.objectweb.asm.tree.AbstractInsnNode; @@ -81,18 +81,15 @@ public final class RootLvtSuggester extends AbstractModule implements LvtSuggest private final HypoContext hypoContext; private final LvtTypeSuggester lvtTypeSuggester; - public final Map missedNameSuggestions; + private final Injector injector; private final List suggesters; public RootLvtSuggester( - final HypoContext hypoContext, - final LvtTypeSuggester lvtTypeSuggester, - final Map missedNameSuggestions) { + final HypoContext hypoContext, final LvtTypeSuggester lvtTypeSuggester, final Reports reports) { this.hypoContext = hypoContext; this.lvtTypeSuggester = lvtTypeSuggester; - this.missedNameSuggestions = missedNameSuggestions; - final Injector injector = Guice.createInjector(this); - this.suggesters = SUGGESTERS.stream().map(injector::getInstance).toList(); + this.injector = Guice.createInjector(this, reports); + this.suggesters = SUGGESTERS.stream().map(this.injector::getInstance).toList(); } @Override @@ -207,11 +204,9 @@ public static String determineFinalName(final String suggestedName, final Set new AtomicInteger(0)) - .incrementAndGet(); + this.injector + .getInstance(MissingMethodLvtSuggestion.class) + .reportMissingMethodLvtSuggestion(call.data(), insn.node()); return null; } diff --git a/codebook-reports/build.gradle.kts b/codebook-reports/build.gradle.kts new file mode 100644 index 0000000..6f37059 --- /dev/null +++ b/codebook-reports/build.gradle.kts @@ -0,0 +1,28 @@ +plugins { + `java-library` + id("codebook") +} + +dependencies { + implementation(platform(libs.hypo.platform)) + + api(libs.checker) + + implementation(libs.bundles.hypo.impl) + implementation(libs.bundles.asm) + + implementation(libs.guice) + implementation(libs.inject) + implementation(libs.guava) +} + +publishing { + publications { + codebook { + pom { + name.set("codebook-reports") + description.set("Codebook reports for PaperMC") + } + } + } +} diff --git a/codebook-reports/src/main/java/io/papermc/codebook/report/ReportType.java b/codebook-reports/src/main/java/io/papermc/codebook/report/ReportType.java new file mode 100644 index 0000000..c9eb4e1 --- /dev/null +++ b/codebook-reports/src/main/java/io/papermc/codebook/report/ReportType.java @@ -0,0 +1,28 @@ +/* + * 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.report; + +public enum ReportType { + MISSING_METHOD_LVT_SUGGESTION, + ; +} diff --git a/codebook-reports/src/main/java/io/papermc/codebook/report/Reports.java b/codebook-reports/src/main/java/io/papermc/codebook/report/Reports.java new file mode 100644 index 0000000..998c00f --- /dev/null +++ b/codebook-reports/src/main/java/io/papermc/codebook/report/Reports.java @@ -0,0 +1,68 @@ +/* + * 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.report; + +import com.google.inject.AbstractModule; +import io.papermc.codebook.report.type.MissingMethodLvtSuggestion; +import io.papermc.codebook.report.type.Report; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.Locale; +import java.util.Map; +import java.util.Map.Entry; +import java.util.Set; + +public class Reports extends AbstractModule { + + private final Path reportsDir; + private final Set typesToGenerate; + private final Map reports; + + public Reports(final Path reportsDir, final Set typesToGenerate) { + this.reportsDir = reportsDir; + this.typesToGenerate = typesToGenerate; + this.reports = Map.of(ReportType.MISSING_METHOD_LVT_SUGGESTION, new MissingMethodLvtSuggestion()); + } + + public void generateReports() throws IOException { + Files.createDirectories(this.reportsDir); + for (final Entry entry : this.reports.entrySet()) { + if (this.typesToGenerate.contains(entry.getKey())) { + final Path reportPath = + this.reportsDir.resolve(entry.getKey().name().toLowerCase(Locale.ENGLISH) + ".txt"); + Files.writeString(reportPath, entry.getValue().generate()); + } + } + } + + @Override + protected void configure() { + this.reports.values().forEach(this::bindReport); + } + + @SuppressWarnings("unchecked") + private void bindReport(final R report) { + this.bind((Class) report.getClass()).toInstance(report); + } +} diff --git a/codebook-reports/src/main/java/io/papermc/codebook/report/type/MissingMethodLvtSuggestion.java b/codebook-reports/src/main/java/io/papermc/codebook/report/type/MissingMethodLvtSuggestion.java new file mode 100644 index 0000000..17b12fb --- /dev/null +++ b/codebook-reports/src/main/java/io/papermc/codebook/report/type/MissingMethodLvtSuggestion.java @@ -0,0 +1,53 @@ +/* + * 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.report.type; + +import dev.denwav.hypo.model.data.MethodData; +import java.util.Comparator; +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.atomic.AtomicInteger; +import org.objectweb.asm.tree.MethodInsnNode; + +public class MissingMethodLvtSuggestion implements Report { + + private static final Comparator> COMPARATOR = + Comparator.comparing(e -> e.getValue().get()); + + private final Map data = new ConcurrentHashMap<>(); + + public void reportMissingMethodLvtSuggestion(final MethodData method, final MethodInsnNode insn) { + this.data + .computeIfAbsent(method.name() + "," + insn.owner + "," + insn.desc, (k) -> new AtomicInteger(0)) + .incrementAndGet(); + } + + @Override + public String generate() { + final StringBuilder output = new StringBuilder(); + this.data.entrySet().stream() + .sorted(COMPARATOR.reversed()) + .forEach(s -> output.append("missed: %s -- %s times%n".formatted(s.getKey(), s.getValue()))); + return output.toString(); + } +} diff --git a/codebook-reports/src/main/java/io/papermc/codebook/report/type/Report.java b/codebook-reports/src/main/java/io/papermc/codebook/report/type/Report.java new file mode 100644 index 0000000..f4e6aa6 --- /dev/null +++ b/codebook-reports/src/main/java/io/papermc/codebook/report/type/Report.java @@ -0,0 +1,28 @@ +/* + * 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.report.type; + +public interface Report { + + String generate(); +} diff --git a/settings.gradle.kts b/settings.gradle.kts index 3bac311..d758232 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -6,5 +6,6 @@ rootProject.name = "codebook" include("codebook-cli") include("codebook-lvt") +include("codebook-reports") enableFeaturePreview("TYPESAFE_PROJECT_ACCESSORS") diff --git a/src/main/java/io/papermc/codebook/CodeBook.java b/src/main/java/io/papermc/codebook/CodeBook.java index a288cc5..1364183 100644 --- a/src/main/java/io/papermc/codebook/CodeBook.java +++ b/src/main/java/io/papermc/codebook/CodeBook.java @@ -43,6 +43,7 @@ import io.papermc.codebook.pages.RemapLvtPage; import io.papermc.codebook.pages.UnpickPage; import io.papermc.codebook.util.IOUtil; +import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; import java.util.List; @@ -95,6 +96,13 @@ private void exec(final Path tempDir) { } IOUtil.move(resultJar, this.ctx.outputJar()); + if (this.ctx.reports() != null) { + try { + this.ctx.reports().generateReports(); + } catch (final IOException e) { + throw new RuntimeException(e); + } + } } private static Injector injector(final Module module) { @@ -172,6 +180,13 @@ protected void configure() { } 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()); + } else { + this.bind(CodeBookPage.Report.KEY).toProvider(Providers.of(null)); + } } }; } diff --git a/src/main/java/io/papermc/codebook/config/CodeBookContext.java b/src/main/java/io/papermc/codebook/config/CodeBookContext.java index 7bfe1c6..d20ecdb 100644 --- a/src/main/java/io/papermc/codebook/config/CodeBookContext.java +++ b/src/main/java/io/papermc/codebook/config/CodeBookContext.java @@ -22,6 +22,7 @@ package io.papermc.codebook.config; +import io.papermc.codebook.report.Reports; import io.soabase.recordbuilder.core.RecordBuilder; import java.nio.file.Path; import org.checkerframework.checker.nullness.qual.Nullable; @@ -41,7 +42,7 @@ public record CodeBookContext( @NotNull Path outputJar, boolean overwrite, @NotNull CodeBookInput input, - boolean logMissingLvtSuggestions) { + @Nullable @org.jetbrains.annotations.Nullable Reports reports) { public static CodeBookContextBuilder builder() { return CodeBookContextBuilder.builder(); diff --git a/src/main/java/io/papermc/codebook/pages/CodeBookPage.java b/src/main/java/io/papermc/codebook/pages/CodeBookPage.java index eee2773..c921b93 100644 --- a/src/main/java/io/papermc/codebook/pages/CodeBookPage.java +++ b/src/main/java/io/papermc/codebook/pages/CodeBookPage.java @@ -31,6 +31,7 @@ import com.google.inject.util.Providers; import dev.denwav.hypo.core.HypoContext; import io.papermc.codebook.config.CodeBookContext; +import io.papermc.codebook.report.Reports; import jakarta.inject.Qualifier; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; @@ -156,4 +157,11 @@ public void to(final @Nullable T value) { public @interface Hypo { Key KEY = Key.get(HypoContext.class, Hypo.class); } + + @Qualifier + @Target(ElementType.PARAMETER) + @Retention(RetentionPolicy.RUNTIME) + public @interface Report { + Key KEY = Key.get(Reports.class, Report.class); + } } diff --git a/src/main/java/io/papermc/codebook/pages/RemapLvtPage.java b/src/main/java/io/papermc/codebook/pages/RemapLvtPage.java index e3e115c..f1003e3 100644 --- a/src/main/java/io/papermc/codebook/pages/RemapLvtPage.java +++ b/src/main/java/io/papermc/codebook/pages/RemapLvtPage.java @@ -26,53 +26,42 @@ import dev.denwav.hypo.core.HypoContext; import dev.denwav.hypo.model.HypoModelUtil; import dev.denwav.hypo.model.data.ClassData; -import io.papermc.codebook.config.CodeBookContext; import io.papermc.codebook.exceptions.UnexpectedException; import io.papermc.codebook.lvt.LvtNamer; +import io.papermc.codebook.report.Reports; import jakarta.inject.Inject; import java.io.IOException; import java.util.ArrayList; -import java.util.Comparator; -import java.util.Map; import java.util.concurrent.ExecutionException; import java.util.concurrent.Future; -import java.util.concurrent.atomic.AtomicInteger; import org.cadixdev.lorenz.MappingSet; public final class RemapLvtPage extends CodeBookPage { private final HypoContext context; private final MappingSet paramMappings; - private final boolean logMissingLvtSuggestions; + private final Reports reports; @Inject public RemapLvtPage( @Hypo final HypoContext hypoContext, @ParamMappings final MappingSet paramMappings, - @Context final CodeBookContext context) { + @Report final Reports reports) { this.context = hypoContext; this.paramMappings = paramMappings; - this.logMissingLvtSuggestions = context.logMissingLvtSuggestions(); + this.reports = reports; } @Override public void exec() { final LvtNamer lvtNamer; try { - lvtNamer = new LvtNamer(this.context, this.paramMappings); + lvtNamer = new LvtNamer(this.context, this.paramMappings, this.reports); } catch (final IOException e) { throw new UnexpectedException("Failed to create LVT namer", e); } this.remapLvt(lvtNamer); - - if (this.logMissingLvtSuggestions) { - final var comparator = Comparator., Integer>comparing( - e -> e.getValue().get()); - lvtNamer.missedNameSuggestions.entrySet().stream() - .sorted(comparator.reversed()) - .forEach(s -> System.out.println("missed: " + s.getKey() + " -- " + s.getValue() + " times")); - } } private void remapLvt(final LvtNamer lvtNamer) { diff --git a/src/test/java/io/papermc/codebook/lvt/LvtAssignmentSuggesterTest.java b/src/test/java/io/papermc/codebook/lvt/LvtAssignmentSuggesterTest.java index 385157e..08b03db 100644 --- a/src/test/java/io/papermc/codebook/lvt/LvtAssignmentSuggesterTest.java +++ b/src/test/java/io/papermc/codebook/lvt/LvtAssignmentSuggesterTest.java @@ -42,9 +42,9 @@ import io.papermc.codebook.lvt.suggestion.context.ContainerContext; import io.papermc.codebook.lvt.suggestion.context.method.MethodCallContext; import io.papermc.codebook.lvt.suggestion.context.method.MethodInsnContext; +import io.papermc.codebook.report.Reports; import java.io.IOException; import java.util.EnumSet; -import java.util.HashMap; import org.checkerframework.checker.nullness.qual.Nullable; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.extension.ExtendWith; @@ -82,6 +82,9 @@ class LvtAssignmentSuggesterTest { @Mock private ClassData randomSourceClass; + @Mock + private Reports reports; + @BeforeEach void setup() throws Exception { final HypoContext context = @@ -95,7 +98,7 @@ void setup() throws Exception { when(this.randomSourceClass.name()).thenReturn(RANDOM_SOURCE_TYPE.asInternalName()); - this.suggester = new RootLvtSuggester(context, new LvtTypeSuggester(context), new HashMap<>()); + this.suggester = new RootLvtSuggester(context, new LvtTypeSuggester(context), this.reports); } @ParameterizedTest From cce7c7dccaf3b15d29c6a3e13bcad6b099e77154 Mon Sep 17 00:00:00 2001 From: MiniDigger | Martin Date: Sun, 14 Jan 2024 18:47:37 +0100 Subject: [PATCH 2/2] make stuff run if we have no reports --- .../java/io/papermc/codebook/report/Reports.java | 13 +++++++++++++ src/main/java/io/papermc/codebook/CodeBook.java | 4 +++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/codebook-reports/src/main/java/io/papermc/codebook/report/Reports.java b/codebook-reports/src/main/java/io/papermc/codebook/report/Reports.java index 998c00f..430b8eb 100644 --- a/codebook-reports/src/main/java/io/papermc/codebook/report/Reports.java +++ b/codebook-reports/src/main/java/io/papermc/codebook/report/Reports.java @@ -35,6 +35,19 @@ public class Reports extends AbstractModule { + @SuppressWarnings({"DataFlowIssue"}) + public static final Reports NOOP = new Reports(null, Set.of()) { + @Override + public void generateReports() { + // NO-OP + } + + @Override + protected void configure() { + // NO-OP + } + }; + private final Path reportsDir; private final Set typesToGenerate; private final Map reports; diff --git a/src/main/java/io/papermc/codebook/CodeBook.java b/src/main/java/io/papermc/codebook/CodeBook.java index 1364183..29baa70 100644 --- a/src/main/java/io/papermc/codebook/CodeBook.java +++ b/src/main/java/io/papermc/codebook/CodeBook.java @@ -42,6 +42,7 @@ 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; import java.io.IOException; import java.nio.file.Files; @@ -185,7 +186,8 @@ protected void configure() { this.bind(CodeBookPage.Report.KEY).toInstance(CodeBook.this.ctx.reports()); this.install(CodeBook.this.ctx.reports()); } else { - this.bind(CodeBookPage.Report.KEY).toProvider(Providers.of(null)); + this.bind(CodeBookPage.Report.KEY).toInstance(Reports.NOOP); + this.install(Reports.NOOP); } } };