bee 0.11.2 → 0.11.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README CHANGED
@@ -25,4 +25,4 @@ or go to URL http://www.apache.org/licenses/LICENSE-2.0).
25
25
 
26
26
  = Copyright
27
27
 
28
- bee version 0.11.2 (C) Michel Casabianca & Contributors - 2006-2012
28
+ bee version 0.11.3 (C) Michel Casabianca & Contributors - 2006-2012
@@ -38,7 +38,8 @@ module Bee
38
38
  'description' => :optional,
39
39
  'context' => :optional,
40
40
  'extends' => :optional,
41
- 'abstract' => :optional
41
+ 'abstract' => :optional,
42
+ 'alias' => :optional
42
43
  }
43
44
 
44
45
  # Build file.
@@ -189,12 +190,17 @@ module Bee
189
190
  end
190
191
  error "Duplicate build info" if @name
191
192
  @name = entry['build']
192
- @targets.default = entry['default']
193
+ # check that 'default' entry is a string or an array
194
+ error "'default' entry of the 'build' block must be a string or an array" if
195
+ entry['default'] and (!entry['default'].kind_of?(String) and
196
+ !entry['default'].kind_of?(Array))
197
+ @targets.default = Array(entry['default']) if entry['default']
198
+ # check that 'alias' entry is a hash
199
+ error "'alias' entry of the 'build' block must be a hash" if
200
+ entry['alias'] and !entry['alias'].kind_of?(Hash)
201
+ @targets.alias = entry['alias'] if entry['alias']
193
202
  @description = entry['description']
194
203
  @abstract = entry['abstract']
195
- # check that 'default' entry is a string
196
- error "'default' entry of the 'build' block must be a string" if
197
- @targets.default and !@targets.default.kind_of?(String)
198
204
  # load parents build if any
199
205
  parents = Array(entry['extends'])
200
206
  if parents.length > 0
@@ -44,6 +44,7 @@ Usage: bee [options] [targets]
44
44
  -f file Build file to run (defaults to "build.yml").
45
45
  -r Look for build file recursively up in file system.
46
46
  -l Print bee logo on console.
47
+ -R resource Print given resource (such as ':bee:clean.yml') on console.
47
48
  -a Print list of available targets.
48
49
  -o Print list of available options.
49
50
  -x Print list of available tasks.
@@ -67,6 +68,7 @@ EOF
67
68
  ['--file', '-f', GetoptLong::REQUIRED_ARGUMENT],
68
69
  ['--recursive', '-r', GetoptLong::NO_ARGUMENT],
69
70
  ['--logo', '-l', GetoptLong::NO_ARGUMENT],
71
+ ['--resource', '-R', GetoptLong::REQUIRED_ARGUMENT],
70
72
  ['--targets', '-a', GetoptLong::NO_ARGUMENT],
71
73
  ['--options', '-o', GetoptLong::NO_ARGUMENT],
72
74
  ['--tasks', '-x', GetoptLong::NO_ARGUMENT],
@@ -113,6 +115,7 @@ EOF
113
115
  file = DEFAULT_BUILD_FILE
114
116
  recursive = false
115
117
  logo = false
118
+ resource = nil
116
119
  print_targets = false
117
120
  print_options = false
118
121
  print_tasks = false
@@ -162,6 +165,8 @@ EOF
162
165
  recursive = true
163
166
  when '--logo'
164
167
  logo = true
168
+ when '--resource'
169
+ resource = arg
165
170
  when '--targets'
166
171
  print_targets = true
167
172
  when '--options'
@@ -176,8 +181,8 @@ EOF
176
181
  ARGV.replace(old_argv)
177
182
  return version, help, help_build, help_task, task, help_template,
178
183
  template, properties, dry_run, verbose, style, color, file,
179
- recursive, logo, print_targets, print_options, print_tasks,
180
- print_templates, targets
184
+ recursive, logo, resource, print_targets, print_options,
185
+ print_tasks, print_templates, targets
181
186
  end
182
187
 
183
188
  # Parse a command line property.
@@ -202,8 +207,8 @@ EOF
202
207
  begin
