buildr 1.2.5 → 1.2.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -20,16 +20,16 @@ module Buildr
20
20
  "Do not search parent directories for the buildfile."],
21
21
  ['--quiet', '-q', GetoptLong::NO_ARGUMENT,
22
22
  "Do not log messages to standard output."],
23
- ['--buildfile', '-f', GetoptLong::OPTIONAL_ARGUMENT,
23
+ ['--buildfile', '-f', GetoptLong::REQUIRED_ARGUMENT,
24
24
  "Use FILE as the buildfile."],
25
25
  ['--require', '-r', GetoptLong::REQUIRED_ARGUMENT,
26
26
  "Require MODULE before executing buildfile."],
27
27
  ['--trace', '-t', GetoptLong::NO_ARGUMENT,
28
28
  "Turn on invoke/execute tracing, enable full backtrace."],
29
- ['--verbose', '-v', GetoptLong::NO_ARGUMENT,
30
- "Log message to standard output (default)."],
31
29
  ['--version', '-V', GetoptLong::NO_ARGUMENT,
32
30
  "Display the program version."],
31
+ ['--environment', '-e', GetoptLong::REQUIRED_ARGUMENT,
32
+ "Environment name (e.g. development, test, production)."],
33
33
  ['--freeze', "-F", GetoptLong::NO_ARGUMENT,
34
34
  "Freezes the Buildfile so it always uses Buildr version #{Buildr::VERSION}"],
35
35
  ['--unfreeze', "-U", GetoptLong::NO_ARGUMENT,
@@ -66,6 +66,8 @@ module Buildr
66
66
  when '--version'
67
67
  puts "Buildr, version #{Buildr::VERSION}"
68
68
  exit
69
+ when '--environment'
70
+ ENV['BUILDR_ENV'] = value
69
71
  when "--freeze"
70
72
  find_buildfile
71
73
  puts "Freezing the Buildfile so it always uses Buildr version #{Buildr::VERSION}"
@@ -85,7 +87,7 @@ module Buildr
85
87
  exit
86
88
  when "--require"
87
89
  @requires << value
88
- when "--nosearch", "--quiet", "--trace", "--verbose"
90
+ when "--nosearch", "--quiet", "--trace"
89
91
  super
90
92
  end
91
93
  end
@@ -109,7 +111,7 @@ module Buildr
109
111
 
110
112
  def load_buildfile()
111
113
  @requires.each { |name| require name }
112
- puts "(in #{Dir.pwd})"
114
+ puts Buildr.environment ? "(in #{Dir.pwd}, #{Buildr.environment})" : "(in #{Dir.pwd})"
113
115
  load File.expand_path(@rakefile) if @rakefile != ''
114
116
  load_imports
115
117
  end
@@ -113,7 +113,9 @@ module Buildr
113
113
  # Make a release.
114
114
  def make()
115
115
  check
116
- version = with_next_version { |filename, version| sh "#{command} clean upload DEBUG=no --buildfile #{filename}" }
116
+ options = ['--buildfile', filename, 'DEBUG=no']
117
+ options << '--environment' << Buildr.environment unless Buildr.environment.to_s.empty?
118
+ version = with_next_version { |filename, version| sh "#{command} clean upload #{option.join(' ')}" }
117
119
  tag version
118
120
  commit version + "-SNAPSHOT"
119
121
  end
@@ -130,6 +132,7 @@ module Buildr
130
132
  # Check that we don't have any local changes in the working copy. Fails if it finds anything
131
133
  # in the working copy that is not checked into source control.
132
134
  def check()
135
+ fail "SVN URL must end with 'trunk' or 'branches/...'" unless svn_url =~ /(trunk)|(branches.*)$/
133
136
  # Status check reveals modified file, but also SVN externals which we can safely ignore.
134
137
  status = svn("status", "--ignore-externals").reject { |line| line =~ /^X\s/ }
135
138
  fail "Uncommitted SVN files violate the First Principle Of Release!\n#{status}" unless
@@ -201,7 +204,7 @@ module Buildr
201
204
  #
202
205
  # Tags the current working copy with the release version number.
203
206
  def tag(version)
204
- url = svn("info").scan(/URL: (.*)/)[0][0].sub(/trunk$/, "tags/#{version}")
207
+ url = svn_url.sub(/(trunk$)|(branches.*)$/, "tags/#{version}")
205
208
  svn "remove", url, "-m", "Removing old copy" rescue nil
206
209
  svn "copy", Dir.pwd, url, "-m", "Release #{version}"
207
210
  end
@@ -226,6 +229,11 @@ module Buildr
226
229
  puts cmd if verbose
227
230
  `#{cmd}`.tap { fail "SVN command failed" unless $?.exitstatus == 0 }
228
231
  end
232
+
233
+ # Return the current SVN URL
234
+ def svn_url
235
+ url = svn("info").scan(/URL: (.*)/)[0][0]
236
+ end
229
237
  end
230
238
 
231
239
  end
@@ -169,6 +169,25 @@ module Buildr
169
169
  Buildr.options
170
170
  end
171
171
 
172
+ # :call-seq:
173
+ # environment() => string or nil
174
+ #
175
+ # Returns the environment name. Use this when your build depends on the environment,
176
+ # for example, development, production, etc. The value comes from the BUILDR_ENV environment variable.
177
+ #
178
+ # For example:
179
+ # buildr -e production
180
+ def environment()
181
+ ENV['BUILDR_ENV']
182
+ end
183
+
184
+ # :call-seq:
185
+ # environment(env)
186
+ #
187
+ # Sets the environment name.
188
+ def environment=(env)
189
+ ENV['BUILDR_ENV'] = env
190
+ end
172
191
 
173
192
  # :call-seq:
174
193
  # struct(hash) => Struct
@@ -334,7 +353,7 @@ module Buildr
334
353
  # For example:
335
354
  # filter.from("src").into("target").using("build"=>Time.now)
336
355
  def into(dir)
337
- @target = file(File.expand_path(dir.to_s))
356
+ @target = file(File.expand_path(dir.to_s)) { |task| run if target == task && !sources.empty? }
338
357
  self
339
358
  end
340
359
 
@@ -417,7 +436,7 @@ module Buildr
417
436
 
418
437
  copy_map = sources.flatten.map(&:to_s).inject({}) do |map, source|
419
438
  base = Pathname.new(source)
420
- files = FileList[File.join(source, "**/*")].reject { |file| File.directory?(file) }.
439
+ files = FileList.recursive(source).
421
440
  map { |file| Pathname.new(file).relative_path_from(base).to_s }.
422
441
  select { |file| @include.empty? || @include.any? { |pattern| File.fnmatch(pattern, file) } }.
423
442
  reject { |file| @exclude.any? { |pattern| File.fnmatch(pattern, file) } }
@@ -434,24 +453,28 @@ module Buildr
434
453
  mkpath target.to_s
435
454
  copy_map.each do |path, source|
436
455
  dest = File.expand_path(path, target.to_s)
437
- mkpath File.dirname(dest) rescue nil
438
- case mapping
439
- when Proc, Method # Call on input, accept output.
440
- mapped = mapping.call(path, File.open(source, "rb") { |file| file.read })
441
- File.open(dest, "wb") { |file| file.write mapped }
442
- when Hash # Map ${key} to value
443
- content = File.open(source, "rb") { |file| file.read }
444
- if Symbol === @mapper
445
- mapped = send("#{@mapper}_mapper", content) { |key| mapping[key] }
456
+ if File.directory?(source)
457
+ mkpath dest
458
+ else
459
+ mkpath File.dirname(dest)
460
+ case mapping
461
+ when Proc, Method # Call on input, accept output.
462
+ mapped = mapping.call(path, File.open(source, "rb") { |file| file.read })
463
+ File.open(dest, "wb") { |file| file.write mapped }
464
+ when Hash # Map ${key} to value
465
+ content = File.open(source, "rb") { |file| file.read }
466
+ if Symbol === @mapper
467
+ mapped = send("#{@mapper}_mapper", content) { |key| mapping[key] }
468
+ else
469
+ mapped = regexp_mapper(content) { |key| mapping[key] }
470
+ end
471
+ #gsub(/\$\{[^}]*\}/) { |str| mapping[str[2..-2]] || str }
472
+ File.open(dest, "wb") { |file| file.write mapped }
473
+ when nil # No mapping.
474
+ cp source, dest
446
475
  else
447
- mapped = regexp_mapper(content) { |key| mapping[key] }
476
+ fail "Filter can be a hash (key=>value), or a proc/method; I don't understand #{mapping}"
448
477
  end
449
- #gsub(/\$\{[^}]*\}/) { |str| mapping[str[2..-2]] || str }
450
- File.open(dest, "wb") { |file| file.write mapped }
451
- when nil # No mapping.
452
- cp source, dest
453
- else
454
- fail "Filter can be a hash (key=>value), or a proc/method; I don't understand #{mapping}"
455
478
  end
456
479
  end
457
480
  touch target.to_s
@@ -17,6 +17,16 @@ module Rake #:nodoc
17
17
  end
18
18
  end
19
19
 
20
+ def execute
21
+ if application.options.dryrun
22
+ puts "** Execute (dry run) #{name}"
23
+ return
24
+ end
25
+ puts "** Execute #{name}" if application.options.trace
26
+ application.enhance_with_matching_rule(name) if @actions.empty?
27
+ @actions.each { |act| result = act.call(self) }
28
+ end
29
+
20
30
  def invoke_prerequisites()
21
31
  prerequisites.each { |n| application[n, @scope].invoke }
22
32
  end
@@ -61,4 +71,11 @@ module Rake #:nodoc
61
71
 
62
72
  end
63
73
 
74
+ class FileList
75
+ class << self
76
+ def recursive(*dirs)
77
+ FileList[dirs.map { |dir| File.join(dir, "/**/{*,.*}") }].reject { |file| File.basename(file) =~ /^[.]{1,2}$/ }
78
+ end
79
+ end
80
+ end
64
81
  end
@@ -546,6 +546,29 @@ module Buildr
546
546
  end
547
547
  end
548
548
 
549
+ def transitive(*specs)
550
+ specs.flatten.inject([]) do |set, spec|
551
+ case spec
552
+ when /([^:]+:){2,4}/ # A spec as opposed to a file name.
553
+ artifact = artifact(spec)
554
+ set |= [artifact] unless artifact.type == :pom
555
+ set |= POM.load(artifact.pom).dependencies.map { |spec| artifact(spec) }
556
+ when Hash
557
+ set |= [transitive(spec)]
558
+ when String # Must always expand path.
559
+ set |= transitive(file(File.expand_path(spec)))
560
+ when Project
561
+ set |= transitive(spec.packages)
562
+ when Rake::Task
563
+ set |= spec.respond_to?(:to_spec) ? transitive(spec.to_spec) : [spec]
564
+ when Struct
565
+ set |= transitive(spec.values)
566
+ else
567
+ fail "Invalid artifact specification in: #{specs.to_s}"
568
+ end
569
+ end
570
+ end
571
+
549
572
  # :call-seq:
550
573
  # groups(ids, :under=>group_name, :version=>number) => artifacts
551
574
  #
@@ -229,10 +229,10 @@ module Buildr
229
229
  target_dir = target.to_s
230
230
  if File.directory?(source)
231
231
  base = Pathname.new(source)
232
- FileList["#{source}/**/*.java"].
233
- each { |file| map[file] = File.join(target_dir, Pathname.new(file).relative_path_from(base).to_s.ext(".class")) }
232
+ FileList["#{source}/**/*.java"].reject { |file| File.directory?(file) }.
233
+ each { |file| map[file] = File.join(target_dir, Pathname.new(file).relative_path_from(base).to_s.ext('.class')) }
234
234
  else
235
- map[source] = File.join(target_dir, File.basename(source).ext(".class"))
235
+ map[source] = File.join(target_dir, File.basename(source).ext('.class'))
236
236
  end
237
237
  map
238
238
  end
@@ -232,13 +232,10 @@ module Buildr
232
232
  cmd_args << "-#{key}"
233
233
  when false
234
234
  cmd_args << "-no#{key}"
235
- when Array
236
- cmd_args << "-#{key}"
237
- cmd_args += value.map(&:to_s)
238
235
  when Hash
239
236
  value.each { |k,v| cmd_args << "-#{key}" << k.to_s << v.to_s }
240
237
  else
241
- cmd_args << "-#{key}" << value.to_s
238
+ cmd_args += Array(value).map { |item| ["-#{key}", item.to_s] }.flatten
242
239
  end
243
240
  end
244
241
  [:sourcepath, :classpath].each do |option|
@@ -378,7 +375,7 @@ module Buildr
378
375
  #
379
376
  # Returns the Java arguments.
380
377
  def java_args()
381
- @java_args ||= (ENV["JAVA_OPTIONS"] || ENV["java_options"] || "").split(" ")
378
+ @java_args ||= (ENV["JAVA_OPTS"] || ENV["JAVA_OPTIONS"] || "").split(" ")
382
379
  end
383
380
 
384
381
  # :call-seq:
@@ -386,12 +383,12 @@ module Buildr
386
383
  #
387
384
  # Sets the Java arguments. These arguments are used when creating a JVM, including for use with RJB
388
385
  # for most tasks (e.g. Ant, compile) and when forking a separate JVM (e.g. JUnit tests). You can also
389
- # use the JAVA_OPTIONS environment variable.
386
+ # use the JAVA_OPTS environment variable.
390
387
  #
391
388
  # For example:
392
389
  # options.java_args = "-verbose"
393
390
  # Or:
394
- # $ set JAVA_OPTIONS = "-Xms1g"
391
+ # $ set JAVA_OPTS = "-Xms1g"
395
392
  # $ buildr
396
393
  def java_args=(args)
397
394
  args = args.split if String === args
@@ -170,10 +170,54 @@ module Buildr
170
170
 
171
171
  end
172
172
 
173
+ # Extends the JarTask to create an AAR file (Axis2 service archive).
174
+ #
175
+ # Supports all the same options as JarTask, with the addition of :wsdls, :services_xml and :libs.
176
+ #
177
+ # * :wsdls -- WSDL files to include (under META-INF). By default packaging will include all WSDL
178
+ # files found under src/main/axis2.
179
+ # * :services_xml -- Location of services.xml file (included under META-INF). By default packaging
180
+ # takes this from src/main/axis2/services.xml. Use a different path if you genereate the services.xml
181
+ # file as part of the build.
182
+ # * :libs -- Array of files, tasks, artifact specifications, etc that will be added to the /lib directory.
183
+ #
184
+ # For example:
185
+ # package(:aar).with(:libs=>"log4j:log4j:jar:1.1")
186
+ #
187
+ # filter.from("src/main/axis2").into("target").include("services.xml", "*.wsdl").using("http_port"=>"8080")
188
+ # package(:aar).wsdls.clear
189
+ # package(:aar).with(:services_xml=>_("target/services.xml"), :wsdls=>_("target/*.wsdl"))
190
+ class AarTask < JarTask
191
+ # Artifacts to include under /lib.
192
+ attr_accessor :libs
193
+ # WSDLs to include under META-INF (defaults to all WSDLs under src/main/axis2).
194
+ attr_accessor :wsdls
195
+ # Location of services.xml file (defaults to src/main/axis2/services.xml).
196
+ attr_accessor :services_xml
197
+
198
+ def initialize(*args) #:nodoc:
199
+ super
200
+ @libs = []
201
+ @wsdls = []
202
+ prepare do
203
+ path("META-INF").include @wsdls
204
+ path("META-INF").include @services_xml, :as=>["services.xml"] if @services_xml
205
+ path("lib").include Buildr.artifacts(@libs) unless @libs.nil? || @libs.empty?
206
+ end
207
+ end
208
+
209
+ def libs=(value) #:nodoc:
210
+ @libs = Buildr.artifacts(value)
211
+ end
212
+
213
+ def wsdls=(value) #:nodoc:
214
+ @wsdls |= Array(value)
215
+ end
216
+ end
217
+
173
218
  end
174
219
  end
175
220
 
176
-
177
221
  Project.on_define do |project|
178
222
  # Need to run buildr before package, since package is often used as a dependency by tasks that
179
223
  # expect build to happen.
@@ -364,6 +408,7 @@ module Buildr
364
408
  jar.include options[:include]
365
409
  else
366
410
  jar.with compile.target unless compile.sources.empty?
411
+ jar.with resources.target unless resources.sources.empty?
367
412
  end
368
413
  end
369
414
  else
@@ -389,6 +434,7 @@ module Buildr
389
434
  war.with :classes=>options[:classes]
390
435
  else
391
436
  war.with :classes=>compile.target unless compile.sources.empty?
437
+ war.with :classes=>resources.target unless resources.sources.empty?
392
438
  end
393
439
  if options.has_key?(:libs)
394
440
  warn_deprecated "The :libs option in package(:war) is deprecated, please use package(:war).with(:libs=>) instead."
@@ -410,6 +456,21 @@ module Buildr
410
456
  file(file_name)
411
457
  end
412
458
 
459
+ def package_as_aar(file_name, options) #:nodoc:
460
+ rake_check_options options, *PACKAGE_OPTIONS
461
+ unless Rake::Task.task_defined?(file_name)
462
+ Java::Packaging::AarTask.define_task(file_name).tap do |aar|
463
+ aar.with :manifest=>manifest, :meta_inf=>meta_inf
464
+ aar.with :wsdls=>path_to("src/main/axis2/*.wsdl")
465
+ aar.with :services_xml=>path_to("src/main/axis2/services.xml")
466
+ aar.with compile.target unless compile.sources.empty?
467
+ aar.with resources.target unless resources.sources.empty?
468
+ aar.with :libs=>compile.classpath
469
+ end
470
+ end
471
+ file(file_name)
472
+ end
473
+
413
474
  def package_as_zip(file_name, options) #:nodoc:
414
475
  unless Rake::Task.task_defined?(file_name)
415
476
  rake_check_options options, *PACKAGE_OPTIONS + [:include]
@@ -426,18 +487,13 @@ module Buildr
426
487
  end
427
488
 
428
489
  def package_as_tar(file_name, options) #:nodoc:
490
+ rake_check_options options, *PACKAGE_OPTIONS
429
491
  unless Rake::Task.task_defined?(file_name)
430
- TarballTask.define_task(file_name)
431
- end
432
- file(file_name)
433
- end
434
-
435
- def package_as_tgz(file_name, options) #:nodoc:
436
- unless Rake::Task.task_defined?(file_name)
437
- TarballTask.define_task(file_name)
492
+ TarTask.define_task(file_name)
438
493
  end
439
494
  file(file_name)
440
495
  end
496
+ alias :package_as_tgz :package_as_tar
441
497
 
442
498
  def package_as_sources(file_name, options) #:nodoc:
443
499
  rake_check_options options, *PACKAGE_OPTIONS
@@ -86,8 +86,6 @@ module Buildr
86
86
  } if exclusions
87
87
 
88
88
  [Artifact.to_spec(spec.except(:scope))] + transitive_deps
89
- else
90
- nil
91
89
  end
92
90
  }.flatten.compact.uniq_by{|spec| art = spec.split(':'); "#{art[0]}:#{art[1]}"}
