| 1 |
function load(fileName){ |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
var fileContents = readFile(fileName); |
| 7 |
|
| 8 |
|
| 9 |
var Context = Packages.org.mozilla.javascript.Context; |
| 10 |
var context = Context.enter(); |
| 11 |
try{ |
| 12 |
return context.evaluateString(this, fileContents, fileName, 1, null); |
| 13 |
}finally{ |
| 14 |
Context.exit(); |
| 15 |
} |
| 16 |
} |
| 17 |
|
| 18 |
function readFile(path, encoding){ |
| 19 |
|
| 20 |
|
| 21 |
encoding = encoding || "utf-8"; |
| 22 |
var file = new java.io.File(path); |
| 23 |
var lineSeparator = "\n"; |
| 24 |
var input = new java.io.BufferedReader(new java.io.InputStreamReader(new java.io.FileInputStream(file), encoding)); |
| 25 |
try { |
| 26 |
var stringBuffer = new java.lang.StringBuffer(); |
| 27 |
var line = ""; |
| 28 |
while((line = input.readLine()) !== null){ |
| 29 |
stringBuffer.append(line); |
| 30 |
stringBuffer.append(lineSeparator); |
| 31 |
} |
| 32 |
|
| 33 |
return new String(stringBuffer.toString()); |
| 34 |
} finally { |
| 35 |
input.close(); |
| 36 |
} |
| 37 |
} |
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
function optimizeJs(fileName, fileContents, copyright, optimizeType, stripConsole){ |
| 42 |
|
| 43 |
|
| 44 |
copyright = copyright || ""; |
| 45 |
|
| 46 |
|
| 47 |
var context = Packages.org.mozilla.javascript.Context.enter(); |
| 48 |
try{ |
| 49 |
|
| 50 |
context.setOptimizationLevel(-1); |
| 51 |
|
| 52 |
|
| 53 |
if(optimizeType.indexOf("shrinksafe") == 0 || optimizeType == "packer"){ |
| 54 |
|
| 55 |
fileContents = new String(Packages.org.dojotoolkit.shrinksafe.Compressor.compressScript(fileContents, 0, 1, stripConsole)); |
| 56 |
if(optimizeType.indexOf(".keepLines") == -1){ |
| 57 |
fileContents = fileContents.replace(/[\r\n]/g, ""); |
| 58 |
} |
| 59 |
}else if(optimizeType == "comments"){ |
| 60 |
|
| 61 |
var script = context.compileString(fileContents, fileName, 1, null); |
| 62 |
fileContents = new String(context.decompileScript(script, 0)); |
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
fileContents = fileContents.replace(/ /g, "\t"); |
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
if(fileName.match(/\/nls\//)){ |
| 71 |
fileContents = fileContents.replace(/;\s*$/, ""); |
| 72 |
} |
| 73 |
} |
| 74 |
}finally{ |
| 75 |
Packages.org.mozilla.javascript.Context.exit(); |
| 76 |
} |
| 77 |
|
| 78 |
|
| 79 |
return copyright + fileContents; |
| 80 |
} |
| 81 |
|
| 82 |
build = { |
| 83 |
make: function( |
| 84 |
|
| 85 |
builderPath, |
| 86 |
|
| 87 |
|
| 88 |
version, |
| 89 |
|
| 90 |
|
| 91 |
cdnType, |
| 92 |
|
| 93 |
|
| 94 |
dependencies, |
| 95 |
|
| 96 |
|
| 97 |
optimizeType){ |
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
if(version != "1.3.2"){ |
| 102 |
return "invalid version"; |
| 103 |
} |
| 104 |
if(cdnType != "google" && cdnType != "aol"){ |
| 105 |
return "invalide CDN type"; |
| 106 |
} |
| 107 |
if(optimizeType != "comments" && optimizeType != "shrinksafe" |
| 108 |
&& optimizeType != "none" && optimizeType != "shrinksafe.keepLines"){ |
| 109 |
return "invalid optimize type"; |
| 110 |
} |
| 111 |
if(!dependencies.match(/^[\w\-\,\s\.]+$/)){ |
| 112 |
return "invalid dependency list"; |
| 113 |
} |
| 114 |
|
| 115 |
|
| 116 |
var xdDojoPath = "http://ajax.googleapis.com/ajax/libs/dojo/"; |
| 117 |
if(cdnType == "aol"){ |
| 118 |
xdDojoPath = "http://o.aolcdn.com/dojo/"; |
| 119 |
} |
| 120 |
xdDojoPath += version; |
| 121 |
|
| 122 |
|
| 123 |
var dojoDir = builderPath + version + "/"; |
| 124 |
|
| 125 |
|
| 126 |
|
| 127 |
var normalizedDependencies = dependencies || ""; |
| 128 |
if(normalizedDependencies){ |
| 129 |
normalizedDependencies = '"' + normalizedDependencies.split(",").join('","') + '"'; |
| 130 |
} |
| 131 |
|
| 132 |
var buildscriptDir = dojoDir + "util/buildscripts/"; |
| 133 |
|
| 134 |
|
| 135 |
load(dojoDir + "util/buildscripts/jslib/logger.js"); |
| 136 |
load(dojoDir + "util/buildscripts/jslib/fileUtil.js"); |
| 137 |
load(dojoDir + "util/buildscripts/jslib/buildUtil.js"); |
| 138 |
load(dojoDir + "util/buildscripts/jslib/buildUtilXd.js"); |
| 139 |
load(dojoDir + "util/buildscripts/jslib/i18nUtil.js"); |
| 140 |
|
| 141 |
|
| 142 |
var kwArgs = buildUtil.makeBuildOptions([ |
| 143 |
"loader=xdomain", |
| 144 |
"version=" + version, |
| 145 |
"xdDojoPath=" + xdDojoPath, |
| 146 |
"layerOptimize=" + optimizeType |
| 147 |
]); |
| 148 |
|
| 149 |
|
| 150 |
var profileText = 'dependencies = {' |
| 151 |
+ 'layers: [' |
| 152 |
+ ' {' |
| 153 |
+ ' name: "dojo.js",' |
| 154 |
+ ' dependencies: [' |
| 155 |
+ normalizedDependencies |
| 156 |
+ ' ]' |
| 157 |
+ ' }' |
| 158 |
+ '],' |
| 159 |
|
| 160 |
+ 'prefixes: [' |
| 161 |
+ ' [ "dojo", "' + dojoDir + 'dojo" ],' |
| 162 |
+ ' [ "dijit", "' + dojoDir + 'dijit" ],' |
| 163 |
+ ' [ "dojox", "' + dojoDir + 'dojox" ]' |
| 164 |
+ ']' |
| 165 |
+ '}'; |
| 166 |
|
| 167 |
|
| 168 |
var profileProperties = buildUtil.evalProfile(profileText, true); |
| 169 |
kwArgs.profileProperties = profileProperties; |
| 170 |
|
| 171 |
|
| 172 |
dependencies = kwArgs.profileProperties.dependencies; |
| 173 |
var prefixes = dependencies.prefixes; |
| 174 |
var lineSeparator = fileUtil.getLineSeparator(); |
| 175 |
var layerLegalText = fileUtil.readFile(buildscriptDir + "copyright.txt") |
| 176 |
+ lineSeparator |
| 177 |
+ fileUtil.readFile(buildscriptDir + "build_notice.txt"); |
| 178 |
|
| 179 |
|
| 180 |
|
| 181 |
dependencies.loader = kwArgs.loader; |
| 182 |
|
| 183 |
|
| 184 |
var depResult = buildUtil.makeDojoJs(buildUtil.loadDependencyList(kwArgs.profileProperties, null, buildscriptDir), kwArgs.version, kwArgs); |
| 185 |
|
| 186 |
|
| 187 |
var layerName = depResult[1].layerName; |
| 188 |
var layerContents = depResult[1].contents; |
| 189 |
|
| 190 |
|
| 191 |
if(layerName.match(/dojo\.xd\.js/) && kwArgs.xdDojoPath){ |
| 192 |
layerContents = buildUtilXd.setXdDojoConfig(layerContents, kwArgs.xdDojoPath); |
| 193 |
} |
| 194 |
|
| 195 |
|
| 196 |
if(kwArgs.internStrings){ |
| 197 |
prefixes = dependencies["prefixes"] || []; |
| 198 |
var skiplist = dependencies["internSkipList"] || []; |
| 199 |
layerContents = buildUtil.interningRegexpMagic(layerName, layerContents, dojoDir, prefixes, skiplist); |
| 200 |
} |
| 201 |
|
| 202 |
|
| 203 |
return optimizeJs(layerName, layerContents, layerLegalText, kwArgs.layerOptimize, ""); |
| 204 |
|
| 205 |
} |
| 206 |
}; |