[FEAT] Allow remap task to take in List<Relocation>

This commit is contained in:
2023-11-05 14:41:46 +02:00
parent fd443fb0d5
commit a9b46c9ffd
2 changed files with 22 additions and 1 deletions

View File

@@ -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<Relocation> 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);
}
}