buildr 0.15.0 → 0.16.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +12 -0
- data/lib/buildr.rb +13 -8
- data/lib/core/artifact.rb +88 -75
- data/lib/core/build.rb +87 -41
- data/lib/core/core.rb +0 -9
- data/lib/core/project.rb +268 -127
- data/lib/core/transports.rb +2 -0
- data/lib/java/compile.rb +9 -4
- data/lib/java/java.rb +8 -11
- data/lib/java/openjpa.rb +2 -1
- data/lib/java/packaging.rb +10 -27
- data/lib/java/test.rb +105 -0
- data/lib/tasks/zip.rb +171 -36
- metadata +3 -2
data/lib/core/transports.rb
CHANGED
data/lib/java/compile.rb
CHANGED
@@ -100,7 +100,7 @@ module Buildr
|
|
100
100
|
puts "All source files are up to date" if Rake.application.options.trace && !sources.empty?
|
101
101
|
elsif target
|
102
102
|
mkpath target, :verbose=>false
|
103
|
-
Java.javac files, :sourcepath=>sourcepath, :classpath=>
|
103
|
+
Java.javac files, :sourcepath=>sourcepath, :classpath=>real_classpath,
|
104
104
|
:output=>target, :javac_args=>options.javac_args, :name=>task.name
|
105
105
|
# By touching the target we let other tasks know we did something,
|
106
106
|
# and also prevent recompiling again for classpath dependencies.
|
@@ -176,6 +176,10 @@ module Buildr
|
|
176
176
|
@files && !@files.empty?
|
177
177
|
end
|
178
178
|
|
179
|
+
def timestamp()
|
180
|
+
File.exist?(target) ? File.stat(target).mtime : Rake::EARLY
|
181
|
+
end
|
182
|
+
|
179
183
|
protected
|
180
184
|
|
181
185
|
# Returns the real classpath. Uses the values of #classpath, but resolves
|
@@ -295,20 +299,21 @@ module Buildr
|
|
295
299
|
end
|
296
300
|
|
297
301
|
|
298
|
-
Project.
|
302
|
+
Project.on_define do |project|
|
299
303
|
# Prepare is prerequisite for compile, resources follows compile.
|
300
304
|
project.compile.enhance([project.prepare]) { |task| project.resources.invoke }
|
301
305
|
project.recursive_task("compile")
|
302
306
|
task("build").enhance [ project.compile ]
|
303
307
|
task("clean") { rm_rf project.path_to(:target_dir), :verbose=>false }
|
304
308
|
|
305
|
-
project.
|
309
|
+
project.after_block do |project|
|
306
310
|
# Automagic compilation only if the source directory exists.
|
307
311
|
project.compile.sources << project.path_to(:java_src_dir) if File.exist?(project.path_to(:java_src_dir))
|
308
312
|
project.compile.target ||= project.path_to(:java_target_dir)
|
309
313
|
project.resources.include project.path_to(:resources_dir, "*") if File.exist?(project.path_to(:resources_dir))
|
310
314
|
project.resources.target ||= project.compile.target
|
311
|
-
file(project.compile.target).enhance
|
315
|
+
file(project.compile.target).enhance [ project.compile ]
|
316
|
+
file(project.resources.target).enhance [ project.resources ]
|
312
317
|
end
|
313
318
|
|
314
319
|
end
|
data/lib/java/java.rb
CHANGED
@@ -11,12 +11,12 @@ module Buildr
|
|
11
11
|
name = options[:name] || "java #{args.first}"
|
12
12
|
cmd_args = []
|
13
13
|
classpath = classpath_from(options)
|
14
|
-
cmd_args << "-cp" << classpath unless classpath.empty?
|
14
|
+
cmd_args << "-cp" << classpath.join(File::PATH_SEPARATOR) unless classpath.empty?
|
15
15
|
cmd_args += options[:java_args].flatten if options[:java_args]
|
16
16
|
cmd_args += args.flatten.compact
|
17
17
|
cmd_args << { :verbose=>options[:verbose] }
|
18
18
|
unless options[:noop]
|
19
|
-
|
19
|
+
puts "Running #{name}" if verbose
|
20
20
|
sh(path_to_bin("java"), *cmd_args) { |ok, res| fail "Failed to execute #{name}, see errors above" unless ok }
|
21
21
|
end
|
22
22
|
end
|
@@ -24,7 +24,7 @@ module Buildr
|
|
24
24
|
def self.apt(*args)
|
25
25
|
options = Hash === args.last ? args.pop : {}
|
26
26
|
options[:verbose] ||= Rake.application.options.trace || false
|
27
|
-
fu_check_options options, :verbose, :noop, :compile, :source, :output, :cp, :classpath
|
27
|
+
fu_check_options options, :verbose, :noop, :compile, :source, :output, :cp, :classpath
|
28
28
|
|
29
29
|
files = args.collect { |arg| File.directory?(arg) ? FileList[File.join(arg, "**", "*.java")] : arg }.flatten
|
30
30
|
args = [ options[:verbose] ? "-verbose" : "-nowarn" ]
|
@@ -35,13 +35,11 @@ module Buildr
|
|
35
35
|
end
|
36
36
|
args << "-source" << options[:source] if options[:source]
|
37
37
|
classpath = classpath_from(options)
|
38
|
-
args << "-cp" << classpath unless classpath.empty?
|
39
|
-
sourcepath = (options[:sourcepath] || []).collect.join(File::PATH_SEPARATOR)
|
40
|
-
args << "-sourcepath" << sourcepath unless sourcepath.empty?
|
38
|
+
args << "-cp" << classpath.join(File::PATH_SEPARATOR) unless classpath.empty?
|
41
39
|
args += files
|
42
40
|
args << { :verbose=>options[:verbose] }
|
43
41
|
unless options[:noop]
|
44
|
-
|
42
|
+
puts "Running apt" if verbose
|
45
43
|
sh(path_to_bin("apt"), *args) { |ok, res| fail "Failed to execute apt, see errors above" unless ok }
|
46
44
|
end
|
47
45
|
end
|
@@ -84,14 +82,14 @@ module Buildr
|
|
84
82
|
cmd_args = []
|
85
83
|
classpath = classpath_from(options)
|
86
84
|
#classpath += options[:output] if options[:output]
|
87
|
-
cmd_args << "-cp" << classpath unless classpath.empty?
|
85
|
+
cmd_args << "-cp" << classpath.join(File::PATH_SEPARATOR) unless classpath.empty?
|
88
86
|
cmd_args << "-sourcepath" << options[:sourcepath].join(File::PATH_SEPARATOR) if options[:sourcepath]
|
89
87
|
cmd_args << "-d" << options[:output] if options[:output]
|
90
88
|
cmd_args += options[:javac_args].flatten if options[:javac_args]
|
91
89
|
cmd_args += files
|
92
90
|
cmd_args << { :verbose=>options[:verbose] }
|
93
91
|
unless options[:noop] || files.empty?
|
94
|
-
|
92
|
+
puts "Compiling #{files.size} source files in #{name}" if verbose
|
95
93
|
sh(path_to_bin("javac"), *cmd_args) { |ok, res| fail "Failed to compile, see errors above" unless ok }
|
96
94
|
end
|
97
95
|
end
|
@@ -104,8 +102,7 @@ module Buildr
|
|
104
102
|
|
105
103
|
def self.classpath_from(options)
|
106
104
|
classpath = (options[:classpath] || []).collect | (options[:cp] || []).collect
|
107
|
-
artifacts(classpath).each { |t| t.invoke if t.respond_to?(:invoke) }.
|
108
|
-
map(&:to_s).join(File::PATH_SEPARATOR)
|
105
|
+
artifacts(classpath).each { |t| t.invoke if t.respond_to?(:invoke) }.map(&:to_s)
|
109
106
|
end
|
110
107
|
|
111
108
|
end
|
data/lib/java/openjpa.rb
CHANGED
@@ -21,7 +21,8 @@ module Buildr
|
|
21
21
|
fu_check_options options, *OPTIONS + [:output]
|
22
22
|
|
23
23
|
runtool options.merge(:class=>"org.apache.openjpa.enhance.PCEnhancer", :name=>"Enhancer",
|
24
|
-
:args=>{ "-p"=>options[:properties], "-d"=>options[:output] }
|
24
|
+
:args=>{ "-p"=>options[:properties], "-d"=>options[:output] },
|
25
|
+
:classpath=>options[:classpath] + [options[:output]])
|
25
26
|
end
|
26
27
|
|
27
28
|
def self.mapping_tool(options)
|
data/lib/java/packaging.rb
CHANGED
@@ -80,17 +80,6 @@ module Buildr
|
|
80
80
|
end
|
81
81
|
|
82
82
|
|
83
|
-
# Global task packages all projects.
|
84
|
-
desc "Package all projects"
|
85
|
-
LocalDirectoryTask.define_task "package"
|
86
|
-
desc "Install packages created by this project"
|
87
|
-
LocalDirectoryTask.define_task "install"
|
88
|
-
desc "Uninstall packages created by this project"
|
89
|
-
LocalDirectoryTask.define_task "uninstall"
|
90
|
-
desc "Deploy packages created by this project"
|
91
|
-
LocalDirectoryTask.define_task "deploy"
|
92
|
-
|
93
|
-
|
94
83
|
class Project
|
95
84
|
|
96
85
|
# Group used for packaging. Inherited from parent project.
|
@@ -98,6 +87,12 @@ module Buildr
|
|
98
87
|
# Version used for packaging. Inherited from parent project.
|
99
88
|
inherited_attr :version
|
100
89
|
|
90
|
+
# The project ID is the project name, and for a sub-project the
|
91
|
+
# parent project ID followed by the project name, separated with a
|
92
|
+
# hyphen. For example, "foo" and "foo-bar".
|
93
|
+
def id()
|
94
|
+
name.gsub(":", "-")
|
95
|
+
end
|
101
96
|
inherited_attr :webapp_src_dir do File.join(src_dir, "main", "webapp") end
|
102
97
|
|
103
98
|
def package(*args)
|
@@ -106,7 +101,7 @@ module Buildr
|
|
106
101
|
else
|
107
102
|
options = {}
|
108
103
|
end
|
109
|
-
options[:type] = args.shift if Symbol === args.first
|
104
|
+
options[:type] = args.shift.to_s if Symbol === args.first
|
110
105
|
fail "No packaging type specified" unless options[:type]
|
111
106
|
options[:group] ||= self.group
|
112
107
|
options[:version] ||= self.version
|
@@ -133,15 +128,15 @@ module Buildr
|
|
133
128
|
|
134
129
|
task "uninstall" do |task|
|
135
130
|
verbose(Rake.application.options.trace) do
|
136
|
-
|
137
|
-
|
131
|
+
[ package, package.pom ].map { |artifact| repositories.locate(artifact) }.
|
132
|
+
each { |file| rm file if File.exist?(file) }
|
138
133
|
end
|
139
134
|
end
|
140
135
|
|
141
136
|
task("deploy") { deploy(package, package.pom) }
|
142
137
|
|
143
138
|
packages << package
|
144
|
-
Artifact.register package
|
139
|
+
Artifact.register package, package.pom
|
145
140
|
package
|
146
141
|
end
|
147
142
|
|
@@ -202,16 +197,4 @@ module Buildr
|
|
202
197
|
end
|
203
198
|
|
204
199
|
|
205
|
-
Project.on_create do |project|
|
206
|
-
# Recursive tasks must be defined in before_create.
|
207
|
-
desc "Create packages in this project"
|
208
|
-
project.recursive_task "package"=>"build"
|
209
|
-
desc "Install packages created by this project"
|
210
|
-
project.recursive_task "install"=>"package"
|
211
|
-
desc "Uninstall packages created by this project"
|
212
|
-
project.recursive_task "uninstall"
|
213
|
-
desc "Deploy packages created by this project"
|
214
|
-
project.recursive_task "deploy"=>"package"
|
215
|
-
end
|
216
|
-
|
217
200
|
end
|
data/lib/java/test.rb
ADDED
@@ -0,0 +1,105 @@
|
|
1
|
+
module Buildr
|
2
|
+
|
3
|
+
class JUnitTask < Rake::Task
|
4
|
+
|
5
|
+
attr_accessor :base_dir
|
6
|
+
attr_accessor :target
|
7
|
+
attr_accessor :classpath
|
8
|
+
|
9
|
+
def initialize(*args)
|
10
|
+
super
|
11
|
+
@classpath = []
|
12
|
+
enhance do |task|
|
13
|
+
test_cases.each do |test|
|
14
|
+
Dir.chdir base_dir
|
15
|
+
java "junit.textui.TestRunner", test, :classpath=>real_classpath, :name=>"tests in #{test}"
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_cases()
|
21
|
+
target = File.expand_path(self.target)
|
22
|
+
return [] unless File.exist?(target)
|
23
|
+
prefix = Regexp.new("^" + Regexp.escape(target) + "/")
|
24
|
+
FileList[File.join(target, "**", "*Test.class")].
|
25
|
+
map { |path| path.sub(prefix, "").ext("").gsub(File::SEPARATOR, ".") }.sort
|
26
|
+
end
|
27
|
+
|
28
|
+
def real_classpath()
|
29
|
+
@real_classpath ||= artifacts(@classpath).map(&:to_s)
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
|
34
|
+
class Tests
|
35
|
+
def prepare(*tasks, &block)
|
36
|
+
returning(@prepare_task ||= task("prepare")) { |task| task.enhance tasks, &block }
|
37
|
+
end
|
38
|
+
|
39
|
+
def compile(*sources, &block)
|
40
|
+
unless @compile_task
|
41
|
+
@compile_task = Java::CompileTask.define_task("compile"=>prepare) { |task| resources.invoke }
|
42
|
+
end
|
43
|
+
returning(@compile_task) { |task| task.sources |= sources ; task.enhance &block }
|
44
|
+
end
|
45
|
+
|
46
|
+
def resources(*tasks, &block)
|
47
|
+
returning(@resources_task ||= Filter.define_task("resources")) { |task| task.enhance tasks, &block }
|
48
|
+
end
|
49
|
+
|
50
|
+
def junit(*tasks, &block)
|
51
|
+
unless @junit_task
|
52
|
+
@junit_task = JUnitTask.define_task("junit"=>compile)
|
53
|
+
end
|
54
|
+
returning(@junit_task) { |task| task.enhance tasks, &block }
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
class Project
|
59
|
+
inherited_attr :test_src_dir do File.join(src_dir, "test", "java") end
|
60
|
+
inherited_attr :test_resources_dir do File.join(src_dir, "test", "resources") end
|
61
|
+
inherited_attr :test_target_dir do File.join(target_dir, "test-classes") end
|
62
|
+
|
63
|
+
def tests()
|
64
|
+
@tests ||= Tests.new
|
65
|
+
end
|
66
|
+
|
67
|
+
def test(*tasks, &block)
|
68
|
+
@tests.junit *tasks, &block
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
# Global task compiles all projects.
|
73
|
+
desc "Run all test cases"
|
74
|
+
LocalDirectoryTask.define_task "test"
|
75
|
+
|
76
|
+
Project.on_define do |project|
|
77
|
+
tests = nil
|
78
|
+
namespace "test" do
|
79
|
+
tests = project.tests
|
80
|
+
#tests.compile.enhance([tests.prepare]) { |task| tests.resources.invoke }
|
81
|
+
tests.compile.classpath += [ "junit:junit:jar:3.8.1", "jmock:jmock:jar:1.1.0" ]
|
82
|
+
tests.junit
|
83
|
+
end
|
84
|
+
tests.compile.enhance [ project.compile ]
|
85
|
+
project.recursive_task("test"=>project.test)
|
86
|
+
|
87
|
+
#project.recursive_task("compile")
|
88
|
+
#task("build").enhance [ project.compile ]
|
89
|
+
#task("clean") { rm_rf project.path_to(:target_dir), :verbose=>false }
|
90
|
+
|
91
|
+
project.after_block do |project|
|
92
|
+
tests.compile.sources << project.path_to(:test_src_dir) if File.exist?(project.path_to(:test_src_dir))
|
93
|
+
tests.compile.target ||= project.path_to(:test_target_dir)
|
94
|
+
tests.compile.classpath << project.compile.target
|
95
|
+
tests.resources.include project.path_to(:test_resources_dir, "*") if File.exists?(project.path_to(:test_resources_dir))
|
96
|
+
tests.resources.target ||= tests.compile.target
|
97
|
+
tests.junit.target = tests.compile.target
|
98
|
+
tests.junit.classpath += tests.compile.classpath
|
99
|
+
tests.junit.classpath += [ tests.compile.target, project.compile.target ]
|
100
|
+
tests.junit.base_dir = project.base_dir
|
101
|
+
file(tests.compile.target).enhance [ tests.compile ]
|
102
|
+
file(tests.resources.target).enhance [ tests.resources ]
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
data/lib/tasks/zip.rb
CHANGED
@@ -9,11 +9,136 @@ module Buildr
|
|
9
9
|
# directories.
|
10
10
|
class ZipTask < Rake::FileTask
|
11
11
|
|
12
|
+
# :nodoc:
|
13
|
+
module IncludeFiles
|
14
|
+
|
15
|
+
# Include the specified files or directories.
|
16
|
+
def include(*files)
|
17
|
+
if Hash === files.last
|
18
|
+
options = files.pop
|
19
|
+
else
|
20
|
+
options = {}
|
21
|
+
end
|
22
|
+
|
23
|
+
if options[:path]
|
24
|
+
path(options[:path]).include *files +[ options.reject { |k,v| k == :path } ]
|
25
|
+
elsif options[:as]
|
26
|
+
raise "You can only use the :as option in combination with the :path option" unless options.keys.size == 1
|
27
|
+
raise "You can only use one file with the :as option" unless files.size == 1
|
28
|
+
include_as(files.first, options[:as])
|
29
|
+
elsif options[:merge]
|
30
|
+
raise "You can only use the :merge option in combination with the :path option" unless options.keys.size == 1
|
31
|
+
files.each { |file| merge file }
|
32
|
+
elsif options.keys.empty?
|
33
|
+
(@files ||= FileList[]).include *files
|
34
|
+
else
|
35
|
+
raise "Unrecognized option #{options.keys.join(", ")}"
|
36
|
+
end
|
37
|
+
self
|
38
|
+
end
|
39
|
+
|
40
|
+
# Exclude the specified file or directories.
|
41
|
+
def exclude(*files)
|
42
|
+
(@files ||= FileList[]).exclude *files
|
43
|
+
self
|
44
|
+
end
|
45
|
+
alias :add :include
|
46
|
+
|
47
|
+
def merge(*files)
|
48
|
+
if Hash === files.last
|
49
|
+
options = files.pop
|
50
|
+
else
|
51
|
+
options = {}
|
52
|
+
end
|
53
|
+
|
54
|
+
if options[:path]
|
55
|
+
path(options[:path]).merge *files +[ options.reject { |k,v| k == :path } ]
|
56
|
+
elsif options.keys.empty?
|
57
|
+
files.collect do |file|
|
58
|
+
@expand_sources << proc { artifacts(file).map(&:to_s) }
|
59
|
+
expander = ZipExpander.new(file)
|
60
|
+
@add_files << proc { |zip| expander.expand(zip, @path) }
|
61
|
+
expander
|
62
|
+
end.first
|
63
|
+
else
|
64
|
+
raise "Unrecognized option #{options.keys.join(", ")}"
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
protected
|
69
|
+
|
70
|
+
def setup_path(path = nil)
|
71
|
+
@path = "#{path}/" if path
|
72
|
+
expand_src = proc { artifacts(*@files || []).map(&:to_s) }
|
73
|
+
@expand_sources = [ expand_src ]
|
74
|
+
@add_files = [] << proc do |zip|
|
75
|
+
expand_src.call.each do |file|
|
76
|
+
if File.directory?(file)
|
77
|
+
in_directory(file, @files) do |file, rel_path|
|
78
|
+
puts "Adding #{@path}#{rel_path}" if Rake.application.options.trace
|
79
|
+
zip.add "#{@path}#{rel_path}", file
|
80
|
+
end
|
81
|
+
else
|
82
|
+
puts "Adding #{@path}#{File.basename(file)}" if Rake.application.options.trace
|
83
|
+
zip.add "#{@path}#{File.basename(file)}", file
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
def include_as(source, as)
|
90
|
+
@expand_sources << proc { artifacts(source).map(&:to_s) }
|
91
|
+
@add_files << proc do |zip|
|
92
|
+
file = artifacts(source).first.to_s
|
93
|
+
if File.directory?(file)
|
94
|
+
in_directory(file) do |file, rel_path|
|
95
|
+
puts "Adding #{@path}#{as}/#{rel_path}" if Rake.application.options.trace
|
96
|
+
zip.add file, "#{@path}#{as}/#{rel_path}"
|
97
|
+
end
|
98
|
+
else
|
99
|
+
puts "Adding #{@path}#{as}" if Rake.application.options.trace
|
100
|
+
zip.add "#{@path}#{as}", file
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
def in_directory(dir, excludes = nil)
|
106
|
+
prefix = Regexp.new("^" + Regexp.escape(File.dirname(dir) + File::SEPARATOR))
|
107
|
+
Dir[File.join(dir, "**", "*")].
|
108
|
+
reject { |file| File.directory?(file) || (excludes && excludes.exclude?(file)) }.
|
109
|
+
each { |file| yield file, file.sub(prefix, "") }
|
110
|
+
end
|
111
|
+
|
112
|
+
def expand_sources()
|
113
|
+
@expand_sources.map(&:call).flatten
|
114
|
+
end
|
115
|
+
|
116
|
+
def add_file(zip)
|
117
|
+
@add_files.each { |action| action.call zip }
|
118
|
+
end
|
119
|
+
|
120
|
+
end
|
121
|
+
|
122
|
+
|
123
|
+
# Which files go where.
|
124
|
+
class Path
|
125
|
+
|
126
|
+
include IncludeFiles
|
127
|
+
|
128
|
+
def initialize(path)
|
129
|
+
setup_path path
|
130
|
+
end
|
131
|
+
|
132
|
+
end
|
133
|
+
|
134
|
+
include IncludeFiles
|
135
|
+
|
12
136
|
def initialize(*args)
|
13
137
|
super
|
14
|
-
@paths = {}
|
138
|
+
@paths = { nil=>self }
|
139
|
+
setup_path
|
15
140
|
enhance do |task|
|
16
|
-
|
141
|
+
puts "Creating #{task.name}" if verbose
|
17
142
|
# We're here because the Zip file does not exist, or one of the files is
|
18
143
|
# newer than the Zip contents; in the later case, opening the Zip file
|
19
144
|
# will add to its contents instead of replacing it, so we want the Zip
|
@@ -29,38 +154,50 @@ module Buildr
|
|
29
154
|
end
|
30
155
|
end
|
31
156
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
# task.include foobar, :path=>"libs" # Include under /libs/
|
38
|
-
def include(*files)
|
39
|
-
if Hash === files.last
|
40
|
-
path = files.pop[:path]
|
157
|
+
|
158
|
+
class ZipExpander
|
159
|
+
|
160
|
+
def initialize(zip_file)
|
161
|
+
@zip_file = zip_file
|
41
162
|
end
|
42
|
-
(@paths[path] ||= FileList[]).include *files
|
43
|
-
self
|
44
|
-
end
|
45
|
-
alias :add :include
|
46
163
|
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
path = files.pop[:path]
|
164
|
+
def include(*files)
|
165
|
+
(@includes ||= [])
|
166
|
+
@includes |= files
|
167
|
+
self
|
52
168
|
end
|
53
|
-
|
54
|
-
|
169
|
+
|
170
|
+
def exclude(*files)
|
171
|
+
(@excludes ||= [])
|
172
|
+
@excludes |= files
|
173
|
+
self
|
174
|
+
end
|
175
|
+
|
176
|
+
def expand(zip, path)
|
177
|
+
@includes ||= ["*"]
|
178
|
+
@excludes ||= []
|
179
|
+
Zip::ZipFile.open(artifacts(@zip_file).map(&:to_s).first) do |source|
|
180
|
+
source.entries.reject { |entry| entry.directory? }.each do |entry|
|
181
|
+
if @includes.any? { |pattern| File.fnmatch(pattern, entry.name) } &&
|
182
|
+
!@excludes.any? { |pattern| File.fnmatch(pattern, entry.name) }
|
183
|
+
puts "Adding #{path}#{entry.name}" if Rake.application.options.trace
|
184
|
+
zip.get_output_stream("#{path}#{entry.name}") { |output| output.write source.read(entry) }
|
185
|
+
# TODO: read and write file
|
186
|
+
end
|
187
|
+
end
|
188
|
+
end
|
189
|
+
end
|
190
|
+
|
55
191
|
end
|
56
192
|
|
193
|
+
|
57
194
|
# Returns a path to which you can include/exclude files.
|
58
195
|
#
|
59
196
|
# zip(..).include("foo", :path=>"bar")
|
60
197
|
# is equivalen to:
|
61
198
|
# zip(..).path("bar").include("foo")
|
62
199
|
def path(path)
|
63
|
-
@paths[path] ||=
|
200
|
+
path.blank? ? @paths[nil] : (@paths[path] ||= Path.new(path))
|
64
201
|
end
|
65
202
|
|
66
203
|
# Pass options to the task. Returns self.
|
@@ -77,34 +214,31 @@ module Buildr
|
|
77
214
|
|
78
215
|
def invoke_prerequisites()
|
79
216
|
super
|
80
|
-
@paths.
|
217
|
+
@paths.collect { |name, path| path.expand_sources }.flatten.each { |src| file(src).invoke }
|
81
218
|
end
|
82
219
|
|
83
220
|
def needed?()
|
221
|
+
return true unless File.exist?(name)
|
84
222
|
# You can do something like:
|
85
223
|
# include("foo", :path=>"foo").exclude("foo/bar", path=>"foo").
|
86
224
|
# include("foo/bar", :path=>"foo/bar")
|
87
225
|
# This will play havoc if we handled all the prerequisites together
|
88
226
|
# under the task, so instead we handle them individually for each path.
|
89
|
-
|
90
|
-
return true unless File.exist?(name)
|
227
|
+
#
|
91
228
|
# We need to check that any file we include is not newer than the
|
92
229
|
# contents of the ZIP. The file itself but also the directory it's
|
93
230
|
# coming from, since some tasks touch the directory, e.g. when the
|
94
231
|
# content of target/classes is included into a WAR.
|
95
|
-
|
96
|
-
|
97
|
-
|
232
|
+
most_recent = @paths.collect { |name, path| path.expand_sources }.flatten.
|
233
|
+
each { |src| File.directory?(src) ? FileList[File.join(src, "**", "*")] | [src] : src }.flatten.
|
234
|
+
select { |file| File.exist?(file) }.collect { |file| File.stat(file).mtime }.max
|
98
235
|
File.stat(name).mtime < (most_recent || Rake::EARLY)
|
99
236
|
end
|
100
237
|
|
101
238
|
protected
|
102
239
|
|
103
240
|
def create(zip)
|
104
|
-
|
105
|
-
puts "Adding #{path}" if Rake.application.options.trace
|
106
|
-
zip.add path, zip_map[path]
|
107
|
-
end
|
241
|
+
@paths.each { |name, obj| obj.add_file zip }
|
108
242
|
end
|
109
243
|
|
110
244
|
def zip_map()
|
@@ -244,9 +378,10 @@ module Buildr
|
|
244
378
|
end
|
245
379
|
|
246
380
|
def needed?()
|
247
|
-
return true unless target && File.exist?(target)
|
248
|
-
return true if prerequisites.any? { |prereq| File.stat(prereq).mtime > File.stat(target).mtime }
|
249
|
-
false
|
381
|
+
#return true unless target && File.exist?(target)
|
382
|
+
#return true if prerequisites.any? { |prereq| File.stat(prereq).mtime > File.stat(target).mtime }
|
383
|
+
#false
|
384
|
+
true
|
250
385
|
end
|
251
386
|
|
252
387
|
# :nodoc:
|