diff options
author | Alexander Marsalek <amarsalek@iaik.tugraz.at> | 2021-06-16 13:52:48 +0200 |
---|---|---|
committer | Alexander Marsalek <amarsalek@iaik.tugraz.at> | 2021-06-16 14:22:52 +0200 |
commit | cc3608bf2b545116b67eba41d69225cae3247994 (patch) | |
tree | adde7813c4618dc54cee65dc8a2277e10394c8db /pdf-as-lib | |
parent | c049cb3fd26dbf537a065e9537db2338b9c7248b (diff) | |
download | pdf-as-4-cc3608bf2b545116b67eba41d69225cae3247994.tar.gz pdf-as-4-cc3608bf2b545116b67eba41d69225cae3247994.tar.bz2 pdf-as-4-cc3608bf2b545116b67eba41d69225cae3247994.zip |
v4.2.0-RC1 workaround to get implementation and specification version from manifest
Diffstat (limited to 'pdf-as-lib')
-rw-r--r-- | pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/api/PdfAsFactory.java | 53 |
1 files changed, 50 insertions, 3 deletions
diff --git a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/api/PdfAsFactory.java b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/api/PdfAsFactory.java index f917de64..0b465bc1 100644 --- a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/api/PdfAsFactory.java +++ b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/api/PdfAsFactory.java @@ -42,14 +42,24 @@ import javax.activation.DataSource; import javax.crypto.Cipher; import java.awt.*; import java.awt.image.BufferedImage; -import java.io.*; +import java.io.BufferedOutputStream; +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; import java.lang.management.ManagementFactory; import java.lang.management.OperatingSystemMXBean; import java.lang.management.RuntimeMXBean; +import java.net.URL; +import java.net.URLClassLoader; import java.security.Provider; import java.security.Security; +import java.util.Enumeration; import java.util.Map; import java.util.Map.Entry; +import java.util.jar.Attributes; +import java.util.jar.Manifest; import java.util.zip.ZipEntry; import java.util.zip.ZipInputStream; @@ -347,7 +357,12 @@ public class PdfAsFactory implements IConfigurationConstants { */ public static String getSCMRevision() { Package pack = PdfAsFactory.class.getPackage(); - return pack.getSpecificationVersion(); + String specificationVersion = pack.getSpecificationVersion(); + + if(specificationVersion != null) + return specificationVersion; + //fallback + return getJarAttributes().getValue("Specification-Version"); } /** @@ -356,8 +371,40 @@ public class PdfAsFactory implements IConfigurationConstants { * @return PDF-AS Verison string */ public static String getVersion() { + Package pack = PdfAsFactory.class.getPackage(); - return pack.getImplementationVersion(); + String version = pack.getImplementationVersion(); + if(version != null) + return version; + //fallback + return getJarAttributes().getValue("Implementation-Version"); + } + + private static Attributes jarAttributes = null; + private static Attributes getJarAttributes() { + if(jarAttributes != null) + return jarAttributes; + try { + URLClassLoader cl = (URLClassLoader) PdfAsFactory.class.getClassLoader(); + Enumeration<URL> urls = cl.findResources("META-INF/MANIFEST.MF"); + URL url = null; + while (urls.hasMoreElements()) { + URL tmp = urls.nextElement(); + if (tmp.getFile().contains("pdf-as-lib")) { + System.out.println("Found:" + tmp); + url = tmp; + } + + } + Manifest manifest = new Manifest(url.openStream()); + Attributes mainAttributes = manifest.getMainAttributes(); + jarAttributes = mainAttributes; + return mainAttributes; + } catch (Exception e) { + // handle + jarAttributes = new Attributes(); + } + return null; } /** |