Skip to content

Commit 038ab56

Browse files
author
Christopher Frost
committed
Packaging should handle missing platform versions
When packaging the Java buildpack it should just report that the requested version for a specific platform can not be found and carry on. This commit makes that change. [#77005312]
1 parent c0ba652 commit 038ab56

File tree

4 files changed

+35
-26
lines changed

4 files changed

+35
-26
lines changed

lib/java_buildpack/repository/repository_index.rb

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,10 @@ def initialize(repository_root)
5050
# @return [TokenizedVersion] the version of the file found
5151
# @return [String] the URI of the file found
5252
def find_item(version)
53-
version = VersionResolver.resolve(version, @index.keys)
54-
uri = @index[version.to_s]
55-
[version, uri]
53+
found_version = VersionResolver.resolve(version, @index.keys)
54+
fail "No version resolvable for '#{version}' in #{@index.keys.join(', ')}" if found_version.nil?
55+
uri = @index[found_version.to_s]
56+
[found_version, uri]
5657
end
5758

5859
private

lib/java_buildpack/repository/version_resolver.rb

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,7 @@ class << self
3535
# @param [TokenizedVersion] candidate_version the version, possibly containing a wildcard, to resolve. If +nil+,
3636
# substituted with +.
3737
# @param [Array<String>] versions the collection of versions to resolve against
38-
# @return [TokenizedVersion] the resolved version
39-
# @raise if no version can be resolved
38+
# @return [TokenizedVersion] the resolved version or nil if no matching version is found
4039
def resolve(candidate_version, versions)
4140
tokenized_candidate_version = safe_candidate_version candidate_version
4241
tokenized_versions = versions.map { |version| JavaBuildpack::Util::TokenizedVersion.new(version, false) }
@@ -45,7 +44,6 @@ def resolve(candidate_version, versions)
4544
.select { |tokenized_version| matches? tokenized_candidate_version, tokenized_version }
4645
.max { |a, b| a <=> b }
4746

48-
fail "No version resolvable for '#{candidate_version}' in #{versions.join(', ')}" if version.nil?
4947
version
5048
end
5149

rakelib/dependency_cache_task.rb

Lines changed: 29 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -53,36 +53,43 @@ def initialize
5353

5454
private_constant :ARCHITECTURE_PATTERN, :DEFAULT_REPOSITORY_ROOT_PATTERN, :PLATFORM_PATTERN
5555

56-
def augment(raw, pattern, candidates, &block)
57-
if raw.respond_to? :map
56+
def augment(raw, key, pattern, candidates, &block)
57+
if raw.respond_to? :at
5858
raw.map(&block)
5959
else
60-
raw =~ pattern ? candidates.map { |p| raw.gsub pattern, p } : raw
60+
if raw[:uri] =~ pattern
61+
candidates.map do |candidate|
62+
dup = raw.clone
63+
dup[key] = candidate
64+
dup[:uri] = raw[:uri].gsub pattern, candidate
65+
66+
dup
67+
end
68+
else
69+
raw
70+
end
6171
end
6272
end
6373

6474
def augment_architecture(raw)
65-
augment(raw, ARCHITECTURE_PATTERN, ARCHITECTURES) { |r| augment_architecture r }
75+
augment(raw, :architecture, ARCHITECTURE_PATTERN, ARCHITECTURES) { |r| augment_architecture r }
6676
end
6777

6878
def augment_path(raw)
69-
if raw.respond_to? :map
79+
if raw.respond_to? :at
7080
raw.map { |r| augment_path r }
7181
else
72-
"#{raw.chomp('/')}/index.yml"
82+
raw[:uri] = "#{raw[:uri].chomp('/')}/index.yml"
83+
raw
7384
end
7485
end
7586

7687
def augment_platform(raw)
77-
augment(raw, PLATFORM_PATTERN, PLATFORMS) { |r| augment_platform r }
88+
augment(raw, :platform, PLATFORM_PATTERN, PLATFORMS) { |r| augment_platform r }
7889
end
7990

8091
def augment_repository_root(raw)
81-
if raw.respond_to? :map
82-
raw.map { |r| augment_repository_root r }
83-
else
84-
raw.gsub DEFAULT_REPOSITORY_ROOT_PATTERN, @default_repository_root
85-
end
92+
augment(raw, :repository_root, DEFAULT_REPOSITORY_ROOT_PATTERN, [@default_repository_root]) { |r| augment_repository_root r }
8693
end
8794

8895
def cache
@@ -122,8 +129,9 @@ def default_repository_root
122129
configuration('repository')['default_repository_root'].chomp('/')
123130
end
124131

125-
def index_uris(configuration)
132+
def index_configuration(configuration)
126133
[configuration['repository_root']]
134+
.map { |r| { uri: r } }
127135
.map { |r| augment_repository_root r }
128136
.map { |r| augment_platform r }
129137
.map { |r| augment_architecture r }
@@ -138,12 +146,14 @@ def uris(configurations)
138146
uris = []
139147

140148
configurations.each do |configuration|
141-
index_uris(configuration).each do |index_uri|
142-
multitask PACKAGE_NAME => [cache_task(index_uri)]
143-
144-
@cache.get(index_uri) do |f|
145-
index = YAML.load f
146-
uris << index[version(configuration, index).to_s]
149+
index_configuration(configuration).each do |index_configuration|
150+
multitask PACKAGE_NAME => [cache_task(index_configuration[:uri])]
151+
152+
@cache.get(index_configuration[:uri]) do |f|
153+
index = YAML.load f
154+
found_version = version(configuration, index)
155+
rake_output_message "Unable to resolve version '#{configuration['version']}' for platform '#{index_configuration[:platform]}'" if found_version.nil?
156+
uris << index[found_version.to_s] unless found_version.nil?
147157
end
148158
end
149159
end

spec/java_buildpack/repository/version_resolver_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
end
5454

5555
it 'should raise an exception if no version can be resolved' do
56-
expect { described_class.resolve(tokenized_version('2.1.0'), versions) }.to raise_error
56+
expect(described_class.resolve(tokenized_version('2.1.0'), versions)).to be_nil
5757
end
5858

5959
it 'should raise an exception when a wildcard is specified in the [] collection' do

0 commit comments

Comments
 (0)