Example usage for com.google.gwt.core.ext.linker ArtifactSet find

List of usage examples for com.google.gwt.core.ext.linker ArtifactSet find

Introduction

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

Prototype

public <T extends Artifact<? super T>> SortedSet<T> find(Class<T> artifactType) 

Source Link

Document

Find all Artifacts assignable to some base type.

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   ww  w  . j  a  va 2  s . co  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.PermutationInfoLinker.java

License:Apache License

@Override
public ArtifactSet link(TreeLogger logger, LinkerContext context, ArtifactSet artifacts, boolean onePermutation)
        throws UnableToCompleteException {
    if (onePermutation) {
        ArtifactSet toReturn = new ArtifactSet(artifacts);
        ArtifactSet writableArtifacts = new ArtifactSet(artifacts);
        for (CompilationResult compilation : artifacts.find(CompilationResult.class)) {
            // pass a writable set so that other stages can use this set for
            // temporary storage
            toReturn.addAll(doEmitCompilation(logger, context, compilation, writableArtifacts));
        }//from   ww  w. j  a v a 2  s . c  o m
        return toReturn;
    } else {
        permutationsUtil.setupPermutationsMap(artifacts);
        ArtifactSet toReturn = new ArtifactSet(artifacts);
        maybeOutputPropertyMap(logger, context, toReturn);
        return toReturn;
    }
}

From source file:com.ait.toolkit.flash.linker.InjectionUtil.java

License:Open Source License

/**
 * Installs stylesheets and scripts./*from w  w w  .  j  av  a2  s  .  c om*/
 */
public static StringBuffer injectResources(StringBuffer selectionScript, ArtifactSet artifacts) {
    // Add external dependencies
    int startPos = selectionScript.indexOf("// __MODULE_STYLES_END__");
    if (startPos != -1) {
        for (StylesheetReference resource : artifacts.find(StylesheetReference.class)) {
            String text = generateStylesheetInjector(resource.getSrc());
            selectionScript.insert(startPos, text);
            startPos += text.length();
        }
    }

    startPos = selectionScript.indexOf("// __MODULE_SCRIPTS_END__");
    if (startPos != -1) {
        for (ScriptReference resource : artifacts.find(ScriptReference.class)) {
            String text = generateScriptInjector(resource.getSrc());
            selectionScript.insert(startPos, text);
            startPos += text.length();
        }
    }
    return selectionScript;
}

From source file:com.ait.toolkit.flash.linker.InjectionUtil.java

License:Open Source License

/**
 * Installs stylesheets using the installOneStylesheet method, which is
 * assumed to be defined on the page. The installOneStylesheet() helper
 * function is invoked as follows:/*from  w  ww  .  j a  va  2s.c  om*/
 * 
 * <pre>
 * installOneStylesheet(URL);
 * </pre>
 */
public static StringBuffer injectStylesheets(StringBuffer selectionScript, ArtifactSet artifacts) {
    int startPos = selectionScript.indexOf("// __MODULE_STYLES__");
    if (startPos != -1) {
        for (StylesheetReference resource : artifacts.find(StylesheetReference.class)) {
            String text = "installOneStylesheet('" + resource.getSrc() + "');\n";
            selectionScript.insert(startPos, text);
            startPos += text.length();
        }
    }
    return selectionScript;
}

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.bcdlog.SimpleAppCacheLinker.java

License:Apache License

public ArtifactSet link(TreeLogger logger, LinkerContext context, ArtifactSet artifacts, boolean onePermutation)
        throws UnableToCompleteException {

    ArtifactSet toReturn = new ArtifactSet(artifacts);

    if (onePermutation) {
        return toReturn;
    }//w  w w . j a va2 s .  co  m

    if (toReturn.find(SelectionInformation.class).isEmpty()) {
        logger.log(TreeLogger.INFO, "DevMode warning: Clobbering " + MANIFEST + " to allow debugging. "
                + "Recompile before deploying your app!");
        artifacts = null;
    }

    // Create the general cache-manifest resource for the landing page:
    toReturn.add(emitLandingPageCacheManifest(context, logger, artifacts));
    return toReturn;
}