203
208
  version, help, help_build, help_task, task, help_template,
204
209
  template, properties, dry_run, verbose, style, color, file,
205
- recursive, logo, print_targets, print_options, print_tasks,
206
- print_templates, targets = parse_command_line(arguments)
210
+ recursive, logo, resource, print_targets, print_options,
211
+ print_tasks, print_templates, targets = parse_command_line(arguments)
207
212
  rescue
208
213
  puts "ERROR: parsing command line: #{$!}"
209
214
  exit(EXIT_PARSING_CMDLINE)
@@ -232,10 +237,19 @@ EOF
232
237
  listener = Listener.new(formatter)
233
238
  build = Build.load(file, false, properties)
234
239
  build.run(targets, listener, dry_run)
240
+ elsif resource
241
+ raise Bee::Util::BuildError.new("'#{resource}' is not a valid resource") if
242
+ !Util::resource?(resource)
243
+ begin
244
+ puts File.read(Bee::Util::resource_path(resource))
245
+ rescue Exception
246
+ raise Bee::Util::BuildError.new("Resource '#{resource}' not found")
247
+ end
235
248
  elsif print_targets
236
249
  begin
237
250
  build = Build.load(file)
238
251
  targets = build.targets.hash.keys
252
+ targets += build.targets.alias.keys if build.targets.alias
239
253
  rescue Exception
240
254
  targets = []
241
255
  end
@@ -215,7 +215,7 @@ module Bee
215
215
  help << "build: #{build.name}\n"
216
216
  end
217
217
  if build.extends
218
- help << "extends: #{build.extends.map{|b| b.name}.join(', ')}\n"
218
+ help << "extends: #{format_list(build.extends.map{|b| b.name})}\n"
219
219
  end
220
220
  if build.description
221
221
  help << format_description('description', build.description, 0, false)
@@ -237,7 +237,15 @@ module Bee
237
237
  end
238
238
  end
239
239
  # print default target
240
- help << "default: #{build.targets.default}\n"
240
+ help << "default: #{format_list(build.targets.default)}\n" if
241
+ build.targets.default
242
+ # print alias for targets
243
+ if build.targets.alias and build.targets.alias.keys.length > 0
244
+ help << "alias:\n"
245
+ for name in build.targets.alias.keys.sort
246
+ help << " #{name}: #{format_list(build.targets.alias[name])}\n"
247
+ end
248
+ end
241
249
  return help.strip
242
250
  end
243
251
 
@@ -320,6 +328,18 @@ module Bee
320
328
  end
321
329
  end
322
330
 
331
+ def format_list(list)
332
+ if list.kind_of?(Array)
333
+ if list.length > 1
334
+ return "[#{list.join(', ')}]"
335
+ else
336
+ return list[0]
337
+ end
338
+ else
339
+ return list
340
+ end
341
+ end
342
+
323
343
  end
324
344
 
325
345
  end
@@ -31,6 +31,8 @@ module Bee
31
31
  attr_reader :already_run
32
32
  # Default target.
33
33
  attr_accessor :default
34
+ # Alias for targets
35
+ attr_accessor :alias
34
36
 
35
37
  # Constructor.
36
38
  # - build: build object.
@@ -51,7 +53,7 @@ module Bee
51
53
  error "Duplicate target definition: '#{target.name}'" if
52
54
  @hash.has_key?(target.name)
53
55
  @hash[target.name] = [target]
54
- @default = target.name if !@default
56
+ # record first target for default
55
57
  end
56
58
 
57
59
  # Extend parent targets.
@@ -85,6 +87,17 @@ module Bee
85
87
  end
86
88
  # set default default target to parent one if none was set
87
89
  @default = @default || parent.default
90
+ # manage alias
91
+ if parent.alias
92
+ @alias = {} if !@alias
93
+ for key in parent.alias.keys
94
+ if @alias.has_key?(key)
95
+ @alias[key] = Array(@alias[key]) + Array(parent.alias[key])
96
+ else
97
+ @alias[key] = Array(parent.alias[key])
98
+ end
99
+ end
100
+ end
88
101
  end
