Skip to content

Commit 24e8397

Browse files
committed
Modify web.xml for auto-reconfiguration
Previously, the auto-reconfiguration JAR was simply copied into the additional lib directory for any application that had Spring in it. This did not actually enable any of the auto-reconfiguration functionality. This change causes the auto-reconfiguration framework to modify a /WEB-INF/web.xml file if it exists in the application. The modifications made by the framework are detailed in the documentation for it. [#49695353]
1 parent 493448f commit 24e8397

40 files changed

+627
-56
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,9 @@ The buildpack supports configuration and extension through the use of Git reposi
2424
* Standard Containers
2525
* [Java Main Class](docs/container-java-main.md) ([Configuration](docs/container-java-main.md#configuration))
2626
* [Play](docs/container-play.md)
27-
* [Tomcat](docs/container-tomcat.md) ([Configuration](docs/container-tomcat.md))
27+
* [Tomcat](docs/container-tomcat.md) ([Configuration](docs/container-tomcat.md#configuration))
2828
* Standard Frameworks
29+
* [Auto Reconfiguration](docs/framework-auto-reconfiguration.md) ([Configuration](docs/framework-auto-reconfiguration.md#configuration))
2930
* [`JAVA_OPTS`](docs/framework-java_opts.md) ([Configuration](docs/framework-java_opts.md#configuration))
3031
* Standard JREs
3132
* [OpenJDK](docs/jre-openjdk.md) ([Configuration](docs/jre-openjdk.md#configuration))

config/components.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,4 @@ jres:
2323
- "JavaBuildpack::Jre::OpenJdk"
2424
frameworks:
2525
- "JavaBuildpack::Framework::JavaOpts"
26-
- "JavaBuildpack::Framework::SpringAutoReconfiguration"
26+
- "JavaBuildpack::Framework::AutoReconfiguration"

docs/container-tomcat.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ The Tomcat Container allows web application to be run. These applications are r
66
<td><strong>Detection Criterion</strong></td><td>Existence of a <tt>WEB-INF/</tt> folder in the application directory</td>
77
</tr>
88
<tr>
9-
<td><strong>Tags</strong></td><td><tt>tomcat-&lang;version&rang;</tt></td>
9+
<td><strong>Tags</strong></td><td><tt>tomcat-&lang;version&rang;</tt>, <tt>tomcat-buildpack-support-&lang;version&rang;</tt></td>
1010
</tr>
1111
</table>
1212
Tags are printed to standard output by the buildpack detect script
13-
13+
1414

1515
## Configuration
1616
The container can be configured by modifying the [`config/tomcat.yml`][tomcat_yml] file. The container uses the [`Repository` utility support][util_repositories] and so it supports the [version syntax][version_syntax] defined there.

docs/extending-containers.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,15 @@ To add a container, the class file must be located in [`lib/java_buildpack/conta
1111
# @option context [String] :app_dir the directory that the application exists in
1212
# @option context [String] :java_home the directory that acts as +JAVA_HOME+
1313
# @option context [Array<String>] :java_opts an array that Java options can be added to
14+
# @option context [String] :lib_directory the directory that additional libraries are placed in
1415
# @option context [Hash] :configuration the configuration provided by the user
1516
def initialize(context)
1617

1718
# Determines if the container can be used to run the application.
1819
#
19-
# @return [String, nil] If the container can be used to run the application, a +String+ that uniquely identifies the
20-
# container (e.g. +tomcat-7.0.29+). Otherwise, +nil+.
20+
# @return [Array<String>, String, nil] If the container can be used to run the application, a +String+ or an
21+
# +Array<String>+ that uniquely identifies the container (e.g.
22+
# +tomcat-7.0.29+). Otherwise, +nil+.
2123
def detect
2224

2325
# Downloads and unpacks the container. The container is expected to transform the application in whatever way

docs/extending-frameworks.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,17 @@ To add a framework, the class file must be located in [`lib/java_buildpack/frame
99
#
1010
# @param [Hash<Symbol, String>] context A shared context provided to all components
1111
# @option context [String] :app_dir the directory that the application exists in
12+
# @option context [String] :java_home the directory that acts as +JAVA_HOME+
1213
# @option context [Array<String>] :java_opts an array that Java options can be added to
14+
# @option context [String] :lib_directory the directory that additional libraries are placed in
1315
# @option context [Hash] :configuration the configuration provided by the user
1416
def initialize(context)
1517

1618
# Determines if the framework can be applied to the application
1719
#
18-
# @return [String, nil] If the framework can be used to run the application, a +String+ that uniquely identifies the
19-
# framework (e.g. +java-opts+). Otherwise, +nil+.
20+
# @return [Array<String>, String, nil] If the framework can be used to run the application, a +String+ or an
21+
# +Array<String>+ that uniquely identifies the framework (e.g. +java-opts+).
22+
# Otherwise, +nil+.
2023
def detect
2124

2225
# Transforms the application based on the framework. Status output written to +STDOUT+ is expected as part of this

docs/extending-jres.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,14 @@ To add a JRE, the class file must be located in [`lib/java_buildpack/jre`][jre_d
1111
# @option context [String] :app_dir the directory that the application exists in
1212
# @option context [String] :java_home the directory that acts as +JAVA_HOME+
1313
# @option context [Array<String>] :java_opts an array that Java options can be added to
14+
# @option context [String] :lib_directory the directory that additional libraries are placed in
1415
# @option context [Hash] :configuration the configuration provided by the user
1516
def initialize(context)
1617

1718
# Determines if the JRE can be used to run the application.
1819
#
19-
# @return [String, nil] If the JRE can be used to run the application, a +String+ that uniquely identifies the JRE
20-
# (e.g. +openjdk-1.7.0_21+). Otherwise, +nil+.
20+
# @return [Array<String>, String, nil] If the JRE can be used to run the application, a +String+ or an +Array<String>+
21+
# that uniquely identifies the JRE (e.g. +openjdk-1.7.0_21+). Otherwise, +nil+.
2122
def detect
2223

2324
# Downloads and unpacks the JRE. Status output written to +STDOUT+ is expected as part of this invocation.
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Auto Reconfiguration Framework
2+
The Auto Reconfiguration Framework causes an application to be automatically reconfigured to work with configured cloud services.
3+
4+
<table>
5+
<tr>
6+
<td><strong>Detection Criterion</strong></td><td>Existence of a <tt>spring-core*.jar</tt> file in the application directory</td>
7+
</tr>
8+
<tr>
9+
<td><strong>Tags</strong></td><td><tt>auto-reconfiguration-&lt;version&gt;</tt></td>
10+
</tr>
11+
</table>
12+
Tags are printed to standard output by the buildpack detect script
13+
14+
If a `/WEB-INF/web.xml` file exists, the framework will modify it in addition to making the auto reconfiguration JAR available on the classpath. These modifications include:
15+
16+
1. Augmenting `contextConfigLocation`. The function starts be enumerating the current `contextConfigLocation`s. If none exist, a default configuration is created with `/WEB-INF/application-context.xml` or `/WEB-INF/<servlet-name>-servlet.xml` as the default. An additional location is then added to the collection of locations; `classpath:META- INF/cloud/cloudfoundry-auto-reconfiguration-context.xml` if the `ApplicationContext` is XML-based, `org.cloudfoundry.reconfiguration.spring.web.CloudAppAnnotationConfigAutoReconfig` if the `ApplicationContext` is annotation-based.
17+
2. Augmenting `contextInitializerClasses`. The function starts by enumerating the current `contextInitializerClasses`. If none exist, a default configuration is created with no value as the default. The `org.cloudfoundry.reconfiguration.spring.CloudApplicationContextInitializer` class is then added to the collection of classes.
18+
19+
## Configuration
20+
The container can be configured by modifying the [`config/autoreconfiguration.yml`][autoreconfiguration_yml] file. The container uses the [`Repository` utility support][util_repositories] and so it supports the [version syntax][version_syntax] defined there.
21+
22+
[autoreconfiguration_yml]: ../config/autoreconfiguration.yml
23+
[util_repositories]: util-repositories.md
24+
[version_syntax]: util-repositories.md#version-syntax-and-ordering
25+
26+
| Name | Description
27+
| ---- | -----------
28+
| `repository_root` | The URL of the Auto Reconfiguration repository index ([details][util_repositories]).
29+
| `version` | The version of Auto Reconfiguration to use. Candidate versions can be found in [this listing][auto_reconfiguration_index_yml].
30+
31+
[auto_reconfiguration_index_yml]: http://download.pivotal.io.s3.amazonaws.com/auto-reconfiguration/lucid/x86_64/index.yml

docs/framework-java_opts.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ Tags are printed to standard output by the buildpack detect script
1313

1414

1515
## Configuration
16-
The framework can be configured by modifying the [`config/java_opts.yml`][java_opts_yml] file.
16+
The framework can be configured by modifying the [`config/javaopts.yml`][javaopts_yml] file.
1717

18-
[java_opts_yml]: ../config/java_opts.yml
18+
[javaopts_yml]: ../config/javaopts.yml
1919

2020
| Name | Description
2121
| ---- | -----------

lib/java_buildpack/container/tomcat.rb

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ def initialize(context)
4848
# @return [String] returns +tomcat-<version>+ if and only if the application has a +WEB-INF+ directory, otherwise
4949
# returns +nil+
5050
def detect
51-
@tomcat_version ? id(@tomcat_version) : nil
51+
@tomcat_version ? [tomcat_id(@tomcat_version), tomcat_support_id(@support_version)] : nil
5252
end
5353

5454
# Downloads and unpacks a Tomcat instance and support JAR
@@ -106,7 +106,7 @@ def download_support
106106
print "-----> Downloading Buildpack Tomcat Support #{@support_version} from #{@support_uri} "
107107

108108
JavaBuildpack::Util::ApplicationCache.new.get(@support_uri) do |file| # TODO Use global cache #50175265
109-
system "cp #{file.path} #{File.join tomcat_home, 'lib', 'tomcat-buildpack-support.jar'}"
109+
system "cp #{file.path} #{File.join(tomcat_home, 'lib', support_jar_name(@support_version))}"
110110
puts "(#{(Time.now - download_start_time).duration})"
111111
end
112112
end
@@ -149,10 +149,14 @@ def self.find_support(app_dir, configuration)
149149
return version, uri
150150
end
151151

152-
def id(version)
152+
def tomcat_id(version)
153153
"tomcat-#{version}"
154154
end
155155

156+
def tomcat_support_id(version)
157+
"tomcat-buildpack-support-#{version}"
158+
end
159+
156160
def link_application
157161
system "rm -rf #{root}"
158162
system "mkdir -p #{webapps}"
@@ -172,6 +176,10 @@ def root
172176
File.join webapps, 'ROOT'
173177
end
174178

179+
def support_jar_name(version)
180+
"#{tomcat_support_id version}.jar"
181+
end
182+
175183
def tomcat_home
176184
File.join @app_dir, TOMCAT_HOME
177185
end

0 commit comments

Comments
 (0)