Class: Fastlane::Actions::SetValueInBuildAction

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

Documentation collapse

Class Method Summary collapse

Class Method Details

.authorsObject



65
66
67
# File 'lib/fastlane/plugin/android_versioning/actions/set_value_in_build.rb', line 65

def self.authors
  ["Manabu OHTAKE"]
end

.available_optionsObject



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/fastlane/plugin/android_versioning/actions/set_value_in_build.rb', line 38

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),
    FastlaneCore::ConfigItem.new(key: :value,
                         description: "The property value",
                                type: String)
  ]
end

.descriptionObject



55
56
57
# File 'lib/fastlane/plugin/android_versioning/actions/set_value_in_build.rb', line 55

def self.description
  "Set the value of your project"
end

.detailsObject



59
60
61
62
63
# File 'lib/fastlane/plugin/android_versioning/actions/set_value_in_build.rb', line 59

def self.details
  [
    "This action will set the value directly in build.gradle . "
  ].join("\n")
end

.is_supported?(platform) ⇒ Boolean

Returns:

  • (Boolean)


69
70
71
# File 'lib/fastlane/plugin/android_versioning/actions/set_value_in_build.rb', line 69

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

.run(params) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/fastlane/plugin/android_versioning/actions/set_value_in_build.rb', line 7

def self.run(params)
  app_project_dir ||= params[:app_project_dir]
  found = false
  Dir.glob("#{app_project_dir}/build.gradle") do |path|
    begin
      temp_file = Tempfile.new('versioning')
      File.open(path, 'r') do |file|
        file.each_line do |line|
          unless line.include? "#{params[:key]} " and !found
            temp_file.puts line
            next
          end
          components = line.strip.split(' ')
          value = components.last.tr("\"", "").tr("\'", "")
          line.replace line.sub(value, params[:value].to_s)
          found = true
          temp_file.puts line
        end
        file.close
      end
      temp_file.rewind
      temp_file.close
      FileUtils.mv(temp_file.path, path)
      temp_file.unlink
    end
  end
end