Example usage for com.google.gwt.core.ext.linker EmittedArtifact getPartialPath

List of usage examples for com.google.gwt.core.ext.linker EmittedArtifact getPartialPath

Introduction

In this page you can find the example usage for com.google.gwt.core.ext.linker EmittedArtifact getPartialPath.

Prototype

public final String getPartialPath() 

Source Link

Document

Returns the partial path within the output directory of the EmittedArtifact.

Usage

From source file:cc.alcina.framework.gwt.appcache.linker.AppCacheManifestLinker.java

License:Apache License

@Override
public ArtifactSet link(TreeLogger logger, LinkerContext context, ArtifactSet artifacts)
        throws UnableToCompleteException {
    ArtifactSet toReturn = new ArtifactSet(artifacts);
    SortedSet<EmittedArtifact> emitted = toReturn.find(EmittedArtifact.class);
    for (EmittedArtifact artifact : emitted) {
        if (artifact.getPartialPath().equals(APPCACHE_MANIFEST)) {
            userManifest = artifact;//from   www .  j  ava2s .  c  o m
            toReturn.remove(artifact);
            emitted.remove(artifact);
            break;
        }
    }
    toReturn.add(emitManifest(logger, context, userManifest, emitted));
    return toReturn;
}

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  ava  2 s .  co  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.bcdlog.SimpleAppCacheLinker.java

License:Apache License

/**
 * Creates the cache-manifest resource specific for the landing page.
 * /*from   www . j  a  v a 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.bedatadriven.rebar.appcache.linker.AppCacheIFrameLinker.java

License:Apache License

/**
 * Generate a string containing object literals for each manifest entry.
 */// www  .ja  v  a  2 s  .  c o  m
private void appendEntries(TreeLogger logger, PermutationContext context, ManifestWriter writer)
        throws UnableToCompleteException {

    logger = logger.branch(TreeLogger.DEBUG, "Generating manifest entries", null);

    // add the bootstrap script (provided by the server)
    writer.appendEntry(logger, context.getModuleName() + ".nocache.js");

    for (EmittedArtifact artifact : context.getToCache()) {
        if (artifact.getVisibility() == Visibility.Public) {

            logger.log(TreeLogger.DEBUG, "adding to manifest:" + artifact.getPartialPath() + " of class "
                    + artifact.getClass().getName() + " and visibility " + artifact.getVisibility());

            if (artifact.getPartialPath().endsWith(".gwt.rpc")) {
                // only used by the server
                continue;
            }

            String path = artifact.getPartialPath();

            // certain paths on the Windows platform (notably deferredjs stuff)
            // show up with backslahes, which throws an illegal escape sequence
            // error when the json is parsed.
            path = path.replace('\\', '/');

            logger.log(TreeLogger.DEBUG, "adding: " + path);
            writer.appendEntry(logger, path);
        } else {
            logger.log(TreeLogger.DEBUG,
                    "excluding " + artifact.getVisibility() + ": " + artifact.getPartialPath());
        }
    }
}

From source file:com.data2semantics.yasgui.mgwtlinker.linker.PermutationMapLinker.java

License:Open Source License

protected Set<String> getArtifactsForCompilation(TreeLogger logger, LinkerContext context,
        ArtifactSet artifacts) {//from   w  ww  . ja v a 2 s  .c o m
    Set<String> artifactNames = new HashSet<String>();
    for (EmittedArtifact artifact : artifacts.find(EmittedArtifact.class)) {
        String pathName = artifact.getPartialPath();
        if (shouldArtifactBeInManifest(pathName)) {
            artifactNames.add(pathName);
        }
    }
    return artifactNames;

}

From source file:com.goodow.web.dev.rebind.BaseAppCacheLinker.java

License:Apache License

/**
 * Creates the cache-manifest resource specific for the landing page.
 * /* w  ww. j  av  a2 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(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.  j a 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

/**
 * Emits the wrapper HTML resource which loads the permutation javascript in
 * an external JS resource.//from   ww  w .j  a va2  s .  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.gwt.sample.core.linker.SimpleAppCacheLinker.java

License:Apache License

/**
 * Creates the cache-manifest resource specific for the landing page.
 * /*from  w ww.ja  v  a 2  s.com*/
 * @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.google.mobile.trippy.web.rebind.RecursiveArtifactLinker.java

License:Apache License

@Override
public ArtifactSet link(TreeLogger logger, LinkerContext context, ArtifactSet artifacts)
        throws UnableToCompleteException {
    ArtifactSet toReturn = new ArtifactSet(artifacts);
    ArtifactSet toReturnAfterRemove = new ArtifactSet(artifacts);
    for (EmittedArtifact artifact : toReturn.find(EmittedArtifact.class)) {
        String partialPath = artifact.getPartialPath();
        if (partialPath.startsWith(TRIPPY_PREFIX) || partialPath.startsWith(WEB_INF_PREFIX)) {
            toReturnAfterRemove.remove(artifact);
        }//w  w  w.  ja v  a2  s  .  c o m
    }
    return toReturnAfterRemove;
}