List of usage examples for com.google.gwt.core.ext LinkerContext getModuleFunctionName
String getModuleFunctionName();
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/* w w w. j a va2s . 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 ww . ja v a 2 s.c o m * {@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.bcdlog.SimpleAppCacheLinker.java
License:Apache License
/** * Creates the cache-manifest resource specific for the landing page. * /*from w w w. ja va 2 s. co m*/ * @param context * the linker environment * @param logger * the tree logger to record to * @param artifacts * {@code null} to generate an empty cache manifest */ private Artifact<?> emitLandingPageCacheManifest(LinkerContext context, TreeLogger logger, ArtifactSet artifacts) throws UnableToCompleteException { StringBuilder publicSourcesSb = new StringBuilder(); StringBuilder staticResoucesSb = new StringBuilder(); if (artifacts != null) { // Iterate over all emitted artifacts, and collect all cacheable // artifacts for (@SuppressWarnings("rawtypes") Artifact artifact : artifacts) { if (artifact instanceof EmittedArtifact) { EmittedArtifact ea = (EmittedArtifact) artifact; String pathName = ea.getPartialPath(); if (pathName.endsWith("symbolMap") || pathName.endsWith(".xml.gz") || pathName.endsWith("rpc.log") || pathName.endsWith("gwt.rpc") || pathName.endsWith("manifest.txt") || pathName.startsWith("rpcPolicyManifest")) { // skip these resources } else { publicSourcesSb.append(pathName + "\n"); } } } String[] cacheExtraFiles = getCacheExtraFiles(); for (int i = 0; i < cacheExtraFiles.length; i++) { staticResoucesSb.append(cacheExtraFiles[i]); staticResoucesSb.append("\n"); } } // build cache list StringBuilder sb = new StringBuilder(); sb.append("CACHE MANIFEST\n"); sb.append("# Unique id #" + (new Date()).getTime() + "." + Math.random() + "\n"); // we have to generate this unique id because the resources can change // but // the hashed cache.html files can remain the same. sb.append("# Note: must change this every time for cache to invalidate\n"); sb.append("\n"); sb.append("CACHE:\n"); sb.append("# Static app files\n"); sb.append(staticResoucesSb.toString()); sb.append("\n# Generated app files\n"); sb.append(publicSourcesSb.toString()); sb.append("\n\n"); sb.append("# All other resources require the user to be online.\n"); sb.append("NETWORK:\n"); sb.append("*\n"); logger.log(TreeLogger.INFO, "Be sure your landing page's <html> tag declares a manifest:" + " <html manifest=" + context.getModuleFunctionName() + "/" + MANIFEST + "\">"); // Create the manifest as a new artifact and return it: return emitString(logger, sb.toString(), MANIFEST); }
From source file:com.goodow.web.dev.rebind.BaseAppCacheLinker.java
License:Apache License
/** * Creates the cache-manifest resource specific for the landing page. * //from w w w . j a v a 2s. c om * @param context the linker environment * @param logger the tree logger to record to * @param artifacts {@code null} to generate an empty cache manifest */ private Artifact<?> emitLandingPageCacheManifest(final LinkerContext context, final TreeLogger logger, final ArtifactSet artifacts) throws UnableToCompleteException { StringBuilder publicSourcesSb = new StringBuilder(); StringBuilder staticResoucesSb = new StringBuilder(); if (artifacts != null) { // Iterate over all emitted artifacts, and collect all cacheable artifacts for (@SuppressWarnings("rawtypes") Artifact artifact : artifacts) { if (artifact instanceof EmittedArtifact) { EmittedArtifact ea = (EmittedArtifact) artifact; String pathName = ea.getPartialPath(); if (pathName.endsWith("symbolMap") || pathName.endsWith(".xml.gz") || pathName.endsWith("rpc.log") || pathName.endsWith("gwt.rpc") || pathName.endsWith("manifest.txt") || pathName.endsWith(".cssmap") || pathName.startsWith("rpcPolicyManifest") || pathName.startsWith("soycReport")) { // skip these resources } else { publicSourcesSb.append(pathName + "\n"); } } } String[] cacheExtraFiles = getCacheExtraFiles(); for (int i = 0; i < cacheExtraFiles.length; i++) { staticResoucesSb.append(cacheExtraFiles[i]); staticResoucesSb.append("\n"); } } // build cache list StringBuilder sb = new StringBuilder(); sb.append("CACHE MANIFEST\n"); sb.append("# Unique id #" + (new Date()).getTime() + "." + Math.random() + "\n"); // we have to generate this unique id because the resources can change but // the hashed cache.html files can remain the same. sb.append("# Note: must change this every time for cache to invalidate\n"); sb.append("\n"); sb.append("CACHE:\n"); sb.append("# Static app files\n"); sb.append(staticResoucesSb.toString()); sb.append("\n# Generated app files\n"); sb.append(publicSourcesSb.toString()); sb.append("\n\n"); sb.append("# All other resources require the user to be online.\n"); sb.append("NETWORK:\n"); sb.append("*\n"); logger.log(TreeLogger.INFO, "Be sure your landing page's <html> tag declares a manifest:" + " <html manifest=" + context.getModuleFunctionName() + "/" + MANIFEST + "\">"); // Create the manifest as a new artifact and return it: return emitString(logger, sb.toString(), MANIFEST); }
From source file:com.google.code.gwt.appcache.linker.IFrameAppCacheLinker.java
License:Apache License
/** * Creates the cache-manifest resource specific for the landing page. *///from ww w . ja va 2 s . c om private Artifact<?> emitLandingPageCacheManifest(LinkerContext context, TreeLogger logger, ArtifactSet artifacts) throws UnableToCompleteException { // Create a list of cacheable resources: SortedSet<String> cachePaths = new TreeSet<String>(); SortedSet<String> networkPaths = new TreeSet<String>(); // Iterate over all emitted artifacts, and collect all // cacheable- and networked artifacts: for (Artifact artifact : artifacts) { // logger.log(TreeLogger.INFO, "Checking artifact " // + artifact.getClass().getName() + " created by " // + artifact.getLinker().getName() + ": " + artifact.toString() + "..."); if (artifact instanceof EmittedArtifact) { EmittedArtifact ea = (EmittedArtifact) artifact; if (ea.getLinker().equals(getClass())) { if (ea.getPartialPath().endsWith(".cache.html") || ea.getPartialPath().endsWith(".nocache.js")) { cachePaths.add(ea.getPartialPath()); } } else { cachePaths.add(ea.getPartialPath()); } } else if (artifact instanceof NetworkSectionArtifact) { NetworkSectionArtifact nsa = (NetworkSectionArtifact) artifact; networkPaths.add(nsa.getUrl()); } } String cacheEntries = concatPaths(cachePaths); String networkEntries = concatPaths(networkPaths); InputStream templateInput = getClass().getResourceAsStream(TEMPLATE_RESOURCE); StringBuilder tb = new StringBuilder(); if (templateInput != null) { logger.log(TreeLogger.INFO, "HTML 5 cache-manifest resource '" + TEMPLATE_RESOURCE + "' found - using that resource as template."); // Read template into a StringBuilder: BufferedReader reader = new BufferedReader(new InputStreamReader(templateInput)); try { String line = null; while ((line = reader.readLine()) != null) { if (!line.trim().startsWith("#")) { line = searchAndReplace(line, CACHE_ENTRIES, cacheEntries); line = searchAndReplace(line, NETWORK_ENTRIES, networkEntries); } tb.append(line).append('\n'); } reader.close(); } catch (IOException e) { logger.log(TreeLogger.ERROR, "Failed to read resource '" + TEMPLATE_RESOURCE + "'!", e); } } if (tb.length() == 0) { logger.log(TreeLogger.INFO, "HTML 5 cache-manifest resource '" + TEMPLATE_RESOURCE + "' not found (or empty or whatever) - generating default manifest."); tb.append("CACHE MANIFEST\n\nCACHE:\n").append(cacheEntries).append("\n\nNETWORK:\n") .append(networkEntries); } logger.log(TreeLogger.INFO, "Make sure you have the following" + " attribute added to your landing page's <html> tag: manifest=\"" + context.getModuleFunctionName() + "/" + MANIFEST + "\""); // Create the manifest as a new artifact and return it: return emitString(logger, tb.toString(), MANIFEST); }
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 . j a v a 2 s.co m @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.gwt.sample.core.linker.SimpleAppCacheLinker.java
License:Apache License
/** * Creates the cache-manifest resource specific for the landing page. * //from w ww . java2 s . c o m * @param context the linker environment * @param logger the tree logger to record to * @param artifacts {@code null} to generate an empty cache manifest */ private Artifact<?> emitLandingPageCacheManifest(LinkerContext context, TreeLogger logger, ArtifactSet artifacts) throws UnableToCompleteException { StringBuilder publicSourcesSb = new StringBuilder(); StringBuilder staticResoucesSb = new StringBuilder(); if (artifacts != null) { // Iterate over all emitted artifacts, and collect all cacheable artifacts for (@SuppressWarnings("rawtypes") Artifact artifact : artifacts) { if (artifact instanceof EmittedArtifact) { EmittedArtifact ea = (EmittedArtifact) artifact; String pathName = ea.getPartialPath(); if (pathName.endsWith("symbolMap") || pathName.endsWith(".xml.gz") || pathName.endsWith("rpc.log") || pathName.endsWith("gwt.rpc") || pathName.endsWith("manifest.txt") || pathName.startsWith("rpcPolicyManifest")) { // skip these resources } else { publicSourcesSb.append(pathName + "\n"); } } } String[] cacheExtraFiles = getCacheExtraFiles(); for (int i = 0; i < cacheExtraFiles.length; i++) { staticResoucesSb.append(cacheExtraFiles[i]); staticResoucesSb.append("\n"); } } // build cache list StringBuilder sb = new StringBuilder(); sb.append("CACHE MANIFEST\n"); sb.append("# Unique id #" + (new Date()).getTime() + "." + Math.random() + "\n"); // we have to generate this unique id because the resources can change but // the hashed cache.html files can remain the same. sb.append("# Note: must change this every time for cache to invalidate\n"); sb.append("\n"); sb.append("CACHE:\n"); sb.append("# Static app files\n"); sb.append(staticResoucesSb.toString()); sb.append("\n# Generated app files\n"); sb.append(publicSourcesSb.toString()); sb.append("\n\n"); sb.append("# All other resources require the user to be online.\n"); sb.append("NETWORK:\n"); sb.append("*\n"); logger.log(TreeLogger.INFO, "Be sure your landing page's <html> tag declares a manifest:" + " <html manifest=" + context.getModuleFunctionName() + "/" + MANIFEST + "\">"); // Create the manifest as a new artifact and return it: return emitString(logger, sb.toString(), MANIFEST); }
From source file:forplay.appcachelinker.AppCacheLinker.java
License:Apache License
/** * Creates the cache-manifest resource specific for the landing page. */// w w w .j a va 2s . c om private Artifact<?> emitLandingPageCacheManifest(LinkerContext context, TreeLogger logger, ArtifactSet artifacts, String[] staticFiles) throws UnableToCompleteException { // Create a string of cacheable resources StringBuilder publicSourcesSb = new StringBuilder(); StringBuilder publicStaticSourcesSb = new StringBuilder(); // Iterate over all emitted artifacts, and collect all cacheable artifacts for (@SuppressWarnings("rawtypes") Artifact artifact : artifacts) { if (artifact instanceof EmittedArtifact) { EmittedArtifact ea = (EmittedArtifact) artifact; String path = "/" + context.getModuleFunctionName() + "/" + ea.getPartialPath(); if (accept(path)) { publicSourcesSb.append(path + "\n"); } } } // Iterate over all static files if (staticFiles != null) { for (String staticFile : staticFiles) { if (accept(staticFile)) { publicStaticSourcesSb.append(staticFile + "\n"); } } } // build cache list StringBuilder sb = new StringBuilder(); sb.append("CACHE MANIFEST\n"); sb.append("# Unique id #" + (new Date()).getTime() + "." + Math.random() + "\n"); // we have to generate this unique id because the resources can change but // the hashed cache.html files can remain the same. sb.append("# Note: must change this every time for cache to invalidate\n"); sb.append("\n"); sb.append("CACHE:\n"); sb.append(publicSourcesSb.toString()); sb.append("# Static cached files\n"); sb.append(publicStaticSourcesSb.toString()); sb.append("\n\n"); sb.append("# All other resources require the user to be online.\n"); sb.append("NETWORK:\n"); sb.append("*\n"); logger.log(TreeLogger.DEBUG, "Make sure you have the following" + " attribute added to your landing page's <html> tag: <html manifest=\"" + context.getModuleFunctionName() + "/" + MANIFEST + "\">"); // Create the manifest as a new artifact and return it: return emitString(logger, sb.toString(), MANIFEST); }
From source file:geogebra.linker.SimpleAppCacheLinker.java
License:Apache License
/** * Creates the cache-manifest resource specific for the landing page. * /*w w w. j a v a2 s . c om*/ * @param context * the linker environment * @param logger * the tree logger to record to * @param artifacts * {@code null} to generate an empty cache manifest */ private Artifact<?> emitLandingPageCacheManifest(LinkerContext context, TreeLogger logger, ArtifactSet artifacts) throws UnableToCompleteException { StringBuilder publicSourcesSb = new StringBuilder(); StringBuilder staticResoucesSb = new StringBuilder(); if (artifacts != null) { // Iterate over all emitted artifacts, and collect all cacheable // artifacts for (@SuppressWarnings("rawtypes") Artifact artifact : artifacts) { if (artifact instanceof EmittedArtifact) { EmittedArtifact ea = (EmittedArtifact) artifact; String pathName = ea.getPartialPath(); if (pathName.endsWith("symbolMap") || pathName.endsWith(".xml.gz") || pathName.endsWith("rpc.log") || pathName.endsWith("gwt.rpc") || pathName.endsWith("manifest.txt") || pathName.startsWith("rpcPolicyManifest") || pathName.endsWith("cssmap") || pathName.endsWith("svnignore.txt") || pathName.endsWith("compilation-mappings.txt") || pathName.endsWith(".php") || pathName.endsWith("README") || pathName.endsWith("oauthWindow.html") || pathName.endsWith("windowslive.html") || pathName.endsWith("devmode.js") || pathName.startsWith("js/properties_")) { // skip these resources } else { publicSourcesSb.append(pathName + "\n"); } } } String[] cacheExtraFiles = getCacheExtraFiles(); for (int i = 0; i < cacheExtraFiles.length; i++) { staticResoucesSb.append(cacheExtraFiles[i]); staticResoucesSb.append("\n"); } } // build cache list StringBuilder sb = new StringBuilder(); sb.append("CACHE MANIFEST\n"); sb.append("# Unique id #" + (new Date()).getTime() + "." + Math.random() + "\n"); // we have to generate this unique id because the resources can change // but // the hashed cache.html files can remain the same. sb.append("# Note: must change this every time for cache to invalidate\n"); sb.append("\n"); sb.append("CACHE:\n"); sb.append("# Static app files\n"); sb.append(staticResoucesSb.toString()); sb.append("\n# Generated app files\n"); sb.append(publicSourcesSb.toString()); sb.append("\n\n"); sb.append("# All other resources require the user to be online.\n"); sb.append("NETWORK:\n"); sb.append("*\n"); logger.log(TreeLogger.INFO, "Make sure you have the following" + " attribute added to your landing page's <html> tag: <html manifest=\"" + context.getModuleFunctionName() + "/" + MANIFEST + "\">"); // Create the manifest as a new artifact and return it: return emitString(logger, sb.toString(), MANIFEST); }
From source file:gwt.ns.webworker.linker.WorkerModuleLinker.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 from template String bootstrap = generateSelectionScript(logger, context, artifacts); bootstrap = context.optimizeJavaScript(logger, bootstrap); out.print(bootstrap);//from w w w. j a v a2 s . c om out.newlineOpt(); // Emit the module's JS within a closure. out.print("(function () {"); out.newlineOpt(); out.print("var $gwt_version = \"" + About.getGwtVersionNum() + "\";"); out.newlineOpt(); /* Point $wnd and $doc to insideWorker global scope. Shouldn't be used, but there * in case preexisting code uses either as a generic global variable * normal access of $wnd and $doc attributes and methods will be broken, * per Worker spec */ out.print("var $self = self;"); out.newlineOpt(); out.print("var $wnd = self;"); out.newlineOpt(); out.print("var $doc = self;"); out.newlineOpt(); out.print("var $moduleName, $moduleBase;"); //needed if no stats/error handling? out.newlineOpt(); out.print("var $stats = null;"); out.newlineOpt(); // append module code // 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); // give a hint to reason for failure logPermutationProperties(logger, context.getProperties()); throw new UnableToCompleteException(); } CompilationResult result = results.iterator().next(); out.print("var $strongName = '" + result.getStrongName() + "';"); out.newlineOpt(); // get actual compiled javascript and output // only one fragment currently supported (no runAsync) String[] js = result.getJavaScript(); if (js.length != 1) { logger.log(TreeLogger.ERROR, "The module must not have multiple fragments when using the " + getDescription() + " Linker. Use of GWT.runAsync within Worker" + " code is the most likely cause of this error.", null); throw new UnableToCompleteException(); } out.print(js[0]); // 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(); // TODO: this naming scheme helps WorkerCompilationLinker, but users // compiling separate worker scripts may desire a strong file name return emitString(logger, out.toString(), context.getModuleName() + WORKER_EXTENSION); }