Class: TestCenter::Helper::MultiScanManager::ReportCollator

Inherits:
Object
  • Object
show all
Defined in:
lib/fastlane/plugin/test_center/helper/multi_scan_manager/report_collator.rb

Constant Summary collapse

CollateJunitReportsAction =
Fastlane::Actions::CollateJunitReportsAction
CollateHtmlReportsAction =
Fastlane::Actions::CollateHtmlReportsAction
CollateJsonReportsAction =
Fastlane::Actions::CollateJsonReportsAction
CollateTestResultBundlesAction =
Fastlane::Actions::CollateTestResultBundlesAction
CollateXcresultsAction =
Fastlane::Actions::CollateXcresultsAction

Instance Method Summary collapse

Constructor Details

#initialize(params) ⇒ ReportCollator

Returns a new instance of ReportCollator.



17
18
19
20
21
22
23
24
25
# File 'lib/fastlane/plugin/test_center/helper/multi_scan_manager/report_collator.rb', line 17

def initialize(params)
  FastlaneCore::UI.verbose("ReportCollator.initialize with ':source_reports_directory_glob' of \"#{params[:source_reports_directory_glob]}\"")
  @source_reports_directory_glob = params[:source_reports_directory_glob]
  @output_directory = params[:output_directory]
  @reportnamer = params[:reportnamer]
  @scheme = params[:scheme]
  @result_bundle = params[:result_bundle]
  @suffix = params[:suffix] || ''
end

Instance Method Details

#collateObject



27
28
29
30
31
32
33
34
# File 'lib/fastlane/plugin/test_center/helper/multi_scan_manager/report_collator.rb', line 27

def collate
  FastlaneCore::UI.verbose("ReportCollator collating")
  collate_junit_reports
  collate_html_reports
  collate_json_reports
  collate_test_result_bundles
  collate_xcresult_bundles
end

#collate_html_reportsObject



76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/fastlane/plugin/test_center/helper/multi_scan_manager/report_collator.rb', line 76

def collate_html_reports
  return unless @reportnamer.includes_html?

  report_files = sort_globbed_files("#{@source_reports_directory_glob}/#{@reportnamer.html_fileglob}")
  collated_file = File.absolute_path(File.join(@output_directory, @reportnamer.html_reportname(@suffix)))
  if report_files.size > 1
    FastlaneCore::UI.verbose("Collating html report files #{report_files}")
    config = create_config(
      CollateJunitReportsAction,
      {
        reports: report_files,
        collated_report: collated_file
      }
    )
    CollateHtmlReportsAction.run(config)
    FileUtils.rm_rf(report_files - [collated_file])
  elsif report_files.size == 1 && ! File.identical?(report_files.first, collated_file)
    FastlaneCore::UI.verbose("Copying html report file #{report_files.first}")
    FileUtils.mkdir_p(File.dirname(collated_file))
    FileUtils.mv(report_files.first, collated_file)
  end
end

#collate_json_reportsObject



99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
# File 'lib/fastlane/plugin/test_center/helper/multi_scan_manager/report_collator.rb', line 99

def collate_json_reports
  return unless @reportnamer.includes_json?

  report_files = sort_globbed_files("#{@source_reports_directory_glob}/#{@reportnamer.json_fileglob}")
  collated_file = File.absolute_path(File.join(@output_directory, @reportnamer.json_reportname(@suffix)))
  if report_files.size > 1
    FastlaneCore::UI.verbose("Collating json report files #{report_files}")
    config = create_config(
      CollateJsonReportsAction,
      {
        reports: report_files,
        collated_report: collated_file
      }
    )
    CollateJsonReportsAction.run(config)
    FileUtils.rm_rf(report_files - [collated_file])
  elsif report_files.size == 1 && ! File.identical?(report_files.first, collated_file)
    FastlaneCore::UI.verbose("Copying json report file #{report_files.first}")
    FileUtils.mkdir_p(File.dirname(collated_file))
    FileUtils.mv(report_files.first, collated_file)
  end
end

#collate_junit_reportsObject

:nocov:



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/fastlane/plugin/test_center/helper/multi_scan_manager/report_collator.rb', line 54

def collate_junit_reports
  glob = "#{@source_reports_directory_glob}/#{@reportnamer.junit_fileglob}"
  report_files = sort_globbed_files(glob)
  collated_file =  File.absolute_path(File.join(@output_directory, @reportnamer.junit_reportname(@suffix)))
  if report_files.size > 1
    FastlaneCore::UI.verbose("Collating junit report files #{report_files}")
    config = create_config(
      CollateJunitReportsAction,
      {
        reports: report_files,
        collated_report: collated_file
      }
    )
    CollateJunitReportsAction.run(config)
    FileUtils.rm_rf(report_files - [collated_file])
  elsif report_files.size == 1 && ! File.identical?(report_files.first, collated_file)
    FastlaneCore::UI.verbose("Copying junit report file #{report_files.first}")
    FileUtils.mkdir_p(File.dirname(collated_file))
    FileUtils.mv(report_files.first, collated_file)
  end
