Author: boisvert Date: Fri Jan 28 20:03:57 2011 New Revision: 1064850 URL: http://svn.apache.org/viewvc?rev=1064850&view=rev Log: BUILDR-562 WAR package isn't updated if files under src/main/webapp are updated
Modified: buildr/trunk/CHANGELOG buildr/trunk/lib/buildr/packaging/archive.rb buildr/trunk/lib/buildr/packaging/tar.rb buildr/trunk/spec/packaging/archive_spec.rb Modified: buildr/trunk/CHANGELOG URL: http://svn.apache.org/viewvc/buildr/trunk/CHANGELOG?rev=1064850&r1=1064849&r2=1064850&view=diff ============================================================================== --- buildr/trunk/CHANGELOG (original) +++ buildr/trunk/CHANGELOG Fri Jan 28 20:03:57 2011 @@ -36,6 +36,8 @@ * Fixed: BUILDR-558 Artifact uploads should show a progress bar (Tammo van Lessen) * Fixed: BUILDR-560 show a meaning full error message when POM cannot be parsed (Tammo van Lessen) +* Fixed: BUILDR-562 WAR package isn't updated if files under src/main/webapp + are updated * Fixed: Scaladoc task would cause build to exit prematurely 1.4.4 (2010-11-16) Modified: buildr/trunk/lib/buildr/packaging/archive.rb URL: http://svn.apache.org/viewvc/buildr/trunk/lib/buildr/packaging/archive.rb?rev=1064850&r1=1064849&r2=1064850&view=diff ============================================================================== --- buildr/trunk/lib/buildr/packaging/archive.rb (original) +++ buildr/trunk/lib/buildr/packaging/archive.rb Fri Jan 28 20:03:57 2011 @@ -113,7 +113,10 @@ module Buildr expanders = files.collect do |file| @sources << proc { file.to_s } expander = ZipExpander.new(file) - @actions << proc { |file_map| expander.expand(file_map, path) } + @actions << proc do |file_map| + file.invoke() if file.is_a?(Rake::Task) + expander.expand(file_map, path) + end expander end Merge.new(expanders) @@ -202,7 +205,6 @@ module Buildr end def include_as(source, as) - @sources << proc { source } @actions << proc do |file_map| file = source.to_s @@ -467,7 +469,15 @@ module Buildr def invoke_prerequisites(args, chain) #:nodoc: @prepares.each { |prepare| prepare.call(self) } @prepares.clear - @prerequisites |= @paths.collect { |name, path| path.sources }.flatten + + file_map = {} + @paths.each do |name, path| + path.add_files(file_map) + end + + # filter out Procs (dynamic content), nils and others + @prerequisites |= file_map.values.select { |src| src.is_a?(String) || src.is_a?(Rake::Task) } + super end Modified: buildr/trunk/lib/buildr/packaging/tar.rb URL: http://svn.apache.org/viewvc/buildr/trunk/lib/buildr/packaging/tar.rb?rev=1064850&r1=1064849&r2=1064850&view=diff ============================================================================== --- buildr/trunk/lib/buildr/packaging/tar.rb (original) +++ buildr/trunk/lib/buildr/packaging/tar.rb Fri Jan 28 20:03:57 2011 @@ -95,7 +95,10 @@ module Buildr file_map.each do |path, content| if content.respond_to?(:call) tar.add_file(path, options) { |os, opts| content.call os } - elsif content.nil? || File.directory?(content.to_s) + elsif content.nil? + elsif File.directory?(content.to_s) + stat = File.stat(content.to_s) + tar.mkdir(path, options.merge(:mode=>stat.mode, :mtime=>stat.mtime)) else File.open content.to_s, 'rb' do |is| tar.add_file path, options.merge(:mode=>is.stat.mode, :mtime=>is.stat.mtime, :uid=>is.stat.uid, :gid=>is.stat.gid) do |os, opts| Modified: buildr/trunk/spec/packaging/archive_spec.rb URL: http://svn.apache.org/viewvc/buildr/trunk/spec/packaging/archive_spec.rb?rev=1064850&r1=1064849&r2=1064850&view=diff ============================================================================== --- buildr/trunk/spec/packaging/archive_spec.rb (original) +++ buildr/trunk/spec/packaging/archive_spec.rb Fri Jan 28 20:03:57 2011 @@ -23,11 +23,20 @@ module ArchiveTaskHelpers "Content for #{File.basename(file)}" end + # Qualify a filename + # + # e.g. qualify("file.zip", "src") => "file-src.zip" + def qualify(filename, qualifier) + ext = (filename =~ /\.$/) ? "." : File.extname(filename) + base = filename[0..0-ext.size-1] + base + "-" + qualifier + ext + end + # Create an archive not using the archive task, this way we do have a file in existence, but we don't # have an already invoked task. Yield an archive task to the block which can use it to include files, # set options, etc. def create_without_task - archive(@archive + '.tmp').tap do |task| + archive(qualify(@archive, "tmp")).tap do |task| yield task if block_given? task.invoke mv task.name, @archive @@ -35,7 +44,7 @@ module ArchiveTaskHelpers end def create_for_merge - zip(@archive + '.src').include(@files).tap do |task| + zip(qualify(@archive, "src")).include(@files).tap do |task| yield task end end @@ -291,7 +300,7 @@ shared_examples_for 'ArchiveTask' do it 'should expand another archive file with nested exclude pattern' do @files = %w{Test1.txt Text2.html}.map { |file| File.join(@dir, "foo", file) }. each { |file| write file, content_for(file) } - zip(@archive + '.src').include(@dir).tap do |task| + zip(qualify(@archive, "src")).include(@dir).tap do |task| archive(@archive).merge(task).exclude('test/*') archive(@archive).invoke inspect_archive.should be_empty @@ -339,6 +348,22 @@ shared_examples_for 'ArchiveTask' do File.stat(@archive).mtime.should be_close(Time.now, 10) end + it 'should update if a file in a subdir is more recent' do + subdir = File.expand_path("subdir", @dir) + test3 = File.expand_path("test3.css", subdir) + + mkdir_p subdir + write test3, '/* Original */' + + create_without_task { |archive| archive.include(:from => @dir) } + inspect_archive { |archive| archive["subdir/test3.css"].should eql('/* Original */') } + + write test3, '/* Refreshed */' + File.utime(Time.now + 100, Time.now + 100, test3) + archive(@archive).include(:from => @dir).invoke + inspect_archive { |archive| archive["subdir/test3.css"].should eql('/* Refreshed */') } + end + it 'should do nothing if all files are uptodate' do create_without_task { |archive| archive.include(@files) } # By touching all files in the past, there's nothing new to update.