capistrano-maven 0.0.6 → 0.0.7

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.
@@ -16,4 +16,6 @@ Gem::Specification.new do |gem|
16
16
  gem.version = Capistrano::Maven::VERSION
17
17
 
18
18
  gem.add_dependency("capistrano")
19
+ gem.add_dependency("capistrano-file-resources", "~> 0.0.1")
20
+ gem.add_dependency("capistrano-file-transfer-ext", "~> 0.0.3")
19
21
  end
@@ -1,8 +1,292 @@
1
- require "capistrano-maven/deploy"
2
1
  require "capistrano-maven/version"
2
+ require "capistrano"
3
+ require "capistrano/configuration/actions/file_transfer_ext"
4
+ require "capistrano/configuration/resources/file_resources"
5
+ require "uri"
3
6
 
4
7
  module Capistrano
5
8
  module Maven
6
- # Your code goes here...
9
+ def self.extended(configuration)
10
+ configuration.load {
11
+ namespace(:mvn) {
12
+ _cset(:mvn_version, '3.0.4')
13
+ _cset(:mvn_major_version) {
14
+ mvn_version.split('.').first.to_i
15
+ }
16
+ _cset(:mvn_archive_url) {
17
+ "http://www.apache.org/dist/maven/maven-#{mvn_major_version}/#{mvn_version}/binaries/apache-maven-#{mvn_version}-bin.tar.gz"
18
+ }
19
+ _cset(:mvn_archive_file) {
20
+ File.join(shared_path, 'tools', 'mvn', File.basename(URI.parse(mvn_archive_url).path))
21
+ }
22
+ _cset(:mvn_archive_file_local) {
23
+ File.join(File.expand_path('.'), 'tools', 'mvn', File.basename(URI.parse(mvn_archive_url).path))
24
+ }
25
+ _cset(:mvn_checksum_url) {
26
+ "#{mvn_archive_url}.md5"
27
+ }
28
+ _cset(:mvn_checksum_file) {
29
+ File.join(shared_path, 'tools', 'mvn', File.basename(URI.parse(mvn_checksum_url).path))
30
+ }
31
+ _cset(:mvn_checksum_file_local) {
32
+ File.join(File.expand_path('.'), 'tools', 'mvn', File.basename(URI.parse(mvn_checksum_url).path))
33
+ }
34
+ _cset(:mvn_checksum_cmd) {
35
+ case File.extname(File.basename(URI.parse(mvn_checksum_url).path))
36
+ when '.md5' then 'md5sum'
37
+ when '.sha1' then 'sha1sum'
38
+ end
39
+ }
40
+ _cset(:mvn_path) {
41
+ File.join(shared_path, 'tools', 'mvn', File.basename(URI.parse(mvn_archive_url).path, "-bin.tar.gz"))
42
+ }
43
+ _cset(:mvn_path_local) {
44
+ File.join(File.expand_path('.'), 'tools', 'mvn', File.basename(URI.parse(mvn_archive_url).path, "-bin.tar.gz"))
45
+ }
46
+ _cset(:mvn_bin) {
47
+ File.join(mvn_path, 'bin', 'mvn')
48
+ }
49
+ _cset(:mvn_bin_local) {
50
+ File.join(mvn_path_local, 'bin', 'mvn')
51
+ }
52
+ _cset(:mvn_cmd) {
53
+ if fetch(:mvn_java_home, nil)
54
+ "env JAVA_HOME=#{mvn_java_home} #{mvn_bin} #{mvn_options.join(' ')}"
55
+ else
56
+ "#{mvn_bin} #{mvn_options.join(' ')}"
57
+ end
58
+ }
59
+ _cset(:mvn_cmd_local) {
60
+ if fetch(:mvn_java_home_local, nil)
61
+ "env JAVA_HOME=#{mvn_java_home_local} #{mvn_bin_local} #{mvn_options_local.join(' ')}"
62
+ else
63
+ "#{mvn_bin_local} #{mvn_options_local.join(' ')}"
64
+ end
65
+ }
66
+ _cset(:mvn_project_path) {
67
+ release_path
68
+ }
69
+ _cset(:mvn_project_path_local) {
70
+ Dir.pwd
71
+ }
72
+ _cset(:mvn_target_path) {
73
+ File.join(mvn_project_path, 'target')
74
+ }
75
+ _cset(:mvn_target_path_local) {
76
+ File.join(mvn_project_path_local, File.basename(mvn_target_path))
77
+ }
78
+ _cset(:mvn_template_path, File.join(File.dirname(__FILE__), 'templates'))
79
+ _cset(:mvn_update_settings, false)
80
+ _cset(:mvn_update_settings_locally, false)
81
+ _cset(:mvn_settings_path) { mvn_project_path }
82
+ _cset(:mvn_settings_path_local) { mvn_project_path_local }
83
+ _cset(:mvn_settings, %w(settings.xml))
84
+ _cset(:mvn_settings_local, %w(settings.xml))
85
+ _cset(:mvn_cleanup_settings, [])
86
+ _cset(:mvn_cleanup_settings_local, [])
87
+ _cset(:mvn_compile_locally, false) # perform precompilation on localhost
88
+ _cset(:mvn_goals, %w(clean package))
89
+ _cset(:mvn_common_options) {
90
+ options = []
91
+ options << "-P#{mvn_profiles.join(',')}" unless fetch(:mvn_profiles, []).empty?
92
+ options << "-Dmaven.test.skip=true" if fetch(:mvn_skip_tests, false)
93
+ options << "-U" if fetch(:mvn_update_snapshots, false)
94
+ options << "-B"
95
+ options
96
+ }
97
+ _cset(:mvn_options) {
98
+ options = mvn_common_options + fetch(:mvn_extra_options, [])
99
+ if mvn_update_settings
100
+ settings = File.join(mvn_settings_path, mvn_settings.first)
101
+ options << "--settings=#{settings}"
102
+ end
103
+ options
104
+ }
105
+ _cset(:mvn_options_local) {
106
+ options = mvn_common_options + fetch(:mvn_extra_options_local, [])
107
+ if mvn_update_settings_locally
108
+ settings = File.join(mvn_settings_path_local, mvn_settings_local.first)
109
+ options << "--settings=#{settings}"
110
+ end
111
+ options
112
+ }
113
+
114
+ desc("Setup maven.")
115
+ task(:setup, :roles => :app, :except => { :no_release => true }) {
116
+ transaction {
117
+ install
118
+ update_settings if mvn_update_settings
119
+ setup_locally if mvn_compile_locally
120
+ }
121
+ }
122
+ after 'deploy:setup', 'mvn:setup'
123
+
124
+ desc("Setup maven locally.")
125
+ task(:setup_locally, :except => { :no_release => true }) {
126
+ transaction {
127
+ install_locally
128
+ update_settings_locally if mvn_update_settings_locally
129
+ }
130
+ }
131
+
132
+ def _validate_archive(archive_file, checksum_file)
133
+ if cmd = fetch(:mvn_checksum_cmd, nil)
134
+ "test `#{cmd} #{archive_file} | cut -d' ' -f1` = `cat #{checksum_file}`"
135
+ else
136
+ "true"
137
+ end
138
+ end
139
+
140
+ def _install(options={})
141
+ path = options.delete(:path)
142
+ bin = options.delete(:bin)
143
+ checksum_file = options.delete(:checksum_file)
144
+ checksum_url = options.delete(:checksum_url)
145
+ archive_file = options.delete(:archive_file)
146
+ archive_url = options.delete(:archive_url)
147
+ dirs = [ File.dirname(checksum_file), File.dirname(archive_file), File.dirname(path) ].uniq()
148
+ execute = []
149
+ execute << "mkdir -p #{dirs.join(' ')}"
150
+ execute << (<<-EOS).gsub(/\s+/, ' ').strip
151
+ if ! test -f #{archive_file}; then
152
+ ( rm -f #{checksum_file}; wget --no-verbose -O #{checksum_file} #{checksum_url} ) &&
153
+ wget --no-verbose -O #{archive_file} #{archive_url} &&
154
+ #{_validate_archive(archive_file, checksum_file)} || ( rm -f #{archive_file}; false ) &&
155
+ test -f #{archive_file};
156
+ fi
157
+ EOS
158
+ execute << (<<-EOS).gsub(/\s+/, ' ').strip
159
+ if ! test -x #{bin}; then
160
+ ( test -d #{path} || tar xf #{archive_file} -C #{File.dirname(path)} ) &&
161
+ test -x #{bin};
162
+ fi
163
+ EOS
164
+ execute.join(' && ')
165
+ end
166
+
167
+ task(:install, :roles => :app, :except => { :no_release => true }) {
168
+ run(_install(:path => mvn_path, :bin => mvn_bin,
169
+ :checksum_file => mvn_checksum_file, :checksum_url => mvn_checksum_url,
170
+ :archive_file => mvn_archive_file, :archive_url => mvn_archive_url))
171
+ run("#{mvn_cmd} --version")
172
+ }
173
+
174
+ task(:install_locally, :except => { :no_release => true }) {
175
+ run_locally(_install(:path => mvn_path_local, :bin => mvn_bin_local,
176
+ :checksum_file => mvn_checksum_file_local, :checksum_url => mvn_checksum_url,
177
+ :archive_file => mvn_archive_file_local, :archive_url => mvn_archive_url))
178
+ run_locally("#{mvn_cmd_local} --version")
179
+ }
180
+
181
+ task(:update_settings, :roles => :app, :except => { :no_release => true }) {
182
+ mvn_settings.each do |f|
183
+ safe_put(template(f, :path => mvn_template_path), File.join(mvn_settings_path, f))
184
+ end
185
+ run("rm -f #{mvn_cleanup_settings.map { |x| x.dump }.join(' ')}") unless mvn_cleanup_settings.empty?
186
+ }
187
+
188
+ task(:update_settings_locally, :except => { :no_release => true }) {
189
+ mvn_settings_local.each do |f|
190
+ File.write(File.join(mvn_settings_path_local, f), template(f, :path => mvn_template_path))
191
+ end
192
+ run_locally("rm -f #{mvn_cleanup_settings_local.map { |x| x.dump }.join(' ')}") unless mvn_cleanup_settings_local.empty?
193
+ }
194
+
195
+ desc("Update maven build.")
196
+ task(:update, :roles => :app, :except => { :no_release => true }) {
197
+ transaction {
198
+ if mvn_compile_locally
199
+ update_locally
200
+ else
201
+ execute
202
+ end
203
+ }
204
+ }
205
+ after 'deploy:finalize_update', 'mvn:update'
206
+
207
+ desc("Update maven build locally.")
208
+ task(:update_locally, :except => { :no_release => true }) {
209
+ transaction {
210
+ execute_locally
211
+ upload_locally
212
+ }
213
+ }
214
+
215
+ def _mvn(cmd, path, goals=[])
216
+ "cd #{path.dump} && #{cmd} #{goals.map { |s| s.dump }.join(' ')}"
217
+ end
218
+
219
+ def _mvn_parse_version(s)
220
+ # FIXME: is there any better way to get project version?
221
+ s.split(/(?:\r?\n)+/).reject { |line| /^\[[A-Z]+\]/ =~ line }.last
222
+ end
223
+
224
+ _cset(:mvn_release_build, false)
225
+ _cset(:mvn_snapshot_pattern, /-SNAPSHOT$/i)
226
+ _cset(:mvn_project_version) {
227
+ _mvn_parse_version(capture(_mvn(mvn_cmd, mvn_project_path, %w(-Dexpression=project.version help:evaluate))))
228
+ }
229
+ _cset(:mvn_project_version_local) {
230
+ _mvn_parse_version(run_locally(_mvn(mvn_cmd_local, mvn_project_path_local, %w(-Dexpression=project.version help:evaluate))))
231
+ }
232
+
233
+ def _validate_project_version(version_key)
234
+ if mvn_release_build
235
+ version = fetch(version_key)
236
+ if mvn_snapshot_pattern === version
237
+ abort("Skip to build project since \`#{version}' is a SNAPSHOT version.")
238
+ end
239
+ end
240
+ end
241
+
242
+ desc("Perform maven build.")
243
+ task(:execute, :roles => :app, :except => { :no_release => true }) {
244
+ on_rollback {
245
+ run(_mvn(mvn_cmd, mvn_project_path, %w(clean)))
246
+ }
247
+ _validate_project_version(:mvn_project_version)
248
+ run(_mvn(mvn_cmd, mvn_project_path, mvn_goals))
249
+ }
250
+
251
+ desc("Perform maven build locally.")
252
+ task(:execute_locally, :roles => :app, :except => { :no_release => true }) {
253
+ on_rollback {
254
+ run_locally(_mvn(mvn_cmd_local, mvn_project_path_local, %w(clean)))
255
+ }
256
+ _validate_project_version(:mvn_project_version_local)
257
+ cmdline = _mvn(mvn_cmd_local, mvn_project_path_local, mvn_goals)
258
+ logger.info(cmdline)
259
+ abort("execution failure") unless system(cmdline)
260
+ }
261
+
262
+ _cset(:mvn_tar, 'tar')
263
+ _cset(:mvn_tar_local, 'tar')
264
+ _cset(:mvn_target_archive) {
265
+ "#{mvn_target_path}.tar.gz"
266
+ }
267
+ _cset(:mvn_target_archive_local) {
268
+ "#{mvn_target_path_local}.tar.gz"
269
+ }
270
+ task(:upload_locally, :roles => :app, :except => { :no_release => true }) {
271
+ on_rollback {
272
+ run("rm -rf #{mvn_target_path} #{mvn_target_archive}")
273
+ }
274
+ begin
275
+ run_locally("cd #{File.dirname(mvn_target_path_local)} && #{mvn_tar_local} chzf #{mvn_target_archive_local} #{File.basename(mvn_target_path_local)}")
276
+ upload(mvn_target_archive_local, mvn_target_archive)
277
+ run("cd #{File.dirname(mvn_target_path)} && #{mvn_tar} xzf #{mvn_target_archive} && rm -f #{mvn_target_archive}")
278
+ ensure
279
+ run_locally("rm -f #{mvn_target_archive_local}")
280
+ end
281
+ }
282
+ }
283
+ }
284
+ end
7
285
  end
8
286
  end
287
+
288
+ if Capistrano::Configuration.instance
289
+ Capistrano::Configuration.instance.extend(Capistrano::Maven)
290
+ end
291
+
292
+ # vim:set ft=ruby :
@@ -1,5 +1,5 @@
1
1
  module Capistrano
2
2
  module Maven
3
- VERSION = "0.0.6"
3
+ VERSION = "0.0.7"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: capistrano-maven
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.0.7
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-02-19 00:00:00.000000000 Z
12
+ date: 2013-02-27 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: capistrano
@@ -27,6 +27,38 @@ dependencies:
27
27
  - - ! '>='
28
28
  - !ruby/object:Gem::Version
29
29
  version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: capistrano-file-resources
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ~>
36
+ - !ruby/object:Gem::Version
37
+ version: 0.0.1
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: 0.0.1
46
+ - !ruby/object:Gem::Dependency
47
+ name: capistrano-file-transfer-ext
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ~>
52
+ - !ruby/object:Gem::Version
53
+ version: 0.0.3
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: 0.0.3
30
62
  description: a capistrano recipe to deploy Apache Maven based projects.
31
63
  email:
32
64
  - yamashita@geishatokyo.com
@@ -41,9 +73,8 @@ files:
41
73
  - Rakefile
42
74
  - capistrano-maven.gemspec
43
75
  - lib/capistrano-maven.rb
44
- - lib/capistrano-maven/deploy.rb
45
- - lib/capistrano-maven/templates/settings.xml
46
76
  - lib/capistrano-maven/version.rb
77
+ - lib/templates/settings.xml
47
78
  homepage: https://github.com/yyuu/capistrano-maven
48
79
  licenses: []
49
80
  post_install_message:
@@ -69,4 +100,3 @@ signing_key:
69
100
  specification_version: 3
70
101
  summary: a capistrano recipe to deploy Apache Maven based projects.
71
102
  test_files: []
72
- has_rdoc:
@@ -1,326 +0,0 @@
1
-
2
- require 'capistrano'
3
- require 'uri'
4
-
5
- module Capistrano
6
- module Maven
7
- def self.extended(configuration)
8
- configuration.load {
9
- namespace(:mvn) {
10
- _cset(:mvn_version, '3.0.4')
11
- _cset(:mvn_major_version) {
12
- mvn_version.split('.').first.to_i
13
- }
14
- _cset(:mvn_archive_url) {
15
- "http://www.apache.org/dist/maven/maven-#{mvn_major_version}/#{mvn_version}/binaries/apache-maven-#{mvn_version}-bin.tar.gz"
16
- }
17
- _cset(:mvn_archive_file) {
18
- File.join(shared_path, 'tools', 'mvn', File.basename(URI.parse(mvn_archive_url).path))
19
- }
20
- _cset(:mvn_archive_file_local) {
21
- File.join(File.expand_path('.'), 'tools', 'mvn', File.basename(URI.parse(mvn_archive_url).path))
22
- }
23
- _cset(:mvn_checksum_url) {
24
- "#{mvn_archive_url}.md5"
25
- }
26
- _cset(:mvn_checksum_file) {
27
- File.join(shared_path, 'tools', 'mvn', File.basename(URI.parse(mvn_checksum_url).path))
28
- }
29
- _cset(:mvn_checksum_file_local) {
30
- File.join(File.expand_path('.'), 'tools', 'mvn', File.basename(URI.parse(mvn_checksum_url).path))
31
- }
32
- _cset(:mvn_checksum_cmd) {
33
- case File.extname(File.basename(URI.parse(mvn_checksum_url).path))
34
- when '.md5' then 'md5sum'
35
- when '.sha1' then 'sha1sum'
36
- end
37
- }
38
- _cset(:mvn_path) {
39
- File.join(shared_path, 'tools', 'mvn', File.basename(URI.parse(mvn_archive_url).path, "-bin.tar.gz"))
40
- }
41
- _cset(:mvn_path_local) {
42
- File.join(File.expand_path('.'), 'tools', 'mvn', File.basename(URI.parse(mvn_archive_url).path, "-bin.tar.gz"))
43
- }
44
- _cset(:mvn_bin) {
45
- File.join(mvn_path, 'bin', 'mvn')
46
- }
47
- _cset(:mvn_bin_local) {
48
- File.join(mvn_path_local, 'bin', 'mvn')
49
- }
50
- _cset(:mvn_cmd) {
51
- if fetch(:mvn_java_home, nil)
52
- "env JAVA_HOME=#{mvn_java_home} #{mvn_bin} #{mvn_options.join(' ')}"
53
- else
54
- "#{mvn_bin} #{mvn_options.join(' ')}"
55
- end
56
- }
57
- _cset(:mvn_cmd_local) {
58
- if fetch(:mvn_java_home_local, nil)
59
- "env JAVA_HOME=#{mvn_java_home_local} #{mvn_bin_local} #{mvn_options_local.join(' ')}"
60
- else
61
- "#{mvn_bin_local} #{mvn_options_local.join(' ')}"
62
- end
63
- }
64
- _cset(:mvn_project_path) {
65
- release_path
66
- }
67
- _cset(:mvn_project_path_local) {
68
- Dir.pwd
69
- }
70
- _cset(:mvn_target_path) {
71
- File.join(mvn_project_path, 'target')
72
- }
73
- _cset(:mvn_target_path_local) {
74
- File.join(mvn_project_path_local, File.basename(mvn_target_path))
75
- }
76
- _cset(:mvn_template_path, File.join(File.dirname(__FILE__), 'templates'))
77
- _cset(:mvn_update_settings, false)
78
- _cset(:mvn_update_settings_locally, false)
79
- _cset(:mvn_settings_path) { mvn_project_path }
80
- _cset(:mvn_settings_path_local) { mvn_project_path_local }
81
- _cset(:mvn_settings, %w(settings.xml))
82
- _cset(:mvn_settings_local, %w(settings.xml))
83
- _cset(:mvn_cleanup_settings, [])
84
- _cset(:mvn_cleanup_settings_local, [])
85
- _cset(:mvn_compile_locally, false) # perform precompilation on localhost
86
- _cset(:mvn_goals, %w(clean package))
87
- _cset(:mvn_common_options) {
88
- options = []
89
- options << "-P#{mvn_profiles.join(',')}" unless fetch(:mvn_profiles, []).empty?
90
- options << "-Dmaven.test.skip=true" if fetch(:mvn_skip_tests, false)
91
- options << "-U" if fetch(:mvn_update_snapshots, false)
92
- options << "-B"
93
- options
94
- }
95
- _cset(:mvn_options) {
96
- options = mvn_common_options + fetch(:mvn_extra_options, [])
97
- if mvn_update_settings
98
- settings = File.join(mvn_settings_path, mvn_settings.first)
99
- options << "--settings=#{settings}"
100
- end
101
- options
102
- }
103
- _cset(:mvn_options_local) {
104
- options = mvn_common_options + fetch(:mvn_extra_options_local, [])
105
- if mvn_update_settings_locally
106
- settings = File.join(mvn_settings_path_local, mvn_settings_local.first)
107
- options << "--settings=#{settings}"
108
- end
109
- options
110
- }
111
-
112
- desc("Setup maven.")
113
- task(:setup, :roles => :app, :except => { :no_release => true }) {
114
- transaction {
115
- install
116
- update_settings if mvn_update_settings
117
- setup_locally if mvn_compile_locally
118
- }
119
- }
120
- after 'deploy:setup', 'mvn:setup'
121
-
122
- desc("Setup maven locally.")
123
- task(:setup_locally, :except => { :no_release => true }) {
124
- transaction {
125
- install_locally
126
- update_settings_locally if mvn_update_settings_locally
127
- }
128
- }
129
-
130
- def _validate_archive(archive_file, checksum_file)
131
- if cmd = fetch(:mvn_checksum_cmd, nil)
132
- "test `#{cmd} #{archive_file} | cut -d' ' -f1` = `cat #{checksum_file}`"
133
- else
134
- "true"
135
- end
136
- end
137
-
138
- def _install(options={})
139
- path = options.delete(:path)
140
- bin = options.delete(:bin)
141
- checksum_file = options.delete(:checksum_file)
142
- checksum_url = options.delete(:checksum_url)
143
- archive_file = options.delete(:archive_file)
144
- archive_url = options.delete(:archive_url)
145
- dirs = [ File.dirname(checksum_file), File.dirname(archive_file), File.dirname(path) ].uniq()
146
- execute = []
147
- execute << "mkdir -p #{dirs.join(' ')}"
148
- execute << (<<-EOS).gsub(/\s+/, ' ').strip
149
- if ! test -f #{archive_file}; then
150
- ( rm -f #{checksum_file}; wget --no-verbose -O #{checksum_file} #{checksum_url} ) &&
151
- wget --no-verbose -O #{archive_file} #{archive_url} &&
152
- #{_validate_archive(archive_file, checksum_file)} || ( rm -f #{archive_file}; false ) &&
153
- test -f #{archive_file};
154
- fi
155
- EOS
156
- execute << (<<-EOS).gsub(/\s+/, ' ').strip
157
- if ! test -x #{bin}; then
158
- ( test -d #{path} || tar xf #{archive_file} -C #{File.dirname(path)} ) &&
159
- test -x #{bin};
160
- fi
161
- EOS
162
- execute.join(' && ')
163
- end
164
-
165
- task(:install, :roles => :app, :except => { :no_release => true }) {
166
- run(_install(:path => mvn_path, :bin => mvn_bin,
167
- :checksum_file => mvn_checksum_file, :checksum_url => mvn_checksum_url,
168
- :archive_file => mvn_archive_file, :archive_url => mvn_archive_url))
169
- run("#{mvn_cmd} --version")
170
- }
171
-
172
- task(:install_locally, :except => { :no_release => true }) {
173
- run_locally(_install(:path => mvn_path_local, :bin => mvn_bin_local,
174
- :checksum_file => mvn_checksum_file_local, :checksum_url => mvn_checksum_url,
175
- :archive_file => mvn_archive_file_local, :archive_url => mvn_archive_url))
176
- run_locally("#{mvn_cmd_local} --version")
177
- }
178
-
179
- def template(file)
180
- if File.file?(file)
181
- File.read(file)
182
- elsif File.file?("#{file}.erb")
183
- ERB.new(File.read("#{file}.erb")).result(binding)
184
- else
185
- abort("No such template: #{file} or #{file}.erb")
186
- end
187
- end
188
-
189
- def _update_settings(files_map, options={})
190
- execute = []
191
- dirs = files_map.map { |src, dst| File.dirname(dst) }.uniq
192
- execute << "mkdir -p #{dirs.join(' ')}" unless dirs.empty?
193
- files_map.each do |src, dst|
194
- execute << "( diff -u #{dst} #{src} || mv -f #{src} #{dst} )"
195
- cleanup = options.fetch(:cleanup, [])
196
- execute << "rm -f #{cleanup.join(' ')}" unless cleanup.empty?
197
- end
198
- execute.join(' && ')
199
- end
200
-
201
- task(:update_settings, :roles => :app, :except => { :no_release => true }) {
202
- srcs = mvn_settings.map { |f| File.join(mvn_template_path, f) }
203
- tmps = mvn_settings.map { |f| capture("mktemp").chomp }
204
- dsts = mvn_settings.map { |f| File.join(mvn_settings_path, f) }
205
- begin
206
- srcs.zip(tmps).each do |src, tmp|
207
- put(template(src), tmp)
208
- end
209
- run(_update_settings(tmps.zip(dsts), :cleanup => mvn_cleanup_settings)) unless tmps.empty?
210
- ensure
211
- run("rm -f #{tmps.join(' ')}") unless tmps.empty?
212
- end
213
- }
214
-
215
- task(:update_settings_locally, :except => { :no_release => true }) {
216
- srcs = mvn_settings_local.map { |f| File.join(mvn_template_path, f) }
217
- tmps = mvn_settings.map { |f| `mktemp`.chomp }
218
- dsts = mvn_settings_local.map { |f| File.join(mvn_settings_path_local, f) }
219
- begin
220
- srcs.zip(tmps).each do |src, tmp|
221
- File.open(tmp, 'wb') { |fp| fp.write(template(src)) }
222
- end
223
- run_locally(_update_settings(tmps.zip(dsts), :cleanup => mvn_cleanup_settings_local)) unless tmps.empty?
224
- ensure
225
- run_locally("rm -f #{tmps.join(' ')}") unless tmps.empty?
226
- end
227
- }
228
-
229
- desc("Update maven build.")
230
- task(:update, :roles => :app, :except => { :no_release => true }) {
231
- transaction {
232
- if mvn_compile_locally
233
- update_locally
234
- else
235
- execute
236
- end
237
- }
238
- }
239
- after 'deploy:finalize_update', 'mvn:update'
240
-
241
- desc("Update maven build locally.")
242
- task(:update_locally, :except => { :no_release => true }) {
243
- transaction {
244
- execute_locally
245
- upload_locally
246
- }
247
- }
248
-
249
- def _mvn(cmd, path, goals=[])
250
- "cd #{path.dump} && #{cmd} #{goals.map { |s| s.dump }.join(' ')}"
251
- end
252
-
253
- def _mvn_parse_version(s)
254
- # FIXME: is there any better way to get project version?
255
- s.split(/(?:\r?\n)+/).reject { |line| /^\[[A-Z]+\]/ =~ line }.last
256
- end
257
-
258
- _cset(:mvn_release_build, false)
259
- _cset(:mvn_snapshot_pattern, /-SNAPSHOT$/i)
260
- _cset(:mvn_project_version) {
261
- _mvn_parse_version(capture(_mvn(mvn_cmd, mvn_project_path, %w(-Dexpression=project.version help:evaluate))))
262
- }
263
- _cset(:mvn_project_version_local) {
264
- _mvn_parse_version(run_locally(_mvn(mvn_cmd_local, mvn_project_path_local, %w(-Dexpression=project.version help:evaluate))))
265
- }
266
-
267
- def _validate_project_version(version_key)
268
- if mvn_release_build
269
- version = fetch(version_key)
270
- if mvn_snapshot_pattern === version
271
- abort("Skip to build project since \`#{version}' is a SNAPSHOT version.")
272
- end
273
- end
274
- end
275
-
276
- desc("Perform maven build.")
277
- task(:execute, :roles => :app, :except => { :no_release => true }) {
278
- on_rollback {
279
- run(_mvn(mvn_cmd, mvn_project_path, %w(clean)))
280
- }
281
- _validate_project_version(:mvn_project_version)
282
- run(_mvn(mvn_cmd, mvn_project_path, mvn_goals))
283
- }
284
-
285
- desc("Perform maven build locally.")
286
- task(:execute_locally, :roles => :app, :except => { :no_release => true }) {
287
- on_rollback {
288
- run_locally(_mvn(mvn_cmd_local, mvn_project_path_local, %w(clean)))
289
- }
290
- _validate_project_version(:mvn_project_version_local)
291
- cmdline = _mvn(mvn_cmd_local, mvn_project_path_local, mvn_goals)
292
- logger.info(cmdline)
293
- abort("execution failure") unless system(cmdline)
294
- }
295
-
296
- _cset(:mvn_tar, 'tar')
297
- _cset(:mvn_tar_local, 'tar')
298
- _cset(:mvn_target_archive) {
299
- "#{mvn_target_path}.tar.gz"
300
- }
301
- _cset(:mvn_target_archive_local) {
302
- "#{mvn_target_path_local}.tar.gz"
303
- }
304
- task(:upload_locally, :roles => :app, :except => { :no_release => true }) {
305
- on_rollback {
306
- run("rm -rf #{mvn_target_path} #{mvn_target_archive}")
307
- }
308
- begin
309
- run_locally("cd #{File.dirname(mvn_target_path_local)} && #{mvn_tar_local} chzf #{mvn_target_archive_local} #{File.basename(mvn_target_path_local)}")
310
- upload(mvn_target_archive_local, mvn_target_archive)
311
- run("cd #{File.dirname(mvn_target_path)} && #{mvn_tar} xzf #{mvn_target_archive} && rm -f #{mvn_target_archive}")
312
- ensure
313
- run_locally("rm -f #{mvn_target_archive_local}")
314
- end
315
- }
316
- }
317
- }
318
- end
319
- end
320
- end
321
-
322
- if Capistrano::Configuration.instance
323
- Capistrano::Configuration.instance.extend(Capistrano::Maven)
324
- end
325
-
326
- # vim:set ft=ruby :