[BUG] Fix output jars being larger than they should, and change to JarManager
This commit is contained in:
@@ -12,7 +12,8 @@ group = 'com.hypherionmc.modutils'
|
|||||||
version = "${version_base}.${version_patch}"
|
version = "${version_base}.${version_patch}"
|
||||||
description = "Gradle plugin to merge multiloader/architectury multiplatform mods into a single jar file"
|
description = "Gradle plugin to merge multiloader/architectury multiplatform mods into a single jar file"
|
||||||
archivesBaseName = 'ModFusioner'
|
archivesBaseName = 'ModFusioner'
|
||||||
java.toolchain.languageVersion = JavaLanguageVersion.of(8)
|
sourceCompatibility = JavaVersion.VERSION_1_8
|
||||||
|
targetCompatibility = JavaVersion.VERSION_1_8
|
||||||
|
|
||||||
if (System.getenv('BUILD_NUMBER') != null) {
|
if (System.getenv('BUILD_NUMBER') != null) {
|
||||||
version = "${version_base}." + System.getenv('BUILD_NUMBER')
|
version = "${version_base}." + System.getenv('BUILD_NUMBER')
|
||||||
@@ -32,17 +33,17 @@ repositories {
|
|||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation gradleApi()
|
implementation gradleApi()
|
||||||
|
testImplementation 'org.jetbrains:annotations:24.0.0'
|
||||||
|
|
||||||
// Shaded Deps
|
// Shaded Deps
|
||||||
shadeMe 'org.jetbrains:annotations:24.0.1'
|
shadeMe 'org.jetbrains:annotations:24.0.1'
|
||||||
shadeMe 'commons-io:commons-io:2.11.0'
|
shadeMe 'commons-io:commons-io:2.11.0'
|
||||||
|
|
||||||
shadeMe('me.lucko:jar-relocator:1.5') {
|
shadeMe('com.hypherionmc:jarmanager:1.0.3') {
|
||||||
exclude group: 'org.ow2.asm'
|
exclude group: 'org.ow2.asm'
|
||||||
}
|
}
|
||||||
shadeMe 'org.ow2.asm:asm:9.3'
|
shadeMe 'org.ow2.asm:asm:9.3'
|
||||||
shadeMe 'org.ow2.asm:asm-commons:9.3'
|
shadeMe 'org.ow2.asm:asm-commons:9.3'
|
||||||
shadeMe "fr.stevecohen.jarmanager:JarManager:0.5.0"
|
|
||||||
shadeMe 'org.apache.commons:commons-compress:1.24.0'
|
shadeMe 'org.apache.commons:commons-compress:1.24.0'
|
||||||
|
|
||||||
compileOnly 'org.projectlombok:lombok:1.18.30'
|
compileOnly 'org.projectlombok:lombok:1.18.30'
|
||||||
|
@@ -1,2 +1,2 @@
|
|||||||
version_base=1.0
|
version_base=1.0
|
||||||
version_patch=6
|
version_patch=7
|
@@ -9,15 +9,13 @@
|
|||||||
*/
|
*/
|
||||||
package com.hypherionmc.modfusioner.actions;
|
package com.hypherionmc.modfusioner.actions;
|
||||||
|
|
||||||
|
import com.hypherionmc.jarmanager.JarManager;
|
||||||
|
import com.hypherionmc.jarrelocator.Relocation;
|
||||||
import com.hypherionmc.modfusioner.Constants;
|
import com.hypherionmc.modfusioner.Constants;
|
||||||
import com.hypherionmc.modfusioner.plugin.FusionerExtension;
|
import com.hypherionmc.modfusioner.plugin.FusionerExtension;
|
||||||
import com.hypherionmc.modfusioner.utils.FileTools;
|
import com.hypherionmc.modfusioner.utils.FileTools;
|
||||||
import fr.stevecohen.jarmanager.JarPacker;
|
|
||||||
import fr.stevecohen.jarmanager.JarUnpacker;
|
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import lombok.Setter;
|
import lombok.Setter;
|
||||||
import me.lucko.jarrelocator.JarRelocator;
|
|
||||||
import me.lucko.jarrelocator.Relocation;
|
|
||||||
import org.apache.commons.io.FileUtils;
|
import org.apache.commons.io.FileUtils;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
@@ -26,7 +24,6 @@ import java.io.FileOutputStream;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.StandardCopyOption;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -69,6 +66,8 @@ public class JarMergeAction {
|
|||||||
private final Map<String, String> ignoredDuplicateRelocations = new HashMap<>();
|
private final Map<String, String> ignoredDuplicateRelocations = new HashMap<>();
|
||||||
private final Map<String, String> removeDuplicateRelocationResources = new HashMap<>();
|
private final Map<String, String> removeDuplicateRelocationResources = new HashMap<>();
|
||||||
private final List<Relocation> relocations = new ArrayList<>();
|
private final List<Relocation> relocations = new ArrayList<>();
|
||||||
|
JarManager jarManager = JarManager.getInstance();
|
||||||
|
|
||||||
|
|
||||||
// Settings
|
// Settings
|
||||||
private final String group;
|
private final String group;
|
||||||
@@ -133,20 +132,24 @@ public class JarMergeAction {
|
|||||||
|
|
||||||
// Extract the input jars to their processing directories
|
// Extract the input jars to their processing directories
|
||||||
logger.lifecycle("Unpacking input jars");
|
logger.lifecycle("Unpacking input jars");
|
||||||
JarUnpacker jarUnpacker = new JarUnpacker();
|
|
||||||
if (FileTools.exists(forgeInput)) {
|
if (FileTools.exists(forgeInput)) {
|
||||||
jarUnpacker.unpack(forgeInput.getAbsolutePath(), forgeTemp.getAbsolutePath());
|
jarManager.unpackJar(forgeInput, forgeTemp);
|
||||||
}
|
}
|
||||||
if (FileTools.exists(fabricInput)) {
|
if (FileTools.exists(fabricInput)) {
|
||||||
jarUnpacker.unpack(fabricInput.getAbsolutePath(), fabricTemp.getAbsolutePath());
|
jarManager.unpackJar(fabricInput, fabricTemp);
|
||||||
}
|
}
|
||||||
if (FileTools.exists(quiltInput)) {
|
if (FileTools.exists(quiltInput)) {
|
||||||
jarUnpacker.unpack(quiltInput.getAbsolutePath(), quiltTemp.getAbsolutePath());
|
jarManager.unpackJar(quiltInput, quiltTemp);
|
||||||
}
|
}
|
||||||
|
|
||||||
customTemps.forEach((key, value) -> value.forEach((k, v) -> {
|
customTemps.forEach((key, value) -> value.forEach((k, v) -> {
|
||||||
if (FileTools.exists(k)) {
|
if (FileTools.exists(k)) {
|
||||||
jarUnpacker.unpack(k.getAbsolutePath(), v.getAbsolutePath());
|
try {
|
||||||
|
jarManager.unpackJar(k, v);
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
|
|
||||||
@@ -174,12 +177,7 @@ public class JarMergeAction {
|
|||||||
|
|
||||||
// Repack the fully processed jars into a single jar
|
// Repack the fully processed jars into a single jar
|
||||||
logger.lifecycle("Fusing jars into single jar");
|
logger.lifecycle("Fusing jars into single jar");
|
||||||
JarPacker jarPacker = new JarPacker();
|
jarManager.remapAndPack(mergedTemp, outJar, relocations);
|
||||||
jarPacker.pack(mergedTemp.getAbsolutePath(), outJar.getAbsolutePath());
|
|
||||||
|
|
||||||
// Relocate duplicate packages that have been de-duplicated
|
|
||||||
logger.lifecycle("Finishing up");
|
|
||||||
relocateJar(outJar, new File(tempDir, "relocate.jar"));
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Files.setPosixFilePermissions(outJar.toPath(), Constants.filePerms);
|
Files.setPosixFilePermissions(outJar.toPath(), Constants.filePerms);
|
||||||
@@ -193,6 +191,7 @@ public class JarMergeAction {
|
|||||||
* @throws IOException - Thrown if an IO error occurs
|
* @throws IOException - Thrown if an IO error occurs
|
||||||
*/
|
*/
|
||||||
public void clean() throws IOException {
|
public void clean() throws IOException {
|
||||||
|
logger.lifecycle("Finishing up");
|
||||||
FileUtils.deleteQuietly(tempDir);
|
FileUtils.deleteQuietly(tempDir);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -202,20 +201,6 @@ public class JarMergeAction {
|
|||||||
* ================================================================================================================
|
* ================================================================================================================
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
|
||||||
* Relocate, or rename packages that have been deduplicated and moved around
|
|
||||||
* @param mergedJar - Input jar
|
|
||||||
* @param mergedOutputJar - Temporary output jar
|
|
||||||
* @throws IOException - Thrown if an IO exception occurs
|
|
||||||
*/
|
|
||||||
private void relocateJar(File mergedJar, File mergedOutputJar) throws IOException {
|
|
||||||
JarRelocator jarRelocator = new JarRelocator(mergedJar, mergedOutputJar, relocations);
|
|
||||||
jarRelocator.run();
|
|
||||||
|
|
||||||
Files.move(mergedOutputJar.toPath(), mergedJar.toPath(), StandardCopyOption.REPLACE_EXISTING);
|
|
||||||
if (mergedOutputJar.exists()) mergedOutputJar.delete();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Process input jars to relocate them internally to their final package names
|
* Process input jars to relocate them internally to their final package names
|
||||||
* @throws IOException - Thrown if an IO error occurs
|
* @throws IOException - Thrown if an IO error occurs
|
||||||
@@ -272,8 +257,7 @@ public class JarMergeAction {
|
|||||||
jarRelocations.add(new Relocation(architectury.get(), target + "." + architectury.get()));
|
jarRelocations.add(new Relocation(architectury.get(), target + "." + architectury.get()));
|
||||||
}
|
}
|
||||||
|
|
||||||
JarRelocator jarRelocator = new JarRelocator(jarFile, remappedJar, jarRelocations);
|
jarManager.remapJar(jarFile, remappedJar, jarRelocations);
|
||||||
jarRelocator.run();
|
|
||||||
|
|
||||||
switch (target) {
|
switch (target) {
|
||||||
case "forge":
|
case "forge":
|
||||||
@@ -326,9 +310,7 @@ public class JarMergeAction {
|
|||||||
customRelocations.add(new Relocation(architectury.get(), name + "." + architectury.get()));
|
customRelocations.add(new Relocation(architectury.get(), name + "." + architectury.get()));
|
||||||
}
|
}
|
||||||
|
|
||||||
JarRelocator customRelocator = new JarRelocator(jarFile, remappedJar, customRelocations);
|
jarManager.remapJar(jarFile, remappedJar, customRelocations);
|
||||||
customRelocator.run();
|
|
||||||
|
|
||||||
customInputs.replace(configuration, jarFile, remappedJar);
|
customInputs.replace(configuration, jarFile, remappedJar);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -354,8 +336,6 @@ public class JarMergeAction {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.lifecycle("Remapping Finished");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Reference in New Issue
Block a user