ittayd-buildr 1.3.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (171) hide show
  1. data/CHANGELOG +915 -0
  2. data/DISCLAIMER +7 -0
  3. data/LICENSE +176 -0
  4. data/NOTICE +26 -0
  5. data/README.rdoc +146 -0
  6. data/Rakefile +64 -0
  7. data/_buildr +28 -0
  8. data/addon/buildr/antlr.rb +65 -0
  9. data/addon/buildr/cobertura.rb +22 -0
  10. data/addon/buildr/drb.rb +281 -0
  11. data/addon/buildr/emma.rb +22 -0
  12. data/addon/buildr/hibernate.rb +142 -0
  13. data/addon/buildr/javacc.rb +85 -0
  14. data/addon/buildr/jdepend.rb +60 -0
  15. data/addon/buildr/jetty.rb +248 -0
  16. data/addon/buildr/jibx.rb +86 -0
  17. data/addon/buildr/nailgun.rb +221 -0
  18. data/addon/buildr/openjpa.rb +90 -0
  19. data/addon/buildr/org/apache/buildr/BuildrNail$Main.class +0 -0
  20. data/addon/buildr/org/apache/buildr/BuildrNail.class +0 -0
  21. data/addon/buildr/org/apache/buildr/BuildrNail.java +41 -0
  22. data/addon/buildr/org/apache/buildr/JettyWrapper$1.class +0 -0
  23. data/addon/buildr/org/apache/buildr/JettyWrapper$BuildrHandler.class +0 -0
  24. data/addon/buildr/org/apache/buildr/JettyWrapper.class +0 -0
  25. data/addon/buildr/org/apache/buildr/JettyWrapper.java +144 -0
  26. data/addon/buildr/path.rb +136 -0
  27. data/addon/buildr/xmlbeans.rb +93 -0
  28. data/bin/buildr +19 -0
  29. data/buildr.buildfile +53 -0
  30. data/buildr.gemspec +58 -0
  31. data/doc/css/default.css +228 -0
  32. data/doc/css/print.css +100 -0
  33. data/doc/css/syntax.css +52 -0
  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 +207 -0
  44. data/doc/pages/building.textile +240 -0
  45. data/doc/pages/contributing.textile +208 -0
  46. data/doc/pages/download.textile +62 -0
  47. data/doc/pages/extending.textile +175 -0
  48. data/doc/pages/getting_started.textile +273 -0
  49. data/doc/pages/index.textile +42 -0
  50. data/doc/pages/languages.textile +407 -0
  51. data/doc/pages/mailing_lists.textile +17 -0
  52. data/doc/pages/more_stuff.textile +314 -0
  53. data/doc/pages/packaging.textile +427 -0
  54. data/doc/pages/projects.textile +274 -0
  55. data/doc/pages/recipes.textile +103 -0
  56. data/doc/pages/settings_profiles.textile +274 -0
  57. data/doc/pages/testing.textile +212 -0
  58. data/doc/pages/troubleshooting.textile +103 -0
  59. data/doc/pages/whats_new.textile +323 -0
  60. data/doc/print.haml +51 -0
  61. data/doc/print.toc.yaml +29 -0
  62. data/doc/scripts/buildr-git.rb +412 -0
  63. data/doc/scripts/install-jruby.sh +44 -0
  64. data/doc/scripts/install-linux.sh +64 -0
  65. data/doc/scripts/install-osx.sh +52 -0
  66. data/doc/site.haml +56 -0
  67. data/doc/site.toc.yaml +47 -0
  68. data/etc/KEYS +151 -0
  69. data/etc/git-svn-authors +16 -0
  70. data/lib/buildr/core/application.rb +665 -0
  71. data/lib/buildr/core/build.rb +311 -0
  72. data/lib/buildr/core/checks.rb +254 -0
  73. data/lib/buildr/core/common.rb +150 -0
  74. data/lib/buildr/core/compile.rb +590 -0
  75. data/lib/buildr/core/environment.rb +117 -0
  76. data/lib/buildr/core/filter.rb +366 -0
  77. data/lib/buildr/core/generate.rb +195 -0
  78. data/lib/buildr/core/help.rb +119 -0
  79. data/lib/buildr/core/osx.rb +49 -0
  80. data/lib/buildr/core/progressbar.rb +156 -0
  81. data/lib/buildr/core/project.rb +923 -0
  82. data/lib/buildr/core/test.rb +715 -0
  83. data/lib/buildr/core/transports.rb +560 -0
  84. data/lib/buildr/core/util.rb +294 -0
  85. data/lib/buildr/core.rb +29 -0
  86. data/lib/buildr/groovy/bdd.rb +106 -0
  87. data/lib/buildr/groovy/compiler.rb +138 -0
  88. data/lib/buildr/groovy.rb +18 -0
  89. data/lib/buildr/ide/eclipse.rb +222 -0
  90. data/lib/buildr/ide/idea.ipr.template +300 -0
  91. data/lib/buildr/ide/idea.rb +190 -0
  92. data/lib/buildr/ide/idea7x.ipr.template +290 -0
  93. data/lib/buildr/ide/idea7x.rb +212 -0
  94. data/lib/buildr/ide.rb +19 -0
  95. data/lib/buildr/java/ant.rb +92 -0
  96. data/lib/buildr/java/bdd.rb +451 -0
  97. data/lib/buildr/java/cobertura.rb +236 -0
  98. data/lib/buildr/java/commands.rb +211 -0
  99. data/lib/buildr/java/compiler.rb +348 -0
  100. data/lib/buildr/java/deprecated.rb +141 -0
  101. data/lib/buildr/java/emma.rb +238 -0
  102. data/lib/buildr/java/jruby.rb +117 -0
  103. data/lib/buildr/java/jtestr_runner.rb.erb +116 -0
  104. data/lib/buildr/java/org/apache/buildr/JavaTestFilter.class +0 -0
  105. data/lib/buildr/java/org/apache/buildr/JavaTestFilter.java +119 -0
  106. data/lib/buildr/java/packaging.rb +717 -0
  107. data/lib/buildr/java/pom.rb +174 -0
  108. data/lib/buildr/java/rjb.rb +155 -0
  109. data/lib/buildr/java/test_result.rb +307 -0
  110. data/lib/buildr/java/tests.rb +329 -0
  111. data/lib/buildr/java/version_requirement.rb +172 -0
  112. data/lib/buildr/java.rb +23 -0
  113. data/lib/buildr/packaging/archive.rb +488 -0
  114. data/lib/buildr/packaging/artifact.rb +759 -0
  115. data/lib/buildr/packaging/artifact_namespace.rb +972 -0
  116. data/lib/buildr/packaging/artifact_search.rb +140 -0
  117. data/lib/buildr/packaging/gems.rb +102 -0
  118. data/lib/buildr/packaging/package.rb +233 -0
  119. data/lib/buildr/packaging/tar.rb +186 -0
  120. data/lib/buildr/packaging/version_requirement.rb +172 -0
  121. data/lib/buildr/packaging/zip.rb +64 -0
  122. data/lib/buildr/packaging/ziptask.rb +313 -0
  123. data/lib/buildr/packaging.rb +24 -0
  124. data/lib/buildr/resources/buildr.icns +0 -0
  125. data/lib/buildr/scala/compiler.rb +109 -0
  126. data/lib/buildr/scala/tests.rb +203 -0
  127. data/lib/buildr/scala.rb +19 -0
  128. data/lib/buildr.rb +33 -0
  129. data/rakelib/apache.rake +191 -0
  130. data/rakelib/changelog.rake +57 -0
  131. data/rakelib/doc.rake +103 -0
  132. data/rakelib/package.rake +76 -0
  133. data/rakelib/release.rake +65 -0
  134. data/rakelib/rspec.rake +83 -0
  135. data/rakelib/rubyforge.rake +56 -0
  136. data/rakelib/scm.rake +49 -0
  137. data/rakelib/setup.rake +81 -0
  138. data/rakelib/stage.rake +48 -0
  139. data/spec/addon/drb_spec.rb +328 -0
  140. data/spec/core/application_spec.rb +419 -0
  141. data/spec/core/build_spec.rb +423 -0
  142. data/spec/core/checks_spec.rb +519 -0
  143. data/spec/core/common_spec.rb +670 -0
  144. data/spec/core/compile_spec.rb +582 -0
  145. data/spec/core/generate_spec.rb +33 -0
  146. data/spec/core/project_spec.rb +776 -0
  147. data/spec/core/test_spec.rb +1098 -0
  148. data/spec/core/transport_spec.rb +500 -0
  149. data/spec/groovy/bdd_spec.rb +80 -0
  150. data/spec/groovy/compiler_spec.rb +239 -0
  151. data/spec/ide/eclipse_spec.rb +311 -0
  152. data/spec/java/ant.rb +33 -0
  153. data/spec/java/bdd_spec.rb +358 -0
  154. data/spec/java/cobertura_spec.rb +77 -0
  155. data/spec/java/compiler_spec.rb +446 -0
  156. data/spec/java/emma_spec.rb +120 -0
  157. data/spec/java/java_spec.rb +96 -0
  158. data/spec/java/packaging_spec.rb +1120 -0
  159. data/spec/java/test_coverage_spec.rb +255 -0
  160. data/spec/java/tests_spec.rb +471 -0
  161. data/spec/packaging/archive_spec.rb +503 -0
  162. data/spec/packaging/artifact_namespace_spec.rb +646 -0
  163. data/spec/packaging/artifact_spec.rb +795 -0
  164. data/spec/packaging/packaging_helper.rb +63 -0
  165. data/spec/packaging/packaging_spec.rb +589 -0
  166. data/spec/sandbox.rb +139 -0
  167. data/spec/scala/compiler_spec.rb +228 -0
  168. data/spec/scala/tests_spec.rb +215 -0
  169. data/spec/spec_helpers.rb +327 -0
  170. data/spec/version_requirement_spec.rb +123 -0
  171. metadata +377 -0
