--- a/rakelib/support.rb Mon Mar 06 21:21:07 2017 +0000
+++ b/rakelib/support.rb Fri Aug 11 09:23:06 2017 +0200
@@ -10,11 +10,9 @@
#
# rake PROJECT=stx:jv-branch compile
#
-ARGV.each do | arg |
+ARGV.each do |arg|
name_and_value = /^([A-Za-z_]+)\w*=(.*)/.match(arg)
- if name_and_value
- self.class.const_set(name_and_value[1], name_and_value[2])
- end
+ self.class.const_set(name_and_value[1], name_and_value[2]) if name_and_value
end
# Update PATH for build so build scripts may access scripts and programs
@@ -28,38 +26,35 @@
# Return true if running under Jenkins, false otherwise
def jenkins?
- return (ENV.has_key? 'WORKSPACE' and
- ENV.has_key? 'JOB_NAME' and
- ENV.has_key? 'BUILD_ID')
+ (ENV.has_key? 'WORKSPACE' and
+ ENV.has_key? 'JOB_NAME' and
+ ENV.has_key? 'BUILD_ID')
end
# Returns true if and only if this is machine of one of the core developers
# (currently only JV).
-# Indeed this is a feeble check and can be easily bypassed by chaning the
+# Indeed this is a feeble check and can be easily bypassed by changing the
# code or by setting a proper environment variable. But this should not hurt
# much as in that case, unauthorized person wouldn't be able to connect to
# stc and librun repository so the build will fail.
def core_developer?
# JV's box: jv@..., vranyj1@...
user = ENV['USER'] || ENV['USERNAME']
- if (user == 'jv') or (user == 'vranyj1')
- return true
- end
- return false
+ (user == 'jv') or (user == 'vranyj1') ? true : false
end
# A super simple API for Jenkins used to download pre-built stc and librun.
module Jenkins
# Return an a Jenkins build with pre-built stc and librun.
# Used to download pre-build stc and librun
- def self.smalltalkx_jv_branch_build()
+ def self.smalltalkx_jv_branch_build
plat = nil
- if win32? then
- plat = 'Windows'
- elsif linux?
+ if win32?
+ plat = 'Windows'
+ elsif linux?
plat = 'Linux'
- else
- error_unsupported_platform()
+ else
+ error_unsupported_platform
end
return Jenkins::Build.new(%Q{https://swing.fit.cvut.cz/jenkins/job/stx_jv/ARCH=#{ARCH},PLATFORM=#{plat}N/lastSuccessfulBuild})
end
@@ -73,23 +68,19 @@
@uri = uri
end
- def download_to(destination)
- if not File.exist? destination
- if not File.directory? File.dirname(destination)
- raise Exception.new("Invalid destination for download: #{destination}")
- end
+ def download_to(destination)
+ if !File.exist? destination
+ raise Exception.new("Invalid destination for download: #{destination}") unless File.directory? File.dirname(destination)
else
- if not File.directory? destination
+ if !File.directory? destination
raise Exception.new("Invalid destination for download: #{destination}")
else
destination = File.join(destination, @name)
end
end
- Jenkins::get(@uri) do | response |
- File.open(destination, "wb") do | file |
- response.read_body do | part |
- file.write part
- end
+ Jenkins::get(@uri) do |response|
+ File.open(destination, 'wb') do |file|
+ response.read_body {|part| file.write part}
end
end
end
@@ -106,18 +97,16 @@
# Return a list of artifacts (as instances of `Jenkins::Artifact`)
# associated with this build.
- def artifacts()
- if not @artifacts then
- @artifacts = @data["artifacts"].collect do | each |
- Artifact.new(each['fileName'], URI(@uri.to_s + '/artifact/' + each['relativePath']))
- end
+ def artifacts
+ unless @artifacts
+ @artifacts = @data['artifacts'].collect {|each| Artifact.new(each['fileName'], URI(@uri.to_s + '/artifact/' + each['relativePath']))}
end
- return @artifacts
+ @artifacts
end
end
# A private method to GET data over HTTP(S)
- def self.get(uri, &block)
+ def self.get(uri, &block)
# http parameters
http_host = Net::HTTP.new(uri.host, uri.port)
http_host.use_ssl = (uri.scheme == 'https') # simple true enough
@@ -133,15 +122,9 @@
# actual download
body = nil
- http_host.start do | http |
- http.request_get(uri) do | response |
- if block then
- yield response
- else
- body = response.body
- end
- end
+ http_host.start do |http|
+ http.request_get(uri) {|response| block ? (yield response) : (body = response.body)}
end
- return body
+ body
end
end
\ No newline at end of file