Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Handle `.xccurrentversion` file when adding versioned data models to project #83

Merged
merged 11 commits into from

4 participants

@Ashton-W

These changes implement and spec the handling of .xccurrentversion files when adding versioned data models to projects.

This was done to try and fix this issue in CocoaPods/CocoaPods#1288
However something is still stopping the xcdatamodeld contents from being processed.

Issue: #81

@alloy

The question marks after the variable name are not correct and will likely lead to a NoMethodError. Another thing you can do is read the version name into the variable at line 226, instead of the whole plist contents and then on line 229 take advantage of Ruby always returning the result of the last evaluation. E.g.

ref.current_version = xccurrentversion || last_child_ref

If xccurrentversion is nil, it will return the value of last_child_ref instead.

Thanks. Excuse the silly mistakes.

@coveralls

Coverage Status

Coverage remained the same when pulling 77bcf03 on Ashton-W:master into 96da037 on CocoaPods:master.

@coveralls

Coverage Status

Coverage remained the same when pulling 188c002 on Ashton-W:master into 96da037 on CocoaPods:master.

@fabiopelosin fabiopelosin merged commit 188c002 into CocoaPods:master

1 check passed

Details default The Travis CI build passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Aug 14, 2013
  1. @Ashton-W
  2. @Ashton-W

    Fixed obvious logic error.

    Ashton-W authored
    Assign current_version with terser syntax.
Commits on Aug 15, 2013
  1. @Ashton-W

    Updated documentation comments

    Ashton-W authored
    get file reference instead of file path for current version from plist.
  2. @Ashton-W
Commits on Aug 18, 2013
  1. @Ashton-W
  2. Added rake task to run given spec file

    Ashton Williams authored
  3. Added CoreData model spec fixture

    Ashton Williams authored
  4. Added CoreData model spec using fixtures

    Ashton Williams authored
  5. Merge branch 'master' of https://github.com/Ashton-W/Xcodeproj

    Ashton Williams authored
    Conflicts:
    	spec/project/object/group_spec.rb
Commits on Aug 19, 2013
  1. @Ashton-W
Commits on Aug 25, 2013
  1. @Ashton-W
