You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@buildr.apache.org by to...@apache.org on 2017/07/31 03:39:23 UTC

[1/3] buildr git commit: Add a transform method when merging artifacts to transform file contents

Repository: buildr
Updated Branches:
  refs/heads/master ae5287300 -> a5340ee0d


Add a transform method when merging artifacts to transform file contents


Project: http://git-wip-us.apache.org/repos/asf/buildr/repo
Commit: http://git-wip-us.apache.org/repos/asf/buildr/commit/d08c7bcb
Tree: http://git-wip-us.apache.org/repos/asf/buildr/tree/d08c7bcb
Diff: http://git-wip-us.apache.org/repos/asf/buildr/diff/d08c7bcb

Branch: refs/heads/master
Commit: d08c7bcb687ecca3e5ff4752a2db2541a9dadb64
Parents: ae52873
Author: Antoine Toulme <an...@lunar-ocean.com>
Authored: Sun Jul 30 02:06:25 2017 -0700
Committer: Antoine Toulme <an...@lunar-ocean.com>
Committed: Sun Jul 30 14:51:51 2017 -0700

----------------------------------------------------------------------
 CHANGELOG                       |  1 +
 lib/buildr/packaging/archive.rb | 37 ++++++++++++++++++++++++++++--------
 lib/buildr/packaging/tar.rb     | 33 +++++++++++++++++++++++++-------
 lib/buildr/packaging/ziptask.rb | 31 +++++++++++++++++++++++-------
 spec/packaging/archive_spec.rb  | 16 ++++++++++++++++
 5 files changed, 96 insertions(+), 22 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/buildr/blob/d08c7bcb/CHANGELOG
----------------------------------------------------------------------
diff --git a/CHANGELOG b/CHANGELOG
index 91b01e4..f99cfa9 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -2,6 +2,7 @@
 * Added: Support to compiling Kotlin
 * Fixed: Remove section on development builds in the Contributing section.
 * Added: New way to concatenate file contents when merging several archives together.
+* Added: New way to transform file contents when merging several archives together.
 
 1.5.3 (2017-05-17)
 * Change: Add support for gwt 2.8.1 to gwt addon.

http://git-wip-us.apache.org/repos/asf/buildr/blob/d08c7bcb/lib/buildr/packaging/archive.rb
----------------------------------------------------------------------
diff --git a/lib/buildr/packaging/archive.rb b/lib/buildr/packaging/archive.rb
index cd24fa4..78df00e 100644
--- a/lib/buildr/packaging/archive.rb
+++ b/lib/buildr/packaging/archive.rb
@@ -112,9 +112,9 @@ module Buildr #:nodoc:
         expanders = files.collect do |file|
           @sources << proc { file.to_s }
           expander = ZipExpander.new(file)
-          @actions << proc do |file_map|
+          @actions << proc do |file_map, transform_map|
             file.invoke() if file.is_a?(Rake::Task)
-            expander.expand(file_map, path)
+            expander.expand(file_map, transform_map, path)
           end
           expander
         end
@@ -133,8 +133,8 @@ module Buildr #:nodoc:
         @sources.map{ |source| source.call }.flatten
       end
 
-      def add_files(file_map) #:nodoc:
-        @actions.each { |action| action.call(file_map) }
+      def add_files(file_map, transform_map) #:nodoc:
+        @actions.each { |action| action.call(file_map, transform_map) }
       end
 
       # :call-seq:
@@ -272,6 +272,11 @@ module Buildr #:nodoc:
         @expanders.each { |expander| expander.concatenate(*files) }
         self
       end
+      
+      def transform(*files, &block)
+        @expanders.each { |expander| expander.transform(*files, &block) }
+        self
+      end
     end
 
 
@@ -283,6 +288,7 @@ module Buildr #:nodoc:
         @includes = []
         @excludes = []
         @concatenates = []
+        @transforms = {}
       end
 
       def include(*files)
@@ -300,8 +306,13 @@ module Buildr #:nodoc:
         @concatenates |= files
         self
       end
+      
+      def transform(*files, &block)
+        @transforms[[files].flatten] = block
+        self
+      end
 
-      def expand(file_map, path)
+      def expand(file_map, transform_map, path)
         @includes = ['*'] if @includes.empty?
         Zip::File.open(@zip_file) do |source|
           source.entries.reject { |entry| entry.directory? }.each do |entry|
