class Object
Public Instance Methods
collectHmapJson()
click to toggle source
# File lib/cocoapods-hmap/hmapcreate/public_hmap.rb, line 90 def collectHmapJson() podfilelock = "./Podfile.lock" podnames = readPodFile(podfilelock) hmap_content = "" for podname in podnames do hmap_item = searchPodHmapJson(podname) # delete_target_public_json(podname) if hmap_item.size == 0 next end begin hmap_content = hmap_content + "#{hmap_item},\n" rescue raise "json 解析失败" end end hmap_content = hmap_content.chomp.chop hmap_content = "{" + "\n #{hmap_content} \n" + "}" generate_public_hmap_file(hmap_content) end
delete_target_public_json(podname)
click to toggle source
生成大的Public.json以后 可以删除每个target下小的Public.json了
# File lib/cocoapods-hmap/hmapcreate/public_hmap.rb, line 72 def delete_target_public_json(podname) outputpath = File.join(Pathname.pwd,"Pods/Headers/headermap") unless Dir.exist?(outputpath) return end outputpath = File.join(outputpath,podname) unless Dir.exist?(outputpath) return end jsonpath = File.join(outputpath,"#{podname}_public" + '.json') unless File.exist?(jsonpath) return end `rm -rf #{jsonpath}` end
generate_public_hmap_file(hmap_content)
click to toggle source
# File lib/cocoapods-hmap/hmapcreate/public_hmap.rb, line 57 def generate_public_hmap_file(hmap_content) outputpath = File.join(Pathname.pwd,"Pods/Headers/headermap") unless Dir.exist?(outputpath) raise "headermap 文件夹不存在" end hmap_json_file = File.join(outputpath,"public_hmap.json") `rm -rf #{hmap_json_file}` unless File.exist?(hmap_json_file) File.open(hmap_json_file, 'w'){|file| file.write(hmap_content)} hmap_file = File.join(outputpath,"public_hmap.hmap") `rm -rf #{hmap_file}` unless File.exist?(hmap_file) `hmap convert #{hmap_json_file} #{hmap_file}` end
modifyPodXcconfig(xcconfig_file,modify_value)
click to toggle source
# File lib/cocoapods-hmap/aggregateconfig/modify_aggregate_config.rb, line 11 def modifyPodXcconfig(xcconfig_file,modify_value) text = File.read(xcconfig_file) lines = text.lines len = lines.size for i in 0..(len -1) do line = replace_xcconfig_headersearchpath(lines[i],modify_value) lines[i] = line unless line.nil? end text = lines.join() # text += "USE_HEADERMAP = false" File.open(xcconfig_file,'w'){|f| f.puts text} end
modify_aggregate_target_config(targets)
click to toggle source
# File lib/cocoapods-hmap/aggregateconfig/modify_aggregate_config.rb, line 31 def modify_aggregate_target_config(targets) #targets为主工程的target xcconfig_paths = [] default_target = '' for target_name in targets do if target_name.start_with? 'Default' default_target = target_name next end if default_target.empty? target_name = "Pods-#{target_name}" else target_name = "Pods-#{default_target}-#{target_name}" end outputpath = 'Pods' + '/Target Support Files' outputpath = File.join(outputpath,target_name) xcconfig_debug_path = File.join(outputpath,target_name + '.debug.xcconfig') xcconfig_release_path = File.join(outputpath,target_name + '.release.xcconfig') xcconfig_paths.append(xcconfig_debug_path) xcconfig_paths.append(xcconfig_release_path) end for xcconfig_name in xcconfig_paths do xcconfig_file = searchPodXcconfig(xcconfig_name) public_hmap_path = File.join(Pathname.pwd,"Pods/Headers/headermap"+"/public_hmap.hmap") modify_value = "HEADER_SEARCH_PATHS = \"#{public_hmap_path}\"" modifyPodXcconfig(xcconfig_file,modify_value) end end
modify_all_target_config(installer)
click to toggle source
# File lib/cocoapods-hmap/modifyconfig/modify_config.rb, line 60 def modify_all_target_config(installer) #修改podsproject下的target podfilelock = "./Podfile.lock" target_names = readPodFile(podfilelock) for target_name in target_names do target_hmap_path = File.join(Pathname.pwd,"Pods/Headers/headermap"+"/#{target_name}/#{target_name}.hmap") public_hmap_path = File.join(Pathname.pwd,"Pods/Headers/headermap"+"/public_hmap.hmap") modify_value = "HEADER_SEARCH_PATHS = \"#{target_hmap_path}\" \"#{public_hmap_path}\"" outputpath = File.join(Pathname.pwd,'Pods' + '/Target Support Files') outputpath = File.join(outputpath,target_name) xcconfig_debug_file = File.join(outputpath,target_name + '.xcconfig') modifyPodXcconfig(xcconfig_debug_file,modify_value) end end
readPodFile(podfileLock)
click to toggle source
# File lib/cocoapods-hmap/hmapcreate/public_hmap.rb, line 1 def readPodFile(podfileLock) raise "#{podfileLock} is invalid" unless File.exist?(podfileLock) file = open(podfileLock) pod_names = [] begin beginPodList = false for line in file do podline = line.strip() if beginPodList == false and podline.start_with? 'SPEC CHECKSUMS' beginPodList = true next end if not beginPodList next end if beginPodList and podline.size == 0 break end podline = podline.split(':') podline = podline[0].gsub('"','') if podline.start_with? '!' next end pod_names.append(podline) end rescue raise "读取过程失败" ensure file.close() end return pod_names end
replace_xcconfig_headersearchpath(line,modify_value)
click to toggle source
# File lib/cocoapods-hmap/aggregateconfig/modify_aggregate_config.rb, line 24 def replace_xcconfig_headersearchpath(line,modify_value) return nil unless line.include?"HEADER_SEARCH_PATHS" line = "#{modify_value}\n" return line end
searchPodHmapJson(podname)
click to toggle source
# File lib/cocoapods-hmap/hmapcreate/public_hmap.rb, line 35 def searchPodHmapJson(podname) outputpath = File.join(Pathname.pwd,"Pods/Headers/headermap") unless Dir.exist?(outputpath) return "" end outputpath = File.join(outputpath,podname) unless Dir.exist?(outputpath) return "" end jsonpath = File.join(outputpath,"#{podname}_public" + '.json') unless File.exist?(jsonpath) return "" end hmap_content = File.read(jsonpath) hmap_content = hmap_content.chop.reverse.chop.reverse if hmap_content.empty? return "" else return hmap_content end end
searchPodXcconfig(configname)
click to toggle source
# File lib/cocoapods-hmap/aggregateconfig/modify_aggregate_config.rb, line 3 def searchPodXcconfig(configname) xcconfig_file = configname unless File.exist?(xcconfig_file) return "" end return xcconfig_file end