rakelib/support.rb
author Jan Vrany <jan.vrany@fit.cvut.cz>
Fri, 17 Jan 2020 21:37:47 +0000
changeset 289 c10f5a5b2e92
parent 288 2986b947d89f
child 322 d31ea885c8fa
permissions -rw-r--r--
Rakefiles: download binary stc and librun from SWING's plain http 'artifact repository' ...rather than from Jenkins as there's no longer publicly available Jenkins instance. This commit is based on an earlier version Patrik Svestka so credit goes to him! Thanks!
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
11
f7dc950d8df8 Automatically download pre-built librun and stc when sources are not available.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 10
diff changeset
     1
require 'net/http'
f7dc950d8df8 Automatically download pre-built librun and stc when sources are not available.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 10
diff changeset
     2
require 'net/https'
f7dc950d8df8 Automatically download pre-built librun and stc when sources are not available.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 10
diff changeset
     3
require 'json'
6
abb35e8d97a7 Add `bin` directory to PATH so build scripts may use scripts located there
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2
diff changeset
     4
require 'rakelib/extensions.rb'
abb35e8d97a7 Add `bin` directory to PATH so build scripts may use scripts located there
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2
diff changeset
     5
require 'rakelib/rbspec.rb'
60
57c963e85a00 Cleanup: Renamed `vcs.rb` & `Rake::StX::VCS` to `scm.rb` and `Rake::StX::SCM`
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 29
diff changeset
     6
require 'rakelib/scm.rb'
6
abb35e8d97a7 Add `bin` directory to PATH so build scripts may use scripts located there
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2
diff changeset
     7
2
d5cd0cfb84d5 Use regexp matching to parse NAME=VALUE pairs given as command line arguments
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 0
diff changeset
     8
# Following hack is required to allow passing variable
d5cd0cfb84d5 Use regexp matching to parse NAME=VALUE pairs given as command line arguments
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 0
diff changeset
     9
# values in `make` style, i.e., to allow for
d5cd0cfb84d5 Use regexp matching to parse NAME=VALUE pairs given as command line arguments
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 0
diff changeset
    10
#
d5cd0cfb84d5 Use regexp matching to parse NAME=VALUE pairs given as command line arguments
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 0
diff changeset
    11
#  rake PROJECT=stx:jv-branch compile
d5cd0cfb84d5 Use regexp matching to parse NAME=VALUE pairs given as command line arguments
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 0
diff changeset
    12
#
137
e665031cade7 Cleaning up code and having it more rubyish
Patrik Svestka <patrik.svestka@gmail.com>
parents: 102
diff changeset
    13
ARGV.each do |arg|
2
d5cd0cfb84d5 Use regexp matching to parse NAME=VALUE pairs given as command line arguments
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 0
diff changeset
    14
  name_and_value = /^([A-Za-z_]+)\w*=(.*)/.match(arg)
137
e665031cade7 Cleaning up code and having it more rubyish
Patrik Svestka <patrik.svestka@gmail.com>
parents: 102
diff changeset
    15
  self.class.const_set(name_and_value[1], name_and_value[2]) if name_and_value
2
d5cd0cfb84d5 Use regexp matching to parse NAME=VALUE pairs given as command line arguments
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 0
diff changeset
    16
end
d5cd0cfb84d5 Use regexp matching to parse NAME=VALUE pairs given as command line arguments
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 0
diff changeset
    17
23
7dad21b22558 Added support to build under MSYS2 environment
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 11
diff changeset
    18
# Update PATH for build so build scripts may access  scripts and programs 
7dad21b22558 Added support to build under MSYS2 environment
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 11
diff changeset
    19
# in `bin` directory. This is required especially on Windows as Windows do 
7dad21b22558 Added support to build under MSYS2 environment
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 11
diff changeset
    20
# not ship with some basic tools (e.g. zip) by default. As a courtesy to the
7dad21b22558 Added support to build under MSYS2 environment
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 11
diff changeset
    21
# user, provide our own. 
7dad21b22558 Added support to build under MSYS2 environment
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 11
diff changeset
    22
# NOTE that this MUST be the first entry in the PATH to be able to override
7dad21b22558 Added support to build under MSYS2 environment
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 11
diff changeset
    23
