diff options
| author | 2022-09-14 13:12:55 +0100 | |
|---|---|---|
| committer | 2022-09-14 13:12:55 +0100 | |
| commit | 9c736848fb7aa82d295b3aa2946e6cd132ee998f (patch) | |
| tree | b982613cfa7201b2db25cb64a5950f9a2c34a5b3 /enigma-cli | |
| parent | Nested packages in Swing UI (#458) (diff) | |
| download | enigma-9c736848fb7aa82d295b3aa2946e6cd132ee998f.tar.gz enigma-9c736848fb7aa82d295b3aa2946e6cd132ee998f.tar.xz enigma-9c736848fb7aa82d295b3aa2946e6cd132ee998f.zip | |
Add checkstyle (#460)
Diffstat (limited to 'enigma-cli')
12 files changed, 284 insertions, 275 deletions
diff --git a/enigma-cli/build.gradle b/enigma-cli/build.gradle index 5b84196e..5281e9e6 100644 --- a/enigma-cli/build.gradle +++ b/enigma-cli/build.gradle | |||
| @@ -1,10 +1,10 @@ | |||
| 1 | plugins { | 1 | plugins { |
| 2 | id 'application' | 2 | id 'application' |
| 3 | id 'com.github.johnrengelman.shadow' version '7.0.0' | 3 | id 'com.github.johnrengelman.shadow' version '7.0.0' |
| 4 | } | 4 | } |
| 5 | 5 | ||
| 6 | dependencies { | 6 | dependencies { |
| 7 | implementation project(':enigma') | 7 | implementation project(':enigma') |
| 8 | } | 8 | } |
| 9 | 9 | ||
| 10 | mainClassName = 'cuchaz.enigma.command.Main' | 10 | mainClassName = 'cuchaz.enigma.command.Main' |
| @@ -12,9 +12,9 @@ mainClassName = 'cuchaz.enigma.command.Main' | |||
| 12 | jar.manifest.attributes 'Main-Class': mainClassName | 12 | jar.manifest.attributes 'Main-Class': mainClassName |
| 13 | 13 | ||
| 14 | publishing { | 14 | publishing { |
| 15 | publications { | 15 | publications { |
| 16 | shadow(MavenPublication) { publication -> | 16 | shadow(MavenPublication) { publication -> |
| 17 | project.shadow.component publication | 17 | project.shadow.component publication |
| 18 | } | 18 | } |
| 19 | } | 19 | } |
| 20 | } | 20 | } |
diff --git a/enigma-cli/src/main/java/cuchaz/enigma/command/CheckMappingsCommand.java b/enigma-cli/src/main/java/cuchaz/enigma/command/CheckMappingsCommand.java index 75ef225a..922d6688 100644 --- a/enigma-cli/src/main/java/cuchaz/enigma/command/CheckMappingsCommand.java +++ b/enigma-cli/src/main/java/cuchaz/enigma/command/CheckMappingsCommand.java | |||
| @@ -1,22 +1,21 @@ | |||
| 1 | package cuchaz.enigma.command; | 1 | package cuchaz.enigma.command; |
| 2 | 2 | ||
| 3 | import java.nio.file.Path; | ||
| 4 | import java.util.Set; | ||
| 5 | import java.util.stream.Collectors; | ||
| 6 | |||
| 3 | import cuchaz.enigma.Enigma; | 7 | import cuchaz.enigma.Enigma; |
| 4 | import cuchaz.enigma.EnigmaProject; | 8 | import cuchaz.enigma.EnigmaProject; |
| 5 | import cuchaz.enigma.ProgressListener; | 9 | import cuchaz.enigma.ProgressListener; |
| 6 | import cuchaz.enigma.analysis.index.JarIndex; | 10 | import cuchaz.enigma.analysis.index.JarIndex; |
| 7 | import cuchaz.enigma.classprovider.ClasspathClassProvider; | 11 | import cuchaz.enigma.classprovider.ClasspathClassProvider; |
| 8 | import cuchaz.enigma.translation.mapping.EntryMapping; | 12 | import cuchaz.enigma.translation.mapping.EntryMapping; |
| 9 | import cuchaz.enigma.translation.mapping.serde.MappingSaveParameters; | ||
| 10 | import cuchaz.enigma.translation.mapping.serde.MappingFormat; | 13 | import cuchaz.enigma.translation.mapping.serde.MappingFormat; |
| 14 | import cuchaz.enigma.translation.mapping.serde.MappingSaveParameters; | ||
| 11 | import cuchaz.enigma.translation.mapping.tree.EntryTree; | 15 | import cuchaz.enigma.translation.mapping.tree.EntryTree; |
| 12 | import cuchaz.enigma.translation.representation.entry.ClassEntry; | 16 | import cuchaz.enigma.translation.representation.entry.ClassEntry; |
| 13 | 17 | ||
| 14 | import java.nio.file.Path; | ||
| 15 | import java.util.Set; | ||
| 16 | import java.util.stream.Collectors; | ||
| 17 | |||
| 18 | public class CheckMappingsCommand extends Command { | 18 | public class CheckMappingsCommand extends Command { |
| 19 | |||
| 20 | public CheckMappingsCommand() { | 19 | public CheckMappingsCommand() { |
| 21 | super("checkmappings"); | 20 | super("checkmappings"); |
| 22 | } | 21 | } |
| @@ -55,19 +54,11 @@ public class CheckMappingsCommand extends Command { | |||
| 55 | boolean error = false; | 54 | boolean error = false; |
| 56 | 55 | ||
| 57 | for (Set<ClassEntry> partition : idx.getPackageVisibilityIndex().getPartitions()) { | 56 | for (Set<ClassEntry> partition : idx.getPackageVisibilityIndex().getPartitions()) { |
| 58 | long packages = partition.stream() | 57 | long packages = partition.stream().map(project.getMapper()::deobfuscate).map(ClassEntry::getPackageName).distinct().count(); |
| 59 | .map(project.getMapper()::deobfuscate) | 58 | |
| 60 | .map(ClassEntry::getPackageName) | ||
| 61 | .distinct() | ||
| 62 | .count(); | ||
| 63 | if (packages > 1) { | 59 | if (packages > 1) { |
| 64 | error = true; | 60 | error = true; |
| 65 | System.err.println("ERROR: Must be in one package:\n" + partition.stream() | 61 | System.err.println("ERROR: Must be in one package:\n" + partition.stream().map(project.getMapper()::deobfuscate).map(ClassEntry::toString).sorted().collect(Collectors.joining("\n"))); |
| 66 | .map(project.getMapper()::deobfuscate) | ||
| 67 | .map(ClassEntry::toString) | ||
| 68 | .sorted() | ||
| 69 | .collect(Collectors.joining("\n")) | ||
| 70 | ); | ||
| 71 | } | 62 | } |
| 72 | } | 63 | } |
| 73 | 64 | ||
diff --git a/enigma-cli/src/main/java/cuchaz/enigma/command/Command.java b/enigma-cli/src/main/java/cuchaz/enigma/command/Command.java index 0d71f028..04d49f2f 100644 --- a/enigma-cli/src/main/java/cuchaz/enigma/command/Command.java +++ b/enigma-cli/src/main/java/cuchaz/enigma/command/Command.java | |||
| @@ -1,21 +1,21 @@ | |||
| 1 | package cuchaz.enigma.command; | 1 | package cuchaz.enigma.command; |
| 2 | 2 | ||
| 3 | import java.io.File; | ||
| 4 | import java.nio.file.Files; | ||
| 5 | import java.nio.file.Path; | ||
| 6 | import java.nio.file.Paths; | ||
| 7 | |||
| 8 | import com.google.common.io.MoreFiles; | ||
| 9 | |||
| 3 | import cuchaz.enigma.Enigma; | 10 | import cuchaz.enigma.Enigma; |
| 4 | import cuchaz.enigma.EnigmaProject; | 11 | import cuchaz.enigma.EnigmaProject; |
| 5 | import cuchaz.enigma.ProgressListener; | 12 | import cuchaz.enigma.ProgressListener; |
| 6 | import cuchaz.enigma.classprovider.ClasspathClassProvider; | 13 | import cuchaz.enigma.classprovider.ClasspathClassProvider; |
| 7 | import cuchaz.enigma.translation.mapping.EntryMapping; | 14 | import cuchaz.enigma.translation.mapping.EntryMapping; |
| 8 | import cuchaz.enigma.translation.mapping.serde.MappingSaveParameters; | ||
| 9 | import cuchaz.enigma.translation.mapping.serde.MappingFormat; | 15 | import cuchaz.enigma.translation.mapping.serde.MappingFormat; |
| 16 | import cuchaz.enigma.translation.mapping.serde.MappingSaveParameters; | ||
| 10 | import cuchaz.enigma.translation.mapping.tree.EntryTree; | 17 | import cuchaz.enigma.translation.mapping.tree.EntryTree; |
| 11 | 18 | ||
| 12 | import java.io.File; | ||
| 13 | import java.nio.file.Files; | ||
| 14 | import java.nio.file.Path; | ||
| 15 | import java.nio.file.Paths; | ||
| 16 | |||
| 17 | import com.google.common.io.MoreFiles; | ||
| 18 | |||
| 19 | public abstract class Command { | 19 | public abstract class Command { |
| 20 | public final String name; | 20 | public final String name; |
| 21 | 21 | ||
| @@ -63,15 +63,19 @@ public abstract class Command { | |||
| 63 | if (path == null) { | 63 | if (path == null) { |
| 64 | return null; | 64 | return null; |
| 65 | } | 65 | } |
| 66 | |||
| 66 | File file = new File(path).getAbsoluteFile(); | 67 | File file = new File(path).getAbsoluteFile(); |
| 67 | File dir = file.getParentFile(); | 68 | File dir = file.getParentFile(); |
| 69 | |||
| 68 | if (dir == null) { | 70 | if (dir == null) { |
| 69 | throw new IllegalArgumentException("Cannot write file: " + path); | 71 | throw new IllegalArgumentException("Cannot write file: " + path); |
| 70 | } | 72 | } |
| 73 | |||
| 71 | // quick fix to avoid stupid stuff in Gradle code | 74 | // quick fix to avoid stupid stuff in Gradle code |
| 72 | if (!dir.isDirectory()) { | 75 | if (!dir.isDirectory()) { |
| 73 | dir.mkdirs(); | 76 | dir.mkdirs(); |
| 74 | } | 77 | } |
| 78 | |||
| 75 | return file; | 79 | return file; |
| 76 | } | 80 | } |
| 77 | 81 | ||
| @@ -79,10 +83,13 @@ public abstract class Command { | |||
| 79 | if (path == null) { | 83 | if (path == null) { |
| 80 | return null; | 84 | return null; |
| 81 | } | 85 | } |
| 86 | |||
| 82 | File dir = new File(path).getAbsoluteFile(); | 87 | File dir = new File(path).getAbsoluteFile(); |
| 88 | |||
| 83 | if (!dir.exists()) { | 89 | if (!dir.exists()) { |
| 84 | throw new IllegalArgumentException("Cannot write to folder: " + dir); | 90 | throw new IllegalArgumentException("Cannot write to folder: " + dir); |
| 85 | } | 91 | } |
| 92 | |||
| 86 | return dir; | 93 | return dir; |
| 87 | } | 94 | } |
| 88 | 95 | ||
| @@ -90,10 +97,13 @@ public abstract class Command { | |||
| 90 | if (path == null) { | 97 | if (path == null) { |
| 91 | return null; | 98 | return null; |
| 92 | } | 99 | } |
| 100 | |||
| 93 | File file = new File(path).getAbsoluteFile(); | 101 | File file = new File(path).getAbsoluteFile(); |
| 102 | |||
| 94 | if (!file.exists()) { | 103 | if (!file.exists()) { |
| 95 | throw new IllegalArgumentException("Cannot find file: " + file.getAbsolutePath()); | 104 | throw new IllegalArgumentException("Cannot find file: " + file.getAbsolutePath()); |
| 96 | } | 105 | } |
| 106 | |||
| 97 | return file; | 107 | return file; |
| 98 | } | 108 | } |
| 99 | 109 | ||
| @@ -101,10 +111,13 @@ public abstract class Command { | |||
| 101 | if (path == null) { | 111 | if (path == null) { |
| 102 | return null; | 112 | return null; |
| 103 | } | 113 | } |
| 114 | |||
| 104 | Path file = Paths.get(path).toAbsolutePath(); | 115 | Path file = Paths.get(path).toAbsolutePath(); |
| 116 | |||
| 105 | if (!Files.exists(file)) { | 117 | if (!Files.exists(file)) { |
| 106 | throw new IllegalArgumentException("Cannot find file: " + file.toString()); | 118 | throw new IllegalArgumentException("Cannot find file: " + file.toString()); |
| 107 | } | 119 | } |
| 120 | |||
| 108 | return file; | 121 | return file; |
| 109 | } | 122 | } |
| 110 | 123 | ||
| @@ -116,11 +129,11 @@ public abstract class Command { | |||
| 116 | return null; | 129 | return null; |
| 117 | } | 130 | } |
| 118 | } | 131 | } |
| 132 | |||
| 119 | return args[i]; | 133 | return args[i]; |
| 120 | } | 134 | } |
| 121 | 135 | ||
| 122 | public static class ConsoleProgressListener implements ProgressListener { | 136 | public static class ConsoleProgressListener implements ProgressListener { |
| 123 | |||
| 124 | private static final int ReportTime = 5000; // 5s | 137 | private static final int ReportTime = 5000; // 5s |
| 125 | 138 | ||
| 126 | private int totalWork; | 139 | private int totalWork; |
| @@ -146,6 +159,7 @@ public abstract class Command { | |||
| 146 | System.out.println(String.format("\tProgress: %3d%%", percent)); | 159 | System.out.println(String.format("\tProgress: %3d%%", percent)); |
| 147 | this.lastReportTime = now; | 160 | this.lastReportTime = now; |
| 148 | } | 161 | } |
| 162 | |||
| 149 | if (isLastUpdate) { | 163 | if (isLastUpdate) { |
| 150 | double elapsedSeconds = (now - this.startTime) / 1000.0; | 164 | double elapsedSeconds = (now - this.startTime) / 1000.0; |
| 151 | System.out.println(String.format("Finished in %.1f seconds", elapsedSeconds)); | 165 | System.out.println(String.format("Finished in %.1f seconds", elapsedSeconds)); |
diff --git a/enigma-cli/src/main/java/cuchaz/enigma/command/ComposeMappingsCommand.java b/enigma-cli/src/main/java/cuchaz/enigma/command/ComposeMappingsCommand.java index e10fd47e..7e9002d8 100644 --- a/enigma-cli/src/main/java/cuchaz/enigma/command/ComposeMappingsCommand.java +++ b/enigma-cli/src/main/java/cuchaz/enigma/command/ComposeMappingsCommand.java | |||
| @@ -1,42 +1,42 @@ | |||
| 1 | package cuchaz.enigma.command; | 1 | package cuchaz.enigma.command; |
| 2 | 2 | ||
| 3 | import cuchaz.enigma.translation.mapping.MappingOperations; | 3 | import java.io.IOException; |
| 4 | import cuchaz.enigma.translation.mapping.serde.MappingParseException; | 4 | import java.nio.file.Path; |
| 5 | import java.nio.file.Paths; | ||
| 6 | |||
| 5 | import cuchaz.enigma.translation.mapping.EntryMapping; | 7 | import cuchaz.enigma.translation.mapping.EntryMapping; |
| 8 | import cuchaz.enigma.translation.mapping.MappingOperations; | ||
| 6 | import cuchaz.enigma.translation.mapping.serde.MappingFileNameFormat; | 9 | import cuchaz.enigma.translation.mapping.serde.MappingFileNameFormat; |
| 10 | import cuchaz.enigma.translation.mapping.serde.MappingParseException; | ||
| 7 | import cuchaz.enigma.translation.mapping.serde.MappingSaveParameters; | 11 | import cuchaz.enigma.translation.mapping.serde.MappingSaveParameters; |
| 8 | import cuchaz.enigma.translation.mapping.tree.EntryTree; | 12 | import cuchaz.enigma.translation.mapping.tree.EntryTree; |
| 9 | import cuchaz.enigma.utils.Utils; | 13 | import cuchaz.enigma.utils.Utils; |
| 10 | 14 | ||
| 11 | import java.io.IOException; | ||
| 12 | import java.nio.file.Path; | ||
| 13 | import java.nio.file.Paths; | ||
| 14 | |||
| 15 | public class ComposeMappingsCommand extends Command { | 15 | public class ComposeMappingsCommand extends Command { |
| 16 | public ComposeMappingsCommand() { | 16 | public ComposeMappingsCommand() { |
| 17 | super("compose-mappings"); | 17 | super("compose-mappings"); |
| 18 | } | 18 | } |
| 19 | 19 | ||
| 20 | @Override | 20 | @Override |
| 21 | public String getUsage() { | 21 | public String getUsage() { |
| 22 | return "<left-format> <left> <right-format> <right> <result-format> <result> <keep-mode>"; | 22 | return "<left-format> <left> <right-format> <right> <result-format> <result> <keep-mode>"; |
| 23 | } | 23 | } |
| 24 | 24 | ||
| 25 | @Override | 25 | @Override |
| 26 | public boolean isValidArgument(int length) { | 26 | public boolean isValidArgument(int length) { |
| 27 | return length == 7; | 27 | return length == 7; |
| 28 | } | 28 | } |
| 29 | 29 | ||
| 30 | @Override | 30 | @Override |
| 31 | public void run(String... args) throws IOException, MappingParseException { | 31 | public void run(String... args) throws IOException, MappingParseException { |
| 32 | MappingSaveParameters saveParameters = new MappingSaveParameters(MappingFileNameFormat.BY_DEOBF); | 32 | MappingSaveParameters saveParameters = new MappingSaveParameters(MappingFileNameFormat.BY_DEOBF); |
| 33 | 33 | ||
| 34 | EntryTree<EntryMapping> left = MappingCommandsUtil.read(args[0], Paths.get(args[1]), saveParameters); | 34 | EntryTree<EntryMapping> left = MappingCommandsUtil.read(args[0], Paths.get(args[1]), saveParameters); |
| 35 | EntryTree<EntryMapping> right = MappingCommandsUtil.read(args[2], Paths.get(args[3]), saveParameters); | 35 | EntryTree<EntryMapping> right = MappingCommandsUtil.read(args[2], Paths.get(args[3]), saveParameters); |
| 36 | EntryTree<EntryMapping> result = MappingOperations.compose(left, right, args[6].equals("left") || args[6].equals("both"), args[6].equals("right") || args[6].equals("both")); | 36 | EntryTree<EntryMapping> result = MappingOperations.compose(left, right, args[6].equals("left") || args[6].equals("both"), args[6].equals("right") || args[6].equals("both")); |
| 37 | 37 | ||
| 38 | Path output = Paths.get(args[5]); | 38 | Path output = Paths.get(args[5]); |
| 39 | Utils.delete(output); | 39 | Utils.delete(output); |
| 40 | MappingCommandsUtil.write(result, args[4], output, saveParameters); | 40 | MappingCommandsUtil.write(result, args[4], output, saveParameters); |
| 41 | } | 41 | } |
| 42 | } | 42 | } |
diff --git a/enigma-cli/src/main/java/cuchaz/enigma/command/ConvertMappingsCommand.java b/enigma-cli/src/main/java/cuchaz/enigma/command/ConvertMappingsCommand.java index 144d89c5..99b27e1f 100644 --- a/enigma-cli/src/main/java/cuchaz/enigma/command/ConvertMappingsCommand.java +++ b/enigma-cli/src/main/java/cuchaz/enigma/command/ConvertMappingsCommand.java | |||
| @@ -1,39 +1,39 @@ | |||
| 1 | package cuchaz.enigma.command; | 1 | package cuchaz.enigma.command; |
| 2 | 2 | ||
| 3 | import cuchaz.enigma.translation.mapping.serde.MappingParseException; | 3 | import java.io.IOException; |
| 4 | import java.nio.file.Path; | ||
| 5 | import java.nio.file.Paths; | ||
| 6 | |||
| 4 | import cuchaz.enigma.translation.mapping.EntryMapping; | 7 | import cuchaz.enigma.translation.mapping.EntryMapping; |
| 5 | import cuchaz.enigma.translation.mapping.serde.MappingFileNameFormat; | 8 | import cuchaz.enigma.translation.mapping.serde.MappingFileNameFormat; |
| 9 | import cuchaz.enigma.translation.mapping.serde.MappingParseException; | ||
| 6 | import cuchaz.enigma.translation.mapping.serde.MappingSaveParameters; | 10 | import cuchaz.enigma.translation.mapping.serde.MappingSaveParameters; |
| 7 | import cuchaz.enigma.translation.mapping.tree.EntryTree; | 11 | import cuchaz.enigma.translation.mapping.tree.EntryTree; |
| 8 | import cuchaz.enigma.utils.Utils; | 12 | import cuchaz.enigma.utils.Utils; |
| 9 | 13 | ||
| 10 | import java.io.IOException; | ||
| 11 | import java.nio.file.Path; | ||
| 12 | import java.nio.file.Paths; | ||
| 13 | |||
| 14 | public class ConvertMappingsCommand extends Command { | 14 | public class ConvertMappingsCommand extends Command { |
| 15 | public ConvertMappingsCommand() { | 15 | public ConvertMappingsCommand() { |
| 16 | super("convert-mappings"); | 16 | super("convert-mappings"); |
| 17 | } | 17 | } |
| 18 | 18 | ||
| 19 | @Override | 19 | @Override |
| 20 | public String getUsage() { | 20 | public String getUsage() { |
| 21 | return "<source-format> <source> <result-format> <result>"; | 21 | return "<source-format> <source> <result-format> <result>"; |
| 22 | } | 22 | } |
| 23 | 23 | ||
| 24 | @Override | 24 | @Override |
| 25 | public boolean isValidArgument(int length) { | 25 | public boolean isValidArgument(int length) { |
| 26 | return length == 4; | 26 | return length == 4; |
| 27 | } | 27 | } |
| 28 | 28 | ||
| 29 | @Override | 29 | @Override |
| 30 | public void run(String... args) throws IOException, MappingParseException { | 30 | public void run(String... args) throws IOException, MappingParseException { |
| 31 | MappingSaveParameters saveParameters = new MappingSaveParameters(MappingFileNameFormat.BY_DEOBF); | 31 | MappingSaveParameters saveParameters = new MappingSaveParameters(MappingFileNameFormat.BY_DEOBF); |
| 32 | 32 | ||
| 33 | EntryTree<EntryMapping> mappings = MappingCommandsUtil.read(args[0], Paths.get(args[1]), saveParameters); | 33 | EntryTree<EntryMapping> mappings = MappingCommandsUtil.read(args[0], Paths.get(args[1]), saveParameters); |
| 34 | 34 | ||
| 35 | Path output = Paths.get(args[3]); | 35 | Path output = Paths.get(args[3]); |
| 36 | Utils.delete(output); | 36 | Utils.delete(output); |
| 37 | MappingCommandsUtil.write(mappings, args[2], output, saveParameters); | 37 | MappingCommandsUtil.write(mappings, args[2], output, saveParameters); |
| 38 | } | 38 | } |
| 39 | } | 39 | } |
diff --git a/enigma-cli/src/main/java/cuchaz/enigma/command/DecompileCommand.java b/enigma-cli/src/main/java/cuchaz/enigma/command/DecompileCommand.java index 12a4e886..020bd979 100644 --- a/enigma-cli/src/main/java/cuchaz/enigma/command/DecompileCommand.java +++ b/enigma-cli/src/main/java/cuchaz/enigma/command/DecompileCommand.java | |||
| @@ -1,17 +1,16 @@ | |||
| 1 | package cuchaz.enigma.command; | 1 | package cuchaz.enigma.command; |
| 2 | 2 | ||
| 3 | import java.lang.reflect.Field; | ||
| 4 | import java.nio.file.Path; | ||
| 5 | import java.util.Locale; | ||
| 6 | |||
| 3 | import cuchaz.enigma.EnigmaProject; | 7 | import cuchaz.enigma.EnigmaProject; |
| 4 | import cuchaz.enigma.ProgressListener; | ||
| 5 | import cuchaz.enigma.EnigmaProject.DecompileErrorStrategy; | 8 | import cuchaz.enigma.EnigmaProject.DecompileErrorStrategy; |
| 9 | import cuchaz.enigma.ProgressListener; | ||
| 6 | import cuchaz.enigma.source.DecompilerService; | 10 | import cuchaz.enigma.source.DecompilerService; |
| 7 | import cuchaz.enigma.source.Decompilers; | 11 | import cuchaz.enigma.source.Decompilers; |
| 8 | 12 | ||
| 9 | import java.lang.reflect.Field; | ||
| 10 | import java.nio.file.Path; | ||
| 11 | import java.util.Locale; | ||
| 12 | |||
| 13 | public class DecompileCommand extends Command { | 13 | public class DecompileCommand extends Command { |
| 14 | |||
| 15 | public DecompileCommand() { | 14 | public DecompileCommand() { |
| 16 | super("decompile"); | 15 | super("decompile"); |
| 17 | } | 16 | } |
diff --git a/enigma-cli/src/main/java/cuchaz/enigma/command/DeobfuscateCommand.java b/enigma-cli/src/main/java/cuchaz/enigma/command/DeobfuscateCommand.java index b0d2a7d0..c8e62008 100644 --- a/enigma-cli/src/main/java/cuchaz/enigma/command/DeobfuscateCommand.java +++ b/enigma-cli/src/main/java/cuchaz/enigma/command/DeobfuscateCommand.java | |||
| @@ -1,12 +1,11 @@ | |||
| 1 | package cuchaz.enigma.command; | 1 | package cuchaz.enigma.command; |
| 2 | 2 | ||
| 3 | import java.nio.file.Path; | ||
| 4 | |||
| 3 | import cuchaz.enigma.EnigmaProject; | 5 | import cuchaz.enigma.EnigmaProject; |
| 4 | import cuchaz.enigma.ProgressListener; | 6 | import cuchaz.enigma.ProgressListener; |
| 5 | 7 | ||
| 6 | import java.nio.file.Path; | ||
| 7 | |||
| 8 | public class DeobfuscateCommand extends Command { | 8 | public class DeobfuscateCommand extends Command { |
| 9 | |||
| 10 | public DeobfuscateCommand() { | 9 | public DeobfuscateCommand() { |
| 11 | super("deobfuscate"); | 10 | super("deobfuscate"); |
| 12 | } | 11 | } |
diff --git a/enigma-cli/src/main/java/cuchaz/enigma/command/InvertMappingsCommand.java b/enigma-cli/src/main/java/cuchaz/enigma/command/InvertMappingsCommand.java index 0780a965..af24978b 100644 --- a/enigma-cli/src/main/java/cuchaz/enigma/command/InvertMappingsCommand.java +++ b/enigma-cli/src/main/java/cuchaz/enigma/command/InvertMappingsCommand.java | |||
| @@ -1,41 +1,41 @@ | |||
| 1 | package cuchaz.enigma.command; | 1 | package cuchaz.enigma.command; |
| 2 | 2 | ||
| 3 | import cuchaz.enigma.translation.mapping.MappingOperations; | 3 | import java.io.IOException; |
| 4 | import cuchaz.enigma.translation.mapping.serde.MappingParseException; | 4 | import java.nio.file.Path; |
| 5 | import java.nio.file.Paths; | ||
| 6 | |||
| 5 | import cuchaz.enigma.translation.mapping.EntryMapping; | 7 | import cuchaz.enigma.translation.mapping.EntryMapping; |
| 8 | import cuchaz.enigma.translation.mapping.MappingOperations; | ||
| 6 | import cuchaz.enigma.translation.mapping.serde.MappingFileNameFormat; | 9 | import cuchaz.enigma.translation.mapping.serde.MappingFileNameFormat; |
| 10 | import cuchaz.enigma.translation.mapping.serde.MappingParseException; | ||
| 7 | import cuchaz.enigma.translation.mapping.serde.MappingSaveParameters; | 11 | import cuchaz.enigma.translation.mapping.serde.MappingSaveParameters; |
| 8 | import cuchaz.enigma.translation.mapping.tree.EntryTree; | 12 | import cuchaz.enigma.translation.mapping.tree.EntryTree; |
| 9 | import cuchaz.enigma.utils.Utils; | 13 | import cuchaz.enigma.utils.Utils; |
| 10 | 14 | ||
| 11 | import java.io.IOException; | ||
| 12 | import java.nio.file.Path; | ||
| 13 | import java.nio.file.Paths; | ||
| 14 | |||
| 15 | public class InvertMappingsCommand extends Command { | 15 | public class InvertMappingsCommand extends Command { |
| 16 | public InvertMappingsCommand() { | 16 | public InvertMappingsCommand() { |
| 17 | super("invert-mappings"); | 17 | super("invert-mappings"); |
| 18 | } | 18 | } |
| 19 | 19 | ||
| 20 | @Override | 20 | @Override |
| 21 | public String getUsage() { | 21 | public String getUsage() { |
| 22 | return "<source-format> <source> <result-format> <result>"; | 22 | return "<source-format> <source> <result-format> <result>"; |
| 23 | } | 23 | } |
| 24 | 24 | ||
| 25 | @Override | 25 | @Override |
| 26 | public boolean isValidArgument(int length) { | 26 | public boolean isValidArgument(int length) { |
| 27 | return length == 4; | 27 | return length == 4; |
| 28 | } | 28 | } |
| 29 | 29 | ||
| 30 | @Override | 30 | @Override |
| 31 | public void run(String... args) throws IOException, MappingParseException { | 31 | public void run(String... args) throws IOException, MappingParseException { |
| 32 | MappingSaveParameters saveParameters = new MappingSaveParameters(MappingFileNameFormat.BY_DEOBF); | 32 | MappingSaveParameters saveParameters = new MappingSaveParameters(MappingFileNameFormat.BY_DEOBF); |
| 33 | 33 | ||
| 34 | EntryTree<EntryMapping> source = MappingCommandsUtil.read(args[0], Paths.get(args[1]), saveParameters); | 34 | EntryTree<EntryMapping> source = MappingCommandsUtil.read(args[0], Paths.get(args[1]), saveParameters); |
| 35 | EntryTree<EntryMapping> result = MappingOperations.invert(source); | 35 | EntryTree<EntryMapping> result = MappingOperations.invert(source); |
| 36 | 36 | ||
| 37 | Path output = Paths.get(args[3]); | 37 | Path output = Paths.get(args[3]); |
| 38 | Utils.delete(output); | 38 | Utils.delete(output); |
| 39 | MappingCommandsUtil.write(result, args[2], output, saveParameters); | 39 | MappingCommandsUtil.write(result, args[2], output, saveParameters); |
| 40 | } | 40 | } |
| 41 | } | 41 | } |
diff --git a/enigma-cli/src/main/java/cuchaz/enigma/command/Main.java b/enigma-cli/src/main/java/cuchaz/enigma/command/Main.java index 0a4c1b9b..9021ff15 100644 --- a/enigma-cli/src/main/java/cuchaz/enigma/command/Main.java +++ b/enigma-cli/src/main/java/cuchaz/enigma/command/Main.java | |||
| @@ -1,36 +1,39 @@ | |||
| 1 | /******************************************************************************* | 1 | /******************************************************************************* |
| 2 | * Copyright (c) 2015 Jeff Martin. | 2 | * Copyright (c) 2015 Jeff Martin. |
| 3 | * All rights reserved. This program and the accompanying materials | 3 | * All rights reserved. This program and the accompanying materials |
| 4 | * are made available under the terms of the GNU Lesser General Public | 4 | * are made available under the terms of the GNU Lesser General Public |
| 5 | * License v3.0 which accompanies this distribution, and is available at | 5 | * License v3.0 which accompanies this distribution, and is available at |
| 6 | * http://www.gnu.org/licenses/lgpl.html | 6 | * http://www.gnu.org/licenses/lgpl.html |
| 7 | * <p> | 7 | * |
| 8 | * Contributors: | 8 | * <p>Contributors: |
| 9 | * Jeff Martin - initial API and implementation | 9 | * Jeff Martin - initial API and implementation |
| 10 | ******************************************************************************/ | 10 | ******************************************************************************/ |
| 11 | 11 | ||
| 12 | package cuchaz.enigma.command; | 12 | package cuchaz.enigma.command; |
| 13 | 13 | ||
| 14 | import cuchaz.enigma.Enigma; | ||
| 15 | |||
| 16 | import java.util.LinkedHashMap; | 14 | import java.util.LinkedHashMap; |
| 17 | import java.util.Locale; | 15 | import java.util.Locale; |
| 18 | import java.util.Map; | 16 | import java.util.Map; |
| 19 | 17 | ||
| 20 | public class Main { | 18 | import cuchaz.enigma.Enigma; |
| 21 | 19 | ||
| 20 | public class Main { | ||
| 22 | private static final Map<String, Command> COMMANDS = new LinkedHashMap<>(); | 21 | private static final Map<String, Command> COMMANDS = new LinkedHashMap<>(); |
| 23 | 22 | ||
| 24 | public static void main(String... args) throws Exception { | 23 | public static void main(String... args) throws Exception { |
| 25 | try { | 24 | try { |
| 26 | // process the command | 25 | // process the command |
| 27 | if (args.length < 1) | 26 | if (args.length < 1) { |
| 28 | throw new IllegalArgumentException("Requires a command"); | 27 | throw new IllegalArgumentException("Requires a command"); |
| 28 | } | ||
| 29 | |||
| 29 | String command = args[0].toLowerCase(Locale.ROOT); | 30 | String command = args[0].toLowerCase(Locale.ROOT); |
| 30 | 31 | ||
| 31 | Command cmd = COMMANDS.get(command); | 32 | Command cmd = COMMANDS.get(command); |
| 32 | if (cmd == null) | 33 | |
| 34 | if (cmd == null) { | ||
| 33 | throw new IllegalArgumentException("Command not recognized: " + command); | 35 | throw new IllegalArgumentException("Command not recognized: " + command); |
| 36 | } | ||
| 34 | 37 | ||
| 35 | if (!cmd.isValidArgument(args.length - 1)) { | 38 | if (!cmd.isValidArgument(args.length - 1)) { |
| 36 | throw new CommandHelpException(cmd); | 39 | throw new CommandHelpException(cmd); |
| @@ -74,6 +77,7 @@ public class Main { | |||
| 74 | 77 | ||
| 75 | private static void register(Command command) { | 78 | private static void register(Command command) { |
| 76 | Command old = COMMANDS.put(command.name, command); | 79 | Command old = COMMANDS.put(command.name, command); |
| 80 | |||
| 77 | if (old != null) { | 81 | if (old != null) { |
| 78 | System.err.println("Command " + old + " with name " + command.name + " has been substituted by " + command); | 82 | System.err.println("Command " + old + " with name " + command.name + " has been substituted by " + command); |
| 79 | } | 83 | } |
| @@ -90,7 +94,6 @@ public class Main { | |||
| 90 | } | 94 | } |
| 91 | 95 | ||
| 92 | private static final class CommandHelpException extends IllegalArgumentException { | 96 | private static final class CommandHelpException extends IllegalArgumentException { |
| 93 | |||
| 94 | final Command command; | 97 | final Command command; |
| 95 | 98 | ||
| 96 | CommandHelpException(Command command) { | 99 | CommandHelpException(Command command) { |
diff --git a/enigma-cli/src/main/java/cuchaz/enigma/command/MapSpecializedMethodsCommand.java b/enigma-cli/src/main/java/cuchaz/enigma/command/MapSpecializedMethodsCommand.java index 46da89a2..644b08d3 100644 --- a/enigma-cli/src/main/java/cuchaz/enigma/command/MapSpecializedMethodsCommand.java +++ b/enigma-cli/src/main/java/cuchaz/enigma/command/MapSpecializedMethodsCommand.java | |||
| @@ -1,5 +1,10 @@ | |||
| 1 | package cuchaz.enigma.command; | 1 | package cuchaz.enigma.command; |
| 2 | 2 | ||
| 3 | import java.io.IOException; | ||
| 4 | import java.nio.file.Path; | ||
| 5 | import java.nio.file.Paths; | ||
| 6 | import java.util.Map; | ||
| 7 | |||
| 3 | import cuchaz.enigma.ProgressListener; | 8 | import cuchaz.enigma.ProgressListener; |
| 4 | import cuchaz.enigma.analysis.IndexTreeBuilder; | 9 | import cuchaz.enigma.analysis.IndexTreeBuilder; |
| 5 | import cuchaz.enigma.analysis.index.BridgeMethodIndex; | 10 | import cuchaz.enigma.analysis.index.BridgeMethodIndex; |
| @@ -18,60 +23,55 @@ import cuchaz.enigma.translation.mapping.tree.HashEntryTree; | |||
| 18 | import cuchaz.enigma.translation.representation.entry.MethodEntry; | 23 | import cuchaz.enigma.translation.representation.entry.MethodEntry; |
| 19 | import cuchaz.enigma.utils.Utils; | 24 | import cuchaz.enigma.utils.Utils; |
| 20 | 25 | ||
| 21 | import java.io.IOException; | ||
| 22 | import java.nio.file.Path; | ||
| 23 | import java.nio.file.Paths; | ||
| 24 | import java.util.Map; | ||
| 25 | |||
| 26 | public class MapSpecializedMethodsCommand extends Command { | 26 | public class MapSpecializedMethodsCommand extends Command { |
| 27 | public MapSpecializedMethodsCommand() { | 27 | public MapSpecializedMethodsCommand() { |
| 28 | super("map-specialized-methods"); | 28 | super("map-specialized-methods"); |
| 29 | } | 29 | } |
| 30 | 30 | ||
| 31 | @Override | 31 | @Override |
| 32 | public String getUsage() { | 32 | public String getUsage() { |
| 33 | return "<jar> <source-format> <source> <result-format> <result>"; | 33 | return "<jar> <source-format> <source> <result-format> <result>"; |
| 34 | } | 34 | } |
| 35 | 35 | ||
| 36 | @Override | 36 | @Override |
| 37 | public boolean isValidArgument(int length) { | 37 | public boolean isValidArgument(int length) { |
| 38 | return length == 5; | 38 | return length == 5; |
| 39 | } | 39 | } |
| 40 | 40 | ||
| 41 | @Override | 41 | @Override |
| 42 | public void run(String... args) throws IOException, MappingParseException { | 42 | public void run(String... args) throws IOException, MappingParseException { |
| 43 | run(Paths.get(args[0]), args[1], Paths.get(args[2]), args[3], Paths.get(args[4])); | 43 | run(Paths.get(args[0]), args[1], Paths.get(args[2]), args[3], Paths.get(args[4])); |
| 44 | } | 44 | } |
| 45 | 45 | ||
| 46 | public static void run(Path jar, String sourceFormat, Path sourcePath, String resultFormat, Path output) throws IOException, MappingParseException { | 46 | public static void run(Path jar, String sourceFormat, Path sourcePath, String resultFormat, Path output) throws IOException, MappingParseException { |
| 47 | MappingSaveParameters saveParameters = new MappingSaveParameters(MappingFileNameFormat.BY_DEOBF); | 47 | MappingSaveParameters saveParameters = new MappingSaveParameters(MappingFileNameFormat.BY_DEOBF); |
| 48 | EntryTree<EntryMapping> source = MappingCommandsUtil.read(sourceFormat, sourcePath, saveParameters); | 48 | EntryTree<EntryMapping> source = MappingCommandsUtil.read(sourceFormat, sourcePath, saveParameters); |
| 49 | EntryTree<EntryMapping> result = new HashEntryTree<>(); | 49 | EntryTree<EntryMapping> result = new HashEntryTree<>(); |
| 50 | 50 | ||
| 51 | JarClassProvider jcp = new JarClassProvider(jar); | 51 | JarClassProvider jcp = new JarClassProvider(jar); |
| 52 | JarIndex jarIndex = JarIndex.empty(); | 52 | JarIndex jarIndex = JarIndex.empty(); |
| 53 | jarIndex.indexJar(jcp.getClassNames(), new CachingClassProvider(jcp), ProgressListener.none()); | 53 | jarIndex.indexJar(jcp.getClassNames(), new CachingClassProvider(jcp), ProgressListener.none()); |
| 54 | 54 | ||
| 55 | BridgeMethodIndex bridgeMethodIndex = jarIndex.getBridgeMethodIndex(); | 55 | BridgeMethodIndex bridgeMethodIndex = jarIndex.getBridgeMethodIndex(); |
| 56 | Translator translator = new MappingTranslator(source, jarIndex.getEntryResolver()); | 56 | Translator translator = new MappingTranslator(source, jarIndex.getEntryResolver()); |
| 57 | IndexTreeBuilder indexTreeBuilder = new IndexTreeBuilder(jarIndex); | 57 | IndexTreeBuilder indexTreeBuilder = new IndexTreeBuilder(jarIndex); |
| 58 | 58 | ||
| 59 | // Copy all non-specialized methods | 59 | // Copy all non-specialized methods |
| 60 | for (EntryTreeNode<EntryMapping> node : source) { | 60 | for (EntryTreeNode<EntryMapping> node : source) { |
| 61 | if (!(node.getEntry() instanceof MethodEntry) || !bridgeMethodIndex.isSpecializedMethod((MethodEntry) node.getEntry())) { | 61 | if (!(node.getEntry() instanceof MethodEntry) || !bridgeMethodIndex.isSpecializedMethod((MethodEntry) node.getEntry())) { |
| 62 | result.insert(node.getEntry(), node.getValue()); | 62 | result.insert(node.getEntry(), node.getValue()); |
| 63 | } | 63 | } |
| 64 | } | 64 | } |
| 65 | 65 | ||
| 66 | // Add correct mappings for specialized methods | 66 | // Add correct mappings for specialized methods |
| 67 | for (Map.Entry<MethodEntry, MethodEntry> entry : bridgeMethodIndex.getBridgeToSpecialized().entrySet()) { | 67 | for (Map.Entry<MethodEntry, MethodEntry> entry : bridgeMethodIndex.getBridgeToSpecialized().entrySet()) { |
| 68 | MethodEntry bridge = entry.getKey(); | 68 | MethodEntry bridge = entry.getKey(); |
| 69 | MethodEntry specialized = indexTreeBuilder.buildMethodInheritance(translator, entry.getValue()).getMethodEntry(); | 69 | MethodEntry specialized = indexTreeBuilder.buildMethodInheritance(translator, entry.getValue()).getMethodEntry(); |
| 70 | String name = translator.translate(bridge).getName(); | 70 | String name = translator.translate(bridge).getName(); |
| 71 | result.insert(specialized, new EntryMapping(name)); | 71 | result.insert(specialized, new EntryMapping(name)); |
| 72 | } | 72 | } |
| 73 | 73 | ||
| 74 | Utils.delete(output); | 74 | Utils.delete(output); |
| 75 | MappingCommandsUtil.write(result, resultFormat, output, saveParameters); | 75 | MappingCommandsUtil.write(result, resultFormat, output, saveParameters); |
| 76 | } | 76 | } |
| 77 | } | 77 | } |
diff --git a/enigma-cli/src/main/java/cuchaz/enigma/command/MappingCommandsUtil.java b/enigma-cli/src/main/java/cuchaz/enigma/command/MappingCommandsUtil.java index d365129b..787625b6 100644 --- a/enigma-cli/src/main/java/cuchaz/enigma/command/MappingCommandsUtil.java +++ b/enigma-cli/src/main/java/cuchaz/enigma/command/MappingCommandsUtil.java | |||
| @@ -1,10 +1,14 @@ | |||
| 1 | package cuchaz.enigma.command; | 1 | package cuchaz.enigma.command; |
| 2 | 2 | ||
| 3 | import java.io.IOException; | ||
| 4 | import java.nio.file.Files; | ||
| 5 | import java.nio.file.Path; | ||
| 6 | |||
| 3 | import cuchaz.enigma.ProgressListener; | 7 | import cuchaz.enigma.ProgressListener; |
| 4 | import cuchaz.enigma.translation.mapping.serde.MappingParseException; | ||
| 5 | import cuchaz.enigma.translation.mapping.EntryMapping; | 8 | import cuchaz.enigma.translation.mapping.EntryMapping; |
| 9 | import cuchaz.enigma.translation.mapping.serde.MappingFormat; | ||
| 10 | import cuchaz.enigma.translation.mapping.serde.MappingParseException; | ||
| 6 | import cuchaz.enigma.translation.mapping.serde.MappingSaveParameters; | 11 | import cuchaz.enigma.translation.mapping.serde.MappingSaveParameters; |
| 7 | import cuchaz.enigma.translation.mapping.serde.*; | ||
| 8 | import cuchaz.enigma.translation.mapping.serde.enigma.EnigmaMappingsReader; | 12 | import cuchaz.enigma.translation.mapping.serde.enigma.EnigmaMappingsReader; |
| 9 | import cuchaz.enigma.translation.mapping.serde.enigma.EnigmaMappingsWriter; | 13 | import cuchaz.enigma.translation.mapping.serde.enigma.EnigmaMappingsWriter; |
| 10 | import cuchaz.enigma.translation.mapping.serde.tiny.TinyMappingsReader; | 14 | import cuchaz.enigma.translation.mapping.serde.tiny.TinyMappingsReader; |
| @@ -12,76 +16,77 @@ import cuchaz.enigma.translation.mapping.serde.tiny.TinyMappingsWriter; | |||
| 12 | import cuchaz.enigma.translation.mapping.serde.tinyv2.TinyV2Writer; | 16 | import cuchaz.enigma.translation.mapping.serde.tinyv2.TinyV2Writer; |
| 13 | import cuchaz.enigma.translation.mapping.tree.EntryTree; | 17 | import cuchaz.enigma.translation.mapping.tree.EntryTree; |
| 14 | 18 | ||
| 15 | import java.io.IOException; | ||
| 16 | import java.nio.file.Files; | ||
| 17 | import java.nio.file.Path; | ||
| 18 | |||
| 19 | public final class MappingCommandsUtil { | 19 | public final class MappingCommandsUtil { |
| 20 | private MappingCommandsUtil() {} | 20 | private MappingCommandsUtil() { |
| 21 | 21 | } | |
| 22 | public static EntryTree<EntryMapping> read(String type, Path path, MappingSaveParameters saveParameters) throws MappingParseException, IOException { | 22 | |
| 23 | if (type.equals("enigma")) { | 23 | public static EntryTree<EntryMapping> read(String type, Path path, MappingSaveParameters saveParameters) throws MappingParseException, IOException { |
| 24 | return (Files.isDirectory(path) ? EnigmaMappingsReader.DIRECTORY : EnigmaMappingsReader.ZIP).read(path, ProgressListener.none(), saveParameters); | 24 | if (type.equals("enigma")) { |
| 25 | } | 25 | return (Files.isDirectory(path) ? EnigmaMappingsReader.DIRECTORY : EnigmaMappingsReader.ZIP).read(path, ProgressListener.none(), saveParameters); |
| 26 | 26 | } | |
| 27 | if (type.equals("tiny")) { | 27 | |
| 28 | return TinyMappingsReader.INSTANCE.read(path, ProgressListener.none(), saveParameters); | 28 | if (type.equals("tiny")) { |
| 29 | } | 29 | return TinyMappingsReader.INSTANCE.read(path, ProgressListener.none(), saveParameters); |
| 30 | 30 | } | |
| 31 | MappingFormat format = null; | 31 | |
| 32 | try { | 32 | MappingFormat format = null; |
| 33 | format = MappingFormat.valueOf(type.toUpperCase()); | 33 | |
| 34 | } catch (IllegalArgumentException ignored) { | 34 | try { |
| 35 | if (type.equals("tinyv2")) { | 35 | format = MappingFormat.valueOf(type.toUpperCase()); |
| 36 | format = MappingFormat.TINY_V2; | 36 | } catch (IllegalArgumentException ignored) { |
| 37 | } | 37 | if (type.equals("tinyv2")) { |
| 38 | } | 38 | format = MappingFormat.TINY_V2; |
| 39 | 39 | } | |
| 40 | if (format != null) { | 40 | } |
| 41 | return format.getReader().read(path, ProgressListener.none(), saveParameters); | 41 | |
| 42 | } | 42 | if (format != null) { |
| 43 | 43 | return format.getReader().read(path, ProgressListener.none(), saveParameters); | |
| 44 | throw new IllegalArgumentException("no reader for " + type); | 44 | } |
| 45 | } | 45 | |
| 46 | 46 | throw new IllegalArgumentException("no reader for " + type); | |
| 47 | public static void write(EntryTree<EntryMapping> mappings, String type, Path path, MappingSaveParameters saveParameters) { | 47 | } |
| 48 | if (type.equals("enigma")) { | 48 | |
| 49 | EnigmaMappingsWriter.DIRECTORY.write(mappings, path, ProgressListener.none(), saveParameters); | 49 | public static void write(EntryTree<EntryMapping> mappings, String type, Path path, MappingSaveParameters saveParameters) { |
| 50 | return; | 50 | if (type.equals("enigma")) { |
| 51 | } | 51 | EnigmaMappingsWriter.DIRECTORY.write(mappings, path, ProgressListener.none(), saveParameters); |
| 52 | 52 | return; | |
| 53 | if (type.startsWith("tinyv2:") || type.startsWith("tiny_v2:")) { | 53 | } |
| 54 | String[] split = type.split(":"); | 54 | |
| 55 | 55 | if (type.startsWith("tinyv2:") || type.startsWith("tiny_v2:")) { | |
| 56 | if (split.length != 3) { | 56 | String[] split = type.split(":"); |
| 57 | throw new IllegalArgumentException("specify column names as 'tinyv2:from_namespace:to_namespace'"); | 57 | |
| 58 | } | 58 | if (split.length != 3) { |
| 59 | 59 | throw new IllegalArgumentException("specify column names as 'tinyv2:from_namespace:to_namespace'"); | |
| 60 | new TinyV2Writer(split[1], split[2]).write(mappings, path, ProgressListener.none(), saveParameters); | 60 | } |
| 61 | return; | 61 | |
| 62 | } | 62 | new TinyV2Writer(split[1], split[2]).write(mappings, path, ProgressListener.none(), saveParameters); |
| 63 | 63 | return; | |
| 64 | if (type.startsWith("tiny:")) { | 64 | } |
| 65 | String[] split = type.split(":"); | 65 | |
| 66 | 66 | if (type.startsWith("tiny:")) { | |
| 67 | if (split.length != 3) { | 67 | String[] split = type.split(":"); |
| 68 | throw new IllegalArgumentException("specify column names as 'tiny:from_column:to_column'"); | 68 | |
| 69 | } | 69 | if (split.length != 3) { |
| 70 | 70 | throw new IllegalArgumentException("specify column names as 'tiny:from_column:to_column'"); | |
| 71 | new TinyMappingsWriter(split[1], split[2]).write(mappings, path, ProgressListener.none(), saveParameters); | 71 | } |
| 72 | return; | 72 | |
| 73 | } | 73 | new TinyMappingsWriter(split[1], split[2]).write(mappings, path, ProgressListener.none(), saveParameters); |
| 74 | 74 | return; | |
| 75 | MappingFormat format = null; | 75 | } |
| 76 | try { | 76 | |
| 77 | format = MappingFormat.valueOf(type.toUpperCase()); | 77 | MappingFormat format = null; |
| 78 | } catch (IllegalArgumentException ignored) {} | 78 | |
| 79 | 79 | try { | |
| 80 | if (format != null) { | 80 | format = MappingFormat.valueOf(type.toUpperCase()); |
| 81 | format.getWriter().write(mappings, path, ProgressListener.none(), saveParameters); | 81 | } catch (IllegalArgumentException ignored) { |
| 82 | return; | 82 | // ignored |
| 83 | } | 83 | } |
| 84 | 84 | ||
| 85 | throw new IllegalArgumentException("no writer for " + type); | 85 | if (format != null) { |
| 86 | } | 86 | format.getWriter().write(mappings, path, ProgressListener.none(), saveParameters); |
| 87 | return; | ||
| 88 | } | ||
| 89 | |||
| 90 | throw new IllegalArgumentException("no writer for " + type); | ||
| 91 | } | ||
| 87 | } | 92 | } |
diff --git a/enigma-cli/src/test/java/cuchaz/enigma/command/CheckMappingsCommandTest.java b/enigma-cli/src/test/java/cuchaz/enigma/command/CheckMappingsCommandTest.java index a29bba40..8cfa49e7 100644 --- a/enigma-cli/src/test/java/cuchaz/enigma/command/CheckMappingsCommandTest.java +++ b/enigma-cli/src/test/java/cuchaz/enigma/command/CheckMappingsCommandTest.java | |||
| @@ -1,21 +1,19 @@ | |||
| 1 | package cuchaz.enigma.command; | 1 | package cuchaz.enigma.command; |
| 2 | 2 | ||
| 3 | import org.junit.Test; | ||
| 4 | |||
| 5 | import java.io.File; | 3 | import java.io.File; |
| 6 | 4 | ||
| 5 | import org.junit.Test; | ||
| 6 | |||
| 7 | public class CheckMappingsCommandTest { | 7 | public class CheckMappingsCommandTest { |
| 8 | private static final String PACKAGE_ACCESS = "../enigma/build/test-obf/packageAccess.jar"; | 8 | private static final String PACKAGE_ACCESS = "../enigma/build/test-obf/packageAccess.jar"; |
| 9 | 9 | ||
| 10 | @Test(expected = IllegalStateException.class) | 10 | @Test(expected = IllegalStateException.class) |
| 11 | public void testWrong() throws Exception { | 11 | public void testWrong() throws Exception { |
| 12 | new CheckMappingsCommand().run(new File(PACKAGE_ACCESS).getAbsolutePath(), new File("src/test/resources" + | 12 | new CheckMappingsCommand().run(new File(PACKAGE_ACCESS).getAbsolutePath(), new File("src/test/resources" + "/packageAccess/wrongMappings").getAbsolutePath()); |
| 13 | "/packageAccess/wrongMappings").getAbsolutePath()); | ||
| 14 | } | 13 | } |
| 15 | 14 | ||
| 16 | @Test | 15 | @Test |
| 17 | public void testRight() throws Exception { | 16 | public void testRight() throws Exception { |
| 18 | new CheckMappingsCommand().run(new File(PACKAGE_ACCESS).getAbsolutePath(), new File("src/test/resources" + | 17 | new CheckMappingsCommand().run(new File(PACKAGE_ACCESS).getAbsolutePath(), new File("src/test/resources" + "/packageAccess/correctMappings").getAbsolutePath()); |
| 19 | "/packageAccess/correctMappings").getAbsolutePath()); | ||
| 20 | } | 18 | } |
| 21 | } | 19 | } |