Class: Fastlane::Actions::GetValueFromBuildAction

Inherits:
Action
  • Object
show all
Defined in:
lib/fastlane/plugin/android_versioning/actions/get_value_from_build.rb

Documentation collapse

Class Method Summary collapse

Class Method Details

.authorsObject



46
47
48
# File 'lib/fastlane/plugin/android_versioning/actions/get_value_from_build.rb', line 46

def self.authors
  ["Manabu OHTAKE"]
end

.available_optionsObject



31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/fastlane/plugin/android_versioning/actions/get_value_from_build.rb', line 31

def self.available_options
  [
    FastlaneCore::ConfigItem.new(key: :app_project_dir,
                            env_name: "ANDROID_VERSIONING_APP_PROJECT_DIR",
                         description: "The path to the application source folder in the Android project (default: android/app)",
                            optional: true,
                                type: String,
                       default_value: "android/app"),
    FastlaneCore::ConfigItem.new(key: :key,
                         description: "The property key",
                                type: String)

  ]
end

.is_supported?(platform) ⇒ Boolean

Returns:

  • (Boolean)


50
51
52
# File 'lib/fastlane/plugin/android_versioning/actions/get_value_from_build.rb', line 50

def self.is_supported?(platform)
  platform == :android
end

.run(params) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/fastlane/plugin/android_versioning/actions/get_value_from_build.rb', line 6

def self.run(params)
  app_project_dir ||= params[:app_project_dir]
  value = ""
  found = false
  Dir.glob("#{app_project_dir}/build.gradle") do |path|
    begin
      File.open(path, 'r') do |file|
        file.each_line do |line|
          unless line.include? "#{params[:key]} " and !found
            next
          end
          components = line.strip.split(' ').reject { |item| item.start_with?("//") }
          value = components.last.tr("\"", "").tr("\'", "")
          break
        end
        file.close
      end
    end
  end
  return value
end