From 78600947e4f5613852800628f1f1f834a1d625b5 Mon Sep 17 00:00:00 2001 From: Ben Hale Date: Fri, 11 Apr 2014 14:21:21 +0100 Subject: [PATCH] JAR file detection Previously, the detection algorithms for Ratpack and Spring Boot contained a bug. This bug manifested itself as detection a JAR that _almost_ matched the name required for discrimination, but when extracting the version, everything would crash. This bug was hidden during testing because the ordering that files were listed affected whether the bug manifested. This change updates the detection algorithms so that the ordering of the files no longer matters. --- lib/java_buildpack/util/ratpack_utils.rb | 12 +++++++++--- lib/java_buildpack/util/spring_boot_utils.rb | 12 +++++++++--- 2 files changed, 18 insertions(+), 6 deletions(-) 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