require "rake" require "dtc_rake/config" require "dtc_rake/ui" require "json" require "uu/os/uesuri" module DtcRake class Product include Singleton include DtcRake::UI # Appbox version specified in deployment descriptor. attr_reader :version # UESURI of the appbox artifact. attr_reader :appbox_uri attr_reader :gem_project, :cmd_project, :vuc_project, :dockerfiles_project attr_reader :has_gem, :has_cmd, :has_vuc, :has_dockerfiles attr_reader :gem_file_name, :cmd_file_name, :vuc_file_name, :yardoc_file_name, :dockerfiles_file_name attr_reader :gem_attachment_code, :cmd_attachment_code, :vuc_attachment_code, :yardoc_attachment_code, :dockerfiles_attachment_code def initialize config = Config.instance root_dir = config.root_dir sibling_dir_path = File.expand_path(File.join(root_dir, "../#{config.vendor}_#{config.app}")) @gem_project = sibling_dir_path @has_gem = File.directory?(@gem_project) @cmd_project = "#{sibling_dir_path}-cmd" @has_cmd = File.directory?(@cmd_project) @vuc_project = "#{sibling_dir_path}-vuc" @has_vuc = File.directory?(@vuc_project) @dockerfiles_project = File.expand_path(File.join(root_dir, "../docker")) @has_dockerfiles = File.directory?(@dockerfiles_project) end def app_descriptor return @app_descriptor if @app_descriptor File.open(Config.instance.app_descriptor_path, "r") do |f| @app_descriptor = JSON.parse(f.read, symbolize_names: true) end end def version app_descriptor[:data][:version] end def appbox_uri return @appbox_uri if @appbox_uri config = Config.instance error("Territory code is not set. Set it in DtcRake.configure (attribute appbox_territory_code) in your Rakefile.") if config.appbox_territory_code.nil? appbox_artifact_code = config.appbox_artifact_code || "#{config.vendor.upcase}.#{config.app.upcase}_#{version}" appbox_uri = UU::OS::UESURI.create(territory_code: config.appbox_territory_code, artifact_code: appbox_artifact_code) @appbox_uri = appbox_uri end def gem_file_name return @gem_file_name if defined? @gem_file_name config = Config.instance # TODO Read version from version.rb or allow to override it from within the Rakefile # the actual gem version differs - e.g. uu_operation_registry-1.3.0.pre.BETA.1.gem (NOT uu_operation_registry-1.3.0-BETA.1.gem) gem_version = version.sub(/-(ALPHA|BETA|RC)/) { |match| ".pre.#{$1}" } @gem_file_name = "#{config.vendor}_#{config.app}-#{gem_version}.gem" end def cmd_file_name return @cmd_file_name if defined? @cmd_file_name config = Config.instance # TODO Read version from version.rb or allow to override it from within the Rakefile @cmd_file_name = "#{config.vendor}_#{config.app}-cmd-#{version}.war" end def vuc_file_name return @vuc_file_name if defined? @vuc_file_name config = Config.instance # TODO Read version from version.rb or allow to override it from within the Rakefile @vuc_file_name = "#{config.vendor}_#{config.app}-vuc-#{version}.war" end def dockerfiles_file_name return @dockerfiles_file_name if defined? @dockerfiles_file_name config = Config.instance # TODO Read version from version.rb or allow to override it from within the Rakefile @dockerfiles_file_name = "#{config.vendor}_#{config.app}-dockerfiles-#{version}.zip" end def yardoc_file_name return @yardoc_file_name if defined? @yardoc_file_name config = Config.instance @yardoc_file_name = "#{config.vendor}_#{config.app}-yardoc-#{version}.zip" end def gem_attachment_code return @gem_attachment_code if defined? @gem_attachment_code config = Config.instance @gem_attachment_code = "#{config.vendor.upcase}.#{config.app.upcase}/GEM-PACK" end def cmd_attachment_code return @cmd_attachment_code if defined? @cmd_attachment_code config = Config.instance @cmd_attachment_code = "#{config.vendor.upcase}.#{config.app.upcase}/CMD-PACK" end def vuc_attachment_code return @vuc_attachment_code if defined? @vuc_attachment_code config = Config.instance @vuc_attachment_code = "#{config.vendor.upcase}.#{config.app.upcase}/VUC-PACK" end def dockerfiles_attachment_code return @dockerfiles_attachment_code if defined? @dockerfiles_attachment_code config = Config.instance @dockerfiles_attachment_code = "#{config.vendor.upcase}.#{config.app.upcase}/DOCKERFILES-PACK" end def yardoc_attachment_code return @yardoc_attachment_code if defined? @yardoc_attachment_code config = Config.instance @yardoc_attachment_code = "#{config.vendor.upcase}.#{config.app.upcase}/YARDOC-PACK" end def app_descriptor_attachment_code return @app_descriptor_attachment_code if defined? @app_descriptor_attachment_code config = Config.instance @app_descriptor_attachment_code = "#{config.vendor.upcase}.#{config.app.upcase}/UUAPP-DEPLOY" end end end