raystool 1.0.2

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.
Files changed (45) hide show
  1. data/bin/__rays_exec.rb +31 -0
  2. data/bin/__rays_init +79 -0
  3. data/lib/rays/config/backup.rb +42 -0
  4. data/lib/rays/config/configuration.rb +376 -0
  5. data/lib/rays/config/environment.rb +73 -0
  6. data/lib/rays/config/templates/global/global.yml +3 -0
  7. data/lib/rays/config/templates/global/scripts/rays +187 -0
  8. data/lib/rays/config/templates/project/.rays +0 -0
  9. data/lib/rays/config/templates/project/config/environment.yml +68 -0
  10. data/lib/rays/config/templates/project/config/project.yml +4 -0
  11. data/lib/rays/core.rb +128 -0
  12. data/lib/rays/exceptions/rays_exception.rb +25 -0
  13. data/lib/rays/interface/commander.rb +394 -0
  14. data/lib/rays/interface/controller.rb +365 -0
  15. data/lib/rays/loaders/highline.rb +24 -0
  16. data/lib/rays/loaders/logging.rb +60 -0
  17. data/lib/rays/models/appmodule/base.rb +185 -0
  18. data/lib/rays/models/appmodule/content.rb +35 -0
  19. data/lib/rays/models/appmodule/ext.rb +36 -0
  20. data/lib/rays/models/appmodule/hook.rb +36 -0
  21. data/lib/rays/models/appmodule/layout.rb +36 -0
  22. data/lib/rays/models/appmodule/manager.rb +130 -0
  23. data/lib/rays/models/appmodule/portlet.rb +36 -0
  24. data/lib/rays/models/appmodule/servicebuilder.rb +36 -0
  25. data/lib/rays/models/appmodule/theme.rb +36 -0
  26. data/lib/rays/models/project.rb +116 -0
  27. data/lib/rays/servers/base.rb +70 -0
  28. data/lib/rays/servers/database.rb +73 -0
  29. data/lib/rays/servers/liferay.rb +64 -0
  30. data/lib/rays/servers/solr.rb +111 -0
  31. data/lib/rays/services/application_service.rb +116 -0
  32. data/lib/rays/services/backup_service.rb +94 -0
  33. data/lib/rays/services/database.rb +59 -0
  34. data/lib/rays/services/remote.rb +75 -0
  35. data/lib/rays/services/scm.rb +92 -0
  36. data/lib/rays/services/sync.rb +90 -0
  37. data/lib/rays/utils/common_utils.rb +153 -0
  38. data/lib/rays/utils/file_utils.rb +118 -0
  39. data/lib/rays/utils/network_utils.rb +50 -0
  40. data/lib/rays/workers/base.rb +134 -0
  41. data/lib/rays/workers/builder.rb +63 -0
  42. data/lib/rays/workers/cleaner.rb +42 -0
  43. data/lib/rays/workers/deployer.rb +92 -0
  44. data/lib/rays/workers/generator.rb +49 -0
  45. metadata +175 -0
