Class: ObjectiveCi::CiTasks

Inherits:
Object
  • Object
show all
Defined in:
lib/objective_ci/ci_tasks.rb

Constant Summary collapse

LINT_DESTINATION =
"lint.xml"
DUPLICATION_DESTINATION =
"duplication.xml"
LINE_COUNT_DESTINATION =
"line-count.sc"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeCiTasks

Returns a new instance of CiTasks.



13
14
15
16
17
18
19
# File 'lib/objective_ci/ci_tasks.rb', line 13

def initialize
  @exclusions = ["vendor"]
  if using_pods?
    @exclusions << "Pods"
    `bundle exec pod install`
  end
end

Instance Attribute Details

#exclusionsObject

Returns the value of attribute exclusions.



7
8
9
# File 'lib/objective_ci/ci_tasks.rb', line 7

def exclusions
  @exclusions
end

Instance Method Details

#build(opts = {}) ⇒ Object



21
22
23
24
25
26
# File 'lib/objective_ci/ci_tasks.rb', line 21

def build(opts={})
  lint(opts)
  lines_of_code(opts)
  test_suite(opts)
  duplicate_code_detection(opts)
end

#duplicate_code_detection(opts = {}) ⇒ Object



66
67
68
69
70
71
72
73
74
75
76
# File 'lib/objective_ci/ci_tasks.rb', line 66

def duplicate_code_detection(opts={})
  opts[:minimum_tokens] ||= 100
  # Use `sed` to change paths like `/some/code/./path.m` to `/some/code/path.m`, or else the Violations plugin in Jenkins
  # doesn't work correctly.
  call_binary("pmd-cpd-objc",
              "--minimum-tokens #{opts[:minimum_tokens]}",
              "| LC_CTYPE=C LANG=C sed 's/\\/\\.\\//\\//' > #{DUPLICATION_DESTINATION}", 
              opts)
  pmd_exclude
  pmd_patch
end

#lines_of_code(opts = {}) ⇒ Object



59
60
61
62
63
64
# File 'lib/objective_ci/ci_tasks.rb', line 59

def lines_of_code(opts={})
  call_binary("sloccount",
              "--duplicates --wide --details .",
              "| grep -v #{exclusion_options_list("-e")} > #{LINE_COUNT_DESTINATION}", 
              opts)
end

#lint(opts = {}) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/objective_ci/ci_tasks.rb', line 28

def lint(opts={})
  requires_at_least_one_option(opts, :workspace, :project)
  requires_options(opts, :scheme)
  opts[:configuration] ||= "Release"

  sliced_opts = opts.select { |k, v| [:scheme, :workspace, :project, :configuration].include?(k) }
  xcodebuild_opts_string = sliced_opts.reduce("") { |str, (k, v)| str += " -#{k} #{v}" }
  xcodebuild_opts_string += " ONLY_ACTIVE_ARCH=NO clean build"

  call_binary("xcodebuild", xcodebuild_opts_string, "| tee xcodebuild.log", opts)
  # oclint-xcodebuild will fail if we don't exclude Pods (absolute path)
  pods_dir = "#{Dir.pwd}/Pods"
  call_binary("oclint-xcodebuild", "-e \"#{pods_dir}\"", "", opts)
  ocjcd_opts_string = "#{exclusion_options_list("-e")} -- -report-type=pmd -o=#{LINT_DESTINATION}"
  call_binary("oclint-json-compilation-database", ocjcd_opts_string, "", opts)
end

#test_suite(opts = {}) ⇒ Object



45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/objective_ci/ci_tasks.rb', line 45

def test_suite(opts={})
  requires_at_least_one_option(opts, :workspace, :project)
  requires_options(opts ,:scheme)
  if !opts[:xcodebuild_override] && xcode_version < 5.0
    puts_red "WARNING: Xcode version #{xcode_version} is less than 5.0, and tests will likely not run"
  end
  
  sliced_opts = opts.select { |k, v| [:scheme, :workspace, :project].include?(k) }
  xcodebuild_opts_string = sliced_opts.reduce("") { |str, (k, v)| str += " -#{k} #{v}" }

  xcodebuild_opts_string += " -destination name=iPad -destination-timeout=10 ONLY_ACTIVE_ARCH=NO test"
  call_binary("xcodebuild", xcodebuild_opts_string, ">&1 | bundle exec ocunit2junit", opts)
end