| 123456789101112131415161718192021222324252627282930313233343536373839 |
- import zipfile, os
- SRC = "target/resource-platform-v4.jar"
- OUT = "target/resource-platform-v5.jar"
- CLASSES = "build_tmp_classes"
- zin = zipfile.ZipFile(SRC)
- names = zin.namelist()
- def is_lib(n):
- return n.startswith("BOOT-INF/lib/")
- new_map = {}
- for root, _, files in os.walk(CLASSES):
- for f in files:
- full = os.path.join(root, f)
- arc = "BOOT-INF/classes/" + os.path.relpath(full, CLASSES).replace(os.sep, "/")
- new_map[arc] = full
- zout = zipfile.ZipFile(OUT, "w", zipfile.ZIP_DEFLATED)
- zout.writestr("META-INF/MANIFEST.MF", zin.read("META-INF/MANIFEST.MF"), zipfile.ZIP_STORED)
- for n in names:
- if n == "META-INF/MANIFEST.MF":
- continue
- if is_lib(n):
- zout.writestr(n, zin.read(n), zipfile.ZIP_STORED)
- elif n.startswith("BOOT-INF/classes/") and not n.endswith("/"):
- if n in new_map:
- with open(new_map[n], "rb") as fh:
- zout.writestr(n, fh.read(), zipfile.ZIP_DEFLATED)
- else:
- zout.writestr(n, zin.read(n), zipfile.ZIP_DEFLATED)
- else:
- zout.writestr(n, zin.read(n), zipfile.ZIP_DEFLATED)
- zout.close()
- zv = zipfile.ZipFile(OUT)
- print("manifest first?", zv.namelist()[0] == "META-INF/MANIFEST.MF")
- print("BusinessException replaced?", "BOOT-INF/classes/com/example/resourceplatform/common/BusinessException.class" in zv.namelist())
|