Line data Source code
1 0 : /* 2 : 3 : OOCheckJSSyntaxVerifierStage.m 4 : 5 : 6 : Oolite 7 : Copyright (C) 2004-2013 Giles C Williams and contributors 8 : 9 : This program is free software; you can redistribute it and/or 10 : modify it under the terms of the GNU General Public License 11 : as published by the Free Software Foundation; either version 2 12 : of the License, or (at your option) any later version. 13 : 14 : This program is distributed in the hope that it will be useful, 15 : but WITHOUT ANY WARRANTY; without even the implied warranty of 16 : MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 : GNU General Public License for more details. 18 : 19 : You should have received a copy of the GNU General Public License 20 : along with this program; if not, write to the Free Software 21 : Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 22 : MA 02110-1301, USA. 23 : 24 : */ 25 : 26 : #import "OOCheckJSSyntaxVerifierStage.h" 27 : 28 : #if OO_OXP_VERIFIER_ENABLED 29 : 30 : #import "OOFileScannerVerifierStage.h" 31 : #import "OOStringParsing.h" 32 : #import "OOScript.h" 33 : #import "OOJSScript.h" 34 : #import "OOJavaScriptEngine.h" 35 : 36 0 : static NSString * const kStageName = @"Checking JS Script file syntax"; 37 : 38 : 39 : @implementation OOCheckJSSyntaxVerifierStage 40 : 41 0 : - (NSString *)name 42 : { 43 : return kStageName; 44 : } 45 : 46 : 47 0 : - (BOOL)shouldRun 48 : { 49 : OOFileScannerVerifierStage *fileScanner = nil; 50 : 51 : fileScanner = [[self verifier] fileScannerStage]; 52 : return ([[fileScanner filesInFolder:@"Scripts"] count] > 0); 53 : } 54 : 55 : 56 0 : - (void)run 57 : { 58 : OOFileScannerVerifierStage *fileScanner = nil; 59 : NSArray *scriptFiles = nil; 60 : NSString *scriptFile = nil; 61 : NSString *fileExt = nil; 62 : NSString *filePath = nil; 63 : 64 : fileScanner = [[self verifier] fileScannerStage]; 65 : scriptFiles = [fileScanner filesInFolder:@"Scripts"]; 66 : 67 : if (scriptFiles == nil) return; 68 : 69 : [[OOJavaScriptEngine sharedEngine] setShowErrorLocations:YES]; 70 : 71 : foreach (scriptFile, scriptFiles) 72 : { 73 : fileExt = [[scriptFile pathExtension] lowercaseString]; 74 : if ([fileExt isEqualToString:@"js"] || [fileExt isEqualToString:@"es"]) 75 : { 76 : filePath = [fileScanner pathForFile:scriptFile inFolder:@"Scripts" referencedFrom:nil checkBuiltIn:NO]; 77 : 78 : OOScript *script = [OOJSScript scriptWithPath:filePath properties:nil]; 79 : (void)script; 80 : } 81 : } 82 : 83 : 84 : } 85 : 86 : @end 87 : 88 : #endif