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

[FileAccessor] Include folders in resources.

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