Skip to content

Commit

Permalink
JAR file detection
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
nebhale committed Apr 11, 2014
1 parent 7a285f4 commit 7860094
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
12 changes: 9 additions & 3 deletions lib/java_buildpack/util/ratpack_utils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,21 +32,27 @@ 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
#
# @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
Expand Down
12 changes: 9 additions & 3 deletions lib/java_buildpack/util/spring_boot_utils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,21 +32,27 @@ 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
#
# @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
Expand Down

0 comments on commit 7860094

Please sign in to comment.