From 7819e174f10b4c911cba494493cedfce94f23cfd Mon Sep 17 00:00:00 2001 From: Francisco Ryan Tolmasky I Date: Fri, 19 Feb 2010 00:42:23 -0800 Subject: [PATCH 1/8] Added setString: to CPData which sits on top of setSerializedPlistObject:. Reviewed by me. --- Foundation/CPData.j | 15 +++++++++++++++ Objective-J/CFPropertyList.js | 4 ++-- Objective-J/Preprocessor.js | 7 +++++++ 3 files changed, 24 insertions(+), 2 deletions(-) diff --git a/Foundation/CPData.j b/Foundation/CPData.j index a418362e4..e5c339a83 100644 --- a/Foundation/CPData.j +++ b/Foundation/CPData.j @@ -70,6 +70,11 @@ return self; } +- (id)initWithString:(CPString)aString +{ + return [self initWithSerializedPlistObject:aPlistObject]; +} + - (id)initWithSerializedPlistObject:(id)aPlistObject { self = [super init]; @@ -90,6 +95,16 @@ return self; } +- (void)setString:(CPString)aString +{ + return [self setSerializedPlistObject:aString]; +} + +- (CPString)string +{ + return [self serializedPlistObject]; +} + - (int)length { return [[self encodedString] length]; diff --git a/Objective-J/CFPropertyList.js b/Objective-J/CFPropertyList.js index 9bddee856..4082f9cda 100644 --- a/Objective-J/CFPropertyList.js +++ b/Objective-J/CFPropertyList.js @@ -66,9 +66,9 @@ CFPropertyList.readPropertyListFromFile = function(/*String*/ aFilePath) return CFPropertyList.propertyListFromString(FILE.read(aFilePath, { charset:"UTF-8" })); } -CFPropertyList.writePropertyListToFile = function(/*CFPropertyList*/ aPropertyList, /*String*/ aFilePath) +CFPropertyList.writePropertyListToFile = function(/*CFPropertyList*/ aPropertyList, /*String*/ aFilePath, /*Format*/ aFormat) { - return FILE.write(aFilePath, CFPropertyList.stringFromPropertyList(aPropertyList), { charset:"UTF-8" }); + return FILE.write(aFilePath, CFPropertyList.stringFromPropertyList(aPropertyList, aFormat), { charset:"UTF-8" }); } #endif diff --git a/Objective-J/Preprocessor.js b/Objective-J/Preprocessor.js index 3323cf412..8223229b4 100644 --- a/Objective-J/Preprocessor.js +++ b/Objective-J/Preprocessor.js @@ -146,6 +146,13 @@ function preprocess(/*String*/ aString, /*String*/ aPath, /*unsigned*/ flags) return new Preprocessor(aString, aPath, flags).executable(); } +objj_preprocess = preprocess; + +objj_eval = function(/*String*/ aString) +{ + return eval(objj_preprocess(aString).code()); +} + function Preprocessor(/*String*/ aString, /*String*/ aPath, /*unsigned*/ flags) { // Remove the shebang. From fd8271396d9e0d2f2ca71f48ad3338924a0720fe Mon Sep 17 00:00:00 2001 From: Francisco Ryan Tolmasky I Date: Fri, 19 Feb 2010 02:08:34 -0800 Subject: [PATCH 2/8] Fix for accounting for non-Cappuccino libraries placing things on Object.prototype. Reviewed by me. --- Objective-J/CFBundle.js | 3 ++- Objective-J/EventDispatcher.js | 26 +++++++++++++++----------- 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/Objective-J/CFBundle.js b/Objective-J/CFBundle.js index c8bbfde8a..a516c722e 100644 --- a/Objective-J/CFBundle.js +++ b/Objective-J/CFBundle.js @@ -464,7 +464,8 @@ function executeBundle(/*Bundle*/ aBundle, /*Function*/ aCallback) var children = staticResource.children(); for (var name in children) - staticResources.push(children[name]); + if (hasOwnProperty.call(children, name)) + staticResources.push(children[name]); } } diff --git a/Objective-J/EventDispatcher.js b/Objective-J/EventDispatcher.js index 317e35e22..10817f3dc 100644 --- a/Objective-J/EventDispatcher.js +++ b/Objective-J/EventDispatcher.js @@ -12,13 +12,15 @@ function EventDispatcher(/*Object*/ anOwner) EventDispatcher.prototype.addEventListener = function(/*String*/ anEventName, /*Function*/ anEventListener) { - var eventListenersForEventName = this._eventListenersForEventNames[anEventName]; + var eventListenersForEventNames = this._eventListenersForEventNames; - if (!eventListenersForEventName) + if (!hasOwnProperty.call(this._eventListenersForEventNames, anEventName)) { - eventListenersForEventName = []; - this._eventListenersForEventNames[anEventName] = eventListenersForEventName; + var eventListenersForEventName = []; + eventListenersForEventNames[anEventName] = eventListenersForEventName; } + else + var eventListenersForEventName = eventListenersForEventNames[anEventName]; var index = eventListenersForEventName.length; @@ -31,12 +33,13 @@ EventDispatcher.prototype.addEventListener = function(/*String*/ anEventName, /* EventDispatcher.prototype.removeEventListener = function(/*String*/ anEventName, /*Function*/ anEventListener) { - var eventListenersForEventName = this._eventListenersForEventNames[anEventName]; + var eventListenersForEventNames = this._eventListenersForEventNames; - if (!eventListenersForEventName) + if (!hasOwnProperty.call(eventListenersForEventNames, anEventName)) return; - var index = eventListenersForEventName.length; + var eventListenersForEventName = eventListenersForEventNames[anEventName]. + index = eventListenersForEventName.length; while (index--) if (eventListenersForEventName[index] === anEventListener) @@ -46,13 +49,14 @@ EventDispatcher.prototype.removeEventListener = function(/*String*/ anEventName, EventDispatcher.prototype.dispatchEvent = function(/*Event*/ anEvent) { var type = anEvent.type, - eventListenersForEventName = this._eventListenersForEventNames[type]; + eventListenersForEventNames = this._eventListenersForEventNames; - if (eventListenersForEventName) + if (hasOwnProperty.call(eventListenersForEventNames, type)) { - var index = 0, + var eventListenersForEventName = this._eventListenersForEventNames[type], + index = 0, count = eventListenersForEventName.length; - + for (; index < count; ++index) eventListenersForEventName[index](anEvent); } From a6d2c42402cea9bbbb02ec13d5a44b1ef8820f61 Mon Sep 17 00:00:00 2001 From: Tom Robinson Date: Fri, 19 Feb 2010 02:43:39 -0800 Subject: [PATCH 3/8] Only log errors in setupEnvironment. --- common.jake | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/common.jake b/common.jake index 2192e465b..f17d5f2c8 100644 --- a/common.jake +++ b/common.jake @@ -180,10 +180,10 @@ function reforkWithPackages() reforkWithPackages(); -function throwIfNotRequireError(e) { +function handleSetupEnvironmentError(e) { if (String(e).indexOf("require error")==-1) { print("setupEnvironment: " + e); - throw e; + //throw e; } } @@ -199,13 +199,13 @@ function setupEnvironment() global.BundleTask = OBJECTIVE_J_JAKE.BundleTask; } catch (e) { - throwIfNotRequireError(e); + handleSetupEnvironmentError(e); } try { require("objective-j").OBJJ_INCLUDE_PATHS.push(FILE.join($BUILD_CONFIGURATION_DIR, "CommonJS", "cappuccino", "Frameworks")); } catch (e) { - throwIfNotRequireError(e); + handleSetupEnvironmentError(e); } try { @@ -216,7 +216,7 @@ function setupEnvironment() // print("no blend!") } catch (e) { - throwIfNotRequireError(e); + handleSetupEnvironmentError(e); } } From 25dfcd38a7c3d974eee299603aa7beffe086ce86 Mon Sep 17 00:00:00 2001 From: Paul Baumgart Date: Fri, 19 Feb 2010 04:45:52 -0800 Subject: [PATCH 4/8] Fix case on require() parameter ("OS" -> "os") --- Objective-J/CommonJS/lib/objective-j/jake/applicationtask.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Objective-J/CommonJS/lib/objective-j/jake/applicationtask.js b/Objective-J/CommonJS/lib/objective-j/jake/applicationtask.js index 99fee40e5..1a136b271 100644 --- a/Objective-J/CommonJS/lib/objective-j/jake/applicationtask.js +++ b/Objective-J/CommonJS/lib/objective-j/jake/applicationtask.js @@ -1,6 +1,6 @@ var FILE = require("file"), - OS = require("OS"), + OS = require("os"), Jake = require("jake"), BundleTask = require("objective-j/jake/bundletask").BundleTask; From 99b43fed7f188187600656972aaed167ced3b324 Mon Sep 17 00:00:00 2001 From: Paul Baumgart Date: Fri, 19 Feb 2010 04:46:25 -0800 Subject: [PATCH 5/8] Add support for sudo-install on systems with sudo compiled w/ --with-secure-path --- Jakefile | 6 +++++- bootstrap.sh | 12 +----------- shell_config_file.sh | 13 +++++++++++++ 3 files changed, 19 insertions(+), 12 deletions(-) create mode 100755 shell_config_file.sh diff --git a/Jakefile b/Jakefile index 37556e7d8..21604f47d 100644 --- a/Jakefile +++ b/Jakefile @@ -57,7 +57,11 @@ task ("sudo-install", ["CommonJS"], function() // FIXME: require("narwhal/tusk/install").install({}, $COMMONJS); // Doesn't work due to some weird this.print business. if (OS.system(["sudo", "tusk", "install", "--force", $BUILD_CJS_OBJECTIVE_J, $BUILD_CJS_CAPPUCCINO])) - OS.exit(1); //rake abort if ($? != 0) + { + // Attempt a hackish work-around for sudo compiled with the --with-secure-path option + if (OS.system("sudo bash -c 'source `sh shell_config_file.sh`; tusk install --force " + $BUILD_CJS_OBJECTIVE_J + " " + $BUILD_CJS_CAPPUCCINO + "'")) + OS.exit(1); //rake abort if ($? != 0) + } }); // Documentation diff --git a/bootstrap.sh b/bootstrap.sh index be6478f27..8dfe33661 100755 --- a/bootstrap.sh +++ b/bootstrap.sh @@ -35,17 +35,7 @@ function ask_remove_dir () { function ask_append_shell_config () { config_string="$1" - shell_config_file="" - # use order outlined by http://hayne.net/MacDev/Notes/unixFAQ.html#shellStartup - if [ -f "$HOME/.bash_profile" ]; then - shell_config_file="$HOME/.bash_profile" - elif [ -f "$HOME/.bash_login" ]; then - shell_config_file="$HOME/.bash_login" - elif [ -f "$HOME/.profile" ]; then - shell_config_file="$HOME/.profile" - elif [ -f "$HOME/.bashrc" ]; then - shell_config_file="$HOME/.bashrc" - fi + shell_config_file=`sh shell_config_file.sh` echo " \"$config_string\" will be appended to \"$shell_config_file\"." if prompt; then diff --git a/shell_config_file.sh b/shell_config_file.sh new file mode 100755 index 000000000..c52e8bc17 --- /dev/null +++ b/shell_config_file.sh @@ -0,0 +1,13 @@ +shell_config_file="" +# use order outlined by http://hayne.net/MacDev/Notes/unixFAQ.html#shellStartup +if [ -f "$HOME/.bash_profile" ]; then + shell_config_file="$HOME/.bash_profile" +elif [ -f "$HOME/.bash_login" ]; then + shell_config_file="$HOME/.bash_login" +elif [ -f "$HOME/.profile" ]; then + shell_config_file="$HOME/.profile" +elif [ -f "$HOME/.bashrc" ]; then + shell_config_file="$HOME/.bashrc" +fi + +echo $shell_config_file From b2179f14ab9289aab552a983abd6f826d4da1abe Mon Sep 17 00:00:00 2001 From: Tom Robinson Date: Fri, 19 Feb 2010 16:09:39 -0800 Subject: [PATCH 6/8] Cleanup Jakefiles: * require common.jake first * require Objective-J/Cappuccino stuff only when needed (automatically requiring these caused too many problems) * remove useless shebangs, cleanup whitespace --- AppKit/Jakefile | 2 ++ AppKit/Themes/Aristo/Jakefile | 1 + AppKit/Themes/BlendKit/Jakefile | 2 ++ AppKit/Themes/CommonJS/Jakefile | 1 - AppKit/Themes/Jakefile | 2 -- CommonJS/Jakefile | 1 - Foundation/Jakefile | 2 ++ Jakefile | 5 ++--- Objective-J/Jakefile | 3 ++- Tools/Jakefile | 2 -- Tools/capp/Jakefile | 3 ++- Tools/nib2cib/Jakefile | 7 ++++--- Tools/press/Jakefile | 3 ++- common.jake | 24 ------------------------ 14 files changed, 19 insertions(+), 39 deletions(-) diff --git a/AppKit/Jakefile b/AppKit/Jakefile index 169c19d20..a958e237f 100644 --- a/AppKit/Jakefile +++ b/AppKit/Jakefile @@ -1,6 +1,8 @@ require("../common.jake"); +var framework = require("objective-j/jake").framework; +var BundleTask = require("objective-j/jake").BundleTask; $BUILD_PATH = FILE.join($BUILD_DIR, $CONFIGURATION, 'AppKit'); diff --git a/AppKit/Themes/Aristo/Jakefile b/AppKit/Themes/Aristo/Jakefile index dccab04a2..b643bb65a 100644 --- a/AppKit/Themes/Aristo/Jakefile +++ b/AppKit/Themes/Aristo/Jakefile @@ -1,6 +1,7 @@ require("../../../common.jake"); +var blend = require("cappuccino/jake").blend; blend ("Aristo.blend", function(aristoTask) { diff --git a/AppKit/Themes/BlendKit/Jakefile b/AppKit/Themes/BlendKit/Jakefile index 488fad2b3..4de9f96bb 100644 --- a/AppKit/Themes/BlendKit/Jakefile +++ b/AppKit/Themes/BlendKit/Jakefile @@ -1,6 +1,8 @@ require("../../../common.jake"); +var framework = require("objective-j/jake").framework; +var BundleTask = require("objective-j/jake").BundleTask; blendKitTask = framework ("BlendKit", function(blendKitTask) { diff --git a/AppKit/Themes/CommonJS/Jakefile b/AppKit/Themes/CommonJS/Jakefile index 0d0bd6b93..f85dee241 100644 --- a/AppKit/Themes/CommonJS/Jakefile +++ b/AppKit/Themes/CommonJS/Jakefile @@ -3,7 +3,6 @@ require("../../../common.jake"); var FILE = require("file"); - $BLENDTASK = "blendtask.j"; $BUILD_CJS_BLENDTASK = FILE.join($BUILD_CJS_CAPPUCCINO, "lib", "cappuccino", "jake", "blendtask.j"); diff --git a/AppKit/Themes/Jakefile b/AppKit/Themes/Jakefile index 7dfa4da91..08b139ea2 100644 --- a/AppKit/Themes/Jakefile +++ b/AppKit/Themes/Jakefile @@ -1,6 +1,4 @@ -#!/usr/bin/env narwhal require("../../common.jake"); - subtasks(["BlendKit", "CommonJS", "Aristo"], ["build", "clean", "clobber"]); diff --git a/CommonJS/Jakefile b/CommonJS/Jakefile index c16dd54a0..311843c93 100644 --- a/CommonJS/Jakefile +++ b/CommonJS/Jakefile @@ -1,7 +1,6 @@ require("../common.jake"); - var FILE = require("file"); new FileList("**/*").exclude("Jakefile").forEach(function(aFilename) diff --git a/Foundation/Jakefile b/Foundation/Jakefile index 36b065a9d..b2720208c 100644 --- a/Foundation/Jakefile +++ b/Foundation/Jakefile @@ -22,6 +22,8 @@ require("../common.jake"); +var framework = require("objective-j/jake").framework; +var BundleTask = require("objective-j/jake").BundleTask; foundationTask = framework ("Foundation", function(foundationTask) { diff --git a/Jakefile b/Jakefile index 21604f47d..c308f60ad 100644 --- a/Jakefile +++ b/Jakefile @@ -1,4 +1,5 @@ -#!/usr/bin/env narwhal + +require("./common.jake"); var FILE = require("file"), SYSTEM = require("system"), @@ -6,8 +7,6 @@ var FILE = require("file"), jake = require("jake"), stream = require("term").stream; -require(FILE.absolute("common.jake")); - var subprojects = ["Objective-J", "CommonJS", "Foundation", "AppKit", "Tools"]; ["build", "clean", "clobber"].forEach(function(aTaskName) diff --git a/Objective-J/Jakefile b/Objective-J/Jakefile index 72f252359..8ed79d573 100644 --- a/Objective-J/Jakefile +++ b/Objective-J/Jakefile @@ -20,11 +20,12 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ +require("../common.jake"); + var FILE = require("file"), OS = require("os"), stream = require("term").stream; -require("../common.jake"); //$BUILD_CONFIGURATION_DIR = "../Build" $BROWSER_FILE = FILE.join("Browser", "Objective-J.js"); diff --git a/Tools/Jakefile b/Tools/Jakefile index f508bfbe6..93affadcf 100644 --- a/Tools/Jakefile +++ b/Tools/Jakefile @@ -1,7 +1,5 @@ -#!/usr/bin/env narwhal require("../common.jake"); - // nib2cib has to come before capp since capp uses nib2cib subtasks(["nib2cib", "capp"/*, "bake"*/, "press"], ["build"/*, "clean", "clobber"*/]); diff --git a/Tools/capp/Jakefile b/Tools/capp/Jakefile index 3fb533ef3..c6260c925 100644 --- a/Tools/capp/Jakefile +++ b/Tools/capp/Jakefile @@ -1,7 +1,8 @@ - require ("../../common.jake"); +var app = require("objective-j/jake").app; +var BundleTask = require("objective-j/jake").BundleTask; app ("capp", function(cappTask) { diff --git a/Tools/nib2cib/Jakefile b/Tools/nib2cib/Jakefile index 66915639a..e711b6813 100644 --- a/Tools/nib2cib/Jakefile +++ b/Tools/nib2cib/Jakefile @@ -1,9 +1,10 @@ - -var FILE = require("file"); - require("../../common.jake"); +var FILE = require("file"); + +var app = require("objective-j/jake").app; +var BundleTask = require("objective-j/jake").BundleTask; app ("nib2cib", function(nib2cibTask) { diff --git a/Tools/press/Jakefile b/Tools/press/Jakefile index d63b0fb75..bfbdadfc6 100644 --- a/Tools/press/Jakefile +++ b/Tools/press/Jakefile @@ -1,7 +1,8 @@ -#!/usr/bin/env narwhal require ("../../common.jake"); +var app = require("objective-j/jake").app; +var BundleTask = require("objective-j/jake").BundleTask; app ("press", function(pressTask) { diff --git a/common.jake b/common.jake index f17d5f2c8..258ca4c69 100644 --- a/common.jake +++ b/common.jake @@ -189,35 +189,11 @@ function handleSetupEnvironmentError(e) { function setupEnvironment() { - // TODO: deprecate these globals - try { - var OBJECTIVE_J_JAKE = require("objective-j/jake"); - - global.app = OBJECTIVE_J_JAKE.app; - global.bundle = OBJECTIVE_J_JAKE.bundle; - global.framework = OBJECTIVE_J_JAKE.framework; - - global.BundleTask = OBJECTIVE_J_JAKE.BundleTask; - } catch (e) { - handleSetupEnvironmentError(e); - } - try { require("objective-j").OBJJ_INCLUDE_PATHS.push(FILE.join($BUILD_CONFIGURATION_DIR, "CommonJS", "cappuccino", "Frameworks")); } catch (e) { handleSetupEnvironmentError(e); } - - try { - var CAPPUCCINO_JAKE = require("cappuccino/jake"); - if (CAPPUCCINO_JAKE.blend) - global.blend = CAPPUCCINO_JAKE.blend; - //else - // print("no blend!") - } - catch (e) { - handleSetupEnvironmentError(e); - } } setupEnvironment(); From b7df6c1480d5745df1ae3f6bcf658e81955cc5d4 Mon Sep 17 00:00:00 2001 From: Ross Boucher Date: Fri, 19 Feb 2010 16:47:17 -0800 Subject: [PATCH 7/8] Fix support for MHTML. This uses feature detection to determine if DataURLs, and then if MHTML is supported, and falls back on the original unsprited images. Closes #376. --- Objective-J/CFBundle.js | 64 ++++++++----- .../objective-j/jake/RESOURCES/MHTMLTest.txt | 9 ++ .../lib/objective-j/jake/bundletask.js | 90 ++++++++++--------- 3 files changed, 96 insertions(+), 67 deletions(-) create mode 100644 Objective-J/CommonJS/lib/objective-j/jake/RESOURCES/MHTMLTest.txt diff --git a/Objective-J/CFBundle.js b/Objective-J/CFBundle.js index a516c722e..a992f2fcf 100644 --- a/Objective-J/CFBundle.js +++ b/Objective-J/CFBundle.js @@ -283,7 +283,7 @@ function loadExecutableForBundle(/*Bundle*/ aBundle, success, failure) { try { - decompileStaticFile(aBundle, anEvent.request.responseText()); + decompileStaticFile(aBundle, anEvent.request.responseText(), aBundle.executablePath()); aBundle._loadStatus &= ~CFBundleLoadingExecutable; success(); } @@ -319,7 +319,7 @@ function loadSpritedImagesForBundle(/*Bundle*/ aBundle, success, failure) { try { - decompileStaticFile(aBundle, anEvent.request.responseText()); + decompileStaticFile(aBundle, anEvent.request.responseText(), spritedImagesPath); aBundle._loadStatus &= ~CFBundleLoadingSpritedImages; success(); } @@ -356,9 +356,10 @@ function CFBundleTestSpriteSupport(/*String*/ MHTMLPath, /*Function*/ aCallback) CFBundleDataURLSpriteType, "data:image/gif;base64,R0lGODlhAQABAIAAAMc9BQAAACH5BAAAAAAALAAAAAABAAEAAAICRAEAOw==", CFBundleMHTMLSpriteType, - MHTMLPath, + MHTMLPath+"!test", CFBundleMHTMLUncachedSpriteType, - MHTMLPath+"?"+CFCacheBuster]); + MHTMLPath+"?"+CFCacheBuster+"!test" + ]); } function CFBundleNotifySpriteSupportListeners() @@ -371,6 +372,13 @@ function CFBundleNotifySpriteSupportListeners() function CFBundleTestSpriteTypes(/*Array*/ spriteTypes) { + if (spriteTypes.length < 2) + { + CFBundleSupportedSpriteType = CFBundleNoSpriteType; + CFBundleNotifySpriteSupportListeners(); + return; + } + var image = new Image(); image.onload = function() @@ -386,21 +394,25 @@ function CFBundleTestSpriteTypes(/*Array*/ spriteTypes) image.onerror = function() { - if (spriteTypes.length === 2) - { - CFBundleSupportedSpriteType = CFBundleNoSpriteType; - CFBundleNotifySpriteSupportListeners(); - } - else - CFBundleTestSpriteTypes(spriteTypes.slice(2)); + CFBundleTestSpriteTypes(spriteTypes.slice(2)); } image.src = spriteTypes[1]; } +function mhtmlBasePath() +{ +#ifdef BROWSER + //FIXME: URL stuff is kind of broken + return window.location.protocol + "//" + window.location.hostname + (window.location.port ? (":" + window.location.port) : ""); +#else + return ""; +#endif +} + function spritedImagesTestPathForBundle(/*Bundle*/ aBundle) { - return FILE.join(aBundle.path(), aBundle.mostEligibleEnvironment() + ".environment", "MHTMLTest.txt"); + return "mhtml:" + mhtmlBasePath() + FILE.join(aBundle.path(), aBundle.mostEligibleEnvironment() + ".environment", "MHTMLTest.txt"); } function spritedImagesPathForBundle(/*Bundle*/ aBundle) @@ -408,12 +420,9 @@ function spritedImagesPathForBundle(/*Bundle*/ aBundle) if (CFBundleSupportedSpriteType === CFBundleDataURLSpriteType) return FILE.join(aBundle.path(), aBundle.mostEligibleEnvironment() + ".environment", "dataURLs.txt"); - if (CFBundleSupportedSpriteType === CFBundleMHTMLSpriteType) - return FILE.join(aBundle.path(), aBundle.mostEligibleEnvironment() + ".environment", "MHTML.txt"); + if (CFBundleSupportedSpriteType === CFBundleMHTMLSpriteType || CFBundleSupportedSpriteType === CFBundleMHTMLUncachedSpriteType) + return mhtmlBasePath() + FILE.join(aBundle.path(), aBundle.mostEligibleEnvironment() + ".environment", "MHTMLPaths.txt"); - if (CFBundleSupportedSpriteType === CFBundleMHTMLUncachedSpriteType) - return FILE.join(aBundle.path(), aBundle.mostEligibleEnvironment() + ".environment", "MHTML.txt?" + CFCacheBuster); - return NULL; } @@ -464,8 +473,7 @@ function executeBundle(/*Bundle*/ aBundle, /*Function*/ aCallback) var children = staticResource.children(); for (var name in children) - if (hasOwnProperty.call(children, name)) - staticResources.push(children[name]); + staticResources.push(children[name]); } } @@ -483,15 +491,15 @@ var STATIC_MAGIC_NUMBER = "@STATIC", MARKER_IMPORT_STD = 'I', MARKER_IMPORT_LOCAL = 'i'; -function decompileStaticFile(/*Bundle*/ aBundle, /*String*/ aString) +function decompileStaticFile(/*Bundle*/ aBundle, /*String*/ aString, /*String*/ aPath) { var stream = new MarkedStream(aString); if (stream.magicNumber() !== STATIC_MAGIC_NUMBER) - throw new Error("Could not read static file."); + throw new Error("Could not read static file: "+aPath); if (stream.version() !== "1.0") - throw new Error("Could not read static file."); + throw new Error("Could not read static file: "+aPath); var marker, bundlePath = aBundle.path(), @@ -514,8 +522,18 @@ function decompileStaticFile(/*Bundle*/ aBundle, /*String*/ aString) var URI = stream.getString(); if (URI.toLowerCase().indexOf("mhtml:") === 0) - URI = "mhtml:" + FILE.join(bundlePath, URI.substr("mhtml:".length)); + { + URI = "mhtml:" + mhtmlBasePath() + FILE.join(bundlePath, URI.substr("mhtml:".length)); + if (CFBundleSupportedSpriteType === CFBundleMHTMLUncachedSpriteType) + { + var exclamationIndex = URI.indexOf("!"), + firstPart = URI.substring(0, exclamationIndex), + lastPart = URI.substring(exclamationIndex); + + URI = firstPart + "?" + CFCacheBuster + lastPart; + } + } aBundle._URIMap[text] = URI; // The unresolved directories must not be bundles. diff --git a/Objective-J/CommonJS/lib/objective-j/jake/RESOURCES/MHTMLTest.txt b/Objective-J/CommonJS/lib/objective-j/jake/RESOURCES/MHTMLTest.txt new file mode 100644 index 000000000..6d8ab99f5 --- /dev/null +++ b/Objective-J/CommonJS/lib/objective-j/jake/RESOURCES/MHTMLTest.txt @@ -0,0 +1,9 @@ +/* +Content-Type: multipart/related; boundary="_SEPARATOR_" + +--_SEPARATOR_ +Content-Location:test +Content-Transfer-Encoding:base64 + +R0lGODlhAQABAIAAAMc9BQAAACH5BAAAAAAALAAAAAABAAEAAAICRAEAOw== +*/ \ No newline at end of file diff --git a/Objective-J/CommonJS/lib/objective-j/jake/bundletask.js b/Objective-J/CommonJS/lib/objective-j/jake/bundletask.js index 24d618d13..e59951ca8 100644 --- a/Objective-J/CommonJS/lib/objective-j/jake/bundletask.js +++ b/Objective-J/CommonJS/lib/objective-j/jake/bundletask.js @@ -317,7 +317,17 @@ BundleTask.prototype.buildProductStaticPathForEnvironment = function(anEnvironme BundleTask.prototype.buildProductMHTMLPathForEnvironment = function(anEnvironment) { - return FILE.join(this.buildProductPath(), anEnvironment.name() + ".environment", "MHTML.txt"); + return FILE.join(this.buildProductPath(), anEnvironment.name() + ".environment", "MHTMLPaths.txt"); +} + +BundleTask.prototype.buildProductMHTMLDataPathForEnvironment = function(anEnvironment) +{ + return FILE.join(this.buildProductPath(), anEnvironment.name() + ".environment", "MHTMLData.txt"); +} + +BundleTask.prototype.buildProductMHTMLTestPathForEnvironment = function(anEnvironment) +{ + return FILE.join(this.buildProductPath(), anEnvironment.name() + ".environment", "MHTMLTest.txt"); } BundleTask.prototype.buildProductDataURLPathForEnvironment = function(anEnvironment) @@ -460,8 +470,7 @@ BundleTask.prototype.defineResourceTask = function(aResourcePath, aDestinationPa FILE.write(spritedDestinationPath, base64.encode(FILE.read(aResourcePath, "b")), { charset:"UTF-8" }); }); - filedir (this.buildProductDataURLPathForEnvironment(anEnvironment), [spritedDestinationPath]); - filedir (this.buildProductMHTMLPathForEnvironment(anEnvironment), [spritedDestinationPath]); + task (anEnvironment.name() + "-sprites", [spritedDestinationPath]); }, this); } @@ -571,6 +580,10 @@ BundleTask.prototype.defineResourceTasks = function() }, this); } + +var RESOURCES_PATH = FILE.join(FILE.absolute(FILE.dirname(module.path)), "RESOURCES"), + MHTMLTestPath = FILE.join(RESOURCES_PATH, "MHTMLTest.txt"); + BundleTask.prototype.defineSpritedImagesTask = function() { this.environments().forEach(function(/*Environment*/ anEnvironment) @@ -580,16 +593,23 @@ BundleTask.prototype.defineSpritedImagesTask = function() var folder = anEnvironment.name() + ".environment", resourcesPath = FILE.join(this.buildIntermediatesProductPath(), folder, "Resources", ""), - productName = this.productName(), - dataURLPath = this.buildProductDataURLPathForEnvironment(anEnvironment); + dataURLPath = this.buildProductDataURLPathForEnvironment(anEnvironment), + MHTMLPath = this.buildProductMHTMLPathForEnvironment(anEnvironment), + MHTMLDataPath = this.buildProductMHTMLDataPathForEnvironment(anEnvironment), + MHTMLTestDestinationPath = this.buildProductMHTMLTestPathForEnvironment(anEnvironment), + productName = this.productName(); - filedir (dataURLPath, function(aTask) + task(anEnvironment.name() + "-sprites", function(aTask) { - TERM.stream.print("Creating data URLs file... \0green(" + dataURLPath + "\0)"); + TERM.stream.print("Creating sprited images file... \0green(" + dataURLPath +"\0)"); - var dataURLStream = FILE.open(dataURLPath, "w+", { charset:"UTF-8" }); + var dataURLStream = FILE.open(dataURLPath, "w+", { charset:"UTF-8" }), + MHTMLStream = FILE.open(MHTMLPath, "w+", { charset:"UTF-8" }), + MHTMLDataStream = FILE.open(MHTMLDataPath, "w+", { charset:"UTF-8" }); dataURLStream.write("@STATIC;1.0;"); + MHTMLStream.write("@STATIC;1.0;"); + MHTMLDataStream.write("/*\r\nContent-Type: multipart/related; boundary=\"_ANY_STRING_WILL_DO_AS_A_SEPARATOR\"\r\n\r\n"); aTask.prerequisites().forEach(function(aFilename) { @@ -599,56 +619,39 @@ BundleTask.prototype.defineSpritedImagesTask = function() var resourcePath = "Resources/" + FILE.relative(resourcesPath, aFilename); dataURLStream.write("u;" + resourcePath.length + ";" + resourcePath); + MHTMLStream.write("u;" + resourcePath.length + ";" + resourcePath); + // As data URL... var contents = "data:" + mimeType(aFilename) + ";base64," + FILE.read(aFilename, "b").decodeToString("UTF-8"); dataURLStream.write(contents.length + ";" + contents); - }); - - dataURLStream.write("e;"); - dataURLStream.close(); - }); - - this.enhance([dataURLPath]); - - var MHTMLPath = this.buildProductMHTMLPathForEnvironment(anEnvironment); - - filedir (MHTMLPath, function(aTask) - { - TERM.stream.print("Creating MHTML images file... \0green(" + MHTMLPath +"\0)"); - - var MHTMLStream = FILE.open(MHTMLPath, "w+", { charset:"UTF-8" }), - MHTMLContents = "/*\r\nContent-Type: multipart/related; boundary=\"_ANY_STRING_WILL_DO_AS_A_SEPARATOR\"\r\n\r\n"; - - MHTMLStream.write("@STATIC;1.0;"); - - aTask.prerequisites().forEach(function(aFilename) - { - if (!FILE.isFile(aFilename) || aFilename.indexOf(resourcesPath) !== 0 || !isImage(aFilename)) - return; - - var resourcePath = "Resources/" + FILE.relative(resourcesPath, aFilename); - - MHTMLStream.write("u;" + resourcePath.length + ";" + resourcePath); // As MHTML... - contents = "mhtml:" + FILE.join(folder, productName + ".sj!") + resourcePath; + contents = "mhtml:" + FILE.join(folder, "MHTMLData.txt!") + resourcePath; - MHTMLContents += "--_ANY_STRING_WILL_DO_AS_A_SEPARATOR\r\n"; - MHTMLContents += "Content-Location:" + resourcePath + "\r\nContent-Transfer-Encoding:base64\r\n\r\n"; - MHTMLContents += FILE.read(aFilename, "b").decodeToString("UTF-8"); - MHTMLContents += "\r\n"; + MHTMLDataStream.write("--_ANY_STRING_WILL_DO_AS_A_SEPARATOR\r\n"); + MHTMLDataStream.write("Content-Location:" + resourcePath + "\r\nContent-Transfer-Encoding:base64\r\n\r\n"); + MHTMLDataStream.write(FILE.read(aFilename, "b").decodeToString("UTF-8")); + MHTMLDataStream.write("\r\n"); MHTMLStream.write(contents.length + ";" + contents); }); + dataURLStream.write("e;"); + dataURLStream.close(); + MHTMLStream.write("e;"); - MHTMLStream.write(MHTMLContents + "*/"); MHTMLStream.close(); + + MHTMLDataStream.write("*/"); + MHTMLDataStream.close(); + + // copy the MHTML test file into this environment + FILE.copy(MHTMLTestPath, MHTMLTestDestinationPath); }); - this.enhance([MHTMLPath]); + this.enhance([anEnvironment.name() + "-sprites"]); }, this); } @@ -668,8 +671,7 @@ BundleTask.prototype.defineStaticTask = function() { TERM.stream.print("Creating static file... \0green(" + staticPath +"\0)"); - var fileStream = FILE.open(staticPath, "w+", { charset:"UTF-8" }), - MHTMLContents = ""; + var fileStream = FILE.open(staticPath, "w+", { charset:"UTF-8" }); fileStream.write("@STATIC;1.0;"); From 338860d05bfc27b0d3434ae8a3a0002a67d720ce Mon Sep 17 00:00:00 2001 From: Tom Robinson Date: Fri, 19 Feb 2010 18:26:40 -0800 Subject: [PATCH 8/8] Allow additional frameworks to be copied by capp gen. Use args parser. --- Tools/capp/Generate.j | 209 +++++++++++++++++++++++++++--------------- 1 file changed, 135 insertions(+), 74 deletions(-) diff --git a/Tools/capp/Generate.j b/Tools/capp/Generate.j index b53315813..bcdd07a47 100644 --- a/Tools/capp/Generate.j +++ b/Tools/capp/Generate.j @@ -6,69 +6,98 @@ var OS = require("os"), FILE = require("file"), OBJJ = require("objective-j"); +var stream = require("term").stream; + +var parser = new (require("args").Parser)(); + +parser.usage("DESTINATION_DIRECTORY"); + +parser.help("Generate a Cappuccino project or Frameworks directory"); + +parser.option("-t", "--template", "template") + .set() + .def("Application") + .help("Selects a project template to use (default: Application)."); + +parser.option("-f", "--frameworks", "justFrameworks") + .set(true) + .help("Only generate or update Frameworks directory."); + +parser.option("-F", "--framework", "framework", "frameworks") + .def([]) + .push() + .help("Additional framework to copy/symlink (default: Objective-J, Foundation, AppKit)"); + +parser.option("--no-frameworks", "noFrameworks") + .set(true) + .help("Don't copy any default frameworks (can be overridden with -F)"); + +parser.option("--symlink", "symlink") + .set(true) + .help("Creates a symlink to each framework instead of copying."); + +parser.option("--build", "useCappBuild") + .set(true) + .help("Uses frameworks in the $CAPP_BUILD."); + +parser.option("-l") + .action(function(o) { o.symlink = o.shouldUseCappBuild = true; }) + .help("Enables both the --symlink and --build options."); + +parser.option("--force", "force") + .set(true) + .help("Overwrite update existing frameworks."); + +parser.option("--noconfig", "noconfig") + .set() + .help("Selects a project template to use."); + +parser.option("--list-templates", "listTemplates") + .set(true) + .help("Lists available templates."); + +parser.option("--list-frameworks", "listFrameworks") + .set(true) + .help("Lists available frameworks."); + +parser.helpful(); + // FIXME: better way to do this: var CAPP_HOME = require("packages").catalog["cappuccino"].directory; +var templatesDirectory = FILE.join(CAPP_HOME, "lib", "capp", "Resources", "Templates"); function gen(/*va_args*/) { - var index = 0, - count = arguments.length, + var args = ["capp gen"].concat(Array.prototype.slice.call(arguments)); + var options = parser.parse(args); - shouldSymbolicallyLink = false, - shouldUseCappBuild = false, - justFrameworks = false, - noConfig = false, - force = false, - - template = "Application", - destination = ""; + if (options.listTemplates) { + listTemplates(); + return; + } - for (; index < count; ++index) - { - var argument = arguments[index]; + if (options.listFrameworks) { + listFrameworks(); + return; + } - switch (argument) - { + var destination = options.args[0]; - case "-l": shouldSymbolicallyLink = true; - shouldUseCappBuild = true; - break; - - case "--symlink": - shouldSymbolicallyLink = true; - break; - - case "--build": - shouldUseCappBuild = true; - break; - - case "-t": - case "--template": template = arguments[++index]; - break; - - case "-f": - case "--frameworks": justFrameworks = true; - break; - - case "--noconfig": noConfig = true; - break; - - case "--force": force = true; - break; - - default: destination = argument; + if (!destination) { + if (options.justFrameworks) + destination = "."; + else { + parser.printUsage(options); + OS.exit(1); } } - if (destination.length === 0) - destination = justFrameworks ? "." : "Untitled"; - var sourceTemplate = null; - if (FILE.isAbsolute(template)) - sourceTemplate = FILE.join(template); + if (FILE.isAbsolute(options.template)) + sourceTemplate = FILE.join(options.template); else - sourceTemplate = FILE.join(CAPP_HOME, "lib", "capp", "Resources", "Templates", template); + sourceTemplate = FILE.join(templatesDirectory, options.template); var configFile = FILE.join(sourceTemplate, "template.config"), config = {}; @@ -77,10 +106,15 @@ function gen(/*va_args*/) config = JSON.parse(FILE.read(configFile, { charset:"UTF-8" })); var destinationProject = destination, - configuration = noConfig ? [Configuration defaultConfiguration] : [Configuration userConfiguration]; + configuration = options.noconfig ? [Configuration defaultConfiguration] : [Configuration userConfiguration]; - if (justFrameworks) - createFrameworksInFile(destinationProject, shouldSymbolicallyLink, shouldUseCappBuild, force); + var frameworks = options.frameworks; + if (!options.noFrameworks) { + frameworks.push("Objective-J", "Foundation", "AppKit"); + } + + if (options.justFrameworks) + createFrameworksInFile(frameworks, destinationProject, options.symlink, options.useCappBuild, options.force); else if (!FILE.exists(destinationProject)) { @@ -124,7 +158,7 @@ function gen(/*va_args*/) } catch (anException) { - print("Copying and modifying " + path + " failed."); + stream.print("Copying and modifying " + path + " failed."); } } @@ -133,24 +167,23 @@ function gen(/*va_args*/) if (config.FrameworksPath) frameworkDestination = FILE.join(frameworkDestination, config.FrameworksPath); - createFrameworksInFile(frameworkDestination, shouldSymbolicallyLink, shouldUseCappBuild); + createFrameworksInFile(frameworks, frameworkDestination, options.symlink, options.useCappBuild); } else - print("Directory already exists"); + stream.print("Directory already exists"); } -function createFrameworksInFile(/*String*/ aFile, /*Boolean*/ symlink, /*Boolean*/ build, /*Boolean*/ force) +function createFrameworksInFile(/*Array*/ frameworks, /*String*/ aFile, /*Boolean*/ symlink, /*Boolean*/ build, /*Boolean*/ force) { var destination = FILE.path(FILE.absolute(aFile)); - var frameworks = ["Foundation", "AppKit"]; - + if (!destination.isDirectory()) throw new Error("Can't create Frameworks. Directory does not exist: " + destination); var destinationFrameworks = destination.join("Frameworks"), destinationDebugFrameworks = destination.join("Frameworks", "Debug"); - print("Creating Frameworks directory in " + destinationFrameworks + "."); + stream.print("Creating Frameworks directory in " + destinationFrameworks + "."); //destinationFrameworks.mkdirs(); // redundant destinationDebugFrameworks.mkdirs(); @@ -164,24 +197,29 @@ function createFrameworksInFile(/*String*/ aFile, /*Boolean*/ symlink, /*Boolean var sourceFrameworks = builtFrameworks.join("Release"), sourceDebugFrameworks = builtFrameworks.join("Debug"); - frameworks.concat("Objective-J").forEach(function(framework) { + frameworks.forEach(function(framework) { installFramework(sourceFrameworks.join(framework), destinationFrameworks.join(framework), force, symlink); installFramework(sourceDebugFrameworks.join(framework), destinationDebugFrameworks.join(framework), force, symlink); }); } else { - // Objective-J. Take from OBJJ_HOME. - var objjHome = FILE.path(OBJJ.OBJJ_HOME); - var objjPath = objjHome.join("Frameworks", "Objective-J"); - var objjDebugPath = objjHome.join("Frameworks", "Debug", "Objective-J"); - - installFramework(objjPath, destinationFrameworks.join("Objective-J"), force, symlink); - installFramework(objjDebugPath, destinationDebugFrameworks.join("Objective-J"), force, symlink); - // Frameworks. Search frameworks paths frameworks.forEach(function(framework) { + // Need a special case for Objective-J + if (framework === "Objective-J") { + // Objective-J. Take from OBJJ_HOME. + var objjHome = FILE.path(OBJJ.OBJJ_HOME); + var objjPath = objjHome.join("Frameworks", "Objective-J"); + var objjDebugPath = objjHome.join("Frameworks", "Debug", "Objective-J"); + + installFramework(objjPath, destinationFrameworks.join("Objective-J"), force, symlink); + installFramework(objjDebugPath, destinationDebugFrameworks.join("Objective-J"), force, symlink); + + return; + } + var found; - + for (var i = 0, found = false; !found && i < OBJJ.objj_frameworks.length; i++) { var sourceFramework = FILE.path(OBJJ.objj_frameworks[i]).join(framework); if (FILE.isDirectory(sourceFramework)) { @@ -190,8 +228,8 @@ function createFrameworksInFile(/*String*/ aFile, /*Boolean*/ symlink, /*Boolean } } if (!found) - print("Warning: Couldn't find framework \"" + framework +"\""); - + stream.print("\0yellow(Warning:\0) Couldn't find framework \0cyan(" + framework +"\0)"); + for (var i = 0, found = false; !found && i < OBJJ.objj_debug_frameworks.length; i++) { var sourceDebugFramework = FILE.path(OBJJ.objj_debug_frameworks[i]).join(framework); if (FILE.isDirectory(sourceDebugFramework)) { @@ -200,7 +238,7 @@ function createFrameworksInFile(/*String*/ aFile, /*Boolean*/ symlink, /*Boolean } } if (!found) - print("Warning: Couldn't find debug framework \"" + framework +"\""); + stream.print("\0yellow(Warning:\0) Couldn't find debug framework \0cyan(" + framework +"\0)"); }); } } @@ -210,19 +248,19 @@ function installFramework(source, dest, force, symlink) { if (force) { dest.rmtree(); } else { - print("Warning: " + dest + " already exists. Use --force to overwrite."); + stream.print("\0yellow(Warning:\0) " + dest + " already exists. Use --force to overwrite."); return; } } if (source.exists()) { - print((symlink ? "Symlinking " : "Copying ") + source + " to " + dest); + stream.print((symlink ? "Symlinking " : "Copying ") + source + " to " + dest); if (symlink) FILE.symlink(source, dest); else FILE.copyTree(source, dest); } else - print("Warning: "+source+" doesn't exist."); + stream.print("\0yellow(Warning:\0) "+source+" doesn't exist."); } function toIdentifier(/*String*/ aString) @@ -253,3 +291,26 @@ function toIdentifier(/*String*/ aString) return identifier; } + +function listTemplates() { + FILE.list(templatesDirectory).forEach(function(templateName) { + stream.print(templateName); + }); +} + +function listFrameworks() { + stream.print("Frameworks:"); + OBJJ.objj_frameworks.forEach(function(frameworksDirectory) { + stream.print(" " + frameworksDirectory); + FILE.list(frameworksDirectory).forEach(function(templateName) { + stream.print(" + " + templateName); + }); + }); + stream.print("Frameworks (Debug):"); + OBJJ.objj_debug_frameworks.forEach(function(frameworksDirectory) { + stream.print(" " + frameworksDirectory); + FILE.list(frameworksDirectory).forEach(function(frameworkName) { + stream.print(" + " + frameworkName); + }); + }); +}