forked from cloudfoundry/java-buildpack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtomcat.rb
More file actions
161 lines (130 loc) · 4.91 KB
/
tomcat.rb
File metadata and controls
161 lines (130 loc) · 4.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
# Encoding: utf-8
# Cloud Foundry Java Buildpack
# Copyright 2013 the original author or authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
require 'fileutils'
require 'java_buildpack/component/base_component'
require 'java_buildpack/container'
require 'java_buildpack/repository/configured_item'
require 'java_buildpack/util/dash_case'
require 'java_buildpack/util/java_main_utils'
module JavaBuildpack::Container
# Encapsulates the detect, compile, and release functionality for Tomcat applications.
class Tomcat < JavaBuildpack::Component::BaseComponent
def initialize(context)
super(context)
if supports?
@tomcat_version, @tomcat_uri = JavaBuildpack::Repository::ConfiguredItem
.find_item(@component_name, @configuration) { |candidate_version| candidate_version.check_size(3) }
@support_version, @support_uri = JavaBuildpack::Repository::ConfiguredItem
.find_item(@component_name, @configuration['support'])
else
@tomcat_version, @tomcat_uri = nil, nil
@support_version, @support_uri = nil, nil
end
end
def detect
@tomcat_version && @support_version ? [tomcat_id(@tomcat_version), support_id(@support_version)] : nil
end
def compile
download_tomcat
download_support
link_to(@application.root.children, root)
do_not_depend_on_this
@droplet.additional_libraries << tomcat_datasource_jar if tomcat_datasource_jar.exist?
@droplet.additional_libraries.link_to web_inf_lib
end
def release
@droplet.java_opts.add_system_property 'http.port', '$PORT'
[
@droplet.java_home.as_env_var,
@droplet.java_opts.as_env_var,
"$PWD/#{(@droplet.sandbox + 'bin/catalina.sh').relative_path_from(@droplet.root)}",
'run'
].compact.join(' ')
end
protected
# The unique identifier of the component, incorporating the version of the dependency (e.g. +tomcat=7.0.42+)
#
# @param [String] version the version of the dependency
# @return [String] the unique identifier of the component
def tomcat_id(version)
"#{Tomcat.to_s.dash_case}=#{version}"
end
# The unique identifier of the component, incorporating the version of the dependency (e.g. +tomcat-buildpack-support=1.1.0+)
#
# @param [String] version the version of the dependency
# @return [String] the unique identifier of the component
def support_id(version)
"tomcat-buildpack-support=#{version}"
end
# Whether or not this component supports this application
#
# @return [Boolean] whether or not this component supports this application
def supports?
web_inf? && !JavaBuildpack::Util::JavaMainUtils.main_class(@application)
end
private
def container_libs_directory
@droplet.root + '.spring-insight/container-libs'
end
# DO NOT DEPEND ON THIS FUNCTIONALITY
def do_not_depend_on_this
link_to(container_libs_directory.children, tomcat_lib) if container_libs_directory.exist?
link_to(extra_applications_directory.children, webapps) if extra_applications_directory.exist?
end
def download_tomcat
download(@tomcat_version, @tomcat_uri) { |file| expand file }
end
def download_support
download_jar(@support_version, @support_uri, support_jar_name, @droplet.sandbox + 'lib',
'Buildpack Tomcat Support')
end
def expand(file)
with_timing "Expanding Tomcat to #{@droplet.sandbox.relative_path_from(@droplet.root)}" do
FileUtils.mkdir_p @droplet.sandbox
shell "tar xzf #{file.path} -C #{@droplet.sandbox} --strip 1 --exclude webapps 2>&1"
@droplet.copy_resources
end
end
def extra_applications_directory
@droplet.root + '.spring-insight/extra-applications'
end
def link_to(source, destination)
FileUtils.mkdir_p destination
source.each { |path| (destination + path.basename).make_symlink(path.relative_path_from(destination)) }
end
def root
webapps + 'ROOT'
end
def support_jar_name
"tomcat_buildpack_support-#{@support_version}.jar"
end
def tomcat_datasource_jar
tomcat_lib + 'tomcat-jdbc.jar'
end
def tomcat_lib
@droplet.sandbox + 'lib'
end
def webapps
@droplet.sandbox + 'webapps'
end
def web_inf_lib
@droplet.root + 'WEB-INF/lib'
end
def web_inf?
(@application.root + 'WEB-INF').exist?
end
end
end