buildr 1.2.5 → 1.2.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,112 +1,87 @@
1
- require 'buildr'
1
+ require 'tasks/zip'
2
2
  require 'archive/tar/minitar'
3
3
 
4
4
  module Buildr
5
- class TarTask < Rake::FileTask
6
5
 
7
- attr_reader :included
6
+ # The TarTask creates a new Tar file. You can include any number of files and and directories,
7
+ # use exclusion patterns, and include files into specific directories.
8
+ #
9
+ # To create a GZipped Tar, either set the gzip option to true, or use the .tgz or .gz suffix.
10
+ #
11
+ # For example:
12
+ # tar("test.tgz").tap do |task|
13
+ # task.include "srcs"
14
+ # task.include "README", "LICENSE"
15
+ # end
16
+ #
17
+ # See Buildr#tar and ArchiveTask.
18
+ class TarTask < ArchiveTask
8
19
 
9
- def initialize(*args)
10
- super
11
- @included = {}
12
- enhance do
13
- $stdout << "Creating #{t.name}.\n" if verbose
14
- rm(name, :verbose=>false) rescue nil
15
- mkdir_p(File.dirname(name), :verbose=>false)
16
- begin
17
- out = File.new(name, "w+")
18
- out = Zlib::GzipWriter.new(out) if (/.tgz$/ =~ name)
19
- create_tar_internal(out)
20
- rescue
21
- rm(name, :verbose=>false) rescue nil
22
- raise
23
- end
24
- end
25
- end
20
+ # To create a GZipped Tar, either set this option to true, or use the .tgz/.gz suffix.
21
+ attr_accessor :gzip
22
+ # Permission mode for files contained in the Tar. Defaults to 0755.
23
+ attr_accessor :mode
26
24
 
27
- def with(options)
28
- options.each do |k,v|
29
- send "#{k}=", v
30
- end
31
- end
32
-
33
- def include(*args)
34
- options = (Hash === args.last) ? args.pop : {}
35
- args = args.flatten
36
- options[:path] ||= "/"
37
- check_add_path_internal options
38
- if options[:as]
39
- raise "Only use :as with one include file at a time" if args.length > 1
40
- dest_file = File.join(options[:path], options[:as])
41
- include_internal(dest_file, args.pop, options)
42
- else
43
- args.each do |f|
44
- dest_file = File.join(options[:path], File.basename(f.to_s))
45
- include_internal(dest_file, f, options)
46
- end
47
- end
25
+ def initialize(*args, &block) #:nodoc:
26
+ super
27
+ self.gzip = name =~ /\.[t?]gz$/
28
+ self.mode = '0755'
48
29
  end
49
30
 
50
31
  private
51
32
 
52
- def check_add_path_internal(opts)
53
- unless @included.has_key?(opts[:path])
54
- include_internal(opts[:path], :mkdir_in_tar, opts)
33
+ def create_from(file_map)
34
+ if gzip
35
+ StringIO.new.tap do |io|
36
+ create_tar io, file_map
37
+ io.seek 0
38
+ Zlib::GzipWriter.open(name) { |gzip| gzip.write io.read }
39
+ end
40
+ else
41
+ File.open(name, 'wb') { |file| create_tar file, file_map }
55
42
  end
56
43
  end
57
44
 
58
- def include_internal(dst, src, opts)
59
- raise %Q("#{dst}" was already included in the archive with source path "#{@included[dst][:source_path]}".) if @included[dst]
60
- @included[dst] = opts.merge({:source_path => src})
61
- enhance([src]) unless :mkdir_in_tar == src
62
- end
45
+ def create_tar(out, file_map)
46
+ Archive::Tar::Minitar::Writer.open(out) do |tar|
47
+ options = { :mode=>mode || '0755', :mtime=>Time.now }
63
48
 
64
- def create_tar_internal(out)
65
- begin
66
- Archive::Tar::Minitar::Writer.open(out) do |tar|
67
- @included.keys.sort.each do |dst|
68
- opts = @included[dst]
69
- src = opts[:source_path]
70
- if :mkdir_in_tar == src
71
- $stdout << "adding directory #{dst}.\n" if verbose
72
- tar.mkdir(dst, {:mode=>"0755", :mtime=>Time.now}.merge(opts.reject{|k,v| not [:mode, :uid, :gid, :mtime].include?(k)}))
73
- else
74
- $stdout << "adding #{dst} from #{src}\n" if verbose
75
- is = File.new(src, "rb")
76
- opts[:size] = is.stat.size
77
- opts[:mode] ||= is.stat.mode
78
- opts[:mtime] ||= is.stat.mtime
79
- opts[:uid] ||= 80
80
- opts[:gid] ||= 80
81
- tar.add_file_simple(dst, opts.reject{|k,v| not [:size, :mode, :uid, :gid, :mtime].include?(k)}) do |os|
49
+ file_map.each do |path, content|
50
+ if content.respond_to?(:call)
51
+ tar.add_file(path, options) { |os, opts| content.call os }
52
+ elsif content.nil? || File.directory?(content.to_s)
53
+ else
54
+ File.open content.to_s, 'rb' do |is|
55
+ 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|
82
56
  while data = is.read(4096)