89
102
 
90
103
  # Run a given target.
@@ -101,9 +114,22 @@ module Bee
101
114
  # Run targets.
102
115
  # - targets: list of target names to run.
103
116
  def run(targets, dry)
104
- error "No default target given" if (!@default and targets.length == 0)
105
- targets = [@default] if targets.length == 0
117
+ if targets.length == 0
118
+ if @default
119
+ targets = @default
120
+ else
121
+ error "No default target given"
122
+ end
123
+ end
124
+ aliased_targets = []
106
125
  for target in targets
126
+ if @alias and @alias.has_key?(target)
127
+ aliased_targets += Array(@alias[target])
128
+ else
129
+ aliased_targets << target
130
+ end
131
+ end
132
+ for target in aliased_targets
107
133
  run_target(target, dry)
108
134
  @already_run.clear
109
135
  end
@@ -556,12 +556,15 @@ EOF
556
556
  # '**/*' to include all files recursively.
557
557
  # - excludes: list of globs for files to exclude from copy. Optional,
558
558
  # default to nil to exclude no file.
559
- # - dest: destination directory for the copy, must be an existing
560
- # directory.
561
559
  # - dotmatch: tells if joker matches dot files. Optional, defaults to
562
560
  # false.
563
561
  # - flatten: tells if included files should be copied in destination
564
562
  # directory, ignoring their subdirectory. Optional, defaults to false.
563
+ # - sets: a single or list of sets made of root, includes, excludes,
564
+ # dotmatch and flatten entries, as defined previously. Can be defined
565
+ # only if no root, includes, excludes, dotmatch or flatten are defined.
566
+ # - dest: destination directory for the copy, must be an existing
567
+ # directory.
565
568
  # - lenient: tells if copy is lenient, which will silently succeed on
566
569
  # errors (for instance if root or destination directory don't exist).
567
570
  # Optional, defaults to false.
@@ -576,21 +579,32 @@ EOF
576
579
  # includes: **/*
577
580
  # excludes: **/CVS/**/*
578
581
  # dest: destination
582
+ #
583
+ # Example:
584
+ #
585
+ # With sets, you could write :
586
+ #
587
+ # - copy:
588
+ # sets:
589
+ # - root: src
590
+ # excludes: **/CVS/**/*
591
+ # - root: res
592
+ # includes: **/*.properties
593
+ # dest: destination
579
594
  #
580
595
  # Note: this task only deals with files. Thus, 'includes' and 'excludes'
581
596
  # globs should be ones for files.
582
597
  def copy(params)
583
598
  # check parameters and set default values
584
599
  params_desc = {
585
- :root => { :mandatory => false, :type => :string,
586
- :default => '.' },
600
+ :root => { :mandatory => false, :type => :string },
587
601
  :includes => { :mandatory => false, :type => :string_or_array },
588
602
  :excludes => { :mandatory => false, :type => :string_or_array },
603
+ :dotmatch => { :mandatory => false, :type => :boolean },
604
+ :sets => { :mandatory => false, :type => :hash_or_array },
589
605
  :dest => { :mandatory => true, :type => :string },
590
606
  :flatten => { :mandatory => false, :type => :boolean,
591
607
  :default => false },
592
- :dotmatch => { :mandatory => false, :type => :boolean,
593
- :default => false },
594
608
  :lenient => { :mandatory => false, :type => :boolean,
595
609
  :default => false }
596
610
  }
@@ -598,18 +612,12 @@ EOF
598
612
  root = params[:root]
599
613
  includes = params[:includes]
600
614
  excludes = params[:excludes]
615
+ dotmatch = params[:dotmatch]
616
+ sets = params[:sets]
601
617
  dest = params[:dest]
602
618
  flatten = params[:flatten]
603
- dotmatch = params[:dotmatch]
604
619
  lenient = params[:lenient]
605
- # check that root and dest are existing directories
606
- if not (File.exists?(root) and File.directory?(root))
607
- if lenient
608
- return
609
- else
610
- error "copy 'root' parameter must be an existing directory"
611
- end
612
- end
620
+ # check that destination is an existing directory
613
621
  if not (File.exists?(dest) and File.directory?(dest))
