Skip to content

Commit 5c02074

Browse files
committed
Ratpack support
This change adds support for running Ratpack[1] applications. The Ratpack support is added as a container and will trigger on the existence of a app/{R,r}atpack.groovy configuration file. [1]: http://www.ratpack.io
1 parent 4a88557 commit 5c02074

19 files changed

Lines changed: 271 additions & 7 deletions

File tree

.idea/dictionaries/bhale.xml

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ To learn how to configure various properties of the buildpack, follow the "Confi
3535
* [Groovy](docs/container-groovy.md) ([Configuration](docs/container-groovy.md#configuration))
3636
* [Java Main](docs/container-java_main.md) ([Configuration](docs/container-java_main.md#configuration))
3737
* [Play Framework](docs/container-play_framework.md)
38+
* [Ratpack](docs/container-ratpack.md)
3839
* [Spring Boot CLI](docs/container-spring_boot_cli.md) ([Configuration](docs/container-spring_boot_cli.md#configuration))
3940
* [Tomcat](docs/container-tomcat.md) ([Configuration](docs/container-tomcat.md#configuration))
4041
* Standard Frameworks

config/components.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ containers:
1919
- "JavaBuildpack::Container::Groovy"
2020
- "JavaBuildpack::Container::JavaMain"
2121
- "JavaBuildpack::Container::PlayFramework"
22+
- "JavaBuildpack::Container::Ratpack"
2223
- "JavaBuildpack::Container::SpringBootCLI"
2324
- "JavaBuildpack::Container::Tomcat"
2425

docs/container-ratpack.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Ratpack Container
2+
The Ratpack Container allows [Ratpack][r] applications to be run.
3+
4+
<table>
5+
<tr>
6+
<td><strong>Detection Criteria</strong></td><td>The <tt>app/Ratpack.groovy</tt> or <tt>app/ratpack.groovy</tt> configuration file exists in either the top-level directory or an immediate subdirectory of the application.</td>
7+
</tr>
8+
<tr>
9+
<td><strong>Tags</strong></td>
10+
<td><tt>ratpack=&lt;version&gt;</tt></td>
11+
</tr>
12+
</table>
13+
Tags are printed to standard output by the buildpack detect script
14+
15+
The container expects to run the application creating by running [`gradle distZip`][d] in an application built with the Ratpack Gradle plugin.
16+
17+
## Configuration
18+
The Ratpack Container cannot be configured.
19+
20+
[d]: http://www.ratpack.io/manual/current/setup.html#using_the_gradle_plugins
21+
[r]: http://www.ratpack.io

lib/java_buildpack/container/groovy.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
require 'java_buildpack/util/class_file_utils'
2020
require 'java_buildpack/util/groovy_utils'
2121
require 'java_buildpack/util/qualify_path'
22+
require 'java_buildpack/util/ratpack_utils'
2223
require 'pathname'
2324
require 'set'
2425
require 'tmpdir'
@@ -60,7 +61,8 @@ def release
6061

6162
# @macro versioned_dependency_component_supports
6263
def supports?
63-
JavaBuildpack::Util::ClassFileUtils.class_files(@application).empty? && main_groovy
64+
JavaBuildpack::Util::ClassFileUtils.class_files(@application).empty? && main_groovy &&
65+
!JavaBuildpack::Util::RatpackUtils.is?(@application)
6466
end
6567

6668
private
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
# Encoding: utf-8
2+
# Cloud Foundry Java Buildpack
3+
# Copyright 2013 the original author or authors.
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
require 'java_buildpack/component/base_component'
18+
require 'java_buildpack/container'
19+
require 'java_buildpack/util/dash_case'
20+
require 'java_buildpack/util/ratpack_utils'
21+
22+
module JavaBuildpack::Container
23+
24+
# Encapsulates the detect, compile, and release functionality for Ratpack applications.
25+
class Ratpack < JavaBuildpack::Component::BaseComponent
26+
27+
def initialize(context)
28+
super(context)
29+
end
30+
31+
def detect
32+
JavaBuildpack::Util::RatpackUtils.is?(@application) ? id(version) : nil
33+
end
34+
35+
def compile
36+
@droplet.additional_libraries.link_to lib_dir
37+
end
38+
39+
def release
40+
@droplet.java_opts.add_system_property 'ratpack.port', '$PORT'
41+
42+
[
43+
@droplet.java_home.as_env_var,
44+
@droplet.java_opts.as_env_var,
45+
"$PWD/#{start_script.relative_path_from(@application.root)}"
46+
].flatten.compact.join(' ')
47+
end
48+
49+
private
50+
51+
RATPACK_CORE_FILE_PATTERN = 'lib/ratpack-core-*.jar'.freeze
52+
53+
def id(version)
54+
"#{Ratpack.to_s.dash_case}=#{version}"
55+
end
56+
57+
def lib_dir
58+
root + 'lib'
59+
end
60+
61+
def root
62+
roots = (@droplet.root + '*').glob.select { |child| child.directory? }
63+
roots.size == 1 ? roots.first : @droplet.root
64+
end
65+
66+
def start_script
67+
candidates = (root + 'bin/*').glob
68+
candidates.size == 1 ? candidates.first : candidates.find { |candidate| Pathname.new("#{candidate}.bat").exist? }
69+
end
70+
71+
def version
72+
(root + RATPACK_CORE_FILE_PATTERN).glob.first.to_s.match(/.*ratpack-core-(.*)\.jar/)[1]
73+
end
74+
75+
end
76+
77+
end

lib/java_buildpack/util/play.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,6 @@
1616

1717
require 'java_buildpack/util'
1818

19-
# A module encapsulating all of the utility components for Play application
19+
# A module encapsulating all of the utility components for Play Framework applications
2020
module JavaBuildpack::Util::Play
2121
end

lib/java_buildpack/util/play/factory.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,17 @@
2222

2323
module JavaBuildpack::Util::Play
2424

25-
# A factory for creating a version-appropriate play application delegate
25+
# A factory for creating a version-appropriate Play Framework application delegate
2626
class Factory
2727

2828
private_class_method :new
2929

3030
class << self
3131

32-
# Creates a Play application based on the given application directory.
32+
# Creates a Play Framework application based on the given application directory.
3333
#
3434
# @param [JavaBuildpack::Component::Droplet] droplet the droplet
35-
# @return [JavaBuildpack::Util::Play::Base] the play application delegate
35+
# @return [JavaBuildpack::Util::Play::Base] the Plat Framework application delegate
3636
def create(droplet)
3737
candidates = [
3838
Post22Dist.new(droplet),
@@ -41,7 +41,7 @@ def create(droplet)
4141
Pre22Staged.new(droplet)
4242
].select { |candidate| candidate.supports? }
4343

44-
fail "Play application version cannot be determined: #{candidates}" if candidates.size > 1
44+
fail "Play Framework application version cannot be determined: #{candidates}" if candidates.size > 1
4545
candidates.empty? ? nil : candidates.first
4646
end
4747

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# Encoding: utf-8
2+
# Cloud Foundry Java Buildpack
3+
# Copyright 2013 the original author or authors.
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
require 'pathname'
18+
require 'java_buildpack/util'
19+
20+
module JavaBuildpack::Util
21+
22+
# Utilities for dealing with Ratpack applications
23+
class RatpackUtils
24+
25+
private_class_method :new
26+
27+
class << self
28+
29+
# Indicates whether a application is a Ratpack application
30+
#
31+
# @param [Application] application the application to search
32+
# @return [Boolean] +true+ if the application is a Ratpack application, +false+ otherwise
33+
def is?(application)
34+
(application.root + RATPACK_FILE_PATTERN).glob.any?
35+
end
36+
37+
private
38+
39+
RATPACK_FILE_PATTERN = '**/app/{R,r}atpack.groovy'.freeze
40+
41+
end
42+
43+
end
44+
45+
end

spec/fixtures/container_groovy_ratpack/application-root/app/Ratpack.groovy

Whitespace-only changes.

0 commit comments

Comments
 (0)