diff --git a/bin/app/user/projects/javaparser/javaparser.srctrlprj b/bin/app/user/projects/javaparser/javaparser.srctrlprj index 4544ffa5..c86ffc4d 100644 --- a/bin/app/user/projects/javaparser/javaparser.srctrlprj +++ b/bin/app/user/projects/javaparser/javaparser.srctrlprj @@ -17,6 +17,7 @@ + 8 Javaparser Source Group .java @@ -25,11 +26,10 @@ ./src/main/java ./target/generated-sources/javacc - 8 enabled Java Source Group 1 - 6 + 7 diff --git a/bin/app/user/projects/tictactoe/tictactoe.srctrlprj b/bin/app/user/projects/tictactoe/tictactoe.srctrlprj index b0b097a7..b1049400 100644 --- a/bin/app/user/projects/tictactoe/tictactoe.srctrlprj +++ b/bin/app/user/projects/tictactoe/tictactoe.srctrlprj @@ -2,6 +2,7 @@ + c++2a unknown @@ -21,10 +22,9 @@ ./src - c++2a enabled C++ Source Group - 6 + 7 diff --git a/bin/app/user/projects/tutorial/tutorial.srctrlprj b/bin/app/user/projects/tutorial/tutorial.srctrlprj index 1dd95ab2..9085f23a 100644 --- a/bin/app/user/projects/tutorial/tutorial.srctrlprj +++ b/bin/app/user/projects/tutorial/tutorial.srctrlprj @@ -17,6 +17,7 @@ + c++2a unknown @@ -33,10 +34,9 @@ ./src - c++2a enabled C++ Source Group - 6 + 7 diff --git a/src/lib/CMakeLists.txt b/src/lib/CMakeLists.txt index a614a32d..633cf90e 100644 --- a/src/lib/CMakeLists.txt +++ b/src/lib/CMakeLists.txt @@ -316,8 +316,14 @@ add_files( settings/SourceGroupSettings.h settings/SourceGroupSettingsCxx.cpp settings/SourceGroupSettingsCxx.h + settings/SourceGroupSettingsCEmpty.cpp + settings/SourceGroupSettingsCEmpty.h + settings/SourceGroupSettingsCppEmpty.cpp + settings/SourceGroupSettingsCppEmpty.h settings/SourceGroupSettingsCxxCdb.cpp settings/SourceGroupSettingsCxxCdb.h + settings/SourceGroupSettingsCxxCodeblocks.cpp + settings/SourceGroupSettingsCxxCodeblocks.h settings/SourceGroupSettingsCxxEmpty.cpp settings/SourceGroupSettingsCxxEmpty.h settings/SourceGroupSettingsCxxSonargraph.cpp @@ -334,12 +340,20 @@ add_files( settings/SourceGroupSettingsJavaSonargraph.h settings/SourceGroupSettingsWithClasspath.cpp settings/SourceGroupSettingsWithClasspath.h + settings/SourceGroupSettingsWithCppStandard.cpp + settings/SourceGroupSettingsWithCppStandard.h + settings/SourceGroupSettingsWithCStandard.cpp + settings/SourceGroupSettingsWithCStandard.h settings/SourceGroupSettingsWithExcludeFilters.cpp settings/SourceGroupSettingsWithExcludeFilters.h settings/SourceGroupSettingsWithIndexedHeaderPaths.cpp settings/SourceGroupSettingsWithIndexedHeaderPaths.h + settings/SourceGroupSettingsWithJavaStandard.cpp + settings/SourceGroupSettingsWithJavaStandard.h settings/SourceGroupSettingsWithSonargraphProjectPath.cpp settings/SourceGroupSettingsWithSonargraphProjectPath.h + settings/SourceGroupSettingsWithSourceExtensions.cpp + settings/SourceGroupSettingsWithSourceExtensions.h settings/SourceGroupSettingsWithSourcePaths.cpp settings/SourceGroupSettingsWithSourcePaths.h settings/SourceGroupStatusType.cpp diff --git a/src/lib/settings/LanguageType.cpp b/src/lib/settings/LanguageType.cpp index d1172485..57aaa85a 100644 --- a/src/lib/settings/LanguageType.cpp +++ b/src/lib/settings/LanguageType.cpp @@ -43,6 +43,8 @@ LanguageType getLanguageTypeForSourceGroupType(SourceGroupType t) return LANGUAGE_CPP; case SOURCE_GROUP_CXX_CDB: return LANGUAGE_CPP; + case SOURCE_GROUP_CXX_CODEBLOCKS: + return LANGUAGE_CPP; case SOURCE_GROUP_CXX_SONARGRAPH: return LANGUAGE_CPP; case SOURCE_GROUP_CXX_VS: diff --git a/src/lib/settings/ProjectSettings.cpp b/src/lib/settings/ProjectSettings.cpp index b1949b40..568abbf7 100644 --- a/src/lib/settings/ProjectSettings.cpp +++ b/src/lib/settings/ProjectSettings.cpp @@ -3,8 +3,10 @@ #include "settings/migration/SettingsMigrationDeleteKey.h" #include "settings/migration/SettingsMigrationLambda.h" #include "settings/migration/SettingsMigrationMoveKey.h" +#include "settings/SourceGroupSettingsCEmpty.h" +#include "settings/SourceGroupSettingsCppEmpty.h" #include "settings/SourceGroupSettingsCxxCdb.h" -#include "settings/SourceGroupSettingsCxxEmpty.h" +#include "settings/SourceGroupSettingsCxxCodeblocks.h" #include "settings/SourceGroupSettingsCxxSonargraph.h" #include "settings/SourceGroupSettingsJavaEmpty.h" #include "settings/SourceGroupSettingsJavaMaven.h" @@ -14,7 +16,7 @@ #include "utility/utilityString.h" #include "utility/utilityUuid.h" -const size_t ProjectSettings::VERSION = 6; +const size_t ProjectSettings::VERSION = 7; const wchar_t PROJECT_FILE_EXTENSION[] = L".srctrlprj"; LanguageType ProjectSettings::getLanguageOfProject(const FilePath& filePath) @@ -144,14 +146,17 @@ std::vector> ProjectSettings::getAllSourceG switch (type) { case SOURCE_GROUP_C_EMPTY: - settings = std::make_shared(id, SOURCE_GROUP_C_EMPTY, this); + settings = std::make_shared(id, this); break; case SOURCE_GROUP_CPP_EMPTY: - settings = std::make_shared(id, SOURCE_GROUP_CPP_EMPTY, this); + settings = std::make_shared(id, this); break; case SOURCE_GROUP_CXX_CDB: settings = std::make_shared(id, this); break; + case SOURCE_GROUP_CXX_CODEBLOCKS: + settings = std::make_shared(id, this); + break; case SOURCE_GROUP_CXX_SONARGRAPH: settings = std::make_shared(id, this); break; @@ -337,6 +342,26 @@ SettingsMigrator ProjectSettings::getMigrations() const } } + for (std::shared_ptr sourceGroupSettings : getAllSourceGroupSettings()) + { + std::string languageName; + switch (getLanguageTypeForSourceGroupType(sourceGroupSettings->getType())) + { + case LANGUAGE_C: + languageName = "c"; + break; + case LANGUAGE_CPP: + languageName = "cpp"; + break; + case LANGUAGE_JAVA: + languageName = "java"; + break; + } + + std::string key = SourceGroupSettings::s_keyPrefix + sourceGroupSettings->getId(); + migrator.addMigration(7, std::make_shared(key + "/standard", key + "/" + languageName + "_standard")); + } + return migrator; } diff --git a/src/lib/settings/SourceGroupSettings.cpp b/src/lib/settings/SourceGroupSettings.cpp index 79b0f22a..3ad5591f 100644 --- a/src/lib/settings/SourceGroupSettings.cpp +++ b/src/lib/settings/SourceGroupSettings.cpp @@ -14,7 +14,6 @@ SourceGroupSettings::SourceGroupSettings( , m_name(sourceGroupTypeToString(type)) , m_type(type) , m_status(SOURCE_GROUP_STATUS_ENABLED) - , m_standard("") { } @@ -29,7 +28,6 @@ void SourceGroupSettings::load(std::shared_ptr config) } setStatus(stringToSourceGroupStatusType(config->getValueOrDefault(key + "/status", sourceGroupStatusTypeToString(SOURCE_GROUP_STATUS_ENABLED)))); - setStandard(config->getValueOrDefault(key + "/standard", "")); } void SourceGroupSettings::save(std::shared_ptr config) @@ -38,7 +36,6 @@ void SourceGroupSettings::save(std::shared_ptr config) config->setValue(key + "/status", sourceGroupStatusTypeToString(getStatus())); config->setValue(key + "/name", getName()); - config->setValue(key + "/standard", getStandard()); } bool SourceGroupSettings::equals(std::shared_ptr other) const @@ -47,8 +44,7 @@ bool SourceGroupSettings::equals(std::shared_ptr other) con m_id == other->m_id && m_name == other->m_name && m_type == other->m_type && - m_status == other->m_status && - m_standard == other->m_standard + m_status == other->m_status ); } @@ -106,17 +102,3 @@ std::vector SourceGroupSettings::makePathsExpandedAndAbsolute(const st { return m_projectSettings->makePathsExpandedAndAbsolute(paths); } - -std::string SourceGroupSettings::getStandard() const -{ - if (m_standard.empty()) - { - return getDefaultStandard(); - } - return m_standard; -} - -void SourceGroupSettings::setStandard(const std::string& standard) -{ - m_standard = standard; -} diff --git a/src/lib/settings/SourceGroupSettings.h b/src/lib/settings/SourceGroupSettings.h index a6fe9cef..6f0782db 100644 --- a/src/lib/settings/SourceGroupSettings.h +++ b/src/lib/settings/SourceGroupSettings.h @@ -42,23 +42,14 @@ public: FilePath makePathExpandedAndAbsolute(const FilePath& path) const; std::vector makePathsExpandedAndAbsolute(const std::vector& paths) const; - virtual std::vector getAvailableLanguageStandards() const = 0; - - std::string getStandard() const; - void setStandard(const std::string& standard); - protected: const ProjectSettings* m_projectSettings; private: - virtual std::string getDefaultStandard() const = 0; - std::string m_id; std::string m_name; const SourceGroupType m_type; SourceGroupStatusType m_status; - - std::string m_standard; }; #endif // SOURCE_GROUP_SETTINGS_H diff --git a/src/lib/settings/SourceGroupSettingsCEmpty.cpp b/src/lib/settings/SourceGroupSettingsCEmpty.cpp new file mode 100644 index 00000000..ecf53b0f --- /dev/null +++ b/src/lib/settings/SourceGroupSettingsCEmpty.cpp @@ -0,0 +1,45 @@ +#include "settings/SourceGroupSettingsCEmpty.h" + +SourceGroupSettingsCEmpty::SourceGroupSettingsCEmpty(const std::string& id, const ProjectSettings* projectSettings) + : SourceGroupSettingsCxxEmpty(id, SOURCE_GROUP_C_EMPTY, projectSettings) +{ +} + +void SourceGroupSettingsCEmpty::load(std::shared_ptr config) +{ + SourceGroupSettingsCxxEmpty::load(config); + + const std::string key = s_keyPrefix + getId(); + + SourceGroupSettingsWithCStandard::load(config, key); +} + +void SourceGroupSettingsCEmpty::save(std::shared_ptr config) +{ + SourceGroupSettingsCxxEmpty::save(config); + + const std::string key = s_keyPrefix + getId(); + + SourceGroupSettingsWithCStandard::save(config, key); +} + +bool SourceGroupSettingsCEmpty::equals(std::shared_ptr other) const +{ + std::shared_ptr otherCxxEmpty = std::dynamic_pointer_cast(other); + + return ( + otherCxxEmpty && + SourceGroupSettingsCxxEmpty::equals(other) && + SourceGroupSettingsWithCStandard::equals(otherCxxEmpty) + ); +} + +const ProjectSettings* SourceGroupSettingsCEmpty::getProjectSettings() const +{ + return m_projectSettings; +} + +std::vector SourceGroupSettingsCEmpty::getDefaultSourceExtensions() const +{ + return { L".c" }; +} diff --git a/src/lib/settings/SourceGroupSettingsCEmpty.h b/src/lib/settings/SourceGroupSettingsCEmpty.h new file mode 100644 index 00000000..f0e38a05 --- /dev/null +++ b/src/lib/settings/SourceGroupSettingsCEmpty.h @@ -0,0 +1,24 @@ +#ifndef SOURCE_GROUP_SETTINGS_C_EMPTY_H +#define SOURCE_GROUP_SETTINGS_C_EMPTY_H + +#include "settings/SourceGroupSettingsCxxEmpty.h" +#include "settings/SourceGroupSettingsWithCStandard.h" + +class SourceGroupSettingsCEmpty + : public SourceGroupSettingsCxxEmpty + , public SourceGroupSettingsWithCStandard +{ +public: + SourceGroupSettingsCEmpty(const std::string& id, const ProjectSettings* projectSettings); + + void load(std::shared_ptr config) override; + void save(std::shared_ptr config) override; + + bool equals(std::shared_ptr other) const override; + +private: + const ProjectSettings* getProjectSettings() const override; + std::vector getDefaultSourceExtensions() const override; +}; + +#endif // SOURCE_GROUP_SETTINGS_C_EMPTY_H diff --git a/src/lib/settings/SourceGroupSettingsCppEmpty.cpp b/src/lib/settings/SourceGroupSettingsCppEmpty.cpp new file mode 100644 index 00000000..c6e86fc5 --- /dev/null +++ b/src/lib/settings/SourceGroupSettingsCppEmpty.cpp @@ -0,0 +1,49 @@ +#include "settings/SourceGroupSettingsCppEmpty.h" + +SourceGroupSettingsCppEmpty::SourceGroupSettingsCppEmpty(const std::string& id, const ProjectSettings* projectSettings) + : SourceGroupSettingsCxxEmpty(id, SOURCE_GROUP_CPP_EMPTY, projectSettings) +{ +} + +void SourceGroupSettingsCppEmpty::load(std::shared_ptr config) +{ + SourceGroupSettingsCxxEmpty::load(config); + + const std::string key = s_keyPrefix + getId(); + + SourceGroupSettingsWithCppStandard::load(config, key); +} + +void SourceGroupSettingsCppEmpty::save(std::shared_ptr config) +{ + SourceGroupSettingsCxxEmpty::save(config); + + const std::string key = s_keyPrefix + getId(); + + SourceGroupSettingsWithCppStandard::save(config, key); +} + +bool SourceGroupSettingsCppEmpty::equals(std::shared_ptr other) const +{ + std::shared_ptr otherCxxEmpty = std::dynamic_pointer_cast(other); + + return ( + otherCxxEmpty && + SourceGroupSettingsCxxEmpty::equals(other) && + SourceGroupSettingsWithCppStandard::equals(otherCxxEmpty) + ); +} + +const ProjectSettings* SourceGroupSettingsCppEmpty::getProjectSettings() const +{ + return m_projectSettings; +} + +std::vector SourceGroupSettingsCppEmpty::getDefaultSourceExtensions() const +{ + return { + L".cpp", + L".cxx", + L".cc" + }; +} diff --git a/src/lib/settings/SourceGroupSettingsCppEmpty.h b/src/lib/settings/SourceGroupSettingsCppEmpty.h new file mode 100644 index 00000000..34a339f1 --- /dev/null +++ b/src/lib/settings/SourceGroupSettingsCppEmpty.h @@ -0,0 +1,24 @@ +#ifndef SOURCE_GROUP_SETTINGS_CPP_EMPTY_H +#define SOURCE_GROUP_SETTINGS_CPP_EMPTY_H + +#include "settings/SourceGroupSettingsCxxEmpty.h" +#include "settings/SourceGroupSettingsWithCppStandard.h" + +class SourceGroupSettingsCppEmpty + : public SourceGroupSettingsCxxEmpty + , public SourceGroupSettingsWithCppStandard +{ +public: + SourceGroupSettingsCppEmpty(const std::string& id, const ProjectSettings* projectSettings); + + void load(std::shared_ptr config) override; + void save(std::shared_ptr config) override; + + bool equals(std::shared_ptr other) const override; + +private: + const ProjectSettings* getProjectSettings() const override; + std::vector getDefaultSourceExtensions() const override; +}; + +#endif // SOURCE_GROUP_SETTINGS_CPP_EMPTY_H diff --git a/src/lib/settings/SourceGroupSettingsCxx.cpp b/src/lib/settings/SourceGroupSettingsCxx.cpp index 12605ba6..f1eccd87 100644 --- a/src/lib/settings/SourceGroupSettingsCxx.cpp +++ b/src/lib/settings/SourceGroupSettingsCxx.cpp @@ -47,60 +47,6 @@ bool SourceGroupSettingsCxx::equals(std::shared_ptr other) ); } -std::vector SourceGroupSettingsCxx::getAvailableLanguageStandards() const -{ - std::vector standards; - - switch (getType()) - { - case SOURCE_GROUP_CPP_EMPTY: - case SOURCE_GROUP_CXX_CDB: - case SOURCE_GROUP_CXX_SONARGRAPH: - standards.push_back("c++2a"); - standards.push_back("gnu++2a"); - - standards.push_back("c++17"); - standards.push_back("gnu++17"); - - standards.push_back("c++14"); - standards.push_back("gnu++14"); - - standards.push_back("c++11"); - standards.push_back("gnu++11"); - - standards.push_back("c++03"); - standards.push_back("gnu++03"); - - standards.push_back("c++98"); - standards.push_back("gnu++98"); - break; - - case SOURCE_GROUP_C_EMPTY: - standards.push_back("c11"); - standards.push_back("gnu11"); - standards.push_back("iso9899:2011"); - - standards.push_back("c99"); - standards.push_back("gnu99"); - standards.push_back("iso9899:1999"); - - standards.push_back("iso9899:199409"); - - standards.push_back("c90"); - standards.push_back("gnu90"); - standards.push_back("iso9899:1990"); - - standards.push_back("c89"); - standards.push_back("gnu89"); - break; - - default: - break; - } - - return standards; -} - std::vector SourceGroupSettingsCxx::getHeaderSearchPaths() const { return m_headerSearchPaths; @@ -140,20 +86,3 @@ void SourceGroupSettingsCxx::setCompilerFlags(const std::vector& c { m_compilerFlags = compilerFlags; } - -std::string SourceGroupSettingsCxx::getDefaultStandard() const -{ - switch (getType()) - { - case SOURCE_GROUP_CPP_EMPTY: - case SOURCE_GROUP_CXX_SONARGRAPH: - return "c++17"; - case SOURCE_GROUP_C_EMPTY: - return "c11"; - case SOURCE_GROUP_CXX_CDB: - default: - break; - } - - return ""; -} diff --git a/src/lib/settings/SourceGroupSettingsCxx.h b/src/lib/settings/SourceGroupSettingsCxx.h index 088fec68..dc021d39 100644 --- a/src/lib/settings/SourceGroupSettingsCxx.h +++ b/src/lib/settings/SourceGroupSettingsCxx.h @@ -3,6 +3,8 @@ #include "settings/SourceGroupSettings.h" +#include "utility/file/FilePath.h" + class SourceGroupSettingsCxx : public SourceGroupSettings { @@ -14,8 +16,6 @@ public: bool equals(std::shared_ptr other) const override; - std::vector getAvailableLanguageStandards() const override; - std::vector getHeaderSearchPaths() const; std::vector getHeaderSearchPathsExpandedAndAbsolute() const; void setHeaderSearchPaths(const std::vector& headerSearchPaths); @@ -28,8 +28,6 @@ public: void setCompilerFlags(const std::vector& compilerFlags); private: - std::string getDefaultStandard() const override; - std::vector m_headerSearchPaths; std::vector m_frameworkSearchPaths; std::vector m_compilerFlags; diff --git a/src/lib/settings/SourceGroupSettingsCxxCodeblocks.cpp b/src/lib/settings/SourceGroupSettingsCxxCodeblocks.cpp new file mode 100644 index 00000000..e32e65cf --- /dev/null +++ b/src/lib/settings/SourceGroupSettingsCxxCodeblocks.cpp @@ -0,0 +1,82 @@ +#include "settings/SourceGroupSettingsCxxCodeblocks.h" + +#include "settings/ProjectSettings.h" +#include "utility/ConfigManager.h" + +SourceGroupSettingsCxxCodeblocks::SourceGroupSettingsCxxCodeblocks(const std::string& id, const ProjectSettings* projectSettings) + : SourceGroupSettingsCxx(id, SOURCE_GROUP_CXX_CODEBLOCKS, projectSettings) +{ +} + +void SourceGroupSettingsCxxCodeblocks::load(std::shared_ptr config) +{ + SourceGroupSettingsCxx::load(config); + + const std::string key = s_keyPrefix + getId(); + + SourceGroupSettingsWithCppStandard::load(config, key); + SourceGroupSettingsWithCStandard::load(config, key); + SourceGroupSettingsWithIndexedHeaderPaths::load(config, key); + SourceGroupSettingsWithSourceExtensions::load(config, key); + + setCodeblocksProjectPath(config->getValueOrDefault(key + "/codeblocks_project_path", FilePath(L""))); +} + +void SourceGroupSettingsCxxCodeblocks::save(std::shared_ptr config) +{ + SourceGroupSettingsCxx::save(config); + + const std::string key = s_keyPrefix + getId(); + + SourceGroupSettingsWithCppStandard::save(config, key); + SourceGroupSettingsWithCStandard::save(config, key); + SourceGroupSettingsWithIndexedHeaderPaths::save(config, key); + SourceGroupSettingsWithSourceExtensions::save(config, key); + + config->setValue(key + "/codeblocks_project_path", getCodeblocksProjectPath().wstr()); +} + +bool SourceGroupSettingsCxxCodeblocks::equals(std::shared_ptr other) const +{ + std::shared_ptr otherCxxCodeblocks = std::dynamic_pointer_cast(other); + + return ( + otherCxxCodeblocks && + SourceGroupSettingsCxx::equals(other) && + SourceGroupSettingsWithCppStandard::equals(otherCxxCodeblocks) && + SourceGroupSettingsWithCStandard::equals(otherCxxCodeblocks) && + SourceGroupSettingsWithIndexedHeaderPaths::equals(otherCxxCodeblocks) && + SourceGroupSettingsWithSourceExtensions::equals(otherCxxCodeblocks) && + m_codeblocksProjectPath == otherCxxCodeblocks->m_codeblocksProjectPath + ); +} + +FilePath SourceGroupSettingsCxxCodeblocks::getCodeblocksProjectPath() const +{ + return m_codeblocksProjectPath; +} + +FilePath SourceGroupSettingsCxxCodeblocks::getCodeblocksProjectPathExpandedAndAbsolute() const +{ + return m_projectSettings->makePathExpandedAndAbsolute(getCodeblocksProjectPath()); +} + +void SourceGroupSettingsCxxCodeblocks::setCodeblocksProjectPath(const FilePath& compilationDatabasePath) +{ + m_codeblocksProjectPath = compilationDatabasePath; +} + +const ProjectSettings* SourceGroupSettingsCxxCodeblocks::getProjectSettings() const +{ + return m_projectSettings; +} + +std::vector SourceGroupSettingsCxxCodeblocks::getDefaultSourceExtensions() const +{ + return { + L".c", + L".cpp", + L".cxx", + L".cc" + }; +} diff --git a/src/lib/settings/SourceGroupSettingsCxxCodeblocks.h b/src/lib/settings/SourceGroupSettingsCxxCodeblocks.h new file mode 100644 index 00000000..e89df64b --- /dev/null +++ b/src/lib/settings/SourceGroupSettingsCxxCodeblocks.h @@ -0,0 +1,36 @@ +#ifndef SOURCE_GROUP_SETTINGS_CXX_CODEBLOCKS_H +#define SOURCE_GROUP_SETTINGS_CXX_CODEBLOCKS_H + +#include "settings/SourceGroupSettingsCxx.h" +#include "settings/SourceGroupSettingsWithCppStandard.h" +#include "settings/SourceGroupSettingsWithCStandard.h" +#include "settings/SourceGroupSettingsWithIndexedHeaderPaths.h" +#include "settings/SourceGroupSettingsWithSourceExtensions.h" + +class SourceGroupSettingsCxxCodeblocks + : public SourceGroupSettingsCxx + , public SourceGroupSettingsWithCppStandard + , public SourceGroupSettingsWithCStandard + , public SourceGroupSettingsWithIndexedHeaderPaths + , public SourceGroupSettingsWithSourceExtensions +{ +public: + SourceGroupSettingsCxxCodeblocks(const std::string& id, const ProjectSettings* projectSettings); + + void load(std::shared_ptr config) override; + void save(std::shared_ptr config) override; + + bool equals(std::shared_ptr other) const override; + + FilePath getCodeblocksProjectPath() const; + FilePath getCodeblocksProjectPathExpandedAndAbsolute() const; + void setCodeblocksProjectPath(const FilePath& compilationDatabasePath); + +private: + const ProjectSettings* getProjectSettings() const override; + std::vector getDefaultSourceExtensions() const override; + + FilePath m_codeblocksProjectPath; +}; + +#endif // SOURCE_GROUP_SETTINGS_CXX_CODEBLOCKS_H diff --git a/src/lib/settings/SourceGroupSettingsCxxEmpty.cpp b/src/lib/settings/SourceGroupSettingsCxxEmpty.cpp index 56663c9b..0ed091a5 100644 --- a/src/lib/settings/SourceGroupSettingsCxxEmpty.cpp +++ b/src/lib/settings/SourceGroupSettingsCxxEmpty.cpp @@ -157,6 +157,7 @@ void SourceGroupSettingsCxxEmpty::load(std::shared_ptr conf const std::string key = s_keyPrefix + getId(); + SourceGroupSettingsWithSourceExtensions::load(config, key); SourceGroupSettingsWithSourcePaths::load(config, key); SourceGroupSettingsWithExcludeFilters::load(config, key); @@ -173,6 +174,7 @@ void SourceGroupSettingsCxxEmpty::save(std::shared_ptr config) const std::string key = s_keyPrefix + getId(); + SourceGroupSettingsWithSourceExtensions::save(config, key); SourceGroupSettingsWithSourcePaths::save(config, key); SourceGroupSettingsWithExcludeFilters::save(config, key); @@ -190,6 +192,7 @@ bool SourceGroupSettingsCxxEmpty::equals(std::shared_ptr ot return ( otherCxxEmpty && SourceGroupSettingsCxx::equals(other) && + SourceGroupSettingsWithSourceExtensions::equals(otherCxxEmpty) && SourceGroupSettingsWithSourcePaths::equals(otherCxxEmpty) && SourceGroupSettingsWithExcludeFilters::equals(otherCxxEmpty) && getTargetFlag() == otherCxxEmpty->getTargetFlag() @@ -258,30 +261,4 @@ std::wstring SourceGroupSettingsCxxEmpty::getTargetFlag() const targetFlag += L"-" + (m_targetAbi.empty() ? L"unknown" : m_targetAbi); } return targetFlag; -} - -const ProjectSettings* SourceGroupSettingsCxxEmpty::getProjectSettings() const -{ - return m_projectSettings; -} - -std::vector SourceGroupSettingsCxxEmpty::getDefaultSourceExtensions() const -{ - std::vector defaultValues; - - switch (getType()) - { - case SOURCE_GROUP_CPP_EMPTY: - defaultValues.push_back(L".cpp"); - defaultValues.push_back(L".cxx"); - defaultValues.push_back(L".cc"); - break; - case SOURCE_GROUP_C_EMPTY: - defaultValues.push_back(L".c"); - break; - default: - break; - } - - return defaultValues; -} +} \ No newline at end of file diff --git a/src/lib/settings/SourceGroupSettingsCxxEmpty.h b/src/lib/settings/SourceGroupSettingsCxxEmpty.h index 236bebe2..07580380 100644 --- a/src/lib/settings/SourceGroupSettingsCxxEmpty.h +++ b/src/lib/settings/SourceGroupSettingsCxxEmpty.h @@ -3,11 +3,13 @@ #include "settings/SourceGroupSettingsCxx.h" #include "settings/SourceGroupSettingsWithExcludeFilters.h" +#include "settings/SourceGroupSettingsWithSourceExtensions.h" #include "settings/SourceGroupSettingsWithSourcePaths.h" class SourceGroupSettingsCxxEmpty : public SourceGroupSettingsCxx , public SourceGroupSettingsWithExcludeFilters + , public SourceGroupSettingsWithSourceExtensions , public SourceGroupSettingsWithSourcePaths { public: @@ -41,9 +43,6 @@ public: std::wstring getTargetFlag() const; private: - const ProjectSettings* getProjectSettings() const override; - std::vector getDefaultSourceExtensions() const override; - bool m_targetOptionsEnabled; std::wstring m_targetArch; std::wstring m_targetVendor; diff --git a/src/lib/settings/SourceGroupSettingsCxxSonargraph.cpp b/src/lib/settings/SourceGroupSettingsCxxSonargraph.cpp index 5021cf98..95433fcc 100644 --- a/src/lib/settings/SourceGroupSettingsCxxSonargraph.cpp +++ b/src/lib/settings/SourceGroupSettingsCxxSonargraph.cpp @@ -11,6 +11,7 @@ void SourceGroupSettingsCxxSonargraph::load(std::shared_ptr const std::string key = s_keyPrefix + getId(); + SourceGroupSettingsWithCppStandard::load(config, key); SourceGroupSettingsWithIndexedHeaderPaths::load(config, key); SourceGroupSettingsWithSonargraphProjectPath::load(config, key); } @@ -21,6 +22,7 @@ void SourceGroupSettingsCxxSonargraph::save(std::shared_ptr confi const std::string key = s_keyPrefix + getId(); + SourceGroupSettingsWithCppStandard::save(config, key); SourceGroupSettingsWithIndexedHeaderPaths::save(config, key); SourceGroupSettingsWithSonargraphProjectPath::save(config, key); } @@ -32,7 +34,8 @@ bool SourceGroupSettingsCxxSonargraph::equals(std::shared_ptr config) SourceGroupSettings::load(config); const std::string key = s_keyPrefix + getId(); - + + SourceGroupSettingsWithSourceExtensions::load(config, key); SourceGroupSettingsWithSourcePaths::load(config, key); SourceGroupSettingsWithExcludeFilters::load(config, key); + SourceGroupSettingsWithJavaStandard::load(config, key); SourceGroupSettingsWithClasspath::load(config, key); } @@ -22,8 +24,10 @@ void SourceGroupSettingsJava::save(std::shared_ptr config) const std::string key = s_keyPrefix + getId(); + SourceGroupSettingsWithSourceExtensions::save(config, key); SourceGroupSettingsWithSourcePaths::save(config, key); SourceGroupSettingsWithExcludeFilters::save(config, key); + SourceGroupSettingsWithJavaStandard::save(config, key); SourceGroupSettingsWithClasspath::save(config, key); } @@ -34,17 +38,14 @@ bool SourceGroupSettingsJava::equals(std::shared_ptr other) return ( otherJava && SourceGroupSettings::equals(other) && + SourceGroupSettingsWithSourceExtensions::equals(otherJava) && SourceGroupSettingsWithSourcePaths::equals(otherJava) && SourceGroupSettingsWithExcludeFilters::equals(otherJava) && + SourceGroupSettingsWithJavaStandard::equals(otherJava) && SourceGroupSettingsWithClasspath::equals(otherJava) ); } -std::vector SourceGroupSettingsJava::getAvailableLanguageStandards() const -{ - return std::vector{"1", "2", "3", "4", "5", "6", "7", "8"}; -} - const ProjectSettings* SourceGroupSettingsJava::getProjectSettings() const { return m_projectSettings; @@ -54,8 +55,3 @@ std::vector SourceGroupSettingsJava::getDefaultSourceExtensions() { return { L".java" }; } - -std::string SourceGroupSettingsJava::getDefaultStandard() const -{ - return "8"; -} diff --git a/src/lib/settings/SourceGroupSettingsJava.h b/src/lib/settings/SourceGroupSettingsJava.h index d289d8df..94d6c672 100644 --- a/src/lib/settings/SourceGroupSettingsJava.h +++ b/src/lib/settings/SourceGroupSettingsJava.h @@ -7,12 +7,16 @@ #include "settings/SourceGroupSettings.h" #include "settings/SourceGroupSettingsWithClasspath.h" #include "settings/SourceGroupSettingsWithExcludeFilters.h" +#include "settings/SourceGroupSettingsWithJavaStandard.h" +#include "settings/SourceGroupSettingsWithSourceExtensions.h" #include "settings/SourceGroupSettingsWithSourcePaths.h" class SourceGroupSettingsJava : public SourceGroupSettings + , public SourceGroupSettingsWithSourceExtensions , public SourceGroupSettingsWithSourcePaths , public SourceGroupSettingsWithExcludeFilters + , public SourceGroupSettingsWithJavaStandard , public SourceGroupSettingsWithClasspath { public: @@ -23,12 +27,9 @@ public: bool equals(std::shared_ptr other) const override; - std::vector getAvailableLanguageStandards() const override; - private: const ProjectSettings* getProjectSettings() const override; std::vector getDefaultSourceExtensions() const override; - std::string getDefaultStandard() const override; }; #endif // SOURCE_GROUP_SETTINGS_JAVA_H diff --git a/src/lib/settings/SourceGroupSettingsJavaSonargraph.cpp b/src/lib/settings/SourceGroupSettingsJavaSonargraph.cpp index 3bed3281..24377a5c 100644 --- a/src/lib/settings/SourceGroupSettingsJavaSonargraph.cpp +++ b/src/lib/settings/SourceGroupSettingsJavaSonargraph.cpp @@ -12,6 +12,7 @@ void SourceGroupSettingsJavaSonargraph::load(std::shared_ptr conf const std::string key = s_keyPrefix + getId(); SourceGroupSettingsWithClasspath::save(config, key); + SourceGroupSettingsWithJavaStandard::save(config, key); SourceGroupSettingsWithSonargraphProjectPath::save(config, key); } @@ -33,20 +35,11 @@ bool SourceGroupSettingsJavaSonargraph::equals(std::shared_ptr SourceGroupSettingsJavaSonargraph::getAvailableLanguageStandards() const -{ - return std::vector{"1", "2", "3", "4", "5", "6", "7", "8"}; -} - -std::string SourceGroupSettingsJavaSonargraph::getDefaultStandard() const -{ - return "8"; -} - const ProjectSettings* SourceGroupSettingsJavaSonargraph::getProjectSettings() const { return m_projectSettings; diff --git a/src/lib/settings/SourceGroupSettingsJavaSonargraph.h b/src/lib/settings/SourceGroupSettingsJavaSonargraph.h index 5c7c2ac6..068dd051 100644 --- a/src/lib/settings/SourceGroupSettingsJavaSonargraph.h +++ b/src/lib/settings/SourceGroupSettingsJavaSonargraph.h @@ -3,11 +3,13 @@ #include "settings/SourceGroupSettings.h" #include "settings/SourceGroupSettingsWithClasspath.h" +#include "settings/SourceGroupSettingsWithJavaStandard.h" #include "settings/SourceGroupSettingsWithSonargraphProjectPath.h" class SourceGroupSettingsJavaSonargraph : public SourceGroupSettings , public SourceGroupSettingsWithClasspath + , public SourceGroupSettingsWithJavaStandard , public SourceGroupSettingsWithSonargraphProjectPath { public: @@ -18,10 +20,7 @@ public: bool equals(std::shared_ptr other) const override; - std::vector getAvailableLanguageStandards() const override; - private: - std::string getDefaultStandard() const override; const ProjectSettings* getProjectSettings() const override; }; diff --git a/src/lib/settings/SourceGroupSettingsWithCStandard.cpp b/src/lib/settings/SourceGroupSettingsWithCStandard.cpp new file mode 100644 index 00000000..5df646cf --- /dev/null +++ b/src/lib/settings/SourceGroupSettingsWithCStandard.cpp @@ -0,0 +1,63 @@ +#include "settings/SourceGroupSettingsWithCStandard.h" + +#include "settings/ProjectSettings.h" + +std::string SourceGroupSettingsWithCStandard::getDefaultCStandardStatic() +{ + return "c11"; +} + +bool SourceGroupSettingsWithCStandard::equals(std::shared_ptr other) const +{ + return ( + other && + m_cStandard == other->m_cStandard + ); +} + +void SourceGroupSettingsWithCStandard::load(std::shared_ptr config, const std::string& key) +{ + setCStandard(config->getValueOrDefault(key + "/c_standard", "")); +} + +void SourceGroupSettingsWithCStandard::save(std::shared_ptr config, const std::string& key) +{ + config->setValue(key + "/c_standard", getCStandard()); +} + +std::string SourceGroupSettingsWithCStandard::getCStandard() const +{ + if (m_cStandard.empty()) + { + return getDefaultCStandard(); + } + return m_cStandard; +} + +void SourceGroupSettingsWithCStandard::setCStandard(const std::string& standard) +{ + m_cStandard = standard; +} + +std::vector SourceGroupSettingsWithCStandard::getAvailableCStandards() const +{ + return { + "c11", + "gnu11", + "iso9899:2011", + "c99", + "gnu99", + "iso9899:1999", + "iso9899:199409", + "c90", + "gnu90", + "iso9899:1990", + "c89", + "gnu89" + }; +} + +std::string SourceGroupSettingsWithCStandard::getDefaultCStandard() const +{ + return getDefaultCStandardStatic(); +} diff --git a/src/lib/settings/SourceGroupSettingsWithCStandard.h b/src/lib/settings/SourceGroupSettingsWithCStandard.h new file mode 100644 index 00000000..4973c847 --- /dev/null +++ b/src/lib/settings/SourceGroupSettingsWithCStandard.h @@ -0,0 +1,37 @@ +#ifndef SOURCE_GROUP_SETTINGS_WITH_C_STANDARD_H +#define SOURCE_GROUP_SETTINGS_WITH_C_STANDARD_H + +#include +#include +#include + +class ConfigManager; +class ProjectSettings; + +class SourceGroupSettingsWithCStandard +{ +public: + static std::string getDefaultCStandardStatic(); + + SourceGroupSettingsWithCStandard() = default; + virtual ~SourceGroupSettingsWithCStandard() = default; + + bool equals(std::shared_ptr other) const; + + std::string getCStandard() const; + void setCStandard(const std::string& standard); + + std::vector getAvailableCStandards() const; + +protected: + void load(std::shared_ptr config, const std::string& key); + void save(std::shared_ptr config, const std::string& key); + +private: + virtual const ProjectSettings* getProjectSettings() const = 0; + std::string getDefaultCStandard() const; + + std::string m_cStandard; +}; + +#endif // SOURCE_GROUP_SETTINGS_WITH_C_STANDARD_H diff --git a/src/lib/settings/SourceGroupSettingsWithCppStandard.cpp b/src/lib/settings/SourceGroupSettingsWithCppStandard.cpp new file mode 100644 index 00000000..d6d0d934 --- /dev/null +++ b/src/lib/settings/SourceGroupSettingsWithCppStandard.cpp @@ -0,0 +1,63 @@ +#include "settings/SourceGroupSettingsWithCppStandard.h" + +#include "settings/ProjectSettings.h" + +std::string SourceGroupSettingsWithCppStandard::getDefaultCppStandardStatic() +{ + return "c++17"; +} + +bool SourceGroupSettingsWithCppStandard::equals(std::shared_ptr other) const +{ + return ( + other && + m_cppStandard == other->m_cppStandard + ); +} + +void SourceGroupSettingsWithCppStandard::load(std::shared_ptr config, const std::string& key) +{ + setCppStandard(config->getValueOrDefault(key + "/cpp_standard", "")); +} + +void SourceGroupSettingsWithCppStandard::save(std::shared_ptr config, const std::string& key) +{ + config->setValue(key + "/cpp_standard", getCppStandard()); +} + +std::string SourceGroupSettingsWithCppStandard::getCppStandard() const +{ + if (m_cppStandard.empty()) + { + return getDefaultCppStandard(); + } + return m_cppStandard; +} + +void SourceGroupSettingsWithCppStandard::setCppStandard(const std::string& standard) +{ + m_cppStandard = standard; +} + +std::vector SourceGroupSettingsWithCppStandard::getAvailableCppStandards() const +{ + return { + "c++2a", + "gnu++2a", + "c++17", + "gnu++17", + "c++14", + "gnu++14", + "c++11", + "gnu++11", + "c++03", + "gnu++03", + "c++98", + "gnu++98" + }; +} + +std::string SourceGroupSettingsWithCppStandard::getDefaultCppStandard() const +{ + return getDefaultCppStandardStatic(); +} diff --git a/src/lib/settings/SourceGroupSettingsWithCppStandard.h b/src/lib/settings/SourceGroupSettingsWithCppStandard.h new file mode 100644 index 00000000..9dd20643 --- /dev/null +++ b/src/lib/settings/SourceGroupSettingsWithCppStandard.h @@ -0,0 +1,37 @@ +#ifndef SOURCE_GROUP_SETTINGS_WITH_CPP_STANDARD_H +#define SOURCE_GROUP_SETTINGS_WITH_CPP_STANDARD_H + +#include +#include +#include + +class ConfigManager; +class ProjectSettings; + +class SourceGroupSettingsWithCppStandard +{ +public: + static std::string getDefaultCppStandardStatic(); + + SourceGroupSettingsWithCppStandard() = default; + virtual ~SourceGroupSettingsWithCppStandard() = default; + + bool equals(std::shared_ptr other) const; + + std::string getCppStandard() const; + void setCppStandard(const std::string& standard); + + std::vector getAvailableCppStandards() const; + +protected: + void load(std::shared_ptr config, const std::string& key); + void save(std::shared_ptr config, const std::string& key); + +private: + virtual const ProjectSettings* getProjectSettings() const = 0; + std::string getDefaultCppStandard() const; + + std::string m_cppStandard; +}; + +#endif // SOURCE_GROUP_SETTINGS_WITH_CPP_STANDARD_H diff --git a/src/lib/settings/SourceGroupSettingsWithJavaStandard.cpp b/src/lib/settings/SourceGroupSettingsWithJavaStandard.cpp new file mode 100644 index 00000000..841cb866 --- /dev/null +++ b/src/lib/settings/SourceGroupSettingsWithJavaStandard.cpp @@ -0,0 +1,50 @@ +#include "settings/SourceGroupSettingsWithJavaStandard.h" + +#include "settings/ProjectSettings.h" + +std::string SourceGroupSettingsWithJavaStandard::getDefaultJavaStandardStatic() +{ + return "8"; +} + +bool SourceGroupSettingsWithJavaStandard::equals(std::shared_ptr other) const +{ + return ( + other && + m_javaStandard == other->m_javaStandard + ); +} + +void SourceGroupSettingsWithJavaStandard::load(std::shared_ptr config, const std::string& key) +{ + setJavaStandard(config->getValueOrDefault(key + "/java_standard", "")); +} + +void SourceGroupSettingsWithJavaStandard::save(std::shared_ptr config, const std::string& key) +{ + config->setValue(key + "/java_standard", getJavaStandard()); +} + +std::string SourceGroupSettingsWithJavaStandard::getJavaStandard() const +{ + if (m_javaStandard.empty()) + { + return getDefaultJavaStandard(); + } + return m_javaStandard; +} + +void SourceGroupSettingsWithJavaStandard::setJavaStandard(const std::string& standard) +{ + m_javaStandard = standard; +} + +std::vector SourceGroupSettingsWithJavaStandard::getAvailableJavaStandards() const +{ + return {"1", "2", "3", "4", "5", "6", "7", "8"}; +} + +std::string SourceGroupSettingsWithJavaStandard::getDefaultJavaStandard() const +{ + return getDefaultJavaStandardStatic(); +} diff --git a/src/lib/settings/SourceGroupSettingsWithJavaStandard.h b/src/lib/settings/SourceGroupSettingsWithJavaStandard.h new file mode 100644 index 00000000..a6cd915a --- /dev/null +++ b/src/lib/settings/SourceGroupSettingsWithJavaStandard.h @@ -0,0 +1,37 @@ +#ifndef SOURCE_GROUP_SETTINGS_WITH_JAVA_STANDARD_H +#define SOURCE_GROUP_SETTINGS_WITH_JAVA_STANDARD_H + +#include +#include +#include + +class ConfigManager; +class ProjectSettings; + +class SourceGroupSettingsWithJavaStandard +{ +public: + static std::string getDefaultJavaStandardStatic(); + + SourceGroupSettingsWithJavaStandard() = default; + virtual ~SourceGroupSettingsWithJavaStandard() = default; + + bool equals(std::shared_ptr other) const; + + std::string getJavaStandard() const; + void setJavaStandard(const std::string& standard); + + std::vector getAvailableJavaStandards() const; + +protected: + void load(std::shared_ptr config, const std::string& key); + void save(std::shared_ptr config, const std::string& key); + +private: + virtual const ProjectSettings* getProjectSettings() const = 0; + std::string getDefaultJavaStandard() const; + + std::string m_javaStandard; +}; + +#endif // SOURCE_GROUP_SETTINGS_WITH_JAVA_STANDARD_H diff --git a/src/lib/settings/SourceGroupSettingsWithSourceExtensions.cpp b/src/lib/settings/SourceGroupSettingsWithSourceExtensions.cpp new file mode 100644 index 00000000..6f292792 --- /dev/null +++ b/src/lib/settings/SourceGroupSettingsWithSourceExtensions.cpp @@ -0,0 +1,38 @@ +#include "settings/SourceGroupSettingsWithSourceExtensions.h" + +#include "settings/ProjectSettings.h" +#include "utility/utility.h" + +SourceGroupSettingsWithSourceExtensions::SourceGroupSettingsWithSourceExtensions() + : m_sourceExtensions(std::vector()) +{ +} + +bool SourceGroupSettingsWithSourceExtensions::equals(std::shared_ptr other) const +{ + return utility::isPermutation(m_sourceExtensions, other->m_sourceExtensions); +} + +void SourceGroupSettingsWithSourceExtensions::load(std::shared_ptr config, const std::string& key) +{ + setSourceExtensions(config->getValuesOrDefaults(key + "/source_extensions/source_extension", std::vector())); +} + +void SourceGroupSettingsWithSourceExtensions::save(std::shared_ptr config, const std::string& key) +{ + config->setValues(key + "/source_extensions/source_extension", getSourceExtensions()); +} + +std::vector SourceGroupSettingsWithSourceExtensions::getSourceExtensions() const +{ + if (m_sourceExtensions.empty()) + { + return getDefaultSourceExtensions(); + } + return m_sourceExtensions; +} + +void SourceGroupSettingsWithSourceExtensions::setSourceExtensions(const std::vector& sourceExtensions) +{ + m_sourceExtensions = sourceExtensions; +} diff --git a/src/lib/settings/SourceGroupSettingsWithSourceExtensions.h b/src/lib/settings/SourceGroupSettingsWithSourceExtensions.h new file mode 100644 index 00000000..7f9d9da3 --- /dev/null +++ b/src/lib/settings/SourceGroupSettingsWithSourceExtensions.h @@ -0,0 +1,34 @@ +#ifndef SOURCE_GROUP_SETTINGS_WITH_SOURCE_EXTENSIONS_H +#define SOURCE_GROUP_SETTINGS_WITH_SOURCE_EXTENSIONS_H + +#include +#include +#include + +class ConfigManager; +class FilePath; +class ProjectSettings; + +class SourceGroupSettingsWithSourceExtensions +{ +public: + SourceGroupSettingsWithSourceExtensions(); + virtual ~SourceGroupSettingsWithSourceExtensions() = default; + + bool equals(std::shared_ptr other) const; + + std::vector getSourceExtensions() const; + void setSourceExtensions(const std::vector& sourceExtensions); + +protected: + void load(std::shared_ptr config, const std::string& key); + void save(std::shared_ptr config, const std::string& key); + +private: + virtual const ProjectSettings* getProjectSettings() const = 0; + virtual std::vector getDefaultSourceExtensions() const = 0; + + std::vector m_sourceExtensions; +}; + +#endif // SOURCE_GROUP_SETTINGS_WITH_SOURCE_EXTENSIONS_H diff --git a/src/lib/settings/SourceGroupSettingsWithSourcePaths.cpp b/src/lib/settings/SourceGroupSettingsWithSourcePaths.cpp index 95a55632..efbee814 100644 --- a/src/lib/settings/SourceGroupSettingsWithSourcePaths.cpp +++ b/src/lib/settings/SourceGroupSettingsWithSourcePaths.cpp @@ -5,28 +5,22 @@ SourceGroupSettingsWithSourcePaths::SourceGroupSettingsWithSourcePaths() : m_sourcePaths(std::vector()) - , m_sourceExtensions(std::vector()) { } bool SourceGroupSettingsWithSourcePaths::equals(std::shared_ptr other) const { - return ( - utility::isPermutation(m_sourcePaths, other->m_sourcePaths) && - utility::isPermutation(m_sourceExtensions, other->m_sourceExtensions) - ); + return utility::isPermutation(m_sourcePaths, other->m_sourcePaths); } void SourceGroupSettingsWithSourcePaths::load(std::shared_ptr config, const std::string& key) { setSourcePaths(config->getValuesOrDefaults(key + "/source_paths/source_path", std::vector())); - setSourceExtensions(config->getValuesOrDefaults(key + "/source_extensions/source_extension", std::vector())); } void SourceGroupSettingsWithSourcePaths::save(std::shared_ptr config, const std::string& key) { config->setValues(key + "/source_paths/source_path", getSourcePaths()); - config->setValues(key + "/source_extensions/source_extension", getSourceExtensions()); } std::vector SourceGroupSettingsWithSourcePaths::getSourcePaths() const @@ -43,17 +37,3 @@ void SourceGroupSettingsWithSourcePaths::setSourcePaths(const std::vector SourceGroupSettingsWithSourcePaths::getSourceExtensions() const -{ - if (m_sourceExtensions.empty()) - { - return getDefaultSourceExtensions(); - } - return m_sourceExtensions; -} - -void SourceGroupSettingsWithSourcePaths::setSourceExtensions(const std::vector& sourceExtensions) -{ - m_sourceExtensions = sourceExtensions; -} diff --git a/src/lib/settings/SourceGroupSettingsWithSourcePaths.h b/src/lib/settings/SourceGroupSettingsWithSourcePaths.h index 420808dd..c8ac7712 100644 --- a/src/lib/settings/SourceGroupSettingsWithSourcePaths.h +++ b/src/lib/settings/SourceGroupSettingsWithSourcePaths.h @@ -21,19 +21,14 @@ public: std::vector getSourcePathsExpandedAndAbsolute() const; void setSourcePaths(const std::vector& sourcePaths); - std::vector getSourceExtensions() const; - void setSourceExtensions(const std::vector& sourceExtensions); - protected: void load(std::shared_ptr config, const std::string& key); void save(std::shared_ptr config, const std::string& key); private: virtual const ProjectSettings* getProjectSettings() const = 0; - virtual std::vector getDefaultSourceExtensions() const = 0; std::vector m_sourcePaths; - std::vector m_sourceExtensions; }; #endif // SOURCE_GROUP_SETTINGS_WITH_SOURCE_PATHS_H diff --git a/src/lib/settings/SourceGroupType.cpp b/src/lib/settings/SourceGroupType.cpp index 14250026..35630b8d 100644 --- a/src/lib/settings/SourceGroupType.cpp +++ b/src/lib/settings/SourceGroupType.cpp @@ -10,6 +10,8 @@ std::string sourceGroupTypeToString(SourceGroupType v) return "C++ Source Group"; case SOURCE_GROUP_CXX_CDB: return "C/C++ from Compilation Database"; + case SOURCE_GROUP_CXX_CODEBLOCKS: + return "C/C++ from Code::Blocks"; case SOURCE_GROUP_CXX_SONARGRAPH: return "C/C++ from Sonargraph"; case SOURCE_GROUP_CXX_VS: @@ -38,6 +40,8 @@ std::string sourceGroupTypeToProjectSetupString(SourceGroupType v) return "Empty C++ Source Group"; case SOURCE_GROUP_CXX_CDB: return "C/C++ from Compilation Database"; + case SOURCE_GROUP_CXX_CODEBLOCKS: + return "C/C++ from Code::Blocks"; case SOURCE_GROUP_CXX_SONARGRAPH: return "C/C++ from Sonargraph"; case SOURCE_GROUP_CXX_VS: @@ -70,6 +74,10 @@ SourceGroupType stringToSourceGroupType(const std::string& v) { return SOURCE_GROUP_CXX_CDB; } + else if (v == sourceGroupTypeToString(SOURCE_GROUP_CXX_CODEBLOCKS)) + { + return SOURCE_GROUP_CXX_CODEBLOCKS; + } else if (v == sourceGroupTypeToString(SOURCE_GROUP_CXX_SONARGRAPH)) { return SOURCE_GROUP_CXX_SONARGRAPH; diff --git a/src/lib/settings/SourceGroupType.h b/src/lib/settings/SourceGroupType.h index d60a9f00..91e42704 100644 --- a/src/lib/settings/SourceGroupType.h +++ b/src/lib/settings/SourceGroupType.h @@ -8,6 +8,7 @@ enum SourceGroupType SOURCE_GROUP_C_EMPTY, SOURCE_GROUP_CPP_EMPTY, SOURCE_GROUP_CXX_CDB, + SOURCE_GROUP_CXX_CODEBLOCKS, SOURCE_GROUP_CXX_SONARGRAPH, SOURCE_GROUP_CXX_VS, SOURCE_GROUP_JAVA_EMPTY, diff --git a/src/lib/utility/file/FilePath.cpp b/src/lib/utility/file/FilePath.cpp index f23fe80d..803383be 100644 --- a/src/lib/utility/file/FilePath.cpp +++ b/src/lib/utility/file/FilePath.cpp @@ -344,7 +344,7 @@ FilePath FilePath::getLowerCase() const bool FilePath::contains(const FilePath& other) const { - if (!isDirectory()) + if (exists() && !isDirectory()) { return false; } diff --git a/src/lib/utility/sonargraph/SonargraphProject.cpp b/src/lib/utility/sonargraph/SonargraphProject.cpp index 82c261a3..c3f2b8e5 100644 --- a/src/lib/utility/sonargraph/SonargraphProject.cpp +++ b/src/lib/utility/sonargraph/SonargraphProject.cpp @@ -60,11 +60,6 @@ namespace Sonargraph return m_softwareSystem->getModules().size(); } - std::set Project::getAllSourcePaths() const - { - return m_softwareSystem->getAllSourcePaths(); - } - std::set Project::getAllSourceFilePathsCanonical() const { return m_softwareSystem->getAllSourceFilePathsCanonical(); @@ -75,11 +70,6 @@ namespace Sonargraph return m_softwareSystem->getAllCxxHeaderSearchPathsCanonical(); } - std::set Project::filterToContainedFilePaths(const std::set& filePaths) const - { - return m_softwareSystem->filterToContainedFilePaths(filePaths); - } - std::vector> Project::getIndexerCommands( std::shared_ptr sourceGroupSettings, std::shared_ptr appSettings) const diff --git a/src/lib/utility/sonargraph/SonargraphProject.h b/src/lib/utility/sonargraph/SonargraphProject.h index abcd9b2b..8dfa9424 100644 --- a/src/lib/utility/sonargraph/SonargraphProject.h +++ b/src/lib/utility/sonargraph/SonargraphProject.h @@ -32,10 +32,8 @@ namespace Sonargraph int getLoadedModuleCount() const; - std::set getAllSourcePaths() const; std::set getAllSourceFilePathsCanonical() const; std::set getAllCxxHeaderSearchPathsCanonical() const; - std::set filterToContainedFilePaths(const std::set& filePaths) const; std::vector> getIndexerCommands( std::shared_ptr sourceGroupSettings, diff --git a/src/lib/utility/sonargraph/SonargraphSoftwareSystem.cpp b/src/lib/utility/sonargraph/SonargraphSoftwareSystem.cpp index 228b6761..efa85acb 100644 --- a/src/lib/utility/sonargraph/SonargraphSoftwareSystem.cpp +++ b/src/lib/utility/sonargraph/SonargraphSoftwareSystem.cpp @@ -90,16 +90,6 @@ namespace Sonargraph return sourceFilePaths; } - std::set SoftwareSystem::filterToContainedFilePaths(const std::set& filePaths) const - { - std::set containedFilePaths; - for (std::shared_ptr module : m_modules) - { - utility::append(containedFilePaths, module->filterToContainedFilePaths(filePaths)); - } - return containedFilePaths; - } - std::vector> SoftwareSystem::getIndexerCommands( std::shared_ptr sourceGroupSettings, std::shared_ptr appSettings) const diff --git a/src/lib/utility/sonargraph/SonargraphSoftwareSystem.h b/src/lib/utility/sonargraph/SonargraphSoftwareSystem.h index 23af27fd..9015ad7c 100644 --- a/src/lib/utility/sonargraph/SonargraphSoftwareSystem.h +++ b/src/lib/utility/sonargraph/SonargraphSoftwareSystem.h @@ -32,7 +32,6 @@ namespace Sonargraph std::set getAllSourcePaths() const; std::set getAllSourceFilePathsCanonical() const; std::set getAllCxxHeaderSearchPathsCanonical() const; - std::set filterToContainedFilePaths(const std::set& filePaths) const; template std::vector> getSpecificSystemExtensions() const; diff --git a/src/lib/utility/sonargraph/SonargraphXsdAbstractModule.h b/src/lib/utility/sonargraph/SonargraphXsdAbstractModule.h index 52278f47..21929bdb 100644 --- a/src/lib/utility/sonargraph/SonargraphXsdAbstractModule.h +++ b/src/lib/utility/sonargraph/SonargraphXsdAbstractModule.h @@ -37,7 +37,6 @@ namespace Sonargraph virtual std::set getAllSourcePaths() const = 0; virtual std::set getAllSourceFilePathsCanonical() const = 0; virtual std::set getAllCxxHeaderSearchPathsCanonical() const = 0; - virtual std::set filterToContainedFilePaths(const std::set& filePaths) const = 0; std::shared_ptr getSoftwareSystem() const; std::vector getDerivedExcludeFilters() const; diff --git a/src/lib/utility/sonargraph/SonargraphXsdCmakeJsonModule.cpp b/src/lib/utility/sonargraph/SonargraphXsdCmakeJsonModule.cpp index 05737d72..27db442b 100644 --- a/src/lib/utility/sonargraph/SonargraphXsdCmakeJsonModule.cpp +++ b/src/lib/utility/sonargraph/SonargraphXsdCmakeJsonModule.cpp @@ -7,6 +7,8 @@ #include "settings/LanguageType.h" #include "settings/SourceGroupSettings.h" #include "settings/SourceGroupSettingsCxxSonargraph.h" +#include "settings/SourceGroupSettingsWithCppStandard.h" +#include "settings/SourceGroupSettingsWithCStandard.h" #include "utility/file/FileSystem.h" #include "utility/logging/logging.h" #include "utility/sonargraph/SonargraphSoftwareSystem.h" @@ -177,75 +179,45 @@ namespace Sonargraph return headerSearchPaths; } - std::set XsdCmakeJsonModule::filterToContainedFilePaths(const std::set& filePaths) const - { - const std::set indexedPaths = getAllSourcePaths(); - const std::vector excludeFilters = getDerivedExcludeFilters(); - const std::vector includeFilters = getDerivedIncludeFilters(); - - std::set containedFilePaths; - for (const FilePath& filePath : filePaths) - { - bool isInIndexedPaths = false; - for (const FilePath& indexedPath : indexedPaths) - { - if (indexedPath == filePath || indexedPath.contains(filePath)) - { - isInIndexedPaths = true; - break; - } - } - - if (isInIndexedPaths) - { - for (const FilePathFilter& excludeFilter : excludeFilters) - { - if (excludeFilter.isMatching(filePath)) - { - isInIndexedPaths = false; - break; - } - } - - if (!isInIndexedPaths) - { - for (const FilePathFilter& includeFilter : includeFilters) - { - if (includeFilter.isMatching(filePath)) - { - isInIndexedPaths = true; - break; - } - } - } - } - - if (isInIndexedPaths) - { - containedFilePaths.insert(filePath); - } - } - - return containedFilePaths; - } - std::vector> XsdCmakeJsonModule::getIndexerCommands( std::shared_ptr sourceGroupSettings, std::shared_ptr appSettings) const { std::vector> indexerCommands; + std::set indexedHeaderPaths; + std::string languageStandard = SourceGroupSettingsWithCppStandard::getDefaultCppStandardStatic(); + + if (std::shared_ptr sonargraphSettings = + std::dynamic_pointer_cast(sourceGroupSettings)) + { + indexedHeaderPaths = utility::toSet(sonargraphSettings->getIndexedHeaderPathsExpandedAndAbsolute()); + languageStandard = sonargraphSettings->getCppStandard(); + } + else + { + LOG_ERROR("Source group doesn't specify language standard. Falling back to \"" + languageStandard + "\"."); + LOG_ERROR("Source group doesn't specify any indexed header paths"); + } + + const std::vector systemHeaderSearchPaths = (appSettings ? appSettings->getHeaderSearchPathsExpanded() : std::vector()); + const std::vector frameworkSearchPaths = (appSettings ? appSettings->getFrameworkSearchPathsExpanded() : std::vector()); + for (std::shared_ptr rootPath : getRootPaths()) { if (std::shared_ptr rootPathWithFiles = std::dynamic_pointer_cast(rootPath)) { - utility::append(indexerCommands, getIndexerCommandsForRootPath(rootPathWithFiles, sourceGroupSettings, appSettings)); + utility::append(indexerCommands, getIndexerCommandsForRootPath( + rootPathWithFiles, indexedHeaderPaths, languageStandard, systemHeaderSearchPaths, frameworkSearchPaths + )); } } for (std::shared_ptr rootPath : m_rootPathWithFiles) { - utility::append(indexerCommands, getIndexerCommandsForRootPath(rootPath, sourceGroupSettings, appSettings)); + utility::append(indexerCommands, getIndexerCommandsForRootPath( + rootPath, indexedHeaderPaths ,languageStandard, systemHeaderSearchPaths, frameworkSearchPaths + )); } return indexerCommands; @@ -321,8 +293,10 @@ namespace Sonargraph std::vector> XsdCmakeJsonModule::getIndexerCommandsForRootPath( std::shared_ptr rootPath, - std::shared_ptr sourceGroupSettings, - std::shared_ptr appSettings) const + const std::set indexedHeaderPaths, + const std::string& languageStandard, + const std::vector systemHeaderSearchPaths, + const std::vector frameworkSearchPaths) const { std::vector> indexerCommands; if (rootPath) @@ -335,17 +309,8 @@ namespace Sonargraph const FilePath baseDir = rootPath->getFilePath(softwareSystem->getBaseDirectory()); - std::set indexedHeaderPaths; - if (std::shared_ptr sonargraphSettings = std::dynamic_pointer_cast(sourceGroupSettings)) - { - indexedHeaderPaths = utility::toSet(sonargraphSettings->getIndexedHeaderPathsExpandedAndAbsolute()); - } - const std::set excludeFilters = utility::toSet(getDerivedExcludeFilters()); const std::set includeFilters = utility::toSet(getDerivedIncludeFilters()); - const std::string languageStandard = sourceGroupSettings->getStandard(); - const std::vector systemHeaderSearchPaths = (appSettings ? appSettings->getHeaderSearchPathsExpanded() : std::vector()); - const std::vector frameworkSearchPaths = (appSettings ? appSettings->getFrameworkSearchPathsExpanded() : std::vector()); OrderedCache> compilerOptionCache([&](const Id& id) { if (std::shared_ptr softwareSystem = getSoftwareSystem()) diff --git a/src/lib/utility/sonargraph/SonargraphXsdCmakeJsonModule.h b/src/lib/utility/sonargraph/SonargraphXsdCmakeJsonModule.h index cd64ad0c..d85ced8e 100644 --- a/src/lib/utility/sonargraph/SonargraphXsdCmakeJsonModule.h +++ b/src/lib/utility/sonargraph/SonargraphXsdCmakeJsonModule.h @@ -17,7 +17,6 @@ namespace Sonargraph std::set getAllSourcePaths() const override; std::set getAllSourceFilePathsCanonical() const override; std::set getAllCxxHeaderSearchPathsCanonical() const override; - std::set filterToContainedFilePaths(const std::set& filePaths) const override; std::vector> getIndexerCommands( std::shared_ptr sourceGroupSettings, std::shared_ptr appSettings) const override; @@ -33,9 +32,11 @@ namespace Sonargraph const std::set& includeFilters) const; std::vector> getIndexerCommandsForRootPath( - std::shared_ptr rootPath, - std::shared_ptr sourceGroupSettings, - std::shared_ptr appSettings) const; + std::shared_ptr rootPath, + const std::set indexedHeaderPaths, + const std::string& languageStandard, + const std::vector systemHeaderSearchPaths, + const std::vector frameworkSearchPaths) const; std::vector> m_rootPathWithFiles; }; diff --git a/src/lib/utility/sonargraph/SonargraphXsdJavaModule.cpp b/src/lib/utility/sonargraph/SonargraphXsdJavaModule.cpp index 68c2b5fb..00c55909 100644 --- a/src/lib/utility/sonargraph/SonargraphXsdJavaModule.cpp +++ b/src/lib/utility/sonargraph/SonargraphXsdJavaModule.cpp @@ -102,58 +102,6 @@ namespace Sonargraph return std::set(); } - std::set XsdJavaModule::filterToContainedFilePaths(const std::set& filePaths) const - { - const std::set indexedPaths = getAllSourcePaths(); - const std::vector excludeFilters = getDerivedExcludeFilters(); - const std::vector includeFilters = getDerivedIncludeFilters(); - - std::set containedFilePaths; - for (const FilePath& filePath : filePaths) - { - bool isInIndexedPaths = false; - for (const FilePath& indexedPath : indexedPaths) - { - if (indexedPath == filePath || indexedPath.contains(filePath)) - { - isInIndexedPaths = true; - break; - } - } - - if (isInIndexedPaths) - { - for (const FilePathFilter& excludeFilter : excludeFilters) - { - if (excludeFilter.isMatching(filePath)) - { - isInIndexedPaths = false; - break; - } - } - - if (!isInIndexedPaths) - { - for (const FilePathFilter& includeFilter : includeFilters) - { - if (includeFilter.isMatching(filePath)) - { - isInIndexedPaths = true; - break; - } - } - } - } - - if (isInIndexedPaths) - { - containedFilePaths.insert(filePath); - } - } - - return containedFilePaths; - } - std::vector> XsdJavaModule::getIndexerCommands( std::shared_ptr sourceGroupSettings, std::shared_ptr appSettings) const @@ -161,7 +109,16 @@ namespace Sonargraph std::vector> indexerCommands; { - const std::string languageStandard = sourceGroupSettings->getStandard(); + std::string languageStandard = SourceGroupSettingsWithJavaStandard::getDefaultJavaStandardStatic(); + if (std::shared_ptr settings = + std::dynamic_pointer_cast(sourceGroupSettings)) + { + languageStandard = settings->getJavaStandard(); + } + else + { + LOG_ERROR("Source group doesn't specify language standard. Falling back to \"" + languageStandard + "\"."); + } for (const FilePath& sourceFilePath : getAllSourceFilePathsCanonical()) { diff --git a/src/lib/utility/sonargraph/SonargraphXsdJavaModule.h b/src/lib/utility/sonargraph/SonargraphXsdJavaModule.h index e8cbced0..22a19e37 100644 --- a/src/lib/utility/sonargraph/SonargraphXsdJavaModule.h +++ b/src/lib/utility/sonargraph/SonargraphXsdJavaModule.h @@ -18,7 +18,6 @@ namespace Sonargraph std::set getAllSourcePaths() const override; std::set getAllSourceFilePathsCanonical() const override; std::set getAllCxxHeaderSearchPathsCanonical() const override; - std::set filterToContainedFilePaths(const std::set& filePaths) const override; std::vector> getIndexerCommands( std::shared_ptr sourceGroupSettings, std::shared_ptr appSettings) const override; diff --git a/src/lib_cxx/CMakeLists.txt b/src/lib_cxx/CMakeLists.txt index 90134048..dbfd1dd6 100644 --- a/src/lib_cxx/CMakeLists.txt +++ b/src/lib_cxx/CMakeLists.txt @@ -78,6 +78,8 @@ add_files( project/SourceGroupCxxCdb.cpp project/SourceGroupCxxCdb.h + project/SourceGroupCxxCodeblocks.cpp + project/SourceGroupCxxCodeblocks.h project/SourceGroupCxxEmpty.cpp project/SourceGroupCxxEmpty.h project/SourceGroupCxxSonargraph.cpp @@ -85,6 +87,18 @@ add_files( project/SourceGroupFactoryModuleCxx.cpp project/SourceGroupFactoryModuleCxx.h + utility/codeblocks/CodeblocksCompiler.cpp + utility/codeblocks/CodeblocksCompiler.h + utility/codeblocks/CodeblocksCompilerVarType.cpp + utility/codeblocks/CodeblocksCompilerVarType.h + utility/codeblocks/CodeblocksProject.cpp + utility/codeblocks/CodeblocksProject.h + utility/codeblocks/CodeblocksTarget.cpp + utility/codeblocks/CodeblocksTarget.h + utility/codeblocks/CodeblocksTargetRelationType.cpp + utility/codeblocks/CodeblocksTargetRelationType.h + utility/codeblocks/CodeblocksUnit.cpp + utility/codeblocks/CodeblocksUnit.h utility/CompilationDatabase.cpp utility/CompilationDatabase.h utility/IncludeDirective.cpp diff --git a/src/lib_cxx/project/SourceGroupCxxCodeblocks.cpp b/src/lib_cxx/project/SourceGroupCxxCodeblocks.cpp new file mode 100644 index 00000000..2a9c6d28 --- /dev/null +++ b/src/lib_cxx/project/SourceGroupCxxCodeblocks.cpp @@ -0,0 +1,106 @@ +#include "project/SourceGroupCxxCodeblocks.h" + +#include "data/indexer/IndexerCommand.h" +#include "settings/ApplicationSettings.h" +#include "settings/SourceGroupSettingsCxxCodeblocks.h" +#include "utility/messaging/type/MessageStatus.h" +#include "utility/codeblocks/CodeblocksProject.h" +#include "utility/utility.h" +#include "Application.h" + +SourceGroupCxxCodeblocks::SourceGroupCxxCodeblocks(std::shared_ptr settings) + : m_settings(settings) +{ +} + +bool SourceGroupCxxCodeblocks::prepareIndexing() +{ + FilePath codeblocksProjectPath = m_settings->getCodeblocksProjectPathExpandedAndAbsolute(); + if (!codeblocksProjectPath.empty() && !codeblocksProjectPath.exists()) + { + MessageStatus(L"Can't refresh project").dispatch(); + + if (std::shared_ptr application = Application::getInstance()) + { + if (application->hasGUI()) + { + application->handleDialog( + L"Can't refresh. The referenced Code::Blocks project does not exist anymore: " + codeblocksProjectPath.wstr(), + { L"Ok" } + ); + } + } + return false; + } + return true; +} + +std::set SourceGroupCxxCodeblocks::filterToContainedFilePaths(const std::set& filePaths) const +{ + std::set containedFilePaths; + + const std::set indexedPaths = utility::concat( + getAllSourceFilePaths(), + utility::toSet(m_settings->getIndexedHeaderPathsExpandedAndAbsolute()) + ); + + for (const FilePath& filePath : filePaths) + { + for (const FilePath& indexedPath : indexedPaths) + { + if (indexedPath == filePath || indexedPath.contains(filePath)) + { + containedFilePaths.insert(filePath); + break; + } + } + } + + return containedFilePaths; +} + +std::set SourceGroupCxxCodeblocks::getAllSourceFilePaths() const +{ + std::set sourceFilePaths; + if (std::shared_ptr project = Codeblocks::Project::load( + m_settings->getCodeblocksProjectPathExpandedAndAbsolute() + )) + { + for (const FilePath& filePath : project->getAllSourceFilePathsCanonical(m_settings)) + { + if (filePath.exists()) + { + sourceFilePaths.insert(filePath); + } + } + } + return sourceFilePaths; +} + +std::vector> SourceGroupCxxCodeblocks::getIndexerCommands(const std::set& filesToIndex) const +{ + std::vector> indexerCommands; + if (std::shared_ptr project = Codeblocks::Project::load( + m_settings->getCodeblocksProjectPathExpandedAndAbsolute() + )) + { + for (std::shared_ptr indexerCommand: project->getIndexerCommands(m_settings, ApplicationSettings::getInstance())) + { + if (filesToIndex.find(indexerCommand->getSourceFilePath()) != filesToIndex.end()) + { + indexerCommands.push_back(indexerCommand); + } + } + } + return indexerCommands; +} + +std::shared_ptr SourceGroupCxxCodeblocks::getSourceGroupSettings() +{ + return m_settings; +} + +std::shared_ptr SourceGroupCxxCodeblocks::getSourceGroupSettings() const +{ + return m_settings; +} diff --git a/src/lib_cxx/project/SourceGroupCxxCodeblocks.h b/src/lib_cxx/project/SourceGroupCxxCodeblocks.h new file mode 100644 index 00000000..2ace02e7 --- /dev/null +++ b/src/lib_cxx/project/SourceGroupCxxCodeblocks.h @@ -0,0 +1,29 @@ +#ifndef SOURCE_GROUP_CXX_CODEBLOCKS_H +#define SOURCE_GROUP_CXX_CODEBLOCKS_H + +#include +#include + +#include "project/SourceGroup.h" + +class SourceGroupSettingsCxxCodeblocks; + +class SourceGroupCxxCodeblocks + : public SourceGroup +{ +public: + SourceGroupCxxCodeblocks(std::shared_ptr settings); + + bool prepareIndexing() override; + std::set filterToContainedFilePaths(const std::set& filePaths) const override; + std::set getAllSourceFilePaths() const override; + std::vector> getIndexerCommands(const std::set& filesToIndex) const override; + +private: + std::shared_ptr getSourceGroupSettings() override; + std::shared_ptr getSourceGroupSettings() const override; + + std::shared_ptr m_settings; +}; + +#endif // SOURCE_GROUP_CXX_CODEBLOCKS_H diff --git a/src/lib_cxx/project/SourceGroupCxxEmpty.cpp b/src/lib_cxx/project/SourceGroupCxxEmpty.cpp index eee082f7..e5101283 100644 --- a/src/lib_cxx/project/SourceGroupCxxEmpty.cpp +++ b/src/lib_cxx/project/SourceGroupCxxEmpty.cpp @@ -3,6 +3,8 @@ #include "data/indexer/IndexerCommandCxxEmpty.h" #include "settings/ApplicationSettings.h" #include "settings/SourceGroupSettingsCxxEmpty.h" +#include "settings/SourceGroupSettingsWithCppStandard.h" +#include "settings/SourceGroupSettingsWithCStandard.h" #include "utility/file/FileManager.h" #include "utility/utility.h" @@ -98,6 +100,22 @@ std::vector> SourceGroupCxxEmpty::getIndexerComm const std::set indexedPaths = utility::toSet(m_settings->getSourcePathsExpandedAndAbsolute()); const std::set excludeFilters = utility::toSet(m_settings->getExcludeFiltersExpandedAndAbsolute()); + std::string languageStandard = SourceGroupSettingsWithCppStandard::getDefaultCppStandardStatic(); + if (std::shared_ptr cSettings = + std::dynamic_pointer_cast(m_settings)) + { + languageStandard = cSettings->getCStandard(); + } + else if (std::shared_ptr cppSettisngs = + std::dynamic_pointer_cast(m_settings)) + { + languageStandard = cppSettisngs->getCppStandard(); + } + else + { + LOG_ERROR("Source group doesn't specify language standard. Falling back to \"" + languageStandard + "\"."); + } + std::vector> indexerCommands; for (const FilePath& sourcePath: getAllSourceFilePaths()) { @@ -112,7 +130,7 @@ std::vector> SourceGroupCxxEmpty::getIndexerComm systemHeaderSearchPaths, frameworkSearchPaths, compilerFlags, - m_settings->getStandard() + languageStandard )); } } diff --git a/src/lib_cxx/project/SourceGroupCxxSonargraph.cpp b/src/lib_cxx/project/SourceGroupCxxSonargraph.cpp index aad71442..9b990bf4 100644 --- a/src/lib_cxx/project/SourceGroupCxxSonargraph.cpp +++ b/src/lib_cxx/project/SourceGroupCxxSonargraph.cpp @@ -5,6 +5,7 @@ #include "settings/SourceGroupSettingsCxxSonargraph.h" #include "utility/messaging/type/MessageStatus.h" #include "utility/sonargraph/SonargraphProject.h" +#include "utility/utility.h" #include "Application.h" SourceGroupCxxSonargraph::SourceGroupCxxSonargraph(std::shared_ptr settings) @@ -36,28 +37,44 @@ bool SourceGroupCxxSonargraph::prepareIndexing() std::set SourceGroupCxxSonargraph::filterToContainedFilePaths(const std::set& filePaths) const { - if (std::shared_ptr project = Sonargraph::Project::load( - m_settings->getSonargraphProjectPathExpandedAndAbsolute(), getLanguage() - )) + std::set containedFilePaths; + + const std::set indexedPaths = utility::concat( + getAllSourceFilePaths(), + utility::toSet(m_settings->getIndexedHeaderPathsExpandedAndAbsolute()) + ); + + for (const FilePath& filePath : filePaths) { - return project->filterToContainedFilePaths(filePaths); + for (const FilePath& indexedPath : indexedPaths) + { + if (indexedPath == filePath || indexedPath.contains(filePath)) + { + containedFilePaths.insert(filePath); + break; + } + } } - else - { - LOG_ERROR("Unable to load Sonargraph project to check the containment of file paths."); - } - return std::set(); + + return containedFilePaths; } std::set SourceGroupCxxSonargraph::getAllSourceFilePaths() const { + std::set sourceFilePaths; if (std::shared_ptr project = Sonargraph::Project::load( m_settings->getSonargraphProjectPathExpandedAndAbsolute(), getLanguage() )) { - return project->getAllSourceFilePathsCanonical(); + for (const FilePath& filePath : project->getAllSourceFilePathsCanonical()) + { + if (filePath.exists()) + { + sourceFilePaths.insert(filePath); + } + } } - return std::set(); + return sourceFilePaths; } std::vector> SourceGroupCxxSonargraph::getIndexerCommands(const std::set& filesToIndex) const diff --git a/src/lib_cxx/project/SourceGroupFactoryModuleCxx.cpp b/src/lib_cxx/project/SourceGroupFactoryModuleCxx.cpp index 8f2d4922..ef5108a7 100644 --- a/src/lib_cxx/project/SourceGroupFactoryModuleCxx.cpp +++ b/src/lib_cxx/project/SourceGroupFactoryModuleCxx.cpp @@ -1,9 +1,11 @@ #include "project/SourceGroupFactoryModuleCxx.h" #include "project/SourceGroupCxxCdb.h" +#include "project/SourceGroupCxxCodeblocks.h" #include "project/SourceGroupCxxEmpty.h" #include "project/SourceGroupCxxSonargraph.h" #include "settings/SourceGroupSettingsCxxCdb.h" +#include "settings/SourceGroupSettingsCxxCodeblocks.h" #include "settings/SourceGroupSettingsCxxEmpty.h" #include "settings/SourceGroupSettingsCxxSonargraph.h" @@ -18,6 +20,7 @@ bool SourceGroupFactoryModuleCxx::supports(SourceGroupType type) const case SOURCE_GROUP_C_EMPTY: case SOURCE_GROUP_CPP_EMPTY: case SOURCE_GROUP_CXX_CDB: + case SOURCE_GROUP_CXX_CODEBLOCKS: case SOURCE_GROUP_CXX_SONARGRAPH: return true; default: @@ -33,6 +36,10 @@ std::shared_ptr SourceGroupFactoryModuleCxx::createSourceGroup(std: { sourceGroup = std::shared_ptr(new SourceGroupCxxCdb(cxxSettings)); } + else if (std::shared_ptr cxxSettings = std::dynamic_pointer_cast(settings)) + { + sourceGroup = std::shared_ptr(new SourceGroupCxxCodeblocks(cxxSettings)); + } else if (std::shared_ptr cxxSettings = std::dynamic_pointer_cast(settings)) { sourceGroup = std::shared_ptr(new SourceGroupCxxEmpty(cxxSettings)); diff --git a/src/lib_cxx/utility/codeblocks/CodeblocksCompiler.cpp b/src/lib_cxx/utility/codeblocks/CodeblocksCompiler.cpp new file mode 100644 index 00000000..d80b8ded --- /dev/null +++ b/src/lib_cxx/utility/codeblocks/CodeblocksCompiler.cpp @@ -0,0 +1,58 @@ +#include "utility/codeblocks/CodeblocksCompiler.h" + +#include "tinyxml/tinyxml.h" + +#include "utility/utilityString.h" + +namespace Codeblocks +{ + std::string Compiler::getXmlElementName() + { + return "Compiler"; + } + + std::shared_ptr Compiler::create(const TiXmlElement* element) + { + if (!element || element->Value() != getXmlElementName()) + { + return std::shared_ptr(); + } + + std::shared_ptr compiler(new Compiler()); + + { + const TiXmlElement* addElement = element->FirstChildElement("Add"); + while (addElement) + { + { + const char* value = addElement->Attribute("option"); + if (value) + { + compiler->m_options.push_back(utility::decodeFromUtf8(value)); + } + } + { + const char* value = addElement->Attribute("directory"); + if (value) + { + compiler->m_directories.push_back(utility::decodeFromUtf8(value)); + } + } + + addElement = addElement->NextSiblingElement("Add"); + } + } + + return compiler; + } + + const std::vector& Compiler::getOptions() const + { + return m_options; + } + + const std::vector& Compiler::getDirectories() const + { + return m_directories; + } +} diff --git a/src/lib_cxx/utility/codeblocks/CodeblocksCompiler.h b/src/lib_cxx/utility/codeblocks/CodeblocksCompiler.h new file mode 100644 index 00000000..958d4680 --- /dev/null +++ b/src/lib_cxx/utility/codeblocks/CodeblocksCompiler.h @@ -0,0 +1,35 @@ +#ifndef CODEBLOCKS_COMPILER_H +#define CODEBLOCKS_COMPILER_H + +#include +#include +#include + +class TiXmlElement; + +class ApplicationSettings; +class FilePath; +class IndexerCommand; +class SourceGroupSettings; +class TextAccess; + +namespace Codeblocks +{ + class Compiler + { + public: + static std::string getXmlElementName(); + static std::shared_ptr create(const TiXmlElement* element); + + const std::vector& getOptions() const; + const std::vector& getDirectories() const; + + private: + Compiler() = default; + + std::vector m_options; + std::vector m_directories; + }; +} + +#endif // CODEBLOCKS_COMPILER_H diff --git a/src/lib_cxx/utility/codeblocks/CodeblocksCompilerVarType.cpp b/src/lib_cxx/utility/codeblocks/CodeblocksCompilerVarType.cpp new file mode 100644 index 00000000..c841bc03 --- /dev/null +++ b/src/lib_cxx/utility/codeblocks/CodeblocksCompilerVarType.cpp @@ -0,0 +1,35 @@ +#include "utility/codeblocks/CodeblocksCompilerVarType.h" + +namespace Codeblocks +{ + std::string compilerVarTypeToString(CompilerVarType v) + { + switch (v) + { + case COMPILER_VAR_CPP: + return "CPP"; + case COMPILER_VAR_C: + return "C"; + case COMPILER_VAR_WINDRES: + return "WINDRES"; + } + return "unknown"; + } + + CompilerVarType stringToCompilerVarType(const std::string& v) + { + if (v == compilerVarTypeToString(COMPILER_VAR_CPP)) + { + return COMPILER_VAR_CPP; + } + else if (v == compilerVarTypeToString(COMPILER_VAR_C)) + { + return COMPILER_VAR_C; + } + else if (v == compilerVarTypeToString(COMPILER_VAR_WINDRES)) + { + return COMPILER_VAR_WINDRES; + } + return COMPILER_VAR_UNKNOWN; + } +} diff --git a/src/lib_cxx/utility/codeblocks/CodeblocksCompilerVarType.h b/src/lib_cxx/utility/codeblocks/CodeblocksCompilerVarType.h new file mode 100644 index 00000000..0045f910 --- /dev/null +++ b/src/lib_cxx/utility/codeblocks/CodeblocksCompilerVarType.h @@ -0,0 +1,20 @@ +#ifndef CODEBLOCKS_COMPILER_VAR_TYPE_H +#define CODEBLOCKS_COMPILER_VAR_TYPE_H + +#include + +namespace Codeblocks +{ + enum CompilerVarType + { + COMPILER_VAR_CPP, + COMPILER_VAR_C, + COMPILER_VAR_WINDRES, + COMPILER_VAR_UNKNOWN + }; + + std::string compilerVarTypeToString(CompilerVarType v); + CompilerVarType stringToCompilerVarType(const std::string& v); +} + +#endif // CODEBLOCKS_COMPILER_VAR_TYPE_H diff --git a/src/lib_cxx/utility/codeblocks/CodeblocksProject.cpp b/src/lib_cxx/utility/codeblocks/CodeblocksProject.cpp new file mode 100644 index 00000000..94b3d444 --- /dev/null +++ b/src/lib_cxx/utility/codeblocks/CodeblocksProject.cpp @@ -0,0 +1,255 @@ +#include "utility/codeblocks/CodeblocksProject.h" + +#include "tinyxml/tinyxml.h" + +#include "data/indexer/IndexerCommandCxxEmpty.h" +#include "settings/ApplicationSettings.h" +#include "settings/SourceGroupSettingsCxxCodeblocks.h" +#include "utility/codeblocks/CodeblocksCompiler.h" +#include "utility/codeblocks/CodeblocksTarget.h" +#include "utility/codeblocks/CodeblocksUnit.h" +#include "utility/logging/logging.h" +#include "utility/text/TextAccess.h" +#include "utility/utility.h" +#include "utility/utilityString.h" +#include "utility/OrderedCache.h" + +namespace Codeblocks +{ + std::shared_ptr Project::load(const FilePath& projectFilePath) + { + return load(TextAccess::createFromFile(projectFilePath)); + } + + std::shared_ptr Project::load(std::shared_ptr xmlAccess) + { + if (!xmlAccess) + { + return std::shared_ptr(); + } + + std::shared_ptr project(new Project()); + + TiXmlDocument doc; + doc.Parse(xmlAccess->getText().c_str(), 0, TIXML_ENCODING_UTF8); + if (doc.Error()) + { + LOG_ERROR( + "Unable to parse Code::Blocks 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(); + } + + TiXmlElement* codeBlocksProjectFileElement; + TiXmlHandle docHandle(&doc); + { + codeBlocksProjectFileElement = docHandle.FirstChildElement("CodeBlocks_project_file").ToElement(); + if (codeBlocksProjectFileElement == nullptr) + { + codeBlocksProjectFileElement = docHandle.FirstChildElement("Code::Blocks_project_file").ToElement(); + } + if (codeBlocksProjectFileElement == nullptr) + { + LOG_ERROR("Unable to find root node in Code::Blocks project."); + return std::shared_ptr(); + } + } + + { + TiXmlElement* versionElement = codeBlocksProjectFileElement->FirstChildElement("FileVersion"); + + if (versionElement->QueryIntAttribute("major", &project->m_versionMajor) != TIXML_SUCCESS) + { + LOG_ERROR("Unable to find \"Project\" node in Code::Blocks project."); + return std::shared_ptr(); + } + + if (versionElement->QueryIntAttribute("minor", &project->m_versionMinor) != TIXML_SUCCESS) + { + LOG_ERROR("Unable to find \"Project\" node in Code::Blocks project."); + return std::shared_ptr(); + } + } + + const TiXmlElement* projectElement = codeBlocksProjectFileElement->FirstChildElement("Project"); + if (codeBlocksProjectFileElement == nullptr) + { + LOG_ERROR("Unable to find \"Project\" node in Code::Blocks project."); + return std::shared_ptr(); + } + + { + const TiXmlElement* optionElement = projectElement->FirstChildElement("Option"); + while (optionElement) + { + { + const char* value = optionElement->Attribute("title"); + if (value) + { + project->m_title = stringToCompilerVarType(value); + } + } + + optionElement = optionElement->NextSiblingElement("Option"); + } + } + + { + const TiXmlElement* buildElement = projectElement->FirstChildElement("Build"); + const TiXmlElement* targetElement = buildElement->FirstChildElement(Target::getXmlElementName().c_str()); + while (targetElement) + { + if (std::shared_ptr unit = Target::create(targetElement)) + { + project->m_targets.push_back(unit); + } + + targetElement = targetElement->NextSiblingElement(Target::getXmlElementName().c_str()); + } + } + + { + const TiXmlElement* unitElement = projectElement->FirstChildElement(Unit::getXmlElementName().c_str()); + while (unitElement) + { + if (std::shared_ptr unit = Unit::create(unitElement)) + { + project->m_units.push_back(unit); + } + + unitElement = unitElement->NextSiblingElement(Unit::getXmlElementName().c_str()); + } + } + + return project; + } + + std::set Project::getAllSourceFilePathsCanonical( + std::shared_ptr sourceGroupSettings + ) const + { + const std::set sourceExtensions = utility::toSet(sourceGroupSettings->getSourceExtensions()); + + std::set filePaths; + for (std::shared_ptr unit : m_units) + { + if (unit && unit->getCompile()) + { + FilePath filePath(unit->getFilename()); + if (sourceExtensions.find(filePath.getLowerCase().extension()) != sourceExtensions.end()) + { + filePaths.insert(filePath.makeCanonical()); + } + } + } + return filePaths; + } + + std::set Project::getAllCxxHeaderSearchPathsCanonical() const + { + std::set paths; + for (std::shared_ptr target : m_targets) + { + if (target) + { + if (std::shared_ptr compiler = target->getCompiler()) + { + for (const std::wstring& directory : compiler->getDirectories()) + { + paths.insert(FilePath(directory).makeCanonical()); + } + } + } + } + return paths; + } + + std::vector> Project::getIndexerCommands( + std::shared_ptr sourceGroupSettings, + std::shared_ptr appSettings) const + { + const std::set sourceExtensions = utility::toSet(sourceGroupSettings->getSourceExtensions()); + + const std::set indexedHeaderPaths = utility::toSet(sourceGroupSettings->getIndexedHeaderPathsExpandedAndAbsolute()); + + const std::vector compilerFlags = sourceGroupSettings->getCompilerFlags(); + + const std::vector systemHeaderSearchPaths = utility::concat( + sourceGroupSettings->getHeaderSearchPathsExpandedAndAbsolute(), + appSettings->getHeaderSearchPathsExpanded() + ); + + const std::vector frameworkSearchPaths = utility::concat( + sourceGroupSettings->getFrameworkSearchPathsExpandedAndAbsolute(), + appSettings->getFrameworkSearchPathsExpanded() + ); + + OrderedCache> optionsCache([&](const std::wstring& targetName) { + for (std::shared_ptr target : m_targets) + { + if (target->getTitle() == targetName) + { + return target->getCompiler()->getOptions(); + } + } + return std::vector(); + }); + + OrderedCache> headerSearchPathsCache([&](const std::wstring& targetName) { + for (std::shared_ptr target : m_targets) + { + if (target->getTitle() == targetName) + { + return utility::convert(target->getCompiler()->getDirectories()); + } + } + return std::vector(); + }); + + std::vector> indexerCommands; + for (std::shared_ptr unit : m_units) + { + if (!unit || !unit->getCompile()) + { + continue; + } + + const FilePath filePath = FilePath(unit->getFilename()).makeCanonical(); + if (sourceExtensions.find(filePath.getLowerCase().extension()) == sourceExtensions.end()) + { + continue; + } + + std::string languageStandard; + switch (unit->getCompilerVar()) + { + case COMPILER_VAR_C: + languageStandard = sourceGroupSettings->getCStandard(); + break; + case COMPILER_VAR_CPP: + languageStandard = sourceGroupSettings->getCppStandard(); + break; + default: + continue; + } + + for (const std::wstring& targetName : unit->getTargetNames()) + { + indexerCommands.push_back(std::make_shared( + filePath, + utility::concat(indexedHeaderPaths, { filePath }), + std::set(), + std::set(), + sourceGroupSettings->getCodeblocksProjectPathExpandedAndAbsolute().getParentDirectory(), + utility::concat(systemHeaderSearchPaths, headerSearchPathsCache.getValue(targetName)), + frameworkSearchPaths, + utility::concat(compilerFlags, optionsCache.getValue(targetName)), + languageStandard + )); + } + } + + return indexerCommands; + } +} diff --git a/src/lib_cxx/utility/codeblocks/CodeblocksProject.h b/src/lib_cxx/utility/codeblocks/CodeblocksProject.h new file mode 100644 index 00000000..ecc18435 --- /dev/null +++ b/src/lib_cxx/utility/codeblocks/CodeblocksProject.h @@ -0,0 +1,48 @@ +#ifndef CODEBLOCKS_PROJECT_H +#define CODEBLOCKS_PROJECT_H + +#include +#include +#include + +class ApplicationSettings; +class FilePath; +class IndexerCommand; +class SourceGroupSettingsCxxCodeblocks; +class SourceGroupSettingsWithSourceExtensions; +class TextAccess; + +namespace Codeblocks +{ + class Target; + class Unit; + + class Project + { + public: + static std::shared_ptr load(const FilePath& projectFilePath); + static std::shared_ptr load(std::shared_ptr xmlAccess); + + std::set getAllSourceFilePathsCanonical( + std::shared_ptr sourceGroupSettings + ) const; + std::set getAllCxxHeaderSearchPathsCanonical() const; + + std::vector> getIndexerCommands( + std::shared_ptr sourceGroupSettings, + std::shared_ptr appSettings) const; + + private: + Project() = default; + + int m_versionMajor; + int m_versionMinor; + + std::wstring m_title; + + std::vector> m_targets; + std::vector> m_units; + }; +} + +#endif // CODEBLOCKS_PROJECT_H diff --git a/src/lib_cxx/utility/codeblocks/CodeblocksTarget.cpp b/src/lib_cxx/utility/codeblocks/CodeblocksTarget.cpp new file mode 100644 index 00000000..00b0406a --- /dev/null +++ b/src/lib_cxx/utility/codeblocks/CodeblocksTarget.cpp @@ -0,0 +1,80 @@ +#include "utility/codeblocks/CodeblocksTarget.h" + +#include "tinyxml/tinyxml.h" + +#include "utility/codeblocks/CodeblocksCompiler.h" +#include "utility/utilityString.h" + +namespace Codeblocks +{ + std::string Target::getXmlElementName() + { + return "Target"; + } + + std::shared_ptr Target::create(const TiXmlElement* element) + { + if (!element || element->Value() != getXmlElementName()) + { + return std::shared_ptr(); + } + + std::shared_ptr target(new Target()); + + { + const char* value = element->Attribute("title"); + if (!value) + { + return std::shared_ptr(); + } + target->m_title = utility::decodeFromUtf8(value); + } + + { + const TiXmlElement* optionElement = element->FirstChildElement("Option"); + while (optionElement) + { + { + int value = 0; + if (optionElement->QueryIntAttribute("projectCompilerOptionsRelation", &value) == TIXML_SUCCESS) + { + target->m_projectCompilerOptionsRelation = intToTargetRelationType(value); + } + } + { + int value = 0; + if (optionElement->QueryIntAttribute("projectIncludeDirsRelation", &value) == TIXML_SUCCESS) + { + target->m_projectIncludeDirsRelation = intToTargetRelationType(value); + } + } + + optionElement = optionElement->NextSiblingElement("Option"); + } + } + + { + const TiXmlElement* compilerElement = element->FirstChildElement(Compiler::getXmlElementName().c_str()); + target->m_compiler = Compiler::create(compilerElement); + } + + return target; + } + + std::wstring Target::getTitle() const + { + return m_title; + } + + std::shared_ptr Target::getCompiler() const + { + return m_compiler; + } + + Target::Target() + : m_title() + , m_projectCompilerOptionsRelation(CODEBLOCKS_TARGET_RELATION_TARGET_AFTER_PROJECT) + , m_projectIncludeDirsRelation(CODEBLOCKS_TARGET_RELATION_TARGET_AFTER_PROJECT) + { + } +} diff --git a/src/lib_cxx/utility/codeblocks/CodeblocksTarget.h b/src/lib_cxx/utility/codeblocks/CodeblocksTarget.h new file mode 100644 index 00000000..b6707034 --- /dev/null +++ b/src/lib_cxx/utility/codeblocks/CodeblocksTarget.h @@ -0,0 +1,35 @@ +#ifndef CODEBLOCKS_TARGET_H +#define CODEBLOCKS_TARGET_H + +#include +#include +#include + +#include "utility/codeblocks/CodeblocksTargetRelationType.h" + +class TiXmlElement; + +namespace Codeblocks +{ + class Compiler; + + class Target + { + public: + static std::string getXmlElementName(); + static std::shared_ptr create(const TiXmlElement* element); + + std::wstring getTitle() const; + std::shared_ptr getCompiler() const; + + private: + Target(); + + std::wstring m_title; + TargetRelationType m_projectCompilerOptionsRelation; + TargetRelationType m_projectIncludeDirsRelation; + std::shared_ptr m_compiler; + }; +} + +#endif // CODEBLOCKS_TARGET_H diff --git a/src/lib_cxx/utility/codeblocks/CodeblocksTargetRelationType.cpp b/src/lib_cxx/utility/codeblocks/CodeblocksTargetRelationType.cpp new file mode 100644 index 00000000..697300b2 --- /dev/null +++ b/src/lib_cxx/utility/codeblocks/CodeblocksTargetRelationType.cpp @@ -0,0 +1,41 @@ +#include "utility/codeblocks/CodeblocksTargetRelationType.h" + +namespace Codeblocks +{ + int targetRelationTypeToInt(TargetRelationType v) + { + switch (v) + { + case CODEBLOCKS_TARGET_RELATION_IGNORE_TARGET: + return 0; + case CODEBLOCKS_TARGET_RELATION_IGNORE_PROJECT: + return 1; + case CODEBLOCKS_TARGET_RELATION_TARGET_BEFORE_PROJECT: + return 2; + case CODEBLOCKS_TARGET_RELATION_TARGET_AFTER_PROJECT: + return 3; + } + return 99; + } + + TargetRelationType intToTargetRelationType(int v) + { + if (v == targetRelationTypeToInt(CODEBLOCKS_TARGET_RELATION_IGNORE_TARGET)) + { + return CODEBLOCKS_TARGET_RELATION_IGNORE_TARGET; + } + else if (v == targetRelationTypeToInt(CODEBLOCKS_TARGET_RELATION_IGNORE_PROJECT)) + { + return CODEBLOCKS_TARGET_RELATION_IGNORE_PROJECT; + } + else if (v == targetRelationTypeToInt(CODEBLOCKS_TARGET_RELATION_TARGET_BEFORE_PROJECT)) + { + return CODEBLOCKS_TARGET_RELATION_TARGET_BEFORE_PROJECT; + } + else if (v == targetRelationTypeToInt(CODEBLOCKS_TARGET_RELATION_TARGET_AFTER_PROJECT)) + { + return CODEBLOCKS_TARGET_RELATION_TARGET_AFTER_PROJECT; + } + return CODEBLOCKS_TARGET_RELATION_UNKNOWN; + } +} diff --git a/src/lib_cxx/utility/codeblocks/CodeblocksTargetRelationType.h b/src/lib_cxx/utility/codeblocks/CodeblocksTargetRelationType.h new file mode 100644 index 00000000..b64c05ab --- /dev/null +++ b/src/lib_cxx/utility/codeblocks/CodeblocksTargetRelationType.h @@ -0,0 +1,19 @@ +#ifndef CODEBLOCKS_TARGET_RELATION_TYPE_H +#define CODEBLOCKS_TARGET_RELATION_TYPE_H + +namespace Codeblocks +{ + enum TargetRelationType + { + CODEBLOCKS_TARGET_RELATION_IGNORE_TARGET, + CODEBLOCKS_TARGET_RELATION_IGNORE_PROJECT, + CODEBLOCKS_TARGET_RELATION_TARGET_BEFORE_PROJECT, + CODEBLOCKS_TARGET_RELATION_TARGET_AFTER_PROJECT, + CODEBLOCKS_TARGET_RELATION_UNKNOWN + }; + + int targetRelationTypeToInt(TargetRelationType v); + TargetRelationType intToTargetRelationType(int v); +} + +#endif // CODEBLOCKS_TARGET_RELATION_TYPE_H diff --git a/src/lib_cxx/utility/codeblocks/CodeblocksUnit.cpp b/src/lib_cxx/utility/codeblocks/CodeblocksUnit.cpp new file mode 100644 index 00000000..2bfc537c --- /dev/null +++ b/src/lib_cxx/utility/codeblocks/CodeblocksUnit.cpp @@ -0,0 +1,89 @@ +#include "utility/codeblocks/CodeblocksUnit.h" + +#include "tinyxml/tinyxml.h" + +#include "utility/utilityString.h" + +namespace Codeblocks +{ + std::string Unit::getXmlElementName() + { + return "Unit"; + } + + std::shared_ptr Unit::create(const TiXmlElement* element) + { + if (!element || element->Value() != getXmlElementName()) + { + return std::shared_ptr(); + } + + std::shared_ptr unit(new Unit()); + + { + const char* value = element->Attribute("filename"); + if (!value) + { + return std::shared_ptr(); + } + unit->m_filename = utility::decodeFromUtf8(value); + } + + const TiXmlElement* optionElement = element->FirstChildElement("Option"); + while (optionElement) + { + { + const char* value = optionElement->Attribute("compilerVar"); + if (value) + { + unit->m_compilerVar = stringToCompilerVarType(value); + } + } + { + int value = 0; + if (optionElement->QueryIntAttribute("compile", &value) == TIXML_SUCCESS) + { + unit->m_compile = (value == 1); + } + } + { + const char* value = optionElement->Attribute("target"); + if (value) + { + unit->m_targetNames.insert(utility::decodeFromUtf8(value)); + } + } + + optionElement = optionElement->NextSiblingElement("Option"); + } + + return unit; + } + + std::wstring Unit::getFilename() const + { + return m_filename; + } + + CompilerVarType Unit::getCompilerVar() const + { + return m_compilerVar; + } + + bool Unit::getCompile() const + { + return m_compile; + } + + std::set Unit::getTargetNames() const + { + return m_targetNames; + } + + Unit::Unit() + : m_filename() + , m_compilerVar(COMPILER_VAR_CPP) + , m_compile(true) + { + } +} diff --git a/src/lib_cxx/utility/codeblocks/CodeblocksUnit.h b/src/lib_cxx/utility/codeblocks/CodeblocksUnit.h new file mode 100644 index 00000000..2d7d08ee --- /dev/null +++ b/src/lib_cxx/utility/codeblocks/CodeblocksUnit.h @@ -0,0 +1,34 @@ +#ifndef CODEBLOCKS_UNIT_H +#define CODEBLOCKS_UNIT_H + +#include +#include + +#include "utility/codeblocks/CodeblocksCompilerVarType.h" + +class TiXmlElement; + +namespace Codeblocks +{ + class Unit + { + public: + static std::string getXmlElementName(); + static std::shared_ptr create(const TiXmlElement* element); + + std::wstring getFilename() const; + CompilerVarType getCompilerVar() const; + bool getCompile() const; + std::set getTargetNames() const; + + private: + Unit(); + + std::wstring m_filename; + CompilerVarType m_compilerVar; + bool m_compile; + std::set m_targetNames; + }; +} + +#endif // CODEBLOCKS_UNIT_H diff --git a/src/lib_gui/CMakeLists.txt b/src/lib_gui/CMakeLists.txt index d4d78841..fd18a1df 100644 --- a/src/lib_gui/CMakeLists.txt +++ b/src/lib_gui/CMakeLists.txt @@ -187,16 +187,20 @@ add_files( qt/window/project_wizzard/QtProjectWizzard.h qt/window/project_wizzard/QtProjectWizzardContent.cpp qt/window/project_wizzard/QtProjectWizzardContent.h + qt/window/project_wizzard/QtProjectWizzardContentCppStandard.cpp + qt/window/project_wizzard/QtProjectWizzardContentCppStandard.h qt/window/project_wizzard/QtProjectWizzardContentCrossCompilationOptions.cpp qt/window/project_wizzard/QtProjectWizzardContentCrossCompilationOptions.h + qt/window/project_wizzard/QtProjectWizzardContentCStandard.cpp + qt/window/project_wizzard/QtProjectWizzardContentCStandard.h qt/window/project_wizzard/QtProjectWizzardContentExtensions.cpp qt/window/project_wizzard/QtProjectWizzardContentExtensions.h qt/window/project_wizzard/QtProjectWizzardContentFlags.cpp qt/window/project_wizzard/QtProjectWizzardContentFlags.h qt/window/project_wizzard/QtProjectWizzardContentGroup.cpp qt/window/project_wizzard/QtProjectWizzardContentGroup.h - qt/window/project_wizzard/QtProjectWizzardContentLanguageAndStandard.cpp - qt/window/project_wizzard/QtProjectWizzardContentLanguageAndStandard.h + qt/window/project_wizzard/QtProjectWizzardContentJavaStandard.cpp + qt/window/project_wizzard/QtProjectWizzardContentJavaStandard.h qt/window/project_wizzard/QtProjectWizzardContentPath.cpp qt/window/project_wizzard/QtProjectWizzardContentPath.h qt/window/project_wizzard/QtProjectWizzardContentPaths.cpp diff --git a/src/lib_gui/qt/window/project_wizzard/QtProjectWizzard.cpp b/src/lib_gui/qt/window/project_wizzard/QtProjectWizzard.cpp index 0ec3e35f..aa464f6d 100644 --- a/src/lib_gui/qt/window/project_wizzard/QtProjectWizzard.cpp +++ b/src/lib_gui/qt/window/project_wizzard/QtProjectWizzard.cpp @@ -7,10 +7,12 @@ #include #include "qt/window/project_wizzard/QtProjectWizzardContent.h" +#include "qt/window/project_wizzard/QtProjectWizzardContentCppStandard.h" #include "qt/window/project_wizzard/QtProjectWizzardContentCrossCompilationOptions.h" +#include "qt/window/project_wizzard/QtProjectWizzardContentCStandard.h" #include "qt/window/project_wizzard/QtProjectWizzardContentExtensions.h" #include "qt/window/project_wizzard/QtProjectWizzardContentFlags.h" -#include "qt/window/project_wizzard/QtProjectWizzardContentLanguageAndStandard.h" +#include "qt/window/project_wizzard/QtProjectWizzardContentJavaStandard.h" #include "qt/window/project_wizzard/QtProjectWizzardContentPath.h" #include "qt/window/project_wizzard/QtProjectWizzardContentPaths.h" #include "qt/window/project_wizzard/QtProjectWizzardContentProjectData.h" @@ -19,8 +21,10 @@ #include "qt/window/project_wizzard/QtProjectWizzardContentSourceGroupInfoText.h" #include "qt/window/project_wizzard/QtProjectWizzardContentGroup.h" #include "qt/window/project_wizzard/QtProjectWizzardContentVS.h" -#include "settings/SourceGroupSettingsCxxEmpty.h" +#include "settings/SourceGroupSettingsCEmpty.h" +#include "settings/SourceGroupSettingsCppEmpty.h" #include "settings/SourceGroupSettingsCxxCdb.h" +#include "settings/SourceGroupSettingsCxxCodeblocks.h" #include "settings/SourceGroupSettingsCxxSonargraph.h" #include "settings/SourceGroupSettingsJavaEmpty.h" #include "settings/SourceGroupSettingsJavaGradle.h" @@ -235,7 +239,7 @@ void QtProjectWizzard::windowReady() updateSourceGroupList(); - if (m_allSourceGroupSettings.size()) + if (!m_allSourceGroupSettings.empty()) { m_sourceGroupList->setCurrentRow(0); } @@ -407,7 +411,7 @@ void QtProjectWizzard::selectedSourceGroupChanged(int index) if (std::shared_ptr settingsJava = std::dynamic_pointer_cast(group)) { - summary->addContent(new QtProjectWizzardContentLanguageAndStandard(group, this)); + summary->addContent(new QtProjectWizzardContentJavaStandard(settingsJava, this)); summary->addSpace(); if (std::shared_ptr settingsJavaEmpty = std::dynamic_pointer_cast(group)) @@ -443,7 +447,7 @@ void QtProjectWizzard::selectedSourceGroupChanged(int index) } else if (std::shared_ptr settingsJavaSonargraph = std::dynamic_pointer_cast(group)) { - summary->addContent(new QtProjectWizzardContentLanguageAndStandard(group, this)); + summary->addContent(new QtProjectWizzardContentJavaStandard(settingsJavaSonargraph, this)); summary->addSpace(); summary->addContent(new QtProjectWizzardContentSonargraphProjectPath(group, this)); summary->addSpace(); @@ -456,7 +460,14 @@ void QtProjectWizzard::selectedSourceGroupChanged(int index) bool indicateSearchPathsAsAdditional = false; if (std::shared_ptr settingsCxxEmpty = std::dynamic_pointer_cast(group)) { - summary->addContent(new QtProjectWizzardContentLanguageAndStandard(group, this)); + if (std::shared_ptr settingsCEmpty = std::dynamic_pointer_cast(group)) + { + summary->addContent(new QtProjectWizzardContentCStandard(settingsCEmpty, this)); + } + else if (std::shared_ptr settingsCppEmpty = std::dynamic_pointer_cast(group)) + { + summary->addContent(new QtProjectWizzardContentCppStandard(settingsCppEmpty, this)); + } summary->addSpace(); summary->addContent(new QtProjectWizzardContentCrossCompilationOptions(group, this)); summary->addSpace(); @@ -477,11 +488,25 @@ void QtProjectWizzard::selectedSourceGroupChanged(int index) summary->addContent(new QtProjectWizzardContentPathsExclude(group, this)); summary->addSpace(); } + else if (std::shared_ptr settingsCxxCodeblocks = std::dynamic_pointer_cast(group)) + { + indicateSearchPathsAsAdditional = true; + + summary->addContent(new QtProjectWizzardContentCppStandard(settingsCxxCodeblocks, this)); + summary->addContent(new QtProjectWizzardContentCStandard(settingsCxxCodeblocks, this)); + summary->addSpace(); + summary->addContent(new QtProjectWizzardContentCodeblocksProjectPath(settingsCxxCodeblocks, this)); + summary->addSpace(); + summary->addContent(new QtProjectWizzardContentIndexedHeaderPaths("Code::Blocks project", settingsCxxCodeblocks, this)); + summary->addSpace(); + summary->addContent(new QtProjectWizzardContentExtensions(settingsCxxCodeblocks, this)); + summary->addSpace(); + } else if (std::shared_ptr settingsCxxSonargraph = std::dynamic_pointer_cast(group)) { indicateSearchPathsAsAdditional = true; - summary->addContent(new QtProjectWizzardContentLanguageAndStandard(group, this)); + summary->addContent(new QtProjectWizzardContentCppStandard(settingsCxxSonargraph, this)); summary->addSpace(); summary->addContent(new QtProjectWizzardContentSonargraphProjectPath(group, this)); summary->addSpace(); @@ -579,12 +604,17 @@ void QtProjectWizzard::duplicateSelectedSourceGroup() newSourceGroup = std::make_shared(*dynamic_cast(oldSourceGroup.get())); break; case SOURCE_GROUP_C_EMPTY: + newSourceGroup = std::make_shared(*dynamic_cast(oldSourceGroup.get())); + break; case SOURCE_GROUP_CPP_EMPTY: - newSourceGroup = std::make_shared(*dynamic_cast(oldSourceGroup.get())); + newSourceGroup = std::make_shared(*dynamic_cast(oldSourceGroup.get())); break; case SOURCE_GROUP_CXX_CDB: newSourceGroup = std::make_shared(*dynamic_cast(oldSourceGroup.get())); break; + case SOURCE_GROUP_CXX_CODEBLOCKS: + newSourceGroup = std::make_shared(*dynamic_cast(oldSourceGroup.get())); + break; case SOURCE_GROUP_CXX_SONARGRAPH: newSourceGroup = std::make_shared(*dynamic_cast(oldSourceGroup.get())); break; @@ -700,7 +730,14 @@ void QtProjectWizzard::selectedProjectType(SourceGroupType sourceGroupType) { case SOURCE_GROUP_C_EMPTY: case SOURCE_GROUP_CPP_EMPTY: - m_newSourceGroupSettings = std::make_shared(sourceGroupId, sourceGroupType, m_projectSettings.get()); + if (sourceGroupType == SOURCE_GROUP_C_EMPTY) + { + m_newSourceGroupSettings = std::make_shared(sourceGroupId, m_projectSettings.get()); + } + else + { + m_newSourceGroupSettings = std::make_shared(sourceGroupId, m_projectSettings.get()); + } if (applicationSettingsContainVisualStudioHeaderSearchPaths()) { std::vector flags; @@ -715,6 +752,10 @@ void QtProjectWizzard::selectedProjectType(SourceGroupType sourceGroupType) m_newSourceGroupSettings = std::make_shared(sourceGroupId, m_projectSettings.get()); emptySourceGroupCDB(); break; + case SOURCE_GROUP_CXX_CODEBLOCKS: + m_newSourceGroupSettings = std::make_shared(sourceGroupId, m_projectSettings.get()); + emptySourceGroupCxxCodeblocks(); + break; case SOURCE_GROUP_CXX_SONARGRAPH: m_newSourceGroupSettings = std::make_shared(sourceGroupId, m_projectSettings.get()); emptySourceGroupCxxSonargraph(); @@ -749,7 +790,18 @@ void QtProjectWizzard::emptySourceGroup() QtProjectWizzardWindow* window = createWindowWithContentGroup( [this](QtProjectWizzardWindow* window, QtProjectWizzardContentGroup* contentGroup) { - contentGroup->addContent(new QtProjectWizzardContentLanguageAndStandard(m_newSourceGroupSettings, window)); + if (std::shared_ptr settingsCEmpty = std::dynamic_pointer_cast(m_newSourceGroupSettings)) + { + contentGroup->addContent(new QtProjectWizzardContentCStandard(settingsCEmpty, this)); + } + else if (std::shared_ptr settingsCppEmpty = std::dynamic_pointer_cast(m_newSourceGroupSettings)) + { + contentGroup->addContent(new QtProjectWizzardContentCppStandard(settingsCppEmpty, this)); + } + else if (std::shared_ptr settingsJavaEmpty = std::dynamic_pointer_cast(m_newSourceGroupSettings)) + { + contentGroup->addContent(new QtProjectWizzardContentJavaStandard(settingsJavaEmpty, this)); + } if (m_newSourceGroupSettings->getType() == SOURCE_GROUP_C_EMPTY || m_newSourceGroupSettings->getType() == SOURCE_GROUP_CPP_EMPTY) { @@ -810,16 +862,42 @@ void QtProjectWizzard::emptySourceGroupCDB() window->updateSubTitle("Compilation Database Path"); } +void QtProjectWizzard::emptySourceGroupCxxCodeblocks() +{ + QtProjectWizzardWindow* window = createWindowWithContentGroup( + [this](QtProjectWizzardWindow* window, QtProjectWizzardContentGroup* contentGroup) + { + if (std::shared_ptr settings = std::dynamic_pointer_cast(m_newSourceGroupSettings)) + { + contentGroup->addContent(new QtProjectWizzardContentCppStandard(settings, this)); + contentGroup->addContent(new QtProjectWizzardContentCStandard(settings, this)); + contentGroup->addSpace(); + contentGroup->addContent(new QtProjectWizzardContentCodeblocksProjectPath(settings, window)); + contentGroup->addSpace(); + contentGroup->addContent(new QtProjectWizzardContentIndexedHeaderPaths("Code::Blocks project", settings, window)); + contentGroup->addSpace(); + contentGroup->addContent(new QtProjectWizzardContentExtensions(settings, window)); + } + } + ); + + connect(window, &QtProjectWizzardWindow::next, this, &QtProjectWizzard::createSourceGroup); + window->updateSubTitle("Code::Blocks Project Path"); +} + void QtProjectWizzard::emptySourceGroupCxxSonargraph() { QtProjectWizzardWindow* window = createWindowWithContentGroup( [this](QtProjectWizzardWindow* window, QtProjectWizzardContentGroup* contentGroup) { - contentGroup->addContent(new QtProjectWizzardContentLanguageAndStandard(m_newSourceGroupSettings, this)); - contentGroup->addSpace(); - contentGroup->addContent(new QtProjectWizzardContentSonargraphProjectPath(m_newSourceGroupSettings, window)); - contentGroup->addSpace(); - contentGroup->addContent(new QtProjectWizzardContentIndexedHeaderPaths("Sonargraph project", m_newSourceGroupSettings, window)); + if (std::shared_ptr settings = std::dynamic_pointer_cast(m_newSourceGroupSettings)) + { + contentGroup->addContent(new QtProjectWizzardContentCppStandard(settings, this)); + contentGroup->addSpace(); + contentGroup->addContent(new QtProjectWizzardContentSonargraphProjectPath(m_newSourceGroupSettings, window)); + contentGroup->addSpace(); + contentGroup->addContent(new QtProjectWizzardContentIndexedHeaderPaths("Sonargraph project", m_newSourceGroupSettings, window)); + } } ); @@ -832,7 +910,12 @@ void QtProjectWizzard::emptySourceGroupJavaSonargraph() QtProjectWizzardWindow* window = createWindowWithContentGroup( [this](QtProjectWizzardWindow* window, QtProjectWizzardContentGroup* contentGroup) { - contentGroup->addContent(new QtProjectWizzardContentSonargraphProjectPath(m_newSourceGroupSettings, window)); + if (std::shared_ptr settings = std::dynamic_pointer_cast(m_newSourceGroupSettings)) + { + contentGroup->addContent(new QtProjectWizzardContentJavaStandard(settings, this)); + contentGroup->addSpace(); + contentGroup->addContent(new QtProjectWizzardContentSonargraphProjectPath(m_newSourceGroupSettings, window)); + } } ); @@ -850,10 +933,11 @@ void QtProjectWizzard::sourcePaths() contentGroup->addContent(new QtProjectWizzardContentPathsSource(settingsCxx, window)); contentGroup->addSpace(); contentGroup->addContent(new QtProjectWizzardContentPathsExclude(settingsCxx, window)); - if (std::shared_ptr settingsSourcePath = std::dynamic_pointer_cast(m_newSourceGroupSettings)) + if (std::shared_ptr settingsSourceExtension = + std::dynamic_pointer_cast(m_newSourceGroupSettings)) { contentGroup->addSpace(); - contentGroup->addContent(new QtProjectWizzardContentExtensions(settingsSourcePath, window)); + contentGroup->addContent(new QtProjectWizzardContentExtensions(settingsSourceExtension, window)); } } } diff --git a/src/lib_gui/qt/window/project_wizzard/QtProjectWizzard.h b/src/lib_gui/qt/window/project_wizzard/QtProjectWizzard.h index 8b81c884..102b4855 100644 --- a/src/lib_gui/qt/window/project_wizzard/QtProjectWizzard.h +++ b/src/lib_gui/qt/window/project_wizzard/QtProjectWizzard.h @@ -87,6 +87,7 @@ private slots: void emptySourceGroup(); void emptySourceGroupCDBVS(); void emptySourceGroupCDB(); + void emptySourceGroupCxxCodeblocks(); void emptySourceGroupCxxSonargraph(); void emptySourceGroupJavaSonargraph(); diff --git a/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentCStandard.cpp b/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentCStandard.cpp new file mode 100644 index 00000000..8f7df189 --- /dev/null +++ b/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentCStandard.cpp @@ -0,0 +1,60 @@ +#include "qt/window/project_wizzard/QtProjectWizzardContentCStandard.h" + +#include +#include + +#include "settings/SourceGroupSettingsWithCStandard.h" + +QtProjectWizzardContentCStandard::QtProjectWizzardContentCStandard( + std::shared_ptr sourceGroupSettings, + QtProjectWizzardWindow* window +) + : QtProjectWizzardContent(window) + , m_sourceGroupSettings(sourceGroupSettings) + , m_standard(nullptr) +{ +} + +void QtProjectWizzardContentCStandard::populate(QGridLayout* layout, int& row) +{ + if (!isInForm()) + { + layout->setRowMinimumHeight(row, 15); + row++; + } + + m_standard = new QComboBox(); + layout->addWidget(createFormLabel("C Standard"), row, QtProjectWizzardWindow::FRONT_COL, Qt::AlignRight); + layout->addWidget(m_standard, row, QtProjectWizzardWindow::BACK_COL, Qt::AlignLeft); + row++; + + if (!isInForm()) + { + layout->setRowMinimumHeight(row, 15); + layout->setRowStretch(row, 1); + } +} + +void QtProjectWizzardContentCStandard::load() +{ + m_standard->clear(); + + if (m_sourceGroupSettings) + { + std::vector standards = m_sourceGroupSettings->getAvailableCStandards(); + for (size_t i = 0; i < standards.size(); i++) + { + m_standard->insertItem(i, standards[i].c_str()); + } + + m_standard->setCurrentText(QString::fromStdString(m_sourceGroupSettings->getCStandard())); + } +} + +void QtProjectWizzardContentCStandard::save() +{ + if (m_sourceGroupSettings) + { + m_sourceGroupSettings->setCStandard(m_standard->currentText().toStdString()); + } +} diff --git a/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentCStandard.h b/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentCStandard.h new file mode 100644 index 00000000..9f9d149c --- /dev/null +++ b/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentCStandard.h @@ -0,0 +1,31 @@ +#ifndef QT_PROJECT_WIZZARD_CONTENT_C_STANDARD +#define QT_PROJECT_WIZZARD_CONTENT_C_STANDARD + +#include "qt/window/project_wizzard/QtProjectWizzardContent.h" + +class QComboBox; +class SourceGroupSettingsWithCStandard; + +class QtProjectWizzardContentCStandard + : public QtProjectWizzardContent +{ + Q_OBJECT + +public: + QtProjectWizzardContentCStandard( + std::shared_ptr sourceGroupSettings, + QtProjectWizzardWindow* window); + + // QtProjectWizzardContent implementation + virtual void populate(QGridLayout* layout, int& row) override; + + virtual void load() override; + virtual void save() override; + +private: + std::shared_ptr m_sourceGroupSettings; + + QComboBox* m_standard; +}; + +#endif // QT_PROJECT_WIZZARD_CONTENT_C_STANDARD diff --git a/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentCppStandard.cpp b/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentCppStandard.cpp new file mode 100644 index 00000000..c4fbb707 --- /dev/null +++ b/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentCppStandard.cpp @@ -0,0 +1,60 @@ +#include "qt/window/project_wizzard/QtProjectWizzardContentCppStandard.h" + +#include +#include + +#include "settings/SourceGroupSettingsWithCppStandard.h" + +QtProjectWizzardContentCppStandard::QtProjectWizzardContentCppStandard( + std::shared_ptr sourceGroupSettings, + QtProjectWizzardWindow* window +) + : QtProjectWizzardContent(window) + , m_sourceGroupSettings(sourceGroupSettings) + , m_standard(nullptr) +{ +} + +void QtProjectWizzardContentCppStandard::populate(QGridLayout* layout, int& row) +{ + if (!isInForm()) + { + layout->setRowMinimumHeight(row, 15); + row++; + } + + m_standard = new QComboBox(); + layout->addWidget(createFormLabel("C++ Standard"), row, QtProjectWizzardWindow::FRONT_COL, Qt::AlignRight); + layout->addWidget(m_standard, row, QtProjectWizzardWindow::BACK_COL, Qt::AlignLeft); + row++; + + if (!isInForm()) + { + layout->setRowMinimumHeight(row, 15); + layout->setRowStretch(row, 1); + } +} + +void QtProjectWizzardContentCppStandard::load() +{ + m_standard->clear(); + + if (m_sourceGroupSettings) + { + std::vector standards = m_sourceGroupSettings->getAvailableCppStandards(); + for (size_t i = 0; i < standards.size(); i++) + { + m_standard->insertItem(i, standards[i].c_str()); + } + + m_standard->setCurrentText(QString::fromStdString(m_sourceGroupSettings->getCppStandard())); + } +} + +void QtProjectWizzardContentCppStandard::save() +{ + if (m_sourceGroupSettings) + { + m_sourceGroupSettings->setCppStandard(m_standard->currentText().toStdString()); + } +} diff --git a/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentCppStandard.h b/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentCppStandard.h new file mode 100644 index 00000000..fda58dd1 --- /dev/null +++ b/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentCppStandard.h @@ -0,0 +1,31 @@ +#ifndef QT_PROJECT_WIZZARD_CONTENT_CPP_STANDARD +#define QT_PROJECT_WIZZARD_CONTENT_CPP_STANDARD + +#include "qt/window/project_wizzard/QtProjectWizzardContent.h" + +class QComboBox; +class SourceGroupSettingsWithCppStandard; + +class QtProjectWizzardContentCppStandard + : public QtProjectWizzardContent +{ + Q_OBJECT + +public: + QtProjectWizzardContentCppStandard( + std::shared_ptr sourceGroupSettings, + QtProjectWizzardWindow* window); + + // QtProjectWizzardContent implementation + virtual void populate(QGridLayout* layout, int& row) override; + + virtual void load() override; + virtual void save() override; + +private: + std::shared_ptr m_sourceGroupSettings; + + QComboBox* m_standard; +}; + +#endif // QT_PROJECT_WIZZARD_CONTENT_CPP_STANDARD diff --git a/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentExtensions.cpp b/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentExtensions.cpp index c5e058c0..6601c6c6 100644 --- a/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentExtensions.cpp +++ b/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentExtensions.cpp @@ -2,11 +2,11 @@ #include -#include "settings/SourceGroupSettingsWithSourcePaths.h" +#include "settings/SourceGroupSettingsWithSourceExtensions.h" #include "qt/element/QtStringListBox.h" QtProjectWizzardContentExtensions::QtProjectWizzardContentExtensions( - std::shared_ptr settings, QtProjectWizzardWindow* window + std::shared_ptr settings, QtProjectWizzardWindow* window ) : QtProjectWizzardContent(window) , m_settings(settings) diff --git a/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentExtensions.h b/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentExtensions.h index 9f292042..89b72936 100644 --- a/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentExtensions.h +++ b/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentExtensions.h @@ -6,7 +6,7 @@ #include "qt/window/project_wizzard/QtProjectWizzardContent.h" class QtStringListBox; -class SourceGroupSettingsWithSourcePaths; +class SourceGroupSettingsWithSourceExtensions; class QtProjectWizzardContentExtensions : public QtProjectWizzardContent @@ -14,7 +14,7 @@ class QtProjectWizzardContentExtensions Q_OBJECT public: - QtProjectWizzardContentExtensions(std::shared_ptr settings, QtProjectWizzardWindow* window); + QtProjectWizzardContentExtensions(std::shared_ptr settings, QtProjectWizzardWindow* window); // QtProjectWizzardContent implementation virtual void populate(QGridLayout* layout, int& row) override; @@ -23,7 +23,7 @@ public: virtual void save() override; private: - std::shared_ptr m_settings; + std::shared_ptr m_settings; QtStringListBox* m_listBox; }; diff --git a/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentJavaStandard.cpp b/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentJavaStandard.cpp new file mode 100644 index 00000000..d8d44bec --- /dev/null +++ b/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentJavaStandard.cpp @@ -0,0 +1,60 @@ +#include "qt/window/project_wizzard/QtProjectWizzardContentJavaStandard.h" + +#include +#include + +#include "settings/SourceGroupSettingsWithJavaStandard.h" + +QtProjectWizzardContentJavaStandard::QtProjectWizzardContentJavaStandard( + std::shared_ptr sourceGroupSettings, + QtProjectWizzardWindow* window +) + : QtProjectWizzardContent(window) + , m_sourceGroupSettings(sourceGroupSettings) + , m_standard(nullptr) +{ +} + +void QtProjectWizzardContentJavaStandard::populate(QGridLayout* layout, int& row) +{ + if (!isInForm()) + { + layout->setRowMinimumHeight(row, 15); + row++; + } + + m_standard = new QComboBox(); + layout->addWidget(createFormLabel("Java Standard"), row, QtProjectWizzardWindow::FRONT_COL, Qt::AlignRight); + layout->addWidget(m_standard, row, QtProjectWizzardWindow::BACK_COL, Qt::AlignLeft); + row++; + + if (!isInForm()) + { + layout->setRowMinimumHeight(row, 15); + layout->setRowStretch(row, 1); + } +} + +void QtProjectWizzardContentJavaStandard::load() +{ + m_standard->clear(); + + if (m_sourceGroupSettings) + { + std::vector standards = m_sourceGroupSettings->getAvailableJavaStandards(); + for (size_t i = 0; i < standards.size(); i++) + { + m_standard->insertItem(i, standards[i].c_str()); + } + + m_standard->setCurrentText(QString::fromStdString(m_sourceGroupSettings->getJavaStandard())); + } +} + +void QtProjectWizzardContentJavaStandard::save() +{ + if (m_sourceGroupSettings) + { + m_sourceGroupSettings->setJavaStandard(m_standard->currentText().toStdString()); + } +} diff --git a/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentJavaStandard.h b/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentJavaStandard.h new file mode 100644 index 00000000..b62d57cd --- /dev/null +++ b/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentJavaStandard.h @@ -0,0 +1,31 @@ +#ifndef QT_PROJECT_WIZZARD_CONTENT_JAVA_STANDARD +#define QT_PROJECT_WIZZARD_CONTENT_JAVA_STANDARD + +#include "qt/window/project_wizzard/QtProjectWizzardContent.h" + +class QComboBox; +class SourceGroupSettingsWithJavaStandard; + +class QtProjectWizzardContentJavaStandard + : public QtProjectWizzardContent +{ + Q_OBJECT + +public: + QtProjectWizzardContentJavaStandard( + std::shared_ptr sourceGroupSettings, + QtProjectWizzardWindow* window); + + // QtProjectWizzardContent implementation + virtual void populate(QGridLayout* layout, int& row) override; + + virtual void load() override; + virtual void save() override; + +private: + std::shared_ptr m_sourceGroupSettings; + + QComboBox* m_standard; +}; + +#endif // QT_PROJECT_WIZZARD_CONTENT_JAVA_STANDARD diff --git a/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentLanguageAndStandard.cpp b/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentLanguageAndStandard.cpp deleted file mode 100644 index 42de160b..00000000 --- a/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentLanguageAndStandard.cpp +++ /dev/null @@ -1,70 +0,0 @@ -#include "qt/window/project_wizzard/QtProjectWizzardContentLanguageAndStandard.h" - -#include -#include - -#include "settings/SourceGroupSettings.h" -#include "utility/logging/logging.h" - -QtProjectWizzardContentLanguageAndStandard::QtProjectWizzardContentLanguageAndStandard( - std::shared_ptr sourceGroupSettings, - QtProjectWizzardWindow* window -) - : QtProjectWizzardContent(window) - , m_sourceGroupSettings(sourceGroupSettings) - , m_language(nullptr) - , m_standard(nullptr) -{ -} - -void QtProjectWizzardContentLanguageAndStandard::populate(QGridLayout* layout, int& row) -{ - if (!isInForm()) - { - layout->setRowMinimumHeight(row, 15); - row++; - } - - m_language = new QLabel(); - layout->addWidget(createFormLabel("Language"), row, QtProjectWizzardWindow::FRONT_COL, Qt::AlignRight); - layout->addWidget(m_language, row, QtProjectWizzardWindow::BACK_COL, Qt::AlignLeft); - row++; - - m_standard = new QComboBox(); - layout->addWidget(createFormLabel("Standard"), row, QtProjectWizzardWindow::FRONT_COL, Qt::AlignRight); - layout->addWidget(m_standard, row, QtProjectWizzardWindow::BACK_COL, Qt::AlignLeft); - row++; - - if (!isInForm()) - { - layout->setRowMinimumHeight(row, 15); - layout->setRowStretch(row, 1); - } -} - -void QtProjectWizzardContentLanguageAndStandard::load() -{ - const LanguageType type = getLanguageTypeForSourceGroupType(m_sourceGroupSettings->getType()); - - if (type == LANGUAGE_UNKNOWN) - { - LOG_ERROR("No language type defined"); - return; - } - - m_language->setText(languageTypeToString(type).c_str()); - - m_standard->clear(); - std::vector standards = m_sourceGroupSettings->getAvailableLanguageStandards(); - for (size_t i = 0; i < standards.size(); i++) - { - m_standard->insertItem(i, standards[i].c_str()); - } - - m_standard->setCurrentText(QString::fromStdString(m_sourceGroupSettings->getStandard())); -} - -void QtProjectWizzardContentLanguageAndStandard::save() -{ - m_sourceGroupSettings->setStandard(m_standard->currentText().toStdString()); -} diff --git a/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentLanguageAndStandard.h b/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentLanguageAndStandard.h deleted file mode 100644 index 45435dce..00000000 --- a/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentLanguageAndStandard.h +++ /dev/null @@ -1,33 +0,0 @@ -#ifndef QT_PROJECT_WIZZARD_CONTENT_LANGUAGE_AND_STANDARD -#define QT_PROJECT_WIZZARD_CONTENT_LANGUAGE_AND_STANDARD - -#include "qt/window/project_wizzard/QtProjectWizzardContent.h" - -class QComboBox; -class QLabel; -class SourceGroupSettings; - -class QtProjectWizzardContentLanguageAndStandard - : public QtProjectWizzardContent -{ - Q_OBJECT - -public: - QtProjectWizzardContentLanguageAndStandard( - std::shared_ptr sourceGroupSettings, - QtProjectWizzardWindow* window); - - // QtProjectWizzardContent implementation - virtual void populate(QGridLayout* layout, int& row) override; - - virtual void load() override; - virtual void save() override; - -private: - std::shared_ptr m_sourceGroupSettings; - - QLabel* m_language; - QComboBox* m_standard; -}; - -#endif // QT_PROJECT_WIZZARD_CONTENT_LANGUAGE_AND_STANDARD diff --git a/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentPath.cpp b/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentPath.cpp index bacc6230..93adaee2 100644 --- a/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentPath.cpp +++ b/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentPath.cpp @@ -16,9 +16,11 @@ #include "settings/SourceGroupSettingsJavaMaven.h" #include "settings/SourceGroupSettingsJavaGradle.h" #include "settings/SourceGroupSettingsWithSonargraphProjectPath.h" +#include "settings/SourceGroupSettingsCxxCodeblocks.h" #include "utility/file/FileManager.h" #include "utility/messaging/type/MessageStatus.h" #include "utility/sonargraph/SonargraphProject.h" +#include "utility/codeblocks/CodeblocksProject.h" #include "utility/ScopedFunctor.h" #include "utility/utility.h" #include "utility/utilityGradle.h" @@ -261,6 +263,132 @@ void QtProjectWizzardContentPathCDB::pickedPath() } +QtProjectWizzardContentCodeblocksProjectPath::QtProjectWizzardContentCodeblocksProjectPath( + std::shared_ptr settings, QtProjectWizzardWindow* window +) + : QtProjectWizzardContentPath(settings, window) +{ + setTitleString("Code::Blocks Project (.cbp)"); + setHelpString( + "Select the Code::Blocks file for the project. Sourcetrail will index your project based on the settings " + "this file. It contains using all include paths and compiler flags required. The Sourcetrail project " + "will stay up to date with changes in the Code::Blocks project on every refresh.
" + "
" + "You can make use of environment variables with ${ENV_VAR}." + ); + setFileEndings({ L".cbp" }); +} + +void QtProjectWizzardContentCodeblocksProjectPath::populate(QGridLayout* layout, int& row) +{ + QtProjectWizzardContentPath::populate(layout, row); + m_picker->setPickDirectory(false); + m_picker->setFileFilter("Code::Blocks Project (*.cbp)"); + connect(m_picker, &QtLocationPicker::locationPicked, this, &QtProjectWizzardContentCodeblocksProjectPath::pickedPath); + + QLabel* description = new QLabel( + "Sourcetrail will use all settings from the Code::Blocks project and stay up-to-date with changes on refresh.", this); + description->setObjectName("description"); + description->setWordWrap(true); + layout->addWidget(description, row, QtProjectWizzardWindow::BACK_COL); + row++; + + QLabel* title = createFormLabel("Source Files to Index"); + layout->addWidget(title, row, QtProjectWizzardWindow::FRONT_COL, Qt::AlignTop); + layout->setRowStretch(row, 0); + + m_fileCountLabel = new QLabel(""); + m_fileCountLabel->setWordWrap(true); + layout->addWidget(m_fileCountLabel, row, QtProjectWizzardWindow::BACK_COL, Qt::AlignTop); + row++; + + addFilesButton("show source files", layout, row); + row++; +} + +void QtProjectWizzardContentCodeblocksProjectPath::load() +{ + m_filePaths.clear(); + + std::shared_ptr settings = + std::dynamic_pointer_cast(m_settings); + if (settings) + { + m_picker->setText(QString::fromStdWString(settings->getCodeblocksProjectPath().wstr())); + + const FilePath codeblocksProjectPath = settings->getCodeblocksProjectPathExpandedAndAbsolute(); + if (!codeblocksProjectPath.empty() && codeblocksProjectPath.exists()) + { + if (std::shared_ptr codeblocksProject = Codeblocks::Project::load( + codeblocksProjectPath + )) + { + m_filePaths = utility::toVector(codeblocksProject->getAllSourceFilePathsCanonical(settings)); + } + } + + if (m_fileCountLabel) + { + m_fileCountLabel->setText("" + QString::number(m_filePaths.size()) + " source files were found in the Code::Blocks project."); + } + } +} + +void QtProjectWizzardContentCodeblocksProjectPath::save() +{ + std::shared_ptr settings = + std::dynamic_pointer_cast(m_settings); + if (settings) + { + settings->setCodeblocksProjectPath(FilePath(m_picker->getText().toStdWString())); + } +} + +bool QtProjectWizzardContentCodeblocksProjectPath::check() +{ + return true; +} + +std::vector QtProjectWizzardContentCodeblocksProjectPath::getFilePaths() const +{ + const_cast(this)->load(); + + return m_filePaths; +} + +QString QtProjectWizzardContentCodeblocksProjectPath::getFileNamesTitle() const +{ + return "Source Files"; +} + +QString QtProjectWizzardContentCodeblocksProjectPath::getFileNamesDescription() const +{ + return " source files will be indexed."; +} + +void QtProjectWizzardContentCodeblocksProjectPath::pickedPath() +{ + m_window->saveContent(); + + if (std::shared_ptr codeblocksSettings = std::dynamic_pointer_cast(m_settings)) + { + const FilePath projectPath = m_settings->getProjectDirectoryPath(); + + std::set indexedHeaderPaths; + for (const FilePath& path : QtProjectWizzardContentIndexedHeaderPaths::getIndexedPathsDerivedFromCodeblocksProject(codeblocksSettings)) + { + if (projectPath.contains(path)) + { + indexedHeaderPaths.insert(path.getRelativeTo(projectPath)); + } + } + codeblocksSettings->setIndexedHeaderPaths(utility::toVector(indexedHeaderPaths)); + } + + m_window->loadContent(); +} + + QtProjectWizzardContentSonargraphProjectPath::QtProjectWizzardContentSonargraphProjectPath( std::shared_ptr settings, QtProjectWizzardWindow* window ) @@ -500,26 +628,23 @@ std::vector QtProjectWizzardContentPathSourceMaven::getFilePaths() con settings->getShouldIndexMavenTests() ); - if (std::shared_ptr pathSettings = std::dynamic_pointer_cast(m_settings)) + FileManager fileManager; + fileManager.update( + sourceDirectories, + settings->getExcludeFiltersExpandedAndAbsolute(), + settings->getSourceExtensions() + ); + + const FilePath projectPath = m_settings->getProjectDirectoryPath(); + + for (FilePath path : fileManager.getAllSourceFilePaths()) { - FileManager fileManager; - fileManager.update( - sourceDirectories, - settings->getExcludeFiltersExpandedAndAbsolute(), - pathSettings->getSourceExtensions() - ); - - const FilePath projectPath = m_settings->getProjectDirectoryPath(); - - for (FilePath path : fileManager.getAllSourceFilePaths()) + if (projectPath.exists()) { - if (projectPath.exists()) - { - path.makeRelativeTo(projectPath); - } - - list.push_back(path); + path.makeRelativeTo(projectPath); } + + list.push_back(path); } } @@ -641,7 +766,7 @@ std::vector QtProjectWizzardContentPathSourceGradle::getFilePaths() co settings->getSourceExtensions() ); - const FilePath projectPath = m_settings->getProjectDirectoryPath(); + const FilePath projectPath = settings->getProjectDirectoryPath(); for (FilePath path : fileManager.getAllSourceFilePaths()) { diff --git a/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentPath.h b/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentPath.h index c5f93e1f..b1b996e0 100644 --- a/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentPath.h +++ b/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentPath.h @@ -71,6 +71,34 @@ private: }; +class QtProjectWizzardContentCodeblocksProjectPath + : public QtProjectWizzardContentPath +{ + Q_OBJECT + +public: + QtProjectWizzardContentCodeblocksProjectPath(std::shared_ptr settings, QtProjectWizzardWindow* window); + + // QtProjectWizzardContent implementation + virtual void populate(QGridLayout* layout, int& row) override; + + virtual void load() override; + virtual void save() override; + virtual bool check() override; + + virtual std::vector getFilePaths() const override; + virtual QString getFileNamesTitle() const override; + virtual QString getFileNamesDescription() const override; + +private slots: + void pickedPath(); + +private: + QLabel* m_fileCountLabel; + std::vector m_filePaths; +}; + + class QtProjectWizzardContentSonargraphProjectPath : public QtProjectWizzardContentPath { diff --git a/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentPaths.cpp b/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentPaths.cpp index 7f8d4a9e..d1d7062f 100644 --- a/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentPaths.cpp +++ b/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentPaths.cpp @@ -16,14 +16,17 @@ #include "qt/window/QtSelectPathsDialog.h" #include "settings/ApplicationSettings.h" #include "settings/SourceGroupSettingsCxxCdb.h" +#include "settings/SourceGroupSettingsCxxCodeblocks.h" #include "settings/SourceGroupSettingsCxxSonargraph.h" #include "settings/SourceGroupSettingsWithClasspath.h" #include "settings/SourceGroupSettingsWithIndexedHeaderPaths.h" #include "settings/SourceGroupSettingsWithExcludeFilters.h" +#include "settings/SourceGroupSettingsWithSourceExtensions.h" #include "settings/SourceGroupSettingsWithSourcePaths.h" -#include "utility/CompilationDatabase.h" +#include "utility/codeblocks/CodeblocksProject.h" #include "utility/file/FileManager.h" #include "utility/sonargraph/SonargraphProject.h" +#include "utility/CompilationDatabase.h" #include "utility/ScopedFunctor.h" #include "utility/utility.h" #include "utility/utilityFile.h" @@ -241,16 +244,17 @@ std::vector QtProjectWizzardContentPathsSource::getFilePaths() const std::dynamic_pointer_cast(dialogView)->setParentWindow(m_window); dialogView->showUnknownProgressDialog(L"Processing", L"Gathering Source Files"); + std::shared_ptr extensionSettings = std::dynamic_pointer_cast(m_settings); std::shared_ptr pathSettings = std::dynamic_pointer_cast(m_settings); std::shared_ptr excludeFilterSettings = std::dynamic_pointer_cast(m_settings); - if (pathSettings && excludeFilterSettings) // FIXME: pass msettings as required type + if (extensionSettings && pathSettings && excludeFilterSettings) // FIXME: pass msettings as required type { FileManager fileManager; fileManager.update( pathSettings->getSourcePathsExpandedAndAbsolute(), excludeFilterSettings->getExcludeFiltersExpandedAndAbsolute(), - pathSettings->getSourceExtensions() + extensionSettings->getSourceExtensions() ); const std::set filePaths = fileManager.getAllSourceFilePathsRelative(m_settings->getProjectDirectoryPath()); @@ -283,7 +287,7 @@ std::vector QtProjectWizzardContentIndexedHeaderPaths::getIndexedPaths { for (const FilePath& path : sonargraphProject->getAllSourceFilePathsCanonical()) { - indexedHeaderPaths.insert(path.getParentDirectory()); + indexedHeaderPaths.insert(path.getCanonical().getParentDirectory()); } utility::append(indexedHeaderPaths, sonargraphProject->getAllCxxHeaderSearchPathsCanonical()); } @@ -296,6 +300,32 @@ std::vector QtProjectWizzardContentIndexedHeaderPaths::getIndexedPaths return utility::getTopLevelPaths(indexedHeaderPaths); } +std::vector QtProjectWizzardContentIndexedHeaderPaths::getIndexedPathsDerivedFromCodeblocksProject( + std::shared_ptr settings) +{ + const FilePath projectPath = settings->getProjectDirectoryPath(); + std::set indexedHeaderPaths; + { + const FilePath codeblocksProjectPath = settings->getCodeblocksProjectPathExpandedAndAbsolute(); + if (!codeblocksProjectPath.empty() && codeblocksProjectPath.exists()) + { + if (std::shared_ptr codeblocksProject = Codeblocks::Project::load(codeblocksProjectPath)) + { + for (const FilePath& path : codeblocksProject->getAllSourceFilePathsCanonical(settings)) + { + indexedHeaderPaths.insert(path.getCanonical().getParentDirectory()); + } + utility::append(indexedHeaderPaths, codeblocksProject->getAllCxxHeaderSearchPathsCanonical()); + } + } + else + { + LOG_WARNING("Unable to fetch indexed header paths. The provided Sonargraph project path does not exist."); + } + } + return utility::getTopLevelPaths(indexedHeaderPaths); +} + std::vector QtProjectWizzardContentIndexedHeaderPaths::getIndexedPathsDerivedFromCDB( std::shared_ptr settings) { @@ -306,13 +336,13 @@ std::vector QtProjectWizzardContentIndexedHeaderPaths::getIndexedPaths { for (const FilePath& path : IndexerCommandCxxCdb::getSourceFilesFromCDB(cdbPath)) { - indexedHeaderPaths.insert(path.getParentDirectory()); + indexedHeaderPaths.insert(path.getCanonical().getParentDirectory()); } for (const FilePath& path : utility::CompilationDatabase(cdbPath).getAllHeaderPaths()) { if (path.exists()) { - indexedHeaderPaths.insert(path); + indexedHeaderPaths.insert(path.getCanonical()); } } } @@ -437,6 +467,38 @@ void QtProjectWizzardContentIndexedHeaderPaths::buttonClicked() m_settings->getProjectDirectoryPath() ); } + else if (std::shared_ptr codeblocksSettings = std::dynamic_pointer_cast(m_settings)) + { + const FilePath codeblocksProjectPath = codeblocksSettings->getCodeblocksProjectPathExpandedAndAbsolute(); + if (!codeblocksProjectPath.exists()) + { + QMessageBox msgBox; + msgBox.setText("The provided Code::Blocks project path does not exist."); + msgBox.setDetailedText(QString::fromStdWString(codeblocksProjectPath.wstr())); + msgBox.exec(); + return; + } + + m_filesDialog = std::make_shared( + "Select from Include Paths", + "The list contains all Include Paths found in the Code::Blocks project. Red paths do not exist. Select the " + "paths containing the header files you want to index with Sourcetrail."); + m_filesDialog->setup(); + + connect(m_filesDialog.get(), &QtSelectPathsDialog::finished, this, &QtProjectWizzardContentIndexedHeaderPaths::savedFilesDialog); + connect(m_filesDialog.get(), &QtSelectPathsDialog::canceled, this, &QtProjectWizzardContentIndexedHeaderPaths::closedFilesDialog); + + const FilePath projectPath = codeblocksSettings->getProjectDirectoryPath(); + + dynamic_cast(m_filesDialog.get())->setPathsList( + utility::convert( + getIndexedPathsDerivedFromCodeblocksProject(codeblocksSettings), + [&](const FilePath& path) { return path.getRelativeTo(projectPath); } + ), + codeblocksSettings->getIndexedHeaderPaths(), + m_settings->getProjectDirectoryPath() + ); + } else if (std::shared_ptr cdbSettings = std::dynamic_pointer_cast(m_settings)) { const FilePath cdbPath = cdbSettings->getCompilationDatabasePathExpandedAndAbsolute(); @@ -471,8 +533,11 @@ void QtProjectWizzardContentIndexedHeaderPaths::buttonClicked() } } - m_filesDialog->showWindow(); - m_filesDialog->raise(); + if (m_filesDialog) + { + m_filesDialog->showWindow(); + m_filesDialog->raise(); + } } void QtProjectWizzardContentIndexedHeaderPaths::savedFilesDialog() @@ -627,10 +692,11 @@ void QtProjectWizzardContentPathsHeaderSearch::validateIncludesButtonClicked() std::thread([&]() { + std::shared_ptr extensionSettings = std::dynamic_pointer_cast(m_settings); std::shared_ptr pathSettings = std::dynamic_pointer_cast(m_settings); std::shared_ptr excludeFilterSettings = std::dynamic_pointer_cast(m_settings); - if (pathSettings && excludeFilterSettings) // FIXME: pass msettings as required type + if (extensionSettings && pathSettings && excludeFilterSettings) // FIXME: pass msettings as required type { std::vector unresolvedIncludes; { @@ -651,7 +717,7 @@ void QtProjectWizzardContentPathsHeaderSearch::validateIncludesButtonClicked() fileManager.update( pathSettings->getSourcePathsExpandedAndAbsolute(), excludeFilterSettings->getExcludeFiltersExpandedAndAbsolute(), - pathSettings->getSourceExtensions() + extensionSettings->getSourceExtensions() ); sourceFilePaths = fileManager.getAllSourceFilePaths(); @@ -695,13 +761,14 @@ void QtProjectWizzardContentPathsHeaderSearch::finishedSelectDetectIncludesRootP // TODO: regard Force Includes here, too! const std::vector searchedPaths = m_settings->makePathsExpandedAndAbsolute(m_pathsDialog->getPaths()); closedPathsDialog(); - - std::shared_ptr pathSettings = std::dynamic_pointer_cast(m_settings); - std::shared_ptr excludeFilterSettings = std::dynamic_pointer_cast(m_settings); - - if (pathSettings && excludeFilterSettings) // FIXME: pass msettings as required type + + std::thread([=]() { - std::thread([=]() + std::shared_ptr extensionSettings = std::dynamic_pointer_cast(m_settings); + std::shared_ptr pathSettings = std::dynamic_pointer_cast(m_settings); + std::shared_ptr excludeFilterSettings = std::dynamic_pointer_cast(m_settings); + + if (extensionSettings && pathSettings && excludeFilterSettings) // FIXME: pass msettings as required type { std::set detectedHeaderSearchPaths; { @@ -720,7 +787,7 @@ void QtProjectWizzardContentPathsHeaderSearch::finishedSelectDetectIncludesRootP fileManager.update( pathSettings->getSourcePathsExpandedAndAbsolute(), excludeFilterSettings->getExcludeFiltersExpandedAndAbsolute(), - pathSettings->getSourceExtensions() + extensionSettings->getSourceExtensions() ); sourceFilePaths = fileManager.getAllSourceFilePaths(); @@ -753,8 +820,8 @@ void QtProjectWizzardContentPathsHeaderSearch::finishedSelectDetectIncludesRootP } m_showDetectedIncludesResultFunctor(detectedHeaderSearchPaths); - }).detach(); - } + } + }).detach(); } void QtProjectWizzardContentPathsHeaderSearch::finishedAcceptDetectedIncludePathsDialog() diff --git a/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentPaths.h b/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentPaths.h index 432ff3e3..305b068b 100644 --- a/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentPaths.h +++ b/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentPaths.h @@ -14,6 +14,7 @@ class QPushButton; class QtPathListDialog; class SourceGroupSettings; class SourceGroupSettingsCxxCdb; +class SourceGroupSettingsCxxCodeblocks; class SourceGroupSettingsCxxSonargraph; class QtProjectWizzardContentPaths @@ -88,6 +89,7 @@ class QtProjectWizzardContentIndexedHeaderPaths public: static std::vector getIndexedPathsDerivedFromSonargraphProject(std::shared_ptr settings); + static std::vector getIndexedPathsDerivedFromCodeblocksProject(std::shared_ptr settings); static std::vector getIndexedPathsDerivedFromCDB(std::shared_ptr settings); QtProjectWizzardContentIndexedHeaderPaths( diff --git a/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentSelect.cpp b/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentSelect.cpp index 83825b29..232d55a3 100644 --- a/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentSelect.cpp +++ b/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentSelect.cpp @@ -32,10 +32,12 @@ void QtProjectWizzardContentSelect::populate(QGridLayout* layout, int& row) sourceGroupInfos[LANGUAGE_C].push_back(SourceGroupInfo(SOURCE_GROUP_CXX_CDB)); sourceGroupInfos[LANGUAGE_C].push_back(SourceGroupInfo(SOURCE_GROUP_CXX_VS)); sourceGroupInfos[LANGUAGE_C].push_back(SourceGroupInfo(SOURCE_GROUP_CXX_SONARGRAPH)); + sourceGroupInfos[LANGUAGE_C].push_back(SourceGroupInfo(SOURCE_GROUP_CXX_CODEBLOCKS)); sourceGroupInfos[LANGUAGE_CPP].push_back(SourceGroupInfo(SOURCE_GROUP_CPP_EMPTY)); sourceGroupInfos[LANGUAGE_CPP].push_back(SourceGroupInfo(SOURCE_GROUP_CXX_CDB)); sourceGroupInfos[LANGUAGE_CPP].push_back(SourceGroupInfo(SOURCE_GROUP_CXX_VS)); sourceGroupInfos[LANGUAGE_CPP].push_back(SourceGroupInfo(SOURCE_GROUP_CXX_SONARGRAPH)); + sourceGroupInfos[LANGUAGE_CPP].push_back(SourceGroupInfo(SOURCE_GROUP_CXX_CODEBLOCKS)); sourceGroupInfos[LANGUAGE_JAVA].push_back(SourceGroupInfo(SOURCE_GROUP_JAVA_EMPTY)); sourceGroupInfos[LANGUAGE_JAVA].push_back(SourceGroupInfo(SOURCE_GROUP_JAVA_MAVEN)); sourceGroupInfos[LANGUAGE_JAVA].push_back(SourceGroupInfo(SOURCE_GROUP_JAVA_GRADLE)); @@ -47,6 +49,7 @@ void QtProjectWizzardContentSelect::populate(QGridLayout* layout, int& row) m_sourceGroupTypeIconName[SOURCE_GROUP_CXX_CDB] = L"cdb_icon"; m_sourceGroupTypeIconName[SOURCE_GROUP_CXX_VS] = L"vs_icon"; m_sourceGroupTypeIconName[SOURCE_GROUP_CXX_SONARGRAPH] = L"sonargraph_icon"; + m_sourceGroupTypeIconName[SOURCE_GROUP_CXX_CODEBLOCKS] = L"empty_icon"; // TODO: change this m_sourceGroupTypeIconName[SOURCE_GROUP_JAVA_EMPTY] = L"empty_icon"; m_sourceGroupTypeIconName[SOURCE_GROUP_JAVA_MAVEN] = L"mvn_icon"; m_sourceGroupTypeIconName[SOURCE_GROUP_JAVA_GRADLE] = L"gradle_icon"; @@ -62,6 +65,7 @@ void QtProjectWizzardContentSelect::populate(QGridLayout* layout, int& row) "Note: Requires a running Visual Studio instance with the " "Visual Studio plugin installed."; m_sourceGroupTypeDescriptions[SOURCE_GROUP_CXX_SONARGRAPH] = "Create a new Source Group from an existing Sonargraph project file."; + m_sourceGroupTypeDescriptions[SOURCE_GROUP_CXX_CODEBLOCKS] = "Create a new Source Group from an existing Code::Blocks project file."; m_sourceGroupTypeDescriptions[SOURCE_GROUP_JAVA_EMPTY] = "Create a new Sourcetrail Source Group by defining which Java files will be indexed."; m_sourceGroupTypeDescriptions[SOURCE_GROUP_JAVA_MAVEN] = "Create a new Source Group from an existing Maven project."; m_sourceGroupTypeDescriptions[SOURCE_GROUP_JAVA_GRADLE] = "Create a new Source Group from an existing Gradle project."; diff --git a/src/lib_java/project/SourceGroupJava.cpp b/src/lib_java/project/SourceGroupJava.cpp index 742c109a..c42c6517 100644 --- a/src/lib_java/project/SourceGroupJava.cpp +++ b/src/lib_java/project/SourceGroupJava.cpp @@ -32,7 +32,7 @@ std::set SourceGroupJava::getAllSourceFilePaths() const std::vector> SourceGroupJava::getIndexerCommands(const std::set& filesToIndex) const { - const std::string languageStandard = getSourceGroupSettingsJava()->getStandard(); + const std::string languageStandard = getSourceGroupSettingsJava()->getJavaStandard(); std::vector classPath = getClassPath(); diff --git a/src/lib_java/project/SourceGroupJavaSonargraph.cpp b/src/lib_java/project/SourceGroupJavaSonargraph.cpp index 860a0e1a..e36795a0 100644 --- a/src/lib_java/project/SourceGroupJavaSonargraph.cpp +++ b/src/lib_java/project/SourceGroupJavaSonargraph.cpp @@ -42,17 +42,23 @@ bool SourceGroupJavaSonargraph::prepareIndexing() std::set SourceGroupJavaSonargraph::filterToContainedFilePaths(const std::set& filePaths) const { - if (std::shared_ptr project = Sonargraph::Project::load( - m_settings->getSonargraphProjectPathExpandedAndAbsolute(), getLanguage() - )) + std::set containedFilePaths; + + const std::set indexedPaths = getAllSourceFilePaths(); + + for (const FilePath& filePath : filePaths) { - return project->filterToContainedFilePaths(filePaths); + for (const FilePath& indexedPath : indexedPaths) + { + if (indexedPath == filePath || indexedPath.contains(filePath)) + { + containedFilePaths.insert(filePath); + break; + } + } } - else - { - LOG_ERROR("Unable to load Sonargraph project to check the containment of file paths."); - } - return std::set(); + + return containedFilePaths; } std::set SourceGroupJavaSonargraph::getAllSourceFilePaths() const diff --git a/src/lib_utility/utility/utilityString.h b/src/lib_utility/utility/utilityString.h index 409ec401..0c3a9a91 100644 --- a/src/lib_utility/utility/utilityString.h +++ b/src/lib_utility/utility/utilityString.h @@ -1,6 +1,7 @@ #ifndef UTILITY_STRING_H #define UTILITY_STRING_H +#include #include #include #include diff --git a/src/test/RefreshInfoGeneratorTestSuite.h b/src/test/RefreshInfoGeneratorTestSuite.h index 712c649d..5985a0e4 100644 --- a/src/test/RefreshInfoGeneratorTestSuite.h +++ b/src/test/RefreshInfoGeneratorTestSuite.h @@ -425,17 +425,6 @@ private: : SourceGroupSettings("TEST_ID", SOURCE_GROUP_UNKNOWN, projectSettings) { } - - std::vector getAvailableLanguageStandards() const override - { - return std::vector(); - } - - private: - std::string getDefaultStandard() const override - { - return ""; - } }; class SourceGroupTest : public SourceGroup