# MINGW/MSYS make.exe with Borland's ancient make.exe (sigh, St/X still deals
7dad21b22558 Added support to build under MSYS2 environment
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 11
diff changeset
    24
# with dinosaurs)
7dad21b22558 Added support to build under MSYS2 environment
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 11
diff changeset
    25
ENV['PATH'] = "#{File.expand_path('bin')};#{File::PATH_SEPARATOR}#{ENV['PATH']}"
0
f46260ba26b1 Initial shot of "new" rake-based builder
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    26
10
cb3e0e3ca28f Fixed repository specifications to allow anonymous checkout.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 9
diff changeset
    27
# Return true if running under Jenkins, false otherwise
cb3e0e3ca28f Fixed repository specifications to allow anonymous checkout.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 9
diff changeset
    28
def jenkins?
137
e665031cade7 Cleaning up code and having it more rubyish
Patrik Svestka <patrik.svestka@gmail.com>
parents: 102
diff changeset
    29
  (ENV.has_key? 'WORKSPACE' and
e665031cade7 Cleaning up code and having it more rubyish
Patrik Svestka <patrik.svestka@gmail.com>
parents: 102
diff changeset
    30
      ENV.has_key? 'JOB_NAME' and
e665031cade7 Cleaning up code and having it more rubyish
Patrik Svestka <patrik.svestka@gmail.com>
parents: 102
diff changeset
    31
      ENV.has_key? 'BUILD_ID')
11
f7dc950d8df8 Automatically download pre-built librun and stc when sources are not available.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 10
diff changeset
    32
end
f7dc950d8df8 Automatically download pre-built librun and stc when sources are not available.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 10
diff changeset
    33
f7dc950d8df8 Automatically download pre-built librun and stc when sources are not available.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 10
diff changeset
    34
# Returns true if and only if this is machine of one of the core developers
288
2986b947d89f Rakefiles: refactor Jenkins API for downloading (binary) artifacts
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 169
diff changeset
    35
# (currently only JV).
137
e665031cade7 Cleaning up code and having it more rubyish
Patrik Svestka <patrik.svestka@gmail.com>
parents: 102
diff changeset
    36
# Indeed this is a feeble check and can be easily bypassed by changing the
288
2986b947d89f Rakefiles: refactor Jenkins API for downloading (binary) artifacts
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 169
diff changeset
    37
# code or by setting a proper environment variable. But this should not hurt
2986b947d89f Rakefiles: refactor Jenkins API for downloading (binary) artifacts
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 169
diff changeset
    38
# much as in that case, unauthorized person wouldn't be able to connect to
2986b947d89f Rakefiles: refactor Jenkins API for downloading (binary) artifacts
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 169
diff changeset
    39
# stc and librun repository so the build will fail.
11
f7dc950d8df8 Automatically download pre-built librun and stc when sources are not available.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 10
diff changeset
    40
def core_developer?
f7dc950d8df8 Automatically download pre-built librun and stc when sources are not available.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 10
diff changeset
    41
  # JV's box: jv@..., vranyj1@...
102
fc572bd895f2 Cleanup: treat stx:stc & stx:librun as normal packages
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 88
diff changeset
    42
  user = ENV['USER'] || ENV['USERNAME']
137
e665031cade7 Cleaning up code and having it more rubyish
Patrik Svestka <patrik.svestka@gmail.com>
parents: 102
diff changeset
    43
  (user == 'jv') or (user == 'vranyj1') ? true : false
11
f7dc950d8df8 Automatically download pre-built librun and stc when sources are not available.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 10
diff changeset
    44
end
f7dc950d8df8 Automatically download pre-built librun and stc when sources are not available.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 10
diff changeset
    45
288
2986b947d89f Rakefiles: refactor Jenkins API for downloading (binary) artifacts
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 169
diff changeset
    46
# ArtifactRepository module provides API for downloading (binary) files from
2986b947d89f Rakefiles: refactor Jenkins API for downloading (binary) artifacts
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 169
diff changeset
    47
# some sort of - well - artifact repository. A repository contains multiple
2986b947d89f Rakefiles: refactor Jenkins API for downloading (binary) artifacts
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 169
diff changeset
    48
# builds (currently the API provides only access to `latestBuild()`), build
2986b947d89f Rakefiles: refactor Jenkins API for downloading (binary) artifacts
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 169
diff changeset
    49
