Skip to content
This repository has been archived by the owner on Feb 2, 2021. It is now read-only.

Commit

Permalink
Collect only currently logged in user-specific schemes rather then al…
Browse files Browse the repository at this point in the history
…l available.
  • Loading branch information
ExtremeMan committed Aug 13, 2015
1 parent 6933e85 commit 728150d
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 16 deletions.
59 changes: 57 additions & 2 deletions xctool/xctool-tests/XcodeSubjectInfoTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,68 @@ - (void)testCanGetProjectPathsInProjectWithNestedProjects
]]));
}

- (void)testCanGetAllSchemesInAProject
- (void)testCanGetAllSchemesInAProjectIncludingCurrentlyLoggedInUserOne
{
NSArray *schemes = [XcodeSubjectInfo schemePathsInContainer:TEST_DATA @"TestProject-Library/TestProject-Library.xcodeproj"];
NSString *projectPath = TEST_DATA @"TestProject-Library/TestProject-Library.xcodeproj";
// create a scheme for a currently logged in user
NSString *schemePath = [NSString pathWithComponents:@[
projectPath,
@"xcuserdata",
[NSUserName() stringByAppendingPathExtension:@"xcuserdatad"],
@"xcschemes",
@"XCTOOL_TEST_SCHEME.xcscheme",
]];
NSError *error = nil;
// create directories if needed
BOOL schemeCreated = [[NSFileManager defaultManager] createDirectoryAtPath:[schemePath stringByDeletingLastPathComponent] withIntermediateDirectories:YES attributes:nil error:&error];
XCTAssert(schemeCreated, @"Test scheme creation failed with error: %@", error);
// remove scheme if it was created previously
[[NSFileManager defaultManager] removeItemAtPath:schemePath error:&error];
// create a new test scheme
schemeCreated = [[NSFileManager defaultManager] createFileAtPath:schemePath contents:[@"" dataUsingEncoding:NSUTF8StringEncoding] attributes:nil];
XCTAssert(schemeCreated, @"Test scheme creation failed.");

NSArray *schemes = [XcodeSubjectInfo schemePathsInContainer:projectPath];
assertThat(schemes, equalTo(@[
TEST_DATA @"TestProject-Library/TestProject-Library.xcodeproj/xcshareddata/xcschemes/Target Name With Spaces.xcscheme",
TEST_DATA @"TestProject-Library/TestProject-Library.xcodeproj/xcshareddata/xcschemes/TestProject-Library.xcscheme",
schemePath,
]));

// remove a test scheme
schemeCreated = [[NSFileManager defaultManager] removeItemAtPath:schemePath error:&error];
XCTAssert(schemeCreated, @"Failed to remove test scheme at path: %@ with error: %@", schemePath, error);
}

- (void)testCanGetAllSchemesInAWorkspaceIgnoringNotCurrentlyLoggedUserSchemes
{
NSString *workspacePath = TEST_DATA @"TestWorkspace-Library/TestWorkspace-Library.xcworkspace";
// create a scheme for a currently logged in user
NSString *schemePath = [NSString pathWithComponents:@[
workspacePath,
@"xcuserdata",
[[NSUserName() stringByAppendingString:@"_xctool"] stringByAppendingPathExtension:@"xcuserdatad"],
@"xcschemes",
@"XCTOOL_TEST_SCHEME.xcscheme",
]];
NSError *error = nil;
// create directories if needed
BOOL schemeCreated = [[NSFileManager defaultManager] createDirectoryAtPath:[schemePath stringByDeletingLastPathComponent] withIntermediateDirectories:YES attributes:nil error:&error];
XCTAssert(schemeCreated, @"Test scheme creation failed with error: %@", error);
// remove scheme if it was created previously
[[NSFileManager defaultManager] removeItemAtPath:schemePath error:&error];
// create a new test scheme
schemeCreated = [[NSFileManager defaultManager] createFileAtPath:schemePath contents:[@"" dataUsingEncoding:NSUTF8StringEncoding] attributes:nil];
XCTAssert(schemeCreated, @"Test scheme creation failed.");

NSArray *schemes = [XcodeSubjectInfo schemePathsInWorkspace:workspacePath];
assertThat(schemes, equalTo(@[
TEST_DATA @"TestWorkspace-Library/TestProject-Library/TestProject-Library.xcodeproj/xcshareddata/xcschemes/TestProject-Library.xcscheme",
]));

// remove test scheme
schemeCreated = [[NSFileManager defaultManager] removeItemAtPath:schemePath error:&error];
XCTAssert(schemeCreated, @"Failed to remove test scheme at path: %@ with error: %@", schemePath, error);
}

- (void)testCanGetAllSchemesInAProjectWithNestedProjects
Expand Down
24 changes: 10 additions & 14 deletions xctool/xctool/XcodeSubjectInfo.m
Original file line number Diff line number Diff line change
Expand Up @@ -245,20 +245,16 @@ + (NSArray *)schemePathsInContainer:(NSString *)project
}

// Collect user-specific schemes.
NSString *userdataPath = [project stringByAppendingPathComponent:@"xcuserdata"];
NSArray *userContents = [fm contentsOfDirectoryAtPath:userdataPath
error:nil];
if (userContents != nil) {
for (NSString *file in userContents) {
if ([file hasSuffix:@".xcuserdatad"]) {
NSString *userSchemesPath = [[userdataPath stringByAppendingPathComponent:file] stringByAppendingPathComponent:@"xcschemes"];
NSArray *userSchemesContents = [fm contentsOfDirectoryAtPath:userSchemesPath error:nil];

for (NSString *file in userSchemesContents) {
if ([file hasSuffix:@".xcscheme"]) {
[schemes addObject:[userSchemesPath stringByAppendingPathComponent:file]];
}
}
NSString *currentlyLoggedInUserSchemesPath = [NSString pathWithComponents:@[
[project stringByAppendingPathComponent:@"xcuserdata"],
[NSUserName() stringByAppendingPathExtension:@"xcuserdatad"],
@"xcschemes"
]];
if ([fm fileExistsAtPath:currentlyLoggedInUserSchemesPath]) {
NSArray *userSchemesContents = [fm contentsOfDirectoryAtPath:currentlyLoggedInUserSchemesPath error:nil];
for (NSString *file in userSchemesContents) {
if ([file hasSuffix:@".xcscheme"]) {
[schemes addObject:[currentlyLoggedInUserSchemesPath stringByAppendingPathComponent:file]];
}
}
}
Expand Down

0 comments on commit 728150d

Please sign in to comment.