001package ch.qos.logback.access.common.util; 002 003import ch.qos.logback.access.common.AccessConstants; 004 005import java.io.IOException; 006import java.io.InputStream; 007import java.util.Properties; 008 009/** 010 * Utility class for retrieving version information about the "logback-access-common" module 011 * based on the self-declared properties file. 012 * 013 * 014 * @since 2.0.9 015 */ 016public class AccessCommonVersionUtil { 017 018 019 static public String getAccessCommonVersionBySelfDeclaredProperties() { 020 return getArtifactVersionBySelfDeclaredProperties(AccessConstants.class, "logback-access-common"); 021 } 022 023 static public String getArtifactVersionBySelfDeclaredProperties(Class<?> aClass, String moduleName) { 024 Properties props = new Properties(); 025 // example propertiesFileName: logback-core-version.properties 026 // 027 String propertiesFileName = moduleName + "-version.properties"; 028 String propertyKey = moduleName+"-version"; 029 try (InputStream is = aClass.getResourceAsStream(propertiesFileName)) { 030 if (is != null) { 031 props.load(is); 032 return props.getProperty(propertyKey); 033 } else { 034 return null; 035 } 036 } catch (IOException e) { 037 return null; 038 } 039 } 040 041 042}