ittayd-buildr 1.3.4 → 1.3.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (169) hide show
  1. data/CHANGELOG +62 -9
  2. data/NOTICE +1 -1
  3. data/README.rdoc +9 -21
  4. data/Rakefile +20 -39
  5. data/_buildr +1 -0
  6. data/{spec/java/ant.rb → _jbuildr} +11 -15
  7. metadata +30 -210
  8. data/DISCLAIMER +0 -7
  9. data/addon/buildr/antlr.rb +0 -65
  10. data/addon/buildr/cobertura.rb +0 -22
  11. data/addon/buildr/drb.rb +0 -281
  12. data/addon/buildr/emma.rb +0 -22
  13. data/addon/buildr/hibernate.rb +0 -142
  14. data/addon/buildr/javacc.rb +0 -85
  15. data/addon/buildr/jdepend.rb +0 -60
  16. data/addon/buildr/jetty.rb +0 -248
  17. data/addon/buildr/jibx.rb +0 -86
  18. data/addon/buildr/nailgun.rb +0 -221
  19. data/addon/buildr/openjpa.rb +0 -90
  20. data/addon/buildr/org/apache/buildr/BuildrNail$Main.class +0 -0
  21. data/addon/buildr/org/apache/buildr/BuildrNail.class +0 -0
  22. data/addon/buildr/org/apache/buildr/BuildrNail.java +0 -41
  23. data/addon/buildr/org/apache/buildr/JettyWrapper$1.class +0 -0
  24. data/addon/buildr/org/apache/buildr/JettyWrapper$BuildrHandler.class +0 -0
  25. data/addon/buildr/org/apache/buildr/JettyWrapper.class +0 -0
  26. data/addon/buildr/org/apache/buildr/JettyWrapper.java +0 -144
  27. data/addon/buildr/path.rb +0 -136
  28. data/addon/buildr/xmlbeans.rb +0 -93
  29. data/buildr.buildfile +0 -53
  30. data/buildr.gemspec +0 -58
  31. data/doc/css/default.css +0 -228
  32. data/doc/css/print.css +0 -100
  33. data/doc/css/syntax.css +0 -52
  34. data/doc/images/apache-incubator-logo.png +0 -0
  35. data/doc/images/buildr-hires.png +0 -0
  36. data/doc/images/buildr.png +0 -0
  37. data/doc/images/favicon.png +0 -0
  38. data/doc/images/growl-icon.tiff +0 -0
  39. data/doc/images/note.png +0 -0
  40. data/doc/images/project-structure.png +0 -0
  41. data/doc/images/tip.png +0 -0
  42. data/doc/images/zbuildr.tif +0 -0
  43. data/doc/pages/artifacts.textile +0 -207
  44. data/doc/pages/building.textile +0 -240
  45. data/doc/pages/contributing.textile +0 -208
  46. data/doc/pages/download.textile +0 -62
  47. data/doc/pages/extending.textile +0 -175
  48. data/doc/pages/getting_started.textile +0 -273
  49. data/doc/pages/index.textile +0 -42
  50. data/doc/pages/languages.textile +0 -407
  51. data/doc/pages/mailing_lists.textile +0 -17
  52. data/doc/pages/more_stuff.textile +0 -314
  53. data/doc/pages/packaging.textile +0 -427
  54. data/doc/pages/projects.textile +0 -274
  55. data/doc/pages/recipes.textile +0 -103
  56. data/doc/pages/settings_profiles.textile +0 -274
  57. data/doc/pages/testing.textile +0 -212
  58. data/doc/pages/troubleshooting.textile +0 -103
  59. data/doc/pages/whats_new.textile +0 -323
  60. data/doc/print.haml +0 -51
  61. data/doc/print.toc.yaml +0 -29
  62. data/doc/scripts/buildr-git.rb +0 -412
  63. data/doc/scripts/install-jruby.sh +0 -44
  64. data/doc/scripts/install-linux.sh +0 -64
  65. data/doc/scripts/install-osx.sh +0 -52
  66. data/doc/site.haml +0 -56
  67. data/doc/site.toc.yaml +0 -47
  68. data/etc/KEYS +0 -151
  69. data/etc/git-svn-authors +0 -16
  70. data/lib/buildr.rb +0 -33
  71. data/lib/buildr/core.rb +0 -29
  72. data/lib/buildr/core/application.rb +0 -665
  73. data/lib/buildr/core/build.rb +0 -311
  74. data/lib/buildr/core/checks.rb +0 -254
  75. data/lib/buildr/core/common.rb +0 -150
  76. data/lib/buildr/core/compile.rb +0 -590
  77. data/lib/buildr/core/environment.rb +0 -117
  78. data/lib/buildr/core/filter.rb +0 -366
  79. data/lib/buildr/core/generate.rb +0 -195
  80. data/lib/buildr/core/help.rb +0 -119
  81. data/lib/buildr/core/osx.rb +0 -49
  82. data/lib/buildr/core/progressbar.rb +0 -156
  83. data/lib/buildr/core/project.rb +0 -923
  84. data/lib/buildr/core/test.rb +0 -715
  85. data/lib/buildr/core/transports.rb +0 -560
  86. data/lib/buildr/core/util.rb +0 -294
  87. data/lib/buildr/groovy.rb +0 -18
  88. data/lib/buildr/groovy/bdd.rb +0 -106
  89. data/lib/buildr/groovy/compiler.rb +0 -138
  90. data/lib/buildr/ide.rb +0 -19
  91. data/lib/buildr/ide/eclipse.rb +0 -222
  92. data/lib/buildr/ide/idea.ipr.template +0 -300
  93. data/lib/buildr/ide/idea.rb +0 -190
  94. data/lib/buildr/ide/idea7x.ipr.template +0 -290
  95. data/lib/buildr/ide/idea7x.rb +0 -212
  96. data/lib/buildr/java.rb +0 -23
  97. data/lib/buildr/java/ant.rb +0 -92
  98. data/lib/buildr/java/bdd.rb +0 -451
  99. data/lib/buildr/java/cobertura.rb +0 -236
  100. data/lib/buildr/java/commands.rb +0 -211
  101. data/lib/buildr/java/compiler.rb +0 -348
  102. data/lib/buildr/java/deprecated.rb +0 -141
  103. data/lib/buildr/java/emma.rb +0 -238
  104. data/lib/buildr/java/jruby.rb +0 -117
  105. data/lib/buildr/java/jtestr_runner.rb.erb +0 -116
  106. data/lib/buildr/java/org/apache/buildr/JavaTestFilter.class +0 -0
  107. data/lib/buildr/java/org/apache/buildr/JavaTestFilter.java +0 -119
  108. data/lib/buildr/java/packaging.rb +0 -717
  109. data/lib/buildr/java/pom.rb +0 -174
  110. data/lib/buildr/java/rjb.rb +0 -155
  111. data/lib/buildr/java/test_result.rb +0 -307
  112. data/lib/buildr/java/tests.rb +0 -329
  113. data/lib/buildr/java/version_requirement.rb +0 -172
  114. data/lib/buildr/packaging.rb +0 -24
  115. data/lib/buildr/packaging/archive.rb +0 -488
  116. data/lib/buildr/packaging/artifact.rb +0 -759
  117. data/lib/buildr/packaging/artifact_namespace.rb +0 -972
  118. data/lib/buildr/packaging/artifact_search.rb +0 -140
  119. data/lib/buildr/packaging/gems.rb +0 -102
  120. data/lib/buildr/packaging/package.rb +0 -233
  121. data/lib/buildr/packaging/tar.rb +0 -186
  122. data/lib/buildr/packaging/version_requirement.rb +0 -172
  123. data/lib/buildr/packaging/zip.rb +0 -64
  124. data/lib/buildr/packaging/ziptask.rb +0 -313
  125. data/lib/buildr/resources/buildr.icns +0 -0
  126. data/lib/buildr/scala.rb +0 -19
  127. data/lib/buildr/scala/compiler.rb +0 -109
  128. data/lib/buildr/scala/tests.rb +0 -203
  129. data/rakelib/apache.rake +0 -191
  130. data/rakelib/changelog.rake +0 -57
  131. data/rakelib/doc.rake +0 -103
  132. data/rakelib/package.rake +0 -76
  133. data/rakelib/release.rake +0 -65
  134. data/rakelib/rspec.rake +0 -83
  135. data/rakelib/rubyforge.rake +0 -56
  136. data/rakelib/scm.rake +0 -49
  137. data/rakelib/setup.rake +0 -81
  138. data/rakelib/stage.rake +0 -48
  139. data/spec/addon/drb_spec.rb +0 -328
  140. data/spec/core/application_spec.rb +0 -419
  141. data/spec/core/build_spec.rb +0 -423
  142. data/spec/core/checks_spec.rb +0 -519
  143. data/spec/core/common_spec.rb +0 -670
  144. data/spec/core/compile_spec.rb +0 -582
  145. data/spec/core/generate_spec.rb +0 -33
  146. data/spec/core/project_spec.rb +0 -776
  147. data/spec/core/test_spec.rb +0 -1098
  148. data/spec/core/transport_spec.rb +0 -500
  149. data/spec/groovy/bdd_spec.rb +0 -80
  150. data/spec/groovy/compiler_spec.rb +0 -239
  151. data/spec/ide/eclipse_spec.rb +0 -311
  152. data/spec/java/bdd_spec.rb +0 -358
  153. data/spec/java/cobertura_spec.rb +0 -77
  154. data/spec/java/compiler_spec.rb +0 -446
  155. data/spec/java/emma_spec.rb +0 -120
  156. data/spec/java/java_spec.rb +0 -96
  157. data/spec/java/packaging_spec.rb +0 -1120
  158. data/spec/java/test_coverage_spec.rb +0 -255
  159. data/spec/java/tests_spec.rb +0 -471
  160. data/spec/packaging/archive_spec.rb +0 -503
  161. data/spec/packaging/artifact_namespace_spec.rb +0 -646
  162. data/spec/packaging/artifact_spec.rb +0 -795
  163. data/spec/packaging/packaging_helper.rb +0 -63
  164. data/spec/packaging/packaging_spec.rb +0 -589
  165. data/spec/sandbox.rb +0 -139
  166. data/spec/scala/compiler_spec.rb +0 -228
  167. data/spec/scala/tests_spec.rb +0 -215
  168. data/spec/spec_helpers.rb +0 -327
  169. data/spec/version_requirement_spec.rb +0 -123