# contains multipe `Artifact`s. An `Artifact` is essentially a downloadable
2986b947d89f Rakefiles: refactor Jenkins API for downloading (binary) artifacts
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 169
diff changeset
    50
# (binary) file.
2986b947d89f Rakefiles: refactor Jenkins API for downloading (binary) artifacts
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 169
diff changeset
    51
#
2986b947d89f Rakefiles: refactor Jenkins API for downloading (binary) artifacts
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 169
diff changeset
    52
# Currently only Jenkins-based repository is provided (see class `Jenkins`
2986b947d89f Rakefiles: refactor Jenkins API for downloading (binary) artifacts
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 169
diff changeset
    53
# within this module)
2986b947d89f Rakefiles: refactor Jenkins API for downloading (binary) artifacts
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 169
diff changeset
    54
module ArtifactRepository
2986b947d89f Rakefiles: refactor Jenkins API for downloading (binary) artifacts
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 169
diff changeset
    55
2986b947d89f Rakefiles: refactor Jenkins API for downloading (binary) artifacts
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 169
diff changeset
    56
  private
2986b947d89f Rakefiles: refactor Jenkins API for downloading (binary) artifacts
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 169
diff changeset
    57
2986b947d89f Rakefiles: refactor Jenkins API for downloading (binary) artifacts
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 169
diff changeset
    58
  # A private method to GET data over HTTP(S)
2986b947d89f Rakefiles: refactor Jenkins API for downloading (binary) artifacts
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 169
diff changeset
    59
  def self.get(uri, &block)
2986b947d89f Rakefiles: refactor Jenkins API for downloading (binary) artifacts
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 169
diff changeset
    60
    # http parameters
2986b947d89f Rakefiles: refactor Jenkins API for downloading (binary) artifacts
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 169
diff changeset
    61
    http_host = Net::HTTP.new(uri.host, uri.port)
2986b947d89f Rakefiles: refactor Jenkins API for downloading (binary) artifacts
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 169
diff changeset
    62
    http_host.use_ssl = (uri.scheme == 'https') # simple true enough
2986b947d89f Rakefiles: refactor Jenkins API for downloading (binary) artifacts
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 169
diff changeset
    63
2986b947d89f Rakefiles: refactor Jenkins API for downloading (binary) artifacts
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 169
diff changeset
    64
    if false # host verification not used (yet)
2986b947d89f Rakefiles: refactor Jenkins API for downloading (binary) artifacts
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 169
diff changeset
    65
      http_host.verify_mode = OpenSSL::SSL::VERIFY_PEER
2986b947d89f Rakefiles: refactor Jenkins API for downloading (binary) artifacts
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 169
diff changeset
    66
      http_host.cert_store = OpenSSL::X509::Store.new
2986b947d89f Rakefiles: refactor Jenkins API for downloading (binary) artifacts
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 169
diff changeset
    67
      http_host.cert_store.set_default_paths
2986b947d89f Rakefiles: refactor Jenkins API for downloading (binary) artifacts
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 169
diff changeset
    68
      http_host.cert_store.add_file('cacert.pem') # file downloaded from curl.haxx.se/ca/cacert.pem
2986b947d89f Rakefiles: refactor Jenkins API for downloading (binary) artifacts
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 169
diff changeset
    69
    else
2986b947d89f Rakefiles: refactor Jenkins API for downloading (binary) artifacts
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 169
diff changeset
    70
      http_host.verify_mode = OpenSSL::SSL::VERIFY_NONE
2986b947d89f Rakefiles: refactor Jenkins API for downloading (binary) artifacts
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 169
diff changeset
    71
    end
2986b947d89f Rakefiles: refactor Jenkins API for downloading (binary) artifacts
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 169
diff changeset
    72
2986b947d89f Rakefiles: refactor Jenkins API for downloading (binary) artifacts
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 169
diff changeset
    73
    # actual download
2986b947d89f Rakefiles: refactor Jenkins API for downloading (binary) artifacts
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 169
diff changeset
    74
    body = nil
2986b947d89f Rakefiles: refactor Jenkins API for downloading (binary) artifacts
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 169
diff changeset
    75
    http_host.start do |http|
