Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Support Play 2.2

Refactor Play framework to encapsulate the application-specific pieces
in a "PlayApp" abstraction defined by the BasePlayApp class. This
class has two subclasses: PlayAppPost22 for Play 2.2 and upwards and
PlayAppPre22 for Play 2.1.x and earlier (actually no earlier than 2.0
since older versions are not supported).

PlayAppPre22 is further subclassed by PlayAppPre22Dist and
PlayAppPre22Staged to represent the differences between Play 2.0/2.1
dist and staged applications, respectively.

PlayAppFactory isolates the using code (the Play container and some
associated frameworks) from the concrete subclasses of BasePlayApp.

Play version parsing and the naming requirements for the Play JAR are
both tightened up.

Play 2.2 support consists of:

1. Looking for a different style of start script. The start script is
now present in the bin directory and named after the application.

2. Updating the classpath variable in the start script (for both dist
and staged apps, which are now identical in structure in Play 2.2).

3. Supporting Play 2.2 style Java options by pre-pending '-J' to each
Java option.

4. Avoiding incompatible minimum and maximum heap sizes. Play 2.2 sets
-Xms to a large value by default and when this exceeds our calculated
-Xmx the JVM fails to initialise. Since we do not normally specify
-Xms, we set this to a low value (currently 2M since 1M is
insufficient for the JVM to initialise), but note that we do this for
Play 2.2 only.

[#58432326]
  • Loading branch information...
commit 4db158aaf2c0ca2a1540c120b0d74381b42c47f0 1 parent 6548d1e
Glyn Normington glyn authored
Showing with 1,183 additions and 370 deletions.
  1. +1 −1  docs/container-play.md
  2. +0 −5 docs/util-other.md
  3. +9 −1 lib/java_buildpack/base_component.rb
  4. +12 −12 lib/java_buildpack/container/container_utils.rb
  5. +17 −66 lib/java_buildpack/container/play.rb
  6. +2 −2 lib/java_buildpack/framework/play_auto_reconfiguration.rb
  7. +7 −9 lib/java_buildpack/framework/play_jpa_plugin.rb
  8. +176 −0 lib/java_buildpack/util/base_play_app.rb
  9. +41 −0 lib/java_buildpack/util/library_utils.rb
  10. +40 −0 lib/java_buildpack/util/play_app_factory.rb
  11. +67 −0 lib/java_buildpack/util/play_app_post22.rb
  12. +53 −0 lib/java_buildpack/util/play_app_pre22.rb
  13. +61 −0 lib/java_buildpack/util/play_app_pre22_dist.rb
  14. +46 −0 lib/java_buildpack/util/play_app_pre22_staged.rb
  15. +0 −105 lib/java_buildpack/util/play_utils.rb
  16. 0  ...n_staged/staged/play_2.1.2.jar → container_play_2.0_dist/application_root/lib/play.play_2.9.1-2.0.jar}
  17. 0  ..._jpa_plugin_play20/staged/play_2.0.2.jar → container_play_2.0_dist/application_root/lib/some.test.jar}
  18. 0  spec/fixtures/{container_play_2.0 → container_play_2.0_dist}/application_root/start
  19. 0  ..._root/lib/play.play_2.1.2.jar → container_play_2.1_dist/application_root/lib/play.play_2.10-2.1.4.jar}
  20. 0  ...ontainer_play_staged/staged/play_0.0.jar → container_play_2.1_dist/application_root/lib/some.test.jar}
  21. 0  spec/fixtures/{container_play → container_play_2.1_dist}/application_root/start
  22. 0  ...0/application_root/lib/play.play_0.0-0.0.0.jar → container_play_2.1_staged/staged/play_2.10-2.1.4.jar}
  23. 0  ...er_play/application_root/lib/play.play_0.0-0.0.0.jar → container_play_2.1_staged/staged/some.test.jar}
  24. 0  spec/fixtures/{container_play_staged → container_play_2.1_staged}/start
  25. +4 −0 spec/fixtures/container_play_2.2/bin/play-application
  26. 0  spec/fixtures/container_play_2.2/bin/play-application.bat
  27. 0  spec/fixtures/container_play_2.2/lib/com.typesafe.play.play_2.10-2.2.0.jar
  28. 0  spec/fixtures/container_play_2.2/lib/some.test.jar
  29. 0  spec/fixtures/container_play_2.2_ambiguous_start_script/bin/application1
  30. 0  spec/fixtures/container_play_2.2_ambiguous_start_script/bin/application2
  31. 0  spec/fixtures/container_play_2.2_ambiguous_start_script/lib/com.typesafe.play.play_2.10-2.2.0.jar
  32. 0  spec/fixtures/container_play_2.2_minus_bat_file/bin/play-application
  33. 0  spec/fixtures/container_play_2.2_minus_bat_file/lib/com.typesafe.play.play_2.10-2.2.0.jar
  34. 0  spec/fixtures/framework_play_jpa_plugin_dist/application_root/lib/play.play_2.10-2.1.2.jar
  35. 0  spec/fixtures/framework_play_jpa_plugin_play20/staged/play.play_2.9.1-2.0.jar
  36. 0  spec/fixtures/framework_play_jpa_plugin_staged/staged/play_2.10-2.1.2.jar
  37. +27 −166 spec/java_buildpack/container/play_spec.rb
  38. +2 −2 spec/java_buildpack/framework/play_auto_reconfiguration_spec.rb
  39. +1 −1  spec/java_buildpack/framework/play_jpa_plugin_spec.rb
  40. +125 −0 spec/java_buildpack/util/base_play_app_spec.rb
  41. +47 −0 spec/java_buildpack/util/play_app_factory_spec.rb
  42. +127 −0 spec/java_buildpack/util/play_app_post22_spec.rb
  43. +159 −0 spec/java_buildpack/util/play_app_pre22_dist_spec.rb
  44. +50 −0 spec/java_buildpack/util/play_app_pre22_spec.rb
  45. +109 −0 spec/java_buildpack/util/play_app_pre22_staged_spec.rb
