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

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

Introduction

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

Prototype

public boolean add(Artifact<?> o) 

Source Link

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  v  a2s .  c o 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

protected void maybeOutputPropertyMap(TreeLogger logger, LinkerContext context, ArtifactSet toReturn) {
    if (permutationsUtil.getPermutationsMap() == null || permutationsUtil.getPermutationsMap().isEmpty()) {
        return;/*www. j av a2s . c  o  m*/
    }
    PropertiesMappingArtifact mappingArtifact = new PropertiesMappingArtifact(CrossSiteIframeLinker.class,
            permutationsUtil.getPermutationsMap());
    toReturn.add(mappingArtifact);
    EmittedArtifact serializedMap;
    try {
        String mappings = mappingArtifact.getSerialized();
        serializedMap = emitString(logger, mappings, "compilation-mappings.txt");
        // TODO(unnurg): make this Deploy
        serializedMap.setVisibility(Visibility.Public);
        toReturn.add(serializedMap);
    } catch (UnableToCompleteException e) {
        e.printStackTrace();
    }
}

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());
    // }/*ww w . jav a2 s  .  c om*/
    // 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;
    }/*  ww w .  j a v a 2s  .  c  o 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  . j  av  a2s  .c  o  m*/

        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.chrome.gwt.linker.ExtensionLinker.java

License:Apache License

private static ArtifactSet addArtifacts(ArtifactSet artifacts, Artifact<?>... newArtifacts) {
    final ArtifactSet newSet = new ArtifactSet(artifacts);
    for (Artifact<?> artifact : newArtifacts) {
        newSet.add(artifact);
    }//from  w w  w.  j  a  va  2  s  .  com
    return newSet;
}

From source file:com.data2semantics.yasgui.mgwtlinker.linker.PermutationMapLinker.java

License:Open Source License

@Override
public ArtifactSet link(TreeLogger logger, LinkerContext context, ArtifactSet artifacts, boolean onePermutation)
        throws UnableToCompleteException {
    if (onePermutation) {
        Map<String, Set<BindingProperty>> permutationMap = buildPermutationMap(logger, context, artifacts);
        Set<Entry<String, Set<BindingProperty>>> entrySet = permutationMap.entrySet();

        // since we are in onePermutation there should be just one
        // strongName
        // better make sure..
        if (permutationMap.size() != 1) {
            logger.log(Type.ERROR, "There should be only one permutation right now, but there were: '"
                    + permutationMap.size() + "'");
            throw new UnableToCompleteException();
        }/*  w  w  w  . j  ava2 s .com*/

        Entry<String, Set<BindingProperty>> next = entrySet.iterator().next();
        String strongName = next.getKey();
        Set<BindingProperty> bindingProperties = next.getValue();

        // all artifacts for this compilation
        Set<String> artifactsForCompilation = getArtifactsForCompilation(logger, context, artifacts);

        ArtifactSet toReturn = new ArtifactSet(artifacts);
        PermutationArtifact permutationArtifact = new PermutationArtifact(PermutationMapLinker.class,
                strongName, artifactsForCompilation, bindingProperties);

        toReturn.add(permutationArtifact);
        return toReturn;
    }

    ArtifactSet toReturn = new ArtifactSet(artifacts);
    Map<String, Set<BindingProperty>> map = buildPermutationMap(logger, context, artifacts);

    if (map.size() == 0) {
        // hosted mode
        return toReturn;
    }

    Map<String, PermutationArtifact> permutationArtifactAsMap = getPermutationArtifactAsMap(artifacts);

    //we need different file sets/manifests for our dev version (unminimized js), and our stable version
    List<String> stableExternalFiles = getStableExternalFiles(logger, context);
    List<String> devExternalFiles = getDevExternalFiles(logger, context);

    // build manifest html page for our stable version (included as iframe in our webapp)
    String appcacheService = "manifest.appcache";
    String manifestHtmlPage = buildManifestHtmlPage(appcacheService);
    toReturn.add(emitString(logger, manifestHtmlPage, appcacheService + ".html"));

    // build manifest html page for our stable version (included as iframe in our webapp)
    String devManifestHtmlPage = buildManifestHtmlPage(appcacheService + "?type=dev");
    toReturn.add(emitString(logger, devManifestHtmlPage, "manifest.dev.appcache.html"));

    Set<String> allPermutationFiles = getAllPermutationFiles(permutationArtifactAsMap);

    // get all artifacts
    Set<String> allArtifacts = getArtifactsForCompilation(logger, context, artifacts);

    for (Entry<String, PermutationArtifact> entry : permutationArtifactAsMap.entrySet()) {
        PermutationArtifact permutationArtifact = entry.getValue();
        // make a copy of all artifacts
        HashSet<String> filesForCurrentPermutation = new HashSet<String>(allArtifacts);
        // remove all permutations
        filesForCurrentPermutation.removeAll(allPermutationFiles);
        // add files of the one permutation we are interested in
        // leaving the common stuff for all permutations in...
        filesForCurrentPermutation.addAll(entry.getValue().getPermutationFiles());
        filesForCurrentPermutation = appendVersionIfNeeded(filesForCurrentPermutation);

        String permXml = buildPermXml(logger, permutationArtifact, filesForCurrentPermutation,
                stableExternalFiles);

        // emit permutation information file
        SyntheticArtifact emitString = emitString(logger, permXml,
                permutationArtifact.getPermutationName() + PERMUTATION_FILE_ENDING);
        toReturn.add(emitString);

        // build manifest for our stable version
        String manifestFile = entry.getKey() + PERMUTATION_MANIFEST_FILE_ENDING;
        @SuppressWarnings("serial")
        Map<String, String> fallbacks = new HashMap<String, String>() {
            {
                put("/", "../index.jsp");
            }
        };
        String maniFest = buildManiFest(entry.getKey(), stableExternalFiles, filesForCurrentPermutation,
                fallbacks);
        toReturn.add(emitString(logger, maniFest, manifestFile));

        // build manifest for our dev version
        String devManifestFile = entry.getKey() + ".dev" + PERMUTATION_MANIFEST_FILE_ENDING;
        String devManiFest = buildManiFest(entry.getKey(), devExternalFiles, filesForCurrentPermutation);
        toReturn.add(emitString(logger, devManiFest, devManifestFile));

    }

    toReturn.add(createPermutationMap(logger, map));
    return toReturn;

}

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());
        }//ww w  .  j av  a  2 s .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   ww  w  .j a va  2s  .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
public ArtifactSet link(TreeLogger logger, LinkerContext context, ArtifactSet artifacts)
        throws UnableToCompleteException {
    ArtifactSet toReturn = new ArtifactSet(artifacts);

    toReturn.add(emitSelectionScript(logger, context, artifacts));

    return toReturn;
}