raystool 1.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/__rays_exec.rb +31 -0
- data/bin/__rays_init +79 -0
- data/lib/rays/config/backup.rb +42 -0
- data/lib/rays/config/configuration.rb +376 -0
- data/lib/rays/config/environment.rb +73 -0
- data/lib/rays/config/templates/global/global.yml +3 -0
- data/lib/rays/config/templates/global/scripts/rays +187 -0
- data/lib/rays/config/templates/project/.rays +0 -0
- data/lib/rays/config/templates/project/config/environment.yml +68 -0
- data/lib/rays/config/templates/project/config/project.yml +4 -0
- data/lib/rays/core.rb +128 -0
- data/lib/rays/exceptions/rays_exception.rb +25 -0
- data/lib/rays/interface/commander.rb +394 -0
- data/lib/rays/interface/controller.rb +365 -0
- data/lib/rays/loaders/highline.rb +24 -0
- data/lib/rays/loaders/logging.rb +60 -0
- data/lib/rays/models/appmodule/base.rb +185 -0
- data/lib/rays/models/appmodule/content.rb +35 -0
- data/lib/rays/models/appmodule/ext.rb +36 -0
- data/lib/rays/models/appmodule/hook.rb +36 -0
- data/lib/rays/models/appmodule/layout.rb +36 -0
- data/lib/rays/models/appmodule/manager.rb +130 -0
- data/lib/rays/models/appmodule/portlet.rb +36 -0
- data/lib/rays/models/appmodule/servicebuilder.rb +36 -0
- data/lib/rays/models/appmodule/theme.rb +36 -0
- data/lib/rays/models/project.rb +116 -0
- data/lib/rays/servers/base.rb +70 -0
- data/lib/rays/servers/database.rb +73 -0
- data/lib/rays/servers/liferay.rb +64 -0
- data/lib/rays/servers/solr.rb +111 -0
- data/lib/rays/services/application_service.rb +116 -0
- data/lib/rays/services/backup_service.rb +94 -0
- data/lib/rays/services/database.rb +59 -0
- data/lib/rays/services/remote.rb +75 -0
- data/lib/rays/services/scm.rb +92 -0
- data/lib/rays/services/sync.rb +90 -0
- data/lib/rays/utils/common_utils.rb +153 -0
- data/lib/rays/utils/file_utils.rb +118 -0
- data/lib/rays/utils/network_utils.rb +50 -0
- data/lib/rays/workers/base.rb +134 -0
- data/lib/rays/workers/builder.rb +63 -0
- data/lib/rays/workers/cleaner.rb +42 -0
- data/lib/rays/workers/deployer.rb +92 -0
- data/lib/rays/workers/generator.rb +49 -0
- metadata +175 -0
@@ -0,0 +1,365 @@
|
|
1
|
+
=begin
|
2
|
+
Copyright (c) 2012 Dmitri Carpov
|
3
|
+
|
4
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
5
|
+
a copy of this software and associated documentation files (the
|
6
|
+
"Software"), to deal in the Software without restriction, including
|
7
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
8
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
9
|
+
permit persons to whom the Software is furnished to do so, subject to
|
10
|
+
the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be
|
13
|
+
included in all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
16
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
17
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
18
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
19
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
20
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
21
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
22
|
+
=end
|
23
|
+
|
24
|
+
require 'rays/core'
|
25
|
+
|
26
|
+
module Rays
|
27
|
+
class Controller
|
28
|
+
include Singleton
|
29
|
+
|
30
|
+
#
|
31
|
+
# Create new project
|
32
|
+
#
|
33
|
+
def create_project(project_name)
|
34
|
+
log_block("create project #{project_name}") do
|
35
|
+
Project.create project_name
|
36
|
+
$log.warn("setup your project environments in #{$rays_config.project_root}/config/environment.yml")
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
#
|
41
|
+
# init project on the current directory
|
42
|
+
#
|
43
|
+
def init_project
|
44
|
+
log_block("init project") do
|
45
|
+
Project.init
|
46
|
+
$log.warn("setup your project environments in #{$rays_config.project_root}/config/environment.yml")
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
#
|
51
|
+
# Show modules
|
52
|
+
#
|
53
|
+
def show_modules
|
54
|
+
log_block("show modules") do
|
55
|
+
AppModule::Manager.instance.all.each do |appmodule|
|
56
|
+
$log.info("#{appmodule.type}: <!#{appmodule.name}!>")
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
|
62
|
+
#
|
63
|
+
# Create a module
|
64
|
+
#
|
65
|
+
def create_module(type, name, generator)
|
66
|
+
log_block("create #{type} #{name}") do
|
67
|
+
AppModule::Manager.instance.create type, name, generator
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
#
|
72
|
+
# Build module(s)
|
73
|
+
#
|
74
|
+
def build(skip_test, modules = nil)
|
75
|
+
show_environment_info
|
76
|
+
log_block("build module(s)") do
|
77
|
+
unless modules.nil?
|
78
|
+
modules.each do |app_module|
|
79
|
+
app_module.build skip_test
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
#
|
86
|
+
# Build and deploy module(s).
|
87
|
+
#
|
88
|
+
def deploy(skip_test, modules = nil)
|
89
|
+
show_environment_info
|
90
|
+
log_block("build and deploy module(s)") do
|
91
|
+
unless modules.nil?
|
92
|
+
modules.each do |app_module|
|
93
|
+
app_module.build skip_test
|
94
|
+
app_module.deploy
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
#
|
101
|
+
# Deploy module(s). No build.
|
102
|
+
#
|
103
|
+
def deploy_no_build(modules=nil)
|
104
|
+
show_environment_info
|
105
|
+
log_block("deploy module(s)") do
|
106
|
+
unless modules.nil?
|
107
|
+
modules.each do |app_module|
|
108
|
+
app_module.deploy
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
#
|
115
|
+
# Clean module(s).
|
116
|
+
#
|
117
|
+
def clean(modules=nil)
|
118
|
+
show_environment_info
|
119
|
+
log_block("deploy module(s)") do
|
120
|
+
unless modules.nil?
|
121
|
+
modules.each do |app_module|
|
122
|
+
app_module.clean
|
123
|
+
end
|
124
|
+
end
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
#
|
129
|
+
# Environment methods
|
130
|
+
#
|
131
|
+
def current_environment
|
132
|
+
log_block("get environment name") do
|
133
|
+
$log.info("<!#{$rays_config.environment.name}!>")
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
137
|
+
def list_environments
|
138
|
+
log_block("get environments list") do
|
139
|
+
$log.info("<!#{$rays_config.environments.keys.join(" ")}!>")
|
140
|
+
end
|
141
|
+
end
|
142
|
+
|
143
|
+
def switch_environment(env_name)
|
144
|
+
log_block("switch environment") do
|
145
|
+
$rays_config.environment = env_name
|
146
|
+
$log.info("<!#{env_name}!>")
|
147
|
+
end
|
148
|
+
end
|
149
|
+
|
150
|
+
#
|
151
|
+
# Point methods
|
152
|
+
#
|
153
|
+
def point(path, name)
|
154
|
+
log_block("remember a point") do
|
155
|
+
$rays_config.point(path, name)
|
156
|
+
end
|
157
|
+
end
|
158
|
+
|
159
|
+
def points
|
160
|
+
log_block("show points") do
|
161
|
+
unless $rays_config.points.nil?
|
162
|
+
$rays_config.points.each_key do |point|
|
163
|
+
$log.info("#{point}: <!#{$rays_config.points[point]}!>")
|
164
|
+
end
|
165
|
+
else
|
166
|
+
$log.info('No points found')
|
167
|
+
end
|
168
|
+
end
|
169
|
+
end
|
170
|
+
|
171
|
+
def remove_point(name)
|
172
|
+
log_block("remove a point") do
|
173
|
+
$rays_config.remove_point(name)
|
174
|
+
end
|
175
|
+
end
|
176
|
+
|
177
|
+
def go(name)
|
178
|
+
log_block("switch directory") do
|
179
|
+
points = $rays_config.points
|
180
|
+
point_name = name
|
181
|
+
point_name ||= 'default'
|
182
|
+
if !points.nil? and points.include?(point_name)
|
183
|
+
dir = points[point_name]
|
184
|
+
if Dir.exists?(dir)
|
185
|
+
$log.info("<!#{dir}!>") # tricky part. it logs to shell the directory name which will be switch by a bash script.
|
186
|
+
else
|
187
|
+
raise RaysException
|
188
|
+
end
|
189
|
+
else
|
190
|
+
raise RaysException.new("no point #{name}. use <!rays point!> to create points")
|
191
|
+
end
|
192
|
+
end
|
193
|
+
end
|
194
|
+
|
195
|
+
def backup
|
196
|
+
log_block("backup") do
|
197
|
+
package = Rays::Service::Backup.new.backup
|
198
|
+
$log.info("Backup created: <!#{package}!>")
|
199
|
+
end
|
200
|
+
end
|
201
|
+
|
202
|
+
def sync
|
203
|
+
if 'local'.eql?($rays_config.environment.name)
|
204
|
+
$log.warn("Select not local environment to import to local.")
|
205
|
+
return
|
206
|
+
end
|
207
|
+
log_block("synchronize environments") do
|
208
|
+
Rays::Service::Sync.new.sync
|
209
|
+
end
|
210
|
+
end
|
211
|
+
|
212
|
+
#
|
213
|
+
# Start liferay's application server
|
214
|
+
#
|
215
|
+
def liferay_start(force=false)
|
216
|
+
show_environment_info
|
217
|
+
task('starting server', 'start command has been sent', 'failed to start the server') do
|
218
|
+
service = $rays_config.environment.liferay.service
|
219
|
+
if service.remote? and !force
|
220
|
+
$log.warn("WARNING: you are trying to start a remote server.")
|
221
|
+
$log.warn("Your current environment is <!#{$rays_config.environment.name}!>.")
|
222
|
+
$log.warn("Use <!--force!> option if you really want to start remote liferay server.")
|
223
|
+
return
|
224
|
+
end
|
225
|
+
service.start
|
226
|
+
end
|
227
|
+
end
|
228
|
+
|
229
|
+
#
|
230
|
+
# Start liferay's application server in debug mode
|
231
|
+
#
|
232
|
+
def liferay_debug(force=false)
|
233
|
+
show_environment_info
|
234
|
+
task('starting server in debug mode', 'start debug command has been sent', 'failed to start the server in debug mode') do
|
235
|
+
service = $rays_config.environment.liferay.service
|
236
|
+
if service.remote? and !force
|
237
|
+
$log.warn("WARNING: you are trying to debug a remote server.")
|
238
|
+
$log.warn("Your current environment is <!#{$rays_config.environment.name}!>.")
|
239
|
+
$log.warn("Use <!--force!> option if you really want to start remote liferay server.")
|
240
|
+
return
|
241
|
+
end
|
242
|
+
service.debug
|
243
|
+
end
|
244
|
+
end
|
245
|
+
|
246
|
+
#
|
247
|
+
# Stop liferay's application server
|
248
|
+
#
|
249
|
+
def liferay_stop(force=false)
|
250
|
+
show_environment_info
|
251
|
+
task('stopping server', 'stop command has been sent', 'failed to stop the server') do
|
252
|
+
service = $rays_config.environment.liferay.service
|
253
|
+
if service.remote? and !force
|
254
|
+
$log.warn("WARNING: you are trying to stop a remote server.")
|
255
|
+
$log.warn("Your current environment is <!#{$rays_config.environment.name}!>.")
|
256
|
+
$log.warn("Use <!--force!> option if you really want to stop remote liferay server.")
|
257
|
+
return
|
258
|
+
end
|
259
|
+
service.stop
|
260
|
+
end
|
261
|
+
end
|
262
|
+
|
263
|
+
#
|
264
|
+
# Show liferay server status
|
265
|
+
#
|
266
|
+
def liferay_status
|
267
|
+
show_environment_info
|
268
|
+
log_block('get server status') do
|
269
|
+
service = $rays_config.environment.liferay.service
|
270
|
+
|
271
|
+
if service.alive?
|
272
|
+
$log.info("running on #{service.host}:#{service.port}")
|
273
|
+
else
|
274
|
+
$log.info("stopped")
|
275
|
+
end
|
276
|
+
end
|
277
|
+
end
|
278
|
+
|
279
|
+
#
|
280
|
+
# Show liferay server logs
|
281
|
+
#
|
282
|
+
def liferay_log
|
283
|
+
show_environment_info
|
284
|
+
task('show server log', '', 'cannot access server log file') do
|
285
|
+
service = $rays_config.environment.liferay.service
|
286
|
+
service.log
|
287
|
+
end
|
288
|
+
end
|
289
|
+
|
290
|
+
#
|
291
|
+
# Clean solr index
|
292
|
+
#
|
293
|
+
def clean_solr_index
|
294
|
+
show_environment_info
|
295
|
+
log_block("clean solr index") do
|
296
|
+
$rays_config.environment.solr.clean_all
|
297
|
+
end
|
298
|
+
end
|
299
|
+
|
300
|
+
#
|
301
|
+
# Start solr application server
|
302
|
+
#
|
303
|
+
def solr_start(force=false)
|
304
|
+
show_environment_info
|
305
|
+
task('starting server', 'start command has been sent', 'failed to start the server') do
|
306
|
+
service = $rays_config.environment.solr.service
|
307
|
+
if service.remote? and !force
|
308
|
+
$log.warn("WARNING: you are trying to start a remote server.")
|
309
|
+
$log.warn("Your current environment is <!#{$rays_config.environment.name}!>.")
|
310
|
+
$log.warn("Use <!--force!> option if you really want to start a remote solr server.")
|
311
|
+
return
|
312
|
+
end
|
313
|
+
service.start
|
314
|
+
end
|
315
|
+
end
|
316
|
+
|
317
|
+
#
|
318
|
+
# Stop solr application server
|
319
|
+
#
|
320
|
+
def solr_stop(force=false)
|
321
|
+
show_environment_info
|
322
|
+
task('stopping server', 'stop command has been sent', 'failed to stop the server') do
|
323
|
+
service = $rays_config.environment.solr.service
|
324
|
+
if service.remote? and !force
|
325
|
+
$log.warn("WARNING: you are trying to stop a remote server.")
|
326
|
+
$log.warn("Your current environment is <!#{$rays_config.environment.name}!>.")
|
327
|
+
$log.warn("Use <!--force!> option if you really want to stop a remote solr server.")
|
328
|
+
return
|
329
|
+
end
|
330
|
+
service.stop
|
331
|
+
end
|
332
|
+
end
|
333
|
+
|
334
|
+
#
|
335
|
+
# Show solr server status
|
336
|
+
#
|
337
|
+
def solr_status
|
338
|
+
show_environment_info
|
339
|
+
log_block('get server status') do
|
340
|
+
service = $rays_config.environment.solr.service
|
341
|
+
if service.alive?
|
342
|
+
$log.info("running on #{service.host}:#{service.port}")
|
343
|
+
else
|
344
|
+
$log.info("stopped")
|
345
|
+
end
|
346
|
+
end
|
347
|
+
end
|
348
|
+
|
349
|
+
#
|
350
|
+
# Show solr server logs
|
351
|
+
#
|
352
|
+
def solr_log
|
353
|
+
show_environment_info
|
354
|
+
task('show server log', '', 'cannot access server log file') do
|
355
|
+
service = $rays_config.environment.solr.service
|
356
|
+
service.log
|
357
|
+
end
|
358
|
+
end
|
359
|
+
|
360
|
+
private
|
361
|
+
def show_environment_info
|
362
|
+
$log.info("environment: <!#{$rays_config.environment.name}!>")
|
363
|
+
end
|
364
|
+
end
|
365
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
=begin
|
2
|
+
Copyright (c) 2012 Dmitri Carpov
|
3
|
+
|
4
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
5
|
+
a copy of this software and associated documentation files (the
|
6
|
+
"Software"), to deal in the Software without restriction, including
|
7
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
8
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
9
|
+
permit persons to whom the Software is furnished to do so, subject to
|
10
|
+
the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be
|
13
|
+
included in all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
16
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
17
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
18
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
19
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
20
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
21
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
22
|
+
=end
|
23
|
+
|
24
|
+
$terminal = HighLine.new
|
@@ -0,0 +1,60 @@
|
|
1
|
+
=begin
|
2
|
+
Copyright (c) 2012 Dmitri Carpov
|
3
|
+
|
4
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
5
|
+
a copy of this software and associated documentation files (the
|
6
|
+
"Software"), to deal in the Software without restriction, including
|
7
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
8
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
9
|
+
permit persons to whom the Software is furnished to do so, subject to
|
10
|
+
the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be
|
13
|
+
included in all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
16
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
17
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
18
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
19
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
20
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
21
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
22
|
+
=end
|
23
|
+
|
24
|
+
$log = Logger.new(STDOUT)
|
25
|
+
$log.level = Logger::INFO
|
26
|
+
$log.formatter = proc do |severity, datetime, progname, msg|
|
27
|
+
color = lambda do |message, color|
|
28
|
+
open_tag = '<!'
|
29
|
+
close_tag = '!>'
|
30
|
+
colored_message = ''
|
31
|
+
message.split(open_tag).each do |sub_message|
|
32
|
+
if sub_message.include?(close_tag)
|
33
|
+
sub_messages = sub_message.split(close_tag)
|
34
|
+
colored_message << sub_messages.first
|
35
|
+
colored_message << sub_messages.last.colorize(color)
|
36
|
+
else
|
37
|
+
colored_message << sub_message.colorize(color)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
colored_message
|
41
|
+
end
|
42
|
+
message = "#{msg}\n"
|
43
|
+
message = color.call(message, :green) if severity.eql? 'INFO'
|
44
|
+
message = color.call(message, :red) if severity.eql? 'ERROR'
|
45
|
+
message = color.call(message, :yellow) if severity.eql? 'WARN'
|
46
|
+
message = message if severity.eql? 'DEBUG'
|
47
|
+
message
|
48
|
+
end
|
49
|
+
|
50
|
+
def $log.debug_on
|
51
|
+
$log.level = Logger::DEBUG
|
52
|
+
end
|
53
|
+
|
54
|
+
def $log.silent_on
|
55
|
+
$log.level = Logger::FATAL
|
56
|
+
end
|
57
|
+
|
58
|
+
def $log.reset
|
59
|
+
$log.level = Logger::INFO
|
60
|
+
end
|
@@ -0,0 +1,185 @@
|
|
1
|
+
=begin
|
2
|
+
Copyright (c) 2012 Dmitri Carpov
|
3
|
+
|
4
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
5
|
+
a copy of this software and associated documentation files (the
|
6
|
+
"Software"), to deal in the Software without restriction, including
|
7
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
8
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
9
|
+
permit persons to whom the Software is furnished to do so, subject to
|
10
|
+
the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be
|
13
|
+
included in all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
16
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
17
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
18
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
19
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
20
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
21
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
22
|
+
=end
|
23
|
+
|
24
|
+
module Rays
|
25
|
+
module AppModule
|
26
|
+
class Module
|
27
|
+
|
28
|
+
#
|
29
|
+
# CLASS
|
30
|
+
#
|
31
|
+
class << self
|
32
|
+
|
33
|
+
attr_reader :type, :base_directory, :archetype_name, :generate_worker, :build_worker, :deploy_worker, :clean_worker
|
34
|
+
|
35
|
+
# Class initializers
|
36
|
+
|
37
|
+
def register(type)
|
38
|
+
@type = type.to_s
|
39
|
+
Manager.instance.register_module_type(@type, self)
|
40
|
+
end
|
41
|
+
|
42
|
+
def directory(directory_name)
|
43
|
+
@base_directory = directory_name
|
44
|
+
end
|
45
|
+
|
46
|
+
def archetype(archetype)
|
47
|
+
@archetype_name = archetype
|
48
|
+
end
|
49
|
+
|
50
|
+
def generator(generate_worker)
|
51
|
+
@generate_worker = generate_worker
|
52
|
+
end
|
53
|
+
|
54
|
+
def builder(build_worker)
|
55
|
+
@build_worker = build_worker
|
56
|
+
end
|
57
|
+
|
58
|
+
def deployer(deploy_worker)
|
59
|
+
@deploy_worker = deploy_worker
|
60
|
+
end
|
61
|
+
|
62
|
+
def cleaner(clean_worker)
|
63
|
+
@clean_worker = clean_worker
|
64
|
+
end
|
65
|
+
|
66
|
+
# Class methods
|
67
|
+
|
68
|
+
# Get module's base directory path.
|
69
|
+
def base_path
|
70
|
+
File.join($rays_config.project_root, @base_directory)
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
#
|
75
|
+
# INSTANCE
|
76
|
+
#
|
77
|
+
attr_reader :type, :name, :archetype_name
|
78
|
+
|
79
|
+
def initialize(name)
|
80
|
+
@name = name
|
81
|
+
|
82
|
+
# transfer class properties to instance properties
|
83
|
+
@type = self.class.type
|
84
|
+
@archetype_name = self.class.archetype_name
|
85
|
+
@generator = self.class.generate_worker
|
86
|
+
@builder = self.class.build_worker
|
87
|
+
@deployer = self.class.deploy_worker
|
88
|
+
@cleaner = self.class.clean_worker
|
89
|
+
|
90
|
+
descriptor = load_descriptor
|
91
|
+
unless descriptor.nil?
|
92
|
+
unless descriptor['builder'].nil?
|
93
|
+
@builder = Worker::Manager.instnace.create :builder, descriptor['builder'].to_sym
|
94
|
+
end
|
95
|
+
unless descriptor['deployer'].nil?
|
96
|
+
@deployer = Worker::Manager.instnace.create :deployer, descriptor['deployer'].to_sym
|
97
|
+
end
|
98
|
+
unless descriptor['cleaner'].nil?
|
99
|
+
@cleaner = Worker::Manager.instnace.create :cleaner, descriptor['cleaner'].to_sym
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
#
|
105
|
+
# Builder
|
106
|
+
#
|
107
|
+
def build(skip_test = false)
|
108
|
+
@builder.build self, skip_test
|
109
|
+
end
|
110
|
+
|
111
|
+
#
|
112
|
+
# Deploy
|
113
|
+
#
|
114
|
+
def deploy
|
115
|
+
@deployer.deploy self
|
116
|
+
end
|
117
|
+
|
118
|
+
#
|
119
|
+
# Clean
|
120
|
+
#
|
121
|
+
def clean
|
122
|
+
@cleaner.clean self
|
123
|
+
end
|
124
|
+
|
125
|
+
#
|
126
|
+
# Create a new module or initialize if a directory exists but no .module file.
|
127
|
+
#
|
128
|
+
def create(generator_name=nil)
|
129
|
+
|
130
|
+
if Dir.exist?(path)
|
131
|
+
task("found <!#{@type} #{@name}!>", "", "failed to initialize <!#{@type} #{@name}!>") do
|
132
|
+
create_descriptor
|
133
|
+
end
|
134
|
+
else
|
135
|
+
|
136
|
+
generator = nil
|
137
|
+
begin
|
138
|
+
generator = Worker::Manager.instance.create(:generator, generator_name.to_sym) unless generator_name.nil?
|
139
|
+
rescue RaysException
|
140
|
+
# do nothing
|
141
|
+
end
|
142
|
+
generator ||= @generator
|
143
|
+
|
144
|
+
FileUtils.mkdir_p(self.class.base_path) unless Dir.exist?(self.class.base_path)
|
145
|
+
|
146
|
+
in_directory(self.class.base_path) do
|
147
|
+
task("creating <!#{@type} #{@name}!>", "done", "failed") do
|
148
|
+
generator.create self
|
149
|
+
create_descriptor
|
150
|
+
end
|
151
|
+
end
|
152
|
+
end
|
153
|
+
end
|
154
|
+
|
155
|
+
def path
|
156
|
+
File.join(self.class.base_path, @name)
|
157
|
+
end
|
158
|
+
|
159
|
+
protected
|
160
|
+
def descriptor_file_path
|
161
|
+
File.join(path, '.module')
|
162
|
+
end
|
163
|
+
|
164
|
+
def create_descriptor
|
165
|
+
if File.exists?(descriptor_file_path)
|
166
|
+
raise RaysException.new("<!#{@type} #{name}!> has already been initialized.")
|
167
|
+
end
|
168
|
+
content = {}
|
169
|
+
content['name'] = @name
|
170
|
+
content['type'] = @type
|
171
|
+
File.open(descriptor_file_path, 'w') do |f|
|
172
|
+
f.write(content.to_yaml)
|
173
|
+
end
|
174
|
+
end
|
175
|
+
|
176
|
+
def load_descriptor
|
177
|
+
descriptor = nil
|
178
|
+
if File.exists?(descriptor_file_path)
|
179
|
+
descriptor = Utils::FileUtils::YamlFile.new(descriptor_file_path).properties
|
180
|
+
end
|
181
|
+
descriptor
|
182
|
+
end
|
183
|
+
end
|
184
|
+
end
|
185
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
=begin
|
2
|
+
Copyright (c) 2012 Dmitri Carpov
|
3
|
+
|
4
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
5
|
+
a copy of this software and associated documentation files (the
|
6
|
+
"Software"), to deal in the Software without restriction, including
|
7
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
8
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
9
|
+
permit persons to whom the Software is furnished to do so, subject to
|
10
|
+
the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be
|
13
|
+
included in all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
16
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
17
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
18
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
19
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
20
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
21
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
22
|
+
=end
|
23
|
+
|
24
|
+
module Rays
|
25
|
+
module AppModule
|
26
|
+
class ContentModule < Module
|
27
|
+
register :content
|
28
|
+
directory 'utils'
|
29
|
+
|
30
|
+
builder Worker::Manager.instance.create :builder, :content_sync
|
31
|
+
deployer Worker::Manager.instance.create :deployer, :content_sync
|
32
|
+
cleaner Worker::Manager.instance.create :cleaner, :maven
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
=begin
|
2
|
+
Copyright (c) 2012 Dmitri Carpov
|
3
|
+
|
4
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
5
|
+
a copy of this software and associated documentation files (the
|
6
|
+
"Software"), to deal in the Software without restriction, including
|
7
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
8
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
9
|
+
permit persons to whom the Software is furnished to do so, subject to
|
10
|
+
the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be
|
13
|
+
included in all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
16
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
17
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
18
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
19
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
20
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
21
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
22
|
+
=end
|
23
|
+
|
24
|
+
module Rays
|
25
|
+
module AppModule
|
26
|
+
class ExtModule < Module
|
27
|
+
register :ext
|
28
|
+
directory 'ext'
|
29
|
+
archetype 'liferay-ext-archetype'
|
30
|
+
generator Worker::Manager.instance.create :generator, :maven
|
31
|
+
builder Worker::Manager.instance.create :builder, :maven
|
32
|
+
deployer Worker::Manager.instance.create :deployer, :maven
|
33
|
+
cleaner Worker::Manager.instance.create :cleaner, :maven
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|