Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.File;
- import java.io.FileOutputStream;
- import java.io.InputStream;
- import java.util.Enumeration;
- import java.util.Iterator;
- import java.util.Objects;
- import java.util.Set;
- import java.util.stream.Collectors;
- import java.util.zip.ZipEntry;
- import java.util.zip.ZipFile;
- import java.util.zip.ZipOutputStream;
- public class ExcludeAPIFromNMSJar {
- public static void main(String[] args) throws Exception {
- if (args.length != 1) return;
- File cache = new File(args[0]);
- //noinspection ConstantConditions
- File patchedFile = cache.listFiles((dir, name) -> name.startsWith("patched_") && name.endsWith(".jar"))[0];
- //noinspection ConstantConditions
- File apiFile = cache.listFiles((dir, name) -> name.startsWith("paper-api-") && name.endsWith(".jar"))[0];
- File nmsFile = new File(cache, "nms.jar");
- System.out.println("Excluding " + apiFile.getName() + " files from " + patchedFile.getName() + "..");
- int apiEntriesCount = 0, patchedEntriesCount = 0;
- try (ZipFile patchedZip = new ZipFile(patchedFile);
- ZipFile apiZip = new ZipFile(apiFile);
- ZipOutputStream zos = new ZipOutputStream(new FileOutputStream(nmsFile))) {
- Set<String> apiEntries = apiZip.stream().map(ZipEntry::getName).collect(Collectors.toSet());
- apiEntriesCount = apiEntries.size();
- Iterator<? extends ZipEntry> iterator = patchedZip.entries().asIterator();
- while (iterator.hasNext()) {
- ZipEntry zipEntry = iterator.next();
- patchedEntriesCount++;
- if (apiEntries.contains(zipEntry.getName()))
- continue;
- zos.putNextEntry(zipEntry);
- InputStream is = patchedZip.getInputStream(zipEntry);
- byte[] buf = new byte[1024];
- int len;
- while((len = is.read(buf)) > 0)
- zos.write(buf, 0, len);
- is.close();
- }
- }
- System.out.println("Excluded " + (patchedEntriesCount - apiEntriesCount) + " files from final nms jar.");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment