aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexander Marsalek <amarsalek@iaik.tugraz.at>2021-06-16 13:52:48 +0200
committerAlexander Marsalek <amarsalek@iaik.tugraz.at>2021-06-16 14:22:52 +0200
commitcc3608bf2b545116b67eba41d69225cae3247994 (patch)
treeadde7813c4618dc54cee65dc8a2277e10394c8db
parentc049cb3fd26dbf537a065e9537db2338b9c7248b (diff)
downloadpdf-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
-rw-r--r--build.gradle2
-rw-r--r--pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/api/PdfAsFactory.java53
2 files changed, 51 insertions, 4 deletions
diff --git a/build.gradle b/build.gradle
index dc5b8c2a..16716be0 100644
--- a/build.gradle
+++ b/build.gradle
@@ -12,7 +12,7 @@ buildscript {
allprojects {
apply plugin: "com.github.ben-manes.versions"
repositories { mavenCentral() }
- version = '4.1.7-RC-0.0.8'
+ version = '4.2.0-RC1'
}
configurations {
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;
}
/**