Skip to content

Commit

Permalink
Started building caching mechanism
Browse files Browse the repository at this point in the history
  • Loading branch information
wokalski committed Apr 9, 2014
1 parent 362e85d commit b68841a
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 39 deletions.
4 changes: 4 additions & 0 deletions KFCocoaPodsPlugin.xcodeproj/project.pbxproj
Expand Up @@ -37,6 +37,7 @@
1DDE21BF17D8B08D0015857D /* KFConsoleController.m in Sources */ = {isa = PBXBuildFile; fileRef = 1DDE21BE17D8B08D0015857D /* KFConsoleController.m */; };
1DF28C9017DA5B6B00DFBD5C /* KFNotificationController.m in Sources */ = {isa = PBXBuildFile; fileRef = 1DF28C8F17DA5B6B00DFBD5C /* KFNotificationController.m */; };
C8DBFFE38BD1451BB6DACAF9 /* libPods.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 8B5BF65125F74E12891B4621 /* libPods.a */; };
C909375F18F5DBCC00234BDD /* ReposCache in Resources */ = {isa = PBXBuildFile; fileRef = C909375E18F5DBCC00234BDD /* ReposCache */; };
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
Expand Down Expand Up @@ -99,6 +100,7 @@
1DF28C8F17DA5B6B00DFBD5C /* KFNotificationController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = KFNotificationController.m; path = Sources/Controllers/KFNotificationController.m; sourceTree = "<group>"; };
890D3963EC534E2586D5020C /* Pods.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = Pods.xcconfig; path = Pods/Pods.xcconfig; sourceTree = SOURCE_ROOT; };
8B5BF65125F74E12891B4621 /* libPods.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libPods.a; sourceTree = BUILT_PRODUCTS_DIR; };
C909375E18F5DBCC00234BDD /* ReposCache */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = ReposCache; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -253,6 +255,7 @@
isa = PBXGroup;
children = (
1DA3B241183839C60009AC4E /* KFPodSearchWindow.xib */,
C909375E18F5DBCC00234BDD /* ReposCache */,
);
name = Resources;
sourceTree = "<group>";
Expand Down Expand Up @@ -349,6 +352,7 @@
1D02735217D746CC00E8389F /* InfoPlist.strings in Resources */,
1DDB9A9B17DE4E4200B69C9D /* PodSyntax.plist in Resources */,
1DA3B243183839C60009AC4E /* KFPodSearchWindow.xib in Resources */,
C909375F18F5DBCC00234BDD /* ReposCache in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
Expand Up @@ -5,34 +5,34 @@
<key>IDESourceControlProjectFavoriteDictionaryKey</key>
<false/>
<key>IDESourceControlProjectIdentifier</key>
<string>49BC308F-F776-4D75-9A75-384DD87FE4C5</string>
<string>F3ED37DB-F20A-421D-8995-1F803AEBD5B6</string>
<key>IDESourceControlProjectName</key>
<string>KFCocoaPodsPlugin</string>
<key>IDESourceControlProjectOriginsDictionary</key>
<dict>
<key>E00B30B8-2F7E-4AE2-B2B3-D019DCCAB9B8</key>
<string>https://github.com/ricobeck/KFCocoaPodsPlugin.git</string>
<key>08D5F82E-B56D-4A60-8F6D-B0845DABE4DD</key>
<string>https://github.com/wczekalski/KFCocoaPodsPlugin.git</string>
</dict>
<key>IDESourceControlProjectPath</key>
<string>KFCocoaPodsPlugin.xcworkspace</string>
<key>IDESourceControlProjectRelativeInstallPathDictionary</key>
<dict>
<key>E00B30B8-2F7E-4AE2-B2B3-D019DCCAB9B8</key>
<key>08D5F82E-B56D-4A60-8F6D-B0845DABE4DD</key>
<string>..</string>
</dict>
<key>IDESourceControlProjectURL</key>
<string>https://github.com/ricobeck/KFCocoaPodsPlugin.git</string>
<string>https://github.com/wczekalski/KFCocoaPodsPlugin.git</string>
<key>IDESourceControlProjectVersion</key>
<integer>110</integer>
<key>IDESourceControlProjectWCCIdentifier</key>
<string>E00B30B8-2F7E-4AE2-B2B3-D019DCCAB9B8</string>
<string>08D5F82E-B56D-4A60-8F6D-B0845DABE4DD</string>
<key>IDESourceControlProjectWCConfigurations</key>
<array>
<dict>
<key>IDESourceControlRepositoryExtensionIdentifierKey</key>
<string>public.vcs.git</string>
<key>IDESourceControlWCCIdentifierKey</key>
<string>E00B30B8-2F7E-4AE2-B2B3-D019DCCAB9B8</string>
<string>08D5F82E-B56D-4A60-8F6D-B0845DABE4DD</string>
<key>IDESourceControlWCCName</key>
<string>KFCocoaPodsPlugin</string>
</dict>
Expand Down
2 changes: 1 addition & 1 deletion KFCocoaPodsPlugin/KFCocoaPodsPlugin-Info.plist
Expand Up @@ -21,7 +21,7 @@
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>150</string>
<string>153</string>
<key>DVTPlugInCompatibilityUUIDs</key>
<array>
<string>63FC1C47-140D-42B0-BB4D-A10B2D225574</string>
Expand Down
90 changes: 59 additions & 31 deletions KFCocoaPodsPlugin/KFCocoaPodsPlugin.m
Expand Up @@ -198,50 +198,78 @@ - (void)buildRepoIndex
[self printMessage:NSLocalizedString(@"Building repo index", nil)];

NSMutableDictionary *parsedRepos = [NSMutableDictionary new];
NSArray *repos = [fileManager contentsOfDirectoryAtPath:[@"~/.cocoapods/repos/" stringByExpandingTildeInPath] error:nil];
NSString *cocoapodsReposPath = [@"~/.cocoapods/repos/" stringByExpandingTildeInPath];
NSArray *repos = [fileManager contentsOfDirectoryAtPath:cocoapodsReposPath error:nil];

for (NSString *repoDirectory in repos)
{

NSString *repoPath = [[@"~/.cocoapods/repos" stringByAppendingPathComponent:repoDirectory] stringByExpandingTildeInPath];
NSArray *pods = [fileManager contentsOfDirectoryAtPath:repoPath error:nil];

for (NSString *podDirectory in pods)
NSBundle *pluginBundle = [NSBundle bundleForClass:[self class]];
NSString *cachesPath = [pluginBundle pathForResource:@"ReposCache" ofType:@""];

NSData *cachedReposData = [NSData dataWithContentsOfFile:cachesPath];
NSDictionary *cachedRepos;
NSDate *cachesLastModifiedDate;

if (cachedReposData) {
cachedRepos = [NSJSONSerialization JSONObjectWithData:cachedReposData options:0 error:nil];
cachesLastModifiedDate = [cachedRepos objectForKey:@"lastModifiedDate"];
}

NSError *error = nil;

NSDictionary *cocoapodsReposAttributes = [fileManager attributesOfItemAtPath:cocoapodsReposPath error:&error];
NSLog(@"Error: %@", error);
NSLog(@"Repo attributes: %@", cocoapodsReposAttributes);
NSDate *cocoapodsReposLastModifiedDate = [cocoapodsReposAttributes objectForKey:NSFileModificationDate];

NSLog(@"Cocoapods last modified date: %@", cocoapodsReposLastModifiedDate);
NSLog(@"Caches last modified date: %@", cachesLastModifiedDate);

if (![cocoapodsReposLastModifiedDate isEqualToDate:cachesLastModifiedDate]) {
for (NSString *repoDirectory in repos)
{
if (![podDirectory hasPrefix:@"."])

NSString *repoPath = [[@"~/.cocoapods/repos" stringByAppendingPathComponent:repoDirectory] stringByExpandingTildeInPath];
NSArray *pods = [fileManager contentsOfDirectoryAtPath:repoPath error:nil];

for (NSString *podDirectory in pods)
{
NSString *podPath = [repoPath stringByAppendingPathComponent:podDirectory];
NSArray *versions = [fileManager contentsOfDirectoryAtPath:podPath error:nil];

NSMutableArray *specs = [NSMutableArray new];

for (NSString *version in versions)
if (![podDirectory hasPrefix:@"."])
{
KFRepoModel *repoModel = [KFRepoModel new];
repoModel.pod = podDirectory;
repoModel.version = version;
NSString *podPath = [repoPath stringByAppendingPathComponent:podDirectory];
NSArray *versions = [fileManager contentsOfDirectoryAtPath:podPath error:nil];

NSString *specPath = [podPath stringByAppendingPathComponent:version];
NSArray *files = [fileManager contentsOfDirectoryAtPath:specPath error:nil];
for (NSString *podspec in files)
NSMutableArray *specs = [NSMutableArray new];

for (NSString *version in versions)
{
if ([podspec.pathExtension isEqualToString:@"podspec"])
KFRepoModel *repoModel = [KFRepoModel new];
repoModel.pod = podDirectory;
repoModel.version = version;

NSString *specPath = [podPath stringByAppendingPathComponent:version];
NSArray *files = [fileManager contentsOfDirectoryAtPath:specPath error:nil];
for (NSString *podspec in files)
{
NSString *specFilePath = [specPath stringByAppendingPathComponent:podspec];
NSData *contents = [NSData dataWithContentsOfFile:specFilePath];
repoModel.checksum = [contents ks_SHA1DigestString];
repoModel.podspec = contents;
repoModel.specFilePath = specFilePath;
if ([podspec.pathExtension isEqualToString:@"podspec"])
{
NSString *specFilePath = [specPath stringByAppendingPathComponent:podspec];
NSData *contents = [NSData dataWithContentsOfFile:specFilePath];
repoModel.checksum = [contents ks_SHA1DigestString];
repoModel.podspec = contents;
repoModel.specFilePath = specFilePath;
}
}
[specs addObject:repoModel];
}
[specs addObject:repoModel];
[parsedRepos setValue:[specs sortedArrayUsingDescriptors:@[[NSSortDescriptor sortDescriptorWithKey:@"version" ascending:NO]]] forKey:podDirectory];
}
[parsedRepos setValue:[specs sortedArrayUsingDescriptors:@[[NSSortDescriptor sortDescriptorWithKey:@"version" ascending:NO]]] forKey:podDirectory];
}
}
NSDictionary *newCacheDictionary = @{@"lastModifiedDate": cocoapodsReposLastModifiedDate, @"parsedContents" : parsedRepos};
[[NSJSONSerialization dataWithJSONObject:newCacheDictionary options:0 error:nil] writeToFile:cachesPath atomically:YES];
self.repos = [parsedRepos copy];
} else {
self.repos = [cachedRepos objectForKey:@"parsedContents"];
}

self.repos = [parsedRepos copy];
}

- (void)insertLoadingMenu {
Expand Down
Empty file added KFCocoaPodsPlugin/ReposCache
Empty file.

0 comments on commit b68841a

Please sign in to comment.