bee 0.3.0 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README +1 -1
- data/lib/bee_default_context.rb +65 -34
- data/test/tc_bee_default_tasks.rb +298 -0
- metadata +3 -2
data/README
CHANGED
data/lib/bee_default_context.rb
CHANGED
@@ -69,11 +69,17 @@ end
|
|
69
69
|
# Make a directory and parent directories if necessary. Doesn't complain if
|
70
70
|
# directory already exists.
|
71
71
|
# - dir: directory to create.
|
72
|
-
def mkdir(
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
72
|
+
def mkdir(dirs)
|
73
|
+
require 'fileutils'
|
74
|
+
dirs = evaluate_object(dirs)
|
75
|
+
error "mkdir parameter must a String or an array of Strings" unless
|
76
|
+
dirs.kind_of?(String) or dirs.kind_of?(Array)
|
77
|
+
for dir in dirs
|
78
|
+
dir = evaluate_object(dir)
|
79
|
+
error "mkdir parameter must a String or an array of Strings" unless
|
80
|
+
dir.kind_of?(String)
|
81
|
+
FileUtils.makedirs(dir)
|
82
|
+
end
|
77
83
|
end
|
78
84
|
|
79
85
|
# Copy a files or directoris to destination file or directory. Parameter is a
|
@@ -88,14 +94,19 @@ def cp(params)
|
|
88
94
|
}
|
89
95
|
check_task_parameters(params, params_desc)
|
90
96
|
src = evaluate_object(params['src'])
|
97
|
+
error "cp 'src' parameter must a glob or a list of globs" unless
|
98
|
+
src.kind_of?(String) or src.kind_of?(Array)
|
91
99
|
dest = evaluate_object(params['dest'])
|
100
|
+
error "cp 'dest' parameter must a glob or a list of globs" unless
|
101
|
+
dest.kind_of?(String)
|
92
102
|
files = []
|
93
103
|
for element in src
|
104
|
+
error "cp 'src' parameter must a glob or a list of globs" unless
|
105
|
+
element.kind_of?(String)
|
94
106
|
files += Dir.glob(element)
|
95
107
|
end
|
96
|
-
|
97
|
-
|
98
|
-
end
|
108
|
+
files = files[0] if files.length == 1
|
109
|
+
FileUtils.cp_r(files, dest)
|
99
110
|
end
|
100
111
|
|
101
112
|
# Move source file(s) or directories to dest file or directory. Parameter is
|
@@ -110,37 +121,50 @@ def mv(params)
|
|
110
121
|
}
|
111
122
|
check_task_parameters(params, params_desc)
|
112
123
|
src = evaluate_object(params['src'])
|
124
|
+
error "mv 'src' parameter must a glob or a list of globs" unless
|
125
|
+
src.kind_of?(String) or src.kind_of?(Array)
|
113
126
|
dest = evaluate_object(params['dest'])
|
127
|
+
error "mv 'dest' parameter must a glob or a list of globs" unless
|
128
|
+
dest.kind_of?(String)
|
114
129
|
files = []
|
115
130
|
for element in src
|
131
|
+
error "mv 'src' parameter must a glob or a list of globs" unless
|
132
|
+
element.kind_of?(String)
|
116
133
|
files += Dir.glob(element)
|
117
134
|
end
|
118
|
-
|
119
|
-
|
120
|
-
end
|
135
|
+
files = files[0] if files.length == 1
|
136
|
+
FileUtils.mv(files, dest)
|
121
137
|
end
|
122
138
|
|
123
139
|
# Delete files for a given glob. Parameter is a string for glob of files
|
124
140
|
# to delete.
|
125
|
-
def rm(
|
141
|
+
def rm(globs)
|
126
142
|
require 'fileutils'
|
127
|
-
|
128
|
-
error "rm parameter is a String" unless
|
129
|
-
|
130
|
-
for
|
131
|
-
|
143
|
+
globs = evaluate_object(globs)
|
144
|
+
error "rm parameter is a String or Array of Strings" unless
|
145
|
+
globs.kind_of?(String) or globs.kind_of?(Array)
|
146
|
+
for glob in globs
|
147
|
+
files = Dir.glob(glob)
|
148
|
+
for file in files
|
149
|
+
FileUtils.rm_f(file)
|
150
|
+
end
|
132
151
|
end
|
133
152
|
end
|
134
153
|
|
135
154
|
# Delete directories recursively. Parameter is a string for glob of directories
|
136
155
|
# to delete.
|
137
|
-
def rmdir(
|
156
|
+
def rmdir(globs)
|
138
157
|
require 'fileutils'
|
139
|
-
|
140
|
-
error "rm parameter is a String" unless
|
141
|
-
|
142
|
-
for
|
143
|
-
|
158
|
+
globs = evaluate_object(globs)
|
159
|
+
error "rm parameter is a String or an Array of Strings" unless
|
160
|
+
globs.kind_of?(String) or globs.kind_of?(Array)
|
161
|
+
for glob in globs
|
162
|
+
error "rm parameter is a String or an Array of Strings" unless
|
163
|
+
glob.kind_of?(String)
|
164
|
+
dirs = Dir.glob(glob)
|
165
|
+
for dir in dirs
|
166
|
+
FileUtils.rm_rf(dir)
|
167
|
+
end
|
144
168
|
end
|
145
169
|
end
|
146
170
|
|
@@ -155,9 +179,13 @@ def find(parameters)
|
|
155
179
|
}
|
156
180
|
check_task_parameters(parameters, params_desc)
|
157
181
|
files = []
|
158
|
-
globs = parameters['files']
|
182
|
+
globs = evaluate_object(parameters['files'])
|
183
|
+
error "find 'files' parameter is a String or an Array of Strings" unless
|
184
|
+
globs.kind_of?(String) or globs.kind_of?(Array)
|
159
185
|
toprop = evaluate_object(parameters['toprop'])
|
160
186
|
for glob in globs
|
187
|
+
error "find 'files' parameter is a String or an Array of Strings" unless
|
188
|
+
glob.kind_of?(String)
|
161
189
|
files += Dir.glob(evaluate_object(glob))
|
162
190
|
end
|
163
191
|
set(toprop, files)
|
@@ -321,11 +349,13 @@ Example:
|
|
321
349
|
|
322
350
|
"mkdir" =>
|
323
351
|
"Make a directory and parent directories if necessary. Doesn't complain if
|
324
|
-
directory already exists. Parameter is directory to create as a String
|
352
|
+
directory already exists. Parameter is directory to create as a String or a
|
353
|
+
list of directories as Strings.
|
325
354
|
|
326
355
|
Example:
|
327
356
|
|
328
|
-
- mkdir \"foo/bar\"
|
357
|
+
- mkdir: \"foo/bar\"
|
358
|
+
- mkdir: [\"foo\", \"bar\"]",
|
329
359
|
|
330
360
|
"cp" =>
|
331
361
|
"Copy files or directories to destination file or directory. Parameter is a
|
@@ -341,23 +371,24 @@ Example:
|
|
341
371
|
dest: :doc",
|
342
372
|
|
343
373
|
"mv" =>
|
344
|
-
"Move source file(s) or
|
345
|
-
a
|
374
|
+
"Move source file(s) or directory(ies) to dest file or directory. Parameter is
|
375
|
+
a Hash with following entries:
|
346
376
|
|
347
377
|
- src: glob for files and directories to move.
|
348
378
|
- dest: file or directory to move file(s) to.
|
349
379
|
|
350
380
|
Example:
|
351
381
|
|
352
|
-
- mv: { src:
|
382
|
+
- mv: { src: \"**/*.java\", dest: \"trash\" }",
|
353
383
|
|
354
384
|
"rm" =>
|
355
|
-
"Delete files for a given glob. Parameter is a
|
356
|
-
|
385
|
+
"Delete files for a given glob or list of globs. Parameter is a glob or list
|
386
|
+
of globs for files to delete.
|
357
387
|
|
358
388
|
Example:
|
359
389
|
|
360
|
-
- rm: \"**/*~\"
|
390
|
+
- rm: \"**/*~\"
|
391
|
+
- rm: [\"**/*~\", \"**/.DS_Store\"]",
|
361
392
|
|
362
393
|
"rmdir" =>
|
363
394
|
"Delete directories recursively. Parameter is a string for glob of directories
|
@@ -368,8 +399,8 @@ Example:
|
|
368
399
|
- rmdir: :build",
|
369
400
|
|
370
401
|
"find" =>
|
371
|
-
"Find files for a
|
372
|
-
a Hash with entries:
|
402
|
+
"Find files for a glob or list of globs and store list in a property.
|
403
|
+
Parameter is a Hash with entries:
|
373
404
|
|
374
405
|
- files: glob or list of globs for files to look for.
|
375
406
|
- toprop: name of the property to set.
|
@@ -0,0 +1,298 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
# Copyright 2006 Michel Casabianca <casa@sweetohm.net>
|
4
|
+
#
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
# you may not use this file except in compliance with the License.
|
7
|
+
# You may obtain a copy of the License at
|
8
|
+
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
#
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
# See the License for the specific language governing permissions and
|
15
|
+
# limitations under the License.
|
16
|
+
|
17
|
+
require 'test/unit'
|
18
|
+
$:.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
19
|
+
require 'bee.rb'
|
20
|
+
require 'fileutils'
|
21
|
+
|
22
|
+
class TestBeeDefaultTasks < Test::Unit::TestCase
|
23
|
+
|
24
|
+
# Temporary directory.
|
25
|
+
TEMP_DIR = 'tmp'
|
26
|
+
|
27
|
+
# Constructor.
|
28
|
+
def initialize(*args)
|
29
|
+
super(*args)
|
30
|
+
@home = File.expand_path(File.dirname(__FILE__))
|
31
|
+
@working_dir = Dir.getwd
|
32
|
+
@tmp_dir = File.join(@home, TEMP_DIR)
|
33
|
+
# try to create temporary directory and disable tests if we can't
|
34
|
+
begin
|
35
|
+
FileUtils.makedirs(@tmp_dir)
|
36
|
+
@run_tests = true
|
37
|
+
rescue
|
38
|
+
@run_tests = false
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
# Run before any test:
|
43
|
+
# - Create temporary directory.
|
44
|
+
# - Create a context object and load tasks in it.
|
45
|
+
def setup
|
46
|
+
FileUtils.makedirs(@tmp_dir)
|
47
|
+
@context = Bee::Context.new
|
48
|
+
script = File.read(File.join(@home, '..', 'lib', 'bee_default_context.rb'))
|
49
|
+
@context.evaluate_script(script)
|
50
|
+
end
|
51
|
+
|
52
|
+
# Run after any test: delete temporary directory.
|
53
|
+
def teardown
|
54
|
+
FileUtils.rm_rf(@tmp_dir)
|
55
|
+
Dir.chdir(@working_dir)
|
56
|
+
end
|
57
|
+
|
58
|
+
############################ UTILITY FUNCTIONS ##########################
|
59
|
+
|
60
|
+
# Clean temporary directory.
|
61
|
+
def clean_tmp
|
62
|
+
FileUtils.rm_rf(@tmp_dir)
|
63
|
+
FileUtils.makedirs(@tmp_dir)
|
64
|
+
end
|
65
|
+
|
66
|
+
# Create a given file in tmp directory with its name as contents.
|
67
|
+
# - name: file name, relative to temporary directory.
|
68
|
+
def create_file(name)
|
69
|
+
File.open(name, 'w') { |file| file.write(name) }
|
70
|
+
end
|
71
|
+
|
72
|
+
# Assert file exists and test its contents.
|
73
|
+
def assert_file(file, contents)
|
74
|
+
assert(File.exists?(file))
|
75
|
+
text = File.read(file)
|
76
|
+
assert_equal(contents, text)
|
77
|
+
end
|
78
|
+
|
79
|
+
############################ TEST FUNCTIONS #############################
|
80
|
+
|
81
|
+
# Test task print.
|
82
|
+
# TODO: implement.
|
83
|
+
def test_task_print
|
84
|
+
return unless @run_tests
|
85
|
+
end
|
86
|
+
|
87
|
+
# Test task cat.
|
88
|
+
# TODO: implement.
|
89
|
+
def test_task_cat
|
90
|
+
return unless @run_tests
|
91
|
+
end
|
92
|
+
|
93
|
+
# Test task cd.
|
94
|
+
def test_task_cd
|
95
|
+
return unless @run_tests
|
96
|
+
working_dir = File.expand_path(File.dirname(__FILE__))
|
97
|
+
# test nominal case
|
98
|
+
@context.cd(@tmp_dir)
|
99
|
+
expected = @tmp_dir
|
100
|
+
actual = Dir.getwd
|
101
|
+
assert_equal(expected, actual)
|
102
|
+
# test changing to a directory that doesn't exists
|
103
|
+
begin
|
104
|
+
dir = File.join(@tmp_dir, 'lkjqzcjv')
|
105
|
+
@context.cd(dir)
|
106
|
+
flunk "Should have raised an Errno::ENOENT"
|
107
|
+
rescue Errno::ENOENT
|
108
|
+
end
|
109
|
+
# test bad arguments
|
110
|
+
begin
|
111
|
+
@context.cd(Object.new)
|
112
|
+
flunk "Should have raised a BuildError"
|
113
|
+
rescue Bee::BuildError
|
114
|
+
expected = 'cd parameter is a String'
|
115
|
+
actual = $!.message
|
116
|
+
assert_equal(expected, actual)
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
# Test task mkdir.
|
121
|
+
def test_task_mkdir
|
122
|
+
return unless @run_tests
|
123
|
+
# nominal case with a single recursive dir
|
124
|
+
dir = File.join(@tmp_dir, 'foo', 'bar')
|
125
|
+
@context.mkdir(dir)
|
126
|
+
expected = true
|
127
|
+
actual = File.exists?(dir) and File.directory?(dir)
|
128
|
+
assert_equal(expected, actual)
|
129
|
+
# nominal case with a list of directories
|
130
|
+
dirs = [File.join(@tmp_dir, 'toto'), File.join(@tmp_dir, 'titi')]
|
131
|
+
@context.mkdir(dirs)
|
132
|
+
found = Dir.entries(@tmp_dir)
|
133
|
+
assert(found.member?('toto'))
|
134
|
+
assert(found.member?('titi'))
|
135
|
+
# error case
|
136
|
+
dir = Object.new
|
137
|
+
begin
|
138
|
+
@context.mkdir(dir)
|
139
|
+
flunk "Should have raised a BuildError"
|
140
|
+
rescue Bee::BuildError => e
|
141
|
+
expected = 'mkdir parameter must a String or an array of Strings'
|
142
|
+
actual = $!.message
|
143
|
+
assert_equal(expected, actual)
|
144
|
+
end
|
145
|
+
# another error case
|
146
|
+
dirs = [File.join(@tmp_dir, 'foo'), Object.new]
|
147
|
+
begin
|
148
|
+
@context.mkdir(dirs)
|
149
|
+
flunk "Should have raised a BuildError"
|
150
|
+
rescue Bee::BuildError => e
|
151
|
+
expected = 'mkdir parameter must a String or an array of Strings'
|
152
|
+
actual = $!.message
|
153
|
+
assert_equal(expected, actual)
|
154
|
+
end
|
155
|
+
end
|
156
|
+
|
157
|
+
# Test task cp.
|
158
|
+
def test_task_cp
|
159
|
+
return unless @run_tests
|
160
|
+
# nominal case for a src and dest file
|
161
|
+
src = File.join(@tmp_dir, 'src.txt')
|
162
|
+
create_file(src)
|
163
|
+
dest = File.join(@tmp_dir, 'dest.txt')
|
164
|
+
@context.cp({ 'src' => src, 'dest' => dest })
|
165
|
+
assert_file(dest, src)
|
166
|
+
# nominal case for src files and destination directory
|
167
|
+
clean_tmp
|
168
|
+
src2 = File.join(@tmp_dir, 'src2.txt')
|
169
|
+
dest = File.join(@tmp_dir, 'dir')
|
170
|
+
create_file(src)
|
171
|
+
create_file(src2)
|
172
|
+
FileUtils.makedirs(dest)
|
173
|
+
@context.cp({ 'src' => [src, src2], 'dest' => dest })
|
174
|
+
assert_file(File.join(dest, 'src.txt'), src)
|
175
|
+
assert_file(File.join(dest, 'src2.txt'), src2)
|
176
|
+
# nominal case for src and dest directory
|
177
|
+
clean_tmp
|
178
|
+
src = File.join(@tmp_dir, 'dir')
|
179
|
+
dest = File.join(@tmp_dir, 'todir')
|
180
|
+
FileUtils.makedirs(src)
|
181
|
+
FileUtils.makedirs(dest)
|
182
|
+
file1 = File.join(src, 'file1.txt')
|
183
|
+
file2 = File.join(src, 'file2.txt')
|
184
|
+
create_file(file1)
|
185
|
+
create_file(file2)
|
186
|
+
@context.cp({ 'src' => src, 'dest' => dest })
|
187
|
+
assert_file(File.join(dest, 'dir', 'file1.txt'), file1)
|
188
|
+
assert_file(File.join(dest, 'dir', 'file2.txt'), file2)
|
189
|
+
end
|
190
|
+
|
191
|
+
# Test task mv.
|
192
|
+
def test_task_mv
|
193
|
+
return unless @run_tests
|
194
|
+
# nominal case for a src and dest file
|
195
|
+
src = File.join(@tmp_dir, 'src.txt')
|
196
|
+
create_file(src)
|
197
|
+
dest = File.join(@tmp_dir, 'dest.txt')
|
198
|
+
@context.mv({ 'src' => src, 'dest' => dest })
|
199
|
+
assert_file(dest, src)
|
200
|
+
assert(!File.exists?(File.join(@tmp_dir, src)))
|
201
|
+
# nominal case with two source files
|
202
|
+
clean_tmp
|
203
|
+
src = File.join(@tmp_dir, 'src.txt')
|
204
|
+
src2 = File.join(@tmp_dir, 'src2.txt')
|
205
|
+
dest = File.join(@tmp_dir, 'dir')
|
206
|
+
create_file(src)
|
207
|
+
create_file(src2)
|
208
|
+
FileUtils.makedirs(dest)
|
209
|
+
@context.mv({ 'src' => File.join(@tmp_dir, '*.txt'), 'dest' => dest })
|
210
|
+
assert_file(File.join(dest, 'src.txt'), src)
|
211
|
+
assert_file(File.join(dest, 'src2.txt'), src2)
|
212
|
+
assert(!File.exists?(src))
|
213
|
+
assert(!File.exists?(src2))
|
214
|
+
# nominal case with directory for src and dest
|
215
|
+
clean_tmp
|
216
|
+
src = File.join(@tmp_dir, 'dir1')
|
217
|
+
dest = File.join(@tmp_dir, 'dir2')
|
218
|
+
FileUtils.makedirs(src)
|
219
|
+
create_file(File.join(src, 'test.txt'))
|
220
|
+
@context.mv({ 'src' => src, 'dest' => dest })
|
221
|
+
assert(File.exists?(dest))
|
222
|
+
assert(File.directory?(dest))
|
223
|
+
assert_file(File.join(dest, 'test.txt'), File.join(src, 'test.txt'))
|
224
|
+
assert(!File.exists?(src))
|
225
|
+
end
|
226
|
+
|
227
|
+
# Test task rm.
|
228
|
+
def test_task_rm
|
229
|
+
return unless @run_tests
|
230
|
+
# nominal case with a glob
|
231
|
+
file = File.join(@tmp_dir, 'test.txt')
|
232
|
+
create_file(file)
|
233
|
+
@context.rm(File.join(@tmp_dir, file))
|
234
|
+
assert(!File.exists?(File.join(@tmp_dir, file)))
|
235
|
+
# nominal case with two globs and three files
|
236
|
+
clean_tmp
|
237
|
+
file1 = File.join(@tmp_dir, 'test1.txt')
|
238
|
+
file2 = File.join(@tmp_dir, 'test2.txt')
|
239
|
+
file3 = File.join(@tmp_dir, 'test3.log')
|
240
|
+
create_file(file1)
|
241
|
+
create_file(file2)
|
242
|
+
create_file(file3)
|
243
|
+
@context.rm([File.join(@tmp_dir, '**/*.txt'),
|
244
|
+
File.join(@tmp_dir, '**/*.log')])
|
245
|
+
assert(!File.exists?(file1))
|
246
|
+
assert(!File.exists?(file2))
|
247
|
+
assert(!File.exists?(file3))
|
248
|
+
end
|
249
|
+
|
250
|
+
# Test task rmdir.
|
251
|
+
def test_task_rmdir
|
252
|
+
return unless @run_tests
|
253
|
+
# nominal case with one dir
|
254
|
+
dir = File.join(@tmp_dir, 'dir')
|
255
|
+
FileUtils.makedirs(dir)
|
256
|
+
@context.rmdir(dir)
|
257
|
+
assert(!File.exists?(dir))
|
258
|
+
# nominal case with two dirs
|
259
|
+
clean_tmp
|
260
|
+
dir1 = File.join(@tmp_dir, 'dir1')
|
261
|
+
dir2 = File.join(@tmp_dir, 'dir2')
|
262
|
+
FileUtils.makedirs(dir1)
|
263
|
+
FileUtils.makedirs(dir2)
|
264
|
+
@context.rmdir([dir1, dir2])
|
265
|
+
assert(!File.exists?(dir1))
|
266
|
+
assert(!File.exists?(dir2))
|
267
|
+
end
|
268
|
+
|
269
|
+
# Test task find.
|
270
|
+
def test_task_find
|
271
|
+
return unless @run_tests
|
272
|
+
file1 = File.join(@tmp_dir, 'file1.txt')
|
273
|
+
file2 = File.join(@tmp_dir, 'file2.txt')
|
274
|
+
dir = File.join(@tmp_dir, 'dir')
|
275
|
+
file3 = File.join(dir, 'file3.txt')
|
276
|
+
create_file(file1)
|
277
|
+
create_file(file2)
|
278
|
+
FileUtils.makedirs(dir)
|
279
|
+
create_file(file3)
|
280
|
+
@context.find({ 'files' => "#{File.join(@tmp_dir, '**/*.txt')}",
|
281
|
+
'toprop' => 'list'})
|
282
|
+
list = @context.get('list').sort
|
283
|
+
expected = [file1, file2, file3].sort
|
284
|
+
assert_equal(expected, list)
|
285
|
+
end
|
286
|
+
|
287
|
+
# Test task erb.
|
288
|
+
def test_task_erb
|
289
|
+
return unless @run_tests
|
290
|
+
@context.set('test', 'TEST')
|
291
|
+
source = 'This is a <%= test %>'
|
292
|
+
@context.erb({ 'source' => source, 'toprop' => 'result' })
|
293
|
+
actual = @context.get('result')
|
294
|
+
expected = 'This is a TEST'
|
295
|
+
assert_equal(expected, actual)
|
296
|
+
end
|
297
|
+
|
298
|
+
end
|
metadata
CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.0
|
|
3
3
|
specification_version: 1
|
4
4
|
name: bee
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 0.3.
|
7
|
-
date: 2006-11-
|
6
|
+
version: 0.3.1
|
7
|
+
date: 2006-11-10 00:00:00 +01:00
|
8
8
|
summary: bee is a build tool
|
9
9
|
require_paths:
|
10
10
|
- lib
|
@@ -34,6 +34,7 @@ files:
|
|
34
34
|
- lib/bee_console.rb
|
35
35
|
- lib/bee_default_context.rb
|
36
36
|
- test/tc_bee_console_formatter.rb
|
37
|
+
- test/tc_bee_default_tasks.rb
|
37
38
|
- test/ts_bee.rb
|
38
39
|
- README
|
39
40
|
- LICENSE
|