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

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

Introduction

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

Prototype

public boolean remove(Object 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;/* w w  w .  j  av a2  s . co  m*/
            toReturn.remove(artifact);
            emitted.remove(artifact);
            break;
        }
    }
    toReturn.add(emitManifest(logger, context, userManifest, emitted));
    return toReturn;
}

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  ww  . j a va  2 s  . 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.mobile.trippy.web.rebind.RecursiveArtifactLinker.java

License:Apache License

@Override
public ArtifactSet link(TreeLogger logger, LinkerContext context, ArtifactSet artifacts)
        throws UnableToCompleteException {
    ArtifactSet toReturn = new ArtifactSet(artifacts);
    ArtifactSet toReturnAfterRemove = new ArtifactSet(artifacts);
    for (EmittedArtifact artifact : toReturn.find(EmittedArtifact.class)) {
        String partialPath = artifact.getPartialPath();
        if (partialPath.startsWith(TRIPPY_PREFIX) || partialPath.startsWith(WEB_INF_PREFIX)) {
            toReturnAfterRemove.remove(artifact);
        }/*from   w w w  .  j a  v a2  s  . c  o  m*/
    }
    return toReturnAfterRemove;
}

From source file:com.smartgwt.linker.SmartGwtLinker.java

License:Open Source License

public ArtifactSet link(TreeLogger logger, LinkerContext context, ArtifactSet artifacts)
        throws UnableToCompleteException {
    // Create a new set of artifacts that we can modify and return.
    ArtifactSet toReturn = new ArtifactSet(artifacts);

    Set<EmittedArtifact> emittedArtifacts = artifacts.find(EmittedArtifact.class);
    for (EmittedArtifact emittedArtifact : emittedArtifacts) {
        String partialPath = emittedArtifact.getPartialPath();
        // If encounter ISC_Core.js or Page.js (when inheriting SmartGwtDebug.gwt.xml),
        // inject the appropriate isomorphicDir var so that users don't need to explicitly
        // specify this in their host html file.
        if (partialPath.endsWith("/ISC_Core.js") || partialPath.endsWith("/Page.js")) {
            String contents = SmartGwtLinkerUtils.getContents(emittedArtifact, logger);
            int isoDirInd = contents.indexOf("/*#ISO_DIR#*/");
            if (isoDirInd >= 0) {
                StringBuffer sb = new StringBuffer(contents);
                sb.replace(isoDirInd, isoDirInd + "/*#ISO_DIR#*/".length(),
                        "if(typeof isomorphicDir == 'undefined'){isomorphicDir = '" + context.getModuleName()
                                + "/sc/';}\n");

                toReturn.remove(emittedArtifact);
                toReturn.add(emitString(logger, sb.toString(), partialPath));
            }/*from   w w  w . j ava 2s  .  c o  m*/
        }
    }
    return toReturn;
}

From source file:com.smartgwt.linker.SmartGwtScriptInjector.java

License:Open Source License

public ArtifactSet link(TreeLogger logger, LinkerContext context, ArtifactSet artifacts, boolean permutation)
        throws UnableToCompleteException {
    Float gwtVersion = Float.parseFloat(About.getGwtVersionNum().replaceFirst("([0-9]+\\.[0-9]+).*", "$1"));
    String moduleName = context.getModuleName();

    // do nothing if the primary linker already handles script injection automatically
    if (permutation || gwtVersion < 2.5f || !forceScriptLoad(logger, moduleName, gwtVersion)) {
        return artifacts;
    }/*from   w  w  w  . j a  v  a  2 s  . c  o m*/

    // if there are no script tags present, then there's nothing to do
    Set<ScriptReference> scripts = artifacts.find(ScriptReference.class);
    if (scripts.size() == 0)
        return artifacts;

    // script tags are present, and manual load required; emit script loading
    ArtifactSet toReturn = new ArtifactSet(artifacts);

    Set<EmittedArtifact> emittedArtifacts = artifacts.find(EmittedArtifact.class);
    for (EmittedArtifact emittedArtifact : emittedArtifacts) {
        String partialPath = emittedArtifact.getPartialPath();
        if (!partialPath.endsWith(".nocache.js"))
            continue;

        toReturn.remove(emittedArtifact);

        // add code at the end of the <moduleName>.nocache.js file to load the scripts
        String contents = SmartGwtLinkerUtils.getContents(emittedArtifact, logger);
        contents += getScriptLoadJS(scripts, context);

        StringBuffer sb = new StringBuffer(contents);
        toReturn.add(emitString(logger, sb.toString(), partialPath));
        break;
    }

    return toReturn;
}