2986b947d89f Rakefiles: refactor Jenkins API for downloading (binary) artifacts
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 169
diff changeset
    76
      http.request_get(uri) {|response| block ? (yield response) : (body = response.body)}
2986b947d89f Rakefiles: refactor Jenkins API for downloading (binary) artifacts
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 169
diff changeset
    77
    end
2986b947d89f Rakefiles: refactor Jenkins API for downloading (binary) artifacts
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 169
diff changeset
    78
    body
11
f7dc950d8df8 Automatically download pre-built librun and stc when sources are not available.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 10
diff changeset
    79
  end
f7dc950d8df8 Automatically download pre-built librun and stc when sources are not available.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 10
diff changeset
    80
288
2986b947d89f Rakefiles: refactor Jenkins API for downloading (binary) artifacts
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 169
diff changeset
    81
  public
2986b947d89f Rakefiles: refactor Jenkins API for downloading (binary) artifacts
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 169
diff changeset
    82
11
f7dc950d8df8 Automatically download pre-built librun and stc when sources are not available.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 10
diff changeset
    83
  class Artifact
f7dc950d8df8 Automatically download pre-built librun and stc when sources are not available.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 10
diff changeset
    84
    attr_reader :name
f7dc950d8df8 Automatically download pre-built librun and stc when sources are not available.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 10
diff changeset
    85
    attr_reader :uri
f7dc950d8df8 Automatically download pre-built librun and stc when sources are not available.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 10
diff changeset
    86
f7dc950d8df8 Automatically download pre-built librun and stc when sources are not available.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 10
diff changeset
    87
    def initialize(name, uri)
f7dc950d8df8 Automatically download pre-built librun and stc when sources are not available.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 10
diff changeset
    88
      @name = name
f7dc950d8df8 Automatically download pre-built librun and stc when sources are not available.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 10
diff changeset
    89
      @uri = uri
f7dc950d8df8 Automatically download pre-built librun and stc when sources are not available.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 10
diff changeset
    90
    end
f7dc950d8df8 Automatically download pre-built librun and stc when sources are not available.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 10
diff changeset
    91
137
e665031cade7 Cleaning up code and having it more rubyish
Patrik Svestka <patrik.svestka@gmail.com>
parents: 102
diff changeset
    92
    def download_to(destination)
e665031cade7 Cleaning up code and having it more rubyish
Patrik Svestka <patrik.svestka@gmail.com>
parents: 102
diff changeset
    93
      if !File.exist? destination
e665031cade7 Cleaning up code and having it more rubyish
Patrik Svestka <patrik.svestka@gmail.com>
parents: 102
diff changeset
    94
        raise Exception.new("Invalid destination for download: #{destination}") unless File.directory? File.dirname(destination)
11
f7dc950d8df8 Automatically download pre-built librun and stc when sources are not available.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 10
diff changeset
    95
      else
137
e665031cade7 Cleaning up code and having it more rubyish
Patrik Svestka <patrik.svestka@gmail.com>
parents: 102
diff changeset
    96
        if !File.directory? destination
11
f7dc950d8df8 Automatically download pre-built librun and stc when sources are not available.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 10
diff changeset
    97
          raise Exception.new("Invalid destination for download: #{destination}")
f7dc950d8df8 Automatically download pre-built librun and stc when sources are not available.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 10
diff changeset
    98
        else
f7dc950d8df8 Automatically download pre-built librun and stc when sources are not available.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 10
diff changeset
    99
          destination = File.join(destination, @name)
f7dc950d8df8 Automatically download pre-built librun and stc when sources are not available.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 10
diff changeset
   100
        end
f7dc950d8df8 Automatically download pre-built librun and stc when sources are not available.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 10
diff changeset
   101
      end
288
2986b947d89f Rakefiles: refactor Jenkins API for downloading (binary) artifacts
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 169
diff changeset
   102
      ArtifactRepository::get(@uri) do |response|
137
e665031cade7 Cleaning up code and having it more rubyish
Patrik Svestka <patrik.svestka@gmail.com>
parents: 102
diff changeset
   103
        File.open(destination, 'wb') do |file|
e665031cade7 Cleaning up code and having it more rubyish
Patrik Svestka <patrik.svestka@gmail.com>
parents: 102
diff changeset
   104
          response.read_body {|part| file.write part}
