Skip to content

Commit 0909e8a

Browse files
committed
Include Java Buildpack version in detect output
This change adds the version of the Java Buildpack to the output of the detect command in the case that the buildpack is going to return truthy. [#68436710]
1 parent 9b75b49 commit 0909e8a

3 files changed

Lines changed: 13 additions & 5 deletions

File tree

lib/java_buildpack/buildpack.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ def detect
4343
tags = tag_detection('container', @containers, true)
4444
tags.concat tag_detection('JRE', @jres, true) unless tags.empty?
4545
tags.concat tag_detection('framework', @frameworks, false) unless tags.empty?
46-
tags = tags.flatten.compact
46+
tags << "java-buildpack=#{@buildpack_version.to_s false}" unless tags.empty?
47+
tags = tags.flatten.compact.sort
4748

4849
@logger.debug { "Detection Tags: #{tags}" }
4950
tags

lib/java_buildpack/buildpack_version.rb

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,15 +45,18 @@ def initialize
4545
# +abcde | https://github.com/cloudfoundry/java-buildpack.git#abcde+ (default version number, online buildpack)
4646
# +https://github.com/cloudfoundry/java-buildpack#12345+ (cloned buildpack)
4747
# +unknown+ (un-packaged, un-cloned)
48-
def to_s
48+
#
49+
# @param [Boolean] human_readable whether the output should be human readable or machine readable
50+
# @return [String] a +String+ representation of the version
51+
def to_s(human_readable = true)
4952
s = []
5053
s << @version if @version
51-
s << '(offline)' if @offline
52-
s << '|' if @version
54+
s << (human_readable ? '(offline)' : 'offline') if @offline
55+
s << '|' if @version && human_readable
5356
s << "#{@remote}##{@hash}" if @remote && @hash
5457
s << 'unknown' if s.empty?
5558

56-
s.join ' '
59+
s.join(human_readable ? ' ' : '-')
5760
end
5861

5962
private

spec/java_buildpack/buildpack_version_spec.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
'remote' => 'test-remote', 'version' => 'test-version' } do
3636

3737
expect(buildpack_version.to_s).to match(/test-version (offline) | test-remote#test-hash/)
38+
expect(buildpack_version.to_s(false)).to match(/test-version-offline-test-remote#test-hash/)
3839
expect(stderr.string).to match(/test-version (offline) | test-remote#test-hash/)
3940
end
4041

@@ -44,6 +45,7 @@
4445
'remote' => 'test-remote', 'version' => 'test-version' } do
4546

4647
expect(buildpack_version.to_s).to match(/test-version | test-remote#test-hash/)
48+
expect(buildpack_version.to_s(false)).to match(/test-version-test-remote#test-hash/)
4749
expect(stderr.string).to match(/test-version | test-remote#test-hash/)
4850
end
4951

@@ -63,6 +65,7 @@
6365
.and_return('test-remote')
6466

6567
expect(buildpack_version.to_s).to match(/test-remote#test-hash/)
68+
expect(buildpack_version.to_s(false)).to match(/test-remote#test-hash/)
6669
expect(stderr.string).to match(/test-remote#test-hash/)
6770
end
6871

@@ -72,6 +75,7 @@
7275
allow_any_instance_of(described_class).to receive(:system).with('which git > /dev/null').and_return(false)
7376

7477
expect(buildpack_version.to_s).to match(/unknown/)
78+
expect(buildpack_version.to_s(false)).to match(/unknown/)
7579
expect(stderr.string).to match(/unknown/)
7680
end
7781

0 commit comments

Comments
 (0)