Class: PackageManager
- Inherits:
-
Object
- Object
- PackageManager
- Defined in:
- lib/JRubyR/package.rb
Defined Under Namespace
Classes: ParseXML
Instance Method Summary collapse
-
#http_download_uri(uri, filename) ⇒ Object
—————————————————————————————-.
-
#initialize ⇒ PackageManager
constructor
—————————————————————————————-.
-
#load_package(name) ⇒ Object
—————————————————————————————- Installs a new package —————————————————————————————-.
-
#new_text(text) ⇒ Object
—————————————————————————————-.
-
#set_value ⇒ Object
—————————————————————————————-.
-
#tag_end(name) ⇒ Object
—————————————————————————————-.
-
#tag_start(name, value) ⇒ Object
—————————————————————————————-.
-
#update(type, name, attrs) ⇒ Object
—————————————————————————————-.
Constructor Details
#initialize ⇒ PackageManager
135 136 137 138 |
# File 'lib/JRubyR/package.rb', line 135 def initialize @properties = Hash.new super end |
Instance Method Details
#http_download_uri(uri, filename) ⇒ Object
214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 |
# File 'lib/JRubyR/package.rb', line 214 def http_download_uri(uri, filename) puts "Starting HTTP download for: " + uri.to_s http_object = Net::HTTP.new(uri.host, uri.port) http_object.use_ssl = true if uri.scheme == 'https' begin http_object.start do |http| request = Net::HTTP::Get.new uri.request_uri http.read_timeout = 500 http.request request do |response| open filename, 'wb' do |io| response.read_body do |chunk| io.write chunk end end end end rescue Exception => e puts "=> Exception: '#{e}'. Skipping download." return end puts "Stored download as " + filename + "." end |
#load_package(name) ⇒ Object
Installs a new package
241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 |
# File 'lib/JRubyR/package.rb', line 241 def load_package(name) # create the cran_dir if it does not already exists Dir.mkdir(SciCom.cran_dir) if !Dir.exists?(SciCom.cran_dir) # download address for Renjin packages renjin_cran = 'http://nexus.bedatadriven.com/content/groups/public/org/renjin/cran/' package = renjin_cran + name spec = package + "/" + "maven-metadata.xml" # read the maven-metadata specification uri = URI(spec) # parse the maven-metadata file parse = ParseXML.new(Net::HTTP.get(uri)) parse.add_observer(self) parse.start download_dir = package + '/' + @properties['latest'] spec2 = download_dir + '/' + "maven-metadata.xml" # parse the second maven-metadata file uri = URI(spec2) # download the spec file, so we know what version is actually installed http_download_uri(uri, SciCom.cran_dir + "/#{name}.xml") # need to clear the properties. If the file has multiple properties with the same # name, then only the last one will be kept. This might be a problem, but for # now this does not seem to matter... We are only interested in the 'value' # property that seems to always be the same for the 'pom' and 'jar' files. @properties.clear parse = ParseXML.new(Net::HTTP.get(uri)) parse.add_observer(self) parse.start filename = '/' + name + '-' + @properties['value'] + ".jar" download_file = download_dir + filename target_file = SciCom.cran_dir + '/' + name + ".jar" uri = URI.parse(download_file) http_download_uri(uri, target_file) end |
#new_text(text) ⇒ Object
187 188 189 |
# File 'lib/JRubyR/package.rb', line 187 def new_text(text) @text = text end |
#set_value ⇒ Object
162 163 164 |
# File 'lib/JRubyR/package.rb', line 162 def set_value @properties[@name] = @text end |
#tag_end(name) ⇒ Object
179 180 181 |
# File 'lib/JRubyR/package.rb', line 179 def tag_end(name) value_read end |
#tag_start(name, value) ⇒ Object
170 171 172 173 |
# File 'lib/JRubyR/package.rb', line 170 def tag_start(name, value) @name = name read_value end |
#update(type, name, attrs) ⇒ Object
195 196 197 198 199 200 201 202 203 204 205 206 207 208 |
# File 'lib/JRubyR/package.rb', line 195 def update(type, name, attrs) case type when :tag_start tag_start(name, attrs) when :tag_end tag_end(name) when :new_text new_text(name) else raise "Unknown type #{type}" end end |