List of usage examples for com.google.gwt.core.ext.linker EmittedArtifact getContents
public abstract InputStream getContents(TreeLogger logger) throws UnableToCompleteException;
From source file:cc.alcina.framework.gwt.appcache.linker.AppCacheManifestLinker.java
License:Apache License
/** * Generate a string containing object literals for each manifest entry. *//*from w w w .j a 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:cc.alcina.framework.gwt.appcache.linker.AppCacheManifestLinker.java
License:Apache License
/** * Load the contents of the manifest template from a file named * {@value #APPCACHE_MANIFEST} in the root of the public path. Failing that, * use the built-in template./* w w w.j a v a2s . com*/ */ private StringBuffer readManifestTemplate(TreeLogger logger, EmittedArtifact userManifest) throws UnableToCompleteException { logger = logger.branch(TreeLogger.DEBUG, "Reading manifest template", null); InputStream in; // See if we have a user-provided manifest to work with if (userManifest != null) { logger.log(TreeLogger.DEBUG, "Reading user-provided manifest", null); in = userManifest.getContents(logger); if (in == null) { logger.log(TreeLogger.ERROR, "Unable to read contents of user manifest", null); throw new UnableToCompleteException(); } } else { // Fall back to the built-in manifest String packagePath = getClass().getPackage().getName().replace('.', '/'); String resourceName = packagePath + "/" + APPCACHE_MANIFEST; in = getClass().getClassLoader().getResourceAsStream(resourceName); if (in == null) { logger.log(TreeLogger.ERROR, "Could not load built-in manifest from " + resourceName, null); throw new UnableToCompleteException(); } } StringBuffer out = new StringBuffer(); BufferedReader reader = new BufferedReader(new InputStreamReader(in)); try { for (String line = reader.readLine(); line != null; line = reader.readLine()) { out.append(line).append("\n"); } } catch (IOException e) { logger.log(TreeLogger.ERROR, "Unable to read manifest template", e); throw new UnableToCompleteException(); } return out; }
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 ww w.j ava 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.smartgwt.linker.SmartGwtLinkerUtils.java
License:Open Source License
/** * Returns the contents of the artifact as a String. * @param emittedArtifact the artifact//from w w w . j av a2 s. c o m * @param logger the logger * @return contents of the artifact * @throws UnableToCompleteException */ static String getContents(EmittedArtifact emittedArtifact, TreeLogger logger) throws UnableToCompleteException { InputStream in = emittedArtifact.getContents(logger); BufferedInputStream bis = new BufferedInputStream(in); ByteArrayOutputStream buf = new ByteArrayOutputStream(); try { int result = bis.read(); while (result != -1) { byte b = (byte) result; buf.write(b); result = bis.read(); } } catch (IOException e) { logger.log(TreeLogger.ERROR, "Unable to read resource load_skin.js", e); throw new UnableToCompleteException(); } return buf.toString(); }
From source file:com.vaadin.sass.linker.SassLinker.java
License:Apache License
@Override public ArtifactSet link(TreeLogger logger, LinkerContext context, ArtifactSet artifacts, boolean onePermutation) throws UnableToCompleteException { if (!onePermutation) { // The artifact to return ArtifactSet toReturn = new ArtifactSet(artifacts); // The temporary scss files provided from the artefacts List<FileInfo> scssFiles = new ArrayList<FileInfo>(); // The public files are provided as inputstream, but the compiler // needs real files, as they can contain references to other // files. They will be stored here, with their relative paths intact String tempFolderName = new Date().getTime() + File.separator; File tempFolder = createTempDir(tempFolderName); // Can't search here specifically for public resources, as the type // is different during compilation. This means we have to loop // through all the artifacts for (EmittedArtifact resource : artifacts.find(EmittedArtifact.class)) { // Create the temporary files. String partialPath = resource.getPartialPath(); if (partialPath.endsWith(".scss")) { // In my opinion, the SCSS file does not need to be // output to the web content folder, as they can't // be used there toReturn.remove(resource); String fileName = partialPath; File path = tempFolder; int separatorIndex = fileName.lastIndexOf(File.separator); if (-1 != separatorIndex) { fileName = fileName.substring(separatorIndex + 1); String filePath = partialPath.substring(0, separatorIndex); path = createTempDir(tempFolderName + filePath); }//from ww w . ja v a 2s. c o m File tempfile = new File(path, fileName); try { boolean fileCreated = tempfile.createNewFile(); if (fileCreated) { // write the received inputstream to the temp file writeFromInputStream(resource.getContents(logger), tempfile); // Store the file info for the compilation scssFiles.add(new FileInfo(tempfile, partialPath)); } else { logger.log(TreeLogger.WARN, "Duplicate file " + tempfile.getPath()); } } catch (IOException e) { logger.log(TreeLogger.ERROR, "Could not write temporary file " + fileName, e); } } } // Compile the files and store them in the artifact logger.log(TreeLogger.INFO, "Processing " + scssFiles.size() + " Sass file(s)"); for (FileInfo fileInfo : scssFiles) { logger.log(TreeLogger.INFO, " " + fileInfo.originalScssPath + " -> " + fileInfo.getOriginalCssPath()); try { ScssStylesheet scss = ScssStylesheet.get(fileInfo.getAbsolutePath()); if (!fileInfo.isMixin()) { scss.compile(); InputStream is = new ByteArrayInputStream(scss.printState().getBytes()); toReturn.add(this.emitInputStream(logger, is, fileInfo.getOriginalCssPath())); } fileInfo.getFile().delete(); } catch (CSSException e) { logger.log(TreeLogger.ERROR, "SCSS compilation failed for " + fileInfo.getOriginalCssPath(), e); } catch (IOException e) { logger.log(TreeLogger.ERROR, "Could not write CSS file for " + fileInfo.getOriginalCssPath(), e); } catch (Exception e) { logger.log(TreeLogger.ERROR, "SCSS compilation failed for " + fileInfo.getOriginalCssPath(), e); } } return toReturn; } return artifacts; }
From source file:org.cesiumjs.linker.CesiumLinkerUtils.java
License:Apache License
static String getContents(EmittedArtifact emittedArtifact, TreeLogger logger) throws UnableToCompleteException { InputStream in = emittedArtifact.getContents(logger); BufferedInputStream bis = new BufferedInputStream(in); ByteArrayOutputStream buf = new ByteArrayOutputStream(); try {//from w ww. j a v a 2 s . co m // Fix for SmartGWT. Thanks for Mark Erikson (https://groups.google.com/forum/#!msg/cesium-dev/ZfyW0CNRsSU/lP6KTaUpEQAJ) buf.write("if (window.buildInDataView === undefined) {window.buildInDataView = window.DataView;}\n" .getBytes()); int result = bis.read(); while (result != -1) { byte b = (byte) result; buf.write(b); result = bis.read(); } } catch (IOException e) { logger.log(TreeLogger.ERROR, "Unable to read resource", e); throw new UnableToCompleteException(); } return buf.toString(); }
From source file:org.cruxframework.crux.core.rebind.screen.linker.ScreenLinker.java
License:Apache License
@Override public ArtifactSet link(TreeLogger logger, LinkerContext context, ArtifactSet artifacts, boolean onePermutation) throws UnableToCompleteException { if (!onePermutation) { SortedSet<EmittedArtifact> resources = artifacts.find(EmittedArtifact.class); for (EmittedArtifact resource : resources) { if (resource.getVisibility().equals(Visibility.Private) && resource.getPartialPath().endsWith(".crux.xml")) { try { String resourcePath = resource.getPartialPath().replace(".crux.xml", ".html"); String content = StreamUtils.readAsUTF8(resource.getContents(logger)); EmittedArtifact manifest = emitString(logger, content, "../" + resourcePath); artifacts.add(manifest); } catch (Exception e) { logger.log(Type.ERROR, "Error generating HTML for crux screen [" + resource.getPartialPath() + "]", e); throw new UnableToCompleteException(); }/* ww w. j a va2s. c o m*/ } } } return super.link(logger, context, artifacts, onePermutation); }
From source file:org.openlayers.linker.OpenLayersLinkerUtils.java
License:Apache License
static String getContents(EmittedArtifact emittedArtifact, TreeLogger logger) throws UnableToCompleteException { InputStream in = emittedArtifact.getContents(logger); BufferedInputStream bis = new BufferedInputStream(in); ByteArrayOutputStream buf = new ByteArrayOutputStream(); try {/*from w w w . ja va 2 s . c o m*/ int result = bis.read(); while (result != -1) { byte b = (byte) result; buf.write(b); result = bis.read(); } } catch (IOException e) { logger.log(TreeLogger.ERROR, "Unable to read resource", e); throw new UnableToCompleteException(); } return buf.toString(); }