Class: Pushwagner::Maven::Repository
- Inherits:
-
Object
- Object
- Pushwagner::Maven::Repository
- Defined in:
- lib/pushwagner/maven.rb
Instance Attribute Summary collapse
-
#releases_url ⇒ Object
readonly
Returns the value of attribute releases_url.
-
#snapshots_url ⇒ Object
readonly
Returns the value of attribute snapshots_url.
Instance Method Summary collapse
- #absolute_url(artifact) ⇒ Object
- #authentication(snapshots = false) ⇒ Object
-
#initialize(repositories) ⇒ Repository
constructor
A new instance of Repository.
- #required(exp, message) ⇒ Object
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_url ⇒ Object (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_url ⇒ Object (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
96 97 98 |
# File 'lib/pushwagner/maven.rb', line 96 def required(exp, ) raise StandardError.new() unless exp end |