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

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

Introduction

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

Prototype

public void newline() 

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());
    // }//w w w.  ja  v a  2  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;
}

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();
    out.print("//create symbol mapping object");
    out.newline();/*from  ww  w.j  a va2 s .  c o  m*/
    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();

    // get compilation result
    Set<CompilationResult> results = artifacts.find(CompilationResult.class);
    if (results.size() == 0) {
        logger.log(TreeLogger.WARN, "Requested 0 permutations");
        return toReturn;
    }/*  w  ww. ja v  a  2  s .  com*/

    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.google.code.gwt.appcache.linker.IFrameAppCacheLinker.java

License:Apache License

/**
 * Outputs a piece of Javascript which is appended to each Permutation.
 *///w ww  . j a v  a 2 s  .c om
@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();
    out.print("var $gwt_version = \"" + About.getGwtVersionNum() + "\";");
    out.newline();/*from w  w w. jav a 2 s.co  m*/
    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: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 a v a  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:org.gwtnode.dev.linker.GwtNodeSymbolStoreLinker.java

License:Apache 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();
    out.print("//create symbol mapping object");
    out.newline();//  w  w w . j  av a  2 s  .  c o  m
    StringBuilder objectJs = new StringBuilder();
    BufferedReader reader = null;
    try {
        reader = new BufferedReader(new InputStreamReader(
                GwtNodeSymbolStoreLinker.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:org.objectfabric.NodeLinker.java

License:Apache License

@Override
public ArtifactSet link(TreeLogger logger, LinkerContext context, ArtifactSet artifacts)
        throws UnableToCompleteException {
    DefaultTextOutput out = new DefaultTextOutput(true);
    Set<CompilationResult> results = artifacts.find(CompilationResult.class);
    CompilationResult result = null;//w  w w .ja  v a  2s.com

    if (results.size() > 1)
        throw new UnableToCompleteException();

    if (!results.isEmpty()) {
        result = results.iterator().next();
        String[] js = result.getJavaScript();

        if (js.length != 1)
            throw new UnableToCompleteException();

        out.print(js[0]);
        out.newline();
    }

    out.print("var $stats = function() { };\n");
    out.print("var $sessionId = function() { };\n");
    out.print("var window = { };\n");
    out.print("var navigator = { };\n");
    out.print("navigator.userAgent = 'webkit';\n");
    out.print("var $doc = { };\n");
    out.newline();
    out.print("var $wnd = window;\n");
    out.print("$wnd.setTimeout = setTimeout;\n");
    out.print("$wnd.clearTimeout = clearTimeout;\n");
    out.print("$wnd.clearInterval = clearInterval;\n");
    out.newline();
    out.print("gwtOnLoad(null, '" + context.getModuleName() + "', null);\n");
    out.print("var fs = require('fs');\n");
    out.print("var WebSocket = require('ws');\n");
    out.print("$wnd.org.objectfabric.node = { };\n");
    out.print("for(var f in $wnd.org.objectfabric)\n");
    out.print("  exports[f] = $wnd.org.objectfabric[f];");

    ArtifactSet set = new ArtifactSet(artifacts);
    set.add(emitString(logger, out.toString(), context.getModuleName() + ".js"));
    return set;
}

From source file:org.urish.gwtit.dev.linker.GwtTitaniumLinker.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);
    out.print("(function () {");
    out.newline();
    // grab compilation result
    Set<CompilationResult> results = artifacts.find(CompilationResult.class);
    if (results.size() == 0) {
        logger.log(TreeLogger.WARN, "Requested 0 permutations");
        return toReturn;
    }/*  w ww  . j  a v  a  2 s  .c o m*/
    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();
    // 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();
    // 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:uk.co.thinkofdeath.mapviewer.linker.WorkerLinker.java

License:Apache License

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

    Set<CompilationResult> results = artifacts.find(CompilationResult.class);
    CompilationResult result = results.iterator().next();

    output.print("(function() {");
    output.indentOut();//  ww  w  . j  a v a 2 s  . c o m
    output.newline();
    output.print("var $wnd = self, window = self, $doc = {compatMode:false},"
            + "$stats = function(){}, $sessionId = function(){};");
    output.newline();
    output.print(result.getJavaScript()[0]);
    output.newline();
    output.print("gwtOnLoad(null, '" + context.getModuleName() + "', null);");
    output.indentIn();
    output.newline();
    output.print("})();");

    set.add(emitString(logger, output.toString(), context.getModuleName() + ".js"));
    return set;
}