2  docs/container-play.md
View
@@ -3,7 +3,7 @@ The Play Container allows Play applications to be run.
<table>
<tr>
- <td><strong>Detection Criteria</strong></td><td>The files <tt>start</tt> and <tt>lib/play.play_*.jar</tt> (or <tt>staged/play_*.jar</tt>) exist in the application
+ <td><strong>Detection Criteria</strong></td><td>The Play start script and the Play runtime JAR exist in the appropriate subdirectories of the application
directory or one of its immediate subdirectories (but not in both)</td>
</tr>
<tr>
5 docs/util-other.md
View
@@ -1,13 +1,9 @@
# Other Utiltities
The buildpack provides a number of other utilities that may help in implementing components.
-
## [`JavaBuildpack::Util::GroovyUtils`][]
The `GroovyUtils` class provides a set of methods for finding groovy files and determing if they are of any special kind (e.g. they have a main method, they are a pogo, etc.).
-## [`JavaBuildpack::Util::PlayUtils`][]
-The `PlayUtils` class provides a set of methods for determing information about a Play Framework application.
-
## [`JavaBuildpack::Util::Properties`][]
The `Properties` class provides a Ruby class that can read in a Java properties file and acts as a `Hash` with that data.
@@ -17,7 +13,6 @@ The `ResourceUtils` class provides an abstract around the `resources` directory
## [`JavaBuildpack::Util::ServiceUtils`][]
The `ServiceUtils` class provides a set of methods for finding a given service in the `VCAP_SERVICES` payload.
-
[`JavaBuildpack::Util::GroovyUtils`]: ../lib/java_buildpack/util/groovy_utils.rb
[`JavaBuildpack::Util::PlayUtils`]: ../lib/java_buildpack/util/play_utils.rb
[`JavaBuildpack::Util::Properties`]: ../lib/java_buildpack/util/properties.rb
10 lib/java_buildpack/base_component.rb
View
@@ -16,6 +16,7 @@
require 'java_buildpack'
require 'java_buildpack/util/application_cache'
+require 'java_buildpack/util/library_utils'
require 'java_buildpack/util/shell'
module JavaBuildpack
@@ -69,7 +70,7 @@ def compile
# are expected to read the +context+ values and take them into account when creating the command.
#
# @return [void, String] components other than containers are not expected to return any value. Container
- # compoonents are expected to return the command required to run the application.
+ # components are expected to return the command required to run the application.
def release
fail "Method 'release' must be defined"
end
@@ -105,6 +106,13 @@ def download_jar(version, uri, jar_name, target_directory = @lib_directory, desc
download(version, uri, description) { |file| shell "cp #{file.path} #{File.join(target_directory, jar_name)}" }
end
+ # Returns the additional libraries.
+ #
+ # @param [Array<String>] the paths of JARs in the additional libraries directory
+ def additional_libraries
+ JavaBuildpack::Util::LibraryUtils.lib_jars @lib_directory
+ end
+
end
end
24 lib/java_buildpack/container/container_utils.rb
View
@@ -33,7 +33,7 @@ def self.to_java_opts_s(java_opts)
# Evaluates a value and if it is not +nil+ or empty, prepends it with a space. This can be used to create BASH
# command lines that do not have ugly extra spacing.
#
- # @param [String, nil] value the value to evalutate for extra spacing
+ # @param [String, nil] value the value to evaluate for extra spacing
# @return [String] an empty string if +value+ is +nil+ or empty, otherwise the value prepended with a space
def self.space(value)
value = value.to_s if value.respond_to?(:to_s)
@@ -47,18 +47,18 @@ def self.space(value)
# @param [String] lib_directory the directory that additional libraries are placed in
# @return [Array<String>] the relative paths of the JARs located in the additional libraries directory
def self.libs(root_dir, lib_directory)
- libs = []
-
- if lib_directory
- root_directory = Pathname.new(root_dir)
-
- libs = Pathname.new(lib_directory).children
- .select { |file| file.extname == '.jar' }
- .map { |file| file.relative_path_from(root_directory) }
- .sort
- end
+ relative_paths(root_dir, JavaBuildpack::Util::LibraryUtils.lib_jars(lib_directory))
+ end
- libs
+ # Returns an +Array+ containing the relative paths of the given files. The
+ # paths of these files are relative to the +root_dir+.
+ #
+ # @param [String] root_dir the directory relative to which the resultant are calculated
+ # @param [Array<String>] libs an array of file paths
+ # @return [Array<String>] the relative paths of the given file paths
+ def self.relative_paths(root_dir, libs)
+ root_directory = Pathname.new(root_dir)
+ libs.map { |lib| lib.relative_path_from(root_directory) }
end
end
83 lib/java_buildpack/container/play.rb
View
@@ -19,7 +19,7 @@
require 'java_buildpack/container/container_utils'
require 'java_buildpack/repository/configured_item'
require 'java_buildpack/util/application_cache'
-require 'java_buildpack/util/play_utils'
+require 'java_buildpack/util/play_app_factory'
require 'pathname'
module JavaBuildpack::Container
@@ -30,95 +30,46 @@ class Play < JavaBuildpack::BaseComponent
def initialize(context)
super('Play Framework', context)
- @play_root = JavaBuildpack::Util::PlayUtils.root(@app_dir)
- @version = @play_root ? JavaBuildpack::Util::PlayUtils.version(@play_root) : nil
+ @play_app = JavaBuildpack::Util::PlayAppFactory.create @app_dir
end
def detect
- @version ? id(@version) : nil
+ if @play_app
+ version = @play_app.version
+ version ? id(version) : nil
+ else
+ nil
+ end
end
def compile
- shell "chmod +x #{JavaBuildpack::Util::PlayUtils.start_script @play_root}"
- add_libs_to_classpath
- replace_bootstrap @play_root
+ @play_app.set_executable
+ @play_app.add_libs_to_classpath additional_libraries
+ @play_app.replace_bootstrap BOOTSTRAP_CLASS_NAME
end
def release
- @java_opts << "-D#{KEY_HTTP_PORT}=$PORT"
+ java_opts = @java_opts.clone
+ java_opts << "-D#{KEY_HTTP_PORT}=$PORT"
path_string = "PATH=#{File.join @java_home, 'bin'}:$PATH"
java_home_string = ContainerUtils.space("JAVA_HOME=#{@java_home}")
- start_script_string = ContainerUtils.space(start_script_relative @play_root)
- java_opts_string = ContainerUtils.space(ContainerUtils.to_java_opts_s(@java_opts))
+ start_script_string = ContainerUtils.space(@play_app.start_script_relative)
+ java_opts_string = ContainerUtils.space(ContainerUtils.to_java_opts_s(@play_app.decorate_java_opts java_opts))
"#{path_string}#{java_home_string}#{start_script_string}#{java_opts_string}"
end
private
- KEY_HTTP_PORT = 'http.port'.freeze
-
- def add_libs_to_classpath
- if JavaBuildpack::Util::PlayUtils.lib_play_jar @play_root
- add_libs_to_dist_classpath
- else
- add_libs_to_staged_classpath
- end
- end
-
- def add_libs_to_staged_classpath
- # Staged applications add all the JARs in the staged directory to the classpath, so add symbolic links to the staged directory.
- # Note: for staged applications, @app_dir = @play_root
- link_libs_to_classpath_directory(JavaBuildpack::Util::PlayUtils.staged @play_root)
- end
+ BOOTSTRAP_CLASS_NAME = 'org.cloudfoundry.reconfiguration.play.Bootstrap'.freeze
- def link_libs_to_classpath_directory(classpath_directory)
- ContainerUtils.libs(@play_root, @lib_directory).each do |lib|
- shell "ln -nsf ../#{lib} #{classpath_directory}"
- end
- end
-
- def add_libs_to_dist_classpath
- # Dist applications either list JARs in a classpath variable (e.g. in Play 2.1.3) or on a -cp parameter (e.g. in Play 2.0),
- # so add to the appropriate list.
- # Note: for dist applications, @play_root is an immediate subdirectory of @app_dir, so @app_dir is equivalent to @play_root/..
- script_dir_relative_path = Pathname.new(@app_dir).relative_path_from(Pathname.new(@play_root)).to_s
-
- additional_classpath = ContainerUtils.libs(@app_dir, @lib_directory).map do |lib|
- "$scriptdir/#{script_dir_relative_path}/#{lib}"
- end
-
- result = update_file JavaBuildpack::Util::PlayUtils.start_script(@play_root), /^classpath=\"(.*)\"$/, "classpath=\"#{additional_classpath.join(':')}:\\1\""
- unless result
- link_libs_to_classpath_directory(JavaBuildpack::Util::PlayUtils.lib @play_root)
- end
- end
+ KEY_HTTP_PORT = 'http.port'.freeze
def id(version)
"#{@parsable_component_name}=#{version}"
end
- def replace_bootstrap(root)
- update_file JavaBuildpack::Util::PlayUtils.start_script(root), /play\.core\.server\.NettyServer/, 'org.cloudfoundry.reconfiguration.play.Bootstrap'
- end
-
- def start_script_relative(play_root)
- "./#{Pathname.new(JavaBuildpack::Util::PlayUtils.start_script(play_root)).relative_path_from(Pathname.new(@app_dir)).to_s}"
- end
-
- def update_file(file_name, pattern, replacement)
- content = File.open(file_name, 'r') { |file| file.read }
- result = content.gsub! pattern, replacement
-
- File.open(file_name, 'w') do |file|
- file.write content
- file.fsync
- end
-
- result
- end
-
end
end
4 lib/java_buildpack/framework/play_auto_reconfiguration.rb
View
@@ -17,7 +17,7 @@
require 'java_buildpack/framework'
require 'java_buildpack/repository/configured_item'
require 'java_buildpack/util/application_cache'
-require 'java_buildpack/util/play_utils'
+require 'java_buildpack/util/play_app_factory'
require 'java_buildpack/versioned_dependency_component'
module JavaBuildpack::Framework
@@ -41,7 +41,7 @@ def release
protected
def supports?
- JavaBuildpack::Util::PlayUtils.root(@app_dir)
+ JavaBuildpack::Util::PlayAppFactory.create @app_dir
end
private
16 lib/java_buildpack/framework/play_jpa_plugin.rb
View
@@ -17,7 +17,7 @@
require 'java_buildpack/framework'
require 'java_buildpack/repository/configured_item'
require 'java_buildpack/util/application_cache'
-require 'java_buildpack/util/play_utils'
+require 'java_buildpack/util/play_app_factory'
require 'java_buildpack/versioned_dependency_component'
module JavaBuildpack::Framework
@@ -44,8 +44,8 @@ def release
def supports?
candidate = false
- root = JavaBuildpack::Util::PlayUtils.root @app_dir
- candidate = uses_jpa?(root) || play20?(root) if root
+ play_app = JavaBuildpack::Util::PlayAppFactory.create @app_dir
+ candidate = uses_jpa?(play_app) || play20?(play_app.version) if play_app
candidate
end
@@ -58,14 +58,12 @@ def jar_name
"#{id @version}.jar"
end
- def play20?(root)
- JavaBuildpack::Util::PlayUtils.version(root) =~ /2.0.[\d]+/
+ def play20?(play_version)
+ play_version =~ /^2\.0(\.[\d]+)?$/
end
- def uses_jpa?(root)
- lib = File.join JavaBuildpack::Util::PlayUtils.lib(root), PLAY_JPA_PLUGIN_JAR
- staged = File.join JavaBuildpack::Util::PlayUtils.staged(root), PLAY_JPA_PLUGIN_JAR
- Dir[lib, staged].first
+ def uses_jpa?(play_app)
+ play_app.contains? PLAY_JPA_PLUGIN_JAR
end
end
176 lib/java_buildpack/util/base_play_app.rb
View
@@ -0,0 +1,176 @@
+# 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 'java_buildpack/util'
+require 'java_buildpack/util/shell'
+
+module JavaBuildpack::Util
+
+ # Base class for Play application classes.
+ class BasePlayApp
+ include JavaBuildpack::Util::Shell
+
+ # Returns the version of this Play application
+ #
+ # @return [String, nil] the version of the Play application
+ attr_reader :version
+
+ # Determines whether the given application directory contains a Play application that this class recognizes.
+ #
+ # @param [String] app_dir the application directory
+ # @return [Boolean] +true+ if and only if this class recognizes a Play application
+ def self.recognizes?(app_dir)
+ find_root app_dir
+ end
+
+ # Creates a Play application based on the given application directory.
+ #
+ # @param [String] app_dir the application directory
+ def initialize(app_dir)
+ @app_dir = app_dir
+ end
+
+ # Ensures this Play application is executable.
+ def set_executable
+ shell "chmod +x #{start_script}"
+ end
+
+ # Replaces the bootstrap class of this Play application.
+ #
+ # @param [String] bootstrap_class the replacement bootstrap class name
+ def replace_bootstrap(bootstrap_class)
+ update_file start_script, /play\.core\.server\.NettyServer/, bootstrap_class
+ end
+
+ # Adds the given JARs to this Play application's classpath.
+ #
+ # @param [Array<String>] libs the JAR paths
+ def add_libs_to_classpath(libs)
+ fail "Method 'add_libs_to_classpath' must be defined"
+ end
+
+ # Returns the path of the Play start script relative to the application directory.
+ #
+ # @return [String] the path of the Play start script relative to the application directory
+ def start_script_relative
+ "./#{Pathname.new(start_script).relative_path_from(Pathname.new(@app_dir)).to_s}"
+ end
+
+ # Determines whether or not the Play application contains a JAR with the given, possibly wildcarded, name.
+ #
+ # @param [Object] jar_name a JAR name which may contain +*+ to match zero or more characters, e.g. +a*.jar+
+ # @return [Boolean] true if and only if at least one JAR was found matching the given name
+ def contains?(jar_name)
+ lib = File.join self.class.classpath_directory(play_root), jar_name
+ Dir[lib].first
+ end
+
+ # Decorates the given Java options as appropriate to the version of Play.
+ #
+ # @param [Array<String>] java_opts the Java options to be decorated
+ # @return [Array<String] the decorated Java options
+ def decorate_java_opts(java_opts)
+ java_opts
+ end
+
+ protected
+
+ # Finds the Play application root directory, in the given application directory, containing a start script
+ # and a Play JAR in the appropriate directory. Also finds the Play application version.
+ #
+ # @param [String] app_dir the application directory
+ # @return [String, nil] the Play application root directory or +nil+ if no such directory was found
+ # @return [String, nil] the Play application version or +nil+ if no version is available
+ def self.root_and_version(app_dir)
+ play_root = find_root(app_dir)
+ fail "Unrecognized Play application in #{app_dir}" unless play_root
+ version = version(classpath_directory_play_jar(play_root))
+ fail "Unrecognized Play application version in #{app_dir}" unless version
+ return play_root, version # rubocop:disable RedundantReturn
+ end
+
+ # The location of the directory containing the JARs of a Play application
+ #
+ # @param [String] root the root of the Play application
+ # @return [String] the path to the directory containing the JARs
+ def self.classpath_directory(root)
+ File.join root, 'lib'
+ end
+
+ # The version of the Play application, as derived from the version number embedded in the name of the +play_+ JAR.
+ #
+ # @param [String] play_jar the path to the play JAR
+ # @return [String, nil] the version of the Play application
+ def self.version(play_jar)
+ play_jar.match(/.*play_.*-(.*)\.jar/)[1]
+ end
+
+ # Returns the path of the start script.
+ #
+ # @return [String] the path of the start script
+ def start_script
+ self.class.start_script play_root
+ end
+
+ # Returns the path of the start script.
+ #
+ # @param [String] app_dir the application root
+ # @return [String] the path of the start script
+ def self.start_script(app_dir)
+ fail "Method 'start_script' must be defined"
+ end
+
+ private
+
+ PLAY_JAR = '*play_*-*.jar'.freeze
+
+ attr_reader :app_dir
+
+ def self.find_root(app_dir)
+ roots = Dir[app_dir, File.join(app_dir, '*')].select do |file|
+ start_script(file) && classpath_directory_play_jar(file)
+ end
+
+ fail "Play application detected in multiple directories: #{roots}" if roots.size > 1
+
+ roots.first
+ end
+
+ def self.play_jar(root)
+ Dir[File.join(root, PLAY_JAR)].first
+ end
+
+ def self.classpath_directory_play_jar(root)
+ play_jar(classpath_directory(root))
+ end
+
+ def update_file(file_name, pattern, replacement)
+ content = File.open(file_name, 'r') { |file| file.read }
+ result = content.gsub! pattern, replacement
+
+ File.open(file_name, 'w') do |file|
+ file.write content
+ file.fsync
+ end
+
+ result
+ end
+
+ attr_reader :play_root
+
+ end
+
+end
41 lib/java_buildpack/util/library_utils.rb
View
@@ -0,0 +1,41 @@
+# 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 'java_buildpack/util'
+
+module JavaBuildpack::Util
+
+ # Common utilities for manipulating libraries (i.e. JARs)
+ class LibraryUtils
+
+ # Returns an +Array+ containing the paths of the JARs located in the given directory.
+ #
+ # @param [String] lib_directory the directory containing zero or more JARs
+ # @return [Array<String>] the paths of the JARs located in the given directory
+ def self.lib_jars(lib_directory)
+ libs = []
+
+ if lib_directory
+ libs = Pathname.new(lib_directory).children
+ .select { |file| file.extname == '.jar' }
+ .sort
+ end
+
+ libs
+ end
+ end
+
+end
40 lib/java_buildpack/util/play_app_factory.rb
View
@@ -0,0 +1,40 @@
+# 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 'java_buildpack/util'
+require 'java_buildpack/util/play_app_pre22_dist'
+require 'java_buildpack/util/play_app_pre22_staged'
+require 'java_buildpack/util/play_app_post22'
+
+module JavaBuildpack::Util
+
+ # Create instances of PlayAppPre22.
+ class PlayAppFactory
+
+ # Creates a Play application based on the given application directory.
+ #
+ # @param [String] app_dir the application directory
+ def self.create(app_dir)
+ recognizers = [PlayAppPre22Staged, PlayAppPre22Dist, PlayAppPost22].select do |play_app_class|
+ play_app_class if play_app_class.recognizes? app_dir
+ end
+ fail "Play application in #{app_dir} is recognized by more than one Play application class: #{recognizers}" if recognizers.size > 1
+ recognizers.empty? ? nil : recognizers[0].new(app_dir)
+ end
+
+ end
+
+end
67 lib/java_buildpack/util/play_app_post22.rb
View
@@ -0,0 +1,67 @@
+# 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 'java_buildpack/container/container_utils'
+require 'java_buildpack/util'
+require 'java_buildpack/util/base_play_app'
+require 'java_buildpack/util/shell'
+
+module JavaBuildpack::Util
+
+ # Encapsulate inspection and modification of Play applications from Play 2.2.0 onwards.
+ class PlayAppPost22 < BasePlayApp
+
+ def initialize(app_dir)
+ super(app_dir)
+ @play_root, @version = self.class.root_and_version(app_dir)
+ end
+
+ def add_libs_to_classpath(libs)
+ script_dir_relative_path = Pathname.new(app_dir).relative_path_from(Pathname.new(File.join(@play_root, 'bin'))).to_s
+
+ additional_classpath = JavaBuildpack::Container::ContainerUtils.relative_paths(app_dir, libs).map do |lib|
+ "$app_home/#{script_dir_relative_path}/#{lib}"
+ end
+
+ update_file start_script, /^declare -r app_classpath=\"(.*)\"$/, "declare -r app_classpath=\"#{additional_classpath.join(':')}:\\1\""
+ end
+
+ def decorate_java_opts(java_opts)
+ decorated_java_opts = []
+ java_opts.each { |java_opt| decorated_java_opts << "-J#{java_opt}" }
+ decorated_java_opts << '-J-Xms2M'
+ end
+
+ private
+
+ def self.start_script(app_dir)
+ scripts = start_scripts app_dir
+ if scripts.size == 1
+ scripts[0]
+ else
+ scripts.find do |script|
+ File.exists?("#{script}.bat")
+ end
+ end
+ end
+
+ def self.start_scripts(app_dir)
+ Dir[File.join(app_dir, 'bin', '*')]
+ end
+
+ end
+
+end
53 lib/java_buildpack/util/play_app_pre22.rb
View
@@ -0,0 +1,53 @@
+# 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 'java_buildpack/container/container_utils'
+require 'java_buildpack/util'
+require 'java_buildpack/util/base_play_app'
+require 'java_buildpack/util/shell'
+
+module JavaBuildpack::Util
+
+ # Base class for inspection and modification of Play applications up to and including Play 2.1.x.
+ class PlayAppPre22 < BasePlayApp
+ include JavaBuildpack::Util::Shell
+
+ def initialize(app_dir)
+ super(app_dir)
+ end
+
+ protected
+
+ # Symbolically links to the given JARs from the classpath directory.
+ #
+ # @param [Array<String>] libs the JAR paths
+ def link_libs_from_classpath_dir(libs)
+ JavaBuildpack::Container::ContainerUtils.relative_paths(play_root, libs).each do |lib|
+ shell "ln -nsf ../#{lib} #{self.class.classpath_directory(play_root)}"
+ end
+ end
+
+ private
+
+ START_SCRIPT = 'start'.freeze
+
+ def self.start_script(root)
+ Dir[File.join(root, START_SCRIPT)].first
+ end
+
+ end
+
+end
61 lib/java_buildpack/util/play_app_pre22_dist.rb
View
@@ -0,0 +1,61 @@
+# 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 'java_buildpack/container/container_utils'
+require 'java_buildpack/util'
+require 'java_buildpack/util/play_app_pre22'
+
+module JavaBuildpack::Util
+
+ # Encapsulate inspection and modification of Play dist applications up to and including Play 2.1.x.
+ class PlayAppPre22Dist < PlayAppPre22
+
+ def initialize(app_dir)
+ super(app_dir)
+ @play_root, @version = self.class.root_and_version(app_dir)
+ end
+
+ def add_libs_to_classpath(libs)
+ # In Play 2.1.x dist applications, the start script contains a list of JARs which form the classpath. To add
+ # libraries to the classpath, the script is edited to extend the list of JARs.
+ #
+ # For Play Play 2.0.x dist applications, the start script builds a classpath dynamically
+ # from the set of JARs in the +lib+ directory. To add libraries to the classpath,
+ # the JARs are symbolically linked into the +lib+ directory.
+ add_libs_to_dist_classpath(libs)
+ end
+
+ private
+
+ def add_libs_to_dist_classpath(libs)
+ # Dist applications either list JARs in a classpath variable (e.g. in Play 2.1.3) or add all the JARs in the lib
+ # directory to the classpath using a -cp parameter (e.g. in Play 2.0).
+ script_dir_relative_path = Pathname.new(app_dir).relative_path_from(Pathname.new(@play_root)).to_s
+
+ additional_classpath = JavaBuildpack::Container::ContainerUtils.relative_paths(app_dir, libs).map do |lib|
+ "$scriptdir/#{script_dir_relative_path}/#{lib}"
+ end
+
+ result = update_file start_script, /^classpath=\"(.*)\"$/, "classpath=\"#{additional_classpath.join(':')}:\\1\""
+ unless result
+ # No classpath variable was found, so add symbolic links to the lib directory.
+ link_libs_from_classpath_dir(libs)
+ end
+ end
+
+ end
+
+end
46 lib/java_buildpack/util/play_app_pre22_staged.rb
View
@@ -0,0 +1,46 @@
+# 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 'java_buildpack/container/container_utils'
+require 'java_buildpack/util'
+require 'java_buildpack/util/play_app_pre22'
+
+module JavaBuildpack::Util
+
+ # Encapsulate inspection and modification of Play staged applications up to and including Play 2.1.x.
+ class PlayAppPre22Staged < PlayAppPre22
+
+ def initialize(app_dir)
+ super(app_dir)
+ @play_root, @version = self.class.root_and_version(app_dir)
+ end
+
+ def add_libs_to_classpath(libs)
+ # For Play 2.0 and 2.1.x staged applications, the start script builds a classpath dynamically
+ # from the set of JARs in the +staged+ directory. To add libraries to the classpath,
+ # the JARs are symbolically linked into the +staged+ directory.
+ link_libs_from_classpath_dir(libs)
+ end
+
+ private
+
+ def self.classpath_directory(root)
+ File.join root, 'staged'
+ end
+
+ end
+
+end
105 lib/java_buildpack/util/play_utils.rb
View
@@ -1,105 +0,0 @@
-# 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/util'
-
-module JavaBuildpack::Util
-
- # Utilities for dealing with Play Framework application
- class PlayUtils
-
- # Locate a Play application root directory in the given application directory.
- #
- # @param [String] app_dir the application directory
- # @return [Dir, nil] the located Play application directory or `nil` if there is no such
- # @raise if more than one Play application directory is located
- def self.root(app_dir)
-
- # A Play application may reside directly in the application directory or in a direct subdirectory of the
- # application directory.
- roots = Dir[app_dir, File.join(app_dir, '*')].select do |file|
- start_script(file) && (lib_play_jar(file) || staged_play_jar(file))
- end
-
- fail "Play application detected in multiple directories: #{roots}" if roots.size > 1
-
- roots.first
- end
-
- # The location of the start script in a Play application
- #
- # @param [String] root the root of the Play application
- # @return [String, nil] the path to the start script, or +nil+ if it does not exist
- def self.start_script(root)
- Dir[File.join(root, START_SCRIPT)].first
- end
-
- # The location of the lib directory in a dist Play application
- #
- # @param [String] root the root of the Play application
- # @return [String, nil] the path to the lib directory, or +nil+ if it does not exist
- def self.lib(root)
- File.join root, 'lib'
- end
-
- # The location of the play JAR in a dist Play application
- #
- # @param [String] root the root of the Play application
- # @return [String, nil] the path to the dist play JAR, or +nil+ if it does not exist
- def self.lib_play_jar(root)
- play_jar(lib(root))
- end
-
- # The location of the staged directory in a staged Play application
- #
- # @param [String] root the root of the Play application
- # @return [String, nil] the path to the staged directory, or +nil+ if it does not exist
- def self.staged(root)
- File.join root, 'staged'
- end
-
- # The location of the play JAR in a staged Play application
- #
- # @param [String] root the root of the Play application
- # @return [String, nil] the path to the staged play JAR, or +nil+ if it does not exist
- def self.staged_play_jar(root)
- play_jar(staged(root))
- end
-
- # The version of the Play application, as derived from the version number embedded in the name of the +play_+ JAR.
- #
- # @param [String] root the root of the Play application
- # @return [String, nil] the version of the Play application
- def self.version(root)
- play_jar = lib_play_jar(root) || staged_play_jar(root)
- play_jar.match(/.*play_(.*)\.jar/)[1]
- end
-
- private
-
- START_SCRIPT = 'start'.freeze
-
- PLAY_JAR = '*play_*.jar'.freeze
-
- def self.play_jar(root)
- Dir[File.join(root, PLAY_JAR)].first
- end
-
- private_class_method :new
-
- end
-
-end
0  ...work_play_jpa_plugin_staged/staged/play_2.1.2.jar → ...dist/application_root/lib/play.play_2.9.1-2.0.jar
View
File renamed without changes
0  ...work_play_jpa_plugin_play20/staged/play_2.0.2.jar → ..._play_2.0_dist/application_root/lib/some.test.jar
View
File renamed without changes
0  ...ixtures/container_play_2.0/application_root/start → ...es/container_play_2.0_dist/application_root/start
View
File renamed without changes
0  ...gin_dist/application_root/lib/play.play_2.1.2.jar → ...ist/application_root/lib/play.play_2.10-2.1.4.jar
View
File renamed without changes
0  ...ixtures/container_play_staged/staged/play_0.0.jar → ..._play_2.1_dist/application_root/lib/some.test.jar
View
File renamed without changes
0  spec/fixtures/container_play/application_root/start → ...es/container_play_2.1_dist/application_root/start
View
File renamed without changes
0  ..._2.0/application_root/lib/play.play_0.0-0.0.0.jar → ...tainer_play_2.1_staged/staged/play_2.10-2.1.4.jar
View
File renamed without changes
0  ...play/application_root/lib/play.play_0.0-0.0.0.jar → ...es/container_play_2.1_staged/staged/some.test.jar
View
File renamed without changes
0  spec/fixtures/container_play_staged/start → spec/fixtures/container_play_2.1_staged/start
View
File renamed without changes
4 spec/fixtures/container_play_2.2/bin/play-application
View
@@ -0,0 +1,4 @@
+
+declare -r app_mainclass="play.core.server.NettyServer"
+
+declare -r app_classpath="$lib_dir/some-dependency.jar"
0  spec/fixtures/container_play_2.2/bin/play-application.bat
View
No changes.
0  spec/fixtures/container_play_2.2/lib/com.typesafe.play.play_2.10-2.2.0.jar
View
No changes.
0  spec/fixtures/container_play_2.2/lib/some.test.jar
View
No changes.
0  spec/fixtures/container_play_2.2_ambiguous_start_script/bin/application1
View
No changes.
0  spec/fixtures/container_play_2.2_ambiguous_start_script/bin/application2
View
No changes.
0  spec/fixtures/container_play_2.2_ambiguous_start_script/lib/com.typesafe.play.play_2.10-2.2.0.jar
View
No changes.
0  spec/fixtures/container_play_2.2_minus_bat_file/bin/play-application
View
No changes.
0  spec/fixtures/container_play_2.2_minus_bat_file/lib/com.typesafe.play.play_2.10-2.2.0.jar
View
No changes.
0  spec/fixtures/framework_play_jpa_plugin_dist/application_root/lib/play.play_2.10-2.1.2.jar
View
No changes.
0  spec/fixtures/framework_play_jpa_plugin_play20/staged/play.play_2.9.1-2.0.jar
View
No changes.
0  spec/fixtures/framework_play_jpa_plugin_staged/staged/play_2.10-2.1.2.jar
View
No changes.
193 spec/java_buildpack/container/play_spec.rb
View
@@ -16,186 +16,47 @@
require 'spec_helper'
require 'java_buildpack/container/play'
+require 'java_buildpack/util/play_app_factory'
module JavaBuildpack::Container
- TEST_JAVA_HOME = 'test-java-home'
- TEST_JAVA_OPTS = ['test-java-opt']
- TEST_PLAY_APP = 'spec/fixtures/container_play'
-
describe Play do
- it 'should not detect an application without a start script' do
- detected = Play.new(
- app_dir: 'spec/fixtures/container_main',
- configuration: {}
- ).detect
-
- expect(detected).to be_nil
- end
-
- it 'should not detect an application with a start directory' do
- detected = Play.new(
- app_dir: 'spec/fixtures/container_play_invalid',
- configuration: {}
- ).detect
+ let(:play_instance) { double('PlayApp') }
- expect(detected).to be_nil
+ it 'should construct an instance using the PlayAppFactory' do
+ JavaBuildpack::Util::PlayAppFactory.stub(:create).with('test-app-dir').and_return(play_instance)
+ Play.new('app_dir' => 'test-app-dir')
end
- it 'should not detect an application which is too deeply nested in the application directory' do
- detected = Play.new(
- app_dir: 'spec/fixtures/container_play_too_deep',
- configuration: {}
- ).detect
-
- expect(detected).to be_nil
+ it 'should used nil returned by the PlayAppFactory to determine the version' do
+ JavaBuildpack::Util::PlayAppFactory.stub(:create).with('test-app-dir').and_return(nil)
+ play = Play.new('app_dir' => 'test-app-dir')
+ expect(play.detect).to be_nil
end
- it 'should fail if a Play application is in more than one directory' do
- expect do
- Play.new(
- app_dir: 'spec/fixtures/container_play_duplicate',
- configuration: {}
- )
- end.to raise_error(/multiple/)
+ it 'should use the PlayApp returned by the PlayAppFactory to determine the version' do
+ JavaBuildpack::Util::PlayAppFactory.stub(:create).with('test-app-dir').and_return(play_instance)
+ play_instance.should_receive(:version).and_return('test-version')
+ play = Play.new('app_dir' => 'test-app-dir')
+ expect(play.detect).to eq('play-framework=test-version')
end
- it 'should detect a dist application with a start script and a suitable Play JAR' do
- detected = Play.new(
- app_dir: 'spec/fixtures/container_play',
- configuration: {}
- ).detect
-
- expect(detected).to eq('play-framework=0.0-0.0.0')
+ it 'should use the PlayApp returned by the PlayAppFactory to perform compilation' do
+ JavaBuildpack::Util::PlayAppFactory.stub(:create).with('test-app-dir').and_return(play_instance)
+ play_instance.should_receive(:set_executable)
+ play_instance.should_receive(:add_libs_to_classpath)
+ play_instance.should_receive(:replace_bootstrap)
+ play = Play.new('app_dir' => 'test-app-dir')
+ play.compile
end
- it 'should detect a staged application with a start script and a suitable Play JAR' do
- detected = Play.new(
- app_dir: 'spec/fixtures/container_play_staged',
- configuration: {}
- ).detect
-
- expect(detected).to eq('play-framework=0.0')
- end
-
- it 'should not detect an application with a start script but no suitable Play JAR' do
- detected = Play.new(
- app_dir: 'spec/fixtures/container_play_like',
- configuration: {}
- ).detect
-
- expect(detected).to be_nil
- end
-
- it 'should make the start script executable in the compile step' do
- Dir.mktmpdir do |root|
- FileUtils.cp_r 'spec/fixtures/container_play/.', root
-
- play = Play.new(
- app_dir: root,
- configuration: {}
- )
-
- play.should_receive(:shell).with("chmod +x #{root}/application_root/start").and_return('')
-
- play.compile
- end
- end
-
- it 'should replace the server command in the start script' do
- Dir.mktmpdir do |root|
- start_script = File.join root, 'application_root', 'start'
- FileUtils.cp_r 'spec/fixtures/container_play/.', root
-
- Play.new(
- app_dir: root,
- configuration: {}
- ).compile
-
- actual = File.open(start_script, 'r') { |file| file.read }
-
- expect(actual).to_not match(/play.core.server.NettyServer/)
- expect(actual).to match(/org.cloudfoundry.reconfiguration.play.Bootstrap/)
- end
- end
-
- it 'should add additional libraries to classpath in (e.g. Play 2.1.3) dist application' do
- Dir.mktmpdir do |root|
- lib_directory = File.join root, '.lib'
- start_script = File.join root, 'application_root', 'start'
-
- FileUtils.cp_r 'spec/fixtures/container_play/.', root
- Dir.mkdir lib_directory
- FileUtils.cp 'spec/fixtures/additional_libs/test-jar-1.jar', lib_directory
-
- Play.new(
- app_dir: root,
- lib_directory: lib_directory,
- configuration: {}
- ).compile
-
- actual = File.open(start_script, 'r') { |file| file.read }
-
- expect(actual).to match(%r(classpath="\$scriptdir/.\./\.lib/test-jar-1\.jar:))
- end
- end
-
- it 'should add additional libraries to lib directory in Play 2.0 dist application' do
- Dir.mktmpdir do |root|
- lib_directory = File.join root, '.lib'
-
- FileUtils.cp_r 'spec/fixtures/container_play_2.0/.', root
- Dir.mkdir lib_directory
- FileUtils.cp 'spec/fixtures/additional_libs/test-jar-1.jar', lib_directory
-
- Play.new(
- app_dir: root,
- lib_directory: lib_directory,
- configuration: {}
- ).compile
-
- relative = File.readlink(File.join root, 'application_root', 'lib', 'test-jar-1.jar')
- actual = Pathname.new(File.join root, 'application_root', 'lib', 'test-jar-1.jar').realpath.to_s
- expected = Pathname.new(File.join lib_directory, 'test-jar-1.jar').realpath.to_s
-
- expect(relative).to_not eq(expected)
- expect(actual).to eq(expected)
- end
- end
-
- it 'should add additional libraries to staged directory in staged application' do
- Dir.mktmpdir do |root|
- lib_directory = File.join root, '.lib'
-
- FileUtils.cp_r 'spec/fixtures/container_play_staged/.', root
- Dir.mkdir lib_directory
- FileUtils.cp 'spec/fixtures/additional_libs/test-jar-1.jar', lib_directory
-
- Play.new(
- app_dir: root,
- lib_directory: lib_directory,
- configuration: {}
- ).compile
-
- relative = File.readlink(File.join root, 'staged', 'test-jar-1.jar')
- actual = Pathname.new(File.join root, 'staged', 'test-jar-1.jar').realpath.to_s
- expected = Pathname.new(File.join lib_directory, 'test-jar-1.jar').realpath.to_s
-
- expect(relative).to_not eq(expected)
- expect(actual).to eq(expected)
- end
- end
-
- it 'should produce the correct command in the release step' do
- command = Play.new(
- app_dir: TEST_PLAY_APP,
- configuration: {},
- java_home: TEST_JAVA_HOME,
- java_opts: TEST_JAVA_OPTS
- ).release
-
- expect(command).to eq("PATH=#{TEST_JAVA_HOME}/bin:$PATH JAVA_HOME=#{TEST_JAVA_HOME} ./application_root/start -Dhttp.port=$PORT #{TEST_JAVA_OPTS[0]}")
+ it 'should use the PlayApp returned by the PlayAppFactory to perform release' do
+ JavaBuildpack::Util::PlayAppFactory.stub(:create).with('test-app-dir').and_return(play_instance)
+ play_instance.should_receive(:start_script_relative).and_return('test-start-script-relative')
+ play_instance.should_receive(:decorate_java_opts).with(['some-option', '-Dhttp.port=$PORT']).and_return(['-Jsome-option', '-J-Dhttp.port=$PORT'])
+ play = Play.new('app_dir' => 'test-app-dir', 'java_opts' => ['some-option'], 'java_home' => 'test-java-home')
+ expect(play.release).to eq('PATH=test-java-home/bin:$PATH JAVA_HOME=test-java-home test-start-script-relative -J-Dhttp.port=$PORT -Jsome-option')
end
end
4 spec/java_buildpack/framework/play_auto_reconfiguration_spec.rb
View
@@ -36,7 +36,7 @@ module JavaBuildpack::Framework
JavaBuildpack::Repository::ConfiguredItem.stub(:find_item).and_return(PLAY_AUTO_RECONFIGURATION_DETAILS)
detected = PlayAutoReconfiguration.new(
- app_dir: 'spec/fixtures/container_play',
+ app_dir: 'spec/fixtures/container_play_2.1_dist',
configuration: {}
).detect
@@ -62,7 +62,7 @@ module JavaBuildpack::Framework
application_cache.stub(:get).with('test-uri').and_yield(File.open('spec/fixtures/stub-auto-reconfiguration.jar'))
PlayAutoReconfiguration.new(
- app_dir: 'spec/fixtures/container_play',
+ app_dir: 'spec/fixtures/container_play_2.1_dist',
lib_directory: lib_directory,
configuration: {}
).compile
2  spec/java_buildpack/framework/play_jpa_plugin_spec.rb
View
@@ -69,7 +69,7 @@ module JavaBuildpack::Framework
JavaBuildpack::Repository::ConfiguredItem.stub(:find_item).and_return(DETAILS)
detected = PlayJpaPlugin.new(
- app_dir: 'spec/fixtures/container_play',
+ app_dir: 'spec/fixtures/container_play_2.1_dist',
configuration: {}
).detect
125 spec/java_buildpack/util/base_play_app_spec.rb
View
@@ -0,0 +1,125 @@
+# 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 'java_buildpack/util/base_play_app'
+
+module JavaBuildpack::Util
+
+ describe BasePlayApp do
+
+ TEST_DIRECTORY_NAME = 'test-dir'
+
+ MISSING_METHOD_REGEX = /Method .* must be defined/
+
+ TEST_JAVA_OPTS = %w(test-option1 test-option2)
+
+ let(:base_play_app) { StubBasePlayApp.new TEST_DIRECTORY_NAME }
+
+ let(:base_play_app_raw) { StubBasePlayAppRaw.new TEST_DIRECTORY_NAME }
+
+ it 'should recognize a Play application' do
+ expect(StubBasePlayApp.recognizes? 'spec/fixtures/container_play_2.2').to be_true
+ end
+
+ it 'should not recognize a non-Play application' do
+ expect(StubBasePlayApp.recognizes? 'spec/fixtures/container_main').to be_false
+ end
+
+ it 'should assign application directory to an instance variable' do
+ expect(base_play_app_raw.app_dir).to eq(TEST_DIRECTORY_NAME)
+ end
+
+ it 'should fail if methods are unimplemented' do
+ expect { base_play_app_raw.add_libs_to_classpath [] }.to raise_error(MISSING_METHOD_REGEX)
+ expect { base_play_app_raw.start_script_relative }.to raise_error(MISSING_METHOD_REGEX)
+ end
+
+ it 'should set the Play script to be executable' do
+ app = base_play_app
+ base_play_app.stub(:shell)
+ base_play_app.should_receive(:shell).with('chmod +x test-dir/application_root/start')
+ app.set_executable
+ end
+
+ it 'should correctly replace the bootstrap class in the start script' do
+ Dir.mktmpdir do |root|
+ FileUtils.cp_r 'spec/fixtures/container_play_2.1_dist/.', root
+
+ play_app = StubBasePlayApp.new root
+
+ play_app.replace_bootstrap 'test.class.name'
+
+ actual = File.open(File.join(root, 'application_root', 'start'), 'r') { |file| file.read }
+
+ expect(actual).to_not match(/play.core.server.NettyServer/)
+ expect(actual).to match(/test.class.name/)
+ end
+ end
+
+ it 'should be able to find JARs in the classpath directory' do
+ play_app = StubBasePlayApp.new 'spec/fixtures/container_play_2.1_dist'
+ expect(play_app.contains?('some.test.jar')).to be_true
+ end
+
+ it 'should be able to find root and version' do
+ root, version = StubBasePlayApp.test_root_and_version 'spec/fixtures/container_play_2.1_dist'
+ expect(root).to eq('spec/fixtures/container_play_2.1_dist/application_root')
+ expect(version).to eq('2.1.4')
+ end
+
+ it 'should not decorate Java options' do
+ play_app = StubBasePlayApp.new 'spec/fixtures/container_play_2.1_dist'
+ expect(play_app.decorate_java_opts(TEST_JAVA_OPTS)).to eq(TEST_JAVA_OPTS)
+ end
+
+ end
+
+ class StubBasePlayAppRaw < BasePlayApp
+
+ def initialize(app_dir)
+ super(app_dir)
+ @play_root = app_dir
+ end
+
+ attr_reader :app_dir
+
+ attr_reader :play_root
+
+ end
+
+ class StubBasePlayApp < BasePlayApp
+
+ def initialize(app_dir)
+ super(app_dir)
+ @play_root = File.join(app_dir, 'application_root')
+ end
+
+ def self.start_script(app_dir)
+ File.join(app_dir, 'start')
+ end
+
+ attr_reader :app_dir
+
+ attr_reader :play_root
+
+ def self.test_root_and_version(app_dir)
+ root_and_version app_dir
+ end
+
+ end
+
+end
47 spec/java_buildpack/util/play_app_factory_spec.rb
View
@@ -0,0 +1,47 @@
+# 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 'java_buildpack/util/play_app_factory'
+
+module JavaBuildpack::Util
+
+ describe PlayAppFactory do
+
+ it 'should successfully create a Play 2.0 application' do
+ PlayAppFactory.create 'spec/fixtures/container_play_2.0_dist'
+ end
+
+ it 'should successfully create a Play 2.1 application' do
+ PlayAppFactory.create 'spec/fixtures/container_play_2.1_dist'
+ end
+
+ it 'should successfully create a Play 2.2 application' do
+ PlayAppFactory.create 'spec/fixtures/container_play_2.2'
+ end
+
+ it 'should fail to create an application which is a hybrid of Play 2.1 and 2.2' do
+ Dir.mktmpdir do |root|
+ FileUtils.cp_r 'spec/fixtures/container_play_2.1_dist/.', root
+ FileUtils.cp_r 'spec/fixtures/container_play_2.2/.', root
+
+ expect { PlayAppFactory.create root }.to raise_error(/Play application in .* is recognized by more than one Play application class/)
+ end
+ end
+
+ end
+
+end
127 spec/java_buildpack/util/play_app_post22_spec.rb
View
@@ -0,0 +1,127 @@
+# 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 'java_buildpack/util/library_utils'
+require 'java_buildpack/util/play_app_post22'
+
+module JavaBuildpack::Util
+
+ describe PlayAppPost22 do
+
+ TEST_JAVA_OPTIONS = %w(test-option1 test-option2)
+
+ it 'should not recognize Play 2.0 applications' do
+ expect(PlayAppPost22.recognizes? 'spec/fixtures/container_play_2.0_dist').to be_false
+ end
+
+ it 'should not recognize Play 2.1 dist applications' do
+ expect(PlayAppPost22.recognizes? 'spec/fixtures/container_play_2.1_dist').to be_false
+ end
+
+ it 'should not recognize Play 2.1 staged applications' do
+ expect(PlayAppPost22.recognizes? 'spec/fixtures/container_play_2.1_staged').to be_false
+ end
+
+ it 'should recognize Play 2.2 applications' do
+ expect(PlayAppPost22.recognizes? 'spec/fixtures/container_play_2.2').to be_true
+ end
+
+ it 'should recognize a Play 2.2 application with a missing .bat file if there is precisely one start script' do
+ expect(PlayAppPost22.recognizes? 'spec/fixtures/container_play_2.2_minus_bat_file').to be_true
+ end
+
+ it 'should not recognize a Play 2.2 application with a missing .bat file and more than one start script' do
+ expect(PlayAppPost22.recognizes? 'spec/fixtures/container_play_2.2_ambiguous_start_script').to be_false
+ end
+
+ it 'should construct a Play 2.2 application' do
+ PlayAppPost22.new 'spec/fixtures/container_play_2.2'
+ end
+
+ it 'should fail to construct a Play application of version prior to 2.2' do
+ expect { PlayAppPost22.new 'spec/fixtures/container_play_2.1_dist' }.to raise_error(/Unrecognized Play application/)
+ end
+
+ it 'should correctly determine the version of a Play 2.2 application' do
+ play_app = PlayAppPost22.new 'spec/fixtures/container_play_2.2'
+ expect(play_app.version).to eq('2.2.0')
+ end
+
+ it 'should make the start script executable' do
+ Dir.mktmpdir do |root|
+ FileUtils.cp_r 'spec/fixtures/container_play_2.2/.', root
+
+ play_app = PlayAppPost22.new root
+
+ JavaBuildpack::Util::PlayAppPost22.any_instance.should_receive(:shell).with("chmod +x #{root}/bin/play-application").and_return('')
+
+ play_app.set_executable
+ end
+ end
+
+ it 'should correctly replace the bootstrap class in the start script' do
+ Dir.mktmpdir do |root|
+ FileUtils.cp_r 'spec/fixtures/container_play_2.2/.', root
+
+ play_app = PlayAppPost22.new root
+
+ play_app.replace_bootstrap 'test.class.name'
+
+ actual = File.open(File.join(root, 'bin', 'play-application'), 'r') { |file| file.read }
+
+ expect(actual).to match(/declare -r app_mainclass="test.class.name"/)
+ end
+ end
+
+ it 'should correctly extend the classpath' do
+ Dir.mktmpdir do |root|
+ lib_dir = File.join(root, '.lib')
+ FileUtils.mkdir_p lib_dir
+ FileUtils.cp 'spec/fixtures/additional_libs/test-jar-1.jar', lib_dir
+
+ FileUtils.cp_r 'spec/fixtures/container_play_2.2/.', root
+
+ play_app = PlayAppPost22.new root
+
+ play_app.add_libs_to_classpath JavaBuildpack::Util::LibraryUtils.lib_jars(lib_dir)
+
+ actual = File.open(File.join(root, 'bin', 'play-application'), 'r') { |file| file.read }
+
+ expect(actual).to match(%r(declare -r app_classpath="\$app_home/\.\./\.lib/test-jar-1\.jar:.*"))
+ end
+ end
+
+ it 'should correctly determine the relative path of the start script' do
+ play_app = PlayAppPost22.new 'spec/fixtures/container_play_2.2'
+ expect(play_app.start_script_relative).to eq('./bin/play-application')
+ end
+
+ it 'should correctly determine whether or not certain JARs are present in the lib directory' do
+ play_app = PlayAppPost22.new 'spec/fixtures/container_play_2.2'
+ expect(play_app.contains? 'so*st.jar').to be_true
+ expect(play_app.contains? 'some.test.jar').to be_true
+ expect(play_app.contains? 'nosuch.jar').to be_false
+ end
+
+ it 'should decorate Java options with -J' do
+ play_app = PlayAppPost22.new 'spec/fixtures/container_play_2.2'
+ expect(play_app.decorate_java_opts(TEST_JAVA_OPTIONS)).to eq(%w(-Jtest-option1 -Jtest-option2 -J-Xms2M))
+ end
+
+ end
+
+end
159 spec/java_buildpack/util/play_app_pre22_dist_spec.rb
View
@@ -0,0 +1,159 @@
+# 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 'java_buildpack/util/library_utils'
+require 'java_buildpack/util/play_app_pre22_dist'
+
+module JavaBuildpack::Util
+
+ describe PlayAppPre22Dist do
+
+ it 'should recognize Play 2.0 dist applications' do
+ expect(PlayAppPre22Dist.recognizes? 'spec/fixtures/container_play_2.0_dist').to be_true
+ end
+
+ it 'should recognize Play 2.1 dist applications' do
+ expect(PlayAppPre22Dist.recognizes? 'spec/fixtures/container_play_2.1_dist').to be_true
+ end
+
+ it 'should not recognize Play 2.1 staged (or equivalently 2.0 staged) applications' do
+ expect(PlayAppPre22Dist.recognizes? 'spec/fixtures/container_play_2.1_staged').to be_false
+ end
+
+ it 'should not recognize Play 2.2 applications' do
+ expect(PlayAppPre22Dist.recognizes? 'spec/fixtures/container_play_2.2').to be_false
+ end
+
+ it 'should construct a Play 2.0 dist application' do
+ PlayAppPre22Dist.new 'spec/fixtures/container_play_2.0_dist'
+ end
+
+ it 'should construct a Play 2.1 dist application' do
+ PlayAppPre22Dist.new 'spec/fixtures/container_play_2.1_dist'
+ end
+
+ it 'should fail to construct a Play 2.1 staged (or equivalently 2.0 staged) application' do
+ expect { PlayAppPre22Dist.new 'spec/fixtures/container_play_2.1_staged' }.to raise_error(/Unrecognized Play application/)
+ end
+
+ it 'should fail to construct a Play 2.2 application' do
+ expect { PlayAppPre22Dist.new 'spec/fixtures/container_play_2.2' }.to raise_error(/Unrecognized Play application/)
+ end
+
+ it 'should correctly determine the version of a Play 2.0 dist application' do
+ play_app = PlayAppPre22Dist.new 'spec/fixtures/container_play_2.0_dist'
+ expect(play_app.version).to eq('2.0')
+ end
+
+ it 'should correctly determine the version of a Play 2.1 dist application' do
+ play_app = PlayAppPre22Dist.new 'spec/fixtures/container_play_2.1_dist'
+ expect(play_app.version).to eq('2.1.4')
+ end
+
+ it 'should make the start script executable' do
+ Dir.mktmpdir do |root|
+ FileUtils.cp_r 'spec/fixtures/container_play_2.1_dist/.', root
+
+ play_app = PlayAppPre22Dist.new root
+
+ JavaBuildpack::Util::PlayAppPre22Dist.any_instance.should_receive(:shell).with("chmod +x #{root}/application_root/start").and_return('')
+
+ play_app.set_executable
+ end
+ end
+
+ it 'should correctly replace the bootstrap class in the start script of a Play 2.1 dist application' do
+ Dir.mktmpdir do |root|
+ FileUtils.cp_r 'spec/fixtures/container_play_2.1_dist/.', root
+
+ play_app = PlayAppPre22Dist.new root
+
+ play_app.replace_bootstrap 'test.class.name'
+
+ actual = File.open(File.join(root, 'application_root', 'start'), 'r') { |file| file.read }
+
+ expect(actual).to_not match(/play.core.server.NettyServer/)
+ expect(actual).to match(/test.class.name/)
+ end
+ end
+
+ it 'should add additional libraries to lib directory of a Play 2.0 dist application' do
+ Dir.mktmpdir do |root|
+ lib_dir = File.join(root, '.lib')
+ FileUtils.mkdir_p lib_dir
+ FileUtils.cp 'spec/fixtures/additional_libs/test-jar-1.jar', lib_dir
+
+ FileUtils.cp_r 'spec/fixtures/container_play_2.0_dist/.', root
+
+ play_app = PlayAppPre22Dist.new root
+
+ play_app.add_libs_to_classpath JavaBuildpack::Util::LibraryUtils.lib_jars(lib_dir)
+
+ relative = File.readlink(File.join root, 'application_root', 'lib', 'test-jar-1.jar')
+ actual = Pathname.new(File.join root, 'application_root', 'lib', 'test-jar-1.jar').realpath.to_s
+ expected = Pathname.new(File.join lib_dir, 'test-jar-1.jar').realpath.to_s
+
+ expect(relative).to_not eq(expected)
+ expect(actual).to eq(expected)
+ end
+ end
+
+ it 'should correctly extend the classpath of a Play 2.1 dist application' do
+ Dir.mktmpdir do |root|
+ lib_dir = File.join(root, '.lib')
+ FileUtils.mkdir_p lib_dir
+ FileUtils.cp 'spec/fixtures/additional_libs/test-jar-1.jar', lib_dir
+
+ FileUtils.cp_r 'spec/fixtures/container_play_2.1_dist/.', root
+
+ play_app = PlayAppPre22Dist.new root
+
+ play_app.add_libs_to_classpath JavaBuildpack::Util::LibraryUtils.lib_jars(lib_dir)
+
+ actual = File.open(File.join(root, 'application_root', 'start'), 'r') { |file| file.read }
+
+ expect(actual).to match(%r(classpath="\$scriptdir/.\./\.lib/test-jar-1\.jar:))
+ end
+ end
+
+ it 'should correctly determine the relative path of the start script of a Play 2.0 dist application' do
+ play_app = PlayAppPre22Dist.new 'spec/fixtures/container_play_2.0_dist'
+ expect(play_app.start_script_relative).to eq('./application_root/start')
+ end
+
+ it 'should correctly determine the relative path of the start script of a Play 2.1 dist application' do
+ play_app = PlayAppPre22Dist.new 'spec/fixtures/container_play_2.1_dist'
+ expect(play_app.start_script_relative).to eq('./application_root/start')
+ end
+
+ it 'should correctly determine whether or not certain JARs are present in the lib directory of a Play 2.0 dist application' do
+ play_app = PlayAppPre22Dist.new 'spec/fixtures/container_play_2.0_dist'
+ expect(play_app.contains? 'so*st.jar').to be_true
+ expect(play_app.contains? 'some.test.jar').to be_true
+ expect(play_app.contains? 'nosuch.jar').to be_false
+ end
+
+ it 'should correctly determine whether or not certain JARs are present in the lib directory of a Play 2.1 dist application' do
+ play_app = PlayAppPre22Dist.new 'spec/fixtures/container_play_2.1_dist'
+ expect(play_app.contains? 'so*st.jar').to be_true
+ expect(play_app.contains? 'some.test.jar').to be_true
+ expect(play_app.contains? 'nosuch.jar').to be_false
+ end
+
+ end
+
+end
50 spec/java_buildpack/util/play_app_pre22_spec.rb
View
@@ -0,0 +1,50 @@
+# 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 'java_buildpack/container/container_utils'
+require 'java_buildpack/util/play_app_pre22'
+
+module JavaBuildpack::Util
+
+ describe PlayAppPre22 do
+
+ let(:play_app_pre22) { StubPlayAppPre22.new 'test-dir' }
+
+ it 'should fail if methods are unimplemented' do
+ JavaBuildpack::Container::ContainerUtils.stub(:relative_paths).and_return(['./test-jar'])
+ JavaBuildpack::Container::ContainerUtils.should_receive(:relative_paths).with('test-dir', ['test.jar'])
+ app = play_app_pre22
+ app.stub(:shell)
+ app.should_receive(:shell).with('ln -nsf .././test-jar test-dir/lib')
+ app.test_link_libs_from_classpath_dir ['test.jar']
+ end
+
+ end
+
+ class StubPlayAppPre22 < PlayAppPre22
+
+ def initialize(app_dir)
+ super(app_dir)
+ @play_root = app_dir
+ end
+
+ def test_link_libs_from_classpath_dir(libs)
+ link_libs_from_classpath_dir(libs)
+ end
+ end
+
+end
109 spec/java_buildpack/util/play_app_pre22_staged_spec.rb
View
@@ -0,0 +1,109 @@
+# 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 'java_buildpack/util/library_utils'
+require 'java_buildpack/util/play_app_pre22_staged'
+
+module JavaBuildpack::Util
+
+ describe PlayAppPre22Staged do
+
+ it 'should not recognize Play 2.0 dist applications' do
+ expect(PlayAppPre22Staged.recognizes? 'spec/fixtures/container_play_2.0_dist').to be_false
+ end
+
+ it 'should not recognize Play 2.1 dist applications' do
+ expect(PlayAppPre22Staged.recognizes? 'spec/fixtures/container_play_2.1_dist').to be_false
+ end
+
+ it 'should recognize Play 2.1 staged (or equivalently 2.0 staged) applications' do
+ expect(PlayAppPre22Staged.recognizes? 'spec/fixtures/container_play_2.1_staged').to be_true
+ end
+
+ it 'should not recognize Play 2.2 applications' do
+ expect(PlayAppPre22Staged.recognizes? 'spec/fixtures/container_play_2.2').to be_false
+ end
+
+ it 'should fail to construct a Play 2.0 dist application' do
+ expect { PlayAppPre22Staged.new 'spec/fixtures/container_play_2.0_dist' }.to raise_error(/Unrecognized Play application/)
+ end
+
+ it 'should fail to construct a Play 2.1 dist application' do
+ expect { PlayAppPre22Staged.new 'spec/fixtures/container_play_2.1_dist' }.to raise_error(/Unrecognized Play application/)
+ end
+
+ it 'should construct a Play 2.1 staged (or equivalently 2.0 staged) application' do
+ PlayAppPre22Staged.new 'spec/fixtures/container_play_2.1_staged'
+ end
+
+ it 'should fail to construct a Play 2.2 application' do
+ expect { PlayAppPre22Staged.new 'spec/fixtures/container_play_2.2' }.to raise_error(/Unrecognized Play application/)
+ end
+
+ it 'should correctly determine the version of a Play 2.1 staged (or equivalently 2.0 staged) application' do
+ play_app = PlayAppPre22Staged.new 'spec/fixtures/container_play_2.1_staged'
+ expect(play_app.version).to eq('2.1.4')
+ end
+
+ it 'should make the start script executable' do
+ Dir.mktmpdir do |root|
+ FileUtils.cp_r 'spec/fixtures/container_play_2.1_staged/.', root
+
+ play_app = PlayAppPre22Staged.new root
+
+ JavaBuildpack::Util::PlayAppPre22Staged.any_instance.should_receive(:shell).with("chmod +x #{root}/start").and_return('')
+
+ play_app.set_executable
+ end
+ end
+
+ it 'should add additional libraries to staged directory of a Play 2.1 staged (or equivalently 2.0 staged) application' do
+ Dir.mktmpdir do |root|
+ lib_dir = File.join(root, '.lib')
+ FileUtils.mkdir_p lib_dir
+ FileUtils.cp 'spec/fixtures/additional_libs/test-jar-1.jar', lib_dir
+
+ FileUtils.cp_r 'spec/fixtures/container_play_2.1_staged/.', root
+
+ play_app = PlayAppPre22Staged.new root
+
+ play_app.add_libs_to_classpath JavaBuildpack::Util::LibraryUtils.lib_jars(lib_dir)
+
+ relative = File.readlink(File.join root, 'staged', 'test-jar-1.jar')
+ actual = Pathname.new(File.join root, 'staged', 'test-jar-1.jar').realpath.to_s
+ expected = Pathname.new(File.join lib_dir, 'test-jar-1.jar').realpath.to_s
+
+ expect(relative).to_not eq(expected)
+ expect(actual).to eq(expected)
+ end
+ end
+
+ it 'should correctly determine the relative path of the start script of a Play 2.1 staged (or equivalently 2.0 staged) application' do
+ play_app = PlayAppPre22Staged.new 'spec/fixtures/container_play_2.1_staged'
+ expect(play_app.start_script_relative).to eq('./start')
+ end
+
+ it 'should correctly determine whether or not certain JARs are present in the lib directory of a Play 2.1 staged (or equivalently 2.0 staged) application' do
+ play_app = PlayAppPre22Staged.new 'spec/fixtures/container_play_2.1_staged'
+ expect(play_app.contains? 'so*st.jar').to be_true
+ expect(play_app.contains? 'some.test.jar').to be_true
+ expect(play_app.contains? 'nosuch.jar').to be_false
+ end
+
+ end
+
+end
Please sign in to comment.
Something went wrong with that request. Please try again.