diff --git a/gradle.properties b/gradle.properties index 6f0c0bd..13187ae 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,6 +1,6 @@ version_major=1 version_minor=0 -version_patch=0 +version_patch=1 maven_group=com.hypherionmc diff --git a/src/main/java/com/hypherionmc/jarmanager/JarManager.java b/src/main/java/com/hypherionmc/jarmanager/JarManager.java index 8213278..b77daf0 100644 --- a/src/main/java/com/hypherionmc/jarmanager/JarManager.java +++ b/src/main/java/com/hypherionmc/jarmanager/JarManager.java @@ -8,6 +8,7 @@ import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; import me.lucko.jarrelocator.JarRelocator; +import me.lucko.jarrelocator.Relocation; import java.io.File; import java.io.IOException; @@ -81,4 +82,24 @@ public final class JarManager { // Move the temporary file to the outputJar Files.move(tempJar.toPath(), outputJar.toPath(), StandardCopyOption.REPLACE_EXISTING); } + + /** + * Relocate or remap packages inside a jar file. + * For example, from com.google.gson to lib.com.google.gson + * @param inputJar - The input jar file that will be modified + * @param outputJar - The file the modified file will be saved to + * @param relocations - Packages to relocate. See example above + * @throws IOException - Thrown when an IO error occurs + */ + public void remapJar(File inputJar, File outputJar, List relocations) throws IOException { + // Set up temp file, to prevent accidental overwrites + File tempJar = new File(inputJar.getParentFile(), "tempRelocated.jar"); + + // Run the jar relocater task + JarRelocator relocator = new JarRelocator(inputJar, tempJar, relocations); + relocator.run(); + + // Move the temporary file to the outputJar + Files.move(tempJar.toPath(), outputJar.toPath(), StandardCopyOption.REPLACE_EXISTING); + } }