Class: Censorius::UUIDGenerator

Inherits:
Xcodeproj::Project::UUIDGenerator
  • Object
show all
Defined in:
lib/censorius.rb

Overview

The main generator class

Instance Method Summary collapse

Instance Method Details

#generate_all_paths_by_objects(projects) ⇒ Object



11
12
13
14
15
16
17
# File 'lib/censorius.rb', line 11

def generate_all_paths_by_objects(projects)
  projects.each do |project|
    generate_paths(project.root_object, project.path.basename.to_s)
    without_path = project.objects.select { |o| @paths_by_object[o].nil? }
    raise "Without paths: #{without_path}" unless without_path.empty?
  end
end

#generate_paths(object, parent_path = '') ⇒ Object

rubocop:disable Metrics/CyclomaticComplexity



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/censorius.rb', line 19

def generate_paths(object, parent_path = '') # rubocop:disable Metrics/CyclomaticComplexity
  case object
  when Xcodeproj::Project::Object::PBXProject
    generate_paths_project(object)
  when Xcodeproj::Project::Object::AbstractTarget
    generate_paths_target(object, parent_path)
  when Xcodeproj::Project::Object::PBXGroup
    generate_paths_group(object)
  when Xcodeproj::Project::Object::PBXFileReference
    generate_paths_file_reference(object)
  when Xcodeproj::Project::Object::XCConfigurationList
    generate_paths_configuration_list(object, parent_path)
  when Xcodeproj::Project::Object::XCBuildConfiguration
    generate_paths_configuration(object, parent_path)
  when Xcodeproj::Project::Object::AbstractBuildPhase
    generate_paths_phase(object, parent_path)
  when Xcodeproj::Project::Object::PBXBuildFile
    generate_paths_build_file(object, parent_path)
  when Xcodeproj::Project::Object::PBXBuildRule
    generate_paths_build_rule(object, parent_path)
  when Xcodeproj::Project::Object::PBXContainerItemProxy
    generate_paths_container_item_proxy(object, parent_path)
  when Xcodeproj::Project::Object::PBXTargetDependency
    generate_paths_target_dependency(object, parent_path)
  when Xcodeproj::Project::Object::PBXReferenceProxy
    generate_paths_reference_proxy(object, parent_path)
  when Xcodeproj::Project::Object::XCRemoteSwiftPackageReference
    generate_paths_remote_swift_package_reference(object, parent_path)
  when Xcodeproj::Project::Object::XCLocalSwiftPackageReference
    generate_paths_local_swift_package_reference(object, parent_path)
  when Xcodeproj::Project::Object::XCSwiftPackageProductDependency
    generate_paths_swift_package_product_dependency(object, parent_path)
  else
    raise "Unrecognized: #{object.class}, at: #{parent_path}"
  end

  @paths_by_object[object]
end

#generate_paths_build_file(build_file, parent_path) ⇒ Object



113
114
115
116
117
118
119
120
121
122
123
124
# File 'lib/censorius.rb', line 113

def generate_paths_build_file(build_file, parent_path)
  if build_file.file_ref
    file_ref_path = generate_paths(build_file.file_ref)
    @paths_by_object[build_file] = "#{parent_path}/PBXBuildFile(#{file_ref_path})"
  elsif build_file.product_ref
    @paths_by_object[build_file.product_ref] ||= generate_paths(dependency.product_ref, parent_path)
    product_ref_path = @paths_by_object[build_file.product_ref]
    @paths_by_object[build_file] = "#{parent_path}/PBXBuildFile(#{product_ref_path})"
  else
    raise "Unsupported: #{build_file}"
  end
end

#generate_paths_build_rule(build_rule, parent_path) ⇒ Object



126
127
128
# File 'lib/censorius.rb', line 126

def generate_paths_build_rule(build_rule, parent_path)
  @paths_by_object[build_rule] = "#{parent_path}/PBXBuildRule(#{build_rule.name})"
end

#generate_paths_configuration(configuration, parent_path) ⇒ Object



81
82
83
# File 'lib/censorius.rb', line 81

def generate_paths_configuration(configuration, parent_path)
  @paths_by_object[configuration] = "#{parent_path}/XCBuildConfiguration(#{configuration.name})"
end

#generate_paths_configuration_list(configuration_list, parent_path) ⇒ Object



74
75
76
77
78
79
# File 'lib/censorius.rb', line 74

def generate_paths_configuration_list(configuration_list, parent_path)
  @paths_by_object[configuration_list] = path = "#{parent_path}/XCConfigurationList"
  configuration_list.build_configurations.each do |config|
    generate_paths(config, path)
  end
end

#generate_paths_container_item_proxy(proxy, parent_path) ⇒ Object



165
166
167
168
169
170
171
172
# File 'lib/censorius.rb', line 165

def generate_paths_container_item_proxy(proxy, parent_path)
  params = [
    "type: #{proxy.proxy_type}",
    "containerPortal: #{proxy.container_portal_annotation.strip}",
    "remoteInfo: #{proxy.remote_info}"
  ]
  @paths_by_object[proxy] = "#{parent_path}/PBXContainerItemProxy(#{params.join(', ')})"
end

#generate_paths_file_reference(file_reference) ⇒ Object



138
139
140
141
142
143
144
145
146
147
148
149
150
# File 'lib/censorius.rb', line 138

