OXP run-time standards checks

Only active in the debug build, level controlled by enforce-oxp-standards
variable (0..3 = off, warn, enforce, quit)

Initial checks that OXPs have manifest.plist and legacy script.plist
not being used.
master
cim 2014-09-07 15:14:05 +01:00
parent 2983a9ea5b
commit f02b75b3ae
7 changed files with 215 additions and 9 deletions

View File

@ -0,0 +1,11 @@
{
title = "Oolite Debug OXP";
identifier = "org.oolite.oolite.debug";
version = "1.81";
required_oolite_version = "1.81";
license = "GPL 2+ / CC-BY-NC-SA 3.0 - see LICENSE.TXT for details";
author = "Giles Williams, Jens Ayton and contributors";
information_url = "http://www.oolite.org/";
}

View File

@ -6,6 +6,7 @@ installers/autopackage/default.x86_64.apspec
src/Cocoa/Info-Oolite.plist
src/Cocoa/oolite-version.xcconfig
Resources/InfoPlist.strings (twice. note: UTF-16)
DebugOXP/Debug.oxp/manifest.plist
- Major versions:
Doc/OoliteReadMe.doc

View File

@ -154,6 +154,7 @@ oolite_C_FILES = \
OOLITE_DEBUG_FILES = \
OODebugMonitor.m \
OODebugStandards.m \
OODebugSupport.m \
OODebugTCPConsoleClient.m \
OOJSConsole.m \

View File

@ -0,0 +1,51 @@
/*
OODebugStandards.h
OXP strictness warnings for errors and deprecated content
Copyright (C) 2014
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#ifdef NDEBUG
// in release mode, stubs
#define OOStandardsDeprecated() do {} while (0)
#define OOStandardsError() do {} while (0)
#define OOEnforceStandards() 0
#else
#import "OOCocoa.h"
// Warn/exit if deprecated functionality used
void OOStandardsDeprecated(NSString *message);
// Warn/exit if an OXP error is detected
void OOStandardsError(NSString *message);
// Return true if in standard enforcing mode
// Always false in release builds
// This will *not* exit in "exit on error" mode
BOOL OOEnforceStandards();
#endif

View File

@ -0,0 +1,118 @@
/*
OODebugStandards.m
OXP strictness warnings for errors and deprecated content
Copyright (C) 2014
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#include "OODebugStandards.h"
#include "OOLogging.h"
#include "OOCollectionExtractors.h"
#include "GameController.h"
#ifndef NDEBUG
void OOStandardsSetup();
void OOStandardsInternal(NSString *type, NSString *message);
static BOOL sSetup = NO;
typedef enum {
// do nothing (equivalent to release build)
STANDARDS_ENFORCEMENT_OFF = 0,
// warn in log but otherwise do nothing
STANDARDS_ENFORCEMENT_WARN,
// warn in log, block use of deprecated or error items
STANDARDS_ENFORCEMENT_ENFORCE,
// note in log, then exit if deprecated or error condition occurs
STANDARDS_ENFORCEMENT_QUIT
} OOStandardsEnforcement;
static OOStandardsEnforcement sEnforcement = STANDARDS_ENFORCEMENT_OFF;
void OOStandardsSetup()
{
if (sSetup)
{
return;
}
NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
int s = [prefs oo_intForKey:@"enforce-oxp-standards"
defaultValue:STANDARDS_ENFORCEMENT_WARN];
if (s < STANDARDS_ENFORCEMENT_OFF)
{
s = STANDARDS_ENFORCEMENT_OFF;
}
else if (s > STANDARDS_ENFORCEMENT_QUIT)
{
s = STANDARDS_ENFORCEMENT_QUIT;
}
sEnforcement = s;
}
void OOStandardsInternal(NSString *type, NSString *message)
{
OOStandardsSetup();
if (sEnforcement == STANDARDS_ENFORCEMENT_OFF)
{
return;
}
OOLog(type,message);
if (sEnforcement == STANDARDS_ENFORCEMENT_QUIT)
{
[[GameController sharedController] exitAppWithContext:type];
// exit
}
}
void OOStandardsDeprecated(NSString *message)
{
OOStandardsInternal(@"oxp-standards.deprecated",message);
}
void OOStandardsError(NSString *message)
{
OOStandardsInternal(@"oxp-standards.error",message);
}
BOOL OOEnforceStandards()
{
OOStandardsSetup();
return sEnforcement >= STANDARDS_ENFORCEMENT_ENFORCE;
}
#endif

View File

@ -39,6 +39,7 @@ MA 02110-1301, USA.
#import "OOOXZManager.h"
#import "unzip.h"
#import "HeadUpDisplay.h"
#import "OODebugStandards.h"
#import "OOJSScript.h"
#import "OOPListScript.h"
@ -601,7 +602,16 @@ static NSMutableDictionary *sStringCache;
}
else
{
// make up a basic manifest
if ([[[path pathExtension] lowercaseString] isEqualToString:@"oxp"])
{
OOStandardsError([NSString stringWithFormat:@"OXP %@ has no manifest.plist", path]);
if (OOEnforceStandards())
{
[self addErrorWithKey:@"oxp-lacks-manifest" param1:[path lastPathComponent] param2:nil];
return;
}
}
// make up a basic manifest in relaxed mode
manifest = [NSDictionary dictionaryWithObjectsAndKeys:[NSString stringWithFormat:@"__oolite.tmp.%@",path],kOOManifestIdentifier,@"1",kOOManifestVersion,@"OXP without manifest",kOOManifestTitle,@"1",kOOManifestRequiredOoliteVersion,nil];
}
}
@ -1524,6 +1534,10 @@ static NSString *LogClassKeyRoot(NSString *key)
/* If the old pirate-victim-roles files exist, merge them in */
NSArray *pirateVictims = [ResourceManager arrayFromFilesNamed:@"pirate-victim-roles.plist" inFolder:@"Config" andMerge:YES];
if (OOEnforceStandards() && [pirateVictims count] > 0)
{
OOStandardsDeprecated(@"pirate-victim-roles.plist is still being used.");
}
[ResourceManager mergeRoleCategories:[NSDictionary dictionaryWithObject:pirateVictims forKey:@"oolite-pirate-victim"] intoDictionary:roleCategories];
return [[roleCategories copy] autorelease];

