From a45869be49e12e95d16584ba3c3b51eae5ad18f1 Mon Sep 17 00:00:00 2001 From: Tom Robinson Date: Wed, 21 Jan 2009 01:45:24 -0800 Subject: [PATCH] Fixed various press bugs. --- Tools/press/press.j | 55 +++++++++++++++++++++++++-------------------- 1 file changed, 31 insertions(+), 24 deletions(-) diff --git a/Tools/press/press.j b/Tools/press/press.j index 4862f0d469..b3aa7aba90 100644 --- a/Tools/press/press.j +++ b/Tools/press/press.j @@ -1,6 +1,6 @@ -import +@import -import "objj-analysis-tools.j" +@import "objj-analysis-tools.j" var defaultMain = "main.j", defaultFrameworks = "Frameworks"; @@ -107,6 +107,7 @@ function main() { var xmlOutput = new Packages.java.io.ByteArrayOutputStream(); outputTransformer(xmlOutput, aResponse.xml, "UTF-8"); + //__fakeResponse.xml = String(xmlOutput.toString()); __fakeResponse.text = CPPropertyListCreate280NorthData(CPPropertyListCreateFromXMLData({ string:String(xmlOutput.toString())})).string; //CPLog.trace("SERIALIZED: " + __fakeResponse.xml.substring(0,100)); } @@ -117,13 +118,15 @@ function main() } // phase 1: get global defines - CPLog.info("Loading application..."); + CPLog.error("PHASE 1: Loading application..."); + var globals = findGlobalDefines(cx, scope, mainPath, evaledFragments); // coalesce the results var dependencies = coalesceGlobalDefines(globals); // phase 2: walk the dependency tree (both imports and references) to determine exactly which files need to be included + CPLog.error("PHASE 2: Walk dependency tree..."); var requiredFiles = {}; @@ -191,7 +194,7 @@ function main() if (flatten) { // phase 3a: build single Application.js file (and modified index.html) - CPLog.info("Flattening..."); + CPLog.error("PHASE 3a: Flattening..."); var applicationJS = [], indexHTML = readFile(rootDirectory + "/index.html"); @@ -208,6 +211,7 @@ function main() var data = new objj_data(); data.string = aResponse.text; bundle.info = CPPropertyListCreateFrom280NorthData(data); + //bundle.info = CPPropertyListCreateFromXMLData({ string : aResponse.xml }); } else bundle.info = new objj_dictionary(); @@ -244,18 +248,11 @@ function main() window.attachEvent('onload', main);" ); + // comment out any OBJJ_MAIN_FILE defintions or objj_import() calls + indexHTML = indexHTML.replace(/(\bOBJJ_MAIN_FILE\s*=|\bobjj_import\s*\()/g, '//$&'); - // do a little regex magic to remove the objj_import and put in a script tag for Application.js - var matches = indexHTML.match(/]*>(?:.|\n)*?<\/script>/g); - for (var i = 0; i < matches.length; i++) - { - if (/\bobjj_import\s*\(/.test(matches[i])) - { - CPLog.warn("Replacing objj_import with script tag."); - var replacement = '\n' + matches[i].replace("objj_import", "//objj_import"); - indexHTML = indexHTML.replace(matches[i], replacement); - } - } + // add a script tag for Application.js at the very end of the block + indexHTML = indexHTML.replace(/([ \t]*)(<\/head>)/, '$1 \n$1$2'); // output Application.js and index.html outputFiles[rootDirectory + "/Application.js"] = applicationJS.join("\n"); @@ -264,6 +261,7 @@ function main() else { // phase 3b: rebuild .sj files with correct imports, copy .j files + CPLog.error("PHASE 3b: Rebuild .sj"); var bundles = {}; @@ -356,30 +354,39 @@ function main() } // phase 3.5: fix bundle plists + CPLog.error("PHASE 3.5: fix bundle plists"); + for (var path in bundles) { - var bundle = bundles[path]; - CPLog.info("Bundle: " + path); - - var dict = file.bundle.info, + var directory = dirname(path), + dict = bundles[path].info, replacedFiles = [dict objectForKey:"CPBundleReplacedFiles"]; + if (replacedFiles) { + var newReplacedFiles = []; + [dict setObject:newReplacedFiles forKey:"CPBundleReplacedFiles"]; + for (var i = 0; i < replacedFiles.length; i++) { - if (!requiredFiles[replacedFiles[i]]) + var replacedFilePath = directory + "/" + replacedFiles[i] + if (!requiredFiles[replacedFilePath]) { CPLog.info("Removing: " + replacedFiles[i]); - replacedFiles.splice(i, 1); + } + else + { + //CPLog.info("Keeping: " + replacedFiles[i]); + newReplacedFiles.push(replacedFiles[i]); } } } - - outputFiles[path] = CPPropertyListCreateXMLData(bundle.info).string; + outputFiles[path] = CPPropertyListCreateXMLData(dict).string; } } // phase 4: copy everything and write out the new files + CPLog.error("PHASE 4: copy to output"); var rootDirectoryFile = new Packages.java.io.File(rootDirectory), outputDirectoryFile = new Packages.java.io.File(outputDirectory); @@ -543,7 +550,7 @@ function outputTransformer(os, document, encoding, standalone) if (standalone) serializer.setOutputProperty(Packages.javax.xml.transform.OutputKeys.STANDALONE, (standalone ? "yes" : "no")); - serializer.transform(domSource, streamResult); + String(serializer.transform(domSource, streamResult)); } main();