@@ -311,6 +322,14 @@ module Buildr #:nodoc:
               trace "Adding #{dest}"
               if @concatenates.any? { |pattern| File.fnmatch(pattern, entry.name) }
                 file_map[dest] << ZipEntryData.new(source, entry)
+              elsif @transforms.each_pair.detect do |transform, transform_block|\
+                  if transform.any? { |pattern| File.fnmatch(pattern, entry.name) }
+                    file_map[dest] << ZipEntryData.new(source, entry)
+                    
+                    transform_map[dest] = transform_block
+                    true
+                  end
+                end
               else
                 file_map[dest] = ZipEntryData.new(source, entry)
               end
@@ -343,6 +362,7 @@ module Buildr #:nodoc:
       # Make sure we're the last enhancements, so other enhancements can add content.
       enhance do
         @file_map = Hash.new {|h,k| h[k]=[]}
+        @transform_map = {}
         enhance do
           send 'create' if respond_to?(:create)
           # We're here because the archive file does not exist, or one of the files is newer than the archive contents;
@@ -353,9 +373,9 @@ module Buildr #:nodoc:
           begin
             @paths.each do |name, object|
               @file_map[name] = nil unless name.empty?
-              object.add_files(@file_map)
+              object.add_files(@file_map, @transform_map)
             end
-            create_from @file_map
+            create_from @file_map, @transform_map
           rescue
             rm name rescue nil
             raise
@@ -501,8 +521,9 @@ module Buildr #:nodoc:
       @prepares.clear
 
       file_map = Hash.new {|h,k| h[k]=[]}
+      transform_map = {}
       @paths.each do |name, path|
-        path.add_files(file_map)
+        path.add_files(file_map, transform_map)
       end
 
       # filter out Procs (dynamic content), nils and others

http://git-wip-us.apache.org/repos/asf/buildr/blob/d08c7bcb/lib/buildr/packaging/tar.rb
----------------------------------------------------------------------
diff --git a/lib/buildr/packaging/tar.rb b/lib/buildr/packaging/tar.rb
index 8e094a4..16a3816 100644
--- a/lib/buildr/packaging/tar.rb
+++ b/lib/buildr/packaging/tar.rb
@@ -74,23 +74,25 @@ module Buildr #:nodoc:
 
     private
 
-    def create_from(file_map)
+    def create_from(file_map, transform_map)
       if gzip
         StringIO.new.tap do |io|
-          create_tar io, file_map
+          create_tar io, file_map, transform_map
           io.seek 0
           Zlib::GzipWriter.open(name) { |gzip| gzip.write io.read }
         end
       else
-        File.open(name, 'wb') { |file| create_tar file, file_map }
+        File.open(name, 'wb') { |file| create_tar file, file_map, transform_map }
       end
     end
 
-    def create_tar(out, file_map)
+    def create_tar(out, file_map, transform_map)
       Archive::Tar::Minitar::Writer.open(out) do |tar|
         options = { :mode=>mode || '0755', :mtime=>Time.now }
 
         file_map.each do |path, contents|
+          to_transform = []
+          transform = transform_map.key?(path)
           if contents.nil?
           elsif File.directory?(contents.to_s)
             stat = File.stat(contents.to_s)
@@ -110,15 +112,32 @@ module Buildr #:nodoc:
             tar.add_file path, combined_options do |os, opts|
               [contents].flatten.each do |content|
                 if content.respond_to?(:call)
-                  content.call os
+                  if transform
+                    output = StringIO.new
+                    content.call output
+                    to_transform << output.string
+                  else
+                    content.call os
+                  end
                 else
                   File.open content.to_s, 'rb' do |is| 
-                    while data = is.read(4096)
-                      os.write(data)
+                    if transform
+                      output = StringIO.new
+                      while data = is.read(4096)
+                        output << data
+                      end
+                      to_transform << output.string
+                    else
+                      while data = is.read(4096)
+                        os.write(data)
+                      end
                     end
                   end
                 end
               end
+              if transform_map.key?(path)
+                os.write(transform_map[path].call(to_transform))
+              end
             end
           end
           

http://git-wip-us.apache.org/repos/asf/buildr/blob/d08c7bcb/lib/buildr/packaging/ziptask.rb
----------------------------------------------------------------------
diff --git a/lib/buildr/packaging/ziptask.rb b/lib/buildr/packaging/ziptask.rb
index 3b9f97d..8190e7b 100644
--- a/lib/buildr/packaging/ziptask.rb
+++ b/lib/buildr/packaging/ziptask.rb
@@ -51,7 +51,7 @@ module Buildr #:nodoc:
 
     private
 
