capistrano-jdk-installer 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -51,6 +51,10 @@ Following options are available to manage your JDK installation.
51
51
  * `:java_cmd` - the `java` command on remote machines.
52
52
  * `:java_cmd_local` - the `java` command on local machine.
53
53
  * `:java_checksum_cmd` - use specified command to compare JDK archives. use `md5sum` by default.
54
+ * `:java_version` - specify a string to identify JDK version. by default, it will be generated from `:java_version_name`.
55
+ * `:java_release` - specify a string to identify JDK release. by default, it will be generated from `:java_version_name`.
56
+ * `:java_deployer_file` - specify a string to identify JDK archive. by default, it will be generated from `:java_version_name`.
57
+ * `:java_deployee_file` - specify a string to identify JDK archive. by default, it will be generated from `:java_version_name`.
54
58
 
55
59
  ## Contributing
56
60
 
@@ -39,6 +39,7 @@ module Capistrano
39
39
 
40
40
  def upload_archive(from, to, options={}, &block)
41
41
  mode = options.delete(:mode)
42
+ run("mkdir -p #{File.dirname(to)}")
42
43
  execute_on_servers(options) { |servers|
43
44
  targets = servers.map { |server| sessions[server] }
44
45
  if dry_run
@@ -72,7 +73,7 @@ module Capistrano
72
73
 
73
74
  def extract_archive(archive, destination)
74
75
  case archive
75
- when /\.bin$/
76
+ when /\.(bin|sh)$/
76
77
  "( cd #{File.dirname(destination)} && yes | sh #{archive} )"
77
78
  when /\.dmg$/
78
79
  if java_update_number
@@ -110,8 +111,8 @@ module Capistrano
110
111
  File.join(File.expand_path('.'), 'tools', 'java')
111
112
  }
