Module: XCTestRunner::SchemeManager

Included in:
XCTestRunner
Defined in:
lib/xctest-runner/scheme-manager.rb

Constant Summary collapse

TEMP_SCHEME =
'XCTestRunnerTemp'
TEMP_SCHEME_NAME =
"#{TEMP_SCHEME}.xcscheme"
BUILD_ACTION_TAG =
'Scheme/BuildAction'
BUILD_ACTION_ENTRY_TAG =
'Scheme/BuildAction/BuildActionEntries/BuildActionEntry'
TEST_REFERENCE_TAG =
'Scheme/TestAction/Testables/TestableReference/BuildableReference'

Instance Method Summary collapse

Instance Method Details

#add_build_action_entry_to(doc) ⇒ Object



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/xctest-runner/scheme-manager.rb', line 58

def add_build_action_entry_to(doc)
  buildable_reference = doc.get_elements(TEST_REFERENCE_TAG).first
  return false unless buildable_reference
  build_action = doc.get_elements(BUILD_ACTION_TAG).first
  return false unless build_action
  entries = build_action.add_element('BuildActionEntries')
  attributes = {
    'buildForTesting' => 'YES',
    'buildForRunning' => 'YES',
    'buildForProfiling' => 'NO',
    'buildForArchiving' => 'NO',
    'buildForAnalyzing' => 'NO',
  }
  entry = entries.add_element('BuildActionEntry', attributes)
  entry.add_element(buildable_reference.name, buildable_reference.attributes)
  true
end

#copy_xcscheme_if_need(scheme) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
# File 'lib/xctest-runner/scheme-manager.rb', line 20

def copy_xcscheme_if_need(scheme)
  return nil unless scheme
  scheme_path = scheme_path_for(scheme)
  return nil unless scheme_path
  find_xml_need_to_be_updated(scheme_path) do |doc|
    temp_scheme_path = File.dirname(scheme_path) << "/#{TEMP_SCHEME_NAME}"
    write_xml(doc, temp_scheme_path)
    return temp_scheme_path
  end
  nil
end

#find_xml_need_to_be_updated(scheme_path, &block) ⇒ Object



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/xctest-runner/scheme-manager.rb', line 42

def find_xml_need_to_be_updated(scheme_path, &block)
  need_to_be_updated = false
  doc = REXML::Document.new(File.open(scheme_path))
  if doc.get_elements(BUILD_ACTION_ENTRY_TAG).empty?
    need_to_be_updated = add_build_action_entry_to(doc)
  else
    doc.elements.each(BUILD_ACTION_ENTRY_TAG) do |element|
      if element.attributes['buildForTesting'] != element.attributes['buildForRunning']
        element.attributes['buildForRunning'] = element.attributes['buildForTesting']
        need_to_be_updated = true
      end
    end
  end
  block.call(doc) if need_to_be_updated
end

#remove_scheme(path) ⇒ Object



83
84
85
# File 'lib/xctest-runner/scheme-manager.rb', line 83

def remove_scheme(path)
  File.unlink(path)
end

#scheme_path_for(scheme) ⇒ Object



32
33
34
35
36
37
38
39
40
# File 'lib/xctest-runner/scheme-manager.rb', line 32

def scheme_path_for(scheme)
  expect = "/#{scheme}.xcscheme"
  Find.find('.') do |path|
    if path.end_with? expect
      return path
    end
  end
  nil
end

#temp_schemeObject



16
17
18
# File 'lib/xctest-runner/scheme-manager.rb', line 16

def temp_scheme
  TEMP_SCHEME
end

#write_xml(doc, path) ⇒ Object



76
77
78
79
80
81
# File 'lib/xctest-runner/scheme-manager.rb', line 76

def write_xml(doc, path)
  File.open(path, 'w') do |f|
    f.sync = true
    f.write(doc)
  end
end