Commit 41391400 authored by Nolan Waite's avatar Nolan Waite

Load/save xcworkspace

parent 384ac16a
framework 'Foundation' framework 'Foundation'
require 'fileutils'
module Pod module Pod
module Xcode module Xcode
...@@ -7,6 +8,20 @@ module Pod ...@@ -7,6 +8,20 @@ module Pod
@projpaths = projpaths @projpaths = projpaths
end end
def self.from_xcworkspace(path)
from_s(File.read(File.join(path, 'contents.xcworkspacedata')))
end
def self.from_s(xml)
doc = NSXMLDocument.alloc.initWithXMLString(xml, options:0, error:nil)
projpaths = doc.nodesForXPath("/Workspace/FileRef", error:nil).map do |node|
node.attributeWithName("location").stringValue.sub(/^group:/, '')
end
new(projpaths)
end
attr_reader :projpaths
def <<(projpath) def <<(projpath)
@projpaths << projpath @projpaths << projpath
end end
...@@ -21,6 +36,13 @@ module Pod ...@@ -21,6 +36,13 @@ module Pod
end end
NSString.alloc.initWithData(doc.XMLData, encoding:NSUTF8StringEncoding) NSString.alloc.initWithData(doc.XMLData, encoding:NSUTF8StringEncoding)
end end
def save_as(path)
FileUtils.mkdir_p(path)
File.open(File.join(path, 'contents.xcworkspacedata'), 'w') do |out|
out << to_s
end
end
end end
end end
end end
...@@ -3,14 +3,22 @@ require File.expand_path('../../../spec_helper', __FILE__) ...@@ -3,14 +3,22 @@ require File.expand_path('../../../spec_helper', __FILE__)
describe "Pod::Xcode::Workspace" do describe "Pod::Xcode::Workspace" do
before do before do
@workspace = Pod::Xcode::Workspace.new('Pods/Pods.xcodeproj', 'App.xcodeproj') @workspace = Pod::Xcode::Workspace.new('Pods/Pods.xcodeproj', 'App.xcodeproj')
end
it "accepts new projects" do
@workspace << 'Framework.xcodeproj'
@workspace.projpaths.should.include 'Framework.xcodeproj'
end
before do
@doc = NSXMLDocument.alloc.initWithXMLString(@workspace.to_s, options:0, error:nil) @doc = NSXMLDocument.alloc.initWithXMLString(@workspace.to_s, options:0, error:nil)
end end
it "is the right workspace version" do it "is the right xml workspace version" do
@doc.rootElement.attributeForName("version").stringValue.should == "1.0" @doc.rootElement.attributeForName("version").stringValue.should == "1.0"
end end
it "contains the projects" do it "refers to the projects in xml" do
@doc.nodesForXPath("/Workspace/FileRef", error:nil).map do |node| @doc.nodesForXPath("/Workspace/FileRef", error:nil).map do |node|
node.attributeForName("location").stringValue.sub(/^group:/, '') node.attributeForName("location").stringValue.sub(/^group:/, '')
end.sort.should == ['App.xcodeproj', 'Pods/Pods.xcodeproj'] end.sort.should == ['App.xcodeproj', 'Pods/Pods.xcodeproj']
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment