Search in sources :

Example 1 with PropertyOracle

use of com.google.gwt.core.ext.PropertyOracle in project gwtphonegap by dankurka.

the class PhoneGapLogThresholdGenerator method generate.

@Override
public String generate(TreeLogger logger, GeneratorContext context, String typeName) throws UnableToCompleteException {
    PropertyOracle propertyOracle = context.getPropertyOracle();
    ConfigurationProperty property = null;
    String level = "INFO";
    try {
        property = propertyOracle.getConfigurationProperty("phonegap.logging.threshold");
        List<String> values = property.getValues();
        if (values.size() < 1) {
            logger.log(TreeLogger.WARN, "can not resolve phonegap.logging.threshold variable - defaulting to INFO");
        } else {
            level = values.get(0);
        }
    } catch (BadPropertyValueException e) {
        logger.log(TreeLogger.WARN, "can not resolve phonegap.logging.threshold variable - defaulting to INFO", e);
    }
    if ("INFO".equalsIgnoreCase(level)) {
        return BASE + ".Info";
    }
    if ("ALL".equalsIgnoreCase(level)) {
        return BASE + ".Info";
    }
    if ("FINEST".equalsIgnoreCase(level)) {
        return BASE + ".Finest";
    }
    if ("FINER".equalsIgnoreCase(level)) {
        return BASE + ".Finer";
    }
    if ("FINE".equalsIgnoreCase(level)) {
        return BASE + ".Fine";
    }
    if ("CONFIG".equalsIgnoreCase(level)) {
        return BASE + ".Config";
    }
    if ("WARNING".equalsIgnoreCase(level)) {
        return BASE + ".Warning";
    }
    if ("SEVERE".equalsIgnoreCase(level)) {
        return BASE + ".Severe";
    }
    if ("SEVERE".equalsIgnoreCase(level)) {
        return BASE + ".All";
    }
    logger.log(TreeLogger.WARN, "unkown value for phonegap.logging.threshold: '" + level + "' - defaulting to INFO");
    return BASE + ".Info";
}
Also used : ConfigurationProperty(com.google.gwt.core.ext.ConfigurationProperty) BadPropertyValueException(com.google.gwt.core.ext.BadPropertyValueException) PropertyOracle(com.google.gwt.core.ext.PropertyOracle)

Example 2 with PropertyOracle

use of com.google.gwt.core.ext.PropertyOracle in project gwtphonegap by dankurka.

the class PhoneGapLogValueGenerator method generate.

@Override
public String generate(TreeLogger logger, GeneratorContext context, String typeName) throws UnableToCompleteException {
    PropertyOracle propertyOracle = context.getPropertyOracle();
    ConfigurationProperty property = null;
    int value = 100;
    try {
        property = propertyOracle.getConfigurationProperty("phonegap.logging.maxentries");
        List<String> values = property.getValues();
        if (values.size() < 1) {
            logger.log(TreeLogger.WARN, "can not resolve phonegap.logging.maxentries variable - defaulting to 100");
        } else {
            String stringValue = values.get(0);
            try {
                value = Integer.parseInt(stringValue);
            } catch (Exception e) {
                logger.log(TreeLogger.WARN, "can not prase phonegap.logging.maxentries variable - value: '" + stringValue + "' - defaulting to 100");
            }
        }
    } catch (BadPropertyValueException e) {
        logger.log(TreeLogger.WARN, "can not resolve phonegap.logging.maxentries variable - defaulting to 100", e);
    }
    JClassType classType = null;
    try {
        classType = context.getTypeOracle().getType(typeName);
    } catch (NotFoundException e) {
        logger.log(TreeLogger.ERROR, "can not find type: '" + typeName + "'", e);
        throw new UnableToCompleteException();
    }
    String packageName = classType.getPackage().getName();
    String simpleName = classType.getSimpleSourceName() + "_" + value;
    String fullName = packageName + "." + simpleName;
    ClassSourceFileComposerFactory composer = new ClassSourceFileComposerFactory(packageName, simpleName);
    composer.addImplementedInterface(typeName);
    composer.addImport(typeName);
    PrintWriter printWriter = context.tryCreate(logger, packageName, simpleName);
    if (printWriter == null) {
        return fullName;
    }
    SourceWriter writer = composer.createSourceWriter(context, printWriter);
    writer.println("public int getMaxEntries() {");
    writer.println("return " + value + ";");
    writer.println("}");
    writer.commit(logger);
    return fullName;
}
Also used : ConfigurationProperty(com.google.gwt.core.ext.ConfigurationProperty) ClassSourceFileComposerFactory(com.google.gwt.user.rebind.ClassSourceFileComposerFactory) NotFoundException(com.google.gwt.core.ext.typeinfo.NotFoundException) SourceWriter(com.google.gwt.user.rebind.SourceWriter) UnableToCompleteException(com.google.gwt.core.ext.UnableToCompleteException) BadPropertyValueException(com.google.gwt.core.ext.BadPropertyValueException) NotFoundException(com.google.gwt.core.ext.typeinfo.NotFoundException) JClassType(com.google.gwt.core.ext.typeinfo.JClassType) UnableToCompleteException(com.google.gwt.core.ext.UnableToCompleteException) BadPropertyValueException(com.google.gwt.core.ext.BadPropertyValueException) PropertyOracle(com.google.gwt.core.ext.PropertyOracle) PrintWriter(java.io.PrintWriter)

Aggregations

BadPropertyValueException (com.google.gwt.core.ext.BadPropertyValueException)2 ConfigurationProperty (com.google.gwt.core.ext.ConfigurationProperty)2 PropertyOracle (com.google.gwt.core.ext.PropertyOracle)2 UnableToCompleteException (com.google.gwt.core.ext.UnableToCompleteException)1 JClassType (com.google.gwt.core.ext.typeinfo.JClassType)1 NotFoundException (com.google.gwt.core.ext.typeinfo.NotFoundException)1 ClassSourceFileComposerFactory (com.google.gwt.user.rebind.ClassSourceFileComposerFactory)1 SourceWriter (com.google.gwt.user.rebind.SourceWriter)1 PrintWriter (java.io.PrintWriter)1