Skip to content

Instantly share code, notes, and snippets.

@AbrarSyed
Last active August 29, 2015 13:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AbrarSyed/8818035 to your computer and use it in GitHub Desktop.
Save AbrarSyed/8818035 to your computer and use it in GitHub Desktop.
A script to help out with people updating their MCP mappings.
import java.util.Map;
import java.util.regex.Matcher;
// args[] is an array of the arguments..
// should be..
// srcDIr MethodCsv FieldCsv
// define constants
def METHOD = /func_[0-9]+_[a-zA-Z_]+/
def FIELD = /field_[0-9]+_[a-zA-Z_]+/
// defining methods
def readCsv(csv)
{
def out = [:]
File file = new File(csv)
file.readLines().each {
def tokens = it.split(',')*.trim();
out[tokens[0]] = tokens[1]
}
return out
}
// read CSVs
def csvs = ['methods': readCsv(args[1]), 'fields': readCsv(args[2])]
// parse files..
File rootDir = new File(args[0])
rootDir.eachFileRecurse { File file ->
if (file.isDirectory() || !(file.path.endsWith(".patch") || file.path.endsWith('.java')))
return // ignore directories and files that arnt patches. This exits the closure.
println "reading $file"
def newLines = file.readLines('utf-8').collect { String line ->
line = line.replaceAll(METHOD) { group ->
csvs.methods[group] ?: group
}
line = line.replaceAll(FIELD) { group ->
csvs.fields[group] ?: group
}
}
file.write(newLines.join("\n") + "\n", 'utf-8')
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment