001/* 002 * Logback: the reliable, generic, fast and flexible logging framework. 003 * Copyright (C) 1999-2026, QOS.ch. All rights reserved. 004 * 005 * This program and the accompanying materials are dual-licensed under 006 * either the terms of the Eclipse Public License v2.0 as published by 007 * the Eclipse Foundation 008 * 009 * or (per the licensee's choosing) 010 * 011 * under the terms of the GNU Lesser General Public License version 2.1 012 * as published by the Free Software Foundation. 013 */ 014 015package ch.qos.logback.access.tomcat; 016 017import ch.qos.logback.core.CoreConstants; 018 019import java.io.IOException; 020import java.io.InputStream; 021import java.util.Properties; 022 023import static ch.qos.logback.access.tomcat.AccessTomcatConstants.LOGBACK_ACCESS_TOMCAT_MODULE_NAME; 024 025public class AccessTomcatVersionUtil { 026 027 static String LOGBACK_ACCESS_TOMCAT_MODULE_VERSION_PROPERTIES_FILE = LOGBACK_ACCESS_TOMCAT_MODULE_NAME + "-version.properties"; 028 static String LOGBACK_ACCESS_TOMCAT_MODULE_VERSION_PROPERTY_KEY = LOGBACK_ACCESS_TOMCAT_MODULE_NAME + "-version"; 029 030 /** 031 * Retrieves the version of the "logback-core" module using a properties file 032 * associated with the module. 033 * 034 * <p>The method locates and reads a properties file named "logback-core-version.properties" 035 * in the package of the {@code CoreConstants.class}. It then extracts the version 036 * information using the key "logback-core-version". 037 * </p> 038 * 039 * @return the version of the "logback-core" module as a string, or null if the version cannot be determined 040 * @since 1.5.26 041 */ 042 static public String getCoreVersionBySelfDeclaredProperties() { 043 Properties props = new Properties(); 044 045 try (InputStream is = AccessTomcatConstants.class.getResourceAsStream(LOGBACK_ACCESS_TOMCAT_MODULE_VERSION_PROPERTIES_FILE)) { 046 if (is != null) { 047 props.load(is); 048 return props.getProperty(LOGBACK_ACCESS_TOMCAT_MODULE_VERSION_PROPERTY_KEY); 049 } else { 050 return null; 051 } 052 } catch (IOException e) { 053 return null; 054 } 055 } 056 057}