Add support for remote --srg-in mappings
Mappings can now be downloaded from remote URLs. Both individual .srgs and directories of .srg/.csv are supported. Examples: java -jar target/SpecialSource-1.3-SNAPSHOT-shaded.jar --in-jar http://assets.minecraft.net/1_4_7/minecraft_server.jar --out-jar /tmp/net.jar --srg-in https://raw.github.com/MinecraftForge/FML/master/conf/joined.srg java -jar target/SpecialSource-1.3-SNAPSHOT-shaded.jar --in-jar http://assets.minecraft.net/1_4_7/minecraft_server.jar --out-jar /tmp/net2.jar --srg-in https://raw.github.com/MinecraftForge/FML/master/conf/
This commit is contained in:
parent
e99d3c7ef4
commit
e36a60a078
@ -90,8 +90,9 @@ public class JarMapping {
|
||||
/**
|
||||
* Load mappings from an MCP directory
|
||||
*/
|
||||
public void loadMappingsDir(File dir, boolean reverse) throws IOException {
|
||||
if (!dir.isDirectory()) {
|
||||
public void loadMappingsDir(String dirname, boolean reverse) throws IOException {
|
||||
File dir = new File(dirname);
|
||||
if (!URLDownloader.isHTTPURL(dirname) && !dir.isDirectory()) {
|
||||
throw new IllegalArgumentException("loadMappingsDir("+dir+"): not a directory");
|
||||
}
|
||||
|
||||
@ -99,14 +100,14 @@ public class JarMapping {
|
||||
|
||||
List<File> srgFiles = new ArrayList<File>();
|
||||
|
||||
File joinedSrg = new File(dir.getPath() + sep + "joined.srg");
|
||||
File joinedSrg = URLDownloader.getLocalFile(dirname + sep + "joined.srg");
|
||||
if (joinedSrg.exists()) {
|
||||
// FML/MCP client/server joined
|
||||
srgFiles.add(joinedSrg);
|
||||
} else {
|
||||
// vanilla MCP separated sides
|
||||
File serverSrg = new File(dir.getPath() + sep + "server.srg");
|
||||
File clientSrg = new File(dir.getPath() + sep + "client.srg");
|
||||
File serverSrg = URLDownloader.getLocalFile(dirname + sep + "server.srg");
|
||||
File clientSrg = URLDownloader.getLocalFile(dirname + sep + "client.srg");
|
||||
if (serverSrg.exists()) {
|
||||
srgFiles.add(serverSrg);
|
||||
}
|
||||
@ -116,13 +117,13 @@ public class JarMapping {
|
||||
}
|
||||
|
||||
if (srgFiles.size() == 0) {
|
||||
throw new IOException("loadMappingsDir("+dir+"): no joined.srg, client.srg, or client.srg found");
|
||||
throw new IOException("loadMappingsDir("+dirname+"): no joined.srg, client.srg, or client.srg found");
|
||||
}
|
||||
|
||||
// Read output names through csv mappings, if available
|
||||
File fieldsCsv = new File(dir.getPath() + sep + "fields.csv");
|
||||
File methodsCsv = new File(dir.getPath() + sep + "methods.csv");
|
||||
File packagesCsv = new File(dir.getPath() + sep + "packages.csv"); // FML repackaging, optional
|
||||
File fieldsCsv = URLDownloader.getLocalFile(dirname + sep + "fields.csv");
|
||||
File methodsCsv = URLDownloader.getLocalFile(dirname + sep + "methods.csv");
|
||||
File packagesCsv = URLDownloader.getLocalFile(dirname + sep + "packages.csv"); // FML repackaging, optional
|
||||
|
||||
CSVMappingTransformer outputTransformer;
|
||||
|
||||
|
@ -120,6 +120,7 @@ public class SpecialSource {
|
||||
}
|
||||
|
||||
JarMapping jarMapping;
|
||||
URLDownloader.verbose = !options.has("quiet");
|
||||
|
||||
if (options.has("first-jar") && options.has("second-jar")) {
|
||||
// Generate mappings from two otherwise-identical jars
|
||||
@ -162,12 +163,10 @@ public class SpecialSource {
|
||||
@SuppressWarnings("unchecked")
|
||||
List<String> filenames = (List<String>) options.valuesOf("srg-in");
|
||||
for (String filename : filenames) {
|
||||
File file = new File(filename);
|
||||
|
||||
if (file.isDirectory()) {
|
||||
jarMapping.loadMappingsDir(file, reverse);
|
||||
if (new File(filename).isDirectory() || filename.endsWith("/")) { // existing local dir or dir URL
|
||||
jarMapping.loadMappingsDir(filename, reverse);
|
||||
} else {
|
||||
jarMapping.loadMappings(new BufferedReader(new FileReader(file)), inputTransformer, outputTransformer, reverse);
|
||||
jarMapping.loadMappings(new BufferedReader(new FileReader(URLDownloader.getLocalFile(filename))), inputTransformer, outputTransformer, reverse);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
@ -208,7 +207,6 @@ public class SpecialSource {
|
||||
return;
|
||||
}
|
||||
|
||||
URLDownloader.verbose = !options.has("quiet");
|
||||
Jar jar3 = Jar.init(URLDownloader.getLocalFile((String) options.valueOf("in-jar")));
|
||||
|
||||
inheritanceProviders.add(new JarInheritanceProvider(jar3));
|
||||
|
@ -75,18 +75,18 @@ public class URLDownloader {
|
||||
}
|
||||
|
||||
public static File getLocalFile(String string) throws IOException {
|
||||
if (new File(string).exists()) {
|
||||
return new File(string);
|
||||
}
|
||||
|
||||
if (string.startsWith("http://") || string.startsWith("https://")) {
|
||||
if (isHTTPURL(string)) {
|
||||
URLDownloader downloader = new URLDownloader(string);
|
||||
return downloader.download();
|
||||
} else {
|
||||
throw new FileNotFoundException(string);
|
||||
return new File(string);
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean isHTTPURL(String string) {
|
||||
return string.startsWith("http://") || string.startsWith("https://");
|
||||
}
|
||||
|
||||
// Borrowed from Guava 13 (since we're on Guava 12) - TODO: remove and use Guava after https://github.com/MinecraftForge/FML/commit/937e9a016936195e4dc51f33ab9e8dde52621684
|
||||
/**
|
||||
* Returns the file name without its
|
||||
|
Loading…
Reference in New Issue
Block a user