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

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

Introduction

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

Prototype

public Visibility getVisibility() 

Source Link

Usage

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 ww.  j  av  a 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.bedatadriven.rebar.appcache.linker.AppCacheIFrameLinker.java

License:Apache License

/**
 * Generate a string containing object literals for each manifest entry.
 *//*from   w w w .j  a va 2 s.  co  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.risevision.viewer.linker.OfflineLinker.java

License:Open Source License

@Override
public ArtifactSet link(TreeLogger logger, LinkerContext context, ArtifactSet artifacts)
        throws UnableToCompleteException {
    ArtifactSet artifactSet = new ArtifactSet(artifacts);
    StringBuilder buf = new StringBuilder();
    buf.append("CACHE MANIFEST\n");
    buf.append("#").append(System.currentTimeMillis()).append("\n");
    buf.append("\n");
    buf.append("CACHE:\n");
    buf.append("Viewer.html\n");
    //      buf.append("scripts/jquery-1.7.1.min.js\n");
    buf.append("scripts/jquery-1.10.2.min.js\n");
    buf.append("scripts/jquery.timers-1.2.js\n");
    buf.append("scripts/viewerScripts.js\n");
    buf.append("scripts/presentationScripts.js\n");
    buf.append("scripts/videoScripts.js\n");
    buf.append("scripts/imageScripts.js\n");
    buf.append("scripts/ext-logger.js\n");
    buf.append("images/ajax-loader-circle-notext.gif\n");
    buf.append("images/eye-icon.png\n");
    buf.append("images/icons-error.png\n");
    buf.append("style/viewer.css\n");
    buf.append("slicebox/js/jquery.easing.1.3.js\n");
    buf.append("slicebox/js/jquery.slicebox.js\n");
    //      buf.append("mediaplayer/BrowserDetect.js\n");
    buf.append("jwplayer/jwplayer.js\n");
    buf.append("jwplayer/jwplayer.html5.js\n");
    buf.append("jwplayer/jwplayer.flash.swf\n");
    buf.append("jwplayer/skins/six.xml\n");
    //      buf.append("videojs/video.min.js\n");
    //      buf.append("videojs/video-js.css\n");
    //      buf.append("videojs/video-js.png\n");
    //      buf.append("videojs/video-js.swf\n");

    buf.append("viewer/viewer.nocache.js\n");
    for (EmittedArtifact artifact : artifacts.find(EmittedArtifact.class)) {
        if (artifact.getVisibility().compareTo(Visibility.Private) != 0
                && !artifact.getPartialPath().contains(".symbolMap")) {
            buf.append("viewer/").append(artifact.getPartialPath()).append("\n");
        }//from w  w w  .j  av  a 2s  .  c  om
    }
    buf.append("\n");
    buf.append("NETWORK:\n");
    buf.append("*\n");

    EmittedArtifact artifact = emitString(logger, buf.toString(), "offline.manifest"); //my manifest file name
    artifactSet.add(artifact);
    return artifactSet;
}

From source file:org.cruxframework.crux.core.rebind.offline.AppCacheLinker.java

License:Apache License

private static void aggroupPermutationArtifacts(ArtifactSet artifacts) {
    String userAgent = getUserAgent(artifacts);
    String deviceFeatures = getDeviceFeatures(artifacts);

    SortedSet<String> hashSet = new TreeSet<String>();
    for (EmittedArtifact emitted : artifacts.find(EmittedArtifact.class)) {
        if (emitted.getVisibility() == Visibility.Private) {
            continue;
        }/*  w  w w .  j  a  va  2 s  . co  m*/
        String pathName = emitted.getPartialPath();
        if (acceptCachedResource(pathName)) {
            hashSet.add(pathName);
            allArtifacts.add(pathName);
        }
    }

    ArtifactsGroup group = new ArtifactsGroup(userAgent, deviceFeatures);

    if (!artifactsByGroup.containsKey(group)) {
        artifactsByGroup.put(group, new TreeSet<String>());
    }

    artifactsByGroup.get(group).addAll(hashSet);
}

From source file:org.cruxframework.crux.core.rebind.offline.AppCacheLinker.java

License:Apache License

/**************************************************
 * manifest file manipulation methods/*ww  w .  ja v a2  s . co m*/
 **************************************************/

private void emitPermutationsAppCache(TreeLogger logger, LinkerContext context, ArtifactSet artifacts,
        String startScreenId, OfflineScreen offlineScreen) throws UnableToCompleteException {
    for (EmittedArtifact emitted : artifacts.find(EmittedArtifact.class)) {
        if (emitted.getVisibility() == Visibility.Private) {
            continue;
        }
        String pathName = emitted.getPartialPath();
        if (acceptCachedResource(pathName)) {
            if (!allArtifacts.contains(pathName)) {
                // common stuff like clear.cache.gif, *.nocache.js, etc
                cachedArtifacts.add(pathName);
            }
        }
    }

    Set<ArtifactsGroup> keySet = artifactsByGroup.keySet();
    for (ArtifactsGroup group : keySet) {
        Set<String> set = artifactsByGroup.get(group);
        set.addAll(cachedArtifacts);
        artifacts.add(
                createCacheManifest(context, logger, set, group.getGroupId(), startScreenId, offlineScreen));
        artifacts.add(createCacheManifestLoader(context, logger, group.getGroupId(), startScreenId));
    }
}

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();
                }/*  w w  w  . j a  va 2  s  . c o  m*/
            }
        }
    }

    return super.link(logger, context, artifacts, onePermutation);
}

