Skip to content

Commit

Permalink
Merge 69332450-dist-zip to master
Browse files Browse the repository at this point in the history
[Completes #69332450]
  • Loading branch information
nebhale committed Apr 11, 2014
2 parents 2960ba2 + 037675d commit 7a285f4
Show file tree
Hide file tree
Showing 34 changed files with 607 additions and 169 deletions.
2 changes: 2 additions & 0 deletions .idea/dictionaries/bhale.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ To learn how to configure various properties of the buildpack, follow the "Confi
* [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](docs/container-spring_boot.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
Expand Down
1 change: 1 addition & 0 deletions config/components.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ containers:
- "JavaBuildpack::Container::JavaMain"
- "JavaBuildpack::Container::PlayFramework"
- "JavaBuildpack::Container::Ratpack"
- "JavaBuildpack::Container::SpringBoot"
- "JavaBuildpack::Container::SpringBootCLI"
- "JavaBuildpack::Container::Tomcat"

Expand Down
3 changes: 1 addition & 2 deletions docs/container-dist_zip.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ The Dist Zip Container allows applications packaged in [`distZip`-style][] to be
<td><strong>Detection Criteria</strong></td>
<td><ul>
<li>A start script in the <tt>bin/</tt> subdirectory of the application directory or one of its immediate subdirectories (but not in both), and</li>
<li>A JAR file in the <tt>lib/</tt> subdirectory of the application directory or one of its immediate subdirectories (but not in both), and</li>
<li>Not a Play Framework application</li>
<li>A JAR file in the <tt>lib/</tt> subdirectory of the application directory or one of its immediate subdirectories (but not in both)</li>
</ul></td>
</tr>
<tr>
Expand Down
5 changes: 3 additions & 2 deletions docs/container-ratpack.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
# Ratpack Container
The Ratpack Container allows [Ratpack][r] applications to be run.
The Ratpack Container allows [Ratpack][r] applications, packaged `distZip`-style 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>
<td><strong>Detection Criteria</strong></td>
<td>The <tt>lib/ratpack-core-.*.jar</tt> file exists in either the top-level directory or an immediate subdirectory of the application.</td>
</tr>
<tr>
<td><strong>Tags</strong></td>
Expand Down
22 changes: 22 additions & 0 deletions docs/container-spring_boot.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Spring Boot Container
The Spring Boot Container allows [Spring Boot][s] applications, packaged `distZip`-style to be run. **Note** All styles of Sping Boot can be run (e.g. self-executable JAR, WAR file, `distZip`-style). This is just explicit support for the `distZip` style.

<table>
<tr>
<td><strong>Detection Criteria</strong></td>
<td>The <tt>lib/spring-boot-.*.jar</tt> 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>spring-boot=&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 Spring Boot Gradle plugin.

## Configuration
The Spring Boot Container cannot be configured.

[d]: http://docs.spring.io/spring-boot/docs/1.0.1.RELEASE/reference/htmlsingle/#using-boot-gradle
[s]: http://projects.spring.io/spring-boot/
88 changes: 16 additions & 72 deletions lib/java_buildpack/container/dist_zip.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,75 +14,38 @@
# 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/container/dist_zip_like'
require 'java_buildpack/util/dash_case'
require 'java_buildpack/util/find_single_directory'
require 'java_buildpack/util/play/factory'
require 'java_buildpack/util/qualify_path'
require 'java_buildpack/util/start_script'
require 'java_buildpack/util/ratpack_utils'
require 'java_buildpack/util/spring_boot_utils'

module JavaBuildpack
module Container

# Encapsulates the detect, compile, and release functionality for +distZip+ style applications.
class DistZip < JavaBuildpack::Component::BaseComponent
include JavaBuildpack::Util
class DistZip < JavaBuildpack::Container::DistZipLike

# Creates an instance
#
# @param [Hash] context a collection of utilities used the component
def initialize(context)
super(context)
end

# (see JavaBuildpack::Component::BaseComponent#detect)
def detect
supports? ? DistZip.to_s.dash_case : nil
end
protected

# (see JavaBuildpack::Component::BaseComponent#compile)
def compile
start_script.chmod 0755
augment_classpath
# (see JavaBuildpack::Container::DistZipLike#id)
def id
DistZip.to_s.dash_case
end

# (see JavaBuildpack::Component::BaseComponent#release)
def release
[
@droplet.java_home.as_env_var,
@droplet.java_opts.as_env_var,
'SERVER_PORT=$PORT',
qualify_path(start_script, @droplet.root)
].flatten.compact.join(' ')
# (see JavaBuildpack::Container::DistZipLike#supports?)
def supports?
start_script(root) &&
start_script(root).exist? &&
jars? &&
!JavaBuildpack::Util::RatpackUtils.is?(@application) &&
!JavaBuildpack::Util::SpringBootUtils.is?(@application) &&
!JavaBuildpack::Util::Play::Factory.create(@droplet)
end

private

PATTERN_APP_CLASSPATH = /^declare -r app_classpath=\"(.*)\"$/

PATTERN_CLASSPATH = /^CLASSPATH=(.*)$/.freeze

def augment_classpath
content = start_script.read

if content =~ PATTERN_CLASSPATH
additional_classpath = @droplet.additional_libraries.sort.map do |additional_library|
"$APP_HOME/#{additional_library.relative_path_from(root)}"
end

update_file start_script, content,
PATTERN_CLASSPATH, "CLASSPATH=#{additional_classpath.join(':')}:\\1"
elsif content =~ PATTERN_APP_CLASSPATH
additional_classpath = @droplet.additional_libraries.sort.map do |additional_library|
"$app_home/#{additional_library.relative_path_from(start_script.dirname)}"
end

update_file start_script, content,
PATTERN_APP_CLASSPATH, "declare -r app_classpath=\"#{additional_classpath.join(':')}:\\1\""
end
end

def jars?
(lib_dir + '*.jar').glob.any?
end
Expand All @@ -91,25 +54,6 @@ def lib_dir
root + 'lib'
end

def root
find_single_directory || @droplet.root
end

def start_script
JavaBuildpack::Util.start_script root
end

def supports?
start_script && start_script.exist? && jars? && !JavaBuildpack::Util::Play::Factory.create(@droplet)
end

def update_file(path, content, pattern, replacement)
path.open('w') do |f|
f.write content.gsub pattern, replacement
f.fsync
end
end

end

end
Expand Down
119 changes: 119 additions & 0 deletions lib/java_buildpack/container/dist_zip_like.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
# 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/find_single_directory'
require 'java_buildpack/util/qualify_path'
require 'java_buildpack/util/start_script'

module JavaBuildpack
module Container

# Encapsulates the detect, compile, and release functionality for selecting a `distZip`-like container.
class DistZipLike < JavaBuildpack::Component::BaseComponent
include JavaBuildpack::Util

# (see JavaBuildpack::Component::BaseComponent#detect)
def detect
supports? ? id : nil
end

# (see JavaBuildpack::Component::BaseComponent#compile)
def compile
start_script(root).chmod 0755
augment_classpath_content
end

# (see JavaBuildpack::Component::BaseComponent#release)
def release
[
@droplet.java_home.as_env_var,
@droplet.java_opts.as_env_var,
qualify_path(start_script(root), @droplet.root)
].flatten.compact.join(' ')
end

protected

# The id of this container
#
# @return [String] the id of this container
def id
fail "Method 'id' must be defined"
end

# The root directory of the application
#
# @return [Pathname] the root directory of the application
def root
find_single_directory || @droplet.root
end

# Whether or not this component supports this application
#
# @return [Boolean] whether or not this component supports this application
def supports?
fail "Method 'supports?' must be defined"
end

private

PATTERN_APP_CLASSPATH = /^declare -r app_classpath=\"(.*)\"$/

PATTERN_CLASSPATH = /^CLASSPATH=(.*)$/.freeze

private_constant :PATTERN_APP_CLASSPATH, :PATTERN_CLASSPATH

def augment_app_classpath(content)
additional_classpath = @droplet.additional_libraries.sort.map do |additional_library|
"$app_home/#{additional_library.relative_path_from(start_script(root).dirname)}"
end

update_file start_script(root), content,
PATTERN_APP_CLASSPATH, "declare -r app_classpath=\"#{additional_classpath.join(':')}:\\1\""
end

def augment_classpath(content)
additional_classpath = @droplet.additional_libraries.sort.map do |additional_library|
"$APP_HOME/#{additional_library.relative_path_from(root)}"
end

update_file start_script(root), content,
PATTERN_CLASSPATH, "CLASSPATH=#{additional_classpath.join(':')}:\\1"
end

def augment_classpath_content
content = start_script(root).read

if content =~ PATTERN_CLASSPATH
augment_classpath content
elsif content =~ PATTERN_APP_CLASSPATH
augment_app_classpath content
end
end

def update_file(path, content, pattern, replacement)
path.open('w') do |f|
f.write content.gsub pattern, replacement
f.fsync
end
end

end

end
end
52 changes: 10 additions & 42 deletions lib/java_buildpack/container/ratpack.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,65 +14,33 @@
# 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/container/dist_zip_like'
require 'java_buildpack/util/dash_case'
require 'java_buildpack/util/ratpack_utils'
require 'java_buildpack/util/start_script'

module JavaBuildpack
module Container

# Encapsulates the detect, compile, and release functionality for Ratpack applications.
class Ratpack < JavaBuildpack::Component::BaseComponent
include JavaBuildpack::Util
class Ratpack < JavaBuildpack::Container::DistZipLike

def initialize(context)
super(context)
end

# (see JavaBuildpack::Component::BaseComponent#detect)
def detect
JavaBuildpack::Util::RatpackUtils.is?(@application) ? id(version) : nil
end

# (see JavaBuildpack::Component::BaseComponent#compile)
def compile
@droplet.additional_libraries.link_to lib_dir
end

# (see JavaBuildpack::Component::BaseComponent#release)
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(root).relative_path_from(@application.root)}"
].flatten.compact.join(' ')
end

private

RATPACK_CORE_FILE_PATTERN = 'lib/ratpack-core-*.jar'.freeze
protected

private_constant :RATPACK_CORE_FILE_PATTERN

def id(version)
# (see JavaBuildpack::Container::DistZipLike#id)
def id
"#{Ratpack.to_s.dash_case}=#{version}"
end

def lib_dir
root + 'lib'
# (see JavaBuildpack::Container::DistZipLike#supports?)
def supports?
JavaBuildpack::Util::RatpackUtils.is? @application
end

def root
roots = (@droplet.root + '*').glob.select { |child| child.directory? }
roots.size == 1 ? roots.first : @droplet.root
end
private

def version
(root + RATPACK_CORE_FILE_PATTERN).glob.first.to_s.match(/.*ratpack-core-(.*)\.jar/)[1]
JavaBuildpack::Util::RatpackUtils.version @application
end

end
Expand Down
Loading

0 comments on commit 7a285f4

Please sign in to comment.