Class: DeployGate::Xcode::Analyze

Inherits:
Object
  • Object
show all
Defined in:
lib/deploygate/xcode/analyze.rb

Defined Under Namespace

Classes: BundleIdentifierDifferentError

Constant Summary collapse

BASE_WORK_DIR_NAME =
'project.xcworkspace'
BUILD_CONFIGRATION =
'Release'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(workspaces) ⇒ DeployGate::Xcode::Analyze



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/deploygate/xcode/analyze.rb', line 14

def initialize(workspaces)
  @workspaces = workspaces
  @scheme_workspace = find_scheme_workspace(workspaces)
  @build_workspace = find_build_workspace(workspaces)
  @xcodeproj = File.dirname(@scheme_workspace)

  config = FastlaneCore::Configuration.create(Gym::Options.available_options, {:workspace => @scheme_workspace})
  project = FastlaneCore::Project.new(config)
  if project.schemes.empty?
    config = FastlaneCore::Configuration.create(Gym::Options.available_options, {:workspace => @build_workspace})
    project = FastlaneCore::Project.new(config)
  end
  project.select_scheme
  @scheme = project.options[:scheme]
end

Instance Attribute Details

#build_workspaceObject (readonly)

Returns the value of attribute build_workspace.



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

def build_workspace
  @build_workspace
end

#schemeObject (readonly)

Returns the value of attribute scheme.



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

def scheme
  @scheme
end

#scheme_workspaceObject (readonly)

Returns the value of attribute scheme_workspace.



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

def scheme_workspace
  @scheme_workspace
end

#workspacesObject (readonly)

Returns the value of attribute workspaces.



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

def workspaces
  @workspaces
end

Instance Method Details

#automatic_provisioning?Boolean



84
85
86
# File 'lib/deploygate/xcode/analyze.rb', line 84

def automatic_provisioning?
  get_provisioning_style == 'Automatic'
end

#convert_bundle_identifier(bundle_identifier) ⇒ String



67
68
69
70
71
72
73
74
75
76
# File 'lib/deploygate/xcode/analyze.rb', line 67

def convert_bundle_identifier(bundle_identifier)
  identifier = bundle_identifier
  if match = bundle_identifier.match(/\$\((.+)\)/)
    custom_id = match[1]
    identifier = target_build_configration.build_settings[custom_id]
  end
  identifier = convert_bundle_identifier(identifier) if bundle_identifier.match(/\$\((.+)\)/)

  identifier
end

#target_bundle_identifierString

Support Xcode7 more



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/deploygate/xcode/analyze.rb', line 32

def target_bundle_identifier
  begin
    product_name = target_product_name
    product_bundle_identifier = target_build_configration.build_settings['PRODUCT_BUNDLE_IDENTIFIER']
    product_bundle_identifier = convert_bundle_identifier(product_bundle_identifier)

    info_plist_file_path = target_build_configration.build_settings['INFOPLIST_FILE']
    root_path = DeployGate::Xcode::Ios.project_root_path(@scheme_workspace)
    plist_bundle_identifier =
        File.open(File.join(root_path, info_plist_file_path)) do |file|
          plist = Plist.parse_xml file.read
          plist['CFBundleIdentifier']
        end
    plist_bundle_identifier = convert_bundle_identifier(plist_bundle_identifier)

    if product_bundle_identifier != plist_bundle_identifier
      raise BundleIdentifierDifferentError,
            I18n.t('xcode.analyze.target_bundle_identifier.bundle_identifier_different', plist_id: plist_bundle_identifier, product_id: product_bundle_identifier)
    end

    bundle_identifier = product_bundle_identifier
    bundle_identifier.gsub!(/\$\(PRODUCT_NAME:.+\)/, product_name)
  rescue BundleIdentifierDifferentError => e
    raise e
  rescue => e
    cli = HighLine.new
    puts I18n.t('xcode.analyze.target_bundle_identifier.prompt')
    bundle_identifier = cli.ask(I18n.t('xcode.analyze.target_bundle_identifier.ask')) { |q| q.validate = /^(\w+)\.(\w+).*\w$/ }
  end

  bundle_identifier
end

#target_xcode_setting_provisioning_profile_uuidString



79
80
81
82
# File 'lib/deploygate/xcode/analyze.rb', line 79

def target_xcode_setting_provisioning_profile_uuid
  uuid = target_build_configration.build_settings['PROVISIONING_PROFILE']
  UUID.validate(uuid) ? uuid : nil
end