Sha256: 36c5818c3b65e693e4e15f6302733611a7afb0bee85b0064dd1711fadff9ea1c

Contents?: true

Size: 1.42 KB

Versions: 5

Compression:

Stored size: 1.42 KB

Contents

module Fastlane
  module Helper
    class GradleTask
      attr_accessor :title

      attr_accessor :description

      def initialize(title: nil, description: nil)
        self.title = title
        self.description = description
      end
    end

    class GradleHelper
      # Path to the gradle script
      attr_accessor :gradle_path

      # All the available tasks
      attr_accessor :tasks

      def initialize(gradle_path: nil)
        self.gradle_path = gradle_path
      end

      # Run a certain action
      def trigger(task: nil, flags: nil, serial: nil)
        # raise "Could not find gradle task '#{task}' in the list of available tasks".red unless task_available?(task)

        android_serial = (serial != "") ? "ANDROID_SERIAL=#{serial}" : nil
        command = [android_serial, gradle_path, task, flags].reject(&:nil?).join(" ")
        Action.sh(command)
      end

      def task_available?(task)
        load_all_tasks
        return tasks.collect(&:title).include?(task)
      end

      private

      def load_all_tasks
        self.tasks = []

        command = [gradle_path, "tasks", "--console=plain"].join(" ")
        output = Actions.sh(command, log: false)
        output.split("\n").each do |line|
          if (result = line.match(/(\w+)\s\-\s([\w\s]+)/))
            self.tasks << GradleTask.new(title: result[1], description: result[2])
          end
        end

        self.tasks
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
fastlane-1.68.0 lib/fastlane/helper/gradle_helper.rb
fastlane-1.67.0 lib/fastlane/helper/gradle_helper.rb
fastlane-1.66.0 lib/fastlane/helper/gradle_helper.rb
fastlane-1.65.0 lib/fastlane/helper/gradle_helper.rb
fastlane-1.64.0 lib/fastlane/helper/gradle_helper.rb