135 end |
135 end |
136 @artifacts |
136 @artifacts |
137 end |
137 end |
138 end # class ArtifactRepository::Jenkins::Build |
138 end # class ArtifactRepository::Jenkins::Build |
139 end # class ArtifactRepository::Jenkins |
139 end # class ArtifactRepository::Jenkins |
|
140 |
|
141 class PlainHTTPListing |
|
142 |
|
143 def initialize(uri) |
|
144 @uri = uri |
|
145 @html_data = Net::HTTP.get(URI(uri)) |
|
146 end |
|
147 |
|
148 def latestBuild() |
|
149 return Build.new(@uri + latest_build + '/') # dont forget trailing '/'! |
|
150 end |
|
151 |
|
152 class Build |
|
153 attr_reader :uri, :html_data |
|
154 |
|
155 def initialize(uri) |
|
156 @uri = uri |
|
157 @html_data = Net::HTTP.get(URI(uri)) |
|
158 end |
|
159 |
|
160 def artifacts |
|
161 unless @artifacts |
|
162 # get latest build file list |
|
163 @artifacts = lastest_build_files(Array.new, String.new).collect {|each_file| Artifact.new(each_file, URI(@uri + each_file))} |
|
164 end |
|
165 @artifacts |
|
166 end |
|
167 |
|
168 private |
|
169 |
|
170 # parse HTML via regexp (yes, bad idea but Apache can't serve natively JSON) |
|
171 # retuns Array of String(s) - filenames and their suffixes |
|
172 def parse_html_directories(html_build_directory_list) |
|
173 files_and_suffixes = html_build_directory_list.scan(/(smalltalkx-jv-branch-\d+.\d+.\d+_build\d+[a-zA-Z0-9_\-]+\.|tar\.bz2|zip|7z|7zip|\.sha256|\.sha512)/) |
|
174 files_and_suffixes.flatten |
|
175 end |
|
176 |
|
177 # create file array where the file part and its suffix will be merged together |
|
178 # returns Array of String filenames without any duplicities (needed due to HTML nature (a href)) |
|
179 def lastest_build_files(stx_latest_build_files, stx_file) |
|
180 parse_html_directories(@html_data).each do |file_part| |
|
181 if file_part.match(/\.$/) # only a file_part has a . at the end |
|
182 stx_latest_build_files.push(stx_file) unless stx_file.empty? |
|
183 stx_file = String.new # empty current String content |
|
184 stx_file = file_part |
|
185 else |
|
186 stx_file = stx_file + file_part |
|
187 end |
|
188 end |
|
189 # prune (duplicities) |
|
190 stx_latest_build_files.uniq! |
|
191 end |
|
192 |
|
193 end # class ArtifactRepository::PlainHTTPListing::Build |
|
194 |
|
195 private |
|
196 |
|
197 # find newest build contains date: yyyy-mm-dd_buildId |
|
198 def latest_build |
|
199 directory_list.max |
|
200 end |
|
201 |
|
202 # get Array of directories |
|
203 def directory_list |
|
204 directories=@html_data.scan(/\d{4}-\d{2}-\d{2}_\d+/) |
|
205 directories.uniq! # remove duplicates |
|
206 end |
|
207 |
|
208 end # class ArtifactRepository::PlainHTTPListing |
|
209 |
140 end # module ArtifactRepository |
210 end # module ArtifactRepository |