diff --git a/build.gradle b/build.gradle index e3d2377757..9e519efa2c 100644 --- a/build.gradle +++ b/build.gradle @@ -87,7 +87,6 @@ dependencies { javadocClasspath(libs.quilt.loader) javadocClasspath(libs.jetbrains.annotations) javadocClasspath(libs.jsr305) // for some other jsr annotations - decompileClasspath(libs.cfr) unpick(libs.unpick.cli) hashed "org.quiltmc:hashed:${minecraft_version}${USE_SNAPSHOT_HASHES ? "-SNAPSHOT" : ""}" intermediary "net.fabricmc:intermediary:${minecraft_version}:v2" @@ -283,17 +282,6 @@ task genFakeSource(type: DecompileTask, dependsOn: [mergeTinyV2, eraseBytecode]) } } -task decompileCFR(type: DecompileTask, dependsOn: [mapNamedJar]) { - input.set mappings.fileConstants.namedJar - output.set file("namedSrc") - decompiler = Decompilers.CFR - libraries = files(configurations.decompileClasspath) - - doFirst { - file("namedSrc").deleteDir() - } -} - task decompileVineflower(type: DecompileTask, dependsOn: [mapNamedJar]) { input.set mappings.fileConstants.namedJar output.set file("namedSrc") diff --git a/buildSrc/build.gradle b/buildSrc/build.gradle index df69e16d55..a88b3c3893 100644 --- a/buildSrc/build.gradle +++ b/buildSrc/build.gradle @@ -47,7 +47,6 @@ dependencies { implementation(libs.javadoc.draftsman) // Decompilers - implementation(libs.cfr) implementation(libs.vineflower) // Testing diff --git a/buildSrc/src/main/java/quilt/internal/decompile/Decompilers.java b/buildSrc/src/main/java/quilt/internal/decompile/Decompilers.java index ad782b34b3..d1b72d137d 100644 --- a/buildSrc/src/main/java/quilt/internal/decompile/Decompilers.java +++ b/buildSrc/src/main/java/quilt/internal/decompile/Decompilers.java @@ -1,10 +1,8 @@ package quilt.internal.decompile; -import quilt.internal.decompile.cfr.CfrDecompiler; import quilt.internal.decompile.vineflower.VineflowerDecompiler; public enum Decompilers { - CFR(CfrDecompiler::new), VINEFLOWER(VineflowerDecompiler::new); private final DecompilerProvider provider; diff --git a/buildSrc/src/main/java/quilt/internal/decompile/cfr/CfrDecompiler.java b/buildSrc/src/main/java/quilt/internal/decompile/cfr/CfrDecompiler.java deleted file mode 100644 index 0f8cc8bf4f..0000000000 --- a/buildSrc/src/main/java/quilt/internal/decompile/cfr/CfrDecompiler.java +++ /dev/null @@ -1,74 +0,0 @@ -package quilt.internal.decompile.cfr; - -import org.benf.cfr.reader.Driver; -import org.benf.cfr.reader.state.ClassFileSourceImpl; -import org.benf.cfr.reader.state.DCCommonState; -import org.benf.cfr.reader.util.AnalysisType; -import org.benf.cfr.reader.util.getopt.Options; -import org.benf.cfr.reader.util.getopt.OptionsImpl; -import org.benf.cfr.reader.util.output.SinkDumperFactory; -import org.gradle.api.Project; -import quilt.internal.decompile.AbstractDecompiler; -import quilt.internal.decompile.javadoc.ClassJavadocProvider; -import quilt.internal.decompile.javadoc.FieldJavadocProvider; -import quilt.internal.decompile.javadoc.MethodJavadocProvider; - -import java.io.File; -import java.util.Collection; -import java.util.Map; -import java.util.stream.Collectors; - -public class CfrDecompiler extends AbstractDecompiler { - private ClassJavadocProvider classJavadocProvider; - private FieldJavadocProvider fieldJavadocProvider; - private MethodJavadocProvider methodJavadocProvider; - - public CfrDecompiler(Project project) { - super(project); - } - - @Override - public void decompile(File file, File outputDir, Map optionsMap, Collection libraries) { - Map stringOptions = optionsMap.entrySet().stream().collect(Collectors.toMap(Map.Entry::getKey, e -> e.getValue().toString())); - Options options = OptionsImpl.getFactory().create(stringOptions); - - ClassFileSourceImpl classFileSource = new ClassFileSourceImpl(options); - - for (File library : libraries) { - classFileSource.addJarContent(library.getAbsolutePath(), AnalysisType.JAR); - } - - classFileSource.informAnalysisRelativePathDetail(null, null); - - DCCommonState state = new DCCommonState(options, classFileSource); - - if (hasMemberJavadocProvider()) { - CfrObfuscationMapping obfuscationMapping = new CfrObfuscationMapping(this.classJavadocProvider, this.fieldJavadocProvider, this.methodJavadocProvider); - state = new DCCommonState(state, obfuscationMapping); - } - - CfrSinkFactory sinkFactory = new CfrSinkFactory(outputDir, getProject().getLogger()); - SinkDumperFactory sinkDumperFactory = new SinkDumperFactory(sinkFactory, options); - - Driver.doJar(state, file.getAbsolutePath(), AnalysisType.JAR, sinkDumperFactory); - } - - private boolean hasMemberJavadocProvider() { - return this.classJavadocProvider != null || this.fieldJavadocProvider != null || this.methodJavadocProvider != null; - } - - @Override - public void withClassJavadocProvider(ClassJavadocProvider javadocProvider) { - this.classJavadocProvider = javadocProvider; - } - - @Override - public void withFieldJavadocProvider(FieldJavadocProvider javadocProvider) { - this.fieldJavadocProvider = javadocProvider; - } - - @Override - public void withMethodJavadocProvider(MethodJavadocProvider javadocProvider) { - this.methodJavadocProvider = javadocProvider; - } -} diff --git a/buildSrc/src/main/java/quilt/internal/decompile/cfr/CfrObfuscationMapping.java b/buildSrc/src/main/java/quilt/internal/decompile/cfr/CfrObfuscationMapping.java deleted file mode 100644 index cb520047af..0000000000 --- a/buildSrc/src/main/java/quilt/internal/decompile/cfr/CfrObfuscationMapping.java +++ /dev/null @@ -1,89 +0,0 @@ -package quilt.internal.decompile.cfr; - -import org.benf.cfr.reader.bytecode.analysis.types.JavaRefTypeInstance; -import org.benf.cfr.reader.bytecode.analysis.types.JavaTypeInstance; -import org.benf.cfr.reader.bytecode.analysis.types.MethodPrototype; -import org.benf.cfr.reader.entities.ClassFile; -import org.benf.cfr.reader.entities.Field; -import org.benf.cfr.reader.mapping.NullMapping; -import org.benf.cfr.reader.util.output.DelegatingDumper; -import org.benf.cfr.reader.util.output.Dumper; -import quilt.internal.decompile.javadoc.ClassJavadocProvider; -import quilt.internal.decompile.javadoc.FieldJavadocProvider; -import quilt.internal.decompile.javadoc.MethodJavadocProvider; - -public class CfrObfuscationMapping extends NullMapping { - private final ClassJavadocProvider classJavadocProvider; - private final FieldJavadocProvider fieldJavadocProvider; - private final MethodJavadocProvider methodJavadocProvider; - - public CfrObfuscationMapping(ClassJavadocProvider classJavadocProvider, FieldJavadocProvider fieldJavadocProvider, MethodJavadocProvider methodJavadocProvider) { - this.classJavadocProvider = classJavadocProvider != null ? classJavadocProvider : ClassJavadocProvider.EMPTY; - this.fieldJavadocProvider = fieldJavadocProvider != null ? fieldJavadocProvider : FieldJavadocProvider.EMPTY; - this.methodJavadocProvider = methodJavadocProvider != null ? methodJavadocProvider : MethodJavadocProvider.EMPTY; - } - - @Override - public Dumper wrap(Dumper d) { - return new JavadocDumper(d); - } - - public class JavadocDumper extends DelegatingDumper { - public JavadocDumper(Dumper delegate) { - super(delegate); - } - - @Override - public Dumper dumpClassDoc(JavaTypeInstance owner) { - String javadoc = classJavadocProvider.provideClassJavadoc(owner.getRawName(), isRecord(owner)); - if (javadoc != null) { - dumpJavadoc(javadoc); - } - - return this; - } - - @Override - public Dumper dumpMethodDoc(MethodPrototype method) { - String javadoc = methodJavadocProvider.provideMethodJavadoc(method.getName(), method.getOriginalDescriptor(), method.getOwner().getRawName()); - if (javadoc != null) { - dumpJavadoc(javadoc); - } - - return this; - } - - @Override - public Dumper dumpFieldDoc(Field field, JavaTypeInstance owner) { - String javadoc = fieldJavadocProvider.provideFieldJavadoc(field.getFieldName(), field.getDescriptor(), owner.getRawName()); - if (javadoc != null) { - dumpJavadoc(javadoc); - } - - return this; - } - - private boolean isRecord(JavaTypeInstance owner) { - if (owner instanceof JavaRefTypeInstance) { - ClassFile classFile = ((JavaRefTypeInstance) owner).getClassFile(); - return classFile.getClassSignature().getSuperClass().getRawName().equals("java.lang.Record"); - } - - return false; - } - - private void dumpJavadoc(String javadoc) { - if (javadoc == null || javadoc.isBlank()) { - return; - } - - print("/**").newln(); - - for (String line : javadoc.split("\n")) { - print(" * ").print(line).newln(); - } - - print(" */").newln(); - } - } -} diff --git a/buildSrc/src/main/java/quilt/internal/decompile/cfr/CfrSinkFactory.java b/buildSrc/src/main/java/quilt/internal/decompile/cfr/CfrSinkFactory.java deleted file mode 100644 index bbccbd8243..0000000000 --- a/buildSrc/src/main/java/quilt/internal/decompile/cfr/CfrSinkFactory.java +++ /dev/null @@ -1,64 +0,0 @@ -package quilt.internal.decompile.cfr; - -import org.benf.cfr.reader.api.OutputSinkFactory; -import org.benf.cfr.reader.api.SinkReturns; -import org.gradle.api.logging.Logger; - -import java.io.File; -import java.io.IOException; -import java.nio.file.Files; -import java.nio.file.Path; -import java.util.Collection; -import java.util.Collections; -import java.util.List; - -class CfrSinkFactory implements OutputSinkFactory { - private final Logger logger; - private final File outputDir; - - public CfrSinkFactory(File outputDir, Logger logger) { - this.outputDir = outputDir; - this.logger = logger; - } - - private static void writeDecompiled(SinkReturns.Decompiled decompiled, File outputDir) { - String packageName = decompiled.getPackageName().replace(".", "/"); - if (!packageName.isEmpty()) { - packageName += "/"; - } - - String fileName = decompiled.getClassName() + ".java"; - String path = packageName + fileName; - - try { - Path outputFile = outputDir.toPath().resolve(path); - if (!Files.exists(outputFile.getParent())) { - Files.createDirectories(outputFile.getParent()); - } - - Files.writeString(outputFile, decompiled.getJava()); - } catch (IOException e) { - throw new RuntimeException("Failed to write decompiled file " + path, e); - } - } - - @Override - public List getSupportedSinks(SinkType sinkType, Collection available) { - return switch (sinkType) { - case JAVA -> List.of(SinkClass.DECOMPILED); - case EXCEPTION -> List.of(SinkClass.STRING, SinkClass.EXCEPTION_MESSAGE); - case PROGRESS -> List.of(SinkClass.STRING); - default -> Collections.emptyList(); - }; - } - - @Override - public Sink getSink(SinkType sinkType, SinkClass sinkClass) { - return switch (sinkType) { - case JAVA -> (d -> writeDecompiled((SinkReturns.Decompiled) d, outputDir)); - case EXCEPTION -> (e -> logger.error((String) e)); - case PROGRESS -> (p -> logger.debug((String) p)); - default -> null; - }; - } -} diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index a619085f87..fd80633bfe 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -15,13 +15,12 @@ javadoc_draftsman = "1.2.3" quilt_loader = "0.26.1" jetbrains_annotations = "23.0.0" jsr305 = "3.0.2" -gson = "2.9.1" +gson = "2.10.1" netty = "4.1" vineflower = "1.10.1" -cfr = "0.2.2" -junit = "5.9.1" +junit = "5.9.3" proguard = "7.5.0" [libraries] @@ -48,7 +47,6 @@ jetbrains_annotations = { module = "org.jetbrains:annotations", version.ref = "j jsr305 = { module = "com.google.code.findbugs:jsr305", version.ref = "jsr305" } # Decompilers -cfr = { module = "net.fabricmc:cfr", version.ref = "cfr" } vineflower = { module = "org.vineflower:vineflower", version.ref = "vineflower" } # Testing