Example usage for com.google.gwt.dev.util DefaultTextOutput toString

List of usage examples for com.google.gwt.dev.util DefaultTextOutput toString

Introduction

In this page you can find the example usage for com.google.gwt.dev.util DefaultTextOutput toString.

Prototype

@Override
    public String toString() 

Source Link

Usage

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());
    // }/*from ww w  .  ja  va 2s  . 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.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 2  s  . c om*/

    // 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 ava2s  .c om
    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: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./* www.  j av  a  2s . c  o  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.google.code.gwt.appcache.linker.IFrameAppCacheLinker.java

License:Apache License

/**
 * Outputs a piece of Javascript which is appended to each Permutation.
 *//*from w  w  w. ja  v a  2  s  .com*/
@Override
protected String getModuleSuffix(TreeLogger logger, LinkerContext context) {
    DefaultTextOutput out = new DefaultTextOutput(context.isOutputCompact());

    out.print("$stats && $stats({moduleName:'" + context.getModuleName()
            + "',subSystem:'startup',evtGroup:'moduleStartup'"
            + ",millis:(new Date()).getTime(),type:'moduleEvalEnd'});");

    // Generate the call to tell the bootstrap code that we're ready to go.
    out.newlineOpt();
    out.print("if ($wnd." + context.getModuleFunctionName() + ") $wnd." + context.getModuleFunctionName()
            + ".onScriptLoad();");
    out.newline();

    return out.toString();
}

From source file:delight.gwt.simplelinker.SimpleLinker.java

License:Apache License

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

    // out.print("var $stats = function() { };");
    out.print("var $_window = this;");
    out.newline();/*  w  ww  .ja  v  a  2s.  c o m*/
    out.print("var $gwt_version = \"" + About.getGwtVersionNum() + "\";");
    out.newline();
    out.print("var $stats = $wnd.__gwtStatsEvent ? function(a) {$wnd.__gwtStatsEvent(a)} : null;");
    out.newline();
    out.print("var $sessionId = function() { };");
    out.newline();

    final 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
        final 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();
    }

    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: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);//ww  w .  j ava 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 EmittedArtifact emitSelectionScript(TreeLogger logger, LinkerContext context, ArtifactSet artifacts)
        throws UnableToCompleteException {

    // Find the single Script result.
    Set<Script> results = artifacts.find(Script.class);
    if (results.size() != 1) {
        logger.log(TreeLogger.ERROR, "The module must have exactly one distinct"
                + " permutation when using the " + getDescription() + " Linker; found " + results.size(), null);
        throw new UnableToCompleteException();
    }//from  w  ww.j a  v a  2  s  . co m
    Script result = results.iterator().next();

    DefaultTextOutput out = new DefaultTextOutput(true);

    // Emit the module's JS as a closure.
    out.print("(function () {");
    out.newlineOpt();
    out.print("var $gwt_version = \"" + About.getGwtVersionNum() + "\";");
    out.newlineOpt();
    out.print("var $wnd = window; /* our linker */");
    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();

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

    out.print(result.getJavaScript());

    out.newlineOpt();
    out.print("gwtOnLoad(undefined, \"" + context.getModuleFunctionName() + "\", \"\", 0);");
    out.newlineOpt();
    out.print("})();");
    out.newlineOpt();

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

From source file:org.gwtnode.dev.linker.GwtNodeLinker.java

License:Apache 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  .j  a  v  a  2  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:org.gwtproject.gwt.worker.linker.SingleScriptLinker.java

License:Apache License

@Override
protected EmittedArtifact emitSelectionScript(TreeLogger logger, LinkerContext context, ArtifactSet artifacts)
        throws UnableToCompleteException {

    // Find the single Script result
    Set<Script> results = artifacts.find(Script.class);
    ensureSinglePermutation(logger, context, results);
    Script result = results.iterator().next();

    DefaultTextOutput out = new DefaultTextOutput(true);

    // Emit the selection script.
    String bootstrap = generateSelectionScript(logger, context, artifacts);
    bootstrap = context.optimizeJavaScript(logger, bootstrap);
    out.print(bootstrap);/* www.  j a  v  a 2s . com*/
    out.newlineOpt();

    // Emit the module's JS a closure.
    out.print("(function () {");
    out.newlineOpt();
    out.print("var $gwt_version = \"" + About.getGwtVersionNum() + "\";");
    out.newlineOpt();

    defineJsWndAndDoc(out);

    out.print("var $moduleName, $moduleBase;");
    out.newlineOpt();
    out.print("var $stats = $wnd.__gwtStatsEvent ? function(a) {$wnd.__gwtStatsEvent(a)} : null;");
    out.newlineOpt();

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

    out.print(result.getJavaScript());

    // 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();

    return emitString(logger, out.toString(),
            context.getModuleName() + getCompilationExtension(logger, context));
}