bozo 0.3.8 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/README.md +443 -426
- data/VERSION +1 -1
- data/bin/bozo +8 -8
- data/lib/bozo.rb +131 -130
- data/lib/bozo/bozo.rb +6 -6
- data/lib/bozo/bozo_configuration.rb +319 -299
- data/lib/bozo/build_dependency_resolver.rb +106 -0
- data/lib/bozo/class_name_helpers.rb +16 -16
- data/lib/bozo/configuration_error.rb +29 -29
- data/lib/bozo/execution_error.rb +35 -35
- data/lib/bozo/executor.rb +263 -288
- data/lib/bozo/logging.rb +40 -40
- data/lib/bozo/runner.rb +63 -63
- data/lib/bozo/versioning/version.rb +96 -96
- data/lib/bozo/versioning/version_bump_error.rb +29 -29
- data/lib/bozo/versioning/version_bumper.rb +36 -36
- data/test/bozo_configuration_version_tests.rb +41 -41
- data/test/test_helper.rb +2 -2
- data/test/version_bumper_tests.rb +61 -61
- data/test/version_tests.rb +25 -25
- metadata +3 -2
@@ -0,0 +1,106 @@
|
|
1
|
+
module Bozo
|
2
|
+
|
3
|
+
# Handles resolving build dependencies
|
4
|
+
#
|
5
|
+
# When resolving the tools from the `build_configuration.build_tools` - first tool runners
|
6
|
+
# in the `Bozo::Tools` module are used, if a class does not exist then the `build_tools_location` is searched.
|
7
|
+
#
|
8
|
+
class BuildDependencyResolver
|
9
|
+
include Bozo::Logging
|
10
|
+
include Bozo::ClassNameHelpers
|
11
|
+
|
12
|
+
def initialize(build_configuration)
|
13
|
+
@build_configuration = build_configuration
|
14
|
+
end
|
15
|
+
|
16
|
+
def resolve
|
17
|
+
retrieve_build_dependencies
|
18
|
+
retrieve_tools
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
def plugin_tools
|
24
|
+
Bozo::Tools.constants.select {|c| Class === Bozo::Tools.const_get(c)}
|
25
|
+
end
|
26
|
+
|
27
|
+
def plugin_tool?(tool)
|
28
|
+
plugin_tools.map { |t| t.to_s }.include?(to_class_name(tool))
|
29
|
+
end
|
30
|
+
|
31
|
+
# Returns the tools path
|
32
|
+
def tools_path
|
33
|
+
File.expand_path(File.join('build', 'tools'))
|
34
|
+
end
|
35
|
+
|
36
|
+
# Retrieves the tools specified in the configuration.
|
37
|
+
def retrieve_tools
|
38
|
+
tools = @build_configuration.tools
|
39
|
+
|
40
|
+
log_info "Retrieving tools - #{tools.inspect}"
|
41
|
+
|
42
|
+
tools.each do |tool|
|
43
|
+
retrieve_plugin_tool tool
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
# Retrieves the required build tools from the configured build tools
|
48
|
+
# location.
|
49
|
+
def retrieve_build_dependencies
|
50
|
+
required_tools = @build_configuration.build_tools
|
51
|
+
|
52
|
+
log_info "Retrieving build tools - #{required_tools.inspect}"
|
53
|
+
|
54
|
+
required_tools.each do |tool|
|
55
|
+
if plugin_tool?(tool)
|
56
|
+
instance = @build_configuration.tools.select {|t| to_tool_name(t) == tool.to_s }.first
|
57
|
+
unless instance
|
58
|
+
instance = Bozo::Tools.const_get(to_class_name(tool)).new
|
59
|
+
instance.extend Bozo::Runner
|
60
|
+
end
|
61
|
+
retrieve_plugin_tool instance
|
62
|
+
else
|
63
|
+
retrieve_from_build_tools_location tool
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
def retrieve_plugin_tool(tool)
|
69
|
+
tool_name = to_tool_name(tool)
|
70
|
+
tool_destination = File.join(tools_path, tool_name)
|
71
|
+
|
72
|
+
if File.exist? tool_destination
|
73
|
+
log_debug "#{tool_name.capitalize} already present"
|
74
|
+
else
|
75
|
+
log_info "Retrieving #{tool_name.capitalize} using #{tool.class.name}"
|
76
|
+
FileUtils.mkdir_p tool_destination
|
77
|
+
|
78
|
+
tool.retrieve tool_destination
|
79
|
+
|
80
|
+
log_debug "#{tool_name.capitalize} retrieved"
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
def retrieve_from_build_tools_location(tool)
|
85
|
+
tools_location = @build_configuration.build_tools_location
|
86
|
+
tool_name = tool.to_s
|
87
|
+
tool_path = File.join(tools_location, tool_name)
|
88
|
+
tool_destination = File.join(tools_path, tool_name)
|
89
|
+
|
90
|
+
if File.exist? tool_destination
|
91
|
+
log_debug "#{tool_name.capitalize} already present"
|
92
|
+
else
|
93
|
+
log_info "Retrieving #{tool_name.capitalize} from #{tools_location}"
|
94
|
+
FileUtils.mkdir_p tool_destination
|
95
|
+
FileUtils.cp_r tool_path, tools_path
|
96
|
+
log_debug "#{tool_name.capitalize} retrieved"
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
def to_tool_name(object)
|
101
|
+
object.class.name.split('::').last.downcase
|
102
|
+
end
|
103
|
+
|
104
|
+
end
|
105
|
+
|
106
|
+
end
|
@@ -1,17 +1,17 @@
|
|
1
|
-
module Bozo
|
2
|
-
|
3
|
-
module ClassNameHelpers
|
4
|
-
|
5
|
-
# Converts a symbol into a Pascal Case class name.
|
6
|
-
#
|
7
|
-
# eg. `:single` => `"Single"`, `:two_words` => `"TwoWords"`.
|
8
|
-
#
|
9
|
-
# @param [Symbol] type
|
10
|
-
# The name of a step executor.
|
11
|
-
def to_class_name(type)
|
12
|
-
type.to_s.split('_').map{|word| word.capitalize}.join
|
13
|
-
end
|
14
|
-
|
15
|
-
end
|
16
|
-
|
1
|
+
module Bozo
|
2
|
+
|
3
|
+
module ClassNameHelpers
|
4
|
+
|
5
|
+
# Converts a symbol into a Pascal Case class name.
|
6
|
+
#
|
7
|
+
# eg. `:single` => `"Single"`, `:two_words` => `"TwoWords"`.
|
8
|
+
#
|
9
|
+
# @param [Symbol] type
|
10
|
+
# The name of a step executor.
|
11
|
+
def to_class_name(type)
|
12
|
+
type.to_s.split('_').map{|word| word.capitalize}.join
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
16
|
+
|
17
17
|
end
|
@@ -1,30 +1,30 @@
|
|
1
|
-
module Bozo
|
2
|
-
|
3
|
-
# Error raised when a runner or hook finds the configuration or build in an
|
4
|
-
# unexpected state.
|
5
|
-
class ConfigurationError < StandardError
|
6
|
-
|
7
|
-
# The code the program should exit with upon handling this error.
|
8
|
-
attr_reader :exit_code
|
9
|
-
|
10
|
-
# A message explaining the corrective actions someone can take to avoid the
|
11
|
-
# error.
|
12
|
-
attr_reader :message
|
13
|
-
|
14
|
-
# Creates a new instance.
|
15
|
-
#
|
16
|
-
# @param [String] message
|
17
|
-
# A message explaining the corrective actions someone can take to avoid
|
18
|
-
# the error.
|
19
|
-
def initialize(message)
|
20
|
-
@message = message
|
21
|
-
@exit_code = -1
|
22
|
-
end
|
23
|
-
|
24
|
-
def inspect
|
25
|
-
"Configuration error: #{message}"
|
26
|
-
end
|
27
|
-
|
28
|
-
end
|
29
|
-
|
1
|
+
module Bozo
|
2
|
+
|
3
|
+
# Error raised when a runner or hook finds the configuration or build in an
|
4
|
+
# unexpected state.
|
5
|
+
class ConfigurationError < StandardError
|
6
|
+
|
7
|
+
# The code the program should exit with upon handling this error.
|
8
|
+
attr_reader :exit_code
|
9
|
+
|
10
|
+
# A message explaining the corrective actions someone can take to avoid the
|
11
|
+
# error.
|
12
|
+
attr_reader :message
|
13
|
+
|
14
|
+
# Creates a new instance.
|
15
|
+
#
|
16
|
+
# @param [String] message
|
17
|
+
# A message explaining the corrective actions someone can take to avoid
|
18
|
+
# the error.
|
19
|
+
def initialize(message)
|
20
|
+
@message = message
|
21
|
+
@exit_code = -1
|
22
|
+
end
|
23
|
+
|
24
|
+
def inspect
|
25
|
+
"Configuration error: #{message}"
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
|
30
30
|
end
|
data/lib/bozo/execution_error.rb
CHANGED
@@ -1,36 +1,36 @@
|
|
1
|
-
module Bozo
|
2
|
-
|
3
|
-
# Error raised when a command line executable does not return an exit code of
|
4
|
-
# zero.
|
5
|
-
class ExecutionError < StandardError
|
6
|
-
|
7
|
-
# The array of parameters that made up the call.
|
8
|
-
attr_reader :command
|
9
|
-
|
10
|
-
# The exit code returned by the command.
|
11
|
-
attr_reader :exit_code
|
12
|
-
|
13
|
-
# The friendly name of the tool that failed.
|
14
|
-
attr_reader :tool
|
15
|
-
|
16
|
-
# Create a new instance.
|
17
|
-
#
|
18
|
-
# @param [Symbol] tool
|
19
|
-
# The friendly name of the tool that failed.
|
20
|
-
# @param [Array] command
|
21
|
-
# The array of parameters that made up the call.
|
22
|
-
# @param [Integer] exit_code
|
23
|
-
# The exit code returned by the command
|
24
|
-
def initialize(tool, command, exit_code)
|
25
|
-
@tool = tool
|
26
|
-
@command = command
|
27
|
-
@exit_code = exit_code
|
28
|
-
end
|
29
|
-
|
30
|
-
def inspect
|
31
|
-
"Execution error: Exit code of #{exit_code} returned from: #{tool} #{command[1..-1].join(' ')}"
|
32
|
-
end
|
33
|
-
|
34
|
-
end
|
35
|
-
|
1
|
+
module Bozo
|
2
|
+
|
3
|
+
# Error raised when a command line executable does not return an exit code of
|
4
|
+
# zero.
|
5
|
+
class ExecutionError < StandardError
|
6
|
+
|
7
|
+
# The array of parameters that made up the call.
|
8
|
+
attr_reader :command
|
9
|
+
|
10
|
+
# The exit code returned by the command.
|
11
|
+
attr_reader :exit_code
|
12
|
+
|
13
|
+
# The friendly name of the tool that failed.
|
14
|
+
attr_reader :tool
|
15
|
+
|
16
|
+
# Create a new instance.
|
17
|
+
#
|
18
|
+
# @param [Symbol] tool
|
19
|
+
# The friendly name of the tool that failed.
|
20
|
+
# @param [Array] command
|
21
|
+
# The array of parameters that made up the call.
|
22
|
+
# @param [Integer] exit_code
|
23
|
+
# The exit code returned by the command
|
24
|
+
def initialize(tool, command, exit_code)
|
25
|
+
@tool = tool
|
26
|
+
@command = command
|
27
|
+
@exit_code = exit_code
|
28
|
+
end
|
29
|
+
|
30
|
+
def inspect
|
31
|
+
"Execution error: Exit code of #{exit_code} returned from: #{tool} #{command[1..-1].join(' ')}"
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
35
|
+
|
36
36
|
end
|
data/lib/bozo/executor.rb
CHANGED
@@ -1,289 +1,264 @@
|
|
1
|
-
module Bozo
|
2
|
-
|
3
|
-
# Class defining the structure of the build and responsible for executing
|
4
|
-
# tasks and their dependencies.
|
5
|
-
class Executor
|
6
|
-
include Runner
|
7
|
-
|
8
|
-
# Create a new instance.
|
9
|
-
#
|
10
|
-
# @param [Configuration] build_configuration
|
11
|
-
# The build configuration.
|
12
|
-
# @param [Hash] global_params
|
13
|
-
# The global parameters
|
14
|
-
def initialize(build_configuration, global_params)
|
15
|
-
@build_configuration = build_configuration
|
16
|
-
@global_params = cli_keys_to_ruby global_params
|
17
|
-
end
|
18
|
-
|
19
|
-
# Executes the command using the given parameters and environment.
|
20
|
-
#
|
21
|
-
# @param [Symbol] command
|
22
|
-
# The name of the command to execute.
|
23
|
-
# @param [Hash] params
|
24
|
-
# The parameters for the command.
|
25
|
-
# @param [Hash] env
|
26
|
-
# The environment that the command is run within.
|
27
|
-
def execute(command, params, env)
|
28
|
-
with_hooks :build, params, env do
|
29
|
-
send command, params, env
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
# Runs the clean task.
|
34
|
-
#
|
35
|
-
# @param [Hash] params
|
36
|
-
# The parameters for the command.
|
37
|
-
# @param [Hash] env
|
38
|
-
# The environment that the command is run within.
|
39
|
-
def clean(params, env)
|
40
|
-
with_hooks :clean, params, env do
|
41
|
-
log_info 'Cleaning project'
|
42
|
-
clear_directory 'temp'
|
43
|
-
clear_directory 'dist'
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
# Runs the uninstall task.
|
48
|
-
#
|
49
|
-
# @param [Hash] params
|
50
|
-
# The parameters for the command.
|
51
|
-
# @param [Hash] env
|
52
|
-
# The environment that the command is run within.
|
53
|
-
def uninstall(params, env)
|
54
|
-
clean params, env
|
55
|
-
with_hooks :uninstall, params, env do
|
56
|
-
log_info 'Uninstalling project'
|
57
|
-
clear_directory 'packages'
|
58
|
-
clear_directory 'build'
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
# Runs the dependency retrieval task.
|
63
|
-
#
|
64
|
-
# @param [Hash] params
|
65
|
-
# The parameters for the command.
|
66
|
-
# @param [Hash] env
|
67
|
-
# The environment that the command is run within.
|
68
|
-
def dependencies(params, env)
|
69
|
-
clean params, env
|
70
|
-
|
71
|
-
execute_with_hooks :dependencies, params, env
|
72
|
-
end
|
73
|
-
|
74
|
-
# Runs the prepare task.
|
75
|
-
#
|
76
|
-
# @param [Hash] params
|
77
|
-
# The parameters for the command.
|
78
|
-
# @param [Hash] env
|
79
|
-
# The environment that the command is run within.
|
80
|
-
def prepare(params, env)
|
81
|
-
dependencies params, env
|
82
|
-
execute_with_hooks :prepare, params, env
|
83
|
-
end
|
84
|
-
|
85
|
-
# Runs the compile task.
|
86
|
-
#
|
87
|
-
# @param [Hash] params
|
88
|
-
# The parameters for the command.
|
89
|
-
# @param [Hash] env
|
90
|
-
# The environment that the command is run within.
|
91
|
-
def compile(params, env)
|
92
|
-
prepare params, env
|
93
|
-
execute_with_hooks :compile, params, env
|
94
|
-
end
|
95
|
-
|
96
|
-
# Runs the test task.
|
97
|
-
#
|
98
|
-
# @param [Hash] params
|
99
|
-
# The parameters for the command.
|
100
|
-
# @param [Hash] env
|
101
|
-
# The environment that the command is run within.
|
102
|
-
def test(params, env)
|
103
|
-
compile params, env
|
104
|
-
execute_with_hooks :test, params, env
|
105
|
-
end
|
106
|
-
|
107
|
-
# Runs the package task.
|
108
|
-
#
|
109
|
-
# @param [Hash] params
|
110
|
-
# The parameters for the command.
|
111
|
-
# @param [Hash] env
|
112
|
-
# The environment that the command is run within.
|
113
|
-
def package(params, env)
|
114
|
-
test params, env
|
115
|
-
execute_with_hooks :package, params, env
|
116
|
-
end
|
117
|
-
|
118
|
-
# Runs the publish task.
|
119
|
-
#
|
120
|
-
# @param [Hash] params
|
121
|
-
# The parameters for the command.
|
122
|
-
# @param [Hash] env
|
123
|
-
# The environment that the command is run within.
|
124
|
-
def publish(params, env)
|
125
|
-
if build_server?
|
126
|
-
package params, env
|
127
|
-
execute_with_hooks :publish, params, env
|
128
|
-
else
|
129
|
-
log_warn 'You can only publish a package from build server.'
|
130
|
-
log_warn ''
|
131
|
-
log_warn 'If you really need to publish the package then provide the --build-server switch but you should only be doing that as a last resort.'
|
132
|
-
end
|
133
|
-
end
|
134
|
-
|
135
|
-
private
|
136
|
-
|
137
|
-
# Executes the executors for the given stage logging all messages with the
|
138
|
-
# given action.
|
139
|
-
#
|
140
|
-
# @param [Symbol] stage
|
141
|
-
# The name of the stage to execute.
|
142
|
-
# @param [Hash] params
|
143
|
-
# The parameters for the command.
|
144
|
-
# @param [Hash] env
|
145
|
-
# The environment that the command is run within.
|
146
|
-
def execute_with_hooks(stage, params, env)
|
147
|
-
action, executors = stage_definition stage
|
148
|
-
with_hooks stage, params, env do
|
149
|
-
log_info '' # blank line for aesthetics
|
150
|
-
log_info action
|
151
|
-
log_debug 'No executors' if executors.empty?
|
152
|
-
executors.each do |executor|
|
153
|
-
log_debug "#{action} with #{executor.class}"
|
154
|
-
set_parameters executor, params, env
|
155
|
-
executor.execute
|
156
|
-
end
|
157
|
-
end
|
158
|
-
end
|
159
|
-
|
160
|
-
# Gets the description and runners associated with the given stage.
|
161
|
-
#
|
162
|
-
# @params [Symbol] stage
|
163
|
-
# The name of the stage.
|
164
|
-
def stage_definition(stage)
|
165
|
-
case stage
|
166
|
-
when :dependencies
|
167
|
-
return 'Resolving dependencies', @build_configuration.dependency_resolvers
|
168
|
-
when :compile
|
169
|
-
return 'Compiling', @build_configuration.compilers
|
170
|
-
when :test
|
171
|
-
return 'Running tests', @build_configuration.test_runners
|
172
|
-
when :package
|
173
|
-
return 'Packaging', @build_configuration.packagers
|
174
|
-
when :prepare
|
175
|
-
return 'Preparing', @build_configuration.preparers
|
176
|
-
when :publish
|
177
|
-
return 'Publishing', @build_configuration.publishers
|
178
|
-
else
|
179
|
-
raise "Unrecognized stage: #{stage}"
|
180
|
-
end
|
181
|
-
end
|
182
|
-
|
183
|
-
# Runs the given code block surrounding it with the hooks for the named
|
184
|
-
# stage.
|
185
|
-
#
|
186
|
-
# @param [Symbol] stage
|
187
|
-
# The name of the stage being run.
|
188
|
-
# @param [Hash] params
|
189
|
-
# The parameters for the command.
|
190
|
-
# @param [Hash] env
|
191
|
-
# The environment that the command is run within.
|
192
|
-
def with_hooks(stage, params, env)
|
193
|
-
call_receiving_hooks "pre_#{stage}".to_sym, params, env
|
194
|
-
|
195
|
-
begin
|
196
|
-
yield
|
197
|
-
rescue
|
198
|
-
call_receiving_hooks "failed_#{stage}".to_sym, params, env
|
199
|
-
raise
|
200
|
-
end
|
201
|
-
|
202
|
-
call_receiving_hooks "post_#{stage}".to_sym, params, env
|
203
|
-
end
|
204
|
-
|
205
|
-
# Invokes the method for the hook for all hook objects that define a
|
206
|
-
# method for it.
|
207
|
-
#
|
208
|
-
# @param [Symbol] stage
|
209
|
-
# The name of the hook to call the methods for.
|
210
|
-
# @param [Hash] params
|
211
|
-
# The parameters for the command.
|
212
|
-
# @param [Hash] env
|
213
|
-
# The environment that the command is run within.
|
214
|
-
def call_receiving_hooks(stage, params, env)
|
215
|
-
@build_configuration.hooks.each do |hook|
|
216
|
-
if hook.respond_to? stage
|
217
|
-
set_parameters hook, params, env
|
218
|
-
hook.send stage
|
219
|
-
end
|
220
|
-
end
|
221
|
-
end
|
222
|
-
|
223
|
-
# Assigns the state of the build system to the runner.
|
224
|
-
#
|
225
|
-
# @param [Runner] runner
|
226
|
-
# The runner to assign the state to.
|
227
|
-
# @param [Hash] params
|
228
|
-
# The parameters for the step.
|
229
|
-
# @param [Hash] env
|
230
|
-
# The environment that the step is run within.
|
231
|
-
def set_parameters(runner, params, env)
|
232
|
-
runner.build_configuration = @build_configuration
|
233
|
-
runner.global_params = @global_params
|
234
|
-
runner.params = cli_keys_to_ruby params
|
235
|
-
runner.env = env
|
236
|
-
end
|
237
|
-
|
238
|
-
# Removes the named directory from the root directory.
|
239
|
-
#
|
240
|
-
# @param [String] dir
|
241
|
-
# The name of the directory to remove.
|
242
|
-
def clear_directory(dir)
|
243
|
-
full_path = File.expand_path(dir)
|
244
|
-
log_debug "Clearing directory #{full_path}"
|
245
|
-
FileUtils.rm_rf full_path
|
246
|
-
end
|
247
|
-
|
248
|
-
#
|
249
|
-
#
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
else
|
265
|
-
log_debug "Retrieving #{tool_name.capitalize}"
|
266
|
-
FileUtils.mkdir_p tool_destination
|
267
|
-
FileUtils.cp_r tool_path, tools_path
|
268
|
-
log_debug "#{tool_name.capitalize} retrieved"
|
269
|
-
end
|
270
|
-
end
|
271
|
-
end
|
272
|
-
|
273
|
-
# Converts a hash containing CLI-style keys (:'multi-word') and converts
|
274
|
-
# them into Ruby-style symbols (:multi_word).
|
275
|
-
#
|
276
|
-
# @param [Hash] hash
|
277
|
-
# A hash containing CLI-style keys.
|
278
|
-
def cli_keys_to_ruby(hash)
|
279
|
-
hash.keys.to_a.each do |key|
|
280
|
-
new_key = key.to_s.gsub('-', '_').to_sym
|
281
|
-
hash[new_key] = hash[key] unless hash.has_key? new_key
|
282
|
-
end
|
283
|
-
|
284
|
-
hash
|
285
|
-
end
|
286
|
-
|
287
|
-
end
|
288
|
-
|
1
|
+
module Bozo
|
2
|
+
|
3
|
+
# Class defining the structure of the build and responsible for executing
|
4
|
+
# tasks and their dependencies.
|
5
|
+
class Executor
|
6
|
+
include Runner
|
7
|
+
|
8
|
+
# Create a new instance.
|
9
|
+
#
|
10
|
+
# @param [Configuration] build_configuration
|
11
|
+
# The build configuration.
|
12
|
+
# @param [Hash] global_params
|
13
|
+
# The global parameters
|
14
|
+
def initialize(build_configuration, global_params)
|
15
|
+
@build_configuration = build_configuration
|
16
|
+
@global_params = cli_keys_to_ruby global_params
|
17
|
+
end
|
18
|
+
|
19
|
+
# Executes the command using the given parameters and environment.
|
20
|
+
#
|
21
|
+
# @param [Symbol] command
|
22
|
+
# The name of the command to execute.
|
23
|
+
# @param [Hash] params
|
24
|
+
# The parameters for the command.
|
25
|
+
# @param [Hash] env
|
26
|
+
# The environment that the command is run within.
|
27
|
+
def execute(command, params, env)
|
28
|
+
with_hooks :build, params, env do
|
29
|
+
send command, params, env
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
# Runs the clean task.
|
34
|
+
#
|
35
|
+
# @param [Hash] params
|
36
|
+
# The parameters for the command.
|
37
|
+
# @param [Hash] env
|
38
|
+
# The environment that the command is run within.
|
39
|
+
def clean(params, env)
|
40
|
+
with_hooks :clean, params, env do
|
41
|
+
log_info 'Cleaning project'
|
42
|
+
clear_directory 'temp'
|
43
|
+
clear_directory 'dist'
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
# Runs the uninstall task.
|
48
|
+
#
|
49
|
+
# @param [Hash] params
|
50
|
+
# The parameters for the command.
|
51
|
+
# @param [Hash] env
|
52
|
+
# The environment that the command is run within.
|
53
|
+
def uninstall(params, env)
|
54
|
+
clean params, env
|
55
|
+
with_hooks :uninstall, params, env do
|
56
|
+
log_info 'Uninstalling project'
|
57
|
+
clear_directory 'packages'
|
58
|
+
clear_directory 'build'
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
# Runs the dependency retrieval task.
|
63
|
+
#
|
64
|
+
# @param [Hash] params
|
65
|
+
# The parameters for the command.
|
66
|
+
# @param [Hash] env
|
67
|
+
# The environment that the command is run within.
|
68
|
+
def dependencies(params, env)
|
69
|
+
clean params, env
|
70
|
+
BuildDependencyResolver.new(@build_configuration).resolve
|
71
|
+
execute_with_hooks :dependencies, params, env
|
72
|
+
end
|
73
|
+
|
74
|
+
# Runs the prepare task.
|
75
|
+
#
|
76
|
+
# @param [Hash] params
|
77
|
+
# The parameters for the command.
|
78
|
+
# @param [Hash] env
|
79
|
+
# The environment that the command is run within.
|
80
|
+
def prepare(params, env)
|
81
|
+
dependencies params, env
|
82
|
+
execute_with_hooks :prepare, params, env
|
83
|
+
end
|
84
|
+
|
85
|
+
# Runs the compile task.
|
86
|
+
#
|
87
|
+
# @param [Hash] params
|
88
|
+
# The parameters for the command.
|
89
|
+
# @param [Hash] env
|
90
|
+
# The environment that the command is run within.
|
91
|
+
def compile(params, env)
|
92
|
+
prepare params, env
|
93
|
+
execute_with_hooks :compile, params, env
|
94
|
+
end
|
95
|
+
|
96
|
+
# Runs the test task.
|
97
|
+
#
|
98
|
+
# @param [Hash] params
|
99
|
+
# The parameters for the command.
|
100
|
+
# @param [Hash] env
|
101
|
+
# The environment that the command is run within.
|
102
|
+
def test(params, env)
|
103
|
+
compile params, env
|
104
|
+
execute_with_hooks :test, params, env
|
105
|
+
end
|
106
|
+
|
107
|
+
# Runs the package task.
|
108
|
+
#
|
109
|
+
# @param [Hash] params
|
110
|
+
# The parameters for the command.
|
111
|
+
# @param [Hash] env
|
112
|
+
# The environment that the command is run within.
|
113
|
+
def package(params, env)
|
114
|
+
test params, env
|
115
|
+
execute_with_hooks :package, params, env
|
116
|
+
end
|
117
|
+
|
118
|
+
# Runs the publish task.
|
119
|
+
#
|
120
|
+
# @param [Hash] params
|
121
|
+
# The parameters for the command.
|
122
|
+
# @param [Hash] env
|
123
|
+
# The environment that the command is run within.
|
124
|
+
def publish(params, env)
|
125
|
+
if build_server?
|
126
|
+
package params, env
|
127
|
+
execute_with_hooks :publish, params, env
|
128
|
+
else
|
129
|
+
log_warn 'You can only publish a package from build server.'
|
130
|
+
log_warn ''
|
131
|
+
log_warn 'If you really need to publish the package then provide the --build-server switch but you should only be doing that as a last resort.'
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
private
|
136
|
+
|
137
|
+
# Executes the executors for the given stage logging all messages with the
|
138
|
+
# given action.
|
139
|
+
#
|
140
|
+
# @param [Symbol] stage
|
141
|
+
# The name of the stage to execute.
|
142
|
+
# @param [Hash] params
|
143
|
+
# The parameters for the command.
|
144
|
+
# @param [Hash] env
|
145
|
+
# The environment that the command is run within.
|
146
|
+
def execute_with_hooks(stage, params, env)
|
147
|
+
action, executors = stage_definition stage
|
148
|
+
with_hooks stage, params, env do
|
149
|
+
log_info '' # blank line for aesthetics
|
150
|
+
log_info action
|
151
|
+
log_debug 'No executors' if executors.empty?
|
152
|
+
executors.each do |executor|
|
153
|
+
log_debug "#{action} with #{executor.class}"
|
154
|
+
set_parameters executor, params, env
|
155
|
+
executor.execute
|
156
|
+
end
|
157
|
+
end
|
158
|
+
end
|
159
|
+
|
160
|
+
# Gets the description and runners associated with the given stage.
|
161
|
+
#
|
162
|
+
# @params [Symbol] stage
|
163
|
+
# The name of the stage.
|
164
|
+
def stage_definition(stage)
|
165
|
+
case stage
|
166
|
+
when :dependencies
|
167
|
+
return 'Resolving dependencies', @build_configuration.dependency_resolvers
|
168
|
+
when :compile
|
169
|
+
return 'Compiling', @build_configuration.compilers
|
170
|
+
when :test
|
171
|
+
return 'Running tests', @build_configuration.test_runners
|
172
|
+
when :package
|
173
|
+
return 'Packaging', @build_configuration.packagers
|
174
|
+
when :prepare
|
175
|
+
return 'Preparing', @build_configuration.preparers
|
176
|
+
when :publish
|
177
|
+
return 'Publishing', @build_configuration.publishers
|
178
|
+
else
|
179
|
+
raise "Unrecognized stage: #{stage}"
|
180
|
+
end
|
181
|
+
end
|
182
|
+
|
183
|
+
# Runs the given code block surrounding it with the hooks for the named
|
184
|
+
# stage.
|
185
|
+
#
|
186
|
+
# @param [Symbol] stage
|
187
|
+
# The name of the stage being run.
|
188
|
+
# @param [Hash] params
|
189
|
+
# The parameters for the command.
|
190
|
+
# @param [Hash] env
|
191
|
+
# The environment that the command is run within.
|
192
|
+
def with_hooks(stage, params, env)
|
193
|
+
call_receiving_hooks "pre_#{stage}".to_sym, params, env
|
194
|
+
|
195
|
+
begin
|
196
|
+
yield
|
197
|
+
rescue
|
198
|
+
call_receiving_hooks "failed_#{stage}".to_sym, params, env
|
199
|
+
raise
|
200
|
+
end
|
201
|
+
|
202
|
+
call_receiving_hooks "post_#{stage}".to_sym, params, env
|
203
|
+
end
|
204
|
+
|
205
|
+
# Invokes the method for the hook for all hook objects that define a
|
206
|
+
# method for it.
|
207
|
+
#
|
208
|
+
# @param [Symbol] stage
|
209
|
+
# The name of the hook to call the methods for.
|
210
|
+
# @param [Hash] params
|
211
|
+
# The parameters for the command.
|
212
|
+
# @param [Hash] env
|
213
|
+
# The environment that the command is run within.
|
214
|
+
def call_receiving_hooks(stage, params, env)
|
215
|
+
@build_configuration.hooks.each do |hook|
|
216
|
+
if hook.respond_to? stage
|
217
|
+
set_parameters hook, params, env
|
218
|
+
hook.send stage
|
219
|
+
end
|
220
|
+
end
|
221
|
+
end
|
222
|
+
|
223
|
+
# Assigns the state of the build system to the runner.
|
224
|
+
#
|
225
|
+
# @param [Runner] runner
|
226
|
+
# The runner to assign the state to.
|
227
|
+
# @param [Hash] params
|
228
|
+
# The parameters for the step.
|
229
|
+
# @param [Hash] env
|
230
|
+
# The environment that the step is run within.
|
231
|
+
def set_parameters(runner, params, env)
|
232
|
+
runner.build_configuration = @build_configuration
|
233
|
+
runner.global_params = @global_params
|
234
|
+
runner.params = cli_keys_to_ruby params
|
235
|
+
runner.env = env
|
236
|
+
end
|
237
|
+
|
238
|
+
# Removes the named directory from the root directory.
|
239
|
+
#
|
240
|
+
# @param [String] dir
|
241
|
+
# The name of the directory to remove.
|
242
|
+
def clear_directory(dir)
|
243
|
+
full_path = File.expand_path(dir)
|
244
|
+
log_debug "Clearing directory #{full_path}"
|
245
|
+
FileUtils.rm_rf full_path
|
246
|
+
end
|
247
|
+
|
248
|
+
# Converts a hash containing CLI-style keys (:'multi-word') and converts
|
249
|
+
# them into Ruby-style symbols (:multi_word).
|
250
|
+
#
|
251
|
+
# @param [Hash] hash
|
252
|
+
# A hash containing CLI-style keys.
|
253
|
+
def cli_keys_to_ruby(hash)
|
254
|
+
hash.keys.to_a.each do |key|
|
255
|
+
new_key = key.to_s.gsub('-', '_').to_sym
|
256
|
+
hash[new_key] = hash[key] unless hash.has_key? new_key
|
257
|
+
end
|
258
|
+
|
259
|
+
hash
|
260
|
+
end
|
261
|
+
|
262
|
+
end
|
263
|
+
|
289
264
|
end
|