diff --git a/maven/lib/dependabot/maven/file_parser.rb b/maven/lib/dependabot/maven/file_parser.rb index ee3ce5128bb..6dfee68bab6 100644 --- a/maven/lib/dependabot/maven/file_parser.rb +++ b/maven/lib/dependabot/maven/file_parser.rb @@ -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: @@ -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 diff --git a/maven/lib/dependabot/maven/language.rb b/maven/lib/dependabot/maven/language.rb new file mode 100644 index 00000000000..3978ff1b768 --- /dev/null +++ b/maven/lib/dependabot/maven/language.rb @@ -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 diff --git a/maven/lib/dependabot/maven/package_manager.rb b/maven/lib/dependabot/maven/package_manager.rb new file mode 100644 index 00000000000..6a79199937a --- /dev/null +++ b/maven/lib/dependabot/maven/package_manager.rb @@ -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 diff --git a/maven/spec/dependabot/maven/file_parser_spec.rb b/maven/spec/dependabot/maven/file_parser_spec.rb index c88f47813ab..07d8534ecbd 100644 --- a/maven/spec/dependabot/maven/file_parser_spec.rb +++ b/maven/spec/dependabot/maven/file_parser_spec.rb @@ -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 diff --git a/maven/spec/dependabot/maven/language_spec.rb b/maven/spec/dependabot/maven/language_spec.rb new file mode 100644 index 00000000000..707ea05c142 --- /dev/null +++ b/maven/spec/dependabot/maven/language_spec.rb @@ -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 diff --git a/maven/spec/dependabot/maven/package_manager_spec.rb b/maven/spec/dependabot/maven/package_manager_spec.rb new file mode 100644 index 00000000000..c2f68a8c0eb --- /dev/null +++ b/maven/spec/dependabot/maven/package_manager_spec.rb @@ -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