@Override
protected EmittedArtifact emitSelectionScript(TreeLogger logger,
LinkerContext context, ArtifactSet artifacts)
throws UnableToCompleteException {
DefaultTextOutput out = new DefaultTextOutput(true);
// Emit the selection script.
String bootstrap = generateSelectionScript(logger, context, artifacts);
bootstrap = context.optimizeJavaScript(logger, bootstrap);
out.print(bootstrap);
out.newlineOpt();
// Emit the module's JS a closure.
out.print("(function () {");
out.newlineOpt();
out.print("var $gwt_version = \"" + About.GWT_VERSION_NUM + "\";");
out.newlineOpt();
out.print("var $wnd = window;");
out.newlineOpt();
out.print("var $doc = $wnd.document;");
out.newlineOpt();
out.print("var $moduleName, $moduleBase;");
out.newlineOpt();
out.print("var $stats = $wnd.__gwtStatsEvent ? function(a) {$wnd.__gwtStatsEvent(a)} : null;");
out.newlineOpt();
// Find the single CompilationResult
Set<CompilationResult> results = artifacts.find(CompilationResult.class);
if (results.size() != 1) {
logger = logger.branch(TreeLogger.ERROR,
"The module must have exactly one distinct"
+ " permutation when using the " + getDescription() + " Linker.",
null);
throw new UnableToCompleteException();
}
CompilationResult result = results.iterator().next();
out.print(result.getJavaScript());
// Generate the call to tell the bootstrap code that we're ready to go.
out.newlineOpt();
out.print("if (" + context.getModuleFunctionName() + ") "
+ context.getModuleFunctionName() + ".onScriptLoad(gwtOnLoad);");
out.newlineOpt();
out.print("})();");
out.newlineOpt();
return emitString(logger, out.toString(), context.getModuleName()
+ ".nocache.js");
}