From d9039f30bd315c2d9f99f12dc9748837f718a762 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hans=20Sch=C3=BClein?= Date: Thu, 24 Aug 2023 22:13:47 +0200 Subject: [PATCH] Hopefully fixed macos-codesigining issue due to license file name collision; bumped version number --- fix_license_file.py | 77 ++++ pom.xml | 919 +++++++++++++++++++++++--------------------- 2 files changed, 548 insertions(+), 448 deletions(-) create mode 100644 fix_license_file.py diff --git a/fix_license_file.py b/fix_license_file.py new file mode 100644 index 0000000..91bbcc4 --- /dev/null +++ b/fix_license_file.py @@ -0,0 +1,77 @@ +#!/usr/bin/env python3 +"""Fix an issue when unpacking the jar on a case insensitive file system. + +When signing the mac app on a case sensitive file system, an error occurs, since +the jar contains both a text file named `LICENSE` at the root level as well as a +directory named `license/`. Some macOS installations are case insensitive, which +means they cannot differentiate between the two when given a path. The runner on +GitHub that is configured to execute the macOS notarization tasks is among them. +This results in a warning when unpacking the .jar in the process, which causes a +non-zero exit-code and thus maven failing. Even if the warning would be muted in +some way, the license file would be lost, which is undesirable. This outcome can +be prevented by renaming the license file inside the zip, which is this script's +goal. + As far as I could find, Python does not allow for directly renaming anything +inside a zip file. The solution here is to copy every file inside the zip into a +zip file inside a temporary directory. The license file is then being renamed to +*LICENSE.txt* instead of *LICENSE* when placing it in the new zip file. Once the +process is complete, the new zip file replaces the old one. As a final step, the +temporary directory the zip file was stored in is deleted. Be aware, that even a +crash during the transfer will not prevent the directory from being deleted. For +debugging, delete the last line. +""" + +import argparse +import shutil +import tempfile +import zipfile +from pathlib import Path + + +def main() -> None: + """Execute the trans-zipping dance.""" + + # Require one single command line argument, crash if it does not exist. + parser = argparse.ArgumentParser() + parser.add_argument("jar", help="the .jar file to rename the license in.") + args = parser.parse_args() + + # Create a temporary directory to store the new jar file in. The Python docs + # state, that I need to clean this up after. + temp_dir = Path(tempfile.mkdtemp()) + # The original jar to rename the file in. + jar = Path(args.jar) + try: + # The name of the temporary .jar file inside the temporary directory. + temp_jar = temp_dir / jar.name + # Open the jar that the data is read from. + with zipfile.ZipFile(jar, "r") as in_file: + # Open the jar that the data is written to. + with zipfile.ZipFile(temp_jar, "w") as out_file: + # Iterate over all the files inside the jar and copy them to the + # new jar. Rename the license in the process. + for item in in_file.infolist(): + # Store the data of that file for writing into the new file. + # It is not used as a direct argument in the `writestr`, due + # to me changing the `item` object, which then would cause a + # crash. I change the data directly as it keeps all metadata + # stored inside ZipInfo intact. + data = in_file.read(item.filename) + # Filter any file at root level named `LICENSE` and edit its + # metadata to rename it to `LICENSE.txt`. `filename` doesn't + # in fact describe the file name but instead the path inside + # the zip file. So the `LICENSE` file inside `license/`, has + # the "filename" `license/LICENSE`. + if item.filename == "LICENSE": + item.filename = "LICENSE.txt" + # Add the file to the new jar, with the tweaked metadata. + out_file.writestr(item, data) + # Replace the old jar with the filtered one. + shutil.move(temp_jar, jar) + finally: + # Delete the temporary directory, even if an error occurred. + shutil.rmtree(temp_dir) + + +if __name__ == "__main__": + main() diff --git a/pom.xml b/pom.xml index e02536e..d34f4d1 100644 --- a/pom.xml +++ b/pom.xml @@ -1,448 +1,471 @@ - - - 4.0.0 - - de.paginagmbh - EPUB-Checker - 2.0.9-SNAPSHOT - - jar - - pagina EPUB-Checker - pagina EPUB-Checker is a free GUI wrapper for the official W3C EPUBCheck library. - https://pagina.gmbh/startseite/leistungen/publishing-softwareloesungen/epub-checker/ - 2010 - - pagina GmbH - https://www.pagina.gmbh - - - - - Tobias Fischer - tofi86 - tobias.carl.fischer@gmail.com - previously pagina GmbH - - - Magdalena Sannwald - Sannwama - magdalena.sannwald@pagina.gmbh - pagina GmbH - - - Kai Weber - sermo_de_arboribus - kai.weber@pagina.gmbh - pagina GmbH - - - Dr. Björn Rudzewitz - br-pagina - bjoern.rudzewitz@pagina.gmbh - pagina GmbH - - - - https://github.com/paginagmbh/EPUB-Checker - scm:git:git@github.com:paginagmbh/EPUB-Checker.git - scm:git:git@github.com:paginagmbh/EPUB-Checker.git - HEAD - - - GitHub - https://github.com/paginagmbh/EPUB-Checker/issues - - - - - - project.local - project - file:${project.basedir}/repo - - - - - - org.w3c - epubcheck - 5.1.0 - - - com.metaparadigm - json-rpc - 1.0 - - - - - - - com.apple - AppleJavaExtensions - 1.5 - - - com.bulenkov - iconloader - 1.0 - - - - - com.ultramixer.jarbundler - jarbundler-core - 3.3.0 - - - - - - UTF-8 - - - true - - - true - - - ${project.basedir}/src/main/assembly - ${project.basedir}/src/build - ${project.build.sourceDir}/icons - ${project.build.sourceDir}/splashscreen - ${project.build.directory}/universalJavaApplicationStub - - - de.paginagmbh.epubchecker.PaginaEPUBChecker - paginaEPUBChecker - EPUB-Checker - pagina EPUB-Checker - ${parsedVersion.majorVersion}.${parsedVersion.minorVersion}.${parsedVersion.incrementalVersion} - Developer ID Application: pagina GmbH Apps (PPJQ7BTA69) - - - - - - - - org.apache.maven.plugins - maven-enforcer-plugin - 3.0.0-M3 - - - enforce-maven - - enforce - - - - - [3.5,) - - - - - - - - - - org.codehaus.mojo - build-helper-maven-plugin - 3.1.0 - - - - - timestamp-property - validate - - timestamp-property - - - current.year - yyyy - - - - - - parse-version - validate - - parse-version - - - - - - - - org.codehaus.mojo - buildnumber-maven-plugin - 1.4 - - 5 - - - - validate - - create - - - - - - - - maven-compiler-plugin - 3.8.1 - - 1.8 - 1.8 - - - - - - maven-assembly-plugin - 3.2.0 - - - jar-with-dependencies - - prepare-package - - single - - - ${my.finalJarName} - false - false - - jar-with-dependencies - - - - - - ${my.mainclass} - - - - . - ${my.versionNumber} - ${buildNumber} - - - - - - - - dist-linux - package - - single - - - - ${project.assembly.sourceDir}/dist-linux.xml - - - - - - - dist-win - package - - single - - - - ${project.assembly.sourceDir}/dist-win.xml - - - - - - - dist-mac - package - - single - - - - ${project.assembly.sourceDir}/dist-mac.xml - - - - - - - - - com.akathist.maven.plugins.launch4j - launch4j-maven-plugin - 2.3.3 - - - exe-win - - prepare-package - - launch4j - - - - ${project.build.sourceDir}/launch4j-config.xml - - - ${project.build.directory}/${my.finalJarName}.jar - ${project.build.directory}/${my.finalShortName}.exe - - ${my.versionNumber}.0 - ${my.versionNumber} - ${my.versionNumber}.0 - ${my.versionNumber} - - - - - - - - - maven-scm-plugin - 1.11.2 - - - get-javaStub - generate-resources - - checkout - - - scm:git:https://github.com/tofi86/universalJavaApplicationStub.git - ${project.JavaStubRepo.directory} - true - - tag - v3.2.0 - - - - - - - - org.apache.maven.plugins - maven-antrun-plugin - 1.8 - - - create-macApp - prepare-package - - - - - - - - - - - - - - - - - - - - - - - - run - - - - - - - - org.codehaus.mojo - exec-maven-plugin - 1.6.0 - - - - - mac-release - prepare-package - - exec - - - ${maven.skip.macSigning} - ${project.build.sourceDir}/mac-release.sh - ${project.basedir} - - ${project.basedir} - ${project.build.directory} - ${my.versionNumber} - ${my.finalShortName} - ${my.finalLongName} - ${my.appleSigningIdentity} - - - - - - - - - - + + + 4.0.0 + + de.paginagmbh + EPUB-Checker + 2.0.10-SNAPSHOT + + jar + + pagina EPUB-Checker + pagina EPUB-Checker is a free GUI wrapper for the official W3C EPUBCheck library. + https://pagina.gmbh/startseite/leistungen/publishing-softwareloesungen/epub-checker/ + 2010 + + pagina GmbH + https://www.pagina.gmbh + + + + + Tobias Fischer + tofi86 + tobias.carl.fischer@gmail.com + previously pagina GmbH + + + Magdalena Sannwald + Sannwama + magdalena.sannwald@pagina.gmbh + pagina GmbH + + + Kai Weber + sermo_de_arboribus + kai.weber@pagina.gmbh + pagina GmbH + + + Dr. Björn Rudzewitz + br-pagina + bjoern.rudzewitz@pagina.gmbh + pagina GmbH + + + Hans Schülein + kamik423 + hans.schuelein@pagina.gmbh + pagina GmbH + + + + https://github.com/paginagmbh/EPUB-Checker + scm:git:git@github.com:paginagmbh/EPUB-Checker.git + scm:git:git@github.com:paginagmbh/EPUB-Checker.git + HEAD + + + GitHub + https://github.com/paginagmbh/EPUB-Checker/issues + + + + + + project.local + project + file:${project.basedir}/repo + + + + + + org.w3c + epubcheck + 5.1.0 + + + com.metaparadigm + json-rpc + 1.0 + + + + + + + com.apple + AppleJavaExtensions + 1.5 + + + com.bulenkov + iconloader + 1.0 + + + + + com.ultramixer.jarbundler + jarbundler-core + 3.3.0 + + + + + + UTF-8 + + + true + + + true + + + ${project.basedir}/src/main/assembly + ${project.basedir}/src/build + ${project.build.sourceDir}/icons + ${project.build.sourceDir}/splashscreen + ${project.build.directory}/universalJavaApplicationStub + + + de.paginagmbh.epubchecker.PaginaEPUBChecker + paginaEPUBChecker + EPUB-Checker + pagina EPUB-Checker + ${parsedVersion.majorVersion}.${parsedVersion.minorVersion}.${parsedVersion.incrementalVersion} + Developer ID Application: pagina GmbH Apps (PPJQ7BTA69) + + + + + + + + org.apache.maven.plugins + maven-enforcer-plugin + 3.0.0-M3 + + + enforce-maven + + enforce + + + + + [3.5,) + + + + + + + + + + org.codehaus.mojo + build-helper-maven-plugin + 3.1.0 + + + + + timestamp-property + validate + + timestamp-property + + + current.year + yyyy + + + + + + parse-version + validate + + parse-version + + + + + + + + org.codehaus.mojo + buildnumber-maven-plugin + 1.4 + + 5 + + + + validate + + create + + + + + + + + maven-compiler-plugin + 3.8.1 + + 1.8 + 1.8 + + + + + + maven-assembly-plugin + 3.2.0 + + + jar-with-dependencies + + prepare-package + + single + + + ${my.finalJarName} + false + false + + jar-with-dependencies + + + + + + ${my.mainclass} + + + + . + ${my.versionNumber} + ${buildNumber} + + + + + + + + dist-linux + package + + single + + + + ${project.assembly.sourceDir}/dist-linux.xml + + + + + + + dist-win + package + + single + + + + ${project.assembly.sourceDir}/dist-win.xml + + + + + + + dist-mac + package + + single + + + + ${project.assembly.sourceDir}/dist-mac.xml + + + + + + + + + com.akathist.maven.plugins.launch4j + launch4j-maven-plugin + 2.3.3 + + + exe-win + + prepare-package + + launch4j + + + + ${project.build.sourceDir}/launch4j-config.xml + + + ${project.build.directory}/${my.finalJarName}.jar + ${project.build.directory}/${my.finalShortName}.exe + + ${my.versionNumber}.0 + ${my.versionNumber} + ${my.versionNumber}.0 + ${my.versionNumber} + + + + + + + + + maven-scm-plugin + 1.11.2 + + + get-javaStub + generate-resources + + checkout + + + scm:git:https://github.com/tofi86/universalJavaApplicationStub.git + ${project.JavaStubRepo.directory} + true + + tag + v3.2.0 + + + + + + + + org.apache.maven.plugins + maven-antrun-plugin + 1.8 + + + create-macApp + prepare-package + + + + + + + + + + + + + + + + + + + + + + + + run + + + + + + + + org.codehaus.mojo + exec-maven-plugin + 1.6.0 + + + + + + python3 + ${project.basedir} + + fix_license_file.py + ${project.build.directory}/${my.finalShortName}.app/Contents/Resources/Java/${my.finalJarName}.jar + + + python_build + prepare-package + + exec + + + + + + mac-release + prepare-package + + exec + + + ${maven.skip.macSigning} + ${project.build.sourceDir}/mac-release.sh + ${project.basedir} + + ${project.basedir} + ${project.build.directory} + ${my.versionNumber} + ${my.finalShortName} + ${my.finalLongName} + ${my.appleSigningIdentity} + + + + + + + + + +