Class: Jnlp::MavenJnlp

Inherits:
Object
  • Object
show all
Defined in:
lib/jnlp/maven_jnlp.rb

Overview

MavenJnlp

Given the url to the root of an active MavenJnlp web start servlet a new instance of MavenJnlp will find all the families, all the versions for each family, and determine the current version.

Example:

require 'jnlp'
mj = Jnlp::MavenJnlp.new('http://jnlp.concord.org', '/dev/org/concord/maven-jnlp/')

This takes about 90s on a 3Mbps connection processing Concord’s Maven Jnlp Web Start server.

You can now do this:

mj.maven_jnlp_families.length                        # => 26
mj.maven_jnlp_families[0].name                       # => "all-otrunk-snapshot"
mj.maven_jnlp_families[0].versions.length            # => 1568
mj.maven_jnlp_families[0].versions.first.version     # => "0.1.0-20070420.131610"
mj.maven_jnlp_families[0].snapshot_version           # => "0.1.0-20090327.222627"

mj.maven_jnlp_families[0].versions.last.url

# => "/dev/org/concord/maven-jnlp/all-otrunk-snapshot/all-otrunk-snapshot-0.1.0-20090327.222627.jnlp"

mj.maven_jnlp_families[0].snapshot.url

# => "/dev/org/concord/maven-jnlp/all-otrunk-snapshot/all-otrunk-snapshot-0.1.0-20090327.222627.jnlp"

mj.maven_jnlp_families[0].versions.first.url

# => "/dev/org/concord/maven-jnlp/all-otrunk-snapshot/all-otrunk-snapshot-0.1.0-20070420.131610.jnlp"

You can pass in an options hash to limit the number of maven jnlp families parsed:

Example: passing in an optional array of maven jnlp families This will get all versions of each family.

mj = Jnlp::MavenJnlp.new('http://jnlp.concord.org', '/dev/org/concord/maven-jnlp/', 
     { :families => ['all-otrunk-snapshot', 'gui-testing'] })

mj.maven_jnlp_families.length
=> 2

Example: passing in an optional hash of maven jnlp families This will get all versions of each family.

mj = Jnlp::MavenJnlp.new('http://jnlp.concord.org', '/dev/org/concord/maven-jnlp/', 
     { :families => { 'all-otrunk-snapshot' => nil, 'gui-testing' => nil } })

mj.maven_jnlp_families.length
=> 2

Example: passing in an optional hash of maven jnlp families and specifying the versions of the jnlp urls to get for one family.

mj = Jnlp::MavenJnlp.new('http://jnlp.concord.org', '/dev/org/concord/maven-jnlp/',
     { :families => { 
       'all-otrunk-snapshot' => { :versions => ['0.1.0-20100513.161426', '0.1.0-20100513.154925'] },
       'gui-testing' => nil }
     })
mjfs = mj.maven_jnlp_families
[mjfs.length, mjfs[0].versions.length, mjfs[1].versions.length]
=> [2, 2, 50]

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(base_url, jnlp_families_path, options = {}) ⇒ MavenJnlp

Pass in:

base_url, maven_jnlp_path


282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
# File 'lib/jnlp/maven_jnlp.rb', line 282

def initialize(base_url, jnlp_families_path, options={})
  @base_url = base_url
  @jnlp_families_path = jnlp_families_path
  @jnlp_families_url = @base_url + @jnlp_families_path
  @maven_jnlp_families = []
  doc = Nokogiri::HTML(open(@jnlp_families_url).read)
  family_paths = doc.search("//a").find_all { |a| 
    a['href'][/#{@jnlp_families_path}/] 
  }.collect { |a| a['href'] }
  if options[:families]
    case options[:families]
    when Hash
      options[:families].each do |family, versions|
        family_path = family_paths.detect { |fp| family == File.basename(fp) }
        if family_path
          maven_jnlp_family = MavenJnlpFamily.new(@base_url, family_path, versions || {}) 
          @maven_jnlp_families << maven_jnlp_family
        end
      end
    when Array
      family_paths = family_paths.select { |path| 
        options[:families].any? { |family| family == File.basename(path) }
      }
      family_paths.each do |family_path|
        maven_jnlp_family = MavenJnlpFamily.new(@base_url, family_path) 
        @maven_jnlp_families << maven_jnlp_family
      end
    end
  end
end

Instance Attribute Details

#base_urlObject (readonly)

Contains the base_url for this MavenJnlp server

Example:

'http://jnlp.concord.org'


254
255
256
# File 'lib/jnlp/maven_jnlp.rb', line 254

def base_url
  @base_url
end

#jnlp_families_pathObject (readonly)

Contains the path to the jnlp families for this MavenJnlp server

Example:

'/dev/org/concord/maven-jnlp/'


263
264
265
# File 'lib/jnlp/maven_jnlp.rb', line 263

def jnlp_families_path
  @jnlp_families_path
end

#jnlp_families_urlObject (readonly)

Contains the url to the jnlp families for this MavenJnlp server

Example:

'http://jnlp.concord.org/dev/org/concord/maven-jnlp/'


272
273
274
# File 'lib/jnlp/maven_jnlp.rb', line 272

def jnlp_families_url
  @jnlp_families_url
end

#maven_jnlp_familiesObject (readonly)

Contains an array of MavenJnlpFamilies



276
277
278
# File 'lib/jnlp/maven_jnlp.rb', line 276

def maven_jnlp_families
  @maven_jnlp_families
end

Instance Method Details

#summarizeObject

summarize

Display a summary of the jnlp families and versions available on stdout.

Example:

require 'jnlp'
mj = Jnlp::MavenJnlp.new('http://jnlp.concord.org', '/dev/org/concord/maven-jnlp/')
mj.summarize                 

Maven Jnlp families: 26

name: all-otrunk-snapshot
  versions: 1568
  current snapshot version: 0.1.0-20090327.222627

name: all-otrunk-snapshot-with-installer
  versions: 167
  current snapshot version: 0.1.0-20090327.222727

name: capa-measuring-resistance
  versions: 1496
  current snapshot version: 0.1.0-20090327.222729

name: capa-otrunk
  versions: 1172
  current snapshot version: 0.1.0-20090327.222733

...


345
346
347
348
349
350
351
352
353
354
355
356
# File 'lib/jnlp/maven_jnlp.rb', line 345

def summarize
  puts 
  puts "Maven Jnlp families: #{@maven_jnlp_families.length}"
  puts
  @maven_jnlp_families.each do |family|
    puts "name: #{family.name}"
    puts "  versions: #{family.versions.length}"
    puts "  current snapshot version: #{family.snapshot_version}"
    puts
  end
  puts
end