end

#collate_test_result_bundlesObject



122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
# File 'lib/fastlane/plugin/test_center/helper/multi_scan_manager/report_collator.rb', line 122

def collate_test_result_bundles
  return unless @result_bundle

  test_result_bundlepaths = sort_globbed_files("#{@source_reports_directory_glob}/#{@scheme}*.test_result")
  result_bundlename_suffix = ''
  result_bundlename_suffix = "-#{@reportnamer.report_count}" if @reportnamer.report_count > 0
  collated_test_result_bundlepath = File.absolute_path("#{File.join(@output_directory, @scheme)}#{result_bundlename_suffix}.test_result")
  if test_result_bundlepaths.size > 1
    FastlaneCore::UI.verbose("Collating test_result bundles #{test_result_bundlepaths}")
    config = create_config(
      CollateTestResultBundlesAction,
      {
        bundles: test_result_bundlepaths,
        collated_bundle: collated_test_result_bundlepath
      }
    )
    CollateTestResultBundlesAction.run(config)
    FileUtils.rm_rf(test_result_bundlepaths - [collated_test_result_bundlepath])
  elsif test_result_bundlepaths.size == 1 && File.realdirpath(test_result_bundlepaths.first) != File.realdirpath(collated_test_result_bundlepath)
    FastlaneCore::UI.verbose("Copying test_result bundle from #{test_result_bundlepaths.first} to #{collated_test_result_bundlepath}")
    FileUtils.mkdir_p(File.dirname(collated_test_result_bundlepath))
    FileUtils.mv(test_result_bundlepaths.first, collated_test_result_bundlepath)
  end
end

#collate_xcresult_bundlesObject



147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
# File 'lib/fastlane/plugin/test_center/helper/multi_scan_manager/report_collator.rb', line 147

def collate_xcresult_bundles
  return unless @reportnamer.includes_xcresult?

  test_xcresult_bundlepaths = sort_globbed_files("#{@source_reports_directory_glob}/#{@reportnamer.xcresult_fileglob}")
  xcresult_bundlename_suffix = ''
  xcresult_bundlename_suffix = "-#{@reportnamer.report_count}" if @reportnamer.report_count > 0
  collated_xcresult_bundlepath = File.absolute_path("#{File.join(@output_directory, @reportnamer.xcresult_bundlename(@suffix))}")
  if test_xcresult_bundlepaths.size > 1
    FastlaneCore::UI.verbose("Collating xcresult bundles #{test_xcresult_bundlepaths}")
    config = create_config(
      CollateXcresultsAction,
      {
        xcresults: test_xcresult_bundlepaths,
        collated_xcresult: collated_xcresult_bundlepath
      }
    )
    CollateXcresultsAction.run(config)
    FileUtils.rm_rf(test_xcresult_bundlepaths - [collated_xcresult_bundlepath])
  elsif test_xcresult_bundlepaths.size == 1 && File.realdirpath(test_xcresult_bundlepaths.first.downcase) != File.realdirpath(collated_xcresult_bundlepath.downcase)
    FastlaneCore::UI.verbose("Copying xcresult bundle from #{test_xcresult_bundlepaths.first} to #{collated_xcresult_bundlepath}")
    FileUtils.mkdir_p(File.dirname(collated_xcresult_bundlepath))
    FileUtils.mv(test_xcresult_bundlepaths.first, collated_xcresult_bundlepath)
  end
end

#create_config(klass, options) ⇒ Object

:nocov:



49
50
51
# File 'lib/fastlane/plugin/test_center/helper/multi_scan_manager/report_collator.rb', line 49

def create_config(klass, options)
  FastlaneCore::Configuration.create(klass.available_options, options)
end

#delete_globbed_intermediatefiles(glob) ⇒ Object



43
44
45
46
# File 'lib/fastlane/plugin/test_center/helper/multi_scan_manager/report_collator.rb', line 43

def delete_globbed_intermediatefiles(glob)
  retried_reportfiles = Dir.glob(glob)
  FileUtils.rm_f(retried_reportfiles)
end

#sort_globbed_files(glob) ⇒ Object



36
37
38
39
40
41
# File 'lib/fastlane/plugin/test_center/helper/multi_scan_manager/report_collator.rb', line 36

def sort_globbed_files(glob)
  files = Dir.glob(glob).map do |relative_filepath|
    File.absolute_path(relative_filepath)
  end
  files.sort! { |f1, f2| File.mtime(f1) <=> File.mtime(f2) }
end