-    def create_from(file_map)
+    def create_from(file_map, transform_map)
       Zip::OutputStream.open name do |zip|
         seen = {}
         mkpath = lambda do |dir|
@@ -69,14 +69,22 @@ module Buildr #:nodoc:
           warn "Warning:  Path in zipfile #{name} contains backslash: #{path}" if path =~ /\\/
           
           entry_created = false
+          to_transform = []
+          transform = transform_map.key?(path)
           [contents].flatten.each do |content|
             if content.respond_to?(:call)
               unless entry_created
-                entry = zip.put_next_entry(path, compression_level) unless entry_created
+                entry = zip.put_next_entry(path, compression_level)
                 entry.unix_perms = content.mode & 07777 if content.respond_to?(:mode)
                 entry_created = true
               end
-              content.call zip
+              if transform
+                output = StringIO.new
+                content.call output
+                to_transform << output.string
+              else
+                content.call zip
+              end
             elsif content.nil? || File.directory?(content.to_s)
               mkpath.call path
             else
@@ -86,14 +94,23 @@ module Buildr #:nodoc:
                   entry.unix_perms = is.stat.mode & 07777
                   entry_created = true
                 end
-                
-                
-                while data = is.read(4096)
-                  zip << data
+                if transform
+                  output = StringIO.new
+                  while data = is.read(4096)
+                    output << data
+                  end
+                  to_transform << output.string
+                else
+                  while data = is.read(4096)
+                    zip << data
+                  end
                 end
               end
             end
           end
+          if transform_map.key?(path)
+            zip << transform_map[path].call(to_transform)
+          end
         end
       end
     end

http://git-wip-us.apache.org/repos/asf/buildr/blob/d08c7bcb/spec/packaging/archive_spec.rb
----------------------------------------------------------------------
diff --git a/spec/packaging/archive_spec.rb b/spec/packaging/archive_spec.rb
index 6da2365..46f1151 100644
--- a/spec/packaging/archive_spec.rb
+++ b/spec/packaging/archive_spec.rb
@@ -320,6 +320,22 @@ shared_examples_for 'ArchiveTask' do
       archive['test1.txt'].should eql(content_for('test1.txt') * @files.size)
     end
   end
+  
+  it 'should merge archives, transforming file contents' do
+    @files = %w{foo1 foo2}.map { |folder| File.join(@dir, folder) }.
+      map do |dir|
+        txt_file = File.join(dir, 'test1.txt')
+        write txt_file, content_for('test1.txt')
+        zip(File.join(dir, 'test1.zip')).include(txt_file)
+      end
+    archive(@archive).merge(@files).transform("test1.txt") do |matches|
+      matches.join("\n=====\n")
+    end
+    archive(@archive).invoke
+    inspect_archive do |archive|
+      archive['test1.txt'].should eql("#{content_for('test1.txt')}\n=====\n#{content_for('test1.txt')}")
+    end
+  end
 
   it 'should expand another archive file into path' do
     create_for_merge do |src|


[3/3] buildr git commit: Remove all .class files from git repository. Ignore .class files going forward

Posted by to...@apache.org.
Remove all .class files from git repository. Ignore .class files going forward


Project: http://git-wip-us.apache.org/repos/asf/buildr/repo
Commit: http://git-wip-us.apache.org/repos/asf/buildr/commit/a5340ee0
Tree: http://git-wip-us.apache.org/repos/asf/buildr/tree/a5340ee0
Diff: http://git-wip-us.apache.org/repos/asf/buildr/diff/a5340ee0

Branch: refs/heads/master
Commit: a5340ee0dcff30b696e094256ea5efbd397657b7
Parents: dbdcaa1
Author: Antoine Toulme <an...@lunar-ocean.com>
Authored: Sun Jul 30 20:38:48 2017 -0700
Committer: Antoine Toulme <an...@lunar-ocean.com>
Committed: Sun Jul 30 20:38:48 2017 -0700

