You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@buildr.apache.org by bo...@apache.org on 2010/03/02 06:56:21 UTC
svn commit: r917885 - in /buildr/trunk: CHANGELOG lib/buildr/core/filter.rb
spec/core/compile_spec.rb
Author: boisvert
Date: Tue Mar 2 05:56:21 2010
New Revision: 917885
URL: http://svn.apache.org/viewvc?rev=917885&view=rev
Log:
BUILDR-391 resources task does not detect changes
Modified:
buildr/trunk/CHANGELOG
buildr/trunk/lib/buildr/core/filter.rb
buildr/trunk/spec/core/compile_spec.rb
Modified: buildr/trunk/CHANGELOG
URL: http://svn.apache.org/viewvc/buildr/trunk/CHANGELOG?rev=917885&r1=917884&r2=917885&view=diff
==============================================================================
--- buildr/trunk/CHANGELOG (original)
+++ buildr/trunk/CHANGELOG Tue Mar 2 05:56:21 2010
@@ -73,6 +73,7 @@
task_dependency if artifact exists
* Fixed: BUILDR-384 Buildr fails with rubygems 1.3.6
* Fixed: BUILDR-386 Display JRuby version in buildr -V (Antoine Toulme)
+* Fixed: BUILDR-391 resources task does not detect changes
* Fixed: buildr test=all didn't run all tests as expected
* Fixed: Fail-fast if package.with() or include() called with nil values
* Fixed: Failures not reported correctly for ScalaTest (Alex Eagle)
Modified: buildr/trunk/lib/buildr/core/filter.rb
URL: http://svn.apache.org/viewvc/buildr/trunk/lib/buildr/core/filter.rb?rev=917885&r1=917884&r2=917885&view=diff
==============================================================================
--- buildr/trunk/lib/buildr/core/filter.rb (original)
+++ buildr/trunk/lib/buildr/core/filter.rb Tue Mar 2 05:56:21 2010
@@ -52,9 +52,9 @@
# Returns the list of source directories (each being a file task).
attr_reader :sources
- # :call-seq:
+ # :call-seq:
# clear => self
- #
+ #
# Clear filter sources and include/exclude patterns
def clear
@include = []
@@ -77,7 +77,14 @@
end
# The target directory as a file task.
- attr_reader :target
+ def target
+ return nil unless @target_dir
+ unless @target
+ @target = file(File.expand_path(@target_dir)) { |task| run if @target == task }
+ @target.enhance copy_map.values
+ end
+ @target
+ end
# :call-seq:
# into(dir) => self
@@ -87,7 +94,8 @@
# For example:
# filter.from('src').into('target').using('build'=>Time.now)
def into(dir)
- @target = file(File.expand_path(dir.to_s)) { |task| run if target == task }
+ @target_dir = dir.to_s
+ @target = nil
self
end
@@ -99,17 +107,17 @@
# By default all files are included. You can use this method to only include specific
# files from the source directory.
def include(*files)
- @include += files
+ @include += files.flatten
self
end
- alias :add :include
+ alias :add :include
# :call-seq:
# exclude(*files) => self
#
# Specifies files to exclude and returns self. See FileList#exclude.
def exclude(*files)
- @exclude += files
+ @exclude += files.flatten
self
end
@@ -159,21 +167,8 @@
#
# Runs the filter.
def run
- sources.each { |source| raise "Source directory #{source} doesn't exist" unless File.exist?(source.to_s) }
- raise 'No target directory specified, where am I going to copy the files to?' if target.nil?
+ copy_map = copy_map()
- copy_map = sources.flatten.map(&:to_s).inject({}) do |map, source|
- files = Util.recursive_with_dot_files(source).
- map { |file| Util.relative_path(file, source) }.
- select { |file| @include.empty? || @include.any? { |pattern| File.fnmatch(pattern, file) } }.
- reject { |file| @exclude.any? { |pattern| File.fnmatch(pattern, file) } }
- files.each do |file|
- src, dest = File.expand_path(file, source), File.expand_path(file, target.to_s)
- map[file] = src if !File.exist?(dest) || File.stat(src).mtime >= File.stat(dest).mtime
- end
- map
- end
-
mkpath target.to_s
return false if copy_map.empty?
@@ -196,30 +191,48 @@
true
end
- # Returns the target directory.
+ # Returns the target directory.
def to_s
- @target.to_s
+ target.to_s
+ end
+
+ private
+ def copy_map
+ sources.each { |source| raise "Source directory #{source} doesn't exist" unless File.exist?(source.to_s) }
+ raise 'No target directory specified, where am I going to copy the files to?' if target.nil?
+
+ sources.flatten.map(&:to_s).inject({}) do |map, source|
+ files = Util.recursive_with_dot_files(source).
+ map { |file| Util.relative_path(file, source) }.
+ select { |file| @include.empty? || @include.any? { |pattern| File.fnmatch(pattern, file) } }.
+ reject { |file| @exclude.any? { |pattern| File.fnmatch(pattern, file) } }
+ files.each do |file|
+ src, dest = File.expand_path(file, source), File.expand_path(file, target.to_s)
+ map[file] = src if !File.exist?(dest) || File.stat(src).mtime >= File.stat(dest).mtime
+ end
+ map
+ end
end
# This class implements content replacement logic for Filter.
#
- # To register a new template engine @:foo@, extend this class with a method like:
- #
+ # To register a new template engine @:foo@, extend this class with a method like:
+ #
# def foo_transform(content, path = nil)
# # if this method yields a key, the value comes from the mapping hash
# content.gsub(/world/) { |str| yield :bar }
# end
#
# Then you can use :foo mapping type on a Filter
- #
+ #
# filter.using :foo, :bar => :baz
#
# Or all by your own, simply
#
# Mapper.new(:foo, :bar => :baz).transform("Hello world") # => "Hello baz"
- #
+ #
# You can handle configuration arguments by providing a @*_config@ method like:
- #
+ #
# # The return value of this method is available with the :config accessor.
# def moo_config(*args, &block)
# raise ArgumentError, "Expected moo block" unless block_given?
@@ -235,7 +248,7 @@
# end
#
# Usage for the @:moo@ mapper would be something like:
- #
+ #
# mapper = Mapper.new(:moo, 'ooone', 'twoo') do |str|
# i = nil; str.capitalize.gsub(/\w/) { |s| s.send( (i = !i) ? 'upcase' : 'downcase' ) }
# end
@@ -247,7 +260,7 @@
def initialize(*args, &block) #:nodoc:
using(*args, &block)
end
-
+
def using(*args, &block)
case args.first
when Hash # Maven hash mapping
@@ -294,15 +307,15 @@
def maven_transform(content, path = nil)
content.gsub(/\$\{.*?\}/) { |str| yield(str[2..-2]) || str }
end
-
+
def ant_transform(content, path = nil)
content.gsub(/@.*?@/) { |str| yield(str[1..-2]) || str }
end
-
+
def ruby_transform(content, path = nil)
content.gsub(/#\{.*?\}/) { |str| yield(str[2..-2]) || str }
end
-
+
def regexp_transform(content, path = nil)
content.gsub(mapper_type) { |str| yield(str.scan(mapper_type).join) || str }
end
@@ -310,7 +323,7 @@
def callback_transform(content, path = nil)
config.call(path, content)
end
-
+
def erb_transform(content, path = nil)
case config
when Binding
Modified: buildr/trunk/spec/core/compile_spec.rb
URL: http://svn.apache.org/viewvc/buildr/trunk/spec/core/compile_spec.rb?rev=917885&r1=917884&r2=917885&view=diff
==============================================================================
--- buildr/trunk/spec/core/compile_spec.rb (original)
+++ buildr/trunk/spec/core/compile_spec.rb Tue Mar 2 05:56:21 2010
@@ -21,11 +21,11 @@
def compile_task
@compile_task ||= define('foo').compile.using(:javac)
end
-
+
def compile_task_without_compiler
@compile_task ||= define('foo').compile
end
-
+
def file_task
@file_taks ||= define('bar').file('src')
end
@@ -112,7 +112,7 @@
it 'should be nil if no compiler identifier' do
define('foo').compile.compiler.should be_nil
end
-
+
it 'should return the selected compiler' do
define('foo') { compile.using(:javac) }
project('foo').compile.compiler.should eql(:javac)
@@ -140,7 +140,7 @@
it 'should be nil if no compiler identifier' do
define('foo').compile.language.should be_nil
end
-
+
it 'should return the appropriate language' do
define('foo') { compile.using(:javac) }
project('foo').compile.language.should eql(:java)
@@ -254,7 +254,7 @@
compile_task.options.foo = 'bar'
compile_task.options.foo.should eql('bar')
end
-
+
it 'should have bracket accessors' do
compile_task.options[:foo] = 'bar'
compile_task.options[:foo].should eql('bar')
@@ -563,6 +563,31 @@
file('target/resources/foo').should contain('Foo')
end
+ it 'should copy new resources to target directory' do
+ time = Time.now
+ mkdir_p 'target/resources'
+ File.utime(time-1, time-1, 'target/resources')
+
+ write 'src/main/resources/foo', 'Foo'
+
+ define('foo')
+ project('foo').file('target/resources').invoke
+ file('target/resources/foo').should exist
+ end
+
+ it 'should copy updated resources to target directory' do
+ time = Time.now
+ mkdir_p 'target/resources'
+ write 'target/resources/foo', 'Foo'
+ File.utime(time-1, time-1, 'target/resources')
+ File.utime(time-1, time-1, 'target/resources/foo')
+
+ write 'src/main/resources/foo', 'Foo2'
+ define('foo')
+ project('foo').file('target/resources').invoke
+ file('target/resources/foo').should contain('Foo2')
+ end
+
it 'should not create target directory unless there are resources' do
define('foo').compile.invoke
file('target/resources').should_not exist