Class: Xcodeproj::XCodeProject
- Inherits:
-
Object
- Object
- Xcodeproj::XCodeProject
- Defined in:
- lib/core_blur/check/project.rb
Instance Attribute Summary collapse
-
#lock_content ⇒ Object
Returns the value of attribute lock_content.
-
#module_items ⇒ Object
Returns the value of attribute module_items.
-
#pod_project ⇒ Object
Returns the value of attribute pod_project.
-
#shell_project ⇒ Object
Returns the value of attribute shell_project.
-
#version_map ⇒ Object
Returns the value of attribute version_map.
Instance Method Summary collapse
- #deal_frameworks(frameworks) ⇒ Object
- #expand_module ⇒ Object
- #expand_with_module(group, module_name) ⇒ Object
- #get_podspec_path(module_name) ⇒ Object
- #init_lockfile ⇒ Object
- #init_pod_project ⇒ Object
- #init_shell_project ⇒ Object
- #init_vendor_frameworks ⇒ Object
- #init_version_map ⇒ Object
-
#initialize ⇒ XCodeProject
constructor
A new instance of XCodeProject.
- #update_dep_frameworks(item_frameworks, json_content) ⇒ Object
Constructor Details
#initialize ⇒ XCodeProject
Returns a new instance of XCodeProject.
13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/core_blur/check/project.rb', line 13 def initialize @shell_project = nil @pod_project = nil @module_items = {} @version_map = {} @lock_content = {} init_shell_project init_pod_project init_lockfile init_version_map init_vendor_frameworks end |
Instance Attribute Details
#lock_content ⇒ Object
Returns the value of attribute lock_content.
11 12 13 |
# File 'lib/core_blur/check/project.rb', line 11 def lock_content @lock_content end |
#module_items ⇒ Object
Returns the value of attribute module_items.
10 11 12 |
# File 'lib/core_blur/check/project.rb', line 10 def module_items @module_items end |
#pod_project ⇒ Object
Returns the value of attribute pod_project.
9 10 11 |
# File 'lib/core_blur/check/project.rb', line 9 def pod_project @pod_project end |
#shell_project ⇒ Object
Returns the value of attribute shell_project.
8 9 10 |
# File 'lib/core_blur/check/project.rb', line 8 def shell_project @shell_project end |
#version_map ⇒ Object
Returns the value of attribute version_map.
12 13 14 |
# File 'lib/core_blur/check/project.rb', line 12 def version_map @version_map end |
Instance Method Details
#deal_frameworks(frameworks) ⇒ Object
212 213 214 215 216 217 |
# File 'lib/core_blur/check/project.rb', line 212 def deal_frameworks(frameworks) temp_array = frameworks.split("/") result = temp_array.last result = result.gsub(".xcframework","") result.gsub(".framework", "") end |
#expand_module ⇒ Object
72 73 74 |
# File 'lib/core_blur/check/project.rb', line 72 def self.(pod_project.main_group, nil) end |
#expand_with_module(group, module_name) ⇒ Object
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 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 118 119 120 121 122 123 124 125 126 127 128 129 130 131 |
# File 'lib/core_blur/check/project.rb', line 75 def (group, module_name) if group.class != Xcodeproj::Project::Object::PBXGroup return end if not module_name and group.hierarchy_path group_hierarchy_path_array = group.hierarchy_path.split("/") module_name = group_hierarchy_path_array.size >= 3 ? group_hierarchy_path_array[2] : nil end source_file_item = @module_items[module_name] if module_name and not source_file_item source_file_item = ModuleItem.new(module_name) source_file_item.podspec_path = get_podspec_path(module_name) @module_items[module_name] = source_file_item end if source_file_item and not source_file_item.module_path and group.hierarchy_path group_hierarchy_path_array = group.hierarchy_path.split("/") if group_hierarchy_path_array.size == 3 source_file_item.module_path = group.real_path end if group_hierarchy_path_array.include?("Development Pods") source_file_item.is_development_module = true end end file_reference_class = Xcodeproj::Project::Object::PBXFileReference not_child_names = ["Podfile","Frameworks", "Products","Targets Support Files","Support Files"] source_file_extension = %w[.h .m .mm .pch .c .cc .cpp .hpp] header_file_extension = %w[.h .hpp] group.children.each {|child| module_name = source_file_item ? source_file_item.module_name : nil if not_child_names.include?(child.name) next end if child.class != file_reference_class self.(child, module_name) next end hierarchy_path_array = child.hierarchy_path.split("/") if hierarchy_path_array.size < 3 self.(child, module_name) next end if source_file_item extend_name = child.real_path.basename.extname basename = child.real_path.basename if basename.to_s == "#{module_name}.podspec" or basename.to_s == "#{module_name}.podspec.json" source_file_item.podspec_path = child.real_path elsif source_file_extension.include?(extend_name) source_file_item.source_files[child.real_path.basename.to_s] = child.real_path if header_file_extension.include?(extend_name) source_file_item.header_files[child.real_path.basename.to_s] = child.real_path end else end end self.(child, module_name) } end |
#get_podspec_path(module_name) ⇒ Object
132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 |
# File 'lib/core_blur/check/project.rb', line 132 def get_podspec_path(module_name) = lock_content["CHECKOUT OPTIONS"] if and [module_name] check_option = [module_name] request = Pod::Downloader::Request.new(released:false, name:module_name, params:check_option) slug_opts = {} cache_path = request.slug(**slug_opts) return "~/Library/Caches/CocoaPods/Pods/Specs/#{cache_path}.podspec.json" end local_spec = lock_content["EXTERNAL SOURCES"] if local_spec and local_spec[module_name] path = local_spec[module_name][:path] podspec_path = "#{path}/#{module_name}.podspec" podspec_json_path = "#{path}/#{module_name}.podspec.json" if File.exist?(podspec_path) return Pathname(podspec_path). elsif File.exist?(podspec_json_path) return Pathname(podspec_json_path). else return nil end end version_spec = @lock_content["SPEC CHECKSUMS"] md5_to5 = "" if version_spec and version_spec[module_name] md5 = version_spec[module_name] md5_to5 = md5.slice(0,5) end version = @version_map[module_name] if version podspec_json_name = "#{version}-#{md5_to5}.podspec.json" path = "~/Library/Caches/CocoaPods/Pods/Specs/Release/#{module_name}/#{podspec_json_name}" return Pathname(path). end nil end |
#init_lockfile ⇒ Object
48 49 50 51 52 53 54 |
# File 'lib/core_blur/check/project.rb', line 48 def init_lockfile lockfile_path = MyConstants::PODFILE_LOCK unless File.exist?(lockfile_path) return end @lock_content = YAML.load_file(lockfile_path) end |
#init_pod_project ⇒ Object
41 42 43 44 45 46 47 |
# File 'lib/core_blur/check/project.rb', line 41 def init_pod_project xcodeproj_path = "#{Dir.pwd}/Pods/Pods.xcodeproj" unless File.exist?(xcodeproj_path) return nil end @pod_project = Xcodeproj::Project.open(xcodeproj_path) end |
#init_shell_project ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/core_blur/check/project.rb', line 27 def init_shell_project xcodeproj_file = nil Dir.foreach(Dir.pwd) do |file| if file.end_with?(".xcodeproj") xcodeproj_file = file break end end xcodeproj_path = "#{Dir.pwd}/#{xcodeproj_file}" unless File.exist?(xcodeproj_path) return nil end @shell_project = Xcodeproj::Project.open(xcodeproj_path) end |
#init_vendor_frameworks ⇒ Object
168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 |
# File 'lib/core_blur/check/project.rb', line 168 def init_vendor_frameworks @module_items.each_value do |module_item| module_item.frameworks << module_item.module_name unless module_item.podspec_path puts "⚠️ 读取#{module_item.module_name}的podspec路径为空,请发送Podfile.lock文件联系开发者修复" next end podspec_content = Util.get_podspec_content(module_item.podspec_path) unless podspec_content next end update_dep_frameworks(module_item.frameworks, podspec_content) subspec_content = podspec_content["subspecs"] if subspec_content and subspec_content.class == Array subspec_content.each { |json_content| update_dep_frameworks(module_item.frameworks, json_content) } end end end |
#init_version_map ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/core_blur/check/project.rb', line 55 def init_version_map lock_content = @lock_content remote_dependencies = lock_content["PODS"] unless remote_dependencies return end remote_dependencies.each do |dependency| if dependency.class == Hash dependency = dependency.keys.first end temp = dependency.split("(") name = temp[0].split("/")[0] # UMCShare/Social/ReducedWeChat name = name.gsub(" ", "").gsub(")", "") version = temp[1].gsub("= ", "").gsub(")", "") @version_map[name] = version end end |
#update_dep_frameworks(item_frameworks, json_content) ⇒ Object
188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 |
# File 'lib/core_blur/check/project.rb', line 188 def update_dep_frameworks(item_frameworks, json_content) vendor_frameworks = json_content["vendored_frameworks"] unless vendor_frameworks ios = json_content["ios"] if ios and ios.class == Hash vendor_frameworks = ios["vendored_frameworks"] end end if vendor_frameworks if vendor_frameworks.class == Array vendor_frameworks.each do |vendor_framework| frameworks = deal_frameworks(vendor_framework) if frameworks != "*" item_frameworks << frameworks end end elsif vendor_frameworks.class == String frameworks = deal_frameworks(vendor_frameworks) if frameworks != "*" item_frameworks << frameworks end end end end |