11
f7dc950d8df8 Automatically download pre-built librun and stc when sources are not available.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 10
diff changeset
   105
        end
f7dc950d8df8 Automatically download pre-built librun and stc when sources are not available.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 10
diff changeset
   106
      end
f7dc950d8df8 Automatically download pre-built librun and stc when sources are not available.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 10
diff changeset
   107
    end
f7dc950d8df8 Automatically download pre-built librun and stc when sources are not available.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 10
diff changeset
   108
  end
f7dc950d8df8 Automatically download pre-built librun and stc when sources are not available.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 10
diff changeset
   109
288
2986b947d89f Rakefiles: refactor Jenkins API for downloading (binary) artifacts
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 169
diff changeset
   110
  # Jenkins-based artifact repository.
2986b947d89f Rakefiles: refactor Jenkins API for downloading (binary) artifacts
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 169
diff changeset
   111
  class Jenkins
11
f7dc950d8df8 Automatically download pre-built librun and stc when sources are not available.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 10
diff changeset
   112
f7dc950d8df8 Automatically download pre-built librun and stc when sources are not available.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 10
diff changeset
   113
    def initialize(uri)
f7dc950d8df8 Automatically download pre-built librun and stc when sources are not available.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 10
diff changeset
   114
      @uri = uri
288
2986b947d89f Rakefiles: refactor Jenkins API for downloading (binary) artifacts
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 169
diff changeset
   115
    end
2986b947d89f Rakefiles: refactor Jenkins API for downloading (binary) artifacts
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 169
diff changeset
   116
2986b947d89f Rakefiles: refactor Jenkins API for downloading (binary) artifacts
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 169
diff changeset
   117
    def latestBuild()
2986b947d89f Rakefiles: refactor Jenkins API for downloading (binary) artifacts
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 169
diff changeset
   118
      return Build.new(@uri + '/lastStableBuild')
11
f7dc950d8df8 Automatically download pre-built librun and stc when sources are not available.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 10
diff changeset
   119
    end
f7dc950d8df8 Automatically download pre-built librun and stc when sources are not available.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 10
diff changeset
   120
288
2986b947d89f Rakefiles: refactor Jenkins API for downloading (binary) artifacts
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 169
diff changeset
   121
    class Build
2986b947d89f Rakefiles: refactor Jenkins API for downloading (binary) artifacts
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 169
diff changeset
   122
      attr_reader :data
2986b947d89f Rakefiles: refactor Jenkins API for downloading (binary) artifacts
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 169
diff changeset
   123
      attr_reader :uri
2986b947d89f Rakefiles: refactor Jenkins API for downloading (binary) artifacts
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 169
diff changeset
   124
2986b947d89f Rakefiles: refactor Jenkins API for downloading (binary) artifacts
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 169
diff changeset
   125
      def initialize(uri)
2986b947d89f Rakefiles: refactor Jenkins API for downloading (binary) artifacts
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 169
diff changeset
   126
        @uri = uri
2986b947d89f Rakefiles: refactor Jenkins API for downloading (binary) artifacts
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 169
diff changeset
   127
        @data = JSON.parse(ArtifactRepository::get(URI(uri.to_s + '/api/json')))
11
f7dc950d8df8 Automatically download pre-built librun and stc when sources are not available.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 10
diff changeset
   128
      end
f7dc950d8df8 Automatically download pre-built librun and stc when sources are not available.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 10
diff changeset
   129
288
2986b947d89f Rakefiles: refactor Jenkins API for downloading (binary) artifacts
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 169
diff changeset
   130
      # Return a list of artifacts (as instances of `ArtifactRepository::Artifact`) 
2986b947d89f Rakefiles: refactor Jenkins API for downloading (binary) artifacts
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 169
diff changeset
   131
      # associated with this build. 
2986b947d89f Rakefiles: refactor Jenkins API for downloading (binary) artifacts
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 169
diff changeset
   132
      def artifacts
2986b947d89f Rakefiles: refactor Jenkins API for downloading (binary) artifacts
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 169
diff changeset
   133
        unless @artifacts
2986b947d89f Rakefiles: refactor Jenkins API for downloading (binary) artifacts
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 169
diff changeset
   134
          @artifacts = @data['artifacts'].collect {|each| Artifact.new(each['fileName'], URI(@uri.to_s + '/artifact/' + each['relativePath']))}
