use of com.thecoderscorner.menu.persist.VersionInfo in project tcMenu by davetcc.
the class CodeGeneratorCommand method call.
@Override
public Integer call() {
try {
var project = projectFileOrNull(projectFile);
System.out.format("Starting code generator for %s\n", project.getOptions().getApplicationName());
var prefsStore = new PrefsConfigurationStorage();
MenuEditorApp.createOrUpdateDirectoriesAsNeeded(prefsStore);
prefsStore.setLastRunVersion(new VersionInfo(prefsStore.getVersion()));
var platforms = new PluginEmbeddedPlatformsImpl();
DefaultXmlPluginLoader loader = new DefaultXmlPluginLoader(platforms, prefsStore, true);
loader.loadPlugins();
platforms.setInstallerConfiguration(new ArduinoLibraryInstaller(new OfflineDetector(), loader, prefsStore), prefsStore);
var embeddedPlatform = platforms.getEmbeddedPlatformFromId(project.getOptions().getEmbeddedPlatform());
var codeGen = platforms.getCodeGeneratorFor(embeddedPlatform, project.getOptions());
System.out.println("Preparing to execute generator");
List<CodePluginItem> allPlugins = loader.getLoadedPlugins().stream().flatMap(pluginLib -> pluginLib.getPlugins().stream()).collect(Collectors.toList());
List<CodePluginItem> plugins = new ArrayList<>();
plugins.add(getPluginOrDefault(allPlugins, project.getOptions().getLastInputUuid(), DEFAULT_INPUT_PLUGIN));
plugins.add(getPluginOrDefault(allPlugins, project.getOptions().getLastDisplayUuid(), DEFAULT_DISPLAY_PLUGIN));
for (var plugin : project.getOptions().getLastRemoteCapabilitiesUuids()) {
plugins.add(getPluginOrDefault(allPlugins, plugin, DEFAULT_REMOTE_PLUGIN));
}
if (project.getOptions().getLastThemeUuid() != null) {
plugins.add(getPluginOrDefault(allPlugins, project.getOptions().getLastThemeUuid(), DEFAULT_THEME_PLUGIN));
}
System.out.format("Executing code generator");
var location = Paths.get(loadedProjectFile.getParent());
codeGen.setLoggerFunction((level, s) -> {
if (verbose)
System.out.format("Gen: %s: %s\n", level, s);
});
codeGen.startConversion(location, plugins, project.getMenuTree(), Collections.emptyList(), project.getOptions());
return 0;
} catch (Exception ex) {
System.out.println("Error during code generation " + ex.getClass().getSimpleName() + " " + ex.getMessage());
if (verbose) {
ex.printStackTrace();
}
return -1;
}
}
Aggregations