614
622
  if lenient
615
623
  return
@@ -617,19 +625,43 @@ EOF
617
625
  error "copy 'dest' parameter must be an existing directory"
618
626
  end
619
627
  end
620
- # select files and copy
621
- files = filter_files(includes, excludes, root, dotmatch)
622
- puts "Copying #{files.length} file(s) to '#{dest}'"
623
- for file in files
624
- from_file = File.join(root, file)
625
- if flatten
626
- to_file = File.join(dest, File.basename(file))
627
- else
628
- to_file = File.join(dest, file)
628
+ # if no sets defined
629
+ if sets == nil
630
+ root = '.' if root == nil
631
+ dotmatch = false if dotmatch == nil
632
+ if not (File.exists?(root) and File.directory?(root))
633
+ if lenient
634
+ return
635
+ else
636
+ error "copy 'root' parameter must be an existing directory"
637
+ end
638
+ end
639
+ files = filter_files(root, includes, excludes, dotmatch)
640
+ copy_files(root, files, dest, flatten)
641
+ # if sets are defined
642
+ else
643
+ for _set in sets
644
+ _unknown = _set.keys - ['root', 'includes', 'excludes', 'dotmatch', 'flatten']
645
+ error "copy 'sets' parameter has unknown entry #{_unknown.join(', ')}" if
646
+ _unknown.size > 0
647
+ _root = _set['root']
648
+ _root = '.' if _root == nil
649
+ if not (File.exists?(_root) and File.directory?(_root))
650
+ if lenient
651
+ continue
652
+ else
653
+ error "copy 'root' entries of 'sets' parameter must be an existing directory"
654
+ end
655
+ end
656
+ _includes = _set['includes']
657
+ _excludes = _set['excludes']
658
+ _dotmatch = _set['dotmatch']
659
+ _dotmatch = false if _dotmatch == nil
660
+ _flatten = _set['flatten']
661
+ _flatten = false if _flatten == nil
662
+ _files = filter_files(_root, _includes, _excludes, _dotmatch)
663
+ copy_files(_root, _files, dest, _flatten)
629
664
  end
630
- to_dir = File.dirname(to_file)
631
- FileUtils.makedirs(to_dir) if not File.exists?(to_dir)
632
- FileUtils.cp(from_file, to_file)
633
665
  end
634
666
  end
635
667
 
@@ -702,7 +734,7 @@ EOF
702
734
  end
703
735
  end
704
736
  # select files and make move
705
- files = filter_files(includes, excludes, root, dotmatch)
737
+ files = filter_files(root, includes, excludes, dotmatch)
706
738
  puts "Moving #{files.length} file(s) to '#{dest}'"
707
739
  for file in files
708
740
  from_file = File.join(root, file)
@@ -847,7 +879,7 @@ EOF
847
879
  property = params[:property]
848
880
  dotmatch = params[:dotmatch]
849
881
  join = params[:join]
850
- files = filter_files(includes, excludes, root, dotmatch)
882
+ files = filter_files(root, includes, excludes, dotmatch)
851
883
  if join
852
884
  files = files.join(join)
853
885
  end
@@ -978,7 +1010,7 @@ EOF
978
1010
  dir = params[:dir]
979
1011
  error "Test directory '#{dir}' not found" if
980
1012
  not (File.exists?(dir) and File.directory?(dir))
981
- files = filter_files(includes, excludes, root, dotmatch)
1013
+ files = filter_files(root, includes, excludes, dotmatch)
982
1014
  files.map! { |file| File.expand_path(File.join(root, file)) }
983
1015
  for file in files
984
1016
  load file
@@ -1109,7 +1141,7 @@ EOF
1109
1141
  dotmatch = params[:dotmatch]
1110
1142
  dest = params[:dest]
1111
1143
  options = params[:options]
1112
- files = filter_files(includes, excludes, root, dotmatch)
1144
+ files = filter_files(root, includes, excludes, dotmatch)
1113
1145
  command_line = ['-S', '-o', dest]
