module Buildr module Generate #:nodoc: task "generate" do script = Generate.from_directory(true).join("\n") buildfile = File.expand_path("buildfile") File.open(buildfile, "w") { |file| file.write script } puts "Created #{buildfile}" end class << self def from_directory(root = false) name = File.basename(Dir.pwd) if root header = <<-EOF # Generated by Buildr #{Buildr::VERSION}, change to your liking # Version number for this release VERSION_NUMBER = "1.0.0" # Version number for the next release NEXT_VERSION = "1.0.1" # 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 } << "" } end end script << "end" script.flatten end end end end