Example usage for com.google.gwt.core.ext TreeLogger branch

List of usage examples for com.google.gwt.core.ext TreeLogger branch

Introduction

In this page you can find the example usage for com.google.gwt.core.ext TreeLogger branch.

Prototype

public final TreeLogger branch(TreeLogger.Type type, String msg, Throwable caught) 

Source Link

Document

Calls #branch(com.google.gwt.core.ext.TreeLogger.Type,String,Throwable,com.google.gwt.core.ext.TreeLogger.HelpInfo) with a null helpInfo.

Usage

From source file:cc.alcina.framework.gwt.appcache.linker.AppCacheManifestLinker.java

License:Apache License

private EmittedArtifact emitManifest(TreeLogger logger, LinkerContext context, EmittedArtifact userManifest,
        SortedSet<EmittedArtifact> artifacts) throws UnableToCompleteException {
    logger = logger.branch(TreeLogger.DEBUG, "Creating manifest artifact", null);
    // Try getting a user-defined manifest
    StringBuffer out = readManifestTemplate(logger, userManifest);
    // Use the template in the MD5 computation
    digester.update(Util.getBytes(out.toString()));
    // Look for @filter expressions in the manifest template
    Set<Pattern> filters = extractFilters(logger, out);
    // Append the builtin filters
    for (String pattern : BUILTIN_FILTERS) {
        filters.add(Pattern.compile(pattern));
    }//from ww w  .  j  a  va  2  s. c om
    filters.add(Pattern.compile(".*?(^|/)\\.[^/]+"));// ignore .-prefixed
    // files (e.g.
    // .cvsignore)
    // Generate the manifest entries
    String entries = generateEntries(logger, context, filters, artifacts);
    replaceAll(out, "__VERSION__", StringUtils.toHexString(digester.digest()));
    replaceAll(out, "__ENTRIES__", entries.toString());
    /*
     * NB: It's tempting to use LinkerContext.optimizeJavaScript here, but
     * the JSON standard requires that the keys in the object literal will
     * be enclosed in double-quotes. In our optimized JS form, the
     * double-quotes would normally be removed.
     */
    return emitBytes(logger, Util.getBytes(out.toString()), "appcache.nocache.manifest");
}

From source file:cc.alcina.framework.gwt.appcache.linker.AppCacheManifestLinker.java

License:Apache License

/**
 * Find all instances of the filter pragma in the manifest template and
 * return compiled regular expression Pattern objects.
 *///from w w  w. j a  v  a2  s  .  com
private Set<Pattern> extractFilters(TreeLogger logger, CharSequence source) throws UnableToCompleteException {
    logger.branch(TreeLogger.DEBUG, "Finding @filter expressions", null);
    boolean filterError = false;
    Matcher filterMatcher = FILTER_PATTERN.matcher(source);
    Set<Pattern> filters = new HashSet<Pattern>();
    while (filterMatcher.find()) {
        String pattern = filterMatcher.group(1);
        try {
            filters.add(Pattern.compile(pattern));
        } catch (PatternSyntaxException e) {
            logger.log(TreeLogger.ERROR,
                    "Could not compile filter pattern at character offset " + filterMatcher.start(), e);
            filterError = true;
        }
    }
    if (filterError) {
        throw new UnableToCompleteException();
    }
    return filters;
}

From source file:cc.alcina.framework.gwt.appcache.linker.AppCacheManifestLinker.java

License:Apache License

/**
 * Generate a string containing object literals for each manifest entry.
 *///from  ww w  .  java 2s .c  o  m
