Class: XcodeBuilder::Configuration

Inherits:
OpenStruct
  • Object
show all
Defined in:
lib/xcode_builder/configuration.rb

Instance Method Summary collapse

Instance Method Details

#app_bundle_pathObject



159
160
161
# File 'lib/xcode_builder/configuration.rb', line 159

def app_bundle_path
  "#{package_destination_path}/#{app_name}.app"
end

#app_file_nameObject

Raises:

  • (ArgumentError)


37
38
39
40
# File 'lib/xcode_builder/configuration.rb', line 37

def app_file_name
  raise ArgumentError, "app_name or target must be set in the BetaBuilder configuration block" if app_name.nil?
  "#{app_name}.app"
end

#build_argumentsObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/xcode_builder/configuration.rb', line 13

def build_arguments
  args = []
  if workspace_file_path
    raise "A scheme is required if building from a workspace" unless scheme
    args << "-workspace '#{workspace_file_path}'"
    args << "-scheme '#{scheme}'"
  else
    args << "-target '#{target}'"
    args << "-project '#{project_file_path}'" if project_file_path
  end

  args << "-sdk iphoneos"
  
  args << "-configuration '#{configuration}'"
  args << "BUILD_DIR=\"#{File.expand_path build_dir}\""
  
  if xcodebuild_extra_args
      args.concat xcodebuild_extra_args if xcodebuild_extra_args.is_a? Array
      args << "#{xcodebuild_extra_args}" if xcodebuild_extra_args.is_a? String
  end
  
  args
end

#build_numberObject



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/xcode_builder/configuration.rb', line 50

def build_number
  # we have a podspec file, so try to get the version out of that
  if (podspec_file != nil)  && (File.exists? podspec_file) then
    # get hte version out of the pod file
    return build_number_from_podspec
  end

  # no plist is found, return a nil version
  if (info_plist_path == nil)  || (!File.exists? info_plist_path) then
    return nil
  end

  # read the plist and extract data
  plist = CFPropertyList::List.new(:file => info_plist_path)
  data = CFPropertyList.native_types(plist.value)
  data["CFBundleShortVersionString"]
end

#build_number_from_podspecObject



68
69
70
71
72
73
74
75
76
77
78
# File 'lib/xcode_builder/configuration.rb', line 68

def build_number_from_podspec
  file = File.open(podspec_file, "r")
  begin
    version_line = file.gets
  end while version_line.eql? "\n"

  if match = version_line.match(/\s*version\s*=\s*["'](.*)["']\s*/i) 
    version = match.captures
  end
  return version[0]
end

#built_app_long_version_suffixObject



143
144
145
146
147
148
149
# File 'lib/xcode_builder/configuration.rb', line 143

def built_app_long_version_suffix
  if build_number == nil then
    ""
  else 
    "-#{build_number}"
  end
end

#built_app_pathObject



151
152
153
# File 'lib/xcode_builder/configuration.rb', line 151

def built_app_path
  File.join("#{build_dir}", "#{configuration}-iphoneos", "#{app_file_name}")
end

#deploy_using(strategy_name, &block) ⇒ Object



163
164
165
166
167
168
169
170
# File 'lib/xcode_builder/configuration.rb', line 163

def deploy_using(strategy_name, &block)
  if DeploymentStrategies.valid_strategy?(strategy_name.to_sym)
    self.deployment_strategy = DeploymentStrategies.build(strategy_name, self)
    self.deployment_strategy.configure(&block)
  else
    raise "Unknown deployment strategy '#{strategy_name}'."
  end
end

#increment_pod_numberObject



93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
# File 'lib/xcode_builder/configuration.rb', line 93

def increment_pod_number
  if !increment_plist_version then
    return false
  end

  if podspec_file == nil then
    return false
  end

  # keep the old build number around
  old_build_number = build_number

  # bump the spec version and save it
  spec_content = File.open(podspec_file, "r").read
  old_version = "version = '#{old_build_number}'"
  new_version = "version = '#{next_build_number}'"

  spec_content = spec_content.sub old_version, new_version

  File.open(podspec_file, "w") {|f|
    f.write spec_content
  }

  true
end

#info_plist_pathObject



42
43
44
45
46
47
48
# File 'lib/xcode_builder/configuration.rb', line 42

def info_plist_path
  if info_plist != nil then 
    File.expand_path info_plist
  else 
    nil
  end
end

#ipa_nameObject



138
139
140
141
# File 'lib/xcode_builder/configuration.rb', line 138

def ipa_name
  prefix = app_name == nil ? target : app_name
  "#{prefix}#{built_app_long_version_suffix}.ipa"
end

#ipa_pathObject



155
156
157
# File 'lib/xcode_builder/configuration.rb', line 155

def ipa_path
  File.join(File.expand_path(package_destination_path), ipa_name)
end

#next_build_numberObject



80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/xcode_builder/configuration.rb', line 80

def next_build_number
  # if we don't have a current version, we don't have a next version :)
  if build_number == nil then
    return nil
  end

  # get a hold on the build number and increment it
  version_components = build_number.split(".")
  new_build_number = version_components.pop.to_i + 1
  version_components.push new_build_number.to_s
  version_components.join "."
end

#release_notes_textObject



8
9
10
11
# File 'lib/xcode_builder/configuration.rb', line 8

def release_notes_text
  return release_notes.call if release_notes.is_a? Proc
  release_notes
end

#release_using(strategy_name, &block) ⇒ Object



172
173
174
175
176
177
178
179
180
# File 'lib/xcode_builder/configuration.rb', line 172

def release_using(strategy_name, &block)
  if ReleaseStrategies.valid_strategy?(strategy_name.to_sym)
    self.release_strategy = ReleaseStrategies.build(strategy_name, self)
    self.release_strategy.configure(&block)
    self.release_strategy.prepare
  else
    raise "Unknown release strategy '#{strategy_name}'."
  end
end

#timestamp_plistObject



119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
# File 'lib/xcode_builder/configuration.rb', line 119

def timestamp_plist
  if info_plist == nil then
    return false
  end

  # read the plist and extract data
  plist = CFPropertyList::List.new(:file => info_plist_path)
  data = CFPropertyList.native_types(plist.value)

  # re inject new version number into the data
  data["CFBundleVersion"] = DateTime.now.strftime("%Y-%m-%d %k:%M")

  # recreate the plist and save it
  plist.value = CFPropertyList.guess(data)
  plist.save(info_plist_path, CFPropertyList::List::FORMAT_XML)
end