Sha256: c5b2ccd9bb676cd59854c29561411feee1fdb748e73362472853be07900a7ce6

Contents?: true

Size: 1.88 KB

Versions: 4

Compression:

Stored size: 1.88 KB

Contents

require "rake"
require "dtc_rake/ui"
require "uu/os/attachment"
require "uu/os/rest/binary_value"
require "uu/os/search"
require "uu/os/security/session"
require "uu/os/uesuri_builder"

module DtcRake
  include DtcRake::UI

  def mv_to_output_dir(src_dir, src_file)
    output_dir = DtcRake::Config.instance.output_dir
    FileUtils.mkpath output_dir
    src_file_path = File.join(src_dir, output_dir, src_file)
    dest_file = File.expand_path(File.join(".", output_dir, src_file))
    FileUtils.mv src_file_path, dest_file
    success "#{dest_file} created"
  end
  module_function :mv_to_output_dir

  # Checks if JRuby is being used. This check is important when building .war
  # files - gems with native extensions (like json, bson) must be added to the
  # output .war file for Java platform. Otherwise certain gems (e.g.
  # uu_os_persistence) cannot be loaded when deployed on servlet container
  # (Tomcat).
  def check_jruby!
    error(".war files must be built using JRuby!") unless RUBY_PLATFORM == "java"
  end
  module_function :check_jruby!

  def upload_pack(attrs)
    file = attrs[:file]
    artifact_uri = attrs[:appbox_uri] || DtcRake::Product.instance.appbox_uri
    attachment_code = attrs[:attachment_code]
    credentials = attrs[:credentials]

    abort "Specify login credentials" unless credentials
    UU::OS::Security::Session.login(credentials)

    attch_uri = UU::OS::UESURIBuilder.parse_uesuri(artifact_uri).set_object_code(attachment_code).to_uesuri

    if UU::OS::Search.exists(attch_uri)
      File.open(file, "rb") do |f|
        UU::OS::Attachment.check_in(attch_uri, data: UU::OS::REST::BinaryValue.new(f))
      end
    else
      File.open(file, "rb") do |f|
        attch_uri = UU::OS::Attachment.create(artifact_uri, code: attachment_code,
            data: UU::OS::REST::BinaryValue.new(f)
        )
      end
    end

    attch_uri
  end
  module_function :upload_pack
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
dtc_rake-1.0.0.pre.beta.1 lib/dtc_rake/util.rb
dtc_rake-0.2.0 lib/dtc_rake/util.rb
dtc_rake-0.1.2 lib/dtc_rake/util.rb
dtc_rake-0.1.0 lib/dtc_rake/util.rb