@@ -0,0 +1,172 @@
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
@@ -0,0 +1,64 @@
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
@@ -0,0 +1,313 @@
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
@@ -0,0 +1,24 @@
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/artifact'
18
+ require 'buildr/packaging/package'
19
+ require 'buildr/packaging/archive'
20
+ require 'buildr/packaging/ziptask'
21
+ require 'buildr/packaging/tar'
22
+ require 'buildr/packaging/gems'
23
+ autoload :Zlib, 'zlib'
24
+ autoload :Zip, 'buildr/packaging/zip'
Binary file
@@ -0,0 +1,109 @@
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
+ require 'buildr/core/project'
17
+ require 'buildr/core/common'
18
+ require 'buildr/core/compile'
19
+ require 'buildr/packaging'
20
+
21
+
22
+ module Buildr::Scala
23
+
24
+ # Scalac compiler:
25
+ # compile.using(:scalac)
26
+ # Used by default if .scala files are found in the src/main/scala directory (or src/test/scala)
27
+ # and sets the target directory to target/classes (or target/test/classes).
28
+ #
29
+ # Accepts the following options:
30
+ # * :warnings -- Generate warnings if true (opposite of -nowarn).
31
+ # * :deprecation -- Output source locations where deprecated APIs are used.
32
+ # * :optimise -- Generates faster bytecode by applying optimisations to the program.
33
+ # * :target -- Class file compatibility with specified release.
34
+ # * :debug -- Generate debugging info.
35
+ # * :other -- Array of options to pass to the Scalac compiler as is, e.g. -Xprint-types
36
+ class Scalac < Buildr::Compiler::Base
37
+ class << self
38
+ def scala_home
39
+ @home ||= ENV['SCALA_HOME']
40
+ end
41
+
42
+ def dependencies
43
+ [ 'scala-library.jar', 'scala-compiler.jar'].map { |jar| File.expand_path("lib/#{jar}", scala_home) }
44
+ end
45
+
46
+ def use_fsc
47
+ ENV["USE_FSC"] =~ /^(yes|on|true)$/i
48
+ end
49
+ end
50
+
51
+ OPTIONS = [:warnings, :deprecation, :optimise, :target, :debug, :other]
52
+ Java.classpath << dependencies
53
+
54
+ specify :language=>:scala, :target=>'classes', :target_ext=>'class', :packaging=>:jar
55
+
56
+ def initialize(project, options) #:nodoc:
57
+ super
58
+ options[:debug] = Buildr.options.debug if options[:debug].nil?
59
+ options[:warnings] = verbose if options[:warnings].nil?
60
+ options[:deprecation] ||= false
61
+ options[:optimise] ||= false
62
+ end
63
+
64
+ def compile(sources, target, dependencies) #:nodoc:
65
+ check_options options, OPTIONS
66
+
67
+ cmd_args = []
68
+ cmd_args << '-classpath' << (dependencies + Scalac.dependencies).join(File::PATH_SEPARATOR)
69
+ source_paths = sources.select { |source| File.directory?(source) }
70
+ cmd_args << '-sourcepath' << source_paths.join(File::PATH_SEPARATOR) unless source_paths.empty?
71
+ cmd_args << '-d' << File.expand_path(target)
72
+ cmd_args += scalac_args
73
+ cmd_args += files_from_sources(sources)
74
+
75
+ unless Buildr.application.options.dryrun
76
+ Scalac.scala_home or fail 'Are we forgetting something? SCALA_HOME not set.'
77
+ trace((['scalac'] + cmd_args).join(' '))
78
+ if Scalac.use_fsc
79
+ system(([File.expand_path('bin/fsc', Scalac.scala_home)] + cmd_args).join(' ')) or
80
+ fail 'Failed to compile, see errors above'
81
+ else
82
+ Java.load
83
+ Java.scala.tools.nsc.Main.process(cmd_args.to_java(Java.java.lang.String))
84
+ fail 'Failed to compile, see errors above' if Java.scala.tools.nsc.Main.reporter.hasErrors
85
+ end
86
+ end
87
+ end
88
+
89
+ private
90
+
91
+ # Returns Scalac command line arguments from the set of options.
92
+ def scalac_args #:nodoc:
93
+ args = []
94
+ args << "-nowarn" unless options[:warnings]
95
+ args << "-verbose" if Buildr.application.options.trace
96
+ args << "-g" if options[:debug]
97
+ args << "-deprecation" if options[:deprecation]
98
+ args << "-optimise" if options[:optimise]
99
+ args << "-target:jvm-" + options[:target].to_s if options[:target]
100
+ args + Array(options[:other])
101
+ end
102
+
103
+ end
104
+
105
+ end
106
+
107
+ # Scala compiler comes first, ahead of Javac, this allows it to pick
108
+ # projects that mix Scala and Java code by spotting Scala code first.
109
+ Buildr::Compiler.compilers << Buildr::Scala::Scalac