lib/core/generate.rb in buildr-1.2.3 vs lib/core/generate.rb in buildr-1.2.4
- old
+ new
@@ -1,5 +1,7 @@
+require 'java/pom'
+
module Buildr
module Generate #:nodoc:
task "generate" do
script = nil
@@ -74,17 +76,18 @@
def from_maven2_pom(root = false)
pom = Buildr::POM.load('pom.xml')
project = pom.project
- artifactId = project['artifactId']
+ artifactId = project['artifactId'].first
description = project['name'] || "The #{artifactId} project"
+ project_name = File.basename(Dir.pwd)
if root
script = HEADER.split("\n")
- settings_file = ENV["m2_settings"] || File.join(Gem::user_home, ".m2/settings.xml")
+ settings_file = ENV["M2_SETTINGS"] || File.join(Gem::user_home, ".m2/settings.xml")
settings = XmlSimple.xml_in(IO.read(settings_file)) if File.exists?(settings_file)
if settings
proxy = settings['proxies'].first['proxy'].find { |proxy|
proxy["active"].nil? || proxy["active"].to_s =~ /true/
@@ -95,35 +98,34 @@
exclude = proxy["nonProxyHosts"].to_s.gsub("|", ",") if proxy["nonProxyHosts"]
script << "options.proxy.http = '#{url}'"
script << "options.proxy.exclude << '#{exclude}'" if exclude
script << ''
# In addition, we need to use said proxies to download artifacts.
- options.proxy.http = url
- options.proxy.exclude << exclude if exclude
+ Buildr.options.proxy.http = url
+ Buildr.options.proxy.exclude << exclude if exclude
end
end
repositories = project["repositories"].first["repository"].select { |repository|
legacy = repository["layout"].to_s =~ /legacy/
!legacy
} rescue nil
- unless repositories.nil? || repositories.empty?
- repositories.each do |repository|
- name, url = repository["name"], repository["url"]
- script << "# #{name}"
- script << "repositories.remote << '#{url}'"
- # In addition we need to use said repositores to download artifacts.
- Buildr.repositories.remote << url.to_s
- end
- script << ""
+ repositories = [{"name" => "Standard maven2 repository", "url" => "http://www.ibiblio.org/maven2/"}] if repositories.nil? || repositories.empty?
+ repositories.each do |repository|
+ name, url = repository["name"], repository["url"]
+ script << "# #{name}"
+ script << "repositories.remote << '#{url}'"
+ # In addition we need to use said repositores to download artifacts.
+ Buildr.repositories.remote << url.to_s
end
+ script << ""
else
script = []
end
script << "desc '#{description}'"
- script << "define '#{artifactId}' do"
+ script << "define '#{project_name}' do"
groupId = project['groupId']
script << " project.group = '#{groupId}'" if groupId
version = project['version']
@@ -138,22 +140,32 @@
script << " compile.options.source = '#{source}'" if source
script << " compile.options.target = '#{target}'" if target
end
- dependencies = pom.dependencies.map{|d| "'#{d}'"}.join(', ')
+ compile_dependencies = pom.dependencies
+ dependencies = compile_dependencies.sort.map{|d| "'#{d}'"}.join(', ')
script << " compile.with #{dependencies}" unless dependencies.empty?
- test_dependencies = pom.dependencies(['test']).map{|d| "'#{d}'"}.join(', ')
- script << " test.compile.with #{test_dependencies}" unless test_dependencies.empty?
+ test_dependencies = (pom.dependencies(['test']) - compile_dependencies).reject{|d| d =~ /^junit:junit:jar:/ }
+ #check if we have testng
+ use_testng = test_dependencies.find{|d| d =~ /^org.testng:testng:jar:/}
+ if use_testng
+ script << " test.using :testng"
+ test_dependencies = pom.dependencies(['test']).reject{|d| d =~ /^org.testng:testng:jar:/ }
+ end
+ test_dependencies = test_dependencies.sort.map{|d| "'#{d}'"}.join(', ')
+ script << " test.with #{test_dependencies}" unless test_dependencies.empty?
+
packaging = project['packaging'].first
if %w(jar war).include?(packaging)
script << " package :#{packaging}, :id => '#{artifactId}'"
end
modules = project['modules'].first['module'] rescue nil
if modules
+ script << ""
modules.each do |mod|
chdir(mod) { script << from_maven2_pom.flatten.map { |line| " " + line } << "" }
end
end
script << "end"