Author: vborja
Date: Sun Aug 31 22:30:39 2008
New Revision: 690851
URL: http://svn.apache.org/viewvc?rev=690851&view=rev
Log:
BUILDR_142: Allow tasks to be specified as path-like arguments from the command
line
Modified:
incubator/buildr/trunk/lib/buildr/core/application.rb
incubator/buildr/trunk/lib/buildr/core/application_cli.rb
incubator/buildr/trunk/lib/buildr/core/project.rb
Modified: incubator/buildr/trunk/lib/buildr/core/application.rb
URL:
http://svn.apache.org/viewvc/incubator/buildr/trunk/lib/buildr/core/application.rb?rev=690851&r1=690850&r2=690851&view=diff
==============================================================================
--- incubator/buildr/trunk/lib/buildr/core/application.rb (original)
+++ incubator/buildr/trunk/lib/buildr/core/application.rb Sun Aug 31 22:30:39
2008
@@ -169,14 +169,42 @@
end
private :listed_gems
+ # :nodoc:
+ # Change directory to options.project if it is an existing directory.
+ # Use this method if user intends to run buildr on a different working dir.
+ # returns Dir.pwd if chdir was performed
+ def chdir_before_loading
+ if options.project && File.directory?(options.project)
+ Dir.chdir(options.project) # change dir before seaching buildfile
+ @original_dir = Dir.pwd
+ end
+ end
+ private :chdir_before_loading
+
+ # :nodo:
+ # Change directory to the basedir of project named in options.project
+ # returns Dir.pwd if chdir was performed
+ def chdir_before_tasks
+ if options.project && !File.directory?(options.project)
+ # if options.project was a project name, we chdir to it's base dir.
+ project_name = options.project.gsub(File::SEPARATOR, ':')
+ project = Buildr.project(project_name)
+ Dir.chdir(project.path_to(nil))
+ @original_dir = Dir.pwd
+ end
+ end
+ private :chdir_before_tasks
+
def run
standard_exception_handling do
+ chdir_before_loading
find_buildfile
load_gems
load_artifacts
load_tasks
load_buildfile
task('buildr:initialize').invoke
+ chdir_before_tasks
top_level
end
title, message = 'Your build has completed', "#{Dir.pwd}\nbuildr [EMAIL
PROTECTED](' ')}"
@@ -226,7 +254,8 @@
end
def find_buildfile
- here = Dir.pwd
+ here = original_dir
+ Dir.chdir(here) unless Dir.pwd == here
while ! have_rakefile
Dir.chdir('..')
if Dir.pwd == here || options.nosearch
@@ -268,6 +297,26 @@
end
private :load_tasks
+ # :nodoc:
+ # Lookup for a task using the given task_name.
+ # This method extends Rake's functionality to obtain the task for a file
path
+ # or the build task if given a project basedir.
+ def lookup(task_name, initial_scope=nil)
+ unless task = super
+ path = File.expand_path(task_name, Buildr.application.original_dir)
+ if !(task = @tasks[path]) && project =
Buildr::Project.local_projects(path).first
+ project_path = project.path_to(nil)
+ if project_path == path
+ task = @tasks[project.name + ':build']
+ else
+ project_task = path.sub(/^#{project_path}\/?/, '').gsub('/',':')
+ task = @tasks[project.name + ':' + project_task] ||
@tasks[project_task]
+ end
+ end
+ end
+ task
+ end
+
def display_prerequisites
invoke_task('buildr:initialize')
tasks.each do |task|
Modified: incubator/buildr/trunk/lib/buildr/core/application_cli.rb
URL:
http://svn.apache.org/viewvc/incubator/buildr/trunk/lib/buildr/core/application_cli.rb?rev=690851&r1=690850&r2=690851&view=diff
==============================================================================
--- incubator/buildr/trunk/lib/buildr/core/application_cli.rb (original)
+++ incubator/buildr/trunk/lib/buildr/core/application_cli.rb Sun Aug 31
22:30:39 2008
@@ -59,7 +59,9 @@
['--version', '-v', GetoptLong::NO_ARGUMENT,
'Display the program version.'],
['--environment', '-e', GetoptLong::REQUIRED_ARGUMENT,
- 'Environment name (e.g. development, test, production).']
+ 'Environment name (e.g. development, test, production).'],
+ ['--project', '-p', GetoptLong::REQUIRED_ARGUMENT,
+ 'Change to project directory before executing tasks.']
]
def collect_tasks
@@ -97,6 +99,8 @@
when '--prereqs'
options.show_prereqs = true
options.show_task_pattern = Regexp.new(value || '.')
+ when '--project'
+ options.project = value
when '--nosearch', '--quiet', '--trace'
super
end
Modified: incubator/buildr/trunk/lib/buildr/core/project.rb
URL:
http://svn.apache.org/viewvc/incubator/buildr/trunk/lib/buildr/core/project.rb?rev=690851&r1=690850&r2=690851&view=diff
==============================================================================
--- incubator/buildr/trunk/lib/buildr/core/project.rb (original)
+++ incubator/buildr/trunk/lib/buildr/core/project.rb Sun Aug 31 22:30:39 2008
@@ -337,7 +337,8 @@
def local_projects(dir = nil, &block) #:nodoc:
dir = File.expand_path(dir || Buildr.application.original_dir)
- projects = Project.projects.select { |project| project.base_dir == dir
}
+ projects = @projects ? @projects.values : []
+ projects = projects.select { |project| project.base_dir == dir }
if projects.empty? && dir != Dir.pwd && File.dirname(dir) != dir
local_projects(File.dirname(dir), &block)
elsif block