83
57
  os.write(data)
84
- $stdout << "." if verbose
85
58
  end
86
59
  end
87
- $stdout << "\n" if verbose
88
60
  end
89
61
  end
90
62
  end
91
- ensure out.close
92
63
  end
93
64
  end
94
- end
95
-
96
- class TarballTask < TarTask
97
65
 
98
- def initialize(*args)
99
- super
100
- end
66
+ end
101
67
 
102
- def include(*args)
103
- options = (Hash === args.last) ? args.pop : {}
104
- args = args.flatten
105
- options[:path] ||= "/"
106
- options[:path] = File.join(name.pathmap("%n"), options[:path])
107
- super args, options
108
- end
68
+ end
109
69
 
110
- end
111
70
 
71
+ # :call-seq:
72
+ # tar(file) => TarTask
73
+ #
74
+ # The TarTask creates a new Tar file. You can include any number of files and
75
+ # and directories, use exclusion patterns, and include files into specific
76
+ # directories.
77
+ #
78
+ # To create a GZipped Tar, either set the gzip option to true, or use the .tgz or .gz suffix.
79
+ #
80
+ # For example:
81
+ # tar("test.tgz").tap do |tgz|
82
+ # tgz.include "srcs"
83
+ # tgz.include "README", "LICENSE"
84
+ # end
85
+ def tar(file)
86
+ TarTask.define_task(file)
112
87
  end
@@ -17,22 +17,25 @@ module Buildr
17
17
  def initialize(root, path)
18
18
  @root = root
19
19
  @path = path.blank? ? path : "#{path}/"
20
- @files = FileList[]
20
+ @includes = FileList[]
21
+ @excludes = []
21
22
  # Expand source files added to this path.
22
- expand_src = proc { @files.map{ |file| file.to_s }.uniq }
23
+ expand_src = proc { @includes.map{ |file| file.to_s }.uniq }
23
24
  @sources = [ expand_src ]
24
25
  # Add files and directories added to this path.
25
26
  @actions = [] << proc do |file_map|
26
27
  expand_src.call.each do |path|
27
- if File.directory?(path)
28
- in_directory(path, @files) do |file, rel_path|
29
- dest = "#{@path}#{rel_path}"
30
- puts "Adding #{dest}" if Rake.application.options.trace
31
- file_map[dest] = file
28
+ unless excluded?(path)
29
+ if File.directory?(path)
30
+ in_directory path do |file, rel_path|
31
+ dest = "#{@path}#{rel_path}"
32
+ puts "Adding #{dest}" if Rake.application.options.trace
33
+ file_map[dest] = file
34
+ end
35
+ else
36
+ puts "Adding #{@path}#{File.basename(path)}" if Rake.application.options.trace
37
+ file_map["#{@path}#{File.basename(path)}"] = path
32
38
  end
33
- else
34
- puts "Adding #{@path}#{File.basename(path)}" if Rake.application.options.trace
35
- file_map["#{@path}#{File.basename(path)}"] = path
36
39
  end
37
40
  end
38
41
  end
@@ -49,7 +52,7 @@ module Buildr
49
52
  files = args.flatten
50
53
 
51
54
  if options.nil? || options.empty?
52
- @files.include *files.map { |file| file.to_s }
55
+ @includes.include *files.flatten
53
56
  elsif options[:path]
54
57
  sans_path = options.reject { |k,v| k == :path }
55
58
  path(options[:path]).include *files + [sans_path]
@@ -74,7 +77,9 @@ module Buildr
74
77
  # :call-seq:
75
78
  # exclude(*files) => self
76
79
  def exclude(*files)
77
- @files.exclude *files
80
+ files = files.flatten.map(&:to_s)
81
+ @excludes |= files
82
+ @excludes |= files.reject { |f| f =~ /\*$/ }.map { |f| "#{f}/*" }
78
83
  self
79
84
  end
80
85
 
@@ -127,28 +132,33 @@ module Buildr
127
132
  @sources << proc { source }
128
133
  @actions << proc do |file_map|
129
134
  file = source.to_s
