Class: Jnlp::MavenJnlpFamily

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

Overview

MavenJnlpFamily

Encapsulates a single MavenJnlp Family of versioned jnlps.

Jnlp::MavenJnlpFamily.new(base_url, family_path)

Example:

require 'jnlp'
mjf = Jnlp::MavenJnlpFamily.new('http://jnlp.concord.org', '/dev/org/concord/maven-jnlp/all-otrunk-snapshot')

mjf = Jnlp::MavenJnlpFamily.new('http://jnlp.concord.org', '/dev/org/concord/maven-jnlp/all-otrunk-snapshot', 
  { :versions => ['0.1.0-20100513.161426', '0.1.0-20100513.154925'] })

You can pass in an options hash to limit the number of versioned jnlps parsed:

Example

mjf = Jnlp::MavenJnlpFamily.new('http://jnlp.concord.org', '/dev/org/concord/maven-jnlp/all-otrunk-snapshot', 
     { :versions => ['0.1.0-20100513.161426', '0.1.0-20100513.154925'] })

mjf.versions.length
=> 2

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(base_url, family_path, options = {}) ⇒ MavenJnlpFamily

Pass in:

base_url, family_path


139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
# File 'lib/jnlp/maven_jnlp.rb', line 139

def initialize(base_url, family_path, options={})
  @base_url = base_url
  @path = family_path
  @url = @base_url + @path
  @name = File.basename(@path)
  @versions = []
  doc = Nokogiri::HTML(open(@url).read)
  anchor_tags = doc.search("//a")
  snapshot_version_path = anchor_tags.find {|a| a['href'][/CURRENT_VERSION\.txt$/] }['href']
  @snapshot_version = open(base_url + snapshot_version_path).read
  jnlp_paths = anchor_tags.find_all { |a| a['href'][/jnlp$/] }.collect { |a| a['href'] }
  jnlp_paths.each do |jnlp_path|
    version = jnlp_path[/#{name}\/#{name}-(.*)\.jnlp/, 1]
    # skip processing unless this jnlp has a version string
    if version
      # only continue processing if:
      #   no options[:version] was passed in OR
      #   the current version matches one of the desired versions OR
      #   one of the desired versions is 'snapshot' and this version IS the snapshot version
      if  options[:versions] == nil || 
          options[:versions].any? { |v| v == version } ||
          options[:versions].any? { |v| v == 'snapshot' && version == @snapshot_version } 
        versioned_jnlp_url = VersionedJnlpUrl.new(@name, jnlp_path, @base_url)
        @versions << versioned_jnlp_url
        if versioned_jnlp_url.version == @snapshot_version
          @snapshot = versioned_jnlp_url
        end
      end
    end
  end
end

Instance Attribute Details

#base_urlObject (readonly)

Contains the base_url for this MavenJnlp server

Example:

"http://jnlp.concord.org"


87
88
89
# File 'lib/jnlp/maven_jnlp.rb', line 87

def base_url
  @base_url
end

#nameObject (readonly)

Contains the name for this family of jnlps

Example:

"all-otrunk-snapshot"


112
113
114
# File 'lib/jnlp/maven_jnlp.rb', line 112

def name
  @name
end

#pathObject (readonly)

Contains the path from the base_url to the root for this family of jnlps

Example:

"/dev/org/concord/maven-jnlp/"


96
97
98
# File 'lib/jnlp/maven_jnlp.rb', line 96

def path
  @path
end

#snapshotObject (readonly)

Contains the VersionedJnlpUrl referencing the latest versioned jnlp. This jnlp is identical to the snapshot jnlp at the time of instantiation.



132
133
134
# File 'lib/jnlp/maven_jnlp.rb', line 132

def snapshot
  @snapshot
end

#snapshot_versionObject (readonly)

Contains the version string for the latest versioned jnlp. This jnlp this version string refers to is identical to the snapshot jnlp at the of processing.

Example:

"0.1.0-20090327.222627"


126
127
128
# File 'lib/jnlp/maven_jnlp.rb', line 126

def snapshot_version
  @snapshot_version
end

#urlObject (readonly)

Contains the root url for this family of jnlps

Example:

"http://jnlp.concord.org/dev/org/concord/maven-jnlp/all-otrunk-snapshot"


104
105
106
# File 'lib/jnlp/maven_jnlp.rb', line 104

def url
  @url
end

#versionsObject (readonly)

Contains an array of VersionedJnlpUrls



116
117
118
# File 'lib/jnlp/maven_jnlp.rb', line 116

def versions
  @versions
end

Instance Method Details

#latest_snapshot_versionObject



175
176
177
# File 'lib/jnlp/maven_jnlp.rb', line 175

def latest_snapshot_version
  open("#{@url}/#{@name}-CURRENT_VERSION.txt").read
end

#updateObject



171
172
173
# File 'lib/jnlp/maven_jnlp.rb', line 171

def update
  
end