Class: FastlaneCore::PkgFileAnalyser

Inherits:
Object
  • Object
show all
Defined in:
fastlane_core/lib/fastlane_core/pkg_file_analyser.rb

Class Method Summary collapse

Class Method Details

.fetch_app_build(path) ⇒ Object

Fetches the app version from the given pkg file.



26
27
28
29
30
# File 'fastlane_core/lib/fastlane_core/pkg_file_analyser.rb', line 26

def self.fetch_app_build(path)
  xml = self.fetch_distribution_xml_file(path)
  return xml.elements['installer-gui-script/pkg-ref/bundle-version/bundle'].attributes['CFBundleVersion'] if xml
  return nil
end

.fetch_app_identifier(path) ⇒ Object



7
8
9
10
11
# File 'fastlane_core/lib/fastlane_core/pkg_file_analyser.rb', line 7

def self.fetch_app_identifier(path)
  xml = self.fetch_distribution_xml_file(path)
  return xml.elements['installer-gui-script/product'].attributes['id'] if xml
  return nil
end

.fetch_app_platform(path) ⇒ Object

Fetches the app platform from the given pkg file.



14
15
16
# File 'fastlane_core/lib/fastlane_core/pkg_file_analyser.rb', line 14

def self.fetch_app_platform(path)
  return "osx"
end

.fetch_app_version(path) ⇒ Object

Fetches the app version from the given pkg file.



19
20
21
22
23
# File 'fastlane_core/lib/fastlane_core/pkg_file_analyser.rb', line 19

def self.fetch_app_version(path)
  xml = self.fetch_distribution_xml_file(path)
  return xml.elements['installer-gui-script/product'].attributes['version'] if xml
  return nil
end

.fetch_distribution_xml_file(path) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'fastlane_core/lib/fastlane_core/pkg_file_analyser.rb', line 32

def self.fetch_distribution_xml_file(path)
  Dir.mktmpdir do |dir|
    Helper.backticks("xar -C #{dir.shellescape} -xf #{path.shellescape}")

    Dir.foreach(dir) do |file|
      next unless file.include?('Distribution')

      begin
        content = File.open(File.join(dir, file))
        xml = REXML::Document.new(content)

        if xml.elements['installer-gui-script/product']
          return xml
        end
      rescue => ex
        UI.error(ex)
        UI.error("Error parsing *.pkg distribution xml #{File.join(dir, file)}")
      end
    end

    nil
  end
end