mguymon-buildr 1.4.5-java

Sign up to get free protection for your applications and to get access to all the features.
Files changed (220) hide show
  1. data/CHANGELOG +1291 -0
  2. data/LICENSE +176 -0
  3. data/NOTICE +26 -0
  4. data/README.rdoc +134 -0
  5. data/Rakefile +44 -0
  6. data/_buildr +35 -0
  7. data/_jbuildr +35 -0
  8. data/addon/buildr/antlr.rb +65 -0
  9. data/addon/buildr/bnd.rb +147 -0
  10. data/addon/buildr/cobertura.rb +22 -0
  11. data/addon/buildr/drb.rb +281 -0
  12. data/addon/buildr/emma.rb +22 -0
  13. data/addon/buildr/hibernate.rb +149 -0
  14. data/addon/buildr/javacc.rb +85 -0
  15. data/addon/buildr/jaxb_xjc.rb +72 -0
  16. data/addon/buildr/jdepend.rb +60 -0
  17. data/addon/buildr/jetty.rb +248 -0
  18. data/addon/buildr/jibx.rb +86 -0
  19. data/addon/buildr/nailgun.rb +221 -0
  20. data/addon/buildr/openjpa.rb +88 -0
  21. data/addon/buildr/org/apache/buildr/BuildrNail$Main.class +0 -0
  22. data/addon/buildr/org/apache/buildr/BuildrNail.class +0 -0
  23. data/addon/buildr/org/apache/buildr/BuildrNail.java +41 -0
  24. data/addon/buildr/org/apache/buildr/JettyWrapper$1.class +0 -0
  25. data/addon/buildr/org/apache/buildr/JettyWrapper$BuildrHandler.class +0 -0
  26. data/addon/buildr/org/apache/buildr/JettyWrapper.class +0 -0
  27. data/addon/buildr/org/apache/buildr/JettyWrapper.java +144 -0
  28. data/addon/buildr/protobuf.rb +88 -0
  29. data/addon/buildr/xmlbeans.rb +93 -0
  30. data/bin/buildr +19 -0
  31. data/buildr.buildfile +58 -0
  32. data/buildr.gemspec +78 -0
  33. data/doc/_config.yml +1 -0
  34. data/doc/_layouts/default.html +90 -0
  35. data/doc/_layouts/preface.html +22 -0
  36. data/doc/artifacts.textile +217 -0
  37. data/doc/building.textile +276 -0
  38. data/doc/contributing.textile +268 -0
  39. data/doc/css/default.css +236 -0
  40. data/doc/css/print.css +101 -0
  41. data/doc/css/syntax.css +23 -0
  42. data/doc/download.textile +151 -0
  43. data/doc/extending.textile +212 -0
  44. data/doc/images/1442160941-frontcover.jpg +0 -0
  45. data/doc/images/asf-logo.gif +0 -0
  46. data/doc/images/asf-logo.png +0 -0
  47. data/doc/images/buildr-hires.png +0 -0
  48. data/doc/images/buildr.png +0 -0
  49. data/doc/images/favicon.png +0 -0
  50. data/doc/images/growl-icon.tiff +0 -0
  51. data/doc/images/note.png +0 -0
  52. data/doc/images/project-structure.png +0 -0
  53. data/doc/images/tip.png +0 -0
  54. data/doc/images/zbuildr.png +0 -0
  55. data/doc/images/zbuildr.tif +0 -0
  56. data/doc/index.textile +109 -0
  57. data/doc/installing.textile +284 -0
  58. data/doc/languages.textile +599 -0
  59. data/doc/mailing_lists.textile +29 -0
  60. data/doc/more_stuff.textile +845 -0
  61. data/doc/packaging.textile +618 -0
  62. data/doc/preface.textile +54 -0
  63. data/doc/projects.textile +276 -0
  64. data/doc/quick_start.textile +210 -0
  65. data/doc/releasing.textile +117 -0
  66. data/doc/scripts/buildr-git.rb +512 -0
  67. data/doc/scripts/gitflow.rb +296 -0
  68. data/doc/scripts/install-jruby.sh +44 -0
  69. data/doc/scripts/install-linux.sh +73 -0
  70. data/doc/scripts/install-osx.sh +52 -0
  71. data/doc/settings_profiles.textile +287 -0
  72. data/doc/testing.textile +247 -0
  73. data/etc/KEYS +189 -0
  74. data/lib/buildr.rb +44 -0
  75. data/lib/buildr/clojure.rb +34 -0
  76. data/lib/buildr/clojure/shell.rb +52 -0
  77. data/lib/buildr/core.rb +34 -0
  78. data/lib/buildr/core/application.rb +700 -0
  79. data/lib/buildr/core/build.rb +516 -0
  80. data/lib/buildr/core/cc.rb +166 -0
  81. data/lib/buildr/core/checks.rb +253 -0
  82. data/lib/buildr/core/common.rb +151 -0
  83. data/lib/buildr/core/compile.rb +622 -0
  84. data/lib/buildr/core/doc.rb +276 -0
  85. data/lib/buildr/core/environment.rb +129 -0
  86. data/lib/buildr/core/filter.rb +404 -0
  87. data/lib/buildr/core/generate.rb +197 -0
  88. data/lib/buildr/core/help.rb +119 -0
  89. data/lib/buildr/core/jrebel.rb +42 -0
  90. data/lib/buildr/core/linux.rb +30 -0
  91. data/lib/buildr/core/osx.rb +46 -0
  92. data/lib/buildr/core/progressbar.rb +161 -0
  93. data/lib/buildr/core/project.rb +975 -0
  94. data/lib/buildr/core/run.rb +43 -0
  95. data/lib/buildr/core/shell.rb +137 -0
  96. data/lib/buildr/core/test.rb +843 -0
  97. data/lib/buildr/core/transports.rb +575 -0
  98. data/lib/buildr/core/util.rb +537 -0
  99. data/lib/buildr/groovy.rb +20 -0
  100. data/lib/buildr/groovy/bdd.rb +106 -0
  101. data/lib/buildr/groovy/compiler.rb +153 -0
  102. data/lib/buildr/groovy/doc.rb +76 -0
  103. data/lib/buildr/groovy/shell.rb +57 -0
  104. data/lib/buildr/ide.rb +19 -0
  105. data/lib/buildr/ide/eclipse.rb +427 -0
  106. data/lib/buildr/ide/eclipse/java.rb +53 -0
  107. data/lib/buildr/ide/eclipse/plugin.rb +71 -0
  108. data/lib/buildr/ide/eclipse/scala.rb +68 -0
  109. data/lib/buildr/ide/idea.rb +576 -0
  110. data/lib/buildr/java.rb +25 -0
  111. data/lib/buildr/java/ant.rb +94 -0
  112. data/lib/buildr/java/bdd.rb +460 -0
  113. data/lib/buildr/java/cobertura.rb +297 -0
  114. data/lib/buildr/java/commands.rb +223 -0
  115. data/lib/buildr/java/compiler.rb +135 -0
  116. data/lib/buildr/java/deprecated.rb +141 -0
  117. data/lib/buildr/java/doc.rb +86 -0
  118. data/lib/buildr/java/ecj.rb +69 -0
  119. data/lib/buildr/java/emma.rb +244 -0
  120. data/lib/buildr/java/external.rb +73 -0
  121. data/lib/buildr/java/jruby.rb +122 -0
  122. data/lib/buildr/java/jtestr_result.rb +295 -0
  123. data/lib/buildr/java/jtestr_runner.rb.erb +116 -0
  124. data/lib/buildr/java/org/apache/buildr/JavaTestFilter.class +0 -0
  125. data/lib/buildr/java/org/apache/buildr/JavaTestFilter.java +142 -0
  126. data/lib/buildr/java/packaging.rb +734 -0
  127. data/lib/buildr/java/pom.rb +178 -0
  128. data/lib/buildr/java/rjb.rb +154 -0
  129. data/lib/buildr/java/test_result.rb +101 -0
  130. data/lib/buildr/java/tests.rb +362 -0
  131. data/lib/buildr/java/version_requirement.rb +172 -0
  132. data/lib/buildr/packaging.rb +25 -0
  133. data/lib/buildr/packaging/archive.rb +535 -0
  134. data/lib/buildr/packaging/artifact.rb +904 -0
  135. data/lib/buildr/packaging/artifact_namespace.rb +984 -0
  136. data/lib/buildr/packaging/artifact_search.rb +140 -0
  137. data/lib/buildr/packaging/gems.rb +105 -0
  138. data/lib/buildr/packaging/package.rb +249 -0
  139. data/lib/buildr/packaging/repository_array.rb +108 -0
  140. data/lib/buildr/packaging/tar.rb +189 -0
  141. data/lib/buildr/packaging/version_requirement.rb +192 -0
  142. data/lib/buildr/packaging/zip.rb +178 -0
  143. data/lib/buildr/packaging/ziptask.rb +356 -0
  144. data/lib/buildr/resources/buildr.icns +0 -0
  145. data/lib/buildr/resources/completed.png +0 -0
  146. data/lib/buildr/resources/failed.png +0 -0
  147. data/lib/buildr/resources/icons-license.txt +17 -0
  148. data/lib/buildr/run.rb +195 -0
  149. data/lib/buildr/scala.rb +26 -0
  150. data/lib/buildr/scala/bdd.rb +118 -0
  151. data/lib/buildr/scala/compiler.rb +242 -0
  152. data/lib/buildr/scala/doc.rb +142 -0
  153. data/lib/buildr/scala/org/apache/buildr/SpecsSingletonRunner.class +0 -0
  154. data/lib/buildr/scala/org/apache/buildr/SpecsSingletonRunner.java +57 -0
  155. data/lib/buildr/scala/shell.rb +52 -0
  156. data/lib/buildr/scala/tests.rb +171 -0
  157. data/lib/buildr/shell.rb +185 -0
  158. data/lib/buildr/version.rb +18 -0
  159. data/rakelib/all-in-one.rake +113 -0
  160. data/rakelib/checks.rake +57 -0
  161. data/rakelib/doc.rake +137 -0
  162. data/rakelib/metrics.rake +39 -0
  163. data/rakelib/package.rake +73 -0
  164. data/rakelib/release.rake +160 -0
  165. data/rakelib/rspec.rake +91 -0
  166. data/rakelib/setup.rake +66 -0
  167. data/rakelib/stage.rake +220 -0
  168. data/spec/addon/bnd_spec.rb +330 -0
  169. data/spec/addon/drb_spec.rb +328 -0
  170. data/spec/addon/jaxb_xjc_spec.rb +125 -0
  171. data/spec/core/application_spec.rb +631 -0
  172. data/spec/core/build_spec.rb +837 -0
  173. data/spec/core/cc_spec.rb +224 -0
  174. data/spec/core/checks_spec.rb +519 -0
  175. data/spec/core/common_spec.rb +725 -0
  176. data/spec/core/compile_spec.rb +658 -0
  177. data/spec/core/doc_spec.rb +195 -0
  178. data/spec/core/extension_spec.rb +201 -0
  179. data/spec/core/generate_spec.rb +33 -0
  180. data/spec/core/project_spec.rb +772 -0
  181. data/spec/core/run_spec.rb +93 -0
  182. data/spec/core/shell_spec.rb +146 -0
  183. data/spec/core/test_spec.rb +1320 -0
  184. data/spec/core/transport_spec.rb +544 -0
  185. data/spec/core/util_spec.rb +141 -0
  186. data/spec/groovy/bdd_spec.rb +80 -0
  187. data/spec/groovy/compiler_spec.rb +251 -0
  188. data/spec/groovy/doc_spec.rb +65 -0
  189. data/spec/ide/eclipse_spec.rb +739 -0
  190. data/spec/ide/idea_spec.rb +1145 -0
  191. data/spec/java/ant_spec.rb +37 -0
  192. data/spec/java/bdd_spec.rb +374 -0
  193. data/spec/java/cobertura_spec.rb +112 -0
  194. data/spec/java/commands_spec.rb +93 -0
  195. data/spec/java/compiler_spec.rb +252 -0
  196. data/spec/java/doc_spec.rb +56 -0
  197. data/spec/java/ecj_spec.rb +115 -0
  198. data/spec/java/emma_spec.rb +121 -0
  199. data/spec/java/external_spec.rb +56 -0
  200. data/spec/java/java_spec.rb +132 -0
  201. data/spec/java/packaging_spec.rb +1266 -0
  202. data/spec/java/run_spec.rb +78 -0
  203. data/spec/java/test_coverage_helper.rb +257 -0
  204. data/spec/java/tests_spec.rb +497 -0
  205. data/spec/packaging/archive_spec.rb +775 -0
  206. data/spec/packaging/artifact_namespace_spec.rb +743 -0
  207. data/spec/packaging/artifact_spec.rb +1074 -0
  208. data/spec/packaging/packaging_helper.rb +63 -0
  209. data/spec/packaging/packaging_spec.rb +719 -0
  210. data/spec/packaging/repository_array_spec.rb +109 -0
  211. data/spec/sandbox.rb +165 -0
  212. data/spec/scala/bdd_spec.rb +124 -0
  213. data/spec/scala/compiler_spec.rb +289 -0
  214. data/spec/scala/doc_spec.rb +88 -0
  215. data/spec/scala/scala.rb +38 -0
  216. data/spec/scala/tests_spec.rb +283 -0
  217. data/spec/spec_helpers.rb +369 -0
  218. data/spec/version_requirement_spec.rb +143 -0
  219. data/spec/xpath_matchers.rb +121 -0
  220. metadata +600 -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