# -------------------------------------------------------------------------- #
# Copyright 2002-2026, OpenNebula Project, OpenNebula Systems                #
#                                                                            #
# Licensed under the Apache License, Version 2.0 (the "License"); you may    #
# not use this file except in compliance with the License. You may obtain    #
# a copy of the License at                                                   #
#                                                                            #
# http://www.apache.org/licenses/LICENSE-2.0                                 #
#                                                                            #
# Unless required by applicable law or agreed to in writing, software        #
# distributed under the License is distributed on an "AS IS" BASIS,          #
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.   #
# See the License for the specific language governing permissions and        #
# limitations under the License.                                             #
#--------------------------------------------------------------------------- #

################################################################################
# Defaults
################################################################################

ruby '>=2.0.0', '<4'
source 'https://rubygems.org'
ruby_version = Gem::Version.new(RUBY_VERSION)
rubygems_version = Gem::Version.new(`gem -v`)

debian_version_file = '/etc/debian_version'
is_lower_than_debian_13 = true
if File.exist?(debian_version_file)
    begin
        debian_version = Gem::Version.new(File.read(debian_version_file).strip)
        is_lower_than_debian_13 = debian_version < Gem::Version.new('13')
    rescue ArgumentError
        # Keep the default value of true if the version is not numeric (ubuntu)
    end
end

################################################################################
# Gems only in one ruby version
################################################################################

if ruby_version >= Gem::Version.new('2.4.0') && ruby_version < Gem::Version.new('3.3.0')
    gem 'xmlrpc'
elsif ruby_version >= Gem::Version.new('3.3.0')
    gem 'xmlrpc', '= 0.3.2'
end

if ruby_version < Gem::Version.new('2.1.0')
    gem 'scrub_rb'
end

if ruby_version < Gem::Version.new('2.6.0')
    gem 'unf', '< 0.2.0'
end

################################################################################
# gems groups
################################################################################

if ruby_version < Gem::Version.new('2.1.0')
    nokogiri = '< 1.7'
elsif ruby_version < Gem::Version.new('2.3.0')
    nokogiri = '< 1.10'
else
    if ruby_version >= Gem::Version.new('3.0.0') && rubygems_version < Gem::Version.new('3.3.22')
        nokogiri = '~> 1.17.2'
    end
end

if ruby_version < Gem::Version.new('2.1.0')
    ps = '< 3.0.0'
elsif ruby_version < Gem::Version.new('2.6.0')
    ps = '< 5.0.0'
elsif ruby_version < Gem::Version.new('3.0.0')
    ps = '< 6.0.0'
end

if ruby_version < Gem::Version.new('2.2.0')
    rack     = '< 2.0.0'
    minitest = '< 5.12.0'
end

if ruby_version < Gem::Version.new('2.3.0')
    zendesk = '< 1.17.0'
    rq      = '< 1.0.0'
end

if ruby_version <= Gem::Version.new('2.0.0')
    gem 'multipart-post', '~> 2.1.0'
end

if rubygems_version < Gem::Version.new('3.3.21')
    gem 'ffi', '< 1.17.0'
end

gem 'ffi-rzmq', '~> 2.0.7'
gem 'net-ldap'
gem 'nokogiri', nokogiri
gem 'public_suffix', ps
gem 'rexml'
gem 'aws-sdk-ec2', '>=1.151'
gem 'aws-sdk-s3'
gem 'grpc'
gem 'ruby-saml'

# Since Ruby 3.4 some common libraries were dropped
if ruby_version >= Gem::Version.new('3.4.0')
    gem 'getoptlong'
    gem 'syslog'
    gem 'mutex_m'
end

group :cli do
    gem 'csv' if ruby_version >= Gem::Version.new('3.4.0')
    gem 'gnuplot'
    gem 'highline', '~> 1.7'
    gem 'mysql2'

    if ruby_version < Gem::Version.new('3.0.0')
        gem 'sqlite3', '<= 1.6.9'
    elsif rubygems_version < Gem::Version.new('3.3.21')
        gem 'sqlite3', '<= 1.7.3'
    else
        gem 'sqlite3'
    end
    gem 'mini_portile2'
    gem 'sequel'
end

group :onecfg, :cli do
    gem 'ruby-augeas'
end

group :onecfg, :cloud, :oneflow, :oneform do
    gem 'json', '>= 2.0'
end

group :onecfg do
    gem 'git', '~> 1.5'
end

group :packethost do
    gem 'minitest', minitest
    if ruby_version >= Gem::Version.new('2.3.0')
        gem 'faraday_middleware', '~> 1.2.0'
    end
    gem 'activesupport', '~> 4.2'
    gem 'i18n', '~> 0.9'
end

group :cloud, :oneflow, :oneform, :oneks, :ods do
    gem 'rack', rack
    if ruby_version >= Gem::Version.new('3.0.0')
        gem 'sinatra'
        gem 'sinatra-contrib'
        gem 'puma'
        gem 'rackup'
    else
        gem 'sinatra', '< 4.0.0'
        gem 'sinatra-contrib', '< 4.0.0'
    end
end

group :cloud do
    if ruby_version < Gem::Version.new('3.0.0')
        gem 'thin', '~> 1.8.2'     # rack/thin 2.2.17 is incompatible with thin 2.0.0+
    end
    gem 'uuidtools'
    gem 'curb'
end

group :oneflow, :oneks, :ods do
    gem 'ipaddress', '~> 0.8.3'
    gem 'treetop', '>= 1.6.3'
    gem 'parse-cron'
end

group :oneform, :oneks, :ods do
    if ruby_version < Gem::Version.new('2.7.0')
        gem 'dry-validation', '~> 1.5.0'
    elsif ruby_version >= Gem::Version.new('3.1.0') && ruby_version < Gem::Version.new('3.2.0')
        # Ruby 3.1 mis-parses the anonymous block parameter (`def m(kw:, &)`)
        # used by dry-schema >= 1.14 (Ruby bug #18632, fixed in 3.2), so pin
        # the dry-schema/dry-validation pair to the last 1.13.x line.
        gem 'dry-validation', '~> 1.10.0'
        gem 'dry-schema', '~> 1.13.0'
    else
        gem 'dry-validation', '~> 1.10'
    end
    gem 'lockfile', '~> 2.1', '>= 2.1.3'
    gem 'hcl_parser', '~> 0.2.2'
end

group :oca do
    gem 'ox'
end

group :prometheus do
    gem 'prometheus-client'
end

group :tproxy do
    gem 'async-io', '= 1.32.1'
    gem 'console', '= 1.15.3'
end

group :oneswap do
    gem 'rbvmomi2'
end
