capistrano-maven 0.0.1
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/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE +22 -0
- data/README.md +63 -0
- data/Rakefile +2 -0
- data/capistrano-maven.gemspec +19 -0
- data/lib/capistrano-maven.rb +8 -0
- data/lib/capistrano-maven/deploy.rb +247 -0
- data/lib/capistrano-maven/templates/settings.xml +2 -0
- data/lib/capistrano-maven/version.rb +5 -0
- metadata +72 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Yamashita Yuu
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
# capistrano-maven
|
2
|
+
|
3
|
+
a capistrano recipe to deploy Apache Maven based projects.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'capistrano-maven'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install capistrano-maven
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
This recipes will try to do following things during Capistrano `deploy:setup` and `deploy` tasks.
|
22
|
+
|
23
|
+
(1) Download and install Maven for current project
|
24
|
+
(2) Prepare Maven's settings.xml for current project (optional)
|
25
|
+
(3) Build Maven project remotely (default) or locally
|
26
|
+
|
27
|
+
To build you Maven projects during Capistrano `deploy` tasks, add following in you `config/deploy.rb`. By default, Maven build will run after the Capistrano's `deploy:finalize_update`.
|
28
|
+
|
29
|
+
# in "config/deploy.rb"
|
30
|
+
require 'capistrano-maven'
|
31
|
+
set(:mvn_version, '3.0.4') # Maven version to build project
|
32
|
+
|
33
|
+
Following options are available to manage your Maven build.
|
34
|
+
|
35
|
+
* `:mvn_version` - project Maven version
|
36
|
+
* `:mvn_archive_url` - download URL for specified Maven version
|
37
|
+
* `:mvn_compile_locally` - compile project on localhost. false by default.
|
38
|
+
* `:mvn_goals` - Maven goals to execute. default is "clean package".
|
39
|
+
* `:mvn_profiles` - Maven profiles to use.
|
40
|
+
* `:mvn_skip_tests` - add `-Dmaven.test.skip=true` in Maven commands. false by default.
|
41
|
+
* `:mvn_update_snapshots` - add `--update-snapshots` if Maven commands. false by default.
|
42
|
+
* `:mvn_update_settings` - update `settings.xml` or not. false by default.
|
43
|
+
* `:mvn_update_settings_locally` - udate `settings.xml` or not on local compilation. false by default.
|
44
|
+
* `:mvn_template_path` - specify ERB template path for settings.xml.
|
45
|
+
* `:mvn_java_home` - optional `JAVA_HOME` settings for Maven commands.
|
46
|
+
* `:mvn_java_home_local` - optional `JAVA_HOME` settings for Maven commands in localhost.
|
47
|
+
|
48
|
+
## Contributing
|
49
|
+
|
50
|
+
1. Fork it
|
51
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
52
|
+
3. Commit your changes (`git commit -am 'Added some feature'`)
|
53
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
54
|
+
5. Create new Pull Request
|
55
|
+
|
56
|
+
## Author
|
57
|
+
|
58
|
+
- YAMASHITA Yuu (https://github.com/yyuu)
|
59
|
+
- Geisha Tokyo Entertainment Inc. (http://www.geishatokyo.com/)
|
60
|
+
|
61
|
+
## License
|
62
|
+
|
63
|
+
MIT
|
data/Rakefile
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/capistrano-maven/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ["Yamashita Yuu"]
|
6
|
+
gem.email = ["yamashita@geishatokyo.com"]
|
7
|
+
gem.description = %q{a capistrano recipe to deploy Apache Maven based projects.}
|
8
|
+
gem.summary = %q{a capistrano recipe to deploy Apache Maven based projects.}
|
9
|
+
gem.homepage = "https://github.com/yyuu/capistrano-maven"
|
10
|
+
|
11
|
+
gem.files = `git ls-files`.split($\)
|
12
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
13
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
14
|
+
gem.name = "capistrano-maven"
|
15
|
+
gem.require_paths = ["lib"]
|
16
|
+
gem.version = Capistrano::Maven::VERSION
|
17
|
+
|
18
|
+
gem.add_dependency("capistrano")
|
19
|
+
end
|
@@ -0,0 +1,247 @@
|
|
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_archive_url) {
|
12
|
+
[
|
13
|
+
"http://www.apache.org/dist//maven/binaries/apache-maven-#{mvn_version}-bin.tar.gz",
|
14
|
+
"http://ftp.kddilabs.jp/infosystems/apache//maven/binaries/apache-maven-#{mvn_version}-bin.tar.gz",
|
15
|
+
"http://ftp.riken.jp/net/apache//maven/binaries/apache-maven-#{mvn_version}-bin.tar.gz",
|
16
|
+
"http://ftp.jaist.ac.jp/pub/apache//maven/binaries/apache-maven-#{mvn_version}-bin.tar.gz",
|
17
|
+
"http://ftp.meisei-u.ac.jp/mirror/apache/dist//maven/binaries/apache-maven-#{mvn_version}-bin.tar.gz",
|
18
|
+
].shuffle().first()
|
19
|
+
}
|
20
|
+
_cset(:mvn_archive_file) {
|
21
|
+
File.join(shared_path, 'tools', 'mvn', File.basename(URI.parse(mvn_archive_url).path))
|
22
|
+
}
|
23
|
+
_cset(:mvn_archive_file_local) {
|
24
|
+
File.join(File.expand_path('.'), 'tools', 'mvn', File.basename(URI.parse(mvn_archive_url).path))
|
25
|
+
}
|
26
|
+
_cset(:mvn_path) {
|
27
|
+
File.join(shared_path, 'tools', 'mvn', File.basename(URI.parse(mvn_archive_url).path, "-bin.tar.gz"))
|
28
|
+
}
|
29
|
+
_cset(:mvn_path_local) {
|
30
|
+
File.join(File.expand_path('.'), 'tools', 'mvn', File.basename(URI.parse(mvn_archive_url).path, "-bin.tar.gz"))
|
31
|
+
}
|
32
|
+
_cset(:mvn_bin) {
|
33
|
+
File.join(mvn_path, 'bin', 'mvn')
|
34
|
+
}
|
35
|
+
_cset(:mvn_bin_local) {
|
36
|
+
File.join(mvn_path_local, 'bin', 'mvn')
|
37
|
+
}
|
38
|
+
_cset(:mvn_cmd) {
|
39
|
+
settings = "--settings=#{mvn_settings_path}/settings.xml" if mvn_update_settings
|
40
|
+
if fetch(:mvn_java_home, nil)
|
41
|
+
"env JAVA_HOME=#{mvn_java_home} #{mvn_bin} #{mvn_options.join(' ')} #{settings}"
|
42
|
+
else
|
43
|
+
"#{mvn_bin} #{mvn_options.join(' ')} #{settings}"
|
44
|
+
end
|
45
|
+
}
|
46
|
+
_cset(:mvn_cmd_local) {
|
47
|
+
settings = "--settings=#{mvn_settings_path_local}/settings.xml" if mvn_update_settings_locally
|
48
|
+
if fetch(:mvn_java_home_local, nil)
|
49
|
+
"env JAVA_HOME=#{mvn_java_home_local} #{mvn_bin_local} #{mvn_options_local.join(' ')} #{settings}"
|
50
|
+
else
|
51
|
+
"#{mvn_bin_local} #{mvn_options_local.join(' ')} #{settings}"
|
52
|
+
end
|
53
|
+
}
|
54
|
+
_cset(:mvn_project_path) {
|
55
|
+
release_path
|
56
|
+
}
|
57
|
+
_cset(:mvn_project_path_local) {
|
58
|
+
Dir.pwd
|
59
|
+
}
|
60
|
+
_cset(:mvn_target_path) {
|
61
|
+
File.join(mvn_project_path, 'target')
|
62
|
+
}
|
63
|
+
_cset(:mvn_target_path_local) {
|
64
|
+
File.join(mvn_project_path_local, File.basename(mvn_target_path))
|
65
|
+
}
|
66
|
+
_cset(:mvn_template_path, File.join(File.dirname(__FILE__), 'templates'))
|
67
|
+
_cset(:mvn_update_settings, false)
|
68
|
+
_cset(:mvn_update_settings_locally, false)
|
69
|
+
_cset(:mvn_settings_path) {
|
70
|
+
mvn_project_path
|
71
|
+
}
|
72
|
+
_cset(:mvn_settings_path_local) {
|
73
|
+
mvn_project_path_local
|
74
|
+
}
|
75
|
+
_cset(:mvn_settings, %w(settings.xml))
|
76
|
+
_cset(:mvn_settings_local, %w(settings.xml))
|
77
|
+
_cset(:mvn_cleanup_settings, [])
|
78
|
+
_cset(:mvn_cleanup_settings_local, [])
|
79
|
+
_cset(:mvn_compile_locally, false) # perform precompilation on localhost
|
80
|
+
_cset(:mvn_goals, %w(clean package))
|
81
|
+
_cset(:mvn_common_options) {
|
82
|
+
options = []
|
83
|
+
options << "-P#{mvn_profiles.join(',')}" unless fetch(:mvn_profiles, []).empty?
|
84
|
+
options << "-Dmaven.test.skip=true" if fetch(:mvn_skip_tests, false)
|
85
|
+
options << "-U" if fetch(:mvn_update_snapshots, false)
|
86
|
+
options << "-B"
|
87
|
+
options
|
88
|
+
}
|
89
|
+
_cset(:mvn_options) {
|
90
|
+
mvn_common_options + fetch(:mvn_extra_options, [])
|
91
|
+
}
|
92
|
+
_cset(:mvn_options_local) {
|
93
|
+
mvn_common_options + fetch(:mvn_extra_options_local, [])
|
94
|
+
}
|
95
|
+
|
96
|
+
desc("Setup maven.")
|
97
|
+
task(:setup, :roles => :app, :except => { :no_release => true }) {
|
98
|
+
transaction {
|
99
|
+
install
|
100
|
+
update_settings if mvn_update_settings
|
101
|
+
setup_locally if mvn_compile_locally
|
102
|
+
}
|
103
|
+
}
|
104
|
+
after 'deploy:setup', 'mvn:setup'
|
105
|
+
|
106
|
+
desc("Setup maven locally.")
|
107
|
+
task(:setup_locally, :except => { :no_release => true }) {
|
108
|
+
transaction {
|
109
|
+
install_locally
|
110
|
+
update_settings_locally if mvn_update_settings_locally
|
111
|
+
}
|
112
|
+
}
|
113
|
+
|
114
|
+
task(:install, :roles => :app, :except => { :no_release => true }) {
|
115
|
+
dirs = [ File.dirname(mvn_archive_file), File.dirname(mvn_path) ].uniq()
|
116
|
+
run(<<-E)
|
117
|
+
if ! test -x #{mvn_bin}; then
|
118
|
+
mkdir -p #{dirs.join(' ')} &&
|
119
|
+
( test -f #{mvn_archive_file} || wget --no-verbose -O #{mvn_archive_file} #{mvn_archive_url} ) &&
|
120
|
+
( test -d #{mvn_path} || tar xf #{mvn_archive_file} -C #{File.dirname(mvn_path)} ) &&
|
121
|
+
test -x #{mvn_bin};
|
122
|
+
fi &&
|
123
|
+
#{mvn_cmd} --version;
|
124
|
+
E
|
125
|
+
}
|
126
|
+
|
127
|
+
task(:install_locally, :except => { :no_release => true }) { # TODO: make install and install_locally together
|
128
|
+
dirs = [ File.dirname(mvn_archive_file_local), File.dirname(mvn_path_local) ].uniq()
|
129
|
+
run_locally(<<-E)
|
130
|
+
if ! test -x #{mvn_bin_local}; then
|
131
|
+
mkdir -p #{dirs.join(' ')} &&
|
132
|
+
( test -f #{mvn_archive_file_local} || wget --no-verbose -O #{mvn_archive_file_local} #{mvn_archive_url} ) &&
|
133
|
+
( test -d #{mvn_path_local} || tar xf #{mvn_archive_file_local} -C #{File.dirname(mvn_path_local)} ) &&
|
134
|
+
test -x #{mvn_bin_local};
|
135
|
+
fi &&
|
136
|
+
#{mvn_cmd_local} --version;
|
137
|
+
E
|
138
|
+
}
|
139
|
+
|
140
|
+
task(:update_settings, :roles => :app, :except => { :no_release => true }) {
|
141
|
+
tmp_files = []
|
142
|
+
on_rollback {
|
143
|
+
run("rm -f #{tmp_files.join(' ')}") unless tmp_files.empty?
|
144
|
+
}
|
145
|
+
mvn_settings.each { |file|
|
146
|
+
tmp_files << tmp_file = File.join('/tmp', File.basename(file))
|
147
|
+
src_file = File.join(mvn_template_path, file)
|
148
|
+
dst_file = File.join(mvn_project_path, file)
|
149
|
+
run(<<-E)
|
150
|
+
( test -d #{File.dirname(dst_file)} || mkdir -p #{File.dirname(dst_file)} ) &&
|
151
|
+
( test -f #{dst_file} && mv -f #{dst_file} #{dst_file}.orig; true );
|
152
|
+
E
|
153
|
+
if File.file?(src_file)
|
154
|
+
put(File.read(src_file), tmp_file)
|
155
|
+
elsif File.file?("#{src_file}.erb")
|
156
|
+
put(ERB.new(File.read("#{src_file}.erb")).result(binding), tmp_file)
|
157
|
+
else
|
158
|
+
abort("mvn:update_settings: no such template found: #{src_file} or #{src_file}.erb")
|
159
|
+
end
|
160
|
+
run("diff #{dst_file} #{tmp_file} || mv -f #{tmp_file} #{dst_file}")
|
161
|
+
}
|
162
|
+
run("rm -f #{mvn_cleanup_settings.join(' ')}") unless mvn_cleanup_settings.empty?
|
163
|
+
}
|
164
|
+
|
165
|
+
task(:update_settings_locally, :except => { :no_release => true }) {
|
166
|
+
mvn_settings_local.each { |file|
|
167
|
+
src_file = File.join(mvn_template_path, file)
|
168
|
+
dst_file = File.join(mvn_project_path_local, file)
|
169
|
+
run_locally(<<-E)
|
170
|
+
( test -d #{File.dirname(dst_file)} || mkdir -p #{File.dirname(dst_file)} ) &&
|
171
|
+
( test -f #{dst_file} && mv -f #{dst_file} #{dst_file}.orig; true );
|
172
|
+
E
|
173
|
+
if File.file?(src_file)
|
174
|
+
File.open(dst_file, 'w') { |fp|
|
175
|
+
fp.write(File.read(src_file))
|
176
|
+
}
|
177
|
+
elsif File.file?("#{src_file}.erb")
|
178
|
+
File.open(dst_file, 'w') { |fp|
|
179
|
+
fp.write(ERB.new(File.read("#{src_file}.erb")).result(binding))
|
180
|
+
}
|
181
|
+
else
|
182
|
+
abort("mvn:update_settings_locally: no such template: #{src_file} or #{src_file}.erb")
|
183
|
+
end
|
184
|
+
}
|
185
|
+
run_locally("rm -f #{mvn_cleanup_settings_local.join(' ')}") unless mvn_cleanup_settings_local.empty?
|
186
|
+
}
|
187
|
+
|
188
|
+
desc("Update maven build.")
|
189
|
+
task(:update, :roles => :app, :except => { :no_release => true }) {
|
190
|
+
transaction {
|
191
|
+
if mvn_compile_locally
|
192
|
+
update_locally
|
193
|
+
else
|
194
|
+
execute
|
195
|
+
end
|
196
|
+
}
|
197
|
+
}
|
198
|
+
after 'deploy:finalize_update', 'mvn:update'
|
199
|
+
|
200
|
+
desc("Update maven build locally.")
|
201
|
+
task(:update_locally, :except => { :no_release => true }) {
|
202
|
+
transaction {
|
203
|
+
execute_locally
|
204
|
+
upload_locally
|
205
|
+
}
|
206
|
+
}
|
207
|
+
|
208
|
+
desc("Perform maven build.")
|
209
|
+
task(:execute, :roles => :app, :except => { :no_release => true }) {
|
210
|
+
on_rollback {
|
211
|
+
run("cd #{mvn_project_path} && #{mvn_cmd} clean")
|
212
|
+
}
|
213
|
+
run("cd #{mvn_project_path} && #{mvn_cmd} #{mvn_goals.join(' ')}")
|
214
|
+
}
|
215
|
+
|
216
|
+
desc("Perform maven build locally.")
|
217
|
+
task(:execute_locally, :roles => :app, :except => { :no_release => true }) {
|
218
|
+
setup_locally
|
219
|
+
on_rollback {
|
220
|
+
run_locally("cd #{mvn_project_path_local} && #{mvn_cmd_local} clean")
|
221
|
+
}
|
222
|
+
cmd = "cd #{mvn_project_path_local} && #{mvn_cmd_local} #{mvn_goals.join(' ')}"
|
223
|
+
logger.info(cmd)
|
224
|
+
abort("execution failure") unless system(cmd)
|
225
|
+
}
|
226
|
+
|
227
|
+
task(:upload_locally, :roles => :app, :except => { :no_release => true }) {
|
228
|
+
on_rollback {
|
229
|
+
run("rm -rf #{mvn_target_path}")
|
230
|
+
}
|
231
|
+
run_locally("test -d #{mvn_target_path_local}")
|
232
|
+
run("mkdir -p #{mvn_target_path}")
|
233
|
+
find_servers_for_task(current_task).each { |server|
|
234
|
+
run_locally("rsync -lrt --chmod=u+rwX,go+rX #{mvn_target_path_local}/ #{user}@#{server.host}:#{mvn_target_path}/")
|
235
|
+
}
|
236
|
+
}
|
237
|
+
}
|
238
|
+
}
|
239
|
+
end
|
240
|
+
end
|
241
|
+
end
|
242
|
+
|
243
|
+
if Capistrano::Configuration.instance
|
244
|
+
Capistrano::Configuration.instance.extend(Capistrano::Maven)
|
245
|
+
end
|
246
|
+
|
247
|
+
# vim:set ft=ruby :
|
metadata
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: capistrano-maven
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Yamashita Yuu
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-08-10 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: capistrano
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
description: a capistrano recipe to deploy Apache Maven based projects.
|
31
|
+
email:
|
32
|
+
- yamashita@geishatokyo.com
|
33
|
+
executables: []
|
34
|
+
extensions: []
|
35
|
+
extra_rdoc_files: []
|
36
|
+
files:
|
37
|
+
- .gitignore
|
38
|
+
- Gemfile
|
39
|
+
- LICENSE
|
40
|
+
- README.md
|
41
|
+
- Rakefile
|
42
|
+
- capistrano-maven.gemspec
|
43
|
+
- lib/capistrano-maven.rb
|
44
|
+
- lib/capistrano-maven/deploy.rb
|
45
|
+
- lib/capistrano-maven/templates/settings.xml
|
46
|
+
- lib/capistrano-maven/version.rb
|
47
|
+
homepage: https://github.com/yyuu/capistrano-maven
|
48
|
+
licenses: []
|
49
|
+
post_install_message:
|
50
|
+
rdoc_options: []
|
51
|
+
require_paths:
|
52
|
+
- lib
|
53
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
54
|
+
none: false
|
55
|
+
requirements:
|
56
|
+
- - ! '>='
|
57
|
+
- !ruby/object:Gem::Version
|
58
|
+
version: '0'
|
59
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
60
|
+
none: false
|
61
|
+
requirements:
|
62
|
+
- - ! '>='
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
version: '0'
|
65
|
+
requirements: []
|
66
|
+
rubyforge_project:
|
67
|
+
rubygems_version: 1.8.23
|
68
|
+
signing_key:
|
69
|
+
specification_version: 3
|
70
|
+
summary: a capistrano recipe to deploy Apache Maven based projects.
|
71
|
+
test_files: []
|
72
|
+
has_rdoc:
|