class Pushwagner::Maven::Repository

Attributes

releases_url[R]
snapshots_url[R]

Public Class Methods

new(repositories) click to toggle source
# File lib/pushwagner/maven.rb, line 70
def initialize(repositories)
  required(repositories, "repositories configuration required")
  required(repositories['snapshots'], "snapshots repository required")
  required(repositories['releases'], "releases repository required")

  @snapshots_url = repositories['snapshots']
  @releases_url = repositories['releases']
end

Public Instance Methods

absolute_url(artifact) click to toggle source
# File lib/pushwagner/maven.rb, line 79
def absolute_url(artifact)
  if artifact.snapshot?
    doc = Nokogiri::XML(open(URI.parse("#{snapshots_url}/#{artifact.base_path}/maven-metadata.xml"), :http_basic_authentication => authentication(true).split(":")))
    snapshot_version = doc.xpath("//metadata/versioning/snapshotVersions/snapshotVersion/value/text()").first.content
    return "#{snapshots_url}/#{artifact.base_path}/#{artifact.artifact_id}-#{snapshot_version}.jar"
  end

  "#{releases_url}/#{artifact.jar_path}"
end
authentication(snapshots = false) click to toggle source
# File lib/pushwagner/maven.rb, line 89
def authentication(snapshots = false)
  @settings_file ||= ENV['M2_HOME'] ? "#{ENV['M2_HOME']}/conf/settings.xml" : "#{ENV['HOME']}/.m2/settings.xml"

  if File.exists?(@settings_file)
    Nokogiri::XML(open(@settings_file)).css("settings servers server").each do |n|
      return "#{n.css("username").text}:#{n.css("password").text}" if n.css("id").text == (snapshots ? 'snapshots' : 'releases')
    end
  end
  ""
end
required(exp, message) click to toggle source
# File lib/pushwagner/maven.rb, line 100
def required(exp, message)
  raise StandardError.new(message) unless exp
end