View Javadoc
1   package com.atlassian.plugin.refimpl;
2   
3   import org.apache.commons.io.IOUtils;
4   
5   import java.io.IOException;
6   import java.io.InputStream;
7   import java.util.Properties;
8   
9   /**
10   * Utility class for system exports.
11   *
12   * @since 2.14.0
13   */
14  public class SystemExportVersionUtils {
15      private SystemExportVersionUtils() {
16      }
17  
18      private static final String GUAVA_PROPERTY_PATH = "META-INF/maven/com.google.guava/guava/pom.properties";
19  
20      /**
21       * Retrieves version number of the bundled google guava.
22       *
23       * @return version of google guava
24       */
25      public static String getGoogleGuavaVersion() {
26          InputStream inputStream = null;
27  
28          try {
29              inputStream = SystemExportVersionUtils.class.getClassLoader().getResourceAsStream(GUAVA_PROPERTY_PATH);
30  
31              if (inputStream == null) {
32                  throw new IllegalStateException("google guava is required in classpath for refapp to function");
33              }
34  
35              Properties props = new Properties();
36              try {
37                  props.load(inputStream);
38              } catch (IOException e) {
39                  throw new IllegalStateException("cannot read the bundled google guava version file");
40              }
41  
42              final String guavaVersion = props.getProperty("version");
43              if (guavaVersion == null) {
44                  throw new IllegalStateException("cannot extract google guava version from the bundled version file");
45              }
46  
47              return guavaVersion;
48          } finally {
49              IOUtils.closeQuietly(inputStream);
50          }
51      }
52  }