mguymon-buildr 1.4.5
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +1291 -0
- data/LICENSE +176 -0
- data/NOTICE +26 -0
- data/README.rdoc +134 -0
- data/Rakefile +44 -0
- data/_buildr +35 -0
- data/_jbuildr +35 -0
- data/addon/buildr/antlr.rb +65 -0
- data/addon/buildr/bnd.rb +147 -0
- data/addon/buildr/cobertura.rb +22 -0
- data/addon/buildr/drb.rb +281 -0
- data/addon/buildr/emma.rb +22 -0
- data/addon/buildr/hibernate.rb +149 -0
- data/addon/buildr/javacc.rb +85 -0
- data/addon/buildr/jaxb_xjc.rb +72 -0
- data/addon/buildr/jdepend.rb +60 -0
- data/addon/buildr/jetty.rb +248 -0
- data/addon/buildr/jibx.rb +86 -0
- data/addon/buildr/nailgun.rb +221 -0
- data/addon/buildr/openjpa.rb +88 -0
- data/addon/buildr/org/apache/buildr/BuildrNail$Main.class +0 -0
- data/addon/buildr/org/apache/buildr/BuildrNail.class +0 -0
- data/addon/buildr/org/apache/buildr/BuildrNail.java +41 -0
- 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/addon/buildr/org/apache/buildr/JettyWrapper.java +144 -0
- data/addon/buildr/protobuf.rb +88 -0
- data/addon/buildr/xmlbeans.rb +93 -0
- data/bin/buildr +19 -0
- data/buildr.buildfile +58 -0
- data/buildr.gemspec +78 -0
- data/doc/_config.yml +1 -0
- data/doc/_layouts/default.html +90 -0
- data/doc/_layouts/preface.html +22 -0
- data/doc/artifacts.textile +217 -0
- data/doc/building.textile +276 -0
- data/doc/contributing.textile +268 -0
- data/doc/css/default.css +236 -0
- data/doc/css/print.css +101 -0
- data/doc/css/syntax.css +23 -0
- data/doc/download.textile +151 -0
- data/doc/extending.textile +212 -0
- data/doc/images/1442160941-frontcover.jpg +0 -0
- data/doc/images/asf-logo.gif +0 -0
- data/doc/images/asf-logo.png +0 -0
- data/doc/images/buildr-hires.png +0 -0
- data/doc/images/buildr.png +0 -0
- data/doc/images/favicon.png +0 -0
- data/doc/images/growl-icon.tiff +0 -0
- data/doc/images/note.png +0 -0
- data/doc/images/project-structure.png +0 -0
- data/doc/images/tip.png +0 -0
- data/doc/images/zbuildr.png +0 -0
- data/doc/images/zbuildr.tif +0 -0
- data/doc/index.textile +109 -0
- data/doc/installing.textile +284 -0
- data/doc/languages.textile +599 -0
- data/doc/mailing_lists.textile +29 -0
- data/doc/more_stuff.textile +845 -0
- data/doc/packaging.textile +618 -0
- data/doc/preface.textile +54 -0
- data/doc/projects.textile +276 -0
- data/doc/quick_start.textile +210 -0
- data/doc/releasing.textile +117 -0
- data/doc/scripts/buildr-git.rb +512 -0
- data/doc/scripts/gitflow.rb +296 -0
- data/doc/scripts/install-jruby.sh +44 -0
- data/doc/scripts/install-linux.sh +73 -0
- data/doc/scripts/install-osx.sh +52 -0
- data/doc/settings_profiles.textile +287 -0
- data/doc/testing.textile +247 -0
- data/etc/KEYS +189 -0
- data/lib/buildr.rb +44 -0
- data/lib/buildr/clojure.rb +34 -0
- data/lib/buildr/clojure/shell.rb +52 -0
- data/lib/buildr/core.rb +34 -0
- data/lib/buildr/core/application.rb +700 -0
- data/lib/buildr/core/build.rb +516 -0
- data/lib/buildr/core/cc.rb +166 -0
- data/lib/buildr/core/checks.rb +253 -0
- data/lib/buildr/core/common.rb +151 -0
- data/lib/buildr/core/compile.rb +622 -0
- data/lib/buildr/core/doc.rb +276 -0
- data/lib/buildr/core/environment.rb +129 -0
- data/lib/buildr/core/filter.rb +404 -0
- data/lib/buildr/core/generate.rb +197 -0
- data/lib/buildr/core/help.rb +119 -0
- data/lib/buildr/core/jrebel.rb +42 -0
- data/lib/buildr/core/linux.rb +30 -0
- data/lib/buildr/core/osx.rb +46 -0
- data/lib/buildr/core/progressbar.rb +161 -0
- data/lib/buildr/core/project.rb +975 -0
- data/lib/buildr/core/run.rb +43 -0
- data/lib/buildr/core/shell.rb +137 -0
- data/lib/buildr/core/test.rb +843 -0
- data/lib/buildr/core/transports.rb +575 -0
- data/lib/buildr/core/util.rb +537 -0
- data/lib/buildr/groovy.rb +20 -0
- data/lib/buildr/groovy/bdd.rb +106 -0
- data/lib/buildr/groovy/compiler.rb +153 -0
- data/lib/buildr/groovy/doc.rb +76 -0
- data/lib/buildr/groovy/shell.rb +57 -0
- data/lib/buildr/ide.rb +19 -0
- data/lib/buildr/ide/eclipse.rb +427 -0
- data/lib/buildr/ide/eclipse/java.rb +53 -0
- data/lib/buildr/ide/eclipse/plugin.rb +71 -0
- data/lib/buildr/ide/eclipse/scala.rb +68 -0
- data/lib/buildr/ide/idea.rb +576 -0
- data/lib/buildr/java.rb +25 -0
- data/lib/buildr/java/ant.rb +94 -0
- data/lib/buildr/java/bdd.rb +460 -0
- data/lib/buildr/java/cobertura.rb +297 -0
- data/lib/buildr/java/commands.rb +223 -0
- data/lib/buildr/java/compiler.rb +135 -0
- data/lib/buildr/java/deprecated.rb +141 -0
- data/lib/buildr/java/doc.rb +86 -0
- data/lib/buildr/java/ecj.rb +69 -0
- data/lib/buildr/java/emma.rb +244 -0
- data/lib/buildr/java/external.rb +73 -0
- data/lib/buildr/java/jruby.rb +122 -0
- data/lib/buildr/java/jtestr_result.rb +295 -0
- data/lib/buildr/java/jtestr_runner.rb.erb +116 -0
- data/lib/buildr/java/org/apache/buildr/JavaTestFilter.class +0 -0
- data/lib/buildr/java/org/apache/buildr/JavaTestFilter.java +142 -0
- data/lib/buildr/java/packaging.rb +734 -0
- data/lib/buildr/java/pom.rb +178 -0
- data/lib/buildr/java/rjb.rb +154 -0
- data/lib/buildr/java/test_result.rb +101 -0
- data/lib/buildr/java/tests.rb +362 -0
- data/lib/buildr/java/version_requirement.rb +172 -0
- data/lib/buildr/packaging.rb +25 -0
- data/lib/buildr/packaging/archive.rb +535 -0
- data/lib/buildr/packaging/artifact.rb +904 -0
- data/lib/buildr/packaging/artifact_namespace.rb +984 -0
- data/lib/buildr/packaging/artifact_search.rb +140 -0
- data/lib/buildr/packaging/gems.rb +105 -0
- data/lib/buildr/packaging/package.rb +249 -0
- data/lib/buildr/packaging/repository_array.rb +108 -0
- data/lib/buildr/packaging/tar.rb +189 -0
- data/lib/buildr/packaging/version_requirement.rb +192 -0
- data/lib/buildr/packaging/zip.rb +178 -0
- data/lib/buildr/packaging/ziptask.rb +356 -0
- data/lib/buildr/resources/buildr.icns +0 -0
- data/lib/buildr/resources/completed.png +0 -0
- data/lib/buildr/resources/failed.png +0 -0
- data/lib/buildr/resources/icons-license.txt +17 -0
- data/lib/buildr/run.rb +195 -0
- data/lib/buildr/scala.rb +26 -0
- data/lib/buildr/scala/bdd.rb +118 -0
- data/lib/buildr/scala/compiler.rb +242 -0
- data/lib/buildr/scala/doc.rb +142 -0
- data/lib/buildr/scala/org/apache/buildr/SpecsSingletonRunner.class +0 -0
- data/lib/buildr/scala/org/apache/buildr/SpecsSingletonRunner.java +57 -0
- data/lib/buildr/scala/shell.rb +52 -0
- data/lib/buildr/scala/tests.rb +171 -0
- data/lib/buildr/shell.rb +185 -0
- data/lib/buildr/version.rb +18 -0
- data/rakelib/all-in-one.rake +113 -0
- data/rakelib/checks.rake +57 -0
- data/rakelib/doc.rake +137 -0
- data/rakelib/metrics.rake +39 -0
- data/rakelib/package.rake +73 -0
- data/rakelib/release.rake +160 -0
- data/rakelib/rspec.rake +91 -0
- data/rakelib/setup.rake +66 -0
- data/rakelib/stage.rake +220 -0
- data/spec/addon/bnd_spec.rb +330 -0
- data/spec/addon/drb_spec.rb +328 -0
- data/spec/addon/jaxb_xjc_spec.rb +125 -0
- data/spec/core/application_spec.rb +631 -0
- data/spec/core/build_spec.rb +837 -0
- data/spec/core/cc_spec.rb +224 -0
- data/spec/core/checks_spec.rb +519 -0
- data/spec/core/common_spec.rb +725 -0
- data/spec/core/compile_spec.rb +658 -0
- data/spec/core/doc_spec.rb +195 -0
- data/spec/core/extension_spec.rb +201 -0
- data/spec/core/generate_spec.rb +33 -0
- data/spec/core/project_spec.rb +772 -0
- data/spec/core/run_spec.rb +93 -0
- data/spec/core/shell_spec.rb +146 -0
- data/spec/core/test_spec.rb +1320 -0
- data/spec/core/transport_spec.rb +544 -0
- data/spec/core/util_spec.rb +141 -0
- data/spec/groovy/bdd_spec.rb +80 -0
- data/spec/groovy/compiler_spec.rb +251 -0
- data/spec/groovy/doc_spec.rb +65 -0
- data/spec/ide/eclipse_spec.rb +739 -0
- data/spec/ide/idea_spec.rb +1145 -0
- data/spec/java/ant_spec.rb +37 -0
- data/spec/java/bdd_spec.rb +374 -0
- data/spec/java/cobertura_spec.rb +112 -0
- data/spec/java/commands_spec.rb +93 -0
- data/spec/java/compiler_spec.rb +252 -0
- data/spec/java/doc_spec.rb +56 -0
- data/spec/java/ecj_spec.rb +115 -0
- data/spec/java/emma_spec.rb +121 -0
- data/spec/java/external_spec.rb +56 -0
- data/spec/java/java_spec.rb +132 -0
- data/spec/java/packaging_spec.rb +1266 -0
- data/spec/java/run_spec.rb +78 -0
- data/spec/java/test_coverage_helper.rb +257 -0
- data/spec/java/tests_spec.rb +497 -0
- data/spec/packaging/archive_spec.rb +775 -0
- data/spec/packaging/artifact_namespace_spec.rb +743 -0
- data/spec/packaging/artifact_spec.rb +1074 -0
- data/spec/packaging/packaging_helper.rb +63 -0
- data/spec/packaging/packaging_spec.rb +719 -0
- data/spec/packaging/repository_array_spec.rb +109 -0
- data/spec/sandbox.rb +165 -0
- data/spec/scala/bdd_spec.rb +124 -0
- data/spec/scala/compiler_spec.rb +289 -0
- data/spec/scala/doc_spec.rb +88 -0
- data/spec/scala/scala.rb +38 -0
- data/spec/scala/tests_spec.rb +283 -0
- data/spec/spec_helpers.rb +369 -0
- data/spec/version_requirement_spec.rb +143 -0
- data/spec/xpath_matchers.rb +121 -0
- metadata +649 -0
@@ -0,0 +1,178 @@
|
|
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
|
+
if RUBY_VERSION >= '1.9.0' # Required to properly load RubyZip under Ruby 1.9
|
18
|
+
$LOADED_FEATURES.unshift 'ftools'
|
19
|
+
require 'fileutils'
|
20
|
+
|
21
|
+
def File.move(source, dest)
|
22
|
+
FileUtils.move source, dest
|
23
|
+
end
|
24
|
+
|
25
|
+
def File.rm_rf(path)
|
26
|
+
FileUtils.rm_rf path
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
require 'zip/zip'
|
31
|
+
require 'zip/zipfilesystem'
|
32
|
+
|
33
|
+
module Zip #:nodoc:
|
34
|
+
|
35
|
+
class ZipCentralDirectory #:nodoc:
|
36
|
+
# Patch to add entries in alphabetical order.
|
37
|
+
def write_to_stream(io)
|
38
|
+
offset = io.tell
|
39
|
+
@entrySet.sort { |a,b| a.name <=> b.name }.each { |entry| entry.write_c_dir_entry(io) }
|
40
|
+
write_e_o_c_d(io, offset)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
|
45
|
+
class ZipEntry
|
46
|
+
|
47
|
+
# :call-seq:
|
48
|
+
# exist() => boolean
|
49
|
+
#
|
50
|
+
# Returns true if this entry exists.
|
51
|
+
def exist?()
|
52
|
+
Zip::ZipFile.open(zipfile) { |zip| zip.file.exist?(@name) }
|
53
|
+
end
|
54
|
+
|
55
|
+
# :call-seq:
|
56
|
+
# empty?() => boolean
|
57
|
+
#
|
58
|
+
# Returns true if this entry is empty.
|
59
|
+
def empty?()
|
60
|
+
Zip::ZipFile.open(zipfile) { |zip| zip.file.read(@name) }.empty?
|
61
|
+
end
|
62
|
+
|
63
|
+
# :call-seq:
|
64
|
+
# contain(patterns*) => boolean
|
65
|
+
#
|
66
|
+
# Returns true if this ZIP file entry matches against all the arguments. An argument may be
|
67
|
+
# a string or regular expression.
|
68
|
+
def contain?(*patterns)
|
69
|
+
content = Zip::ZipFile.open(zipfile) { |zip| zip.file.read(@name) }
|
70
|
+
patterns.map { |pattern| Regexp === pattern ? pattern : Regexp.new(Regexp.escape(pattern.to_s)) }.
|
71
|
+
all? { |pattern| content =~ pattern }
|
72
|
+
end
|
73
|
+
|
74
|
+
# Override of write_c_dir_entry to fix comments being set to a fixnum instead of string
|
75
|
+
def write_c_dir_entry(io) #:nodoc:all
|
76
|
+
case @fstype
|
77
|
+
when FSTYPE_UNIX
|
78
|
+
ft = nil
|
79
|
+
case @ftype
|
80
|
+
when :file
|
81
|
+
ft = 010
|
82
|
+
@unix_perms ||= 0644
|
83
|
+
when :directory
|
84
|
+
ft = 004
|
85
|
+
@unix_perms ||= 0755
|
86
|
+
when :symlink
|
87
|
+
ft = 012
|
88
|
+
@unix_perms ||= 0755
|
89
|
+
else
|
90
|
+
raise ZipInternalError, "unknown file type #{self.inspect}"
|
91
|
+
end
|
92
|
+
|
93
|
+
@externalFileAttributes = (ft << 12 | (@unix_perms & 07777)) << 16
|
94
|
+
end
|
95
|
+
|
96
|
+
io <<
|
97
|
+
[0x02014b50,
|
98
|
+
@version, # version of encoding software
|
99
|
+
@fstype, # filesystem type
|
100
|
+
10, # @versionNeededToExtract
|
101
|
+
0, # @gp_flags
|
102
|
+
@compression_method,
|
103
|
+
@time.to_binary_dos_time, # @lastModTime
|
104
|
+
@time.to_binary_dos_date, # @lastModDate
|
105
|
+
@crc,
|
106
|
+
@compressed_size,
|
107
|
+
@size,
|
108
|
+
@name ? @name.length : 0,
|
109
|
+
@extra ? @extra.c_dir_length : 0,
|
110
|
+
@comment ? comment.to_s.length : 0,
|
111
|
+
0, # disk number start
|
112
|
+
@internalFileAttributes, # file type (binary=0, text=1)
|
113
|
+
@externalFileAttributes, # native filesystem attributes
|
114
|
+
@localHeaderOffset,
|
115
|
+
@name,
|
116
|
+
@extra,
|
117
|
+
@comment
|
118
|
+
].pack('VCCvvvvvVVVvvvvvVV')
|
119
|
+
|
120
|
+
io << @name
|
121
|
+
io << (@extra ? @extra.to_c_dir_bin : "")
|
122
|
+
io << @comment
|
123
|
+
end
|
124
|
+
|
125
|
+
# Override write_c_dir_entry to fix comments being set to a fixnum instead of string
|
126
|
+
def write_c_dir_entry(io) #:nodoc:all
|
127
|
+
@comment = "" if @comment.nil? || @comment == -1 # Hack fix @comment being nil or fixnum -1
|
128
|
+
|
129
|
+
case @fstype
|
130
|
+
when FSTYPE_UNIX
|
131
|
+
ft = nil
|
132
|
+
case @ftype
|
133
|
+
when :file
|
134
|
+
ft = 010
|
135
|
+
@unix_perms ||= 0644
|
136
|
+
when :directory
|
137
|
+
ft = 004
|
138
|
+
@unix_perms ||= 0755
|
139
|
+
when :symlink
|
140
|
+
ft = 012
|
141
|
+
@unix_perms ||= 0755
|
142
|
+
else
|
143
|
+
raise ZipInternalError, "unknown file type #{self.inspect}"
|
144
|
+
end
|
145
|
+
|
146
|
+
@externalFileAttributes = (ft << 12 | (@unix_perms & 07777)) << 16
|
147
|
+
end
|
148
|
+
|
149
|
+
io <<
|
150
|
+
[0x02014b50,
|
151
|
+
@version, # version of encoding software
|
152
|
+
@fstype, # filesystem type
|
153
|
+
10, # @versionNeededToExtract
|
154
|
+
0, # @gp_flags
|
155
|
+
@compression_method,
|
156
|
+
@time.to_binary_dos_time, # @lastModTime
|
157
|
+
@time.to_binary_dos_date, # @lastModDate
|
158
|
+
@crc,
|
159
|
+
@compressed_size,
|
160
|
+
@size,
|
161
|
+
@name ? @name.length : 0,
|
162
|
+
@extra ? @extra.c_dir_length : 0,
|
163
|
+
@comment ? @comment.length : 0,
|
164
|
+
0, # disk number start
|
165
|
+
@internalFileAttributes, # file type (binary=0, text=1)
|
166
|
+
@externalFileAttributes, # native filesystem attributes
|
167
|
+
@localHeaderOffset,
|
168
|
+
@name,
|
169
|
+
@extra,
|
170
|
+
@comment].pack('VCCvvvvvVVVvvvvvVV')
|
171
|
+
|
172
|
+
io << @name
|
173
|
+
io << (@extra ? @extra.to_c_dir_bin : "")
|
174
|
+
io << @comment
|
175
|
+
|
176
|
+
end
|
177
|
+
end
|
178
|
+
end
|
@@ -0,0 +1,356 @@
|
|
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/archive'
|
18
|
+
|
19
|
+
|
20
|
+
module Buildr
|
21
|
+
|
22
|
+
# The ZipTask creates a new Zip file. You can include any number of files and and directories,
|
23
|
+
# use exclusion patterns, and include files into specific directories.
|
24
|
+
#
|
25
|
+
# For example:
|
26
|
+
# zip('test.zip').tap do |task|
|
27
|
+
# task.include 'srcs'
|
28
|
+
# task.include 'README', 'LICENSE'
|
29
|
+
# end
|
30
|
+
#
|
31
|
+
# See Buildr#zip and ArchiveTask.
|
32
|
+
class ZipTask < ArchiveTask
|
33
|
+
|
34
|
+
# Compression leve for this Zip.
|
35
|
+
attr_accessor :compression_level
|
36
|
+
|
37
|
+
def initialize(*args) #:nodoc:
|
38
|
+
self.compression_level = Zlib::DEFAULT_COMPRESSION
|
39
|
+
super
|
40
|
+
end
|
41
|
+
|
42
|
+
# :call-seq:
|
43
|
+
# entry(name) => Entry
|
44
|
+
#
|
45
|
+
# Returns a ZIP file entry. You can use this to check if the entry exists and its contents,
|
46
|
+
# for example:
|
47
|
+
# package(:jar).entry("META-INF/LICENSE").should contain(/Apache Software License/)
|
48
|
+
def entry(entry_name)
|
49
|
+
::Zip::ZipEntry.new(name, entry_name)
|
50
|
+
end
|
51
|
+
|
52
|
+
def entries #:nodoc:
|
53
|
+
@entries ||= Zip::ZipFile.open(name) { |zip| zip.entries }
|
54
|
+
end
|
55
|
+
|
56
|
+
private
|
57
|
+
|
58
|
+
def create_from(file_map)
|
59
|
+
Zip::ZipOutputStream.open name do |zip|
|
60
|
+
seen = {}
|
61
|
+
mkpath = lambda do |dir|
|
62
|
+
dirname = (dir[-1..-1] =~ /\/$/) ? dir : dir + '/'
|
63
|
+
unless dir == '.' || seen[dirname]
|
64
|
+
mkpath.call File.dirname(dirname)
|
65
|
+
zip.put_next_entry(dirname, compression_level)
|
66
|
+
seen[dirname] = true
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
file_map.each do |path, content|
|
71
|
+
warn "Warning: Path in zipfile #{name} contains backslash: #{path}" if path =~ /\\/
|
72
|
+
mkpath.call File.dirname(path)
|
73
|
+
if content.respond_to?(:call)
|
74
|
+
zip.put_next_entry(path, compression_level)
|
75
|
+
content.call zip
|
76
|
+
elsif content.nil? || File.directory?(content.to_s)
|
77
|
+
mkpath.call path
|
78
|
+
else
|
79
|
+
entry = zip.put_next_entry(path, compression_level)
|
80
|
+
File.open content.to_s, 'rb' do |is|
|
81
|
+
entry.unix_perms = is.stat.mode & 07777
|
82
|
+
while data = is.read(4096)
|
83
|
+
zip << data
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
end
|
92
|
+
|
93
|
+
|
94
|
+
# :call-seq:
|
95
|
+
# zip(file) => ZipTask
|
96
|
+
#
|
97
|
+
# The ZipTask creates a new Zip file. You can include any number of files and
|
98
|
+
# and directories, use exclusion patterns, and include files into specific
|
99
|
+
# directories.
|
100
|
+
#
|
101
|
+
# For example:
|
102
|
+
# zip('test.zip').tap do |task|
|
103
|
+
# task.include 'srcs'
|
104
|
+
# task.include 'README', 'LICENSE'
|
105
|
+
# end
|
106
|
+
def zip(file)
|
107
|
+
ZipTask.define_task(file)
|
108
|
+
end
|
109
|
+
|
110
|
+
|
111
|
+
# An object for unzipping/untarring a file into a target directory. You can tell it to include
|
112
|
+
# or exclude only specific files and directories, and also to map files from particular
|
113
|
+
# paths inside the zip file into the target directory. Once ready, call #extract.
|
114
|
+
#
|
115
|
+
# Usually it is more convenient to create a file task for extracting the zip file
|
116
|
+
# (see #unzip) and pass this object as a prerequisite to other tasks.
|
117
|
+
#
|
118
|
+
# See Buildr#unzip.
|
119
|
+
class Unzip
|
120
|
+
|
121
|
+
# The zip file to extract.
|
122
|
+
attr_accessor :zip_file
|
123
|
+
# The target directory to extract to.
|
124
|
+
attr_accessor :target
|
125
|
+
|
126
|
+
# Initialize with hash argument of the form target=>zip_file.
|
127
|
+
def initialize(args)
|
128
|
+
@target, arg_names, zip_file = Buildr.application.resolve_args([args])
|
129
|
+
@zip_file = zip_file.first
|
130
|
+
@paths = {}
|
131
|
+
end
|
132
|
+
|
133
|
+
# :call-seq:
|
134
|
+
# extract
|
135
|
+
#
|
136
|
+
# Extract the zip/tgz file into the target directory.
|
137
|
+
#
|
138
|
+
# You can call this method directly. However, if you are using the #unzip method,
|
139
|
+
# it creates a file task for the target directory: use that task instead as a
|
140
|
+
# prerequisite. For example:
|
141
|
+
# build unzip(dir=>zip_file)
|
142
|
+
# Or:
|
143
|
+
# unzip(dir=>zip_file).target.invoke
|
144
|
+
def extract
|
145
|
+
# If no paths specified, then no include/exclude patterns
|
146
|
+
# specified. Nothing will happen unless we include all files.
|
147
|
+
if @paths.empty?
|
148
|
+
@paths[nil] = FromPath.new(self, nil)
|
149
|
+
end
|
150
|
+
|
151
|
+
# Otherwise, empty unzip creates target as a file when touching.
|
152
|
+
mkpath target.to_s
|
153
|
+
if zip_file.to_s.match /\.t?gz$/
|
154
|
+
#un-tar.gz
|
155
|
+
Zlib::GzipReader.open(zip_file.to_s) { |tar|
|
156
|
+
Archive::Tar::Minitar::Input.open(tar) do |inp|
|
157
|
+
inp.each do |tar_entry|
|
158
|
+
@paths.each do |path, patterns|
|
159
|
+
patterns.map([tar_entry]).each do |dest, entry|
|
160
|
+
next if entry.directory?
|
161
|
+
dest = File.expand_path(dest, target.to_s)
|
162
|
+
trace "Extracting #{dest}"
|
163
|
+
mkpath File.dirname(dest) rescue nil
|
164
|
+
#entry.restore_permissions = true
|
165
|
+
File.open(dest, 'wb') {|f| f.write entry.read}
|
166
|
+
end
|
167
|
+
end
|
168
|
+
end
|
169
|
+
end
|
170
|
+
}
|
171
|
+
else
|
172
|
+
Zip::ZipFile.open(zip_file.to_s) do |zip|
|
173
|
+
entries = zip.collect
|
174
|
+
@paths.each do |path, patterns|
|
175
|
+
patterns.map(entries).each do |dest, entry|
|
176
|
+
next if entry.directory?
|
177
|
+
dest = File.expand_path(dest, target.to_s)
|
178
|
+
trace "Extracting #{dest}"
|
179
|
+
mkpath File.dirname(dest) rescue nil
|
180
|
+
entry.restore_permissions = true
|
181
|
+
entry.extract(dest) { true }
|
182
|
+
end
|
183
|
+
end
|
184
|
+
end
|
185
|
+
end
|
186
|
+
# Let other tasks know we updated the target directory.
|
187
|
+
touch target.to_s
|
188
|
+
end
|
189
|
+
|
190
|
+
#reads the includes/excludes and apply them to the entry_name
|
191
|
+
def included?(entry_name)
|
192
|
+
@paths.each do |path, patterns|
|
193
|
+
return true if path.nil?
|
194
|
+
if entry_name =~ /^#{path}/
|
195
|
+
short = entry_name.sub(path, '')
|
196
|
+
if patterns.include.any? { |pattern| File.fnmatch(pattern, entry_name) } &&
|
197
|
+
!patterns.exclude.any? { |pattern| File.fnmatch(pattern, entry_name) }
|
198
|
+
# trace "tar_entry.full_name " + entry_name + " is included"
|
199
|
+
return true
|
200
|
+
end
|
201
|
+
end
|
202
|
+
end
|
203
|
+
# trace "tar_entry.full_name " + entry_name + " is excluded"
|
204
|
+
return false
|
205
|
+
end
|
206
|
+
|
207
|
+
|
208
|
+
# :call-seq:
|
209
|
+
# include(*files) => self
|
210
|
+
# include(*files, :path=>name) => self
|
211
|
+
#
|
212
|
+
# Include all files that match the patterns and returns self.
|
213
|
+
#
|
214
|
+
# Use include if you only want to unzip some of the files, by specifying
|
215
|
+
# them instead of using exclusion. You can use #include in combination
|
216
|
+
# with #exclude.
|
217
|
+
def include(*files)
|
218
|
+
if Hash === files.last
|
219
|
+
from_path(files.pop[:path]).include *files
|
220
|
+
else
|
221
|
+
from_path(nil).include *files
|
222
|
+
end
|
223
|
+
self
|
224
|
+
end
|
225
|
+
alias :add :include
|
226
|
+
|
227
|
+
# :call-seq:
|
228
|
+
# exclude(*files) => self
|
229
|
+
#
|
230
|
+
# Exclude all files that match the patterns and return self.
|
231
|
+
#
|
232
|
+
# Use exclude to unzip all files except those that match the pattern.
|
233
|
+
# You can use #exclude in combination with #include.
|
234
|
+
def exclude(*files)
|
235
|
+
if Hash === files.last
|
236
|
+
from_path(files.pop[:path]).exclude *files
|
237
|
+
else
|
238
|
+
from_path(nil).exclude *files
|
239
|
+
end
|
240
|
+
self
|
241
|
+
end
|
242
|
+
|
243
|
+
# :call-seq:
|
244
|
+
# from_path(name) => Path
|
245
|
+
#
|
246
|
+
# Allows you to unzip from a path. Returns an object you can use to
|
247
|
+
# specify which files to include/exclude relative to that path.
|
248
|
+
# Expands the file relative to that path.
|
249
|
+
#
|
250
|
+
# For example:
|
251
|
+
# unzip(Dir.pwd=>'test.jar').from_path('etc').include('LICENSE')
|
252
|
+
# will unzip etc/LICENSE into ./LICENSE.
|
253
|
+
#
|
254
|
+
# This is different from:
|
255
|
+
# unzip(Dir.pwd=>'test.jar').include('etc/LICENSE')
|
256
|
+
# which unzips etc/LICENSE into ./etc/LICENSE.
|
257
|
+
def from_path(name)
|
258
|
+
@paths[name] ||= FromPath.new(self, name)
|
259
|
+
end
|
260
|
+
alias :path :from_path
|
261
|
+
|
262
|
+
# :call-seq:
|
263
|
+
# root => Unzip
|
264
|
+
#
|
265
|
+
# Returns the root path, essentially the Unzip object itself. In case you are wondering
|
266
|
+
# down paths and want to go back.
|
267
|
+
def root
|
268
|
+
self
|
269
|
+
end
|
270
|
+
|
271
|
+
# Returns the path to the target directory.
|
272
|
+
def to_s
|
273
|
+
target.to_s
|
274
|
+
end
|
275
|
+
|
276
|
+
class FromPath #:nodoc:
|
277
|
+
|
278
|
+
def initialize(unzip, path)
|
279
|
+
@unzip = unzip
|
280
|
+
if path
|
281
|
+
@path = path[-1] == ?/ ? path : path + '/'
|
282
|
+
else
|
283
|
+
@path = ''
|
284
|
+
end
|
285
|
+
end
|
286
|
+
|
287
|
+
# See UnzipTask#include
|
288
|
+
def include(*files) #:doc:
|
289
|
+
@include ||= []
|
290
|
+
@include |= files
|
291
|
+
self
|
292
|
+
end
|
293
|
+
|
294
|
+
# See UnzipTask#exclude
|
295
|
+
def exclude(*files) #:doc:
|
296
|
+
@exclude ||= []
|
297
|
+
@exclude |= files
|
298
|
+
self
|
299
|
+
end
|
300
|
+
|
301
|
+
def map(entries)
|
302
|
+
includes = @include || ['*']
|
303
|
+
excludes = @exclude || []
|
304
|
+
entries.inject({}) do |map, entry|
|
305
|
+
if entry.name =~ /^#{@path}/
|
306
|
+
short = entry.name.sub(@path, '')
|
307
|
+
if includes.any? { |pat| File.fnmatch(pat, short) } &&
|
308
|
+
!excludes.any? { |pat| File.fnmatch(pat, short) }
|
309
|
+
map[short] = entry
|
310
|
+
end
|
311
|
+
end
|
312
|
+
map
|
313
|
+
end
|
314
|
+
end
|
315
|
+
|
316
|
+
# Documented in Unzip.
|
317
|
+
def root
|
318
|
+
@unzip
|
319
|
+
end
|
320
|
+
|
321
|
+
# The target directory to extract to.
|
322
|
+
def target
|
323
|
+
@unzip.target
|
324
|
+
end
|
325
|
+
|
326
|
+
end
|
327
|
+
|
328
|
+
end
|
329
|
+
|
330
|
+
# :call-seq:
|
331
|
+
# unzip(to_dir=>zip_file) => Zip
|
332
|
+
#
|
333
|
+
# Creates a task that will unzip a file into the target directory. The task name
|
334
|
+
# is the target directory, the prerequisite is the file to unzip.
|
335
|
+
#
|
336
|
+
# This method creates a file task to expand the zip file. It returns an Unzip object
|
337
|
+
# that specifies how the file will be extracted. You can include or exclude specific
|
338
|
+
# files from within the zip, and map to different paths.
|
339
|
+
#
|
340
|
+
# The Unzip object's to_s method return the path to the target directory, so you can
|
341
|
+
# use it as a prerequisite. By keeping the Unzip object separate from the file task,
|
342
|
+
# you overlay additional work on top of the file task.
|
343
|
+
#
|
344
|
+
# For example:
|
345
|
+
# unzip('all'=>'test.zip')
|
346
|
+
# unzip('src'=>'test.zip').include('README', 'LICENSE')
|
347
|
+
# unzip('libs'=>'test.zip').from_path('libs')
|
348
|
+
def unzip(args)
|
349
|
+
target, arg_names, zip_file = Buildr.application.resolve_args([args])
|
350
|
+
task = file(File.expand_path(target.to_s)=>zip_file)
|
351
|
+
Unzip.new(task=>zip_file).tap do |setup|
|
352
|
+
task.enhance { setup.extract }
|
353
|
+
end
|
354
|
+
end
|
355
|
+
|
356
|
+
end
|