112
113
  _cset(:java_home) {
113
- case java_deployee_platform
114
- when /Mac OS X/i
114
+ case java_deployee_file
115
+ when /macosx/i
115
116
  if java_update_number
116
117
  File.join("/Library", "Java", "JavaVirtualMachines",
117
118
  "jdk%s_%02d.jdk" % [java_inner_version, java_update_number],
@@ -130,8 +131,8 @@ module Capistrano
130
131
  end
131
132
  }
132
133
  _cset(:java_home_local) {
133
- case java_deployer_platform
134
- when /Mac OS X/i
134
+ case java_deployer_file
135
+ when /macosx/i
135
136
  if java_update_number
136
137
  File.join("/Library", "Java", "JavaVirtualMachines",
137
138
  "jdk%s_%02d.jdk" % [java_inner_version, java_update_number],
@@ -160,42 +161,35 @@ module Capistrano
160
161
  }
161
162
  _cset(:java_version_info) {
162
163
  case java_version_name
163
- when /^(1\.4\.(\d+))(?:_([0-9]+))?$/ then [ $1, '1.4', $2, $3 ]
164
- when /^(1\.5\.(\d+))(?:_([0-9]+))?$/ then [ $1, '5', $2, $3 ]
165
- when /^(\d+)(?:u(\d+))?$/ then [ "1.#{$1}.0", $1, nil, $2 ]
164
+ when /^(1\.4\.(\d+))(?:[_u]([0-9]+))?$/ then [ $1, '1.4', $2, $3 ]
165
+ when /^(1\.5\.(\d+))(?:[_u]([0-9]+))?$/ then [ $1, '5', $2, $3 ]
166
+ when /^(\d+)(?:u(\d+))?$/ then [ "1.#{$1}.0", $1, 0, $2 ]
166
167
  else
167
168
  abort("Could not parse JDK version name: #{java_version_name}")
168
169
  end
169
170
  }
170
171
  _cset(:java_inner_version) { java_version_info[0] } # e.g. "1.7.0"
171
- _cset(:java_major_version) { java_version_info[1] } # e.g. "7"
172
- _cset(:java_minor_version) { java_version_info[2] } # e.g. nil
173
- _cset(:java_update_number) { java_version_info[3] } # e.g. "6"
172
+ _cset(:java_major_version) { java_version_info[1] } # e.g. 7
173
+ _cset(:java_minor_version) { java_version_info[2] } # e.g. 0
174
+ _cset(:java_update_number) { java_version_info[3] } # e.g. 6
174
175
  _cset(:java_version) {
175
176
  "JDK #{java_major_version}"
176
177
  }
177
178
  _cset(:java_release) {
178
179
  case java_major_version
179
- when '1.4'
180
+ when '1.4', '5'
181
+ jdk = java_major_version == '1.4' ? 'j2sdk' : 'jdk'
180
182
  if java_update_number
181
- "Java SE Development Kit #{java_inner_version.gsub('.', '_')}_#{java_update_number}"
183
+ '%s-%s_%02d-oth-JPR' % [jdk, java_inner_version, java_update_number]
182
184
  else
183
- "Java SE Development Kit #{java_inner_version.gsub('.', '_')}"
185
+ '%s-%s-oth-JPR' % [jdk, java_inner_version]
184
186
  end
185
- when '5'
186
- if java_update_number
187
- "Java SE Development Kit #{java_major_version}.#{java_minor_version} Update #{java_update_number}"
188
- else
189
- "Java SE Development Kit #{java_major_version}.#{java_minor_version}"
190
- end
191
- when '6', '7'
187
+ else
192
188
  if java_update_number
193
- "Java SE Development Kit #{java_major_version}u#{java_update_number}"
189
+ 'jdk-%du%d-oth-JPR' % [java_major_version, java_update_number]
194
190
  else
195
- "Java SE Development Kit #{java_major_version}"
191
+ 'jdk-%d-oth-JPR' % [java_major_version]
196
192
  end
197
- else
198
- abort("Unknown JDK version: #{java_major_version}")
199
193
  end
200
194
  }
201
195
  def java_platform(ostype, arch)
@@ -203,35 +197,56 @@ module Capistrano
203
197
  when /^Darwin$/i
204
198
  case arch
205
199
  when /^i[3-7]86$/i, /^x86_64$/i
206
- 'Mac OS X x64'
200
+ "macosx-x64"
207
201
  else
208
- "Mac OS X #{arch}"
202
+ "macosx-#{arch.downcase}"
209
203
  end
210
204
  when /^Linux$/i
211
205
  case arch
212
206
  when /^i[3-7]86$/i
213
- 'Linux x86'
207
+ "linux-i586"
214
208
  when /^x86_64$/i
215
- 'Linux x64'
209
+ case java_major_version
210
+ when '1.4', '5'
211
+ "linux-amd64"
212
+ else
213
+ "linux-x64"
214
+ end
216
215
  else
217
- "Linux #{arch}"
216
+ "linux-#{arch.downcase}"
218
217
  end
219
218
  when /^Solaris$/i
220
219
  case arch
221
220
  when /^sparc$/i
222
- "Solaris SPARC"
221
+ "solaris-sparc"
223
222
  when /^sparcv9$/i
224
- "Solaris SPARC 64-bit"
223
+ "solaris-sparcv9"
225
224
  when /^i[3-7]86$/i
226
- "Solaris x86"
225
+ "solaris-i586"
227
226
  when /^x86_64$/i
228
- "Solaris x64"
227
+ "solaris-x64"
229
228
  else
230
- "Solaris #{arch}"
229
+ "solaris-#{arch.downcase}"
230
+ end
231
+ end
232
+ end
233
+ def java_file(ostype, arch)
234
+ case java_major_version
235
+ when '1.4', '5'
236
+ jdk = java_major_version == '1.4' ? 'j2sdk' : 'jdk'
237
+ if java_update_number
238
+ '%s-%s_%02d-%s' % [jdk, java_inner_version.gsub('.', '_'), java_update_number, java_platform(ostype, arch)]
239
+ else
240
+ '%s-%s-%s' % [jdk, java_inner_version.gsub('.', '_'), java_platform(ostype, arch)]
241
+ end
242
+ else
243
+ if java_update_number
244
+ 'jdk-%du%d-%s' % [java_major_version, java_update_number, java_platform(ostype, arch)]
245
+ else
246
+ 'jdk-%d-%s' % [java_major_version, java_platform(ostype, arch)]
231
247
  end
232
248
  end
233
249
  end
234
-
235
250
  ## hudson.tools.JDKInstaller.json
236
251
  _cset(:java_mechanize_agent) {
237
252
  Mechanize.log = ::Logger.new(STDERR)
@@ -277,30 +292,44 @@ module Capistrano
277
292
  abort("Unknown JSON format version: #{version}") if version != 2
278
293
  regex = Regexp.new(Regexp.quote(java_version), Regexp::IGNORECASE)
279
294
  data = java_installer_json['data']
280
- data.find { |datum| regex === datum['name'].strip }
295
+ logger.info("Requested JDK version is #{java_version.dump}.")
296
+ data.find { |datum|
297
+ logger.debug("Checking JDK version: #{datum['name'].strip}")
298
+ regex === datum['name'].strip
299
+ }
281
300
  }
282
301
  _cset(:java_release_data) {
302
+ abort("No such JDK version found: #{java_version}") unless java_version_data
283
303
  regex = Regexp.new(Regexp.quote(java_release), Regexp::IGNORECASE)
284
304
  releases = java_version_data['releases']
285
- releases.find { |release| regex === release['name'].strip or regex === release['title'].strip }
305
+ logger.info("Requested JDK release is #{java_release.dump}.")
306
+ releases.find { |release|
307
+ logger.debug("Checking JDK release: #{release['title'].strip} (#{release['name'].strip})")
308
+ regex === release['name'].strip or regex === release['title'].strip
309
+ }
286
310
  }
287
311
  _cset(:java_release_license_title) {
312
+ abort("No such JDK release found: #{java_version}/#{java_release}") unless java_release_data
288
313
  java_release_data['lictitle']
289
314
  }
290
- def java_platform_data(regex)
315
+ def java_file_data(name)
316
+ abort("No such JDK release found: #{java_version}/#{java_release}") unless java_release_data
317
+ regex = Regexp.new(Regexp.quote(name.to_s), Regexp::IGNORECASE)
318
+ logger.info("Requested JDK file is #{name.dump}.")
291
319
  files = java_release_data['files']
292
- data = files.find { |data|
293
- regex === data['title']
320
+ files.find { |data|
321
+ logger.debug("Checking JDK file: #{data['title'].strip} (#{data['name'].strip})")
322
+ regex === data['name'] or regex === data['title']
294
323
  }
295
- abort("Not supported on specified JDK release: #{regex.inspect}") unless data
296
- data
297
324
  end
298
325
 
299
326
  ## settings for local machine
300
- _cset(:java_deployer_platform) { java_platform(`uname -s`.strip, `uname -m`.strip) }
327
+ _cset(:java_deployer_file) {
328
+ java_file(`uname -s`.strip, `uname -m`.strip)
329
+ }
301
330
  _cset(:java_deployer_archive_uri) {
302
- regex = Regexp.new(Regexp.quote(java_deployer_platform), Regexp::IGNORECASE)
303
- data = java_platform_data(regex)
331
+ data = java_file_data(java_deployer_file)
332
+ abort("No such JDK release found for specified platform: #{java_version}/#{java_release}/#{java_deployer_file}") unless data
304
333
  data['filepath']
305
334
  }
306
335
  _cset(:java_deployer_archive) {
@@ -311,10 +340,12 @@ module Capistrano
311
340
  }
312
341
 
313
342
  ## settings for remote machines
314
- _cset(:java_deployee_platform) { java_platform(capture('uname -s').strip, capture('uname -m').strip) }
343
+ _cset(:java_deployee_file) {
344
+ java_file(capture('uname -s').strip, capture('uname -m').strip)
345
+ }
315
346
  _cset(:java_deployee_archive_uri) {
316
- regex = Regexp.new(Regexp.quote(java_deployee_platform), Regexp::IGNORECASE)
317
- data = java_platform_data(regex)
347
+ data = java_file_data(java_deployee_file)
348
+ abort("No such JDK release found for specified platform: #{java_version}/#{java_release}/#{java_deployee_file}") unless data
318
349
  data['filepath']
319
350
  }
320
351
  _cset(:java_deployee_archive) {
@@ -333,14 +364,11 @@ module Capistrano
333
364
  ## tasks
334
365
  desc("Install java locally.")
335
366
  task(:setup_locally, :except => { :no_release => true }) {
336
- if fetch(:java_setup_locally, false)
337
- transaction {
338
- download_locally
339
- install_locally
340
- }
341
- end
367
+ transaction {
368
+ download_locally
369
+ install_locally
370
+ }
342
371
  }
343
- after 'deploy:setup', 'java:setup'
344
372
 
345
373
  task(:download_locally, :except => { :no_release => true }) {
346
374
  download_archive(java_deployer_archive_uri, java_deployer_archive_local)
@@ -368,6 +396,7 @@ module Capistrano
368
396
  download
369
397
  upload_archive(java_deployee_archive_local, java_deployee_archive)
370
398
  install
399
+ setup_locally if fetch(:java_setup_locally, false)
371
400
  }
372
401
  end
373
402
  }
@@ -1,5 +1,5 @@
1
1
  module Capistrano
2
2
  module JDKInstaller
3
- VERSION = "0.0.2"
3
+ VERSION = "0.0.3"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: capistrano-jdk-installer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
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-10-01 00:00:00.000000000 Z
12
+ date: 2012-10-19 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: capistrano