capistrano-maven 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -48,6 +48,7 @@ Following options are available to manage your Maven build.
48
48
  * `:mvn_template_path` - specify ERB template path for settings.xml.
49
49
  * `:mvn_java_home` - optional `JAVA_HOME` settings for Maven commands.
50
50
  * `:mvn_java_home_local` - optional `JAVA_HOME` settings for Maven commands in localhost.
51
+ * `:mvn_release_build` - Skip building on SNAPSHOT version. `false` by default.
51
52
 
52
53
  ## Contributing
53
54
 
@@ -1,6 +1,5 @@
1
1
 
2
2
  require 'capistrano'
3
- require 'tempfile'
4
3
  require 'uri'
5
4
 
6
5
  module Capistrano
@@ -201,7 +200,7 @@ module Capistrano
201
200
 
202
201
  task(:update_settings, :roles => :app, :except => { :no_release => true }) {
203
202
  srcs = mvn_settings.map { |f| File.join(mvn_template_path, f) }
204
- tmps = mvn_settings.map { |f| t=Tempfile.new('mvn');s=t.path;t.close(true);s }
203
+ tmps = mvn_settings.map { |f| capture("mktemp").chomp }
205
204
  dsts = mvn_settings.map { |f| File.join(mvn_settings_path, f) }
206
205
  begin
207
206
  srcs.zip(tmps).each do |src, tmp|
@@ -215,7 +214,7 @@ module Capistrano
215
214
 
216
215
  task(:update_settings_locally, :except => { :no_release => true }) {
217
216
  srcs = mvn_settings_local.map { |f| File.join(mvn_template_path, f) }
218
- tmps = mvn_settings.map { |f| t=Tempfile.new('mvn');s=t.path;t.close(true);s }
217
+ tmps = mvn_settings.map { |f| `mktemp`.chomp }
219
218
  dsts = mvn_settings_local.map { |f| File.join(mvn_settings_path_local, f) }
220
219
  begin
221
220
  srcs.zip(tmps).each do |src, tmp|
@@ -247,22 +246,51 @@ module Capistrano
247
246
  }
248
247
  }
249
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
+
250
276
  desc("Perform maven build.")
251
277
  task(:execute, :roles => :app, :except => { :no_release => true }) {
252
278
  on_rollback {
253
- run("cd #{mvn_project_path} && #{mvn_cmd} clean")
279
+ run(_mvn(mvn_cmd, mvn_project_path, %w(clean)))
254
280
  }
255
- run("cd #{mvn_project_path} && #{mvn_cmd} #{mvn_goals.join(' ')}")
281
+ _validate_project_version(:mvn_project_version)
282
+ run(_mvn(mvn_cmd, mvn_project_path, mvn_goals))
256
283
  }
257
284
 
258
285
  desc("Perform maven build locally.")
259
286
  task(:execute_locally, :roles => :app, :except => { :no_release => true }) {
260
287
  on_rollback {
261
- run_locally("cd #{mvn_project_path_local} && #{mvn_cmd_local} clean")
288
+ run_locally(_mvn(mvn_cmd_local, mvn_project_path_local, %w(clean)))
262
289
  }
263
- cmd = "cd #{mvn_project_path_local} && #{mvn_cmd_local} #{mvn_goals.join(' ')}"
264
- logger.info(cmd)
265
- abort("execution failure") unless system(cmd)
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)
266
294
  }
267
295
 
268
296
  _cset(:mvn_tar, 'tar')
@@ -1,5 +1,5 @@
1
1
  module Capistrano
2
2
  module Maven
3
- VERSION = "0.0.5"
3
+ VERSION = "0.0.6"
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.5
4
+ version: 0.0.6
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: 2012-11-01 00:00:00.000000000 Z
12
+ date: 2013-02-19 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: capistrano
@@ -69,3 +69,4 @@ signing_key:
69
69
  specification_version: 3
70
70
  summary: a capistrano recipe to deploy Apache Maven based projects.
71
71
  test_files: []
72
+ has_rdoc: