Skip to content

Commit

Permalink
End With Wildcards
Browse files Browse the repository at this point in the history
Previously, the version wildcarding system only worked as an all or nothing
proposition.  This meant that you couldn't ask for a wildcarded suffix to a
version qualifier.  This hadn't been a problem up until now, but with the
latest release of the JRE (_102) the lexical analyzation would not select the
proper version because it came before _91.  This change updates the wildcard
behavior so that it can be used *as a tailing wildcard* allowing us to set a
version of `1.8.0_10+` and select these new versions of the JRE.

[resolves #324]
  • Loading branch information
nebhale committed Aug 26, 2016
1 parent 619dbba commit df1bdf0
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 13 deletions.
2 changes: 1 addition & 1 deletion config/open_jdk_jre.yml
Expand Up @@ -17,7 +17,7 @@
# If Java 7 is required, permgen will be used instead of metaspace. Please see the documentation for more detail.
---
jre:
version: 1.8.0_+
version: 1.8.0_10+
repository_root: "{default.repository.root}/openjdk/{platform}/{architecture}"
memory_calculator:
version: 2.+
Expand Down
2 changes: 1 addition & 1 deletion config/oracle_jre.yml
Expand Up @@ -20,7 +20,7 @@
# e.g. repository_root: "http://example.com/oracle-jre/{platform}/{architecture}"
---
jre:
version: 1.8.0_+
version: 1.8.0_10+
repository_root: ""
memory_calculator:
version: 2.+
Expand Down
2 changes: 1 addition & 1 deletion config/zulu_jre.yml
Expand Up @@ -20,7 +20,7 @@
# e.g. repository_root: "http://example.com/zulu-jre/{platform}/{architecture}"
---
jre:
version: 1.8.0_+
version: 1.8.0_10+
repository_root: "https://cdn.azul.com/zulu/bin"
memory_calculator:
version: 2.+
Expand Down
8 changes: 5 additions & 3 deletions lib/java_buildpack/repository/version_resolver.rb
Expand Up @@ -76,12 +76,14 @@ def safe_candidate_version(candidate_version)

def matches?(tokenized_candidate_version, tokenized_version)
(0..3).all? do |i|
tokenized_candidate_version[i].nil? ||
tokenized_candidate_version[i] == JavaBuildpack::Util::TokenizedVersion::WILDCARD ||
tokenized_candidate_version[i] == tokenized_version[i]
tokenized_candidate_version[i].nil? || as_regex(tokenized_candidate_version[i]) =~ tokenized_version[i]
end
end

def as_regex(version)
/^#{version.gsub(JavaBuildpack::Util::TokenizedVersion::WILDCARD, '.*')}/
end

end

end
Expand Down
6 changes: 3 additions & 3 deletions lib/java_buildpack/util/tokenized_version.rb
Expand Up @@ -141,12 +141,12 @@ def non_nil_qualifier(qualifier)
def validate(allow_wildcards)
wildcarded = false
each do |value|
if value == WILDCARD && !allow_wildcards
if !value.nil? && value.end_with?(WILDCARD) && !allow_wildcards
raise "Invalid version '#{@version}': wildcards are not allowed this context"
end

raise "Invalid version '#{@version}': no characters are allowed after a wildcard" if wildcarded && value
wildcarded = true if value == WILDCARD
wildcarded = true if !value.nil? && value.end_with?(WILDCARD)
end
raise "Invalid version '#{@version}': missing component" if !wildcarded && compact.length < 3
end
Expand All @@ -156,7 +156,7 @@ def valid_major_minor_or_micro(major_minor_or_micro)
end

def valid_qualifier(qualifier)
qualifier.nil? || qualifier.empty? || qualifier =~ /^[-\.a-zA-Z\d]*$/ || qualifier =~ /^\+$/
qualifier.nil? || qualifier.empty? || qualifier =~ /^[-\.a-zA-Z\d]*[\+]?$/
end
end

Expand Down
4 changes: 4 additions & 0 deletions spec/java_buildpack/repository/version_resolver_spec.rb
Expand Up @@ -45,6 +45,10 @@
expect(described_class.resolve(tokenized_version('1.8.0_+'), versions)).to eq(tokenized_version('1.8.0_05'))
end

it 'resolves a partial-wildcard qualifier' do
expect(described_class.resolve(tokenized_version('1.7.0_1+'), versions)).to eq(tokenized_version('1.7.0_19'))
end

it 'resolves a non-wildcard version' do
expect(described_class.resolve(tokenized_version('1.6.0_26'), versions)).to eq(tokenized_version('1.6.0_26'))
expect(described_class.resolve(tokenized_version('2.0.0'), versions)).to eq(tokenized_version('2.0.0'))
Expand Down
13 changes: 9 additions & 4 deletions spec/java_buildpack/util/tokenized_version_spec.rb
Expand Up @@ -62,6 +62,14 @@
expect { described_class.new('1.6_26') }.to raise_error(/Invalid/)
end

it 'accepts wildcards when legal' do
described_class.new('+')
described_class.new('1.+')
described_class.new('1.1.+')
described_class.new('1.1.1_+')
described_class.new('1.1.1_1+')
end

it 'raises an exception when micro version is missing' do
expect { described_class.new('1.6') }.to raise_error(/Invalid/)
end
Expand All @@ -78,10 +86,6 @@
expect { described_class.new('1.6.0+') }.to raise_error(/Invalid/)
end

it 'raises an exception when qualifier version is not legal' do
expect { described_class.new('1.6.0_05+') }.to raise_error(/Invalid/)
end

it 'raises an exception when the qualifier is not letter, number, or hyphen' do
expect { described_class.new('1.6.0_?') }.to raise_error(/Invalid/)
expect { described_class.new('1.6.0__5') }.to raise_error(/Invalid/)
Expand Down Expand Up @@ -114,6 +118,7 @@
expect { described_class.new('1.+', false) }.to raise_error(/Invalid/)
expect { described_class.new('1.1.+', false) }.to raise_error(/Invalid/)
expect { described_class.new('1.1.1_+', false) }.to raise_error(/Invalid/)
expect { described_class.new('1.1.1_1+', false) }.to raise_error(/Invalid/)
end

it 'raises an exception when a version ends with a component separator' do
Expand Down

0 comments on commit df1bdf0

Please sign in to comment.