mirror of
https://github.com/cappuccino/cappuccino.git
synced 2026-08-25 21:17:03 +00:00
Merge pull request #2360 from Dogild/XMLOutputFormatObjj
New: added the option --xml-output-format for the command objj
This commit is contained in:
@@ -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(" -x, --xml specify the output format in xml.")
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -101,15 +102,23 @@ 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;
|
||||
break
|
||||
|
||||
case "-x":
|
||||
case "--xml":
|
||||
argv.shift();
|
||||
exports.outputFormatInXML = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -229,6 +238,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)",
|
||||
|
||||
@@ -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.path());
|
||||
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.path())
|
||||
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.path());
|
||||
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)
|
||||
|
||||
+24
-9
@@ -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,13 +18,22 @@ function cleanup() {
|
||||
}
|
||||
|
||||
- (void)setUp
|
||||
{
|
||||
cleanup();
|
||||
FILE.write("objj2objcskeletonTestFile.j", "@import <Foundation/CPObject.j>\n@import <AppKit/AppKit.j>\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 <Foundation/Foundation.j>@implementation AppController : CPObject{CPWindow theWindow;}@end");
|
||||
FILE.write("objjErrorTestFile.j", "@implementation AppController : CPObject{}@end");
|
||||
}
|
||||
|
||||
- (void)tearDown
|
||||
{
|
||||
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"];
|
||||
@@ -38,14 +47,25 @@ function cleanup() {
|
||||
status = OS.system(["objj", "ToolsTestApp/AppController.j"]);
|
||||
[self assert:0 equals:status message:"objj failed"];
|
||||
|
||||
status = OS.system(["objj", "-x", "ToolsTestApp/AppController.j"]);
|
||||
[self assert:0 equals:status message:"objj failed"];
|
||||
|
||||
var p = OS.popen(["objj", "--xml", "objjErrorTestFile.j"]);
|
||||
[self assert:1 equals:p.wait() message:"objj failed"];
|
||||
[self assert:"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\"><plist version = \"1.0\"><array><dict><key>line</key><integer>1</integer><key>path</key><string>" + rootDirectory + "/objjErrorTestFile.j</string><key>message</key><string>Can't find superclass CPObject</string></dict></array></plist>\n" equals:p.stdout.read() message:"objj failed"];
|
||||
|
||||
var p = OS.popen(["objj", "-x", "objjWarningTestFile.j"]);
|
||||
[self assert:0 equals:p.wait() message:"objj failed"];
|
||||
[self assert:"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\"><plist version = \"1.0\"><array><dict><key>line</key><integer>1</integer><key>path</key><string>" + rootDirectory + "/objjWarningTestFile.j</string><key>message</key><string>\n@import <Foundation/Foundation.j>@implementation AppController : CPObject{CPWindow theWindow;}@end\
|
||||
\n ^\
|
||||
\nWARNING line 1 in file:" + rootDirectory + "/objjWarningTestFile.j: Unknown type 'CPWindow' for ivar 'theWindow'</string></dict></array></plist>\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 <Foundation/CPObject.j>\n@import <AppKit/AppKit.j>\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 +80,4 @@ function cleanup() {
|
||||
[self assert:contentMFile equals:expectedMResult message:@"File generated by objj2objcskeleton is wrong"];
|
||||
}
|
||||
|
||||
- (void)tearDown
|
||||
{
|
||||
cleanup();
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
Reference in New Issue
Block a user