bee 0.3.1 → 0.4.0
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 +1 -1
- data/bin/bee +16 -0
- data/bin/bee.bat +32 -0
- data/lib/bee.rb +165 -170
- data/lib/bee_console.rb +90 -87
- data/lib/bee_task.rb +149 -0
- data/lib/bee_task_default.rb +525 -0
- data/lib/bee_util.rb +230 -0
- data/test/tc_bee_build.rb +216 -0
- data/test/tc_bee_console.rb +106 -0
- data/test/tc_bee_console_formatter.rb +38 -3
- data/test/tc_bee_context.rb +84 -0
- data/test/tc_bee_task_default.rb +467 -0
- data/test/tc_bee_util.rb +85 -0
- data/test/test_build.rb +26 -0
- data/test/test_build_listener.rb +60 -0
- data/test/tmp_test_case.rb +58 -0
- data/test/ts_bee.rb +1 -1
- metadata +35 -8
- data/lib/bee_default_context.rb +0 -475
- data/test/tc_bee_default_tasks.rb +0 -298
data/test/tc_bee_util.rb
ADDED
@@ -0,0 +1,85 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
# Copyright 2006-2007 Michel Casabianca <michel.casabianca@gmail.com>
|
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 'fileutils'
|
18
|
+
$:.unshift(File.join(File.dirname(__FILE__)))
|
19
|
+
require 'tmp_test_case'
|
20
|
+
$:.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
21
|
+
require 'bee_util'
|
22
|
+
|
23
|
+
# Test case for utility methods.
|
24
|
+
class TestBeeUtil < TmpTestCase
|
25
|
+
|
26
|
+
include Bee::Util::FileSelector
|
27
|
+
|
28
|
+
# Test FileSelector class.
|
29
|
+
def test_select_files
|
30
|
+
# make test files
|
31
|
+
path = File.join(@tmp_dir, '1.txt')
|
32
|
+
File.open(path, 'w') {|file| file.write('TEST')}
|
33
|
+
path = File.join(@tmp_dir, '2.txt')
|
34
|
+
File.open(path, 'w') {|file| file.write('TEST')}
|
35
|
+
path = File.join(@tmp_dir, '3.txt')
|
36
|
+
File.open(path, 'w') {|file| file.write('TEST')}
|
37
|
+
path = File.join(@tmp_dir, '1.tst')
|
38
|
+
File.open(path, 'w') {|file| file.write('TEST')}
|
39
|
+
path = File.join(@tmp_dir, '2.tst')
|
40
|
+
File.open(path, 'w') {|file| file.write('TEST')}
|
41
|
+
path = File.join(@tmp_dir, '3.tst')
|
42
|
+
File.open(path, 'w') {|file| file.write('TEST')}
|
43
|
+
# test file selection
|
44
|
+
includes = "#{@tmp_dir}/*"
|
45
|
+
excludes = nil
|
46
|
+
actual = select_files(includes, excludes)
|
47
|
+
expected = ["#{@tmp_dir}/1.tst", "#{@tmp_dir}/1.txt",
|
48
|
+
"#{@tmp_dir}/2.tst", "#{@tmp_dir}/2.txt",
|
49
|
+
"#{@tmp_dir}/3.tst", "#{@tmp_dir}/3.txt"]
|
50
|
+
assert_equal(expected, actual)
|
51
|
+
includes = "#{@tmp_dir}/*"
|
52
|
+
excludes = "#{@tmp_dir}/*.tst"
|
53
|
+
actual = select_files(includes, excludes)
|
54
|
+
expected = ["#{@tmp_dir}/1.txt", "#{@tmp_dir}/2.txt", "#{@tmp_dir}/3.txt"]
|
55
|
+
assert_equal(expected, actual)
|
56
|
+
includes = "#{@tmp_dir}/1.*"
|
57
|
+
excludes = nil
|
58
|
+
actual = select_files(includes, excludes)
|
59
|
+
expected = ["#{@tmp_dir}/1.tst", "#{@tmp_dir}/1.txt"]
|
60
|
+
assert_equal(expected, actual)
|
61
|
+
end
|
62
|
+
|
63
|
+
# Test find method.
|
64
|
+
def test_find
|
65
|
+
# nominal case
|
66
|
+
file = File.join(@tmp_dir, 'file.txt')
|
67
|
+
File.open(file, 'w') {|file| file.write('TEST')}
|
68
|
+
dir = File.join(@tmp_dir, 'dir')
|
69
|
+
FileUtils.mkdir(dir)
|
70
|
+
Dir.chdir(dir)
|
71
|
+
actual = Bee::Util::find('file.txt')
|
72
|
+
expected = '../file.txt'
|
73
|
+
assert_equal(expected, actual)
|
74
|
+
# failure: file not found
|
75
|
+
begin
|
76
|
+
Bee::Util::find('foo.bar')
|
77
|
+
flunk "Should have failed"
|
78
|
+
rescue
|
79
|
+
expected = 'File not found'
|
80
|
+
actual = $!.to_s
|
81
|
+
assert_equal(expected, actual)
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
end
|
data/test/test_build.rb
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# Copyright 2006-2007 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
|
+
# Empty build for testing purpose. Contains a single context.
|
16
|
+
class TestBuild
|
17
|
+
|
18
|
+
attr_reader :context
|
19
|
+
attr_reader :listener
|
20
|
+
|
21
|
+
def initialize(context, listener)
|
22
|
+
@context = context
|
23
|
+
@listener = listener
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
# Copyright 2006-2007 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
|
+
# Test build listener.
|
16
|
+
class TestBuildListener
|
17
|
+
|
18
|
+
attr_reader :started
|
19
|
+
attr_reader :finished
|
20
|
+
attr_reader :targets
|
21
|
+
attr_reader :tasks
|
22
|
+
attr_reader :success
|
23
|
+
attr_reader :errors
|
24
|
+
attr_accessor :output
|
25
|
+
|
26
|
+
def initialize
|
27
|
+
@targets = []
|
28
|
+
@tasks = []
|
29
|
+
@output = ''
|
30
|
+
end
|
31
|
+
|
32
|
+
def build_started(build)
|
33
|
+
@started = true
|
34
|
+
end
|
35
|
+
|
36
|
+
def build_finished(build)
|
37
|
+
@finished = true
|
38
|
+
end
|
39
|
+
|
40
|
+
def target(target)
|
41
|
+
@targets << target
|
42
|
+
end
|
43
|
+
|
44
|
+
def task(task)
|
45
|
+
@tasks << tasks
|
46
|
+
end
|
47
|
+
|
48
|
+
def error(exception)
|
49
|
+
@errors = exception
|
50
|
+
end
|
51
|
+
|
52
|
+
def print(text)
|
53
|
+
@output << text
|
54
|
+
end
|
55
|
+
|
56
|
+
def puts(text)
|
57
|
+
@output << text + "\n"
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
# Copyright 2006-2007 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
|
+
require 'test/unit'
|
16
|
+
require 'fileutils'
|
17
|
+
|
18
|
+
# Test case that creates a 'tmp' directory before each test and deletes it
|
19
|
+
# after. Also disable tests if we can't write on disk (if we run tests while
|
20
|
+
# installing with gem in a system directory for instance).
|
21
|
+
class TmpTestCase < Test::Unit::TestCase
|
22
|
+
|
23
|
+
# Temporary directory.
|
24
|
+
TEMP_DIR = 'tmp'
|
25
|
+
|
26
|
+
# Constructor: disable test if we don't have write permission.
|
27
|
+
def initialize(*args)
|
28
|
+
super(*args)
|
29
|
+
@home = File.expand_path(File.dirname(__FILE__))
|
30
|
+
@working_dir = Dir.getwd
|
31
|
+
@tmp_dir = File.join(@home, TEMP_DIR)
|
32
|
+
begin
|
33
|
+
FileUtils.makedirs(@tmp_dir)
|
34
|
+
@run_tests = true
|
35
|
+
rescue
|
36
|
+
@run_tests = false
|
37
|
+
methods = self.class.public_instance_methods
|
38
|
+
for method in methods
|
39
|
+
self.class.remove_method(Symbol.new(method)) if method =~ /^test_.*/
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
# Run before any test: create temporary directory.
|
45
|
+
def setup
|
46
|
+
FileUtils.makedirs(@tmp_dir)
|
47
|
+
end
|
48
|
+
|
49
|
+
# Run after any test: delete temporary directory.
|
50
|
+
def teardown
|
51
|
+
Dir.chdir(@working_dir)
|
52
|
+
FileUtils.rm_rf(@tmp_dir)
|
53
|
+
end
|
54
|
+
|
55
|
+
def test_
|
56
|
+
end
|
57
|
+
|
58
|
+
end
|
data/test/ts_bee.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
-
# Copyright 2006 Michel Casabianca <
|
3
|
+
# Copyright 2006-2007 Michel Casabianca <michel.casabianca@gmail.com>
|
4
4
|
#
|
5
5
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
6
|
# you may not use this file except in compliance with the License.
|
metadata
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
|
-
rubygems_version: 0.9.
|
2
|
+
rubygems_version: 0.9.4
|
3
3
|
specification_version: 1
|
4
4
|
name: bee
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 0.
|
7
|
-
date:
|
6
|
+
version: 0.4.0
|
7
|
+
date: 2007-06-25 00:00:00 +02:00
|
8
8
|
summary: bee is a build tool
|
9
9
|
require_paths:
|
10
10
|
- lib
|
@@ -27,14 +27,24 @@ signing_key:
|
|
27
27
|
cert_chain:
|
28
28
|
post_install_message: Enjoy bee!
|
29
29
|
authors:
|
30
|
-
- Michel Casabianca
|
30
|
+
- Michel Casabianca & Contributors
|
31
31
|
files:
|
32
32
|
- bin/bee
|
33
|
+
- bin/bee.bat
|
33
34
|
- lib/bee.rb
|
34
35
|
- lib/bee_console.rb
|
35
|
-
- lib/
|
36
|
+
- lib/bee_task.rb
|
37
|
+
- lib/bee_task_default.rb
|
38
|
+
- lib/bee_util.rb
|
39
|
+
- test/tc_bee_build.rb
|
40
|
+
- test/tc_bee_console.rb
|
36
41
|
- test/tc_bee_console_formatter.rb
|
37
|
-
- test/
|
42
|
+
- test/tc_bee_context.rb
|
43
|
+
- test/tc_bee_task_default.rb
|
44
|
+
- test/tc_bee_util.rb
|
45
|
+
- test/test_build.rb
|
46
|
+
- test/test_build_listener.rb
|
47
|
+
- test/tmp_test_case.rb
|
38
48
|
- test/ts_bee.rb
|
39
49
|
- README
|
40
50
|
- LICENSE
|
@@ -51,5 +61,22 @@ extensions: []
|
|
51
61
|
|
52
62
|
requirements: []
|
53
63
|
|
54
|
-
dependencies:
|
55
|
-
|
64
|
+
dependencies:
|
65
|
+
- !ruby/object:Gem::Dependency
|
66
|
+
name: archive-tar-minitar
|
67
|
+
version_requirement:
|
68
|
+
version_requirements: !ruby/object:Gem::Version::Requirement
|
69
|
+
requirements:
|
70
|
+
- - ">="
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
version: 0.5.1
|
73
|
+
version:
|
74
|
+
- !ruby/object:Gem::Dependency
|
75
|
+
name: rubyzip
|
76
|
+
version_requirement:
|
77
|
+
version_requirements: !ruby/object:Gem::Version::Requirement
|
78
|
+
requirements:
|
79
|
+
- - ">="
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: 0.9.1
|
82
|
+
version:
|
data/lib/bee_default_context.rb
DELETED
@@ -1,475 +0,0 @@
|
|
1
|
-
# Copyright 2006 Michel Casabianca <casa@sweetohm.net>
|
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
|
-
# Default bee context. This script is evaluated before getting binding
|
16
|
-
# for context, thus all defined functions are accessible in scripts
|
17
|
-
# that run in targets. Furthermore, last evaluated expression is a
|
18
|
-
# mapping of extension tasks.
|
19
|
-
|
20
|
-
############################ UTILITY FUNCTIONS ############################
|
21
|
-
|
22
|
-
# Convenient method to raise a BuildError. This is necessary to interrupt
|
23
|
-
# build with an error message but without a stack trace (which would
|
24
|
-
# indicate an internal error).
|
25
|
-
# - message: error message.
|
26
|
-
def error(message)
|
27
|
-
raise BuildError.new(message)
|
28
|
-
end
|
29
|
-
|
30
|
-
# Run a shell script and raise a build error if script returned a value
|
31
|
-
# different of 0.
|
32
|
-
# - script: script to run.
|
33
|
-
def sh(script)
|
34
|
-
system(script) or error "Script '#{script}' exited with value '#{$?}'"
|
35
|
-
end
|
36
|
-
|
37
|
-
############################ TASK DEFINITIONS #############################
|
38
|
-
|
39
|
-
# Prints a message. This message may be a String (standard output) or any
|
40
|
-
# Ruby object. In this latter case, print its inspected value.
|
41
|
-
# - message: message to print.
|
42
|
-
def print(message)
|
43
|
-
case message
|
44
|
-
when String
|
45
|
-
puts evaluate_object(message)
|
46
|
-
else
|
47
|
-
puts message.inspect
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
# Print a file contents.
|
52
|
-
# - file: file to print out.
|
53
|
-
def cat(file)
|
54
|
-
file = evaluate_object(file)
|
55
|
-
error "Parameter must be a String" unless file.kind_of?(String)
|
56
|
-
error "File '#{file}' not found" unless
|
57
|
-
File.exists?(file) or File.directory?(file)
|
58
|
-
puts File.read(file).strip
|
59
|
-
end
|
60
|
-
|
61
|
-
# Change working directory. This change will persist for all tasks run in
|
62
|
-
# the target. Parameter is a string with directory to change to.
|
63
|
-
def cd(dir)
|
64
|
-
dir = evaluate_object(dir)
|
65
|
-
error "cd parameter is a String" unless dir.kind_of?(String)
|
66
|
-
Dir.chdir(dir)
|
67
|
-
end
|
68
|
-
|
69
|
-
# Make a directory and parent directories if necessary. Doesn't complain if
|
70
|
-
# directory already exists.
|
71
|
-
# - dir: directory to create.
|
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
|
83
|
-
end
|
84
|
-
|
85
|
-
# Copy a files or directoris to destination file or directory. Parameter is a
|
86
|
-
# Hash with following entries:
|
87
|
-
# - src: glob for source files or directories.
|
88
|
-
# - dest: destination file or directory.
|
89
|
-
def cp(params)
|
90
|
-
require 'fileutils'
|
91
|
-
params_desc = {
|
92
|
-
'src' => :mandatory,
|
93
|
-
'dest' => :mandatory
|
94
|
-
}
|
95
|
-
check_task_parameters(params, params_desc)
|
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)
|
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)
|
102
|
-
files = []
|
103
|
-
for element in src
|
104
|
-
error "cp 'src' parameter must a glob or a list of globs" unless
|
105
|
-
element.kind_of?(String)
|
106
|
-
files += Dir.glob(element)
|
107
|
-
end
|
108
|
-
files = files[0] if files.length == 1
|
109
|
-
FileUtils.cp_r(files, dest)
|
110
|
-
end
|
111
|
-
|
112
|
-
# Move source file(s) or directories to dest file or directory. Parameter is
|
113
|
-
# a Hahs with following keys:
|
114
|
-
# - src: glob for files and directories to move.
|
115
|
-
# - dest: file or directory to move file(s) to.
|
116
|
-
def mv(params)
|
117
|
-
require 'fileutils'
|
118
|
-
params_desc = {
|
119
|
-
'src' => :mandatory,
|
120
|
-
'dest' => :mandatory
|
121
|
-
}
|
122
|
-
check_task_parameters(params, params_desc)
|
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)
|
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)
|
129
|
-
files = []
|
130
|
-
for element in src
|
131
|
-
error "mv 'src' parameter must a glob or a list of globs" unless
|
132
|
-
element.kind_of?(String)
|
133
|
-
files += Dir.glob(element)
|
134
|
-
end
|
135
|
-
files = files[0] if files.length == 1
|
136
|
-
FileUtils.mv(files, dest)
|
137
|
-
end
|
138
|
-
|
139
|
-
# Delete files for a given glob. Parameter is a string for glob of files
|
140
|
-
# to delete.
|
141
|
-
def rm(globs)
|
142
|
-
require 'fileutils'
|
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
|
151
|
-
end
|
152
|
-
end
|
153
|
-
|
154
|
-
# Delete directories recursively. Parameter is a string for glob of directories
|
155
|
-
# to delete.
|
156
|
-
def rmdir(globs)
|
157
|
-
require 'fileutils'
|
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
|
168
|
-
end
|
169
|
-
end
|
170
|
-
|
171
|
-
# Find files for a given glob and store list in a property. Parameter is
|
172
|
-
# a Hash with entries:
|
173
|
-
# - files: glob or list of globs for files to look for.
|
174
|
-
# - toprop: name of the property to set.
|
175
|
-
def find(parameters)
|
176
|
-
params_desc = {
|
177
|
-
'files' => :mandatory,
|
178
|
-
'toprop' => :mandatory
|
179
|
-
}
|
180
|
-
check_task_parameters(parameters, params_desc)
|
181
|
-
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)
|
185
|
-
toprop = evaluate_object(parameters['toprop'])
|
186
|
-
for glob in globs
|
187
|
-
error "find 'files' parameter is a String or an Array of Strings" unless
|
188
|
-
glob.kind_of?(String)
|
189
|
-
files += Dir.glob(evaluate_object(glob))
|
190
|
-
end
|
191
|
-
set(toprop, files)
|
192
|
-
end
|
193
|
-
|
194
|
-
# Run a set of tests selected using globs. Parameter is a glob or list of
|
195
|
-
# globs for files or directories to run.
|
196
|
-
# FIXME: if tasks runs twice, it will run twice loaded tests...
|
197
|
-
def test(globs)
|
198
|
-
require 'test/unit'
|
199
|
-
require 'test/unit/testresult'
|
200
|
-
files = []
|
201
|
-
for glob in globs
|
202
|
-
error "Parameter must be a String or a list of Strings" unless
|
203
|
-
glob.kind_of?(String)
|
204
|
-
files += Dir.glob(evaluate_object(glob))
|
205
|
-
end
|
206
|
-
for file in files
|
207
|
-
load file
|
208
|
-
end
|
209
|
-
Test::Unit::AutoRunner.run
|
210
|
-
end
|
211
|
-
|
212
|
-
# Run an ERB file or source and store result in a file or property. Parameter
|
213
|
-
# is a Hash with following keys:
|
214
|
-
# - source: ERB source text (if no 'file').
|
215
|
-
# - file: ERB file name (if no 'source').
|
216
|
-
# - tofile: file where to store result (if no 'toprop').
|
217
|
-
# - toprop: property name where to store result (if no 'tofile').
|
218
|
-
def erb(params)
|
219
|
-
require 'erb'
|
220
|
-
# check parameters
|
221
|
-
params_desc = {
|
222
|
-
'source' => :optional,
|
223
|
-
'file' => :optional,
|
224
|
-
'tofile' => :optional,
|
225
|
-
'toprop' => :optional
|
226
|
-
}
|
227
|
-
check_task_parameters(params, params_desc)
|
228
|
-
source = params['source']
|
229
|
-
file = evaluate_object(params['file'])
|
230
|
-
tofile = evaluate_object(params['tofile'])
|
231
|
-
toprop = evaluate_object(params['toprop'])
|
232
|
-
error "Must pass one of 'source' or 'file' parameters to erb task" if
|
233
|
-
not source and not file
|
234
|
-
error "Must pass one of 'tofile' or 'toprop' parameters to erb task" if
|
235
|
-
not tofile and not toprop
|
236
|
-
# load ERB source
|
237
|
-
erb_source = source||File.read(file)
|
238
|
-
template = ERB.new(erb_source)
|
239
|
-
begin
|
240
|
-
result = template.result(@context_binding)
|
241
|
-
rescue
|
242
|
-
error "Error processing ERB: #{$!}"
|
243
|
-
end
|
244
|
-
# write result in file or set property
|
245
|
-
if tofile
|
246
|
-
File.open(tofile, 'w') { |file| file.write(result) }
|
247
|
-
else
|
248
|
-
set(toprop, result)
|
249
|
-
end
|
250
|
-
end
|
251
|
-
|
252
|
-
# Generate RDoc documentation for a given list of globs and an output directory.
|
253
|
-
# Parameter is a Hash with following keys:
|
254
|
-
# - input: input files as a glob (or list of globs). File mays be directories.
|
255
|
-
# - output: output directory for generated documentation.
|
256
|
-
def rdoc(params)
|
257
|
-
require 'rdoc/rdoc'
|
258
|
-
params_desc = {
|
259
|
-
'input' => :mandatory,
|
260
|
-
'output' => :mandatory
|
261
|
-
}
|
262
|
-
check_task_parameters(params, params_desc)
|
263
|
-
files = []
|
264
|
-
input = params['input']
|
265
|
-
for glob in input
|
266
|
-
files += Dir.glob(evaluate_object(glob))
|
267
|
-
end
|
268
|
-
output = evaluate_object(params['output'])
|
269
|
-
command_line = ['-S', '-o', output] + files
|
270
|
-
rdoc = RDoc::RDoc.new
|
271
|
-
rdoc.document(command_line)
|
272
|
-
end
|
273
|
-
|
274
|
-
# Generate a Gem package. Parameter is the name of the Gem description file.
|
275
|
-
# Resulting Gem package is generated in current directory (as with command
|
276
|
-
# line tool).
|
277
|
-
def gembuild(description)
|
278
|
-
require 'rubygems'
|
279
|
-
description = evaluate_object(description)
|
280
|
-
arguments = ['build', description]
|
281
|
-
Gem.manage_gems
|
282
|
-
Gem::GemRunner.new.run(arguments)
|
283
|
-
end
|
284
|
-
|
285
|
-
# Generate a ZIP archive. Parameter is a Hash with following entries:
|
286
|
-
# - files: glob or list of globs for files to select for the archive.
|
287
|
-
# - archive: the archive name.
|
288
|
-
# - prefix: prefix for archive entries (default to nil).
|
289
|
-
# Note: if archive exists, files are added to the archive.
|
290
|
-
def zip(parameters)
|
291
|
-
require 'zip/zip'
|
292
|
-
# parse parameters
|
293
|
-
params_desc = {
|
294
|
-
'files' => :mandatory,
|
295
|
-
'archive' => :mandatory,
|
296
|
-
'prefix' => :optional
|
297
|
-
}
|
298
|
-
check_task_parameters(parameters, params_desc)
|
299
|
-
globs = evaluate_object(parameters['files'])
|
300
|
-
files = []
|
301
|
-
for glob in globs
|
302
|
-
files += Dir.glob(evaluate_object(glob))
|
303
|
-
end
|
304
|
-
archive = evaluate_object(parameters['archive'])
|
305
|
-
prefix = evaluate_object(parameters['prefix'])
|
306
|
-
# build the archive
|
307
|
-
zipfile = Zip::ZipFile.open(archive, Zip::ZipFile::CREATE) do |zip|
|
308
|
-
for file in files
|
309
|
-
entry = prefix ? File.join(prefix, file) : file
|
310
|
-
puts "Adding '#{entry}'"
|
311
|
-
zip.add(entry, file)
|
312
|
-
end
|
313
|
-
zip.close
|
314
|
-
end
|
315
|
-
end
|
316
|
-
|
317
|
-
############################## TASKS MAPPING ##############################
|
318
|
-
|
319
|
-
{
|
320
|
-
"print" =>
|
321
|
-
"Print a message on console. This message may be a String (standard output)
|
322
|
-
or any Ruby object. In this latter case, print its inspected value. Parameter
|
323
|
-
is the message to output as a String.
|
324
|
-
|
325
|
-
- message: message to print.
|
326
|
-
|
327
|
-
Example:
|
328
|
-
|
329
|
-
- print: \"Hello World!\"",
|
330
|
-
|
331
|
-
"cat" =>
|
332
|
-
"Print contents of a given file on the console. Parameter is file to output
|
333
|
-
as a String.
|
334
|
-
|
335
|
-
- file: file to print out.
|
336
|
-
|
337
|
-
Example:
|
338
|
-
|
339
|
-
- cat: \"doc/welcome-message.txt\"",
|
340
|
-
|
341
|
-
"cd" =>
|
342
|
-
"Change working directory. This change will persist for all tasks in the
|
343
|
-
target but not in other targets. Parameter is a String with directory to
|
344
|
-
change to.
|
345
|
-
|
346
|
-
Example:
|
347
|
-
|
348
|
-
- cd: \"build\"",
|
349
|
-
|
350
|
-
"mkdir" =>
|
351
|
-
"Make a directory and parent directories if necessary. Doesn't complain if
|
352
|
-
directory already exists. Parameter is directory to create as a String or a
|
353
|
-
list of directories as Strings.
|
354
|
-
|
355
|
-
Example:
|
356
|
-
|
357
|
-
- mkdir: \"foo/bar\"
|
358
|
-
- mkdir: [\"foo\", \"bar\"]",
|
359
|
-
|
360
|
-
"cp" =>
|
361
|
-
"Copy files or directories to destination file or directory. Parameter is a
|
362
|
-
Hash with following entries:
|
363
|
-
|
364
|
-
- src: glob for source files or directories.
|
365
|
-
- dest: destination file or directory.
|
366
|
-
|
367
|
-
Example:
|
368
|
-
|
369
|
-
- cp:
|
370
|
-
src: \"doc/png/*.png\"
|
371
|
-
dest: :doc",
|
372
|
-
|
373
|
-
"mv" =>
|
374
|
-
"Move source file(s) or directory(ies) to dest file or directory. Parameter is
|
375
|
-
a Hash with following entries:
|
376
|
-
|
377
|
-
- src: glob for files and directories to move.
|
378
|
-
- dest: file or directory to move file(s) to.
|
379
|
-
|
380
|
-
Example:
|
381
|
-
|
382
|
-
- mv: { src: \"**/*.java\", dest: \"trash\" }",
|
383
|
-
|
384
|
-
"rm" =>
|
385
|
-
"Delete files for a given glob or list of globs. Parameter is a glob or list
|
386
|
-
of globs for files to delete.
|
387
|
-
|
388
|
-
Example:
|
389
|
-
|
390
|
-
- rm: \"**/*~\"
|
391
|
-
- rm: [\"**/*~\", \"**/.DS_Store\"]",
|
392
|
-
|
393
|
-
"rmdir" =>
|
394
|
-
"Delete directories recursively. Parameter is a string for glob of directories
|
395
|
-
to delete.
|
396
|
-
|
397
|
-
Example:
|
398
|
-
|
399
|
-
- rmdir: :build",
|
400
|
-
|
401
|
-
"find" =>
|
402
|
-
"Find files for a glob or list of globs and store list in a property.
|
403
|
-
Parameter is a Hash with entries:
|
404
|
-
|
405
|
-
- files: glob or list of globs for files to look for.
|
406
|
-
- toprop: name of the property to set.
|
407
|
-
|
408
|
-
Example:
|
409
|
-
|
410
|
-
- find: { files: \"**/*.rb\", toprop: \"rb_files_to_check\" }",
|
411
|
-
|
412
|
-
"test" =>
|
413
|
-
"Run a set of tests selected using globs. Parameter is a glob or list of
|
414
|
-
globs for files or directories to run.
|
415
|
-
|
416
|
-
Example:
|
417
|
-
|
418
|
-
- test: \"**/tc_*.rb\"
|
419
|
-
|
420
|
-
*FIXME*: if tasks runs twice, it will run twice loaded tests...",
|
421
|
-
|
422
|
-
"erb" =>
|
423
|
-
"Run an ERB file or source in bee context and store result in a file or
|
424
|
-
property. Parameter is a Hash with following entries:
|
425
|
-
|
426
|
-
- source: ERB source text (if no 'file').
|
427
|
-
- file: ERB file name (if no 'source').
|
428
|
-
- tofile: file where to store result (if no 'toprop').
|
429
|
-
- toprop: property name where to store result (if no 'tofile').
|
430
|
-
|
431
|
-
Example:
|
432
|
-
|
433
|
-
- erb: { file: \"gem.spec.erb\", tofile: \"gem.spec\" }
|
434
|
-
|
435
|
-
Notes: In these ERB files, you can access a property _foo_ writing:
|
436
|
-
|
437
|
-
<p>Hello <%= foo %>!</p>",
|
438
|
-
|
439
|
-
"rdoc" =>
|
440
|
-
"Generate RDoc documentation for a given list of globs and an output directory.
|
441
|
-
Parameter is a Hash with following entries:
|
442
|
-
|
443
|
-
- input: input files as a glob (or list of globs). File mays be directories.
|
444
|
-
- output: output directory for generated documentation.
|
445
|
-
|
446
|
-
Example:
|
447
|
-
|
448
|
-
- rdoc:
|
449
|
-
input: [\"README\", \"LICENSE\", :src]
|
450
|
-
output: :api",
|
451
|
-
|
452
|
-
"gembuild" =>
|
453
|
-
"Generate a Gem package. Parameter is the name of the Gem description file.
|
454
|
-
Resulting Gem package is generated in current directory (as with command
|
455
|
-
line tool).
|
456
|
-
|
457
|
-
Example:
|
458
|
-
|
459
|
-
- gembuild: :gem_spec",
|
460
|
-
|
461
|
-
"zip" =>
|
462
|
-
"Generate a ZIP archive. Parameter is a Hash with following entries:
|
463
|
-
|
464
|
-
- files: glob or list of globs for files to select for the archive.
|
465
|
-
- archive: the archive name.
|
466
|
-
- prefix: prefix for archive entries (default to nil).
|
467
|
-
|
468
|
-
Example:
|
469
|
-
|
470
|
-
- zip:
|
471
|
-
files: :zip_files
|
472
|
-
archive: :zip_archive
|
473
|
-
|
474
|
-
Note: if archive already exists, files are added to the archive."
|
475
|
-
}
|