buildr 1.2.3 → 1.2.4

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG CHANGED
@@ -1,7 +1,24 @@
1
+ 1.2.4 (8/3/2007)
2
+ * Added: Forking option for JUnit test framework: :once to fork for each project, :each to fork for each test case, and false to not fork. (Tammo van Lessen)
3
+ * Added: Path traversal in Zip, so zip.path("foo/bar").path("..") returns zip.path("foo").
4
+ * Fixed: JUnit test framework output shows errors in console, more readable when forking is on (Tammo van Lessen).
5
+ * Fixed: Cobertura reports not working (Anatol Pomozov).
6
+ * Fixed: Zip creates funky directory name when using :as (Tommy Mason).
7
+ * Fixed: package_as_tar incorrectly calling with(options) (Tommy Mason).
8
+ * Fixed: Loading of everything which should get rid of "already initialized constant VERSION" warning.
9
+ * Fixed: --requires option now works properly when using buildr.
10
+ * Fixed: MANIFEST.MF lines must not be longer than 72 characters (Tommy Mason).
11
+ * Fixed: Creating manifest from array does not place Name first.
12
+ * Fixed: Complain if no remote repositories defined, add at least one repository when creating from POM, POM reader fails if dependencyManagement missing (Jean-Baptiste Quenot).
13
+ * Fixed: Not looking for buildfile in parent directory.
14
+ * Fixed: Project's compile/test task looking for options in local task of same name.
15
+ * Fixed: ZIP/JAR/WAR include directory entries in some cases and not others.
16
+ * Fixed: Computation of relative paths in Eclipse project generation (Cameron Pope)
17
+
1
18
  1.2.3 (7/26/2007)
2
- * Added: Get your buildfile created form existing POM, just run buildr on existing Maven project (Anatol Pomozov).
19
+ * Added: Get your buildfile created form existing POM, just run buildr on existing Maven project (Anatol Pomozov).
3
20
  * Added: package(:tar), package(:tgz), TarballTask dn TarTask (Tommy Knowlton).
4
- * Changed: The ArchiveTask needs no introduction: it's a base task that provides common functionality for ZipTask, TarTask and friends.
21
+ * Changed: The ArchiveTask needs no introduction: it's a base task that provides common functionality for ZipTask, TarTask and friends.
5
22
  * Fixed: Release runs buildr instead of buildr.cmd on Windows (Chris Power).
6
23
  * Fixed: Cobertura reports broken (Anatol Pomozov).
7
24
 
data/lib/buildr.rb CHANGED
@@ -24,159 +24,25 @@ require "builder"
24
24
 
25
25
 
26
26
  module Buildr
27
- VERSION = "1.2.3".freeze
27
+ VERSION = "1.2.4".freeze # unless const_defined?(:VERSION)
28
28
  end
29
29
 
30
+ # Now it's safe to load Buildr, after we set up the Rake Application.
31
+ require "core/application"
32
+ require "core/project"
33
+ require "core/build"
34
+ require "core/help"
35
+ require "core/generate"
30
36
 