From source file:com.totsp.crossword.misc.GadgetLinker.java

License:Apache License

@Override
public ArtifactSet link(TreeLogger logger, LinkerContext context, ArtifactSet artifacts)
        throws UnableToCompleteException {
    ArtifactSet toLink = new ArtifactSet(artifacts);

    // Mask the stub manifest created by the generator
    for (EmittedArtifact res : toLink.find(EmittedArtifact.class)) {
        if (res.getPartialPath().endsWith(".gadget.xml")) {
            manifestArtifact = res;//w w w  .  j  a va2s.c  om
            toLink.remove(res);

            break;
        }
    }

    if (manifestArtifact == null) {
        if (artifacts.find(CompilationResult.class).isEmpty()) {
            // Maybe hosted mode or junit, defer to XSLinker.
            return new XSLinker().link(logger, context, toLink);
        } else {
            // When compiling for web mode, enforce that the manifest is present.
            logger.log(TreeLogger.ERROR, "No gadget manifest found in ArtifactSet.");
            throw new UnableToCompleteException();
        }
    }

    return super.link(logger, context, toLink);
}

From source file:com.vaadin.sass.linker.SassLinker.java

License:Apache License

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

    if (!onePermutation) {
        // The artifact to return
        ArtifactSet toReturn = new ArtifactSet(artifacts);

        // The temporary scss files provided from the artefacts
        List<FileInfo> scssFiles = new ArrayList<FileInfo>();

        // The public files are provided as inputstream, but the compiler
        // needs real files, as they can contain references to other
        // files. They will be stored here, with their relative paths intact
        String tempFolderName = new Date().getTime() + File.separator;
        File tempFolder = createTempDir(tempFolderName);

        // Can't search here specifically for public resources, as the type
        // is different during compilation. This means we have to loop
        // through all the artifacts
        for (EmittedArtifact resource : artifacts.find(EmittedArtifact.class)) {

            // Create the temporary files.
            String partialPath = resource.getPartialPath();
            if (partialPath.endsWith(".scss")) {
                // In my opinion, the SCSS file does not need to be
                // output to the web content folder, as they can't
                // be used there
                toReturn.remove(resource);

                String fileName = partialPath;
                File path = tempFolder;

                int separatorIndex = fileName.lastIndexOf(File.separator);
                if (-1 != separatorIndex) {
                    fileName = fileName.substring(separatorIndex + 1);

                    String filePath = partialPath.substring(0, separatorIndex);
                    path = createTempDir(tempFolderName + filePath);
                }/*from w w w.  ja v a  2s  . co  m*/

                File tempfile = new File(path, fileName);
                try {
                    boolean fileCreated = tempfile.createNewFile();
                    if (fileCreated) {

                        // write the received inputstream to the temp file
                        writeFromInputStream(resource.getContents(logger), tempfile);

                        // Store the file info for the compilation
                        scssFiles.add(new FileInfo(tempfile, partialPath));
                    } else {
                        logger.log(TreeLogger.WARN, "Duplicate file " + tempfile.getPath());
                    }
                } catch (IOException e) {
                    logger.log(TreeLogger.ERROR, "Could not write temporary file " + fileName, e);
                }
            }
        }

        // Compile the files and store them in the artifact
        logger.log(TreeLogger.INFO, "Processing " + scssFiles.size() + " Sass file(s)");
        for (FileInfo fileInfo : scssFiles) {
            logger.log(TreeLogger.INFO,
                    "   " + fileInfo.originalScssPath + " -> " + fileInfo.getOriginalCssPath());

            try {
                ScssStylesheet scss = ScssStylesheet.get(fileInfo.getAbsolutePath());
                if (!fileInfo.isMixin()) {
                    scss.compile();
                    InputStream is = new ByteArrayInputStream(scss.printState().getBytes());

                    toReturn.add(this.emitInputStream(logger, is, fileInfo.getOriginalCssPath()));
                }

                fileInfo.getFile().delete();
            } catch (CSSException e) {
                logger.log(TreeLogger.ERROR, "SCSS compilation failed for " + fileInfo.getOriginalCssPath(), e);
            } catch (IOException e) {
                logger.log(TreeLogger.ERROR, "Could not write CSS file for " + fileInfo.getOriginalCssPath(),
                        e);
            } catch (Exception e) {
                logger.log(TreeLogger.ERROR, "SCSS compilation failed for " + fileInfo.getOriginalCssPath(), e);
            }
        }

        return toReturn;
    }

    return artifacts;
}

