11# frozen_string_literal: true
22
33# Cloud Foundry Java Buildpack
4- # Copyright 2013-2020 the original author or authors.
4+ # Copyright 2013-2021 the original author or authors.
55#
66# Licensed under the Apache License, Version 2.0 (the "License");
77# you may not use this file except in compliance with the License.
@@ -32,6 +32,7 @@ def compile
3232 return unless supports?
3333
3434 download_tar ( false , tomcat_lib , tar_name )
35+ detect_geode_tomcat_version
3536 mutate_context
3637 mutate_server
3738 create_cache_client_xml
@@ -58,7 +59,6 @@ def supports?
5859 KEY_LOCATORS = 'locators'
5960 KEY_USERS = 'users'
6061
61- SESSION_MANAGER_CLASS_NAME = 'org.apache.geode.modules.session.catalina.Tomcat9DeltaSessionManager'
6262 REGION_ATTRIBUTES_ID = 'PARTITION_REDUNDANT_HEAP_LRU'
6363 CACHE_CLIENT_LISTENER_CLASS_NAME =
6464 'org.apache.geode.modules.session.catalina.ClientServerCacheLifecycleListener'
@@ -67,7 +67,7 @@ def supports?
6767 SCHEMA_LOCATION = 'http://geode.apache.org/schema/cache http://geode.apache.org/schema/cache/cache-1.0.xsd'
6868 LOCATOR_REGEXP = Regexp . new ( '([^\\[]+)\\[([^\\]]+)\\]' ) . freeze
6969
70- private_constant :FILTER , :KEY_LOCATORS , :KEY_USERS , :SESSION_MANAGER_CLASS_NAME , : REGION_ATTRIBUTES_ID,
70+ private_constant :FILTER , :KEY_LOCATORS , :KEY_USERS , :REGION_ATTRIBUTES_ID ,
7171 :CACHE_CLIENT_LISTENER_CLASS_NAME , :SCHEMA_URL , :SCHEMA_INSTANCE_URL , :SCHEMA_LOCATION ,
7272 :LOCATOR_REGEXP
7373
@@ -98,7 +98,7 @@ def add_locators(pool)
9898
9999 def add_manager ( context )
100100 context . add_element 'Manager' ,
101- 'className' => SESSION_MANAGER_CLASS_NAME ,
101+ 'className' => @session_manager_classname ,
102102 'enableLocalCache' => 'true' ,
103103 'regionAttributesId' => REGION_ATTRIBUTES_ID
104104 end
@@ -124,9 +124,42 @@ def create_cache_client_xml
124124 write_xml cache_client_xml_path , document
125125 end
126126
127+ def detect_geode_tomcat_version
128+ geode_tomcat_version = nil
129+
130+ geode_modules_tomcat_pattern = /geode-modules-tomcat(?<version>[0-9]*).*.jar/ . freeze
131+ Dir . foreach ( @droplet . sandbox + 'lib' ) do |file |
132+ if geode_modules_tomcat_pattern . match ( file )
133+ unless geode_tomcat_version . nil?
134+ raise ( 'Multiple versions of geode-modules-tomcat jar found. ' \
135+ 'Please verify your geode_store tar only contains one geode-modules-tomcat jar.' )
136+ end
137+
138+ geode_tomcat_version = geode_modules_tomcat_pattern . match ( file ) . named_captures [ 'version' ]
139+ end
140+ end
141+
142+ if geode_tomcat_version . nil?
143+ raise ( 'Geode Tomcat module not found. ' \
144+ 'Please verify your geode_store tar contains a geode-modules-tomcat jar.' )
145+ end
146+
147+ tomcat_version = @configuration [ 'tomcat_version' ]
148+
149+ # leave possibility for generic jar/session manager class that is compatible with all tomcat versions
150+ if !geode_tomcat_version . empty? && geode_tomcat_version != tomcat_version
151+ puts " WARNING: Tomcat version #{ tomcat_version } " \
152+ "does not match Geode Tomcat #{ geode_tomcat_version } module. " \
153+ 'If you encounter compatibility issues, please make sure these versions match.'
154+ end
155+
156+ puts " Detected Geode Tomcat #{ geode_tomcat_version } module"
157+ @session_manager_classname =
158+ "org.apache.geode.modules.session.catalina.Tomcat#{ geode_tomcat_version } DeltaSessionManager"
159+ end
160+
127161 def mutate_context
128162 puts ' Adding Geode-based Session Replication'
129-
130163 document = read_xml context_xml
131164 context = REXML ::XPath . match ( document , '/Context' ) . first
132165
0 commit comments