capistrano-sbt 0.0.6 → 0.0.7
Sign up to get free protection for your applications and to get access to all the features.
data/capistrano-sbt.gemspec
CHANGED
data/lib/capistrano-sbt.rb
CHANGED
@@ -1,8 +1,276 @@
|
|
1
|
-
require "capistrano-sbt/deploy"
|
2
1
|
require "capistrano-sbt/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 Sbt
|
6
|
-
|
9
|
+
def self.extended(configuration)
|
10
|
+
configuration.load {
|
11
|
+
namespace(:sbt) {
|
12
|
+
_cset(:sbt_version, '0.12.2')
|
13
|
+
_cset(:sbt_group_id) {
|
14
|
+
case sbt_version
|
15
|
+
when /^0\.(?:7|10)\.\d+$/, /^0\.11\.[0-2]$/
|
16
|
+
'org.scala-tools.sbt'
|
17
|
+
else
|
18
|
+
'org.scala-sbt'
|
19
|
+
end
|
20
|
+
}
|
21
|
+
_cset(:sbt_jar_url) {
|
22
|
+
"http://typesafe.artifactoryonline.com/typesafe/ivy-releases/#{sbt_group_id}/sbt-launch/#{sbt_version}/sbt-launch.jar"
|
23
|
+
}
|
24
|
+
_cset(:sbt_jar_file) {
|
25
|
+
File.join(shared_path, 'tools', 'sbt', "sbt-#{sbt_version}", File.basename(URI.parse(sbt_jar_url).path))
|
26
|
+
}
|
27
|
+
_cset(:sbt_jar_file_local) {
|
28
|
+
File.join(File.expand_path('.'), 'tools', 'sbt', "sbt-#{sbt_version}", File.basename(URI.parse(sbt_jar_url).path))
|
29
|
+
}
|
30
|
+
_cset(:sbt_use_extras, false)
|
31
|
+
_cset(:sbt_extras_url, "https://raw.github.com/paulp/sbt-extras/master/sbt")
|
32
|
+
_cset(:sbt_extras_file) { File.join(shared_path, 'tools', 'sbt', 'sbt') }
|
33
|
+
_cset(:sbt_extras_file_local) { File.join(File.expand_path('.'), 'tools', 'sbt', 'sbt') }
|
34
|
+
_cset(:sbt_extras_check_interval, 86400)
|
35
|
+
_cset(:sbt_extras_check_timestamp) { (Time.now - sbt_extras_check_interval).strftime('%Y%m%d%H%M') }
|
36
|
+
_cset(:sbt_cmd) {
|
37
|
+
if fetch(:sbt_java_home, nil)
|
38
|
+
env = "env JAVA_HOME=#{sbt_java_home.dump}"
|
39
|
+
java = "#{sbt_java_home}/bin/java"
|
40
|
+
else
|
41
|
+
env = ""
|
42
|
+
java = "java"
|
43
|
+
end
|
44
|
+
if sbt_use_extras
|
45
|
+
"#{env} #{sbt_extras_file} #{sbt_options.join(' ')}".strip
|
46
|
+
else
|
47
|
+
"#{env} #{java} -jar #{sbt_jar_file} #{sbt_options.join(' ')}".strip
|
48
|
+
end
|
49
|
+
}
|
50
|
+
_cset(:sbt_cmd_local) {
|
51
|
+
if fetch(:sbt_java_home_local, nil)
|
52
|
+
env = "env JAVA_HOME=#{sbt_java_home_local.dump}"
|
53
|
+
java = "#{sbt_java_home_local}/bin/java"
|
54
|
+
end
|
55
|
+
if sbt_use_extras
|
56
|
+
"#{env} #{sbt_extras_file_local} #{sbt_options_local.join(' ')}".strip
|
57
|
+
else
|
58
|
+
"#{env} #{java} -jar #{sbt_jar_file_local} #{sbt_options_local.join(' ')}".strip
|
59
|
+
end
|
60
|
+
}
|
61
|
+
_cset(:sbt_project_path) {
|
62
|
+
release_path
|
63
|
+
}
|
64
|
+
_cset(:sbt_project_path_local) {
|
65
|
+
Dir.pwd
|
66
|
+
}
|
67
|
+
_cset(:sbt_target_path) {
|
68
|
+
File.join(sbt_project_path, 'target')
|
69
|
+
}
|
70
|
+
_cset(:sbt_target_path_local) {
|
71
|
+
File.join(sbt_project_path_local, File.basename(sbt_target_path))
|
72
|
+
}
|
73
|
+
_cset(:sbt_template_path, File.join(File.dirname(__FILE__), 'templates'))
|
74
|
+
_cset(:sbt_update_settings, false)
|
75
|
+
_cset(:sbt_update_settings_locally, false)
|
76
|
+
_cset(:sbt_settings_path) { File.join(sbt_project_path, 'sbt') }
|
77
|
+
_cset(:sbt_settings_path_local) { File.join(sbt_project_path_local, 'sbt') }
|
78
|
+
_cset(:sbt_settings, [])
|
79
|
+
_cset(:sbt_settings_local, [])
|
80
|
+
_cset(:sbt_cleanup_settings, [])
|
81
|
+
_cset(:sbt_cleanup_settings_local, [])
|
82
|
+
_cset(:sbt_compile_locally, false) # perform precompilation on localhost
|
83
|
+
_cset(:sbt_goals, %w(reload clean package))
|
84
|
+
_cset(:sbt_common_options) {
|
85
|
+
options = []
|
86
|
+
if fetch(:sbt_log_noformat, true)
|
87
|
+
options << if sbt_use_extras
|
88
|
+
"-no-colors"
|
89
|
+
else
|
90
|
+
"-Dsbt.log.noformat=true"
|
91
|
+
end
|
92
|
+
end
|
93
|
+
options
|
94
|
+
}
|
95
|
+
_cset(:sbt_options) {
|
96
|
+
options = sbt_common_options + fetch(:sbt_extra_options, [])
|
97
|
+
if sbt_update_settings
|
98
|
+
options << if sbt_use_extras
|
99
|
+
"-sbt-dir #{sbt_settings_path}"
|
100
|
+
else
|
101
|
+
"-Dsbt.global.base=#{sbt_settings_path}"
|
102
|
+
end
|
103
|
+
end
|
104
|
+
options
|
105
|
+
}
|
106
|
+
_cset(:sbt_options_local) {
|
107
|
+
options = sbt_common_options + fetch(:sbt_extra_options_local, [])
|
108
|
+
if sbt_update_settings_locally
|
109
|
+
options << if sbt_use_extras
|
110
|
+
"-sbt-dir #{sbt_settings_path_local}"
|
111
|
+
else
|
112
|
+
"-Dsbt.global.base=#{sbt_settings_path_local}"
|
113
|
+
end
|
114
|
+
end
|
115
|
+
options
|
116
|
+
}
|
117
|
+
|
118
|
+
desc("Setup sbt.")
|
119
|
+
task(:setup, :roles => :app, :except => { :no_release => true }) {
|
120
|
+
transaction {
|
121
|
+
install
|
122
|
+
update_settings if sbt_update_settings
|
123
|
+
setup_locally if sbt_compile_locally
|
124
|
+
}
|
125
|
+
}
|
126
|
+
after 'deploy:setup', 'sbt:setup'
|
127
|
+
|
128
|
+
desc("Setup sbt locally.")
|
129
|
+
task(:setup_locally, :except => { :no_release => true }) {
|
130
|
+
transaction {
|
131
|
+
install_locally
|
132
|
+
update_settings_locally if sbt_update_settings_locally
|
133
|
+
}
|
134
|
+
}
|
135
|
+
|
136
|
+
def _install(options={})
|
137
|
+
execute = []
|
138
|
+
if sbt_use_extras
|
139
|
+
extras_file = options.delete(:extras_file)
|
140
|
+
execute << "mkdir -p #{File.dirname(extras_file)}"
|
141
|
+
x = "/tmp/sbt-extras.#{$$}"
|
142
|
+
execute << "touch -t #{sbt_extras_check_timestamp} #{x}"
|
143
|
+
execute << "( test #{extras_file} -nt #{x} || wget --no-verbose -O #{extras_file} #{sbt_extras_url} )"
|
144
|
+
execute << "touch #{extras_file}"
|
145
|
+
execute << "rm -f #{x}"
|
146
|
+
execute << "( test -x #{extras_file} || chmod a+x #{extras_file} )"
|
147
|
+
else
|
148
|
+
jar_file = options.delete(:jar_file)
|
149
|
+
execute << "mkdir -p #{File.dirname(jar_file)}"
|
150
|
+
execute << "( test -f #{jar_file} || wget --no-verbose -O #{jar_file} #{sbt_jar_url} )"
|
151
|
+
execute << "test -f #{jar_file}"
|
152
|
+
end
|
153
|
+
execute.join(' && ')
|
154
|
+
end
|
155
|
+
|
156
|
+
task(:install, :roles => :app, :except => { :no_release => true }) {
|
157
|
+
run(_install(:jar_file => sbt_jar_file, :extras_file => sbt_extras_file))
|
158
|
+
}
|
159
|
+
|
160
|
+
task(:install_locally, :except => { :no_release => true }) {
|
161
|
+
run_locally(_install(:jar_file => sbt_jar_file_local, :extras_file => sbt_extras_file_local))
|
162
|
+
}
|
163
|
+
|
164
|
+
task(:update_settings, :roles => :app, :except => { :no_release => true }) {
|
165
|
+
sbt_settings.each do |f|
|
166
|
+
safe_put(template(f, :path => sbt_template_path), File.join(sbt_settings_path, f))
|
167
|
+
end
|
168
|
+
run("rm -f #{sbt_cleanup_settings.map { |x| x.dump }.join(' ')}") unless sbt_cleanup_settings.empty?
|
169
|
+
}
|
170
|
+
|
171
|
+
task(:update_settings_locally, :except => { :no_release => true }) {
|
172
|
+
sbt_settings_local.each do |f|
|
173
|
+
File.write(File.join(sbt_settings_path_local, f), template(f, :path => sbt_template_path))
|
174
|
+
end
|
175
|
+
run_locally("rm -f #{sbt_cleanup_settings_local.map { |x| x.dump }.join(' ')}") unless sbt_cleanup_settings_local.empty?
|
176
|
+
}
|
177
|
+
|
178
|
+
desc("Update sbt build.")
|
179
|
+
task(:update, :roles => :app, :except => { :no_release => true }) {
|
180
|
+
transaction {
|
181
|
+
if sbt_compile_locally
|
182
|
+
update_locally
|
183
|
+
else
|
184
|
+
execute
|
185
|
+
end
|
186
|
+
}
|
187
|
+
}
|
188
|
+
after 'deploy:finalize_update', 'sbt:update'
|
189
|
+
|
190
|
+
desc("Update sbt build locally.")
|
191
|
+
task(:update_locally, :except => { :no_release => true }) {
|
192
|
+
transaction {
|
193
|
+
execute_locally
|
194
|
+
upload_locally
|
195
|
+
}
|
196
|
+
}
|
197
|
+
|
198
|
+
def _sbt(cmd, path, goals=[])
|
199
|
+
"cd #{path.dump} && #{cmd} #{goals.map { |s| s.dump }.join(' ')}"
|
200
|
+
end
|
201
|
+
|
202
|
+
def _sbt_parse_version(s)
|
203
|
+
# FIXME: is there any better way to get project version?
|
204
|
+
lastline = s.split(/(?:\r?\n)+/)[-1]
|
205
|
+
lastline.split[-1]
|
206
|
+
end
|
207
|
+
|
208
|
+
_cset(:sbt_release_build, false)
|
209
|
+
_cset(:sbt_snapshot_pattern, /-SNAPSHOT$/i)
|
210
|
+
_cset(:sbt_project_version) {
|
211
|
+
_sbt_parse_version(capture(_sbt(sbt_cmd, sbt_project_path, ["show version"])))
|
212
|
+
}
|
213
|
+
_cset(:sbt_project_version_local) {
|
214
|
+
_sbt_parse_version(run_locally(_sbt(sbt_cmd_local, sbt_project_path_local, ["show version"])))
|
215
|
+
}
|
216
|
+
|
217
|
+
def _validate_project_version(version_key)
|
218
|
+
if sbt_release_build
|
219
|
+
version = fetch(version_key)
|
220
|
+
if sbt_snapshot_pattern === version
|
221
|
+
abort("Skip to build project since \`#{version}' is a SNAPSHOT version.")
|
222
|
+
end
|
223
|
+
end
|
224
|
+
end
|
225
|
+
|
226
|
+
desc("Perform sbt build.")
|
227
|
+
task(:execute, :roles => :app, :except => { :no_release => true }) {
|
228
|
+
on_rollback {
|
229
|
+
run(_sbt(sbt_cmd, sbt_project_path, %w(clean)))
|
230
|
+
}
|
231
|
+
_validate_project_version(:sbt_project_version)
|
232
|
+
run(_sbt(sbt_cmd, sbt_project_path, sbt_goals))
|
233
|
+
}
|
234
|
+
|
235
|
+
desc("Perform sbt build locally.")
|
236
|
+
task(:execute_locally, :roles => :app, :except => { :no_release => true }) {
|
237
|
+
on_rollback {
|
238
|
+
run_locally(_sbt(sbt_cmd_local, sbt_project_path_local, %w(clean)))
|
239
|
+
}
|
240
|
+
_validate_project_version(:sbt_project_version_local)
|
241
|
+
cmdline = _sbt(sbt_cmd_local, sbt_project_path_local, sbt_goals)
|
242
|
+
logger.info(cmdline)
|
243
|
+
abort("execution failure") unless system(cmdline)
|
244
|
+
}
|
245
|
+
|
246
|
+
_cset(:sbt_tar, 'tar')
|
247
|
+
_cset(:sbt_tar_local, 'tar')
|
248
|
+
_cset(:sbt_target_archive) {
|
249
|
+
"#{sbt_target_path}.tar.gz"
|
250
|
+
}
|
251
|
+
_cset(:sbt_target_archive_local) {
|
252
|
+
"#{sbt_target_path_local}.tar.gz"
|
253
|
+
}
|
254
|
+
task(:upload_locally, :roles => :app, :except => { :no_release => true }) {
|
255
|
+
on_rollback {
|
256
|
+
run("rm -rf #{sbt_target_path} #{sbt_target_archive}")
|
257
|
+
}
|
258
|
+
begin
|
259
|
+
run_locally("cd #{File.dirname(sbt_target_path_local)} && #{sbt_tar_local} chzf #{sbt_target_archive_local} #{File.basename(sbt_target_path_local)}")
|
260
|
+
upload(sbt_target_archive_local, sbt_target_archive)
|
261
|
+
run("cd #{File.dirname(sbt_target_path)} && #{sbt_tar} xzf #{sbt_target_archive} && rm -f #{sbt_target_archive}")
|
262
|
+
ensure
|
263
|
+
run_locally("rm -f #{sbt_target_archive_local}")
|
264
|
+
end
|
265
|
+
}
|
266
|
+
}
|
267
|
+
}
|
268
|
+
end
|
7
269
|
end
|
8
270
|
end
|
271
|
+
|
272
|
+
if Capistrano::Configuration.instance
|
273
|
+
Capistrano::Configuration.instance.extend(Capistrano::Sbt)
|
274
|
+
end
|
275
|
+
|
276
|
+
# vim:set ft=ruby :
|
File without changes
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: capistrano-sbt
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
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-
|
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 sbt based projects.
|
31
63
|
email:
|
32
64
|
- yamashita@geishatokyo.com
|
@@ -41,9 +73,8 @@ files:
|
|
41
73
|
- Rakefile
|
42
74
|
- capistrano-sbt.gemspec
|
43
75
|
- lib/capistrano-sbt.rb
|
44
|
-
- lib/capistrano-sbt/deploy.rb
|
45
|
-
- lib/capistrano-sbt/templates/global.sbt
|
46
76
|
- lib/capistrano-sbt/version.rb
|
77
|
+
- lib/templates/global.sbt
|
47
78
|
homepage: https://github.com/yyuu/capistrano-sbt
|
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 sbt based projects.
|
71
102
|
test_files: []
|
72
|
-
has_rdoc:
|
@@ -1,310 +0,0 @@
|
|
1
|
-
|
2
|
-
require 'capistrano'
|
3
|
-
require 'uri'
|
4
|
-
|
5
|
-
module Capistrano
|
6
|
-
module Sbt
|
7
|
-
def self.extended(configuration)
|
8
|
-
configuration.load {
|
9
|
-
namespace(:sbt) {
|
10
|
-
_cset(:sbt_version, '0.12.2')
|
11
|
-
_cset(:sbt_group_id) {
|
12
|
-
case sbt_version
|
13
|
-
when /^0\.(?:7|10)\.\d+$/, /^0\.11\.[0-2]$/
|
14
|
-
'org.scala-tools.sbt'
|
15
|
-
else
|
16
|
-
'org.scala-sbt'
|
17
|
-
end
|
18
|
-
}
|
19
|
-
_cset(:sbt_jar_url) {
|
20
|
-
"http://typesafe.artifactoryonline.com/typesafe/ivy-releases/#{sbt_group_id}/sbt-launch/#{sbt_version}/sbt-launch.jar"
|
21
|
-
}
|
22
|
-
_cset(:sbt_jar_file) {
|
23
|
-
File.join(shared_path, 'tools', 'sbt', "sbt-#{sbt_version}", File.basename(URI.parse(sbt_jar_url).path))
|
24
|
-
}
|
25
|
-
_cset(:sbt_jar_file_local) {
|
26
|
-
File.join(File.expand_path('.'), 'tools', 'sbt', "sbt-#{sbt_version}", File.basename(URI.parse(sbt_jar_url).path))
|
27
|
-
}
|
28
|
-
_cset(:sbt_use_extras, false)
|
29
|
-
_cset(:sbt_extras_url, "https://raw.github.com/paulp/sbt-extras/master/sbt")
|
30
|
-
_cset(:sbt_extras_file) { File.join(shared_path, 'tools', 'sbt', 'sbt') }
|
31
|
-
_cset(:sbt_extras_file_local) { File.join(File.expand_path('.'), 'tools', 'sbt', 'sbt') }
|
32
|
-
_cset(:sbt_extras_check_interval, 86400)
|
33
|
-
_cset(:sbt_extras_check_timestamp) { (Time.now - sbt_extras_check_interval).strftime('%Y%m%d%H%M') }
|
34
|
-
_cset(:sbt_cmd) {
|
35
|
-
if fetch(:sbt_java_home, nil)
|
36
|
-
env = "env JAVA_HOME=#{sbt_java_home.dump}"
|
37
|
-
java = "#{sbt_java_home}/bin/java"
|
38
|
-
else
|
39
|
-
env = ""
|
40
|
-
java = "java"
|
41
|
-
end
|
42
|
-
if sbt_use_extras
|
43
|
-
"#{env} #{sbt_extras_file} #{sbt_options.join(' ')}".strip
|
44
|
-
else
|
45
|
-
"#{env} #{java} -jar #{sbt_jar_file} #{sbt_options.join(' ')}".strip
|
46
|
-
end
|
47
|
-
}
|
48
|
-
_cset(:sbt_cmd_local) {
|
49
|
-
if fetch(:sbt_java_home_local, nil)
|
50
|
-
env = "env JAVA_HOME=#{sbt_java_home_local.dump}"
|
51
|
-
java = "#{sbt_java_home_local}/bin/java"
|
52
|
-
end
|
53
|
-
if sbt_use_extras
|
54
|
-
"#{env} #{sbt_extras_file_local} #{sbt_options_local.join(' ')}".strip
|
55
|
-
else
|
56
|
-
"#{env} #{java} -jar #{sbt_jar_file_local} #{sbt_options_local.join(' ')}".strip
|
57
|
-
end
|
58
|
-
}
|
59
|
-
_cset(:sbt_project_path) {
|
60
|
-
release_path
|
61
|
-
}
|
62
|
-
_cset(:sbt_project_path_local) {
|
63
|
-
Dir.pwd
|
64
|
-
}
|
65
|
-
_cset(:sbt_target_path) {
|
66
|
-
File.join(sbt_project_path, 'target')
|
67
|
-
}
|
68
|
-
_cset(:sbt_target_path_local) {
|
69
|
-
File.join(sbt_project_path_local, File.basename(sbt_target_path))
|
70
|
-
}
|
71
|
-
_cset(:sbt_template_path, File.join(File.dirname(__FILE__), 'templates'))
|
72
|
-
_cset(:sbt_update_settings, false)
|
73
|
-
_cset(:sbt_update_settings_locally, false)
|
74
|
-
_cset(:sbt_settings_path) { File.join(sbt_project_path, 'sbt') }
|
75
|
-
_cset(:sbt_settings_path_local) { File.join(sbt_project_path_local, 'sbt') }
|
76
|
-
_cset(:sbt_settings, [])
|
77
|
-
_cset(:sbt_settings_local, [])
|
78
|
-
_cset(:sbt_cleanup_settings, [])
|
79
|
-
_cset(:sbt_cleanup_settings_local, [])
|
80
|
-
_cset(:sbt_compile_locally, false) # perform precompilation on localhost
|
81
|
-
_cset(:sbt_goals, %w(reload clean package))
|
82
|
-
_cset(:sbt_common_options) {
|
83
|
-
options = []
|
84
|
-
if fetch(:sbt_log_noformat, true)
|
85
|
-
options << if sbt_use_extras
|
86
|
-
"-no-colors"
|
87
|
-
else
|
88
|
-
"-Dsbt.log.noformat=true"
|
89
|
-
end
|
90
|
-
end
|
91
|
-
options
|
92
|
-
}
|
93
|
-
_cset(:sbt_options) {
|
94
|
-
options = sbt_common_options + fetch(:sbt_extra_options, [])
|
95
|
-
if sbt_update_settings
|
96
|
-
options << if sbt_use_extras
|
97
|
-
"-sbt-dir #{sbt_settings_path}"
|
98
|
-
else
|
99
|
-
"-Dsbt.global.base=#{sbt_settings_path}"
|
100
|
-
end
|
101
|
-
end
|
102
|
-
options
|
103
|
-
}
|
104
|
-
_cset(:sbt_options_local) {
|
105
|
-
options = sbt_common_options + fetch(:sbt_extra_options_local, [])
|
106
|
-
if sbt_update_settings_locally
|
107
|
-
options << if sbt_use_extras
|
108
|
-
"-sbt-dir #{sbt_settings_path_local}"
|
109
|
-
else
|
110
|
-
"-Dsbt.global.base=#{sbt_settings_path_local}"
|
111
|
-
end
|
112
|
-
end
|
113
|
-
options
|
114
|
-
}
|
115
|
-
|
116
|
-
desc("Setup sbt.")
|
117
|
-
task(:setup, :roles => :app, :except => { :no_release => true }) {
|
118
|
-
transaction {
|
119
|
-
install
|
120
|
-
update_settings if sbt_update_settings
|
121
|
-
setup_locally if sbt_compile_locally
|
122
|
-
}
|
123
|
-
}
|
124
|
-
after 'deploy:setup', 'sbt:setup'
|
125
|
-
|
126
|
-
desc("Setup sbt locally.")
|
127
|
-
task(:setup_locally, :except => { :no_release => true }) {
|
128
|
-
transaction {
|
129
|
-
install_locally
|
130
|
-
update_settings_locally if sbt_update_settings_locally
|
131
|
-
}
|
132
|
-
}
|
133
|
-
|
134
|
-
def _install(options={})
|
135
|
-
execute = []
|
136
|
-
if sbt_use_extras
|
137
|
-
extras_file = options.delete(:extras_file)
|
138
|
-
execute << "mkdir -p #{File.dirname(extras_file)}"
|
139
|
-
x = "/tmp/sbt-extras.#{$$}"
|
140
|
-
execute << "touch -t #{sbt_extras_check_timestamp} #{x}"
|
141
|
-
execute << "( test #{extras_file} -nt #{x} || wget --no-verbose -O #{extras_file} #{sbt_extras_url} )"
|
142
|
-
execute << "touch #{extras_file}"
|
143
|
-
execute << "rm -f #{x}"
|
144
|
-
execute << "( test -x #{extras_file} || chmod a+x #{extras_file} )"
|
145
|
-
else
|
146
|
-
jar_file = options.delete(:jar_file)
|
147
|
-
execute << "mkdir -p #{File.dirname(jar_file)}"
|
148
|
-
execute << "( test -f #{jar_file} || wget --no-verbose -O #{jar_file} #{sbt_jar_url} )"
|
149
|
-
execute << "test -f #{jar_file}"
|
150
|
-
end
|
151
|
-
execute.join(' && ')
|
152
|
-
end
|
153
|
-
|
154
|
-
task(:install, :roles => :app, :except => { :no_release => true }) {
|
155
|
-
run(_install(:jar_file => sbt_jar_file, :extras_file => sbt_extras_file))
|
156
|
-
}
|
157
|
-
|
158
|
-
task(:install_locally, :except => { :no_release => true }) {
|
159
|
-
run_locally(_install(:jar_file => sbt_jar_file_local, :extras_file => sbt_extras_file_local))
|
160
|
-
}
|
161
|
-
|
162
|
-
def template(file)
|
163
|
-
if File.file?(file)
|
164
|
-
File.read(file)
|
165
|
-
elsif File.file?("#{file}.erb")
|
166
|
-
ERB.new(File.read("#{file}.erb")).result(binding)
|
167
|
-
else
|
168
|
-
abort("No such template: #{file} or #{file}.erb")
|
169
|
-
end
|
170
|
-
end
|
171
|
-
|
172
|
-
def _update_settings(files_map, options={})
|
173
|
-
execute = []
|
174
|
-
dirs = files_map.map { |src, dst| File.dirname(dst) }.uniq
|
175
|
-
execute << "mkdir -p #{dirs.join(' ')}" unless dirs.empty?
|
176
|
-
files_map.each do |src, dst|
|
177
|
-
execute << "( diff -u #{dst} #{src} || mv -f #{src} #{dst} )"
|
178
|
-
cleanup = options.fetch(:cleanup, [])
|
179
|
-
execute << "rm -f #{cleanup.join(' ')}" unless cleanup.empty?
|
180
|
-
end
|
181
|
-
execute.join(' && ')
|
182
|
-
end
|
183
|
-
|
184
|
-
task(:update_settings, :roles => :app, :except => { :no_release => true }) {
|
185
|
-
srcs = sbt_settings.map { |f| File.join(sbt_template_path, f) }
|
186
|
-
tmps = sbt_settings.map { |f| capture("mktemp").chomp }
|
187
|
-
dsts = sbt_settings.map { |f| File.join(sbt_settings_path, f) }
|
188
|
-
begin
|
189
|
-
srcs.zip(tmps).each do |src, tmp|
|
190
|
-
put(template(src), tmp)
|
191
|
-
end
|
192
|
-
run(_update_settings(tmps.zip(dsts), :cleanup => sbt_cleanup_settings)) unless tmps.empty?
|
193
|
-
ensure
|
194
|
-
run("rm -f #{tmps.join(' ')}") unless tmps.empty?
|
195
|
-
end
|
196
|
-
}
|
197
|
-
|
198
|
-
task(:update_settings_locally, :except => { :no_release => true }) {
|
199
|
-
srcs = sbt_settings_local.map { |f| File.join(sbt_template_path, f) }
|
200
|
-
tmps = sbt_settings.map { |f| `mktemp`.chomp }
|
201
|
-
dsts = sbt_settings_local.map { |f| File.join(sbt_settings_path_local, f) }
|
202
|
-
begin
|
203
|
-
srcs.zip(tmps).each do |src, tmp|
|
204
|
-
File.open(tmp, 'wb') { |fp| fp.write(template(src)) }
|
205
|
-
end
|
206
|
-
run_locally(_update_settings(tmps.zip(dsts), :cleanup => sbt_cleanup_settings_local)) unless tmps.empty?
|
207
|
-
ensure
|
208
|
-
run_locally("rm -f #{tmps.join(' ')}") unless tmps.empty?
|
209
|
-
end
|
210
|
-
}
|
211
|
-
|
212
|
-
desc("Update sbt build.")
|
213
|
-
task(:update, :roles => :app, :except => { :no_release => true }) {
|
214
|
-
transaction {
|
215
|
-
if sbt_compile_locally
|
216
|
-
update_locally
|
217
|
-
else
|
218
|
-
execute
|
219
|
-
end
|
220
|
-
}
|
221
|
-
}
|
222
|
-
after 'deploy:finalize_update', 'sbt:update'
|
223
|
-
|
224
|
-
desc("Update sbt build locally.")
|
225
|
-
task(:update_locally, :except => { :no_release => true }) {
|
226
|
-
transaction {
|
227
|
-
execute_locally
|
228
|
-
upload_locally
|
229
|
-
}
|
230
|
-
}
|
231
|
-
|
232
|
-
def _sbt(cmd, path, goals=[])
|
233
|
-
"cd #{path.dump} && #{cmd} #{goals.map { |s| s.dump }.join(' ')}"
|
234
|
-
end
|
235
|
-
|
236
|
-
def _sbt_parse_version(s)
|
237
|
-
# FIXME: is there any better way to get project version?
|
238
|
-
lastline = s.split(/(?:\r?\n)+/)[-1]
|
239
|
-
lastline.split[-1]
|
240
|
-
end
|
241
|
-
|
242
|
-
_cset(:sbt_release_build, false)
|
243
|
-
_cset(:sbt_snapshot_pattern, /-SNAPSHOT$/i)
|
244
|
-
_cset(:sbt_project_version) {
|
245
|
-
_sbt_parse_version(capture(_sbt(sbt_cmd, sbt_project_path, ["show version"])))
|
246
|
-
}
|
247
|
-
_cset(:sbt_project_version_local) {
|
248
|
-
_sbt_parse_version(run_locally(_sbt(sbt_cmd_local, sbt_project_path_local, ["show version"])))
|
249
|
-
}
|
250
|
-
|
251
|
-
def _validate_project_version(version_key)
|
252
|
-
if sbt_release_build
|
253
|
-
version = fetch(version_key)
|
254
|
-
if sbt_snapshot_pattern === version
|
255
|
-
abort("Skip to build project since \`#{version}' is a SNAPSHOT version.")
|
256
|
-
end
|
257
|
-
end
|
258
|
-
end
|
259
|
-
|
260
|
-
desc("Perform sbt build.")
|
261
|
-
task(:execute, :roles => :app, :except => { :no_release => true }) {
|
262
|
-
on_rollback {
|
263
|
-
run(_sbt(sbt_cmd, sbt_project_path, %w(clean)))
|
264
|
-
}
|
265
|
-
_validate_project_version(:sbt_project_version)
|
266
|
-
run(_sbt(sbt_cmd, sbt_project_path, sbt_goals))
|
267
|
-
}
|
268
|
-
|
269
|
-
desc("Perform sbt build locally.")
|
270
|
-
task(:execute_locally, :roles => :app, :except => { :no_release => true }) {
|
271
|
-
on_rollback {
|
272
|
-
run_locally(_sbt(sbt_cmd_local, sbt_project_path_local, %w(clean)))
|
273
|
-
}
|
274
|
-
_validate_project_version(:sbt_project_version_local)
|
275
|
-
cmdline = _sbt(sbt_cmd_local, sbt_project_path_local, sbt_goals)
|
276
|
-
logger.info(cmdline)
|
277
|
-
abort("execution failure") unless system(cmdline)
|
278
|
-
}
|
279
|
-
|
280
|
-
_cset(:sbt_tar, 'tar')
|
281
|
-
_cset(:sbt_tar_local, 'tar')
|
282
|
-
_cset(:sbt_target_archive) {
|
283
|
-
"#{sbt_target_path}.tar.gz"
|
284
|
-
}
|
285
|
-
_cset(:sbt_target_archive_local) {
|
286
|
-
"#{sbt_target_path_local}.tar.gz"
|
287
|
-
}
|
288
|
-
task(:upload_locally, :roles => :app, :except => { :no_release => true }) {
|
289
|
-
on_rollback {
|
290
|
-
run("rm -rf #{sbt_target_path} #{sbt_target_archive}")
|
291
|
-
}
|
292
|
-
begin
|
293
|
-
run_locally("cd #{File.dirname(sbt_target_path_local)} && #{sbt_tar_local} chzf #{sbt_target_archive_local} #{File.basename(sbt_target_path_local)}")
|
294
|
-
upload(sbt_target_archive_local, sbt_target_archive)
|
295
|
-
run("cd #{File.dirname(sbt_target_path)} && #{sbt_tar} xzf #{sbt_target_archive} && rm -f #{sbt_target_archive}")
|
296
|
-
ensure
|
297
|
-
run_locally("rm -f #{sbt_target_archive_local}")
|
298
|
-
end
|
299
|
-
}
|
300
|
-
}
|
301
|
-
}
|
302
|
-
end
|
303
|
-
end
|
304
|
-
end
|
305
|
-
|
306
|
-
if Capistrano::Configuration.instance
|
307
|
-
Capistrano::Configuration.instance.extend(Capistrano::Sbt)
|
308
|
-
end
|
309
|
-
|
310
|
-
# vim:set ft=ruby :
|