1 package com.atlassian.plugin.util;
2
3 import com.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 {
19 private static final Logger LOG = LoggerFactory.getLogger(PluginFrameworkUtils.class);
20 private static final String BUILD_PROPERTY_PATH = "META-INF/maven/com.atlassian.plugins/atlassian-plugins-core/pom.properties";
21
22
23
24
25 private PluginFrameworkUtils()
26 {}
27
28
29
30
31
32
33
34 public static String getPluginFrameworkVersion()
35 {
36 return pluginFrameworkVersionRef.get();
37 }
38
39 private static final LazyReference<String> pluginFrameworkVersionRef = new LazyReference<String>()
40 {
41 @Override
42 protected String create() throws Exception
43 {
44 return getPluginFrameworkVersionInternal();
45 }
46 };
47
48 private static String getPluginFrameworkVersionInternal()
49 {
50 Properties props = new Properties();
51 InputStream in = null;
52
53 try
54 {
55 in = ClassLoaderUtils.getResourceAsStream(BUILD_PROPERTY_PATH, PluginFrameworkUtils.class);
56 if (in != null)
57 {
58
59 props.load(in);
60 return props.getProperty("version");
61 }
62 else
63 {
64
65 return "2.7.0";
66 }
67
68 }
69 catch (IOException e)
70 {
71 LOG.error("cannot determine the plugin framework version", e);
72 throw new IllegalStateException("cannot determine the plugin framework version", e);
73 }
74 finally
75 {
76 IOUtils.closeQuietly(in);
77 }
78 }
79 }