View File

@ -30,6 +30,7 @@ MA 02110-1301, USA.
#import "OOJavaScriptEngine.h"
#import "OOPListParsing.h"
#import "ResourceManager.h"
#import "OODebugStandards.h"
static NSString * const kOOLogLoadScriptJavaScript = @"script.load.javaScript";
@ -97,15 +98,19 @@ static NSString * const kOOLogLoadScriptNone = @"script.load.none";
filePath = [path stringByAppendingPathComponent:@"script.plist"];
if ([fmgr oo_oxzFileExistsAtPath:filePath])
{
foundScript = YES;
OOLog(kOOLogLoadScriptPList, @"Trying to load property list script %@", filePath);
OOLogIndentIf(kOOLogLoadScriptPList);
OOStandardsDeprecated([NSString stringWithFormat:@"Legacy script %@ is deprecated",filePath]);
if (!OOEnforceStandards())
{
foundScript = YES;
OOLog(kOOLogLoadScriptPList, @"Trying to load property list script %@", filePath);
OOLogIndentIf(kOOLogLoadScriptPList);
result = [OOPListScript scriptsInPListFile:filePath];
if (result != nil) OOLog(kOOLogLoadScriptOK, @"Successfully loaded property list script %@", filePath);
else OOLogERR(kOOLogLoadScriptParseError, @"Failed to load property list script %@", filePath);
result = [OOPListScript scriptsInPListFile:filePath];
if (result != nil) OOLog(kOOLogLoadScriptOK, @"Successfully loaded property list script %@", filePath);
else OOLogERR(kOOLogLoadScriptParseError, @"Failed to load property list script %@", filePath);
OOLogOutdentIf(kOOLogLoadScriptPList);
OOLogOutdentIf(kOOLogLoadScriptPList);
}
}
}
@ -171,6 +176,11 @@ static NSString * const kOOLogLoadScriptNone = @"script.load.none";
}
else if ([extension isEqualToString:@"plist"])
{
OOStandardsDeprecated([NSString stringWithFormat:@"Legacy script %@ is deprecated",filePath]);
if (OOEnforceStandards())
{
return nil;
}
return [OOPListScript scriptsInPListFile:filePath];
}