require "rake" require "pathname" module DtcRake def configure(&block) yield Config.instance end module_function :configure class Config include Singleton def initialize @root_dir = Dir.pwd @output_dir = "target" @colorize = true @appbox_meta_artifact_code = "UU.OS/RUNTIME/APP_BOX" @upload_app_descriptor = false guess_vendor_and_app end # Code of application. Guessed from root_dir name if not set. attr_accessor :app # Code of appbox artifact. Guessed from vendor, app and version in uuApp # deployment descriptor if not set. attr_accessor :appbox_artifact_code # Code of appbox location (folder or organization unit). Required. attr_accessor :appbox_location_code # Code of appbox meta artifact. Default value: UU.OS/RUNTIME/APP_BOX. attr_accessor :appbox_meta_artifact_code # Code of territory where the appbox artifact is / should be. Required. attr_accessor :appbox_territory_code # Path to uarchive with contents of appbox artifact. Default value: nil. # If not set, appbox is created with empty content. # Relative path is relative to root_dir. attr_accessor :appbox_uarchive # Path to uuApp deployment descriptor. Guessed from vendor and app if not set. attr_accessor :app_descriptor_path # Print messages in colors. Default value: true. attr_accessor :colorize # Name of folder with build products. Default value: target. # Relative path is relative to root_dir. attr_accessor :output_dir # Appbox project root folder. Default value: current working directory. attr_accessor :root_dir # Upload uuApp deployment descriptor to appbox artifact. Default value: false. attr_accessor :upload_app_descriptor # Code of vendor. Guessed from root_dir name if not set. attr_accessor :vendor def app=(name) @app = name.downcase unless name.nil? end def appbox_uarchive=(path) unless path.nil? path = File.join(root_dir, path) if Pathname.new(path).relative? # File.expand_path converts path to absolute and expands "~" to real user home path @appbox_uarchive = File.expand_path(path) end end def app_descriptor_path return @app_descriptor_path if @app_descriptor_path default_file_path = File.expand_path(File.join(root_dir, "#{vendor}_#{app}-uuapp-deploy.json")) Dir.chdir(root_dir) do unless File.file?(default_file_path) abort "uuApp deployment descriptor not found. Please create file #{default_file_path} or configure its path in Rakefile." end @app_descriptor_path = default_file_path end end def output_dir=(path) unless path.nil? path = File.join(root_dir, path) if Pathname.new(path).relative? # File.expand_path converts path to absolute and expands "~" to real user home path @output_dir = File.expand_path(path) end end def vendor=(name) @vendor = name.downcase unless name.nil? end private def guess_vendor_and_app base_name = File.basename(root_dir) if /([^_]+)_([^-]+)-appbox/ =~ base_name @vendor = $1 @app = $2 else abort "Appbox root folder (#{base_name}) does not match naming convention _-appbox." \ " Either change the folder name or configure 'vendor' and 'app' in Rakefile." end end end end