bee 0.6.1 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README +1 -1
- data/egg/sinatra.yml +55 -0
- data/egg/sinatra/build.yml +45 -0
- data/egg/sinatra/server.rb +10 -0
- data/lib/bee.rb +27 -1
- data/lib/bee_console.rb +6 -1
- data/lib/bee_task.rb +2 -0
- data/lib/bee_task_default.rb +108 -15
- metadata +5 -2
data/README
CHANGED
data/egg/sinatra.yml
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
- build: package
|
2
|
+
default: all
|
3
|
+
description: "Generate a Sinatra project"
|
4
|
+
|
5
|
+
- properties:
|
6
|
+
- name: sinatra
|
7
|
+
- description: |
|
8
|
+
This script will create a Sinatra project. Generated build file has a
|
9
|
+
target 'run' to run the server, 'zip' to generate a distribution archive
|
10
|
+
and 'clean' to delete generated files.
|
11
|
+
|
12
|
+
- target: welcome
|
13
|
+
description: "Print information message"
|
14
|
+
script:
|
15
|
+
- print: :description
|
16
|
+
|
17
|
+
- target: prompt
|
18
|
+
depends: welcome
|
19
|
+
description: "Prompt for project information"
|
20
|
+
script:
|
21
|
+
- print: "Please answer following questions to generate the project:"
|
22
|
+
- prompt:
|
23
|
+
message: "What is the project's name?"
|
24
|
+
default: :name
|
25
|
+
property: name
|
26
|
+
|
27
|
+
- target: generate
|
28
|
+
depends: prompt
|
29
|
+
description: "Generate project"
|
30
|
+
script:
|
31
|
+
- print: "Generating project..."
|
32
|
+
- rb: |
|
33
|
+
error "A directory named '#{name}' already exists, aborting" if
|
34
|
+
File.exists?("#{here}/#{name}")
|
35
|
+
- mkdir: "#{here}/#{name}"
|
36
|
+
- erb:
|
37
|
+
src: "#{base}/sinatra/build.yml"
|
38
|
+
dest: "#{here}/#{name}/build.yml"
|
39
|
+
- cp:
|
40
|
+
src: "#{base}/sinatra/server.rb"
|
41
|
+
dest: "#{here}/#{name}/server.rb"
|
42
|
+
|
43
|
+
- target: customization
|
44
|
+
depends: generate
|
45
|
+
description: "Print information about project customization"
|
46
|
+
script:
|
47
|
+
- print: |
|
48
|
+
Project has been generated in directory '#{name}'. Type 'bee -b' to print
|
49
|
+
information about generated build file. To start server, type 'b run'. To
|
50
|
+
send a request, call URL 'http://localhost:4567/hello/world', typing
|
51
|
+
'b call' for instance (which requires curl).
|
52
|
+
Enjoy!
|
53
|
+
|
54
|
+
- target: all
|
55
|
+
depends: [welcome, prompt, generate, customization]
|
@@ -0,0 +1,45 @@
|
|
1
|
+
- build: <%= name %>
|
2
|
+
description: Project <%= name %>
|
3
|
+
default: all
|
4
|
+
|
5
|
+
- properties:
|
6
|
+
- name: "<%= name %>"
|
7
|
+
- version: "0.0.0"
|
8
|
+
- build: "build"
|
9
|
+
- zip_prefix: "#{name}-#{version}"
|
10
|
+
- zip_file: "#{build}/#{zip_prefix}.zip"
|
11
|
+
- url: "http://localhost:4567/hello"
|
12
|
+
- clean_dirs: [:build]
|
13
|
+
- clean_files: ["**/*~", "**/.#*", "**/.DS_Store"]
|
14
|
+
|
15
|
+
- target: run
|
16
|
+
description: Run server
|
17
|
+
script:
|
18
|
+
- "./server.rb"
|
19
|
+
|
20
|
+
- target: call
|
21
|
+
description: Call server
|
22
|
+
script:
|
23
|
+
- get:
|
24
|
+
url: "#{url}/World"
|
25
|
+
prop: response
|
26
|
+
- print: :response
|
27
|
+
|
28
|
+
- target: zip
|
29
|
+
description: Generate a ZIP archive
|
30
|
+
script:
|
31
|
+
- mkdir: :build
|
32
|
+
- zip:
|
33
|
+
includes: "server.rb"
|
34
|
+
prefix: :zip_prefix
|
35
|
+
dest: :zip_file
|
36
|
+
|
37
|
+
- target: clean
|
38
|
+
description: Clean generated files
|
39
|
+
script:
|
40
|
+
- rmdir: :clean_dirs
|
41
|
+
- rm: :clean_files
|
42
|
+
|
43
|
+
- target: all
|
44
|
+
depends: [clean, zip]
|
45
|
+
description: Generate the whole project
|
data/lib/bee.rb
CHANGED
@@ -629,6 +629,9 @@ module Bee
|
|
629
629
|
# for construct
|
630
630
|
elsif construct.keys.include?('for')
|
631
631
|
construct_for(construct, dry)
|
632
|
+
# try construct
|
633
|
+
elsif construct.keys.include?('try')
|
634
|
+
construct_try(construct, dry)
|
632
635
|
else
|
633
636
|
error "Unknown construct '#{construct.keys.join('-')}'"
|
634
637
|
end
|
@@ -711,6 +714,29 @@ module Bee
|
|
711
714
|
end
|
712
715
|
end
|
713
716
|
|
717
|
+
# Run try-catch construct.
|
718
|
+
# - task: the construct as a hash.
|
719
|
+
# - dry: tells if we run in dry mode.
|
720
|
+
def construct_try(task, dry)
|
721
|
+
# test entries
|
722
|
+
error "Try-catch construct must include 'catch' entry" if
|
723
|
+
not task.keys.include?('catch')
|
724
|
+
unknown_keys = task.keys - ['try', 'catch']
|
725
|
+
error "Try-catch construct may only include 'try' and 'catch' entries" if
|
726
|
+
unknown_keys.length > 0
|
727
|
+
error "Try entry in try-catch construct must be a list" if
|
728
|
+
not task['try'].kind_of?(Array)
|
729
|
+
error "Catch entry in try-catch construct must be a list" if
|
730
|
+
not task['catch'].kind_of?(Array)
|
731
|
+
# try and catch errors
|
732
|
+
begin
|
733
|
+
run_block(task['try'], dry)
|
734
|
+
rescue
|
735
|
+
@targets.build.listener.recover if @targets.build.listener
|
736
|
+
run_block(task['catch'], dry)
|
737
|
+
end
|
738
|
+
end
|
739
|
+
|
714
740
|
# Run a block, that is a list of tasks.
|
715
741
|
# - block: the block to run as a list of tasks.
|
716
742
|
# - dry: tells if we run in dry mode.
|
@@ -776,7 +802,7 @@ module Bee
|
|
776
802
|
|
777
803
|
# Return list of properties (as local variables of binding).
|
778
804
|
def properties
|
779
|
-
return eval('local_variables', @context_binding)
|
805
|
+
return eval('local_variables', @context_binding).map{ |var| var.to_s }
|
780
806
|
end
|
781
807
|
|
782
808
|
# Evaluate a script in context.
|
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.7.0 http://bee.rubyforge.org
|
64
64
|
|
65
65
|
EOF
|
66
66
|
|
@@ -621,6 +621,11 @@ EOF
|
|
621
621
|
raise Bee::Util::BuildError.new(message)
|
622
622
|
end
|
623
623
|
|
624
|
+
# Recover from a previous error (catching it for instance).
|
625
|
+
def recover
|
626
|
+
@success = true
|
627
|
+
end
|
628
|
+
|
624
629
|
# Print text on the console.
|
625
630
|
# - text: text to print.
|
626
631
|
def print(text)
|
data/lib/bee_task.rb
CHANGED
@@ -73,6 +73,7 @@ module Bee
|
|
73
73
|
when :string_or_array
|
74
74
|
error "#{task} '#{param}' parameter must be a string or an array" unless
|
75
75
|
params[param.to_s].kind_of?(String) or params[param.to_s].kind_of?(Array)
|
76
|
+
params[param.to_s] = Array(params[param.to_s])
|
76
77
|
when :string_or_integer
|
77
78
|
error "#{task} '#{param}' parameter must be a string or an integer" unless
|
78
79
|
params[param.to_s].kind_of?(String) or params[param.to_s].kind_of?(Integer)
|
@@ -119,6 +120,7 @@ module Bee
|
|
119
120
|
Dir.chdir(root) if root
|
120
121
|
included = []
|
121
122
|
includes = '**/*' if not includes
|
123
|
+
includes = Array(includes)
|
122
124
|
for include in includes
|
123
125
|
error "includes must be a glob or a list of globs" unless
|
124
126
|
include.kind_of?(String)
|
data/lib/bee_task_default.rb
CHANGED
@@ -18,6 +18,7 @@ require 'bee_task'
|
|
18
18
|
require 'bee_util'
|
19
19
|
require 'erb'
|
20
20
|
require 'fileutils'
|
21
|
+
require 'net/smtp'
|
21
22
|
|
22
23
|
module Bee
|
23
24
|
|
@@ -130,6 +131,21 @@ module Bee
|
|
130
131
|
@build.context.set_property(property, value)
|
131
132
|
end
|
132
133
|
|
134
|
+
# Trow a build error with a given message.
|
135
|
+
#
|
136
|
+
# - message: the error message. Will be printed on the console as the
|
137
|
+
# build failure reason.
|
138
|
+
#
|
139
|
+
# Example
|
140
|
+
#
|
141
|
+
# - if: "not File.exists?('/etc/config')"
|
142
|
+
# then:
|
143
|
+
# - throw: "No /etc/config file found!"
|
144
|
+
def throw(message)
|
145
|
+
error "throw parameter must be a string" if not message.kind_of?(String)
|
146
|
+
error message
|
147
|
+
end
|
148
|
+
|
133
149
|
# Get a given URL and store its content in a given file. Parameters
|
134
150
|
# is a Hash with following entries:
|
135
151
|
#
|
@@ -137,6 +153,8 @@ module Bee
|
|
137
153
|
# - dest: destination file. Optional, defaults to retrieved file name
|
138
154
|
# in current directory. If destination is a directory, file is saved
|
139
155
|
# in destination directory with the name of the retrieved file.
|
156
|
+
# - prop: Property to set with content of the response body. Optional
|
157
|
+
# defaults to output in a file.
|
140
158
|
# - limit: the redirections limit. Optional, defaults to 10.
|
141
159
|
#
|
142
160
|
# Example
|
@@ -145,19 +163,23 @@ module Bee
|
|
145
163
|
# url: http://rubyforge.org/frs/download.php/22185/bee-0.4.0.zip
|
146
164
|
def get(parameters)
|
147
165
|
params_desc = {
|
148
|
-
:url => { :mandatory => true,
|
149
|
-
:dest => { :mandatory => false,
|
150
|
-
:
|
166
|
+
:url => { :mandatory => true, :type => :string },
|
167
|
+
:dest => { :mandatory => false, :type => :string },
|
168
|
+
:prop => { :mandatory => false, :type => :string },
|
169
|
+
:limit => { :mandatory => false, :type => :integer, :default => 10 }
|
151
170
|
}
|
152
171
|
check_parameters(parameters, params_desc)
|
153
172
|
url = parameters[:url]
|
154
173
|
dest = parameters[:dest]
|
155
|
-
|
174
|
+
prop = parameters[:prop]
|
175
|
+
if not dest and not prop
|
156
176
|
destination = File.basename(url)
|
157
|
-
elsif File.directory?(dest)
|
177
|
+
elsif dest and File.directory?(dest)
|
158
178
|
destination = File.join(dest, File.basename(url))
|
159
|
-
|
179
|
+
elsif dest
|
160
180
|
destination = dest
|
181
|
+
else
|
182
|
+
destination = nil
|
161
183
|
end
|
162
184
|
limit = parameters[:limit]
|
163
185
|
puts "Getting URL '#{url}'..."
|
@@ -166,12 +188,65 @@ module Bee
|
|
166
188
|
rescue Exception
|
167
189
|
error "Error getting URL: #{$!}"
|
168
190
|
end
|
169
|
-
|
191
|
+
if destination
|
192
|
+
todir = File.dirname(destination)
|
193
|
+
begin
|
194
|
+
FileUtils.makedirs(todir) if not File.exists?(todir)
|
195
|
+
File.open(destination, 'w') { |file| file.write(content) }
|
196
|
+
rescue Exception
|
197
|
+
error "Error saving file: #{$!}"
|
198
|
+
end
|
199
|
+
end
|
200
|
+
if prop
|
201
|
+
@build.context.set_property(prop, content)
|
202
|
+
end
|
203
|
+
end
|
204
|
+
|
205
|
+
|
206
|
+
# Send an email using SMTP.
|
207
|
+
#
|
208
|
+
# - from: The sender of the email.
|
209
|
+
# - to: Recipient of the email. This may be a list of recipients.
|
210
|
+
# - subject: The subject of the email.
|
211
|
+
# - message: The body of the email.
|
212
|
+
# - smtp: The address of the SMTP server.
|
213
|
+
#
|
214
|
+
# Example
|
215
|
+
#
|
216
|
+
# - mail:
|
217
|
+
# from: "foo@bee.com"
|
218
|
+
# to: "bar@bee.com"
|
219
|
+
# subject: "Bee Release 0.6.2"
|
220
|
+
# message: "Hi! There is a new Bee release!"
|
221
|
+
# smtp: "smtp.bee.com"
|
222
|
+
def mail(parameters)
|
223
|
+
params_desc = {
|
224
|
+
:from => { :mandatory => true, :type => :string },
|
225
|
+
:to => { :mandatory => true, :type => :string_or_array },
|
226
|
+
:subject => { :mandatory => true, :type => :string },
|
227
|
+
:message => { :mandatory => true, :type => :string },
|
228
|
+
:smtp => { :mandatory => true, :type => :string },
|
229
|
+
}
|
230
|
+
check_parameters(parameters, params_desc)
|
231
|
+
from = parameters[:from]
|
232
|
+
to = Array(parameters[:to])
|
233
|
+
subject = parameters[:subject]
|
234
|
+
message = parameters[:message]
|
235
|
+
smtp = parameters[:smtp]
|
236
|
+
body = <<EOF
|
237
|
+
From: #{from}
|
238
|
+
To: #{to.join(', ')}
|
239
|
+
Subject: #{subject}
|
240
|
+
|
241
|
+
#{message}
|
242
|
+
EOF
|
243
|
+
puts "Sending email about '#{subject}'..."
|
170
244
|
begin
|
171
|
-
|
172
|
-
|
245
|
+
Net::SMTP.start(smtp) do |smtp_server|
|
246
|
+
smtp_server.send_message(body, from, to)
|
247
|
+
end
|
173
248
|
rescue Exception
|
174
|
-
error "Error
|
249
|
+
error "Error sending email: #{$!}"
|
175
250
|
end
|
176
251
|
end
|
177
252
|
|
@@ -364,6 +439,7 @@ module Bee
|
|
364
439
|
def mkdir(dirs)
|
365
440
|
error "mkdir parameter must a String or an array of Strings" unless
|
366
441
|
dirs.kind_of?(String) or dirs.kind_of?(Array)
|
442
|
+
dirs = Array(dirs)
|
367
443
|
for dir in dirs
|
368
444
|
error "mkdir parameter must a String or an array of Strings" unless
|
369
445
|
dir.kind_of?(String)
|
@@ -623,6 +699,7 @@ module Bee
|
|
623
699
|
def rm(globs)
|
624
700
|
error "rm parameter is a String or Array of Strings" unless
|
625
701
|
globs.kind_of?(String) or globs.kind_of?(Array)
|
702
|
+
globs = Array(globs)
|
626
703
|
for glob in globs
|
627
704
|
error "rm parameter is a String or Array of Strings" unless
|
628
705
|
glob.kind_of?(String)
|
@@ -646,9 +723,9 @@ module Bee
|
|
646
723
|
#
|
647
724
|
# - rmrf: :build
|
648
725
|
def rmrf(globs)
|
649
|
-
globs = [globs] if globs.kind_of?(String)
|
650
726
|
error "rmrf parameter is a String or an Array of Strings" unless
|
651
727
|
globs.kind_of?(String) or globs.kind_of?(Array)
|
728
|
+
globs = Array(globs)
|
652
729
|
for glob in globs
|
653
730
|
error "rmrf parameter is a String or an Array of Strings" unless
|
654
731
|
glob.kind_of?(String)
|
@@ -676,9 +753,9 @@ module Bee
|
|
676
753
|
#
|
677
754
|
# - touch: '#{target}/classes/**/*.class'
|
678
755
|
def touch(globs)
|
679
|
-
globs = [globs] if globs.kind_of?(String)
|
680
756
|
error "touch parameter is a String or an Array of Strings" unless
|
681
757
|
globs.kind_of?(String) or globs.kind_of?(Array)
|
758
|
+
globs = Array(globs)
|
682
759
|
files = []
|
683
760
|
for glob in globs
|
684
761
|
error "touch parameter is a String or an Array of Strings" unless
|
@@ -864,7 +941,6 @@ module Bee
|
|
864
941
|
# dir: "test"
|
865
942
|
def test(params)
|
866
943
|
require 'test/unit'
|
867
|
-
require 'test/unit/testresult'
|
868
944
|
params_desc = {
|
869
945
|
:root => { :mandatory => false, :type => :string },
|
870
946
|
:includes => { :mandatory => true, :type => :string },
|
@@ -1000,7 +1076,8 @@ module Bee
|
|
1000
1076
|
:root => { :mandatory => false, :type => :string },
|
1001
1077
|
:includes => { :mandatory => true, :type => :string_or_array },
|
1002
1078
|
:excludes => { :mandatory => false, :type => :string_or_array },
|
1003
|
-
:dotmatch => { :mandatory => false, :type => :boolean,
|
1079
|
+
:dotmatch => { :mandatory => false, :type => :boolean,
|
1080
|
+
:default => false },
|
1004
1081
|
:dest => { :mandatory => true, :type => :string },
|
1005
1082
|
:options => { :mandatory => false, :type => :string_or_array }
|
1006
1083
|
}
|
@@ -1013,7 +1090,7 @@ module Bee
|
|
1013
1090
|
options = params[:options]
|
1014
1091
|
files = filter_files(includes, excludes, root, dotmatch)
|
1015
1092
|
command_line = ['-S', '-o', dest]
|
1016
|
-
command_line
|
1093
|
+
command_line += options if options
|
1017
1094
|
command_line += files
|
1018
1095
|
begin
|
1019
1096
|
rdoc = RDoc::RDoc.new
|
@@ -1501,6 +1578,22 @@ module Bee
|
|
1501
1578
|
def for
|
1502
1579
|
end
|
1503
1580
|
|
1581
|
+
# Try construct will run the block in the 'try' entry and will switch to
|
1582
|
+
# block in the 'catch' entry if an error occurs.
|
1583
|
+
#
|
1584
|
+
# - try: the block to run.
|
1585
|
+
# - catch: the block to switch to if an error occurs.
|
1586
|
+
#
|
1587
|
+
# Example:
|
1588
|
+
#
|
1589
|
+
# - try:
|
1590
|
+
# - print: "In the try block"
|
1591
|
+
# - throw: "Something went terribly wrong!"
|
1592
|
+
# catch:
|
1593
|
+
# - print: "An error occured"
|
1594
|
+
def try
|
1595
|
+
end
|
1596
|
+
|
1504
1597
|
end
|
1505
1598
|
|
1506
1599
|
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.7.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-17 00:00:00 +01:00
|
13
13
|
default_executable: bee
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -64,6 +64,9 @@ files:
|
|
64
64
|
- egg/package/test_build_listener.rb
|
65
65
|
- egg/package/test_suite.rb
|
66
66
|
- egg/package.yml
|
67
|
+
- egg/sinatra/build.yml
|
68
|
+
- egg/sinatra/server.rb
|
69
|
+
- egg/sinatra.yml
|
67
70
|
- README
|
68
71
|
- LICENSE
|
69
72
|
has_rdoc: true
|