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

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

Introduction

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

Prototype

public final void log(TreeLogger.Type type, String msg) 

Source Link

Document

Calls #log(TreeLogger.Type,String,Throwable,HelpInfo) with a null caught and helpInfo.

Usage

From source file:com.ait.ext4j.rebind.TemplateGenerator.java

License:Apache License

/**
 * Given a TemplateResource interface, return the path to its .html file,
 * suitable for any classloader to find it as a resource. If the .html does
 * not exist or is empty see if the template was declared inline. If no
 * content is found we throw an exception.
 *//*from   w  w w.ja  v  a 2 s. c  om*/
private String getTemplateContent(GeneratorContext context, TreeLogger logger, JClassType interfaceType)
        throws UnableToCompleteException {
    String templateHtmlFile = null;

    TemplateResource annotation = interfaceType.getAnnotation(TemplateResource.class);
    if (annotation == null) {
        // if the interface is defined as a nested class, use the name of
        // the
        // enclosing type
        if (interfaceType.getEnclosingType() != null) {
            interfaceType = interfaceType.getEnclosingType();
        }
        templateHtmlFile = slashify(interfaceType.getQualifiedBinaryName()) + TEMPLATE_SUFFIX;
        logger.log(TreeLogger.INFO, "Template : " + templateHtmlFile);

        InputStream stream = getTemplateResource(context, logger, templateHtmlFile);
        if (stream == null) {
            logger.log(Type.ERROR, "No data could be loaded - no data at path "
                    + interfaceType.getQualifiedBinaryName() + TEMPLATE_SUFFIX);
            throw new UnableToCompleteException();
        }
        return sanitize(Util.readStreamAsString(stream));

    } else {
        // first we look at the HTML File
        templateHtmlFile = annotation.source();

        if (templateHtmlFile.length() > 0) {

            if (!templateHtmlFile.endsWith(TEMPLATE_SUFFIX)) {
                logger.log(TreeLogger.ERROR, "Template file name must end with " + TEMPLATE_SUFFIX);
                throw new UnableToCompleteException();
            }

            if (annotation.value().length() != 0) {
                logger.log(Type.WARN, "Found both source file and inline template, using source file");
            }

            templateHtmlFile = slashify(interfaceType.getPackage().getName()) + "/" + templateHtmlFile;
            InputStream stream = getTemplateResource(context, logger, templateHtmlFile);
            return sanitize(Util.readStreamAsString(stream));

        } else if (annotation.value().length() > 0) {
            return annotation.value();
        } else {
            logger.log(Type.ERROR,
                    "Template annotation found with no contents, cannot generate method , this may cause other failures.");
        }

    }
    return null;
}

From source file:com.ait.ext4j.rebind.TemplateGenerator.java

License:Apache License

@Override
public String generate(TreeLogger logger, GeneratorContext context, String typeName)
        throws UnableToCompleteException {
    TypeOracle oracle = context.getTypeOracle();
    this.templatesInterface = oracle.findType(Name.getSourceNameForClass(Template.class));

    JClassType interfaceType;//from  www . j a v  a 2 s. co m
    try {
        interfaceType = oracle.getType(typeName);
    } catch (NotFoundException e) {
        throw new RuntimeException(e);
    }

    if (interfaceType.isInterface() == null) {
        logger.log(TreeLogger.ERROR, typeName + " is not an interface type");
        throw new UnableToCompleteException();
    }
    if (!interfaceType.isAssignableTo(templatesInterface)) {
        logger.log(Type.ERROR, "This isn't a Template subtype...");
        throw new UnableToCompleteException();
    }

    String content = getTemplateContent(context, logger, interfaceType);
    String packageName = interfaceType.getPackage().getName();
    String className = "Template_For_" + interfaceType.getQualifiedSourceName().replace(".", "_");

    ClassSourceFileComposerFactory composer = new ClassSourceFileComposerFactory(packageName, className);
    composer.addImport(SafeHtml.class.getName());
    composer.addImport(SafeHtmlUtils.class.getName());
    composer.addImplementedInterface(Template.class.getName());

    PrintWriter pw = context.tryCreate(logger, packageName, className);
    SourceWriter sw = composer.createSourceWriter(context, pw);

    sw.println("  public SafeHtml getContent(){");
    sw.println("      return SafeHtmlUtils.fromSafeConstant(\"" + content + "\");");
    sw.println("  }");
    sw.println("");
    sw.println("");
    sw.println("  public SafeHtml getSafeContent(){");
    sw.println("      return SafeHtmlUtils.fromString(\"" + content + "\");");
    sw.println("  }");

    sw.commit(logger);
    return composer.getCreatedClassName();

}

From source file:com.ait.ext4j.rebind.TemplateGenerator.java

