diff --git a/lib/java_buildpack/util/ratpack_utils.rb b/lib/java_buildpack/util/ratpack_utils.rb index d90644e7de..3b101a9381 100644 --- a/lib/java_buildpack/util/ratpack_utils.rb +++ b/lib/java_buildpack/util/ratpack_utils.rb @@ -32,7 +32,7 @@ class << self # @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_CORE_FILE_PATTERN).glob.any? + jar application end # The version of Ratpack used by the application @@ -40,13 +40,19 @@ def is?(application) # @param [Application] application the application to search # @return [String] the version of Ratpack used by the application def version(application) - (application.root + RATPACK_CORE_FILE_PATTERN).glob.first.to_s.match(/.*ratpack-core-(.*)\.jar/)[1] + jar(application).to_s.match(RATPACK_CORE_FILE_PATTERN)[1] end - RATPACK_CORE_FILE_PATTERN = '**/lib/ratpack-core-*.jar'.freeze + private + + RATPACK_CORE_FILE_PATTERN = /.*ratpack-core-(.*)\.jar/.freeze private_constant :RATPACK_CORE_FILE_PATTERN + def jar(application) + (application.root + '**/lib/*.jar').glob.find { |jar| jar.to_s =~ RATPACK_CORE_FILE_PATTERN } + end + end end diff --git a/lib/java_buildpack/util/spring_boot_utils.rb b/lib/java_buildpack/util/spring_boot_utils.rb index 4933091e17..d54beb721c 100644 --- a/lib/java_buildpack/util/spring_boot_utils.rb +++ b/lib/java_buildpack/util/spring_boot_utils.rb @@ -32,7 +32,7 @@ class << self # @param [Application] application the application to search # @return [Boolean] +true+ if the application is a Spring Boot application, +false+ otherwise def is?(application) - (application.root + SPRING_BOOT_CORE_FILE_PATTERN).glob.any? + jar application end # The version of Spring Boot used by the application @@ -40,13 +40,19 @@ def is?(application) # @param [Application] application the application to search # @return [String] the version of Spring Boot used by the application def version(application) - (application.root + SPRING_BOOT_CORE_FILE_PATTERN).glob.first.to_s.match(/.*spring-boot-([^-]*)\.jar/)[1] + jar(application).to_s.match(SPRING_BOOT_CORE_FILE_PATTERN)[1] end - SPRING_BOOT_CORE_FILE_PATTERN = '**/lib/spring-boot-*.jar'.freeze + private + + SPRING_BOOT_CORE_FILE_PATTERN = /.*spring-boot-([^-]*)\.jar/.freeze private_constant :SPRING_BOOT_CORE_FILE_PATTERN + def jar(application) + (application.root + '**/lib/*.jar').glob.find { |jar| jar.to_s =~ SPRING_BOOT_CORE_FILE_PATTERN } + end + end end