lib/slather/project.rb in slather-0.0.3 vs lib/slather/project.rb in slather-0.0.21
- old
+ new
@@ -1,96 +1,51 @@
require 'fileutils'
require 'xcodeproj'
require 'json'
-require 'yaml'
module Slather
class Project < Xcodeproj::Project
- attr_accessor :build_directory, :ignore_list, :ci_service, :coverage_service
-
- def self.open(xcodeproj)
- proj = super
- proj.configure_from_yml
- proj
- end
-
def derived_data_dir
File.expand_path('~') + "/Library/Developer/Xcode/DerivedData/"
end
private :derived_data_dir
- def build_directory
- @build_directory || derived_data_dir
- end
-
def coverage_files
- coverage_files = Dir["#{build_directory}/**/*.gcno"].map do |file|
- coverage_file = coverage_file_class.new(self, file)
- # If there's no source file for this gcno, it probably belongs to another project.
- coverage_file.source_file_pathname && !coverage_file.ignored? ? coverage_file : nil
+ Dir["#{derived_data_dir}/**/*.gcno"].map do |file|
+ coverage_file = Slather::CoverallsCoverageFile.new(file)
+ coverage_file.project = self
+ # If there's no source file for this gcno, or the gcno is old, it probably belongs to another project.
+ if coverage_file.source_file_pathname
+ stale_seconds_limit = 60
+ if (Time.now - File.mtime(file) < stale_seconds_limit)
+ next coverage_file
+ else
+ puts "Skipping #{file} -- older than #{stale_seconds_limit} seconds ago."
+ end
+ end
+ next nil
end.compact
-
- if coverage_files.empty?
- raise StandardError, "No coverage files found. Are you sure your project is setup for generating coverage files? Try `slather setup your/project.pbxproj`"
- else
- coverage_files
- end
end
private :coverage_files
- def self.yml_filename
- '.slather.yml'
+ def coveralls_coverage_data
+ {
+ :service_job_id => ENV['TRAVIS_JOB_ID'],
+ :service_name => "travis-ci",
+ :source_files => coverage_files.map(&:as_json)
+ }.to_json
end
+ private :coveralls_coverage_data
- def self.yml
- @yml ||= File.exist?(yml_filename) ? YAML.load_file(yml_filename) : {}
- end
-
- def configure_from_yml
- configure_build_directory_from_yml
- configure_ignore_list_from_yml
- configure_ci_service_from_yml
- configure_coverage_service_from_yml
- end
-
- def configure_build_directory_from_yml
- self.build_directory = self.class.yml["build_directory"] if self.class.yml["build_directory"] && !@build_directory
- end
-
- def configure_ignore_list_from_yml
- self.ignore_list = [(self.class.yml["ignore"] || [])].flatten unless self.ignore_list
- end
-
- def configure_ci_service_from_yml
- self.ci_service = (self.class.yml["ci_service"] || :travis_ci) unless self.ci_service
- end
-
- def ci_service=(service)
- @ci_service = service && service.to_sym
- end
-
- def configure_coverage_service_from_yml
- self.coverage_service = (self.class.yml["coverage_service"] || :terminal) unless coverage_service
- end
-
- def coverage_service=(service)
- service = service && service.to_sym
- if service == :coveralls
- extend(Slather::CoverageService::Coveralls)
- elsif service == :terminal
- extend(Slather::CoverageService::SimpleOutput)
- else
- raise ArgumentError, "`#{coverage_service}` is not a valid coverage service. Try `terminal` or `coveralls`"
- end
- @coverage_service = service
- end
-
- def setup_for_coverage
- build_configurations.each do |build_configuration|
- build_configuration.build_settings["GCC_INSTRUMENT_PROGRAM_FLOW_ARCS"] = "YES"
- build_configuration.build_settings["GCC_GENERATE_TEST_COVERAGE_FILES"] = "YES"
- end
+ def post_to_coveralls
+ f = File.open('coveralls_json_file', 'w+')
+ f.write(coveralls_coverage_data)
+ puts "file data!!!!!"
+ f.rewind
+ puts f.read
+ `curl -s --form json_file=@#{f.path} https://coveralls.io/api/v1/jobs`
+ FileUtils.rm(f)
end
end
end
\ No newline at end of file