List of usage examples for com.google.gwt.i18n.rebind LocaleUtils getAllCompileLocales
public Set<GwtLocale> getAllCompileLocales()
From source file:org.jboss.hal.config.rebind.EnvironmentGenerator.java
License:Apache License
private void generateProductInfo(final TreeLogger logger, final GeneratorContext generatorContext) { // get print writer that receives the source code PrintWriter printWriter = generatorContext.tryCreate(logger, PRODUCT_INFO_PACKAGE, PRODUCT_INFO_CLASS); // print writer if null, source code has ALREADY been generated, return if (printWriter == null) { return;//w w w . ja va2s .c o m } String halVersion = failSafeGetProperty(generatorContext.getPropertyOracle(), "hal.version", "0.0.0"); String halBuild = failSafeGetProperty(generatorContext.getPropertyOracle(), "hal.build", null); LocaleUtils localeUtils = LocaleUtils.getInstance(logger, generatorContext.getPropertyOracle(), generatorContext); Set<GwtLocale> locales = localeUtils.getAllCompileLocales(); List<String> localeValues = locales.stream().map(GwtLocale::getAsString) .filter(locale -> !Strings.isNullOrEmpty(locale)).collect(Collectors.toList()); StringBuffer code = generator.generate(PRODUCT_INFO_TEMPLATE, () -> { Map<String, Object> context = new HashMap<>(); context.put("packageName", PRODUCT_INFO_PACKAGE); context.put("className", PRODUCT_INFO_CLASS); context.put("halVersion", halVersion); context.put("halBuild", halBuild); context.put("locales", localeValues); return context; }); printWriter.write(code.toString()); generatorContext.commit(logger, printWriter); }
From source file:org.jboss.hal.config.rebind.ProductInfoGenerator.java
License:Open Source License
@Override protected String generate(final TreeLogger logger, final GeneratorContext context) { String halVersion = failSafeGetProperty(context.getPropertyOracle(), "hal.version", "n/a"); String variantValue = failSafeGetProperty(context.getPropertyOracle(), "hal.variant", "COMMUNITY") .toUpperCase();//w ww . j a v a 2 s . c o m Variant variant; try { variant = Variant.valueOf(variantValue); } catch (IllegalArgumentException e) { variant = Variant.COMMUNITY; } LocaleUtils localeUtils = LocaleUtils.getInstance(logger, context.getPropertyOracle(), context); Set<GwtLocale> locales = localeUtils.getAllCompileLocales(); List<String> localeValues = new ArrayList<>(); for (GwtLocale locale : locales) { if (locale.getAsString() != null && locale.getAsString().length() != 0) { localeValues.add(locale.getAsString()); } } return ClassBuilder.define(PACKAGE_NAME + "." + CLASS_NAME, AbstractProductInfo.class).publicScope() .implementsInterface(ProductInfo.class).body().publicConstructor() .callSuper(Stmt.loadLiteral(variant), Stmt.loadLiteral(halVersion), Stmt.loadLiteral(localeValues)) .finish().toJavaString(); }