Skip to content

Commit

Permalink
Make native-mt a Maven/Gradle version type
Browse files Browse the repository at this point in the history
  • Loading branch information
greysteil committed Jul 23, 2021
1 parent f3572ce commit 15b85b2
Show file tree
Hide file tree
Showing 6 changed files with 86 additions and 17 deletions.
16 changes: 9 additions & 7 deletions gradle/lib/dependabot/gradle/update_checker/version_finder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class VersionFinder
GOOGLE_MAVEN_REPO = "https://maven.google.com"
GRADLE_PLUGINS_REPO = "https://plugins.gradle.org/m2"
KOTLIN_PLUGIN_REPO_PREFIX = "org.jetbrains.kotlin"
TYPE_SUFFICES = %w(jre android java).freeze
TYPE_SUFFICES = %w(jre android java native_mt).freeze

def initialize(dependency:, dependency_files:, credentials:,
ignored_versions:, raise_on_ignored: false,
Expand Down Expand Up @@ -258,16 +258,18 @@ def plugin_repository_details
def matches_dependency_version_type?(comparison_version)
return true unless dependency.version

current_type = dependency.version.split(/[.\-]/).
current_type = dependency.version.
gsub("native-mt", "native_mt").
split(/[.\-]/).
find do |type|
TYPE_SUFFICES.
find { |s| type.include?(s) }
TYPE_SUFFICES.find { |s| type.include?(s) }
end

version_type = comparison_version.to_s.split(/[.\-]/).
version_type = comparison_version.to_s.
gsub("native-mt", "native_mt").
split(/[.\-]/).
find do |type|
TYPE_SUFFICES.
find { |s| type.include?(s) }
TYPE_SUFFICES.find { |s| type.include?(s) }
end

current_type == version_type
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,6 @@

context "when the user has asked for a version type and it's available" do
let(:dependency_name) { "com.thoughtworks.xstream:xstream" }
let(:dependency_version) { "1.4.11.1" }

let(:maven_central_metadata_url) do
"https://repo.maven.apache.org/maven2/"\
"com/thoughtworks/xstream/xstream/maven-metadata.xml"
Expand All @@ -98,6 +96,13 @@
end
let(:dependency_version) { "1.4.11-java7" }
its([:version]) { is_expected.to eq(version_class.new("1.4.12-java7")) }

context "and the type is native-mt" do
let(:dependency_version) { "1.4.11-native-mt" }
its([:version]) do
is_expected.to eq(version_class.new("1.4.12-native-mt"))
end
end
end

context "when a version type is available that wasn't requested" do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@
<versions>
<version>1.4.11</version>
<version>1.4.11-java7</version>
<version>1.4.11-native-mt</version>
<version>1.4.11.1</version>
<version>1.4.12</version>
<version>1.4.12-java7</version>
<version>1.4.12-java11</version>
<version>1.4.12-native-mt</version>
</versions>
<lastUpdated>20200412215547</lastUpdated>
</versioning>
Expand Down
22 changes: 14 additions & 8 deletions maven/lib/dependabot/maven/update_checker/version_finder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ module Dependabot
module Maven
class UpdateChecker
class VersionFinder
TYPE_SUFFICES = %w(jre android java).freeze
TYPE_SUFFICES = %w(jre android java native_mt).freeze

def initialize(dependency:, dependency_files:, credentials:,
ignored_versions:, security_advisories:,
Expand Down Expand Up @@ -221,13 +221,19 @@ def credentials_repository_details
def matches_dependency_version_type?(comparison_version)
return true unless dependency.version

current_type =
TYPE_SUFFICES.
find { |t| dependency.version.split(/[.\-]/).include?(t) }

version_type =
TYPE_SUFFICES.
find { |t| comparison_version.to_s.split(/[.\-]/).include?(t) }
current_type = dependency.version.
gsub("native-mt", "native_mt").
split(/[.\-]/).
find do |type|
TYPE_SUFFICES.find { |s| type.include?(s) }
end

version_type = comparison_version.to_s.
gsub("native-mt", "native_mt").
split(/[.\-]/).
find do |type|
TYPE_SUFFICES.find { |s| type.include?(s) }
end

current_type == version_type
end
Expand Down
35 changes: 35 additions & 0 deletions maven/spec/dependabot/maven/update_checker/version_finder_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,41 @@
end
end

context "when the user has asked for a version type and it's available" do
let(:dependency_name) { "com.thoughtworks.xstream:xstream" }
let(:maven_central_metadata_url) do
"https://repo.maven.apache.org/maven2/"\
"com/thoughtworks/xstream/xstream/maven-metadata.xml"
end
let(:maven_central_releases) do
fixture("maven_central_metadata", "with_version_type_releases.xml")
end
let(:dependency_version) { "1.4.11-java7" }
its([:version]) { is_expected.to eq(version_class.new("1.4.12-java7")) }

context "and the type is native-mt" do
let(:dependency_version) { "1.4.11-native-mt" }
its([:version]) do
is_expected.to eq(version_class.new("1.4.12-native-mt"))
end
end
end

context "when a version type is available that wasn't requested" do
let(:dependency_name) { "com.thoughtworks.xstream:xstream" }
let(:dependency_version) { "1.4.11.1" }

let(:maven_central_metadata_url) do
"https://repo.maven.apache.org/maven2/"\
"com/thoughtworks/xstream/xstream/maven-metadata.xml"
end
let(:maven_central_releases) do
fixture("maven_central_metadata", "with_version_type_releases.xml")
end
let(:dependency_version) { "1.4.11.1" }
its([:version]) { is_expected.to eq(version_class.new("1.4.12")) }
end

context "when there are date-based versions" do
let(:dependency_version) { "3.1" }
let(:dependency_name) { "commons-collections:commons-collections" }
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<metadata>
<groupId>com.thoughtworks.xstream</groupId>
<artifactId>xstream</artifactId>
<versioning>
<latest>1.4.12-java11</latest>
<release>1.4.12-java11</release>
<versions>
<version>1.4.11</version>
<version>1.4.11-java7</version>
<version>1.4.11-native-mt</version>
<version>1.4.11.1</version>
<version>1.4.12</version>
<version>1.4.12-java7</version>
<version>1.4.12-java11</version>
<version>1.4.12-native-mt</version>
</versions>
<lastUpdated>20200412215547</lastUpdated>
</versioning>
</metadata>

0 comments on commit 15b85b2

Please sign in to comment.