def generate_paths_file_reference(file_reference)
  project_path = @paths_by_object[file_reference.project.root_object]
  params = []
  if !file_reference.name.nil? &&
     !file_reference.name.empty? &&
     file_reference.name != File.basename(file_reference.full_path, '.*') &&
     file_reference.name != File.basename(file_reference.full_path)
    params << "name: #{file_reference.name}"
  end
  params << file_reference.full_path.to_s

  @paths_by_object[file_reference] = "#{project_path}/PBXFileReference(#{params.join(', ')})"
end

#generate_paths_group(group) ⇒ Object



130
131
132
133
134
135
136
# File 'lib/censorius.rb', line 130

def generate_paths_group(group)
  project_path = @paths_by_object[group.project.root_object]
  @paths_by_object[group] = path = "#{project_path}/PBXGroup(#{group.hierarchy_path || '/'})"
  group.children.each do |child|
    generate_paths(child, path)
  end
end

#generate_paths_local_swift_package_reference(reference, parent_path) ⇒ Object



187
188
189
190
191
192
# File 'lib/censorius.rb', line 187

def generate_paths_local_swift_package_reference(reference, parent_path)
  params = [
    reference.relative_path
  ]
  @paths_by_object[reference] = "#{parent_path}/XCLocalSwiftPackageReference(#{params.join(', ')})"
end

#generate_paths_phase(phase, parent_path) ⇒ Object



106
107
108
109
110
111
# File 'lib/censorius.rb', line 106

def generate_paths_phase(phase, parent_path)
  @paths_by_object[phase] = path = "#{parent_path}/#{phase.class.name.split('::').last}(#{phase.display_name})"
  phase.files.each do |file|
    generate_paths(file, path)
  end
end

#generate_paths_project(project) ⇒ Object



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/censorius.rb', line 58

def generate_paths_project(project)
  @paths_by_object[project] = path = "PBXProject(#{project.name})"
  generate_paths(project.main_group, path)
  generate_paths(project.build_configuration_list, path)
  project.package_references.each do |package_reference|
    generate_paths(package_reference, path)
  end
  project.project_references.each do |ref|
    product_group = ref[:product_group]
    generate_paths(product_group, path) if product_group
  end
  project.targets.each do |target|
    generate_paths(target, path)
  end
end

#generate_paths_reference_proxy(proxy, parent_path) ⇒ Object



174
175
176
177
# File 'lib/censorius.rb', line 174

def generate_paths_reference_proxy(proxy, parent_path)
  @paths_by_object[proxy] = path = "#{parent_path}/PBXReferenceProxy(#{proxy.source_tree}/#{proxy.path})"
  generate_paths(proxy.remote_ref, path) if proxy.remote_ref
end

#generate_paths_remote_swift_package_reference(reference, parent_path) ⇒ Object



179
180
181
182
183
184
185
# File 'lib/censorius.rb', line 179

def generate_paths_remote_swift_package_reference(reference, parent_path)
  params = [
    reference.repositoryURL,
    reference.requirement
  ]
  @paths_by_object[reference] = "#{parent_path}/XCRemoteSwiftPackageReference(#{params.join(', ')})"
end

#generate_paths_swift_package_product_dependency(dependency, parent_path) ⇒ Object



194
195
196
197
198
199
200
# File 'lib/censorius.rb', line 194

def generate_paths_swift_package_product_dependency(dependency, parent_path)
  params = [
    @paths_by_object[dependency.package],
    dependency.product_name
  ]
  @paths_by_object[dependency] = "#{parent_path}/XCSwiftPackageProductDependency(#{params.join(', ')})"
end

#generate_paths_target(target, parent_path) ⇒ Object



85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/censorius.rb', line 85

def generate_paths_target(target, parent_path)
  @paths_by_object[target] = path = "#{parent_path}/#{target.class.name.split('::').last}(#{target.name})"
  if target.respond_to?(:package_product_dependencies)
    target.package_product_dependencies.each do |dependency|
      generate_paths(dependency, path)
    end
  end
  target.build_phases.each do |phase|
    generate_paths(phase, path)
  end
  if target.respond_to?(:build_rules)
    target.build_rules.each do |rule|
      generate_paths(rule, path)
    end
  end
  generate_paths(target.build_configuration_list, path)
  target.dependencies.each do |dependency|
    generate_paths(dependency, path)
  end
end

#generate_paths_target_dependency(dependency, parent_path) ⇒ Object



152
153
154
155
156
157
158
159
160
161
162
163
# File 'lib/censorius.rb', line 152

def generate_paths_target_dependency(dependency, parent_path)
  if dependency.target_proxy
    @paths_by_object[dependency] = path = "#{parent_path}/PBXTargetDependency(#{dependency.name})"
    generate_paths(dependency.target_proxy, path)
  elsif dependency.product_ref
    @paths_by_object[dependency.product_ref] ||= generate_paths(dependency.product_ref, parent_path)
    product_ref_path = @paths_by_object[dependency.product_ref]
    @paths_by_object[dependency] = "#{parent_path}/PBXTargetDependency(#{product_ref_path})"
  else
    raise "Unsupported: #{dependency}"
  end
end

#write_debug_pathsObject



202
203
204
205
206
207
208
209
210
211
# File 'lib/censorius.rb', line 202

def write_debug_paths
  return if @projects.empty?

  debug_info = @paths_by_object
               .to_a
               .map(&:last)
               .sort
  file_name = @projects.count == 1 ? File.basename(@projects.first.path, '.*') : 'multi'
  File.write("#{file_name}.txt", debug_info.join("\n"))
end