Jar merging + reformat

dev/0.11
modmuss50 2016-08-17 17:38:54 +01:00
parent c03f842227
commit 65e2a76d70
21 changed files with 980 additions and 924 deletions

View File

@ -42,6 +42,7 @@ dependencies {
shade 'com.google.code.gson:gson:2.6.2'
shade 'commons-io:commons-io:1.4'
shade 'com.google.guava:guava:19.0'
shade 'net.fabricmc:blending-jar:0.1.0'
shade 'net.fabricmc:enigma:0.11.+'
shade 'org.javassist:javassist:3.+'

View File

@ -24,16 +24,14 @@
package net.fabricmc.loom;
import com.google.common.collect.ImmutableMap;
import com.google.gson.Gson;
import net.fabricmc.loom.task.DownloadTask;
import net.fabricmc.loom.util.Constants;
import com.google.common.collect.ImmutableMap;
import net.fabricmc.loom.util.Version;
import org.gradle.api.Action;
import org.gradle.api.Plugin;
import org.gradle.api.Project;
import org.gradle.api.Task;
import org.gradle.api.artifacts.repositories.FlatDirectoryArtifactRepository;
import org.gradle.api.artifacts.repositories.MavenArtifactRepository;
import org.gradle.api.plugins.JavaPlugin;
import org.gradle.api.plugins.JavaPluginConvention;
@ -42,7 +40,6 @@ import org.gradle.api.tasks.javadoc.Javadoc;
import org.gradle.plugins.ide.eclipse.model.EclipseModel;
import org.gradle.plugins.ide.idea.model.IdeaModel;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
@ -189,7 +186,7 @@ public class AbstractPlugin implements Plugin<Project> {
} catch (IOException e) {
e.printStackTrace();
}
project1.getDependencies().add(Constants.CONFIG_MC_DEPENDENCIES, "net.minecraft:" + Constants.MINECRAFT_CLIENT_MAPPED_JAR.get(extension).getName().replace(".jar", ""));
project1.getDependencies().add(Constants.CONFIG_MC_DEPENDENCIES, "net.minecraft:" + Constants.MINECRAFT_MAPPED_JAR.get(extension).getName().replace(".jar", ""));
if (extension.fabricVersion != null && !extension.fabricVersion.isEmpty()) {
//only add this when not in a fabric dev env
@ -197,6 +194,5 @@ public class AbstractPlugin implements Plugin<Project> {
}
});
}
}

View File

