Class: IosAndroidToolbox::AndroidVersionController

Inherits:
VersionController show all
Defined in:
lib/ios_android_toolbox/android.rb

Constant Summary collapse

MANIFEST =
'/manifest'
ANDROID_NS =
'android:'
ANDROID_VERSION_CODE =
'versionCode'
ANDROID_VERSION_NAME =
'versionName'
APP =
'application'
ANDROID_DEBUGGABLE =
'debuggable'

Instance Attribute Summary

Attributes inherited from VersionController

#inc_idx, #max_comps

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from VersionController

#components, find_project_info, #next_build_number!, #next_version, #suffix, version_file

Constructor Details

#initialize(manifest_file) ⇒ AndroidVersionController

Returns a new instance of AndroidVersionController.



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/ios_android_toolbox/android.rb', line 38

def initialize(manifest_file)
    super()
    raise "No manifest file specified" if manifest_file.nil?
    
    begin
        @xml = Nokogiri::XML(File.open(manifest_file))
        @manifest = @xml.xpath(MANIFEST, 'android' => "http://schemas.android.com/apk/res/android").first
    rescue
        raise "Cannot parse file #{version_file}"
    end
    
    raise "File #{manifest_fiile} does not have a #{MANIFEST} node" if @xml.xpath(MANIFEST).nil?
    
    self
end

Class Method Details

.find_project_info_candidates_for_dir(dir) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/ios_android_toolbox/android.rb', line 18

def self.find_project_info_candidates_for_dir(dir)
  candidates = []

  manifests=`find "#{dir}" -name "AndroidManifest.xml"`

  manifests.split("\n").each do |filename|
    if File.exists?(filename)
      begin
        manifest = Nokogiri::XML(File.open(filename)).xpath(MANIFEST, 'android' => "http://schemas.android.com/apk/res/android").first
        version = manifest[ANDROID_VERSION_NAME] || manifest[ANDROID_NS+ANDROID_VERSION_NAME]
        candidates.push filename if manifest and version
      rescue
        # Do nothing, just skip the file. Must be in binary format
      end
    end
  end

  candidates
end

Instance Method Details

#app_idObject



58
59
60
# File 'lib/ios_android_toolbox/android.rb', line 58

def app_id
    raise "Not implemented yet."
end

#applicationObject



78
79
80
# File 'lib/ios_android_toolbox/android.rb', line 78

def application
    @manifest.xpath(APP, 'android' => "http://schemas.android.com/apk/res/android").first
end

#next_version!(inc_idx = nil) ⇒ Object



66
67
68
# File 'lib/ios_android_toolbox/android.rb', line 66

def next_version!(inc_idx = nil)
    @manifest[ANDROID_NS+ANDROID_VERSION_NAME] = next_version
end

#next_version_codeObject



70
71
72
# File 'lib/ios_android_toolbox/android.rb', line 70

def next_version_code
    version_code.to_i + 1
end

#next_version_code!Object



74
75
76
# File 'lib/ios_android_toolbox/android.rb', line 74

def next_version_code!
    @manifest[ANDROID_NS+ANDROID_VERSION_CODE] = next_version_code
end

#release_versionObject



86
87
88
# File 'lib/ios_android_toolbox/android.rb', line 86

def release_version
    @manifest[ANDROID_NS+ANDROID_VERSION_NAME] = components.slice(0,3).join "."
end

#set_debuggable(on = true) ⇒ Object



82
83
84
# File 'lib/ios_android_toolbox/android.rb', line 82

def set_debuggable(on = true)
    application[ANDROID_NS+ANDROID_DEBUGGABLE] = (on ? 'true' : 'false')
end

#versionObject



54
55
56
# File 'lib/ios_android_toolbox/android.rb', line 54

def version
    @manifest[ANDROID_VERSION_NAME] || @manifest[ANDROID_NS+ANDROID_VERSION_NAME]
end

#version_codeObject



62
63
64
# File 'lib/ios_android_toolbox/android.rb', line 62

def version_code
    @manifest[ANDROID_VERSION_CODE]
end

#write_to_output_file(output_file) ⇒ Object



100
101
102
# File 'lib/ios_android_toolbox/android.rb', line 100

def write_to_output_file(output_file)
    write_to_xml_file(output_file)
end

#write_to_xml_file(output_file) ⇒ Object



90
91
92
93
94
95
96
97
98
# File 'lib/ios_android_toolbox/android.rb', line 90

def write_to_xml_file(output_file)
    if output_file == '-'
        puts @xml.to_xml
    else
        File.open output_file, "w+" do |f|
            f.write(@xml.to_xml)
        end
    end
end