Oolite
Loading...
Searching...
No Matches
OOCheckRequiresPListVerifierStage.m
Go to the documentation of this file.
1/*
2
3OOCheckRequiresPListVerifierStage.m
4
5
6Oolite
7Copyright (C) 2004-2013 Giles C Williams and contributors
8
9This program is free software; you can redistribute it and/or
10modify it under the terms of the GNU General Public License
11as published by the Free Software Foundation; either version 2
12of the License, or (at your option) any later version.
13
14This program is distributed in the hope that it will be useful,
15but WITHOUT ANY WARRANTY; without even the implied warranty of
16MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17GNU General Public License for more details.
18
19You should have received a copy of the GNU General Public License
20along with this program; if not, write to the Free Software
21Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
22MA 02110-1301, USA.
23
24*/
25
27
28#if OO_OXP_VERIFIER_ENABLED
29
31#import "OOStringParsing.h"
32
33static NSString* const kStageName = @"Checking requires.plist";
34
36
37- (NSString*)name
38{
39 return kStageName;
40}
41
42- (BOOL)shouldRun
43{
44 OOFileScannerVerifierStage* fileScanner = nil;
45
46 fileScanner = [[self verifier] fileScannerStage];
47 return [fileScanner fileExists:@"requires.plist"
48 inFolder:@"Config"
50 checkBuiltIn:NO];
51}
52
53- (void)run
54{
55 OOFileScannerVerifierStage* fileScanner = nil;
56 NSDictionary* requiresPList = nil;
57 NSSet* knownKeys = nil;
58 NSMutableSet* actualKeys = nil;
59 NSString *version = nil,
60 *maxVersion = nil;
61 NSArray *ooVersionComponents = nil,
62 *versionComponents = nil,
63 *maxVersionComponents = nil;
64
65 fileScanner = [[self verifier] fileScannerStage];
66 requiresPList = [fileScanner plistNamed:@"requires.plist"
67 inFolder:@"Config"
69 checkBuiltIn:NO];
70
71 if (requiresPList == nil)
72 return;
73
74 // Check that it's a dictionary
75 if (![requiresPList isKindOfClass:[NSDictionary class]]) {
76 OOLog(@"verifyOXP.requiresPList.notDict", @"%@", @"***** ERROR: requires.plist is not a dictionary.");
77 return;
78 }
79
80 // Check that all the keys are known.
81 knownKeys = [[self verifier] configurationSetForKey:@"requiresPListSupportedKeys"];
82 actualKeys = [NSMutableSet setWithArray:[requiresPList allKeys]];
83 [actualKeys minusSet:knownKeys];
84
85 if ([actualKeys count] != 0) {
86
87 OOLog(@"verifyOXP.requiresPList.unknownKeys", @"----- WARNING: requires.plist contains unknown keys. This OXP will not be loaded by this version of Oolite. Unknown keys are: %@.", [[actualKeys allObjects] componentsJoinedByString:@", "]);
88 }
89
90 // Sanity check the known keys.
91 version = [requiresPList objectForKey:@"version"];
92 if (version != nil) {
93 if (![version isKindOfClass:[NSString class]]) {
94 OOLog(@"verifyOXP.requiresPList.badValue", @"%@", @"***** ERROR: Value for 'version' is not a string.");
95 version = nil;
96 }
97 }
98
99 maxVersion = [requiresPList objectForKey:@"max_version"];
100 if (maxVersion != nil) {
101 if (![maxVersion isKindOfClass:[NSString class]]) {
102 OOLog(@"verifyOXP.requiresPList.badValue", @"%@", @"***** ERROR: Value for 'max_version' is not a string.");
103 maxVersion = nil;
104 }
105 }
106
107 if (version != nil || maxVersion != nil) {
108 ooVersionComponents = ComponentsFromVersionString([[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"]);
109 if (ooVersionComponents == nil) {
110 OOLog(@"verifyOXP.requiresPList.cantFindOoliteVersion", @"%@", @"----- WARNING: could not find Oolite's version for requires.plist sanity check.");
111 }
112 if (version != nil) {
113 versionComponents = ComponentsFromVersionString(version);
114 if (versionComponents == nil) {
115 OOLog(@"verifyOXP.requiresPList.badValue", @"***** ERROR: could not interpret version string \"%@\" as version number.", version);
116 } else if (ooVersionComponents != nil) {
117 if (CompareVersions(ooVersionComponents, versionComponents) == NSOrderedAscending) {
118 OOLog(@"verifyOXP.requiresPList.oxpRequiresNewerOolite", @"----- WARNING: this OXP requires a newer version of Oolite (%@) to work.", version);
119 }
120 }
121 }
122 if (maxVersion != nil) {
123 maxVersionComponents = ComponentsFromVersionString(maxVersion);
124 if (maxVersionComponents == nil) {
125 OOLog(@"verifyOXP.requiresPList.badValue", @"***** ERROR: could not interpret max_version string \"%@\" as version number.", maxVersion);
126 } else if (ooVersionComponents != nil) {
127 if (CompareVersions(ooVersionComponents, maxVersionComponents) == NSOrderedDescending) {
128 OOLog(@"verifyOXP.requiresPList.oxpRequiresOlderOolite", @"----- WARNING: this OXP requires an older version of Oolite (%@) to work.", maxVersion);
129 }
130 }
131 }
132
133 if (versionComponents != nil && maxVersionComponents != nil) {
134 if (CompareVersions(versionComponents, maxVersionComponents) == NSOrderedDescending) {
135 OOLog(@"verifyOXP.requiresPList.noVersionsInRange", @"***** ERROR: this OXP's maximum version (%@) is less than its minimum version (%@).", maxVersion, version);
136 }
137 }
138 }
139}
140
141@end
142
143#endif
static NSString *const kStageName
#define OOLog(class, format,...)
Definition OOLogging.h:84
unsigned count
return nil
NSArray * ComponentsFromVersionString(NSString *string)
NSComparisonResult CompareVersions(NSArray *version1, NSArray *version2)
id plistNamed:inFolder:referencedFrom:checkBuiltIn:(NSString *file,[inFolder] NSString *folder,[referencedFrom] NSString *context,[checkBuiltIn] BOOL checkBuiltIn)
BOOL fileExists:inFolder:referencedFrom:checkBuiltIn:(NSString *file,[inFolder] NSString *folder,[referencedFrom] NSString *context,[checkBuiltIn] BOOL checkBuiltIn)
OOOXPVerifier * verifier()
OOFileScannerVerifierStage * fileScannerStage()
NSSet * configurationSetForKey:(NSString *key)