Author: assaf
Date: Mon Oct 20 15:16:29 2008
New Revision: 706428
URL: http://svn.apache.org/viewvc?rev=706428&view=rev
Log:
Running buildr with no buildfile will offer to generate one from pom file or
current directory (previous behavior restored).
Added --generate command line option to explicitly generate new buildfile.
Modified:
incubator/buildr/trunk/lib/buildr/core/application.rb
incubator/buildr/trunk/lib/buildr/core/generate.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=706428&r1=706427&r2=706428&view=diff
==============================================================================
--- incubator/buildr/trunk/lib/buildr/core/application.rb (original)
+++ incubator/buildr/trunk/lib/buildr/core/application.rb Mon Oct 20 15:16:29
2008
@@ -279,6 +279,14 @@
"Environment name (e.g. development, test, production).",
lambda { |value| ENV['BUILDR_ENV'] = value }
],
+ ['--generate [PATH]',
+ "Generate buildfile from either pom.xml file or directory path.",
+ lambda { |value|
+ value ||= File.exist?('pom.xml') ? 'pom.xml' : Dir.pwd
+ raw_generate_buildfile value
+ exit
+ }
+ ],
['--libdir', '-I LIBDIR', "Include LIBDIR in the search path for
required modules.",
lambda { |value| $:.push(value) }
],
@@ -352,12 +360,36 @@
end
def find_buildfile
- buildfile, location = find_rakefile_location
+ buildfile, location = find_rakefile_location || (tty_output? &&
ask_generate_buildfile)
fail "No Buildfile found (looking for: [EMAIL PROTECTED](', ')})" if
buildfile.nil?
@rakefile = buildfile
Dir.chdir(location)
end
+ def ask_generate_buildfile
+ source = choose do |menu|
+ menu.header = "To use Buildr you need a buildfile. Do you want me to
create one?"
+ menu.choice("From Maven2 POM file") { 'pom.xml' } if
File.exist?('pom.xml')
+ menu.choice("From directory structure") { Dir.pwd }
+ menu.choice("Cancel") { }
+ end
+ if source
+ buildfile = raw_generate_buildfile(source)
+ [buildfile, File.dirname(buildfile)]
+ end
+ end
+
+ def raw_generate_buildfile(source)
+ buildfile = File.expand_path(DEFAULT_BUILDFILES.first)
+ fail "Buildfile already exists" if File.exist?(buildfile) &&
!(tty_output? && agree('Buildfile exists, overwrite?'))
+ script = File.directory?(source) ? Generate.from_directory(source) :
Generate.from_maven2_pom(source)
+ File.open buildfile, 'w' do |file|
+ file.puts script
+ end
+ puts "Created #{buildfile}" if verbose
+ buildfile
+ end
+
def raw_load_buildfile # replaces raw_load_rakefile
puts "(in #{Dir.pwd}, #{environment})" unless options.silent
load File.expand_path(@rakefile) if @rakefile && @rakefile != ''
Modified: incubator/buildr/trunk/lib/buildr/core/generate.rb
URL:
http://svn.apache.org/viewvc/incubator/buildr/trunk/lib/buildr/core/generate.rb?rev=706428&r1=706427&r2=706428&view=diff
==============================================================================
--- incubator/buildr/trunk/lib/buildr/core/generate.rb (original)
+++ incubator/buildr/trunk/lib/buildr/core/generate.rb Mon Oct 20 15:16:29 2008
@@ -20,7 +20,7 @@
module Buildr
module Generate #:nodoc:
- task "generate" do
+ task 'generate' do
script = nil
choose do |menu|
menu.header = "To use Buildr you need a buildfile. Do you want me to
create one?"
@@ -39,58 +39,58 @@
class << self
-
HEADER = "# Generated by Buildr #{Buildr::VERSION}, change to your
liking\n\n"
-
- def from_directory(root = false)
- name = File.basename(Dir.pwd)
- if root
- script = HEADER.split("\n")
- header = <<-EOF
-# Version number for this release
-VERSION_NUMBER = "1.0.0"
-# Group identifier for your projects
-GROUP = "#{name}"
-COPYRIGHT = ""
-
-# Specify Maven 2.0 remote repositories here, like this:
-repositories.remote << "http://www.ibiblio.org/maven2/"
-
-desc "The #{name.capitalize} project"
-define "#{name}" do
-
- project.version = VERSION_NUMBER
- project.group = GROUP
- manifest["Implementation-Vendor"] = COPYRIGHT
-EOF
- script += header.split("\n")
- else
- script = [ %{define "#{name}" do} ]
- end
- script << " compile.with # Add classpath dependencies" if
File.exist?("src/main/java")
- script << " resources" if File.exist?("src/main/resources")
- script << " test.compile.with # Add classpath dependencies" if
File.exist?("src/test/java")
- script << " test.resources" if File.exist?("src/test/resources")
- if File.exist?("src/main/webapp")
- script << " package(:war)"
- elsif File.exist?("src/main/java")
- script << " package(:jar)"
- end
- dirs = FileList["*"].exclude("src", "target", "report").
- select { |file| File.directory?(file) && File.exist?(File.join(file,
"src")) }
- unless dirs.empty?
- script << ""
- dirs.sort.each do |dir|
- Dir.chdir(dir) { script << from_directory.flatten.map { |line| "
" + line } << "" }
+ def from_directory(path = Dir.pwd, root = true)
+ Dir.chdir(path) do
+ name = File.basename(path)
+ if root
+ script = HEADER.split("\n")
+ header = <<-EOF
+ # Version number for this release
+ VERSION_NUMBER = "1.0.0"
+ # Group identifier for your projects
+ GROUP = "#{name}"
+ COPYRIGHT = ""
+
+ # Specify Maven 2.0 remote repositories here, like this:
+ repositories.remote << "http://www.ibiblio.org/maven2/"
+
+ desc "The #{name.capitalize} project"
+ define "#{name}" do
+
+ project.version = VERSION_NUMBER
+ project.group = GROUP
+ manifest["Implementation-Vendor"] = COPYRIGHT
+ EOF
+ script += header.split("\n")
+ else
+ script = [ %{define "#{name}" do} ]
+ end
+ script << " compile.with # Add classpath dependencies" if
File.exist?("src/main/java")
+ script << " resources" if File.exist?("src/main/resources")
+ script << " test.compile.with # Add classpath dependencies" if
File.exist?("src/test/java")
+ script << " test.resources" if File.exist?("src/test/resources")
+ if File.exist?("src/main/webapp")
+ script << " package(:war)"
+ elsif File.exist?("src/main/java")
+ script << " package(:jar)"
+ end
+ dirs = FileList["*"].exclude("src", "target", "report").
+ select { |file| File.directory?(file) &&
File.exist?(File.join(file, "src")) }
+ unless dirs.empty?
+ script << ""
+ dirs.sort.each do |dir|
+ script << from_directory(dir, false).flatten.map { |line| " " +
line } << ""
+ end
end
+ script << "end"
+ script.flatten
end
- script << "end"
- script.flatten
end
- def from_maven2_pom(root = false)
- pom = Buildr::POM.load('pom.xml')
+ def from_maven2_pom(path = 'pom.xml', root = true)
+ pom = Buildr::POM.load(path)
project = pom.project
artifactId = project['artifactId'].first
@@ -183,7 +183,7 @@
if modules
script << ""
modules.each do |mod|
- chdir(mod) { script << from_maven2_pom.flatten.map { |line| " " +
line } << "" }
+ script << from_maven2_pom(File.join(File.dirname(path), mod,
'pom.xml'), false).flatten.map { |line| " " + line } << ""
end
end
script << "end"