Example usage for com.google.gwt.core.ext.linker CompilationResult getStrongName

List of usage examples for com.google.gwt.core.ext.linker CompilationResult getStrongName

Introduction

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

Prototype

public abstract String getStrongName();

Source Link

Document

Return a string that uniquely identifies this compilation result.

Usage

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

License:Apache License

protected Collection<Artifact<?>> doEmitCompilation(TreeLogger logger, LinkerContext context,
        CompilationResult result, ArtifactSet artifacts) throws UnableToCompleteException {
    Collection<Artifact<?>> toReturn = new ArrayList<Artifact<?>>();
    toReturn.addAll(emitSelectionInformation(result.getStrongName(), result));
    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
 */// w ww  .  ja  va 2 s .c om
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.didactilab.gwt.phprpc.linker.PhpClientOracleLinker.java

License:Apache License

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

    if (onePermutation) {
        artifacts = new ArtifactSet(artifacts);

        Map<String, List<String>> allSerializableFields = new HashMap<String, List<String>>();

        for (RpcDataArtifact data : artifacts.find(RpcDataArtifact.class)) {
            allSerializableFields.putAll(data.getOperableFields());
        }//from   ww  w .  ja va  2s. c  o  m

        for (CompilationResult result : artifacts.find(CompilationResult.class)) {
            PhpWebClientOracleBuilder builder = new PhpWebClientOracleBuilder();

            for (Map.Entry<String, List<String>> entry : allSerializableFields.entrySet()) {
                builder.setSerializableFields(entry.getKey(), entry.getValue());
            }

            for (SymbolData symbolData : result.getSymbolMap()) {

                String castableTypeMapString = (symbolData.getCastableTypeMap() == null) ? null
                        : symbolData.getCastableTypeMap().toJs();

                builder.add(symbolData.getSymbolName(), symbolData.getJsniIdent(), symbolData.getClassName(),
                        symbolData.getMemberName(), symbolData.getQueryId(),
                        new CastableTypeDataImpl(castableTypeMapString));
            }

            ByteArrayOutputStream out = new ByteArrayOutputStream();
            try {
                builder.store(out);
            } catch (IOException e) {
                // Should generally not happen
                logger.log(TreeLogger.ERROR, "Unable to store deRPC data", e);
                throw new UnableToCompleteException();
            }

            SyntheticArtifact a = emitBytes(logger, out.toByteArray(), result.getStrongName() + SUFFIX);
            artifacts.add(a);
        }
    }
    return artifacts;
}

From source file:com.emitrom.ti4j.mobile.hybrid.linker.TiMobileHybridLinker.java

License:Apache License

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

    ArtifactSet toReturn = new ArtifactSet(artifacts);
    DefaultTextOutput out = new DefaultTextOutput(true);
    long compilationTime = System.currentTimeMillis();
    out.print("(function(){");
    out.newline();/*from  www .  j  av a 2s.  co  m*/

    // get compilation result
    Set<CompilationResult> results = artifacts.find(CompilationResult.class);
    if (results.size() == 0) {
        logger.log(TreeLogger.WARN, "Requested 0 permutations");
        return toReturn;
    }

    CompilationResult result = results.iterator().next();

    // get the generated javascript
    String[] javaScript = result.getJavaScript();
    out.print("var $wnd;var $doc;");
    out.print("var $moduleName, $moduleBase;");
    out.newline();
    out.print("if(typeof(window) != 'undefined'){ $wnd = window;  $doc = $wnd.document; }");
    out.newline();
    out.print("var $gwt_version = \"" + About.getGwtVersionNum() + "\";");
    out.newlineOpt();
    out.print(javaScript[0]);
    out.newline();
    out.print("var $stats = function(){};");
    out.newline();
    out.print("var $sessionId = function(){};");
    out.newline();
    out.print("var navigator = {};");
    out.newline();
    out.print("navigator.userAgent = 'timobile';");
    out.newline();
    out.print("$strongName = '" + result.getStrongName() + "';");
    out.newline();
    out.print("$ti4jCompilationDate = " + compilationTime + ";");
    out.newline();
    out.print("gwtOnLoad(null,'" + context.getModuleName() + "',null);");
    out.newline();
    out.print("})();");
    out.newline();

    toReturn.add(emitString(logger, out.toString(), context.getModuleName() + ".js"));
    // toReturn.add(emitString(logger, Long.toString(compilationTime),
    // APP_COMPILATION_FILE_NAME));

    return toReturn;
}

