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.
387 388 389 390 391 392 393 394 395 396 397 398 399 |
# File 'lib/capistrano-jdk-installer/jdk-installer.rb', line 387 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
348 349 350 351 352 353 354 355 356 |
# File 'lib/capistrano-jdk-installer/jdk-installer.rb', line 348 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
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 384 |
# File 'lib/capistrano-jdk-installer/jdk-installer.rb', line 358 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
465 466 467 |
# File 'lib/capistrano-jdk-installer/jdk-installer.rb', line 465 def [](regex) files.find { |file| regex === file.to_s } end |
#expired?(t = Time.now) ⇒ Boolean
411 412 413 |
# File 'lib/capistrano-jdk-installer/jdk-installer.rb', line 411 def expired?(t=Time.now) not(File.file?(@file)) or ( File.mtime(@file) + @ttl < t ) end |
#files ⇒ Object
461 462 463 |
# File 'lib/capistrano-jdk-installer/jdk-installer.rb', line 461 def files @files ||= releases.map { |release| release.files }.flatten end |
#logger ⇒ Object
401 402 403 |
# File 'lib/capistrano-jdk-installer/jdk-installer.rb', line 401 def logger @logger ||= Logger.new(STDOUT) end |
#mechanize ⇒ Object
405 406 407 408 409 |
# File 'lib/capistrano-jdk-installer/jdk-installer.rb', line 405 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
445 446 447 448 449 450 451 |
# File 'lib/capistrano-jdk-installer/jdk-installer.rb', line 445 def read() if @file.respond_to?(:read) @file.read else File.read(@file) end end |
#releases ⇒ Object
457 458 459 |
# File 'lib/capistrano-jdk-installer/jdk-installer.rb', line 457 def releases @releases ||= versions.map { |version| version.releases }.flatten end |
#update ⇒ Object
415 416 417 418 419 420 |
# File 'lib/capistrano-jdk-installer/jdk-installer.rb', line 415 def update if expired? logger.info("The cache of JDKInstaller.json has been expired. (ttl=#{@ttl})") update! end end |
#update! ⇒ Object
422 423 424 425 426 427 428 429 430 431 432 433 434 |
# File 'lib/capistrano-jdk-installer/jdk-installer.rb', line 422 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
453 454 455 |
# File 'lib/capistrano-jdk-installer/jdk-installer.rb', line 453 def versions @versions ||= JDKInstallerVersions.parse(read, @options) end |
#write(s) ⇒ Object
436 437 438 439 440 441 442 443 |
# File 'lib/capistrano-jdk-installer/jdk-installer.rb', line 436 def write(s) if @file.respond_to?(:write) @file.write(s) else FileUtils.mkdir_p(File.dirname(@file)) File.write(@file, s) end end |