capistrano-java 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/.document +5 -0
- data/.gitignore +21 -0
- data/LICENSE +20 -0
- data/README.rdoc +18 -0
- data/Rakefile +52 -0
- data/lib/capistrano/recipes/deploy/strategy/build_copy.rb +234 -0
- data/lib/capistrano-java.rb +0 -0
- data/test/helper.rb +10 -0
- data/test/test_capistrano-java.rb +7 -0
- metadata +74 -0
data/.document
ADDED
data/.gitignore
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 keebeom kim
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
= capistrano-java
|
2
|
+
|
3
|
+
Description goes here.
|
4
|
+
|
5
|
+
== Note on Patches/Pull Requests
|
6
|
+
|
7
|
+
* Fork the project.
|
8
|
+
* Make your feature addition or bug fix.
|
9
|
+
* Add tests for it. This is important so I don't break it in a
|
10
|
+
future version unintentionally.
|
11
|
+
* Commit, do not mess with rakefile, version, or history.
|
12
|
+
(if you want to have your own version, that is fine but
|
13
|
+
bump version in a commit by itself I can ignore when I pull)
|
14
|
+
* Send me a pull request. Bonus points for topic branches.
|
15
|
+
|
16
|
+
== Copyright
|
17
|
+
|
18
|
+
Copyright (c) 2009 keebeom kim. See LICENSE for details.
|
data/Rakefile
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'jeweler'
|
6
|
+
Jeweler::Tasks.new do |gem|
|
7
|
+
gem.name = "capistrano-java"
|
8
|
+
gem.summary = "support deploy java build file or directory"
|
9
|
+
gem.description = "support deploy java build file or directory"
|
10
|
+
gem.email = "badaboda@gmail.com"
|
11
|
+
gem.homepage = "http://github.com/badaboda/capistrano-java"
|
12
|
+
gem.authors = ["keebeom kim"]
|
13
|
+
gem.add_development_dependency "thoughtbot-shoulda", ">= 0"
|
14
|
+
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
15
|
+
end
|
16
|
+
rescue LoadError
|
17
|
+
puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
|
18
|
+
end
|
19
|
+
|
20
|
+
require 'rake/testtask'
|
21
|
+
Rake::TestTask.new(:test) do |test|
|
22
|
+
test.libs << 'lib' << 'test'
|
23
|
+
test.pattern = 'test/**/test_*.rb'
|
24
|
+
test.verbose = true
|
25
|
+
end
|
26
|
+
|
27
|
+
begin
|
28
|
+
require 'rcov/rcovtask'
|
29
|
+
Rcov::RcovTask.new do |test|
|
30
|
+
test.libs << 'test'
|
31
|
+
test.pattern = 'test/**/test_*.rb'
|
32
|
+
test.verbose = true
|
33
|
+
end
|
34
|
+
rescue LoadError
|
35
|
+
task :rcov do
|
36
|
+
abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
task :test => :check_dependencies
|
41
|
+
|
42
|
+
task :default => :test
|
43
|
+
|
44
|
+
require 'rake/rdoctask'
|
45
|
+
Rake::RDocTask.new do |rdoc|
|
46
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
47
|
+
|
48
|
+
rdoc.rdoc_dir = 'rdoc'
|
49
|
+
rdoc.title = "capistrano-java #{version}"
|
50
|
+
rdoc.rdoc_files.include('README*')
|
51
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
52
|
+
end
|
@@ -0,0 +1,234 @@
|
|
1
|
+
require 'capistrano/recipes/deploy/strategy/base'
|
2
|
+
require 'fileutils'
|
3
|
+
require 'tempfile' # Dir.tmpdir
|
4
|
+
require 'find'
|
5
|
+
|
6
|
+
module Capistrano
|
7
|
+
module Deploy
|
8
|
+
module Strategy
|
9
|
+
|
10
|
+
class BuildCopy < Base
|
11
|
+
def deploy!
|
12
|
+
logger.debug("start build strategy #{copy_cache}")
|
13
|
+
if copy_cache
|
14
|
+
if File.exists?(copy_cache)
|
15
|
+
logger.debug "refreshing local cache to revision #{revision} at #{copy_cache}"
|
16
|
+
system(source.sync(revision, copy_cache))
|
17
|
+
else
|
18
|
+
logger.debug "preparing local cache at #{copy_cache}"
|
19
|
+
system(source.checkout(revision, copy_cache))
|
20
|
+
end
|
21
|
+
|
22
|
+
logger.debug("start build command")
|
23
|
+
system(build_command)
|
24
|
+
|
25
|
+
logger.debug "copying cache to deployment staging area #{destination}"
|
26
|
+
Dir.chdir(copy_cache) do
|
27
|
+
FileUtils.mkdir_p(destination)
|
28
|
+
queue = Dir.glob("*", File::FNM_DOTMATCH)
|
29
|
+
while queue.any?
|
30
|
+
item = queue.shift
|
31
|
+
name = File.basename(item)
|
32
|
+
|
33
|
+
next if name == "." || name == ".."
|
34
|
+
next if copy_exclude.any? { |pattern| File.fnmatch(pattern, item) }
|
35
|
+
|
36
|
+
if File.directory?(item)
|
37
|
+
queue += Dir.glob("#{item}/*", File::FNM_DOTMATCH)
|
38
|
+
FileUtils.mkdir(File.join(destination, item))
|
39
|
+
else
|
40
|
+
FileUtils.ln(File.join(copy_cache, item), File.join(destination, item))
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
else
|
45
|
+
logger.debug "getting (via #{copy_strategy}) revision #{revision} to #{destination}"
|
46
|
+
system(command)
|
47
|
+
logger.debug("start build command")
|
48
|
+
system(build_command)
|
49
|
+
|
50
|
+
if copy_exclude.any?
|
51
|
+
logger.debug "processing exclusions..."
|
52
|
+
copy_exclude.each { |pattern| FileUtils.rm_rf(File.join(destination, pattern)) }
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
Dir.chdir(tmpdir)
|
57
|
+
FileUtils.mv(build_target_path,destination_tmp)
|
58
|
+
FileUtils.rm_rf(destination)
|
59
|
+
FileUtils.mv(destination_tmp, destination)
|
60
|
+
File.open(File.join(destination, "REVISION"), "w") { |f| f.puts(revision) }
|
61
|
+
|
62
|
+
logger.trace "compressing #{destination} to #{filename} at #{tmpdir}"
|
63
|
+
Dir.chdir(tmpdir) { system(compress(File.basename(destination), File.basename(filename)).join(" ")) }
|
64
|
+
|
65
|
+
content = File.open(filename, "rb") { |f| f.read }
|
66
|
+
put content, remote_filename
|
67
|
+
run "cd #{configuration[:releases_path]} && #{decompress(remote_filename).join(" ")} && rm #{remote_filename}"
|
68
|
+
ensure
|
69
|
+
FileUtils.rm filename rescue nil
|
70
|
+
FileUtils.rm_rf destination rescue nil
|
71
|
+
FileUtils.rm_rf destination_tmp rescue nil
|
72
|
+
end
|
73
|
+
|
74
|
+
def check!
|
75
|
+
super.check do |d|
|
76
|
+
d.local.command(source.local.command)
|
77
|
+
d.local.command(compress(nil, nil).first)
|
78
|
+
d.remote.command(decompress(nil).first)
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
# Returns the location of the local copy cache, if the strategy should
|
83
|
+
# use a local cache + copy instead of a new checkout/export every
|
84
|
+
# time. Returns +nil+ unless :copy_cache has been set. If :copy_cache
|
85
|
+
# is +true+, a default cache location will be returned.
|
86
|
+
def copy_cache
|
87
|
+
@copy_cache ||= configuration[:copy_cache] == true ?
|
88
|
+
File.join(Dir.tmpdir, configuration[:application]) :
|
89
|
+
configuration[:copy_cache]
|
90
|
+
end
|
91
|
+
|
92
|
+
private
|
93
|
+
|
94
|
+
def build_command
|
95
|
+
Dir.chdir("#{destination}")
|
96
|
+
configuration[:build_command] || Capistrano::CLI.ui.ask('build command:')
|
97
|
+
end
|
98
|
+
|
99
|
+
#def remove_dir(dir, excludes)
|
100
|
+
# Find.find(dir) do |path|
|
101
|
+
# if dir.eql?path
|
102
|
+
# next
|
103
|
+
# else
|
104
|
+
# if File.directory?path
|
105
|
+
# if excludes.include?path
|
106
|
+
# Find.prune
|
107
|
+
# else
|
108
|
+
# logger.debug(path)
|
109
|
+
# FileUtils.rm_rf(path)
|
110
|
+
# Find.prune
|
111
|
+
# end
|
112
|
+
# else
|
113
|
+
# logger.debug(path)
|
114
|
+
# FileUtils.rm_rf(path)
|
115
|
+
# Find.prune
|
116
|
+
# end
|
117
|
+
# end
|
118
|
+
# end
|
119
|
+
#end
|
120
|
+
|
121
|
+
|
122
|
+
def build_target_path
|
123
|
+
File.join(destination, configuration[:build_target_path])
|
124
|
+
end
|
125
|
+
|
126
|
+
|
127
|
+
# Specify patterns to exclude from the copy. This is only valid
|
128
|
+
# when using a local cache.
|
129
|
+
def copy_exclude
|
130
|
+
@copy_exclude ||= Array(configuration.fetch(:copy_exclude, []))
|
131
|
+
end
|
132
|
+
|
133
|
+
# Returns the basename of the release_path, which will be used to
|
134
|
+
# name the local copy and archive file.
|
135
|
+
def destination
|
136
|
+
#configuration[:release_path]
|
137
|
+
@destination ||= File.join(tmpdir, File.basename(configuration[:release_path]))
|
138
|
+
|
139
|
+
end
|
140
|
+
|
141
|
+
def destination_tmp
|
142
|
+
#configuration[:release_path]
|
143
|
+
@destination_tmp ||= "#{destination}_tmp"
|
144
|
+
|
145
|
+
end
|
146
|
+
|
147
|
+
# Returns the value of the :copy_strategy variable, defaulting to
|
148
|
+
# :checkout if it has not been set.
|
149
|
+
def copy_strategy
|
150
|
+
@copy_strategy ||= configuration.fetch(:copy_strategy, :checkout)
|
151
|
+
end
|
152
|
+
|
153
|
+
# Should return the command(s) necessary to obtain the source code
|
154
|
+
# locally.
|
155
|
+
def command
|
156
|
+
logger.debug("#{copy_strategy}")
|
157
|
+
@command ||= case copy_strategy
|
158
|
+
when :checkout
|
159
|
+
source.checkout(revision, destination)
|
160
|
+
when :export
|
161
|
+
source.export(revision, destination)
|
162
|
+
end
|
163
|
+
end
|
164
|
+
|
165
|
+
# Returns the name of the file that the source code will be
|
166
|
+
# compressed to.
|
167
|
+
def filename
|
168
|
+
@filename ||= File.join(tmpdir, "#{File.basename(destination)}.#{compression_extension}")
|
169
|
+
end
|
170
|
+
|
171
|
+
# The directory to which the copy should be checked out
|
172
|
+
def tmpdir
|
173
|
+
@tmpdir ||= configuration[:copy_dir] || Dir.tmpdir
|
174
|
+
end
|
175
|
+
|
176
|
+
# The directory on the remote server to which the archive should be
|
177
|
+
# copied
|
178
|
+
def remote_dir
|
179
|
+
@remote_dir ||= configuration[:copy_remote_dir] || "/tmp"
|
180
|
+
end
|
181
|
+
|
182
|
+
# The location on the remote server where the file should be
|
183
|
+
# temporarily stored.
|
184
|
+
def remote_filename
|
185
|
+
@remote_filename ||= File.join(remote_dir, File.basename(filename))
|
186
|
+
end
|
187
|
+
|
188
|
+
# The compression method to use, defaults to :gzip.
|
189
|
+
def compression
|
190
|
+
configuration[:copy_compression] || :gzip
|
191
|
+
end
|
192
|
+
|
193
|
+
# Returns the file extension used for the compression method in
|
194
|
+
# question.
|
195
|
+
def compression_extension
|
196
|
+
case compression
|
197
|
+
when :gzip, :gz then "tar.gz"
|
198
|
+
when :bzip2, :bz2 then "tar.bz2"
|
199
|
+
when :zip then "zip"
|
200
|
+
else raise ArgumentError, "invalid compression type #{compression.inspect}"
|
201
|
+
end
|
202
|
+
end
|
203
|
+
|
204
|
+
# Returns the command necessary to compress the given directory
|
205
|
+
# into the given file. The command is returned as an array, where
|
206
|
+
# the first element is the utility to be used to perform the compression.
|
207
|
+
def compress(directory, file)
|
208
|
+
case compression
|
209
|
+
when :gzip, :gz then ["tar", "czf", file, directory]
|
210
|
+
when :bzip2, :bz2 then ["tar", "cjf", file, directory]
|
211
|
+
when :zip then ["zip", "-qr", file, directory]
|
212
|
+
else raise ArgumentError, "invalid compression type #{compression.inspect}"
|
213
|
+
end
|
214
|
+
end
|
215
|
+
|
216
|
+
# Returns the command necessary to decompress the given file,
|
217
|
+
# relative to the current working directory. It must also
|
218
|
+
# preserve the directory structure in the file. The command is returned
|
219
|
+
# as an array, where the first element is the utility to be used to
|
220
|
+
# perform the decompression.
|
221
|
+
def decompress(file)
|
222
|
+
case compression
|
223
|
+
when :gzip, :gz then ["tar", "xzf", file]
|
224
|
+
when :bzip2, :bz2 then ["tar", "xjf", file]
|
225
|
+
when :zip then ["unzip", "-q", file]
|
226
|
+
else raise ArgumentError, "invalid compression type #{compression.inspect}"
|
227
|
+
end
|
228
|
+
end
|
229
|
+
|
230
|
+
end
|
231
|
+
|
232
|
+
end
|
233
|
+
end
|
234
|
+
end
|
File without changes
|
data/test/helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: capistrano-java
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- keebeom kim
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-11-09 00:00:00 +09:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: thoughtbot-shoulda
|
17
|
+
type: :development
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: "0"
|
24
|
+
version:
|
25
|
+
description: "supports java build file or directory "
|
26
|
+
email: badaboda@gmail.com
|
27
|
+
executables: []
|
28
|
+
|
29
|
+
extensions: []
|
30
|
+
|
31
|
+
extra_rdoc_files:
|
32
|
+
- LICENSE
|
33
|
+
- README.rdoc
|
34
|
+
files:
|
35
|
+
- .document
|
36
|
+
- .gitignore
|
37
|
+
- LICENSE
|
38
|
+
- README.rdoc
|
39
|
+
- Rakefile
|
40
|
+
- lib/capistrano-java.rb
|
41
|
+
- lib/capistrano/recipes/deploy/strategy/build_copy.rb
|
42
|
+
- test/helper.rb
|
43
|
+
- test/test_capistrano-java.rb
|
44
|
+
has_rdoc: true
|
45
|
+
homepage: http://github.com/badaboda/capistrano-java
|
46
|
+
licenses: []
|
47
|
+
|
48
|
+
post_install_message:
|
49
|
+
rdoc_options:
|
50
|
+
- --charset=UTF-8
|
51
|
+
require_paths:
|
52
|
+
- lib
|
53
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
54
|
+
requirements:
|
55
|
+
- - ">="
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
version: "0"
|
58
|
+
version:
|
59
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
60
|
+
requirements:
|
61
|
+
- - ">="
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: "0"
|
64
|
+
version:
|
65
|
+
requirements: []
|
66
|
+
|
67
|
+
rubyforge_project:
|
68
|
+
rubygems_version: 1.3.5
|
69
|
+
signing_key:
|
70
|
+
specification_version: 3
|
71
|
+
summary: supports java build file or director
|
72
|
+
test_files:
|
73
|
+
- test/helper.rb
|
74
|
+
- test/test_capistrano-java.rb
|