From source file:com.envjs.gwt.linker.ServerSingleScriptLinker.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.
    // this for 'real browsers' to load the script
    // we don't need this.
    /*/* w  w w  .  j a va 2s  . com*/
    String bootstrap = generateSelectionScript(logger, context, artifacts);
    bootstrap = context.optimizeJavaScript(logger, bootstrap);
    out.print(bootstrap);
    out.newlineOpt();
    */

    // we need a ref to the top level window
    //  it is referenced in the closure below
    out.print("var $_window = this;");
    out.newlineOpt();

    // this is a hack to make backwards compatible
    out.print("var __defineParser__ = function(){};");
    out.newlineOpt();

    // Emit the module's JS a closure.
    out.newlineOpt();
    out.print("(function () {");
    out.newlineOpt();
    out.print("var $gwt_version = \"" + About.getGwtVersionNum() + "\";");
    out.newlineOpt();
    out.print("var $wnd = $_window;");
    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) {$wnd.__gwtStatsEvent(a)} : null;");
    out.newlineOpt();

    // 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);
        throw new UnableToCompleteException();
    }
    CompilationResult result = results.iterator().next();

    out.print("var $strongName = '" + result.getStrongName() + "';");
    out.newlineOpt();

    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]);

    // Generate the call to tell the bootstrap code that we're ready to go.
    out.newlineOpt();

    // the original code setup an "onScriptLoad" event. 
    // Here we just do it
    out.print("gwtOnLoad();");

    out.newlineOpt();
    out.print("})();");
    out.newlineOpt();

    return emitString(logger, out.toString(), context.getModuleName() + ".nocache.js");
}

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  ww  . j  a v  a  2 s  . c  o m
    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);
}

From source file:org.chromium.distiller.dev.DistillerScriptLinker.java

License:Apache License

@Override
protected Collection<Artifact<?>> doEmitCompilation(TreeLogger logger, LinkerContext context,
        CompilationResult result, ArtifactSet artifacts) throws UnableToCompleteException {

    String[] js = result.getJavaScript();
    if (js.length != 1) {
        logger.branch(TreeLogger.ERROR,/*from  w  ww.j  av a2 s  .c  o m*/
                "The module must not have multiple fragments when using the " + getDescription() + " Linker.",
                null);
        throw new UnableToCompleteException();
    }

    Collection<Artifact<?>> toReturn = new ArrayList<Artifact<?>>();
    toReturn.add(new Script(result.getStrongName(), js[0]));
    toReturn.addAll(emitSelectionInformation(result.getStrongName(), result));
    return toReturn;
}

From source file:org.gwtproject.gwt.worker.linker.SingleScriptLinker.java

License:Apache License

@Override
protected Collection<Artifact<?>> doEmitCompilation(TreeLogger logger, LinkerContext context,
        CompilationResult result, ArtifactSet artifacts) throws UnableToCompleteException {

    String[] js = result.getJavaScript();
    if (js.length != 1) {
        logger.branch(TreeLogger.ERROR, getMultiFragmentWarningMessage(), null);
        throw new UnableToCompleteException();
    }/*from   w  w w . j  a  va 2 s  . c  om*/

    Collection<Artifact<?>> toReturn = new ArrayList<Artifact<?>>();
    toReturn.add(new Script(result.getStrongName(), js[0]));
    toReturn.addAll(emitSelectionInformation(result.getStrongName(), result));
    return toReturn;
}

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();
                }//  ww  w.ja v  a  2s  . c  o  m
                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;
}

From source file:uk.co.thinkofdeath.thinkcraft.html.linker.WorkerLinker.java

License:Apache License

@Override
protected Collection<Artifact<?>> doEmitCompilation(TreeLogger logger, LinkerContext context,
        CompilationResult result, ArtifactSet artifacts) throws UnableToCompleteException {
    String[] javascript = result.getJavaScript();
    if (javascript.length != 1) {
        logger.branch(TreeLogger.ERROR, "Too many fragments");
        throw new UnableToCompleteException();
    }//from  w w w.j av a 2  s . c o  m
    ArrayList<Artifact<?>> newArtifacts = new ArrayList<>();
    newArtifacts.addAll(emitSelectionInformation(result.getStrongName(), result));
    newArtifacts.add(new WorkerScript(result.getStrongName(), javascript[0]));
    return newArtifacts;
}