lib/core/project.rb in buildr-0.21.0 vs lib/core/project.rb in buildr-0.22.0
- old
+ new
@@ -159,16 +159,21 @@
@projects[name].tap { |project| project.invoke }
end
# See Buildr#projects.
def projects(*names) #:nodoc:
+ options = names.pop if Hash === names.last
@projects ||= {}
- if names.empty?
- @projects.keys.map { |name| project(name) }.sort_by(&:name)
+ names = @projects.keys if names.empty?
+ if options && options[:in]
+ parent = @projects[options[:in].to_s] or raise "No such project #{options[:in].to_s}"
+ names.uniq.map { |name| @projects[name] or raise "No such project #{name}" }.
+ select { |project| project.parent == parent }.
+ each { |project| project.invoke }.sort_by(&:name)
else
- names.map { |name| project(name) or raise "No such project #{name}" }.uniq.sort_by(&:name)
- end
+ names.uniq.map { |name| project(name) or raise "No such project #{name}" }.sort_by(&:name)
+ end
end
# :call-seq:
# clear()
#
@@ -323,22 +328,24 @@
#
# Returns a path from a combination of name, relative to the project's base directory.
# Essentially, joins all the supplied names and expands the path relative to #base_dir.
# Symbol arguments are converted to paths by calling the attribute accessor on the project.
#
- # For example:
+ # Keep in mind that all tasks are defined and executed relative to the Rakefile directory,
+ # so you want to use #path_to to get the actual path within the project as a matter of practice.
#
# For example:
# path_to("foo", "bar")
# => /home/project1/foo/bar
# path_to("/tmp")
# => /tmp
- # path_to(:base_dir, "foo")
+ # path_to(:base_dir, "foo") # same as path_to("foo")
# => /home/project1/foo
def path_to(*names)
File.expand_path(File.join(names.map { |name| Symbol === name ? send(name) : name.to_s }), base_dir)
end
+ alias :_ :path_to
# :call-seq:
# define(name, properties?) { |project| ... } => project
#
# Define a new sub-project within this project. See Buildr#define.
@@ -380,16 +387,12 @@
#
# puts project("foo:bar").file("src").to_s
# => "/home/foo/bar/src"
def file(args, &block)
task_name, deps = Rake.application.resolve_args(args)
- unless task = Rake.application.lookup(task_name, [])
- task = Rake::FileTask.define_task(File.expand_path(task_name, base_dir))
- task.base_dir = base_dir
- end
deps = [deps] unless deps.respond_to?(:to_ary)
- task.enhance deps, &block
+ Rake::FileTask.define_task(path_to(task_name)=>deps, &block)
end
# :call-seq:
# task(name) => Task
# task(name=>prereqs) => Task
@@ -443,25 +446,18 @@
# Define a recursive task. A recursive task executes itself and the same task
# in all the sub-projects.
def recursive_task(args, &block)
task_name, deps = Rake.application.resolve_args(args)
deps = [deps] unless deps.respond_to?(:to_ary)
- task(task_name=>deps).tap do |task|
- if parent
- Rake.application.lookup(task_name, parent.name.split(":")).enhance [task]
- #Rake::Task["^#{name}"].enhance([ task ])
- end
- task.enhance &block
- end
+ task = ENV["PARALLEL"] =~ /(yes|on|true)/ ? multitask(task_name) : task(task_name)
+ Rake.application.lookup(task_name, parent.name.split(":")).enhance [task] if parent
+ task.enhance deps, &block
end
def execute() #:nodoc:
# Reset the namespace, so all tasks are automatically defined in the project's namespace.
- Rake.application.in_namespace ":#{name}" do
- # Everything we do inside the project is relative to its working directory.
- Dir.chdir(base_dir) { super }
- end
+ Rake.application.in_namespace(":#{name}") { super }
end
end
# :call-seq:
@@ -534,21 +530,26 @@
Project.project(name)
end
# :call-seq:
# projects(*names) => projects
+ # projects(:in=>parent) => projects
#
# With no arguments, returns a list of all projects defined so far. With arguments,
# returns a list of these projects, fails on undefined projects.
#
# Like #project, this method evaluates the definition of each project before returning it.
# Be advised of circular dependencies.
#
+ # Use the :in option if you only want the sub-projects of a given parent project.
+ #
# For example:
# files = projects.map { |prj| FileList[prj.path_to("src/**/*.java") }.flatten
# puts "There are #{files.size} source files in #{projects.size} projects"
#
- # puts projects("project1", "project2").map(&:base_dir)
+ # puts projects("myapp:beans", "myapp:webapp").map(&:name)
+ # Same as:
+ # puts projects(:in=>"mayapp").map(&:name)
def projects(*names)
Project.projects *names
end
# Add project definition tests.