Class: XcodeInstall::InstalledXcode

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ InstalledXcode

Returns a new instance of InstalledXcode.



426
427
428
# File 'lib/xcode/install.rb', line 426

def initialize(path)
  @path = Pathname.new(path)
end

Instance Attribute Details

#available_simulatorsObject (readonly)

Returns the value of attribute available_simulators.



424
425
426
# File 'lib/xcode/install.rb', line 424

def available_simulators
  @available_simulators
end

#bundle_versionObject (readonly)

Returns the value of attribute bundle_version.



421
422
423
# File 'lib/xcode/install.rb', line 421

def bundle_version
  @bundle_version
end

#downloadable_index_urlObject (readonly)

Returns the value of attribute downloadable_index_url.



423
424
425
# File 'lib/xcode/install.rb', line 423

def downloadable_index_url
  @downloadable_index_url
end

#pathObject (readonly)

Returns the value of attribute path.



419
420
421
# File 'lib/xcode/install.rb', line 419

def path
  @path
end

#uuidObject (readonly)

Returns the value of attribute uuid.



422
423
424
# File 'lib/xcode/install.rb', line 422

def uuid
  @uuid
end

#versionObject (readonly)

Returns the value of attribute version.



420
421
422
# File 'lib/xcode/install.rb', line 420

def version
  @version
end

Instance Method Details

#approve_licenseObject



446
447
448
449
450
451
452
453
# File 'lib/xcode/install.rb', line 446

def approve_license
  license_path = "#{@path}/Contents/Resources/English.lproj/License.rtf"
  license_id = IO.read(license_path).match(/^EA\d{4}/)
  license_plist_path = '/Library/Preferences/com.apple.dt.Xcode.plist'
  `sudo rm -rf #{license_plist_path}`
  `sudo /usr/libexec/PlistBuddy -c "add :IDELastGMLicenseAgreedTo string #{license_id}" #{license_plist_path}`
  `sudo /usr/libexec/PlistBuddy -c "add :IDEXcodeVersionForAgreedToGMLicense string #{@version}" #{license_plist_path}`
end

#fetch_versionObject



477
478
479
480
481
# File 'lib/xcode/install.rb', line 477

def fetch_version
  output = `DEVELOPER_DIR='' "#{@path}/Contents/Developer/usr/bin/xcodebuild" -version`
  return '0.0' if output.nil? # ¯\_(ツ)_/¯
  output.split("\n").first.split(' ')[1]
end

#install_componentsObject



461
462
463
464
465
466
467
468
469
# File 'lib/xcode/install.rb', line 461

def install_components
  Dir.glob("#{@path}/Contents/Resources/Packages/*.pkg").each do |pkg|
    `sudo installer -pkg #{pkg} -target /`
  end
  osx_build_version = `sw_vers -buildVersion`.chomp
  tools_version = `/usr/libexec/PlistBuddy -c "Print :ProductBuildVersion" "#{@path}/Contents/version.plist"`.chomp
  cache_dir = `getconf DARWIN_USER_CACHE_DIR`.chomp
  `touch #{cache_dir}com.apple.dt.Xcode.InstallCheckCache_#{osx_build_version}_#{tools_version}`
end

#plist_entry(keypath) ⇒ Object



473
474
475
# File 'lib/xcode/install.rb', line 473

def plist_entry(keypath)
  `/usr/libexec/PlistBuddy -c "Print :#{keypath}" "#{path}/Contents/Info.plist"`.chomp
end