Class: Xcov::Manager

Inherits:
Object
  • Object
show all
Defined in:
lib/xcov/manager.rb

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Manager

Returns a new instance of Manager.



15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/xcov/manager.rb', line 15

def initialize(options)
  # Set command options
  Xcov.config = options

  # Set project options
  FastlaneCore::Project.detect_projects(options)
  Xcov.project = FastlaneCore::Project.new(options)

  # Set ignored files handler
  Xcov.ignore_handler = IgnoreHandler.new

  # Print summary
  FastlaneCore::PrintTable.print_values(config: options, hide_keys: [:slack_url, :coveralls_repo_token], title: "Summary for xcov #{Xcov::VERSION}")
end

Instance Method Details

#parse_xccoverageObject



42
43
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/xcov/manager.rb', line 42

def parse_xccoverage
  xccoverage_files = []

  # xcresults to parse and export after collecting
  xcresults_to_parse_and_export = []

  # Find .xccoverage file
  # If no xccov direct path, use the old derived data path method
  if xccov_file_direct_paths.nil?
    extension = Xcov.config[:legacy_support] ? "xccoverage" : "xccovreport"
    test_logs_path = derived_data_path + "Logs/Test/"
    xccoverage_files = Dir["#{test_logs_path}*.#{extension}", "#{test_logs_path}*.xcresult/*/action.#{extension}"].sort_by { |filename| File.mtime(filename) }.reverse

    if xccoverage_files.empty?
      xcresult_paths = Dir["#{test_logs_path}*.xcresult"].sort_by { |filename| File.mtime(filename) }.reverse
      xcresult_paths.each do |xcresult_path|
        xcresults_to_parse_and_export << xcresult_path
      end
    end

    unless test_logs_path.directory?
      ErrorHandler.handle_error("XccoverageFileNotFound")
    end
  else
    # Iterate over direct paths and find .xcresult files
    # that need to be processed before getting coverage
    xccov_file_direct_paths.each do |path|
      if File.extname(path) == '.xcresult'
        xcresults_to_parse_and_export << path
      else
        xccoverage_files << path
      end
    end
  end

  # Iterates over xcresults
  # Exports .xccovarchives
  # Exports .xccovreports and collects the paths
  unless xcresults_to_parse_and_export.empty?
    xccoverage_files = process_xcresults!(xcresults_to_parse_and_export)
  end

  # Errors if no coverage files were found
  if xccoverage_files.empty?
    ErrorHandler.handle_error("XccoverageFileNotFound")
  end

  # Convert .xccoverage file to json
  ide_foundation_path = Xcov.config[:legacy_support] ? nil : Xcov.config[:ideFoundationPath]
  json_report = Xcov::Core::Parser.parse(xccoverage_files.first, Xcov.config[:output_directory], ide_foundation_path)
  ErrorHandler.handle_error("UnableToParseXccoverageFile") if json_report.nil?

  json_report
end

#runObject



30
31
32
33
34
35
36
37
38
39
40
# File 'lib/xcov/manager.rb', line 30

def run
  # Run xcov
  json_report = parse_xccoverage
  report = generate_xcov_report(json_report)
  validate_report(report)
  submit_to_coveralls(report)
  tmp_dir = File.join(Xcov.config[:output_directory], 'tmp')
  FileUtils.rm_rf(tmp_dir) if File.directory?(tmp_dir)

  json_report
end