capistrano-jdk-installer 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -45,7 +45,8 @@ Following options are available to manage your JDK installation.
45
45
  * `:java_setup_remotely` - specify whether you want to setup JDK on remote machines. `true` by default.
46
46
  * `:java_installer_json_uri` - `http://updates.jenkins-ci.org/updates/hudson.tools.JDKInstaller.json` by default.
47
47
  * `:java_installer_json_cache` - the cache file path of "hudson.tools.JDKINstaller.json".
48
- * `:java_installer_json_expires` - the cache TTL. cache `86400` seconds by default.
48
+ * `:java_installer_json_expires` - the cache TTL. cache `259200` seconds by default.
49
+ * `:java_installer_json_keep_stale` - use stale cache when `:java_installer_json_uri` is down. `true` by default.
49
50
  * `:java_home` - the path to the `JAVA_HOME` on remote machines.
50
51
  * `:java_home_local` - the path to the `JAVA_HOME` on local machine.
51
52
  * `:java_cmd` - the `java` command on remote machines.
@@ -265,27 +265,33 @@ module Capistrano
265
265
  _cset(:java_installer_json_cache) {
266
266
  File.join(java_tools_path_local, File.basename(URI.parse(java_installer_json_uri).path))
267
267
  }
268
- _cset(:java_installer_json_expires, 86400)
268
+ _cset(:java_installer_json_expires, 259200) # 3 days
269
+ _cset(:java_installer_json_keep_stale, true) # keep staled cache even if wget fails
269
270
  _cset(:java_installer_json) {
270
- if File.file?(java_installer_json_cache)
271
- refresh = File.mtime(java_installer_json_cache) + java_installer_json_expires < Time.now
272
- else
273
- refresh = true
274
- end
275
- if refresh
276
- execute = []
277
- execute << "mkdir -p #{File.dirname(java_installer_json_cache)}"
278
- execute << "rm -f #{java_installer_json_cache}"
279
- execute << "wget --no-verbose -O #{java_installer_json_cache} #{java_installer_json_uri}"
280
- if dry_run
281
- logger.debug(execute.join(' && '))
282
- else
283
- run_locally(execute.join(' && '))
271
+ # should not update cache directly from wget.
272
+ # wget will save response to the file even if the request fails.
273
+ tempfile = "#{java_installer_json_cache}.#{$$}"
274
+ begin
275
+ if not File.file?(java_installer_json_cache) or File.mtime(java_installer_json_cache)+java_installer_json_expires < Time.now
276
+ execute = []
277
+ execute << "mkdir -p #{File.dirname(java_installer_json_cache)}"
278
+ success_cmd = "mv -f #{tempfile} #{java_installer_json_cache}"
279
+ failure_cmd = java_installer_json_keep_stale ? 'true' : 'false'
280
+ execute << "( wget --no-verbose -O #{tempfile} #{java_installer_json_uri} && #{success_cmd} || #{failure_cmd} )"
281
+
282
+ if dry_run
283
+ logger.debug(execute.join(' && '))
284
+ else
285
+ run_locally(execute.join(' && '))
286
+ end
284
287
  end
288
+ abort("No such file: #{java_installer_json_cache}") unless File.file?(java_installer_json_cache)
289
+ json = File.read(java_installer_json_cache)
290
+ json = json.sub(/\A[^{]*/, '').sub(/[^}]*\z/, '').strip # remove leading & trailing JS code from response
291
+ JSON.load(json)
292
+ ensure
293
+ run_locally("rm -f #{tempfile}") unless dry_run
285
294
  end
286
- json = File.read(java_installer_json_cache)
287
- json = json.sub(/\A[^{]*/, '').sub(/[^}]*\z/, '') # remove leading & trailing JS code from response
288
- JSON.load(json)
289
295
  }
290
296
  _cset(:java_version_data) {
291
297
  version = java_installer_json['version']
@@ -1,5 +1,5 @@
1
1
  module Capistrano
2
2
  module JDKInstaller
3
- VERSION = "0.0.3"
3
+ VERSION = "0.0.4"
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.3
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-10-19 00:00:00.000000000 Z
12
+ date: 2012-10-22 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: capistrano