Class: Slather::Project

Inherits:
Xcodeproj::Project show all
Defined in:
lib/slather/project.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Xcodeproj::Project

#slather_setup_for_coverage

Instance Attribute Details

#binary_basenameObject

Returns the value of attribute binary_basename.



53
54
55
# File 'lib/slather/project.rb', line 53

def binary_basename
  @binary_basename
end

#binary_fileObject

Returns the value of attribute binary_file.



53
54
55
# File 'lib/slather/project.rb', line 53

def binary_file
  @binary_file
end

#build_directoryObject

Returns the value of attribute build_directory.



53
54
55
# File 'lib/slather/project.rb', line 53

def build_directory
  @build_directory
end

#ci_serviceObject

Returns the value of attribute ci_service.



53
54
55
# File 'lib/slather/project.rb', line 53

def ci_service
  @ci_service
end

#coverage_access_tokenObject

Returns the value of attribute coverage_access_token.



53
54
55
# File 'lib/slather/project.rb', line 53

def coverage_access_token
  @coverage_access_token
end

#coverage_serviceObject

Returns the value of attribute coverage_service.



53
54
55
# File 'lib/slather/project.rb', line 53

def coverage_service
  @coverage_service
end

#ignore_listObject

Returns the value of attribute ignore_list.



53
54
55
# File 'lib/slather/project.rb', line 53

def ignore_list
  @ignore_list
end

#input_formatObject

Returns the value of attribute input_format.



53
54
55
# File 'lib/slather/project.rb', line 53

def input_format
  @input_format
end

#output_directoryObject

Returns the value of attribute output_directory.



53
54
55
# File 'lib/slather/project.rb', line 53

def output_directory
  @output_directory
end

#schemeObject

Returns the value of attribute scheme.



53
54
55
# File 'lib/slather/project.rb', line 53

def scheme
  @scheme
end

#show_htmlObject

Returns the value of attribute show_html.



53
54
55
# File 'lib/slather/project.rb', line 53

def show_html
  @show_html
end

#source_directoryObject

Returns the value of attribute source_directory.



53
54
55
# File 'lib/slather/project.rb', line 53

def source_directory
  @source_directory
end

#verbose_modeObject

Returns the value of attribute verbose_mode.



53
54
55
# File 'lib/slather/project.rb', line 53

def verbose_mode
  @verbose_mode
end

#xcodeprojObject

Returns the value of attribute xcodeproj.



53
54
55
# File 'lib/slather/project.rb', line 53

def xcodeproj
  @xcodeproj
end

Class Method Details

.open(xcodeproj) ⇒ Object



58
59
60
61
62
# File 'lib/slather/project.rb', line 58

def self.open(xcodeproj)
  proj = super
  proj.xcodeproj = xcodeproj
  proj
end

.ymlObject



185
186
187
# File 'lib/slather/project.rb', line 185

def self.yml
  @yml ||= File.exist?(yml_filename) ? YAML.load_file(yml_filename) : {}
end

.yml_filenameObject



181
182
183
# File 'lib/slather/project.rb', line 181

def self.yml_filename
  '.slather.yml'
end

Instance Method Details

#configureObject



189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
# File 'lib/slather/project.rb', line 189

def configure
  configure_build_directory
  configure_ignore_list
  configure_ci_service
  configure_coverage_access_token
  configure_coverage_service
  configure_source_directory
  configure_output_directory
  configure_input_format
  configure_scheme
  configure_binary_file

  if self.verbose_mode
    puts "\nProcessing coverage file: #{profdata_file}"
    puts "Against binary file: #{self.binary_file}\n\n"
  end
end

#configure_binary_fileObject



280
281
282
283
284
# File 'lib/slather/project.rb', line 280

def configure_binary_file
  if self.input_format == "profdata"
    self.binary_file ||= self.class.yml["binary_file"] || File.expand_path(find_binary_file)
  end
end

#configure_build_directoryObject



207
208
209
# File 'lib/slather/project.rb', line 207

def configure_build_directory
  self.build_directory ||= self.class.yml["build_directory"] || derived_data_path
end

#configure_ci_serviceObject



223
224
225
# File 'lib/slather/project.rb', line 223

def configure_ci_service
  self.ci_service ||= (self.class.yml["ci_service"] || :travis_ci)
end

#configure_coverage_access_tokenObject



255
256
257
# File 'lib/slather/project.rb', line 255

def configure_coverage_access_token
  self.coverage_access_token ||= (ENV["COVERAGE_ACCESS_TOKEN"] || self.class.yml["coverage_access_token"] || "")
end

#configure_coverage_serviceObject



251
252
253
# File 'lib/slather/project.rb', line 251

def configure_coverage_service
  self.coverage_service ||= (self.class.yml["coverage_service"] || :terminal)
