Class: Capistrano::JDKInstaller::JDKInstaller
- Inherits:
-
Object
- Object
- Capistrano::JDKInstaller::JDKInstaller
- Defined in:
- lib/capistrano-jdk-installer/jdk-installer.rb
Constant Summary collapse
- JDK_INSTALLER_URI =
"http://updates.jenkins-ci.org/updates/hudson.tools.JDKInstaller.json"
- JDK_INSTALLER_TTL =
259200
Class Method Summary collapse
- .major_version(version_name) ⇒ Object
- .platform_string(version_name, ostype, arch, options = {}) ⇒ Object
Instance Method Summary collapse
- #[](regex) ⇒ Object
- #expired?(t = Time.now) ⇒ Boolean
- #files ⇒ Object
-
#initialize(options = {}) ⇒ JDKInstaller
constructor
A new instance of JDKInstaller.
- #logger ⇒ Object
- #mechanize ⇒ Object
- #read ⇒ Object
- #releases ⇒ Object
- #update ⇒ Object
- #update! ⇒ Object
- #versions ⇒ Object
- #write(s) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ JDKInstaller
Returns a new instance of JDKInstaller.
386 387 388 389 390 391 392 393 394 395 396 397 398 |
# File 'lib/capistrano-jdk-installer/jdk-installer.rb', line 386 def initialize(={}) @uri = ( .delete(:uri) || JDK_INSTALLER_URI ) @ttl = ( .delete(:ttl) || JDK_INSTALLER_TTL ) @file = if .key?(:file) .delete(:file) else Tempfile.new("jdk-installer") end @keep_stale = .fetch(:keep_stale, false) @options = .dup @logger = @options[:logger] update end |
Class Method Details
.major_version(version_name) ⇒ Object
347 348 349 350 351 352 353 354 355 |
# File 'lib/capistrano-jdk-installer/jdk-installer.rb', line 347 def major_version(version_name) case version_name when /^1_4_\d+(?:_[0-9]+)?$/ then "1.4" when /^1_5_\d+(?:_[0-9]+)?$/ then "5" when /^(\d+)(?:u\d+)?$/ then $1 else raise(JDKInstallerParseError.new("Could not parse JDK version name: #{version_name}")) end end |
.platform_string(version_name, ostype, arch, options = {}) ⇒ Object
357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 |
# File 'lib/capistrano-jdk-installer/jdk-installer.rb', line 357 def platform_string(version_name, ostype, arch, ={}) major_version = major_version(version_name) ostype = ostype.to_s.strip.downcase arch = arch.to_s.strip.downcase case major_version when /^(?:1\.4|5)$/ arch = case arch when /^(?:i[3-7]86)$/i then "i586" when /^(?:amd64|x86_64)$/i then "amd64" else arch end else ostype = case ostype when /^Darwin$/i then "macosx" else ostype end arch = case arch when /^(?:i[3-7]86)$/i then ostype == "macosx" ? "x64" : "i586" when /^(?:amd64|x86_64)$/i then "x64" else arch end end "#{ostype}-#{arch}" end |
Instance Method Details
#[](regex) ⇒ Object
464 465 466 |
# File 'lib/capistrano-jdk-installer/jdk-installer.rb', line 464 def [](regex) files.find { |file| regex === file.to_s } end |
#expired?(t = Time.now) ⇒ Boolean
410 411 412 |
# File 'lib/capistrano-jdk-installer/jdk-installer.rb', line 410 def expired?(t=Time.now) not(File.file?(@file)) or ( File.mtime(@file) + @ttl < t ) end |
#files ⇒ Object
460 461 462 |
# File 'lib/capistrano-jdk-installer/jdk-installer.rb', line 460 def files @files ||= releases.map { |release| release.files }.flatten end |
#logger ⇒ Object
400 401 402 |
# File 'lib/capistrano-jdk-installer/jdk-installer.rb', line 400 def logger @logger ||= Logger.new(STDOUT) end |
#mechanize ⇒ Object
404 405 406 407 408 |
# File 'lib/capistrano-jdk-installer/jdk-installer.rb', line 404 def mechanize @mechanize ||= ::Mechanize.new { |agent| agent.ssl_version = :TLSv1 # we have to declare TLS version explicitly to avoid problems on LP:965371 } end |
#read ⇒ Object
444 445 446 447 448 449 450 |
# File 'lib/capistrano-jdk-installer/jdk-installer.rb', line 444 def read() if @file.respond_to?(:read) @file.read else File.read(@file) end end |
#releases ⇒ Object
456 457 458 |
# File 'lib/capistrano-jdk-installer/jdk-installer.rb', line 456 def releases @releases ||= versions.map { |version| version.releases }.flatten end |
#update ⇒ Object
414 415 416 417 418 419 |
# File 'lib/capistrano-jdk-installer/jdk-installer.rb', line 414 def update if expired? logger.info("The cache of JDKInstaller.json has been expired. (ttl=#{@ttl})") update! end end |
#update! ⇒ Object
421 422 423 424 425 426 427 428 429 430 431 432 433 |
# File 'lib/capistrano-jdk-installer/jdk-installer.rb', line 421 def update! begin page = mechanize.get(@uri) write(page.body) rescue ::Mechanize::Error => error logger.info("Could not update JDKInstaller.json from #{@uri}. (#{error})") if @keep_stale logger.info("Try to use stale JDKInstaller.json at #{@file}.") else raise end end end |
#versions ⇒ Object
452 453 454 |
# File 'lib/capistrano-jdk-installer/jdk-installer.rb', line 452 def versions @versions ||= JDKInstallerVersions.parse(read, @options) end |
#write(s) ⇒ Object
435 436 437 438 439 440 441 442 |
# File 'lib/capistrano-jdk-installer/jdk-installer.rb', line 435 def write(s) if @file.respond_to?(:write) @file.write(s) else FileUtils.mkdir_p(File.dirname(@file)) File.write(@file, s) end end |