Skip to content

Commit 0b5ce49

Browse files
committed
Address review feedback
1 parent 485d8c9 commit 0b5ce49

File tree

17 files changed

+110
-168
lines changed

17 files changed

+110
-168
lines changed

Example/Auth/Tests/FIRAuthTests.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
#import <FirebaseAuthInterop/FIRAuthInterop.h>
2222
#import <FirebaseCore/FIRAppInternal.h>
2323
#import <FirebaseCore/FIRComponent.h>
24-
#import <FirebaseCore/FIRComponentRegistrant.h>
24+
#import <FirebaseCore/FIRLibrary.h>
2525

2626
#import "FIRAdditionalUserInfo.h"
2727
#import "FIRAuth_Internal.h"
@@ -225,7 +225,7 @@
225225
static const NSTimeInterval kWaitInterval = .5;
226226

227227
/** Category for FIRAuth to expose FIRComponentRegistrant conformance. */
228-
@interface FIRAuth () <FIRComponentRegistrant>
228+
@interface FIRAuth () <FIRLibrary>
229229
@end
230230

231231
/** @class FIRAuthTests

Example/Core/Tests/FIRAppTest.m

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -778,38 +778,23 @@ - (void)testIsDefaultAppConfigured {
778778
}
779779

780780
- (void)testIllegalLibraryName {
781-
[FIRApp registerLibrary:@"Oops>"
782-
withVersion:@"1.0.0"
783-
withComponentRegistrant:nil
784-
withConfigurable:nil];
781+
[FIRApp registerLibrary:nil withName:@"Oops>" withVersion:@"1.0.0"];
785782
XCTAssertTrue([[FIRApp firebaseUserAgent] isEqualToString:@""]);
786783
}
787784

788785
- (void)testIllegalLibraryVersion {
789-
[FIRApp registerLibrary:@"LegalName"
790-
withVersion:@"1.0.0+"
791-
withComponentRegistrant:nil
792-
withConfigurable:nil];
786+
[FIRApp registerLibrary:nil withName:@"LegalName" withVersion:@"1.0.0+"];
793787
XCTAssertTrue([[FIRApp firebaseUserAgent] isEqualToString:@""]);
794788
}
795789

796790
- (void)testSingleLibrary {
797-
[FIRApp registerLibrary:@"LegalName"
798-
withVersion:@"1.0.0"
799-
withComponentRegistrant:nil
800-
withConfigurable:nil];
791+
[FIRApp registerLibrary:nil withName:@"LegalName" withVersion:@"1.0.0"];
801792
XCTAssertTrue([[FIRApp firebaseUserAgent] containsString:@"LegalName/1.0.0"]);
802793
}
803794

804795
- (void)testMultipleLibraries {
805-
[FIRApp registerLibrary:@"LegalName"
806-
withVersion:@"1.0.0"
807-
withComponentRegistrant:nil
808-
withConfigurable:nil];
809-
[FIRApp registerLibrary:@"LegalName2"
810-
withVersion:@"2.0.0"
811-
withComponentRegistrant:nil
812-
withConfigurable:nil];
796+
[FIRApp registerLibrary:nil withName:@"LegalName" withVersion:@"1.0.0"];
797+
[FIRApp registerLibrary:nil withName:@"LegalName2" withVersion:@"2.0.0"];
813798
XCTAssertTrue([[FIRApp firebaseUserAgent] containsString:@"LegalName/1.0.0 LegalName2/2.0.0"]);
814799
}
815800

Example/Core/Tests/FIRTestComponents.h

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
#import <FirebaseCore/FIRComponent.h>
1818
#import <FirebaseCore/FIRComponentContainer.h>
19-
#import <FirebaseCore/FIRComponentRegistrant.h>
19+
#import <FirebaseCore/FIRLibrary.h>
2020

2121
@protocol FIRComponentRegistrant;
2222

@@ -28,13 +28,12 @@
2828
@end
2929

3030
/// A test class that is a component registrant.
31-
@interface FIRTestClass
32-
: NSObject <FIRTestProtocol, FIRComponentRegistrant, FIRComponentLifecycleMaintainer>
31+
@interface FIRTestClass : NSObject <FIRTestProtocol, FIRComponentLifecycleMaintainer, FIRLibrary>
3332
@end
3433

3534
/// A test class that is a component registrant, a duplicate of FIRTestClass.
3635
@interface FIRTestClassDuplicate
37-
: NSObject <FIRTestProtocol, FIRComponentRegistrant, FIRComponentLifecycleMaintainer>
36+
: NSObject <FIRTestProtocol, FIRComponentLifecycleMaintainer, FIRLibrary>
3837
@end
3938

4039
#pragma mark - Eager Component
@@ -47,7 +46,7 @@
4746
/// A test class that is a component registrant that provides a component requiring eager
4847
/// instantiation, and is cached for easier validation that it was instantiated.
4948
@interface FIRTestClassEagerCached
50-
: NSObject <FIRTestProtocolEagerCached, FIRComponentRegistrant, FIRComponentLifecycleMaintainer>
49+
: NSObject <FIRTestProtocol, FIRComponentLifecycleMaintainer, FIRLibrary>
5150
@end
5251

5352
#pragma mark - Cached Component
@@ -59,5 +58,5 @@
5958
/// A test class that is a component registrant that provides a component that requests to be
6059
/// cached.
6160
@interface FIRTestClassCached
62-
: NSObject <FIRTestProtocolCached, FIRComponentRegistrant, FIRComponentLifecycleMaintainer>
61+
: NSObject <FIRTestProtocol, FIRComponentLifecycleMaintainer, FIRLibrary>
6362
@end

Example/Core/Tests/FIRTestComponents.m

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ @implementation FIRTestClassDuplicate
4747
- (void)doSomething {
4848
}
4949

50-
/// FIRComponentRegistrant conformance.
50+
/// FIRLibrary conformance.
5151
+ (nonnull NSArray<FIRComponent *> *)componentsToRegister {
5252
FIRComponent *testComponent =
5353
[FIRComponent componentWithProtocol:@protocol(FIRTestProtocol)
@@ -72,7 +72,7 @@ @implementation FIRTestClassEagerCached
7272
- (void)doSomethingFaster {
7373
}
7474

75-
/// FIRComponentRegistrant conformance.
75+
/// FIRLibrary conformance.
7676
+ (nonnull NSArray<FIRComponent *> *)componentsToRegister {
7777
FIRComponent *testComponent = [FIRComponent
7878
componentWithProtocol:@protocol(FIRTestProtocolEagerCached)
@@ -92,13 +92,16 @@ - (void)doSomethingFaster {
9292
- (void)appWillBeDeleted:(FIRApp *)app {
9393
}
9494

95+
- (void)doSomething {
96+
}
97+
9598
@end
9699

97100
#pragma mark - Cached Component
98101

99102
@implementation FIRTestClassCached
100103

101-
/// FIRComponentRegistrant conformance.
104+
/// FIRLibrary conformance.
102105
+ (nonnull NSArray<FIRComponent *> *)componentsToRegister {
103106
FIRComponent *testComponent = [FIRComponent
104107
componentWithProtocol:@protocol(FIRTestProtocolCached)
@@ -115,4 +118,7 @@ @implementation FIRTestClassCached
115118
- (void)appWillBeDeleted:(FIRApp *)app {
116119
}
117120

121+
- (void)doSomething {
122+
}
123+
118124
@end

Example/Storage/Tests/Unit/FIRStorageComponentTests.m

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,15 @@
1919

2020
#import <FirebaseCore/FIRAppInternal.h>
2121
#import <FirebaseCore/FIRComponent.h>
22-
#import <FirebaseCore/FIRComponentRegistrant.h>
22+
#import <FirebaseCore/FIRLibrary.h>
2323
#import <FirebaseCore/FIROptions.h>
2424

2525
#import "FIRComponentTestUtilities.h"
2626
#import "FIRStorageComponent.h"
2727

2828
// Make FIRComponentRegistrant conformance visible to the tests and expose the initializer.
29-
@interface FIRStorageComponent () <FIRComponentRegistrant>
30-
/// Internal intializer.
29+
@interface FIRStorageComponent () <FIRLibrary>
30+
/// Internal initializer.
3131
- (instancetype)initWithApp:(FIRApp *)app;
3232
@end
3333

Firebase/Auth/Source/FIRAuth.m

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,7 @@
2727
#import <FirebaseCore/FIRAppInternal.h>
2828
#import <FirebaseCore/FIRComponent.h>
2929
#import <FirebaseCore/FIRComponentContainer.h>
30-
#import <FirebaseCore/FIRComponentRegistrant.h>
31-
#import <FirebaseCore/FIRCoreConfigurable.h>
30+
#import <FirebaseCore/FIRLibrary.h>
3231
#import <FirebaseCore/FIRLogger.h>
3332
#import <FirebaseCore/FIROptions.h>
3433
#import <GoogleUtilities/GULAppEnvironmentUtil.h>
@@ -226,9 +225,10 @@ + (FIRActionCodeOperation)actionCodeOperationForRequestType:(NSString *)requestT
226225
#pragma mark - FIRAuth
227226

228227
#if TARGET_OS_IOS
229-
@interface FIRAuth () <FIRAuthAppDelegateHandler, FIRAuthInterop, FIRComponentRegistrant, FIRCoreConfigurable, FIRComponentLifecycleMaintainer>
228+
@interface FIRAuth () <FIRAuthAppDelegateHandler, FIRAuthInterop, FIRLibrary,
229+
FIRComponentLifecycleMaintainer>
230230
#else
231-
@interface FIRAuth () <FIRAuthInterop, FIRComponentRegistrant, FIRCoreConfigurable, FIRComponentLifecycleMaintainer>
231+
@interface FIRAuth () <FIRAuthInterop, FIRLibrary, FIRComponentLifecycleMaintainer>
232232
#endif
233233

234234
/** @property firebaseAppId
@@ -308,8 +308,9 @@ @implementation FIRAuth {
308308
}
309309

310310
+ (void)load {
311-
[FIRApp registerLibrary:@"FirebaseAuth" withVersion:[NSString stringWithUTF8String:FirebaseAuthVersionStr] withComponentRegistrant:self withConfigurable:self];
312-
[FIRComponentContainer registerAsComponentRegistrant:self];
311+
[FIRApp registerLibrary:(id<FIRLibrary>)self
312+
withName:@"auth"
313+
withVersion:[NSString stringWithUTF8String:FirebaseAuthVersionStr]];
313314
[FIRApp registerAsConfigurable:self];
314315
}
315316

Firebase/Core/FIRApp.m

Lines changed: 18 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,15 @@
1414

1515
#include <sys/utsname.h>
1616

17-
#import "FIRApp.h"
18-
#import "FIRConfiguration.h"
1917
#import "Private/FIRAnalyticsConfiguration+Internal.h"
2018
#import "Private/FIRAppInternal.h"
2119
#import "Private/FIRBundleUtil.h"
2220
#import "Private/FIRComponentContainerInternal.h"
23-
#import "Private/FIRCoreConfigurable.h"
21+
#import "Private/FIRLibrary.h"
2422
#import "Private/FIRLogger.h"
2523
#import "Private/FIROptionsInternal.h"
24+
#import "Public/FIRApp.h"
25+
#import "Public/FIRConfiguration.h"
2626

2727
NSString *const kFIRServiceAdMob = @"AdMob";
2828
NSString *const kFIRServiceAuth = @"Auth";
@@ -81,7 +81,7 @@
8181
* An array of all classes that registered as `FIRCoreConfigurable` in order to receive lifecycle
8282
* events from Core.
8383
*/
84-
static NSMutableArray<Class<FIRCoreConfigurable>> *gRegisteredAsConfigurable;
84+
static NSMutableArray<Class<FIRLibrary>> *gRegisteredAsConfigurable;
8585

