Skip to content

Commit 7860094

Browse files
committed
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.
1 parent 7a285f4 commit 7860094

File tree

2 files changed

+18
-6
lines changed

2 files changed

+18
-6
lines changed

lib/java_buildpack/util/ratpack_utils.rb

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,21 +32,27 @@ class << self
3232
# @param [Application] application the application to search
3333
# @return [Boolean] +true+ if the application is a Ratpack application, +false+ otherwise
3434
def is?(application)
35-
(application.root + RATPACK_CORE_FILE_PATTERN).glob.any?
35+
jar application
3636
end
3737

3838
# The version of Ratpack used by the application
3939
#
4040
# @param [Application] application the application to search
4141
# @return [String] the version of Ratpack used by the application
4242
def version(application)
43-
(application.root + RATPACK_CORE_FILE_PATTERN).glob.first.to_s.match(/.*ratpack-core-(.*)\.jar/)[1]
43+
jar(application).to_s.match(RATPACK_CORE_FILE_PATTERN)[1]
4444
end
4545

46-
RATPACK_CORE_FILE_PATTERN = '**/lib/ratpack-core-*.jar'.freeze
46+
private
47+
48+
RATPACK_CORE_FILE_PATTERN = /.*ratpack-core-(.*)\.jar/.freeze
4749

4850
private_constant :RATPACK_CORE_FILE_PATTERN
4951

52+
def jar(application)
53+
(application.root + '**/lib/*.jar').glob.find { |jar| jar.to_s =~ RATPACK_CORE_FILE_PATTERN }
54+
end
55+
5056
end
5157

5258
end

lib/java_buildpack/util/spring_boot_utils.rb

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,21 +32,27 @@ class << self
3232
# @param [Application] application the application to search
3333
# @return [Boolean] +true+ if the application is a Spring Boot application, +false+ otherwise
3434
def is?(application)
35-
(application.root + SPRING_BOOT_CORE_FILE_PATTERN).glob.any?
35+
jar application
3636
end
3737

3838
# The version of Spring Boot used by the application
3939
#
4040
# @param [Application] application the application to search
4141
# @return [String] the version of Spring Boot used by the application
4242
def version(application)
43-
(application.root + SPRING_BOOT_CORE_FILE_PATTERN).glob.first.to_s.match(/.*spring-boot-([^-]*)\.jar/)[1]
43+
jar(application).to_s.match(SPRING_BOOT_CORE_FILE_PATTERN)[1]
4444
end
4545

46-
SPRING_BOOT_CORE_FILE_PATTERN = '**/lib/spring-boot-*.jar'.freeze
46+
private
47+
48+
SPRING_BOOT_CORE_FILE_PATTERN = /.*spring-boot-([^-]*)\.jar/.freeze
4749

4850
private_constant :SPRING_BOOT_CORE_FILE_PATTERN
4951

52+
def jar(application)
53+
(application.root + '**/lib/*.jar').glob.find { |jar| jar.to_s =~ SPRING_BOOT_CORE_FILE_PATTERN }
54+
end
55+
5056
end
5157

5258
end

0 commit comments

Comments
 (0)