class Fastlane::Helper::GradleParserHelper

Public Class Methods

handle_default_config(line) click to toggle source
# File lib/fastlane/plugin/gradle_manager/helper/gradle_parser_helper.rb, line 49
def self.handle_default_config(line)
  trimmed = line.strip

  if trimmed == '}'
    @reading_default_config = false
    return
  end

  components = trimmed.split(' ')
  return unless !components.nil? && components.length > 0

  key = components[0].tr("\"", '')
  case key
    when 'applicationId'
      symbol = :application_id
    when 'versionCode'
      symbol = :version_code
    when 'versionName'
      symbol = :version_name
    else
      return
  end

  @result[:default_config][symbol] = components[components.length - 1].tr('\"', '')
end
handle_line(line) click to toggle source
# File lib/fastlane/plugin/gradle_manager/helper/gradle_parser_helper.rb, line 32
def self.handle_line(line)
  if line.include? 'defaultConfig'
    @result[:default_config] = {}
    @reading_default_config = true
  elsif line.include? 'productFlavors'
    @result[:product_flavors] = {}
    @reading_product_flavors = true
    @current_indent = 0
  elsif @reading_default_config
    handle_default_config(line)
  elsif @reading_product_flavor_block
    handle_product_flavor_block(line)
  elsif @reading_product_flavors
    handle_product_flavors(line)
  end
end
handle_product_flavor_block(line) click to toggle source
# File lib/fastlane/plugin/gradle_manager/helper/gradle_parser_helper.rb, line 93
def self.handle_product_flavor_block(line)
  trimmed = line.strip

  if trimmed == '}'
    @current_indent -= 1
    @reading_product_flavor_block = false
    return
  end

  components = trimmed.split(' ')
  return unless !components.nil? && components.length > 0

  key = components[0].tr("\"", '')
  case key
    when 'applicationId'
      symbol = :application_id
    when 'applicationIdSuffix'
      symbol = :application_id_suffix
    when 'versionCode'
      symbol = :version_code
    when 'versionName'
      symbol = :version_name
    else
      return
  end

  flavors = @result[:product_flavors].keys
  @result[:product_flavors][flavors[flavors.length - 1]][symbol] = components[components.length - 1].tr('\"', '')
end
handle_product_flavors(line) click to toggle source
# File lib/fastlane/plugin/gradle_manager/helper/gradle_parser_helper.rb, line 75
def self.handle_product_flavors(line)
  trimmed = line.strip

  if trimmed == '}'
    @current_indent -= 1
    @reading_product_flavors = false if @current_indent < 0
    return
  end

  components = trimmed.split(' ')
  return unless !components.nil? && components.length > 0 && components[components.length - 1].tr("\"", '') == '{'

  flavor = components[0].tr("\"", '')
  @result[:product_flavors][flavor] = {}
  @current_indent += 1
  @reading_product_flavor_block = true
end
parse(gradle_file) click to toggle source
# File lib/fastlane/plugin/gradle_manager/helper/gradle_parser_helper.rb, line 4
def self.parse(gradle_file)
  reset

  unless File.file?(gradle_file)
    return nil
  end

  begin
    file = File.new(gradle_file, 'r')
    while (line = file.gets)
      handle_line(line)
    end
    file.close
  rescue => err
    throw err
  end

  return @result
end
reset() click to toggle source
# File lib/fastlane/plugin/gradle_manager/helper/gradle_parser_helper.rb, line 24
def self.reset
  @reading_default_config = false
  @reading_product_flavors = false
  @reading_product_flavor_block = false
  @current_indent = 0
  @result = {}
end