Fix some streams not being closed, clean up the mod reobfuscater, fix runClient task

This commit is contained in:
modmuss50 2018-11-03 13:50:57 +00:00
parent 356a7c4d00
commit 30a71c133d
5 changed files with 26 additions and 20 deletions

View file

@ -79,6 +79,7 @@ public class MixinServiceGradle extends MixinServiceLaunchWrapper implements ICl
public byte[] getClassBytes(String name, String transformedName) throws IOException {
InputStream inputStream = getResourceAsStream(name.replace(".", "/") + ".class");
byte[] classBytes = ByteStreams.toByteArray(inputStream);
inputStream.close();
if(classBytes == null){
return super.getClassBytes(name, transformedName);
}

View file

@ -66,7 +66,6 @@ public class RunClientTask extends JavaExec {
//Removes the deobf jars
libs.removeIf(s -> s.contains(Constants.MINECRAFT_FINAL_JAR.get(extension).getName()));
libs.removeIf(s -> s.contains(getProject().getName() + "-" + getProject().getVersion() + "-deobf.jar"));
classpath(libs);
@ -77,6 +76,14 @@ public class RunClientTask extends JavaExec {
super.exec();
}
@Override
public void setWorkingDir(File dir) {
if(!dir.exists()){
dir.mkdirs();
}
super.setWorkingDir(dir);
}
@Override
public String getMain() {
return "net.minecraft.launchwrapper.Launch";

View file

@ -77,6 +77,14 @@ public class RunServerTask extends JavaExec {
return "net.minecraft.launchwrapper.Launch";
}
@Override
public void setWorkingDir(File dir) {
if(!dir.exists()){
dir.mkdirs();
}
super.setWorkingDir(dir);
}
@Override
public List<String> getJvmArgs() {
LoomGradleExtension extension = this.getProject().getExtensions().getByType(LoomGradleExtension.class);

View file

@ -125,6 +125,7 @@ public class ModProcessor {
remapper.read(mcDeps);
remapper.apply(input.toPath(), outputConsumer);
outputConsumer.finish();
remapper.finish();
} catch (Exception e){
remapper.finish();
throw new RuntimeException("Failed to remap JAR to " + toM, e);
@ -141,7 +142,10 @@ public class ModProcessor {
if (!entry.isDirectory() && entry.getName().endsWith(".json") && !entry.getName().contains("/") && !entry.getName().contains("\\")) {
// JSON file in root directory
try {
JsonObject json = gson.fromJson(new InputStreamReader(stream), JsonObject.class);
InputStreamReader inputStreamReader = new InputStreamReader(stream);
JsonObject json = gson.fromJson(inputStreamReader, JsonObject.class);
inputStreamReader.close();
stream.close();
if (json != null && json.has("refmap")) {
mixinRefmapFilenames.add(json.get("refmap").getAsString());
}

View file

@ -43,25 +43,13 @@ public class ModRemapper {
LoomGradleExtension extension = project.getExtensions().getByType(LoomGradleExtension.class);
// TODO: What's the proper way of doing this?
File libsDir = new File(project.getBuildDir(), "libs");
File deobfJar = new File(libsDir, project.getName() + "-" + project.getVersion() + "-deobf.jar");
File modJar = new File(libsDir, project.getName() + "-" + project.getVersion() + ".jar");
if (!modJar.exists()) {
project.getLogger().error("Could not find mod .JAR at" + deobfJar.getAbsolutePath());
project.getLogger().error("This is can be fixed by adding a 'settings.gradle' file specifying 'rootProject.name'");
return;
}
if (deobfJar.exists()) {
deobfJar.delete();
}
FileUtils.touch(modJar); //Done to ensure that the file can be moved
//Move the pre existing mod jar to the deobf jar
if(!modJar.renameTo(deobfJar)){
throw new RuntimeException("Failed to rename " + modJar);
}
Path mappings = Constants.MAPPINGS_TINY.get(extension).toPath();
String fromM = "named";
@ -86,10 +74,10 @@ public class ModRemapper {
try {
OutputConsumerPath outputConsumer = new OutputConsumerPath(modJar.toPath());
outputConsumer.addNonClassFiles(deobfJar.toPath());
remapper.read(deobfJar.toPath());
outputConsumer.addNonClassFiles(modJar.toPath());
remapper.read(modJar.toPath());
remapper.read(classpath);
remapper.apply(deobfJar.toPath(), outputConsumer);
remapper.apply(modJar.toPath(), outputConsumer);
outputConsumer.finish();
remapper.finish();
} catch (Exception e){
@ -97,11 +85,9 @@ public class ModRemapper {
throw new RuntimeException("Failed to remap JAR", e);
}
if(!deobfJar.exists() || !modJar.exists()){
if(!modJar.exists()){
throw new RuntimeException("Failed to reobfuscate JAR");
}
deobfJar.delete();
}
}