----------------------------------------------------------------------
 .gitignore                                          |   2 +-
 CHANGELOG                                           |   1 +
 .../buildr/org/apache/buildr/BuildrNail$Main.class  | Bin 561 -> 0 bytes
 addon/buildr/org/apache/buildr/BuildrNail.class     | Bin 256 -> 0 bytes
 addon/buildr/org/apache/buildr/JettyWrapper$1.class | Bin 220 -> 0 bytes
 .../apache/buildr/JettyWrapper$BuildrHandler.class  | Bin 3903 -> 0 bytes
 addon/buildr/org/apache/buildr/JettyWrapper.class   | Bin 1432 -> 0 bytes
 .../java/org/apache/buildr/JavaTestFilter.class     | Bin 3941 -> 0 bytes
 .../apache/buildr/KotlinMessageCollector$1.class    | Bin 852 -> 0 bytes
 .../org/apache/buildr/KotlinMessageCollector.class  | Bin 1591 -> 0 bytes
 10 files changed, 2 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/buildr/blob/a5340ee0/.gitignore
----------------------------------------------------------------------
diff --git a/.gitignore b/.gitignore
index 63a162d..fcb4db3 100644
--- a/.gitignore
+++ b/.gitignore
@@ -25,6 +25,6 @@
 /Gemfile.lock
 *.rbc
 /site
-/lib/buildr/scala/org/apache/buildr/Specs2Runner.class
 .bundle
 .DS_Store
+*.class
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/buildr/blob/a5340ee0/CHANGELOG
----------------------------------------------------------------------
diff --git a/CHANGELOG b/CHANGELOG
index f99cfa9..076a2de 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -3,6 +3,7 @@
 * Fixed: Remove section on development builds in the Contributing section.
 * Added: New way to concatenate file contents when merging several archives together.
 * Added: New way to transform file contents when merging several archives together.
+* Fixed: Removed .class files from being checked in.
 
 1.5.3 (2017-05-17)
 * Change: Add support for gwt 2.8.1 to gwt addon.

http://git-wip-us.apache.org/repos/asf/buildr/blob/a5340ee0/addon/buildr/org/apache/buildr/BuildrNail$Main.class
----------------------------------------------------------------------
diff --git a/addon/buildr/org/apache/buildr/BuildrNail$Main.class b/addon/buildr/org/apache/buildr/BuildrNail$Main.class
deleted file mode 100644
index 8bb9ecd..0000000
Binary files a/addon/buildr/org/apache/buildr/BuildrNail$Main.class and /dev/null differ

http://git-wip-us.apache.org/repos/asf/buildr/blob/a5340ee0/addon/buildr/org/apache/buildr/BuildrNail.class
----------------------------------------------------------------------
diff --git a/addon/buildr/org/apache/buildr/BuildrNail.class b/addon/buildr/org/apache/buildr/BuildrNail.class
deleted file mode 100644
index fbb8563..0000000
Binary files a/addon/buildr/org/apache/buildr/BuildrNail.class and /dev/null differ

http://git-wip-us.apache.org/repos/asf/buildr/blob/a5340ee0/addon/buildr/org/apache/buildr/JettyWrapper$1.class
----------------------------------------------------------------------
diff --git a/addon/buildr/org/apache/buildr/JettyWrapper$1.class b/addon/buildr/org/apache/buildr/JettyWrapper$1.class
deleted file mode 100644
index c1ac1ea..0000000
Binary files a/addon/buildr/org/apache/buildr/JettyWrapper$1.class and /dev/null differ

http://git-wip-us.apache.org/repos/asf/buildr/blob/a5340ee0/addon/buildr/org/apache/buildr/JettyWrapper$BuildrHandler.class
----------------------------------------------------------------------
diff --git a/addon/buildr/org/apache/buildr/JettyWrapper$BuildrHandler.class b/addon/buildr/org/apache/buildr/JettyWrapper$BuildrHandler.class
deleted file mode 100644
index 943fcbd..0000000
Binary files a/addon/buildr/org/apache/buildr/JettyWrapper$BuildrHandler.class and /dev/null differ

http://git-wip-us.apache.org/repos/asf/buildr/blob/a5340ee0/addon/buildr/org/apache/buildr/JettyWrapper.class
----------------------------------------------------------------------
diff --git a/addon/buildr/org/apache/buildr/JettyWrapper.class b/addon/buildr/org/apache/buildr/JettyWrapper.class
deleted file mode 100644
index 2e22f95..0000000
Binary files a/addon/buildr/org/apache/buildr/JettyWrapper.class and /dev/null differ