From source file:org.gwtbootstrap3.extras.cachemanifest.Offline.java

License:Apache License

private boolean skipArtifact(final EmittedArtifact emitted) {

    if (emitted.getVisibility().matches(Visibility.Private))
        return true;

    final String pathName = emitted.getPartialPath();

    if (pathName.endsWith("symbolMap"))
        return true;
    if (pathName.endsWith(".xml.gz"))
        return true;
    if (pathName.endsWith("rpc.log"))
        return true;
    if (pathName.endsWith("gwt.rpc"))
        return true;
    if (pathName.endsWith("manifest.txt"))
        return true;
    if (pathName.startsWith("rpcPolicyManifest"))
        return true;
    if (pathName.startsWith("soycReport"))
        return true;
    if (pathName.endsWith(".cssmap"))
        return true;

    return false;
}

From source file:org.sigmah.linker.ManifestGenerationLinker.java

License:Open Source License

@Override
public ArtifactSet link(TreeLogger logger, LinkerContext context, ArtifactSet artifacts)
        throws UnableToCompleteException {
    final ArtifactSet artifactSet = new ArtifactSet(artifacts);

    final SortedSet<EmittedArtifact> emittedArtifacts = artifacts.find(EmittedArtifact.class);
    final SortedSet<CompilationResult> compilationResults = artifacts.find(CompilationResult.class);

    final SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
    final HashMap<Manifest, StringBuilder> manifests = new HashMap<>();

    final Map<String, Manifest> permutationMap = new HashMap<>();
    for (final CompilationResult compilationResult : compilationResults) {
        final String permutationName = compilationResult.getStrongName();

        for (final SortedMap<SelectionProperty, String> map : compilationResult.getPropertyMap()) {
            String userAgent = null;
            String locale = null;

            for (Map.Entry<SelectionProperty, String> entry : map.entrySet()) {
                if (entry.getKey().getName().equals("user.agent")) {
                    userAgent = entry.getValue();
                }/*w  w  w. j  a  v a 2s .c  om*/
                if (entry.getKey().getName().equals("locale")) {
                    locale = entry.getValue();
                }
            }

            final Manifest manifest = new Manifest(userAgent, locale);
            System.out.println("      Permutation '" + permutationName + "' : " + manifest);

            permutationMap.put(permutationName, manifest);
            addManifest(manifests, manifest, dateFormat);
        }
    }

    if (permutationMap.isEmpty()) {
        addManifest(manifests, new Manifest(), dateFormat);
    }

    appendToAll(manifests, MODULE_NAME + ".nocache.js\n");
    appendToAll(manifests, MODULE_NAME + ".extra.nocache.js\n");

    for (EmittedArtifact artifact : emittedArtifacts) {
        if (EmittedArtifact.Visibility.Public.matches(artifact.getVisibility())) {
            final String partialPath = artifact.getPartialPath();
            Manifest manifest = null;
            for (Map.Entry<String, Manifest> entry : permutationMap.entrySet()) {
                if (partialPath.contains(entry.getKey())) {
                    manifest = entry.getValue();
                    break;
                }
            }

            final StringBuilder manifestBuilder = manifests.get(manifest);
            if (manifestBuilder != null) {
                manifestBuilder.append(artifact.getPartialPath()).append("\n");
            } else if (!partialPath.startsWith("manuals/")) {
                appendToAll(manifests, artifact.getPartialPath()).appendToAll(manifests, "\n");
            }
        }
    }

    // Generating offline fallback sources
    appendToAll(manifests, "FALLBACK:\nonline.nocache.json offline.nocache.json\n");
    artifactSet.add(emitString(logger, "{\"online\": false}", "offline.nocache.json"));
    artifactSet.add(emitString(logger, "{\"online\": true}", "online.nocache.json"));

    appendToAll(manifests, "is_online.nocache.js is_offline.nocache.js\n");
    artifactSet.add(emitString(logger, "window.online = false;", "is_offline.nocache.js"));
    artifactSet.add(emitString(logger, "window.online = true;", "is_online.nocache.js"));

    appendToAll(manifests, "export export_offline.html\n");
    artifactSet.add(emitString(logger,
            "<html><header><title>Sigmah</title></header><body>Export functionality is only available when online.</body></html>",
            "export_offline.html"));

    if (PREFER_ONLINE) {
        appendToAll(manifests, "SETTINGS:\nprefer-online\n");
    }

    appendToAll(manifests, "NETWORK:\n*");

    for (Map.Entry<Manifest, StringBuilder> entry : manifests.entrySet()) {
        artifactSet.add(emitString(logger, entry.getValue().toString(), entry.getKey().toFileName()));
    }
    return artifactSet;
}