From e6f4596adcb2fed0e0ef172a5b47b001bf463229 Mon Sep 17 00:00:00 2001 From: lhalegria Date: Tue, 28 Nov 2017 11:20:02 -0200 Subject: [PATCH] add flavor action --- fastlane/Fastfile | 3 ++- .../actions/get_version_name_action.rb | 24 ++++++++++++++----- 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/fastlane/Fastfile b/fastlane/Fastfile index 7f641ce..e5bde1c 100644 --- a/fastlane/Fastfile +++ b/fastlane/Fastfile @@ -1,7 +1,8 @@ lane :test do value = get_version_name( gradle_file_path:"project/build.gradle", - ext_constant_name:"versionName" + ext_constant_name:"versionName", + flavor_name: "flavor" ) puts "VALUE = #{value}" end diff --git a/lib/fastlane/plugin/get_version_name/actions/get_version_name_action.rb b/lib/fastlane/plugin/get_version_name/actions/get_version_name_action.rb index 345573c..9871a52 100644 --- a/lib/fastlane/plugin/get_version_name/actions/get_version_name_action.rb +++ b/lib/fastlane/plugin/get_version_name/actions/get_version_name_action.rb @@ -4,10 +4,11 @@ class GetVersionNameAction < Action def self.run(params) version_name = "0" constant_name ||= params[:ext_constant_name] + flavor_name ||= params[:ext_flavor_name] gradle_file_path ||= params[:gradle_file_path] if gradle_file_path != nil UI.message("The increment_version_code plugin will use gradle file at (#{gradle_file_path})!") - version_name = getVersionName(gradle_file_path, constant_name) + version_name = getVersionName(gradle_file_path, constant_name, flavor_name) else app_folder_name ||= params[:app_folder_name] UI.message("The get_version_code plugin is looking inside your project folder (#{app_folder_name})!") @@ -16,7 +17,7 @@ def self.run(params) #foundVersionCode = "false" Dir.glob("**/#{app_folder_name}/build.gradle") do |path| UI.message(" -> Found a build.gradle file at path: (#{path})!") - version_name = getVersionName(path, constant_name) + version_name = getVersionName(path, constant_name, flavor_name) end end @@ -33,8 +34,10 @@ def self.run(params) end - def self.getVersionName(path, constant_name) + def self.getVersionName(path, constant_name, flavor_name) version_name = "0" + is_from_selected_flavor = flavor_name == nil + if !File.file?(path) UI.message(" -> No file exist at path: (#{path})!") return version_name @@ -42,7 +45,10 @@ def self.getVersionName(path, constant_name) begin file = File.new(path, "r") while (line = file.gets) - if line.include? constant_name + if flavor_name != nil && line.include? flavor_name + is_from_selected_flavor = true + + if line.include? constant_name && is_from_selected_flavor versionComponents = line.strip.split(' ') version_name = versionComponents[versionComponents.length - 1].tr("\"","") break @@ -85,7 +91,13 @@ def self.available_options description: "If the version name is set in an ext constant, specify the constant name (optional)", optional: true, type: String, - default_value: "versionName") + default_value: "versionName"), + FastlaneCore::ConfigItem.new(key: :flavor_name, + env_name: "GETVERSIONNAME_FLAVOR_NAME", + description: "If the gradle file has many flavors, specify the flavor to get versionName (optional)", + optional: true, + type: String, + default_value: nil) ] end @@ -100,4 +112,4 @@ def self.is_supported?(platform) end end end - end + end \ No newline at end of file