Skip to content

Commit

Permalink
Add support for centralized package manager & language abstraction fo… (
Browse files Browse the repository at this point in the history
#10929)

* Add support for centralized package manager & language abstraction for maven

* Use NOT-APPLICABLE for unknown info

* Fix failing file parser ecosystem tests
  • Loading branch information
amazimbe authored Nov 15, 2024
1 parent 1c65ca1 commit 938cbb9
Show file tree
Hide file tree
Showing 6 changed files with 203 additions and 0 deletions.
29 changes: 29 additions & 0 deletions maven/lib/dependabot/maven/file_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
require "dependabot/file_parsers"
require "dependabot/file_parsers/base"
require "dependabot/maven/version"
require "dependabot/maven/language"
require "dependabot/maven/package_manager"
require "dependabot/errors"

# The best Maven documentation is at:
Expand Down Expand Up @@ -44,8 +46,35 @@ def parse
dependency_set.dependencies
end

sig { returns(Ecosystem) }
def ecosystem
@ecosystem ||= T.let(
Ecosystem.new(
name: ECOSYSTEM,
package_manager: package_manager,
language: language
),
T.nilable(Ecosystem)
)
end

private

sig { returns(Ecosystem::VersionManager) }
def package_manager
@package_manager ||= T.let(
PackageManager.new("NOT-AVAILABLE"),
T.nilable(Dependabot::Maven::PackageManager)
)
end

sig { returns(T.nilable(Ecosystem::VersionManager)) }
def language
@language ||= T.let(begin
Language.new("NOT-AVAILABLE")
end, T.nilable(Dependabot::Maven::Language))
end

sig { params(pom: Dependabot::DependencyFile).returns(DependencySet) }
def pomfile_dependencies(pom)
dependency_set = DependencySet.new
Expand Down
25 changes: 25 additions & 0 deletions maven/lib/dependabot/maven/language.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# typed: strong
# frozen_string_literal: true

require "sorbet-runtime"
require "dependabot/ecosystem"
require "dependabot/maven/version"
require "dependabot/maven/requirement"

module Dependabot
module Maven
LANGUAGE = "java"

class Language < Dependabot::Ecosystem::VersionManager
extend T::Sig

sig { params(raw_version: String).void }
def initialize(raw_version)
super(
LANGUAGE,
Version.new(raw_version)
)
end
end
end
end
50 changes: 50 additions & 0 deletions maven/lib/dependabot/maven/package_manager.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# typed: strong
# frozen_string_literal: true

require "sorbet-runtime"
require "dependabot/ecosystem"
require "dependabot/maven/version"
require "dependabot/maven/requirement"

module Dependabot
module Maven
ECOSYSTEM = "maven"
PACKAGE_MANAGER = "maven"

# Supported versions specified here: https://maven.apache.org/docs/history.html
SUPPORTED_MAVEN_VERSIONS = T.let([Version.new("3")].freeze, T::Array[Dependabot::Version])

# When a version is going to be unsupported, it will be added here
DEPRECATED_MAVEN_VERSIONS = T.let([].freeze, T::Array[Dependabot::Version])

class PackageManager < Dependabot::Ecosystem::VersionManager
extend T::Sig

sig do
params(
raw_version: String,
requirement: T.nilable(Requirement)
).void
end
def initialize(raw_version, requirement = nil)
super(
PACKAGE_MANAGER,
Version.new(raw_version),
DEPRECATED_MAVEN_VERSIONS,
SUPPORTED_MAVEN_VERSIONS,
requirement,
)
end

sig { returns(T::Boolean) }
def deprecated?
false
end

sig { returns(T::Boolean) }
def unsupported?
false
end
end
end
end
28 changes: 28 additions & 0 deletions maven/spec/dependabot/maven/file_parser_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1064,5 +1064,33 @@
end
end
end

describe "#ecosystem" do
subject(:ecosystem) { parser.ecosystem }

it "has the correct name" do
expect(ecosystem.name).to eq "maven"
end

describe "#package_manager" do
subject(:package_manager) { ecosystem.package_manager }

it "returns the correct package manager" do
expect(package_manager.name).to eq "maven"
expect(package_manager.requirement).to be_nil
expect(package_manager.version.to_s).to eq "NOT-AVAILABLE"
end
end

describe "#language" do
subject(:language) { ecosystem.language }

it "returns the correct language" do
expect(language.name).to eq "java"
expect(language.requirement).to be_nil
expect(language.version.to_s).to eq "NOT-AVAILABLE"
end
end
end
end
end
35 changes: 35 additions & 0 deletions maven/spec/dependabot/maven/language_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# typed: false
# frozen_string_literal: true

require "dependabot/maven/language"
require "dependabot/ecosystem"
require "spec_helper"

RSpec.describe Dependabot::Maven::Language do
let(:language) { described_class.new(version) }
let(:version) { "3.0.0" }

describe "#version" do
it "returns the version" do
expect(language.version).to eq(Dependabot::Maven::Version.new(version))
end
end

describe "#name" do
it "returns the name" do
expect(language.name).to eq(Dependabot::Maven::LANGUAGE)
end
end

describe "#unsupported?" do
it "returns false by default" do
expect(language.unsupported?).to be false
end
end

describe "#deprecated?" do
it "returns false by default" do
expect(language.deprecated?).to be false
end
end
end
36 changes: 36 additions & 0 deletions maven/spec/dependabot/maven/package_manager_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# typed: false
# frozen_string_literal: true

require "dependabot/maven/package_manager"
require "dependabot/ecosystem"
require "spec_helper"

RSpec.describe Dependabot::Maven::PackageManager do
subject(:package_manager) { described_class.new(version) }

let(:version) { "3.9.5" }

describe "#version" do
it "returns the version" do
expect(package_manager.version).to eq(Dependabot::Maven::Version.new(version))
end
end

describe "#name" do
it "returns the name" do
expect(package_manager.name).to eq(Dependabot::Maven::PACKAGE_MANAGER)
end
end

describe "#deprecated_versions" do
it "returns deprecated versions" do
expect(package_manager.deprecated_versions).to eq(Dependabot::Maven::DEPRECATED_MAVEN_VERSIONS)
end
end

describe "#supported_versions" do
it "returns supported versions" do
expect(package_manager.supported_versions).to eq(Dependabot::Maven::SUPPORTED_MAVEN_VERSIONS)
end
end
end

0 comments on commit 938cbb9

Please sign in to comment.