@Override protected Collection<EmittedArtifact> doEmitCompilation( TreeLogger logger, LinkerContext context, CompilationResult result) throws UnableToCompleteException { if (result.getJavaScript().length != 1) { logger.branch( TreeLogger.ERROR, "The module must not have multiple fragments when using the " + getDescription() + " Linker.", null); throw new UnableToCompleteException(); } return super.doEmitCompilation(logger, context, result); }
@Override protected EmittedArtifact emitSelectionScript( TreeLogger logger, LinkerContext context, ArtifactSet artifacts) throws UnableToCompleteException { DefaultTextOutput out = new DefaultTextOutput(true); // Emit the selection script. // this for 'real browsers' to load the script // we don't need this. /* String bootstrap = generateSelectionScript(logger, context, artifacts); bootstrap = context.optimizeJavaScript(logger, bootstrap); out.print(bootstrap); out.newlineOpt(); */ // we need a ref to the top level window // it is referenced in the closure below out.print("var $_window = this;"); out.newlineOpt(); // this is a hack to make backwards compatible out.print("var __defineParser__ = function(){};"); out.newlineOpt(); // Emit the module's JS a closure. out.newlineOpt(); out.print("(function () {"); out.newlineOpt(); out.print("var $gwt_version = \"" + About.getGwtVersionNum() + "\";"); 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.log( 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("var $strongName = '" + result.getStrongName() + "';"); out.newlineOpt(); String[] js = result.getJavaScript(); if (js.length != 1) { logger.log( TreeLogger.ERROR, "The module must not have multiple fragments when using the " + getDescription() + " Linker.", null); throw new UnableToCompleteException(); } out.print(js[0]); // Generate the call to tell the bootstrap code that we're ready to go. out.newlineOpt(); // the original code setup an "onScriptLoad" event. // Here we just do it out.print("gwtOnLoad();"); out.newlineOpt(); out.print("})();"); out.newlineOpt(); return emitString(logger, out.toString(), context.getModuleName() + ".nocache.js"); }
@Override protected final int compareToComparableArtifact(CompilationResult o) { return getStrongName().compareTo(o.getStrongName()); }