private String generateEntries(TreeLogger logger, LinkerContext context, Set<Pattern> filters,
        SortedSet<EmittedArtifact> artifacts) throws UnableToCompleteException {
    logger = logger.branch(TreeLogger.DEBUG, "Generating manifest contents", null);
    StringBuffer entries = new StringBuffer();
    paths: for (EmittedArtifact artifact : artifacts) {
        if (artifact.getVisibility() != Visibility.Public) {
            // These artifacts won't be in the module output directory
            continue;
        }
        String path = artifact.getPartialPath();
        for (Pattern p : filters) {
            if (p.matcher(path).matches()) {
                logger.log(TreeLogger.DEBUG, "Filtering resource " + path, null);
                continue paths;
            }
        }
        entries.append("/" + context.getModuleName() + "/" + path);
        entries.append("\n");
        // Read the artifact into the digester
        InputStream in = artifact.getContents(logger);
        byte[] buffer = new byte[4096];
        int read;
        try {
            while ((read = in.read(buffer)) != -1) {
                digester.update(buffer, 0, read);
            }
        } catch (IOException e) {
            logger.log(TreeLogger.ERROR, "Unable to read artifact " + artifact.getPartialPath(), e);
            throw new UnableToCompleteException();
        }
    }
    // Add an alias for Module.nocache.js?compiled to support hosted-mode
    entries.append("/" + context.getModuleName() + "/" + context.getModuleName() + ".nocache.js?compiled\n");
    entries.append("/" + context.getModuleName() + "/" + context.getModuleName() + ".nocache.js\n");
    return entries.toString();
}

From source file:cc.alcina.framework.gwt.appcache.linker.AppCacheManifestLinker.java

License:Apache License

/**
 * Load the contents of the manifest template from a file named
 * {@value #APPCACHE_MANIFEST} in the root of the public path. Failing that,
 * use the built-in template.//from w  w w. j  a  v  a2 s  .  c o  m
 */
private StringBuffer readManifestTemplate(TreeLogger logger, EmittedArtifact userManifest)
        throws UnableToCompleteException {
    logger = logger.branch(TreeLogger.DEBUG, "Reading manifest template", null);
    InputStream in;
    // See if we have a user-provided manifest to work with
    if (userManifest != null) {
        logger.log(TreeLogger.DEBUG, "Reading user-provided manifest", null);
        in = userManifest.getContents(logger);
        if (in == null) {
            logger.log(TreeLogger.ERROR, "Unable to read contents of user manifest", null);
            throw new UnableToCompleteException();
        }
    } else {
        // Fall back to the built-in manifest
        String packagePath = getClass().getPackage().getName().replace('.', '/');
        String resourceName = packagePath + "/" + APPCACHE_MANIFEST;
        in = getClass().getClassLoader().getResourceAsStream(resourceName);
        if (in == null) {
            logger.log(TreeLogger.ERROR, "Could not load built-in manifest from " + resourceName, null);
            throw new UnableToCompleteException();
        }
    }
    StringBuffer out = new StringBuffer();
    BufferedReader reader = new BufferedReader(new InputStreamReader(in));
    try {
        for (String line = reader.readLine(); line != null; line = reader.readLine()) {
            out.append(line).append("\n");
        }
    } catch (IOException e) {
        logger.log(TreeLogger.ERROR, "Unable to read manifest template", e);
        throw new UnableToCompleteException();
    }
    return out;
}

From source file:com.bedatadriven.rebar.appcache.linker.AppCacheIFrameLinker.java

License:Apache License

private EmittedArtifact doEmitManifest(TreeLogger logger, PermutationContext context, ManifestWriter writer)
        throws UnableToCompleteException {

    logger = logger.branch(TreeLogger.DEBUG, "Generating " + writer.getSuffix() + " contents", null);

    StringBuffer out = readManifestTemplate(logger, context, writer.getSuffix());

    // Generate the manifest entries
    appendEntries(logger, context, writer);

    // use the current time as the version number
    replaceAll(out, "__NAME__", context.getModuleName());
    replaceAll(out, "__VERSION__", context.getStrongName());
    replaceAll(out, "__ENTRIES__", writer.getEntries());

    /*// w ww. j ava 2 s  .  c om
    * NB: It's tempting to use LinkerContext.optimizeJavaScript here, but the
    * JSON standard requires that the keys in the object literal will be
    * enclosed in double-quotes. In our optimized JS form, the double-quotes
    * would normally be removed.
    */
    return emitBytes(logger, Util.getBytes(out.toString()), context.getStrongName() + "." + writer.getSuffix());
}