8686
@interface FIRApp ()
8787

@@ -431,7 +431,7 @@ + (void)sendNotificationsToSDKs:(FIRApp *)app {
431431

432432
// This is the new way of sending information to SDKs.
433433
// TODO: Do we want this on a background thread, maybe?
434-
for (Class<FIRCoreConfigurable> library in gRegisteredAsConfigurable) {
434+
for (Class<FIRLibrary> library in gRegisteredAsConfigurable) {
435435
[library configureWithApp:app];
436436
}
437437
}
@@ -471,49 +471,45 @@ + (NSError *)errorForInvalidAppID {
471471
userInfo:errorDict];
472472
}
473473

474-
+ (void)registerAsConfigurable:(Class<FIRCoreConfigurable>)klass {
474+
+ (void)registerAsConfigurable:(Class<FIRLibrary>)klass {
475475
// This is called at +load time, keep the work to a minimum.
476476
static dispatch_once_t onceToken;
477477
dispatch_once(&onceToken, ^{
478478
gRegisteredAsConfigurable = [[NSMutableArray alloc] initWithCapacity:1];
479479
});
480-
481-
NSAssert([(Class)klass conformsToProtocol:@protocol(FIRCoreConfigurable)],
482-
@"The class being registered (%@) must conform to `FIRCoreConfigurable`.", klass);
480+
NSAssert([(Class)klass conformsToProtocol:@protocol(FIRLibrary)] &&
481+
[(Class)klass respondsToSelector:@selector(configureWithApp:)],
482+
@"The class being registered (%@) must conform to `FIRLibrary`.", klass);
483483
[gRegisteredAsConfigurable addObject:klass];
484484
}
485485

486486
+ (BOOL)isDefaultAppConfigured {
487487
return (sDefaultApp != nil);
488488
}
489489

490-
+ (void)registerLibrary:(nonnull NSString *)library
491-
withVersion:(nonnull NSString *)version
492-
withComponentRegistrant:(nullable Class)componentRegistrant
493-
withConfigurable:(nullable Class<FIRCoreConfigurable>)configurableRegistrant {
490+
+ (void)registerLibrary:(nullable id<FIRLibrary>)library
491+
withName:(nonnull NSString *)name
492+
withVersion:(nonnull NSString *)version {
493+
if (library) {
494+
[FIRComponentContainer registerAsComponentRegistrant:library];
495+
}
494496
// Create the set of characters which aren't allowed, only if this feature is used.
495497
NSMutableCharacterSet *allowedSet = [NSMutableCharacterSet alphanumericCharacterSet];
496498
[allowedSet addCharactersInString:@"-_."];
497499
NSCharacterSet *disallowedSet = [allowedSet invertedSet];
498500
// Make sure the library name and version strings do not contain unexpected characters, and
499501
// add the name/version pair to the dictionary.
500-
if ([library rangeOfCharacterFromSet:disallowedSet].location == NSNotFound &&
502+
if ([name rangeOfCharacterFromSet:disallowedSet].location == NSNotFound &&
501503
[version rangeOfCharacterFromSet:disallowedSet].location == NSNotFound) {
502504
if (!sLibraryVersions) {
503505
sLibraryVersions = [[NSMutableDictionary alloc] init];
504506
}
505-
sLibraryVersions[library] = version;
507+
sLibraryVersions[name] = version;
506508
} else {
507509
FIRLogError(kFIRLoggerCore, @"I-COR000027",
508510
@"The library name (%@) or version number (%@) contain illegal characters. "
509511
@"Only alphanumeric, dash, underscore and period characters are allowed.",
510-
library, version);
511-
}
512-
if (configurableRegistrant) {
513-
[FIRApp registerAsConfigurable:configurableRegistrant];
514-
}
515-
if (componentRegistrant) {
516-
[FIRComponentContainer registerAsComponentRegistrant:componentRegistrant];
512+
name, version);
517513
}
518514
}
519515

Firebase/Core/FIRComponentContainer.m

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
#import "Private/FIRAppInternal.h"
2020
#import "Private/FIRComponent.h"
21-
#import "Private/FIRComponentRegistrant.h"
21+
#import "Private/FIRLibrary.h"
2222
#import "Private/FIRLogger.h"
2323

2424
NS_ASSUME_NONNULL_BEGIN
@@ -41,13 +41,13 @@ @implementation FIRComponentContainer
4141

4242
#pragma mark - Public Registration
4343

44-
+ (void)registerAsComponentRegistrant:(Class)klass {
44+
+ (void)registerAsComponentRegistrant:(id<FIRLibrary>)klass {
4545
static dispatch_once_t onceToken;
4646
dispatch_once(&onceToken, ^{
4747
gFIRComponentRegistrants = [[NSMutableSet<Class> alloc] init];
4848
});
4949

50-
[self registerAsComponentRegistrant:klass inSet:gFIRComponentRegistrants];
50+
[self registerAsComponentRegistrant:(Class)klass inSet:gFIRComponentRegistrants];
5151
}
5252

5353
+ (void)registerAsComponentRegistrant:(Class)klass inSet:(NSMutableSet<Class> *)allRegistrants {
@@ -59,7 +59,7 @@ + (void)registerAsComponentRegistrant:(Class)klass inSet:(NSMutableSet<Class> *)
5959
}
6060

6161
// Ensure the class given conforms to the proper protocol.
62-
if (![klass conformsToProtocol:@protocol(FIRComponentRegistrant)] ||
62+
if (![klass conformsToProtocol:@protocol(FIRLibrary)] ||
6363
![klass respondsToSelector:@selector(componentsToRegister)]) {
6464
[NSException raise:NSInvalidArgumentException
6565
format:
@@ -91,7 +91,7 @@ - (instancetype)initWithApp:(FIRApp *)app registrants:(NSMutableSet<Class> *)all
9191

9292
- (void)populateComponentsFromRegisteredClasses:(NSSet<Class> *)classes forApp:(FIRApp *)app {
9393
// Loop through the verified component registrants and populate the components array.
94-
for (Class<FIRComponentRegistrant> klass in classes) {
94+
for (Class<FIRLibrary> klass in classes) {
9595
// Loop through all the components being registered and store them as appropriate.
9696
// Classes which do not provide functionality should use a dummy FIRComponentRegistrant
9797
// protocol.

Firebase/Core/FIROptions.m

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -113,30 +113,23 @@ + (void)initialize {
113113
NSRange major = NSMakeRange(0, 1);
114114
NSRange minor = NSMakeRange(1, 2);
115115
NSRange patch = NSMakeRange(3, 2);
116-
[FIRApp registerLibrary:@"fire-ios"
117-
withVersion:[NSString
118-
stringWithFormat:@"%@.%d.%d",
119-
[kFIRLibraryVersionID substringWithRange:major],
120-
[[kFIRLibraryVersionID substringWithRange:minor]
121-
intValue],
122-
[[kFIRLibraryVersionID substringWithRange:patch]
123-
intValue]]
124-
withComponentRegistrant:nil
125-
withConfigurable:nil];
116+
[FIRApp
117+
registerLibrary:nil
118+
withName:@"fire-ios"
119+
withVersion:[NSString stringWithFormat:@"%@.%d.%d",
120+
[kFIRLibraryVersionID substringWithRange:major],
121+
[[kFIRLibraryVersionID substringWithRange:minor]
122+
intValue],
123+
[[kFIRLibraryVersionID substringWithRange:patch]
124+
intValue]]];
126125
NSDictionary<NSString *, id> *info = [[NSBundle mainBundle] infoDictionary];
127126
NSString *xcodeVersion = info[@"DTXcodeBuild"];
128127
NSString *sdkVersion = info[@"DTSDKBuild"];
129128
if (xcodeVersion) {
130-
[FIRApp registerLibrary:@"xcode"
131-
withVersion:xcodeVersion
132-
withComponentRegistrant:nil
133-
withConfigurable:nil];
129+
[FIRApp registerLibrary:nil withName:@"xcode" withVersion:xcodeVersion];
134130
}
135131
if (sdkVersion) {
136-
[FIRApp registerLibrary:@"apple-sdk"
137-
withVersion:sdkVersion
138-
withComponentRegistrant:nil
139-
withConfigurable:nil];
132+
[FIRApp registerLibrary:nil withName:@"apple-sdk" withVersion:sdkVersion];
140133
}
141134
}
142135

0 commit comments

Comments
 (0)