1114
1146
  command_line += options if options
1115
1147
  command_line += files
@@ -1228,7 +1260,7 @@ EOF
1228
1260
  dotmatch = parameters[:dotmatch]
1229
1261
  dest = parameters[:dest]
1230
1262
  prefix = parameters[:prefix]
1231
- files = filter_files(includes, excludes, root, dotmatch)
1263
+ files = filter_files(root, includes, excludes, dotmatch)
1232
1264
  # build the archive
1233
1265
  puts "Building ZIP archive '#{dest}'"
1234
1266
  begin
@@ -1329,7 +1361,7 @@ EOF
1329
1361
  excludes = parameters[:excludes]
1330
1362
  dotmatch = parameters[:dotmatch]
1331
1363
  dest = parameters[:dest]
1332
- files = filter_files(includes, excludes, root, dotmatch)
1364
+ files = filter_files(root, includes, excludes, dotmatch)
1333
1365
  # build the archive
1334
1366
  puts "Processing TAR archive '#{dest}'"
1335
1367
  begin
@@ -1476,7 +1508,7 @@ EOF
1476
1508
  excludes = parameters[:excludes]
1477
1509
  dotmatch = parameters[:dotmatch]
1478
1510
  dest = parameters[:dest]
1479
- files = filter_files(includes, excludes, root, dotmatch)
1511
+ files = filter_files(root, includes, excludes, dotmatch)
1480
1512
  # build the archive
1481
1513
  puts "Building TARGZ archive '#{dest}'"
1482
1514
  begin
@@ -87,6 +87,14 @@ module Bee
87
87
  when :hash
88
88
  error "#{task} '#{param}' parameter must be a hash" unless
89
89
  params[param.to_s].kind_of?(Hash)
90
+ when :hash_or_array
91
+ error "#{task} '#{param}' parameter must be a hash or list of hashes" unless
92
+ params[param.to_s].kind_of?(Hash) or params[param.to_s].kind_of?(Array)
93
+ if params[param.to_s].kind_of?(Hash)
94
+ params[param.to_s] = [params[param.to_s]]
95
+ elsif !params[param.to_s].kind_of?(Array)
96
+ error "#{task} '#{param}' parameter must be a hash or a list of hashes"
97
+ end
90
98
  else
91
99
  error "Unknown parameter type '#{description[param][:type]}'"
92
100
  end
@@ -110,7 +118,7 @@ module Bee
110
118
  # - excludes: list of globs for files to exclude from search.
111
119
  # - dotmatch: tells if joker matches dot files.
112
120
  # Return: the list of found files (no directories included).
113
- def filter_files(includes, excludes, root, dotmatch=true)
121
+ def filter_files(root, includes, excludes, dotmatch=true)
114
122
  error "includes must be a glob or a list of globs" unless
115
123
  !includes or includes.kind_of?(String) or includes.kind_of?(Array)
116
124
  error "excludes must be a glob or a list of globs" unless
@@ -156,6 +164,73 @@ module Bee
156
164
  end
157
165
  end
158
166
 
