Sha256: 8adf31603435bf19cbd572f67f49bea0ac39fedbb179efdb527185a510306a69

Contents?: true

Size: 1.67 KB

Versions: 1

Compression:

Stored size: 1.67 KB

Contents

require 'fileutils'
require 'xcodeproj'
require 'json'

module Slather
  class Project < Xcodeproj::Project

    attr_accessor :build_directory

    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
    private :build_directory

    def coverage_files
      Dir["#{build_directory}/**/*.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
    end
    private :coverage_files

    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 post_to_coveralls
      puts "build_directory: #{build_directory}"
      puts "gcno files:"
      puts Dir["#{build_directory}/**/*.gcno"]
      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

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
slather-0.0.23 lib/slather/project.rb