From 204ed1f2579ef191793d1489bddbdc1a07c8e6ca Mon Sep 17 00:00:00 2001 From: Alexandre Wilhelm Date: Mon, 25 May 2015 11:20:55 -0700 Subject: [PATCH 1/8] New: added the option --xml-output-format for the command objj Previously, it was not possible to specify the desired output format of the command objj. Now we can have either the default format or a xml format if --xml-output-format is added. --- Objective-J/CommonJS/lib/objective-j.js | 7 +++ Objective-J/ObjJAcornCompiler.js | 58 ++++++++++++++++++++++--- 2 files changed, 59 insertions(+), 6 deletions(-) diff --git a/Objective-J/CommonJS/lib/objective-j.js b/Objective-J/CommonJS/lib/objective-j.js index 9dbf5ebd9..9ff487184 100644 --- a/Objective-J/CommonJS/lib/objective-j.js +++ b/Objective-J/CommonJS/lib/objective-j.js @@ -94,6 +94,7 @@ exports.run = function(args) print(" -I, --objj-include-paths include a specific framework paths") print(" -h, --help print this help"); print(" -m, --multifiles launch objj on several files") + print(" --xml-output-format specify the output format in xml.") return; } @@ -110,6 +111,11 @@ exports.run = function(args) argv.shift(); multipleFiles = true; break + + case "--xml-output-format": + argv.shift(); + exports.outputFormatInXML = true; + break; } } } @@ -229,6 +235,7 @@ function getPackage() { exports.version = function() { return getPackage()["version"]; } exports.revision = function() { return getPackage()["cappuccino-revision"]; } exports.timestamp = function() { return new Date(getPackage()["cappuccino-timestamp"]); } +exports.outputFormatInXML = false; exports.fullVersionString = function() { return sprintf("objective-j %s (%04d-%02d-%02d %s)", diff --git a/Objective-J/ObjJAcornCompiler.js b/Objective-J/ObjJAcornCompiler.js index d5561fb47..b1e819d21 100644 --- a/Objective-J/ObjJAcornCompiler.js +++ b/Objective-J/ObjJAcornCompiler.js @@ -394,9 +394,22 @@ var ObjJAcornCompiler = function(/*String*/ aString, /*CFURL*/ aURL, /*unsigned* #ifdef BROWSER console.log(message); #else - print(message); + if (exports.outputFormatInXML) + { + var dict = new CFMutableDictionary(); + dict.addValueForKey('line', e.line); + dict.addValueForKey('path', this.URL.absoluteString()); + dict.addValueForKey('message', message); + + print(CFPropertyListCreateXMLData([dict], kCFPropertyListXMLFormat_v1_0).rawString()); + } + else + { + print(message); + } #endif } + throw e; } @@ -434,6 +447,8 @@ exports.ObjJAcornCompiler.compileFileDependencies = function(/*String*/ aString, ObjJAcornCompiler.prototype.compilePass2 = function() { + var warnings = []; + ObjJAcornCompiler.currentCompileFile = this.URL; this.pass = 2; this.jsBuffer = new StringBuffer(); @@ -442,14 +457,32 @@ ObjJAcornCompiler.prototype.compilePass2 = function() compile(this.tokens, new Scope(null ,{ compiler: this }), pass2); for (var i = 0; i < this.warnings.length; i++) { - var message = this.prettifyMessage(this.warnings[i], "WARNING"); + var warning = this.warnings[i], + type = "WARNING"; + + var message = this.prettifyMessage(warning, type); #ifdef BROWSER console.log(message); #else - print(message); + if (exports.outputFormatInXML) + { + var dict = new CFMutableDictionary(); + dict.addValueForKey('line', warning.line) + dict.addValueForKey('path', this.URL.absoluteString()) + dict.addValueForKey('message', message) + + warnings.push(dict); + } + else + { + print(message); + } #endif } + if (warnings.length && exports.outputFormatInXML) + print(CFPropertyListCreateXMLData(warnings, kCFPropertyListXMLFormat_v1_0).rawString()); + //print(this.URL + ": " + this.jsBuffer.toString()); return this.jsBuffer.toString(); } @@ -659,10 +692,23 @@ ObjJAcornCompiler.prototype.prettifyMessage = function(/* Message */ aMessage, / ObjJAcornCompiler.prototype.error_message = function(errorMessage, node) { - var pos = exports.acorn.getLineInfo(this.source, node.start), - syntaxError = {message: errorMessage, line: pos.line, column: pos.column, lineStart: pos.lineStart, lineEnd: pos.lineEnd}; + var pos = exports.acorn.getLineInfo(this.source, node.start); - return new SyntaxError(this.prettifyMessage(syntaxError, "ERROR")); + if (exports.outputFormatInXML) + { + var dict = new CFMutableDictionary(); + dict.addValueForKey('line', pos.line); + dict.addValueForKey('path', this.URL.absoluteString()); + dict.addValueForKey('message', errorMessage); + + return CFPropertyListCreateXMLData([dict], kCFPropertyListXMLFormat_v1_0).rawString(); + } + else + { + var syntaxError = {message: errorMessage, line: pos.line, column: pos.column, lineStart: pos.lineStart, lineEnd: pos.lineEnd}; + + return new SyntaxError(this.prettifyMessage(syntaxError, "ERROR")); + } } ObjJAcornCompiler.prototype.pushImport = function(url) From f232b327c020754d86591809978d9dacacc41d2b Mon Sep 17 00:00:00 2001 From: Alexandre Wilhelm Date: Mon, 25 May 2015 11:38:16 -0700 Subject: [PATCH 2/8] Fixed: issue with options --objj-include-paths and --multifiles. Long options were not taken --- Objective-J/CommonJS/lib/objective-j.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Objective-J/CommonJS/lib/objective-j.js b/Objective-J/CommonJS/lib/objective-j.js index 9ff487184..747e53dc1 100644 --- a/Objective-J/CommonJS/lib/objective-j.js +++ b/Objective-J/CommonJS/lib/objective-j.js @@ -102,11 +102,13 @@ exports.run = function(args) { switch (argv[0]) { + case "--objj-include-paths": case "-I": argv.shift(); OBJJ_INCLUDE_PATHS.unshift.apply(OBJJ_INCLUDE_PATHS, argv.shift().split(":")); break; + case "--multifiles": case "-m": argv.shift(); multipleFiles = true; From 3102c545ceccbcbdabafe5d059c6398028192b4e Mon Sep 17 00:00:00 2001 From: Alexandre Wilhelm Date: Mon, 25 May 2015 13:26:37 -0700 Subject: [PATCH 3/8] Fixed: used url path (/Users/..) instead of absoluth path (file://Users/..) in the xml output format of objj --- Objective-J/ObjJAcornCompiler.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Objective-J/ObjJAcornCompiler.js b/Objective-J/ObjJAcornCompiler.js index b1e819d21..f18dc6387 100644 --- a/Objective-J/ObjJAcornCompiler.js +++ b/Objective-J/ObjJAcornCompiler.js @@ -398,7 +398,7 @@ var ObjJAcornCompiler = function(/*String*/ aString, /*CFURL*/ aURL, /*unsigned* { var dict = new CFMutableDictionary(); dict.addValueForKey('line', e.line); - dict.addValueForKey('path', this.URL.absoluteString()); + dict.addValueForKey('path', this.URL.path()); dict.addValueForKey('message', message); print(CFPropertyListCreateXMLData([dict], kCFPropertyListXMLFormat_v1_0).rawString()); @@ -468,7 +468,7 @@ ObjJAcornCompiler.prototype.compilePass2 = function() { var dict = new CFMutableDictionary(); dict.addValueForKey('line', warning.line) - dict.addValueForKey('path', this.URL.absoluteString()) + dict.addValueForKey('path', this.URL.path()) dict.addValueForKey('message', message) warnings.push(dict); @@ -698,7 +698,7 @@ ObjJAcornCompiler.prototype.error_message = function(errorMessage, node) { var dict = new CFMutableDictionary(); dict.addValueForKey('line', pos.line); - dict.addValueForKey('path', this.URL.absoluteString()); + dict.addValueForKey('path', this.URL.path()); dict.addValueForKey('message', errorMessage); return CFPropertyListCreateXMLData([dict], kCFPropertyListXMLFormat_v1_0).rawString(); From 4f64d466fb7e034c836c4361b1cddf8625ad9157 Mon Sep 17 00:00:00 2001 From: Alexandre Wilhelm Date: Mon, 25 May 2015 13:27:03 -0700 Subject: [PATCH 4/8] Test: added unit test for option -xml-output-format of objj --- Tests/Tools/ToolsTest.j | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/Tests/Tools/ToolsTest.j b/Tests/Tools/ToolsTest.j index bf541005a..a15d1df01 100644 --- a/Tests/Tools/ToolsTest.j +++ b/Tests/Tools/ToolsTest.j @@ -7,7 +7,7 @@ function cleanup() { FILE.rmtree(dir); }); - ["objj2objcskeletonTestFile.h", "objj2objcskeletonTestFile.m", "objj2objcskeletonTestFile.j"].forEach(function(file) { + ["objj2objcskeletonTestFile.h", "objj2objcskeletonTestFile.m", "objj2objcskeletonTestFile.j", "objjWarningTestFile.j", "objjErrorTestFile.j"].forEach(function(file) { if (FILE.isFile(file)) FILE.remove(file); }); @@ -18,6 +18,14 @@ function cleanup() { } - (void)setUp +{ + cleanup(); + FILE.write("objj2objcskeletonTestFile.j", "@import \n@import \n\n\n@implementation AppController : CPObject\n{\n @outlet CPSplitView splitViewA;\n @outlet CPSplitView splitViewB;\n @outlet CPSplitView splitViewC;\n}\n\n@end"); + FILE.write("objjWarningTestFile.j", "@import @implementation AppController : CPObject{CPWindow theWindow;}@end"); + FILE.write("objjErrorTestFile.j", "@implementation AppController : CPObject{}@end"); +} + +- (void)tearDown { cleanup(); } @@ -38,14 +46,25 @@ function cleanup() { status = OS.system(["objj", "ToolsTestApp/AppController.j"]); [self assert:0 equals:status message:"objj failed"]; + status = OS.system(["objj", "--xml-output-format", "ToolsTestApp/AppController.j"]); + [self assert:0 equals:status message:"objj failed"]; + + var p = OS.popen(["objj", "--xml-output-format", "objjErrorTestFile.j"]); + [self assert:1 equals:p.wait() message:"objj failed"]; + [self assert:"\nline1path/Users/Dogild/Project/cappuccino/objjErrorTestFile.jmessageCan't find superclass CPObject\n" equals:p.stdout.read() message:"objj failed"]; + + var p = OS.popen(["objj", "--xml-output-format", "objjWarningTestFile.j"]); + [self assert:0 equals:p.wait() message:"objj failed"]; + [self assert:"\nline1path/Users/Dogild/Project/cappuccino/objjWarningTestFile.jmessage\n@import <Foundation/Foundation.j>@implementation AppController : CPObject{CPWindow theWindow;}@end\ +\n ^\ +\nWARNING line 1 in file:/Users/Dogild/Project/cappuccino/objjWarningTestFile.j: Unknown type 'CPWindow' for ivar 'theWindow'\n" equals:p.stdout.read() message:"objj failed"]; + 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"]); [self assert:0 equals:status message:"objj failed with options -I"]; - FILE.write("objj2objcskeletonTestFile.j", "@import \n@import \n\n\n@implementation AppController : CPObject\n{\n @outlet CPSplitView splitViewA;\n @outlet CPSplitView splitViewB;\n @outlet CPSplitView splitViewC;\n}\n\n@end"); - status = OS.system(["objj2objcskeleton", "objj2objcskeletonTestFile.j", "."]); [self assert:0 equals:status message:"objj2objcskeleton failed"]; @@ -60,9 +79,4 @@ function cleanup() { [self assert:contentMFile equals:expectedMResult message:@"File generated by objj2objcskeleton is wrong"]; } -- (void)tearDown -{ - cleanup(); -} - @end From 3e03d52fcea9fa339f5f07ccd86c3183c10f8462 Mon Sep 17 00:00:00 2001 From: Alexandre Wilhelm Date: Mon, 25 May 2015 15:22:30 -0700 Subject: [PATCH 5/8] Fixed: objj tests did only work on my system... --- Tests/Tools/ToolsTest.j | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/Tests/Tools/ToolsTest.j b/Tests/Tools/ToolsTest.j index a15d1df01..ea2966173 100644 --- a/Tests/Tools/ToolsTest.j +++ b/Tests/Tools/ToolsTest.j @@ -32,7 +32,8 @@ function cleanup() { - (void)testTools { - var status; + var status, + rootDirectory = FILE.cwd(); status = OS.system(["capp", "gen", "ToolsTestApp"].map(OS.enquote).join(" ") + " > /dev/null"); [self assert:0 equals:status message:"capp gen failed"]; @@ -51,13 +52,13 @@ function cleanup() { var p = OS.popen(["objj", "--xml-output-format", "objjErrorTestFile.j"]); [self assert:1 equals:p.wait() message:"objj failed"]; - [self assert:"\nline1path/Users/Dogild/Project/cappuccino/objjErrorTestFile.jmessageCan't find superclass CPObject\n" equals:p.stdout.read() message:"objj failed"]; + [self assert:"\nline1path" + rootDirectory + "/objjErrorTestFile.jmessageCan't find superclass CPObject\n" equals:p.stdout.read() message:"objj failed"]; var p = OS.popen(["objj", "--xml-output-format", "objjWarningTestFile.j"]); [self assert:0 equals:p.wait() message:"objj failed"]; - [self assert:"\nline1path/Users/Dogild/Project/cappuccino/objjWarningTestFile.jmessage\n@import <Foundation/Foundation.j>@implementation AppController : CPObject{CPWindow theWindow;}@end\ + [self assert:"\nline1path" + rootDirectory + "/objjWarningTestFile.jmessage\n@import <Foundation/Foundation.j>@implementation AppController : CPObject{CPWindow theWindow;}@end\ \n ^\ -\nWARNING line 1 in file:/Users/Dogild/Project/cappuccino/objjWarningTestFile.j: Unknown type 'CPWindow' for ivar 'theWindow'\n" equals:p.stdout.read() message:"objj failed"]; +\nWARNING line 1 in file:" + rootDirectory + "/objjWarningTestFile.j: Unknown type 'CPWindow' for ivar 'theWindow'\n" equals:p.stdout.read() message:"objj failed"]; status = OS.system(["objj", "-m", "ToolsTestApp/AppController.j", "ToolsTestApp/AppController.j"]); [self assert:0 equals:status message:"objj failed with several files"]; From abcdc0875c6a60cd1fa1d3ad636333853a2a9aed Mon Sep 17 00:00:00 2001 From: Alexandre Wilhelm Date: Wed, 27 May 2015 11:12:36 -0700 Subject: [PATCH 6/8] Fixed: added option -x for objj and changed xml-output-format to --xml --- Objective-J/CommonJS/lib/objective-j.js | 3 ++- Tests/Tools/ToolsTest.j | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/Objective-J/CommonJS/lib/objective-j.js b/Objective-J/CommonJS/lib/objective-j.js index 747e53dc1..fbe2c2d81 100644 --- a/Objective-J/CommonJS/lib/objective-j.js +++ b/Objective-J/CommonJS/lib/objective-j.js @@ -94,7 +94,7 @@ exports.run = function(args) print(" -I, --objj-include-paths include a specific framework paths") print(" -h, --help print this help"); print(" -m, --multifiles launch objj on several files") - print(" --xml-output-format specify the output format in xml.") + print(" -x, --xml specify the output format in xml.") return; } @@ -114,6 +114,7 @@ exports.run = function(args) multipleFiles = true; break + case "-x": case "--xml-output-format": argv.shift(); exports.outputFormatInXML = true; diff --git a/Tests/Tools/ToolsTest.j b/Tests/Tools/ToolsTest.j index ea2966173..fe05f692c 100644 --- a/Tests/Tools/ToolsTest.j +++ b/Tests/Tools/ToolsTest.j @@ -47,10 +47,10 @@ function cleanup() { status = OS.system(["objj", "ToolsTestApp/AppController.j"]); [self assert:0 equals:status message:"objj failed"]; - status = OS.system(["objj", "--xml-output-format", "ToolsTestApp/AppController.j"]); + status = OS.system(["objj", "-x", "ToolsTestApp/AppController.j"]); [self assert:0 equals:status message:"objj failed"]; - var p = OS.popen(["objj", "--xml-output-format", "objjErrorTestFile.j"]); + var p = OS.popen(["objj", "--xml", "objjErrorTestFile.j"]); [self assert:1 equals:p.wait() message:"objj failed"]; [self assert:"\nline1path" + rootDirectory + "/objjErrorTestFile.jmessageCan't find superclass CPObject\n" equals:p.stdout.read() message:"objj failed"]; From 5095620005c9225311c5855dc673fb6699aa30ee Mon Sep 17 00:00:00 2001 From: Alexandre Wilhelm Date: Wed, 27 May 2015 11:46:43 -0700 Subject: [PATCH 7/8] Fixed: changed --xml-output-format to --xml in objj --- Objective-J/CommonJS/lib/objective-j.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Objective-J/CommonJS/lib/objective-j.js b/Objective-J/CommonJS/lib/objective-j.js index fbe2c2d81..4c347ec64 100644 --- a/Objective-J/CommonJS/lib/objective-j.js +++ b/Objective-J/CommonJS/lib/objective-j.js @@ -115,7 +115,7 @@ exports.run = function(args) break case "-x": - case "--xml-output-format": + case "--xml": argv.shift(); exports.outputFormatInXML = true; break; From caba631db9a740c36ce073d7fb5302d2a450a035 Mon Sep 17 00:00:00 2001 From: Alexandre Wilhelm Date: Wed, 27 May 2015 12:38:56 -0700 Subject: [PATCH 8/8] Test: updated ToolsTest.j --- Tests/Tools/ToolsTest.j | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tests/Tools/ToolsTest.j b/Tests/Tools/ToolsTest.j index fe05f692c..c86fff7da 100644 --- a/Tests/Tools/ToolsTest.j +++ b/Tests/Tools/ToolsTest.j @@ -54,7 +54,7 @@ function cleanup() { [self assert:1 equals:p.wait() message:"objj failed"]; [self assert:"\nline1path" + rootDirectory + "/objjErrorTestFile.jmessageCan't find superclass CPObject\n" equals:p.stdout.read() message:"objj failed"]; - var p = OS.popen(["objj", "--xml-output-format", "objjWarningTestFile.j"]); + var p = OS.popen(["objj", "-x", "objjWarningTestFile.j"]); [self assert:0 equals:p.wait() message:"objj failed"]; [self assert:"\nline1path" + rootDirectory + "/objjWarningTestFile.jmessage\n@import <Foundation/Foundation.j>@implementation AppController : CPObject{CPWindow theWindow;}@end\ \n ^\