From source file:com.bedatadriven.rebar.appcache.linker.AppCacheIFrameLinker.java

License:Apache License

/**
 * Generate a string containing object literals for each manifest entry.
 *//* ww  w . j  av a 2 s  .  c o m*/
private void appendEntries(TreeLogger logger, PermutationContext context, ManifestWriter writer)
        throws UnableToCompleteException {

    logger = logger.branch(TreeLogger.DEBUG, "Generating manifest entries", null);

    // add the bootstrap script (provided by the server)
    writer.appendEntry(logger, context.getModuleName() + ".nocache.js");

    for (EmittedArtifact artifact : context.getToCache()) {
        if (artifact.getVisibility() == Visibility.Public) {

            logger.log(TreeLogger.DEBUG, "adding to manifest:" + artifact.getPartialPath() + " of class "
                    + artifact.getClass().getName() + " and visibility " + artifact.getVisibility());

            if (artifact.getPartialPath().endsWith(".gwt.rpc")) {
                // only used by the server
                continue;
            }

            String path = artifact.getPartialPath();

            // certain paths on the Windows platform (notably deferredjs stuff)
            // show up with backslahes, which throws an illegal escape sequence
            // error when the json is parsed.
            path = path.replace('\\', '/');

            logger.log(TreeLogger.DEBUG, "adding: " + path);
            writer.appendEntry(logger, path);
        } else {
            logger.log(TreeLogger.DEBUG,
                    "excluding " + artifact.getVisibility() + ": " + artifact.getPartialPath());
        }
    }
}

From source file:com.browsexml.jetty.MyJettyLauncher.java

License:Apache License

@Override
public ServletContainer start(TreeLogger logger, int port, File appRootDir) throws Exception {
    TreeLogger branch = logger.branch(TreeLogger.TRACE, "Starting Jetty on port " + port, null);

    checkStartParams(branch, port, appRootDir);

    // Setup our branch logger during startup.
    Log.setLog(new JettyTreeLogger(branch));

    // Force load some JRE singletons that can pin the classloader.
    jreLeakPrevention(logger);// w  w  w  . j a va2  s.c o  m

    // Turn off XML validation.
    System.setProperty("org.mortbay.xml.XmlParser.Validating", "false");

    AbstractConnector connector = getConnector();
    if (bindAddress != null) {
        connector.setHost(bindAddress.toString());
    }
    connector.setPort(port);

    // Don't share ports with an existing process.
    connector.setReuseAddress(false);

    // Linux keeps the port blocked after shutdown if we don't disable this.
    connector.setSoLingerTime(0);

    Server server = new Server();
    server.addConnector(connector);

    // Create a new web app in the war directory.
    WebAppContext wac = createWebAppContext(logger, appRootDir);
    wac.setConfigurationClasses(__dftConfigurationClasses);

    RequestLogHandler logHandler = new RequestLogHandler();
    logHandler.setRequestLog(new JettyRequestLogger(logger, getBaseLogLevel()));
    logHandler.setHandler(wac);
    server.setHandler(logHandler);
    server.start();
    server.setStopAtShutdown(true);

    // Now that we're started, log to the top level logger.
    Log.setLog(new JettyTreeLogger(logger));

    return createServletContainer(logger, appRootDir, server, wac, connector.getLocalPort());
}

From source file:com.eleven.rebind.SkinBundleBuilder.java

License:Apache License

