mirror of
https://github.com/cappuccino/cappuccino.git
synced 2026-10-06 00:52:58 +00:00
Fixed incompatibilities in nib2cib with CommonJS and JavaScriptCore.
Reviewed by me.
This commit is contained in:
1 parent
40b5332c83
commit
16deb3700d
5 files changed
+63
-93
No files matched your search
+18
-15
@@ -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
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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]);
|
||||
|
||||
+14
-34
@@ -23,8 +23,7 @@
|
||||
@import <Foundation/CPObject.j>
|
||||
@import <Foundation/CPData.j>
|
||||
|
||||
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("<archive type=\"com.apple.InterfaceBuilder3.CocoaTouch.XIB\"") !== -1)
|
||||
inferredFormat = NibFormatIPhone;
|
||||
|
||||
@@ -86,9 +85,9 @@ ConverterConversionException = @"ConverterConversionException";
|
||||
[CPException raise:ConverterConversionException reason:@"nib2cib does not understand this nib format."];
|
||||
|
||||
if (![outputPath length])
|
||||
outputPath = cibExtension(inputPath);
|
||||
outputPath = inputPath.substr(0, inputPath.length - FILE.extension(inputPath).length) + ".cib";
|
||||
|
||||
File.write(outputPath, [convertedData string], { charset:"UTF-8" });
|
||||
FILE.write(outputPath, [convertedData string], { charset:"UTF-8" });
|
||||
}
|
||||
catch(anException)
|
||||
{
|
||||
@@ -99,52 +98,33 @@ ConverterConversionException = @"ConverterConversionException";
|
||||
- (CPData)CPCompliantNibDataAtFilePath:(CPString)aFilePath
|
||||
{
|
||||
// Compile xib or nib to make sure we have a non-new format nib.
|
||||
var temporaryNibFilePath = FILE.join("/tmp", aFilePath + ".tmp.nib");
|
||||
var temporaryNibFilePath = FILE.join("/tmp", FILE.basename(aFilePath) + ".tmp.nib");
|
||||
|
||||
if (popen("/usr/bin/ibtool " + aFilePath + " --compile " + temporaryNibFilePath).wait() === 1)
|
||||
throw "Could not compile file at " + aFilePath;
|
||||
|
||||
// Convert from binary plist to XML plist
|
||||
var temporaryPlistFilePath = FILE.join("/tmp", aFilePath + ".tmp.plist");
|
||||
var temporaryPlistFilePath = FILE.join("/tmp", FILE.basename(aFilePath) + ".tmp.plist");
|
||||
|
||||
if (popen("/usr/bin/plutil " + " -convert xml1 " + temporaryNibFilePath + " -o " + temporaryPlistFilePath).wait() === 1)
|
||||
throw "Could not convert to xml plist for file at " + aFilePath;
|
||||
|
||||
if (!File.isReadable(temporaryPlistFilePath))
|
||||
if (!FILE.isReadable(temporaryPlistFilePath))
|
||||
[CPException raise:ConverterConversionException reason:@"Unable to convert nib file."];
|
||||
|
||||
var plistContents = File.read(temporaryPlistFilePath, { charset:"UTF-8" });
|
||||
var plistContents = FILE.read(temporaryPlistFilePath, { charset:"UTF-8" });
|
||||
|
||||
// Minor NS keyed archive to CP keyed archive conversion.
|
||||
// Use Java directly because rhino's string.replace is *so slow*. 4 seconds vs. 1 millisecond.
|
||||
// plistContents = plistContents.replace(/\<key\>\s*CF\$UID\s*\<\/key\>/g, "<key>CP$UID</key>");
|
||||
plistContents = String(java.lang.String(plistContents).replaceAll("\\<key\\>\\s*CF\\$UID\\s*\\<\/key\\>", "<key>CP\\$UID</key>"));
|
||||
if (system.engine === "rhino")
|
||||
plistContents = String(java.lang.String(plistContents).replaceAll("\\<key\\>\\s*CF\\$UID\\s*\\<\/key\\>", "<key>CP\\$UID</key>"));
|
||||
else
|
||||
plistContents = plistContents.replace(/\<key\>\s*CF\$UID\s*\<\/key\>/g, "<key>CP$UID</key>");
|
||||
|
||||
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"
|
||||
+22
-41
@@ -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])
|
||||
|
||||
Reference in new issue
Block a user