From 15b85b29d880040047df4dc962ff8bee988a5642 Mon Sep 17 00:00:00 2001 From: Grey Baker Date: Fri, 23 Jul 2021 11:19:44 -0400 Subject: [PATCH] Make native-mt a Maven/Gradle version type --- .../gradle/update_checker/version_finder.rb | 16 +++++---- .../update_checker/version_finder_spec.rb | 9 +++-- .../with_version_type_releases.xml | 2 ++ .../maven/update_checker/version_finder.rb | 22 +++++++----- .../update_checker/version_finder_spec.rb | 35 +++++++++++++++++++ .../with_version_type_releases.xml | 19 ++++++++++ 6 files changed, 86 insertions(+), 17 deletions(-) create mode 100644 maven/spec/fixtures/maven_central_metadata/with_version_type_releases.xml diff --git a/gradle/lib/dependabot/gradle/update_checker/version_finder.rb b/gradle/lib/dependabot/gradle/update_checker/version_finder.rb index dea73ea75e..a5f390b3b2 100644 --- a/gradle/lib/dependabot/gradle/update_checker/version_finder.rb +++ b/gradle/lib/dependabot/gradle/update_checker/version_finder.rb @@ -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, @@ -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 diff --git a/gradle/spec/dependabot/gradle/update_checker/version_finder_spec.rb b/gradle/spec/dependabot/gradle/update_checker/version_finder_spec.rb index b69790bd0f..772b553b03 100644 --- a/gradle/spec/dependabot/gradle/update_checker/version_finder_spec.rb +++ b/gradle/spec/dependabot/gradle/update_checker/version_finder_spec.rb @@ -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" @@ -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 diff --git a/gradle/spec/fixtures/maven_central_metadata/with_version_type_releases.xml b/gradle/spec/fixtures/maven_central_metadata/with_version_type_releases.xml index ac0be7947c..a5523d4fd6 100644 --- a/gradle/spec/fixtures/maven_central_metadata/with_version_type_releases.xml +++ b/gradle/spec/fixtures/maven_central_metadata/with_version_type_releases.xml @@ -7,10 +7,12 @@ 1.4.11 1.4.11-java7 + 1.4.11-native-mt 1.4.11.1 1.4.12 1.4.12-java7 1.4.12-java11 + 1.4.12-native-mt 20200412215547 diff --git a/maven/lib/dependabot/maven/update_checker/version_finder.rb b/maven/lib/dependabot/maven/update_checker/version_finder.rb index d25f9318ed..f2f4d636b6 100644 --- a/maven/lib/dependabot/maven/update_checker/version_finder.rb +++ b/maven/lib/dependabot/maven/update_checker/version_finder.rb @@ -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:, @@ -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 diff --git a/maven/spec/dependabot/maven/update_checker/version_finder_spec.rb b/maven/spec/dependabot/maven/update_checker/version_finder_spec.rb index 01125c4d54..5c90d746ad 100644 --- a/maven/spec/dependabot/maven/update_checker/version_finder_spec.rb +++ b/maven/spec/dependabot/maven/update_checker/version_finder_spec.rb @@ -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" } diff --git a/maven/spec/fixtures/maven_central_metadata/with_version_type_releases.xml b/maven/spec/fixtures/maven_central_metadata/with_version_type_releases.xml new file mode 100644 index 0000000000..a5523d4fd6 --- /dev/null +++ b/maven/spec/fixtures/maven_central_metadata/with_version_type_releases.xml @@ -0,0 +1,19 @@ + + com.thoughtworks.xstream + xstream + + 1.4.12-java11 + 1.4.12-java11 + + 1.4.11 + 1.4.11-java7 + 1.4.11-native-mt + 1.4.11.1 + 1.4.12 + 1.4.12-java7 + 1.4.12-java11 + 1.4.12-native-mt + + 20200412215547 + +