use of com.google.gwt.core.ext.BadPropertyValueException 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";
}
use of com.google.gwt.core.ext.BadPropertyValueException 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;
}
Aggregations