Skip to content

Commit dfe25d6

Browse files
author
Glyn Normington
committed
Merge 59314610-tomcat-datasource to master
[Completes #59314610]
2 parents 1cca2c8 + a81e748 commit dfe25d6

3 files changed

Lines changed: 82 additions & 3 deletions

File tree

lib/java_buildpack/container/tomcat.rb

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ def detect
4747
def compile
4848
download_tomcat
4949
download_support
50+
link_tomcat_datasource
5051
link_application
5152
link_container_libs
5253
link_extra_applications
@@ -94,6 +95,8 @@ def supports?
9495

9596
KEY_SUPPORT = 'support'.freeze
9697

98+
TOMCAT_DATASOURCE_JAR = 'tomcat-jdbc.jar'.freeze
99+
97100
WEB_INF_DIRECTORY = 'WEB-INF'.freeze
98101

99102
def container_libs_directory
@@ -130,7 +133,7 @@ def link_application
130133
@application.children.each { |child| FileUtils.ln_sf child.relative_path_from(root), root }
131134
end
132135

133-
# Support for container libs in addition to the users application in temporay and will go away in the future.
136+
# Support for container libs in addition to the user's application is temporary and will go away in the future.
134137
def link_container_libs
135138
if container_libs_directory.exist?
136139
container_libs = ContainerUtils.libs(@app_dir, container_libs_directory)
@@ -142,14 +145,14 @@ def link_container_libs
142145
end
143146
end
144147

145-
# Support for extra applications in addition to the users application in temporay and will go away in the future.
148+
# Support for extra applications in addition to the user's application is temporary and will go away in the future.
146149
def link_extra_applications
147150
if extra_applications_directory.exist?
148151
extra_applications = ContainerUtils.relative_paths(@app_dir, extra_applications_directory.children) { |file| file.directory? }
149152

150153
if extra_applications
151154
FileUtils.mkdir_p webapps
152-
extra_applications.each { |extra_application| FileUtils.ln_sf(File.join('..', '..', extra_application), webapps) }
155+
extra_applications.each { |extra_application| FileUtils.ln_sf(File.join('..', '..', extra_application), webapps) }
153156
end
154157
end
155158
end
@@ -163,6 +166,18 @@ def link_libs
163166
end
164167
end
165168

169+
170+
def link_tomcat_datasource
171+
tomcat_datasource_jar = tomcat_lib + TOMCAT_DATASOURCE_JAR
172+
if tomcat_datasource_jar.exist?
173+
# Link Tomcat datasource JAR into .lib
174+
lib_directory_pathname = Pathname.new(@lib_directory)
175+
symlink_source = tomcat_datasource_jar.relative_path_from(lib_directory_pathname)
176+
symlink_target = lib_directory_pathname + TOMCAT_DATASOURCE_JAR
177+
symlink_target.make_symlink symlink_source
178+
end
179+
end
180+
166181
def root
167182
webapps + 'ROOT'
168183
end

spec/fixtures/stub-tomcat7.tar.gz

229 Bytes
Binary file not shown.

spec/java_buildpack/container/tomcat_spec.rb

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,70 @@ module JavaBuildpack::Container
156156
end
157157
end
158158

159+
it 'should link the Tomcat datasource JAR to the ROOT webapp when that JAR is present' do
160+
Dir.mktmpdir do |root|
161+
Dir.mkdir File.join(root, 'WEB-INF')
162+
lib_directory = File.join(root, '.lib')
163+
Dir.mkdir lib_directory
164+
165+
JavaBuildpack::Repository::ConfiguredItem.stub(:find_item) { |&block| block.call(TOMCAT_VERSION) if block }
166+
.and_return(TOMCAT_DETAILS, SUPPORT_DETAILS)
167+
168+
JavaBuildpack::Util::ApplicationCache.stub(:new).and_return(application_cache)
169+
application_cache.stub(:get).with('test-tomcat-uri').and_yield(File.open('spec/fixtures/stub-tomcat7.tar.gz'))
170+
application_cache.stub(:get).with('test-support-uri').and_yield(File.open('spec/fixtures/stub-support.jar'))
171+
172+
application = JavaBuildpack::Application.new(root)
173+
174+
Tomcat.new(
175+
app_dir: root,
176+
application: application,
177+
configuration: {},
178+
lib_directory: lib_directory
179+
).compile
180+
181+
root_webapp = File.join root, '.tomcat', 'webapps', 'ROOT'
182+
183+
tomcat_datasource_jar = File.join root_webapp, 'WEB-INF', 'lib', 'tomcat-jdbc.jar'
184+
expect(File.exists?(tomcat_datasource_jar)).to be_true
185+
expect(File.readlink(tomcat_datasource_jar)).to eq('../../.lib/tomcat-jdbc.jar')
186+
187+
tomcat_datasource_link_in_lib_directory = File.join lib_directory, 'tomcat-jdbc.jar'
188+
expect(File.exists?(tomcat_datasource_link_in_lib_directory))
189+
expect(File.readlink(tomcat_datasource_link_in_lib_directory)).to eq('../.tomcat/lib/tomcat-jdbc.jar')
190+
end
191+
end
192+
193+
it 'should not link the Tomcat datasource JAR to the ROOT webapp when that JAR is absent' do
194+
Dir.mktmpdir do |root|
195+
Dir.mkdir File.join(root, 'WEB-INF')
196+
lib_directory = File.join(root, '.lib')
197+
Dir.mkdir lib_directory
198+
199+
JavaBuildpack::Repository::ConfiguredItem.stub(:find_item) { |&block| block.call(TOMCAT_VERSION) if block }
200+
.and_return(TOMCAT_DETAILS, SUPPORT_DETAILS)
201+
202+
JavaBuildpack::Util::ApplicationCache.stub(:new).and_return(application_cache)
203+
application_cache.stub(:get).with('test-tomcat-uri').and_yield(File.open('spec/fixtures/stub-tomcat.tar.gz'))
204+
application_cache.stub(:get).with('test-support-uri').and_yield(File.open('spec/fixtures/stub-support.jar'))
205+
206+
application = JavaBuildpack::Application.new(root)
207+
208+
Tomcat.new(
209+
app_dir: root,
210+
application: application,
211+
configuration: {},
212+
lib_directory: lib_directory
213+
).compile
214+
215+
root_webapp = File.join root, '.tomcat', 'webapps', 'ROOT'
216+
217+
tomcat_datasource_jar = File.join root_webapp, 'WEB-INF', 'lib', 'tomcat-jdbc.jar'
218+
expect(File.exists?(tomcat_datasource_jar)).to be_false
219+
end
220+
end
221+
222+
159223
it 'should link additional libraries to the ROOT webapp' do
160224
Dir.mktmpdir do |root|
161225
Dir.mkdir File.join root, 'WEB-INF'

0 commit comments

Comments
 (0)