From 5bd07716eba18f5d9cb397c099dbd64a35bbd8d2 Mon Sep 17 00:00:00 2001 From: Alexandre Wilhelm Date: Mon, 3 Nov 2014 14:49:25 -0800 Subject: [PATCH 01/11] New: new options for the command objj This pull requests adds the following feature for the command objj: - Option -h or --help to get the help of the command - Option -I or --objj-include-paths to specify the frameworks to be used - Possibility to pass several files to the command, for example objj AppController.j Test.j --- Objective-J/CommonJS/lib/objective-j.js | 38 +++++++++++++++++++------ 1 file changed, 29 insertions(+), 9 deletions(-) diff --git a/Objective-J/CommonJS/lib/objective-j.js b/Objective-J/CommonJS/lib/objective-j.js index cf5504a3f..ff89d8766 100644 --- a/Objective-J/CommonJS/lib/objective-j.js +++ b/Objective-J/CommonJS/lib/objective-j.js @@ -79,27 +79,47 @@ exports.run = function(args) // copy the args since we're going to modify them var argv = args.slice(1); - if (argv[0] === "--version") + if (argv[0] === "--version" || argv[0] === "-v") { print(exports.fullVersionString()); return; } - while (argv.length && argv[0].indexOf('-I') === 0) - OBJJ_INCLUDE_PATHS.unshift.apply(OBJJ_INCLUDE_PATHS, argv.shift().substr(2).split(':')); + if (argv[0] === "--help" || argv[0] === "-h") + { + print("Usage (objj): " + args[0] + " [options] [--] files..."); + print(" -v, --version print the current version of objj"); + print(" -I, --objj-include-paths specify the framework to be used") + print(" -h, --help print this help"); + return; + } + + while (argv.length && argv[0] == "-I" || argv[0] == "--objj-include-paths") + { + argv.shift(); + OBJJ_INCLUDE_PATHS.unshift.apply(OBJJ_INCLUDE_PATHS, argv.shift().split(":")); + } } if (argv && argv.length > 0) { - var arg0 = argv.shift(); - var mainFilePath = FILE.canonical(arg0); + while (argv.length > 0) + { + var arg0 = argv.shift(); + var mainFilePath = FILE.canonical(arg0); - exports.make_narwhal_factory(mainFilePath)(require, { }, module, system, print); + exports.make_narwhal_factory(mainFilePath)(require, { }, module, system, print); - if (typeof main === "function") - main([arg0].concat(argv)); + if (typeof main === "function") + main([arg0].concat(argv)); - require("browser/timeout").serviceTimeouts(); + require("browser/timeout").serviceTimeouts(); + + ObjectiveJ.Executable.resetCachedFileExecutableSearchers(); + ObjectiveJ.StaticResource.resetRootResources(); + ObjectiveJ.FileExecutable.resetFileExecutables(); + objj_resetRegisterClasses(); + } } else { From f21dcb8265d78683f984aa70014e1fb91a191ae7 Mon Sep 17 00:00:00 2001 From: Alexandre Wilhelm Date: Mon, 3 Nov 2014 15:25:47 -0800 Subject: [PATCH 02/11] New: Added option --parser/-p to the command objj Previously it wasn't possible to specify a custom parser for the command objj. This is needed for xCodeCapp --- Objective-J/CommonJS/lib/objective-j.js | 8 +++++++- Tools/XcodeCapp/XcodeCapp/ProcessSourceOperation.m | 1 + 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/Objective-J/CommonJS/lib/objective-j.js b/Objective-J/CommonJS/lib/objective-j.js index ff89d8766..47d838406 100644 --- a/Objective-J/CommonJS/lib/objective-j.js +++ b/Objective-J/CommonJS/lib/objective-j.js @@ -90,10 +90,16 @@ exports.run = function(args) print("Usage (objj): " + args[0] + " [options] [--] files..."); print(" -v, --version print the current version of objj"); print(" -I, --objj-include-paths specify the framework to be used") - print(" -h, --help print this help"); + print(" -p, --parser specify to use a specific parser") return; } + if (argv[0] === "-p" || argv[0] === "--parser") + { + argv.shift(); + optionalParserUsed = true; + } + while (argv.length && argv[0] == "-I" || argv[0] == "--objj-include-paths") { argv.shift(); diff --git a/Tools/XcodeCapp/XcodeCapp/ProcessSourceOperation.m b/Tools/XcodeCapp/XcodeCapp/ProcessSourceOperation.m index 81e9b7cf6..0a987b2e3 100644 --- a/Tools/XcodeCapp/XcodeCapp/ProcessSourceOperation.m +++ b/Tools/XcodeCapp/XcodeCapp/ProcessSourceOperation.m @@ -71,6 +71,7 @@ { launchPath = self.xcc.executablePaths[@"objj"]; arguments = @[ + @"--parser", self.xcc.parserPath, self.projectPath, self.sourcePath From f74888419c4bb29d4acb7715e11b796df4b17500 Mon Sep 17 00:00:00 2001 From: Alexandre Wilhelm Date: Mon, 3 Nov 2014 15:33:37 -0800 Subject: [PATCH 03/11] Fixed: part of the code missing after the previous commit refs #f21dcb8265d78683f984aa70014e1fb91a191ae7 --- Objective-J/CommonJS/lib/objective-j.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Objective-J/CommonJS/lib/objective-j.js b/Objective-J/CommonJS/lib/objective-j.js index 47d838406..c123e81c0 100644 --- a/Objective-J/CommonJS/lib/objective-j.js +++ b/Objective-J/CommonJS/lib/objective-j.js @@ -121,6 +121,12 @@ exports.run = function(args) require("browser/timeout").serviceTimeouts(); + if (optionalParserUsed) + { + // Here we have no idea what the parser does...this is used for xCodeCapp + break; + } + ObjectiveJ.Executable.resetCachedFileExecutableSearchers(); ObjectiveJ.StaticResource.resetRootResources(); ObjectiveJ.FileExecutable.resetFileExecutables(); From 5678fe3b83fbb4e27f231b14ca59584b22127127 Mon Sep 17 00:00:00 2001 From: Alexandre Wilhelm Date: Mon, 3 Nov 2014 18:12:47 -0800 Subject: [PATCH 04/11] Fixed: change option -p in objj by bash concept -- --- Objective-J/CommonJS/lib/objective-j.js | 23 +++++++++---------- .../XcodeCapp/ProcessSourceOperation.m | 2 +- 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/Objective-J/CommonJS/lib/objective-j.js b/Objective-J/CommonJS/lib/objective-j.js index c123e81c0..4b74070c2 100644 --- a/Objective-J/CommonJS/lib/objective-j.js +++ b/Objective-J/CommonJS/lib/objective-j.js @@ -89,17 +89,11 @@ exports.run = function(args) { print("Usage (objj): " + args[0] + " [options] [--] files..."); print(" -v, --version print the current version of objj"); - print(" -I, --objj-include-paths specify the framework to be used") - print(" -p, --parser specify to use a specific parser") + print(" -I, --objj-include-paths include a specific framework paths") + print(" -h, --help print this help"); return; } - if (argv[0] === "-p" || argv[0] === "--parser") - { - argv.shift(); - optionalParserUsed = true; - } - while (argv.length && argv[0] == "-I" || argv[0] == "--objj-include-paths") { argv.shift(); @@ -109,6 +103,8 @@ exports.run = function(args) if (argv && argv.length > 0) { + var endCommand = false; + while (argv.length > 0) { var arg0 = argv.shift(); @@ -116,16 +112,19 @@ exports.run = function(args) exports.make_narwhal_factory(mainFilePath)(require, { }, module, system, print); + if (argv[0] == "--") + { + endCommand = true; + argv.shift(); + } + if (typeof main === "function") main([arg0].concat(argv)); require("browser/timeout").serviceTimeouts(); - if (optionalParserUsed) - { - // Here we have no idea what the parser does...this is used for xCodeCapp + if (endCommand) break; - } ObjectiveJ.Executable.resetCachedFileExecutableSearchers(); ObjectiveJ.StaticResource.resetRootResources(); diff --git a/Tools/XcodeCapp/XcodeCapp/ProcessSourceOperation.m b/Tools/XcodeCapp/XcodeCapp/ProcessSourceOperation.m index 0a987b2e3..8d95e03a8 100644 --- a/Tools/XcodeCapp/XcodeCapp/ProcessSourceOperation.m +++ b/Tools/XcodeCapp/XcodeCapp/ProcessSourceOperation.m @@ -71,8 +71,8 @@ { launchPath = self.xcc.executablePaths[@"objj"]; arguments = @[ - @"--parser", self.xcc.parserPath, + @"--", self.projectPath, self.sourcePath ]; From 4d77e7dd6b74f010b650db3c7db74dc7a7c88f91 Mon Sep 17 00:00:00 2001 From: Alexandre Wilhelm Date: Mon, 3 Nov 2014 19:54:35 -0800 Subject: [PATCH 05/11] Fixed: fixed issue with press, capp and nib2cib with the new command objj --- Objective-J/CommonJS/lib/objective-j.js | 3 +++ Objective-J/CommonJS/objj-executable | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/Objective-J/CommonJS/lib/objective-j.js b/Objective-J/CommonJS/lib/objective-j.js index 4b74070c2..883e34e7f 100644 --- a/Objective-J/CommonJS/lib/objective-j.js +++ b/Objective-J/CommonJS/lib/objective-j.js @@ -119,7 +119,10 @@ exports.run = function(args) } if (typeof main === "function") + { main([arg0].concat(argv)); + endCommand = true; + } require("browser/timeout").serviceTimeouts(); diff --git a/Objective-J/CommonJS/objj-executable b/Objective-J/CommonJS/objj-executable index 919302c11..9f2f05a02 100755 --- a/Objective-J/CommonJS/objj-executable +++ b/Objective-J/CommonJS/objj-executable @@ -3,5 +3,5 @@ var execPath = require("file").path(module.path); var mainPath = execPath.dirname().dirname().join("lib", execPath.basename(), "main.j"); -var args = ["objj", String(mainPath)].concat(system.args.slice(1)); +var args = ["objj", String(mainPath), "--"].concat(system.args.slice(1)); require("objective-j").run(args); From 7abcc42a42962b6bfbcb75be4372709ad133fc7e Mon Sep 17 00:00:00 2001 From: Alexandre Wilhelm Date: Mon, 3 Nov 2014 19:55:02 -0800 Subject: [PATCH 06/11] Test: updated test ToolTest.j. Added tests for capp_lint and objj --- Tests/Tools/ToolsTest.j | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/Tests/Tools/ToolsTest.j b/Tests/Tools/ToolsTest.j index b3e16e59e..0b4605664 100644 --- a/Tests/Tools/ToolsTest.j +++ b/Tests/Tools/ToolsTest.j @@ -29,6 +29,18 @@ function cleanup() { status = OS.system(["flatten", "-f", "ToolsTestApp", "FlattenTestApp"].map(OS.enquote).join(" ") + " > /dev/null"); [self assert:0 equals:status message:"flatten failed"]; + + status = OS.system(["objj", "ToolsTestApp/AppController.j"]); + [self assert:0 equals:status message:"objj failed"]; + + status = OS.system(["objj", "ToolsTestApp/AppController.j", "ToolsTestApp/AppController.j"]); + [self assert:0 equals:status message:"objj failed with several files"]; + + status = OS.system(["objj", "-I", "ToolsTestApp/Frameworks", "ToolsTestApp/AppController.j"]); + [self assert:0 equals:status message:"objj failed with options -I"]; + + status = OS.system(["capp_lint", "ToolsTestApp/AppController.j"]); + [self assert:0 equals:status message:"capp lint failed"]; } - (void)tearDown From 2bf012100a04eb67714486a1dcffd67d1c51f519 Mon Sep 17 00:00:00 2001 From: Alexandre Wilhelm Date: Mon, 3 Nov 2014 21:02:15 -0800 Subject: [PATCH 07/11] Test: removed test for capp_lint --- Tests/Manual/MultipleValueBindings/AppController.j | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/Tests/Manual/MultipleValueBindings/AppController.j b/Tests/Manual/MultipleValueBindings/AppController.j index bbc814a2f..a39a346b4 100644 --- a/Tests/Manual/MultipleValueBindings/AppController.j +++ b/Tests/Manual/MultipleValueBindings/AppController.j @@ -6,8 +6,8 @@ * Copyright 2013, Cappuccino Foundation. All rights reserved. */ -@import -@import +@import +@import @import "Transformers.j" @@ -28,12 +28,13 @@ - (id)init { - if (self = [super init]) + if (self = super init]) { foo = nil; [self setNow]; [self setAllowColorChange:NO]; [self setCanEditPeople:YES]; + people = [ [CPDictionary dictionaryWithObjectsAndKeys:@"tom", @"firstname", @"jones", @"lastname", 27, @"age", 0, @"numberOfChildren"], [CPDictionary dictionaryWithObjectsAndKeys:@"dick", @"firstname", @"clark", @"lastname", 31, @"age", 4, @"numberOfChildren"], From 735b0f8593d5ef398bee8c664ab7778f722bad13 Mon Sep 17 00:00:00 2001 From: Alexandre Wilhelm Date: Mon, 3 Nov 2014 21:22:01 -0800 Subject: [PATCH 08/11] Revert "Test: removed test for capp_lint" This reverts commit 2bf012100a04eb67714486a1dcffd67d1c51f519. --- Tests/Manual/MultipleValueBindings/AppController.j | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/Tests/Manual/MultipleValueBindings/AppController.j b/Tests/Manual/MultipleValueBindings/AppController.j index a39a346b4..bbc814a2f 100644 --- a/Tests/Manual/MultipleValueBindings/AppController.j +++ b/Tests/Manual/MultipleValueBindings/AppController.j @@ -6,8 +6,8 @@ * Copyright 2013, Cappuccino Foundation. All rights reserved. */ -@import -@import +@import +@import @import "Transformers.j" @@ -28,13 +28,12 @@ - (id)init { - if (self = super init]) + if (self = [super init]) { foo = nil; [self setNow]; [self setAllowColorChange:NO]; [self setCanEditPeople:YES]; - people = [ [CPDictionary dictionaryWithObjectsAndKeys:@"tom", @"firstname", @"jones", @"lastname", 27, @"age", 0, @"numberOfChildren"], [CPDictionary dictionaryWithObjectsAndKeys:@"dick", @"firstname", @"clark", @"lastname", 31, @"age", 4, @"numberOfChildren"], From 58f2d7117a825e2e56c6b3393ea1a9d2a41a56d9 Mon Sep 17 00:00:00 2001 From: Alexandre Wilhelm Date: Mon, 3 Nov 2014 21:22:31 -0800 Subject: [PATCH 09/11] Test: removed test for capp_lint --- Tests/Tools/ToolsTest.j | 3 --- 1 file changed, 3 deletions(-) diff --git a/Tests/Tools/ToolsTest.j b/Tests/Tools/ToolsTest.j index 0b4605664..b588f25c7 100644 --- a/Tests/Tools/ToolsTest.j +++ b/Tests/Tools/ToolsTest.j @@ -38,9 +38,6 @@ function cleanup() { status = OS.system(["objj", "-I", "ToolsTestApp/Frameworks", "ToolsTestApp/AppController.j"]); [self assert:0 equals:status message:"objj failed with options -I"]; - - status = OS.system(["capp_lint", "ToolsTestApp/AppController.j"]); - [self assert:0 equals:status message:"capp lint failed"]; } - (void)tearDown From ad82b0064a240232d8e9834e1703776de6edd286 Mon Sep 17 00:00:00 2001 From: Alexandre Wilhelm Date: Tue, 4 Nov 2014 13:23:54 -0800 Subject: [PATCH 10/11] Fixed: added options -m for objj. This option allows you to make objj on several files --- Objective-J/CommonJS/lib/objective-j.js | 27 ++++++++++++------- Objective-J/CommonJS/objj-executable | 2 +- Tests/Tools/ToolsTest.j | 2 +- .../XcodeCapp/ProcessSourceOperation.m | 19 +++++++------ 4 files changed, 28 insertions(+), 22 deletions(-) diff --git a/Objective-J/CommonJS/lib/objective-j.js b/Objective-J/CommonJS/lib/objective-j.js index 883e34e7f..1bce5a864 100644 --- a/Objective-J/CommonJS/lib/objective-j.js +++ b/Objective-J/CommonJS/lib/objective-j.js @@ -68,6 +68,8 @@ with (window) // runs the objj repl or file provided in args exports.run = function(args) { + var multipleFiles = false; + if (args) { // we expect args to be in the format: @@ -91,13 +93,24 @@ exports.run = function(args) print(" -v, --version print the current version of objj"); print(" -I, --objj-include-paths include a specific framework paths") print(" -h, --help print this help"); + print(" -m, --multifiles launch objj on several files") return; } - while (argv.length && argv[0] == "-I" || argv[0] == "--objj-include-paths") + while (argv.length && argv[0].indexOf('-') === 0) { - argv.shift(); - OBJJ_INCLUDE_PATHS.unshift.apply(OBJJ_INCLUDE_PATHS, argv.shift().split(":")); + switch (argv[0]) + { + case "-I": + argv.shift(); + OBJJ_INCLUDE_PATHS.unshift.apply(OBJJ_INCLUDE_PATHS, argv.shift().split(":")); + break; + + case "-m": + argv.shift(); + multipleFiles = true; + break + } } } @@ -112,12 +125,6 @@ exports.run = function(args) exports.make_narwhal_factory(mainFilePath)(require, { }, module, system, print); - if (argv[0] == "--") - { - endCommand = true; - argv.shift(); - } - if (typeof main === "function") { main([arg0].concat(argv)); @@ -126,7 +133,7 @@ exports.run = function(args) require("browser/timeout").serviceTimeouts(); - if (endCommand) + if (!multipleFiles || endCommand) break; ObjectiveJ.Executable.resetCachedFileExecutableSearchers(); diff --git a/Objective-J/CommonJS/objj-executable b/Objective-J/CommonJS/objj-executable index 9f2f05a02..919302c11 100755 --- a/Objective-J/CommonJS/objj-executable +++ b/Objective-J/CommonJS/objj-executable @@ -3,5 +3,5 @@ var execPath = require("file").path(module.path); var mainPath = execPath.dirname().dirname().join("lib", execPath.basename(), "main.j"); -var args = ["objj", String(mainPath), "--"].concat(system.args.slice(1)); +var args = ["objj", String(mainPath)].concat(system.args.slice(1)); require("objective-j").run(args); diff --git a/Tests/Tools/ToolsTest.j b/Tests/Tools/ToolsTest.j index b588f25c7..000a05aa8 100644 --- a/Tests/Tools/ToolsTest.j +++ b/Tests/Tools/ToolsTest.j @@ -33,7 +33,7 @@ function cleanup() { status = OS.system(["objj", "ToolsTestApp/AppController.j"]); [self assert:0 equals:status message:"objj failed"]; - status = OS.system(["objj", "ToolsTestApp/AppController.j", "ToolsTestApp/AppController.j"]); + status = OS.system(["objj", "-m", "ToolsTestApp/AppController.j", "ToolsTestApp/AppController.j"]); [self assert:0 equals:status message:"objj failed with several files"]; status = OS.system(["objj", "-I", "ToolsTestApp/Frameworks", "ToolsTestApp/AppController.j"]); diff --git a/Tools/XcodeCapp/XcodeCapp/ProcessSourceOperation.m b/Tools/XcodeCapp/XcodeCapp/ProcessSourceOperation.m index 8d95e03a8..7872f8887 100644 --- a/Tools/XcodeCapp/XcodeCapp/ProcessSourceOperation.m +++ b/Tools/XcodeCapp/XcodeCapp/ProcessSourceOperation.m @@ -44,7 +44,7 @@ return; NSNotificationCenter *center = [NSNotificationCenter defaultCenter]; - + NSDictionary *info = @{ @"projectId":self.projectId, @"path":self.sourcePath }; [center postNotificationName:XCCConversionDidStartNotification object:self userInfo:info]; @@ -72,7 +72,6 @@ launchPath = self.xcc.executablePaths[@"objj"]; arguments = @[ self.xcc.parserPath, - @"--", self.projectPath, self.sourcePath ]; @@ -85,21 +84,21 @@ return; [self.xcc performSelectorOnMainThread:@selector(computeIgnoredPaths) withObject:nil waitUntilDone:NO]; - + notificationTitle = @"Parsed .xcodecapp-ignore"; notificationMessage = @"Ignored paths updated"; } // Run the task and get the response if needed NSInteger status = 0; - + if (arguments) { if (self.isCancelled) return; DDLogVerbose(@"Running processing task: %@", launchPath); - + NSDictionary *taskResult = [self.xcc runTaskWithLaunchPath:launchPath arguments:arguments returnType:kTaskReturnTypeAny]; @@ -121,7 +120,7 @@ notificationTitle = @"Error converting xib"; NSString *message = [NSString stringWithFormat:@"%@\n%@", self.sourcePath.lastPathComponent, response]; - + NSDictionary *info = @{ @"projectId":self.projectId, @@ -132,7 +131,7 @@ if (self.isCancelled) return; - + [center postNotificationName:XCCConversionDidGenerateErrorNotification object:self userInfo:info]; } else @@ -153,14 +152,14 @@ [self postErrorNotificationForPath:self.sourcePath line:0 message:response status:status]; } } - + if ([self.xcc shouldShowErrorNotification]) [self notifyUserWithTitle:notificationTitle message:notificationMessage]; } else if (!self.xcc.isLoadingProject) { BOOL showFinalNotification = YES; - + if ([self.xcc shouldProcessWithCappLint]) { showFinalNotification = [self.xcc checkCappLintForPath:[NSArray arrayWithObject:self.sourcePath]]; @@ -168,7 +167,7 @@ if (!showFinalNotification) [self.xcc showCappLintErrors]; } - + if (showFinalNotification) [self notifyUserWithTitle:notificationTitle message:notificationMessage]; } From 97a65059e595b07a65819c44974690ca516e9bc6 Mon Sep 17 00:00:00 2001 From: Alexandre Wilhelm Date: Wed, 5 Nov 2014 11:12:17 -0800 Subject: [PATCH 11/11] Fixed: when using the option -m, objj doesn't process every files in a error is raised, now it does --- Objective-J/CommonJS/lib/objective-j.js | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/Objective-J/CommonJS/lib/objective-j.js b/Objective-J/CommonJS/lib/objective-j.js index 1bce5a864..9dbf5ebd9 100644 --- a/Objective-J/CommonJS/lib/objective-j.js +++ b/Objective-J/CommonJS/lib/objective-j.js @@ -123,7 +123,23 @@ exports.run = function(args) var arg0 = argv.shift(); var mainFilePath = FILE.canonical(arg0); - exports.make_narwhal_factory(mainFilePath)(require, { }, module, system, print); + if (multipleFiles) + { + // This is needed to process every files passed in args + // Otherwise it would stop when an error is raised or we would like to objj the other given files + try + { + exports.make_narwhal_factory(mainFilePath)(require, { }, module, system, print); + } + catch(e) + { + print("\n" + e); + } + } + else + { + exports.make_narwhal_factory(mainFilePath)(require, { }, module, system, print); + } if (typeof main === "function") {