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
29
30
# File 'lib/xcov/manager.rb', line 15

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

  # Set project options
  if !Xcov.config[:is_swift_package]
    FastlaneCore::Project.detect_projects(options)
    Xcov.project = FastlaneCore::Project.new(options)
  end

  # 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



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
96
97
98
99
100
101
# File 'lib/xcov/manager.rb', line 44

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.empty?
    extension = Xcov.config[:legacy_support] ? "xccoverage" : "xccovreport"
    
    test_logs_path = derived_data_path + "Logs/Test/"
    UI.important("Derived content from #{Dir["#{test_logs_path}/*"]}")
    
    xccoverage_files = Dir["#{test_logs_path}*.#{extension}", "#{test_logs_path}*.xcresult/*/action.#{extension}"]
    if xccoverage_files.empty?
      xcresult_paths = Dir["#{test_logs_path}*.xcresult"]
      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
  # Merge .xccovreports if multiple exists and return merged report
  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]
  xccoverage_files = xccoverage_files.sort_by {|filename| File.mtime(filename)}.reverse
  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



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

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