Permalink
Browse files

🚧 Add PackageManagerKit

  • Loading branch information...
1 parent 7b243bf commit 894202cb9fd0cea0cb0c3afccab791fd1a535c81 @andreyvit andreyvit committed Sep 30, 2015
Showing with 3,655 additions and 5 deletions.
  1. +1 βˆ’1 ATVersionKit
  2. +1 βˆ’1 ExpressiveCasting
  3. +1 βˆ’1 ExpressiveCocoa
  4. +1 βˆ’1 ExpressiveCollections
  5. +1 βˆ’1 FSMonitoringKit
  6. +24 βˆ’0 PackageManagerKit/Metadata/Info-Tests.plist
  7. +28 βˆ’0 PackageManagerKit/Metadata/Info.plist
  8. +728 βˆ’0 PackageManagerKit/PackageManagerKit.xcodeproj/project.pbxproj
  9. +1 βˆ’0 PackageManagerKit/README.md
  10. +21 βˆ’0 PackageManagerKit/Source/GenericPackages/LRPackage.h
  11. +32 βˆ’0 PackageManagerKit/Source/GenericPackages/LRPackage.m
  12. +45 βˆ’0 PackageManagerKit/Source/GenericPackages/LRPackageContainer.h
  13. +75 βˆ’0 PackageManagerKit/Source/GenericPackages/LRPackageContainer.m
  14. +23 βˆ’0 PackageManagerKit/Source/GenericPackages/LRPackageManager.h
  15. +79 βˆ’0 PackageManagerKit/Source/GenericPackages/LRPackageManager.m
  16. +20 βˆ’0 PackageManagerKit/Source/GenericPackages/LRPackageReference.h
  17. +33 βˆ’0 PackageManagerKit/Source/GenericPackages/LRPackageReference.m
  18. +16 βˆ’0 PackageManagerKit/Source/GenericPackages/LRPackageResolutionContext.h
  19. +47 βˆ’0 PackageManagerKit/Source/GenericPackages/LRPackageResolutionContext.m
  20. +25 βˆ’0 PackageManagerKit/Source/GenericPackages/LRPackageSet.h
  21. +53 βˆ’0 PackageManagerKit/Source/GenericPackages/LRPackageSet.m
  22. +24 βˆ’0 PackageManagerKit/Source/GenericPackages/LRPackageType.h
  23. +47 βˆ’0 PackageManagerKit/Source/GenericPackages/LRPackageType.m
  24. +6 βˆ’0 PackageManagerKit/Source/GenericRuntime/MissingRuntimeInstance.h
  25. +27 βˆ’0 PackageManagerKit/Source/GenericRuntime/MissingRuntimeInstance.m
  26. +47 βˆ’0 PackageManagerKit/Source/GenericRuntime/RuntimeContainer.h
  27. +175 βˆ’0 PackageManagerKit/Source/GenericRuntime/RuntimeContainer.m
  28. +7 βˆ’0 PackageManagerKit/Source/GenericRuntime/RuntimeGlobals.h
  29. +4 βˆ’0 PackageManagerKit/Source/GenericRuntime/RuntimeGlobals.m
  30. +46 βˆ’0 PackageManagerKit/Source/GenericRuntime/RuntimeInstance.h
  31. +164 βˆ’0 PackageManagerKit/Source/GenericRuntime/RuntimeInstance.m
  32. +16 βˆ’0 PackageManagerKit/Source/GenericRuntime/RuntimeObject.h
  33. +19 βˆ’0 PackageManagerKit/Source/GenericRuntime/RuntimeReference.h
  34. +53 βˆ’0 PackageManagerKit/Source/GenericRuntime/RuntimeReference.m
  35. +42 βˆ’0 PackageManagerKit/Source/GenericRuntime/RuntimeRepository.h
  36. +273 βˆ’0 PackageManagerKit/Source/GenericRuntime/RuntimeRepository.m
  37. +6 βˆ’0 PackageManagerKit/Source/NodePackages/NpmPackage.h
  38. +12 βˆ’0 PackageManagerKit/Source/NodePackages/NpmPackage.m
  39. +10 βˆ’0 PackageManagerKit/Source/NodePackages/NpmPackageContainer.h
  40. +76 βˆ’0 PackageManagerKit/Source/NodePackages/NpmPackageContainer.m
  41. +7 βˆ’0 PackageManagerKit/Source/NodePackages/NpmPackageType.h
  42. +21 βˆ’0 PackageManagerKit/Source/NodePackages/NpmPackageType.m
  43. +46 βˆ’0 PackageManagerKit/Source/PackageManagerKit.h
  44. +2 βˆ’0 PackageManagerKit/Source/PrivateUtilities/SandboxingUtil.h
  45. +16 βˆ’0 PackageManagerKit/Source/PrivateUtilities/SandboxingUtil.m
  46. +7 βˆ’0 PackageManagerKit/Source/RubyGemPackages/GemPackage.h
  47. +12 βˆ’0 PackageManagerKit/Source/RubyGemPackages/GemPackage.m
  48. +11 βˆ’0 PackageManagerKit/Source/RubyGemPackages/GemPackageContainer.h
  49. +67 βˆ’0 PackageManagerKit/Source/RubyGemPackages/GemPackageContainer.m
  50. +7 βˆ’0 PackageManagerKit/Source/RubyGemPackages/GemPackageType.h
  51. +55 βˆ’0 PackageManagerKit/Source/RubyGemPackages/GemPackageType.m
  52. +12 βˆ’0 PackageManagerKit/Source/RubyGemPackages/GemVersion.h
  53. +105 βˆ’0 PackageManagerKit/Source/RubyGemPackages/GemVersion.m
  54. +9 βˆ’0 PackageManagerKit/Source/RubyGemPackages/GemVersionSpace.h
  55. +30 βˆ’0 PackageManagerKit/Source/RubyGemPackages/GemVersionSpace.m
  56. +10 βˆ’0 PackageManagerKit/Source/RubyRuntime/CustomRubyInstance.h
  57. +49 βˆ’0 PackageManagerKit/Source/RubyRuntime/CustomRubyInstance.m
  58. +18 βˆ’0 PackageManagerKit/Source/RubyRuntime/HomebrewContainer.h
  59. +126 βˆ’0 PackageManagerKit/Source/RubyRuntime/HomebrewContainer.m
  60. +12 βˆ’0 PackageManagerKit/Source/RubyRuntime/HomebrewRubyInstance.h
  61. +42 βˆ’0 PackageManagerKit/Source/RubyRuntime/HomebrewRubyInstance.m
  62. +17 βˆ’0 PackageManagerKit/Source/RubyRuntime/RbenvContainer.h
  63. +137 βˆ’0 PackageManagerKit/Source/RubyRuntime/RbenvContainer.m
  64. +12 βˆ’0 PackageManagerKit/Source/RubyRuntime/RbenvRubyInstance.h
  65. +41 βˆ’0 PackageManagerKit/Source/RubyRuntime/RbenvRubyInstance.m
  66. +8 βˆ’0 PackageManagerKit/Source/RubyRuntime/RubyInstance.h
  67. +83 βˆ’0 PackageManagerKit/Source/RubyRuntime/RubyInstance.m
  68. +13 βˆ’0 PackageManagerKit/Source/RubyRuntime/RubyRuntimeRepository.h
  69. +54 βˆ’0 PackageManagerKit/Source/RubyRuntime/RubyRuntimeRepository.m
  70. +18 βˆ’0 PackageManagerKit/Source/RubyRuntime/RvmContainer.h
  71. +138 βˆ’0 PackageManagerKit/Source/RubyRuntime/RvmContainer.m
  72. +12 βˆ’0 PackageManagerKit/Source/RubyRuntime/RvmRubyInstance.h
  73. +64 βˆ’0 PackageManagerKit/Source/RubyRuntime/RvmRubyInstance.m
  74. +8 βˆ’0 PackageManagerKit/Source/RubyRuntime/SystemRubyInstance.h
  75. +38 βˆ’0 PackageManagerKit/Source/RubyRuntime/SystemRubyInstance.m
  76. +39 βˆ’0 PackageManagerKit/Tests/PackageManagerKitTests.m