130
- if File.directory?(file)
131
- in_directory(file) do |file, rel_path|
132
- path = rel_path.split("/")[1..-1]
133
- path.unshift as unless as == "."
134
- dest = "#{@path}#{path.join('/')}"
135
- puts "Adding #{dest}" if Rake.application.options.trace
136
- file_map[dest] = file
135
+ unless excluded?(file)
136
+ if File.directory?(file)
137
+ in_directory file do |file, rel_path|
138
+ path = rel_path.split("/")[1..-1]
139
+ path.unshift as unless as == "."
140
+ dest = "#{@path}#{path.join('/')}"
141
+ puts "Adding #{dest}" if Rake.application.options.trace
142
+ file_map[dest] = file
143
+ end
144
+ else
145
+ puts "Adding #{@path}#{as}" if Rake.application.options.trace
146
+ file_map["#{@path}#{as}"] = file
137
147
  end
138
- else
139
- puts "Adding #{@path}#{as}" if Rake.application.options.trace
140
- file_map["#{@path}#{as}"] = file
141
148
  end
142
149
  end
143
150
  end
144
151
 
145
- def in_directory(dir, excludes = nil)
152
+ def in_directory(dir)
146
153
  prefix = Regexp.new("^" + Regexp.escape(File.dirname(dir) + File::SEPARATOR))
147
- FileList["#{dir}/**/*"].
148
- reject { |file| File.directory?(file) || (excludes && excludes.exclude?(file)) }.
154
+ FileList.recursive(dir).reject { |file| excluded?(file) }.
149
155
  each { |file| yield file, file.sub(prefix, "") }
150
156
  end
151
157
 
158
+ def excluded?(file)
159
+ @excludes.any? { |exclude| File.fnmatch(exclude, file) }
160
+ end
161
+
152
162
  end
153
163
 
154
164
 
@@ -355,7 +365,7 @@ module Buildr
355
365
  # coming from, since some tasks touch the directory, e.g. when the
356
366
  # content of target/classes is included into a WAR.
357
367
  most_recent = @paths.collect { |name, path| path.sources }.flatten.
358
- each { |src| File.directory?(src) ? FileList["#{src}/**/*"] | [src] : src }.flatten.
368
+ each { |src| File.directory?(src) ? FileList.recursive(src) | [src] : src }.flatten.
359
369
  select { |file| File.exist?(file) }.collect { |file| File.stat(file).mtime }.max
360
370
  File.stat(name).mtime < (most_recent || Rake::EARLY) || super
361
371
  end
@@ -376,8 +386,6 @@ module Buildr
376
386
 
377
387
  end
378
388
 
379
-
380
-
381
389
  # The ZipTask creates a new Zip file. You can include any number of files and and directories,
382
390
  # use exclusion patterns, and include files into specific directories.
383
391
  #
@@ -395,16 +403,21 @@ module Buildr
395
403
  def create_from(file_map)
396
404
  Zip::ZipFile.open(name, Zip::ZipFile::CREATE) do |zip|
397
405
  zip.restore_permissions = true
406
+ mkpath = lambda do |dir|
407
+ unless dir == "." || zip.find_entry(dir)
408
+ mkpath.call File.dirname(dir)
409
+ zip.mkdir dir
410
+ end
411
+ end
412
+
398
413
  file_map.each do |path, content|
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
414
+ mkpath.call File.dirname(path)
415
+ if content.respond_to?(:call)
416
+ zip.get_output_stream(path) { |output| content.call(output) }
417
+ elsif content.nil? || File.directory?(content.to_s)
418
+ mkpath.call path
406
419
  else
407
- zip.mkdir path unless zip.find_entry(path)
420
+ zip.add path, content.to_s
408
421
  end
409
422
  end
410
423
  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.5
7
- date: 2007-08-13 00:00:00 -07:00
6
+ version: 1.2.6
7
+ date: 2007-09-26 00:00:00 -07:00
8
8
  summary: A build system that doesn't suck
9
9
  require_paths:
10
10
  - lib
@@ -47,6 +47,7 @@ files:
47
47
  - lib/buildr
48
48
  - lib/buildr/jetty.rb
49
49
  - lib/buildr/hibernate.rb
50
+ - lib/buildr/scala.rb
50
51
  - lib/buildr/xmlbeans.rb
51
52
  - lib/buildr/javacc.rb
52
53
  - lib/buildr/cobertura.rb
@@ -153,7 +154,7 @@ dependencies:
153
154
  requirements:
154
155
  - - "="
155
156
  - !ruby/object:Gem::Version
156
- version: 1.2.9
157
+ version: 1.4.0
157
158
  version:
158
159
  - !ruby/object:Gem::Dependency
159
160
  name: rjb
@@ -180,7 +181,7 @@ dependencies:
180
181
  requirements:
181
182
  - - "="
182
183
  - !ruby/object:Gem::Version
183
- version: 1.0.5
184
+ version: 1.0.8
184
185
  version:
185
186
  - !ruby/object:Gem::Dependency
186
187
  name: xml-simple