Permalink
Browse files

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
  • Loading branch information...
1 parent 4a88557 commit 5c0207426627bb22884d3e1865336b3d021631d7 @nebhale nebhale committed Jan 13, 2014
@@ -4,6 +4,7 @@
<w>addons</w>
<w>appdynamics</w>
<w>argv</w>
+ <w>atpack</w>
<w>codeclimate</w>
<w>constantized</w>
<w>dhttp</w>
@@ -30,6 +31,7 @@
<w>pkill</w>
<w>progname</w>
<w>proto</w>
+ <w>ratpack</w>
<w>rbconfig</w>
<w>rdonly</w>
<w>readlink</w>
View
@@ -35,6 +35,7 @@ To learn how to configure various properties of the buildpack, follow the "Confi
* [Groovy](docs/container-groovy.md) ([Configuration](docs/container-groovy.md#configuration))
* [Java Main](docs/container-java_main.md) ([Configuration](docs/container-java_main.md#configuration))
* [Play Framework](docs/container-play_framework.md)
+ * [Ratpack](docs/container-ratpack.md)
* [Spring Boot CLI](docs/container-spring_boot_cli.md) ([Configuration](docs/container-spring_boot_cli.md#configuration))
* [Tomcat](docs/container-tomcat.md) ([Configuration](docs/container-tomcat.md#configuration))
* Standard Frameworks
View
@@ -19,6 +19,7 @@ containers:
- "JavaBuildpack::Container::Groovy"
- "JavaBuildpack::Container::JavaMain"
- "JavaBuildpack::Container::PlayFramework"
+ - "JavaBuildpack::Container::Ratpack"
- "JavaBuildpack::Container::SpringBootCLI"
- "JavaBuildpack::Container::Tomcat"
View
@@ -0,0 +1,21 @@
+# Ratpack Container
+The Ratpack Container allows [Ratpack][r] applications to be run.
+
+<table>
+ <tr>
+ <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>
+ </tr>
+ <tr>
+ <td><strong>Tags</strong></td>
+ <td><tt>ratpack=&lt;version&gt;</tt></td>
+ </tr>
+</table>
+Tags are printed to standard output by the buildpack detect script
+
+The container expects to run the application creating by running [`gradle distZip`][d] in an application built with the Ratpack Gradle plugin.
+
+## Configuration
+The Ratpack Container cannot be configured.
+
+[d]: http://www.ratpack.io/manual/current/setup.html#using_the_gradle_plugins
+[r]: http://www.ratpack.io
@@ -19,6 +19,7 @@
require 'java_buildpack/util/class_file_utils'
require 'java_buildpack/util/groovy_utils'
require 'java_buildpack/util/qualify_path'
+require 'java_buildpack/util/ratpack_utils'
require 'pathname'
require 'set'
require 'tmpdir'
@@ -60,7 +61,8 @@ def release
# @macro versioned_dependency_component_supports
def supports?
- JavaBuildpack::Util::ClassFileUtils.class_files(@application).empty? && main_groovy
+ JavaBuildpack::Util::ClassFileUtils.class_files(@application).empty? && main_groovy &&
+ !JavaBuildpack::Util::RatpackUtils.is?(@application)
end
private
@@ -0,0 +1,77 @@
+# 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 'java_buildpack/component/base_component'
+require 'java_buildpack/container'
+require 'java_buildpack/util/dash_case'
+require 'java_buildpack/util/ratpack_utils'
+
+module JavaBuildpack::Container
+
+ # Encapsulates the detect, compile, and release functionality for Ratpack applications.
+ class Ratpack < JavaBuildpack::Component::BaseComponent
+
+ def initialize(context)
+ super(context)
+ end
+
+ def detect
+ JavaBuildpack::Util::RatpackUtils.is?(@application) ? id(version) : nil
+ end
+
+ def compile
+ @droplet.additional_libraries.link_to lib_dir
+ end
+
+ def release
+ @droplet.java_opts.add_system_property 'ratpack.port', '$PORT'
+
+ [
+ @droplet.java_home.as_env_var,
+ @droplet.java_opts.as_env_var,
+ "$PWD/#{start_script.relative_path_from(@application.root)}"
+ ].flatten.compact.join(' ')
+ end
+
+ private
+
+ RATPACK_CORE_FILE_PATTERN = 'lib/ratpack-core-*.jar'.freeze
+
+ def id(version)
+ "#{Ratpack.to_s.dash_case}=#{version}"
+ end
+
+ def lib_dir
+ root + 'lib'
+ end
+
+ def root
+ roots = (@droplet.root + '*').glob.select { |child| child.directory? }
+ roots.size == 1 ? roots.first : @droplet.root
+ end
+
+ def start_script
+ candidates = (root + 'bin/*').glob
+ candidates.size == 1 ? candidates.first : candidates.find { |candidate| Pathname.new("#{candidate}.bat").exist? }
+ end
+
+ def version
+ (root + RATPACK_CORE_FILE_PATTERN).glob.first.to_s.match(/.*ratpack-core-(.*)\.jar/)[1]
+ end
+
+ end
+
+end
@@ -16,6 +16,6 @@
require 'java_buildpack/util'
-# A module encapsulating all of the utility components for Play application
+# A module encapsulating all of the utility components for Play Framework applications
module JavaBuildpack::Util::Play
end
@@ -22,17 +22,17 @@
module JavaBuildpack::Util::Play
- # A factory for creating a version-appropriate play application delegate
+ # A factory for creating a version-appropriate Play Framework application delegate
class Factory
private_class_method :new
class << self
- # Creates a Play application based on the given application directory.
+ # Creates a Play Framework application based on the given application directory.
#
# @param [JavaBuildpack::Component::Droplet] droplet the droplet
- # @return [JavaBuildpack::Util::Play::Base] the play application delegate
+ # @return [JavaBuildpack::Util::Play::Base] the Plat Framework application delegate
def create(droplet)
candidates = [
Post22Dist.new(droplet),
@@ -41,7 +41,7 @@ def create(droplet)
Pre22Staged.new(droplet)
].select { |candidate| candidate.supports? }
- fail "Play application version cannot be determined: #{candidates}" if candidates.size > 1
+ fail "Play Framework application version cannot be determined: #{candidates}" if candidates.size > 1
candidates.empty? ? nil : candidates.first
end
@@ -0,0 +1,45 @@
+# 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 'pathname'
+require 'java_buildpack/util'
+
+module JavaBuildpack::Util
+
+ # Utilities for dealing with Ratpack applications
+ class RatpackUtils
+
+ private_class_method :new
+
+ class << self
+
+ # Indicates whether a application is a Ratpack application
+ #
+ # @param [Application] application the application to search
+ # @return [Boolean] +true+ if the application is a Ratpack application, +false+ otherwise
+ def is?(application)
+ (application.root + RATPACK_FILE_PATTERN).glob.any?
+ end
+
+ private
+
+ RATPACK_FILE_PATTERN = '**/app/{R,r}atpack.groovy'.freeze
+
+ end
+
+ end
+
+end
@@ -51,6 +51,12 @@
expect(component.detect).to be_nil
end
+ it 'should not detect a Groovy file from Ratpack',
+ app_fixture: 'container_groovy_ratpack' do
+
+ expect(component.detect).to be_nil
+ end
+
it 'should detect a Groovy file with #!',
app_fixture: 'container_groovy_shebang' do
@@ -0,0 +1,67 @@
+# 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 'spec_helper'
+require 'component_helper'
+require 'java_buildpack/container/ratpack'
+
+describe JavaBuildpack::Container::Ratpack do
+ include_context 'component_helper'
+
+ it 'should detect a dist Ratpack application',
+ app_fixture: 'container_ratpack_dist' do
+
+ expect(component.detect).to eq('ratpack=0.9.0')
+ end
+
+ it 'should detect a staged Ratpack application',
+ app_fixture: 'container_ratpack_staged' do
+
+ expect(component.detect).to eq('ratpack=0.9.0')
+ end
+
+ it 'should not detect a non-Ratpack application',
+ app_fixture: 'container_main' do
+
+ expect(component.detect).to be_nil
+ end
+
+ it 'should link classpath JARs',
+ app_fixture: 'container_ratpack_staged' do
+
+ component.compile
+
+ lib = app_dir + 'lib'
+
+ jar_1 = lib + 'test-jar-1.jar'
+ expect(jar_1).to exist
+ expect(jar_1).to be_symlink
+ expect(jar_1.readlink).to eq((additional_libs_directory + 'test-jar-1.jar').relative_path_from(lib))
+
+ jar_2 = lib + 'test-jar-2.jar'
+ expect(jar_2).to exist
+ expect(jar_2).to be_symlink
+ expect(jar_2.readlink).to eq((additional_libs_directory + 'test-jar-2.jar').relative_path_from(lib))
+ end
+
+ it 'should return command',
+ app_fixture: 'container_ratpack_staged' do
+
+ expect(component.release).to eq("#{java_home.as_env_var} JAVA_OPTS=\"-Dratpack.port=$PORT test-opt-1 test-opt-2\" " +
+ '$PWD/bin/application')
+ end
+
+end
@@ -46,7 +46,7 @@
it 'should fail to create an application which is a hybrid of Play 2.1 and 2.2',
app_fixture: 'container_play_2.1_2.2_hybrid' do
- expect { trigger }.to raise_error(/Play application version cannot be determined/)
+ expect { trigger }.to raise_error(/Play Framework application version cannot be determined/)
end
end
@@ -0,0 +1,42 @@
+# Encoding: utf-8
+# Cloud Foundry Java Buildpack
+# Copyright (c) 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 'spec_helper'
+require 'application_helper'
+require 'java_buildpack/util/ratpack_utils'
+
+describe JavaBuildpack::Util::RatpackUtils do
+ include_context 'application_helper'
+
+ it 'should detect a dist Ratpack application',
+ app_fixture: 'container_ratpack_dist' do
+
+ expect(described_class.is?(application)).to be
+ end
+
+ it 'should detect a staged Ratpack application',
+ app_fixture: 'container_ratpack_staged' do
+
+ expect(described_class.is?(application)).to be
+ end
+
+ it 'should not detect a non-Ratpack application ',
+ app_fixture: 'container_main' do
+
+ expect(described_class.is?(application)).not_to be
+ end
+
+end

0 comments on commit 5c02074

Please sign in to comment.