@@ -0,0 +1,153 @@
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
+ #
25
+ # 1. Execution pointcuts
26
+ # 2. General use methods
27
+ #
28
+
29
+ # 1. Execution pointcuts
30
+
31
+ #
32
+ # Execute a given block and process any exception with a proper logging.
33
+ #
34
+ def log_block(message)
35
+ begin
36
+ yield
37
+ rescue RaysException => e
38
+ $log.error(e)
39
+ $log.debug("#{e}:\tBacktrace:\r\n#{e.backtrace.join("\r\n")}")
40
+ raise e
41
+ rescue => e
42
+ $log.error("Cannot #{message}.")
43
+ $log.debug("#{e}:\tBacktrace:\r\n#{e.backtrace.join("\r\n")}")
44
+ raise e
45
+ end
46
+ end
47
+
48
+ #
49
+ # Wrap a given block with progress information.
50
+ #
51
+ def task(start_message, done_message, failed_message)
52
+ begin
53
+ $log.info("<!#{start_message}!>")
54
+ yield
55
+ $log.info(done_message)
56
+ rescue => e
57
+ $log.error("#{failed_message}\nreason: #{e.message}")
58
+ $log.debug("#{e}.:\tBacktrace:\r\n#{e.backtrace.join("\r\n")}")
59
+ raise e
60
+ end
61
+ end
62
+
63
+ #
64
+ # Block console output for a given block.
65
+ #
66
+ def silent
67
+ begin
68
+ orig_stdout = $stdout.dup # does a dup2() internally
69
+ $stdout.reopen('/dev/null', 'w')
70
+ yield
71
+ ensure
72
+ $stdout.reopen(orig_stdout)
73
+ end
74
+ end
75
+
76
+
77
+ # 2. General use methods
78
+
79
+ #
80
+ # Execute OS command.
81
+ #
82
+ def rays_exec(command)
83
+ success = false
84
+ if $log.debug?
85
+ success = system command
86
+ else
87
+ silent { success = system command }
88
+ end
89
+ raise RaysException.new("Failed to execute: #{command}") unless success
90
+ success
91
+ end
92
+
93
+ #
94
+ # Safe execute. Use it for user input commands.
95
+ #
96
+ def rays_safe_exec(command, *args)
97
+ SafeShell.execute(command, *args)
98
+ end
99
+
100
+ #
101
+ # Execute a given code a directory.
102
+ #
103
+ def in_directory(directory)
104
+ original_directory = Dir.pwd
105
+ Dir.chdir(directory) if Dir.exist?(directory)
106
+ begin
107
+ yield
108
+ ensure
109
+ Dir.chdir(original_directory)
110
+ end
111
+ end
112
+
113
+ #
114
+ # Execute a given command while liferay service is stopped.
115
+ #
116
+ def service_safe(stop = true)
117
+ environment = $rays_config.environment
118
+ if stop and environment.liferay.service.alive?
119
+ environment.liferay.service.stop
120
+ yield
121
+ environment.liferay.service.start
122
+ else
123
+ yield
124
+ end
125
+ end
126
+
127
+ #
128
+ # In local environment
129
+ #
130
+ def in_local_environment
131
+ original_environment_name = $rays_config.environment.name
132
+ begin
133
+ $rays_config.environment = 'local'
134
+ yield
135
+ ensure
136
+ $rays_config.environment = original_environment_name
137
+ end
138
+ end
139
+
140
+ #
141
+ # Create a missing option string
142
+ #
143
+ def missing_environment_option(name, option)
144
+ "#{name} does not contain #{option} information. see config/environment.yml"
145
+ end
146
+
147
+ #
148
+ # Check if command in the PATH
149
+ #
150
+ def command?(command)
151
+ system("which #{ command} > /dev/null 2>&1")
152
+ end
153
+
@@ -0,0 +1,118 @@
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 Utils
26
+ module FileUtils
27
+ #
28
+ # Get parent path from a given path
29
+ #
30
+ def self.parent dir
31
+ return nil unless Dir.exists?(dir)
32
+ Pathname.new(dir).parent.to_s
33
+ end
34
+
35
+ #
36
+ # Find a file specified by regexp in a given directory recursively down.
37
+ #
38
+ def self.find_down dir, file
39
+ files = []
40
+ if Dir.exist?(dir)
41
+ Find.find(dir) do |file_path|
42
+ next unless file_path.match(file)
43
+ files << file_path
44
+ end
45
+ end
46
+ files
47
+ end
48
+
49
+ #
50
+ # Find a parent directory which contains a given file name (no patterns allowed)
51
+ #
52
+ def self.find_up file, dir = Dir.pwd, limit = '/'
53
+ return nil if dir.eql? limit or !dir.start_with?(limit)
54
+ return dir unless Dir.new(dir).find_index(file).nil?
55
+ find_up file, Pathname.new(dir).parent.to_s, limit
56
+ end
57
+
58
+ #
59
+ # Get list of child directory names of a given directory.
60
+ # Goes one level down only.
61
+ #
62
+ def self.find_directories path, hidden=false
63
+ dirs = []
64
+ Dir.glob("#{path}/*/").each do |dir|
65
+ dirs << File.basename(dir)
66
+ end
67
+ if hidden
68
+ Dir.glob("#{path}/.*/").each do |dir|
69
+ basename = File.basename(dir)
70
+ dirs << File.basename(dir) if basename != '.' and basename != '..'
71
+ end
72
+ end
73
+ dirs
74
+ end
75
+
76
+ #
77
+ # YamlFile allows to work with java .properties files as a ruby hash
78
+ #
79
+ class YamlFile
80
+ attr_reader :properties
81
+
82
+ def initialize(file)
83
+ @file_name = file
84
+ @properties = {}
85
+ @properties = YAML::load_file(File.open(@file_name)) || Hash.new
86
+ end
87
+
88
+ def write
89
+ File.open(@file_name, 'w') do |out|
90
+ YAML.dump(@properties, out)
91
+ end
92
+ end
93
+ end
94
+
95
+ #
96
+ # PropertiesFile allows to work with java .properties files as a ruby hash
97
+ #
98
+ class PropertiesFile
99
+ attr_reader :properties
100
+
101
+ def initialize file
102
+ @file_name = file
103
+ @properties = {}
104
+ file = File.open(@file_name, 'r')
105
+ IO.foreach(file) do |line|
106
+ @properties[$1.strip] = $2 if line =~ /([^=]*)=(.*)\/\/(.*)/ || line =~ /([^=]*)=(.*)/
107
+ end
108
+ end
109
+
110
+ def write
111
+ properties_file = File.new(@file_name, 'w+')
112
+ @properties.each { |key, value| properties_file.puts "#{key}=#{value}\n" }
113
+ properties_file.close
114
+ end
115
+ end
116
+ end
117
+ end
118
+ end
@@ -0,0 +1,50 @@
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 Utils
26
+ class NetworkUtils
27
+ class << self
28
+
29
+ def port_open?(ip, port)
30
+ begin
31
+ Timeout::timeout(1) do
32
+ begin
33
+ s = TCPSocket.new(ip, port)
34
+ s.close
35
+ return true
36
+ rescue Errno::ECONNREFUSED, Errno::EHOSTUNREACH
37
+ return false
38
+ end
39
+ end
40
+ rescue Timeout::Error
41
+ return false
42
+ end
43
+
44
+ false
45
+ end
46
+
47
+ end
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,134 @@
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
+ module Rays
24
+ module Worker
25
+ class Manager
26
+ include Singleton
27
+
28
+ def initialize
29
+ @workers = {}
30
+ end
31
+
32
+ def register(type, name, worker_class)
33
+ @workers[type] = {} if @workers[type].nil?
34
+ @workers[type][name] = worker_class
35
+ end
36
+
37
+ def create(type, name)
38
+ if !@workers[type].nil? and !@workers[type][name].nil?
39
+ @workers[type][name].instance
40
+ else
41
+ raise RaysException.new("Cannot find #{type} #{name}")
42
+ end
43
+ end
44
+ end
45
+
46
+ class BaseWorker
47
+ def self.register(type, name)
48
+ Manager.instance.register(type, name, self)
49
+ end
50
+
51
+ def execute(process, app_module)
52
+ if app_module.nil? or !Dir.exist?(app_module.path)
53
+ raise RaysException.new("Do not know how to #{process} <!#{app_module.inspect}!>")
54
+ end
55
+
56
+ in_directory(app_module.path) do
57
+ task("#{process} <!#{app_module.type} #{app_module.name}!>", "done", "failed") do
58
+ yield
59
+ end
60
+ end
61
+ end
62
+ end
63
+
64
+ class MavenUtil
65
+ class << self
66
+ def link_to_parent(module_pom)
67
+ check_parent_pom
68
+ add_parent_pom_to module_pom
69
+ end
70
+
71
+ private
72
+ def check_parent_pom
73
+ in_directory($rays_config.project_root) do
74
+ unless File.exists?('pom.xml')
75
+ builder = Nokogiri::XML::Builder.new do |xml|
76
+ xml.project {
77
+ xml.name Project.instance.name
78
+ xml.groupId Project.instance.package
79
+ xml.artifactId Project.instance.name
80
+ xml.version '1.0'
81
+ xml.packaging 'pom'
82
+ xml.properties {
83
+ xml << "<liferay.version>#{Project.instance.liferay}</liferay.version>"
84
+ }
85
+ }
86
+ end
87
+
88
+ File.open('pom.xml', 'w') do |file|
89
+ file.write(builder.to_xml)
90
+ end
91
+
92
+ end
93
+ end
94
+ end
95
+
96
+ def add_parent_pom_to(module_pom)
97
+ doc = Nokogiri::XML(open(module_pom), &:noblanks)
98
+
99
+ # remove generated liferay.version tags
100
+ properties_node = doc.css('properties')
101
+ unless properties_node.nil?
102
+ properties_node.children.each do |node|
103
+ if node.name == 'liferay.version'
104
+ node.remove
105
+ end
106
+ end
107
+ end
108
+
109
+ parent_node = Nokogiri::XML::Node.new('parent',doc)
110
+
111
+ group_id_node = Nokogiri::XML::Node.new('groupId',doc)
112
+ group_id_node.content = Project.instance.package
113
+ parent_node.add_child group_id_node
114
+
115
+ artifact_id_node = Nokogiri::XML::Node.new('artifactId',doc)
116
+ artifact_id_node.content = Project.instance.name
117
+ parent_node.add_child artifact_id_node
118
+
119
+ version_node = Nokogiri::XML::Node.new('version',doc)
120
+ version_node.content = '1.0'
121
+ parent_node.add_child version_node
122
+
123
+ relative_path_node = Nokogiri::XML::Node.new('relativePath',doc)
124
+ relative_path_node.content = '../../pom.xml'
125
+ parent_node.add_child relative_path_node
126
+
127
+ doc.root.children.first.add_previous_sibling parent_node
128
+
129
+ File.open(module_pom, 'w') { |file| file.write doc.to_xml }
130
+ end
131
+ end
132
+ end
133
+ end
134
+ end
@@ -0,0 +1,63 @@
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
+ module Rays
24
+ module Worker
25
+ module Builder
26
+
27
+ # Maven builder
28
+ class Maven < BaseWorker
29
+ register :builder, :maven
30
+ include Singleton
31
+
32
+ def build(app_module, skip_test = false)
33
+ execute('build', app_module) do
34
+ test_args = ''
35
+ test_args = '-Dmaven.skip.tests=true' if skip_test
36
+
37
+ rays_exec("#{$rays_config.mvn} clean package #{test_args}")
38
+ end
39
+ end
40
+ end
41
+
42
+ # Content builder
43
+ class Content < BaseWorker
44
+ register :builder, :content_sync
45
+ include Singleton
46
+
47
+ def build(app_module, skip_test = false)
48
+ execute('build', app_module) do
49
+ # replace liferay server port
50
+ properties_file = Rays::Utils::FileUtils::PropertiesFile.new "#{app_module.path}/src/main/resources/configuration.properties"
51
+ properties_file.properties['server.port'] = $rays_config.environment.liferay.port
52
+ properties_file.write
53
+
54
+ test_args = ''
55
+ test_args = '-Dmaven.skip.tests=true' if skip_test
56
+
57
+ rays_exec("cd #{app_module.path} && #{$rays_config.mvn} clean assembly:single package #{test_args}")
58
+ end
59
+ end
60
+ end
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,42 @@
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
+ module Rays
24
+ module Worker
25
+ module Cleaner
26
+
27
+ # Maven cleaner
28
+ class Maven < BaseWorker
29
+ register :cleaner, :maven
30
+
31
+ include Singleton
32
+
33
+ def clean(app_module)
34
+ execute('clean', app_module) do
35
+ rays_exec("#{$rays_config.mvn} clean")
36
+ end
37
+ end
38
+
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,92 @@
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
+ require 'net/ssh'
24
+
25
+ module Rays
26
+ module Worker
27
+ module Deployer
28
+
29
+ # Maven deployer
30
+ class Maven < BaseWorker
31
+ register :deployer, :maven
32
+
33
+ include Singleton
34
+
35
+ def deploy(app_module)
36
+ execute('deploy', app_module) do
37
+ env = $rays_config.environment
38
+ Rays::Utils::FileUtils.find_down("./", '.*\\.war$').each do |file_to_deploy|
39
+ if env.liferay.remote?
40
+ env.liferay.remote.copy_to(file_to_deploy, env.liferay.deploy_directory)
41
+ else
42
+ FileUtils.cp(file_to_deploy, env.liferay.deploy_directory)
43
+ end
44
+ end
45
+ end
46
+ end
47
+ end
48
+
49
+ # Content deployer
50
+ class Content < BaseWorker
51
+ register :deployer, :content_sync
52
+
53
+ include Singleton
54
+
55
+ def deploy(app_module)
56
+ execute('deploy', app_module) do
57
+ env = $rays_config.environment
58
+ base_filenames = []
59
+ deploy_dir = "/tmp/content_sync"
60
+ if env.liferay.remote?
61
+ env.liferay.remote.exec("rm -rf #{deploy_dir} && mkdir #{deploy_dir}")
62
+ else
63
+ rays_exec("rm -rf #{deploy_dir} && mkdir #{deploy_dir}")
64
+ end
65
+ Rays::Utils::FileUtils.find_down("./target/", '.*\\.jar$').each do |file|
66
+ if env.liferay.remote?
67
+ env.liferay.remote.copy_to(file, deploy_dir)
68
+ else
69
+ FileUtils.cp(file, env.liferay.deploy_directory)
70
+ end
71
+ base_filenames << File.basename(file)
72
+ end
73
+
74
+ class_path = base_filenames.join ':'
75
+ structures_cmd = "export JAVA_HOME=#{env.liferay.java_home} && cd #{deploy_dir} && #{env.liferay.java_cmd} -cp #{class_path} com.savoirfairelinux.liferay.client.UpdateStructures"
76
+ templates_cmd = "export JAVA_HOME=#{env.liferay.java_home} && cd #{deploy_dir} && #{env.liferay.java_cmd} -cp #{class_path} com.savoirfairelinux.liferay.client.UpdateTemplates"
77
+
78
+ if env.liferay.remote?
79
+ env.liferay.remote.exec(structures_cmd)
80
+ env.liferay.remote.exec(templates_cmd)
81
+ else
82
+ rays_exec(structures_cmd)
83
+ rays_exec(templates_cmd)
84
+ end
85
+
86
+ end
87
+ end
88
+ end
89
+
90
+ end
91
+ end
92
+ end
@@ -0,0 +1,49 @@
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
+ module Rays
24
+ module Worker
25
+ module Generator
26
+
27
+ # Maven generator
28
+ class Maven < BaseWorker
29
+ register :generator, :maven
30
+
31
+ include Singleton
32
+
33
+ def create(app_module)
34
+ raise RaysException.new("Don't know how to create #{app_module.type}/#{app_module.name}.") if app_module.archetype_name.nil?
35
+ create_cmd = "#{$rays_config.mvn} archetype:generate" <<
36
+ " -DarchetypeGroupId=com.liferay.maven.archetypes" <<
37
+ " -DarchetypeArtifactId=#{app_module.archetype_name}" <<
38
+ " -DarchetypeVersion=#{Project.instance.liferay}" <<
39
+ " -DgroupId=#{Project.instance.package}.#{app_module.type}" <<
40
+ " -DartifactId=#{app_module.name}" <<
41
+ " -Dversion=1.0-SNAPSHOT" <<
42
+ " -Dpackaging=war -B"
43
+ rays_exec(create_cmd)
44
+ MavenUtil.link_to_parent File.join(app_module.path, 'pom.xml')
45
+ end
46
+ end
47
+ end
48
+ end
49
+ end