93
91
 
@@ -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, :fork=>:once, :properties=>{} }
145
+ DEFAULT_OPTIONS = { :fail_on_failure=>true, :fork=>:once, :properties=>{}, :environment=>{} }
146
146
 
147
147
  # JMock version..
148
148
  JMOCK_VERSION = "1.2.0"
@@ -258,6 +258,7 @@ module Buildr
258
258
  # * :fork -- Fork test cases (JUnit only).
259
259
  # * :java_args -- Java arguments when forking a new JVM.
260
260
  # * :properties -- System properties.
261
+ # * :environment -- Environment variables.
261
262
  #
262
263
  # The :fork option takes the following values:
263
264
  # * :once -- Fork one JVM for each project (default).
@@ -310,7 +311,7 @@ module Buildr
310
311
  patterns = self.class.const_get("#{framework.to_s.upcase}_TESTS_PATTERN").to_a
311
312
  FileList[patterns.map { |pattern| "#{base}/**/#{pattern}.class" }].
312
313
  map { |file| Pathname.new(file).relative_path_from(base).to_s.ext("").gsub(File::SEPARATOR, ".") }.
313
- select { |name| include?(name) }.flatten.sort
314
+ select { |name| include?(name) }.reject { |name| name =~ /\$/ }.sort
314
315
  end