2986b947d89f Rakefiles: refactor Jenkins API for downloading (binary) artifacts
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 169
diff changeset
   135
        end
2986b947d89f Rakefiles: refactor Jenkins API for downloading (binary) artifacts
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 169
diff changeset
   136
        @artifacts
2986b947d89f Rakefiles: refactor Jenkins API for downloading (binary) artifacts
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 169
diff changeset
   137
      end
2986b947d89f Rakefiles: refactor Jenkins API for downloading (binary) artifacts
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 169
diff changeset
   138
    end # class ArtifactRepository::Jenkins::Build
2986b947d89f Rakefiles: refactor Jenkins API for downloading (binary) artifacts
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 169
diff changeset
   139
  end # class ArtifactRepository::Jenkins
289
c10f5a5b2e92 Rakefiles: download binary stc and librun from SWING's plain http 'artifact repository'
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 288
diff changeset
   140
c10f5a5b2e92 Rakefiles: download binary stc and librun from SWING's plain http 'artifact repository'
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 288
diff changeset
   141
  class PlainHTTPListing
c10f5a5b2e92 Rakefiles: download binary stc and librun from SWING's plain http 'artifact repository'
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 288
diff changeset
   142
c10f5a5b2e92 Rakefiles: download binary stc and librun from SWING's plain http 'artifact repository'
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 288
diff changeset
   143
    def initialize(uri)
c10f5a5b2e92 Rakefiles: download binary stc and librun from SWING's plain http 'artifact repository'
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 288
diff changeset
   144
      @uri = uri
c10f5a5b2e92 Rakefiles: download binary stc and librun from SWING's plain http 'artifact repository'
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 288
diff changeset
   145
      @html_data = Net::HTTP.get(URI(uri))
c10f5a5b2e92 Rakefiles: download binary stc and librun from SWING's plain http 'artifact repository'
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 288
diff changeset
   146
    end
c10f5a5b2e92 Rakefiles: download binary stc and librun from SWING's plain http 'artifact repository'
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 288
diff changeset
   147
c10f5a5b2e92 Rakefiles: download binary stc and librun from SWING's plain http 'artifact repository'
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 288
diff changeset
   148
    def latestBuild()
c10f5a5b2e92 Rakefiles: download binary stc and librun from SWING's plain http 'artifact repository'
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 288
diff changeset
   149
      return Build.new(@uri + latest_build + '/') # dont forget trailing '/'!
c10f5a5b2e92 Rakefiles: download binary stc and librun from SWING's plain http 'artifact repository'
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 288
diff changeset
   150
    end
c10f5a5b2e92 Rakefiles: download binary stc and librun from SWING's plain http 'artifact repository'
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 288
diff changeset
   151
c10f5a5b2e92 Rakefiles: download binary stc and librun from SWING's plain http 'artifact repository'
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 288
diff changeset
   152
    class Build
c10f5a5b2e92 Rakefiles: download binary stc and librun from SWING's plain http 'artifact repository'
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 288
diff changeset
   153
      attr_reader :uri, :html_data
c10f5a5b2e92 Rakefiles: download binary stc and librun from SWING's plain http 'artifact repository'
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 288
diff changeset
   154
c10f5a5b2e92 Rakefiles: download binary stc and librun from SWING's plain http 'artifact repository'
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 288
diff changeset
   155
      def initialize(uri)
c10f5a5b2e92 Rakefiles: download binary stc and librun from SWING's plain http 'artifact repository'
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 288
diff changeset
   156
        @uri = uri
c10f5a5b2e92 Rakefiles: download binary stc and librun from SWING's plain http 'artifact repository'
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 288
diff changeset
   157
        @html_data = Net::HTTP.get(URI(uri))
c10f5a5b2e92 Rakefiles: download binary stc and librun from SWING's plain http 'artifact repository'
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 288
diff changeset
   158
      end
c10f5a5b2e92 Rakefiles: download binary stc and librun from SWING's plain http 'artifact repository'
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 288
diff changeset
   159
c10f5a5b2e92 Rakefiles: download binary stc and librun from SWING's plain http 'artifact repository'
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 288
diff changeset
   160
      def artifacts
