Class: Capistrano::JDKInstaller::JDKInstallerFile
- Inherits:
-
Object
- Object
- Capistrano::JDKInstaller::JDKInstallerFile
- Defined in:
- lib/capistrano-jdk-installer/jdk-installer.rb
Constant Summary collapse
- MECHANIZE_USER_AGENT =
"Mozilla/5.0 (Windows; U; MSIE 9.0; Windows NT 9.0; en-US)"
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#release ⇒ Object
readonly
Returns the value of attribute release.
Instance Method Summary collapse
- #basename ⇒ Object
- #download(filename, options = {}) ⇒ Object
- #filepath ⇒ Object (also: #file)
-
#initialize(release, data, options = {}) ⇒ JDKInstallerFile
constructor
A new instance of JDKInstallerFile.
- #inner_version ⇒ Object
- #install_command(filename, destination, options = {}) ⇒ Object
- #install_path(options = {}) ⇒ Object
- #licpath ⇒ Object (also: #license_path)
- #lictitle ⇒ Object (also: #license_title)
- #logger ⇒ Object
- #major_version ⇒ Object
- #mechanize ⇒ Object
- #minor_version ⇒ Object
- #name ⇒ Object (also: #to_s)
- #platform ⇒ Object
- #title ⇒ Object
- #update_number ⇒ Object
- #uri ⇒ Object
- #version ⇒ Object
Constructor Details
#initialize(release, data, options = {}) ⇒ JDKInstallerFile
Returns a new instance of JDKInstallerFile.
20 21 22 23 24 25 |
# File 'lib/capistrano-jdk-installer/jdk-installer.rb', line 20 def initialize(release, data, ={}) @release = release @data = data @options = .dup @logger = @options[:logger] end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
26 27 28 |
# File 'lib/capistrano-jdk-installer/jdk-installer.rb', line 26 def @options end |
#release ⇒ Object (readonly)
Returns the value of attribute release.
26 27 28 |
# File 'lib/capistrano-jdk-installer/jdk-installer.rb', line 26 def release @release end |
Instance Method Details
#basename ⇒ Object
122 123 124 |
# File 'lib/capistrano-jdk-installer/jdk-installer.rb', line 122 def basename File.basename(uri.path) end |
#download(filename, options = {}) ⇒ Object
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/capistrano-jdk-installer/jdk-installer.rb', line 94 def download(filename, ={}) = @options.merge() username = .fetch(:username, "") password = .fetch(:password, "") logger.debug("Download JDK archive from #{filepath}....") page = mechanize.get(filepath) 1.upto(16) do # to avoid infinity loop... if page.uri.host == "login.oracle.com" # login.oracle.com doesn't return proper Content-Type if page.is_a?(::Mechanize::File) page = ::Mechanize::Page.new(page.uri, page.response, page.body, page.code, mechanize) end form = page.form_with form["ssousername"] = username form["password"] = password page = mechanize.submit(form) else page.save(filename) logger.debug("Wrote #{page.body.size} bytes to #{filename}.") break end end end |
#filepath ⇒ Object Also known as: file
32 33 34 |
# File 'lib/capistrano-jdk-installer/jdk-installer.rb', line 32 def filepath @filepath ||= @data["filepath"] end |
#inner_version ⇒ Object
71 72 73 |
# File 'lib/capistrano-jdk-installer/jdk-installer.rb', line 71 def inner_version release.inner_version end |
#install_command(filename, destination, options = {}) ⇒ Object
150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 |
# File 'lib/capistrano-jdk-installer/jdk-installer.rb', line 150 def install_command(filename, destination, ={}) execute = [] execute << "mkdir -p #{File.dirname(destination).dump}" case filename when /\.(bin|sh)$/ execute << "( cd #{File.dirname(destination).dump} && yes | sh #{filename.dump} )" when /\.dmg$/ if update_number pkg = File.join("/Volumes", "JDK %d Update %02d" % [major_version, update_number], "JDK %d Update %02d.pkg" % [major_version, update_number]) else pkg = File.join("/Volumes", "JDK %d" % [major_version], "JDK %d" % [major_version]) end execute << "open #{filenamedump}" execute << "( while test \! -f #{pkg.dump}; do sleep 1; done )" execute << "open #{pkg.dump}" execute << "( while test \! -d #{destination.dump}; do sleep 1; done )" when /\.(tar\.(gz|bz2)|tgz|tbz2)$/ execute << "tar xf #{filename.dump} -C #{File.dirname(destination).dump}" when /\.zip$/ execute << "( cd #{File.dirname(destination).dump} && unzip #{filename.dump} )" else execute << "true" end execute.join(" && ") end |
#install_path(options = {}) ⇒ Object
126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 |
# File 'lib/capistrano-jdk-installer/jdk-installer.rb', line 126 def install_path(={}) = @options.merge() case platform when /macosx/i v = if update_number "jdk%s_%02d.jdk" % [inner_version, update_number] else "jdk%s.jdk" % [inner_version] end File.join("/Library", "Java", "JavaVirtualMachines", v, "Contents", "Home") else v = if update_number "jdk%s_%02d" % [inner_version, update_number] else "jdk%s" % [inner_version] end if .key?(:path) File.join([:path], v) else v end end end |
#licpath ⇒ Object Also known as: license_path
75 76 77 |
# File 'lib/capistrano-jdk-installer/jdk-installer.rb', line 75 def licpath release.licpath end |
#lictitle ⇒ Object Also known as: license_title
80 81 82 |
# File 'lib/capistrano-jdk-installer/jdk-installer.rb', line 80 def lictitle release.lictitle end |
#logger ⇒ Object
28 29 30 |
# File 'lib/capistrano-jdk-installer/jdk-installer.rb', line 28 def logger @logger ||= Logger.new(STDOUT) end |
#major_version ⇒ Object
59 60 61 |
# File 'lib/capistrano-jdk-installer/jdk-installer.rb', line 59 def major_version release.major_version end |
#mechanize ⇒ Object
85 86 87 88 89 90 91 92 |
# File 'lib/capistrano-jdk-installer/jdk-installer.rb', line 85 def mechanize @mechanize ||= ::Mechanize.new { |agent| agent.user_agent = MECHANIZE_USER_AGENT agent..add!(::Mechanize::Cookie.new("gpw_e24", ".", :domain => ".oracle.com", :path => "/", :secure => false, :for_domain => true)) agent..add!(::Mechanize::Cookie.new("oraclelicense", "accept-securebackup-cookie", :domain => ".oracle.com", :path => "/", :secure => false, :for_domain => true)) agent.ssl_version = :TLSv1 # we have to declare TLS version explicitly to avoid problems on LP:965371 } end |
#minor_version ⇒ Object
63 64 65 |
# File 'lib/capistrano-jdk-installer/jdk-installer.rb', line 63 def minor_version release.minor_version end |
#name ⇒ Object Also known as: to_s
37 38 39 |
# File 'lib/capistrano-jdk-installer/jdk-installer.rb', line 37 def name @name ||= @data["name"] end |
#platform ⇒ Object
46 47 48 49 50 51 52 53 |
# File 'lib/capistrano-jdk-installer/jdk-installer.rb', line 46 def platform @platform ||= case name when /jdk-\d+(?:u\d+)?-(\w+-\w+)\.\w+/ then $1.downcase when /j2?dk-\d+_\d+_\d+(?:_\d+)?-(\w+-\w+)\.\w+/ then $1.downcase else raise(JDKInstallerParseError.new("Could not parse JDK file name: #{name}")) end end |
#title ⇒ Object
42 43 44 |
# File 'lib/capistrano-jdk-installer/jdk-installer.rb', line 42 def title @title ||= @data["title"] end |
#update_number ⇒ Object
67 68 69 |
# File 'lib/capistrano-jdk-installer/jdk-installer.rb', line 67 def update_number release.update_number end |
#uri ⇒ Object
118 119 120 |
# File 'lib/capistrano-jdk-installer/jdk-installer.rb', line 118 def uri @uri ||= URI.parse(filepath) end |
#version ⇒ Object
55 56 57 |
# File 'lib/capistrano-jdk-installer/jdk-installer.rb', line 55 def version release.version end |