Class: Fastlane::Actions::GetApplicationIdAction

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

Class Method Summary collapse

Class Method Details

.authorsObject



58
59
60
# File 'lib/fastlane/plugin/get_application_id/actions/get_application_id_action.rb', line 58

def self.authors
  ['Helder Pinhal']
end

.available_optionsObject



70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/fastlane/plugin/get_application_id/actions/get_application_id_action.rb', line 70

def self.available_options
  [
      FastlaneCore::ConfigItem.new(key: :app_folder_name,
                                   env_name: 'GETAPPLICATIONID_APP_NAME',
                                   description: 'The name of the application source folder in the Android project (default: app)',
                                   optional: true,
                                   type: String,
                                   default_value: 'app'),
      FastlaneCore::ConfigItem.new(key: :gradle_file_path,
                                   env_name: 'GETAPPLICATIONID_GRADLE_FILE_PATH',
                                   description: 'The relative path to the gradle file containing the applicationId parameter (default:app/build.gradle)',
                                   optional: true,
                                   type: String,
                                   default_value: nil),
      FastlaneCore::ConfigItem.new(key: :ext_constant_name,
                                   env_name: 'GETAPPLICATIONID_EXT_CONSTANT_NAME',
                                   description: 'If the applicationId is set in an ext constant, specify the constant name (optional)',
                                   optional: true,
                                   type: String,
                                   default_value: 'applicationId')
  ]
end

.descriptionObject



54
55
56
# File 'lib/fastlane/plugin/get_application_id/actions/get_application_id_action.rb', line 54

def self.description
  'Get the applicationId of an Android project.'
end

.detailsObject



66
67
68
# File 'lib/fastlane/plugin/get_application_id/actions/get_application_id_action.rb', line 66

def self.details
  'Get the applicationId of an Android project. This action will return the applicationId of your project according to the one set in your build.gradle file.'
end

.get_application_id(path, constant_name) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/fastlane/plugin/get_application_id/actions/get_application_id_action.rb', line 32

def self.get_application_id(path, constant_name)
  application_id = nil
  unless File.file?(path)
    UI.message(" -> No file exists at path: (#{path})!")
    return application_id
  end
  begin
    file = File.new(path, 'r')
    while (line = file.gets)
      next unless line.include? constant_name
      components = line.strip.split(' ')
      application_id = components[components.length - 1].tr("\"", '')
      break
    end
    file.close
  rescue => err
    UI.error("An exception occurred while reading the gradle file: #{err}")
    err
  end
  return application_id
end

.is_supported?(platform) ⇒ Boolean

Returns:

  • (Boolean)


99
100
101
# File 'lib/fastlane/plugin/get_application_id/actions/get_application_id_action.rb', line 99

def self.is_supported?(platform)
  [:android].include?(platform)
end

.outpuObject



93
94
95
96
97
# File 'lib/fastlane/plugin/get_application_id/actions/get_application_id_action.rb', line 93

def self.outpu
  [
      ['APPLICATION_ID', 'The applicationId']
  ]
end

.return_valueObject



62
63
64
# File 'lib/fastlane/plugin/get_application_id/actions/get_application_id_action.rb', line 62

def self.return_value
  'Returns the applicationId.'
end

.run(params) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/fastlane/plugin/get_application_id/actions/get_application_id_action.rb', line 4

def self.run(params)
  application_id = nil
  constant_name ||= params[:ext_constant_name]
  gradle_file_path ||= params[:gradle_file_path]
  if !gradle_file_path.nil?
    UI.message("The get_application_id plugin will use gradle file at (#{gradle_file_path})!")
    application_id = get_application_id(gradle_file_path, constant_name)
  else
    app_folder_name ||= params[:app_folder_name]
    UI.message("The get_application_id plugin is looking inside your project folder (#{app_folder_name})!")

    Dir.glob("**/#{app_folder_name}/build.gradle") do |path|
      UI.message(" -> Found a build.gradle file at path: (#{path})!")
      application_id = get_application_id(path, constant_name)
    end
  end

  if application_id.nil?
    UI.user_error!('Impossible to find the applicationId with the specified properties 😭')
  else
    # Store the applicationId in the shared hash
    Actions.lane_context['APPLICATION_ID'] = application_id
    UI.success("👍 applicationId found: #{application_id}")
  end

  return application_id
end