@@ -0,0 +1,24 @@
+<?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>CFBundleDevelopmentRegion</key>
+ <string>en</string>
+ <key>CFBundleExecutable</key>
+ <string>$(EXECUTABLE_NAME)</string>
+ <key>CFBundleIdentifier</key>
+ <string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
+ <key>CFBundleInfoDictionaryVersion</key>
+ <string>6.0</string>
+ <key>CFBundleName</key>
+ <string>$(PRODUCT_NAME)</string>
+ <key>CFBundlePackageType</key>
+ <string>BNDL</string>
+ <key>CFBundleShortVersionString</key>
+ <string>1.0</string>
+ <key>CFBundleSignature</key>
+ <string>????</string>
+ <key>CFBundleVersion</key>
+ <string>1</string>
+</dict>
+</plist>
@@ -0,0 +1,28 @@
+<?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>CFBundleDevelopmentRegion</key>
+ <string>en</string>
+ <key>CFBundleExecutable</key>
+ <string>$(EXECUTABLE_NAME)</string>
+ <key>CFBundleIdentifier</key>
+ <string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
+ <key>CFBundleInfoDictionaryVersion</key>
+ <string>6.0</string>
+ <key>CFBundleName</key>
+ <string>$(PRODUCT_NAME)</string>
+ <key>CFBundlePackageType</key>
+ <string>FMWK</string>
+ <key>CFBundleShortVersionString</key>
+ <string>1.0</string>
+ <key>CFBundleSignature</key>
+ <string>????</string>
+ <key>CFBundleVersion</key>
+ <string>$(CURRENT_PROJECT_VERSION)</string>
+ <key>NSHumanReadableCopyright</key>
+ <string>Copyright Β© 2015 Andrey Tarantsov. All rights reserved.</string>
+ <key>NSPrincipalClass</key>
+ <string></string>
+</dict>
+</plist>
Oops, something went wrong.
@@ -0,0 +1 @@
+# PackageManagerKit
@@ -0,0 +1,21 @@
+
+#import <Foundation/Foundation.h>
+
+
+@class LRVersion;
+@class LRPackageContainer;
+
+
+@interface LRPackage : NSObject
+
+- (instancetype)initWithName:(NSString *)name version:(LRVersion *)version container:(LRPackageContainer *)container sourceFolderURL:(NSURL *)sourceFolderURL;
+
+@property(nonatomic, readonly) NSString *name;
+@property(nonatomic, readonly) LRVersion *version;
+@property(nonatomic, readonly, weak) LRPackageContainer *container;
+@property(nonatomic, readonly) NSURL *sourceFolderURL;
+
+@property(nonatomic, readonly) NSString *identifier; // type:name
+@property(nonatomic, readonly) NSString *identifierIncludingVersion; // type:name:version
+
+@end
@@ -0,0 +1,32 @@
+
+#import "LRPackage.h"
+#import "LRPackageContainer.h"
+#import "LRPackageType.h"
+@import ATVersionKit;
+
+
+@interface LRPackage ()
+
+@end
+
+
+@implementation LRPackage
+
+- (instancetype)initWithName:(NSString *)name version:(LRVersion *)version container:(LRPackageContainer *)container sourceFolderURL:(NSURL *)sourceFolderURL {
+ self = [super init];
+ if (self) {
+ _name = [name copy];
+ _version = version;
+ _container = container;
+ _sourceFolderURL = sourceFolderURL;
+ _identifier = [_container.packageType identifierOfPackageNamed:_name];
+ _identifierIncludingVersion = [NSString stringWithFormat:@"%@:%@", _identifier, _version.description];
+ }
+ return self;
+}
+
+- (NSString *)description {
+ return [NSString stringWithFormat:@"%@(%@ %@)", NSStringFromClass(self.class), _name, _version];
+}
+
+@end
@@ -0,0 +1,45 @@
+
+#import <Foundation/Foundation.h>
+
+
+@class LRPackageType;
+@class LRPackageReference;
+@class LRPackage;
+@class RuntimeInstance;
+
+
+extern NSString *const LRPackageContainerDidChangePackageListNotification;
+
+
+typedef enum {
+ LRPackageContainerTypeBundled,
+ LRPackageContainerTypeRuntimeInstance,
+ LRPackageContainerTypeOptionalSet,
+ LRPackageContainerTypeProjectLocal
+} LRPackageContainerType;
+
+
+@interface LRPackageContainer : NSObject
+
+- (instancetype)initWithPackageType:(LRPackageType *)packageType;
+
+@property(nonatomic, readonly) LRPackageType *packageType;
+
+@property(nonatomic, readonly) NSArray *packages;
+
+@property(nonatomic) LRPackageContainerType containerType;
+@property(nonatomic, strong) RuntimeInstance *runtimeInstance;
+
+- (NSArray *)packagesMatchingReference:(LRPackageReference *)reference;
+- (LRPackage *)bestPackageMatchingReference:(LRPackageReference *)reference;
+
+- (void)startTrackingPackages;
+- (void)endTrackingPackages;
+
+// for subclasses
+@property(nonatomic, readonly, getter=isUpdateInProgress) BOOL updateInProgress;
+- (void)doUpdate;
+- (void)updateSucceededWithPackages:(NSArray *)packages;
+- (void)updateFailedWithError:(NSError *)error;
+
+@end
@@ -0,0 +1,75 @@
+
+#import "LRPackageContainer.h"
+#import "LRPackageReference.h"
+
+
+NSString *const LRPackageContainerDidChangePackageListNotification = @"LRPackageContainerDidChangePackageList";
+
+
+@interface LRPackageContainer ()
+
+@end
+
+
+@implementation LRPackageContainer
+
+- (instancetype)initWithPackageType:(LRPackageType *)packageType {
+ self = [super init];
+ if (self) {
+ _packageType = packageType;
+ }
+ return self;
+}
+
+- (NSArray *)packagesMatchingReference:(LRPackageReference *)reference {
+ NSMutableArray *result = [NSMutableArray new];
+ for (LRPackage *package in _packages) {
+ if ([reference matchesPackage:package]) {
+ [result addObject:package];
+ }
+ }
+ return result;
+}
+
+- (LRPackage *)bestPackageMatchingReference:(LRPackageReference *)reference {
+ NSArray *choices = [self packagesMatchingReference:reference];
+ if (choices.count == 0)
+ return nil;
+ else
+ return [choices firstObject]; // TODO return the best object
+}
+
+- (void)startTrackingPackages {
+ [self _updatePackages];
+}
+
+- (void)endTrackingPackages {
+
+}
+
+- (void)_updatePackages {
+ if (_updateInProgress)
+ return;
+
+ _updateInProgress = YES;
+ NSLog(@"%@: updating", self);
+ [self doUpdate];
+}
+
+- (void)doUpdate {
+ [self updateSucceededWithPackages:@[]];
+}
+
+- (void)updateSucceededWithPackages:(NSArray *)packages {
+ NSLog(@"%@: update succeeded, found %d packages: %@", self, (int)packages.count, [packages componentsJoinedByString:@", "]);
+ _packages = packages;
+ _updateInProgress = NO;
+ [[NSNotificationCenter defaultCenter] postNotificationName:LRPackageContainerDidChangePackageListNotification object:self];
+}
+
+- (void)updateFailedWithError:(NSError *)error {
+ NSLog(@"%@: update failed: %@ - %ld - %@", self, error.domain, (long)error.code, error.localizedDescription);
+ _updateInProgress = NO;
+}
+
+@end
@@ -0,0 +1,23 @@
+
+#import <Foundation/Foundation.h>
+
+
+@class LRPackageType;
+@class LRPackageContainer;
+@class LRPackageReference;
+
+
+@interface LRPackageManager : NSObject
+
+- (void)addPackageType:(LRPackageType *)type;
+- (LRPackageType *)packageTypeNamed:(NSString *)name;
+
+@property(nonatomic, readonly) NSArray *packageTypes;
+
+- (void)addPackageContainer:(LRPackageContainer *)container;
+- (void)removePackageContainer:(LRPackageContainer *)container;
+
+- (LRPackageReference *)packageReferenceWithDictionary:(NSDictionary *)dictionary;
+- (LRPackageReference *)packageReferenceWithString:(NSString *)string;
+
+@end
@@ -0,0 +1,79 @@
+
+#import "LRPackageManager.h"
+#import "LRPackageType.h"
+#import "LRPackageReference.h"
+@import ATVersionKit;
+
+
+@interface LRPackageManager ()
+
+@end
+
+
+@implementation LRPackageManager {
+ NSMutableArray *_packageTypes;
+ NSMutableDictionary *_packageTypesByName;
+}
+
+- (id)init {
+ self = [super init];
+ if (self) {
+ _packageTypes = [NSMutableArray new];
+ _packageTypesByName = [NSMutableDictionary new];
+ }
+ return self;
+}
+
+- (void)addPackageType:(LRPackageType *)type {
+ [_packageTypes addObject:type];
+ _packageTypesByName[type.name] = type;
+}
+
+- (LRPackageType *)packageTypeNamed:(NSString *)name {
+ return _packageTypesByName[name];
+}
+
+- (NSArray *)packageTypes {
+ return [_packageTypes copy];
+}
+
+- (void)addPackageContainer:(LRPackageContainer *)container {
+
+}
+
+- (void)removePackageContainer:(LRPackageContainer *)container {
+
+}
+
+- (LRPackageReference *)packageReferenceWithDictionary:(NSDictionary *)dictionary {
+ NSString *typeName = dictionary[@"type"];
+ if (!typeName)
+ return nil;
+ LRPackageType *type = [self packageTypeNamed:typeName];
+ if (!type)
+ return nil;
+
+ NSString *name = dictionary[@"name"];
+ if (!name)
+ return nil;
+
+ NSString *versionSpec = dictionary[@"version"];
+ LRVersionSet *versionSet = nil;
+ if (versionSpec) {
+ versionSet = [type.versionSpace versionSetWithString:versionSpec];
+ if (!versionSet.valid) {
+ NSLog(@"Package '%@' version spec problem: %@", name, versionSet.error.localizedDescription);
+ }
+ }
+
+ return [[LRPackageReference alloc] initWithType:type name:name versionSpec:versionSet];
+}
+
+- (LRPackageReference *)packageReferenceWithString:(NSString *)string {
+ NSArray *components = [string componentsSeparatedByString:@":"];
+ if (components.count != 3)
+ return nil;
+ return [self packageReferenceWithDictionary:@{@"type": components[0], @"name": components[1], @"version": components[2]}];
+}
+
+@end
@@ -0,0 +1,20 @@
+
+#import <Foundation/Foundation.h>
+
+
+@class LRPackageType;
+@class LRVersionSet;
+@class LRPackage;
+
+
+@interface LRPackageReference : NSObject
+
+- (instancetype)initWithType:(LRPackageType *)type name:(NSString *)name versionSpec:(LRVersionSet *)versionSet;
+
+@property(nonatomic, readonly) LRPackageType *type;
+@property(nonatomic, readonly) NSString *name;
+@property(nonatomic, readonly) LRVersionSet *versionSpec;
+
+- (BOOL)matchesPackage:(LRPackage *)package;
+
+@end
Oops, something went wrong.

0 comments on commit 894202c

Please sign in to comment.