Skip to content

Commit

Permalink
Add support for gradle ecosystem metrics collection
Browse files Browse the repository at this point in the history
  • Loading branch information
amazimbe committed Dec 2, 2024
1 parent 59effb5 commit 221d912
Show file tree
Hide file tree
Showing 6 changed files with 193 additions and 0 deletions.
29 changes: 29 additions & 0 deletions gradle/lib/dependabot/gradle/file_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
require "dependabot/file_parsers/base"
require "dependabot/shared_helpers"
require "dependabot/gradle/version"
require "dependabot/gradle/language"
require "dependabot/gradle/package_manager"

# The best Gradle documentation is at:
# - https://docs.gradle.org/current/dsl/org.gradle.api.artifacts.dsl.
Expand Down Expand Up @@ -71,8 +73,35 @@ def self.find_includes(buildfile, dependency_files)
.filter_map { |f| dependency_files.find { |bf| bf.name == f } }
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::Gradle::PackageManager)
)
end

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

def version_catalog_dependencies(toml_file)
dependency_set = DependencySet.new
parsed_toml_file = parsed_toml_file(toml_file)
Expand Down
24 changes: 24 additions & 0 deletions gradle/lib/dependabot/gradle/language.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# typed: strong
# frozen_string_literal: true

require "sorbet-runtime"
require "dependabot/ecosystem"
require "dependabot/gradle/version"

module Dependabot
module Gradle
LANGUAGE = "jvm_languages"

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
41 changes: 41 additions & 0 deletions gradle/lib/dependabot/gradle/package_manager.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# typed: strong
# frozen_string_literal: true

require "sorbet-runtime"
require "dependabot/ecosystem"
require "dependabot/gradle/version"

module Dependabot
module Gradle
ECOSYSTEM = "gradle"
PACKAGE_MANAGER = "gradle"
SUPPORTED_GRADLE_VERSIONS = T.let([].freeze, T::Array[Dependabot::Version])

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

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

sig { params(raw_version: String).void }
def initialize(raw_version)
super(
PACKAGE_MANAGER,
Version.new(raw_version),
DEPRECATED_GRADLE_VERSIONS,
SUPPORTED_GRADLE_VERSIONS
)
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 gradle/spec/dependabot/gradle/file_parser_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1068,4 +1068,32 @@
its(:length) { is_expected.to eq(2) }
end
end

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

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

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

it "returns the correct package manager" do
expect(package_manager.name).to eq "gradle"
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 "jvm_languages"
expect(language.requirement).to be_nil
expect(language.version.to_s).to eq "NOT-AVAILABLE"
end
end
end
end
35 changes: 35 additions & 0 deletions gradle/spec/dependabot/gradle/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/gradle/language"
require "dependabot/ecosystem"
require "spec_helper"

RSpec.describe Dependabot::Gradle::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::Gradle::Version.new(version))
end
end

describe "#name" do
it "returns the name" do
expect(language.name).to eq(Dependabot::Gradle::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 gradle/spec/dependabot/gradle/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/gradle/package_manager"
require "dependabot/ecosystem"
require "spec_helper"

RSpec.describe Dependabot::Gradle::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::Gradle::Version.new(version))
end
end

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

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

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

0 comments on commit 221d912

Please sign in to comment.