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

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

Introduction

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

Prototype

TreeLogger

Source Link

Usage

From source file:org.jboss.errai.ioc.rebind.ioc.test.harness.MockIOCGenerator.java

License:Apache License

public Class<? extends Bootstrapper> generate() {
    ClassScanner.setReflectionsScanning(true);

    final String packageName = Bootstrapper.class.getPackage().getName();
    final String className = "MockBootstrapperImpl";

    final IOCBootstrapGenerator bootstrapGenerator = new IOCBootstrapGenerator(
            GeneratorContextBuilder.newCoreBasedBuilder().buildGeneratorContext(), new TreeLogger() {
                @Override//from  w ww  .  ja  v a 2 s .  co m
                public TreeLogger branch(final Type type, final String msg, final Throwable caught,
                        final HelpInfo helpInfo) {
                    return null;
                }

                @Override
                public boolean isLoggable(final Type type) {
                    return false;
                }

                @Override
                public void log(final Type type, final String msg, final Throwable caught,
                        final HelpInfo helpInfo) {
                    System.out.println(type.getLabel() + ": " + msg);
                    if (caught != null) {
                        caught.printStackTrace();
                    }
                }
            }, packages, true);

    final String classStr = bootstrapGenerator.generate(packageName, className);

    final File fileCacheDir = RebindUtils.getErraiCacheDir();
    final File cacheFile = new File(fileCacheDir.getAbsolutePath() + "/" + className + ".java");

    RebindUtils.writeStringToFile(cacheFile, classStr);

    try {
        final File directory = new File(
                RebindUtils.getTempDirectory() + "/ioc/classes/" + packageName.replaceAll("\\.", "/"));

        final File sourceFile = new File(directory.getAbsolutePath() + "/" + className + ".java");
        final File outFile = new File(directory.getAbsolutePath() + "/" + className + ".class");

        if (sourceFile.exists()) {
            sourceFile.delete();
            outFile.delete();
        }

        directory.mkdirs();

        final FileOutputStream outputStream = new FileOutputStream(sourceFile);

        outputStream.write(classStr.getBytes("UTF-8"));
        outputStream.flush();
        outputStream.close();

        System.out.println("wrote file: " + sourceFile.getAbsolutePath());

        final Class<? extends Bootstrapper> bsClass = ClassChangeUtil.compileAndLoad(sourceFile, packageName,
                className);

        return bsClass;

    } catch (Exception e) {
        throw new RuntimeException(e);
    } finally {
        ClassScanner.setReflectionsScanning(false);
    }
}

From source file:rocket.compiler.TreeLoggers.java

License:Apache License

/**
 * Creates a TreeLogger that pipes any messages to the given logger as well
 * as recording each message to the given collection. Subsequent branches
 * will also have their messages captured.
 * // w w  w  .  j  a v a  2  s  .co m
 * @param logger
 * @param messages
 * @return
 */
static public TreeLogger pipeAndCapture(final TreeLogger logger, final Collection<String> messages) {
    Checker.notNull("parameter:logger", logger);
    Checker.notNull("parameter:messages", messages);

    return new TreeLogger() {

        public TreeLogger branch(final TreeLogger.Type type, final String message, final Throwable caught,
                final HelpInfo helpInfo) {
            if (this.isLoggable(type)) {
                messages.add(message);
            }
            final TreeLogger branch = TreeLoggers.pipeAndCapture(logger.branch(type, message, caught),
                    messages);
            return branch;
        }

        public boolean isLoggable(final TreeLogger.Type type) {
            return true;
        }

        public void log(final TreeLogger.Type type, final String message, final Throwable caught,
                final HelpInfo helpInfo) {
            if (this.isLoggable(type)) {
                messages.add(message);
            }
            logger.log(type, message, caught);
        }
    };
}