#include "utility/sonargraph/SonargraphProject.h" #include "tinyxml/tinyxml.h" #include "utility/sonargraph/SonargraphSoftwareSystem.h" #include "utility/logging/logging.h" #include "utility/text/TextAccess.h" #include "utility/utilityString.h" #include "utility/utilityXml.h" namespace Sonargraph { std::shared_ptr Project::load(const FilePath& projectFilePath, LanguageType targetLanguage) { return load(TextAccess::createFromFile(projectFilePath), targetLanguage); } std::shared_ptr Project::load(std::shared_ptr xmlAccess, LanguageType targetLanguage) { if (!xmlAccess) { return std::shared_ptr(); } std::shared_ptr project = std::shared_ptr(new Project()); TiXmlDocument doc; doc.Parse(xmlAccess->getText().c_str(), 0, TIXML_ENCODING_UTF8); if (doc.Error()) { LOG_ERROR( "Unable to parse Sonargraph project because of an error in row " + std::to_string(doc.ErrorRow()) + ", col " + std::to_string(doc.ErrorCol()) + ": " + std::string(doc.ErrorDesc()) ); return std::shared_ptr(); } TiXmlHandle docHandle(&doc); TiXmlElement* softwareSystemElement = docHandle.FirstChildElement("ns2:softwareSystem").ToElement(); if (softwareSystemElement == nullptr) { LOG_ERROR("Unable to find \"ns2:softwareSystem\" in Sonargraph project."); return std::shared_ptr(); } std::shared_ptr softwareSystem = SoftwareSystem::create( softwareSystemElement, xmlAccess->getFilePath().getParentDirectory().getParentDirectory(), targetLanguage ); if (!softwareSystem) { return std::shared_ptr(); } project->m_softwareSystem = softwareSystem; return project; } int Project::getLoadedModuleCount() const { return m_softwareSystem->getModules().size(); } std::set Project::getAllSourceFilePathsCanonical() const { return m_softwareSystem->getAllSourceFilePathsCanonical(); } std::set Project::getAllCxxHeaderSearchPathsCanonical() const { return m_softwareSystem->getAllCxxHeaderSearchPathsCanonical(); } std::vector> Project::getIndexerCommands( std::shared_ptr sourceGroupSettings, std::shared_ptr appSettings) const { return m_softwareSystem->getIndexerCommands(sourceGroupSettings, appSettings); } }