@@ -66,59 +66,74 @@ def self.get(required_version, opts = {})
66
66
# Download the given version of the selenium-server-standalone jar.
67
67
#
68
68
69
- def self . download ( required_version )
70
- required_version = latest if required_version == :latest
71
- download_file_name = "selenium-server-standalone-#{ required_version } .jar"
69
+ class << self
70
+ def download ( required_version )
71
+ required_version = latest if required_version == :latest
72
+ download_file_name = "selenium-server-standalone-#{ required_version } .jar"
72
73
73
- if File . exists? download_file_name
74
- return download_file_name
75
- end
74
+ if File . exists? download_file_name
75
+ return download_file_name
76
+ end
76
77
77
- begin
78
- open ( download_file_name , "wb" ) do |destination |
79
- net_http . start ( "selenium-release.storage.googleapis.com" ) do |http |
80
- resp = http . request_get ( "/#{ required_version [ /(\d +\. \d +)\. / , 1 ] } /#{ download_file_name } " ) do |response |
81
- total = response . content_length
82
- progress = 0
83
- segment_count = 0
84
-
85
- response . read_body do |segment |
86
- progress += segment . length
87
- segment_count += 1
88
-
89
- if segment_count % 15 == 0
90
- percent = ( progress . to_f / total . to_f ) * 100
91
- print "#{ CL_RESET } Downloading #{ download_file_name } : #{ percent . to_i } % (#{ progress } / #{ total } )"
92
- segment_count = 0
78
+ begin
79
+ open ( download_file_name , "wb" ) do |destination |
80
+ net_http . start ( "selenium-release.storage.googleapis.com" ) do |http |
81
+ resp = http . request_get ( "/#{ required_version [ /(\d +\. \d +)\. / , 1 ] } /#{ download_file_name } " ) do |response |
82
+ total = response . content_length
83
+ progress = 0
84
+ segment_count = 0
85
+
86
+ response . read_body do |segment |
87
+ progress += segment . length
88
+ segment_count += 1
89
+
90
+ if segment_count % 15 == 0
91
+ percent = ( progress . to_f / total . to_f ) * 100
92
+ print "#{ CL_RESET } Downloading #{ download_file_name } : #{ percent . to_i } % (#{ progress } / #{ total } )"
93
+ segment_count = 0
94
+ end
95
+
96
+ destination . write ( segment )
93
97
end
94
-
95
- destination . write ( segment )
96
98
end
97
- end
98
99
99
- unless resp . kind_of? Net ::HTTPSuccess
100
- raise Error , "#{ resp . code } for #{ download_file_name } "
100
+ unless resp . kind_of? Net ::HTTPSuccess
101
+ raise Error , "#{ resp . code } for #{ download_file_name } "
102
+ end
101
103
end
102
104
end
105
+ rescue
106
+ FileUtils . rm download_file_name if File . exists? download_file_name
107
+ raise
103
108
end
104
- rescue
105
- FileUtils . rm download_file_name if File . exists? download_file_name
106
- raise
109
+
110
+ download_file_name
107
111
end
108
112
109
- download_file_name
110
- end
113
+ #
114
+ # Ask Google Code what the latest selenium-server-standalone version is.
115
+ #
111
116
112
- #
113
- # Ask Google Code what the latest selenium-server-standalone version is.
114
- #
117
+ def latest
118
+ require 'rexml/document'
119
+ net_http . start ( "selenium-release.storage.googleapis.com" ) do |http |
120
+ REXML ::Document . new ( http . get ( "/" ) . body ) . root . get_elements ( "//Contents/Key" ) . map { |e |
121
+ e . text [ /selenium-server-standalone-(\d +\. \d +\. \d +)\. jar/ , 1 ]
122
+ } . compact . max
123
+ end
124
+ end
125
+
126
+ def net_http
127
+ http_proxy = ENV [ 'http_proxy' ] || ENV [ 'HTTP_PROXY' ]
128
+
129
+ if http_proxy
130
+ http_proxy = "http://#{ http_proxy } " unless http_proxy . start_with? ( "http://" )
131
+ uri = URI . parse ( http_proxy )
115
132
116
- def self . latest
117
- require 'rexml/document'
118
- net_http . start ( "selenium-release.storage.googleapis.com" ) do |http |
119
- REXML ::Document . new ( http . get ( "/" ) . body ) . root . get_elements ( "//Contents/Key" ) . map { |e |
120
- e . text [ /selenium-server-standalone-(\d +\. \d +\. \d +)\. jar/ , 1 ]
121
- } . compact . max
133
+ Net ::HTTP ::Proxy ( uri . host , uri . port )
134
+ else
135
+ Net ::HTTP
136
+ end
122
137
end
123
138
end
124
139
@@ -204,19 +219,6 @@ def <<(arg)
204
219
205
220
private
206
221
207
- def self . net_http
208
- http_proxy = ENV [ 'http_proxy' ] || ENV [ 'HTTP_PROXY' ]
209
-
210
- if http_proxy
211
- http_proxy = "http://#{ http_proxy } " unless http_proxy . start_with? ( "http://" )
212
- uri = URI . parse ( http_proxy )
213
-
214
- Net ::HTTP ::Proxy ( uri . host , uri . port )
215
- else
216
- Net ::HTTP
217
- end
218
- end
219
-
220
222
def stop_process
221
223
return unless @process . alive?
222
224
0 commit comments