Class: Fastlane::Wpmreleasetoolkit::Versioning::AndroidVersionFile

Inherits:
Object
  • Object
show all
Defined in:
lib/fastlane/plugin/wpmreleasetoolkit/versioning/files/android_version_file.rb

Overview

The ‘AndroidVersionFile` class takes in a version.properties file path and reads/writes values to/from the file.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(version_properties_path: 'version.properties') ⇒ AndroidVersionFile

Initializes a new instance of AndroidVersionFile with the specified version.properties file path.

Parameters:

  • version_properties_path (String) (defaults to: 'version.properties')

    The path to the version.properties file.



14
15
16
17
18
# File 'lib/fastlane/plugin/wpmreleasetoolkit/versioning/files/android_version_file.rb', line 14

def initialize(version_properties_path: 'version.properties')
  UI.user_error!("version.properties not found at this path: #{version_properties_path}") unless File.exist?(version_properties_path)

  @version_properties_path = version_properties_path
end

Instance Attribute Details

#version_properties_pathObject (readonly)

Returns the value of attribute version_properties_path.



8
9
10
# File 'lib/fastlane/plugin/wpmreleasetoolkit/versioning/files/android_version_file.rb', line 8

def version_properties_path
  @version_properties_path
end

Instance Method Details

#read_version_codeBuildCode

Reads the version code from a version.properties file.

Parameters:

  • file_path (String)

    The path to the version.properties file.

Returns:

  • (BuildCode)

    An instance of ‘BuildCode` representing the version code read from the file.

Raises:

  • (UI::Error)

    If the file_path is nil or the version code is not found.



43
44
45
46
47
48
49
50
51
# File 'lib/fastlane/plugin/wpmreleasetoolkit/versioning/files/android_version_file.rb', line 43

def read_version_code
  # Read the version code from the version.properties file
  file_content = JavaProperties.load(version_properties_path)
  version_code = file_content[:versionCode]
  UI.user_error!('Version code not found in version.properties') if version_code.nil?

  # Create a BuildCode object
  Fastlane::Models::BuildCode.new(version_code.to_i)
end

#read_version_nameString

Reads the version name from a version.properties file.

Returns:

  • (String)

    The version name read from the file.

Raises:

  • (UI::Error)

    If the file_path is nil or the version name is not found.



26
27
28
29
30
31
32
33
# File 'lib/fastlane/plugin/wpmreleasetoolkit/versioning/files/android_version_file.rb', line 26

def read_version_name
  # Read the version name from the version.properties file
  file_content = JavaProperties.load(version_properties_path)
  version_name = file_content[:versionName]
  UI.user_error!('Version name not found in version.properties') if version_name.nil?

  version_name
end

#write_version(version_name:, version_code:) ⇒ Object

Writes the provided version name and version code to the version.properties file.

Parameters:

  • version_name (String)

    The version name to write to the file.

  • version_code (String)

    The version code to write to the file.

Raises:

  • (UI::Error)

    If the version name or version code is nil.



60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/fastlane/plugin/wpmreleasetoolkit/versioning/files/android_version_file.rb', line 60

def write_version(version_name:, version_code:)
  # Create the version name and version code hash
  version = {
    versionName: version_name,
    versionCode: version_code
  }

  # Write the version name and version code hash to the version.properties file
  JavaProperties.write(
    version,
    version_properties_path
  )
end