c10f5a5b2e92 Rakefiles: download binary stc and librun from SWING's plain http 'artifact repository'
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 288
diff changeset
   161
        unless @artifacts
c10f5a5b2e92 Rakefiles: download binary stc and librun from SWING's plain http 'artifact repository'
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 288
diff changeset
   162
          # get latest build file list
c10f5a5b2e92 Rakefiles: download binary stc and librun from SWING's plain http 'artifact repository'
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 288
diff changeset
   163
          @artifacts = lastest_build_files(Array.new, String.new).collect {|each_file| Artifact.new(each_file, URI(@uri + each_file))} 
c10f5a5b2e92 Rakefiles: download binary stc and librun from SWING's plain http 'artifact repository'
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 288
diff changeset
   164
        end
c10f5a5b2e92 Rakefiles: download binary stc and librun from SWING's plain http 'artifact repository'
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 288
diff changeset
   165
        @artifacts
c10f5a5b2e92 Rakefiles: download binary stc and librun from SWING's plain http 'artifact repository'
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 288
diff changeset
   166
      end
c10f5a5b2e92 Rakefiles: download binary stc and librun from SWING's plain http 'artifact repository'
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 288
diff changeset
   167
c10f5a5b2e92 Rakefiles: download binary stc and librun from SWING's plain http 'artifact repository'
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 288
diff changeset
   168
      private
c10f5a5b2e92 Rakefiles: download binary stc and librun from SWING's plain http 'artifact repository'
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 288
diff changeset
   169
c10f5a5b2e92 Rakefiles: download binary stc and librun from SWING's plain http 'artifact repository'
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 288
diff changeset
   170
      # parse HTML via regexp (yes, bad idea but Apache can't serve natively JSON)
c10f5a5b2e92 Rakefiles: download binary stc and librun from SWING's plain http 'artifact repository'
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 288
diff changeset
   171
      # retuns Array of String(s) - filenames and their suffixes
c10f5a5b2e92 Rakefiles: download binary stc and librun from SWING's plain http 'artifact repository'
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 288
diff changeset
   172
      def parse_html_directories(html_build_directory_list)
c10f5a5b2e92 Rakefiles: download binary stc and librun from SWING's plain http 'artifact repository'
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 288
diff changeset
   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)/)
c10f5a5b2e92 Rakefiles: download binary stc and librun from SWING's plain http 'artifact repository'
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 288
diff changeset
   174
        files_and_suffixes.flatten
c10f5a5b2e92 Rakefiles: download binary stc and librun from SWING's plain http 'artifact repository'
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 288
diff changeset
   175
      end
c10f5a5b2e92 Rakefiles: download binary stc and librun from SWING's plain http 'artifact repository'
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 288
diff changeset
   176
c10f5a5b2e92 Rakefiles: download binary stc and librun from SWING's plain http 'artifact repository'
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 288
diff changeset
   177
      # create file array where the file part and its suffix will be merged together
c10f5a5b2e92 Rakefiles: download binary stc and librun from SWING's plain http 'artifact repository'
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 288
diff changeset
   178
      # returns Array of String filenames without any duplicities (needed due to HTML nature (a href))
c10f5a5b2e92 Rakefiles: download binary stc and librun from SWING's plain http 'artifact repository'
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 288
diff changeset
   179
      def lastest_build_files(stx_latest_build_files, stx_file)  
c10f5a5b2e92 Rakefiles: download binary stc and librun from SWING's plain http 'artifact repository'
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 288
diff changeset
   180
        parse_html_directories(@html_data).each do |file_part|
c10f5a5b2e92 Rakefiles: download binary stc and librun from SWING's plain http 'artifact repository'
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 288
diff changeset
   181
          if file_part.match(/\.$/) # only a file_part has a . at the end
c10f5a5b2e92 Rakefiles: download binary stc and librun from SWING's plain http 'artifact repository'
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 288
diff changeset
   182
            stx_latest_build_files.push(stx_file) unless stx_file.empty? 
c10f5a5b2e92 Rakefiles: download binary stc and librun from SWING's plain http 'artifact repository'
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 288
diff changeset
   183
            stx_file = String.new  # empty current String content
c10f5a5b2e92 Rakefiles: download binary stc and librun from SWING's plain http 'artifact repository'
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 288
diff changeset
   184
            stx_file = file_part