This page is out of date. Refresh to see the latest.
View
5 Rakefile
@@ -133,6 +133,11 @@ namespace :spec do
task :kick do
exec "bundle exec kicker -c"
end
+
+ desc "Run single spec"
+ task :single, :spec_file do |t, args|
+ sh "bundle exec bacon #{args.spec_file}"
+ end
end
#-----------------------------------------------------------------------------#
View
15 lib/xcodeproj/project/object/group.rb
@@ -198,8 +198,9 @@ def new_framework(path, sub_group_path = nil)
# Creates a new version group reference to an xcdatamodeled adding the
# xcdatamodel files included in the wrapper as chidren file references.
#
- # @note To match Xcode behaviour the last xcdatamodel according to its
- # path is set as the current version.
+ # @note To match Xcode behaviour the current version is read from the
+ # .xccurrentversion file, if it doesn't exist the last xcdatamodel
+ # according to its path is set as the current version.
#
# @note @see #new_file
#
@@ -215,15 +216,19 @@ def new_xcdatamodeld(path, sub_group_path = nil)
ref.version_group_type = 'wrapper.xcdatamodel'
last_child_ref = nil
+ xccurrentversion = nil
if path.exist?
path.children.each do |child_path|
if File.extname(child_path) == '.xcdatamodel'
- child_ref = ref.new_file_reference(child_path)
+ child_ref = ref.new_file_reference(File.basename(child_path))
child_ref.source_tree = '<group>'
last_child_ref = child_ref
+ elsif File.basename(child_path) == '.xccurrentversion'
+ xccurrentversion = Xcodeproj.read_plist(child_path)['_XCCurrentVersionName']
end
end
- ref.current_version = last_child_ref
+ ref.current_version = ref.children.select { |obj| obj.path == xccurrentversion }.first if xccurrentversion
+ ref.current_version = last_child_ref unless xccurrentversion
end
parent_group = find_subpath(sub_group_path, true)
@@ -295,7 +300,7 @@ def new_bundle(product_name)
# @return [XCVersionGroup] The new group.
#
def new_xcdatamodel_group(xcdatamodel_path)
- g = @project.new(XCVersionGroup)
+ g = project.new(XCVersionGroup)
g.path = xcdatamodel_path
g.version_group_type = 'wrapper.xcdatamodel'
file = g.new_file(xcdatamodel_path.sub(/xcdatamodeld$/, 'xcdatamodel'))
View
8 spec/fixtures/CoreData/VersionedModel.xcdatamodeld/.xccurrentversion
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+<dict>
+ <key>_XCCurrentVersionName</key>
+ <string>VersionedModel 2.xcdatamodel</string>
+</dict>
+</plist>
View
9 spec/fixtures/CoreData/VersionedModel.xcdatamodeld/VersionedModel 2.xcdatamodel/contents
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
+<model name="" userDefinedModelVersionIdentifier="" type="com.apple.IDECoreDataModeler.DataModel" documentVersion="1.0" lastSavedToolsVersion="2061" systemVersion="12E55" minimumToolsVersion="Xcode 4.3" macOSVersion="Automatic" iOSVersion="Automatic">
+ <entity name="Entity" syncable="YES">
+ <attribute name="attribute" optional="YES" attributeType="String" syncable="YES"/>
+ </entity>
+ <elements>
+ <element name="Entity" positionX="160" positionY="192" width="128" height="60"/>
+ </elements>
+</model>
View
9 spec/fixtures/CoreData/VersionedModel.xcdatamodeld/VersionedModel.xcdatamodel/contents
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
+<model name="" userDefinedModelVersionIdentifier="" type="com.apple.IDECoreDataModeler.DataModel" documentVersion="1.0" lastSavedToolsVersion="2061" systemVersion="12E55" minimumToolsVersion="Xcode 4.3" macOSVersion="Automatic" iOSVersion="Automatic">
+ <entity name="Entity" syncable="YES">
+ <attribute name="attribute" optional="YES" attributeType="String" syncable="YES"/>
+ </entity>
+ <elements>
+ <element name="Entity" positionX="160" positionY="192" width="128" height="60"/>
+ </elements>
+</model>
View
21 spec/project/object/group_spec.rb
@@ -72,7 +72,7 @@ module ProjectSpecs
ref.path.should == 'Model.xcdatamodeld'
ref.source_tree.should == '<group>'
ref.version_group_type.should == 'wrapper.xcdatamodel'
- ref.children.map(&:path).should == ['Model.xcdatamodel', 'Model 2.xcdatamodel']
+ ref.children.map{ |x| File.basename(x.path) }.should == ['Model.xcdatamodel', 'Model 2.xcdatamodel']
ref.current_version.isa.should == 'PBXFileReference'
ref.current_version.path.should == 'Model 2.xcdatamodel'
ref.current_version.last_known_file_type.should == 'wrapper.xcdatamodel'
@@ -81,6 +81,23 @@ module ProjectSpecs
end
end
+ describe '#new_xcdatamodeld' do
+
+ it "handles xccurrentversion file" do
+ ref = @group.new_file(fixture_path("CoreData/VersionedModel.xcdatamodeld"))
+ ref.isa.should == 'XCVersionGroup'
+ ref.path.should.include 'VersionedModel.xcdatamodeld'
+ ref.source_tree.should == '<group>'
+ ref.version_group_type.should == 'wrapper.xcdatamodel'
+ ref.children.map(&:path).to_set.should == ['VersionedModel.xcdatamodel', 'VersionedModel 2.xcdatamodel'].to_set
+ ref.current_version.isa.should == 'PBXFileReference'
+ ref.current_version.path.should.include 'VersionedModel 2.xcdatamodel'
+ ref.current_version.last_known_file_type.should == 'wrapper.xcdatamodel'
+ ref.current_version.source_tree.should == '<group>'
+ @group.children.should.include(ref)
+ end
+ end
+
it "returns a list of files and groups" do
@group.children.map(&:display_name).sort.should == %w{ Abracadabra.h Abracadabra.m Banana.h Banana.m ZappMachine }
end
@@ -93,7 +110,7 @@ module ProjectSpecs
end
it "adds XCVersionGroups" do
- group = @group.new_xcdatamodel_group('some/Model.xcdatamodeld')
+ group = @group.new_file('some/Model.xcdatamodeld')
group.isa.should == 'XCVersionGroup'
group.source_tree.should == '<group>'
group.version_group_type.should == 'wrapper.xcdatamodel';
Something went wrong with that request. Please try again.