Class: Fastlane::Helper::GradleParserHelper

Inherits:
Object
  • Object
show all
Defined in:
lib/fastlane/plugin/gradle_manager/helper/gradle_parser_helper.rb

Class Method Summary collapse

Class Method Details

.handle_default_config(line) ⇒ Object



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# 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) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# 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) ⇒ Object



93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
# 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) ⇒ Object



75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# 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) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# 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

.resetObject



24
25
26
27
28
29
30
# 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