Ensure all resources are closed
Also updates to Java 7 to allow try-with-resources
This commit is contained in:
parent
b342037b99
commit
98cadeffbf
4
pom.xml
4
pom.xml
@ -36,8 +36,8 @@
|
||||
</issueManagement>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>1.6</maven.compiler.source>
|
||||
<maven.compiler.target>1.6</maven.compiler.target>
|
||||
<maven.compiler.source>1.7</maven.compiler.source>
|
||||
<maven.compiler.target>1.7</maven.compiler.target>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
|
||||
|
@ -90,7 +90,9 @@ public class AccessMap {
|
||||
}
|
||||
|
||||
public void loadAccessTransformer(File file) throws IOException {
|
||||
loadAccessTransformer(new BufferedReader(new FileReader(file)));
|
||||
try (BufferedReader reader = new BufferedReader(new FileReader(file))) {
|
||||
loadAccessTransformer(reader);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -92,6 +92,7 @@ public class Jar implements Closeable {
|
||||
* @param name The name of the resource
|
||||
* @return true Whether a resource with the given name exists
|
||||
*/
|
||||
@SuppressWarnings("resource") // closed when the this Jar is closed
|
||||
public boolean containsResource(String name) {
|
||||
JarFile jarFile = jarForResource.get(name);
|
||||
return jarFile != null && jarFile.getEntry(name) != null;
|
||||
@ -104,6 +105,7 @@ public class Jar implements Closeable {
|
||||
* @return
|
||||
* @throws IOException
|
||||
*/
|
||||
@SuppressWarnings("resource") // closed when the this Jar is closed
|
||||
public InputStream getResource(String name) throws IOException {
|
||||
JarFile jarFile = jarForResource.get(name);
|
||||
if (jarFile == null) {
|
||||
|
@ -191,7 +191,9 @@ public class JarMapping {
|
||||
}
|
||||
|
||||
public void loadMappings(File file) throws IOException {
|
||||
loadMappings(new BufferedReader(new FileReader(file)), null, null, false);
|
||||
try (BufferedReader reader = new BufferedReader(new FileReader(file))) {
|
||||
loadMappings(reader, null, null, false);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -233,7 +235,9 @@ public class JarMapping {
|
||||
throw new IllegalArgumentException("loadMappings(" + filename + "): numeric only supported on directories, not files");
|
||||
}
|
||||
|
||||
loadMappings(new BufferedReader(new FileReader(FileLocator.getFile(filename))), inputTransformer, outputTransformer, reverse);
|
||||
try (BufferedReader reader = new BufferedReader(new FileReader(FileLocator.getFile(filename)))) {
|
||||
loadMappings(reader, inputTransformer, outputTransformer, reverse);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -155,6 +155,13 @@ public class SpecialSource {
|
||||
return;
|
||||
}
|
||||
|
||||
if (options.has("in-jar") && !options.has("out-jar")) {
|
||||
System.err.println("No output jar given, in-jar requires out-jar");
|
||||
parser.printHelpOn(System.err);
|
||||
System.exit(-1);
|
||||
return;
|
||||
}
|
||||
|
||||
JarMapping jarMapping;
|
||||
verbose = !options.has("quiet");
|
||||
kill_source = options.has("kill-source");
|
||||
@ -174,11 +181,13 @@ public class SpecialSource {
|
||||
|
||||
FileLocator.useCache = !options.has("force-redownload");
|
||||
|
||||
Jar jar1 = null, jar2 = null, jar3 = null;
|
||||
|
||||
if (options.has("first-jar") && options.has("second-jar")) {
|
||||
// Generate mappings from two otherwise-identical jars
|
||||
log("Reading jars");
|
||||
Jar jar1 = Jar.init(FileLocator.getFile((String) options.valueOf("first-jar")));
|
||||
Jar jar2 = Jar.init(FileLocator.getFile((String) options.valueOf("second-jar")));
|
||||
jar1 = Jar.init(FileLocator.getFile((String) options.valueOf("first-jar")));
|
||||
jar2 = Jar.init(FileLocator.getFile((String) options.valueOf("second-jar")));
|
||||
|
||||
log("Creating jar compare");
|
||||
JarComparer visitor1 = new JarComparer(jar1);
|
||||
@ -229,10 +238,11 @@ public class SpecialSource {
|
||||
if (options.has("read-inheritance")) {
|
||||
InheritanceMap inheritanceMap = new InheritanceMap();
|
||||
|
||||
BufferedReader reader = new BufferedReader(new FileReader(FileLocator.getFile((String) options.valueOf("read-inheritance"))));
|
||||
|
||||
BiMap<String, String> inverseClassMap = HashBiMap.create(jarMapping.classes).inverse();
|
||||
inheritanceMap.load(reader, inverseClassMap);
|
||||
File inheritanceFile = FileLocator.getFile((String) options.valueOf("read-inheritance"));
|
||||
try (BufferedReader reader = new BufferedReader(new FileReader(inheritanceFile))) {
|
||||
inheritanceMap.load(reader, inverseClassMap);
|
||||
}
|
||||
log("Loaded inheritance map for " + inheritanceMap.size() + " classes");
|
||||
|
||||
inheritanceProviders.add(inheritanceMap);
|
||||
@ -246,14 +256,7 @@ public class SpecialSource {
|
||||
accessMapper = new RemapperProcessor(null, jarMapping, access);
|
||||
}
|
||||
|
||||
if (options.has("in-jar")) {
|
||||
if (!options.has("out-jar")) {
|
||||
System.err.println("No output jar given, in-jar requires out-jar");
|
||||
parser.printHelpOn(System.err);
|
||||
System.exit(-1);
|
||||
return;
|
||||
}
|
||||
|
||||
if (options.has("in-jar") && options.has("out-jar")) {
|
||||
@SuppressWarnings("unchecked")
|
||||
List<String> filenames = (List<String>) options.valuesOf("in-jar");
|
||||
List<File> files = new ArrayList<File>();
|
||||
@ -261,7 +264,7 @@ public class SpecialSource {
|
||||
files.add(FileLocator.getFile(filename));
|
||||
}
|
||||
|
||||
Jar jar3 = Jar.init(files);
|
||||
jar3 = Jar.init(files);
|
||||
|
||||
inheritanceProviders.add(new JarProvider(jar3));
|
||||
|
||||
@ -287,6 +290,9 @@ public class SpecialSource {
|
||||
}
|
||||
}
|
||||
}
|
||||
if (jar1 != null) jar1.close();
|
||||
if (jar2 != null) jar2.close();
|
||||
if (jar3 != null) jar3.close();
|
||||
}
|
||||
|
||||
public static void log(String message) {
|
||||
|
Loading…
Reference in New Issue
Block a user