Class: Dependabot::Nuget::NativeDependencyFileDiscovery

Inherits:
Object
  • Object
show all
Extended by:
T::Sig
Defined in:
lib/dependabot/nuget/native_discovery/native_dependency_file_discovery.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file_path:, dependencies:) ⇒ NativeDependencyFileDiscovery

Returns a new instance of NativeDependencyFileDiscovery.



32
33
34
35
# File 'lib/dependabot/nuget/native_discovery/native_dependency_file_discovery.rb', line 32

def initialize(file_path:, dependencies:)
  @file_path = file_path
  @dependencies = dependencies
end

Instance Attribute Details

#dependenciesObject (readonly)

Returns the value of attribute dependencies.



41
42
43
# File 'lib/dependabot/nuget/native_discovery/native_dependency_file_discovery.rb', line 41

def dependencies
  @dependencies
end

#file_pathObject (readonly)

Returns the value of attribute file_path.



38
39
40
# File 'lib/dependabot/nuget/native_discovery/native_dependency_file_discovery.rb', line 38

def file_path
  @file_path
end

Class Method Details

.from_json(json, directory) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
# File 'lib/dependabot/nuget/native_discovery/native_dependency_file_discovery.rb', line 16

def self.from_json(json, directory)
  return nil if json.nil?

  file_path = File.join(directory, T.let(json.fetch("FilePath"), String))
  dependencies = T.let(json.fetch("Dependencies"), T::Array[T::Hash[String, T.untyped]]).map do |dep|
    NativeDependencyDetails.from_json(dep)
  end

  NativeDependencyFileDiscovery.new(file_path: file_path,
                                    dependencies: dependencies)
end

Instance Method Details

#dependency_setObject

rubocop:disable Metrics/PerceivedComplexity,Metrics/CyclomaticComplexity,Metrics/AbcSize



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/dependabot/nuget/native_discovery/native_dependency_file_discovery.rb', line 44

def dependency_set # rubocop:disable Metrics/PerceivedComplexity,Metrics/CyclomaticComplexity,Metrics/AbcSize
  dependency_set = Dependabot::FileParsers::Base::DependencySet.new

  file_name = Pathname.new(file_path).cleanpath.to_path
  dependencies.each do |dependency|
    next if dependency.name.casecmp("Microsoft.NET.Sdk")&.zero?

    # If the version string was evaluated it must have been successfully resolved
    if dependency.evaluation && dependency.evaluation&.result_type != "Success"
      logger.warn "Dependency '#{dependency.name}' excluded due to unparsable version: #{dependency.version}"
      next
    end

    # Exclude any dependencies using version ranges or wildcards
    next if dependency.version&.include?(",") ||
            dependency.version&.include?("*")

    # Exclude any dependencies specified using interpolation
    next if dependency.name.include?("%(") ||
            dependency.version&.include?("%(")

    # Exclude any dependencies which reference an item type
    next if dependency.name.include?("@(")

    dependency_file_name = file_name
    if dependency.type == "PackagesConfig"
      dir_name = File.dirname(file_name)
      dependency_file_name = "packages.config"
      dependency_file_name = File.join(dir_name, "packages.config") unless dir_name == "."
    end

    dependency_set << build_dependency(dependency_file_name, dependency)
  end

  dependency_set
end