end

#configure_ignore_listObject



219
220
221
# File 'lib/slather/project.rb', line 219

def configure_ignore_list
  self.ignore_list ||= [(self.class.yml["ignore"] || [])].flatten
end

#configure_input_formatObject



227
228
229
# File 'lib/slather/project.rb', line 227

def configure_input_format
  self.input_format ||= self.class.yml["input_format"] || input_format
end

#configure_output_directoryObject



215
216
217
# File 'lib/slather/project.rb', line 215

def configure_output_directory
  self.output_directory ||= self.class.yml["output_directory"] if self.class.yml["output_directory"]
end

#configure_schemeObject



243
244
245
# File 'lib/slather/project.rb', line 243

def configure_scheme
  self.scheme ||= self.class.yml["scheme"] if self.class.yml["scheme"]
end

#configure_source_directoryObject



211
212
213
# File 'lib/slather/project.rb', line 211

def configure_source_directory
  self.source_directory ||= self.class.yml["source_directory"] if self.class.yml["source_directory"]
end

#find_binary_fileObject

Raises:

  • (StandardError)


286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
# File 'lib/slather/project.rb', line 286

def find_binary_file
  xctest_bundle = Dir["#{profdata_coverage_dir}/**/*.xctest"].reject { |bundle|
    bundle.include? "-Runner.app/PlugIns/"
  }.first
  raise StandardError, "No product binary found in #{profdata_coverage_dir}. Are you sure your project is setup for generating coverage files? Try `slather setup your/project.xcodeproj`" unless xctest_bundle != nil

  # Find the matching binary file
  search_for = self.binary_basename || self.class.yml["binary_basename"] || '*'
  xctest_bundle_file_directory = Pathname.new(xctest_bundle).dirname
  app_bundle = Dir["#{xctest_bundle_file_directory}/#{search_for}.app"].first
  dynamic_lib_bundle = Dir["#{xctest_bundle_file_directory}/#{search_for}.framework"].first

  if app_bundle != nil
    find_binary_file_for_app(app_bundle)
  elsif dynamic_lib_bundle != nil
    find_binary_file_for_dynamic_lib(dynamic_lib_bundle)
  else
    find_binary_file_for_static_lib(xctest_bundle)
  end
end

#find_binary_file_for_app(app_bundle_file) ⇒ Object



141
142
143
144
# File 'lib/slather/project.rb', line 141

def find_binary_file_for_app(app_bundle_file)
  app_bundle_file_name_noext = Pathname.new(app_bundle_file).basename.to_s.gsub(".app", "")
  Dir["#{app_bundle_file}/**/#{app_bundle_file_name_noext}"].first
end

#find_binary_file_for_dynamic_lib(framework_bundle_file) ⇒ Object



146
147
148
149
# File 'lib/slather/project.rb', line 146

def find_binary_file_for_dynamic_lib(framework_bundle_file)
  framework_bundle_file_name_noext = Pathname.new(framework_bundle_file).basename.to_s.gsub(".framework", "")
  "#{framework_bundle_file}/#{framework_bundle_file_name_noext}"
end

#find_binary_file_for_static_lib(xctest_bundle_file) ⇒ Object



151
152
153
154
# File 'lib/slather/project.rb', line 151

def find_binary_file_for_static_lib(xctest_bundle_file)
  xctest_bundle_file_name_noext = Pathname.new(xctest_bundle_file).basename.to_s.gsub(".xctest", "")
  Dir["#{xctest_bundle_file}/**/#{xctest_bundle_file_name_noext}"].first
end

#first_product_nameObject



107
108
109
110
111
112
# File 'lib/slather/project.rb', line 107

def first_product_name
  first_product = self.products.first
  # If name is not available it computes it using
  # the path by dropping the 'extension' of the path.
  first_product.name || remove_extension(first_product.path)
end

#profdata_coverage_dirObject

Raises:

  • (StandardError)


114
115
116
117
118
119
120
121
122
123
124
125
# File 'lib/slather/project.rb', line 114

def profdata_coverage_dir
  raise StandardError, "The specified build directory (#{self.build_directory}) does not exist" unless File.exists?(self.build_directory)
  dir = nil
  if self.scheme
    dir = Dir[File.join("#{build_directory}","/**/CodeCoverage/#{self.scheme}")].first
  else
    dir = Dir[File.join("#{build_directory}","/**/#{first_product_name}")].first
  end

  raise StandardError, "No coverage directory found. Are you sure your project is setup for generating coverage files? Try `slather setup your/project.xcodeproj`" unless dir != nil
  dir
end

#remove_extension(path) ⇒ Object



103
104
105
# File 'lib/slather/project.rb', line 103

def remove_extension(path)
  path.split(".")[0..-2].join(".")
end