Class Raven::Maven2Repository
In: lib/raven/repo_builder.rb
Parent: Object

Enumerates on a Maven repository by scraping HTML. Yields on every artifact found in there.

Methods

each   group_filters   new   read_page  

Constants

EXCLUDE = ["sha1", "md5", "pom"]

Attributes

group_filters  [W] 

Public Class methods

[Source]

    # File lib/raven/repo_builder.rb, line 64
64:     def initialize(server, port, url, proxy_info)
65:       @server, @url, @port, @proxy_info = server, url, port, proxy_info
66:     end

Public Instance methods

[Source]

    # File lib/raven/repo_builder.rb, line 68
68:     def each
69:       if @proxy_info
70:         http = Net::HTTP::Proxy(*@proxy_info).new(@server, @port)
71:       else
72:         http = Net::HTTP.new(@server, @port)
73:       end
74:       folder_regexp = /<img src="\/icons\/folder.gif" alt="\[DIR\]"> <a href="[^\/]*\/">/
75:       file_regexp = /<img src="\/icons\/unknown.gif" alt="\[   \]"> <a href="[^"]*">/
76:       read_page(http, @url, folder_regexp) do |url1, groupId|
77:         if @group_filters.nil? || @group_filters.include?(groupId)
78:           puts "#{groupId}"
79:           read_page(http, url1 + groupId + '/', folder_regexp) do |url2, artifactId|
80:             puts "  #{artifactId}"
81:             read_page(http, url2 + artifactId + '/', folder_regexp) do |url3, versionId|
82:               puts "    #{versionId}"
83:               art_path = "#{groupId}/#{artifactId}/#{versionId}/#{artifactId}-#{versionId}.jar"
84:               artifact = Raven::Artifact.new(groupId, artifactId, versionId, art_path)
85:               yield(artifact, http)
86:               
87:               # Check each file if someday we want to package sources files or javadoc as well...

88:               # read_page(http, url3 + versionId + '/', file_regexp, 52, 3) do |url4, filename|

89:               #   type = filename[(filename.rindex('.') + 1)..filename.length]

90:               # end

91:             end
92:           end
93:         end
94:       end
95:     end

[Source]

    # File lib/raven/repo_builder.rb, line 60
60:     def group_filters
61:       @group_filters
62:     end

[Source]

     # File lib/raven/repo_builder.rb, line 97
 97:     def read_page(http, url, regexp, start=51, crop=4)
 98:       response = http.get(url, nil)
 99:       if response.is_a? Net::HTTPSuccess
100:         response.body.scan(regexp) do |line|
101:           groupId = line[start..(line.length - crop)]
102:           yield(url, groupId)
103:         end
104:       else
105:         STDERR.puts "Error connecting to repository: #{response.message}"
106:         if response.is_a?(Net::HTTPRedirection) && response["location"]
107:           puts "Location: #{response['location']}"
108:         else
109:           puts "------ RESPONSE CODE -----------------------------"
110:           puts "Response code: #{response.code}"
111:           puts "------ HEADERS -----------------------------------"
112:           response.each_header do |key, value|
113:             puts "#{key}: #{value}"
114:           end
115:           puts "------ CONTENT -----------------------------------"
116:           puts response.body
117:           puts '-' * 50
118:         end
119:       end
120:     end

[Validate]