Skip to content

Commit

Permalink
Merge branch 'master' into navigator-fix
Browse files Browse the repository at this point in the history
  • Loading branch information
PiTheGuy authored Nov 2, 2024
2 parents aed7352 + 2983b4f commit 9472635
Show file tree
Hide file tree
Showing 42 changed files with 576 additions and 98 deletions.
37 changes: 36 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,8 @@ More bugfixes. I work so hard for my beloved users.

# 2.5.0

`2.5.0` brings contributions from 3 of our lovely enigma users in addition to our regular duo, bringing you some reworks to long-broken features and fixing some long-bothersome bugs!

- new [theme system and theme](https://github.com/QuiltMC/enigma/pull/216) (thanks [supersaiyansubtlety](https://github.com/supersaiyansubtlety)!)
- adds a new theme: darcerula
- this theme is yet darker than the old dark theme, for those that appreciate a pitch black atmosphere for their mappings
Expand All @@ -248,7 +250,12 @@ More bugfixes. I work so hard for my beloved users.
- can be enabled by setting the `index_libraries` property to true in service's config in the enigma profile
- refer to Javadocs in `JarIndexerService` for how to implement this property, we recommend adding it!
- currently, only `Record` and `Object` from the JDK are indexed as libraries by default
- added name proposal for record components
- API changes around indexing
- `JarIndex#indexJar` no longer receives a scope
- the `ClassProvider` parameter has been replaced with a `ProjectClassProvider`, providing classes and scope for both the main jar and libraries
- `JarIndexerService#acceptJar` now takes a `ProjectClassProvider` instead of a `ClassProvider`
- the scope has not been removed, and if the service is configured to accept libraries will be the main scope on first run and the library scope on the second
- added name proposal for record components
- names for record getters are automatically proposed as their corresponding field is named
- methods are linked to fields based on bytecode
- this is a fail-fast solution: if there is no method perfectly matching the expected code for a record getter no mapping will be proposed
Expand All @@ -271,3 +278,31 @@ More bugfixes. I work so hard for my beloved users.
- fixed a bunch more scaling issues (thanks [supersaiyansubtlety](https://github.com/supersaiyansubtlety) again!)
- fixed config values sometimes being messed up when changing scale and restarting
- fixed editor font size sometimes being overwritten
- fixed possibly incorrect save location when saving from the unsaved warning dialogue (thanks again [pitheguy](https://github.com/PiTheGuy)!)

# 2.5.1

Hot off the tail of `2.5`, enigma `2.5.1` features some minor improvements to `drop-invalid-mappings` and the usual wealth of bugfixes.
But honey, I know you're just here to see if you can remove the ASM snapshot repo from your buildscript. I'm happy to report that you can!

- improved `drop-invalid-mappings` command
- improved logging
- do not print lines about writing new mappings when no changes have occurred
- print stats after completion on how many mappings were dropped
- improved behaviour for dropping
- drop methods that have no name and no valid parameters
- drop parameters whose index is outside their parent method's scope of valid indices
- added unit testing
- fixed various issues with javadoc on parameters
- fixed comments on parameters sometimes being improperly written by the tinyv2 writer
- fixed javadoc on method overrides not properly finding parameter names
- fixed javadoc not always refreshing on parameter name updates
- fixed entry navigator pointing to the wrong entry after an entry's token type was changed
- the most common time this would occur was when you renamed an obfuscated entry with the default navigator, and since there were then a different amount of obfuscated entries, the navigator would point to a different one than previously
- this fix is thanks to [pitheguy](https://github.com/PiTheGuy)!
- fixed identifier panel mislabelling inner classes' outer class as their "superclass"
- fixed stats of parent classes not reloading when their entries are mapped from a child class
- fixed folder icons in the "obfuscated classes" docker not being visible
- updated dependencies
- asm: `9.8-SNAPSHOT` -> `9.7.1`
- you can now remove the ASM snapshot repo from your buildscript when depending on enigma through maven/gradle!
6 changes: 1 addition & 5 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,6 @@ subprojects {
maven {
url = "https://maven.fabricmc.net/"
}
// remove when ASM fix is released
maven {
url = "https://repository.ow2.org/nexus/content/repositories/snapshots/"
}
}

dependencies {
Expand All @@ -35,7 +31,7 @@ subprojects {
}

group = 'org.quiltmc'
version = '2.5.0'
version = '2.5.1'

var ENV = System.getenv()
version = version + (ENV.GITHUB_ACTIONS ? (ENV.SNAPSHOTS_URL ? "-SNAPSHOT" : "") : "+local")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import org.quiltmc.enigma.api.class_provider.CachingClassProvider;
import org.quiltmc.enigma.api.class_provider.ClasspathClassProvider;
import org.quiltmc.enigma.api.class_provider.JarClassProvider;
import org.quiltmc.enigma.api.class_provider.ProjectClassProvider;
import org.quiltmc.enigma.api.translation.mapping.EntryMapping;
import org.quiltmc.enigma.api.translation.mapping.MappingDelta;
import org.quiltmc.enigma.api.translation.mapping.serde.MappingParseException;
Expand Down Expand Up @@ -108,7 +109,7 @@ public static JarIndex loadJar(Path jar) throws IOException {
Logger.info("Reading JAR...");
JarClassProvider classProvider = new JarClassProvider(jar);
JarIndex index = MainJarIndex.empty();
index.indexJar(classProvider.getClassNames(), new CachingClassProvider(classProvider), ProgressListener.createEmpty());
index.indexJar(new ProjectClassProvider(new CachingClassProvider(classProvider), null), ProgressListener.createEmpty());

return index;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public String getName() {

@Override
public String getDescription() {
return "Removes all invalid mapping entries (entries whose obfuscated name is not found in the jar) from the provided mappings.";
return "Removes all invalid mapping entries (entries whose obfuscated name is not found in the jar) and empty mappings (garbage lines that don't add anything to the mappings) from the provided mappings.";
}

public static void run(Path jarIn, Path mappingsIn, Path mappingsOut) throws Exception {
Expand All @@ -51,30 +51,35 @@ public static void run(Path jarIn, Path mappingsIn, Path mappingsOut) throws Exc

Logger.info("Dropping invalid mappings...");

project.dropMappings(ProgressListener.createEmpty());

Logger.info("Writing mappings...");

if (mappingsOut == mappingsIn) {
Logger.info("Overwriting input mappings");
Files.walkFileTree(mappingsIn, new SimpleFileVisitor<>() {
@Override
public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException {
Files.delete(dir);
return FileVisitResult.CONTINUE;
}

@Override
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
Files.delete(file);
return FileVisitResult.CONTINUE;
}
});

Files.deleteIfExists(mappingsIn);
var droppedMappings = project.dropMappings(ProgressListener.createEmpty());

if (!droppedMappings.isEmpty()) {
Logger.info("Found and dropped {} invalid mappings.", droppedMappings.size());
Logger.info("Writing mappings...");

if (mappingsOut == mappingsIn) {
Logger.info("Overwriting input mappings");
Files.walkFileTree(mappingsIn, new SimpleFileVisitor<>() {
@Override
public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException {
Files.delete(dir);
return FileVisitResult.CONTINUE;
}

@Override
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
Files.delete(file);
return FileVisitResult.CONTINUE;
}
});

Files.deleteIfExists(mappingsIn);
}

MappingSaveParameters saveParameters = project.getEnigma().getProfile().getMappingSaveParameters();
writer.write(project.getRemapper().getMappings(), mappingsOut, ProgressListener.createEmpty(), saveParameters);
} else {
Logger.info("No invalid mappings found.");
}

MappingSaveParameters saveParameters = project.getEnigma().getProfile().getMappingSaveParameters();
writer.write(project.getRemapper().getMappings(), mappingsOut, ProgressListener.createEmpty(), saveParameters);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package org.quiltmc.enigma.command;

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.quiltmc.enigma.TestUtil;

import java.nio.file.Files;
import java.nio.file.Path;

public class DropInvalidMappingsTest extends CommandTest {
private static final Path JAR = TestUtil.obfJar("lone_class");
private static final Path INPUT_DIR = getResource("/drop_invalid_mappings/input/");
private static final Path EXPECTED_DIR = getResource("/drop_invalid_mappings/expected/");
private static final Path INVALID_MAPPINGS_INPUT = INPUT_DIR.resolve("InvalidMappings.mapping");
private static final Path INVALID_MAPPINGS_EXPECTED = EXPECTED_DIR.resolve("InvalidMappings.mapping");
private static final Path EMPTY_MAPPINGS_INPUT = INPUT_DIR.resolve("EmptyMappings.mapping");
private static final Path EMPTY_MAPPINGS_EXPECTED = EXPECTED_DIR.resolve("EmptyMappings.mapping");

@Test
public void testInvalidMappings() throws Exception {
Path resultFile = Files.createTempFile("invalidMappingsResult", ".mapping");

DropInvalidMappingsCommand.run(JAR, INVALID_MAPPINGS_INPUT, resultFile);

String expectedLines = Files.readString(INVALID_MAPPINGS_EXPECTED);
String actualLines = Files.readString(resultFile);

Assertions.assertEquals(expectedLines, actualLines);
}

@Test
public void testEmptyMappings() throws Exception {
Path resultFile = Files.createTempFile("emptyMappingsResult", ".mapping");

DropInvalidMappingsCommand.run(JAR, EMPTY_MAPPINGS_INPUT, resultFile);

String expectedLines = Files.readString(EMPTY_MAPPINGS_EXPECTED);
String actualLines = Files.readString(resultFile);

Assertions.assertEquals(expectedLines, actualLines);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package org.quiltmc.enigma.command;

import org.junit.jupiter.api.Test;

public class HelpCommandTest {
@Test
void test() throws Exception {
// for manually verifying output
new HelpCommand().run();
}
}
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
CLASS a InvalidMappings
FIELD a slayField Ljava/lang/String;
METHOD <init> (Ljava/lang/String;)V
ARG 1 coolParameter
METHOD a slayMethod ()Ljava/lang/String;
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
CLASS a
FIELD a Ljava/lang/String;
METHOD <init> (Ljava/lang/String;)V
ARG 1
METHOD a ()Ljava/lang/String;
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
CLASS a InvalidMappings
FIELD a slayField Ljava/lang/String;
FIELD b fakeField I
METHOD <init> (Ljava/lang/String;)V
ARG 0 outOfBoundsParameter1
ARG 1 coolParameter
ARG 2 outOfBoundsParameter2
ARG 3 outOfBoundsParameter3
METHOD a slayMethod ()Ljava/lang/String;
ARG 1 fakeParameter
METHOD b fakeMethod ()V
CLASS b NonExistentClass
25 changes: 21 additions & 4 deletions enigma-swing/src/main/java/org/quiltmc/enigma/gui/Gui.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import org.quiltmc.enigma.api.Enigma;
import org.quiltmc.enigma.api.EnigmaProfile;
import org.quiltmc.enigma.api.analysis.EntryReference;
import org.quiltmc.enigma.api.analysis.index.jar.InheritanceIndex;
import org.quiltmc.enigma.api.source.TokenType;
import org.quiltmc.enigma.api.translation.mapping.EntryMapping;
import org.quiltmc.enigma.api.translation.mapping.EntryRemapper;
Expand Down Expand Up @@ -54,6 +55,7 @@
import javax.swing.JScrollBar;
import javax.swing.JSplitPane;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;
import javax.swing.WindowConstants;
import java.awt.BorderLayout;
import java.awt.Container;
Expand Down Expand Up @@ -161,6 +163,9 @@ private void setupDockers() {
}

private void setupUi() {
// fix folder icons being automatically hidden: https://github.com/JFormDesigner/FlatLaf/pull/609
UIManager.put("Tree.showDefaultIcons", true);

this.setupDockers();

this.jarFileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
Expand Down Expand Up @@ -488,7 +493,9 @@ public void showDiscardDiag(IntFunction<Void> callback, String... options) {
public CompletableFuture<Void> saveMapping() {
ExtensionFileFilter.setupFileChooser(this.getController().getGui(), this.mappingsFileChooser, this.controller.getReadWriteService());

if (this.mappingsFileChooser.getSelectedFile() != null || this.mappingsFileChooser.showSaveDialog(this.mainWindow.getFrame()) == JFileChooser.APPROVE_OPTION) {
if (this.mappingsFileChooser.getSelectedFile() != null) {
return this.controller.saveMappings(this.mappingsFileChooser.getSelectedFile().toPath());
} else if (this.mappingsFileChooser.showSaveDialog(this.mainWindow.getFrame()) == JFileChooser.APPROVE_OPTION) {
return this.controller.saveMappings(ExtensionFileFilter.getSavePath(this.mappingsFileChooser));
}

Expand Down Expand Up @@ -584,18 +591,28 @@ public void moveClassTree(ClassEntry classEntry, boolean updateSwingState, boole
allClassesSelector.restoreExpansionState(expansionState);
deobfuscatedClassSelector.restoreExpansionState(deobfuscatedPanelExpansionState);
obfuscatedClassSelector.restoreExpansionState(obfuscatedPanelExpansionState);
this.reloadStats(classEntry);
this.reloadStats(classEntry, false);
}
}

/**
* Reloads stats for the provided class in all selectors.
* @param classEntry the class to reload
* @param propagate whether to also reload ancestors of the class
*/
public void reloadStats(ClassEntry classEntry) {
public void reloadStats(ClassEntry classEntry, boolean propagate) {
List<ClassEntry> toUpdate = new ArrayList<>();
toUpdate.add(classEntry);
if (propagate) {
Collection<ClassEntry> parents = this.controller.getProject().getJarIndex().getIndex(InheritanceIndex.class).getAncestors(classEntry);
toUpdate.addAll(parents);
}

for (Docker value : this.dockerManager.getDockers()) {
if (value instanceof ClassesDocker docker) {
docker.getClassSelector().reloadStats(classEntry);
for (ClassEntry entry : toUpdate) {
docker.getClassSelector().reloadStats(entry);
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@
import org.quiltmc.enigma.api.EnigmaProject;
import org.quiltmc.enigma.api.ProgressListener;
import org.quiltmc.enigma.api.analysis.index.jar.EntryIndex;
import org.quiltmc.enigma.api.analysis.index.jar.InheritanceIndex;
import org.quiltmc.enigma.api.analysis.tree.ClassImplementationsTreeNode;
import org.quiltmc.enigma.api.analysis.tree.ClassInheritanceTreeNode;
import org.quiltmc.enigma.api.analysis.tree.ClassReferenceTreeNode;
import org.quiltmc.enigma.api.analysis.EntryReference;
import org.quiltmc.enigma.api.analysis.tree.FieldReferenceTreeNode;
import org.quiltmc.enigma.api.service.ReadWriteService;
import org.quiltmc.enigma.api.translation.representation.entry.LocalVariableEntry;
import org.quiltmc.enigma.gui.dialog.CrashDialog;
import org.quiltmc.enigma.gui.network.IntegratedEnigmaClient;
import org.quiltmc.enigma.impl.analysis.IndexTreeBuilder;
Expand Down Expand Up @@ -553,6 +555,16 @@ private void applyChange0(ValidationContext vc, EntryChange<?> change, boolean u

if (!Objects.equals(prev.targetName(), mapping.targetName()) || !Objects.equals(prev.tokenType(), mapping.tokenType())) {
this.chp.invalidateMapped();

// local variable entries need to be propagated up the tree to update param names in javadoc
if (target instanceof LocalVariableEntry) {
this.chp.invalidateJavadoc(target.getTopLevelClass());

var children = this.project.getJarIndex().getIndex(InheritanceIndex.class).getChildren(target.getContainingClass());
for (ClassEntry child : children) {
this.chp.invalidateJavadoc(child.getTopLevelClass());
}
}
}

if (!Objects.equals(prev.javadoc(), mapping.javadoc())) {
Expand All @@ -564,7 +576,9 @@ private void applyChange0(ValidationContext vc, EntryChange<?> change, boolean u
boolean isNewOb = mapping.targetName() == null;
this.gui.moveClassTree(target.getContainingClass(), updateSwingState, isOldOb, isNewOb);
} else if (updateSwingState) {
this.gui.reloadStats(change.getTarget().getTopLevelClass());
// update stat icons for classes that could have had their mappings changed by this update
boolean propagate = target instanceof FieldEntry || target instanceof MethodEntry || target instanceof LocalVariableEntry;
this.gui.reloadStats(change.getTarget().getTopLevelClass(), propagate);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import javax.swing.Icon;
import javax.swing.JLabel;
import javax.swing.JTree;
import javax.swing.UIManager;
import javax.swing.tree.DefaultTreeCellRenderer;
import java.awt.Component;
import java.util.function.Function;
Expand All @@ -27,9 +26,6 @@ public class ClassTreeCellRenderer extends DefaultTreeCellRenderer {
public ClassTreeCellRenderer(Gui gui, ClassSelector selector) {
this.controller = gui.getController();
this.selector = selector;

// fix folder icons being automatically hidden: https://github.com/JFormDesigner/FlatLaf/pull/609
UIManager.put("Tree.showDefaultIcons", true);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ public void refreshReference() {
th.addCopiableStringRow(I18n.translate("info_panel.identifier.obfuscated"), this.entry.getName());

if (ce.getParent() != null) {
th.addCopiableStringRow(I18n.translate("info_panel.identifier.superclass"), ce.getParent().getFullName());
th.addCopiableStringRow(I18n.translate("info_panel.identifier.outer_class"), ce.getParent().getFullName());
}
} else if (this.deobfEntry instanceof FieldEntry fe) {
this.nameField = th.addRenameTextField(EditableType.FIELD, fe.getName());
Expand Down
Loading

0 comments on commit 9472635

Please sign in to comment.