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

dev/0.11
modmuss50 2018-11-04 18:46:37 +00:00
parent 40f9168b6a
commit bbf5e341e3
5 changed files with 26 additions and 21 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

@ -105,6 +105,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);
@ -121,7 +122,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

@ -28,7 +28,6 @@ import net.fabricmc.loom.LoomGradleExtension;
import net.fabricmc.tinyremapper.OutputConsumerPath;
import net.fabricmc.tinyremapper.TinyRemapper;
import net.fabricmc.tinyremapper.TinyUtils;
import org.apache.commons.io.FileUtils;
import org.gradle.api.Project;
import java.io.File;
@ -43,25 +42,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 +73,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 +84,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();
}
}