c10f5a5b2e92 Rakefiles: download binary stc and librun from SWING's plain http 'artifact repository'
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 288
diff changeset
   185
          else 
c10f5a5b2e92 Rakefiles: download binary stc and librun from SWING's plain http 'artifact repository'
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 288
diff changeset
   186
            stx_file = stx_file + file_part
c10f5a5b2e92 Rakefiles: download binary stc and librun from SWING's plain http 'artifact repository'
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 288
diff changeset
   187
          end
c10f5a5b2e92 Rakefiles: download binary stc and librun from SWING's plain http 'artifact repository'
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 288
diff changeset
   188
        end
c10f5a5b2e92 Rakefiles: download binary stc and librun from SWING's plain http 'artifact repository'
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 288
diff changeset
   189
        # prune (duplicities)
c10f5a5b2e92 Rakefiles: download binary stc and librun from SWING's plain http 'artifact repository'
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 288
diff changeset
   190
        stx_latest_build_files.uniq!
c10f5a5b2e92 Rakefiles: download binary stc and librun from SWING's plain http 'artifact repository'
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 288
diff changeset
   191
      end
c10f5a5b2e92 Rakefiles: download binary stc and librun from SWING's plain http 'artifact repository'
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 288
diff changeset
   192
c10f5a5b2e92 Rakefiles: download binary stc and librun from SWING's plain http 'artifact repository'
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 288
diff changeset
   193
    end # class ArtifactRepository::PlainHTTPListing::Build
c10f5a5b2e92 Rakefiles: download binary stc and librun from SWING's plain http 'artifact repository'
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 288
diff changeset
   194
c10f5a5b2e92 Rakefiles: download binary stc and librun from SWING's plain http 'artifact repository'
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 288
diff changeset
   195
    private
c10f5a5b2e92 Rakefiles: download binary stc and librun from SWING's plain http 'artifact repository'
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 288
diff changeset
   196
c10f5a5b2e92 Rakefiles: download binary stc and librun from SWING's plain http 'artifact repository'
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 288
diff changeset
   197
    # find newest build contains date: yyyy-mm-dd_buildId
c10f5a5b2e92 Rakefiles: download binary stc and librun from SWING's plain http 'artifact repository'
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 288
diff changeset
   198
    def latest_build
c10f5a5b2e92 Rakefiles: download binary stc and librun from SWING's plain http 'artifact repository'
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 288
diff changeset
   199
      directory_list.max
c10f5a5b2e92 Rakefiles: download binary stc and librun from SWING's plain http 'artifact repository'
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 288
diff changeset
   200
    end
c10f5a5b2e92 Rakefiles: download binary stc and librun from SWING's plain http 'artifact repository'
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 288
diff changeset
   201
c10f5a5b2e92 Rakefiles: download binary stc and librun from SWING's plain http 'artifact repository'
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 288
diff changeset
   202
    # get Array of directories
c10f5a5b2e92 Rakefiles: download binary stc and librun from SWING's plain http 'artifact repository'
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 288
diff changeset
   203
    def directory_list
c10f5a5b2e92 Rakefiles: download binary stc and librun from SWING's plain http 'artifact repository'
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 288
diff changeset
   204
      directories=@html_data.scan(/\d{4}-\d{2}-\d{2}_\d+/)
c10f5a5b2e92 Rakefiles: download binary stc and librun from SWING's plain http 'artifact repository'
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 288
diff changeset
   205
      directories.uniq! # remove duplicates
c10f5a5b2e92 Rakefiles: download binary stc and librun from SWING's plain http 'artifact repository'
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 288
diff changeset
   206
    end
c10f5a5b2e92 Rakefiles: download binary stc and librun from SWING's plain http 'artifact repository'
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 288
diff changeset
   207
c10f5a5b2e92 Rakefiles: download binary stc and librun from SWING's plain http 'artifact repository'
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 288
diff changeset
   208
  end # class ArtifactRepository::PlainHTTPListing
c10f5a5b2e92 Rakefiles: download binary stc and librun from SWING's plain http 'artifact repository'
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 288
diff changeset
   209
288
2986b947d89f Rakefiles: refactor Jenkins API for downloading (binary) artifacts
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 169
diff changeset
   210
end # module ArtifactRepository