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

dev/0.11
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 { public byte[] getClassBytes(String name, String transformedName) throws IOException {
InputStream inputStream = getResourceAsStream(name.replace(".", "/") + ".class"); InputStream inputStream = getResourceAsStream(name.replace(".", "/") + ".class");
byte[] classBytes = ByteStreams.toByteArray(inputStream); byte[] classBytes = ByteStreams.toByteArray(inputStream);
inputStream.close();
if(classBytes == null){ if(classBytes == null){
return super.getClassBytes(name, transformedName); return super.getClassBytes(name, transformedName);
} }

View File

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

View File

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

View File

@ -125,6 +125,7 @@ public class ModProcessor {
remapper.read(mcDeps); remapper.read(mcDeps);
remapper.apply(input.toPath(), outputConsumer); remapper.apply(input.toPath(), outputConsumer);
outputConsumer.finish(); outputConsumer.finish();
remapper.finish();
} catch (Exception e){ } catch (Exception e){
remapper.finish(); remapper.finish();
throw new RuntimeException("Failed to remap JAR to " + toM, e); 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("\\")) { if (!entry.isDirectory() && entry.getName().endsWith(".json") && !entry.getName().contains("/") && !entry.getName().contains("\\")) {
// JSON file in root directory // JSON file in root directory
try { 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")) { if (json != null && json.has("refmap")) {
mixinRefmapFilenames.add(json.get("refmap").getAsString()); mixinRefmapFilenames.add(json.get("refmap").getAsString());
} }

View File

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