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.



454
455
456
# File 'lib/xcode/install.rb', line 454

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

Instance Attribute Details

#available_simulatorsObject (readonly)

Returns the value of attribute available_simulators.



452
453
454
# File 'lib/xcode/install.rb', line 452

def available_simulators
  @available_simulators
end

#bundle_versionObject (readonly)

Returns the value of attribute bundle_version.



449
450
451
# File 'lib/xcode/install.rb', line 449

def bundle_version
  @bundle_version
end

#downloadable_index_urlObject (readonly)

Returns the value of attribute downloadable_index_url.



451
452
453
# File 'lib/xcode/install.rb', line 451

def downloadable_index_url
  @downloadable_index_url
end

#pathObject (readonly)

Returns the value of attribute path.



447
448
449
# File 'lib/xcode/install.rb', line 447

def path
  @path
end

#uuidObject (readonly)

Returns the value of attribute uuid.



450
451
452
# File 'lib/xcode/install.rb', line 450

def uuid
  @uuid
end

#versionObject (readonly)

Returns the value of attribute version.



448
449
450
# File 'lib/xcode/install.rb', line 448

def version
  @version
end

Instance Method Details

#approve_licenseObject



480
481
482
483
484
485
486
487
# File 'lib/xcode/install.rb', line 480

def approve_license
  license_path = "#{@path}/Contents/Resources/English.lproj/License.rtf"
  license_id = IO.read(license_path).match(/\bEA\d{4}\b/)
  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



511
512
513
514
515
# File 'lib/xcode/install.rb', line 511

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



495
496
497
498
499
500
501
502
503
# File 'lib/xcode/install.rb', line 495

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



507
508
509
# File 'lib/xcode/install.rb', line 507

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