lib/buildr/core/generate.rb in assaf-buildr-1.3.3 vs lib/buildr/core/generate.rb in assaf-buildr-1.3.4
- old
+ new
@@ -18,17 +18,17 @@
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?"
- menu.choice("From maven2 pom file") { script = Generate.from_maven2_pom(true).join("\n") } if File.exists?("pom.xml")
- menu.choice("From directory structure") { script = Generate.from_directory(true).join("\n") }
+ menu.choice("From maven2 pom file") { script = Generate.from_maven2_pom('pom.xml').join("\n") } if File.exists?("pom.xml")
+ menu.choice("From directory structure") { script = Generate.from_directory(Dir.pwd).join("\n") }
menu.choice("Skip") { }
end
if script
buildfile = File.expand_path(Buildr::Application::DEFAULT_BUILDFILES.first)
@@ -37,62 +37,62 @@
end
end
class << self
-
HEADER = "# Generated by Buildr #{Buildr::VERSION}, change to your liking\n\n"
+ 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 = ""
- 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/"
-# Specify Maven 2.0 remote repositories here, like this:
-repositories.remote << "http://www.ibiblio.org/maven2/"
+ desc "The #{name.capitalize} project"
+ define "#{name}" do
-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 } << "" }
+ 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
description = project['name'] || "The #{artifactId} project"
project_name = File.basename(Dir.pwd)
@@ -181,10 +181,10 @@
modules = project['modules'].first['module'] rescue nil
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"
script.flatten
end