Class: Fastlane::Actions::AndroidChangePackageIdentifierAction

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

Class Method Summary collapse

Class Method Details

.authorsObject



49
50
51
# File 'lib/fastlane/plugin/android_change_package_identifier/actions/android_change_package_identifier_action.rb', line 49

def self.authors
  ["MaximusMcCann"]
end

.available_optionsObject



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/fastlane/plugin/android_change_package_identifier/actions/android_change_package_identifier_action.rb', line 62

def self.available_options
  [
    FastlaneCore::ConfigItem.new(key: :newIdentifier,
                            env_name: "",
                         description: "The new package identifier for the app. Trumps appendToIdentifier",
                            optional: true,
                                type: String),
    FastlaneCore::ConfigItem.new(key: :appendToIdentifier,
                            env_name: "",
                         description: "The text to append to the package identifier. adds a (.) intitally",
                            optional: true,
                                type: String),
    FastlaneCore::ConfigItem.new(key: :manifest,
                            env_name: "",
                         description: "Optional custom location for AndroidManifest.xml",
                            optional: false,
                                type: String,
                       default_value: "app/src/main/AndroidManifest.xml")
  ]
end

.descriptionObject



45
46
47
# File 'lib/fastlane/plugin/android_change_package_identifier/actions/android_change_package_identifier_action.rb', line 45

def self.description
  "Change the package identifier in the AndroidManifest.xml file. Can revert as well."
end

.detailsObject



57
58
59
60
# File 'lib/fastlane/plugin/android_change_package_identifier/actions/android_change_package_identifier_action.rb', line 57

def self.details
  # Optional:
  "Change the package identifier in the AndroidManifest.xml file. Can revert as well."
end

.is_supported?(platform) ⇒ Boolean

Returns:

  • (Boolean)


89
90
91
# File 'lib/fastlane/plugin/android_change_package_identifier/actions/android_change_package_identifier_action.rb', line 89

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

.outputObject



83
84
85
86
87
# File 'lib/fastlane/plugin/android_change_package_identifier/actions/android_change_package_identifier_action.rb', line 83

def self.output
  [
    ['ANDROID_CHANGE_PACKAGE_IDENTIFIER_ORIGINAL', 'The original package identifier.']
  ]
end

.return_valueObject



53
54
55
# File 'lib/fastlane/plugin/android_change_package_identifier/actions/android_change_package_identifier_action.rb', line 53

def self.return_value
  # If your method provides a return value, you can describe here what it does
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
34
35
36
37
38
39
40
41
42
43
# File 'lib/fastlane/plugin/android_change_package_identifier/actions/android_change_package_identifier_action.rb', line 7

def self.run(params)
  require 'nokogiri'

  newIdentifier = params[:newIdentifier]
  appendToIdentifier = nil
  manifest = params[:manifest]

  if newIdentifier.to_s.strip.length == 0
    appendToIdentifier = params[:appendToIdentifier]

    if appendToIdentifier.to_s.strip.length == 0
      UI.error("Must provide either newIdentifier or appendToIdentifier")
    end
  end


  doc = File.open(manifest) { |f|
    @doc = Nokogiri::XML(f)

    original = nil

    @doc.css("manifest").each do |response_node|
      original = response_node["package"]

      if newIdentifier.to_s.strip.length != 0
        response_node["package"] = newIdentifier
      else
        response_node["package"] = "#{original}.#{appendToIdentifier}"
      end
      UI.message("Updating package identifier to: #{response_node["package"]}")
    end

    Actions.lane_context[SharedValues::ANDROID_CHANGE_PACKAGE_IDENTIFIER_ORIGINAL] = original

    File.write(manifest, @doc.to_xml)
  }
end