+ public static void updateCdmlibManifestInfo() {
+ cdmlibVersion = null;
+ cdmlibLastModified = null;
+ String cdmlibPathPrefix = "lib/cdmlib-services-";
+ String jarSuffix = ".jar";
+ Bundle bundle = Platform.getBundle("eu.etaxonomy.taxeditor.cdmlib");
+ Dictionary<String, String> headers = bundle.getHeaders();
+ String bundleClasspath = headers.get(Constants.BUNDLE_CLASSPATH);
+ try {
+ ManifestElement[] elements = ManifestElement.parseHeader(Constants.BUNDLE_CLASSPATH, bundleClasspath);
+ for (ManifestElement manifestElement : elements) {
+ String jar = manifestElement.getValue();
+ if(jar.startsWith(cdmlibPathPrefix) && jar.endsWith(jarSuffix)) {
+ URL fileURL = bundle.getEntry(jar);
+ File file = null;
+ try {
+ String urlString = FileLocator.resolve(fileURL).toExternalForm().replace(" ", "%20");
+
+ file = new File(new URI(urlString).getJavaUri());
+ JarFile jarFile = new JarFile(file);
+ Manifest manifest = jarFile.getManifest();
+ Attributes attributes = manifest.getMainAttributes();
+ // from the OSGI spec the LastModified value is " the number of milliseconds
+ // since midnight Jan. 1, 1970 UTC with the condition that a change must
+ // always result in a higher value than the previous last modified time
+ // of any bundle"
+ cdmlibVersion = attributes.getValue("Bundle-Version");
+ cdmlibLastModified = attributes.getValue("Bnd-LastModified");
+
+ jarFile.close();
+ if(cdmlibVersion == null || cdmlibLastModified == null) {
+ throw new IllegalStateException("Invalid cdmlib manifest info");
+ }
+ } catch (URISyntaxException urise) {
+ throw new IllegalStateException(urise);
+ } catch (IOException ioe) {
+ throw new IllegalStateException(ioe);
+ } catch (IllegalArgumentException iae) {
+ String message = iae.getMessage().concat("uri" + jar);
+ throw new IllegalStateException(message);
+ }
+ }
+ }
+ } catch (BundleException e) {
+ throw new IllegalStateException(e);
+ }
+ }
+
+ public static String getCdmlibVersion() {
+ if(cdmlibVersion == null) {
+ updateCdmlibManifestInfo();
+ }
+ return cdmlibVersion;
+ }