capistrano-jdk-installer 0.0.6 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +0 -5
- data/capistrano-jdk-installer.gemspec +4 -1
- data/lib/capistrano-jdk-installer.rb +145 -347
- data/lib/capistrano-jdk-installer/jdk-installer.rb +471 -0
- data/lib/capistrano-jdk-installer/version.rb +1 -1
- data/test/centos6-64/.gitignore +5 -0
- data/test/centos6-64/Capfile +2 -0
- data/test/centos6-64/Gemfile +2 -0
- data/test/centos6-64/Vagrantfile +99 -0
- data/test/centos6-64/run.sh +7 -0
- data/test/config/deploy.rb +309 -0
- data/test/precise64/.gitignore +5 -0
- data/test/precise64/Capfile +2 -0
- data/test/precise64/Gemfile +2 -0
- data/test/precise64/Vagrantfile +99 -0
- data/test/precise64/run.sh +7 -0
- metadata +76 -5
data/README.md
CHANGED
@@ -51,11 +51,6 @@ Following options are available to manage your JDK installation.
|
|
51
51
|
* `:java_home_local` - the path to the `JAVA_HOME` on local machine.
|
52
52
|
* `:java_cmd` - the `java` command on remote machines.
|
53
53
|
* `:java_cmd_local` - the `java` command on local machine.
|
54
|
-
* `:java_checksum_cmd` - use specified command to compare JDK archives. use `md5sum` by default.
|
55
|
-
* `:java_version` - specify a string to identify JDK version. by default, it will be generated from `:java_version_name`.
|
56
|
-
* `:java_release` - specify a string to identify JDK release. by default, it will be generated from `:java_version_name`.
|
57
|
-
* `:java_deployer_file` - specify a string to identify JDK archive. by default, it will be generated from `:java_version_name`.
|
58
|
-
* `:java_deployee_file` - specify a string to identify JDK archive. by default, it will be generated from `:java_version_name`.
|
59
54
|
|
60
55
|
## Contributing
|
61
56
|
|
@@ -18,7 +18,10 @@ Gem::Specification.new do |gem|
|
|
18
18
|
gem.require_paths = ["lib"]
|
19
19
|
|
20
20
|
gem.add_dependency("capistrano")
|
21
|
-
gem.add_dependency("capistrano-file-transfer-ext", "~> 0.0
|
21
|
+
gem.add_dependency("capistrano-file-transfer-ext", "~> 0.1.0")
|
22
22
|
gem.add_dependency("json")
|
23
23
|
gem.add_dependency("mechanize", "~> 2.5.0")
|
24
|
+
gem.add_development_dependency("net-scp", "~> 1.0.4")
|
25
|
+
gem.add_development_dependency("net-ssh", "~> 2.2.2")
|
26
|
+
gem.add_development_dependency("vagrant", "~> 1.0.6")
|
24
27
|
end
|
@@ -1,329 +1,118 @@
|
|
1
|
+
require "capistrano-jdk-installer/jdk-installer"
|
1
2
|
require "capistrano-jdk-installer/version"
|
2
3
|
require "capistrano/configuration/actions/file_transfer_ext"
|
3
|
-
require "json"
|
4
|
-
require "logger"
|
5
|
-
require "mechanize"
|
6
|
-
require "uri"
|
7
4
|
|
8
5
|
module Capistrano
|
9
6
|
module JDKInstaller
|
10
|
-
def download_archive(uri, archive)
|
11
|
-
if FileTest.exist?(archive)
|
12
|
-
logger.info("Found downloaded archive: #{archive}")
|
13
|
-
else
|
14
|
-
if java_release_license_title != java_license_title or !java_accept_license
|
15
|
-
abort("You must accept JDK license before downloading.")
|
16
|
-
end
|
17
|
-
|
18
|
-
logger.info("Download archive from #{uri}.")
|
19
|
-
unless dry_run
|
20
|
-
run_locally("mkdir -p #{File.dirname(archive)}")
|
21
|
-
page = java_mechanize_agent.get(uri)
|
22
|
-
1.upto(16) { # to avoid infinity loop...
|
23
|
-
if page.uri.host == "login.oracle.com" # login.oracle.com doesn't return proper Content-Type
|
24
|
-
page = Mechanize::Page.new(page.uri, page.response, page.body, page.code, java_mechanize_agent) if page.is_a?(Mechanize::File)
|
25
|
-
form = page.form_with
|
26
|
-
form["ssousername"] = java_oracle_username
|
27
|
-
form["password"] = java_oracle_password
|
28
|
-
page = java_mechanize_agent.submit(form)
|
29
|
-
else
|
30
|
-
page.save(archive)
|
31
|
-
logger.info("Wrote #{page.body.size} bytes to #{archive}.")
|
32
|
-
break
|
33
|
-
end
|
34
|
-
}
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
def extract_archive(archive, destination)
|
40
|
-
case archive
|
41
|
-
when /\.(bin|sh)$/
|
42
|
-
"( cd #{File.dirname(destination)} && yes | sh #{archive} )"
|
43
|
-
when /\.dmg$/
|
44
|
-
if java_update_number
|
45
|
-
pkg = File.join("/Volumes",
|
46
|
-
"JDK %d Update %02d" % [java_major_version, java_update_number],
|
47
|
-
"JDK %d Update %02d.pkg" % [java_major_version, java_update_number])
|
48
|
-
else
|
49
|
-
pkg = File.join("/Volumes",
|
50
|
-
"JDK %d" % [java_major_version],
|
51
|
-
"JDK %d" % [java_major_version])
|
52
|
-
end
|
53
|
-
execute = []
|
54
|
-
execute << "open #{archive.dump}"
|
55
|
-
execute << "( while ! test -f #{pkg.dump}; do sleep 1; done )"
|
56
|
-
execute << "open #{pkg.dump}"
|
57
|
-
execute << "( while ! test -d #{destination.dump}; do sleep 1; done )"
|
58
|
-
execute.join(' && ')
|
59
|
-
when /\.(tar\.(gz|bz2)|tgz|tbz2)$/
|
60
|
-
"tar xf #{archive} -C #{File.dirname(destination)}"
|
61
|
-
when /\.zip$/
|
62
|
-
"( cd #{File.dirname(destination)} && unzip #{archive} )"
|
63
|
-
else
|
64
|
-
abort("Unknown archive type: #{archive}")
|
65
|
-
end
|
66
|
-
end
|
67
|
-
|
68
7
|
def self.extended(configuration)
|
69
8
|
configuration.load {
|
70
9
|
namespace(:java) {
|
71
|
-
## JDK
|
72
|
-
_cset(:
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
}
|
78
|
-
_cset(:
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
"Contents", "Home")
|
85
|
-
else
|
86
|
-
File.join("/Library", "Java", "JavaVirtualMachines",
|
87
|
-
"jdk%s.jdk" % [java_inner_version],
|
88
|
-
"Contents", "Home")
|
89
|
-
end
|
90
|
-
else
|
91
|
-
if java_update_number
|
92
|
-
File.join(java_tools_path, "jdk%s_%02d" % [java_inner_version, java_update_number])
|
93
|
-
else
|
94
|
-
File.join(java_tools_path, "jdk%s" % [java_inner_version])
|
95
|
-
end
|
96
|
-
end
|
97
|
-
}
|
98
|
-
_cset(:java_home_local) {
|
99
|
-
case java_deployer_file
|
100
|
-
when /macosx/i
|
101
|
-
if java_update_number
|
102
|
-
File.join("/Library", "Java", "JavaVirtualMachines",
|
103
|
-
"jdk%s_%02d.jdk" % [java_inner_version, java_update_number],
|
104
|
-
"Contents", "Home")
|
105
|
-
else
|
106
|
-
File.join("/Library", "Java", "JavaVirtualMachines",
|
107
|
-
"jdk%s.jdk" % [java_inner_version],
|
108
|
-
"Contents", "Home")
|
109
|
-
end
|
110
|
-
else
|
111
|
-
if java_update_number
|
112
|
-
File.join(java_tools_path_local, "jdk%s_%02d" % [java_inner_version, java_update_number])
|
113
|
-
else
|
114
|
-
File.join(java_tools_path_local, "jdk%s" % [java_inner_version])
|
115
|
-
end
|
116
|
-
end
|
117
|
-
}
|
118
|
-
_cset(:java_bin) { File.join(java_home, 'bin', 'java') }
|
119
|
-
_cset(:java_bin_local) { File.join(java_home_local, 'bin', 'java') }
|
120
|
-
_cset(:java_cmd) { "env JAVA_HOME=#{java_home} #{java_bin}" }
|
121
|
-
_cset(:java_cmd_local) { "env JAVA_HOME=#{java_home_local} #{java_bin_local}" }
|
10
|
+
## JDK installer
|
11
|
+
_cset(:java_installer) { JDKInstaller.new(java_installer_options) }
|
12
|
+
_cset(:java_installer_options) {{
|
13
|
+
:logger => logger, :keep_stale => java_installer_json_keep_stale,
|
14
|
+
:file => java_installer_json_cache, :ttl => java_installer_json_expires, :uri => java_installer_json_uri,
|
15
|
+
:username => java_oracle_username, :password => java_oracle_password,
|
16
|
+
}}
|
17
|
+
_cset(:java_installer_json_uri, "http://updates.jenkins-ci.org/updates/hudson.tools.JDKInstaller.json")
|
18
|
+
_cset(:java_installer_json_cache) { File.join(java_archive_path_local, "hudson.tools.JDKInstaller.json") }
|
19
|
+
_cset(:java_installer_json_expires, 259200) # 3 days
|
20
|
+
_cset(:java_installer_json_keep_stale, true) # keep staled cache even if get fails
|
21
|
+
_cset(:java_installer_tool) { java_installer[java_version_regex] }
|
22
|
+
_cset(:java_installer_tool_local) { java_installer[java_version_regex_local] }
|
122
23
|
|
123
24
|
## JDK version settings
|
124
|
-
_cset(:java_version_name) {
|
125
|
-
|
126
|
-
}
|
127
|
-
_cset(:
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
25
|
+
_cset(:java_version_name) { abort("You must specify JDK version explicitly.") }
|
26
|
+
_cset(:java_platform) { JDKInstaller.platform_string(java_version_name, capture("uname -s"), capture("uname -m")) }
|
27
|
+
_cset(:java_platform_local) { JDKInstaller.platform_string(java_version_name, run_locally("uname -s"), run_locally("uname -m")) }
|
28
|
+
_cset(:java_version_regex) {
|
29
|
+
Regexp.new(Regexp.escape("#{java_version_name}-#{java_platform}"), Regexp::IGNORECASE)
|
30
|
+
}
|
31
|
+
_cset(:java_version_regex_local) {
|
32
|
+
Regexp.new(Regexp.escape("#{java_version_name}-#{java_platform_local}"), Regexp::IGNORECASE)
|
33
|
+
}
|
34
|
+
|
35
|
+
## JDK paths
|
36
|
+
_cset(:java_tools_path) { File.join(shared_path, "tools", "java") }
|
37
|
+
_cset(:java_tools_path_local) { File.expand_path("tools/java") }
|
38
|
+
_cset(:java_archive_path) { java_tools_path }
|
39
|
+
_cset(:java_archive_path_local) { java_tools_path_local }
|
40
|
+
_cset(:java_home) { java_installer_tool.install_path(:path => java_tools_path) }
|
41
|
+
_cset(:java_home_local) { java_installer_tool_local.install_path(:path => java_tools_path_local) }
|
42
|
+
_cset(:java_bin_path) { File.join(java_home, "bin") }
|
43
|
+
_cset(:java_bin_path_local) { File.join(java_home_local, "bin") }
|
44
|
+
_cset(:java_bin) { File.join(java_bin_path, "java") }
|
45
|
+
_cset(:java_bin_local) { File.join(java_bin_path_local, "java") }
|
46
|
+
_cset(:java_archive_file) { File.join(java_archive_path, java_installer_tool.basename) }
|
47
|
+
_cset(:java_archive_file_local) { File.join(java_archive_path_local, java_installer_tool_local.basename) }
|
48
|
+
|
49
|
+
## JDK environment
|
50
|
+
_cset(:java_setup_remotely, true)
|
51
|
+
_cset(:java_setup_locally, false)
|
52
|
+
_cset(:java_common_environment, {})
|
53
|
+
_cset(:java_default_environment) {
|
54
|
+
environment = {}
|
55
|
+
if java_setup_remotely
|
56
|
+
environment["JAVA_HOME"] = java_home
|
57
|
+
environment["PATH"] = [ java_bin_path, "$PATH" ].join(":")
|
134
58
|
end
|
59
|
+
_merge_environment(java_common_environment, environment)
|
135
60
|
}
|
136
|
-
_cset(:
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
"JDK #{java_major_version}"
|
142
|
-
}
|
143
|
-
_cset(:java_release) {
|
144
|
-
case java_major_version
|
145
|
-
when '1.4', '5'
|
146
|
-
jdk = java_major_version == '1.4' ? 'j2sdk' : 'jdk'
|
147
|
-
if java_update_number
|
148
|
-
'%s-%s_%02d-oth-JPR' % [jdk, java_inner_version, java_update_number]
|
149
|
-
else
|
150
|
-
'%s-%s-oth-JPR' % [jdk, java_inner_version]
|
151
|
-
end
|
152
|
-
else
|
153
|
-
if java_update_number
|
154
|
-
'jdk-%du%d-oth-JPR' % [java_major_version, java_update_number]
|
155
|
-
else
|
156
|
-
'jdk-%d-oth-JPR' % [java_major_version]
|
157
|
-
end
|
61
|
+
_cset(:java_default_environment_local) {
|
62
|
+
environment = {}
|
63
|
+
if java_setup_locally
|
64
|
+
environment["JAVA_HOME"] = java_home_local
|
65
|
+
environment["PATH"] = [ java_bin_path_local, "$PATH" ].join(":")
|
158
66
|
end
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
case arch
|
171
|
-
when /^i[3-7]86$/i
|
172
|
-
"linux-i586"
|
173
|
-
when /^x86_64$/i
|
174
|
-
case java_major_version
|
175
|
-
when '1.4', '5'
|
176
|
-
"linux-amd64"
|
177
|
-
else
|
178
|
-
"linux-x64"
|
179
|
-
end
|
180
|
-
else
|
181
|
-
"linux-#{arch.downcase}"
|
182
|
-
end
|
183
|
-
when /^Solaris$/i
|
184
|
-
case arch
|
185
|
-
when /^sparc$/i
|
186
|
-
"solaris-sparc"
|
187
|
-
when /^sparcv9$/i
|
188
|
-
"solaris-sparcv9"
|
189
|
-
when /^i[3-7]86$/i
|
190
|
-
"solaris-i586"
|
191
|
-
when /^x86_64$/i
|
192
|
-
"solaris-x64"
|
193
|
-
else
|
194
|
-
"solaris-#{arch.downcase}"
|
195
|
-
end
|
67
|
+
_merge_environment(java_common_environment, environment)
|
68
|
+
}
|
69
|
+
_cset(:java_environment) { _merge_environment(java_default_environment, fetch(:java_extra_environment, {})) }
|
70
|
+
_cset(:java_environment_local) { _merge_environment(java_default_environment_local, fetch(:java_extra_environment_local, {})) }
|
71
|
+
def _command(cmdline, options={})
|
72
|
+
environment = options.fetch(:env, {})
|
73
|
+
if environment.empty?
|
74
|
+
cmdline
|
75
|
+
else
|
76
|
+
env = (["env"] + environment.map { |k, v| "#{k}=#{v.dump}" }).join(" ")
|
77
|
+
"#{env} #{cmdline}"
|
196
78
|
end
|
197
79
|
end
|
198
|
-
def
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
80
|
+
def command(cmdline, options={})
|
81
|
+
_command(cmdline, :env => java_environment.merge(options.fetch(:env, {})))
|
82
|
+
end
|
83
|
+
def command_local(cmdline, options={})
|
84
|
+
_command(cmdline, :env => java_environment_local.merge(options.fetch(:env, {})))
|
85
|
+
end
|
86
|
+
_cset(:java_cmd) { command(java_bin) }
|
87
|
+
_cset(:java_cmd_local) { command_local(java_bin_local) }
|
88
|
+
|
89
|
+
if top.namespaces.key?(:multistage)
|
90
|
+
after "multistage:ensure", "java:setup_default_environment"
|
91
|
+
else
|
92
|
+
on :start do
|
93
|
+
if top.namespaces.key?(:multistage)
|
94
|
+
after "multistage:ensure", "java:setup_default_environment"
|
210
95
|
else
|
211
|
-
|
96
|
+
setup_default_environment
|
212
97
|
end
|
213
98
|
end
|
214
99
|
end
|
215
|
-
## hudson.tools.JDKInstaller.json
|
216
|
-
_cset(:java_mechanize_agent) {
|
217
|
-
Mechanize.log = ::Logger.new(STDERR)
|
218
|
-
Mechanize.log.level = ::Logger::INFO
|
219
|
-
agent = Mechanize.new { |agent|
|
220
|
-
agent.user_agent = 'Mozilla/5.0 (Windows; U; MSIE 9.0; Windows NT 9.0; en-US)'
|
221
|
-
agent.cookie_jar.add!(Mechanize::Cookie.new('gpw_e24', '.', :domain => 'oracle.com', :path => '/', :secure => false, :for_domain => true))
|
222
|
-
}
|
223
|
-
agent.ssl_version = :TLSv1 # we have to declare TLS version explicitly to avoid problems on LP:965371
|
224
|
-
agent
|
225
|
-
}
|
226
|
-
_cset(:java_installer_json_uri) {
|
227
|
-
# fetch :java_installer_uri first for backward compatibility
|
228
|
-
fetch(:java_installer_uri, "http://updates.jenkins-ci.org/updates/hudson.tools.JDKInstaller.json")
|
229
|
-
}
|
230
|
-
_cset(:java_installer_json_cache) {
|
231
|
-
File.join(java_tools_path_local, File.basename(URI.parse(java_installer_json_uri).path))
|
232
|
-
}
|
233
|
-
_cset(:java_installer_json_expires, 259200) # 3 days
|
234
|
-
_cset(:java_installer_json_keep_stale, true) # keep staled cache even if wget fails
|
235
|
-
_cset(:java_installer_json) {
|
236
|
-
# should not update cache directly from wget.
|
237
|
-
# wget will save response to the file even if the request fails.
|
238
|
-
tempfile = `mktemp /tmp/capistrano-jdk-installer.XXXXXXXXXX`.chomp
|
239
|
-
begin
|
240
|
-
if not File.file?(java_installer_json_cache) or File.mtime(java_installer_json_cache)+java_installer_json_expires < Time.now
|
241
|
-
execute = []
|
242
|
-
execute << "mkdir -p #{File.dirname(java_installer_json_cache)}"
|
243
|
-
success_cmd = "mv -f #{tempfile} #{java_installer_json_cache}"
|
244
|
-
failure_cmd = java_installer_json_keep_stale ? 'true' : 'false'
|
245
|
-
execute << "( wget --no-verbose -O #{tempfile} #{java_installer_json_uri} && #{success_cmd} || #{failure_cmd} )"
|
246
100
|
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
101
|
+
_cset(:java_environment_join_keys, %w(DYLD_LIBRARY_PATH LD_LIBRARY_PATH MANPATH PATH))
|
102
|
+
def _merge_environment(x, y)
|
103
|
+
x.merge(y) { |key, x_val, y_val|
|
104
|
+
if java_environment_join_keys.include?(key)
|
105
|
+
( y_val.split(":") + x_val.split(":") ).uniq.join(":")
|
106
|
+
else
|
107
|
+
y_val
|
252
108
|
end
|
253
|
-
abort("No such file: #{java_installer_json_cache}") unless File.file?(java_installer_json_cache)
|
254
|
-
json = File.read(java_installer_json_cache)
|
255
|
-
json = json.sub(/\A[^{]*/, '').sub(/[^}]*\z/, '').strip # remove leading & trailing JS code from response
|
256
|
-
JSON.load(json)
|
257
|
-
ensure
|
258
|
-
run_locally("rm -f #{tempfile}") unless dry_run
|
259
|
-
end
|
260
|
-
}
|
261
|
-
_cset(:java_version_data) {
|
262
|
-
version = java_installer_json['version']
|
263
|
-
abort("Unknown JSON format version: #{version}") if version != 2
|
264
|
-
regex = Regexp.new(Regexp.quote(java_version), Regexp::IGNORECASE)
|
265
|
-
data = java_installer_json['data']
|
266
|
-
logger.info("Requested JDK version is #{java_version.dump}.")
|
267
|
-
data.find { |datum|
|
268
|
-
logger.debug("Checking JDK version: #{datum['name'].strip}")
|
269
|
-
regex === datum['name'].strip
|
270
|
-
}
|
271
|
-
}
|
272
|
-
_cset(:java_release_data) {
|
273
|
-
abort("No such JDK version found: #{java_version}") unless java_version_data
|
274
|
-
regex = Regexp.new(Regexp.quote(java_release), Regexp::IGNORECASE)
|
275
|
-
releases = java_version_data['releases']
|
276
|
-
logger.info("Requested JDK release is #{java_release.dump}.")
|
277
|
-
releases.find { |release|
|
278
|
-
logger.debug("Checking JDK release: #{release['title'].strip} (#{release['name'].strip})")
|
279
|
-
regex === release['name'].strip or regex === release['title'].strip
|
280
|
-
}
|
281
|
-
}
|
282
|
-
_cset(:java_release_license_title) {
|
283
|
-
abort("No such JDK release found: #{java_version}/#{java_release}") unless java_release_data
|
284
|
-
java_release_data['lictitle']
|
285
|
-
}
|
286
|
-
def java_file_data(name)
|
287
|
-
abort("No such JDK release found: #{java_version}/#{java_release}") unless java_release_data
|
288
|
-
regex = Regexp.new(Regexp.quote(name.to_s), Regexp::IGNORECASE)
|
289
|
-
logger.info("Requested JDK file is #{name.dump}.")
|
290
|
-
files = java_release_data['files']
|
291
|
-
files.find { |data|
|
292
|
-
logger.debug("Checking JDK file: #{data['title'].strip} (#{data['name'].strip})")
|
293
|
-
regex === data['name'] or regex === data['title']
|
294
109
|
}
|
295
110
|
end
|
296
|
-
|
297
|
-
## settings for local machine
|
298
|
-
_cset(:java_deployer_file) {
|
299
|
-
java_file(`uname -s`.strip, `uname -m`.strip)
|
300
|
-
}
|
301
|
-
_cset(:java_deployer_archive_uri) {
|
302
|
-
data = java_file_data(java_deployer_file)
|
303
|
-
abort("No such JDK release found for specified platform: #{java_version}/#{java_release}/#{java_deployer_file}") unless data
|
304
|
-
data['filepath']
|
305
|
-
}
|
306
|
-
_cset(:java_deployer_archive) {
|
307
|
-
File.join(java_tools_path, File.basename(URI.parse(java_deployer_archive_uri).path))
|
308
|
-
}
|
309
|
-
_cset(:java_deployer_archive_local) {
|
310
|
-
File.join(java_tools_path_local, File.basename(URI.parse(java_deployer_archive_uri).path))
|
311
|
-
}
|
312
111
|
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
_cset(:java_deployee_archive_uri) {
|
318
|
-
data = java_file_data(java_deployee_file)
|
319
|
-
abort("No such JDK release found for specified platform: #{java_version}/#{java_release}/#{java_deployee_file}") unless data
|
320
|
-
data['filepath']
|
321
|
-
}
|
322
|
-
_cset(:java_deployee_archive) {
|
323
|
-
File.join(java_tools_path, File.basename(URI.parse(java_deployee_archive_uri).path))
|
324
|
-
}
|
325
|
-
_cset(:java_deployee_archive_local) {
|
326
|
-
File.join(java_tools_path_local, File.basename(URI.parse(java_deployee_archive_uri).path))
|
112
|
+
task(:setup_default_environment, :except => { :no_release => true }) {
|
113
|
+
if fetch(:java_setup_default_environment, true)
|
114
|
+
set(:default_environment, _merge_environment(default_environment, java_environment))
|
115
|
+
end
|
327
116
|
}
|
328
117
|
|
329
118
|
## license settings
|
@@ -332,60 +121,69 @@ module Capistrano
|
|
332
121
|
_cset(:java_oracle_username) { abort("java_oracle_username was not set") }
|
333
122
|
_cset(:java_oracle_password) { abort("java_oracle_password was not set") }
|
334
123
|
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
}
|
343
|
-
|
344
|
-
task(:download_locally, :except => { :no_release => true }) {
|
345
|
-
download_archive(java_deployer_archive_uri, java_deployer_archive_local)
|
346
|
-
}
|
124
|
+
def _invoke_command(cmdline, options={})
|
125
|
+
if options[:via] == :run_locally
|
126
|
+
run_locally(cmdline)
|
127
|
+
else
|
128
|
+
invoke_command(cmdline, options)
|
129
|
+
end
|
130
|
+
end
|
347
131
|
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
#{extract_archive(java_deployer_archive_local, java_home_local)} &&
|
352
|
-
( #{java_cmd_local} -version || rm -rf #{java_home_local} ) &&
|
353
|
-
test -d #{java_home_local};
|
354
|
-
fi;
|
355
|
-
EOS
|
356
|
-
if dry_run
|
357
|
-
logger.debug(command)
|
132
|
+
def _download(jdk, filename, options={})
|
133
|
+
if FileTest.exist?(filename)
|
134
|
+
logger.info("Found downloaded archive: #{filename}")
|
358
135
|
else
|
359
|
-
|
136
|
+
if jdk.license_title != java_license_title or !java_accept_license
|
137
|
+
abort("You must accept JDK license before downloading.")
|
138
|
+
end
|
139
|
+
jdk.download(filename, fetch(:java_download_options, {}).merge(options))
|
360
140
|
end
|
361
|
-
|
141
|
+
end
|
362
142
|
|
143
|
+
def _upload(filename, remote_filename, options={})
|
144
|
+
_invoke_command("mkdir -p #{File.dirname(remote_filename).dump}", options)
|
145
|
+
transfer_if_modified(:up, filename, remote_filename, fetch(:java_upload_options, {}).merge(options))
|
146
|
+
end
|
147
|
+
|
148
|
+
def _install(jdk, filename, destination, options={})
|
149
|
+
cmdline = jdk.install_command(filename, destination, fetch(:java_install_options, {}).merge(options))
|
150
|
+
_invoke_command(cmdline, options)
|
151
|
+
end
|
152
|
+
|
153
|
+
def _installed?(destination, options={})
|
154
|
+
java = File.join(destination, "bin", "java")
|
155
|
+
cmdline = "test -d #{destination.dump} && test -x #{java.dump}"
|
156
|
+
_invoke_command(cmdline, options)
|
157
|
+
true
|
158
|
+
rescue
|
159
|
+
false
|
160
|
+
end
|
161
|
+
|
162
|
+
## tasks
|
363
163
|
desc("Install java.")
|
364
164
|
task(:setup, :roles => :app, :except => { :no_release => true }) {
|
365
|
-
if
|
366
|
-
|
367
|
-
download
|
368
|
-
transfer_if_modified(:up, java_deployee_archive_local, java_deployee_archive)
|
369
|
-
install
|
370
|
-
setup_locally if fetch(:java_setup_locally, false)
|
371
|
-
}
|
372
|
-
end
|
165
|
+
setup_remotely if java_setup_remotely
|
166
|
+
setup_locally if java_setup_locally
|
373
167
|
}
|
374
|
-
after
|
168
|
+
after "deploy:setup", "java:setup"
|
375
169
|
|
376
|
-
|
377
|
-
|
170
|
+
desc("Install java locally.")
|
171
|
+
task(:setup_locally, :except => { :no_release => true }) {
|
172
|
+
_download(java_installer_tool_local, java_archive_file_local, :via => :run_locally)
|
173
|
+
unless _installed?(java_home_local, :via => :run_locally)
|
174
|
+
_install(java_installer_tool_local, java_archive_file_local, java_home_local, :via => :run_locally)
|
175
|
+
_installed?(java_home_local, :via => :run_locally)
|
176
|
+
end
|
378
177
|
}
|
379
178
|
|
380
|
-
task(:
|
381
|
-
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
|
388
|
-
run(command)
|
179
|
+
task(:setup_remotely, :except => { :no_release => true }) {
|
180
|
+
filename = File.join(java_archive_path_local, File.basename(java_archive_file))
|
181
|
+
_download(java_installer_tool, filename, :via => :run_locally)
|
182
|
+
_upload(filename, java_archive_file)
|
183
|
+
unless _installed?(java_home)
|
184
|
+
_install(java_installer_tool, java_archive_file, java_home)
|
185
|
+
_installed?(java_home)
|
186
|
+
end
|
389
187
|
}
|
390
188
|
}
|
391
189
|
}
|
@@ -397,4 +195,4 @@ if Capistrano::Configuration.instance
|
|
397
195
|
Capistrano::Configuration.instance.extend(Capistrano::JDKInstaller)
|
398
196
|
end
|
399
197
|
|
400
|
-
# vim:set ft=ruby :
|
198
|
+
# vim:set ft=ruby sw=2 ts=2 :
|