License:Apache License

protected InputStream getTemplateResource(GeneratorContext context, TreeLogger l, String markerPath)
        throws UnableToCompleteException {
    // look for a local file first
    String path = slashify(markerPath);
    l.log(Type.INFO, "Current resource path : " + markerPath);
    Resource res = context.getResourcesOracle().getResourceMap().get(path);
    // if not a local path, try an absolute one
    if (res == null) {
        l.log(Type.INFO, "Resource is Null trying with URL ");
        URL url = Thread.currentThread().getContextClassLoader().getResource(markerPath);
        if (url == null) {
            l.log(Type.INFO, "URL seems to be null here ... hmmmmss");
            return null;
        }/*from ww  w . j  a  v a2s  .com*/
        try {
            return url.openStream();
        } catch (IOException e) {
            l.log(Type.ERROR, "IO Exception occured", e);
            throw new UnableToCompleteException();
        }
    }
    try {
        return res.openContents();
    } catch (Exception e) {
        l.log(Type.ERROR, "Exception occured reading " + path, e);
        throw new UnableToCompleteException();
    }
}

From source file:com.ait.toolkit.rebind.TemplateGenerator.java

License:Open Source License

@Override
public String generate(TreeLogger logger, GeneratorContext context, String typeName)
        throws UnableToCompleteException {
    TypeOracle oracle = context.getTypeOracle();
    this.templatesInterface = oracle.findType(Name.getSourceNameForClass(Template.class));

    JClassType interfaceType;//from w w w .  j  ava2 s  .c o  m
    try {
        interfaceType = oracle.getType(typeName);
    } catch (NotFoundException e) {
        throw new RuntimeException(e);
    }

    if (interfaceType.isInterface() == null) {
        logger.log(TreeLogger.ERROR, typeName + " is not an interface type");
        throw new UnableToCompleteException();
    }
    if (!interfaceType.isAssignableTo(templatesInterface)) {
        logger.log(Type.ERROR, "This isn't a Template subtype...");
        throw new UnableToCompleteException();
    }

    String content = getTemplateContent(context, logger, interfaceType);
    String packageName = interfaceType.getPackage().getName();
    String className = "Tpl_For_" + interfaceType.getQualifiedSourceName().replace(".", "_") + "_Generated";

    ClassSourceFileComposerFactory composer = new ClassSourceFileComposerFactory(packageName, className);
    composer.addImport(SafeHtml.class.getName());
    composer.addImport(SafeHtmlUtils.class.getName());
    composer.addImplementedInterface(Template.class.getName());

    PrintWriter pw = context.tryCreate(logger, packageName, className);

    if (pw != null) {
        SourceWriter sw = composer.createSourceWriter(context, pw);

        sw.println("  public SafeHtml getContent(){");
        sw.println("      return SafeHtmlUtils.fromSafeConstant(\"" + content + "\");");
        sw.println("  }");
        sw.println("");
        sw.println("");
        sw.println("  public SafeHtml getSafeContent(){");
        sw.println("      return SafeHtmlUtils.fromString(\"" + content + "\");");
        sw.println("  }");

        sw.commit(logger);
    }

    return composer.getCreatedClassName();

}

From source file:com.ait.toolkit.rebind.TemplateGenerator.java

License:Open Source License

protected InputStream getTemplateResource(GeneratorContext context, TreeLogger l, String markerPath)
        throws UnableToCompleteException {
    // look for a local file first
    String path = slashify(markerPath);
    l.log(Type.INFO, "Current resource path : " + markerPath);
    Resource res = context.getResourcesOracle().getResourceMap().get(path);
    // if not a local path, try an absolute one
    if (res == null) {
        l.log(Type.INFO, "Resource is Null trying with URL ");
        URL url = Thread.currentThread().getContextClassLoader().getResource(markerPath);
        if (url == null) {
            l.log(Type.INFO, "URL seems to be null here ... hmmmmss");
            return null;
        } else {// w w w.  j  a v  a 2  s .  c  o m
            l.log(Type.INFO, "URL seems to be NOT null.");
        }
        try {
            return url.openStream();
        } catch (IOException e) {
            l.log(Type.ERROR, "IO Exception occured", e);
            throw new UnableToCompleteException();
        }
    }
    try {
        return res.openContents();
    } catch (Exception e) {
        l.log(Type.ERROR, "Exception occured reading " + path, e);
        throw new UnableToCompleteException();
    }
}

From source file:com.arcbees.gwtpolymer.rebind.RebindModule.java

License:Apache License

