Class: Xcode::ProvisioningProfile

Inherits:
Object
  • Object
show all
Includes:
TerminalOutput
Defined in:
lib/xcode/provisioning_profile.rb

Constant Summary

Constants included from TerminalOutput

TerminalOutput::LEVELS

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from TerminalOutput

#color_output=, #color_output?, #format_lhs, included, #log_level, log_level=, #print, #print_input, #print_output, #print_system, #print_task, #puts, terminal_supports_colors?

Constructor Details

#initialize(path) ⇒ ProvisioningProfile

Returns a new instance of ProvisioningProfile.



5
6
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
44
45
46
47
48
# File 'lib/xcode/provisioning_profile.rb', line 5

def initialize(path)
  
  raise "Provisioning profile '#{path}' does not exist" unless File.exists? path
  
  @path = path
  @identifiers = []
  @devices = []
  @appstore = true
  @enterprise = false
  
  # TODO: im sure this could be done in a nicer way.  maybe read out the XML-like stuff and use the plist -> json converter
  uuid = nil
  File.open(path, "rb") do |f|
    input = f.read
    
    if input=~/ProvisionedDevices/
      @appstore = false
    end
    
    if input=~/<key>ProvisionsAllDevices<\/key>/
      @enterprise = true
    end
    
    if input=~/<key>ProvisionedDevices<\/key>.*?<array>(.*?)<\/array>/im
      $1.split(/<string>/).each do |id|
        next if id.nil? or id.strip==""
        @devices << id.gsub(/<\/string>/,'').strip
      end
    end
    
    input=~/<key>UUID<\/key>.*?<string>(.*?)<\/string>/im
    @uuid = $1.strip
            
    input=~/<key>Name<\/key>.*?<string>(.*?)<\/string>/im
    @name = $1.strip
    
    input=~/<key>ApplicationIdentifierPrefix<\/key>.*?<array>(.*?)<\/array>/im
    $1.split(/<string>/).each do |id|
      next if id.nil? or id.strip==""
      @identifiers << id.gsub(/<\/string>/,'').strip
    end
  end

end

Instance Attribute Details

#appstoreObject (readonly)

Returns the value of attribute appstore.



4
5
6
# File 'lib/xcode/provisioning_profile.rb', line 4

def appstore
  @appstore
end

#devicesObject (readonly)

Returns the value of attribute devices.



4
5
6
# File 'lib/xcode/provisioning_profile.rb', line 4

def devices
  @devices
end

#identifiersObject (readonly)

Returns the value of attribute identifiers.



4
5
6
# File 'lib/xcode/provisioning_profile.rb', line 4

def identifiers
  @identifiers
end

#nameObject (readonly)

Returns the value of attribute name.



4
5
6
# File 'lib/xcode/provisioning_profile.rb', line 4

def name
  @name
end

#pathObject (readonly)

Returns the value of attribute path.



4
5
6
# File 'lib/xcode/provisioning_profile.rb', line 4

def path
  @path
end

#uuidObject (readonly)

Returns the value of attribute uuid.



4
5
6
# File 'lib/xcode/provisioning_profile.rb', line 4

def uuid
  @uuid
end

Class Method Details

.find_installed_by_uuid(uuid) ⇒ Object



96
97
98
99
100
# File 'lib/xcode/provisioning_profile.rb', line 96

def self.find_installed_by_uuid uuid
  ProvisioningProfile.installed_profiles.each do |p|
    return p if p.uuid == uuid
  end
end

.installed_profile(name) ⇒ Object



102
103
104
# File 'lib/xcode/provisioning_profile.rb', line 102

def self.installed_profile(name)
  self.installed_profiles.select {|p| p.name == name.to_s}.first;
end

.installed_profilesObject



90
91
92
93
94
# File 'lib/xcode/provisioning_profile.rb', line 90

def self.installed_profiles
  Dir["#{self.profiles_path}/*.mobileprovision"].map do |file|
    ProvisioningProfile.new(file)
  end
end

.profiles_pathObject



58
59
60
# File 'lib/xcode/provisioning_profile.rb', line 58

def self.profiles_path
  File.expand_path "~/Library/MobileDevice/Provisioning\\ Profiles/"  
end

Instance Method Details

#appstore?Boolean

Returns:

  • (Boolean)


50
51
52
# File 'lib/xcode/provisioning_profile.rb', line 50

def appstore?
  @appstore
end

#enterprise?Boolean

Returns:

  • (Boolean)


54
55
56
# File 'lib/xcode/provisioning_profile.rb', line 54

def enterprise?
  @enterprise
end

#installObject



66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/xcode/provisioning_profile.rb', line 66

def install
  # Do not reinstall if profile is same and is already installed
  return if (self.path == self.install_path.gsub(/\\ /, ' '))
  
  ProvisioningProfile.installed_profiles.each do |installed|
    if installed.identifiers==self.identifiers and installed.uuid==self.uuid
      installed.uninstall
    end
  end

  # print_task "profile", "installing #{self.path} with uuid #{self.uuid}", :info
  cmd = Xcode::Shell::Command.new 'cp'
  cmd << self.path
  cmd << self.install_path
  cmd.execute
end

#install_pathObject



62
63
64
# File 'lib/xcode/provisioning_profile.rb', line 62

def install_path
  "#{ProvisioningProfile.profiles_path}/#{self.uuid}.mobileprovision"
end

#uninstallObject



83
84
85
86
87
88
# File 'lib/xcode/provisioning_profile.rb', line 83

def uninstall
  # print_task "profile", "removing #{self.install_path}", :info
  cmd = Xcode::Shell::Command.new 'rm'
  cmd << "-f #{self.install_path}"
  cmd.execute
end