use of freemarker.template.TemplateModel in project be5 by DevelopmentOnTheEdge.
the class FtlToYaml method ftlToHash.
public static LinkedHashMap<String, Object> ftlToHash(TemplateHashModelEx model) throws TemplateModelException {
LinkedHashMap<String, Object> result = new LinkedHashMap<>();
TemplateCollectionModel keys = model.keys();
TemplateModelIterator iterator = keys.iterator();
while (iterator.hasNext()) {
TemplateModel next = iterator.next();
if (!(next instanceof TemplateScalarModel)) {
throw new TemplateModelException("Invalid key: " + next);
}
String key = ((TemplateScalarModel) next).getAsString();
TemplateModel value = model.get(key);
try {
result.put(key, ftlToObject(value));
} catch (TemplateModelException e) {
throw new TemplateModelException(key + ": " + e.getMessage(), e);
}
}
return result;
}
use of freemarker.template.TemplateModel in project openj9 by eclipse.
the class UMA method generate.
public void generate() throws UMAException {
Parser parser = new Parser(this);
if (!parser.parse()) {
return;
}
modules = parser.getModules();
platform.decorateModules(modules);
try {
Map<String, TemplateModel> map = new HashMap<String, TemplateModel>();
map.put(FREEMARKER_UMA, new com.ibm.uma.freemarker.UMA());
for (String tmp : templateLoader.getTemplates()) {
Template template = freemarkerConfig.getTemplate(tmp);
String filename = tmp.substring(0, tmp.lastIndexOf(".ftl"));
StringWriter writer = new StringWriter();
template.process(map, writer);
new FileAssistant(this.rootDirectory + filename, writer.getBuffer()).writeToDisk();
}
} catch (IOException e) {
throw new UMAException(e);
} catch (TemplateException e) {
throw new UMAException(e);
}
writeTargetInformationMacrosFile();
// top level module is the first in the list.
Module rootModule = null;
for (Module module : modules) {
if (module.isTopLevel()) {
if (rootModule != null) {
throw new UMAException("Error: more than one root module " + rootModule.getFullName() + " and " + module.getFullName());
}
rootModule = module;
}
}
if (rootModule == null) {
throw new UMAException("Error: no " + configuration.getMetadataFilename() + " found in the root directory " + getRootDirectory());
}
writeDirectoryMakefile(rootModule);
Logger.getLogger().println(Logger.InformationL1Log, "Complete");
}
use of freemarker.template.TemplateModel in project openj9 by eclipse.
the class Spec method get.
public TemplateModel get(String arg0) throws TemplateModelException {
if (arg0.equals("flags")) {
return new Flags();
}
if (arg0.equals("tools")) {
return new Tools();
}
if (arg0.equals("properties")) {
return new Properties();
}
if (arg0.equals("artifacts")) {
return new Artifacts(UMA.getUma().getArtifacts());
}
if (arg0.equals("type")) {
return new Type();
}
if (arg0.equals("processor")) {
return new Processor();
}
try {
TemplateModel platformExtension = com.ibm.uma.UMA.getUma().getPlatform().getDataModelExtension("uma.spec", arg0);
if (platformExtension != null)
return platformExtension;
TemplateModel configurationExtension = com.ibm.uma.UMA.getUma().getConfiguration().getDataModelExtension("uma.spec", arg0);
if (configurationExtension != null)
return configurationExtension;
} catch (UMAException e) {
throw new TemplateModelException(e);
}
return null;
}
use of freemarker.template.TemplateModel in project openj9 by eclipse.
the class Flag method get.
public TemplateModel get(String arg0) throws TemplateModelException {
if (arg0.equals("name")) {
return new SimpleScalar(flag);
}
if (arg0.equals("enabled")) {
return new BooleanModel(UMA.getUma().getConfiguration().isFlagSet(flag), new BeansWrapper());
}
try {
TemplateModel platformExtension = com.ibm.uma.UMA.getUma().getPlatform().getDataModelExtension("uma.spec.flags." + flag, arg0);
if (platformExtension != null)
return platformExtension;
TemplateModel configurationExtension = com.ibm.uma.UMA.getUma().getConfiguration().getDataModelExtension("uma.spec.flags." + flag, arg0);
if (configurationExtension != null)
return configurationExtension;
} catch (UMAException e) {
throw new TemplateModelException(e);
}
return null;
}
use of freemarker.template.TemplateModel in project openj9 by eclipse.
the class Artifact method get.
public TemplateModel get(String arg0) throws TemplateModelException {
try {
if (arg0.equals("name")) {
return new ArtifactName(artifact);
}
if (arg0.equals("data")) {
return new ArtifactData(artifact);
}
if (arg0.equals("targetNameWithRelease")) {
return new SimpleScalar(UMA.getUma().getPlatform().getTargetNameWithRelease(artifact));
}
if (arg0.equals("exportNames")) {
return new ExportNames(artifact);
}
if (arg0.equals("bundledArtifacts")) {
return new Artifacts(artifact.getAllArtifactsInThisBundleInHashtable());
}
TemplateModel platformExtension = com.ibm.uma.UMA.getUma().getPlatform().getDataModelExtension("uma.spec.flags." + artifact.getTargetName(), arg0);
if (platformExtension != null)
return platformExtension;
TemplateModel configurationExtension = com.ibm.uma.UMA.getUma().getConfiguration().getDataModelExtension("uma.spec.flags." + artifact.getTargetName(), arg0);
if (configurationExtension != null)
return configurationExtension;
return null;
} catch (UMAException e) {
throw new TemplateModelException(e);
}
}
Aggregations