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

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

Introduction

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

Prototype

public void print(char c) 

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   w w  w .j av  a2 s .com
    // 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.ait.toolkit.node.dev.linker.NodeJsSymbolStoreLinker.java

License:Open Source License

@Override
protected void addPreloadCode(TreeLogger logger, LinkerContext context, ArtifactSet artifacts,
        CompilationResult result, DefaultTextOutput out) throws UnableToCompleteException {
    super.addPreloadCode(logger, context, artifacts, result, out);
    //add the symbols
    out.print("//--- BEGIN SYMBOL MAPPING ---");
    out.newline();//  w  w  w .j av  a2s .c  o  m
    out.print("//create symbol mapping object");
    out.newline();
    StringBuilder objectJs = new StringBuilder();
    BufferedReader reader = null;
    try {
        reader = new BufferedReader(new InputStreamReader(
                NodeJsSymbolStoreLinker.class.getResourceAsStream("SymbolStoreObject.js")));
        String line = reader.readLine();
        while (line != null) {
            line = line.replace("${objectName}", ClientSymbolStore.GLOBAL_JS_OBJECT_NAME);
            line = line.replace("${classesName}", ClientSymbolStore.CLASSES_MAP_NAME);
            line = line.replace("${methodsName}", ClientSymbolStore.METHODS_MAP_NAME);
            line = line.replace("${fieldsName}", ClientSymbolStore.FIELDS_MAP_NAME);
            objectJs.append(line).append("\n");
            line = reader.readLine();
        }
    } catch (IOException e) {
        logger.log(Type.ERROR, "Can't read local file", e);
        throw new UnableToCompleteException();
    } finally {
        try {
            reader.close();
        } catch (Exception ignore) {
        }
    }
    out.print(objectJs.toString());
    out.newline();
    out.print("//add symbols");
    for (SymbolData symbol : result.getSymbolMap()) {
        out.newline();
        out.print("global.");
        out.print(ClientSymbolStore.GLOBAL_JS_OBJECT_NAME);
        out.print("._add(");
        out.print(buildSymbolJson(symbol));
        out.print(");");
    }
    out.newline();
    out.print("//--- END SYMBOL MAPPING ---");
    out.newline();
}

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 w  ww. j  a v a2 s .com*/

    // 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.
    /*/*from w w  w  .  j  a  va2s  .  c o  m*/
    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./*from w  w  w  .ja  va  2s.  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.code.gwt.appcache.linker.IFrameAppCacheLinker.java

License:Apache License

/**
 * Outputs a piece of Javascript which is appended to each Permutation.
 *///from w  w w .java 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();/*from   www.  ja  va2s. c  om*/
    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);
    out.newlineOpt();//from  w  w  w  .  j  ava 2s  .  co m

    // 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  w w.  java  2s .c om
    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());
    //}//from  w ww.  j av a2  s .co  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;
}