buildr 1.2.10 → 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +566 -268
- data/DISCLAIMER +7 -1
- data/KEYS +151 -0
- data/NOTICE +23 -8
- data/README +122 -22
- data/Rakefile +49 -229
- data/{lib → addon}/buildr/antlr.rb +23 -10
- data/addon/buildr/cobertura.rb +232 -0
- data/{lib → addon}/buildr/hibernate.rb +20 -4
- data/{lib → addon}/buildr/javacc.rb +27 -12
- data/addon/buildr/jdepend.rb +60 -0
- data/{lib → addon}/buildr/jetty.rb +34 -18
- data/addon/buildr/nailgun.rb +892 -0
- data/{lib → addon}/buildr/openjpa.rb +23 -6
- data/addon/buildr/org/apache/buildr/JettyWrapper$1.class +0 -0
- data/addon/buildr/org/apache/buildr/JettyWrapper$BuildrHandler.class +0 -0
- data/addon/buildr/org/apache/buildr/JettyWrapper.class +0 -0
- data/{lib/buildr/jetty → addon/buildr/org/apache/buildr}/JettyWrapper.java +19 -0
- data/{lib → addon}/buildr/xmlbeans.rb +39 -14
- data/bin/buildr +21 -7
- data/buildr.gemspec +50 -0
- data/doc/css/default.css +225 -0
- data/doc/css/print.css +95 -0
- data/doc/css/syntax.css +43 -0
- data/doc/images/apache-incubator-logo.png +0 -0
- data/doc/images/buildr-hires.png +0 -0
- data/doc/images/buildr.png +0 -0
- data/doc/images/note.png +0 -0
- data/doc/images/tip.png +0 -0
- data/doc/images/zbuildr.tif +0 -0
- data/doc/pages/artifacts.textile +317 -0
- data/doc/pages/building.textile +501 -0
- data/doc/pages/contributing.textile +178 -0
- data/doc/pages/download.textile +25 -0
- data/doc/pages/extending.textile +229 -0
- data/doc/pages/getting_started.textile +337 -0
- data/doc/pages/index.textile +63 -0
- data/doc/pages/mailing_lists.textile +17 -0
- data/doc/pages/more_stuff.textile +367 -0
- data/doc/pages/packaging.textile +592 -0
- data/doc/pages/projects.textile +449 -0
- data/doc/pages/recipes.textile +127 -0
- data/doc/pages/settings_profiles.textile +339 -0
- data/doc/pages/testing.textile +475 -0
- data/doc/pages/troubleshooting.textile +121 -0
- data/doc/pages/whats_new.textile +389 -0
- data/doc/print.haml +52 -0
- data/doc/print.toc.yaml +28 -0
- data/doc/scripts/buildr-git.rb +411 -0
- data/doc/scripts/install-jruby.sh +44 -0
- data/doc/scripts/install-linux.sh +64 -0
- data/doc/scripts/install-osx.sh +52 -0
- data/doc/site.haml +55 -0
- data/doc/site.toc.yaml +44 -0
- data/lib/buildr.rb +28 -45
- data/lib/buildr/core.rb +27 -0
- data/lib/buildr/core/application.rb +373 -0
- data/lib/buildr/core/application_cli.rb +134 -0
- data/lib/{core → buildr/core}/build.rb +91 -77
- data/lib/{core → buildr/core}/checks.rb +116 -95
- data/lib/buildr/core/common.rb +155 -0
- data/lib/buildr/core/compile.rb +594 -0
- data/lib/buildr/core/environment.rb +120 -0
- data/lib/buildr/core/filter.rb +258 -0
- data/lib/{core → buildr/core}/generate.rb +22 -5
- data/lib/buildr/core/help.rb +118 -0
- data/lib/buildr/core/progressbar.rb +156 -0
- data/lib/{core → buildr/core}/project.rb +468 -213
- data/lib/buildr/core/test.rb +690 -0
- data/lib/{core → buildr/core}/transports.rb +107 -127
- data/lib/buildr/core/util.rb +235 -0
- data/lib/buildr/ide.rb +19 -0
- data/lib/{java → buildr/ide}/eclipse.rb +86 -60
- data/lib/{java → buildr/ide}/idea.ipr.template +16 -0
- data/lib/buildr/ide/idea.rb +194 -0
- data/lib/buildr/ide/idea7x.ipr.template +290 -0
- data/lib/buildr/ide/idea7x.rb +210 -0
- data/lib/buildr/java.rb +26 -0
- data/lib/buildr/java/ant.rb +71 -0
- data/lib/buildr/java/bdd_frameworks.rb +267 -0
- data/lib/buildr/java/commands.rb +210 -0
- data/lib/buildr/java/compilers.rb +432 -0
- data/lib/buildr/java/deprecated.rb +141 -0
- data/lib/buildr/java/groovyc.rb +137 -0
- data/lib/buildr/java/jruby.rb +99 -0
- data/lib/buildr/java/org/apache/buildr/BuildrNail$Main.class +0 -0
- data/lib/buildr/java/org/apache/buildr/BuildrNail.class +0 -0
- data/lib/buildr/java/org/apache/buildr/BuildrNail.java +41 -0
- data/lib/buildr/java/org/apache/buildr/JavaTestFilter.class +0 -0
- data/lib/buildr/java/org/apache/buildr/JavaTestFilter.java +116 -0
- data/lib/buildr/java/packaging.rb +706 -0
- data/lib/{java → buildr/java}/pom.rb +20 -4
- data/lib/buildr/java/rjb.rb +142 -0
- data/lib/buildr/java/test_frameworks.rb +290 -0
- data/lib/buildr/java/version_requirement.rb +172 -0
- data/lib/buildr/packaging.rb +21 -0
- data/lib/{java → buildr/packaging}/artifact.rb +170 -179
- data/lib/buildr/packaging/artifact_namespace.rb +957 -0
- data/lib/buildr/packaging/artifact_search.rb +140 -0
- data/lib/buildr/packaging/gems.rb +102 -0
- data/lib/buildr/packaging/package.rb +233 -0
- data/lib/{tasks → buildr/packaging}/tar.rb +18 -1
- data/lib/{tasks → buildr/packaging}/zip.rb +153 -105
- data/rakelib/apache.rake +126 -0
- data/rakelib/changelog.rake +56 -0
- data/rakelib/doc.rake +103 -0
- data/rakelib/package.rake +44 -0
- data/rakelib/release.rake +53 -0
- data/rakelib/rspec.rake +81 -0
- data/rakelib/rubyforge.rake +45 -0
- data/rakelib/scm.rake +49 -0
- data/rakelib/setup.rake +59 -0
- data/rakelib/stage.rake +45 -0
- data/spec/application_spec.rb +316 -0
- data/spec/archive_spec.rb +494 -0
- data/spec/artifact_namespace_spec.rb +635 -0
- data/spec/artifact_spec.rb +738 -0
- data/spec/build_spec.rb +193 -0
- data/spec/checks_spec.rb +537 -0
- data/spec/common_spec.rb +579 -0
- data/spec/compile_spec.rb +561 -0
- data/spec/groovy_compilers_spec.rb +239 -0
- data/spec/java_bdd_frameworks_spec.rb +238 -0
- data/spec/java_compilers_spec.rb +446 -0
- data/spec/java_packaging_spec.rb +1042 -0
- data/spec/java_test_frameworks_spec.rb +414 -0
- data/spec/packaging_helper.rb +63 -0
- data/spec/packaging_spec.rb +589 -0
- data/spec/project_spec.rb +739 -0
- data/spec/sandbox.rb +116 -0
- data/spec/scala_compilers_spec.rb +239 -0
- data/spec/spec.opts +6 -0
- data/spec/spec_helpers.rb +283 -0
- data/spec/test_spec.rb +871 -0
- data/spec/transport_spec.rb +300 -0
- data/spec/version_requirement_spec.rb +115 -0
- metadata +188 -77
- data/lib/buildr/cobertura.rb +0 -89
- data/lib/buildr/jdepend.rb +0 -40
- data/lib/buildr/jetty/JettyWrapper$1.class +0 -0
- data/lib/buildr/jetty/JettyWrapper$BuildrHandler.class +0 -0
- data/lib/buildr/jetty/JettyWrapper.class +0 -0
- data/lib/buildr/scala.rb +0 -368
- data/lib/core/application.rb +0 -188
- data/lib/core/common.rb +0 -562
- data/lib/core/help.rb +0 -72
- data/lib/core/rake_ext.rb +0 -81
- data/lib/java/ant.rb +0 -71
- data/lib/java/compile.rb +0 -589
- data/lib/java/idea.rb +0 -159
- data/lib/java/java.rb +0 -432
- data/lib/java/packaging.rb +0 -581
- data/lib/java/test.rb +0 -795
- data/lib/tasks/concat.rb +0 -35
@@ -1,6 +1,23 @@
|
|
1
|
-
|
1
|
+
# Licensed to the Apache Software Foundation (ASF) under one or more
|
2
|
+
# contributor license agreements. See the NOTICE file distributed with this
|
3
|
+
# work for additional information regarding copyright ownership. The ASF
|
4
|
+
# licenses this file to you under the Apache License, Version 2.0 (the
|
5
|
+
# "License"); you may not use this file except in compliance with the License.
|
6
|
+
# You may obtain a copy of the License at
|
7
|
+
#
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
#
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
12
|
+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
13
|
+
# License for the specific language governing permissions and limitations under
|
14
|
+
# the License.
|
15
|
+
|
16
|
+
|
17
|
+
require 'buildr/packaging/zip'
|
2
18
|
require 'archive/tar/minitar'
|
3
19
|
|
20
|
+
|
4
21
|
module Buildr
|
5
22
|
|
6
23
|
# The TarTask creates a new Tar file. You can include any number of files and and directories,
|
@@ -1,5 +1,21 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
# Licensed to the Apache Software Foundation (ASF) under one or more
|
2
|
+
# contributor license agreements. See the NOTICE file distributed with this
|
3
|
+
# work for additional information regarding copyright ownership. The ASF
|
4
|
+
# licenses this file to you under the Apache License, Version 2.0 (the
|
5
|
+
# "License"); you may not use this file except in compliance with the License.
|
6
|
+
# You may obtain a copy of the License at
|
7
|
+
#
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
#
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
12
|
+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
13
|
+
# License for the specific language governing permissions and limitations under
|
14
|
+
# the License.
|
15
|
+
|
16
|
+
|
17
|
+
require 'zip/zip'
|
18
|
+
require 'zip/zipfilesystem'
|
3
19
|
|
4
20
|
|
5
21
|
module Buildr
|
@@ -16,7 +32,7 @@ module Buildr
|
|
16
32
|
|
17
33
|
def initialize(root, path)
|
18
34
|
@root = root
|
19
|
-
@path = path.
|
35
|
+
@path = path.empty? ? path : "#{path}/"
|
20
36
|
@includes = FileList[]
|
21
37
|
@excludes = []
|
22
38
|
# Expand source files added to this path.
|
@@ -29,11 +45,11 @@ module Buildr
|
|
29
45
|
if File.directory?(path)
|
30
46
|
in_directory path do |file, rel_path|
|
31
47
|
dest = "#{@path}#{rel_path}"
|
32
|
-
puts "Adding #{dest}" if
|
48
|
+
puts "Adding #{dest}" if Buildr.application.options.trace
|
33
49
|
file_map[dest] = file
|
34
50
|
end
|
35
51
|
else
|
36
|
-
puts "Adding #{@path}#{File.basename(path)}" if
|
52
|
+
puts "Adding #{@path}#{File.basename(path)}" if Buildr.application.options.trace
|
37
53
|
file_map["#{@path}#{File.basename(path)}"] = path
|
38
54
|
end
|
39
55
|
end
|
@@ -57,22 +73,23 @@ module Buildr
|
|
57
73
|
sans_path = options.reject { |k,v| k == :path }
|
58
74
|
path(options[:path]).include *files + [sans_path]
|
59
75
|
elsif options[:as]
|
60
|
-
raise
|
61
|
-
raise
|
76
|
+
raise 'You can only use the :as option in combination with the :path option' unless options.size == 1
|
77
|
+
raise 'You can only use one file with the :as option' unless files.size == 1
|
62
78
|
include_as files.first.to_s, options[:as]
|
63
79
|
elsif options[:from]
|
64
|
-
raise
|
65
|
-
raise
|
66
|
-
[options[:from]].flatten.each { |path| include_as path.to_s,
|
80
|
+
raise 'You can only use the :from option in combination with the :path option' unless options.size == 1
|
81
|
+
raise 'You canont use the :from option with file names' unless files.empty?
|
82
|
+
[options[:from]].flatten.each { |path| include_as path.to_s, '.' }
|
67
83
|
elsif options[:merge]
|
68
|
-
raise
|
84
|
+
raise 'You can only use the :merge option in combination with the :path option' unless options.size == 1
|
69
85
|
files.each { |file| merge file }
|
70
86
|
else
|
71
|
-
raise "Unrecognized option #{options.keys.join(
|
87
|
+
raise "Unrecognized option #{options.keys.join(', ')}"
|
72
88
|
end
|
73
89
|
self
|
74
90
|
end
|
75
91
|
alias :add :include
|
92
|
+
alias :<< :include
|
76
93
|
|
77
94
|
# :call-seq:
|
78
95
|
# exclude(*files) => self
|
@@ -87,28 +104,23 @@ module Buildr
|
|
87
104
|
# merge(*files) => Merge
|
88
105
|
# merge(*files, :path=>name) => Merge
|
89
106
|
def merge(*args)
|
90
|
-
options =
|
107
|
+
options = Hash === args.last ? args.pop : {}
|
91
108
|
files = args.flatten
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
elsif options[:path]
|
101
|
-
sans_path = options.reject { |k,v| k == :path }
|
102
|
-
path(options[:path]).merge *files + [sans_path]
|
103
|
-
self
|
104
|
-
else
|
105
|
-
raise "Unrecognized option #{options.keys.join(", ")}"
|
109
|
+
rake_check_options options, :path
|
110
|
+
raise ArgumentError, "Expected at least one file to merge" if files.empty?
|
111
|
+
path = options[:path] || @path
|
112
|
+
expanders = files.collect do |file|
|
113
|
+
@sources << proc { file.to_s }
|
114
|
+
expander = ZipExpander.new(file)
|
115
|
+
@actions << proc { |file_map| expander.expand(file_map, path) }
|
116
|
+
expander
|
106
117
|
end
|
118
|
+
Merge.new(expanders)
|
107
119
|
end
|
108
120
|
|
109
121
|
# Returns a Path relative to this one.
|
110
122
|
def path(path)
|
111
|
-
return self if path.
|
123
|
+
return self if path.nil?
|
112
124
|
return root.path(path[1..-1]) if path[0] == ?/
|
113
125
|
root.path("#{@path}#{path}")
|
114
126
|
end
|
@@ -135,14 +147,14 @@ module Buildr
|
|
135
147
|
unless excluded?(file)
|
136
148
|
if File.directory?(file)
|
137
149
|
in_directory file do |file, rel_path|
|
138
|
-
path = rel_path.split(
|
139
|
-
path.unshift as unless as ==
|
150
|
+
path = rel_path.split('/')[1..-1]
|
151
|
+
path.unshift as unless as == '.'
|
140
152
|
dest = "#{@path}#{path.join('/')}"
|
141
|
-
puts "Adding #{dest}" if
|
153
|
+
puts "Adding #{dest}" if Buildr.application.options.trace
|
142
154
|
file_map[dest] = file
|
143
155
|
end
|
144
156
|
else
|
145
|
-
puts "Adding #{@path}#{as}" if
|
157
|
+
puts "Adding #{@path}#{as}" if Buildr.application.options.trace
|
146
158
|
file_map["#{@path}#{as}"] = file
|
147
159
|
end
|
148
160
|
end
|
@@ -150,17 +162,34 @@ module Buildr
|
|
150
162
|
end
|
151
163
|
|
152
164
|
def in_directory(dir)
|
153
|
-
prefix = Regexp.new(
|
154
|
-
|
155
|
-
each { |file| yield file, file.sub(prefix,
|
165
|
+
prefix = Regexp.new('^' + Regexp.escape(File.dirname(dir) + File::SEPARATOR))
|
166
|
+
Util.recursive_with_dot_files(dir).reject { |file| excluded?(file) }.
|
167
|
+
each { |file| yield file, file.sub(prefix, '') }
|
156
168
|
end
|
157
169
|
|
158
170
|
def excluded?(file)
|
159
|
-
@excludes.any? { |exclude| File.fnmatch(exclude, file) }
|
171
|
+
@excludes.any? { |exclude| File.fnmatch(exclude, file, File::FNM_PATHNAME) }
|
160
172
|
end
|
161
173
|
|
162
174
|
end
|
163
175
|
|
176
|
+
class Merge
|
177
|
+
def initialize(expanders)
|
178
|
+
@expanders = expanders
|
179
|
+
end
|
180
|
+
|
181
|
+
def include(*files)
|
182
|
+
@expanders.each { |expander| expander.include(*files) }
|
183
|
+
self
|
184
|
+
end
|
185
|
+
alias :<< :include
|
186
|
+
|
187
|
+
def exclude(*files)
|
188
|
+
@expanders.each { |expander| expander.exclude(*files) }
|
189
|
+
self
|
190
|
+
end
|
191
|
+
end
|
192
|
+
|
164
193
|
|
165
194
|
# Extend one Zip file into another.
|
166
195
|
class ZipExpander #:nodoc:
|
@@ -175,6 +204,7 @@ module Buildr
|
|
175
204
|
@includes |= files
|
176
205
|
self
|
177
206
|
end
|
207
|
+
alias :<< :include
|
178
208
|
|
179
209
|
def exclude(*files)
|
180
210
|
@excludes |= files
|
@@ -182,13 +212,13 @@ module Buildr
|
|
182
212
|
end
|
183
213
|
|
184
214
|
def expand(file_map, path)
|
185
|
-
@includes = [
|
215
|
+
@includes = ['**/*'] if @includes.empty?
|
186
216
|
Zip::ZipFile.open(@zip_file) do |source|
|
187
217
|
source.entries.reject { |entry| entry.directory? }.each do |entry|
|
188
|
-
if @includes.any? { |pattern| File.fnmatch(pattern, entry.name) } &&
|
189
|
-
!@excludes.any? { |pattern| File.fnmatch(pattern, entry.name) }
|
190
|
-
dest =
|
191
|
-
puts "Adding #{dest}" if
|
218
|
+
if @includes.any? { |pattern| File.fnmatch(pattern, entry.name, File::FNM_PATHNAME) } &&
|
219
|
+
!@excludes.any? { |pattern| File.fnmatch(pattern, entry.name, File::FNM_PATHNAME) }
|
220
|
+
dest = path =~ /^\/?$/ ? entry.name : Util.relative_path(path + "/" + entry.name)
|
221
|
+
puts "Adding #{dest}" if Buildr.application.options.trace
|
192
222
|
file_map[dest] = lambda { |output| output.write source.read(entry) }
|
193
223
|
end
|
194
224
|
end
|
@@ -200,14 +230,13 @@ module Buildr
|
|
200
230
|
|
201
231
|
def initialize(*args) #:nodoc:
|
202
232
|
super
|
203
|
-
|
204
|
-
@prepares = []
|
233
|
+
clean
|
205
234
|
|
206
235
|
# Make sure we're the last enhancements, so other enhancements can add content.
|
207
236
|
enhance do
|
208
237
|
@file_map = {}
|
209
238
|
enhance do
|
210
|
-
send
|
239
|
+
send 'create' if respond_to?(:create)
|
211
240
|
# We're here because the archive file does not exist, or one of the files is newer than the archive contents;
|
212
241
|
# we need to make sure the archive doesn't exist (e.g. opening an existing Zip will add instead of create).
|
213
242
|
# We also want to protect against partial updates.
|
@@ -215,7 +244,7 @@ module Buildr
|
|
215
244
|
mkpath File.dirname(name), :verbose=>false
|
216
245
|
begin
|
217
246
|
@paths.each do |name, object|
|
218
|
-
@file_map[name] = nil unless name.
|
247
|
+
@file_map[name] = nil unless name.empty?
|
219
248
|
object.add_files(@file_map)
|
220
249
|
end
|
221
250
|
create_from @file_map
|
@@ -227,6 +256,22 @@ module Buildr
|
|
227
256
|
end
|
228
257
|
end
|
229
258
|
|
259
|
+
# :call-seq:
|
260
|
+
# clean => self
|
261
|
+
#
|
262
|
+
# Removes all previously added content from this archive.
|
263
|
+
# Use this method if you want to remove default content from a package.
|
264
|
+
# For example, package(:jar) by default includes compiled classes and resources,
|
265
|
+
# using this method, you can create an empty jar and afterwards add the
|
266
|
+
# desired content to it.
|
267
|
+
#
|
268
|
+
# package(:jar).clean.include path_to('desired/content')
|
269
|
+
def clean
|
270
|
+
@paths = { '' => Path.new(self, '') }
|
271
|
+
@prepares = []
|
272
|
+
self
|
273
|
+
end
|
274
|
+
|
230
275
|
# :call-seq:
|
231
276
|
# include(*files) => self
|
232
277
|
# include(*files, :path=>path) => self
|
@@ -238,39 +283,40 @@ module Buildr
|
|
238
283
|
#
|
239
284
|
# The first form accepts a list of files, directories and glob patterns and adds them to the archive.
|
240
285
|
# For example, to include the file foo, directory bar (including all files in there) and all files under baz:
|
241
|
-
# zip(..).include(
|
286
|
+
# zip(..).include('foo', 'bar', 'baz/*')
|
242
287
|
#
|
243
288
|
# The second form is similar but adds files/directories under the specified path. For example,
|
244
289
|
# to add foo as bar/foo:
|
245
|
-
# zip(..).include(
|
290
|
+
# zip(..).include('foo', :path=>'bar')
|
246
291
|
# The :path option is the same as using the path method:
|
247
|
-
# zip(..).path(
|
292
|
+
# zip(..).path('bar').include('foo')
|
248
293
|
# All other options can be used in combination with the :path option.
|
249
294
|
#
|
250
295
|
# The third form adds a file or directory under a different name. For example, to add the file foo under the
|
251
296
|
# name bar:
|
252
|
-
# zip(..).include(
|
297
|
+
# zip(..).include('foo', :as=>'bar')
|
253
298
|
#
|
254
299
|
# The fourth form adds the contents of a directory using the directory as a prerequisite:
|
255
|
-
# zip(..).include(:from=>
|
256
|
-
# Unlike <code>include(
|
257
|
-
# Unlike <code>include(
|
300
|
+
# zip(..).include(:from=>'foo')
|
301
|
+
# Unlike <code>include('foo')</code> it includes the contents of the directory, not the directory itself.
|
302
|
+
# Unlike <code>include('foo/*')</code>, it uses the directory timestamp for dependency management.
|
258
303
|
#
|
259
304
|
# The fifth form includes the contents of another archive by expanding it into this archive. For example:
|
260
|
-
# zip(..).include(
|
305
|
+
# zip(..).include('foo.zip', :merge=>true).include('bar.zip')
|
261
306
|
# You can also use the method #merge.
|
262
307
|
def include(*files)
|
263
|
-
@paths[
|
308
|
+
@paths[''].include *files
|
264
309
|
self
|
265
310
|
end
|
266
311
|
alias :add :include
|
312
|
+
alias :<< :include
|
267
313
|
|
268
314
|
# :call-seq:
|
269
315
|
# exclude(*files) => self
|
270
316
|
#
|
271
317
|
# Excludes files and returns self. Can be used in combination with include to prevent some files from being included.
|
272
318
|
def exclude(*files)
|
273
|
-
@paths[
|
319
|
+
@paths[''].exclude *files
|
274
320
|
self
|
275
321
|
end
|
276
322
|
|
@@ -282,34 +328,34 @@ module Buildr
|
|
282
328
|
#
|
283
329
|
# Returns an object that supports two methods: include and exclude. You can use these methods to merge
|
284
330
|
# only specific files. For example:
|
285
|
-
# zip(..).merge(
|
331
|
+
# zip(..).merge('src.zip').include('module1/*')
|
286
332
|
def merge(*files)
|
287
|
-
@paths[
|
333
|
+
@paths[''].merge *files
|
288
334
|
end
|
289
335
|
|
290
336
|
# :call-seq:
|
291
337
|
# path(name) => Path
|
292
338
|
#
|
293
339
|
# Returns a path object. Use the path object to include files under a path, for example, to include
|
294
|
-
# the file
|
295
|
-
# zip(..).path(
|
340
|
+
# the file 'foo' as 'bar/foo':
|
341
|
+
# zip(..).path('bar').include('foo')
|
296
342
|
#
|
297
343
|
# Returns a Path object. The Path object implements all the same methods, like include, exclude, merge
|
298
344
|
# and so forth. It also implements path and root, so that:
|
299
|
-
# path(
|
300
|
-
# path(
|
345
|
+
# path('foo').path('bar') == path('foo/bar')
|
346
|
+
# path('foo').root == root
|
301
347
|
def path(name)
|
302
|
-
return @paths[
|
303
|
-
normalized = name.split(
|
348
|
+
return @paths[''] if name.nil?
|
349
|
+
normalized = name.split('/').inject([]) do |path, part|
|
304
350
|
case part
|
305
|
-
when
|
351
|
+
when '.', nil, ''
|
306
352
|
path
|
307
|
-
when
|
353
|
+
when '..'
|
308
354
|
path[0...-1]
|
309
355
|
else
|
310
356
|
path << part
|
311
357
|
end
|
312
|
-
end.join(
|
358
|
+
end.join('/')
|
313
359
|
@paths[normalized] ||= Path.new(self, normalized)
|
314
360
|
end
|
315
361
|
|
@@ -328,24 +374,19 @@ module Buildr
|
|
328
374
|
# the WarTask supports options like :manifest, :libs and :classes.
|
329
375
|
#
|
330
376
|
# For example:
|
331
|
-
# package(:jar).with(:manifest=>
|
377
|
+
# package(:jar).with(:manifest=>'MANIFEST_MF')
|
332
378
|
def with(options)
|
333
379
|
options.each do |key, value|
|
334
380
|
begin
|
335
381
|
send "#{key}=", value
|
336
|
-
rescue
|
337
|
-
|
338
|
-
warn_deprecated "The []= method is deprecated, please use attribute accessors instead."
|
339
|
-
self[key] = value
|
340
|
-
else
|
341
|
-
raise ArgumentError, "This task does not support the option #{key}."
|
342
|
-
end
|
382
|
+
rescue NoMethodError
|
383
|
+
raise ArgumentError, "#{self.class.name} does not support the option #{key}"
|
343
384
|
end
|
344
385
|
end
|
345
386
|
self
|
346
387
|
end
|
347
388
|
|
348
|
-
def invoke_prerequisites() #:nodoc:
|
389
|
+
def invoke_prerequisites(args, chain) #:nodoc:
|
349
390
|
@prepares.each { |prepare| prepare.call(self) }
|
350
391
|
@prepares.clear
|
351
392
|
@prerequisites |= @paths.collect { |name, path| path.sources }.flatten
|
@@ -355,8 +396,8 @@ module Buildr
|
|
355
396
|
def needed?() #:nodoc:
|
356
397
|
return true unless File.exist?(name)
|
357
398
|
# You can do something like:
|
358
|
-
# include(
|
359
|
-
# include(
|
399
|
+
# include('foo', :path=>'foo').exclude('foo/bar', path=>'foo').
|
400
|
+
# include('foo/bar', :path=>'foo/bar')
|
360
401
|
# This will play havoc if we handled all the prerequisites together
|
361
402
|
# under the task, so instead we handle them individually for each path.
|
362
403
|
#
|
@@ -365,7 +406,7 @@ module Buildr
|
|
365
406
|
# coming from, since some tasks touch the directory, e.g. when the
|
366
407
|
# content of target/classes is included into a WAR.
|
367
408
|
most_recent = @paths.collect { |name, path| path.sources }.flatten.
|
368
|
-
each { |src| File.directory?(src) ?
|
409
|
+
each { |src| File.directory?(src) ? Util.recursive_with_dot_files(src) | [src] : src }.flatten.
|
369
410
|
select { |file| File.exist?(file) }.collect { |file| File.stat(file).mtime }.max
|
370
411
|
File.stat(name).mtime < (most_recent || Rake::EARLY) || super
|
371
412
|
end
|
@@ -390,37 +431,45 @@ module Buildr
|
|
390
431
|
# use exclusion patterns, and include files into specific directories.
|
391
432
|
#
|
392
433
|
# For example:
|
393
|
-
# zip(
|
394
|
-
# task.include
|
395
|
-
# task.include
|
434
|
+
# zip('test.zip').tap do |task|
|
435
|
+
# task.include 'srcs'
|
436
|
+
# task.include 'README', 'LICENSE'
|
396
437
|
# end
|
397
438
|
#
|
398
439
|
# See Buildr#zip and ArchiveTask.
|
399
440
|
class ZipTask < ArchiveTask
|
400
441
|
|
442
|
+
# Compression leve for this Zip.
|
443
|
+
attr_accessor :compression_level
|
444
|
+
|
445
|
+
def initialize(*args) #:nodoc:
|
446
|
+
self.compression_level = Zlib::NO_COMPRESSION
|
447
|
+
super
|
448
|
+
end
|
449
|
+
|
401
450
|
private
|
402
451
|
|
403
452
|
def create_from(file_map)
|
404
453
|
Zip::ZipOutputStream.open name do |zip|
|
405
454
|
seen = {}
|
406
455
|
mkpath = lambda do |dir|
|
407
|
-
unless dir ==
|
456
|
+
unless dir == '.' || seen[dir]
|
408
457
|
mkpath.call File.dirname(dir)
|
409
|
-
zip.put_next_entry
|
458
|
+
zip.put_next_entry(dir + '/', compression_level)
|
410
459
|
seen[dir] = true
|
411
460
|
end
|
412
461
|
end
|
413
|
-
|
462
|
+
|
414
463
|
file_map.each do |path, content|
|
415
464
|
mkpath.call File.dirname(path)
|
416
465
|
if content.respond_to?(:call)
|
417
|
-
zip.put_next_entry
|
466
|
+
zip.put_next_entry(path, compression_level)
|
418
467
|
content.call zip
|
419
468
|
elsif content.nil? || File.directory?(content.to_s)
|
420
469
|
mkpath.call path
|
421
470
|
else
|
422
|
-
zip.put_next_entry
|
423
|
-
File.open content.to_s,
|
471
|
+
zip.put_next_entry(path, compression_level)
|
472
|
+
File.open content.to_s, 'rb' do |is|
|
424
473
|
while data = is.read(4096)
|
425
474
|
zip << data
|
426
475
|
end
|
@@ -441,9 +490,9 @@ module Buildr
|
|
441
490
|
# directories.
|
442
491
|
#
|
443
492
|
# For example:
|
444
|
-
# zip(
|
445
|
-
# task.include
|
446
|
-
# task.include
|
493
|
+
# zip('test.zip').tap do |task|
|
494
|
+
# task.include 'srcs'
|
495
|
+
# task.include 'README', 'LICENSE'
|
447
496
|
# end
|
448
497
|
def zip(file)
|
449
498
|
ZipTask.define_task(file)
|
@@ -467,7 +516,7 @@ module Buildr
|
|
467
516
|
|
468
517
|
# Initialize with hash argument of the form target=>zip_file.
|
469
518
|
def initialize(args)
|
470
|
-
@target, @zip_file =
|
519
|
+
@target, arg_names, @zip_file = Buildr.application.resolve_args([args])
|
471
520
|
@paths = {}
|
472
521
|
end
|
473
522
|
|
@@ -487,7 +536,6 @@ module Buildr
|
|
487
536
|
# specified. Nothing will happen unless we include all files.
|
488
537
|
if @paths.empty?
|
489
538
|
@paths[nil] = FromPath.new(self, nil)
|
490
|
-
@paths[nil].include "*"
|
491
539
|
end
|
492
540
|
|
493
541
|
# Otherwise, empty unzip creates target as a file when touching.
|
@@ -498,7 +546,7 @@ module Buildr
|
|
498
546
|
patterns.map(entries).each do |dest, entry|
|
499
547
|
next if entry.directory?
|
500
548
|
dest = File.expand_path(dest, target.to_s)
|
501
|
-
puts "Extracting #{dest}" if
|
549
|
+
puts "Extracting #{dest}" if Buildr.application.options.trace
|
502
550
|
mkpath File.dirname(dest), :verbose=>false rescue nil
|
503
551
|
entry.extract(dest) { true }
|
504
552
|
end
|
@@ -551,11 +599,11 @@ module Buildr
|
|
551
599
|
# Expands the file relative to that path.
|
552
600
|
#
|
553
601
|
# For example:
|
554
|
-
# unzip(Dir.pwd=>
|
602
|
+
# unzip(Dir.pwd=>'test.jar').from_path('etc').include('LICENSE')
|
555
603
|
# will unzip etc/LICENSE into ./LICENSE.
|
556
604
|
#
|
557
605
|
# This is different from:
|
558
|
-
# unzip(Dir.pwd=>
|
606
|
+
# unzip(Dir.pwd=>'test.jar').include('etc/LICENSE')
|
559
607
|
# which unzips etc/LICENSE into ./etc/LICENSE.
|
560
608
|
def from_path(name)
|
561
609
|
@paths[name] ||= FromPath.new(self, name)
|
@@ -581,9 +629,9 @@ module Buildr
|
|
581
629
|
def initialize(unzip, path)
|
582
630
|
@unzip = unzip
|
583
631
|
if path
|
584
|
-
@path = path[-1] == ?/ ? path : path +
|
632
|
+
@path = path[-1] == ?/ ? path : path + '/'
|
585
633
|
else
|
586
|
-
@path =
|
634
|
+
@path = ''
|
587
635
|
end
|
588
636
|
end
|
589
637
|
|
@@ -602,12 +650,12 @@ module Buildr
|
|
602
650
|
end
|
603
651
|
|
604
652
|
def map(entries)
|
605
|
-
includes = @include || [
|
653
|
+
includes = @include || ['**/*']
|
606
654
|
excludes = @exclude || []
|
607
655
|
entries.inject({}) do |map, entry|
|
608
|
-
short = entry.name.sub(@path,
|
609
|
-
if includes.any? { |pat| File.fnmatch(pat, short) } &&
|
610
|
-
!excludes.any? { |pat| File.fnmatch(pat, short) }
|
656
|
+
short = entry.name.sub(@path, '')
|
657
|
+
if includes.any? { |pat| File.fnmatch(pat, short, File::FNM_PATHNAME) } &&
|
658
|
+
!excludes.any? { |pat| File.fnmatch(pat, short, File::FNM_PATHNAME) }
|
611
659
|
map[short] = entry
|
612
660
|
end
|
613
661
|
map
|
@@ -643,11 +691,11 @@ module Buildr
|
|
643
691
|
# you overlay additional work on top of the file task.
|
644
692
|
#
|
645
693
|
# For example:
|
646
|
-
# unzip(
|
647
|
-
# unzip(
|
648
|
-
# unzip(
|
694
|
+
# unzip('all'=>'test.zip')
|
695
|
+
# unzip('src'=>'test.zip').include('README', 'LICENSE')
|
696
|
+
# unzip('libs'=>'test.zip').from_path('libs')
|
649
697
|
def unzip(args)
|
650
|
-
target, zip_file =
|
698
|
+
target, arg_names, zip_file = Buildr.application.resolve_args([args])
|
651
699
|
task = file(File.expand_path(target.to_s)=>zip_file)
|
652
700
|
Unzip.new(task=>zip_file).tap do |setup|
|
653
701
|
task.enhance { setup.extract }
|