http://git-wip-us.apache.org/repos/asf/buildr/blob/a5340ee0/lib/buildr/java/org/apache/buildr/JavaTestFilter.class
----------------------------------------------------------------------
diff --git a/lib/buildr/java/org/apache/buildr/JavaTestFilter.class b/lib/buildr/java/org/apache/buildr/JavaTestFilter.class
deleted file mode 100644
index f65575b..0000000
Binary files a/lib/buildr/java/org/apache/buildr/JavaTestFilter.class and /dev/null differ

http://git-wip-us.apache.org/repos/asf/buildr/blob/a5340ee0/lib/buildr/kotlin/org/apache/buildr/KotlinMessageCollector$1.class
----------------------------------------------------------------------
diff --git a/lib/buildr/kotlin/org/apache/buildr/KotlinMessageCollector$1.class b/lib/buildr/kotlin/org/apache/buildr/KotlinMessageCollector$1.class
deleted file mode 100644
index 5bb12fd..0000000
Binary files a/lib/buildr/kotlin/org/apache/buildr/KotlinMessageCollector$1.class and /dev/null differ

http://git-wip-us.apache.org/repos/asf/buildr/blob/a5340ee0/lib/buildr/kotlin/org/apache/buildr/KotlinMessageCollector.class
----------------------------------------------------------------------
diff --git a/lib/buildr/kotlin/org/apache/buildr/KotlinMessageCollector.class b/lib/buildr/kotlin/org/apache/buildr/KotlinMessageCollector.class
deleted file mode 100644
index 958ef1d..0000000
Binary files a/lib/buildr/kotlin/org/apache/buildr/KotlinMessageCollector.class and /dev/null differ


[2/3] buildr git commit: Documentation to packaging doc to document the new concatenate and transform methods

Posted by to...@apache.org.
Documentation to packaging doc to document the new concatenate and transform methods


Project: http://git-wip-us.apache.org/repos/asf/buildr/repo
Commit: http://git-wip-us.apache.org/repos/asf/buildr/commit/dbdcaa1b
Tree: http://git-wip-us.apache.org/repos/asf/buildr/tree/dbdcaa1b
Diff: http://git-wip-us.apache.org/repos/asf/buildr/diff/dbdcaa1b

Branch: refs/heads/master
Commit: dbdcaa1bfc08d2c80ccb6eb61d9b13759c66f3e3
Parents: d08c7bc
Author: Antoine Toulme <an...@lunar-ocean.com>
Authored: Sun Jul 30 15:04:43 2017 -0700
Committer: Antoine Toulme <an...@lunar-ocean.com>
Committed: Sun Jul 30 15:04:43 2017 -0700

----------------------------------------------------------------------
 doc/packaging.textile | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/buildr/blob/dbdcaa1b/doc/packaging.textile
----------------------------------------------------------------------
diff --git a/doc/packaging.textile b/doc/packaging.textile
index 318a8c8..6ea599a 100644
--- a/doc/packaging.textile
+++ b/doc/packaging.textile
@@ -142,6 +142,8 @@ For example, when you use @package :jar@, under the hood it specifies to include
 
 If you need to get rid of all the included files, call the @clean@ method. Some packaging types default to adding various files and directories, for example, JAR packaging will include all the compiled classes and resources.
 
+h2(#merging). Merging archives
+
 You can also merge two ZIP files together, expanding the content of one ZIP into the other.  For example:
 
 {% highlight ruby %}
@@ -155,6 +157,25 @@ If you need to be more selective, you can apply the include/exclude pattern to t
 package(:zip).merge(_('bigbad.war')).exclude('libs/**/*')
 {% endhighlight %}
 
+h3(#transforming). Transforming files while merging them
+
+You may need to have special treatment for files that you are merging from multiple locations.
+
+If you wish to concatenate the file contents, you can perform the following:
+
+{% highlight ruby %}
+package(:zip).merge(_('part1.zip'), _('part2.zip')).concatenate('META-INF/services/spring.providers')
+{% endhighlight %}
+
+If you need to transform the file contents to assemble the final output, you can work with the @transform@ method.
+The transform method takes a block to process the contents of all the matching paths, as the zip file is assembled.
+
+{% highlight ruby %}
+package(:zip).merge(_('part1.zip'), _('part2.zip')).transform('plugin.xml') do |plugin_xml_files|
+  return "<plugin>#{plugin_xml_files.map {|xml| xml.match('<plugin>(.*)</plugin>')[1]}}</plugin>"
+end
+{% endhighlight %}
+
 
 h2(#jar). Packaging JARs