@@ -1,186 +0,0 @@
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
- gem 'archive-tar-minitar' ; autoload :Archive, 'archive/tar/minitar'
19
-
20
-
21
- module Buildr
22
-
23
- # The TarTask creates a new Tar file. You can include any number of files and and directories,
24
- # use exclusion patterns, and include files into specific directories.
25
- #
26
- # To create a GZipped Tar, either set the gzip option to true, or use the .tgz or .gz suffix.
27
- #
28
- # For example:
29
- # tar("test.tgz").tap do |task|
30
- # task.include "srcs"
31
- # task.include "README", "LICENSE"
32
- # end
33
- #
34
- # See Buildr#tar and ArchiveTask.
35
- class TarTask < ArchiveTask
36
-
37
- # To create a GZipped Tar, either set this option to true, or use the .tgz/.gz suffix.
38
- attr_accessor :gzip
39
- # Permission mode for files contained in the Tar. Defaults to 0755.
40
- attr_accessor :mode
41
-
42
- def initialize(*args, &block) #:nodoc:
43
- super
44
- self.gzip = name =~ /\.[t?]gz$/
45
- self.mode = '0755'
46
- end
47
-
48
- # :call-seq:
49
- # entry(name) => Entry
50
- #
51
- # Returns a Tar file entry. You can use this to check if the entry exists and its contents,
52
- # for example:
53
- # package(:tar).entry("src/LICENSE").should contain(/Apache Software License/)
54
- def entry(entry_name)
55
- Buildr::TarEntry.new(self, entry_name)
56
- end
57
-
58
- def entries() #:nodoc:
59
- tar_entries = nil
60
- with_uncompressed_tar { |tar| tar_entries = tar.entries }
61
- tar_entries
62
- end
63
-
64
- # :call-seq:
65
- # with_uncompressed_tar { |tar_entries| ... }
66
- #
67
- # Yields an Archive::Tar::Minitar::Input object to the provided block.
68
- # Opening, closing and Gzip-decompressing is automatically taken care of.
69
- def with_uncompressed_tar &block
70
- if gzip
71
- Zlib::GzipReader.open(name) { |tar| Archive::Tar::Minitar.open(tar, &block) }
72
- else
73
- Archive::Tar::Minitar.open(name, &block)
74
- end
75
- end
76
-
77
- private
78
-
79
- def create_from(file_map)
80
- if gzip
81
- StringIO.new.tap do |io|
82
- create_tar io, file_map
83
- io.seek 0
84
- Zlib::GzipWriter.open(name) { |gzip| gzip.write io.read }
85
- end
86
- else
87
- File.open(name, 'wb') { |file| create_tar file, file_map }
88
- end
89
- end
90
-
91
- def create_tar(out, file_map)
92
- Archive::Tar::Minitar::Writer.open(out) do |tar|
93
- options = { :mode=>mode || '0755', :mtime=>Time.now }
94
-
95
- file_map.each do |path, content|
96
- if content.respond_to?(:call)
97
- tar.add_file(path, options) { |os, opts| content.call os }
98
- elsif content.nil? || File.directory?(content.to_s)
99
- else
100
- File.open content.to_s, 'rb' do |is|
101
- tar.add_file path, options.merge(:mode=>is.stat.mode, :mtime=>is.stat.mtime, :uid=>is.stat.uid, :gid=>is.stat.gid) do |os, opts|
102
- while data = is.read(4096)
103
- os.write(data)
104
- end
105
- end
106
- end
107
- end
108
- end
109
- end
110
- end
111
-
112
- end
113
-
114
-
115
- class TarEntry #:nodoc:
116
-
117
- def initialize(tar_task, entry_name)
118
- @tar_task = tar_task
119
- @entry_name = entry_name
120
- end
121
-
122
- # :call-seq:
123
- # contain?(*patterns) => boolean
124
- #
125
- # Returns true if this Tar file entry matches against all the arguments. An argument may be
126
- # a string or regular expression.
127
- def contain?(*patterns)
128
- content = read_content_from_tar
129
- patterns.map { |pattern| Regexp === pattern ? pattern : Regexp.new(Regexp.escape(pattern.to_s)) }.
130
- all? { |pattern| content =~ pattern }
131
- end
132
-
133
- # :call-seq:
134
- # empty?() => boolean
135
- #
136
- # Returns true if this entry is empty.
137
- def empty?()
138
- read_content_from_tar.nil?
139
- end
140
-
141
- # :call-seq:
142
- # exist() => boolean
143
- #
144
- # Returns true if this entry exists.
145
- def exist?()
146
- exist = false
147
- @tar_task.with_uncompressed_tar { |tar| exist = tar.any? { |entry| entry.name == @entry_name } }
148
- exist
149
- end
150
-
151
- def to_s #:nodoc:
152
- @entry_name
153
- end
154
-
155
- private
156
-
157
- def read_content_from_tar
158
- content = Errno::ENOENT.new("No such file or directory - #{@entry_name}")
159
- @tar_task.with_uncompressed_tar do |tar|
160
- content = tar.inject(content) { |content, entry| entry.name == @entry_name ? entry.read : content }
161
- end
162
- raise content if Exception === content
163
- content
164
- end
165
- end
166
-
167
- end
168
-
169
-
170
- # :call-seq:
171
- # tar(file) => TarTask
172
- #
173
- # The TarTask creates a new Tar file. You can include any number of files and
174
- # and directories, use exclusion patterns, and include files into specific
175
- # directories.
176
- #
177
- # To create a GZipped Tar, either set the gzip option to true, or use the .tgz or .gz suffix.
178
- #
179
- # For example:
180
- # tar("test.tgz").tap do |tgz|
181
- # tgz.include "srcs"
182
- # tgz.include "README", "LICENSE"
183
- # end
184
- def tar(file)
185
- TarTask.define_task(file)
186
- end
@@ -1,172 +0,0 @@
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
- module Buildr
18
-
19
- #
20
- # See ArtifactNamespace#need
21
- class VersionRequirement
22
-
23
- CMP_PROCS = Gem::Requirement::OPS.dup
24
- CMP_REGEX = Gem::Requirement::OP_RE.dup
25
- CMP_CHARS = CMP_PROCS.keys.join
26
- BOOL_CHARS = '\|\&\!'
27
- VER_CHARS = '\w\.\-'
28
-
29
- class << self
30
- # is +str+ a version string?
31
- def version?(str)
32
- /^\s*[#{VER_CHARS}]+\s*$/ === str
33
- end
34
-
35
- # is +str+ a version requirement?
36
- def requirement?(str)
37
- /[#{BOOL_CHARS}#{CMP_CHARS}\(\)]/ === str
38
- end
39
-
40
- # :call-seq:
41
- # VersionRequirement.create(" >1 <2 !(1.5) ") -> requirement
42
- #
43
- # parse the +str+ requirement
44
- def create(str)
45
- instance_eval normalize(str)
46
- rescue StandardError => e
47
- raise "Failed to parse #{str.inspect} due to: #{e}"
48
- end
49
-
50
- private
51
- def requirement(req)
52
- unless req =~ /^\s*(#{CMP_REGEX})?\s*([#{VER_CHARS}]+)\s*$/
53
- raise "Invalid requirement string: #{req}"
54
- end
55
- comparator, version = $1, $2
56
- version = Gem::Version.new(0).tap { |v| v.version = version }
57
- VersionRequirement.new(nil, [$1, version])
58
- end
59
-
60
- def negate(vreq)
61
- vreq.negative = !vreq.negative
62
- vreq
63
- end
64
-
65
- def normalize(str)
66
- str = str.strip
67
- if str[/[^\s\(\)#{BOOL_CHARS + VER_CHARS + CMP_CHARS}]/]
68
- raise "version string #{str.inspect} contains invalid characters"
69
- end
70
- str.gsub!(/\s+(and|\&\&)\s+/, ' & ')
71
- str.gsub!(/\s+(or|\|\|)\s+/, ' | ')
72
- str.gsub!(/(^|\s*)not\s+/, ' ! ')
73
- pattern = /(#{CMP_REGEX})?\s*[#{VER_CHARS}]+/
74
- left_pattern = /[#{VER_CHARS}\)]$/
75
- right_pattern = /^(#{pattern}|\()/
76
- str = str.split.inject([]) do |ary, i|
77
- ary << '&' if ary.last =~ left_pattern && i =~ right_pattern
78
- ary << i
79
- end
80
- str = str.join(' ')
81
- str.gsub!(/!([^=])?/, ' negate \1')
82
- str.gsub!(pattern) do |expr|
83
- case expr.strip
84
- when 'not', 'negate' then 'negate '
85
- else 'requirement("' + expr + '")'
86
- end
87
- end
88
- str.gsub!(/negate\s+\(/, 'negate(')
89
- str
90
- end
91
- end
92
-
93
- def initialize(op, *requirements) #:nodoc:
94
- @op, @requirements = op, requirements
95
- end
96
-
97
- # Is this object a composed requirement?
98
- # VersionRequirement.create('1').composed? -> false
99
- # VersionRequirement.create('1 | 2').composed? -> true
100
- # VersionRequirement.create('1 & 2').composed? -> true
101
- def composed?
102
- requirements.size > 1
103
- end
104
-
105
- # Return the last requirement on this object having an = operator.
106
- def default
107
- default = nil
108
- requirements.reverse.find do |r|
109
- if Array === r
110
- if !negative && (r.first.nil? || r.first.include?('='))
111
- default = r.last.to_s
112
- end
113
- else
114
- default = r.default
115
- end
116
- end
117
- default
118
- end
119
-
120
- # Test if this requirement can be satisfied by +version+
121
- def satisfied_by?(version)
122
- return false unless version
123
- unless version.kind_of?(Gem::Version)
124
- raise "Invalid version: #{version.inspect}" unless self.class.version?(version)
125
- version = Gem::Version.new(0).tap { |v| v.version = version.strip }
126
- end
127
- message = op == :| ? :any? : :all?
128
- result = requirements.send message do |req|
129
- if Array === req
130
- cmp, rv = *req
131
- CMP_PROCS[cmp || '='].call(version, rv)
132
- else
133
- req.satisfied_by?(version)
134
- end
135
- end
136
- negative ? !result : result
137
- end
138
-
139
- # Either modify the current requirement (if it's already an or operation)
140
- # or create a new requirement
141
- def |(other)
142
- operation(:|, other)
143
- end
144
-
145
- # Either modify the current requirement (if it's already an and operation)
146
- # or create a new requirement
147
- def &(other)
148
- operation(:&, other)
149
- end
150
-
151
- # return the parsed expression
152
- def to_s
153
- str = requirements.map(&:to_s).join(" " + @op.to_s + " ").to_s
154
- str = "( " + str + " )" if negative || requirements.size > 1
155
- str = "!" + str if negative
156
- str
157
- end
158
-
159
- attr_accessor :negative
160
- protected
161
- attr_reader :requirements, :op
162
- def operation(op, other)
163
- @op ||= op
164
- if negative == other.negative && @op == op && other.requirements.size == 1
165
- @requirements << other.requirements.first
166
- self
167
- else
168
- self.class.new(op, self, other)
169
- end
170
- end
171
- end # VersionRequirement
172
- end
@@ -1,64 +0,0 @@
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
- $LOADED_FEATURES.unshift 'ftools' if RUBY_VERSION >= '1.9.0' # Required to properly load RubyZip under Ruby 1.9
18
- require 'zip/zip'
19
- require 'zip/zipfilesystem'
20
-
21
-
22
- module Zip #:nodoc:
23
-
24
- class ZipCentralDirectory #:nodoc:
25
- # Patch to add entries in alphabetical order.
26
- def write_to_stream(io)
27
- offset = io.tell
28
- @entrySet.sort { |a,b| a.name <=> b.name }.each { |entry| entry.write_c_dir_entry(io) }
29
- write_e_o_c_d(io, offset)
30
- end
31
- end
32
-
33
-
34
- class ZipEntry
35
-
36
- # :call-seq:
37
- # exist() => boolean
38
- #
39
- # Returns true if this entry exists.
40
- def exist?()
41
- Zip::ZipFile.open(zipfile) { |zip| zip.file.exist?(@name) }
42
- end
43
-
44
- # :call-seq:
45
- # empty?() => boolean
46
- #
47
- # Returns true if this entry is empty.
48
- def empty?()
49
- Zip::ZipFile.open(zipfile) { |zip| zip.file.read(@name) }.empty?
50
- end
51
-
52
- # :call-seq:
53
- # contain(patterns*) => boolean
54
- #
55
- # Returns true if this ZIP file entry matches against all the arguments. An argument may be
56
- # a string or regular expression.
57
- def contain?(*patterns)
58
- content = Zip::ZipFile.open(zipfile) { |zip| zip.file.read(@name) }
59
- patterns.map { |pattern| Regexp === pattern ? pattern : Regexp.new(Regexp.escape(pattern.to_s)) }.
60
- all? { |pattern| content =~ pattern }
61
- end
62
-
63
- end
64
- end
@@ -1,313 +0,0 @@
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::NO_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
- unless dir == '.' || seen[dir]
63
- mkpath.call File.dirname(dir)
64
- zip.put_next_entry(dir + '/', compression_level)
65
- seen[dir] = true
66
- end
67
- end
68
-
69
- file_map.each do |path, content|
70
- mkpath.call File.dirname(path)
71
- if content.respond_to?(:call)
72
- zip.put_next_entry(path, compression_level)
73
- content.call zip
74
- elsif content.nil? || File.directory?(content.to_s)
75
- mkpath.call path
76
- else
77
- zip.put_next_entry(path, compression_level)
78
- File.open content.to_s, 'rb' do |is|
79
- while data = is.read(4096)
80
- zip << data
81
- end
82
- end
83
- end
84
- end
85
- end
86
- end
87
-
88
- end
89
-
90
-
91
- # :call-seq:
92
- # zip(file) => ZipTask
93
- #
94
- # The ZipTask creates a new Zip file. You can include any number of files and
95
- # and directories, use exclusion patterns, and include files into specific
96
- # directories.
97
- #
98
- # For example:
99
- # zip('test.zip').tap do |task|
100
- # task.include 'srcs'
101
- # task.include 'README', 'LICENSE'
102
- # end
103
- def zip(file)
104
- ZipTask.define_task(file)
105
- end
106
-
107
-
108
- # An object for unzipping a file into a target directory. You can tell it to include
109
- # or exclude only specific files and directories, and also to map files from particular
110
- # paths inside the zip file into the target directory. Once ready, call #extract.
111
- #
112
- # Usually it is more convenient to create a file task for extracting the zip file
113
- # (see #unzip) and pass this object as a prerequisite to other tasks.
114
- #
115
- # See Buildr#unzip.
116
- class Unzip
117
-
118
- # The zip file to extract.
119
- attr_accessor :zip_file
120
- # The target directory to extract to.
121
- attr_accessor :target
122
-
123
- # Initialize with hash argument of the form target=>zip_file.
124
- def initialize(args)
125
- @target, arg_names, @zip_file = Buildr.application.resolve_args([args])
126
- @paths = {}
127
- end
128
-
129
- # :call-seq:
130
- # extract
131
- #
132
- # Extract the zip file into the target directory.
133
- #
134
- # You can call this method directly. However, if you are using the #unzip method,
135
- # it creates a file task for the target directory: use that task instead as a
136
- # prerequisite. For example:
137
- # build unzip(dir=>zip_file)
138
- # Or:
139
- # unzip(dir=>zip_file).target.invoke
140
- def extract
141
- # If no paths specified, then no include/exclude patterns
142
- # specified. Nothing will happen unless we include all files.
143
- if @paths.empty?
144
- @paths[nil] = FromPath.new(self, nil)
145
- end
146
-
147
- # Otherwise, empty unzip creates target as a file when touching.
148
- mkpath target.to_s, :verbose=>false
149
- Zip::ZipFile.open(zip_file.to_s) do |zip|
150
- entries = zip.collect
151
- @paths.each do |path, patterns|
152
- patterns.map(entries).each do |dest, entry|
153
- next if entry.directory?
154
- dest = File.expand_path(dest, target.to_s)
155
- trace "Extracting #{dest}"
156
- mkpath File.dirname(dest), :verbose=>false rescue nil
157
- entry.extract(dest) { true }
158
- end
159
- end
160
- end
161
- # Let other tasks know we updated the target directory.
162
- touch target.to_s, :verbose=>false
163
- end
164
-
165
- # :call-seq:
166
- # include(*files) => self
167
- # include(*files, :path=>name) => self
168
- #
169
- # Include all files that match the patterns and returns self.
170
- #
171
- # Use include if you only want to unzip some of the files, by specifying
172
- # them instead of using exclusion. You can use #include in combination
173
- # with #exclude.
174
- def include(*files)
175
- if Hash === files.last
176
- from_path(files.pop[:path]).include *files
177
- else
178
- from_path(nil).include *files
179
- end
180
- self
181
- end
182
- alias :add :include
183
-
184
- # :call-seq:
185
- # exclude(*files) => self
186
- #
187
- # Exclude all files that match the patterns and return self.
188
- #
189
- # Use exclude to unzip all files except those that match the pattern.
190
- # You can use #exclude in combination with #include.
191
- def exclude(*files)
192
- if Hash === files.last
193
- from_path(files.pop[:path]).exclude *files
194
- else
195
- from_path(nil).exclude *files
196
- end
197
- self
198
- end
199
-
200
- # :call-seq:
201
- # from_path(name) => Path
202
- #
203
- # Allows you to unzip from a path. Returns an object you can use to
204
- # specify which files to include/exclude relative to that path.
205
- # Expands the file relative to that path.
206
- #
207
- # For example:
208
- # unzip(Dir.pwd=>'test.jar').from_path('etc').include('LICENSE')
209
- # will unzip etc/LICENSE into ./LICENSE.
210
- #
211
- # This is different from:
212
- # unzip(Dir.pwd=>'test.jar').include('etc/LICENSE')
213
- # which unzips etc/LICENSE into ./etc/LICENSE.
214
- def from_path(name)
215
- @paths[name] ||= FromPath.new(self, name)
216
- end
217
- alias :path :from_path
218
-
219
- # :call-seq:
220
- # root => Unzip
221
- #
222
- # Returns the root path, essentially the Unzip object itself. In case you are wondering
223
- # down paths and want to go back.
224
- def root
225
- self
226
- end
227
-
228
- # Returns the path to the target directory.
229
- def to_s
230
- target.to_s
231
- end
232
-
233
- class FromPath #:nodoc:
234
-
235
- def initialize(unzip, path)
236
- @unzip = unzip
237
- if path
238
- @path = path[-1] == ?/ ? path : path + '/'
239
- else
240
- @path = ''
241
- end
242
- end
243
-
244
- # See UnzipTask#include
245
- def include(*files) #:doc:
246
- @include ||= []
247
- @include |= files
248
- self
249
- end
250
-
251
- # See UnzipTask#exclude
252
- def exclude(*files) #:doc:
253
- @exclude ||= []
254
- @exclude |= files
255
- self
256
- end
257
-
258
- def map(entries)
259
- includes = @include || ['**/*']
260
- excludes = @exclude || []
261
- entries.inject({}) do |map, entry|
262
- if entry.name =~ /^#{@path}/
263
- short = entry.name.sub(@path, '')
264
- if includes.any? { |pat| File.fnmatch(pat, short, File::FNM_PATHNAME) } &&
265
- !excludes.any? { |pat| File.fnmatch(pat, short, File::FNM_PATHNAME) }
266
- map[short] = entry
267
- end
268
- end
269
- map
270
- end
271
- end
272
-
273
- # Documented in Unzip.
274
- def root
275
- @unzip
276
- end
277
-
278
- # The target directory to extract to.
279
- def target
280
- @unzip.target
281
- end
282
-
283
- end
284
-
285
- end
286
-
287
- # :call-seq:
288
- # unzip(to_dir=>zip_file) => Zip
289
- #
290
- # Creates a task that will unzip a file into the target directory. The task name
291
- # is the target directory, the prerequisite is the file to unzip.
292
- #
293
- # This method creates a file task to expand the zip file. It returns an Unzip object
294
- # that specifies how the file will be extracted. You can include or exclude specific
295
- # files from within the zip, and map to different paths.
296
- #
297
- # The Unzip object's to_s method return the path to the target directory, so you can
298
- # use it as a prerequisite. By keeping the Unzip object separate from the file task,
299
- # you overlay additional work on top of the file task.
300
- #
301
- # For example:
302
- # unzip('all'=>'test.zip')
303
- # unzip('src'=>'test.zip').include('README', 'LICENSE')
304
- # unzip('libs'=>'test.zip').from_path('libs')
305
- def unzip(args)
306
- target, arg_names, zip_file = Buildr.application.resolve_args([args])
307
- task = file(File.expand_path(target.to_s)=>zip_file)
308
- Unzip.new(task=>zip_file).tap do |setup|
309
- task.enhance { setup.extract }
310
- end
311
- end
312
-
313
- end