class RXCode::Workspace

Constants

WORKSPACE_EXTENSION
WORKSPACE DISCOVERY ========================================================================================

Attributes

path[R]
PATH =======================================================================================================

Public Class Methods

is_workspace_at_path?(path) click to toggle source
# File lib/rxcode/workspace.rb, line 17
def self.is_workspace_at_path?(path)
  File.extname(path) == WORKSPACE_EXTENSION && File.directory?(path)
end
new(workspace_path) click to toggle source
# File lib/rxcode/workspace.rb, line 5
def initialize(workspace_path)
  unless self.class.is_workspace_at_path?(workspace_path)
    raise "#{workspace_path.inspect} is not a valid XCode workspace path" 
  end
  
  @path = workspace_path
end

Public Instance Methods

build_location() click to toggle source
# File lib/rxcode/workspace.rb, line 108
def build_location
  Dir[File.join(derived_data_location, '*/info.plist')].each do |info_plist_path|
    build_location_data = Plist::parse_xml(info_plist_path)
    workspace_path = build_location_data['WorkspacePath']
    
    if workspace_path == self.path || (project_dependent? && workspace_path == enclosing_product_path)
      return File.dirname(info_plist_path)
    end
  end
  
  nil
end
built_products_dir() click to toggle source
# File lib/rxcode/workspace.rb, line 121
def built_products_dir
  if build_root = build_location
    File.join(build_root, "Build/Products")
  end
end
contents_path() click to toggle source
CONTENTS ===================================================================================================
# File lib/rxcode/workspace.rb, line 84
def contents_path
  @contents_path ||= File.join(path, 'contents.xcworkspacedata').freeze
end
derived_data_location() click to toggle source
BUILD LOCATION =============================================================================================
# File lib/rxcode/workspace.rb, line 90
def derived_data_location
  derived_data_style = value_for_setting('IDEWorkspaceUserSettings_DerivedDataLocationStyle')
  custom_derived_data_location = value_for_setting('IDEWorkspaceUserSettings_DerivedDataCustomLocation')
  
  if derived_data_style == 2 # 2 is the code for 'Workspace-relative path'
    File.expand_path(custom_derived_data_location, self.root)
  else
    
    prefs = RXCode.xcode_preferences
    if prefs.derived_data_location_is_relative_to_workspace?
      File.expand_path(prefs.derived_data_location, self.root)
    else
      prefs.derived_data_location
    end
    
  end
end
enclosing_product_path() click to toggle source
# File lib/rxcode/workspace.rb, line 51
def enclosing_product_path
  File.dirname(path) if project_dependent?
end
name() click to toggle source
# File lib/rxcode/workspace.rb, line 41
def name
  File.basename(path, '.xcworkspace')
end
project_dependent?() click to toggle source
PROJECTS ===================================================================================================
# File lib/rxcode/workspace.rb, line 47
def project_dependent?
  name == 'project' && RXCode::Project.is_project_at_path?(File.dirname(path))
end
project_independent?() click to toggle source
# File lib/rxcode/workspace.rb, line 55
def project_independent?
  !project_dependent?
end
project_paths() click to toggle source
# File lib/rxcode/workspace.rb, line 63
def project_paths
  require 'nokogiri'
  
  if project_dependent?
    
    [ File.dirname(path) ]
    
  elsif File.exist?(contents_path)
    document = Nokogiri::XML(File.read(contents_path))
    
    document.xpath('/Workspace/FileRef').collect { |element|
      resolve_file_reference(element['location']) if element['location'] =~ /\.xcodeproj$/
    }.compact
    
  else
    []
  end
end
projects() click to toggle source
# File lib/rxcode/workspace.rb, line 59
def projects
  @projects ||= project_paths.map { |project_path| Project.new(project_path, :workspace => self) }
end
resolve_file_reference(location) click to toggle source
# File lib/rxcode/workspace.rb, line 33
def resolve_file_reference(location)
  if location =~ /^(?:container|group):(.*)$/
    File.expand_path("../#{$1}", path)
  else
    location
  end
end
root() click to toggle source
# File lib/rxcode/workspace.rb, line 25
def root
  if project_dependent?
    File.expand_path('../..', path)
  else
    File.dirname(path)
  end
end
settings_file_for_user(user_name) click to toggle source
# File lib/rxcode/workspace.rb, line 150
def settings_file_for_user(user_name)
  File.join(user_data_directory_for_user(user_name), "WorkspaceSettings.xcsettings")
end
settings_for_user(user_name) click to toggle source
# File lib/rxcode/workspace.rb, line 154
def settings_for_user(user_name)
  settings_file = settings_file_for_user(user_name)
  if File.file?(settings_file)
    Plist::parse_xml(settings_file)
  else
    {}
  end
end
shared_data_directory() click to toggle source
SETTINGS ===================================================================================================
# File lib/rxcode/workspace.rb, line 129
def shared_data_directory
  File.join(self.path, "xcshareddata")
end
shared_settings() click to toggle source
# File lib/rxcode/workspace.rb, line 137
def shared_settings
  settings_file = shared_settings_file
  if File.file?(settings_file)
    Plist::parse_xml(settings_file)
  else
    {}
  end
end
shared_settings_file() click to toggle source
# File lib/rxcode/workspace.rb, line 133
def shared_settings_file
  File.join(shared_data_directory, "WorkspaceSettings.xcsettings")
end
user_data_directory_for_user(user_name) click to toggle source
# File lib/rxcode/workspace.rb, line 146
def user_data_directory_for_user(user_name)
  File.join(path, "xcuserdata", "#{user_name}.xcuserdatad")
end
user_settings() click to toggle source
# File lib/rxcode/workspace.rb, line 163
def user_settings
  settings_for_user(ENV['USER'])
end
value_for_setting(setting_name) click to toggle source
# File lib/rxcode/workspace.rb, line 167
def value_for_setting(setting_name)
  user_settings[setting_name] || shared_settings[setting_name]
end