Class: Danger::DangerXcodeWarnings

Inherits:
Plugin
  • Object
show all
Defined in:
lib/xcode_warnings/plugin.rb

Overview

Parse the xcodebuild log file and convert warnings.

Examples:

Parse and show xcodebuild warnings.


danger-xcode_warnings.analyze_file 'logfile'

See Also:

  • Scior/danger-xcode_warnings

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#show_build_timing_summaryvoid

This method returns an undefined value.

Whether show build timing summary or not. The default value is ‘false`.



24
25
26
# File 'lib/xcode_warnings/plugin.rb', line 24

def show_build_timing_summary
  @show_build_timing_summary
end

#show_build_warningsObject

rubocop:disable Lint/DuplicateMethods



16
17
18
# File 'lib/xcode_warnings/plugin.rb', line 16

def show_build_warnings
  @show_build_warnings
end

#show_linker_warningsvoid

This method returns an undefined value.

Whether show linker warnings or not. The default value is ‘false`.



20
21
22
# File 'lib/xcode_warnings/plugin.rb', line 20

def show_linker_warnings
  @show_linker_warnings
end

#use_xcprettyvoid

This method returns an undefined value.

Whether use xcpretty for formatting logs. The default value is ‘false`.



28
29
30
# File 'lib/xcode_warnings/plugin.rb', line 28

def use_xcpretty
  @use_xcpretty
end

Instance Method Details

#analyze(log_text, inline: true, sticky: true) ⇒ void

This method returns an undefined value.

Parses the log text from xcodebuild and show warnings.

Parameters:

  • log_text (String)

    Raw build log text.

  • inline (Boolean) (defaults to: true)

    Whether leave comments inline or not.

  • sticky (Boolean) (defaults to: true)

    Whether use sticky flag or not.



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/xcode_warnings/plugin.rb', line 56

def analyze(log_text, inline: true, sticky: true)
  if use_xcpretty
    parser = LogParserXCPretty.new
  else
    parser = LogParser.new
    parser.show_build_timing_summary = show_build_timing_summary
  end
  parser.show_build_warnings = show_build_warnings
  parser.show_linker_warnings = show_linker_warnings

  parsed = parser.parse_warnings(log_text)
  parsed.each do |warning|
    if inline
      warn(warning[:message], sticky: sticky, file: warning[:file], line: warning[:line])
    else
      warn MessageFormatter.new.format(warning)
    end
  end
  message "Detected #{parsed.count} build-time warnings." unless parsed.empty?
  message parser.parse_build_timing_summary(log_text)
end

#analyze_file(file_path, inline: false, sticky: true) ⇒ void

This method returns an undefined value.

Parses the log file from xcodebuild and show warnings.

Parameters:

  • file_path (String)

    Path for the log file.

  • inline (Boolean) (defaults to: false)

    Whether leave comments inline or not.

  • sticky (Boolean) (defaults to: true)

    Whether use sticky flag or not.



85
86
87
88
89
90
91
92
# File 'lib/xcode_warnings/plugin.rb', line 85

def analyze_file(file_path, inline: false, sticky: true)
  File.open(file_path) do |f|
    puts "Opened #{file_path}"
    analyze(f.read, inline: inline, sticky: sticky)
  end
rescue Errno::ENOENT, Errno::EACCES => e
  puts "Couldn't open the file: #{e}"
end