1616
1717require 'java_buildpack'
1818require 'java_buildpack/util/configuration_utils'
19+ require 'java_buildpack/util/to_b'
1920
2021module JavaBuildpack
2122
@@ -26,16 +27,48 @@ module JavaBuildpack
2627 # 3. unknown
2728 class BuildpackVersion
2829
30+ # @!attribute [r] hash
31+ # @return [String, nil] the Git hash of this version, or +nil+ if it cannot be determined
32+ attr_reader :hash
33+
34+ # @!attribute [r] offline
35+ # @return [Boolean] +true+ if the buildpack is offline, +false+ otherwise
36+ attr_reader :offline
37+
38+ # @!attribute [r] remote
39+ # @return [String, nil] the Git remote of this version, or +nil+ if it cannot be determined
40+ attr_reader :remote
41+
42+ # @!attribute [r] version
43+ # @return [String, nil] the version name of this version, or +nil+ if it cannot be determined
44+ attr_reader :version
45+
2946 # Creates a new instance
30- def initialize
31- configuration = JavaBuildpack ::Util ::ConfigurationUtils . load 'version'
47+ def initialize ( should_log = true )
48+ configuration = JavaBuildpack ::Util ::ConfigurationUtils . load 'version' , should_log
3249 @hash = configuration [ 'hash' ] || hash
33- @offline = configuration [ 'offline' ]
50+ @offline = configuration [ 'offline' ] || ENV [ 'OFFLINE' ] . to_b
3451 @remote = configuration [ 'remote' ] || remote
35- @version = configuration [ 'version' ]
52+ @version = configuration [ 'version' ] || ENV [ 'VERSION' ] || @hash
53+
54+ if should_log
55+ logger = Logging ::LoggerFactory . instance . get_logger BuildpackVersion
56+ logger . debug { to_s }
57+ end
58+ end
59+
60+ # Returns a +Hash+ representation of the buildpack version.
61+ #
62+ # @return [Hash] a representation of the buildpack version
63+ def to_hash
64+ h = { }
65+
66+ h [ 'hash' ] = @hash if @hash
67+ h [ 'offline' ] = @offline if @offline
68+ h [ 'remote' ] = @remote if @remote
69+ h [ 'version' ] = @version if @version
3670
37- logger = Logging ::LoggerFactory . instance . get_logger BuildpackVersion
38- logger . debug { to_s }
71+ h
3972 end
4073
4174 # Creates a string representation of the version. The string representation looks like the following:
0 commit comments