1   package ch.qos.logback.access.common.util;
2   
3   import ch.qos.logback.access.common.AccessConstants;
4   
5   import java.io.IOException;
6   import java.io.InputStream;
7   import java.util.Properties;
8   
9   /**
10   * Utility class for retrieving version information about the "logback-access-common" module
11   * based on the self-declared properties file.
12   *
13   *
14   * @since 2.0.9
15   */
16  public class AccessCommonVersionUtil {
17  
18  
19      static public String getAccessCommonVersionBySelfDeclaredProperties() {
20          return getArtifactVersionBySelfDeclaredProperties(AccessConstants.class, "logback-access-common");
21      }
22  
23      static public String getArtifactVersionBySelfDeclaredProperties(Class<?> aClass, String moduleName) {
24          Properties props = new Properties();
25          // example propertiesFileName: logback-core-version.properties
26          //
27          String propertiesFileName = moduleName + "-version.properties";
28          String propertyKey = moduleName+"-version";
29          try (InputStream is = aClass.getResourceAsStream(propertiesFileName)) {
30              if (is != null) {
31                  props.load(is);
32                  return props.getProperty(propertyKey);
33              } else {
34                  return null;
35              }
36          } catch (IOException e) {
37              return null;
38          }
39      }
40  
41  
42  }