@Provides
@Singleton//  ww  w. jav a  2  s .c om
VelocityEngine getVelocityEngine(@Named("VELOCITY_PROPERTIES") String velocityProperties, TreeLogger logger)
        throws UnableToCompleteException {
    try {
        Properties properties = new Properties();
        try (InputStream inputStream = getClass().getClassLoader().getResourceAsStream(velocityProperties)) {
            properties.load(inputStream);
            return new VelocityEngine(properties);
        } catch (Exception e) {
            logger.log(TreeLogger.Type.ERROR, "Cannot load velocity properties from " + velocityProperties);
            throw new UnableToCompleteException();
        }
    } catch (Exception e) {
        logger.log(TreeLogger.Type.ERROR, e.getMessage(), e);
    }

    return null;
}

From source file:com.artemis.gwtref.gen.ReflectionCacheGenerator.java

License:Apache License

@Override
public String generate(TreeLogger logger, GeneratorContext context, String typeName)
        throws UnableToCompleteException {
    TypeOracle oracle = context.getTypeOracle();
    assert (oracle != null);
    JClassType type = oracle.findType(typeName);
    if (type == null) {
        logger.log(ERROR, "Couldn't find type '" + typeName + "'");
        throw new UnableToCompleteException();
    }/* w  ww  . j a  v a 2  s.c  o  m*/

    if (type.isInterface() == null) {
        logger.log(ERROR, "Type '" + typeName + "' must be an interface");
        throw new UnableToCompleteException();
    }

    ReflectionCacheSourceCreator source = new ReflectionCacheSourceCreator(logger, context, type);
    return source.create();
}

From source file:com.artemis.gwtref.gen.ReflectionCacheSourceCreator.java

License:Apache License

public ReflectionCacheSourceCreator(TreeLogger logger, GeneratorContext context, JClassType type) {
    this.logger = logger;
    this.context = context;
    this.type = type;
    this.packageName = type.getPackage().getName();
    this.simpleName = type.getSimpleSourceName() + "Generated";
    logger.log(Type.INFO, type.getQualifiedSourceName());
}

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;
    }/* w w  w.j ava2s  .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.bcdlog.SimpleAppCacheLinker.java

License:Apache License

/**
 * Creates the cache-manifest resource specific for the landing page.
 * //from  w  w  w  .  j a  v a 2 s .  co  m
 * @param context
 *            the linker environment
 * @param logger
 *            the tree logger to record to
 * @param artifacts
 *            {@code null} to generate an empty cache manifest
 */
private Artifact<?> emitLandingPageCacheManifest(LinkerContext context, TreeLogger logger,
        ArtifactSet artifacts) throws UnableToCompleteException {
    StringBuilder publicSourcesSb = new StringBuilder();
    StringBuilder staticResoucesSb = new StringBuilder();

    if (artifacts != null) {
        // Iterate over all emitted artifacts, and collect all cacheable
        // artifacts
        for (@SuppressWarnings("rawtypes")
        Artifact artifact : artifacts) {
            if (artifact instanceof EmittedArtifact) {
                EmittedArtifact ea = (EmittedArtifact) artifact;
                String pathName = ea.getPartialPath();
                if (pathName.endsWith("symbolMap") || pathName.endsWith(".xml.gz")
                        || pathName.endsWith("rpc.log") || pathName.endsWith("gwt.rpc")
                        || pathName.endsWith("manifest.txt") || pathName.startsWith("rpcPolicyManifest")) {
                    // skip these resources
                } else {
                    publicSourcesSb.append(pathName + "\n");
                }
            }
        }

        String[] cacheExtraFiles = getCacheExtraFiles();
        for (int i = 0; i < cacheExtraFiles.length; i++) {
            staticResoucesSb.append(cacheExtraFiles[i]);
            staticResoucesSb.append("\n");
        }
    }

    // build cache list
    StringBuilder sb = new StringBuilder();
    sb.append("CACHE MANIFEST\n");
    sb.append("# Unique id #" + (new Date()).getTime() + "." + Math.random() + "\n");
    // we have to generate this unique id because the resources can change
    // but
    // the hashed cache.html files can remain the same.
    sb.append("# Note: must change this every time for cache to invalidate\n");
    sb.append("\n");
    sb.append("CACHE:\n");
    sb.append("# Static app files\n");
    sb.append(staticResoucesSb.toString());
    sb.append("\n# Generated app files\n");
    sb.append(publicSourcesSb.toString());
    sb.append("\n\n");
    sb.append("# All other resources require the user to be online.\n");
    sb.append("NETWORK:\n");
    sb.append("*\n");

    logger.log(TreeLogger.INFO, "Be sure your landing page's <html> tag declares a manifest:"
            + " <html manifest=" + context.getModuleFunctionName() + "/" + MANIFEST + "\">");

    // Create the manifest as a new artifact and return it:
    return emitString(logger, sb.toString(), MANIFEST);
}