From fb18c1e542c034e01b8c45a3977ca7e1ace6cfa7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabian=20J=C3=A4ger?= Date: Tue, 2 Apr 2019 16:26:35 +0200 Subject: [PATCH] Phased rollout interval is an appcast item attribute and not its own element (#1385) * phased rollout interval is an appcast item attribute and not its own element * add basic test for getting phased rollout interval from appcast item --- Sparkle/SUAppcastItem.m | 5 ++++- Sparkle/SUBasicUpdateDriver.m | 15 +++++++++++---- Sparkle/SUConstants.h | 2 +- Sparkle/SUConstants.m | 2 +- Tests/Resources/testappcast.xml | 2 +- Tests/SUAppcastTest.swift | 1 + Tests/Sparkle Unit Tests-Bridging-Header.h | 2 +- 7 files changed, 20 insertions(+), 9 deletions(-) diff --git a/Sparkle/SUAppcastItem.m b/Sparkle/SUAppcastItem.m index 20fc1a1a..11b1043e 100644 --- a/Sparkle/SUAppcastItem.m +++ b/Sparkle/SUAppcastItem.m @@ -189,7 +189,10 @@ self.displayVersionString = self.versionString; } - self.phasedRolloutInterval = [enclosure objectForKey:SUAppcastElementPhasedRolloutInterval]; + NSString* enclosureRolloutIntervalString = [enclosure objectForKey:SUAppcastAttributePhasedRolloutInterval]; + if(enclosureRolloutIntervalString) { + self.phasedRolloutInterval = @(enclosureRolloutIntervalString.integerValue); + } // Find the appropriate release notes URL. NSString *releaseNotesString = [dict objectForKey:SUAppcastElementReleaseNotesLink]; diff --git a/Sparkle/SUBasicUpdateDriver.m b/Sparkle/SUBasicUpdateDriver.m index aa303365..89dc2a68 100644 --- a/Sparkle/SUBasicUpdateDriver.m +++ b/Sparkle/SUBasicUpdateDriver.m @@ -22,6 +22,7 @@ #import "SUUpdateValidator.h" #import "SULocalizations.h" #import "SUErrors.h" +#import "SUUpdater.h" #import "SUAppcast.h" #import "SUAppcastItem.h" @@ -96,19 +97,25 @@ return comparator; } -- (SUAppcastItem *)bestItemFromAppcastItems:(NSArray *)appcastItems getDeltaItem:(SUAppcastItem * __autoreleasing *)deltaItem +// This method is only used for testing ++ (SUAppcastItem *)bestItemFromAppcastItems:(NSArray *)appcastItems getDeltaItem:(SUAppcastItem *_Nullable __autoreleasing *_Nullable)deltaItem withHostVersion:(NSString *)hostVersion comparator:(id)comparator { + SUBasicUpdateDriver* basicUpdateDriver = [[SUBasicUpdateDriver alloc] initWithUpdater:(id)[SUUpdater sharedUpdater]]; + return [basicUpdateDriver bestItemFromAppcastItems:appcastItems getDeltaItem:deltaItem withHostVersion:hostVersion comparator:comparator]; +} + +- (SUAppcastItem *)bestItemFromAppcastItems:(NSArray *)appcastItems getDeltaItem:(SUAppcastItem * __autoreleasing *)deltaItem withHostVersion:(NSString *)hostVersion comparator:(id)comparator { SUAppcastItem *item = nil; for(SUAppcastItem *candidate in appcastItems) { if ([self hostSupportsItem:candidate]) { - if (!item || [[self versionComparator] compareVersion:item.versionString toVersion:candidate.versionString] == NSOrderedAscending) { + if (!item || [comparator compareVersion:item.versionString toVersion:candidate.versionString] == NSOrderedAscending) { item = candidate; } } } if (item && deltaItem) { - SUAppcastItem *deltaUpdateItem = [[item deltaUpdates] objectForKey:self.host.version]; + SUAppcastItem *deltaUpdateItem = [[item deltaUpdates] objectForKey:hostVersion]; if (deltaUpdateItem && [self hostSupportsItem:deltaUpdateItem]) { *deltaItem = deltaUpdateItem; } @@ -186,7 +193,7 @@ { // Find the best supported update SUAppcastItem *deltaUpdateItem = nil; - item = [self bestItemFromAppcastItems:ac.items getDeltaItem:&deltaUpdateItem]; + item = [self bestItemFromAppcastItems:ac.items getDeltaItem:&deltaUpdateItem withHostVersion:self.host.version comparator:[self versionComparator]]; if (item && deltaUpdateItem) { self.nonDeltaUpdateItem = item; diff --git a/Sparkle/SUConstants.h b/Sparkle/SUConstants.h index 2c48e949..86e0b97f 100644 --- a/Sparkle/SUConstants.h +++ b/Sparkle/SUConstants.h @@ -71,6 +71,7 @@ extern NSString *const SUAppcastAttributeEDSignature; extern NSString *const SUAppcastAttributeShortVersionString; extern NSString *const SUAppcastAttributeVersion; extern NSString *const SUAppcastAttributeOsType; +extern NSString *const SUAppcastAttributePhasedRolloutInterval; extern NSString *const SUAppcastElementCriticalUpdate; extern NSString *const SUAppcastElementDeltas; @@ -78,7 +79,6 @@ extern NSString *const SUAppcastElementMinimumSystemVersion; extern NSString *const SUAppcastElementMaximumSystemVersion; extern NSString *const SUAppcastElementReleaseNotesLink; extern NSString *const SUAppcastElementTags; -extern NSString *const SUAppcastElementPhasedRolloutInterval; extern NSString *const SURSSAttributeURL; extern NSString *const SURSSAttributeLength; diff --git a/Sparkle/SUConstants.m b/Sparkle/SUConstants.m index f50483c1..2e5d9317 100644 --- a/Sparkle/SUConstants.m +++ b/Sparkle/SUConstants.m @@ -61,6 +61,7 @@ NSString *const SUAppcastAttributeEDSignature = @"sparkle:edSignature"; NSString *const SUAppcastAttributeShortVersionString = @"sparkle:shortVersionString"; NSString *const SUAppcastAttributeVersion = @"sparkle:version"; NSString *const SUAppcastAttributeOsType = @"sparkle:os"; +NSString *const SUAppcastAttributePhasedRolloutInterval = @"sparkle:phasedRolloutInterval"; NSString *const SUAppcastElementCriticalUpdate = @"sparkle:criticalUpdate"; NSString *const SUAppcastElementDeltas = @"sparkle:deltas"; @@ -68,7 +69,6 @@ NSString *const SUAppcastElementMinimumSystemVersion = @"sparkle:minimumSystemVe NSString *const SUAppcastElementMaximumSystemVersion = @"sparkle:maximumSystemVersion"; NSString *const SUAppcastElementReleaseNotesLink = @"sparkle:releaseNotesLink"; NSString *const SUAppcastElementTags = @"sparkle:tags"; -NSString *const SUAppcastElementPhasedRolloutInterval = @"sparkle:phasedRolloutInterval"; NSString *const SURSSAttributeURL = @"url"; NSString *const SURSSAttributeLength = @"length"; diff --git a/Tests/Resources/testappcast.xml b/Tests/Resources/testappcast.xml index a47acd3f..d5794351 100644 --- a/Tests/Resources/testappcast.xml +++ b/Tests/Resources/testappcast.xml @@ -12,7 +12,7 @@ Version 3.0 - + )comparator; @end