bee 0.5.3 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README +1 -1
- data/egg/package/test_suite.rb +0 -0
- data/lib/bee.rb +120 -14
- data/lib/bee_console.rb +1 -1
- data/lib/bee_task_default.rb +171 -17
- metadata +13 -13
data/README
CHANGED
data/egg/package/test_suite.rb
CHANGED
File without changes
|
data/lib/bee.rb
CHANGED
@@ -541,9 +541,7 @@ module Bee
|
|
541
541
|
end
|
542
542
|
@targets.build.listener.target(self) if
|
543
543
|
@targets.build.listener and @targets.is_last(self)
|
544
|
-
|
545
|
-
run_task(task, dry)
|
546
|
-
end
|
544
|
+
run_block(@script, dry)
|
547
545
|
ensure
|
548
546
|
Dir.chdir(current_dir)
|
549
547
|
end
|
@@ -561,18 +559,25 @@ module Bee
|
|
561
559
|
# shell script
|
562
560
|
run_shell(task, dry)
|
563
561
|
when Hash
|
564
|
-
|
565
|
-
|
566
|
-
|
567
|
-
# ruby script
|
568
|
-
script = task['rb']
|
569
|
-
run_ruby(script, dry)
|
570
|
-
elsif task.key?('super')
|
571
|
-
# call super target
|
572
|
-
targets.call_super(self, dry)
|
562
|
+
if task.keys.length > 1
|
563
|
+
# construct
|
564
|
+
run_construct(task, dry)
|
573
565
|
else
|
574
|
-
|
575
|
-
|
566
|
+
if task.key?('rb')
|
567
|
+
# ruby script
|
568
|
+
script = task['rb']
|
569
|
+
run_ruby(script, dry)
|
570
|
+
elsif task.key?('sh')
|
571
|
+
# shell script
|
572
|
+
script = task['sh']
|
573
|
+
run_shell(script, dry)
|
574
|
+
elsif task.key?('super')
|
575
|
+
# call super target
|
576
|
+
targets.call_super(self, dry)
|
577
|
+
else
|
578
|
+
# must be a task
|
579
|
+
run_bee_task(task, dry)
|
580
|
+
end
|
576
581
|
end
|
577
582
|
end
|
578
583
|
end
|
@@ -610,6 +615,107 @@ module Bee
|
|
610
615
|
@targets.build.package_manager.run_task(task)
|
611
616
|
end
|
612
617
|
|
618
|
+
# Run a given construct.
|
619
|
+
# - construct: construct to run as a Hash.
|
620
|
+
def run_construct(construct, dry=false)
|
621
|
+
@listener.task(construct) if @listener
|
622
|
+
return if dry
|
623
|
+
# if construct
|
624
|
+
if construct.keys.include?('if')
|
625
|
+
construct_if(construct, dry)
|
626
|
+
# while construct
|
627
|
+
elsif construct.keys.include?('while')
|
628
|
+
construct_while(construct, dry)
|
629
|
+
# for construct
|
630
|
+
elsif construct.keys.include?('for')
|
631
|
+
construct_for(construct, dry)
|
632
|
+
else
|
633
|
+
error "Unknown construct '#{construct.keys.join('-')}'"
|
634
|
+
end
|
635
|
+
end
|
636
|
+
|
637
|
+
# Run if construct.
|
638
|
+
# - task: the construct as a hash.
|
639
|
+
# - dry: tells if we run in dry mode.
|
640
|
+
def construct_if(task, dry)
|
641
|
+
# test entries
|
642
|
+
error "If construct must include 'then' entry" if
|
643
|
+
not task.keys.include?('then')
|
644
|
+
unknown_keys = task.keys - ['if', 'then', 'else']
|
645
|
+
error "If construct may only include 'if', 'then' and 'else' entries" if
|
646
|
+
unknown_keys.length > 0
|
647
|
+
# evaluate condition in the build context
|
648
|
+
if evaluate(task['if'].to_s)
|
649
|
+
run_block(task['then'], dry)
|
650
|
+
else
|
651
|
+
run_block(task['else'], dry) if task['else']
|
652
|
+
end
|
653
|
+
end
|
654
|
+
|
655
|
+
# Run while construct.
|
656
|
+
# - task: the construct as a hash.
|
657
|
+
# - dry: tells if we run in dry mode.
|
658
|
+
def construct_while(task, dry)
|
659
|
+
# test entries
|
660
|
+
error "While construct must include 'do' entry" if
|
661
|
+
not task.keys.include?('do')
|
662
|
+
unknown_keys = task.keys - ['while', 'do']
|
663
|
+
error "While construct may only include 'while' and 'do' entries" if
|
664
|
+
unknown_keys.length > 0
|
665
|
+
# evaluate condition in the build context
|
666
|
+
while evaluate(task['while'])
|
667
|
+
run_block(task['do'], dry)
|
668
|
+
end
|
669
|
+
end
|
670
|
+
|
671
|
+
# Run for construct.
|
672
|
+
# - task: the construct as a hash.
|
673
|
+
# - dry: tells if we run in dry mode.
|
674
|
+
def construct_for(task, dry)
|
675
|
+
# test entries
|
676
|
+
error "For construct must include 'in' and 'do' entries" if
|
677
|
+
not task.keys.include?('in') or not task.keys.include?('do')
|
678
|
+
unknown_keys = task.keys - ['for', 'in', 'do']
|
679
|
+
error "For construct may only include 'for', 'in' and 'do' entries" if
|
680
|
+
unknown_keys.length > 0
|
681
|
+
error "For entry in for construct must be a string" if
|
682
|
+
not task['for'].kind_of?(String)
|
683
|
+
error "In entry in for construct must be a list or a string" if
|
684
|
+
not task['in'].kind_of?(Enumerable) and not task['in'].kind_of?(String)
|
685
|
+
# iterate over list
|
686
|
+
if task['in'].kind_of?(String)
|
687
|
+
enumerable = evaluate(task['in'])
|
688
|
+
else
|
689
|
+
enumerable = task['in']
|
690
|
+
end
|
691
|
+
for element in enumerable
|
692
|
+
begin
|
693
|
+
@targets.build.context.set_property(task['for'], element)
|
694
|
+
rescue
|
695
|
+
error "Error setting property '#{task['for']}'"
|
696
|
+
end
|
697
|
+
run_block(task['do'], dry)
|
698
|
+
end
|
699
|
+
end
|
700
|
+
|
701
|
+
# Run a block, that is a list of tasks.
|
702
|
+
# - block: the block to run as a list of tasks.
|
703
|
+
# - dry: tells if we run in dry mode.
|
704
|
+
def run_block(block, dry)
|
705
|
+
for task in block
|
706
|
+
run_task(task, dry)
|
707
|
+
end
|
708
|
+
end
|
709
|
+
|
710
|
+
# Evaluate a given condition and raise a BuildError if an error happens.
|
711
|
+
def evaluate(condition)
|
712
|
+
begin
|
713
|
+
return @targets.build.context.evaluate_script(condition)
|
714
|
+
rescue
|
715
|
+
error "Error evaluating condition: #{$!}"
|
716
|
+
end
|
717
|
+
end
|
718
|
+
|
613
719
|
end
|
614
720
|
|
615
721
|
# Class for Ruby scripts context. All embedded Ruby scripts run in this
|
data/lib/bee_console.rb
CHANGED
@@ -60,7 +60,7 @@ targets Targets to run (default target if omitted).'
|
|
60
60
|
| |__ ___ ___
|
61
61
|
____ | '_ \ / _ \/ _ \ _____ _____ _____ _____ _____ _____ _____ _____ _____
|
62
62
|
|____| | |_) | __/ __/ |_____|_____|_____|_____|_____|_____|_____|_____|_____|
|
63
|
-
|_.__/ \___|\___| 0.
|
63
|
+
|_.__/ \___|\___| 0.6.0 http://bee.rubyforge.org
|
64
64
|
|
65
65
|
EOF
|
66
66
|
|
data/lib/bee_task_default.rb
CHANGED
@@ -97,7 +97,8 @@ module Bee
|
|
97
97
|
:default => { :mandatory => false, :type => :string },
|
98
98
|
:pattern => { :mandatory => false, :type => :string },
|
99
99
|
:error => { :mandatory => false, :type => :string },
|
100
|
-
:attempts => { :mandatory => false, :type => :integer,
|
100
|
+
:attempts => { :mandatory => false, :type => :integer,
|
101
|
+
:default => 0 }
|
101
102
|
}
|
102
103
|
check_parameters(params, params_desc)
|
103
104
|
message = params[:message]
|
@@ -281,7 +282,8 @@ module Bee
|
|
281
282
|
params_desc = {
|
282
283
|
:files => { :mandatory => true, :type => :string_or_array },
|
283
284
|
:mode => { :mandatory => true, :type => :integer },
|
284
|
-
:recursive => { :mandatory => false, :type => :boolean,
|
285
|
+
:recursive => { :mandatory => false, :type => :boolean,
|
286
|
+
:default => false }
|
285
287
|
}
|
286
288
|
check_parameters(parameters, params_desc)
|
287
289
|
files = parameters[:files]
|
@@ -329,7 +331,8 @@ module Bee
|
|
329
331
|
:files => { :mandatory => true, :type => :string_or_array },
|
330
332
|
:user => { :mandatory => false, :type => :string_or_integer },
|
331
333
|
:group => { :mandatory => false, :type => :string_or_integer },
|
332
|
-
:recursive => { :mandatory => false, :type => :boolean,
|
334
|
+
:recursive => { :mandatory => false, :type => :boolean,
|
335
|
+
:default => false }
|
333
336
|
}
|
334
337
|
check_parameters(parameters, params_desc)
|
335
338
|
files = parameters['files']
|
@@ -475,13 +478,17 @@ module Bee
|
|
475
478
|
def copy(params)
|
476
479
|
# check parameters and set default values
|
477
480
|
params_desc = {
|
478
|
-
:root => { :mandatory => false, :type => :string,
|
481
|
+
:root => { :mandatory => false, :type => :string,
|
482
|
+
:default => '.' },
|
479
483
|
:includes => { :mandatory => false, :type => :string_or_array },
|
480
484
|
:excludes => { :mandatory => false, :type => :string_or_array },
|
481
485
|
:dest => { :mandatory => true, :type => :string },
|
482
|
-
:flatten => { :mandatory => false, :type => :boolean,
|
483
|
-
|
484
|
-
:
|
486
|
+
:flatten => { :mandatory => false, :type => :boolean,
|
487
|
+
:default => false },
|
488
|
+
:dotmatch => { :mandatory => false, :type => :boolean,
|
489
|
+
:default => false },
|
490
|
+
:lenient => { :mandatory => false, :type => :boolean,
|
491
|
+
:default => false }
|
485
492
|
}
|
486
493
|
check_parameters(params, params_desc)
|
487
494
|
root = params[:root]
|
@@ -555,13 +562,17 @@ module Bee
|
|
555
562
|
def move(params)
|
556
563
|
# check parameters and set default values
|
557
564
|
params_desc = {
|
558
|
-
:root => { :mandatory => false, :type => :string,
|
565
|
+
:root => { :mandatory => false, :type => :string,
|
566
|
+
:default => '.' },
|
559
567
|
:includes => { :mandatory => false, :type => :string_or_array },
|
560
568
|
:excludes => { :mandatory => false, :type => :string_or_array },
|
561
569
|
:dest => { :mandatory => true, :type => :string },
|
562
|
-
:flatten => { :mandatory => false, :type => :boolean,
|
563
|
-
|
564
|
-
:
|
570
|
+
:flatten => { :mandatory => false, :type => :boolean,
|
571
|
+
:default => false },
|
572
|
+
:dotmatch => { :mandatory => false, :type => :boolean,
|
573
|
+
:default => false },
|
574
|
+
:lenient => { :mandatory => false, :type => :boolean,
|
575
|
+
:default => false }
|
565
576
|
}
|
566
577
|
check_parameters(params, params_desc)
|
567
578
|
root = params[:root]
|
@@ -715,11 +726,13 @@ module Bee
|
|
715
726
|
# property: "image_files"
|
716
727
|
def find(params)
|
717
728
|
params_desc = {
|
718
|
-
:root => { :mandatory => false, :type => :string,
|
729
|
+
:root => { :mandatory => false, :type => :string,
|
730
|
+
:default => '.' },
|
719
731
|
:includes => { :mandatory => false, :type => :string_or_array },
|
720
732
|
:excludes => { :mandatory => false, :type => :string_or_array },
|
721
733
|
:property => { :mandatory => true, :type => :string },
|
722
|
-
:dotmatch => { :mandatory => false, :type => :boolean,
|
734
|
+
:dotmatch => { :mandatory => false, :type => :boolean,
|
735
|
+
:default => false },
|
723
736
|
:join => { :mandatory => false, :type => :string }
|
724
737
|
}
|
725
738
|
check_parameters(params, params_desc)
|
@@ -736,6 +749,59 @@ module Bee
|
|
736
749
|
@build.context.set_property(property, files)
|
737
750
|
end
|
738
751
|
|
752
|
+
# Load a YAML file in a given property.
|
753
|
+
#
|
754
|
+
# - prop: the property name to set with YAML parsed content.
|
755
|
+
# - file: the YAML file name to load.
|
756
|
+
#
|
757
|
+
# Example
|
758
|
+
#
|
759
|
+
# - yaml_load:
|
760
|
+
# prop: "my_list"
|
761
|
+
# file: "my_list.yml"
|
762
|
+
def yaml_load(params)
|
763
|
+
params_desc = {
|
764
|
+
:prop => { :mandatory => true, :type => :string },
|
765
|
+
:file => { :mandatory => true, :type => :string }
|
766
|
+
}
|
767
|
+
check_parameters(params, params_desc)
|
768
|
+
prop = params[:prop]
|
769
|
+
file = params[:file]
|
770
|
+
error "YAML file '#{file}' not found" if not File.exists?(file)
|
771
|
+
script = "#{prop} = YAML.load(File.read('#{file}'))"
|
772
|
+
begin
|
773
|
+
@build.context.evaluate_script(script)
|
774
|
+
rescue
|
775
|
+
error "Error loading YAML file '#{file}': #{$!}"
|
776
|
+
end
|
777
|
+
end
|
778
|
+
|
779
|
+
# Dump the content of a given property into a YAML file.
|
780
|
+
#
|
781
|
+
# - prop: the property to dump.
|
782
|
+
# - file: the YAML file name to dump into.
|
783
|
+
#
|
784
|
+
# Example
|
785
|
+
#
|
786
|
+
# - yaml_dump:
|
787
|
+
# prop: "my_list"
|
788
|
+
# file: "my_list.yml"
|
789
|
+
def yaml_dump(params)
|
790
|
+
params_desc = {
|
791
|
+
:prop => { :mandatory => true, :type => :string },
|
792
|
+
:file => { :mandatory => true, :type => :string }
|
793
|
+
}
|
794
|
+
check_parameters(params, params_desc)
|
795
|
+
prop = params[:prop]
|
796
|
+
file = params[:file]
|
797
|
+
script = "File.open('#{file}', 'w') {|f| f.write(YAML.dump(#{prop}))}"
|
798
|
+
begin
|
799
|
+
@build.context.evaluate_script(script)
|
800
|
+
rescue
|
801
|
+
error "Error dumping YAML file '#{file}': #{$!}"
|
802
|
+
end
|
803
|
+
end
|
804
|
+
|
739
805
|
######################################################################
|
740
806
|
# RUBY RELATED TASKS #
|
741
807
|
######################################################################
|
@@ -803,8 +869,10 @@ module Bee
|
|
803
869
|
:root => { :mandatory => false, :type => :string },
|
804
870
|
:includes => { :mandatory => true, :type => :string },
|
805
871
|
:excludes => { :mandatory => false, :type => :string },
|
806
|
-
:dotmatch => { :mandatory => false, :type => :boolean,
|
807
|
-
|
872
|
+
:dotmatch => { :mandatory => false, :type => :boolean,
|
873
|
+
:default => false },
|
874
|
+
:dir => { :mandatory => false, :type => :string,
|
875
|
+
:default => '.' }
|
808
876
|
}
|
809
877
|
check_parameters(params, params_desc)
|
810
878
|
root = params[:root]
|
@@ -838,6 +906,14 @@ module Bee
|
|
838
906
|
# - src: ERB file name (if no 'source').
|
839
907
|
# - dest: file where to store result (if no 'property').
|
840
908
|
# - property: property name where to store result (if no 'dest').
|
909
|
+
# - options: ERB options, a String containing one or more of the
|
910
|
+
# following modifiers:
|
911
|
+
# % enables Ruby code processing for lines beginning with %
|
912
|
+
# <> omit newline for lines starting with <% and ending in %>
|
913
|
+
# > omit newline for lines ending in %>
|
914
|
+
#
|
915
|
+
# For more information ebout ERB syntax, please see documentation at:
|
916
|
+
# http://www.ruby-doc.org/stdlib/libdoc/erb/rdoc/.
|
841
917
|
#
|
842
918
|
# Example
|
843
919
|
#
|
@@ -853,13 +929,15 @@ module Bee
|
|
853
929
|
:source => { :mandatory => false, :type => :string },
|
854
930
|
:src => { :mandatory => false, :type => :string },
|
855
931
|
:dest => { :mandatory => false, :type => :string },
|
856
|
-
:property => { :mandatory => false, :type => :string }
|
932
|
+
:property => { :mandatory => false, :type => :string },
|
933
|
+
:options => { :mandatory => false, :type => :string }
|
857
934
|
}
|
858
935
|
check_parameters(params, params_desc)
|
859
936
|
source = params[:source]
|
860
937
|
src = params[:src]
|
861
938
|
dest = params[:dest]
|
862
939
|
property = params[:property]
|
940
|
+
options = params[:options]
|
863
941
|
error "Must pass one of 'source' or 'src' parameters to erb task" if
|
864
942
|
not source and not src
|
865
943
|
error "Must pass one of 'dest' or 'property' parameters to erb task" if
|
@@ -869,7 +947,11 @@ module Bee
|
|
869
947
|
not File.readable?(src))
|
870
948
|
# load ERB source
|
871
949
|
erb_source = source||File.read(src)
|
872
|
-
|
950
|
+
if options
|
951
|
+
template = ERB.new(erb_source, 0, options)
|
952
|
+
else
|
953
|
+
template = ERB.new(erb_source)
|
954
|
+
end
|
873
955
|
if src
|
874
956
|
puts "Processing ERB '#{src}'"
|
875
957
|
else
|
@@ -1347,6 +1429,78 @@ module Bee
|
|
1347
1429
|
end
|
1348
1430
|
end
|
1349
1431
|
|
1432
|
+
######################################################################
|
1433
|
+
# CONSTRUCTS #
|
1434
|
+
######################################################################
|
1435
|
+
|
1436
|
+
# If construct will evaluate the expression in the 'if' entry and run
|
1437
|
+
# block in the 'then' entry or 'else' entry accordingly.
|
1438
|
+
#
|
1439
|
+
# - if: the condition to evaluate. This is a Ruby expression evaluated
|
1440
|
+
# in the build context.
|
1441
|
+
# - then: block that is evaluated if confition in if is true.
|
1442
|
+
# - else: block that is evaluated if confition in if is false.
|
1443
|
+
#
|
1444
|
+
# Example
|
1445
|
+
#
|
1446
|
+
# - if: RUBY_PLATFORM =~ /darwin/
|
1447
|
+
# then:
|
1448
|
+
# - print: Hello, I'm a Mac
|
1449
|
+
# else:
|
1450
|
+
# - print: Hello, I'm a PC
|
1451
|
+
def if
|
1452
|
+
end
|
1453
|
+
|
1454
|
+
# While construct will run the block in the 'do' entry while the
|
1455
|
+
# condition in the 'while' entry is true.
|
1456
|
+
#
|
1457
|
+
# - while: the condition to evaluate. This is a Ruby expression evaluated
|
1458
|
+
# in the build context.
|
1459
|
+
# - do: the block to run while the condition is true.
|
1460
|
+
#
|
1461
|
+
# Example:
|
1462
|
+
#
|
1463
|
+
# - while: i > 0
|
1464
|
+
# do:
|
1465
|
+
# - print: :i
|
1466
|
+
# - rb: i -= 1
|
1467
|
+
def while
|
1468
|
+
end
|
1469
|
+
|
1470
|
+
# For construct iterates on a list in the 'in' entry, putting values in
|
1471
|
+
# a property which name is in the 'for' entry and running the block in
|
1472
|
+
# the 'do' entry for each value.
|
1473
|
+
#
|
1474
|
+
# - for: the name of the property which receives values of the iteration.
|
1475
|
+
# - in: a list on which to iterate. This can be a list or a ruby
|
1476
|
+
# expression to evaluate in the context of the build to obtain the
|
1477
|
+
# Enumerable on which to iterate.
|
1478
|
+
# - do: the block to run at each iteration.
|
1479
|
+
#
|
1480
|
+
# Example
|
1481
|
+
#
|
1482
|
+
# - for: file
|
1483
|
+
# in: [foo, bar]
|
1484
|
+
# do:
|
1485
|
+
# - print: "Creating #{file}..."
|
1486
|
+
# - touch: :file
|
1487
|
+
#
|
1488
|
+
# To iterate five times, we could write (using a Ruby Range):
|
1489
|
+
#
|
1490
|
+
# - for: i
|
1491
|
+
# in: (1..5)
|
1492
|
+
# do:
|
1493
|
+
# - print: :i
|
1494
|
+
#
|
1495
|
+
# To iterate on files in current directory, we could write:
|
1496
|
+
#
|
1497
|
+
# - for: file
|
1498
|
+
# in: "Dir.glob('*')"
|
1499
|
+
# do:
|
1500
|
+
# - print: :file
|
1501
|
+
def for
|
1502
|
+
end
|
1503
|
+
|
1350
1504
|
end
|
1351
1505
|
|
1352
1506
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bee
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michel Casabianca & Contributors
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2010-02-
|
12
|
+
date: 2010-02-08 00:00:00 +01:00
|
13
13
|
default_executable: bee
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -42,28 +42,28 @@ extra_rdoc_files:
|
|
42
42
|
- README
|
43
43
|
- LICENSE
|
44
44
|
files:
|
45
|
-
- bin/bee
|
46
45
|
- bin/bee.bat
|
47
|
-
-
|
46
|
+
- bin/bee
|
48
47
|
- lib/bee_console.rb
|
49
48
|
- lib/bee_task.rb
|
50
49
|
- lib/bee_task_default.rb
|
51
50
|
- lib/bee_util.rb
|
52
|
-
-
|
51
|
+
- lib/bee.rb
|
52
|
+
- egg/package.yml
|
53
|
+
- egg/package/test.erb
|
54
|
+
- egg/package/test_suite.rb
|
55
|
+
- egg/package/gem_spec.erb
|
53
56
|
- egg/package/build.erb
|
54
|
-
- egg/package/egg.yml
|
55
|
-
- egg/package/egg_build.erb
|
56
|
-
- egg/package/egg_launcher.erb
|
57
57
|
- egg/package/egg_script.rb
|
58
|
-
- egg/package/gem_spec.erb
|
59
58
|
- egg/package/license
|
59
|
+
- egg/package/egg_launcher.erb
|
60
60
|
- egg/package/readme.erb
|
61
|
-
- egg/package/
|
61
|
+
- egg/package/bee_task.erb
|
62
|
+
- egg/package/egg.yml
|
62
63
|
- egg/package/test_build.erb
|
63
|
-
- egg/package/
|
64
|
+
- egg/package/egg_build.erb
|
64
65
|
- egg/package/test_build_listener.rb
|
65
|
-
- egg/package/
|
66
|
-
- egg/package.yml
|
66
|
+
- egg/package/test_build.rb
|
67
67
|
- README
|
68
68
|
- LICENSE
|
69
69
|
has_rdoc: true
|