167
+ def evaluate_sets(root, includes, excludes, dotmatch, flatten, sets, lenient)
168
+ response = []
169
+ # check that no root and sets are defined at the same time
170
+ if (root || includes || excludes || dotmatch || flatten) && sets
171
+ error "Sets might not be used along with root, includes, excludes, dotmatch or flatten"
172
+ end
173
+ # if no sets defined
174
+ if sets == nil
175
+ root = '.' if root == nil
176
+ dotmatch = false if dotmatch == nil
177
+ flatten = false if flatten == nil
178
+ if not (File.exists?(root) and File.directory?(root))
179
+ if lenient
180
+ return
181
+ else
182
+ error "'root' parameter must be an existing directory"
183
+ end
184
+ end
185
+ response << {:files => filter_files(root, includes, excludes, dotmatch), :flatten => flatten}
186
+ # if sets are defined
187
+ else
188
+ for _set in sets
189
+ _unknown = _set.keys - ['root', 'includes', 'excludes', 'dotmatch', 'flatten']
190
+ error "'sets' parameter has unknown entry #{_unknown.join(', ')}" if
191
+ _unknown.size > 0
192
+ _root = _set['root']
193
+ _root = '.' if _root == nil
194
+ if not (File.exists?(_root) and File.directory?(_root))
195
+ if lenient
196
+ continue
197
+ else
198
+ error "'root' entries of 'sets' parameter must be an existing directory"
199
+ end
200
+ end
201
+ _includes = _set['includes']
202
+ _excludes = _set['excludes']
203
+ _dotmatch = _set['dotmatch']
204
+ _dotmatch = false if _dotmatch == nil
205
+ _flatten = _set['flatten']
206
+ _flatten = false if _flatten == nil
207
+ files += filter_files(_root, _includes, _excludes, _dotmatch)
208
+ end
209
+ response << {:files => files, :flatten => _flatten}
210
+ end
211
+ return response
212
+ end
213
+
214
+ # Copy a list of files to a given diretory:
215
+ # - root: root directory of source files.
216
+ # - files: a list of files to copy relative to root.
217
+ # - dest: destination directory.
218
+ # - flatten: tells if a flat copy is made.
219
+ def copy_files(root, files, dest, flatten)
220
+ puts "Copying #{files.length} file(s) to '#{dest}'"
221
+ for file in files
222
+ from_file = File.join(root, file)
223
+ if flatten
224
+ to_file = File.join(dest, File.basename(file))
225
+ else
226
+ to_file = File.join(dest, file)
227
+ end
228
+ to_dir = File.dirname(to_file)
229
+ FileUtils.makedirs(to_dir) if not File.exists?(to_dir)
230
+ FileUtils.cp(from_file, to_file)
231
+ end
232
+ end
233
+
159
234
  # Print text on the console.
160
235
  # - text: text to print.
161
236
  def print(text)
@@ -1,5 +1,5 @@
1
1
  module Bee
2
2
 
3
- VERSION = '0.11.2'
3
+ VERSION = '0.11.3'
4
4
 
5
5
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bee
3
3
  version: !ruby/object:Gem::Version
4
- hash: 55
4
+ hash: 53
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 11
9
- - 2
10
- version: 0.11.2
9
+ - 3
10
+ version: 0.11.3
11
11
  platform: ruby
12
12
  authors:
13
13
  - Michel Casabianca & Contributors
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2012-01-29 00:00:00 +01:00
18
+ date: 2012-06-01 00:00:00 +02:00
19
19
  default_executable: bee
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -127,7 +127,6 @@ files:
127
127
  - egg/xmlrpc/client.rb
128
128
  - egg/xmlrpc/server.rb
129
129
  - egg/xmlrpc.yml
130
- - clean.yml
131
130
  - README
132
131
  - LICENSE
133
132
  has_rdoc: true
data/clean.yml DELETED
@@ -1,36 +0,0 @@
1
- # Copyright 2006-2012 Michel Casabianca <michel.casabianca@gmail.com>
2
- #
3
- # Licensed under the Apache License, Version 2.0 (the "License");
4
- # you may not use this file except in compliance with the License.
5
- # You may obtain a copy of the License at
6
- #
7
- # http://www.apache.org/licenses/LICENSE-2.0
8
- #
9
- # Unless required by applicable law or agreed to in writing, software
10
- # distributed under the License is distributed on an "AS IS" BASIS,
11
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
- # See the License for the specific language governing permissions and
13
- # limitations under the License.
14
-
15
- # Build info
16
- - build: bee
17
- default: clean
18
- description: Parent build file to clean
19
- abstract: true
20
-
21
- # Build properties
22
- - properties:
23
- build_dir: ~
24
- clean_dirs:
25
- - :build_dir
26
- clean_files:
27
- - "**/*~"
28
- - "**/.#*#"
29
-
30
- # Build targets
31
- - target: clean
32
- description: Clean generated files
33
- script:
34
- - rmdir: :clean_dirs
35
- - rm: :clean_files
36
-