31
- # When running from +rake+, we already have an Application setup and must plug into it,
32
- # since the top-level tasks come from there. When running from +buildr+, we get to load
33
- # Rake and set everything up, and we use our own Application full of cool Buildr features.
34
- unless defined?(Rake)
35
- require "rake"
36
-
37
- module Buildr
38
- class Application < Rake::Application #:nodoc:
39
-
40
- DEFAULT_BUILDFILES = ["buildfile", "Buildfile"] + DEFAULT_RAKEFILES
41
-
42
- OPTIONS = [ # :nodoc:
43
- ['--help', '-H', GetoptLong::NO_ARGUMENT,
44
- "Display this help message."],
45
- ['--nosearch', '-N', GetoptLong::NO_ARGUMENT,
46
- "Do not search parent directories for the buildfile."],
47
- ['--quiet', '-q', GetoptLong::NO_ARGUMENT,
48
- "Do not log messages to standard output."],
49
- ['--buildfile', '-f', GetoptLong::OPTIONAL_ARGUMENT,
50
- "Use FILE as the buildfile."],
51
- ['--require', '-r', GetoptLong::REQUIRED_ARGUMENT,
52
- "Require MODULE before executing buildfile."],
53
- ['--trace', '-t', GetoptLong::NO_ARGUMENT,
54
- "Turn on invoke/execute tracing, enable full backtrace."],
55
- ['--verbose', '-v', GetoptLong::NO_ARGUMENT,
56
- "Log message to standard output (default)."],
57
- ['--version', '-V', GetoptLong::NO_ARGUMENT,
58
- "Display the program version."],
59
- ['--freeze', "-F", GetoptLong::NO_ARGUMENT,
60
- "Freezes the Buildfile so it always uses Buildr version #{Buildr::VERSION}"],
61
- ['--unfreeze', "-U", GetoptLong::NO_ARGUMENT,
62
- "Unfreezes the Buildfile to use the latest version of Buildr"]
63
- ]
64
-
65
- def initialize()
66
- super
67
- @rakefiles = DEFAULT_BUILDFILES
68
- @name = "Buildr"
69
- opts = GetoptLong.new(*command_line_options)
70
- opts.each { |opt, value| do_option(opt, value) }
71
- collect_tasks
72
- end
73
-
74
- def run()
75
- standard_exception_handling do
76
- load_buildfile
77
- top_level
78
- end
79
- end
80
-
81
- def do_option(opt, value)
82
- case opt
83
- when '--help'
84
- help
85
- exit
86
- when "--buildfile"
87
- @rakefiles.clear
88
- @rakefiles << value
89
- when '--version'
90
- puts "Buildr, version #{Buildr::VERSION}"
91
- exit
92
- when "--freeze"
93
- find_buildfile
94
- puts "Freezing the Buildfile so it always uses Buildr version #{Buildr::VERSION}"
95
- gem =
96
- original = File.read(rakefile)
97
- if original =~ /gem\s*(["'])buildr\1/
98
- modified = original.sub(/gem\s*(["'])buildr\1\s*,\s*(["']).*\2/, %{gem "buildr", "#{Buildr::VERSION}"})
99
- else
100
- modified = %{gem "buildr", "#{Buildr::VERSION}"\n} + original
101
- end
102
- File.open(rakefile, "w") { |file| file.write modified }
103
- exit
104
- when "--unfreeze"
105
- find_buildfile
106
- puts "Unfreezing the Buildfile to use the latest version of Buildr from your Gems repository."
107
- modified = File.read(rakefile).sub(/^\s*gem\s*(["'])buildr\1.*\n/, "")
108
- File.open(rakefile, "w") { |file| file.write modified }
109
- exit
110
- when '--require', "--nosearch", "--quiet", "--trace", "--verbose"
111
- super
112
- end
113
- end
114
-
115
- def find_buildfile()
116
- here = Dir.pwd
117
- while ! have_rakefile
118
- Dir.chdir("..")
119
- if Dir.pwd == here || options.nosearch
120
- error = "No Buildfile found (looking for: #{@rakefiles.join(', ')})"
121
- if STDIN.isatty
122
- chdir(original_dir) { task("generate").invoke }
123
- exit 1
124
- else
125
- raise error
126
- end
127
- end
128
- here = Dir.pwd
129
- end
130
- end
131
-
132
- def load_buildfile()
133
- find_buildfile
134
- puts "(in #{Dir.pwd})"
135
- load File.expand_path(@rakefile) if @rakefile != ''
136
- load_imports
137
- end
138
-
139
- def usage()
140
- puts "Buildr #{Buildr::VERSION}"
141
- puts
142
- puts "Usage:"
143
- puts " buildr [-f buildfile] {options} targets..."
144
- end
145
-
146
- def help()
147
- usage
148
- puts
149
- puts "Options:"
150
- OPTIONS.sort.each do |long, short, mode, desc|
151
- if mode == GetoptLong::REQUIRED_ARGUMENT
152
- if desc =~ /\b([A-Z]{2,})\b/
153
- long = long + "=#{$1}"
154
- end
155
- end
156
- printf " %-20s (%s)\n", long, short
157
- printf " %s\n", desc
158
- end
159
- puts
160
- puts "For help with your buildfile:"
161
- puts " buildr help"
162
- end
163
-
164
- def command_line_options
165
- OPTIONS.collect { |lst| lst[0..-2] }
166
- end
167
-
168
- end
169
-
170
- Rake.application = Application.new
171
- end
172
- end
173
-
37
+ require "tasks/concat.rb"
38
+ require "tasks/zip.rb"
39
+ require "tasks/tar.rb"
174
40
 
175
- # Now it's safe to load Buildr, after we set up the Rake Application.
176
- $LOAD_PATH.unshift __DIR__
177
- ["core", "tasks", "java"].each do |dir|
178
- Dir[File.join(__DIR__, dir, "*.rb")].map { |file| File.basename(file) }.each { |file| require "#{dir}/#{file}" }
179
- end
41
+ require "java/compile"
42
+ require "java/test"
43
+ require "java/packaging"
44
+ require "java/eclipse"
45
+ require "java/idea"
180
46
 
181
47
 
182
48
  # Methods defined in Buildr are both instance methods (e.g. when included in Project)
@@ -190,24 +56,5 @@ end
190
56
  # Project has visibility to everything in the Buildr namespace. (See above for constants)
191
57
  class Project ; include Buildr ; end
192
58
 
193
-
194
- module Buildr
195
- @loaded_features_to_ignore = $LOADED_FEATURES
196
- end
197
-
198
- # Load the settings files.
199
- [ File.expand_path("buildr.rb", Gem::user_home), "buildr.rb" ].each { |file| load file if File.exist?(file) }
200
- [ File.expand_path("buildr.rake", Gem::user_home), File.expand_path("buildr.rake") ].each do |file|
201
- if File.exist?(file)
202
- warn "Please use '#{file.ext('rb')}' instead of '#{file}'"
203
- load file
204
- end
205
- end
206
-
207
- #Load local tasks that can be used in the Buildfile.
208
- Dir["#{Dir.pwd}/tasks/*.rake"].each do |file|
209
- unless $LOADED_FEATURES.include?(file)
210
- load file
211
- $LOADED_FEATURES << file
212
- end
213
- end
59
+ # Load .rake files form tasks directory, and buildr.rb files.
60
+ Buildr.load_tasks_and_local_files
@@ -6,7 +6,8 @@ module Buildr
6
6
 
7
7
  class << self
8
8
 
9
- REQUIRES = ["cobertura:cobertura:jar:1.8", "log4j:log4j:jar:1.2.9", "asm:asm:jar:2.2.1", "oro:oro:jar:2.0.8"]
9
+ REQUIRES = ["net.sourceforge.cobertura:cobertura:jar:1.9", "log4j:log4j:jar:1.2.9",
10
+ "asm:asm:jar:2.2.1", "asm:asm-tree:jar:2.2.1", "oro:oro:jar:2.0.8"]
10
11
 
11
12
  def requires()
12
13
  @requires ||= Buildr.artifacts(REQUIRES).each(&:invoke).map(&:to_s)
@@ -41,15 +42,16 @@ module Buildr
41
42
  # We now have two target directories with bytecode. It would make sense to remove compile.target
42
43
  # and add instrumented instead, but apparently Cobertura only creates some of the classes, so
43
44
  # we need both directories and instrumented must come first.
44
- project.test.classpath.unshift file(instrumented)
45
+ project.test.classpath.unshift instrumented
45
46
  project.test.with requires
47
+ project.test.options[:properties]["net.sourceforge.cobertura.datafile"] = data_file
46
48
  project.clean { rm_rf instrumented.to_s, :verbose=>false }
47
49
  end
48
50
  end
49
51
  end
50
52
 
51
53
  desc "Run the test cases and produce code coverage reports in #{report_to(:html)}"
52
- task "html"=>["instrument", "test:all"] do
54
+ task "html"=>["instrument", "test"] do
53
55
  puts "Creating test coverage reports in #{report_to(:html)}"
54
56
  Buildr.ant "cobertura" do |ant|
55
57
  ant.taskdef :classpath=>requires.join(File::PATH_SEPARATOR), :resource=>"tasks.properties"
@@ -62,7 +64,7 @@ module Buildr
62
64
  end
63
65
 
64
66
  desc "Run the test cases and produce code coverage reports in #{report_to(:xml)}"
65
- task "xml"=>["instrument", "test:all"] do
67
+ task "xml"=>["instrument", "test"] do
66
68
  puts "Creating test coverage reports in #{report_to(:xml)}"
67
69
  Buildr.ant "cobertura" do |ant|
68
70
  ant.taskdef :classpath=>requires.join(File::PATH_SEPARATOR), :resource=>"tasks.properties"
@@ -0,0 +1,180 @@
1
+ module Buildr
2
+
3
+ # When running from +rake+, we already have an Application setup and must plug into it,
4
+ # since the top-level tasks come from there. When running from +buildr+, we get to load
5
+ # Rake and set everything up, and we use our own Application full of cool Buildr features.
6
+ unless defined?(Rake)
7
+ require "rake"
8
+
9
+ class Application < Rake::Application #:nodoc:
10
+
11
+ DEFAULT_BUILDFILES = ["buildfile", "Buildfile"] + DEFAULT_RAKEFILES
12
+
13
+ OPTIONS = [ # :nodoc:
14
+ ['--help', '-H', GetoptLong::NO_ARGUMENT,
15
+ "Display this help message."],
16
+ ['--nosearch', '-N', GetoptLong::NO_ARGUMENT,
17
+ "Do not search parent directories for the buildfile."],
18
+ ['--quiet', '-q', GetoptLong::NO_ARGUMENT,
19
+ "Do not log messages to standard output."],
20
+ ['--buildfile', '-f', GetoptLong::OPTIONAL_ARGUMENT,
21
+ "Use FILE as the buildfile."],
22
+ ['--require', '-r', GetoptLong::REQUIRED_ARGUMENT,
23
+ "Require MODULE before executing buildfile."],
24
+ ['--trace', '-t', GetoptLong::NO_ARGUMENT,
25
+ "Turn on invoke/execute tracing, enable full backtrace."],
26
+ ['--verbose', '-v', GetoptLong::NO_ARGUMENT,
27
+ "Log message to standard output (default)."],
28
+ ['--version', '-V', GetoptLong::NO_ARGUMENT,
29
+ "Display the program version."],
30
+ ['--freeze', "-F", GetoptLong::NO_ARGUMENT,
31
+ "Freezes the Buildfile so it always uses Buildr version #{Buildr::VERSION}"],
32
+ ['--unfreeze', "-U", GetoptLong::NO_ARGUMENT,
33
+ "Unfreezes the Buildfile to use the latest version of Buildr"]
34
+ ]
35
+
36
+ def initialize()
37
+ super
38
+ @rakefiles = DEFAULT_BUILDFILES
39
+ @name = "Buildr"
40
+ @requires = []
41
+ opts = GetoptLong.new(*command_line_options)
42
+ opts.each { |opt, value| do_option(opt, value) }
43
+ collect_tasks
44
+ end
45
+
46
+ def run()
47
+ standard_exception_handling do
48
+ find_buildfile
49
+ load_buildfile
50
+ top_level
51
+ end
52
+ end
53
+
54
+ def do_option(opt, value)
55
+ case opt
56
+ when '--help'
57
+ help
58
+ exit
59
+ when "--buildfile"
60
+ @rakefiles.clear
61
+ @rakefiles << value
62
+ when '--version'
63
+ puts "Buildr, version #{Buildr::VERSION}"
64
+ exit
65
+ when "--freeze"
66
+ find_buildfile
67
+ puts "Freezing the Buildfile so it always uses Buildr version #{Buildr::VERSION}"
68
+ gem =
69
+ original = File.read(rakefile)
70
+ if original =~ /gem\s*(["'])buildr\1/
71
+ modified = original.sub(/gem\s*(["'])buildr\1\s*,\s*(["']).*\2/, %{gem "buildr", "#{Buildr::VERSION}"})
72
+ else
73
+ modified = %{gem "buildr", "#{Buildr::VERSION}"\n} + original
74
+ end
75
+ File.open(rakefile, "w") { |file| file.write modified }
76
+ exit
77
+ when "--unfreeze"
78
+ find_buildfile
79
+ puts "Unfreezing the Buildfile to use the latest version of Buildr from your Gems repository."
80
+ modified = File.read(rakefile).sub(/^\s*gem\s*(["'])buildr\1.*\n/, "")
81
+ File.open(rakefile, "w") { |file| file.write modified }
82
+ exit
83
+ when "--require"
84
+ @requires << value
85
+ when "--nosearch", "--quiet", "--trace", "--verbose"
86
+ super
87
+ end
88
+ end
89
+
90
+ def find_buildfile()
91
+ unless have_rakefile
92
+ here = Dir.pwd
93
+ Dir.chdir("..") do
94
+ if Dir.pwd == here || options.nosearch
95
+ error = "No Buildfile found (looking for: #{@rakefiles.join(', ')})"
96
+ if STDIN.isatty
97
+ chdir(original_dir) { task("generate").invoke }
98
+ exit 1
99
+ else
100
+ raise error
101
+ end
102
+ end
103
+ find_buildfile
104
+ end
105
+ end
106
+ end
107
+
108
+ def load_buildfile()
109
+ @requires.each { |name| require name }
110
+ puts "(in #{Dir.pwd})"
111
+ load File.expand_path(@rakefile) if @rakefile != ''
112
+ load_imports
113
+ end
114
+
115
+ def usage()
116
+ puts "Buildr #{Buildr::VERSION}"
117
+ puts
118
+ puts "Usage:"
119
+ puts " buildr [-f buildfile] {options} targets..."
120
+ end
121
+
122
+ def help()
123
+ usage
124
+ puts
125
+ puts "Options:"
126
+ OPTIONS.sort.each do |long, short, mode, desc|
127
+ if mode == GetoptLong::REQUIRED_ARGUMENT
128
+ if desc =~ /\b([A-Z]{2,})\b/
129
+ long = long + "=#{$1}"
130
+ end
131
+ end
132
+ printf " %-20s (%s)\n", long, short
133
+ printf " %s\n", desc
134
+ end
135
+ puts
136
+ puts "For help with your buildfile:"
137
+ puts " buildr help"
138
+ end
139
+
140
+ def command_line_options
141
+ OPTIONS.collect { |lst| lst[0..-2] }
142
+ end
143
+ end
144
+
145
+ Rake.application = Buildr::Application.new
146
+
147
+ end
148
+
149
+
150
+ class << self
151
+
152
+ # Loads buildr.rake files from users home directory and project directory.
153
+ # Loads custom tasks from .rake files in tasks directory.
154
+ def load_tasks_and_local_files() #:nodoc:
155
+ return false if @build_files
156
+ # Load the settings files.
157
+ @build_files = [ File.expand_path("buildr.rb", Gem::user_home), "buildr.rb" ].select { |file| File.exist?(file) }
158
+ @build_files += [ File.expand_path("buildr.rake", Gem::user_home), File.expand_path("buildr.rake") ].
159
+ select { |file| File.exist?(file) }.each { |file| warn "Please use '#{file.ext('rb')}' instead of '#{file}'" }
160
+ #Load local tasks that can be used in the Buildfile.
161
+ @build_files += Dir["#{Dir.pwd}/tasks/*.rake"]
162
+ @build_files.each do |file|
163
+ unless $LOADED_FEATURES.include?(file)
164
+ load file
165
+ $LOADED_FEATURES << file
166
+ end
167
+ end
168
+ true
169
+ end
170
+
171
+ # :call-seq:
172
+ # build_files() => files
173
+ #
174
+ # Returns a list of build files. These are files used by the build,
175
+ def build_files()
176
+ [Rake.application.rakefile].compact + @build_files
177
+ end
178
+
179
+ end
180
+ end
data/lib/core/checks.rb CHANGED
@@ -212,8 +212,8 @@ module Rake #:nodoc:
212
212
  end
213
213
 
214
214
  # :call-seq:
215
- # contain(pattern*) => boolean
216
- # contain(file*) => boolean
215
+ # contain?(pattern*) => boolean
216
+ # contain?(file*) => boolean
217
217
  #
218
218
  # For a file, returns true if the file content matches against all the arguments. An argument may be
219
219
  # a string or regular expression.
data/lib/core/common.rb CHANGED
@@ -19,7 +19,8 @@ class Hash
19
19
  def from_java_properties(string)
20
20
  string.gsub(/\\\n/, "").split("\n").select { |line| line =~ /^[^#].*=.*/ }.
21
21
  map { |line| line.gsub(/\\[trnf\\]/) { |escaped| {?t=>"\t", ?r=>"\r", ?n=>"\n", ?f=>"\f", ?\\=>"\\"}[escaped[1]] } }.
22
- inject({}) { |hash, line| name, value = line.split("=") ; hash[name] = value ; hash }
22
+ map { |line| line.split("=") }.
23
+ inject({}) { |hash, (name, value)| hash.merge(name=>value) }
23
24
  end
24
25
 
25
26
  end
@@ -31,9 +32,9 @@ class Hash
31
32
  #
32
33
  # For example:
33
34
  # { :a=>1, :b=>2, :c=>3, :d=>4 }.only(:a, :c)
34
- # => { :b=>2, :d=>4 }
35
+ # => { :a=>1, :c=>3 }
35
36
  def only(*keys)
36
- self.inject({}) { |hash, pair| hash[pair[0]] = pair[1] if keys.include?(pair[0]) ; hash }
37
+ keys.inject({}) { |hash, key| has_key?(key) ? hash.merge(key=>self[key]) : hash }
37
38
  end
38
39
 
39
40
 
@@ -44,9 +45,9 @@ class Hash
44
45
  #
45
46
  # For example:
46
47
  # { :a=>1, :b=>2, :c=>3, :d=>4 }.except(:a, :c)
47
- # => { :a=>1, :c=>3 }
48
+ # => { :b=>2, :d=>4 }
48
49
  def except(*keys)
49
- self.inject({}) { |hash, pair| hash[pair[0]] = pair[1] unless keys.include?(pair[0]) ; hash }
50
+ (self.keys - keys).inject({}) { |hash, key| hash.merge(key=>self[key]) }
50
51
  end
51
52
 
52
53
  # :call-seq:
data/lib/core/generate.rb CHANGED
@@ -1,3 +1,5 @@
1
+ require 'java/pom'
2
+
1
3
  module Buildr
2
4
  module Generate #:nodoc:
3
5
 
@@ -76,13 +78,14 @@ EOF
76
78
  pom = Buildr::POM.load('pom.xml')
77
79
  project = pom.project
78
80
 
79
- artifactId = project['artifactId']
81
+ artifactId = project['artifactId'].first
80
82
  description = project['name'] || "The #{artifactId} project"
83
+ project_name = File.basename(Dir.pwd)
81
84
 
82
85
  if root
83
86
  script = HEADER.split("\n")
84
87
 
85
- settings_file = ENV["m2_settings"] || File.join(Gem::user_home, ".m2/settings.xml")
88
+ settings_file = ENV["M2_SETTINGS"] || File.join(Gem::user_home, ".m2/settings.xml")
86
89
  settings = XmlSimple.xml_in(IO.read(settings_file)) if File.exists?(settings_file)
87
90
 
88
91
  if settings
@@ -97,8 +100,8 @@ EOF
97
100
  script << "options.proxy.exclude << '#{exclude}'" if exclude
98
101
  script << ''
99
102
  # In addition, we need to use said proxies to download artifacts.
100
- options.proxy.http = url
101
- options.proxy.exclude << exclude if exclude
103
+ Buildr.options.proxy.http = url
104
+ Buildr.options.proxy.exclude << exclude if exclude
102
105
  end
103
106
  end
104
107
 
@@ -106,22 +109,21 @@ EOF
106
109
  legacy = repository["layout"].to_s =~ /legacy/
107
110
  !legacy
108
111
  } rescue nil
109
- unless repositories.nil? || repositories.empty?
110
- repositories.each do |repository|
111
- name, url = repository["name"], repository["url"]
112
- script << "# #{name}"
113
- script << "repositories.remote << '#{url}'"
114
- # In addition we need to use said repositores to download artifacts.
115
- Buildr.repositories.remote << url.to_s
116
- end
117
- script << ""
112
+ repositories = [{"name" => "Standard maven2 repository", "url" => "http://www.ibiblio.org/maven2/"}] if repositories.nil? || repositories.empty?
113
+ repositories.each do |repository|
114
+ name, url = repository["name"], repository["url"]
115
+ script << "# #{name}"
116
+ script << "repositories.remote << '#{url}'"
117
+ # In addition we need to use said repositores to download artifacts.
118
+ Buildr.repositories.remote << url.to_s
118
119
  end
120
+ script << ""
119
121
  else
120
122
  script = []
121
123
  end
122
124
 
123
125
  script << "desc '#{description}'"
124
- script << "define '#{artifactId}' do"
126
+ script << "define '#{project_name}' do"
125
127
 
126
128
  groupId = project['groupId']
127
129
  script << " project.group = '#{groupId}'" if groupId
@@ -140,11 +142,20 @@ EOF
140
142
  script << " compile.options.target = '#{target}'" if target
141
143
  end
142
144
 
143
- dependencies = pom.dependencies.map{|d| "'#{d}'"}.join(', ')
145
+ compile_dependencies = pom.dependencies
146
+ dependencies = compile_dependencies.sort.map{|d| "'#{d}'"}.join(', ')
144
147
  script << " compile.with #{dependencies}" unless dependencies.empty?
145
148
 
146
- test_dependencies = pom.dependencies(['test']).map{|d| "'#{d}'"}.join(', ')
147
- script << " test.compile.with #{test_dependencies}" unless test_dependencies.empty?
149
+ test_dependencies = (pom.dependencies(['test']) - compile_dependencies).reject{|d| d =~ /^junit:junit:jar:/ }
150
+ #check if we have testng
151
+ use_testng = test_dependencies.find{|d| d =~ /^org.testng:testng:jar:/}
152
+ if use_testng
153
+ script << " test.using :testng"
154
+ test_dependencies = pom.dependencies(['test']).reject{|d| d =~ /^org.testng:testng:jar:/ }
155
+ end
156
+
157
+ test_dependencies = test_dependencies.sort.map{|d| "'#{d}'"}.join(', ')
158
+ script << " test.with #{test_dependencies}" unless test_dependencies.empty?
148
159
 
149
160
  packaging = project['packaging'].first
150
161
  if %w(jar war).include?(packaging)
@@ -153,6 +164,7 @@ EOF
153
164
 
154
165
  modules = project['modules'].first['module'] rescue nil
155
166
  if modules
167
+ script << ""
156
168
  modules.each do |mod|
157
169
  chdir(mod) { script << from_maven2_pom.flatten.map { |line| " " + line } << "" }
158
170
  end
data/lib/core/project.rb CHANGED
@@ -284,6 +284,19 @@ module Buildr
284
284
  end
285
285
  end
286
286
 
287
+ # :call-seq:
288
+ # task_in_parent_project(task_name) => task_name or nil
289
+ #
290
+ # Assuming the task name is prefixed with the current project, finds and returns a task with the
291
+ # same name in a parent project. Call this with "foo:bar:test" will return "foo:test", but call
292
+ # this with "foo:test" will return nil.
293
+ def task_in_parent_project(task_name)
294
+ namespace = task_name.split(":")
295
+ last_name = namespace.pop
296
+ namespace.pop
297
+ Rake.application.lookup((namespace + [last_name]).join(":"), []) unless namespace.empty?
298
+ end
299
+
287
300
  end
288
301
 
289
302
  include InheritedAttributes
data/lib/java/ant.rb CHANGED
@@ -48,6 +48,7 @@ module Buildr
48
48
  def ant(name, options=nil, &block)
49
49
  warn_deprecated "Options are ignored." if options
50
50
  options = { :name=>name, :basedir=>Dir.pwd, :declarative=>true }
51
+ options.merge!(:logger=> Logger.new(STDOUT), :loglevel=> Logger::DEBUG) if Rake.application.options.trace
51
52
  Java.rjb do
52
53
  AntProject.new(options).tap do |project|
53
54
  # Set Ant logging level to debug (--trace), info (default) or error only (--quiet).
data/lib/java/artifact.rb CHANGED
@@ -269,6 +269,7 @@ module Buildr
269
269
  def download()
270
270
  puts "Downloading #{to_spec}" if Rake.application.options.trace
271
271
  remote = Buildr.repositories.remote
272
+ fail "No remote repositories defined!" if remote.empty?
272
273
  remote.find do |repo_url|
273
274
  repo_url = URI.parse(repo_url) unless URI === repo_url
274
275
  repo_url.path += "/" unless repo_url.path[-1] == "/"
data/lib/java/compile.rb CHANGED
@@ -111,7 +111,7 @@ module Buildr
111
111
 
112
112
  def initialize(*args) #:nodoc:
113
113
  super
114
- parent = Rake::Task["^compile"] if name[":"] # Only if in namespace
114
+ parent = Project.task_in_parent_project(name)
115
115
  if parent && parent.respond_to?(:options)
116
116
  @options = Options.new(parent.options)
117
117
  else
data/lib/java/eclipse.rb CHANGED
@@ -19,8 +19,7 @@ module Buildr
19
19
  # the Buildfile (buildr.rb, separate file listing dependencies, etc), so we add anything required
20
20
  # after the Buildfile. So which don't know where Buildr shows up exactly, ignore files that show
21
21
  # in $LOADED_FEATURES that we cannot resolve.
22
- sources = ($LOADED_FEATURES - Buildr.instance_eval("@loaded_features_to_ignore")).
23
- map { |file| File.expand_path(file) }.select { |file| File.exist?(file) }
22
+ sources = Buildr.build_files.map { |file| File.expand_path(file) }.select { |file| File.exist?(file) }
24
23
  sources << File.expand_path(Rake.application.rakefile, root_path) if Rake.application.rakefile
25
24
 
26
25
  # Only for projects that are Eclipse packagable.
@@ -35,7 +34,7 @@ module Buildr
35
34
  relative = lambda do |path|
36
35
  msg = [:to_path, :to_str, :to_s].find { |msg| path.respond_to? msg }
37
36
  path = path.__send__(msg)
38
- Pathname.new(path).relative_path_from(Pathname.new(project.path_to)).to_s
37
+ Pathname.new(File.expand_path(path)).relative_path_from(Pathname.new(project.path_to)).to_s
39
38
  end
40
39
 
41
40
  m2repo = Buildr::Repositories.instance.local
data/lib/java/idea.rb CHANGED
@@ -21,8 +21,7 @@ module Buildr
21
21
  # the Buildfile (buildr.rb, separate file listing dependencies, etc), so we add anything required
22
22
  # after the Buildfile. So which don't know where Buildr shows up exactly, ignore files that show
23
23
  # in $LOADED_FEATURES that we cannot resolve.
24
- sources = ($LOADED_FEATURES - Buildr.instance_eval("@loaded_features_to_ignore")).
25
- map { |file| File.expand_path(file) }.select { |file| File.exist?(file) }
24
+ sources = Buildr.build_files.map { |file| File.expand_path(file) }.select { |file| File.exist?(file) }
26
25
  sources << File.expand_path(Rake.application.rakefile, root_path) if Rake.application.rakefile
27
26
 
28
27
  # Find a path relative to the project's root directory.
@@ -15,7 +15,7 @@ module Buildr
15
15
  # the project definition, since it does all the heavy lifting.
16
16
  module Packaging
17
17
 
18
- MANIFEST_HEADER = "Manifest-Version: 1.0\nCreated-By: Buildr\n"
18
+ MANIFEST_HEADER = ["Manifest-Version: 1.0", "Created-By: Buildr"]
19
19
 
20
20
  # Adds support for MANIFEST.MF and other META-INF files.
21
21
  module WithManifest
@@ -49,6 +49,10 @@ module Buildr
49
49
  # Tempfiles gets deleted on garbage collection, so we're going to hold on to it
50
50
  # through instance variable not closure variable.
51
51
  Tempfile.open "MANIFEST.MF" do |@manifest_tmp|
52
+ lines = String === manifest || Rake::Task === manifest ? manifest_lines_from(File.read(manifest.to_s)) :
53
+ manifest_lines_from(manifest)
54
+ @manifest_tmp.write((MANIFEST_HEADER + lines).join("\n"))
55
+ =begin
52
56
  @manifest_tmp.write MANIFEST_HEADER
53
57
  case manifest
54
58
  when Hash
@@ -64,12 +68,40 @@ module Buildr
64
68
  else
65
69
  fail "Invalid manifest, expecting Hash, Array, file name/task or proc/method."
66
70
  end
71
+ =end
67
72
  meta_inf_path.include @manifest_tmp.path, :as=>"MANIFEST.MF"
68
73
  end
69
74
  end
70
75
  end
71
76
  end
72
77
 
78
+ private
79
+
80
+ def manifest_lines_from(arg)
81
+ case arg
82
+ when Hash
83
+ arg.map { |name, value| "#{name}: #{value}" }.sort.
84
+ map { |line| manifest_wrap_at_72(line) }.flatten
85
+ when Array
86
+ arg.map { |section|
87
+ name = section.has_key?("Name") ? ["Name: #{section["Name"]}"] : []
88
+ name + section.except("Name").map { |name, value| "#{name}: #{value}" }.sort + [""]
89
+ }.flatten.map { |line| manifest_wrap_at_72(line) }.flatten
90
+ when Proc, Method
91
+ manifest_lines_from(arg.call)
92
+ when String
93
+ arg.split("\n").map { |line| manifest_wrap_at_72(line) }.flatten
94
+ else
95
+ fail "Invalid manifest, expecting Hash, Array, file name/task or proc/method."
96
+ end
97
+ end
98
+
99
+ def manifest_wrap_at_72(arg)
100
+ #return arg.map { |line| manifest_wrap_at_72(line) }.flatten.join("\n") if Array === arg
101
+ return arg if arg.size < 72
102
+ [ arg[0..70], manifest_wrap_at_72(" " + arg[71..-1]) ]
103
+ end
104
+
73
105
  end
74
106
 
75
107
  class ::Buildr::ZipTask
@@ -413,14 +445,14 @@ module Buildr
413
445
 
414
446
  def package_as_tar(file_name, options) #:nodoc:
415
447
  unless Rake::Task.task_defined?(file_name)
416
- TarballTask.define_task(file_name).with(options)
448
+ TarballTask.define_task(file_name)
417
449
  end
418
450
  file(file_name)
419
451
  end
420
452
 
421
453
  def package_as_tgz(file_name, options) #:nodoc:
422
454
  unless Rake::Task.task_defined?(file_name)
423
- TarballTask.define_task(file_name).with(options)
455
+ TarballTask.define_task(file_name)
424
456
  end
425
457
  file(file_name)
426
458
  end
data/lib/java/pom.rb CHANGED
@@ -26,10 +26,14 @@ module Buildr
26
26
  when Hash
27
27
  load(Buildr.artifact(source).pom)
28
28
  when Artifact
29
- load(source.pom.to_s)
30
- when String, Rake::FileTask
29
+ pom = source.pom
30
+ pom.invoke
31
+ load(pom.to_s)
32
+ when Rake::FileTask
33
+ source.invoke
34
+ load(source.to_s)
35
+ when String
31
36
  filename = File.expand_path(source)
32
- file(filename).invoke
33
37
  unless pom = cache[filename]
34
38
  puts "Loading m2 pom file from #{filename}" if Rake.application.options.trace
35
39
  pom = POM.new(IO.read(filename))
@@ -118,11 +122,14 @@ module Buildr
118
122
  # The second form uses a single spec hash and expands it from the current/parent POM. Used to determine
119
123
  # the version number if specified in dependencyManagement instead of dependencies.
120
124
  def managed(spec = nil)
121
- return managed.detect { |dep| [:group, :id, :type, :classifier].all? { |key| spec[key] == dep[key] } } ||
122
- (parent ? parent.managed(spec) : nil) if spec
123
- @managed ||= begin
124
- managed = project["dependencyManagement"].first["dependencies"].first["dependency"] rescue []
125
- managed.map { |dep| pom_to_hash(dep, properties) }
125
+ if spec
126
+ managed.detect { |dep| [:group, :id, :type, :classifier].all? { |key| spec[key] == dep[key] } } ||
127
+ (parent ? parent.managed(spec) : nil)
128
+ else
129
+ @managed ||= begin
130
+ managed = project["dependencyManagement"].first["dependencies"].first["dependency"] rescue nil
131
+ managed ? managed.map { |dep| pom_to_hash(dep, properties) } : []
132
+ end
126
133
  end
127
134
  end
128
135
 
data/lib/java/test.rb CHANGED
@@ -142,7 +142,7 @@ module Buildr
142
142
  TEST_FRAMEWORKS = []
143
143
 
144
144
  # Default options already set on each test task.
145
- DEFAULT_OPTIONS = { :fail_on_failure=>true }
145
+ DEFAULT_OPTIONS = { :fail_on_failure=>true, :fork=>:once, :properties=>{} }
146
146
 
147
147
  # JMock version..
148
148
  JMOCK_VERSION = "1.2.0"
@@ -159,7 +159,7 @@ module Buildr
159
159
  @classpath = []
160
160
  @include = []
161
161
  @exclude = []
162
- parent = Rake::Task["^test"] if name[":"] # Only if in namespace
162
+ parent = Project.task_in_parent_project(name)
163
163
  @options = parent && parent.respond_to?(:options) ? parent.options.clone : DEFAULT_OPTIONS.clone
164
164
  enhance { run_tests }
165
165
  end
@@ -251,15 +251,21 @@ module Buildr
251
251
  #
252
252
  # Sets various test options and returns self. Accepts a hash of options, or symbols (a symbol sets that
253
253
  # option to true). For example:
254
- # test.using :testng, :properties=>{ "url"=>"http://localhost:8080" }
254
+ # test.using :testng, :fork=>:each, :properties=>{ "url"=>"http://localhost:8080" }
255
255
  #
256
256
  # Currently supports the following options:
257
- # * :properties -- System properties.
258
- # * :java_args -- Java arguments when forking a new JVM.
259
257
  # * :fail_on_failure -- True to fail on test failure (default is true).
258
+ # * :fork -- Fork test cases (JUnit only).
259
+ # * :java_args -- Java arguments when forking a new JVM.
260
+ # * :properties -- System properties.
261
+ #
262
+ # The :fork option takes the following values:
263
+ # * :once -- Fork one JVM for each project (default).
264
+ # * :each -- Fork one JVM for each test case.
265
+ # * false -- Do not fork, running all test cases in the same JVM.
260
266
  def using(*args)
261
- args.pop.each { |key, value| @options[key.to_sym] = value } if Hash === args.last
262
- args.each { |key| @options[key.to_sym] = true }
267
+ args.pop.each { |key, value| options[key.to_sym] = value } if Hash === args.last
268
+ args.each { |key| options[key.to_sym] = true }
263
269
  self
264
270
  end
265
271
 
@@ -467,11 +473,23 @@ module Buildr
467
473
  rm_rf report_to.to_s ; mkpath report_to.to_s
468
474
  # Use Ant to execute the Junit tasks, gives us performance and reporting.
469
475
  Buildr.ant("junit") do |ant|
470
- ant.junit :printsummary=>"withOutAndErr" do
476
+ case options[:fork]
477
+ when false
478
+ forking = {}
479
+ when :each
480
+ forking = { :fork=>true, :forkmode=>"perTest" }
481
+ when true, :once
482
+ forking = { :fork=>true, :forkmode=>"once" }
483
+ else
484
+ fail "Option fork must be :once, :each or false."
485
+ end
486
+ ant.junit forking do
471
487
  ant.classpath :path=>args[:classpath].map(&:to_s).each { |path| file(path).invoke }.join(File::PATH_SEPARATOR)
472
488
  args[:properties].each { |key, value| ant.sysproperty :key=>key, :value=>value }
473
489
  ant.formatter :type=>"plain"
474
490
  ant.formatter :type=>"xml"
491
+ ant.formatter :type=>"plain", :usefile=>false # log test
492
+ ant.formatter :type=>"xml"
475
493
  ant.batchtest :todir=>report_to.to_s, :failureproperty=>"failed" do
476
494
  ant.fileset :dir=>compile.target.to_s do
477
495
  args[:classes].each { |cls| ant.include :name=>cls.gsub(".", "/").ext("class") }
data/lib/tasks/zip.rb CHANGED
@@ -16,14 +16,13 @@ module Buildr
16
16
 
17
17
  def initialize(root, path)
18
18
  @root = root
19
- @path = "#{path}/" if path
19
+ @path = path.blank? ? path : "#{path}/"
20
20
  @files = FileList[]
21
21
  # Expand source files added to this path.
22
22
  expand_src = proc { @files.map{ |file| file.to_s }.uniq }
23
23
  @sources = [ expand_src ]
24
24
  # Add files and directories added to this path.
25
25
  @actions = [] << proc do |file_map|
26
- file_map[@path] = nil if @path
27
26
  expand_src.call.each do |path|
28
27
  if File.directory?(path)
29
28
  in_directory(path, @files) do |file, rel_path|
@@ -104,7 +103,9 @@ module Buildr
104
103
 
105
104
  # Returns a Path relative to this one.
106
105
  def path(path)
107
- path.blank? ? self : @root.path("#{@path}#{path}")
106
+ return self if path.blank?
107
+ return root.path(path[1..-1]) if path[0] == ?/
108
+ root.path("#{@path}#{path}")
108
109
  end
109
110
 
110
111
  # Returns all the source files.
@@ -117,7 +118,7 @@ module Buildr
117
118
  end
118
119
 
119
120
  def to_s()
120
- @path || ""
121
+ @path
121
122
  end
122
123
 
123
124
  protected
@@ -126,10 +127,11 @@ module Buildr
126
127
  @sources << proc { source }
127
128
  @actions << proc do |file_map|
128
129
  file = source.to_s
129
- file_map[@path] = nil if @path
130
130
  if File.directory?(file)
131
131
  in_directory(file) do |file, rel_path|
132
- dest = as == "." ? (@path || "") + rel_path.split("/")[1..-1].join("/") : "#{@path}#{as}#{rel_path}"
132
+ path = rel_path.split("/")[1..-1]
133
+ path.unshift as unless as == "."
134
+ dest = "#{@path}#{path.join('/')}"
133
135
  puts "Adding #{dest}" if Rake.application.options.trace
134
136
  file_map[dest] = file
135
137
  end
@@ -188,7 +190,7 @@ module Buildr
188
190
 
189
191
  def initialize(*args) #:nodoc:
190
192
  super
191
- @paths = { nil=>Path.new(self, nil) }
193
+ @paths = { ""=>Path.new(self, "") }
192
194
  @prepares = []
193
195
 
194
196
  # Make sure we're the last enhancements, so other enhancements can add content.
@@ -202,7 +204,10 @@ module Buildr
202
204
  rm name, :verbose=>false rescue nil
203
205
  mkpath File.dirname(name), :verbose=>false
204
206
  begin
205
- @paths.each { |name, object| object.add_files(@file_map) }
207
+ @paths.each do |name, object|
208
+ @file_map[name] = nil unless name.blank?
209
+ object.add_files(@file_map)
210
+ end
206
211
  create_from @file_map
207
212
  rescue
208
213
  rm name, :verbose=>false rescue nil
@@ -245,7 +250,7 @@ module Buildr
245
250
  # zip(..).include("foo.zip", :merge=>true).include("bar.zip")
246
251
  # You can also use the method #merge.
247
252
  def include(*files)
248
- @paths[nil].include *files
253
+ @paths[""].include *files
249
254
  self
250
255
  end
251
256
  alias :add :include
@@ -255,7 +260,7 @@ module Buildr
255
260
  #
256
261
  # Excludes files and returns self. Can be used in combination with include to prevent some files from being included.
257
262
  def exclude(*files)
258
- @paths[nil].exclude *files
263
+ @paths[""].exclude *files
259
264
  self
260
265
  end
261
266
 
@@ -269,7 +274,7 @@ module Buildr
269
274
  # only specific files. For example:
270
275
  # zip(..).merge("src.zip").include("module1/*")
271
276
  def merge(*files)
272
- @paths[nil].merge *files
277
+ @paths[""].merge *files
273
278
  end
274
279
 
275
280
  # :call-seq:
@@ -284,8 +289,18 @@ module Buildr
284
289
  # path("foo").path("bar") == path("foo/bar")
285
290
  # path("foo").root == root
286
291
  def path(name)
287
- return @paths[nil] if name.blank?
288
- @paths[name] ||= Path.new(self, name)
292
+ return @paths[""] if name.blank?
293
+ normalized = name.split("/").inject([]) do |path, part|
294
+ case part
295
+ when ".", nil, ""
296
+ path
297
+ when ".."
298
+ path[0...-1]
299
+ else
300
+ path << part
301
+ end
302
+ end.join("/")
303
+ @paths[normalized] ||= Path.new(self, normalized)
289
304
  end
290
305
 
291
306
  # :call-seq:
@@ -381,9 +396,16 @@ module Buildr
381
396
  Zip::ZipFile.open(name, Zip::ZipFile::CREATE) do |zip|
382
397
  zip.restore_permissions = true
383
398
  file_map.each do |path, content|
384
- zip.mkdir path unless content || zip.find_entry(path)
385
- zip.add path, content if String === content
386
- zip.get_output_stream(path) { |output| content.call(output) } if content.respond_to?(:call)
399
+ if content
400
+ File.dirname(path).tap { |dir| zip.mkdir dir unless zip.find_entry(dir) }
401
+ if content.respond_to?(:call)
402
+ zip.get_output_stream(path) { |output| content.call(output) }
403
+ else
404
+ zip.add path, content.to_s
405
+ end
406
+ else
407
+ zip.mkdir path unless zip.find_entry(path)
408
+ end
387
409
  end
388
410
  end
389
411
  end
metadata CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.4
3
3
  specification_version: 1
4
4
  name: buildr
5
5
  version: !ruby/object:Gem::Version
6
- version: 1.2.3
7
- date: 2007-07-26 00:00:00 -07:00
6
+ version: 1.2.4
7
+ date: 2007-08-03 00:00:00 -07:00
8
8
  summary: A build system that doesn't suck
9
9
  require_paths:
10
10
  - lib
@@ -36,6 +36,7 @@ files:
36
36
  - lib/core
37
37
  - lib/core/generate.rb
38
38
  - lib/core/transports.rb
39
+ - lib/core/application.rb
39
40
  - lib/core/build.rb
40
41
  - lib/core/checks.rb
41
42
  - lib/core/help.rb