use of com.developmentontheedge.be5.metadata.model.FreemarkerCatalog in project be5 by DevelopmentOnTheEdge.
the class ProjectGenerator method addIncludes.
public static void addIncludes(final Project project) {
final StringBuilder sb = new StringBuilder();
for (final Module module : project.getModules()) {
final FreemarkerCatalog collection = module.getMacroCollection();
if (collection == null)
continue;
final FreemarkerScript script = collection.optScript(FreemarkerCatalog.MAIN_MACRO_LIBRARY);
if (script == null)
continue;
sb.append("<#include \"../../Modules/" + module.getName() + "/Macros/common\"/>\n");
}
final String includes = sb.toString();
if (!includes.isEmpty()) {
final FreemarkerScript script = new FreemarkerScript(FreemarkerCatalog.MAIN_MACRO_LIBRARY, project.getMacroCollection());
script.setSource(includes);
DataElementUtils.saveQuiet(script);
}
}
use of com.developmentontheedge.be5.metadata.model.FreemarkerCatalog in project be5 by DevelopmentOnTheEdge.
the class YamlSerializer method serialize.
private List<Object> serialize(final FreemarkerCatalog scripts, Function<String, Path> getPath, final boolean serializeReferencedFiles) throws WriteException {
List<Object> paths = list();
for (final FreemarkerScript script : scripts.getScripts()) {
try {
String relativePath = script.getRelativePath(scripts);
if (serializeReferencedFiles) {
final Path scriptFile = getPath.apply(relativePath);
if (!Files.exists(scriptFile.getParent()))
Files.createDirectories(scriptFile.getParent());
if (!script.isLoaded())
continue;
write(scriptFile, script);
script.setLinkedFile(scriptFile);
}
paths.add(relativePath);
} catch (final Exception e) {
throw new WriteException(script, e);
}
}
return paths;
}
use of com.developmentontheedge.be5.metadata.model.FreemarkerCatalog in project be5 by DevelopmentOnTheEdge.
the class AppData method execute.
@Override
public void execute() throws MojoFailureException {
init();
PrintStream ps = null;
try {
if (logPath != null) {
logPath.mkdirs();
ps = new PrintStream(new File(logPath, be5Project.getName() + "_scripts_" + script.replace(';', '_').replace(':', '.') + ".sql"), "UTF-8");
}
ModuleLoader2.addModuleScripts(be5Project);
List<FreemarkerScript> scripts = new ArrayList<>();
for (String scriptName : script.split(";")) {
int pos = scriptName.indexOf(':');
FreemarkerCatalog scriptsCatalog = be5Project.getApplication().getFreemarkerScripts();
if (pos > 0) {
String moduleName = scriptName.substring(0, pos);
scriptName = scriptName.substring(pos + 1);
if (moduleName.equals("all")) {
for (Module module : be5Project.getModules()) {
scriptsCatalog = module.getFreemarkerScripts();
if (scriptsCatalog == null)
continue;
FreemarkerScript script = scriptsCatalog.optScript(scriptName);
if (script == null)
continue;
scripts.add(script);
}
FreemarkerScript script = be5Project.getApplication().getFreemarkerScripts().optScript(scriptName);
if (script != null) {
scripts.add(script);
}
continue;
} else {
Module module = be5Project.getModule(moduleName);
if (module == null) {
if (ignoreMissing) {
System.err.println("Warning: module '" + moduleName + "' not found");
continue;
} else
throw new MojoFailureException("Module '" + moduleName + "' not found");
}
scriptsCatalog = module.getFreemarkerScripts();
}
}
FreemarkerScript freemarkerScript = scriptsCatalog == null ? null : scriptsCatalog.optScript(scriptName);
if (freemarkerScript == null) {
if (ignoreMissing) {
System.err.println("Warning: FTL script " + scriptName + " not found");
continue;
} else
throw new MojoFailureException("FTL script " + scriptName + " not found");
}
scripts.add(freemarkerScript);
}
SqlExecutor sqlExecutor = new BeSqlExecutor(connector, ps);
for (FreemarkerScript freemarkerScript : scripts) {
executeScript(sqlExecutor, freemarkerScript);
}
DatabaseUtils.clearAllCache(sqlExecutor);
} catch (ProjectElementException | FreemarkerSqlException e) {
throw new MojoFailureException(e.getMessage(), e);
} catch (Exception e) {
throw new MojoFailureException(e.getMessage(), e);
} finally {
if (ps != null) {
ps.close();
}
}
}
use of com.developmentontheedge.be5.metadata.model.FreemarkerCatalog in project be5 by DevelopmentOnTheEdge.
the class YamlDeserializer method readMacroFiles.
private void readMacroFiles(BaseDeserializer deserializer, Map<String, Object> serializedModuleBody, FreemarkerCatalog macroFiles) throws ReadException {
final Object includes = serializedModuleBody.get(TAG_MACRO_FILES);
if (includes == null)
return;
for (final String scriptName : deserializer.asStrList(includes)) {
final Path macroFile = getFileSystem().getMacroFile(scriptName);
try {
final FreemarkerScript script = new FreemarkerScript(scriptName, macroFiles);
if (Files.exists(macroFile)) {
script.setLinkedFile(macroFile);
script.getTemplateCode();
}
DataElementUtils.saveQuiet(script);
} catch (final Exception e) {
loadContext.addWarning(new ReadException(e, macroFiles.getCompletePath().getChildPath(scriptName), macroFile));
}
}
}
use of com.developmentontheedge.be5.metadata.model.FreemarkerCatalog in project be5 by DevelopmentOnTheEdge.
the class FreemarkerUtils method getConfiguration.
public static Configuration getConfiguration(Project project) {
Configuration config = (Configuration) configTemplate.clone();
config.setCacheStorage(new SoftCacheStorage());
try {
config.setSharedVariable("project", project);
} catch (TemplateModelException e) {
throw new RuntimeException("Unexpected error: " + e, e);
}
FreemarkerScript macroCollection = project.getMacroCollection().optScript(FreemarkerCatalog.MAIN_MACRO_LIBRARY);
if (macroCollection != null) {
config.addAutoInclude(macroCollection.getCompletePath().toString());
}
for (Module module : project.getModules()) {
FreemarkerCatalog collection = module.getMacroCollection();
if (collection != null) {
FreemarkerScript script = collection.optScript(FreemarkerCatalog.MAIN_MACRO_LIBRARY);
if (script != null) {
config.addAutoInclude(script.getCompletePath().toString());
}
}
}
config.setTemplateLoader(new ProjectTemplateLoader(project));
return config;
}
Aggregations