class Xcodeproj::Project::Object::FileReferencesFactory

def configure_defaults_for_file_reference(ref)

Returns:
  • (void) -

Other tags:
    Note: - To closely match the Xcode behaviour the name attribute of

Parameters:
  • ref (PBXFileReference) --
def configure_defaults_for_file_reference(ref)
  if ref.path.include?('/')
    ref.name = ref.path.split('/').last
  end
  if File.extname(ref.path).downcase == '.framework'
    ref.include_in_index = nil
  end
end

def find_products_group_ref(group, should_create = false)

def find_products_group_ref(group, should_create = false)
  product_group_ref =
    (group.project.root_object.product_ref_group ||= group.project.main_group.find_subpath('Products', should_create))
  product_group_ref
end

def new_bundle(group, product_name)

Returns:
  • (PBXFileReference) - The new file reference.

Parameters:
  • product_name (#to_s) --
  • group (PBXGroup) --
def new_bundle(group, product_name)
  ref = new_reference(group, "#{product_name}.bundle", :built_products)
  ref.include_in_index = '0'
  ref.set_explicit_file_type('wrapper.cfbundle')
  ref
end

def new_file_reference(group, path, source_tree)

Returns:
  • (PBXFileReference) - The new file reference.

Parameters:
  • source_tree (Symbol) --
  • path (#to_s) --
  • group (PBXGroup) --
def new_file_reference(group, path, source_tree)
  path = Pathname.new(path)
  ref = group.project.new(PBXFileReference)
  group.children << ref
  GroupableHelper.set_path_with_source_tree(ref, path, source_tree)
  ref.set_last_known_file_type
  ref
end

def new_product_ref_for_target(group, target_name, product_type)

Returns:
  • (PBXFileReference) - The new file reference.

Parameters:
  • product_name (#to_s) --
  • group (PBXGroup) --
def new_product_ref_for_target(group, target_name, product_type)
  if product_type == :static_library
    prefix = 'lib'
  end
  extension = Constants::PRODUCT_UTI_EXTENSIONS[product_type]
  ref = new_reference(group, "#{prefix}#{target_name}.#{extension}", :built_products)
  ref.include_in_index = '0'
  ref.set_explicit_file_type
  ref
end

def new_reference(group, path, source_tree)

Returns:
  • (PBXFileReference, XCVersionGroup) - The new reference.

Parameters:
  • source_tree (Symbol) --
  • path (#to_s) --
  • group (PBXGroup) --
def new_reference(group, path, source_tree)
  ref = case File.extname(path).downcase
        when '.xcdatamodeld'
          new_xcdatamodeld(group, path, source_tree)
        when '.xcodeproj'
          new_subproject(group, path, source_tree)
        else
          new_file_reference(group, path, source_tree)
        end
  configure_defaults_for_file_reference(ref)
  ref
end

def new_subproject(group, path, source_tree)

Returns:
  • (PBXFileReference) - The new file reference.

Other tags:
    Note: - To analyze the targets the given project is read and thus

Parameters:
  • source_tree (Symbol) --
  • path (#to_s) --
  • group (PBXGroup) --
def new_subproject(group, path, source_tree)
  ref = new_file_reference(group, path, source_tree)
  ref.include_in_index = nil
  product_group_ref = find_products_group_ref(group, true)
  subproj = Project.open(path)
  subproj.products_group.files.each do |product_reference|
    container_proxy = group.project.new(PBXContainerItemProxy)
    container_proxy.container_portal = ref.uuid
    container_proxy.proxy_type = Constants::PROXY_TYPES[:reference]
    container_proxy.remote_global_id_string = product_reference.uuid
    container_proxy.remote_info = 'Subproject'
    reference_proxy = group.project.new(PBXReferenceProxy)
    extension = File.extname(product_reference.path)[1..-1]
    reference_proxy.file_type = Constants::FILE_TYPES_BY_EXTENSION[extension]
    reference_proxy.path = product_reference.path
    reference_proxy.remote_ref = container_proxy
    reference_proxy.source_tree = 'BUILT_PRODUCTS_DIR'
    product_group_ref << reference_proxy
  end
  attribute = PBXProject.references_by_keys_attributes.find { |attrb| attrb.name == :project_references }
  project_reference = ObjectDictionary.new(attribute, group.project.root_object)
  project_reference[:project_ref] = ref
  project_reference[:product_group] = product_group_ref
  group.project.root_object.project_references << project_reference
  ref
end

def new_xcdatamodeld(group, path, source_tree)

Returns:
  • (XCVersionGroup) - The new reference.

Other tags:
    Note: - To match Xcode behaviour the current version is read from

Parameters:
  • source_tree (Symbol) --
  • path (#to_s) --
  • group (PBXGroup) --
def new_xcdatamodeld(group, path, source_tree)
  path = Pathname.new(path)
  ref = group.project.new(XCVersionGroup)
  group.children << ref
  GroupableHelper.set_path_with_source_tree(ref, path, source_tree)
  ref.version_group_type = 'wrapper.xcdatamodel'
  real_path = group.real_path.join(path)
  current_version_name = nil
  if real_path.exist?
    real_path.children.each do |child_path|
      if File.extname(child_path) == '.xcdatamodel'
        new_file_reference(ref, child_path, :group)
      elsif File.basename(child_path) == '.xccurrentversion'
        full_path = real_path + File.basename(child_path)
        xccurrentversion = Plist.read_from_path(full_path)
        current_version_name = xccurrentversion['_XCCurrentVersionName']
      end
    end
    if current_version_name
      ref.current_version = ref.children.find do |obj|
        obj.path.split('/').last == current_version_name
      end
    end
  end
  ref
end