Skip to content

Commit f7eb63d

Browse files
committed
Add MCP Patching step
Add more controls over reformatting
1 parent c78b61e commit f7eb63d

6 files changed

Lines changed: 1171 additions & 93 deletions

File tree

src/main/java/net/minecraftforge/mcpcleanup/ConsoleTool.java

Lines changed: 61 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,13 @@
66

77
import java.io.File;
88
import java.io.IOException;
9-
import joptsimple.OptionException;
9+
import java.util.HashSet;
10+
import java.util.Set;
11+
1012
import joptsimple.OptionParser;
1113
import joptsimple.OptionSet;
1214
import joptsimple.OptionSpec;
15+
import net.minecraftforge.mcpcleanup.MCPCleanup.Mode;
1316

1417
public class ConsoleTool {
1518
private static boolean get(OptionSet options, boolean _default, OptionSpec<Boolean> spec) {
@@ -31,48 +34,70 @@ public static void main(String[] args) throws IOException {
3134
OptionSpec<Boolean> basicCleanupO = parser.accepts("basic", "Rus the BasicCleanups set").withOptionalArg().ofType(Boolean.class);
3235
OptionSpec<Boolean> glCleanupO = parser.accepts("gl", "Runs the GLConstantFixer set").withOptionalArg().ofType(Boolean.class);
3336
OptionSpec<Boolean> fmlCleanupO = parser.accepts("fml", "Runs the FMLCleanup set").withOptionalArg().ofType(Boolean.class);
37+
OptionSpec<Boolean> fmlCasesCleanupO = parser.accepts("fml-cases", "Fixed blank lines around case statements when doing FMLCleanup").withOptionalArg().ofType(Boolean.class);
3438
OptionSpec<Boolean> astyleO = parser.accepts("astyle", "Runs AStyle formatter").withOptionalArg().ofType(Boolean.class);
3539

36-
try {
37-
OptionSet options = parser.parse(args);
40+
OptionSpec<Mode> modeO = parser.accepts("mode", "What set of fixes we should be running").withRequiredArg().withValuesConvertedBy(Mode.MODERN);
41+
OptionSpec<String> ignorePatchesO = parser.accepts("ignore-patches", "Patch files to ingore").withRequiredArg();
42+
43+
44+
OptionSpec<File> patchesO = parser.accepts("patches", "Archive containing patch files to apply after doing the FernFlower cleanup").withRequiredArg().ofType(File.class);
45+
OptionSpec<String> patchesPrefixO = parser.accepts("patches-prefix", "Prefix of patch files in the specified archive").withRequiredArg();
3846

39-
File input = options.valueOf(inputO);
40-
File output = options.valueOf(outputO);
41-
boolean filterFML = get(options, false, filterFMLO);
42-
boolean fixParams = get(options, false, fixGeneric);
43-
boolean ffCleanup = get(options, false, ffCleanupO);
44-
boolean basicCleanup = get(options, true, basicCleanupO);
45-
boolean glCleanup = get(options, true, glCleanupO);
46-
boolean fmlCleanup = get(options, false, fmlCleanupO);
47-
boolean astyle = get(options, true, astyleO);
47+
OptionSet options = parser.parse(args);
4848

49-
log("MCPCleanup: ");
50-
log(" Input: " + input);
51-
log(" Output: " + output);
52-
log(" FilterFML: " + filterFML);
53-
log(" Abstract: " + fixParams);
54-
log(" FF: " + ffCleanup);
55-
log(" Basic: " + basicCleanup);
56-
log(" GL: " + glCleanup);
57-
log(" FML: " + fmlCleanup);
58-
log(" Astyle: " + astyle);
49+
File input = options.valueOf(inputO);
50+
File output = options.valueOf(outputO);
51+
Mode mode = options.valueOf(modeO);
52+
boolean filterFML = get(options, false, filterFMLO);
53+
boolean fixParams = get(options, false, fixGeneric);
54+
boolean ffCleanup = get(options, false, ffCleanupO);
55+
boolean basicCleanup = get(options, true, basicCleanupO);
56+
boolean glCleanup = get(options, true, glCleanupO);
57+
boolean fmlCleanup = get(options, false, fmlCleanupO);
58+
boolean fmlCasesCleanup = get(options, true, fmlCasesCleanupO);
59+
boolean astyle = get(options, true, astyleO);
60+
File patches = options.has(patchesO) ? options.valueOf(patchesO) : null;
61+
String prefix = options.has(patchesPrefixO) ? options.valueOf(patchesPrefixO) : null;
62+
Set<String> ignores = new HashSet<String>();
5963

60-
MCPCleanup cleanup = MCPCleanup.create(input, output)
61-
.filterFML(filterFML)
62-
.fixParams(fixParams)
63-
.fernflower(ffCleanup)
64-
.basic(basicCleanup)
65-
.gl(glCleanup)
66-
.fml(fmlCleanup)
67-
.astyle(astyle)
68-
;
69-
cleanup.process();
70-
} catch (OptionException e) {
71-
parser.printHelpOn(System.out);
72-
e.printStackTrace();
64+
log("MCPCleanup: ");
65+
log(" Input: " + input);
66+
log(" Output: " + output);
67+
log(" FilterFML: " + filterFML);
68+
log(" Abstract: " + fixParams);
69+
log(" FF: " + ffCleanup);
70+
log(" Mode: " + mode);
71+
log(" Basic: " + basicCleanup);
72+
log(" GL: " + glCleanup);
73+
log(" FML: " + fmlCleanup);
74+
log(" FML Case: " + fmlCasesCleanup);
75+
log(" Astyle: " + astyle);
76+
if (patches != null) {
77+
log(" Patches: " + patches.getAbsolutePath());
78+
if (prefix != null)
79+
log(" Prefix: " + prefix);
80+
for (String value : options.valuesOf(ignorePatchesO)) {
81+
log(" Ignore: " + value);
82+
ignores.add(value.replace('/', '.'));
83+
}
7384
}
74-
}
7585

86+
MCPCleanup cleanup = MCPCleanup.create(input, output)
87+
.filterFML(filterFML)
88+
.fixParams(fixParams)
89+
.fernflower(ffCleanup)
90+
.mode(mode)
91+
.basic(basicCleanup)
92+
.gl(glCleanup)
93+
.fml(fmlCleanup)
94+
.fmlCases(fmlCasesCleanup)
95+
.astyle(astyle)
96+
;
97+
if (patches != null)
98+
cleanup.patches(patches, prefix, ignores);
99+
cleanup.process();
100+
}
76101

77102
public static void log(String message) {
78103
System.out.println(message);

0 commit comments

Comments
 (0)