class Dependabot::Gradle::FileFetcher::SettingsFileParser

Attributes

settings_file[R]

Public Class Methods

new(settings_file:) click to toggle source
# File lib/dependabot/gradle/file_fetcher/settings_file_parser.rb, line 9
def initialize(settings_file:)
  @settings_file = settings_file
end

Public Instance Methods

subproject_paths() click to toggle source
# File lib/dependabot/gradle/file_fetcher/settings_file_parser.rb, line 13
def subproject_paths
  subprojects = []

  comment_free_content.scan(function_regex("include")) do
    args = Regexp.last_match.named_captures.fetch("args")
    args = args.split(",")
    args = args.map { |p| p.gsub(/["']/, "").strip }.compact
    subprojects += args
  end

  subprojects = subprojects.uniq

  subproject_dirs = subprojects.map do |proj|
    if comment_free_content.match?(project_dir_regex(proj))
      comment_free_content.match(project_dir_regex(proj)).
        named_captures.fetch("path").sub(%r{^/}, "")
    else
      proj.tr(":", "/").sub(%r{^/}, "")
    end
  end

  subproject_dirs.uniq
end

Private Instance Methods

comment_free_content() click to toggle source
# File lib/dependabot/gradle/file_fetcher/settings_file_parser.rb, line 41
def comment_free_content
  settings_file.content.
    gsub(%r{(?<=^|\s)//.*$}, "\n").
    gsub(%r{(?<=^|\s)/\*.*?\*/}m, "")
end
function_regex(function_name) click to toggle source
# File lib/dependabot/gradle/file_fetcher/settings_file_parser.rb, line 47
def function_regex(function_name)
  /
    (?:^|\s)#{Regexp.quote(function_name)}(?:\s*\(|\s)
    (?<args>\s*[^\s,\)]+(?:,\s*[^\s,\)]+)*)
  /mx
end
project_dir_regex(proj) click to toggle source
# File lib/dependabot/gradle/file_fetcher/settings_file_parser.rb, line 54
def project_dir_regex(proj)
  prefixed_proj = Regexp.quote(":#{proj.gsub(/^:/, '')}")
  /['"]#{prefixed_proj}['"].*dir\s*=.*['"](?<path>.*?)['"]/i
end