Class: Maven

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

Instance Method Summary collapse

Constructor Details

#initialize(url) ⇒ Maven

Returns a new instance of Maven.



12
13
14
15
16
17
# File 'lib/crapapult.rb', line 12

def initialize(url)
  @url = url.gsub(/\/$/, '')
  @session = Patron::Session.new
  @session.timeout = 10
  @session.base_url = @url
end

Instance Method Details

#find_release_versions(group_id, artifact_id) ⇒ Object



28
29
30
# File 'lib/crapapult.rb', line 28

def find_release_versions(group_id, artifact_id)
  find_versions(group_id, artifact_id).select { |v| v !~ /SNAPSHOT$/ }
end

#find_snapshot_builds(group_id, artifact_id, version) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/crapapult.rb', line 32

def find_snapshot_builds(group_id, artifact_id, version)
  resp = @session.get("/#{urlify(group_id)}/#{artifact_id}/#{version}/maven-metadata.xml")
  if resp.status == 200
    Nokogiri::XML(resp.body).css('metadata > versioning > snapshotVersions').map { |e|
      ext = e.at("extension")
      if ext && ext.text.strip == "jar"
        e.at("value").text.strip
      else
        []
      end
    }.flatten
  else
    raise "unable to find metadata for #{group_id}:#{artifact_id}:#{version}"
  end
end

#find_versions(group_id, artifact_id) ⇒ Object



19
20
21
22
23
24
25
26
# File 'lib/crapapult.rb', line 19

def find_versions(group_id, artifact_id)
  resp = @session.get("/#{urlify(group_id)}/#{artifact_id}/maven-metadata.xml")
  if resp.status == 200
    Nokogiri::XML(resp.body).css("metadata versioning versions version").map { |e| e.text.strip }
  else
    raise "unable to find metadata for #{group_id}:#{artifact_id}"
  end
end

#release_artifact_url(group_id, artifact_id, version) ⇒ Object



48
49
50
# File 'lib/crapapult.rb', line 48

def release_artifact_url(group_id, artifact_id, version)
  "#{@url}/#{urlify(group_id)}/#{artifact_id}/#{version}/#{artifact_id}-#{version}.jar"
end

#snapshot_artifact_url(group_id, artifact_id, version, build) ⇒ Object



52
53
54
# File 'lib/crapapult.rb', line 52

def snapshot_artifact_url(group_id, artifact_id, version, build)
  "#{@url}/#{urlify(group_id)}/#{artifact_id}/#{version}/#{artifact_id}-#{build}.jar"
end