capistrano-maven 0.0.3 → 0.0.4
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.
- data/lib/capistrano-maven/deploy.rb +104 -64
- data/lib/capistrano-maven/version.rb +1 -1
- metadata +2 -2
@@ -1,5 +1,6 @@
|
|
1
1
|
|
2
2
|
require 'capistrano'
|
3
|
+
require 'tempfile'
|
3
4
|
require 'uri'
|
4
5
|
|
5
6
|
module Capistrano
|
@@ -20,6 +21,21 @@ module Capistrano
|
|
20
21
|
_cset(:mvn_archive_file_local) {
|
21
22
|
File.join(File.expand_path('.'), 'tools', 'mvn', File.basename(URI.parse(mvn_archive_url).path))
|
22
23
|
}
|
24
|
+
_cset(:mvn_checksum_url) {
|
25
|
+
"#{mvn_archive_url}.md5"
|
26
|
+
}
|
27
|
+
_cset(:mvn_checksum_file) {
|
28
|
+
File.join(shared_path, 'tools', 'mvn', File.basename(URI.parse(mvn_checksum_url).path))
|
29
|
+
}
|
30
|
+
_cset(:mvn_checksum_file_local) {
|
31
|
+
File.join(File.expand_path('.'), 'tools', 'mvn', File.basename(URI.parse(mvn_checksum_url).path))
|
32
|
+
}
|
33
|
+
_cset(:mvn_checksum_cmd) {
|
34
|
+
case File.extname(File.basename(URI.parse(mvn_checksum_url).path))
|
35
|
+
when '.md5' then 'md5sum'
|
36
|
+
when '.sha1' then 'sha1sum'
|
37
|
+
end
|
38
|
+
}
|
23
39
|
_cset(:mvn_path) {
|
24
40
|
File.join(shared_path, 'tools', 'mvn', File.basename(URI.parse(mvn_archive_url).path, "-bin.tar.gz"))
|
25
41
|
}
|
@@ -108,78 +124,103 @@ module Capistrano
|
|
108
124
|
}
|
109
125
|
}
|
110
126
|
|
127
|
+
def _validate_archive(archive_file, checksum_file)
|
128
|
+
if cmd = fetch(:mvn_checksum_cmd, nil)
|
129
|
+
"test `#{cmd} #{archive_file} | cut -d' ' -f1` = `cat #{checksum_file}`"
|
130
|
+
else
|
131
|
+
"true"
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
def _install(options={})
|
136
|
+
path = options.delete(:path)
|
137
|
+
bin = options.delete(:bin)
|
138
|
+
checksum_file = options.delete(:checksum_file)
|
139
|
+
checksum_url = options.delete(:checksum_url)
|
140
|
+
archive_file = options.delete(:archive_file)
|
141
|
+
archive_url = options.delete(:archive_url)
|
142
|
+
dirs = [ File.dirname(checksum_file), File.dirname(archive_file), File.dirname(path) ].uniq()
|
143
|
+
execute = []
|
144
|
+
execute << "mkdir -p #{dirs.join(' ')}"
|
145
|
+
execute << (<<-EOS).gsub(/\s+/, ' ').strip
|
146
|
+
if ! test -f #{archive_file}; then
|
147
|
+
( rm -f #{checksum_file}; wget --no-verbose -O #{checksum_file} #{checksum_url} ) &&
|
148
|
+
wget --no-verbose -O #{archive_file} #{archive_url} &&
|
149
|
+
#{_validate_archive(archive_file, checksum_file)} || ( rm -f #{archive_file}; false ) &&
|
150
|
+
test -f #{archive_file};
|
151
|
+
fi
|
152
|
+
EOS
|
153
|
+
execute << (<<-EOS).gsub(/\s+/, ' ').strip
|
154
|
+
if ! test -x #{bin}; then
|
155
|
+
( test -d #{path} || tar xf #{archive_file} -C #{File.dirname(path)} ) &&
|
156
|
+
test -x #{bin};
|
157
|
+
fi
|
158
|
+
EOS
|
159
|
+
execute.join(' && ')
|
160
|
+
end
|
161
|
+
|
111
162
|
task(:install, :roles => :app, :except => { :no_release => true }) {
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
task(:install_locally, :except => { :no_release => true }) { # TODO: make install and install_locally together
|
125
|
-
dirs = [ File.dirname(mvn_archive_file_local), File.dirname(mvn_path_local) ].uniq()
|
126
|
-
run_locally(<<-E)
|
127
|
-
if ! test -x #{mvn_bin_local}; then
|
128
|
-
mkdir -p #{dirs.join(' ')} &&
|
129
|
-
( test -f #{mvn_archive_file_local} || wget --no-verbose -O #{mvn_archive_file_local} #{mvn_archive_url} ) &&
|
130
|
-
( test -d #{mvn_path_local} || tar xf #{mvn_archive_file_local} -C #{File.dirname(mvn_path_local)} ) &&
|
131
|
-
test -x #{mvn_bin_local};
|
132
|
-
fi &&
|
133
|
-
#{mvn_cmd_local} --version;
|
134
|
-
E
|
163
|
+
run(_install(:path => mvn_path, :bin => mvn_bin,
|
164
|
+
:checksum_file => mvn_checksum_file, :checksum_url => mvn_checksum_url,
|
165
|
+
:archive_file => mvn_archive_file, :archive_url => mvn_archive_url))
|
166
|
+
run("#{mvn_cmd} --version")
|
167
|
+
}
|
168
|
+
|
169
|
+
task(:install_locally, :except => { :no_release => true }) {
|
170
|
+
run_locally(_install(:path => mvn_path_local, :bin => mvn_bin_local,
|
171
|
+
:checksum_file => mvn_checksum_file_local, :checksum_url => mvn_checksum_url,
|
172
|
+
:archive_file => mvn_archive_file_local, :archive_url => mvn_archive_url))
|
173
|
+
run_locally("#{mvn_cmd_local} --version")
|
135
174
|
}
|
136
175
|
|
176
|
+
def template(file)
|
177
|
+
if File.file?(file)
|
178
|
+
File.read(file)
|
179
|
+
elsif File.file?("#{file}.erb")
|
180
|
+
ERB.new(File.read(file)).result(binding)
|
181
|
+
else
|
182
|
+
abort("No such template: #{file} or #{file}.erb")
|
183
|
+
end
|
184
|
+
end
|
185
|
+
|
186
|
+
def _update_settings(files_map, options={})
|
187
|
+
execute = []
|
188
|
+
dirs = files_map.map { |src, dst| File.dirname(dst) }.uniq
|
189
|
+
execute << "mkdir -p #{dirs.join(' ')}" unless dirs.empty?
|
190
|
+
files_map.each do |src, dst|
|
191
|
+
execute << "( diff -u #{dst} #{src} || mv -f #{src} #{dst} )"
|
192
|
+
cleanup = options.fetch(:cleanup, [])
|
193
|
+
execute << "rm -f #{cleanup.join(' ')}" unless cleanup.empty?
|
194
|
+
end
|
195
|
+
execute.join(' && ')
|
196
|
+
end
|
197
|
+
|
137
198
|
task(:update_settings, :roles => :app, :except => { :no_release => true }) {
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
src_file = File.join(mvn_template_path, file)
|
145
|
-
dst_file = File.join(mvn_project_path, file)
|
146
|
-
run(<<-E)
|
147
|
-
( test -d #{File.dirname(dst_file)} || mkdir -p #{File.dirname(dst_file)} ) &&
|
148
|
-
( test -f #{dst_file} && mv -f #{dst_file} #{dst_file}.orig; true );
|
149
|
-
E
|
150
|
-
if File.file?(src_file)
|
151
|
-
put(File.read(src_file), tmp_file)
|
152
|
-
elsif File.file?("#{src_file}.erb")
|
153
|
-
put(ERB.new(File.read("#{src_file}.erb")).result(binding), tmp_file)
|
154
|
-
else
|
155
|
-
abort("mvn:update_settings: no such template found: #{src_file} or #{src_file}.erb")
|
199
|
+
srcs = mvn_settings.map { |f| File.join(mvn_template_path, f) }
|
200
|
+
tmps = mvn_settings.map { |f| t=Tempfile.new('mvn');s=t.path;t.close(true);s }
|
201
|
+
dsts = mvn_settings.map { |f| File.join(mvn_settings_path, f) }
|
202
|
+
begin
|
203
|
+
srcs.zip(tmps).each do |src, tmp|
|
204
|
+
put(template(src), tmp)
|
156
205
|
end
|
157
|
-
run(
|
158
|
-
|
159
|
-
|
206
|
+
run(_update_settings(tmps.zip(dsts), :cleanup => mvn_cleanup_settings)) unless tmps.empty?
|
207
|
+
ensure
|
208
|
+
run("rm -f #{tmps.join(' ')}") unless tmps.empty?
|
209
|
+
end
|
160
210
|
}
|
161
211
|
|
162
212
|
task(:update_settings_locally, :except => { :no_release => true }) {
|
163
|
-
mvn_settings_local.
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
(
|
169
|
-
E
|
170
|
-
if File.file?(src_file)
|
171
|
-
File.open(dst_file, 'w') { |fp|
|
172
|
-
fp.write(File.read(src_file))
|
173
|
-
}
|
174
|
-
elsif File.file?("#{src_file}.erb")
|
175
|
-
File.open(dst_file, 'w') { |fp|
|
176
|
-
fp.write(ERB.new(File.read("#{src_file}.erb")).result(binding))
|
177
|
-
}
|
178
|
-
else
|
179
|
-
abort("mvn:update_settings_locally: no such template: #{src_file} or #{src_file}.erb")
|
213
|
+
srcs = mvn_settings_local.map { |f| File.join(mvn_template_path, f) }
|
214
|
+
tmps = mvn_settings.map { |f| t=Tempfile.new('mvn');s=t.path;t.close(true);s }
|
215
|
+
dsts = mvn_settings_local.map { |f| File.join(mvn_settings_path_local, f) }
|
216
|
+
begin
|
217
|
+
srcs.zip(tmps).each do |src, tmp|
|
218
|
+
File.open(tmp, 'wb') { |fp| fp.write(template(src)) }
|
180
219
|
end
|
181
|
-
|
182
|
-
|
220
|
+
run_locally(_update_settings(tmps.zip(dsts), :cleanup => mvn_cleanup_settings_local)) unless tmps.empty?
|
221
|
+
ensure
|
222
|
+
run_locally("rm -f #{tmps.join(' ')}") unless tmps.empty?
|
223
|
+
end
|
183
224
|
}
|
184
225
|
|
185
226
|
desc("Update maven build.")
|
@@ -212,7 +253,6 @@ module Capistrano
|
|
212
253
|
|
213
254
|
desc("Perform maven build locally.")
|
214
255
|
task(:execute_locally, :roles => :app, :except => { :no_release => true }) {
|
215
|
-
setup_locally
|
216
256
|
on_rollback {
|
217
257
|
run_locally("cd #{mvn_project_path_local} && #{mvn_cmd_local} clean")
|
218
258
|
}
|
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.
|
4
|
+
version: 0.0.4
|
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-
|
12
|
+
date: 2012-10-18 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: capistrano
|