List of usage examples for com.google.gwt.core.ext LinkerContext getModuleName
String getModuleName();
From source file:cc.alcina.framework.gwt.appcache.linker.AppCacheManifestLinker.java
License:Apache License
/** * Generate a string containing object literals for each manifest entry. *//* w ww . ja v a2s . c o m*/ private String generateEntries(TreeLogger logger, LinkerContext context, Set<Pattern> filters, SortedSet<EmittedArtifact> artifacts) throws UnableToCompleteException { logger = logger.branch(TreeLogger.DEBUG, "Generating manifest contents", null); StringBuffer entries = new StringBuffer(); paths: for (EmittedArtifact artifact : artifacts) { if (artifact.getVisibility() != Visibility.Public) { // These artifacts won't be in the module output directory continue; } String path = artifact.getPartialPath(); for (Pattern p : filters) { if (p.matcher(path).matches()) { logger.log(TreeLogger.DEBUG, "Filtering resource " + path, null); continue paths; } } entries.append("/" + context.getModuleName() + "/" + path); entries.append("\n"); // Read the artifact into the digester InputStream in = artifact.getContents(logger); byte[] buffer = new byte[4096]; int read; try { while ((read = in.read(buffer)) != -1) { digester.update(buffer, 0, read); } } catch (IOException e) { logger.log(TreeLogger.ERROR, "Unable to read artifact " + artifact.getPartialPath(), e); throw new UnableToCompleteException(); } } // Add an alias for Module.nocache.js?compiled to support hosted-mode entries.append("/" + context.getModuleName() + "/" + context.getModuleName() + ".nocache.js?compiled\n"); entries.append("/" + context.getModuleName() + "/" + context.getModuleName() + ".nocache.js\n"); return entries.toString(); }
From source file:com.ait.toolkit.flash.linker.SwfIFrameLinker.java
License:Open Source License
/** * Generate a selection script. The selection information should previously * have been scanned using/*from w w w. jav a 2 s . c o m*/ * {@link PermutationsUtil#setupPermutationsMap(ArtifactSet)}. */ @Override protected String fillSelectionScriptTemplate(StringBuffer selectionScript, TreeLogger logger, LinkerContext context, ArtifactSet artifacts, CompilationResult result) throws UnableToCompleteException { String computeScriptBase; String processMetas; try { computeScriptBase = Utility.getFileFromClassPath(COMPUTE_SCRIPT_BASE_JS); processMetas = Utility.getFileFromClassPath(PROCESS_METAS_JS); } catch (IOException e) { logger.log(TreeLogger.ERROR, "Unable to read selection script template", e); throw new UnableToCompleteException(); } replaceAll(selectionScript, "__COMPUTE_SCRIPT_BASE__", computeScriptBase); replaceAll(selectionScript, "__PROCESS_METAS__", processMetas); selectionScript = InjectionUtil.injectResources(selectionScript, artifacts); permutationsUtil.addPermutationsJs(selectionScript, logger, context); replaceAll(selectionScript, "__MODULE_FUNC__", context.getModuleFunctionName()); replaceAll(selectionScript, "__MODULE_NAME__", context.getModuleName()); replaceAll(selectionScript, "__HOSTED_FILENAME__", getHostedFilename()); return selectionScript.toString(); }
From source file:com.ait.toolkit.flash.linker.SwfSingleScriptLinker.java
License:Open Source License
/** * Generate a selection script. The selection information should previously * have been scanned using/*from w w w . j av a 2 s . c om*/ * {@link PermutationsUtil#setupPermutationsMap(ArtifactSet)}. */ @Override /** * Generate a selection script. The selection information should previously * have been scanned using * {@link PermutationsUtil#setupPermutationsMap(ArtifactSet)}. */ protected String fillSelectionScriptTemplate(StringBuffer selectionScript, TreeLogger logger, LinkerContext context, ArtifactSet artifacts, CompilationResult result) throws UnableToCompleteException { String computeScriptBase; String processMetas; try { computeScriptBase = Utility.getFileFromClassPath(COMPUTE_SCRIPT_BASE_JS); processMetas = Utility.getFileFromClassPath(PROCESS_METAS_JS); } catch (IOException e) { logger.log(TreeLogger.ERROR, "Unable to read selection script template", e); throw new UnableToCompleteException(); } replaceAll(selectionScript, "__COMPUTE_SCRIPT_BASE__", computeScriptBase); replaceAll(selectionScript, "__PROCESS_METAS__", processMetas); selectionScript = InjectionUtil.injectResources(selectionScript, artifacts); permutationsUtil.addPermutationsJs(selectionScript, logger, context); replaceAll(selectionScript, "__MODULE_FUNC__", context.getModuleFunctionName()); replaceAll(selectionScript, "__MODULE_NAME__", context.getModuleName()); replaceAll(selectionScript, "__HOSTED_FILENAME__", getHostedFilename()); return selectionScript.toString(); }
From source file:com.ait.toolkit.node.dev.linker.NodeJsLinker.java
License:Open Source License
@Override public ArtifactSet link(TreeLogger logger, LinkerContext context, ArtifactSet artifacts) throws UnableToCompleteException { ArtifactSet toReturn = new ArtifactSet(artifacts); DefaultTextOutput out = new DefaultTextOutput(true); // inject other scripts // for (ScriptReference resource : // artifacts.find(ScriptReference.class)) { // out.print(resource.toString()); // }// w w w. ja v a2 s . c o m // closure // out.print("(function () {"); // out.newline(); // grab compilation result Set<CompilationResult> results = artifacts.find(CompilationResult.class); CompilationResult result = null; 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(); } else if (!results.isEmpty()) { result = results.iterator().next(); // dump JS 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]); out.newline(); } out.print("var $stats = function() { };"); out.newline(); out.print("var $sessionId = function() { };"); out.newline(); // global window // TODO: check this against jsdom // out.print("var window = { };"); // out.newline(); // preload code addPreloadCode(logger, context, artifacts, result, out); out.newline(); out.print("gwtOnLoad(null, '" + context.getModuleName() + "', null);"); out.newline(); // out.print("})();"); // out.newline(); // and to string toReturn.add(emitString(logger, out.toString(), context.getModuleName() + ".js")); return toReturn; }
From source file:com.chrome.gwt.linker.ExtensionLinker.java
License:Apache License
private static String getHtmlFilename(LinkerContext context) { return context.getModuleName() + ".html"; }
From source file:com.emitrom.ti4j.mobile.hybrid.linker.TiMobileHybridLinker.java
License:Apache License
public ArtifactSet link(TreeLogger logger, LinkerContext context, ArtifactSet artifacts) throws UnableToCompleteException { ArtifactSet toReturn = new ArtifactSet(artifacts); DefaultTextOutput out = new DefaultTextOutput(true); long compilationTime = System.currentTimeMillis(); out.print("(function(){"); out.newline();/* ww w.j a v a2 s . c om*/ // get compilation result Set<CompilationResult> results = artifacts.find(CompilationResult.class); if (results.size() == 0) { logger.log(TreeLogger.WARN, "Requested 0 permutations"); return toReturn; } CompilationResult result = results.iterator().next(); // get the generated javascript String[] javaScript = result.getJavaScript(); out.print("var $wnd;var $doc;"); out.print("var $moduleName, $moduleBase;"); out.newline(); out.print("if(typeof(window) != 'undefined'){ $wnd = window; $doc = $wnd.document; }"); out.newline(); out.print("var $gwt_version = \"" + About.getGwtVersionNum() + "\";"); out.newlineOpt(); out.print(javaScript[0]); out.newline(); out.print("var $stats = function(){};"); out.newline(); out.print("var $sessionId = function(){};"); out.newline(); out.print("var navigator = {};"); out.newline(); out.print("navigator.userAgent = 'timobile';"); out.newline(); out.print("$strongName = '" + result.getStrongName() + "';"); out.newline(); out.print("$ti4jCompilationDate = " + compilationTime + ";"); out.newline(); out.print("gwtOnLoad(null,'" + context.getModuleName() + "',null);"); out.newline(); out.print("})();"); out.newline(); toReturn.add(emitString(logger, out.toString(), context.getModuleName() + ".js")); // toReturn.add(emitString(logger, Long.toString(compilationTime), // APP_COMPILATION_FILE_NAME)); return toReturn; }
From source file:com.envjs.gwt.linker.ServerSingleScriptLinker.java
License:Apache License
@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. /*/*from w ww . j ava 2 s . c o m*/ 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"); }
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 w w .j a v a 2 s . co m */ 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. */// w w w. ja v a 2 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.google.javascript.jscomp.gwt.linker.MinimalLinker.java
License:Apache License
@Override public ArtifactSet link(TreeLogger logger, LinkerContext context, ArtifactSet artifacts, boolean onePermutation) throws UnableToCompleteException { ArtifactSet toReturn = new ArtifactSet(artifacts); ArtifactSet writableArtifacts = new ArtifactSet(artifacts); for (CompilationResult result : toReturn.find(CompilationResult.class)) { String[] js = result.getJavaScript(); Preconditions.checkArgument(js.length == 1, "MinimalLinker doesn't support GWT.runAsync"); byte[] primary = Util.getBytes(PREFIX + js[0] + SUFFIX); toReturn.add(emitBytes(logger, primary, context.getModuleName() + ".js")); }//ww w . j a v a 2 s . c om for (SymbolMapsLinker.ScriptFragmentEditsArtifact ea : writableArtifacts .find(SymbolMapsLinker.ScriptFragmentEditsArtifact.class)) { toReturn.add(ea); } return toReturn; }