private ImageRect addImage(TreeLogger logger, final String imageName) throws UnableToCompleteException {

    logger = logger.branch(TreeLogger.TRACE, "Adding image '" + imageName + "'", null);

    // Fetch the image.
    try {/*from   w w  w  . j ava  2 s .c  o m*/
        /*
                 // Could turn this lookup logic into an externally-supplied policy
                 // for
                 // increased generality.
                 URL imageUrl = getClass().getClassLoader().getResource(imageName);
                 if (imageUrl == null) {
        */
        // 11pc
        File file = new File(imageName);

        if (!file.exists()) {
            // This should never happen, because this check is done right
            // after
            // the image name is retrieved from the metadata or the method
            // name.
            // If there is a failure in obtaining the resource, it will
            // happen
            // before this point.
            logger.log(TreeLogger.ERROR, "Resource not found on classpath (is the name specified as "
                    + "Class.getResource() would expect?)", null);
            throw new UnableToCompleteException();
        }

        BufferedImage image;
        // Load the image
        try {
            image = ImageIO.read(file);
        } catch (IllegalArgumentException iex) {
            if (imageName.toLowerCase().endsWith("png") && iex.getMessage() != null && iex.getStackTrace()[0]
                    .getClassName().equals("javax.imageio.ImageTypeSpecifier$Indexed")) {
                logger.log(TreeLogger.ERROR, "Unable to read image. The image may not be in valid PNG format. "
                        + "This problem may also be due to a bug in versions of the " + "JRE prior to 1.6. See "
                        + "http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=5098176 "
                        + "for more information. If this bug is the cause of the "
                        + "error, try resaving the image using a different image "
                        + "program, or upgrade to a newer JRE.", null);
                throw new UnableToCompleteException();
            } else
                throw iex;
        }

        if (image == null) {
            logger.log(TreeLogger.ERROR, "Unrecognized image file format", null);
            throw new UnableToCompleteException();
        }

        return new ImageRect(imageName, image);

    } catch (IOException e) {
        logger.log(TreeLogger.ERROR, "Unable to read image resource", null);
        throw new UnableToCompleteException();
    }
}

From source file:com.eleven.rebind.SkinBundleGenerator.java

License:Apache License

/**
 * Attempts to get the image name from the name of the method itself by
 * speculatively appending various image-like file extensions in a
 * prioritized order. The first image found, if any, is used.
 *
 * @param logger//  w  w w  .j a v  a2s. c  o  m
 *                    if no matching image resource is found, an explanatory message
 *                    will be logged
 * @param method
 *                    the method whose name is being examined for matching image
 *                    resources
 * @return a resource name that is suitable to be passed into
 *                      <code>ClassLoader.getResource()</code>; never returns
 *                      <code>null</code>
 * @throws UnableToCompleteException
 *                     thrown when no image can be found based on the method name
 */
private String getImageNameFromMethodName(final TreeLogger logger, final JMethodOracle method)
        throws UnableToCompleteException {
    String pkgName = method.getPackageName();
    String pkgPrefix = pkgName.replace('.', '/');
    if (pkgPrefix.length() > 0)
        pkgPrefix += "/";

    String methodName = method.getName();
    String pkgAndMethodName = pkgPrefix + methodName;
    List<String> testImgNames = new ArrayList<String>();
    for (int i = 0; i < IMAGE_FILE_EXTENSIONS.length; i++) {
        String testImgName = pkgAndMethodName + '.' + IMAGE_FILE_EXTENSIONS[i];
        if (resLocator.isResourcePresent(testImgName))
            return testImgName;

        testImgNames.add(testImgName);
    }

    TreeLogger branch = logger.branch(TreeLogger.ERROR, MSG_NO_FILE_BASED_ON_METHOD_NAME, null);
    for (String testImgName : testImgNames)
        branch.log(TreeLogger.ERROR, testImgName, null);

    throw new UnableToCompleteException();
}

From source file:com.envjs.gwt.linker.ServerSingleScriptLinker.java

License:Apache License

@Override
protected Collection<EmittedArtifact> doEmitCompilation(TreeLogger logger, LinkerContext context,
        CompilationResult result) throws UnableToCompleteException {
    if (result.getJavaScript().length != 1) {
        logger.branch(TreeLogger.ERROR,
                "The module must not have multiple fragments when using the " + getDescription() + " Linker.",
                null);/* w  w  w  .  j  a v  a 2  s  .c o  m*/
        throw new UnableToCompleteException();
    }
    return super.doEmitCompilation(logger, context, result);
}