List of usage examples for com.google.gwt.core.ext LinkerContext isOutputCompact
boolean isOutputCompact();
true if the output should be as compact is possible and false if the output should be human-readable. From source file:com.google.code.gwt.appcache.linker.IFrameAppCacheLinker.java
License:Apache License
/** * Emits the wrapper HTML resource which loads the permutation javascript in * an external JS resource./*from w ww. ja v a 2s . c om*/ */ private void emitPermutationArtifacts(TreeLogger logger, LinkerContext context, CompilationResult cr, ArtifactSet toReturn) { // Define the strongName(s) and replace the compilation artifact: String htmlStrongName = null; String jsStrongName = null; String manifestStrongName = null; try { // Compute the strongName of the permutation artifact: EmittedArtifact htmlArtifact = doEmitCompilation(logger, context, cr); htmlStrongName = htmlArtifact.getPartialPath(); // Now remove the '.cache.html' permutation artifact from the 'toReturn' // ArtifactSet, and replace it with a '.cache.js' artifact: toReturn.remove(htmlArtifact); // Compute the new 'strongName' for the cache.js artifact: jsStrongName = htmlStrongName.substring(0, htmlStrongName.length() - 4) + "js"; SyntheticArtifact jsArtifact = emitInputStream(logger, htmlArtifact.getContents(logger), jsStrongName); toReturn.add(jsArtifact); // Emit the cache manifest: EmittedArtifact cacheManifestArtifact = emitPermutationCacheManifest(logger, context, jsStrongName); toReturn.add(cacheManifestArtifact); manifestStrongName = cacheManifestArtifact.getPartialPath(); } catch (UnableToCompleteException e) { logger.log(TreeLogger.ERROR, "Failed to emit compilation!", e); } DefaultTextOutput out = new DefaultTextOutput(context.isOutputCompact()); out.print("<html manifest=\"" + manifestStrongName + "\">"); out.newlineOpt(); // Setup the well-known variables. // out.print("<head><script>"); out.newlineOpt(); out.print("var $gwt_version = \"" + About.GWT_VERSION_NUM + "\";"); out.newlineOpt(); out.print("var $wnd = parent;"); 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) {return $wnd.__gwtStatsEvent(a);} : null;"); out.newlineOpt(); out.print("$stats && $stats({moduleName:'" + context.getModuleName() + "',subSystem:'startup',evtGroup:'moduleStartup'" + ",millis:(new Date()).getTime(),type:'moduleEvalStart'});"); out.newlineOpt(); out.print("</script></head>"); out.newlineOpt(); out.print("<body>"); out.newlineOpt(); // Output the JS strongName to the HTML wrapper: out.print("<script type=\"text/javascript\" src=\"" + jsStrongName + "\"></script></body></html>"); out.newlineOpt(); try { toReturn.add(emitString(logger, out.toString(), htmlStrongName)); } catch (UnableToCompleteException e) { logger.log(TreeLogger.ERROR, "Failed to emit wrapper HTML!", e); } }
From source file:com.google.code.gwt.appcache.linker.IFrameAppCacheLinker.java
License:Apache License
/** * Outputs a piece of Javascript which is appended to each Permutation. */// ww w. jav a2 s . c om @Override protected String getModuleSuffix(TreeLogger logger, LinkerContext context) { DefaultTextOutput out = new DefaultTextOutput(context.isOutputCompact()); out.print("$stats && $stats({moduleName:'" + context.getModuleName() + "',subSystem:'startup',evtGroup:'moduleStartup'" + ",millis:(new Date()).getTime(),type:'moduleEvalEnd'});"); // Generate the call to tell the bootstrap code that we're ready to go. out.newlineOpt(); out.print("if ($wnd." + context.getModuleFunctionName() + ") $wnd." + context.getModuleFunctionName() + ".onScriptLoad();"); out.newline(); return out.toString(); }
From source file:com.smartgwt.linker.SmartGwtScriptInjector.java
License:Open Source License
private String getScriptLoadJS(Set<ScriptReference> scriptsToLoad, LinkerContext context) { String moduleName = context.getModuleName(); System.out.println(SCRIPT_ANNOUNCE.replaceFirst("module", moduleName)); String result = "\nif (!window." + LOADED_SCRIPTS + ") " + "window." + LOADED_SCRIPTS + " = {};\n"; for (ScriptReference script : scriptsToLoad) { String src = script.getSrc(); result += "if (!" + LOADED_SCRIPTS + "['" + src + "']) {\n " + LOADED_SCRIPTS + "['" + src + "'] = true;\n " + "document.write('<script language=\"javascript\" src=\"'+" + moduleName + "." + XSI_LINKER_MODULE_BASE + "+'" + src + "\"></script>');\n" + "}\n"; System.out.println(src);//from w w w . j a va 2s. c o m } result += "\n"; return context.isOutputCompact() ? result.replaceAll("\n\\s*", "") : result; }
From source file:org.cesiumjs.linker.CesiumScriptInjector.java
License:Apache License
protected SyntheticArtifact emitString(TreeLogger logger, String what, String partialPath, LinkerContext context) throws UnableToCompleteException { if (context.isOutputCompact()) { what = what.replaceAll("\n\\s*", ""); }/* w ww. ja va 2 s.c om*/ return super.emitString(logger, what, partialPath); }
From source file:org.cruxframework.crux.plugin.gadget.linker.GadgetLinker.java
License:Apache License
@Override protected String getModulePrefix(TreeLogger logger, LinkerContext context, String strongName) throws UnableToCompleteException { TextOutput out = new DefaultTextOutput(context.isOutputCompact()); // $wnd is the main window that the GWT code will affect and also the // location where the bootstrap function was defined. In iframe-based linkers, // $wnd is set to window.parent. Usually, in others, $wnd = window. // By default, $wnd is not set when the module starts, but a replacement for // installLocationIframe.js may set it. //BEGIN GADGET GWT 2.6.1 CHANGE out.print("var $wnd;"); out.newlineOpt();//from w ww. j av a 2 s . c o m out.print("if($wnd && $wnd." + context.getModuleFunctionName() + ") { $wnd = $wnd; } " + "else if(window." + context.getModuleFunctionName() + "){ $wnd = window; } " + "else { $wnd = window.parent; }"); //END GADGET GWT 2.6.1 CHANGE out.newlineOpt(); out.print("var __gwtModuleFunction = $wnd." + context.getModuleFunctionName() + ";"); out.newlineOpt(); out.print("var $sendStats = __gwtModuleFunction.__sendStats;"); out.newlineOpt(); out.print("$sendStats('moduleStartup', 'moduleEvalStart');"); out.newlineOpt(); out.print("var $gwt_version = \"" + About.getGwtVersionNum() + "\";"); out.newlineOpt(); out.print("var $strongName = '" + strongName + "';"); out.newlineOpt(); out.print("var $doc = $wnd.document;"); // The functions for runAsync are set up in the bootstrap script so they // can be overriden in the same way as other bootstrap code is, however // they will be called from, and expected to run in the scope of the GWT code // (usually an iframe) so, here we set up those pointers. out.print("function __gwtStartLoadingFragment(frag) {"); out.newlineOpt(); String fragDir = getFragmentSubdir(logger, context) + '/'; out.print("var fragFile = '" + fragDir + "' + $strongName + '/' + frag + '" + FRAGMENT_EXTENSION + "';"); out.newlineOpt(); out.print("return __gwtModuleFunction.__startLoadingFragment(fragFile);"); out.newlineOpt(); out.print("}"); out.newlineOpt(); out.print("function __gwtInstallCode(code) {return __gwtModuleFunction.__installRunAsyncCode(code);}"); out.newlineOpt(); // Even though we call the $sendStats function in the code written in this // linker, some of the compilation code still needs the $stats and // $sessionId // variables to be available. out.print("var $stats = $wnd.__gwtStatsEvent ? function(a) {return $wnd.__gwtStatsEvent(a);} : null;"); out.newlineOpt(); out.print("var $sessionId = $wnd.__gwtStatsSessionId ? $wnd.__gwtStatsSessionId : null;"); out.newlineOpt(); return out.toString(); }