Class: Dependabot::Gradle::FileFetcher::SettingsFileParser

Inherits:
Object
  • Object
show all
Defined in:
lib/dependabot/gradle/file_fetcher/settings_file_parser.rb

Constant Summary collapse

INCLUDE_ARGS_REGEX =
/(?:^|\s)include(?:\(|\s)(\s*[^\s,\)]+(?:,\s*[^\s,\)]+)*)/.freeze

Instance Method Summary collapse

Constructor Details

#initialize(settings_file:) ⇒ SettingsFileParser

Returns a new instance of SettingsFileParser.



12
13
14
# File 'lib/dependabot/gradle/file_fetcher/settings_file_parser.rb', line 12

def initialize(settings_file:)
  @settings_file = settings_file
end

Instance Method Details

#subproject_pathsObject



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/dependabot/gradle/file_fetcher/settings_file_parser.rb', line 16

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