1 package com.atlassian.plugin.util;
2
3 import io.atlassian.util.concurrent.LazyReference;
4 import org.apache.commons.io.IOUtils;
5 import org.slf4j.Logger;
6 import org.slf4j.LoggerFactory;
7
8 import java.io.IOException;
9 import java.io.InputStream;
10 import java.util.Properties;
11
12
13
14
15
16
17 public final class PluginFrameworkUtils {
18 private static final Logger LOG = LoggerFactory.getLogger(PluginFrameworkUtils.class);
19 private static final String BUILD_PROPERTY_PATH = "META-INF/maven/com.atlassian.plugins/atlassian-plugins-core/pom.properties";
20
21
22
23
24 private PluginFrameworkUtils() {
25 }
26
27
28
29
30
31
32
33 public static String getPluginFrameworkVersion() {
34 return pluginFrameworkVersionRef.get();
35 }
36
37 private static final LazyReference<String> pluginFrameworkVersionRef = new LazyReference<String>() {
38 @Override
39 protected String create() {
40 return getPluginFrameworkVersionInternal();
41 }
42 };
43
44 private static String getPluginFrameworkVersionInternal() {
45 Properties props = new Properties();
46 InputStream in = null;
47
48 try {
49 in = ClassLoaderUtils.getResourceAsStream(BUILD_PROPERTY_PATH, PluginFrameworkUtils.class);
50 if (in != null) {
51
52 props.load(in);
53 return props.getProperty("version");
54 } else {
55
56 return "2.7.0";
57 }
58
59 } catch (IOException e) {
60 LOG.error("cannot determine the plugin framework version", e);
61 throw new IllegalStateException("cannot determine the plugin framework version", e);
62 } finally {
63 IOUtils.closeQuietly(in);
64 }
65 }
66 }