Commit 1546afe6 authored by Fabio Pelosin's avatar Fabio Pelosin

[FileAccessor] Include folders in resources.

parent 815f8c16
...@@ -85,7 +85,7 @@ module Pod ...@@ -85,7 +85,7 @@ module Pod
def resources def resources
result = {} result = {}
spec_consumer.resources.each do |destination, patterns| spec_consumer.resources.each do |destination, patterns|
result[destination] = expanded_paths(patterns) result[destination] = expanded_paths(patterns, {:include_dirs => true})
end end
result result
end end
...@@ -138,9 +138,11 @@ module Pod ...@@ -138,9 +138,11 @@ module Pod
# #
def paths_for_attribute(attribute) def paths_for_attribute(attribute)
file_patterns = spec_consumer.send(attribute) file_patterns = spec_consumer.send(attribute)
dir_pattern = glob_for_attribute(attribute) options = {
exclude_files = spec_consumer.exclude_files :exclude_patterns => spec_consumer.exclude_files,
expanded_paths(file_patterns, dir_pattern, exclude_files) :dir_pattern => glob_for_attribute(attribute)
}
expanded_paths(file_patterns, options)
end end
# Returns the pattern to use to glob a directory for an attribute. # Returns the pattern to use to glob a directory for an attribute.
...@@ -150,7 +152,7 @@ module Pod ...@@ -150,7 +152,7 @@ module Pod
# #
# @return [String] the glob pattern. # @return [String] the glob pattern.
# #
# @todo move to the cocoapods-core so it appears in the docs? # @todo Move to the cocoapods-core so it appears in the docs?
# #
def glob_for_attribute(attrbute) def glob_for_attribute(attrbute)
globs = { globs = {
...@@ -178,14 +180,14 @@ module Pod ...@@ -178,14 +180,14 @@ module Pod
# #
# @todo Implement case insensitive search # @todo Implement case insensitive search
# #
def expanded_paths(patterns, dir_pattern = nil, exclude_patterns = nil) def expanded_paths(patterns, options = {})
return [] if patterns.empty? return [] if patterns.empty?
file_lists = patterns.select { |p| p.is_a?(FileList) } file_lists = patterns.select { |p| p.is_a?(FileList) }
glob_patterns = patterns - file_lists glob_patterns = patterns - file_lists
result = [] result = []
result << path_list.glob(glob_patterns, dir_pattern, exclude_patterns) result << path_list.glob(glob_patterns, options)
result << file_lists.map do |file_list| result << file_lists.map do |file_list|
file_list.prepend_patterns(path_list.root) file_list.prepend_patterns(path_list.root)
file_list.glob file_list.glob
......
...@@ -65,8 +65,8 @@ module Pod ...@@ -65,8 +65,8 @@ module Pod
# @return [Array<Pathname>] Similar to {glob} but returns the absolute # @return [Array<Pathname>] Similar to {glob} but returns the absolute
# paths. # paths.
# #
def glob(patterns, dir_pattern = nil, exclude_patterns = nil) def glob(patterns, options = {})
relative_glob(patterns, dir_pattern, exclude_patterns).map {|p| root + p } relative_glob(patterns, options).map {|p| root + p }
end end
# @return [Array<Pathname>] The list of relative paths that are case # @return [Array<Pathname>] The list of relative paths that are case
...@@ -80,20 +80,30 @@ module Pod ...@@ -80,20 +80,30 @@ module Pod
# An optional pattern to append to a pattern, if it is the path # An optional pattern to append to a pattern, if it is the path
# to a directory. # to a directory.
# #
def relative_glob(patterns, dir_pattern = nil, exclude_patterns = nil) def relative_glob(patterns, options = {})
return [] if patterns.empty? return [] if patterns.empty?
dir_pattern = options[:dir_pattern]
exclude_patterns = options[:exclude_patterns]
include_dirs = options[:include_dirs]
if include_dirs
full_list = files + dirs
else
full_list = files
end
list = Array(patterns).map do |pattern| list = Array(patterns).map do |pattern|
if pattern.is_a?(String) if pattern.is_a?(String)
pattern += '/' + dir_pattern if directory?(pattern) && dir_pattern pattern += '/' + dir_pattern if directory?(pattern) && dir_pattern
expanded_patterns = dir_glob_equivalent_patterns(pattern) expanded_patterns = dir_glob_equivalent_patterns(pattern)
files.select do |path| full_list.select do |path|
expanded_patterns.any? do |p| expanded_patterns.any? do |p|
File.fnmatch(p, path, File::FNM_CASEFOLD | File::FNM_PATHNAME) File.fnmatch(p, path, File::FNM_CASEFOLD | File::FNM_PATHNAME)
end end
end end
else else
files.select { |path| path.match(pattern) } full_list.select { |path| path.match(pattern) }
end end
end.flatten end.flatten
......
...@@ -70,9 +70,10 @@ module Pod ...@@ -70,9 +70,10 @@ module Pod
end end
it "returns the resources" do it "returns the resources" do
@accessor.resources.should == { @accessor.resources[:resources].sort.should == [
:resources => [ @root + "Resources/logo-sidebar.png" ] @root + "Resources/logo-sidebar.png",
} @root + "Resources/sub_dir",
]
end end
it "returns the preserve path" do it "returns the preserve path" do
...@@ -113,10 +114,12 @@ module Pod ...@@ -113,10 +114,12 @@ module Pod
it "takes into account dir patterns and excluded files" do it "takes into account dir patterns and excluded files" do
file_patterns = ["Classes/*.{h,m}", "Vendor"] file_patterns = ["Classes/*.{h,m}", "Vendor"]
dir_pattern = "*.{h,hpp,hh,m,mm,c,cpp}" options = {
exclude_files = ["Classes/**/osx/**/*", "Resources/**/osx/**/*"] :exclude_patterns => ["Classes/**/osx/**/*", "Resources/**/osx/**/*"],
@spec.exclude_files = exclude_files :dir_pattern => "*.{h,hpp,hh,m,mm,c,cpp}"
@accessor.expects(:expanded_paths).with(file_patterns, dir_pattern, exclude_files) }
@spec.exclude_files = options[:exclude_patterns]
@accessor.expects(:expanded_paths).with(file_patterns, options)
@accessor.send(:paths_for_attribute, :source_files) @accessor.send(:paths_for_attribute, :source_files)
end end
......
...@@ -22,6 +22,7 @@ module Pod ...@@ -22,6 +22,7 @@ module Pod
Classes/BananaPrivate.h Classes/BananaPrivate.h
README README
Resources/logo-sidebar.png Resources/logo-sidebar.png
Resources/sub_dir/logo-sidebar.png
preserve_me.txt preserve_me.txt
sub-dir/sub-dir-2/somefile.txt sub-dir/sub-dir-2/somefile.txt
] ]
...@@ -34,7 +35,7 @@ module Pod ...@@ -34,7 +35,7 @@ module Pod
dirs.reject! do |f| dirs.reject! do |f|
f.include?('libPusher') || f.include?('.git') f.include?('libPusher') || f.include?('.git')
end end
dirs.sort.should == %w| Classes Resources sub-dir sub-dir/sub-dir-2 | dirs.sort.should == %w| Classes Resources Resources/sub_dir sub-dir sub-dir/sub-dir-2 |
end end
end end
...@@ -42,8 +43,6 @@ module Pod ...@@ -42,8 +43,6 @@ module Pod
#-------------------------------------------------------------------------# #-------------------------------------------------------------------------#
describe "Globbing" do describe "Globbing" do
it "can glob the root for a given pattern" do it "can glob the root for a given pattern" do
paths = @path_list.relative_glob('Classes/*.{h,m}').map(&:to_s) paths = @path_list.relative_glob('Classes/*.{h,m}').map(&:to_s)
paths.sort.should == %w[ paths.sort.should == %w[
...@@ -53,6 +52,16 @@ module Pod ...@@ -53,6 +52,16 @@ module Pod
] ]
end end
it "can return the absolute paths from glob" do
paths = @path_list.glob('Classes/*.{h,m}')
paths.all? { |p| p.absolute? }.should == true
end
it "can return the relative paths from glob" do
paths = @path_list.relative_glob('Classes/*.{h,m}')
paths.any? { |p| p.absolute? }.should == false
end
it "supports the `**` glob pattern" do it "supports the `**` glob pattern" do
paths = @path_list.relative_glob('Classes/**/*.{h,m}').map(&:to_s) paths = @path_list.relative_glob('Classes/**/*.{h,m}').map(&:to_s)
paths.sort.should == %w[ paths.sort.should == %w[
...@@ -63,7 +72,7 @@ module Pod ...@@ -63,7 +72,7 @@ module Pod
end end
it "supports an optional pattern for globbing directories" do it "supports an optional pattern for globbing directories" do
paths = @path_list.relative_glob('Classes', '*.{h,m}').map(&:to_s) paths = @path_list.relative_glob('Classes', { :dir_pattern => '*.{h,m}'} ).map(&:to_s)
paths.sort.should == %w[ paths.sort.should == %w[
Classes/Banana.h Classes/Banana.h
Classes/Banana.m Classes/Banana.m
...@@ -73,22 +82,21 @@ module Pod ...@@ -73,22 +82,21 @@ module Pod
it "supports an optional list of patterns to exclude" do it "supports an optional list of patterns to exclude" do
exclude_patterns = ['**/*.m', '**/*Private*.*'] exclude_patterns = ['**/*.m', '**/*Private*.*']
paths = @path_list.relative_glob('Classes/*', nil, exclude_patterns).map(&:to_s) paths = @path_list.relative_glob('Classes/*', { :exclude_patterns => exclude_patterns }).map(&:to_s)
paths.sort.should == %w[ paths.sort.should == %w[
Classes/Banana.h Classes/Banana.h
Classes/BananaLib.pch Classes/BananaLib.pch
] ]
end end
it "can return the absolute paths from glob" do it "can optionally include the directories in the results" do
paths = @path_list.glob('Classes/*.{h,m}') paths = @path_list.relative_glob('Resources/*', { :include_dirs => true }).map(&:to_s)
paths.all? { |p| p.absolute? }.should == true paths.sort.should == %w[
Resources/logo-sidebar.png
Resources/sub_dir
]
end end
it "can return the relative paths from glob" do
paths = @path_list.relative_glob('Classes/*.{h,m}')
paths.any? { |p| p.absolute? }.should == false
end
end end
#-------------------------------------------------------------------------# #-------------------------------------------------------------------------#
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment