-
-
Notifications
You must be signed in to change notification settings - Fork 32
Drop proposed mappings from the files #278
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
package org.quiltmc.enigma.command; | ||
|
||
import org.quiltmc.enigma.api.Enigma; | ||
import org.quiltmc.enigma.api.EnigmaProfile; | ||
import org.quiltmc.enigma.api.EnigmaProject; | ||
import org.quiltmc.enigma.api.ProgressListener; | ||
import org.quiltmc.enigma.api.translation.mapping.serde.MappingSaveParameters; | ||
import org.quiltmc.enigma.api.translation.mapping.serde.MappingsWriter; | ||
import org.tinylog.Logger; | ||
|
||
import java.io.IOException; | ||
import java.nio.file.FileVisitResult; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import java.nio.file.SimpleFileVisitor; | ||
import java.nio.file.attribute.BasicFileAttributes; | ||
|
||
public class DropProposedMappingsCommand extends Command { | ||
public DropProposedMappingsCommand() { | ||
super(Argument.INPUT_JAR.required(), | ||
Argument.INPUT_MAPPINGS.required(), | ||
Argument.ENIGMA_PROFILE.required(), | ||
Argument.MAPPING_OUTPUT.optional()); | ||
} | ||
|
||
@Override | ||
public void run(String... args) throws Exception { | ||
Path jarIn = getReadablePath(this.getArg(args, 0)); | ||
Path mappingsIn = getReadablePath(this.getArg(args, 1)); | ||
Path profile = getReadablePath(this.getArg(args, 2)); | ||
String mappingsOutArg = this.getArg(args, 3); | ||
Path mappingsOut = mappingsOutArg != null && !mappingsOutArg.isEmpty() ? getReadablePath(mappingsOutArg) : mappingsIn; | ||
|
||
run(jarIn, mappingsIn, profile, mappingsOut); | ||
} | ||
|
||
@Override | ||
public String getName() { | ||
return "drop-proposed-mappings"; | ||
} | ||
|
||
@Override | ||
public String getDescription() { | ||
return "Removes all proposed mapping entries that are the same as manually written entries from the provided mappings."; | ||
} | ||
|
||
public static void run(Path jarIn, Path mappingsIn, Path profilePath, Path mappingsOut) throws Exception { | ||
if (mappingsIn == null) { | ||
Logger.warn("No mappings input specified, skipping."); | ||
return; | ||
} | ||
|
||
Enigma enigma = createEnigma(EnigmaProfile.read(profilePath), null); | ||
|
||
MappingsWriter writer = CommandsUtil.getWriter(enigma, mappingsIn); | ||
EnigmaProject project = openProject(jarIn, mappingsIn, enigma); | ||
|
||
Logger.info("Dropping proposed mappings..."); | ||
|
||
var droppedMappings = project.dropProposedMappings(ProgressListener.createEmpty()); | ||
|
||
if (!droppedMappings.isEmpty()) { | ||
Logger.info("Found and dropped {} duplicate 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 duplicate proposed mappings found."); | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
package org.quiltmc.enigma.api.translation.mapping.tree; | ||
|
||
import org.quiltmc.enigma.api.source.TokenType; | ||
import org.quiltmc.enigma.api.translation.Translator; | ||
import org.quiltmc.enigma.api.translation.mapping.EntryMap; | ||
import org.quiltmc.enigma.api.translation.mapping.EntryMapping; | ||
|
@@ -42,10 +43,15 @@ public EntryMapping remove(Entry<?> entry) { | |
@Override | ||
public EntryMapping get(Entry<?> entry) { | ||
EntryMapping main = this.mainTree.get(entry); | ||
|
||
if (main == null || (main.equals(EntryMapping.OBFUSCATED) && this.secondaryTree.contains(entry))) { | ||
return this.secondaryTree.get(entry); | ||
} | ||
|
||
if (main.tokenType().equals(TokenType.OBFUSCATED) && this.secondaryTree.contains(entry)) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @ix0rai what is your opinion on this? it allows for javadocs to be on empty mappings, but get a name from a proposer There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. just making sure you know i'm not ignoring you, i'm pretty busy rn and i want to look into javadoc support on obf mappings a bit deeper |
||
return EntryMapping.merge(main, this.secondaryTree.get(entry)); | ||
} | ||
|
||
return main; | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this should preserve fallback-proposed names as well
also why do delegate params need an exception?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe this was a work around until we figure out why we are getting the massive spooky diffs,
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah, ok
it could be a useful to have an arg for
proposerplugin ids to excludeThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
potentially, but i also feel like that defeats a bit of the purpose of this feature, which is to make sure that no more proposed names are left in the mappings. If the proposer is fragile enough to break with this, its probably not written very well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
true
I wouldn't expect it to be used often
maybe it would be better not to have an arg; if a proposer is having issues it can just be set to fallback as a workaround