class DeployGate::Android::GradleDeploy

Constants

GRADLE_DEPLOY_DISTRIBUTION_KEY_ENV
GRADLE_DEPLOY_MESSAGE_ENV
GRADLE_DEPLOY_USER_NAME_ENV

Public Class Methods

new(dir, options) click to toggle source
# File lib/deploygate/android/gradle_deploy.rb, line 9
def initialize (dir, options)
  @dir = dir
  @cli = HighLine.new

  GradleProject.root_dir?(@dir)     or raise "#{@dir} is not the root directory of Android project"
  Dir.chdir(@dir)                   or raise "Cannot chdir to #{@dir}"
  @gradle = find_gradle_executable  or raise 'Gradle executable not found.'
  @deploy_env = env(options)
end

Public Instance Methods

deploy() click to toggle source
# File lib/deploygate/android/gradle_deploy.rb, line 19
def deploy
  print 'Looking for DeployGate tasks...'
  tasks = get_deploygate_tasks
  puts

  task  = case tasks.size
            when 0
              install_plugin and return deploy
            when 1
              tasks[0]
            else
              choose(tasks)
          end

  run_task task unless task.nil?
end

Private Instance Methods

choose(tasks) click to toggle source
# File lib/deploygate/android/gradle_deploy.rb, line 53
def choose(tasks)
  @cli.choose do |menu|
    menu.prompt = 'Please choose a task to run: '
    menu.choices(*tasks) do |task|
      return task
    end
  end
end
env(options) click to toggle source

@param [Hash] options @return [String]

# File lib/deploygate/android/gradle_deploy.rb, line 78
def env(options)
  result = ''

  owner            = options.user
  message          = options.message
  distribution_key = options.distribution_key
  open             = options.open

  result += "#{GRADLE_DEPLOY_USER_NAME_ENV}=#{owner} " if owner
  result += "#{GRADLE_DEPLOY_MESSAGE_ENV}=#{message} " if message != nil && message != ''
  result += "#{GRADLE_DEPLOY_DISTRIBUTION_KEY_ENV}=#{distribution_key} " if distribution_key
  puts @cli.color('Not supported browser open', HighLine::YELLOW) if open

  result
end
find_gradle_executable() click to toggle source
# File lib/deploygate/android/gradle_deploy.rb, line 38
def find_gradle_executable
  if File.exist?('gradlew')
    './gradlew'
  else
    cmd = %x(which gradle)
    !cmd.empty? and cmd
  end
end
get_deploygate_tasks() click to toggle source
# File lib/deploygate/android/gradle_deploy.rb, line 68
def get_deploygate_tasks
  %x(#{@gradle} -q --configure-on-demand tasks --all).
      split(/\n/).
      grep(/uploadDeployGate(?!.*signingConfig).+$/).
      map { |line| line.split(/\s/, 2).first }.
      sort
end
install_plugin() click to toggle source
# File lib/deploygate/android/gradle_deploy.rb, line 47
def install_plugin
  if @cli.agree("<%= color('Looks like Gradle DeployGate plugin isn\\'t available on your project.', BOLD) %> Install? ") {|q| q.default = 'y'}
    GradlePluginInstaller.new.install
  end
end
run_task(task) click to toggle source
# File lib/deploygate/android/gradle_deploy.rb, line 62
def run_task(task)
  command = "#{@deploy_env} #{@gradle} #{task}"
  @cli.say "Running <%= color(\"#{command}\", BOLD) %>"
  system command
end