From source file:com.bedatadriven.rebar.appcache.linker.AppCacheIFrameLinker.java

License:Apache License

@Override
public ArtifactSet link(TreeLogger logger, LinkerContext linkerContext, ArtifactSet artifacts)
        throws UnableToCompleteException {

    Collection<CompilationResult> compilationResults = artifacts.find(CompilationResult.class);

    hostedMode = compilationResults.size() == 0;

    if (hostedMode) {
        // if we are being run in hosted mode, revert entirely to the IFrameLinker

        return super.link(logger, linkerContext, artifacts);

    } else {/* www  . jav  a2  s.c  om*/

        ArtifactSet writableArtifacts = new ArtifactSet(artifacts);
        ArtifactSet toReturn = new ArtifactSet(artifacts);

        for (CompilationResult compilation : compilationResults) {
            PermutationContext context = new PermutationContext(linkerContext, writableArtifacts, compilation);

            Collection<Artifact<?>> compilationArtifacts = doEmitCompilation(logger, linkerContext, compilation,
                    writableArtifacts);

            context.addToCache(writableArtifacts.find(EmittedArtifact.class));
            context.addToCache(emittedArtifacts(compilationArtifacts));

            toReturn.addAll(compilationArtifacts);
            toReturn.add(doEmitBootstrapScript(logger, context, writableArtifacts));
            toReturn.add(doEmitManifest(logger, context, new Html5ManifestWriter()));
        }

        toReturn.add(emitPermutationMap(logger, linkerContext, writableArtifacts));

        return toReturn;
    }
}

From source file:com.bedatadriven.rebar.appcache.linker.AppCacheIFrameLinker.java

License:Apache License

/**
 * The permutation map is used on the server side to serve the appropriate permutation
 *//*www .  ja  v a2  s  .co m*/
protected EmittedArtifact emitPermutationMap(TreeLogger logger, LinkerContext context, ArtifactSet artifacts)
        throws UnableToCompleteException {

    try {

        // Emit the selection script.
        StringWriter json = new StringWriter();
        JsonWriter writer = new JsonWriter(json);
        writer.setIndent("  ");

        SortedSet<CompilationResult> compilationResults = artifacts.find(CompilationResult.class);
        writer.beginArray();

        for (CompilationResult result : compilationResults) {
            for (SortedMap<SelectionProperty, String> map : result.getPropertyMap()) {
                writer.beginObject();
                writer.name("permutation").value(result.getStrongName());
                writer.name("properties");
                writer.beginObject();

                for (Map.Entry<SelectionProperty, String> property : map.entrySet()) {
                    writer.name(property.getKey().getName());
                    writer.value(property.getValue());
                }
                writer.endObject();
                writer.endObject();
            }
        }
        writer.endArray();
        return emitString(logger, json.toString(), "permutations");

    } catch (IOException e) {
        logger.log(TreeLogger.Type.ERROR, "Error writing permutation map", e);
        throw new UnableToCompleteException();
    }
}

From source file:com.chrome.gwt.linker.ExtensionLinker.java

License:Apache License

private static CompilationResult findCompilation(TreeLogger logger, ArtifactSet artifacts)
        throws UnableToCompleteException {
    final SortedSet<CompilationResult> compilations = artifacts.find(CompilationResult.class);
    if (compilations.size() > 1) {
        logger.log(TreeLogger.ERROR,//  w  ww  .j  av a 2s  .  c o  m
                "One permutation per module, please. Seriously, you changed something you weren't supposed to.");
        throw new UnableToCompleteException();
    }
    return compilations.first();
}

From source file:com.chrome.gwt.linker.ExtensionLinker.java

License:Apache License

private static ExtensionArtifact findExtensionArtifact(TreeLogger logger, ArtifactSet artifacts)
        throws UnableToCompleteException {
    final SortedSet<ExtensionArtifact> extensions = artifacts.find(ExtensionArtifact.class);
    int size = extensions.size();
    if (size > 1) {
        // TODO(knorton): Improve error message.
        logger.log(TreeLogger.ERROR, "One extension per module, please.");
        throw new UnableToCompleteException();
    }/*ww  w  .j  a  va 2  s  .c  o  m*/

    return extensions.first();
}