315
316
 
316
317
  # List of failed test classes. Set after running the tests.
@@ -369,7 +370,8 @@ module Buildr
369
370
  :classes => classes,
370
371
  :classpath => @classpath + [compile.target],
371
372
  :properties => { "baseDir" => compile.target.to_s }.merge(options[:properties] || {}),
372
- :java_args => options[:java_args])
373
+ :environment=> options[:environment] || {},
374
+ :java_args => options[:java_args] || Buildr.options.java_args)
373
375
  unless @failed_tests.empty?
374
376
  warn "The following tests failed:\n#{@failed_tests.join("\n")}" if verbose
375
377
  fail "Tests failed!"
@@ -483,9 +485,13 @@ module Buildr
483
485
  else
484
486
  fail "Option fork must be :once, :each or false."
485
487
  end
486
- ant.junit forking do
488
+ ant.junit forking.merge(:clonevm=>true) do
487
489
  ant.classpath :path=>args[:classpath].map(&:to_s).each { |path| file(path).invoke }.join(File::PATH_SEPARATOR)
488
490
  args[:properties].each { |key, value| ant.sysproperty :key=>key, :value=>value }
491
+ args[:environment].each { |key, value| ant.env :key=>key, :value=>value }
492
+ java_args = args[:java_args]
493
+ java_args = java_args.split(" ") if String === java_args
494
+ java_args.each { |value| ant.jvmarg :value=>value } if java_args
489
495
  ant.formatter :type=>"plain"
490
496
  ant.formatter :type=>"xml"
491
497
  ant.formatter :type=>"plain", :usefile=>false # log test