Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#657] Form path for group references taking into account parent group. #661

Merged
merged 2 commits into from
Feb 14, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@
[joshdholtz](https://github.com/joshdholtz)
[#656](https://github.com/CocoaPods/CocoaPods/pull/656)

* Ensure a `GroupReference`'s path includes its parent `GroupReference`'s path.
Both `FileReference`s and `GroupReference`s only prepend the parent path if
the child has a type of `group`.
[Kesi Maduka](https://github.com/k3zi)
[#657](https://github.com/CocoaPods/Xcodeproj/issues/657)

## 1.8.0 (2019-01-25)

Expand Down
30 changes: 6 additions & 24 deletions lib/xcodeproj/workspace/file_reference.rb
Original file line number Diff line number Diff line change
@@ -1,22 +1,14 @@
require 'xcodeproj/workspace/reference'

module Xcodeproj
class Workspace
# Describes a file reference of a Workspace.
#
class FileReference
class FileReference < Reference
# @return [String] the path to the project
#
attr_reader :path

# @return [String] the type of reference to the project
#
# This can be of the following values:
# - absolute
# - group
# - container
# - developer (unsupported)
#
attr_reader :type

# @param [#to_s] path @see path
# @param [#to_s] type @see type
#
Expand Down Expand Up @@ -47,20 +39,10 @@ def hash
#
def self.from_node(xml_node)
type, path = xml_node.attribute('location').value.split(':', 2)
path = prepend_parent_path(xml_node, path)
new(path, type)
end

def self.prepend_parent_path(xml_node, path)
if !xml_node.parent.nil? && (xml_node.parent.name == 'Group')
group = GroupReference.from_node(xml_node.parent)
if !group.location.nil? && !group.location.empty?
path = '' if path.nil?
path = File.join(group.location, path)
end
if type == 'group'
path = prepend_parent_path(xml_node, path)
end

path
new(path, type)
end

# @return [REXML::Element] the XML representation of the file reference.
Expand Down
17 changes: 6 additions & 11 deletions lib/xcodeproj/workspace/group_reference.rb
Original file line number Diff line number Diff line change
@@ -1,22 +1,14 @@
require 'xcodeproj/workspace/reference'

module Xcodeproj
class Workspace
# Describes a group reference of a Workspace.
#
class GroupReference
class GroupReference < Reference
# @return [String] the name of the group
#
attr_reader :name

# @return [String] the type of reference to the project
#
# This can be of the following values:
# - absolute
# - group
# - container (only supported value)
# - developer
#
attr_reader :type

# @return [String] the location of the group on disk
#
attr_reader :location
Expand Down Expand Up @@ -55,6 +47,9 @@ def self.from_node(xml_node)
location_array = xml_node.attribute('location').value.split(':', 2)
type = location_array.first
location = location_array[1] || ''
if type == 'group'
location = prepend_parent_path(xml_node, location)
end
name = xml_node.attribute('name').value
new(name, type, location)
end
Expand Down
40 changes: 40 additions & 0 deletions lib/xcodeproj/workspace/reference.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
module Xcodeproj
class Workspace
# Describes a file/group reference of a Workspace.
#
class Reference
# @return [String] the type of reference to the project
#
# This can be of the following values:
# - absolute
# - group
# - container
# - developer (unsupported)
#
attr_reader :type

# Returns the relative path to the parent group reference (if one exists)
# prepended to the passed in path.
#
# @param [REXML::Element] xml_node
# the XML representation.
#
# @param [String] path
# the path that will be prepended to.
#
# @return [String] the extended path including the parent node's path.
#
def self.prepend_parent_path(xml_node, path)
if !xml_node.parent.nil? && (xml_node.parent.name == 'Group')
group = GroupReference.from_node(xml_node.parent)
if !group.location.nil? && !group.location.empty?
path = '' if path.nil?
path = File.join(group.location, path)
end
end

path
end
end
end
end
Loading