diff --git a/Foundation/CPBundle.j b/Foundation/CPBundle.j index 503acb38e..dac71e354 100644 --- a/Foundation/CPBundle.j +++ b/Foundation/CPBundle.j @@ -132,44 +132,47 @@ self._infoConnection = [CPURLConnection connectionWithRequest:[CPURLRequest requestWithURL:[self bundlePath] + "/Info.plist"] delegate:self]; } +- (CPString)firstEligiblePlatform +{ + var platforms = [self objectForInfoDictionaryKey:"CPBundlePlatforms"]; + + return [platforms firstObjectCommonWithArray:OBJJ_PLATFORMS] || nil; +} + - (void)connection:(CPURLConnection)aConnection didReceiveData:(CPString)data { if (aConnection === self._infoConnection) { info = CPPropertyListCreateFromData([CPData dataWithString:data]); - var platform = '/', - platforms = [self objectForInfoDictionaryKey:"CPBundlePlatforms"]; + var platform = [self firstEligiblePlatform]; - if (platforms) - { - platform = [platforms firstObjectCommonWithArray:OBJJ_PLATFORMS]; - platform = platform ? '/' + platform + ".platform/" : '/'; - } + if (!platform) + throw "Engine not supported."; - [CPURLConnection connectionWithRequest:[CPURLRequest requestWithURL:[self bundlePath] + platform + [self objectForInfoDictionaryKey:"CPBundleExecutable"]] delegate:self]; + [CPURLConnection connectionWithRequest:[CPURLRequest requestWithURL:[self bundlePath] + '/' + platform + ".platform/" + [self objectForInfoDictionaryKey:"CPBundleExecutable"]] delegate:self]; } else { objj_decompile([data string], self); - + var context = new objj_context(); - + if ([_delegate respondsToSelector:@selector(bundleDidFinishLoading:)]) context.didCompleteCallback = function() { [_delegate bundleDidFinishLoading:self]; }; - - var files = [self objectForInfoDictionaryKey:@"CPBundleReplacedFiles"], + + var files = [[self objectForInfoDictionaryKey:@"CPBundleReplacedFiles"] objectForKey:[self firstEligiblePlatform]], count = files.length, bundlePath = [self bundlePath]; - + while (count--) { var fileName = files[count]; - + if (fileName.indexOf(".j") === fileName.length - 2) context.pushFragment(fragment_create_file(bundlePath + '/' + fileName, new objj_bundle(""), YES, NULL)); } - + if (context.fragments.length) context.evaluate(); else diff --git a/Objective-J/CommonJS/objective-j/lib-js/objective-j.js b/Objective-J/CommonJS/objective-j/lib-js/objective-j.js index c37b7e2f7..a226ba7f5 100644 --- a/Objective-J/CommonJS/objective-j/lib-js/objective-j.js +++ b/Objective-J/CommonJS/objective-j/lib-js/objective-j.js @@ -3,7 +3,8 @@ var file = require("file"), var window = require("browser/window"); -if (system.engine === "rhino") { +if (system.engine === "rhino") +{ window.__parent__ = null; window.__proto__ = global; } diff --git a/Objective-J/CommonJS/objective-j/lib-js/objective-j/jake/bundletask.js b/Objective-J/CommonJS/objective-j/lib-js/objective-j/jake/bundletask.js index ee5fc48f1..24ca82ec0 100644 --- a/Objective-J/CommonJS/objective-j/lib-js/objective-j/jake/bundletask.js +++ b/Objective-J/CommonJS/objective-j/lib-js/objective-j/jake/bundletask.js @@ -381,8 +381,13 @@ BundleTask.prototype.defineResourceTask = function(aResourcePath, aDestinationPa { filedir (aDestinationPath, [aResourcePath], function() { - // HEY TOM THIS ONE - cp_r(aResourcePath, aDestinationPath); + if (FILE.exists(aDestinationPath)) + rm_rf(aDestinationPath); + + if (FILE.isDirectory(aResourcePath)) + FILE.copyTree(aResourcePath, aDestinationPath); + else + FILE.copy(aResourcePath, aDestinationPath); }); this.enhance([aDestinationPath]); diff --git a/Tools/nib2cib/Converter.j b/Tools/nib2cib/Converter.j index ade65b36e..05ee2a07e 100644 --- a/Tools/nib2cib/Converter.j +++ b/Tools/nib2cib/Converter.j @@ -23,8 +23,7 @@ @import @import -var File = require("file"), - FILE = require("file"), +var FILE = require("file"), popen = require("os").popen; @@ -56,10 +55,10 @@ ConverterConversionException = @"ConverterConversionException"; { try { - if ([resourcesPath length] && !File.isReadable(resourcesPath)) + if ([resourcesPath length] && !FILE.isReadable(resourcesPath)) [CPException raise:ConverterConversionException reason:@"Could not read Resources at path \"" + resourcesPath + "\""]; - var stringContents = File.read(inputPath, { charset:"UTF-8" }), + var stringContents = FILE.read(inputPath, { charset:"UTF-8" }), inferredFormat = format; if (inferredFormat === NibFormatUndetermined) @@ -68,7 +67,7 @@ ConverterConversionException = @"ConverterConversionException"; inferredFormat = NibFormatMac; // Some .xibs are iPhone nibs, check the actual contents in this case. - if (File.extname(inputPath) !== ".nib" && + if (FILE.extension(inputPath) !== ".nib" && stringContents.indexOf("\s*CF\$UID\s*\<\/key\>/g, "CP$UID"); - plistContents = String(java.lang.String(plistContents).replaceAll("\\\\s*CF\\$UID\\s*\\<\/key\\>", "CP\\$UID")); + if (system.engine === "rhino") + plistContents = String(java.lang.String(plistContents).replaceAll("\\\\s*CF\\$UID\\s*\\<\/key\\>", "CP\\$UID")); + else + plistContents = plistContents.replace(/\\s*CF\$UID\s*\<\/key\>/g, "CP$UID"); return [CPData dataWithString:plistContents]; } @end -function cibExtension(aPath) -{ - var start = aPath.length - 1; - - while (aPath.charAt(start) === '/') - start--; - - aPath = aPath.substr(0, start + 1); - - var dotIndex = aPath.lastIndexOf('.'); - - if (dotIndex == -1) - return aPath + ".cib"; - - var slashIndex = aPath.lastIndexOf('/'); - - if (slashIndex > dotIndex) - return aPath + ".cib"; - - return aPath.substr(0, dotIndex) + ".cib"; -} - @import "Converter+Mac.j" diff --git a/Tools/nib2cib/main.j b/Tools/nib2cib/main.j index bd47e196f..aaba68830 100644 --- a/Tools/nib2cib/main.j +++ b/Tools/nib2cib/main.j @@ -30,16 +30,16 @@ @import "Nib2CibKeyedUnarchiver.j" @import "Converter.j" -var File = require("file"); +var FILE = require("file"), + OS = require("os"); -importPackage(java.io); CPLogRegister(CPLogPrint); function printUsage() { print("usage: nib2cib INPUT_FILE [OUTPUT_FILE] [-F /path/to/required/framework] [-R path/to/resources]"); - java.lang.System.exit(1); + OS.exit(1); } function loadFrameworks(frameworkPaths, aCallback) @@ -47,59 +47,40 @@ function loadFrameworks(frameworkPaths, aCallback) if (!frameworkPaths || frameworkPaths.length === 0) return aCallback(); - var frameworkPath = frameworkPaths.shift(), - infoPlistPath = frameworkPath + "/Info.plist"; - - if (!File.isReadable(infoPlistPath)) + frameworkPaths.forEach(function(aFrameworkPath) { - print("'" + frameworkPath + "' is not a framework or could not be found."); - java.lang.System.exit(1); - } + var infoPlistPath = FILE.join(aFrameworkPath, "Info.plist"); - var infoDictionary = CPPropertyListCreateFromData([CPData dataWithString:File.read(infoPlistPath, { charset:"UTF-8" })]); - - if ([infoDictionary objectForKey:@"CPBundlePackageType"] !== "FMWK") - { - print("'" + frameworkPath + "' is not a framework."); - java.lang.System.exit(1); - } - - print("Loading " + [infoDictionary objectForKey:@"CPBundleName"]); - - var files = [[infoDictionary objectForKey:@"CPBundleReplacedFiles"] objectForKey:[CPBundle firstCompatibleEngineFromArray:[infoDictionary objectForKey:@"CPBundlePlatforms"]]], - count = files.length; - - if (count) - { - var context = new objj_context(); - - context.didCompleteCallback = function() { loadFrameworks(frameworkPaths, aCallback) }; -print("2he"); - while (count--) + if (!FILE.isReadable(infoPlistPath)) { - print(frameworkPath + '/' + files[count]); - context.pushFragment(fragment_create_file(frameworkPath + '/' + files[count], new objj_bundle(""), YES, NULL)); + print("'" + aFrameworkPath + "' is not a framework or could not be found."); + OS.exit(1); } -print("hmmm"); - context.evaluate();print("wha???"); - } - else - loadFrameworks(frameworkPaths, aCallback); -print("so far so good..."); + + print("Loading " + aFrameworkPath); + + var frameworkBundle = [[CPBundle alloc] initWithPath:infoPlistPath]; + + [frameworkBundle loadWithDelegate:nil]; + + require("browser/timeout").serviceTimeouts(); + }); + + aCallback(); } function main() { var count = arguments.length; - + if (count < 1) return printUsage(); - + var index = 0, frameworkPaths = [], converter = [[Converter alloc] init]; - + for (; index < count; ++index) { switch(arguments[index])