From source file:gwt.ns.webworker.linker.WorkerCompilationLinker.java

License:Apache License

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

    ArtifactSet toReturn = new ArtifactSet(artifacts);

    // get set of requests for insideWorker compilations from artifacts
    SortedSet<WorkerRequestArtifact> workerRequests = toReturn.find(WorkerRequestArtifact.class);
    if (workerRequests.size() == 0) {
        logger.log(TreeLogger.SPAM, "No Worker compilations requested. No action taken.");
        return toReturn; // early exit, sorry
    }//from  w  w  w .  j  a v a 2s.  com

    // compile all requested workers
    // if this is a recursive call, requests were passed up to parent so
    // returned value is null
    SortedMap<WorkerRequestArtifact, String> workerScripts = WorkerCompiler.run(logger, workerRequests);

    // if they exist, deal with compiled scripts:
    if (workerScripts != null && workerScripts.size() != 0) {
        // directory strong name from all scripts
        byte[][] bytejs = Util.getBytes(workerScripts.values().toArray(new String[0]));
        String scriptDirStrongName = Util.computeStrongName(bytejs);

        // emit worker scripts
        for (Map.Entry<WorkerRequestArtifact, String> script : workerScripts.entrySet()) {
            WorkerRequestArtifact req = script.getKey();
            toReturn.add(emitString(logger, script.getValue(),
                    req.getRelativePath(scriptDirStrongName, File.separator)));
        }

        // get the set of current compilation results
        SortedSet<CompilationResult> compResults = toReturn.find(CompilationResult.class);

        /*
         * Reading the js from and writing it to a new CompilationResult is
         * expensive (possibly disk cached), so read once and write only if
         * altered.
         */
        for (CompilationResult compRes : compResults) {
            // assume all need modification
            // TODO: rule out emulated permutations via properties
            toReturn.remove(compRes);

            CompilationResult altered = replacePlaceholder(logger, compRes,
                    WorkerRequestArtifact.getPlaceholderStrongName(), scriptDirStrongName);
            toReturn.add(altered);
        }
    }

    return toReturn;
}

From source file:net.randomhacks.wave.voting.approval.ApprovalVotingLinker.java

License:Apache License

private void renameSyntheticArtifact(TreeLogger logger, ArtifactSet result, SyntheticArtifact gadgetXml,
        String partialPath) throws UnableToCompleteException {
    result.remove(gadgetXml);
    result.add(/*from   www. ja v a  2  s.  com*/
            emitInputStream(logger, gadgetXml.getContents(logger), partialPath, gadgetXml.getLastModified()));
}

From source file:org.cesiumjs.linker.CesiumLinker.java

License:Apache License

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

    Set<EmittedArtifact> emittedArtifacts = artifacts.find(EmittedArtifact.class);
    for (EmittedArtifact emittedArtifact : emittedArtifacts) {
        String partialPath = emittedArtifact.getPartialPath();
        // Add to Cesium.js file, path, where Cesium/Cesium.js stored.
        // It need for inject css files for example - Viewer
        if (partialPath.endsWith("/Cesium.js")) {
            String contents = CesiumLinkerUtils.getContents(emittedArtifact, logger);
            StringBuffer sb = new StringBuffer(contents);
            sb.insert(0, "window.CesiumPath = '" + context.getModuleName() + "/js/';\n");
            toReturn.remove(emittedArtifact);
            toReturn.add(emitString(logger, sb.toString(), partialPath));
        }// w  w w  . j  a va2s  .c o m
    }
    return toReturn;
}