ittayd-buildr 1.3.4
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +915 -0
- data/DISCLAIMER +7 -0
- data/LICENSE +176 -0
- data/NOTICE +26 -0
- data/README.rdoc +146 -0
- data/Rakefile +64 -0
- data/_buildr +28 -0
- data/addon/buildr/antlr.rb +65 -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 +142 -0
- data/addon/buildr/javacc.rb +85 -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 +90 -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/path.rb +136 -0
- data/addon/buildr/xmlbeans.rb +93 -0
- data/bin/buildr +19 -0
- data/buildr.buildfile +53 -0
- data/buildr.gemspec +58 -0
- data/doc/css/default.css +228 -0
- data/doc/css/print.css +100 -0
- data/doc/css/syntax.css +52 -0
- data/doc/images/apache-incubator-logo.png +0 -0
- data/doc/images/buildr-hires.png +0 -0
- data/doc/images/buildr.png +0 -0
- data/doc/images/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.tif +0 -0
- data/doc/pages/artifacts.textile +207 -0
- data/doc/pages/building.textile +240 -0
- data/doc/pages/contributing.textile +208 -0
- data/doc/pages/download.textile +62 -0
- data/doc/pages/extending.textile +175 -0
- data/doc/pages/getting_started.textile +273 -0
- data/doc/pages/index.textile +42 -0
- data/doc/pages/languages.textile +407 -0
- data/doc/pages/mailing_lists.textile +17 -0
- data/doc/pages/more_stuff.textile +314 -0
- data/doc/pages/packaging.textile +427 -0
- data/doc/pages/projects.textile +274 -0
- data/doc/pages/recipes.textile +103 -0
- data/doc/pages/settings_profiles.textile +274 -0
- data/doc/pages/testing.textile +212 -0
- data/doc/pages/troubleshooting.textile +103 -0
- data/doc/pages/whats_new.textile +323 -0
- data/doc/print.haml +51 -0
- data/doc/print.toc.yaml +29 -0
- data/doc/scripts/buildr-git.rb +412 -0
- data/doc/scripts/install-jruby.sh +44 -0
- data/doc/scripts/install-linux.sh +64 -0
- data/doc/scripts/install-osx.sh +52 -0
- data/doc/site.haml +56 -0
- data/doc/site.toc.yaml +47 -0
- data/etc/KEYS +151 -0
- data/etc/git-svn-authors +16 -0
- data/lib/buildr/core/application.rb +665 -0
- data/lib/buildr/core/build.rb +311 -0
- data/lib/buildr/core/checks.rb +254 -0
- data/lib/buildr/core/common.rb +150 -0
- data/lib/buildr/core/compile.rb +590 -0
- data/lib/buildr/core/environment.rb +117 -0
- data/lib/buildr/core/filter.rb +366 -0
- data/lib/buildr/core/generate.rb +195 -0
- data/lib/buildr/core/help.rb +119 -0
- data/lib/buildr/core/osx.rb +49 -0
- data/lib/buildr/core/progressbar.rb +156 -0
- data/lib/buildr/core/project.rb +923 -0
- data/lib/buildr/core/test.rb +715 -0
- data/lib/buildr/core/transports.rb +560 -0
- data/lib/buildr/core/util.rb +294 -0
- data/lib/buildr/core.rb +29 -0
- data/lib/buildr/groovy/bdd.rb +106 -0
- data/lib/buildr/groovy/compiler.rb +138 -0
- data/lib/buildr/groovy.rb +18 -0
- data/lib/buildr/ide/eclipse.rb +222 -0
- data/lib/buildr/ide/idea.ipr.template +300 -0
- data/lib/buildr/ide/idea.rb +190 -0
- data/lib/buildr/ide/idea7x.ipr.template +290 -0
- data/lib/buildr/ide/idea7x.rb +212 -0
- data/lib/buildr/ide.rb +19 -0
- data/lib/buildr/java/ant.rb +92 -0
- data/lib/buildr/java/bdd.rb +451 -0
- data/lib/buildr/java/cobertura.rb +236 -0
- data/lib/buildr/java/commands.rb +211 -0
- data/lib/buildr/java/compiler.rb +348 -0
- data/lib/buildr/java/deprecated.rb +141 -0
- data/lib/buildr/java/emma.rb +238 -0
- data/lib/buildr/java/jruby.rb +117 -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 +119 -0
- data/lib/buildr/java/packaging.rb +717 -0
- data/lib/buildr/java/pom.rb +174 -0
- data/lib/buildr/java/rjb.rb +155 -0
- data/lib/buildr/java/test_result.rb +307 -0
- data/lib/buildr/java/tests.rb +329 -0
- data/lib/buildr/java/version_requirement.rb +172 -0
- data/lib/buildr/java.rb +23 -0
- data/lib/buildr/packaging/archive.rb +488 -0
- data/lib/buildr/packaging/artifact.rb +759 -0
- data/lib/buildr/packaging/artifact_namespace.rb +972 -0
- data/lib/buildr/packaging/artifact_search.rb +140 -0
- data/lib/buildr/packaging/gems.rb +102 -0
- data/lib/buildr/packaging/package.rb +233 -0
- data/lib/buildr/packaging/tar.rb +186 -0
- data/lib/buildr/packaging/version_requirement.rb +172 -0
- data/lib/buildr/packaging/zip.rb +64 -0
- data/lib/buildr/packaging/ziptask.rb +313 -0
- data/lib/buildr/packaging.rb +24 -0
- data/lib/buildr/resources/buildr.icns +0 -0
- data/lib/buildr/scala/compiler.rb +109 -0
- data/lib/buildr/scala/tests.rb +203 -0
- data/lib/buildr/scala.rb +19 -0
- data/lib/buildr.rb +33 -0
- data/rakelib/apache.rake +191 -0
- data/rakelib/changelog.rake +57 -0
- data/rakelib/doc.rake +103 -0
- data/rakelib/package.rake +76 -0
- data/rakelib/release.rake +65 -0
- data/rakelib/rspec.rake +83 -0
- data/rakelib/rubyforge.rake +56 -0
- data/rakelib/scm.rake +49 -0
- data/rakelib/setup.rake +81 -0
- data/rakelib/stage.rake +48 -0
- data/spec/addon/drb_spec.rb +328 -0
- data/spec/core/application_spec.rb +419 -0
- data/spec/core/build_spec.rb +423 -0
- data/spec/core/checks_spec.rb +519 -0
- data/spec/core/common_spec.rb +670 -0
- data/spec/core/compile_spec.rb +582 -0
- data/spec/core/generate_spec.rb +33 -0
- data/spec/core/project_spec.rb +776 -0
- data/spec/core/test_spec.rb +1098 -0
- data/spec/core/transport_spec.rb +500 -0
- data/spec/groovy/bdd_spec.rb +80 -0
- data/spec/groovy/compiler_spec.rb +239 -0
- data/spec/ide/eclipse_spec.rb +311 -0
- data/spec/java/ant.rb +33 -0
- data/spec/java/bdd_spec.rb +358 -0
- data/spec/java/cobertura_spec.rb +77 -0
- data/spec/java/compiler_spec.rb +446 -0
- data/spec/java/emma_spec.rb +120 -0
- data/spec/java/java_spec.rb +96 -0
- data/spec/java/packaging_spec.rb +1120 -0
- data/spec/java/test_coverage_spec.rb +255 -0
- data/spec/java/tests_spec.rb +471 -0
- data/spec/packaging/archive_spec.rb +503 -0
- data/spec/packaging/artifact_namespace_spec.rb +646 -0
- data/spec/packaging/artifact_spec.rb +795 -0
- data/spec/packaging/packaging_helper.rb +63 -0
- data/spec/packaging/packaging_spec.rb +589 -0
- data/spec/sandbox.rb +139 -0
- data/spec/scala/compiler_spec.rb +228 -0
- data/spec/scala/tests_spec.rb +215 -0
- data/spec/spec_helpers.rb +327 -0
- data/spec/version_requirement_spec.rb +123 -0
- metadata +377 -0
@@ -0,0 +1,366 @@
|
|
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 'erb'
|
18
|
+
|
19
|
+
|
20
|
+
module Buildr
|
21
|
+
|
22
|
+
# A filter knows how to copy files from one directory to another, applying mappings to the
|
23
|
+
# contents of these files.
|
24
|
+
#
|
25
|
+
# You can specify the mapping using a Hash, and it will map ${key} fields found in each source
|
26
|
+
# file into the appropriate value in the target file. For example:
|
27
|
+
#
|
28
|
+
# filter.using 'version'=>'1.2', 'build'=>Time.now
|
29
|
+
#
|
30
|
+
# will replace all occurrences of <tt>${version}</tt> with <tt>1.2</tt>, and <tt>${build}</tt>
|
31
|
+
# with the current date/time.
|
32
|
+
#
|
33
|
+
# You can also specify the mapping by passing a proc or a method, that will be called for
|
34
|
+
# each source file, with the file name and content, returning the modified content.
|
35
|
+
#
|
36
|
+
# Without any mapping, the filter simply copies files from the source directory into the target
|
37
|
+
# directory.
|
38
|
+
#
|
39
|
+
# A filter has one target directory, but you can specify any number of source directories,
|
40
|
+
# either when creating the filter or calling #from. Include/exclude patterns are specified
|
41
|
+
# relative to the source directories, so:
|
42
|
+
# filter.include '*.png'
|
43
|
+
# will only include PNG files from any of the source directories.
|
44
|
+
#
|
45
|
+
# See Buildr#filter.
|
46
|
+
class Filter
|
47
|
+
|
48
|
+
def initialize #:nodoc:
|
49
|
+
clear
|
50
|
+
end
|
51
|
+
|
52
|
+
# Returns the list of source directories (each being a file task).
|
53
|
+
attr_reader :sources
|
54
|
+
|
55
|
+
# :call-seq:
|
56
|
+
# clear => self
|
57
|
+
#
|
58
|
+
# Clear filter sources and include/exclude patterns
|
59
|
+
def clear
|
60
|
+
@include = []
|
61
|
+
@exclude = []
|
62
|
+
@sources = FileList[]
|
63
|
+
@mapper = Mapper.new
|
64
|
+
self
|
65
|
+
end
|
66
|
+
|
67
|
+
# :call-seq:
|
68
|
+
# from(*sources) => self
|
69
|
+
#
|
70
|
+
# Adds additional directories from which to copy resources.
|
71
|
+
#
|
72
|
+
# For example:
|
73
|
+
# filter.from('src').into('target').using('build'=>Time.now)
|
74
|
+
def from(*sources)
|
75
|
+
@sources |= sources.flatten.map { |dir| file(File.expand_path(dir.to_s)) }
|
76
|
+
self
|
77
|
+
end
|
78
|
+
|
79
|
+
# The target directory as a file task.
|
80
|
+
attr_reader :target
|
81
|
+
|
82
|
+
# :call-seq:
|
83
|
+
# into(dir) => self
|
84
|
+
#
|
85
|
+
# Sets the target directory into which files are copied and returns self.
|
86
|
+
#
|
87
|
+
# For example:
|
88
|
+
# filter.from('src').into('target').using('build'=>Time.now)
|
89
|
+
def into(dir)
|
90
|
+
@target = file(File.expand_path(dir.to_s)) { |task| run if target == task }
|
91
|
+
self
|
92
|
+
end
|
93
|
+
|
94
|
+
# :call-seq:
|
95
|
+
# include(*files) => self
|
96
|
+
#
|
97
|
+
# Specifies files to include and returns self. See FileList#include.
|
98
|
+
#
|
99
|
+
# By default all files are included. You can use this method to only include specific
|
100
|
+
# files from the source directory.
|
101
|
+
def include(*files)
|
102
|
+
@include += files
|
103
|
+
self
|
104
|
+
end
|
105
|
+
alias :add :include
|
106
|
+
|
107
|
+
# :call-seq:
|
108
|
+
# exclude(*files) => self
|
109
|
+
#
|
110
|
+
# Specifies files to exclude and returns self. See FileList#exclude.
|
111
|
+
def exclude(*files)
|
112
|
+
@exclude += files
|
113
|
+
self
|
114
|
+
end
|
115
|
+
|
116
|
+
# The mapping. See #using.
|
117
|
+
def mapping #:nodoc:
|
118
|
+
@mapper.config
|
119
|
+
end
|
120
|
+
|
121
|
+
# The mapper to use. See #using.
|
122
|
+
def mapper #:nodoc:
|
123
|
+
@mapper.mapper_type
|
124
|
+
end
|
125
|
+
|
126
|
+
# :call-seq:
|
127
|
+
# using(mapping) => self
|
128
|
+
# using { |file_name, contents| ... } => self
|
129
|
+
#
|
130
|
+
# Specifies the mapping to use and returns self.
|
131
|
+
#
|
132
|
+
# The most typical mapping uses a Hash, and the default mapping uses the Maven style, so
|
133
|
+
# <code>${key}</code> are mapped to the values. You can change that by passing a different
|
134
|
+
# format as the first argument. Currently supports:
|
135
|
+
# * :ant -- Map <code>@key@</code>.
|
136
|
+
# * :maven -- Map <code>${key}</code> (default).
|
137
|
+
# * :ruby -- Map <code>#{key}</code>.
|
138
|
+
# * :erb -- Map <code><%= key %></code>.
|
139
|
+
# * Regexp -- Maps the matched data (e.g. <code>/=(.*?)=/</code>
|
140
|
+
#
|
141
|
+
# For example:
|
142
|
+
# filter.using 'version'=>'1.2'
|
143
|
+
# Is the same as:
|
144
|
+
# filter.using :maven, 'version'=>'1.2'
|
145
|
+
#
|
146
|
+
# You can also pass a proc or method. It will be called with the file name and content,
|
147
|
+
# to return the mapped content.
|
148
|
+
#
|
149
|
+
# Without any mapping, all files are copied as is.
|
150
|
+
#
|
151
|
+
# To register new mapping type see the Mapper class.
|
152
|
+
def using(*args, &block)
|
153
|
+
@mapper.using(*args, &block)
|
154
|
+
self
|
155
|
+
end
|
156
|
+
|
157
|
+
# :call-seq:
|
158
|
+
# run => boolean
|
159
|
+
#
|
160
|
+
# Runs the filter.
|
161
|
+
def run
|
162
|
+
sources.each { |source| raise "Source directory #{source} doesn't exist" unless File.exist?(source.to_s) }
|
163
|
+
raise 'No target directory specified, where am I going to copy the files to?' if target.nil?
|
164
|
+
|
165
|
+
copy_map = sources.flatten.map(&:to_s).inject({}) do |map, source|
|
166
|
+
files = Util.recursive_with_dot_files(source).
|
167
|
+
map { |file| Util.relative_path(file, source) }.
|
168
|
+
select { |file| @include.empty? || @include.any? { |pattern| File.fnmatch(pattern, file, File::FNM_PATHNAME) } }.
|
169
|
+
reject { |file| @exclude.any? { |pattern| File.fnmatch(pattern, file, File::FNM_PATHNAME) } }
|
170
|
+
files.each do |file|
|
171
|
+
src, dest = File.expand_path(file, source), File.expand_path(file, target.to_s)
|
172
|
+
map[file] = src if !File.exist?(dest) || File.stat(src).mtime >= File.stat(dest).mtime
|
173
|
+
end
|
174
|
+
map
|
175
|
+
end
|
176
|
+
|
177
|
+
mkpath target.to_s, :verbose=>Buildr.application.options.trace
|
178
|
+
return false if copy_map.empty?
|
179
|
+
|
180
|
+
verbose(Buildr.application.options.trace || false) do
|
181
|
+
copy_map.each do |path, source|
|
182
|
+
dest = File.expand_path(path, target.to_s)
|
183
|
+
if File.directory?(source)
|
184
|
+
mkpath dest, :verbose=>false
|
185
|
+
else
|
186
|
+
mkpath File.dirname(dest)
|
187
|
+
if @mapper.mapper_type
|
188
|
+
mapped = @mapper.transform(File.open(source, 'rb') { |file| file.read }, path)
|
189
|
+
File.open(dest, 'wb') { |file| file.write mapped }
|
190
|
+
else # no mapping
|
191
|
+
cp source, dest
|
192
|
+
File.chmod(0664, dest)
|
193
|
+
end
|
194
|
+
end
|
195
|
+
end
|
196
|
+
touch target.to_s
|
197
|
+
end
|
198
|
+
true
|
199
|
+
end
|
200
|
+
|
201
|
+
# Returns the target directory.
|
202
|
+
def to_s
|
203
|
+
@target.to_s
|
204
|
+
end
|
205
|
+
|
206
|
+
# This class implements content replacement logic for Filter.
|
207
|
+
#
|
208
|
+
# To register a new template engine @:foo@, extend this class with a method like:
|
209
|
+
#
|
210
|
+
# def foo_transform(content, path = nil)
|
211
|
+
# # if this method yields a key, the value comes from the mapping hash
|
212
|
+
# content.gsub(/world/) { |str| yield :bar }
|
213
|
+
# end
|
214
|
+
#
|
215
|
+
# Then you can use :foo mapping type on a Filter
|
216
|
+
#
|
217
|
+
# filter.using :foo, :bar => :baz
|
218
|
+
#
|
219
|
+
# Or all by your own, simply
|
220
|
+
#
|
221
|
+
# Mapper.new(:foo, :bar => :baz).transform("Hello world") # => "Hello baz"
|
222
|
+
#
|
223
|
+
# You can handle configuration arguments by providing a @*_config@ method like:
|
224
|
+
#
|
225
|
+
# # The return value of this method is available with the :config accessor.
|
226
|
+
# def moo_config(*args, &block)
|
227
|
+
# raise ArgumentError, "Expected moo block" unless block_given?
|
228
|
+
# { :moos => args, :callback => block }
|
229
|
+
# end
|
230
|
+
#
|
231
|
+
# def moo_transform(content, path = nil)
|
232
|
+
# content.gsub(/moo+/i) do |str|
|
233
|
+
# moos = yield :moos # same than config[:moos]
|
234
|
+
# moo = moos[str.size - 3] || str
|
235
|
+
# config[:callback].call(moo)
|
236
|
+
# end
|
237
|
+
# end
|
238
|
+
#
|
239
|
+
# Usage for the @:moo@ mapper would be something like:
|
240
|
+
#
|
241
|
+
# mapper = Mapper.new(:moo, 'ooone', 'twoo') do |str|
|
242
|
+
# i = nil; str.capitalize.gsub(/\w/) { |s| s.send( (i = !i) ? 'upcase' : 'downcase' ) }
|
243
|
+
# end
|
244
|
+
# mapper.transform('Moo cow, mooo cows singing mooooo') # => 'OoOnE cow, TwOo cows singing MoOoOo'
|
245
|
+
class Mapper
|
246
|
+
|
247
|
+
attr_reader :mapper_type, :config
|
248
|
+
|
249
|
+
def initialize(*args, &block) #:nodoc:
|
250
|
+
using(*args, &block)
|
251
|
+
end
|
252
|
+
|
253
|
+
def using(*args, &block)
|
254
|
+
case args.first
|
255
|
+
when Hash # Maven hash mapping
|
256
|
+
using :maven, *args
|
257
|
+
when Binding # Erb binding
|
258
|
+
using :erb, *args
|
259
|
+
when Symbol # Mapping from a method
|
260
|
+
raise ArgumentError, "Unknown mapping type: #{args.first}" unless respond_to?("#{args.first}_transform", true)
|
261
|
+
configure(*args, &block)
|
262
|
+
when Regexp # Mapping using a regular expression
|
263
|
+
raise ArgumentError, 'Expected regular expression followed by mapping hash' unless args.size == 2 && Hash === args[1]
|
264
|
+
@mapper_type, @config = *args
|
265
|
+
else
|
266
|
+
unless args.empty? && block.nil?
|
267
|
+
raise ArgumentError, 'Expected proc, method or a block' if args.size > 1 || (args.first && block)
|
268
|
+
@mapper_type = :callback
|
269
|
+
config = args.first || block
|
270
|
+
raise ArgumentError, 'Expected proc, method or callable' unless config.respond_to?(:call)
|
271
|
+
@config = config
|
272
|
+
end
|
273
|
+
end
|
274
|
+
self
|
275
|
+
end
|
276
|
+
|
277
|
+
def transform(content, path = nil)
|
278
|
+
type = Regexp === mapper_type ? :regexp : mapper_type
|
279
|
+
raise ArgumentError, "Invalid mapper type: #{type.inspect}" unless respond_to?("#{type}_transform", true)
|
280
|
+
self.__send__("#{type}_transform", content, path) { |key| config[key] || config[key.to_s.to_sym] }
|
281
|
+
end
|
282
|
+
|
283
|
+
private
|
284
|
+
def configure(mapper_type, *args, &block)
|
285
|
+
configurer = method("#{mapper_type}_config") rescue nil
|
286
|
+
if configurer
|
287
|
+
@config = configurer.call(*args, &block)
|
288
|
+
else
|
289
|
+
raise ArgumentError, "Missing hash argument after :#{mapper_type}" unless args.size == 1 && Hash === args[0]
|
290
|
+
@config = *args
|
291
|
+
end
|
292
|
+
@mapper_type = mapper_type
|
293
|
+
end
|
294
|
+
|
295
|
+
def maven_transform(content, path = nil)
|
296
|
+
content.gsub(/\$\{.*?\}/) { |str| yield(str[2..-2]) || str }
|
297
|
+
end
|
298
|
+
|
299
|
+
def ant_transform(content, path = nil)
|
300
|
+
content.gsub(/@.*?@/) { |str| yield(str[1..-2]) || str }
|
301
|
+
end
|
302
|
+
|
303
|
+
def ruby_transform(content, path = nil)
|
304
|
+
content.gsub(/#\{.*?\}/) { |str| yield(str[2..-2]) || str }
|
305
|
+
end
|
306
|
+
|
307
|
+
def regexp_transform(content, path = nil)
|
308
|
+
content.gsub(mapper_type) { |str| yield(str.scan(mapper_type).join) || str }
|
309
|
+
end
|
310
|
+
|
311
|
+
def callback_transform(content, path = nil)
|
312
|
+
config.call(path, content)
|
313
|
+
end
|
314
|
+
|
315
|
+
def erb_transform(content, path = nil)
|
316
|
+
case config
|
317
|
+
when Binding, Proc
|
318
|
+
bnd = config
|
319
|
+
when Method
|
320
|
+
bnd = config.to_proc
|
321
|
+
when Hash
|
322
|
+
bnd = OpenStruct.new
|
323
|
+
table = config.inject({}) { |h, e| h[e.first.to_sym] = e.last; h }
|
324
|
+
bnd.instance_variable_set(:@table, table)
|
325
|
+
bnd = bnd.instance_eval { binding }
|
326
|
+
else
|
327
|
+
bnd = config.instance_eval { binding }
|
328
|
+
end
|
329
|
+
require 'erb'
|
330
|
+
ERB.new(content).result(bnd)
|
331
|
+
end
|
332
|
+
|
333
|
+
def erb_config(*args, &block)
|
334
|
+
if block_given?
|
335
|
+
raise ArgumentError, "Expected block or single argument, but both given." unless args.empty?
|
336
|
+
block
|
337
|
+
elsif args.size > 1
|
338
|
+
raise ArgumentError, "Expected block or single argument."
|
339
|
+
else
|
340
|
+
args.first
|
341
|
+
end
|
342
|
+
end
|
343
|
+
|
344
|
+
end # class Mapper
|
345
|
+
|
346
|
+
end
|
347
|
+
|
348
|
+
# :call-seq:
|
349
|
+
# filter(*source) => Filter
|
350
|
+
#
|
351
|
+
# Creates a filter that will copy files from the source directory(ies) into the target directory.
|
352
|
+
# You can extend the filter to modify files by mapping <tt>${key}</tt> into values in each
|
353
|
+
# of the copied files, and by including or excluding specific files.
|
354
|
+
#
|
355
|
+
# A filter is not a task, you must call the Filter#run method to execute it.
|
356
|
+
#
|
357
|
+
# For example, to copy all files from one directory to another:
|
358
|
+
# filter('src/files').into('target/classes').run
|
359
|
+
# To include only the text files, and replace each instance of <tt>${build}</tt> with the current
|
360
|
+
# date/time:
|
361
|
+
# filter('src/files').into('target/classes').include('*.txt').using('build'=>Time.now).run
|
362
|
+
def filter(*sources)
|
363
|
+
Filter.new.from(*sources)
|
364
|
+
end
|
365
|
+
|
366
|
+
end
|
@@ -0,0 +1,195 @@
|
|
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/java/pom'
|
18
|
+
|
19
|
+
|
20
|
+
module Buildr
|
21
|
+
module Generate #:nodoc:
|
22
|
+
|
23
|
+
task 'generate' do
|
24
|
+
script = nil
|
25
|
+
choose do |menu|
|
26
|
+
menu.header = "To use Buildr you need a buildfile. Do you want me to create one?"
|
27
|
+
|
28
|
+
menu.choice("From maven2 pom file") { script = Generate.from_maven2_pom('pom.xml').join("\n") } if File.exists?("pom.xml")
|
29
|
+
menu.choice("From directory structure") { script = Generate.from_directory(Dir.pwd).join("\n") }
|
30
|
+
menu.choice("Skip") { }
|
31
|
+
end
|
32
|
+
|
33
|
+
if script
|
34
|
+
buildfile = File.expand_path(Buildr::Application::DEFAULT_BUILDFILES.first)
|
35
|
+
File.open(buildfile, "w") { |file| file.write script }
|
36
|
+
puts "Created #{buildfile}"
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
class << self
|
41
|
+
|
42
|
+
HEADER = "# Generated by Buildr #{Buildr::VERSION}, change to your liking\n\n"
|
43
|
+
|
44
|
+
def from_directory(path = Dir.pwd, root = true)
|
45
|
+
Dir.chdir(path) do
|
46
|
+
name = File.basename(path)
|
47
|
+
if root
|
48
|
+
script = HEADER.split("\n")
|
49
|
+
header = <<-EOF
|
50
|
+
# Version number for this release
|
51
|
+
VERSION_NUMBER = "1.0.0"
|
52
|
+
# Group identifier for your projects
|
53
|
+
GROUP = "#{name}"
|
54
|
+
COPYRIGHT = ""
|
55
|
+
|
56
|
+
# Specify Maven 2.0 remote repositories here, like this:
|
57
|
+
repositories.remote << "http://www.ibiblio.org/maven2/"
|
58
|
+
|
59
|
+
desc "The #{name.capitalize} project"
|
60
|
+
define "#{name}" do
|
61
|
+
|
62
|
+
project.version = VERSION_NUMBER
|
63
|
+
project.group = GROUP
|
64
|
+
manifest["Implementation-Vendor"] = COPYRIGHT
|
65
|
+
EOF
|
66
|
+
script += header.split("\n")
|
67
|
+
else
|
68
|
+
script = [ %{define "#{name}" do} ]
|
69
|
+
end
|
70
|
+
script << " compile.with # Add classpath dependencies" if File.exist?("src/main/java")
|
71
|
+
script << " resources" if File.exist?("src/main/resources")
|
72
|
+
script << " test.compile.with # Add classpath dependencies" if File.exist?("src/test/java")
|
73
|
+
script << " test.resources" if File.exist?("src/test/resources")
|
74
|
+
if File.exist?("src/main/webapp")
|
75
|
+
script << " package(:war)"
|
76
|
+
elsif File.exist?("src/main/java")
|
77
|
+
script << " package(:jar)"
|
78
|
+
end
|
79
|
+
dirs = FileList["*"].exclude("src", "target", "report").
|
80
|
+
select { |file| File.directory?(file) && File.exist?(File.join(file, "src")) }
|
81
|
+
unless dirs.empty?
|
82
|
+
script << ""
|
83
|
+
dirs.sort.each do |dir|
|
84
|
+
script << from_directory(dir, false).flatten.map { |line| " " + line } << ""
|
85
|
+
end
|
86
|
+
end
|
87
|
+
script << "end"
|
88
|
+
script.flatten
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
def from_maven2_pom(path = 'pom.xml', root = true)
|
93
|
+
pom = Buildr::POM.load(path)
|
94
|
+
project = pom.project
|
95
|
+
|
96
|
+
artifactId = project['artifactId'].first
|
97
|
+
description = project['name'] || "The #{artifactId} project"
|
98
|
+
project_name = File.basename(Dir.pwd)
|
99
|
+
|
100
|
+
if root
|
101
|
+
script = HEADER.split("\n")
|
102
|
+
|
103
|
+
settings_file = ENV["M2_SETTINGS"] || File.join(ENV['HOME'], ".m2/settings.xml")
|
104
|
+
settings = XmlSimple.xml_in(IO.read(settings_file)) if File.exists?(settings_file)
|
105
|
+
|
106
|
+
if settings
|
107
|
+
proxy = settings['proxies'].first['proxy'].find { |proxy|
|
108
|
+
proxy["active"].nil? || proxy["active"].to_s =~ /true/
|
109
|
+
} rescue nil
|
110
|
+
|
111
|
+
if proxy
|
112
|
+
url = %{#{proxy["protocol"].first}://#{proxy["host"].first}:#{proxy["port"].first}}
|
113
|
+
exclude = proxy["nonProxyHosts"].to_s.gsub("|", ",") if proxy["nonProxyHosts"]
|
114
|
+
script << "options.proxy.http = '#{url}'"
|
115
|
+
script << "options.proxy.exclude << '#{exclude}'" if exclude
|
116
|
+
script << ''
|
117
|
+
# In addition, we need to use said proxies to download artifacts.
|
118
|
+
Buildr.options.proxy.http = url
|
119
|
+
Buildr.options.proxy.exclude << exclude if exclude
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
repositories = project["repositories"].first["repository"].select { |repository|
|
124
|
+
legacy = repository["layout"].to_s =~ /legacy/
|
125
|
+
!legacy
|
126
|
+
} rescue nil
|
127
|
+
repositories = [{"name" => "Standard maven2 repository", "url" => "http://www.ibiblio.org/maven2/"}] if repositories.nil? || repositories.empty?
|
128
|
+
repositories.each do |repository|
|
129
|
+
name, url = repository["name"], repository["url"]
|
130
|
+
script << "# #{name}"
|
131
|
+
script << "repositories.remote << '#{url}'"
|
132
|
+
# In addition we need to use said repositores to download artifacts.
|
133
|
+
Buildr.repositories.remote << url.to_s
|
134
|
+
end
|
135
|
+
script << ""
|
136
|
+
else
|
137
|
+
script = []
|
138
|
+
end
|
139
|
+
|
140
|
+
script << "desc '#{description}'"
|
141
|
+
script << "define '#{project_name}' do"
|
142
|
+
|
143
|
+
groupId = project['groupId']
|
144
|
+
script << " project.group = '#{groupId}'" if groupId
|
145
|
+
|
146
|
+
version = project['version']
|
147
|
+
script << " project.version = '#{version}'" if version
|
148
|
+
|
149
|
+
#get plugins configurations
|
150
|
+
plugins = project['build'].first['plugins'].first['plugin'] rescue {}
|
151
|
+
if plugins
|
152
|
+
compile_plugin = plugins.find{|pl| (pl['groupId'].nil? or pl['groupId'].first == 'org.apache.maven.plugins') and pl['artifactId'].first == 'maven-compiler-plugin'}
|
153
|
+
if compile_plugin
|
154
|
+
source = compile_plugin.first['configuration'].first['source'] rescue nil
|
155
|
+
target = compile_plugin.first['configuration'].first['target'] rescue nil
|
156
|
+
|
157
|
+
script << " compile.options.source = '#{source}'" if source
|
158
|
+
script << " compile.options.target = '#{target}'" if target
|
159
|
+
end
|
160
|
+
end
|
161
|
+
|
162
|
+
compile_dependencies = pom.dependencies
|
163
|
+
dependencies = compile_dependencies.sort.map{|d| "'#{d}'"}.join(', ')
|
164
|
+
script << " compile.with #{dependencies}" unless dependencies.empty?
|
165
|
+
|
166
|
+
test_dependencies = (pom.dependencies(['test']) - compile_dependencies).reject{|d| d =~ /^junit:junit:jar:/ }
|
167
|
+
#check if we have testng
|
168
|
+
use_testng = test_dependencies.find{|d| d =~ /^org.testng:testng:jar:/}
|
169
|
+
if use_testng
|
170
|
+
script << " test.using :testng"
|
171
|
+
test_dependencies = pom.dependencies(['test']).reject{|d| d =~ /^org.testng:testng:jar:/ }
|
172
|
+
end
|
173
|
+
|
174
|
+
test_dependencies = test_dependencies.sort.map{|d| "'#{d}'"}.join(', ')
|
175
|
+
script << " test.with #{test_dependencies}" unless test_dependencies.empty?
|
176
|
+
|
177
|
+
packaging = project['packaging'] ? project['packaging'].first : 'jar'
|
178
|
+
if %w(jar war).include?(packaging)
|
179
|
+
script << " package :#{packaging}, :id => '#{artifactId}'"
|
180
|
+
end
|
181
|
+
|
182
|
+
modules = project['modules'].first['module'] rescue nil
|
183
|
+
if modules
|
184
|
+
script << ""
|
185
|
+
modules.each do |mod|
|
186
|
+
script << from_maven2_pom(File.join(File.dirname(path), mod, 'pom.xml'), false).flatten.map { |line| " " + line } << ""
|
187
|
+
end
|
188
|
+
end
|
189
|
+
script << "end"
|
190
|
+
script.flatten
|
191
|
+
end
|
192
|
+
|
193
|
+
end
|
194
|
+
end
|
195
|
+
end
|
@@ -0,0 +1,119 @@
|
|
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/core/common'
|
18
|
+
require 'buildr/core/project'
|
19
|
+
|
20
|
+
|
21
|
+
module Buildr
|
22
|
+
|
23
|
+
module Help #:nodoc:
|
24
|
+
class << self
|
25
|
+
|
26
|
+
def <<(arg)
|
27
|
+
if arg.respond_to?(:call)
|
28
|
+
texters << arg
|
29
|
+
else
|
30
|
+
texters << lambda { arg }
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def to_s
|
35
|
+
texters.map(&:call).join("\n")
|
36
|
+
end
|
37
|
+
|
38
|
+
protected
|
39
|
+
def texters
|
40
|
+
@texters ||= []
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
class << self
|
47
|
+
def help(&block)
|
48
|
+
Help << block if block_given?
|
49
|
+
Help
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
54
|
+
|
55
|
+
|
56
|
+
task 'help' do
|
57
|
+
# Greeater.
|
58
|
+
puts 'Usage:'
|
59
|
+
puts ' buildr [-f rakefile] {options} targets...'
|
60
|
+
puts
|
61
|
+
|
62
|
+
# Show only the top-level projects.
|
63
|
+
projects.reject(&:parent).tap do |top_level|
|
64
|
+
unless top_level.empty?
|
65
|
+
puts 'Top-level projects (buildr help:projects for full list):'
|
66
|
+
width = [top_level.map(&:name).map(&:size), 20].flatten.max
|
67
|
+
top_level.each do |project|
|
68
|
+
puts project.comment.to_s.empty? ? project.name : (" %-#{width}s # %s" % [project.name, project.comment])
|
69
|
+
end
|
70
|
+
puts
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
# Show all the top-level tasks, excluding projects.
|
75
|
+
puts 'Common tasks:'
|
76
|
+
task('help:tasks').invoke
|
77
|
+
puts
|
78
|
+
puts 'For help on command line options:'
|
79
|
+
puts ' buildr --help'
|
80
|
+
puts Buildr.help.to_s
|
81
|
+
end
|
82
|
+
|
83
|
+
|
84
|
+
module Buildr
|
85
|
+
|
86
|
+
# :call-seq:
|
87
|
+
# help() { ... }
|
88
|
+
#
|
89
|
+
# Use this to enhance the help task, e.g. to print some important information about your build,
|
90
|
+
# configuration options, build instructions, etc.
|
91
|
+
def help(&block)
|
92
|
+
Buildr.help << block
|
93
|
+
end
|
94
|
+
|
95
|
+
end
|
96
|
+
|
97
|
+
|
98
|
+
namespace 'help' do
|
99
|
+
|
100
|
+
desc 'List all projects defined by this buildfile'
|
101
|
+
task 'projects' do
|
102
|
+
width = projects.map(&:name).map(&:size).max
|
103
|
+
projects.each do |project|
|
104
|
+
puts project.comment.to_s.empty? ? " #{project.name}" : (" %-#{width}s # %s" % [project.name, project.comment])
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
desc 'List all tasks available from this buildfile'
|
109
|
+
task 'tasks' do
|
110
|
+
Buildr.application.tasks.select(&:comment).reject { |task| Project === task }.tap do |tasks|
|
111
|
+
width = [tasks.map(&:name).map(&:size), 20].flatten.max
|
112
|
+
tasks.each do |task|
|
113
|
+
printf " %-#{width}s # %s\n", task.name, task.comment
|
114
|
+
end
|
115
|
+
puts
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
end
|