Class: Pushwagner::Maven::Repository

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(repositories) ⇒ Repository

Returns a new instance of Repository.



66
67
68
69
70
71
72
73
# File 'lib/pushwagner/maven.rb', line 66

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

Instance Attribute Details

#releases_urlObject (readonly)

Returns the value of attribute releases_url.



64
65
66
# File 'lib/pushwagner/maven.rb', line 64

def releases_url
  @releases_url
end

#snapshots_urlObject (readonly)

Returns the value of attribute snapshots_url.



63
64
65
# File 'lib/pushwagner/maven.rb', line 63

def snapshots_url
  @snapshots_url
end

Instance Method Details

#absolute_url(artifact) ⇒ Object



75
76
77
78
79
80
81
82
83
# File 'lib/pushwagner/maven.rb', line 75

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) ⇒ Object



85
86
87
88
89
90
91
92
93
94
# File 'lib/pushwagner/maven.rb', line 85

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) ⇒ Object

Raises:

  • (StandardError)


96
97
98
# File 'lib/pushwagner/maven.rb', line 96

def required(exp, message)
  raise StandardError.new(message) unless exp
end