@ -24,10 +24,7 @@
package net.fabricmc.loom;
import net.fabricmc.loom.task.DownloadTask;
import net.fabricmc.loom.task.ExtractNativesTask;
import net.fabricmc.loom.task.GenIdeaProjectTask;
import net.fabricmc.loom.task.MapJarsTask;
import net.fabricmc.loom.task.*;
import org.gradle.api.DefaultTask;
import org.gradle.api.Project;
@ -37,7 +34,8 @@ public class LoomGradlePlugin extends AbstractPlugin {
super.apply(target);
makeTask("download", DownloadTask.class);
makeTask("mapJars", MapJarsTask.class).dependsOn("download");
makeTask("mergeJars", MergeJarsTask.class).dependsOn("download");
makeTask("mapJars", MapJarsTask.class).dependsOn("mergeJars");
makeTask("setupFabric", DefaultTask.class).dependsOn("mapJars");
makeTask("extractNatives", ExtractNativesTask.class).dependsOn("download");

View File

@ -24,13 +24,13 @@
package net.fabricmc.loom.task;
import net.fabricmc.loom.util.Constants;
import net.fabricmc.loom.util.Version;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import net.fabricmc.loom.LoomGradleExtension;
import net.fabricmc.loom.util.Checksum;
import net.fabricmc.loom.util.Constants;
import net.fabricmc.loom.util.ManifestVersion;
import net.fabricmc.loom.util.Version;
import net.fabricmc.loom.util.assets.AssetIndex;
import net.fabricmc.loom.util.assets.AssetObject;
import net.fabricmc.loom.util.progress.ProgressLogger;
@ -44,7 +44,6 @@ import org.gradle.api.tasks.TaskAction;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Map;
import java.util.Optional;
@ -65,6 +64,11 @@ public class DownloadTask extends DefaultTask {
FileUtils.copyURLToFile(new URL(version.downloads.get("client").url), Constants.MINECRAFT_CLIENT_JAR.get(extension));
}
if (!Constants.MINECRAFT_SERVER_JAR.get(extension).exists() || !Checksum.equals(Constants.MINECRAFT_SERVER_JAR.get(extension), version.downloads.get("server").sha1)) {
this.getLogger().lifecycle(":downloading server");
FileUtils.copyURLToFile(new URL(version.downloads.get("server").url), Constants.MINECRAFT_SERVER_JAR.get(extension));
}
if (Constants.MAPPINGS_ZIP.exists()) {
Constants.MAPPINGS_ZIP.delete();
}

View File

@ -24,11 +24,11 @@
package net.fabricmc.loom.task;
import com.google.gson.Gson;
import net.fabricmc.loom.LoomGradleExtension;
import net.fabricmc.loom.util.Constants;
import net.fabricmc.loom.util.IdeaRunConfig;
import net.fabricmc.loom.util.Version;
import com.google.gson.Gson;
import org.gradle.api.DefaultTask;
import org.gradle.api.tasks.TaskAction;
import org.w3c.dom.Document;
@ -130,7 +130,7 @@ public class GenIdeaProjectTask extends DefaultTask {
Element javadoc = doc.createElement("JAVADOC");
Element sources = doc.createElement("SOURCES");
Element root = doc.createElement("root");
root.setAttribute("url", "jar://" + Constants.MINECRAFT_CLIENT_MAPPED_JAR.get(extension).getAbsolutePath() + "!/");
root.setAttribute("url", "jar://" + Constants.MINECRAFT_MAPPED_JAR.get(extension).getAbsolutePath() + "!/");
classes.appendChild(root);
libraryElement.appendChild(classes);
libraryElement.appendChild(javadoc);

View File

@ -45,9 +45,6 @@ public class MapJarsTask extends DefaultTask {
@TaskAction
public void mapJars() throws IOException, MappingParseException {
LoomGradleExtension extension = this.getProject().getExtensions().getByType(LoomGradleExtension.class);
if(Constants.MINECRAFT_CLIENT_MAPPED_JAR.get(extension).exists()){
Constants.MINECRAFT_CLIENT_MAPPED_JAR.get(extension).delete();
}
this.getLogger().lifecycle(":unpacking mappings");
if (Constants.MAPPINGS_DIR.exists()) {
FileUtils.deleteDirectory(Constants.MAPPINGS_DIR);
@ -55,9 +52,9 @@ public class MapJarsTask extends DefaultTask {
ZipUtil.unpack(Constants.MAPPINGS_ZIP, Constants.MAPPINGS_DIR);
this.getLogger().lifecycle(":remapping jar");
deobfuscator = new Deobfuscator(new JarFile(Constants.MINECRAFT_CLIENT_JAR.get(extension)));
deobfuscator = new Deobfuscator(new JarFile(Constants.MINECRAFT_MERGED_JAR.get(extension)));
this.deobfuscator.setMappings(new MappingsEnigmaReader().read(new File(Constants.MAPPINGS_DIR, "pomf-master" + File.separator + "mappings")));
this.deobfuscator.writeJar(Constants.MINECRAFT_CLIENT_MAPPED_JAR.get(extension), new ProgressListener());
this.deobfuscator.writeJar(Constants.MINECRAFT_MAPPED_JAR.get(extension), new ProgressListener());
File tempAssests = new File(Constants.CACHE_FILES, "tempAssets");
@ -68,9 +65,9 @@ public class MapJarsTask extends DefaultTask {
return null;
}
});
ZipUtil.unpack(Constants.MINECRAFT_CLIENT_MAPPED_JAR.get(extension), tempAssests);
ZipUtil.unpack(Constants.MINECRAFT_MAPPED_JAR.get(extension), tempAssests);
ZipUtil.pack(tempAssests, Constants.MINECRAFT_CLIENT_MAPPED_JAR.get(extension));
ZipUtil.pack(tempAssests, Constants.MINECRAFT_MAPPED_JAR.get(extension));
}
public static class ProgressListener implements Deobfuscator.ProgressListener {
@ -85,5 +82,4 @@ public class MapJarsTask extends DefaultTask {
}
}
}

View File

@ -0,0 +1,59 @@
/*
* This file is part of fabric-loom, licensed under the MIT License (MIT).
*
* Copyright (c) 2016 FabricMC
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package net.fabricmc.loom.task;
import net.fabricmc.blendingjar.JarMerger;
import net.fabricmc.loom.LoomGradleExtension;
import net.fabricmc.loom.util.Constants;
import org.gradle.api.DefaultTask;
import org.gradle.api.tasks.TaskAction;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
public class MergeJarsTask extends DefaultTask {
@TaskAction
public void mergeJars() throws IOException {
this.getLogger().lifecycle(":merging jars");
LoomGradleExtension extension = this.getProject().getExtensions().getByType(LoomGradleExtension.class);
FileInputStream client = new FileInputStream(Constants.MINECRAFT_CLIENT_JAR.get(extension));
FileInputStream server = new FileInputStream(Constants.MINECRAFT_SERVER_JAR.get(extension));
FileOutputStream merged = new FileOutputStream(Constants.MINECRAFT_MERGED_JAR.get(extension));
JarMerger jarMerger = new JarMerger(client, server, merged);
jarMerger.merge();
jarMerger.close();
client.close();
server.close();
merged.close();
}
}

View File

@ -24,8 +24,8 @@
package net.fabricmc.loom.util;
import net.fabricmc.loom.util.delayed.IDelayed;
import net.fabricmc.loom.util.delayed.DelayedFile;
import net.fabricmc.loom.util.delayed.IDelayed;
import java.io.File;
import java.net.URL;
@ -38,7 +38,9 @@ public class Constants {
public static final File CACHE_FILES = new File(WORKING_DIRECTORY, ".gradle/minecraft");
public static final IDelayed<File> MINECRAFT_CLIENT_JAR = new DelayedFile(extension -> new File(CACHE_FILES, extension.version + "-client.jar"));
public static final IDelayed<File> MINECRAFT_CLIENT_MAPPED_JAR = new DelayedFile(extension -> new File(CACHE_FILES, extension.version + "-client-mapped.jar"));
public static final IDelayed<File> MINECRAFT_SERVER_JAR = new DelayedFile(extension -> new File(CACHE_FILES, extension.version + "-server.jar"));
public static final IDelayed<File> MINECRAFT_MERGED_JAR = new DelayedFile(extension -> new File(CACHE_FILES, extension.version + "-merged.jar"));
public static final IDelayed<File> MINECRAFT_MAPPED_JAR = new DelayedFile(extension -> new File(CACHE_FILES, extension.version + "-mapped.jar"));
public static final File MAPPINGS_ZIP = new File(CACHE_FILES, "mappings.zip");
public static final File MAPPINGS_DIR = new File(CACHE_FILES, "mappings");