From 3cbe83f9e6028343c6485eff78ad3b2a088b16bd Mon Sep 17 00:00:00 2001 From: malte_langkabel Date: Wed, 8 Mar 2017 14:55:42 +0100 Subject: [PATCH] logic: maven project setup * added option to create a Coati project from a Maven POM file * show list of indexed file paths in maven project setup * use FileManager to detect indexed files in project setup (except cdb) * added Maven path to preferences window and added path detectors. * fixed: QtDialogView::hideStatusDialog now also hides loader in status bar. * refactored ProjectType fortune cookie message = If you continually give, you will continually have. --- CMakeLists.txt | 6 +- bin/app/data/gui/window/window.css | 2 +- bin/test/data/log/test_log.txt | 74 ------ src/app/main.cpp | 26 +- src/lib/Application.cpp | 21 +- src/lib/Application.h | 2 +- src/lib/CMakeLists.txt | 4 + src/lib/Project.cpp | 8 +- src/lib/Project.h | 6 +- src/lib/ProjectFactory.cpp | 2 +- src/lib/ProjectFactory.h | 2 +- src/lib/ProjectFactoryModule.h | 2 +- src/lib/component/ComponentManager.cpp | 4 +- src/lib/component/ComponentManager.h | 2 +- .../controller/StatusBarController.cpp | 5 +- src/lib/data/TaskCleanStorage.cpp | 4 +- src/lib/data/TaskCleanStorage.h | 4 +- src/lib/data/TaskFinishParsing.cpp | 2 +- src/lib/data/TaskFinishParsing.h | 4 +- src/lib/data/TaskShowStatusDialog.cpp | 2 +- src/lib/data/TaskShowStatusDialog.h | 4 +- src/lib/data/indexer/TaskBuildIndex.cpp | 2 +- src/lib/data/indexer/TaskBuildIndex.h | 4 +- src/lib/data/parser/TaskParseWrapper.cpp | 2 +- src/lib/data/parser/TaskParseWrapper.h | 4 +- src/lib/settings/ApplicationSettings.cpp | 10 + src/lib/settings/ApplicationSettings.h | 3 + src/lib/settings/CxxProjectSettings.cpp | 25 ++ src/lib/settings/CxxProjectSettings.h | 2 + src/lib/settings/JavaProjectSettings.cpp | 48 +++- src/lib/settings/JavaProjectSettings.h | 15 +- src/lib/settings/LanguageType.cpp | 22 ++ src/lib/settings/LanguageType.h | 3 + src/lib/settings/ProjectSettings.cpp | 5 + src/lib/settings/ProjectSettings.h | 4 +- src/lib/settings/ProjectType.cpp | 53 ++++ src/lib/settings/ProjectType.h | 20 ++ src/lib/utility/file/FileManager.cpp | 24 +- src/lib/utility/file/FileManager.h | 2 +- .../solution/SolutionParserUtility.cpp | 57 +---- .../utility/solution/SolutionParserUtility.h | 3 +- src/lib/utility/utility.h | 31 +++ src/lib/utility/utilityString.cpp | 41 ++++ src/lib/utility/utilityString.h | 2 + src/lib/utility/utilityXml.cpp | 153 ++++++++++++ src/lib/utility/utilityXml.h | 19 ++ src/lib_cxx/CxxProject.cpp | 2 +- src/lib_cxx/CxxProject.h | 2 +- src/lib_cxx/ProjectFactoryModuleC.cpp | 2 +- src/lib_cxx/ProjectFactoryModuleC.h | 2 +- src/lib_cxx/ProjectFactoryModuleCpp.cpp | 2 +- src/lib_cxx/ProjectFactoryModuleCpp.h | 2 +- src/lib_gui/CMakeLists.txt | 7 + .../project_wizzard/QtProjectWizzard.cpp | 157 ++++++------ .../window/project_wizzard/QtProjectWizzard.h | 9 +- .../QtProjectWizzardContent.cpp | 7 +- .../QtProjectWizzardContentBuildFile.cpp | 120 +++------ .../QtProjectWizzardContentBuildFile.h | 7 +- .../QtProjectWizzardContentPath.cpp | 203 ++++++++++++++++ .../QtProjectWizzardContentPath.h | 69 ++++++ .../QtProjectWizzardContentPaths.cpp | 32 +-- .../QtProjectWizzardContentPaths.h | 1 - .../QtProjectWizzardContentPreferences.cpp | 97 +++++++- .../QtProjectWizzardContentPreferences.h | 6 + .../QtProjectWizzardContentSelect.cpp | 230 +++++++++--------- .../QtProjectWizzardContentSelect.h | 16 +- .../QtProjectWizzardWindow.cpp | 7 +- .../project_wizzard/QtProjectWizzardWindow.h | 2 + .../MavenPathDetectorUnix.cpp | 25 ++ .../maven_executable/MavenPathDetectorUnix.h | 15 ++ .../MavenPathDetectorWindows.cpp | 25 ++ .../MavenPathDetectorWindows.h | 15 ++ src/lib_gui/utility/utilityApp.cpp | 10 +- src/lib_gui/utility/utilityApp.h | 5 +- src/lib_gui/utility/utilityPathDetection.cpp | 18 ++ src/lib_gui/utility/utilityPathDetection.h | 1 + src/lib_java/CMakeLists.txt | 3 + src/lib_java/JavaProject.cpp | 85 ++++++- src/lib_java/JavaProject.h | 2 +- src/lib_java/ProjectFactoryModuleJava.cpp | 2 +- src/lib_java/ProjectFactoryModuleJava.h | 2 +- src/lib_java/utility/utilityMaven.cpp | 104 ++++++++ src/lib_java/utility/utilityMaven.h | 13 + 83 files changed, 1502 insertions(+), 545 deletions(-) create mode 100644 src/lib/settings/ProjectType.cpp create mode 100644 src/lib/settings/ProjectType.h create mode 100644 src/lib/utility/utilityXml.cpp create mode 100644 src/lib/utility/utilityXml.h create mode 100644 src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentPath.cpp create mode 100644 src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentPath.h create mode 100644 src/lib_gui/utility/path_detector/maven_executable/MavenPathDetectorUnix.cpp create mode 100644 src/lib_gui/utility/path_detector/maven_executable/MavenPathDetectorUnix.h create mode 100644 src/lib_gui/utility/path_detector/maven_executable/MavenPathDetectorWindows.cpp create mode 100644 src/lib_gui/utility/path_detector/maven_executable/MavenPathDetectorWindows.h create mode 100644 src/lib_java/utility/utilityMaven.cpp create mode 100644 src/lib_java/utility/utilityMaven.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 9f9253aa..9c45c472 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -217,8 +217,6 @@ set_property( "${CMAKE_SOURCE_DIR}/src/lib" "${CMAKE_SOURCE_DIR}/src/external" "${CMAKE_SOURCE_DIR}/src/lib_license" - "${CMAKE_SOURCE_DIR}/src/lib_cxx" - "${CMAKE_SOURCE_DIR}/src/lib_java" "${CMAKE_BINARY_DIR}/src/lib_license" ) @@ -275,6 +273,7 @@ set_property( PROPERTY INCLUDE_DIRECTORIES "${CMAKE_SOURCE_DIR}/src/lib_java" "${CMAKE_SOURCE_DIR}/src/lib" + "${CMAKE_SOURCE_DIR}/src/lib_gui" ) target_include_directories(${LIB_JAVA_PROJECT_NAME} SYSTEM @@ -284,6 +283,8 @@ target_include_directories(${LIB_JAVA_PROJECT_NAME} SYSTEM link_directories(${Boost_LIBRARY_DIRS}) +target_link_libraries(${LIB_JAVA_PROJECT_NAME} ${LIB_PROJECT_NAME}) + add_custom_command( TARGET ${LIB_JAVA_PROJECT_NAME} PRE_BUILD @@ -361,6 +362,7 @@ set_property( "${CMAKE_SOURCE_DIR}/src/lib_gui" "${CMAKE_SOURCE_DIR}/src/lib" "${CMAKE_SOURCE_DIR}/src/lib_cxx" + "${CMAKE_SOURCE_DIR}/src/lib_java" "${CMAKE_SOURCE_DIR}/src/lib_license" "${CMAKE_BINARY_DIR}/src/lib_gui" "${CMAKE_BINARY_DIR}/src/lib_license" diff --git a/bin/app/data/gui/window/window.css b/bin/app/data/gui/window/window.css index 228f42e3..09b07372 100644 --- a/bin/app/data/gui/window/window.css +++ b/bin/app/data/gui/window/window.css @@ -154,7 +154,7 @@ QLabel, QCheckBox { color: black; font-size: 12px; width: 7em; - height: 7em; + height: 8em; margin-top: 10px; } diff --git a/bin/test/data/log/test_log.txt b/bin/test/data/log/test_log.txt index e1103410..e69de29b 100644 --- a/bin/test/data/log/test_log.txt +++ b/bin/test/data/log/test_log.txt @@ -1,74 +0,0 @@ -Token.cpp ERROR: Location Id was not referenced by this Token. -Node.cpp WARNING: Cannot change NodeType after it was already set from namespace to class -Edge.cpp ERROR: Nodes are not plain copies. - INFO: send MessageStatus Enabled console and file logging. - INFO: send TestMessage - INFO: send TestMessage - INFO: send TestMessage - INFO: send TestMessage2 - INFO: send TestMessage - INFO: send TestMessage2 - INFO: send TestMessage - INFO: send TestMessage - INFO: send TestMessage2 - INFO: send TestMessage - INFO: send TestMessage - INFO: send TestMessage - INFO: send TestMessage - INFO: send TestMessage - INFO: send TestMessage -NetworkProtocolHelper.cpp ERROR: Failed to parse message, invalid type token: foo. Expected setActiveToken -NetworkProtocolHelper.cpp ERROR: Failed to parse setActiveToken message, invalid token count -Settings.cpp WARNING: File for Settings not found: data/SettingsTestSuite/wrong_settings.xml -Settings.cpp WARNING: File for Settings not found: data/SettingsTestSuite/wrong_settings.xml -TextAccess.cpp ERROR: Could not open file path/to/test.h -TextAccess.cpp WARNING: Index 'firstLine' has to be lower or equal index 'lastLine', is 3 > 2 -TextAccess.cpp WARNING: Tried to access index 10. Maximum index is 8 -TextAccess.cpp WARNING: Tried to access index 10. Maximum index is 8 -TextAccess.cpp WARNING: Line numbers start with one, is 0 -TextAccess.cpp WARNING: Line numbers start with one, is 0 -TokenLocationCollection.cpp ERROR: TokenLocation has wrong boundaries: file.c 2:3 2:1 -TokenLocationCollection.cpp ERROR: TokenLocation has wrong boundaries: file.c 4:1 1:10 - INFO: Indexer - indexing source file: input.cc - INFO: Indexer - indexing source file: input.cc - INFO: Indexer - indexing source file: input.cc - INFO: Indexer - indexing source file: input.cc - INFO: Indexer - indexing source file: input.cc - INFO: Indexer - indexing source file: input.cc - INFO: Indexer - indexing source file: input.cc - INFO: Indexer - indexing source file: input.cc - INFO: Indexer - indexing source file: input.cc - INFO: Indexer - indexing source file: input.cc - INFO: Indexer - indexing source file: input.cc - INFO: Indexer - indexing source file: input.cc - INFO: Indexer - indexing source file: input.cc - INFO: Indexer - indexing source file: input.cc - INFO: Indexer - indexing source file: input.cc - INFO: Indexer - indexing source file: input.cc - INFO: Indexer - indexing source file: input.cc - INFO: Indexer - indexing source file: input.cc - INFO: Indexer - indexing source file: input.cc - INFO: Indexer - indexing source file: input.cc - INFO: Indexer - indexing source file: input.cc - INFO: Indexer - indexing source file: input.cc - INFO: Indexer - indexing source file: input.cc - INFO: Indexer - indexing source file: input.cc - INFO: Indexer - indexing source file: input.cc - INFO: Indexer - indexing source file: input.cc - INFO: Indexer - indexing source file: input.cc - INFO: Indexer - indexing source file: input.cc - INFO: Indexer - indexing source file: input.cc - INFO: Indexer - indexing source file: input.cc - INFO: Indexer - indexing source file: input.cc - INFO: Indexer - indexing source file: input.cc - INFO: Indexer - indexing source file: input.cc - INFO: Indexer - indexing source file: input.cc - INFO: Indexer - indexing source file: input.cc - INFO: Indexer - indexing source file: input.cc - INFO: Indexer - indexing source file: input.cc - INFO: Indexer - indexing source file: input.cc - INFO: Indexer - indexing source file: input.cc - INFO: Indexer - indexing source file: input.cc - INFO: Indexer - indexing source file: input.cc - INFO: Indexer - indexing source file: input.cc - INFO: Indexer - indexing source file: input.cc diff --git a/src/app/main.cpp b/src/app/main.cpp index 7064c14d..c749d9bb 100644 --- a/src/app/main.cpp +++ b/src/app/main.cpp @@ -9,8 +9,6 @@ #include "data/indexer/IndexerFactoryModuleCxxCdb.h" #include "data/indexer/IndexerFactoryModuleCxxManual.h" - - #include "includes.h" // defines 'void setup(int argc, char *argv[])' #include "LicenseChecker.h" #include "qt/network/QtNetworkFactory.h" @@ -66,7 +64,27 @@ void prefillJavaRuntimePath() else { MessageStatus("Run Java runtime path detection, no path found."); - std::cout << "no javapath" << std::endl; + } + } +} + +void prefillMavenExecutablePath() +{ + std::shared_ptr settings = ApplicationSettings::getInstance(); + if (settings->getMavenPath().empty()) + { + std::shared_ptr mavenPathDetector = utility::getMavenExecutablePathDetector(); + std::vector paths = mavenPathDetector->getPaths(); + if (!paths.empty()) + { + MessageStatus("Run Maven executable path detection, found: " + paths.front().str()); + + settings->setMavenPath(paths.front().str()); + settings->save(); + } + else + { + MessageStatus("Run Maven executable path detection, no path found."); } } } @@ -142,6 +160,7 @@ int main(int argc, char *argv[]) }); prefillJavaRuntimePath(); + prefillMavenExecutablePath(); prefillCxxHeaderPaths(); prefillCxxFrameworkPaths(); @@ -203,6 +222,7 @@ int main(int argc, char *argv[]) }); prefillJavaRuntimePath(); + prefillMavenExecutablePath(); prefillCxxHeaderPaths(); prefillCxxFrameworkPaths(); diff --git a/src/lib/Application.cpp b/src/lib/Application.cpp index b9d678d0..cd75a7d1 100644 --- a/src/lib/Application.cpp +++ b/src/lib/Application.cpp @@ -130,6 +130,16 @@ int Application::handleDialog(const std::string& message, const std::vectorconfirm(message, options); } +std::shared_ptr Application::getDialogView() +{ + if (m_componentManager) + { + return m_componentManager->getDialogView(); + } + + return std::shared_ptr(); +} + bool Application::isInTrial() const { return m_isInTrial; @@ -303,17 +313,6 @@ void Application::updateRecentProjects(const FilePath& projectSettingsFilePath) } } -DialogView* Application::getDialogView() const -{ - if (m_componentManager) - { - return m_componentManager->getDialogView(); - } - - static DialogView dialogView(nullptr); - return &dialogView; -} - void Application::logStorageStats() const { if (!ApplicationSettings::getInstance()->getLoggingEnabled()) diff --git a/src/lib/Application.h b/src/lib/Application.h index f19c5cd9..a75d9ea0 100644 --- a/src/lib/Application.h +++ b/src/lib/Application.h @@ -51,6 +51,7 @@ public: int handleDialog(const std::string& message); int handleDialog(const std::string& message, const std::vector& options); + std::shared_ptr getDialogView(); bool isInTrial() const; @@ -70,7 +71,6 @@ private: void updateRecentProjects(const FilePath& projectSettingsFilePath); - DialogView* getDialogView() const; void logStorageStats() const; void updateTitle(); diff --git a/src/lib/CMakeLists.txt b/src/lib/CMakeLists.txt index 3e2b1efa..c3a1f6e4 100644 --- a/src/lib/CMakeLists.txt +++ b/src/lib/CMakeLists.txt @@ -236,6 +236,8 @@ add_files( settings/LanguageType.h settings/ProjectSettings.cpp settings/ProjectSettings.h + settings/ProjectType.cpp + settings/ProjectType.h settings/Settings.cpp settings/Settings.h settings/SettingsMigrator.cpp @@ -442,6 +444,8 @@ add_files( utility/utilityLibrary.h utility/utilityString.cpp utility/utilityString.h + utility/utilityXml.cpp + utility/utilityXml.h utility/UUIDUtility.cpp utility/UUIDUtility.h utility/Version.cpp diff --git a/src/lib/Project.cpp b/src/lib/Project.cpp index 171eb8a4..e760c5ff 100644 --- a/src/lib/Project.cpp +++ b/src/lib/Project.cpp @@ -34,8 +34,6 @@ #include "utility/Version.h" #include "Application.h" -#include "CxxProject.h" -#include "JavaProject.h" Project::~Project() { @@ -156,8 +154,6 @@ std::string Project::getDescription() const return getProjectSettings()->getDescription(); } -#include "utility/file/FileSystem.h" - std::set Project::getSourceFilePaths() const { return m_fileManager.getSourceFilePaths(); @@ -176,14 +172,14 @@ void Project::setStateSettingsUpdated() } } -Project::Project(StorageAccessProxy* storageAccessProxy, DialogView* dialogView) +Project::Project(StorageAccessProxy* storageAccessProxy, std::shared_ptr dialogView) : m_storageAccessProxy(storageAccessProxy) , m_dialogView(dialogView) , m_state(PROJECT_STATE_NOT_LOADED) { } -DialogView* Project::getDialogView() const +std::shared_ptr Project::getDialogView() const { return m_dialogView; } diff --git a/src/lib/Project.h b/src/lib/Project.h index 3864f31d..ce567e3c 100644 --- a/src/lib/Project.h +++ b/src/lib/Project.h @@ -35,8 +35,8 @@ public: void setStateSettingsUpdated(); protected: - Project(StorageAccessProxy* storageAccessProxy, DialogView* dialogView); - DialogView* getDialogView() const; + Project(StorageAccessProxy* storageAccessProxy, std::shared_ptr dialogView); + std::shared_ptr getDialogView() const; std::vector getSourcePaths() const; virtual std::shared_ptr getProjectSettings() = 0; @@ -70,7 +70,7 @@ private: virtual void updateFileManager(FileManager& fileManager) = 0; StorageAccessProxy* const m_storageAccessProxy; - DialogView* m_dialogView; + std::shared_ptr m_dialogView; ProjectStateType m_state; FileManager m_fileManager; diff --git a/src/lib/ProjectFactory.cpp b/src/lib/ProjectFactory.cpp index 7b3045ad..dde690a3 100644 --- a/src/lib/ProjectFactory.cpp +++ b/src/lib/ProjectFactory.cpp @@ -14,7 +14,7 @@ void ProjectFactory::addModule(std::shared_ptr module) } std::shared_ptr ProjectFactory::createProject( - const FilePath& projectSettingsFile, StorageAccessProxy* storageAccessProxy, DialogView* dialogView) + const FilePath& projectSettingsFile, StorageAccessProxy* storageAccessProxy, std::shared_ptr dialogView) { std::shared_ptr project; diff --git a/src/lib/ProjectFactory.h b/src/lib/ProjectFactory.h index 11a73766..74a8f764 100644 --- a/src/lib/ProjectFactory.h +++ b/src/lib/ProjectFactory.h @@ -18,7 +18,7 @@ public: void addModule(std::shared_ptr module); std::shared_ptr createProject( - const FilePath& projectSettingsFile, StorageAccessProxy* storageAccessProxy, DialogView* dialogView); + const FilePath& projectSettingsFile, StorageAccessProxy* storageAccessProxy, std::shared_ptr dialogView); private: std::map> m_modules; diff --git a/src/lib/ProjectFactoryModule.h b/src/lib/ProjectFactoryModule.h index 1776a7f9..1beedf6b 100644 --- a/src/lib/ProjectFactoryModule.h +++ b/src/lib/ProjectFactoryModule.h @@ -17,7 +17,7 @@ public: virtual LanguageType getLanguage() const = 0; virtual std::shared_ptr createProject( - const FilePath& projectSettingsFile, StorageAccessProxy* storageAccessProxy, DialogView* dialogView + const FilePath& projectSettingsFile, StorageAccessProxy* storageAccessProxy, std::shared_ptr dialogView ) = 0; }; diff --git a/src/lib/component/ComponentManager.cpp b/src/lib/component/ComponentManager.cpp index dbfc9183..cf193d67 100644 --- a/src/lib/component/ComponentManager.cpp +++ b/src/lib/component/ComponentManager.cpp @@ -110,9 +110,9 @@ void ComponentManager::refreshViews() } } -DialogView* ComponentManager::getDialogView() const +std::shared_ptr ComponentManager::getDialogView() const { - return m_dialogView.get(); + return m_dialogView; } ComponentManager::ComponentManager() diff --git a/src/lib/component/ComponentManager.h b/src/lib/component/ComponentManager.h index 46450be7..ce44ddad 100644 --- a/src/lib/component/ComponentManager.h +++ b/src/lib/component/ComponentManager.h @@ -28,7 +28,7 @@ public: void clearComponents(); void refreshViews(); - DialogView* getDialogView() const; + std::shared_ptr getDialogView() const; private: ComponentManager(); diff --git a/src/lib/component/controller/StatusBarController.cpp b/src/lib/component/controller/StatusBarController.cpp index 9b0f2f16..e57cea87 100644 --- a/src/lib/component/controller/StatusBarController.cpp +++ b/src/lib/component/controller/StatusBarController.cpp @@ -73,7 +73,8 @@ void StatusBarController::setStatus(const std::string& status, bool isError, boo if (!status.empty()) { LOG_INFO_STREAM(<< "STATUS " << status); - - getView()->showMessage(status, isError, showLoader); } + + getView()->showMessage(status, isError, showLoader); + } diff --git a/src/lib/data/TaskCleanStorage.cpp b/src/lib/data/TaskCleanStorage.cpp index 57d742d6..60535bc0 100644 --- a/src/lib/data/TaskCleanStorage.cpp +++ b/src/lib/data/TaskCleanStorage.cpp @@ -6,7 +6,7 @@ #include "utility/utility.h" TaskCleanStorage::TaskCleanStorage( - PersistentStorage* storage, const std::vector& filePaths, DialogView* dialogView + PersistentStorage* storage, const std::vector& filePaths, std::shared_ptr dialogView ) : m_storage(storage) , m_filePaths(filePaths) @@ -28,7 +28,7 @@ void TaskCleanStorage::doEnter(std::shared_ptr blackboard) Task::TaskState TaskCleanStorage::doUpdate(std::shared_ptr blackboard) { - DialogView* dialogView = m_dialogView; + std::shared_ptr dialogView = m_dialogView; m_storage->clearFileElements(m_filePaths, [=](int progress) { if (dialogView != nullptr) diff --git a/src/lib/data/TaskCleanStorage.h b/src/lib/data/TaskCleanStorage.h index 735db161..f987303c 100644 --- a/src/lib/data/TaskCleanStorage.h +++ b/src/lib/data/TaskCleanStorage.h @@ -17,7 +17,7 @@ public: TaskCleanStorage( PersistentStorage* storage, const std::vector& filePaths, - DialogView* dialogView + std::shared_ptr dialogView ); private: @@ -28,7 +28,7 @@ private: PersistentStorage* m_storage; std::vector m_filePaths; - DialogView* m_dialogView; + std::shared_ptr m_dialogView; TimePoint m_start; }; diff --git a/src/lib/data/TaskFinishParsing.cpp b/src/lib/data/TaskFinishParsing.cpp index f17f5ecb..111fa440 100644 --- a/src/lib/data/TaskFinishParsing.cpp +++ b/src/lib/data/TaskFinishParsing.cpp @@ -10,7 +10,7 @@ TaskFinishParsing::TaskFinishParsing( PersistentStorage* storage, StorageAccess* storageAccess, - DialogView* dialogView + std::shared_ptr dialogView ) : m_storage(storage) , m_storageAccess(storageAccess) diff --git a/src/lib/data/TaskFinishParsing.h b/src/lib/data/TaskFinishParsing.h index 10e1e6a2..861ca6ed 100644 --- a/src/lib/data/TaskFinishParsing.h +++ b/src/lib/data/TaskFinishParsing.h @@ -18,7 +18,7 @@ public: TaskFinishParsing( PersistentStorage* storage, StorageAccess* storageAccess, - DialogView* dialogView + std::shared_ptr dialogView ); virtual ~TaskFinishParsing(); @@ -31,7 +31,7 @@ private: PersistentStorage* m_storage; StorageAccess* m_storageAccess; - DialogView* m_dialogView; + std::shared_ptr m_dialogView; }; #endif // TASK_FINISH_PARSING_H diff --git a/src/lib/data/TaskShowStatusDialog.cpp b/src/lib/data/TaskShowStatusDialog.cpp index 1401b423..959182ed 100644 --- a/src/lib/data/TaskShowStatusDialog.cpp +++ b/src/lib/data/TaskShowStatusDialog.cpp @@ -5,7 +5,7 @@ TaskShowStatusDialog::TaskShowStatusDialog( const std::string& title, const std::string& message, - DialogView* dialogView + std::shared_ptr dialogView ) : m_title(title) , m_message(message) diff --git a/src/lib/data/TaskShowStatusDialog.h b/src/lib/data/TaskShowStatusDialog.h index 972dd29b..352a6ad4 100644 --- a/src/lib/data/TaskShowStatusDialog.h +++ b/src/lib/data/TaskShowStatusDialog.h @@ -14,7 +14,7 @@ public: TaskShowStatusDialog( const std::string& title, const std::string& message, - DialogView* dialogView + std::shared_ptr dialogView ); virtual ~TaskShowStatusDialog(); @@ -27,7 +27,7 @@ private: const std::string m_title; const std::string m_message; - DialogView* m_dialogView; + std::shared_ptr m_dialogView; }; #endif // TASK_SHOW_STATUS_DIALOG_H diff --git a/src/lib/data/indexer/TaskBuildIndex.cpp b/src/lib/data/indexer/TaskBuildIndex.cpp index f3b5c2bb..e97e18f9 100644 --- a/src/lib/data/indexer/TaskBuildIndex.cpp +++ b/src/lib/data/indexer/TaskBuildIndex.cpp @@ -14,7 +14,7 @@ TaskBuildIndex::TaskBuildIndex( std::shared_ptr indexerCommandList, std::shared_ptr storageProvider, std::shared_ptr fileRegisterStateData, - DialogView* dialogView + std::shared_ptr dialogView ) : m_indexerCommandList(indexerCommandList) , m_storageProvider(storageProvider) diff --git a/src/lib/data/indexer/TaskBuildIndex.h b/src/lib/data/indexer/TaskBuildIndex.h index ae635e89..1831604f 100644 --- a/src/lib/data/indexer/TaskBuildIndex.h +++ b/src/lib/data/indexer/TaskBuildIndex.h @@ -22,7 +22,7 @@ public: std::shared_ptr indexerCommandList, std::shared_ptr storageProvider, std::shared_ptr fileRegisterStateData, - DialogView* dialogView + std::shared_ptr dialogView ); protected: @@ -36,7 +36,7 @@ protected: std::shared_ptr m_indexerCommandList; std::shared_ptr m_storageProvider; std::shared_ptr m_fileRegisterStateData; - DialogView* m_dialogView; + std::shared_ptr m_dialogView; std::shared_ptr m_indexer; }; diff --git a/src/lib/data/parser/TaskParseWrapper.cpp b/src/lib/data/parser/TaskParseWrapper.cpp index 448c9e03..b6ff302f 100644 --- a/src/lib/data/parser/TaskParseWrapper.cpp +++ b/src/lib/data/parser/TaskParseWrapper.cpp @@ -7,7 +7,7 @@ TaskParseWrapper::TaskParseWrapper( PersistentStorage* storage, - DialogView* dialogView + std::shared_ptr dialogView ) : m_storage(storage) , m_dialogView(dialogView) diff --git a/src/lib/data/parser/TaskParseWrapper.h b/src/lib/data/parser/TaskParseWrapper.h index a907b0ee..39cf2b89 100644 --- a/src/lib/data/parser/TaskParseWrapper.h +++ b/src/lib/data/parser/TaskParseWrapper.h @@ -20,7 +20,7 @@ class TaskParseWrapper public: TaskParseWrapper( PersistentStorage* storage, - DialogView* dialogView + std::shared_ptr dialogView ); virtual ~TaskParseWrapper(); @@ -33,7 +33,7 @@ private: virtual void doReset(std::shared_ptr blackboard); PersistentStorage* m_storage; - DialogView* m_dialogView; + std::shared_ptr m_dialogView; TimePoint m_start; std::shared_ptr m_taskRunner; diff --git a/src/lib/settings/ApplicationSettings.cpp b/src/lib/settings/ApplicationSettings.cpp index 533ef859..400d9d4a 100644 --- a/src/lib/settings/ApplicationSettings.cpp +++ b/src/lib/settings/ApplicationSettings.cpp @@ -247,6 +247,16 @@ void ApplicationSettings::setJavaMaximumMemory(int size) setValue("indexing/java/java_maximum_memory", size); } +std::string ApplicationSettings::getMavenPath() const +{ + return getValue("indexing/java/maven_path", ""); +} + +void ApplicationSettings::setMavenPath(const std::string path) +{ + setValue("indexing/java/maven_path", path); +} + std::vector ApplicationSettings::getHeaderSearchPaths() const { return getPathValues("indexing/cxx/header_search_paths/header_search_path"); diff --git a/src/lib/settings/ApplicationSettings.h b/src/lib/settings/ApplicationSettings.h index 82161691..4e3f4fe3 100644 --- a/src/lib/settings/ApplicationSettings.h +++ b/src/lib/settings/ApplicationSettings.h @@ -76,6 +76,9 @@ public: int getJavaMaximumMemory() const; void setJavaMaximumMemory(int size); + std::string getMavenPath() const; + void setMavenPath(const std::string path); + std::vector getHeaderSearchPaths() const; std::vector getHeaderSearchPathsExpanded() const; bool setHeaderSearchPaths(const std::vector& headerSearchPaths); diff --git a/src/lib/settings/CxxProjectSettings.cpp b/src/lib/settings/CxxProjectSettings.cpp index 6455f0a0..89b40ba9 100644 --- a/src/lib/settings/CxxProjectSettings.cpp +++ b/src/lib/settings/CxxProjectSettings.cpp @@ -23,6 +23,31 @@ CxxProjectSettings::~CxxProjectSettings() { } +ProjectType CxxProjectSettings::getProjectType() const +{ + if (!getVisualStudioSolutionPath().empty()) // I think this is crap. VS solution path is not used anymore.. so vs projects are handled like cdb projects + { + return PROJECT_CXX_VS; + } + else if (!getCompilationDatabasePath().empty()) + { + return PROJECT_CXX_CDB; + } + else + { + switch (getLanguage()) + { + case LANGUAGE_C: + return PROJECT_C_EMPTY; + case LANGUAGE_CPP: + return PROJECT_CPP_EMPTY; + default: + return PROJECT_UNKNOWN; + } + } + return PROJECT_UNKNOWN; +} + bool CxxProjectSettings::equalsExceptNameAndLocation(const ProjectSettings& other) const { if (other.getLanguage() == getLanguage()) diff --git a/src/lib/settings/CxxProjectSettings.h b/src/lib/settings/CxxProjectSettings.h index c7e001d4..4cc99eec 100644 --- a/src/lib/settings/CxxProjectSettings.h +++ b/src/lib/settings/CxxProjectSettings.h @@ -11,6 +11,8 @@ public: CxxProjectSettings(std::string projectName, const FilePath& projectFileLocation); virtual ~CxxProjectSettings(); + virtual ProjectType getProjectType() const; + virtual bool equalsExceptNameAndLocation(const ProjectSettings& other) const; virtual std::vector getLanguageStandards() const; diff --git a/src/lib/settings/JavaProjectSettings.cpp b/src/lib/settings/JavaProjectSettings.cpp index 5bc804db..dad41ee1 100644 --- a/src/lib/settings/JavaProjectSettings.cpp +++ b/src/lib/settings/JavaProjectSettings.cpp @@ -23,6 +23,11 @@ JavaProjectSettings::~JavaProjectSettings() { } +ProjectType JavaProjectSettings::getProjectType() const +{ + return PROJECT_JAVA_EMPTY; +} + bool JavaProjectSettings::equalsExceptNameAndLocation(const ProjectSettings& other) const { if (other.getLanguage() == getLanguage()) @@ -51,9 +56,48 @@ std::vector JavaProjectSettings::getAbsoluteClasspaths() const return makePathsAbsolute(expandPaths(getClasspaths())); } -bool JavaProjectSettings::setClasspaths(const std::vector& paths) +bool JavaProjectSettings::setClasspaths(const std::vector& classpaths) { - return setPathValues("source/class_paths/class_path", paths); + return setPathValues("source/class_paths/class_path", classpaths); +} + +FilePath JavaProjectSettings::getMavenProjectFilePath() const +{ + return FilePath(getValue("source/maven/project_root", "")); +} + +FilePath JavaProjectSettings::getAbsoluteMavenProjectFilePath() const +{ + return makePathAbsolute(expandPath(getMavenProjectFilePath())); +} + +bool JavaProjectSettings::setMavenProjectFilePath(const FilePath& path) +{ + return setValue("source/maven/project_root", path.str()); +} + +FilePath JavaProjectSettings::getMavenDependenciesDirectory() const +{ + return FilePath(getValue("source/maven/dependencies_directory", "")); +} + +FilePath JavaProjectSettings::getAbsoluteMavenDependenciesDirectory() const +{ + return makePathAbsolute(expandPath(getMavenDependenciesDirectory())); +} + +bool JavaProjectSettings::setMavenDependenciesDirectory(const FilePath& path) +{ + return setValue("source/maven/dependencies_directory", path.str()); +} + +bool JavaProjectSettings::getShouldIndexMavenTests() const +{ + return getValue("source/maven/should_index_tests", false); +} +void JavaProjectSettings::setShouldIndexMavenTests(bool value) +{ + setValue("source/maven/should_index_tests", value); } std::vector JavaProjectSettings::getDefaultSourceExtensions() const diff --git a/src/lib/settings/JavaProjectSettings.h b/src/lib/settings/JavaProjectSettings.h index 865941cc..3636f654 100644 --- a/src/lib/settings/JavaProjectSettings.h +++ b/src/lib/settings/JavaProjectSettings.h @@ -12,13 +12,26 @@ public: JavaProjectSettings(std::string projectName, const FilePath& projectFileLocation); virtual ~JavaProjectSettings(); + virtual ProjectType getProjectType() const; + virtual bool equalsExceptNameAndLocation(const ProjectSettings& other) const; virtual std::vector getLanguageStandards() const; std::vector getClasspaths() const; std::vector getAbsoluteClasspaths() const; - bool setClasspaths(const std::vector& headerSearchPaths); + bool setClasspaths(const std::vector& classpaths); + + FilePath getMavenProjectFilePath() const; + FilePath getAbsoluteMavenProjectFilePath() const; + bool setMavenProjectFilePath(const FilePath& path); + + FilePath getMavenDependenciesDirectory() const; + FilePath getAbsoluteMavenDependenciesDirectory() const; + bool setMavenDependenciesDirectory(const FilePath& path); + + bool getShouldIndexMavenTests() const; + void setShouldIndexMavenTests(bool value); private: virtual std::vector getDefaultSourceExtensions() const; diff --git a/src/lib/settings/LanguageType.cpp b/src/lib/settings/LanguageType.cpp index 1298aed8..2995f2e2 100644 --- a/src/lib/settings/LanguageType.cpp +++ b/src/lib/settings/LanguageType.cpp @@ -47,3 +47,25 @@ std::string getSymbolNameDelimiterForLanguage(LanguageType t) } return "@"; } + +LanguageType getLanguageTypeForProjectType(ProjectType t) +{ + switch (t) + { + case PROJECT_C_EMPTY: + return LANGUAGE_C; + case PROJECT_CPP_EMPTY: + return LANGUAGE_CPP; + case PROJECT_CXX_CDB: + return LANGUAGE_CPP; + case PROJECT_CXX_VS: + return LANGUAGE_CPP; + case PROJECT_JAVA_EMPTY: + return LANGUAGE_JAVA; + case PROJECT_JAVA_MAVEN: + return LANGUAGE_JAVA; + default: + break; + } +} + diff --git a/src/lib/settings/LanguageType.h b/src/lib/settings/LanguageType.h index 2644fe44..c3cdd574 100644 --- a/src/lib/settings/LanguageType.h +++ b/src/lib/settings/LanguageType.h @@ -3,6 +3,8 @@ #include +#include "settings/ProjectType.h" + enum LanguageType { LANGUAGE_C, @@ -15,5 +17,6 @@ std::string languageTypeToString(LanguageType t); LanguageType stringToLanguageType(std::string s); std::string getSymbolNameDelimiterForLanguage(LanguageType t); +LanguageType getLanguageTypeForProjectType(ProjectType t); #endif // LANGUAGE_TYPE_H diff --git a/src/lib/settings/ProjectSettings.cpp b/src/lib/settings/ProjectSettings.cpp index 12bc421c..83669f80 100644 --- a/src/lib/settings/ProjectSettings.cpp +++ b/src/lib/settings/ProjectSettings.cpp @@ -32,6 +32,11 @@ ProjectSettings::~ProjectSettings() { } +ProjectType ProjectSettings::getProjectType() const +{ + return PROJECT_UNKNOWN; +} + bool ProjectSettings::equalsExceptNameAndLocation(const ProjectSettings& other) const { return ( diff --git a/src/lib/settings/ProjectSettings.h b/src/lib/settings/ProjectSettings.h index 7834f9d3..1669430d 100644 --- a/src/lib/settings/ProjectSettings.h +++ b/src/lib/settings/ProjectSettings.h @@ -20,6 +20,8 @@ public: ProjectSettings(std::string projectName, const FilePath& projectFileLocation); virtual ~ProjectSettings(); + virtual ProjectType getProjectType() const; + virtual bool equalsExceptNameAndLocation(const ProjectSettings& other) const; virtual std::vector getLanguageStandards() const; @@ -36,7 +38,7 @@ public: void setProjectFileLocation(const FilePath& location); std::string getDescription() const; - + LanguageType getLanguage() const; bool setLanguage(LanguageType language); diff --git a/src/lib/settings/ProjectType.cpp b/src/lib/settings/ProjectType.cpp new file mode 100644 index 00000000..81d9ab39 --- /dev/null +++ b/src/lib/settings/ProjectType.cpp @@ -0,0 +1,53 @@ +#include "settings/ProjectType.h" + +std::string projectTypeToString(ProjectType v) +{ + switch (v) + { + case PROJECT_C_EMPTY: + return "Empty C Project"; + case PROJECT_CPP_EMPTY: + return "Empty C++ Project"; + case PROJECT_CXX_CDB: + return "C/C++ from Compilation Database"; + case PROJECT_CXX_VS: + return "C/C++ from Visual Studio"; + case PROJECT_JAVA_EMPTY: + return "Empty Java Project"; + case PROJECT_JAVA_MAVEN: + return "Java Project from Maven"; + case PROJECT_UNKNOWN: + break; + } + return "unknown"; +} + +ProjectType stringToProjectType(std::string v) +{ + if (v == projectTypeToString(PROJECT_C_EMPTY)) + { + return PROJECT_C_EMPTY; + } + else if (v == projectTypeToString(PROJECT_CPP_EMPTY)) + { + return PROJECT_CPP_EMPTY; + } + else if (v == projectTypeToString(PROJECT_CXX_CDB)) + { + return PROJECT_CXX_CDB; + } + else if (v == projectTypeToString(PROJECT_CXX_VS)) + { + return PROJECT_CXX_VS; + } + else if (v == projectTypeToString(PROJECT_JAVA_EMPTY)) + { + return PROJECT_JAVA_EMPTY; + } + else if (v == projectTypeToString(PROJECT_JAVA_MAVEN)) + { + return PROJECT_JAVA_MAVEN; + } + + return PROJECT_UNKNOWN; +} diff --git a/src/lib/settings/ProjectType.h b/src/lib/settings/ProjectType.h new file mode 100644 index 00000000..cb8845c7 --- /dev/null +++ b/src/lib/settings/ProjectType.h @@ -0,0 +1,20 @@ +#ifndef PROJECT_TYPE_H +#define PROJECT_TYPE_H + +#include + +enum ProjectType +{ + PROJECT_C_EMPTY, + PROJECT_CPP_EMPTY, + PROJECT_CXX_CDB, + PROJECT_CXX_VS, + PROJECT_JAVA_EMPTY, + PROJECT_JAVA_MAVEN, + PROJECT_UNKNOWN +}; + +std::string projectTypeToString(ProjectType v); +ProjectType stringToProjectType(std::string v); + +#endif // PROJECT_TYPE_H diff --git a/src/lib/utility/file/FileManager.cpp b/src/lib/utility/file/FileManager.cpp index 4f8f1c30..c9920dac 100644 --- a/src/lib/utility/file/FileManager.cpp +++ b/src/lib/utility/file/FileManager.cpp @@ -106,7 +106,21 @@ std::set FileManager::getSourceFilePaths() const std::set sourceFilePaths; for (const FileInfo& fileInfo: FileSystem::getFileInfosFromPaths(m_sourcePaths, m_sourceExtensions)) { - sourceFilePaths.emplace(fileInfo.path); + const FilePath& path = fileInfo.path; + bool excluded = false; + for (FilePath p: m_excludePaths) + { + if (p == path || p.contains(path)) + { + excluded = true; + break; + } + } + + if (!excluded) + { + sourceFilePaths.emplace(path); + } } return sourceFilePaths; } @@ -115,6 +129,14 @@ bool FileManager::hasSourceFilePath(const FilePath& filePath) const { if (m_sourceFilePaths.find(filePath) != m_sourceFilePaths.end()) { + for (FilePath p: m_excludePaths) + { + if (p == filePath || p.contains(filePath)) + { + return false; + } + } + return true; } diff --git a/src/lib/utility/file/FileManager.h b/src/lib/utility/file/FileManager.h index 035d63b0..95a6481f 100644 --- a/src/lib/utility/file/FileManager.h +++ b/src/lib/utility/file/FileManager.h @@ -37,7 +37,7 @@ public: std::set getSourceFilePaths() const; // checks if file is in non-excluded source directory - virtual bool hasSourceFilePath(const FilePath& filePath) const; + bool hasSourceFilePath(const FilePath& filePath) const; private: std::vector makeCanonical(const std::vector& filePaths); diff --git a/src/lib/utility/solution/SolutionParserUtility.cpp b/src/lib/utility/solution/SolutionParserUtility.cpp index 9fa5ecf5..f038b0d0 100644 --- a/src/lib/utility/solution/SolutionParserUtility.cpp +++ b/src/lib/utility/solution/SolutionParserUtility.cpp @@ -68,59 +68,6 @@ TiXmlElement* SolutionParserUtility::getFirstTagByName(TiXmlElement* root, const return NULL; } -std::vector SolutionParserUtility::getAllTagsByName(TiXmlElement* root, const std::string& tag) -{ - std::vector nodes; - - TiXmlElement* element = root; - - while (element) - { - std::string value = element->Value(); - - if (value == tag) - { - nodes.push_back(element); - } - - if (element->FirstChildElement() != NULL) - { - element = element->FirstChildElement(); - } - else if (element->NextSiblingElement() != NULL) - { - element = element->NextSiblingElement(); - } - else - { - if (element == NULL) - { - } - - while (element->Parent()->ToElement() != NULL && element->Parent()->NextSiblingElement() == NULL) - { - TiXmlElement* newElement = element->Parent()->ToElement(); - - if (newElement == NULL) - { - } - - element = newElement; - } - if (element->Parent() != NULL && element->Parent()->NextSiblingElement() != NULL) - { - element = element->Parent()->NextSiblingElement(); - } - else - { - break; - } - } - } - - return nodes; -} - TiXmlElement* SolutionParserUtility::getFirstTagByNameWithAttribute(TiXmlElement* root, const std::string& tag, const std::string& attribute) { TiXmlElement* element = root; @@ -284,7 +231,7 @@ std::string SolutionParserUtility::findAndResolveEnvironmentVariable(const std:: if (macro != "") { LOG_WARNING_STREAM(<< "Encountered IDE macro \"" << macro << "\""); - + if (m_ideMacroValues.find(macro) == m_ideMacroValues.end()) { LOG_WARNING_STREAM(<< "Could not resolve IDE macro \"" << macro << "\""); @@ -358,7 +305,7 @@ std::string SolutionParserUtility::makePathCanonical(const std::string& path) { std::string what = e.what(); LOG_WARNING_STREAM(<< e.what()); - + std::stringstream errorMessage; errorMessage << "Could not make path \"" << path << "\" canonical. Check if it really exists."; MessageStatus(errorMessage.str(), true).dispatch(); diff --git a/src/lib/utility/solution/SolutionParserUtility.h b/src/lib/utility/solution/SolutionParserUtility.h index 33598c22..4d7f31d3 100644 --- a/src/lib/utility/solution/SolutionParserUtility.h +++ b/src/lib/utility/solution/SolutionParserUtility.h @@ -11,7 +11,6 @@ class SolutionParserUtility { public: static TiXmlElement* getFirstTagByName(TiXmlElement* root, const std::string& tag); - static std::vector getAllTagsByName(TiXmlElement* root, const std::string& tag); static TiXmlElement* getFirstTagByNameWithAttribute(TiXmlElement* root, const std::string& tag, const std::string& attribute); static std::vector getAllTagsByNameWithAttribute(TiXmlElement* root, const std::string& tag, const std::string& attribute); @@ -24,7 +23,7 @@ public: static std::string makePathCanonical(const std::string& path); static std::string checkIsIdeMacro(const std::string& text); // returns matching macro or empty string if no match was found - + static std::vector m_ideMacros; static std::map m_ideMacroValues; // to replace macros with known values }; diff --git a/src/lib/utility/utility.h b/src/lib/utility/utility.h index 3fac358c..1948d4de 100644 --- a/src/lib/utility/utility.h +++ b/src/lib/utility/utility.h @@ -2,6 +2,7 @@ #define UTILITY_H #include +#include #include #include #include @@ -47,6 +48,15 @@ namespace utility template std::vector toVector(const std::set& d); + template + void fillVectorWithElements(std::vector& v, const T& arg); + + template + void fillVectorWithElements(std::vector& v, const T& arg, const Args&... args); + + template + std::vector createVectorFromElements(const Args&... args); + template std::vector toStrings(const std::vector& d); template<> @@ -156,6 +166,27 @@ std::vector utility::toVector(const std::set& d) return v; } +template +void utility::fillVectorWithElements(std::vector& v, const T& arg) +{ + v.push_back(arg); +} + +template +void utility::fillVectorWithElements(std::vector& v, const T& arg, const Args&... args) +{ + fillVectorWithElements(v, arg); + fillVectorWithElements(v, args...); +} + +template +std::vector utility::createVectorFromElements(const Args&... args) +{ + std::vector v; + fillVectorWithElements(v, args...); + return v; +} + template std::vector utility::toStrings(const std::vector& d) { diff --git a/src/lib/utility/utilityString.cpp b/src/lib/utility/utilityString.cpp index 8b26d02e..eaa06eaa 100644 --- a/src/lib/utility/utilityString.cpp +++ b/src/lib/utility/utilityString.cpp @@ -211,6 +211,47 @@ namespace utility return str; } + std::string insertLineBreaksAtBlankSpaces(const std::string& s, int maxLineLength) + { + const std::vector atoms = splitToVector(s, " "); + + std::string ret = ""; + std::string currentLine = ""; + for (const std::string& atom: atoms) + { + if (currentLine.size() + 1 + atom.size() <= maxLineLength) + { + currentLine += " " + atom; + } + else + { + if (!ret.empty()) + { + ret += "\n"; + } + + if (currentLine.empty()) + { + ret += atom; + } + else + { + ret += currentLine; + currentLine = atom; + } + } + } + if (!currentLine.empty()) + { + if (!ret.empty()) + { + ret += "\n"; + } + ret += currentLine; + } + return ret; + } + std::string trim(const std::string &str) { auto wsfront = std::find_if_not(str.begin(), str.end(), [](int c){ return std::isspace(c); }); diff --git a/src/lib/utility/utilityString.h b/src/lib/utility/utilityString.h index 9ca841e6..a4635b13 100644 --- a/src/lib/utility/utilityString.h +++ b/src/lib/utility/utilityString.h @@ -45,6 +45,8 @@ namespace utility std::string replace(std::string str, const std::string& from, const std::string& to); + std::string insertLineBreaksAtBlankSpaces(const std::string& s, int maxLineLength); + std::string trim(const std::string &str); template diff --git a/src/lib/utility/utilityXml.cpp b/src/lib/utility/utilityXml.cpp new file mode 100644 index 00000000..711b065f --- /dev/null +++ b/src/lib/utility/utilityXml.cpp @@ -0,0 +1,153 @@ +#include "utility/utilityXml.h"; + +#include "tinyxml/tinyxml.h"; + +namespace utility +{ + + std::vector getValuesOfAllXmlElementsOnPath(std::shared_ptr textAccess, const std::vector& tags) + { + std::vector values; + + std::string text = textAccess->getText(); + + TiXmlDocument doc; + const char* pTest = doc.Parse(text.c_str(), 0, TIXML_ENCODING_LEGACY); + if (pTest != NULL) + { + TiXmlHandle docHandle(&doc); + std::vector> traversalStates; + traversalStates.push_back(std::make_pair(docHandle.ToNode()->FirstChildElement(), 0)); + + while (!traversalStates.empty()) + { + TiXmlElement* currentElement = traversalStates.back().first; + const size_t currentIndex = traversalStates.back().second; + traversalStates.pop_back(); + + if(currentElement != nullptr && + currentElement->Value() == tags[currentIndex] + ) + { + if (currentIndex < tags.size() - 1) + { + TiXmlElement* nextElement = currentElement->FirstChildElement(); + + while (nextElement) + { + traversalStates.push_back(std::make_pair(nextElement, size_t(currentIndex + 1))); + nextElement = nextElement->NextSiblingElement(); + } + } + else + { + if (currentElement->FirstChild() && + currentElement->FirstChild() == currentElement->LastChild() && + currentElement->FirstChild()->ToText() + ) + { + values.push_back(currentElement->FirstChild()->ToText()->Value()); + } + } + } + } + } + else + { + // LOG_ERROR("Unable to load file."); + } + return values; + } + + + + std::vector getValuesOfAllXmlTagsByName(std::shared_ptr textAccess, const std::string& tag) + { + std::vector values; + + std::string text = textAccess->getText(); + + TiXmlDocument doc; + const char* pTest = doc.Parse(text.c_str(), 0, TIXML_ENCODING_UTF8); + if (pTest != NULL) + { + TiXmlHandle docHandle(&doc); + TiXmlElement *rootElement = docHandle.ToNode()->FirstChildElement(); + if(rootElement != nullptr) + { + for (TiXmlElement* element: getAllXmlTagsByName(rootElement, tag)) + { + if (element->FirstChild() && + element->FirstChild() == element->LastChild() && + element->FirstChild()->ToText() + ) + { + values.push_back(element->FirstChild()->ToText()->Value()); + } + } + } + else + { + // LOG_ERROR("Unable to load file."); + } + } + else + { + // LOG_ERROR("Unable to load file."); + } + return values; + } + + std::vector getAllXmlTagsByName(TiXmlElement* root, const std::string& tag) + { + std::vector nodes; + + TiXmlElement* element = root; + + while (element) + { + std::string value = element->Value(); + + if (value == tag) + { + nodes.push_back(element); + } + + if (element->FirstChildElement() != NULL) + { + element = element->FirstChildElement(); + } + else if (element->NextSiblingElement() != NULL) + { + element = element->NextSiblingElement(); + } + else + { + if (element == NULL) + { + } + + while (element->Parent()->ToElement() != NULL && element->Parent()->NextSiblingElement() == NULL) + { + TiXmlElement* newElement = element->Parent()->ToElement(); + + if (newElement == NULL) + { + } + + element = newElement; + } + if (element->Parent() != NULL && element->Parent()->NextSiblingElement() != NULL) + { + element = element->Parent()->NextSiblingElement(); + } + else + { + break; + } + } + } + + return nodes; + } +} diff --git a/src/lib/utility/utilityXml.h b/src/lib/utility/utilityXml.h new file mode 100644 index 00000000..456ddcb4 --- /dev/null +++ b/src/lib/utility/utilityXml.h @@ -0,0 +1,19 @@ +#ifndef UTILITY_XML_H +#define UTILITY_XML_H + +#include +#include +#include + +#include "utility/text/TextAccess.h" + +class TiXmlElement; + +namespace utility +{ + std::vector getValuesOfAllXmlElementsOnPath(std::shared_ptr textAccess, const std::vector& tags); + std::vector getValuesOfAllXmlTagsByName(std::shared_ptr textAccess, const std::string& tag); + std::vector getAllXmlTagsByName(TiXmlElement* root, const std::string& tag); +} + +#endif // UTILITY_XML_H diff --git a/src/lib_cxx/CxxProject.cpp b/src/lib_cxx/CxxProject.cpp index f30c2e0e..f770a96e 100644 --- a/src/lib_cxx/CxxProject.cpp +++ b/src/lib_cxx/CxxProject.cpp @@ -16,7 +16,7 @@ #include "Application.h" CxxProject::CxxProject( - std::shared_ptr projectSettings, StorageAccessProxy* storageAccessProxy, DialogView* dialogView + std::shared_ptr projectSettings, StorageAccessProxy* storageAccessProxy, std::shared_ptr dialogView ) : Project(storageAccessProxy, dialogView) , m_projectSettings(projectSettings) diff --git a/src/lib_cxx/CxxProject.h b/src/lib_cxx/CxxProject.h index 70a390b7..5741596c 100644 --- a/src/lib_cxx/CxxProject.h +++ b/src/lib_cxx/CxxProject.h @@ -12,7 +12,7 @@ public: CxxProject( std::shared_ptr projectSettings, StorageAccessProxy* storageAccessProxy, - DialogView* dialogView + std::shared_ptr dialogView ); virtual ~CxxProject(); diff --git a/src/lib_cxx/ProjectFactoryModuleC.cpp b/src/lib_cxx/ProjectFactoryModuleC.cpp index 056ba94d..0a3f18d3 100644 --- a/src/lib_cxx/ProjectFactoryModuleC.cpp +++ b/src/lib_cxx/ProjectFactoryModuleC.cpp @@ -13,7 +13,7 @@ LanguageType ProjectFactoryModuleC::getLanguage() const } std::shared_ptr ProjectFactoryModuleC::createProject( - const FilePath& projectSettingsFile, StorageAccessProxy* storageAccessProxy, DialogView* dialogView + const FilePath& projectSettingsFile, StorageAccessProxy* storageAccessProxy, std::shared_ptr dialogView ) { return std::shared_ptr(new CxxProject( diff --git a/src/lib_cxx/ProjectFactoryModuleC.h b/src/lib_cxx/ProjectFactoryModuleC.h index e62c0e70..a6e36ff2 100644 --- a/src/lib_cxx/ProjectFactoryModuleC.h +++ b/src/lib_cxx/ProjectFactoryModuleC.h @@ -10,7 +10,7 @@ public: virtual LanguageType getLanguage() const; virtual std::shared_ptr createProject( - const FilePath& projectSettingsFile, StorageAccessProxy* storageAccessProxy, DialogView* dialogView + const FilePath& projectSettingsFile, StorageAccessProxy* storageAccessProxy, std::shared_ptr dialogView ); }; diff --git a/src/lib_cxx/ProjectFactoryModuleCpp.cpp b/src/lib_cxx/ProjectFactoryModuleCpp.cpp index 9e742d74..2cb12594 100644 --- a/src/lib_cxx/ProjectFactoryModuleCpp.cpp +++ b/src/lib_cxx/ProjectFactoryModuleCpp.cpp @@ -13,7 +13,7 @@ LanguageType ProjectFactoryModuleCpp::getLanguage() const } std::shared_ptr ProjectFactoryModuleCpp::createProject( - const FilePath& projectSettingsFile, StorageAccessProxy* storageAccessProxy, DialogView* dialogView + const FilePath& projectSettingsFile, StorageAccessProxy* storageAccessProxy, std::shared_ptr dialogView ) { return std::shared_ptr(new CxxProject( diff --git a/src/lib_cxx/ProjectFactoryModuleCpp.h b/src/lib_cxx/ProjectFactoryModuleCpp.h index e32f8451..6366c41c 100644 --- a/src/lib_cxx/ProjectFactoryModuleCpp.h +++ b/src/lib_cxx/ProjectFactoryModuleCpp.h @@ -10,7 +10,7 @@ public: virtual LanguageType getLanguage() const; virtual std::shared_ptr createProject( - const FilePath& projectSettingsFile, StorageAccessProxy* storageAccessProxy, DialogView* dialogView + const FilePath& projectSettingsFile, StorageAccessProxy* storageAccessProxy, std::shared_ptr dialogView ); }; diff --git a/src/lib_gui/CMakeLists.txt b/src/lib_gui/CMakeLists.txt index 9bb665eb..e6476598 100644 --- a/src/lib_gui/CMakeLists.txt +++ b/src/lib_gui/CMakeLists.txt @@ -158,6 +158,8 @@ add_files( qt/window/project_wizzard/QtProjectWizzardContentExtensions.h qt/window/project_wizzard/QtProjectWizzardContentFlags.cpp qt/window/project_wizzard/QtProjectWizzardContentFlags.h + qt/window/project_wizzard/QtProjectWizzardContentPath.cpp + qt/window/project_wizzard/QtProjectWizzardContentPath.h qt/window/project_wizzard/QtProjectWizzardContentPaths.cpp qt/window/project_wizzard/QtProjectWizzardContentPaths.h qt/window/project_wizzard/QtProjectWizzardContentPreferences.cpp @@ -223,6 +225,11 @@ add_files( utility/path_detector/java_runtime/JavaPathDetectorWindows.cpp utility/path_detector/java_runtime/JavaPathDetectorWindows.h + utility/path_detector/maven_executable/MavenPathDetectorUnix.cpp + utility/path_detector/maven_executable/MavenPathDetectorUnix.h + utility/path_detector/maven_executable/MavenPathDetectorWindows.cpp + utility/path_detector/maven_executable/MavenPathDetectorWindows.h + utility/path_detector/CombinedPathDetector.cpp utility/path_detector/CombinedPathDetector.h utility/path_detector/PathDetector.cpp diff --git a/src/lib_gui/qt/window/project_wizzard/QtProjectWizzard.cpp b/src/lib_gui/qt/window/project_wizzard/QtProjectWizzard.cpp index 50012484..1360dbe4 100644 --- a/src/lib_gui/qt/window/project_wizzard/QtProjectWizzard.cpp +++ b/src/lib_gui/qt/window/project_wizzard/QtProjectWizzard.cpp @@ -10,6 +10,7 @@ #include "qt/window/project_wizzard/QtProjectWizzardContentData.h" #include "qt/window/project_wizzard/QtProjectWizzardContentExtensions.h" #include "qt/window/project_wizzard/QtProjectWizzardContentFlags.h" +#include "qt/window/project_wizzard/QtProjectWizzardContentPath.h" #include "qt/window/project_wizzard/QtProjectWizzardContentPaths.h" #include "qt/window/project_wizzard/QtProjectWizzardContentPreferences.h" #include "qt/window/project_wizzard/QtProjectWizzardContentSimple.h" @@ -48,8 +49,6 @@ QtProjectWizzard::QtProjectWizzard(QWidget* parent) m_parserManager = std::make_shared(); - // wip - // m_parserManager->pushSolutionParser(std::make_shared()); } void QtProjectWizzard::showWindow() @@ -77,19 +76,19 @@ void QtProjectWizzard::newProject() QtProjectWizzardWindow* window = createWindowWithContent(); connect(dynamic_cast(window->content()), - SIGNAL(selected(LanguageType, QtProjectWizzardContentSelect::ProjectType)), - this, SLOT(selectedProjectType(LanguageType, QtProjectWizzardContentSelect::ProjectType))); + SIGNAL(selected(ProjectType)), + this, SLOT(selectedProjectType(ProjectType))); window->setNextEnabled(false); window->setPreviousEnabled(false); window->updateSubTitle("Type Selection"); } -void QtProjectWizzard::newProjectFromSolution(const std::string& ideId, const std::string& visualStudioSolutionPath) +void QtProjectWizzard::newProjectFromSolution(const std::string& ideId, const std::string& solutionPath) { if (m_parserManager->canParseSolution(ideId)) { - std::shared_ptr settings = m_parserManager->getProjectSettings(ideId, visualStudioSolutionPath); + std::shared_ptr settings = m_parserManager->getProjectSettings(ideId, solutionPath); // this looks rather hacky.. calling the edit project and then setting the title. editProject(settings); @@ -136,7 +135,7 @@ void QtProjectWizzard::newProjectFromCDB(const std::string& filePath, const std: emptyProjectCDBVS(); } -void QtProjectWizzard::refreshProjectFromSolution(const std::string& ideId, const std::string& visualStudioSolutionPath) +void QtProjectWizzard::refreshProjectFromSolution(const std::string& ideId, const std::string& solutionPath) { if (m_parserManager->canParseSolution(ideId)) { @@ -146,7 +145,7 @@ void QtProjectWizzard::refreshProjectFromSolution(const std::string& ideId, cons window->content()->save(); } - std::shared_ptr settings = m_parserManager->getProjectSettings(ideId, visualStudioSolutionPath); + std::shared_ptr settings = m_parserManager->getProjectSettings(ideId, solutionPath); std::shared_ptr otherCxxSettings = std::dynamic_pointer_cast(settings); std::shared_ptr ownCxxSettings = std::dynamic_pointer_cast(m_settings); @@ -154,7 +153,7 @@ void QtProjectWizzard::refreshProjectFromSolution(const std::string& ideId, cons { ownCxxSettings->setSourcePaths(otherCxxSettings->getSourcePaths()); ownCxxSettings->setHeaderSearchPaths(otherCxxSettings->getHeaderSearchPaths()); - ownCxxSettings->setVisualStudioSolutionPath(FilePath(visualStudioSolutionPath)); + ownCxxSettings->setVisualStudioSolutionPath(FilePath(solutionPath)); } if (window) { @@ -342,67 +341,44 @@ void QtProjectWizzard::windowStackChanged() } } -void QtProjectWizzard::selectedProjectType(LanguageType languageType, QtProjectWizzardContentSelect::ProjectType type) +void QtProjectWizzard::selectedProjectType(ProjectType projectType) { - switch (type) + LanguageType languageType = getLanguageTypeForProjectType(projectType); + switch (projectType) { - case QtProjectWizzardContentSelect::PROJECT_EMPTY: - if (languageType == LANGUAGE_JAVA) + case PROJECT_C_EMPTY: + case PROJECT_CPP_EMPTY: + m_settings = std::make_shared(); + if (applicationSettingsContainVisualStudioHeaderSearchPaths()) { - m_settings = std::make_shared(); - } - else - { - m_settings = std::make_shared(); - - if (applicationSettingsContainVisualStudioHeaderSearchPaths()) - { - std::vector flags; - flags.push_back("-fms-extensions"); - flags.push_back("-fms-compatibility"); - flags.push_back("-fms-compatibility-version=19"); - std::dynamic_pointer_cast(m_settings)->setCompilerFlags(flags); - } + std::vector flags; + flags.push_back("-fms-extensions"); + flags.push_back("-fms-compatibility"); + flags.push_back("-fms-compatibility-version=19"); + std::dynamic_pointer_cast(m_settings)->setCompilerFlags(flags); } m_settings->setLanguage(languageType); emptyProject(); break; - - case QtProjectWizzardContentSelect::PROJECT_MANAGED: - /*{ - std::string fileEndings = "("; - for (unsigned int i = 0; i < m_parserManager->getParserCount(); i++) - { - fileEndings += " *" + m_parserManager->getParserFileEnding(i); - } - fileEndings += ")"; - - QString fileName = QFileDialog::getOpenFileName( - this, tr("Open Solution"), "", fileEndings.c_str() - ); - - if (!fileName.isNull()) - { - for (unsigned int i = 0; i < m_parserManager->getParserCount(); i++) - { - if (fileName.contains(m_parserManager->getParserFileEnding(i).c_str())) - { - newProjectFromSolution(m_parserManager->getParserIdeId(i), fileName.toStdString()); - } - } - } - break; - }*/ - + case PROJECT_CXX_CDB: + m_settings = std::make_shared(); + m_settings->setLanguage(languageType); + emptyProjectCDB(); + break; + case PROJECT_CXX_VS: m_settings = std::make_shared(); m_settings->setLanguage(languageType); emptyProjectCDBVS(); break; - - case QtProjectWizzardContentSelect::PROJECT_CDB: - m_settings = std::make_shared(); + case PROJECT_JAVA_EMPTY: + m_settings = std::make_shared(); m_settings->setLanguage(languageType); - emptyProjectCDB(); + emptyProject(); + break; + case PROJECT_JAVA_MAVEN: + m_settings = std::make_shared(); + m_settings->setLanguage(languageType); + emptyProjectJavaMaven(); break; } } @@ -501,6 +477,14 @@ void QtProjectWizzard::emptyProjectCDB() window->updateSubTitle("Project Data"); } +void QtProjectWizzard::emptyProjectJavaMaven() +{ + QtProjectWizzardWindow* window = createWindowWithContent(); + + connect(window, SIGNAL(next()), this, SLOT(sourcePathsJavaMaven())); + window->updateSubTitle("Project Data"); +} + void QtProjectWizzard::headerPathsCDB() { QtProjectWizzardWindow* window = createWindowWithSummary( @@ -535,6 +519,27 @@ void QtProjectWizzard::sourcePathsJava() window->updateSubTitle("Indexed Paths"); } +void QtProjectWizzard::sourcePathsJavaMaven() +{ + std::dynamic_pointer_cast(m_settings)->setMavenDependenciesDirectory( + "./coati_dependencies/" + utility::replace(m_settings->getProjectName(), " ", "_") + "/maven" + ); + + QtProjectWizzardWindow* window = createWindowWithSummary( + [this](QtProjectWizzardWindow* window, QtProjectWizzardContentSummary* summary) + { + summary->addContent(new QtProjectWizzardContentPathSourceMaven(m_settings, window)); + summary->addSpace(); + summary->addContent(new QtProjectWizzardContentPathDependenciesMaven(m_settings, window)); + + window->setup(); + } + ); + + connect(window, SIGNAL(next()), this, SLOT(advancedSettingsJava())); + window->updateSubTitle("Indexed Paths"); +} + void QtProjectWizzard::advancedSettingsCxx() { QtProjectWizzardWindow* window = createWindowWithSummary( @@ -577,23 +582,13 @@ void QtProjectWizzard::showSummary() summary->setIsForm(true); QtProjectWizzardContentBuildFile* buildFile = new QtProjectWizzardContentBuildFile(m_settings, window); - bool isCDB = buildFile->getType() == QtProjectWizzardContentSelect::PROJECT_CDB; + const bool isCDB = buildFile->getType() == PROJECT_CXX_CDB || buildFile->getType() == PROJECT_CXX_VS; if (!isCDB) { summary->addContent(new QtProjectWizzardContentData(m_settings, window, m_editing)); summary->addSpace(); - if (buildFile->getType() == QtProjectWizzardContentSelect::PROJECT_MANAGED) - { - summary->addContent(buildFile); - summary->addSpace(); - - connect(dynamic_cast(buildFile), - SIGNAL(refreshVisualStudioSolution(const std::string&, const std::string&)), - this, SLOT(refreshProjectFromSolution(const std::string&, const std::string&))); - } - summary->addContent(new QtProjectWizzardContentPathsSource(m_settings, window)); summary->addContent(new QtProjectWizzardContentExtensions(m_settings, window)); summary->addSpace(); @@ -656,15 +651,31 @@ void QtProjectWizzard::showSummaryJava() { summary->setIsForm(true); + bool isMaven = false; + std::shared_ptr javaSettings = std::dynamic_pointer_cast(m_settings); + if (javaSettings) + { + isMaven = javaSettings->getAbsoluteMavenProjectFilePath().exists(); + } + + summary->addContent(new QtProjectWizzardContentData(m_settings, window, m_editing)); summary->addSpace(); - summary->addContent(new QtProjectWizzardContentPathsSource(m_settings, window)); - summary->addSpace(); + if (isMaven) + { + summary->addContent(new QtProjectWizzardContentPathSourceMaven(m_settings, window)); + summary->addSpace(); + summary->addContent(new QtProjectWizzardContentPathDependenciesMaven(m_settings, window)); + } + else + { + summary->addContent(new QtProjectWizzardContentPathsSource(m_settings, window)); + summary->addSpace(); + summary->addContent(new QtProjectWizzardContentPathsClassJava(m_settings, window)); + } - summary->addContent(new QtProjectWizzardContentPathsClassJava(m_settings, window)); summary->addSpace(); - summary->addContent(new QtProjectWizzardContentExtensions(m_settings, window)); summary->addSpace(); summary->addContent(new QtProjectWizzardContentPathsExclude(m_settings, window)); diff --git a/src/lib_gui/qt/window/project_wizzard/QtProjectWizzard.h b/src/lib_gui/qt/window/project_wizzard/QtProjectWizzard.h index fd01e921..1584722a 100644 --- a/src/lib_gui/qt/window/project_wizzard/QtProjectWizzard.h +++ b/src/lib_gui/qt/window/project_wizzard/QtProjectWizzard.h @@ -33,9 +33,9 @@ public: public slots: void newProject(); - void newProjectFromSolution(const std::string& ideId, const std::string& visualStudioSolutionPath); + void newProjectFromSolution(const std::string& ideId, const std::string& solutionPath); void newProjectFromCDB(const std::string& filePath, const std::vector& headerPaths); - void refreshProjectFromSolution(const std::string& ideId, const std::string& visualStudioSolutionPath); + void refreshProjectFromSolution(const std::string& ideId, const std::string& solutionPath); void editProject(const FilePath& settingsPath); void editProject(std::shared_ptr settings); @@ -65,7 +65,7 @@ private slots: void windowStackChanged(); - void selectedProjectType(LanguageType languageType, QtProjectWizzardContentSelect::ProjectType type); + void selectedProjectType(ProjectType type); void emptyProject(); @@ -77,9 +77,12 @@ private slots: void emptyProjectCDBVS(); void emptyProjectCDB(); + void emptyProjectJavaMaven(); + void headerPathsCDB(); void sourcePathsJava(); + void sourcePathsJavaMaven(); void advancedSettingsCxx(); void advancedSettingsJava(); diff --git a/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContent.cpp b/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContent.cpp index 401a6415..2e3a9603 100644 --- a/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContent.cpp +++ b/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContent.cpp @@ -134,7 +134,10 @@ QPushButton* QtProjectWizzardContent::addFilesButton(QString name, QGridLayout* { QPushButton* button = new QPushButton(name); button->setObjectName("windowButton"); - layout->addWidget(button, row, QtProjectWizzardWindow::BACK_COL, Qt::AlignRight | Qt::AlignTop); + if (layout) + { + layout->addWidget(button, row, QtProjectWizzardWindow::BACK_COL, Qt::AlignRight | Qt::AlignTop); + } connect(button, SIGNAL(clicked()), this, SLOT(filesButtonClicked())); return button; @@ -142,7 +145,7 @@ QPushButton* QtProjectWizzardContent::addFilesButton(QString name, QGridLayout* void QtProjectWizzardContent::filesButtonClicked() { - save(); + m_window->saveContent(); if (!m_filesDialog) { diff --git a/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentBuildFile.cpp b/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentBuildFile.cpp index 5cafbed3..0764f769 100644 --- a/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentBuildFile.cpp +++ b/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentBuildFile.cpp @@ -13,23 +13,12 @@ QtProjectWizzardContentBuildFile::QtProjectWizzardContentBuildFile( std::shared_ptr settings, QtProjectWizzardWindow* window ) : QtProjectWizzardContent(settings, window) - , m_type(QtProjectWizzardContentSelect::PROJECT_EMPTY) + , m_type(PROJECT_UNKNOWN) { - std::shared_ptr cxxSettings = std::dynamic_pointer_cast(m_settings); - if (cxxSettings) - { - if (!cxxSettings->getVisualStudioSolutionPath().empty()) - { - m_type = QtProjectWizzardContentSelect::PROJECT_MANAGED; - } - else if (!cxxSettings->getCompilationDatabasePath().empty()) - { - m_type = QtProjectWizzardContentSelect::PROJECT_CDB; - } - } + m_type = m_settings->getProjectType(); } -QtProjectWizzardContentSelect::ProjectType QtProjectWizzardContentBuildFile::getType() const +ProjectType QtProjectWizzardContentBuildFile::getType() const { return m_type; } @@ -41,18 +30,16 @@ void QtProjectWizzardContentBuildFile::populate(QGridLayout* layout, int& row) switch (m_type) { - case QtProjectWizzardContentSelect::PROJECT_EMPTY: - name = "Build Text"; - filter = "Text (*.txt)"; - return; - case QtProjectWizzardContentSelect::PROJECT_MANAGED: - name = "Visual Studio Solution"; - filter = "Visual Studio Solution (*.sln)"; - break; - case QtProjectWizzardContentSelect::PROJECT_CDB: - name = "Compilation Database"; - filter = "JSON Compilation Database (*.json)"; - break; + case PROJECT_C_EMPTY: + case PROJECT_CPP_EMPTY: + name = "Build Text"; + filter = "Text (*.txt)"; + return; + case PROJECT_CXX_VS: + case PROJECT_CXX_CDB: + name = "Compilation Database"; + filter = "JSON Compilation Database (*.json)"; + break; } QLabel* label = createFormLabel(name); @@ -62,19 +49,6 @@ void QtProjectWizzardContentBuildFile::populate(QGridLayout* layout, int& row) m_picker->setFileFilter(filter); m_picker->setRelativeRootDirectory(m_settings->getProjectFileLocation()); - QPushButton* button = new QtIconButton( - (ResourcePaths::getGuiPath() + "window/refresh.png").c_str(), - (ResourcePaths::getGuiPath() + "window/refresh_hover.png").c_str()); - button->setToolTip("refresh paths"); - connect(button, SIGNAL(clicked()), this, SLOT(refreshClicked())); - - if (m_type == QtProjectWizzardContentSelect::PROJECT_CDB) - { - button->hide(); - } - - m_picker->layout()->addWidget(button); - layout->addWidget(m_picker, row, QtProjectWizzardWindow::BACK_COL); row++; @@ -87,14 +61,13 @@ void QtProjectWizzardContentBuildFile::load() { switch (m_type) { - case QtProjectWizzardContentSelect::PROJECT_EMPTY: - return; - case QtProjectWizzardContentSelect::PROJECT_MANAGED: - m_picker->setText(QString::fromStdString(cxxSettings->getVisualStudioSolutionPath().str())); - break; - case QtProjectWizzardContentSelect::PROJECT_CDB: - m_picker->setText(QString::fromStdString(cxxSettings->getCompilationDatabasePath().str())); - break; + case PROJECT_C_EMPTY: + case PROJECT_CPP_EMPTY: + return; + case PROJECT_CXX_VS: + case PROJECT_CXX_CDB: + m_picker->setText(QString::fromStdString(cxxSettings->getCompilationDatabasePath().str())); + break; } } } @@ -106,10 +79,11 @@ void QtProjectWizzardContentBuildFile::save() { switch (m_type) { - case QtProjectWizzardContentSelect::PROJECT_EMPTY: - case QtProjectWizzardContentSelect::PROJECT_MANAGED: + case PROJECT_C_EMPTY: + case PROJECT_CPP_EMPTY: break; - case QtProjectWizzardContentSelect::PROJECT_CDB: + case PROJECT_CXX_VS: + case PROJECT_CXX_CDB: { FilePath path = m_picker->getText().toStdString(); FilePath absPath = m_settings->makePathAbsolute(m_settings->expandPath(path)); @@ -128,10 +102,11 @@ bool QtProjectWizzardContentBuildFile::check() { switch (m_type) { - case QtProjectWizzardContentSelect::PROJECT_EMPTY: - case QtProjectWizzardContentSelect::PROJECT_MANAGED: - break; - case QtProjectWizzardContentSelect::PROJECT_CDB: + case PROJECT_C_EMPTY: + case PROJECT_CPP_EMPTY: + break; + case PROJECT_CXX_VS: + case PROJECT_CXX_CDB: { FilePath path = m_picker->getText().toStdString(); FilePath absPath = m_settings->makePathAbsolute(m_settings->expandPath(path)); @@ -147,40 +122,3 @@ bool QtProjectWizzardContentBuildFile::check() return true; } - -void QtProjectWizzardContentBuildFile::refreshClicked() -{ - FilePath path = m_picker->getText().toStdString(); - FilePath absPath = m_settings->makePathAbsolute(m_settings->expandPath(path)); - if (!absPath.exists()) - { - QMessageBox msgBox; - msgBox.setText("Please enter a valid file path."); - msgBox.exec(); - return; - } - - QMessageBox::StandardButton reply = - QMessageBox::question( - this, - "Refresh Paths", - "Do you really want to refresh from the given file? All changes you have made to the project paths " - "and include paths will be lost.", - QMessageBox::Yes | QMessageBox::No - ); - - if (reply == QMessageBox::No) - { - return; - } - - switch (m_type) - { - case QtProjectWizzardContentSelect::PROJECT_EMPTY: - case QtProjectWizzardContentSelect::PROJECT_CDB: - break; - case QtProjectWizzardContentSelect::PROJECT_MANAGED: - emit refreshVisualStudioSolution("vs", path.str()); - break; - } -} diff --git a/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentBuildFile.h b/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentBuildFile.h index 13591168..b086d6bb 100644 --- a/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentBuildFile.h +++ b/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentBuildFile.h @@ -18,7 +18,7 @@ signals: public: QtProjectWizzardContentBuildFile(std::shared_ptr settings, QtProjectWizzardWindow* window); - QtProjectWizzardContentSelect::ProjectType getType() const; + ProjectType getType() const; // QtProjectWizzardContent implementation virtual void populate(QGridLayout* layout, int& row) override; @@ -27,13 +27,10 @@ public: virtual void save() override; virtual bool check() override; -private slots: - void refreshClicked(); - private: QtLocationPicker* m_picker; - QtProjectWizzardContentSelect::ProjectType m_type; + ProjectType m_type; }; #endif // QT_PROJECT_WIZZARD_CONTENT_BUILD_FILE_H diff --git a/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentPath.cpp b/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentPath.cpp new file mode 100644 index 00000000..12af7bc6 --- /dev/null +++ b/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentPath.cpp @@ -0,0 +1,203 @@ +#include "qt/window/project_wizzard/QtProjectWizzardContentPath.h" + +#include +#include +#include +#include +#include + +#include "component/view/DialogView.h" +#include "qt/element/QtLocationPicker.h" +#include "settings/ApplicationSettings.h" +#include "settings/JavaProjectSettings.h" +#include "utility/file/FileManager.h" +#include "utility/messaging/type/MessageStatus.h" +#include "utility/utilityMaven.h" +#include "utility/ScopedFunctor.h" +#include "Application.h" + +QtProjectWizzardContentPath::QtProjectWizzardContentPath(std::shared_ptr settings, QtProjectWizzardWindow* window) + : QtProjectWizzardContent(settings, window) + , m_makePathRelativeToProjectFileLocation(true) +{ +} + +void QtProjectWizzardContentPath::populate(QGridLayout* layout, int& row) +{ + QLabel* label = createFormLabel(m_titleString); + layout->addWidget(label, row, QtProjectWizzardWindow::FRONT_COL, Qt::AlignTop); + + if (m_helpString.size() > 0) + { + addHelpButton(m_helpString, layout, row); + } + + m_picker = new QtLocationPicker(this); + m_picker->setPickDirectory(true); + + if (m_makePathRelativeToProjectFileLocation) + { + m_picker->setRelativeRootDirectory(m_settings->getProjectFileLocation()); + } + + layout->addWidget(m_picker, row, QtProjectWizzardWindow::BACK_COL); + row++; +} + +bool QtProjectWizzardContentPath::check() +{ + if (m_picker->getText().isEmpty()) + { + QMessageBox msgBox; + msgBox.setText("Please define the location for the \"" + m_titleString + "\"."); + msgBox.exec(); + return false; + } + + return true; +} + +void QtProjectWizzardContentPath::setTitleString(const QString& title) +{ + m_titleString = title; +} + +void QtProjectWizzardContentPath::setHelpString(const QString& help) +{ + m_helpString = help; +} + +QtProjectWizzardContentPathSourceMaven::QtProjectWizzardContentPathSourceMaven( + std::shared_ptr settings, QtProjectWizzardWindow* window +) + : QtProjectWizzardContentPath(settings, window) +{ + setTitleString("Maven Project Root"); + setHelpString( + "Enter the root folder of your Maven project (where the main .pom file resides).
" + "
" + "You can make use of environment variables with ${ENV_VAR}." + ); +} + +void QtProjectWizzardContentPathSourceMaven::populate(QGridLayout* layout, int& row) +{ + QtProjectWizzardContentPath::populate(layout, row); + m_picker->setPickDirectory(false); + m_picker->setFileFilter("POM File (pom.xml)"); + + QPushButton* filesButton = addFilesButton("show source files", nullptr, row); + m_shouldIndexTests = new QCheckBox("Should Index Tests"); + + QHBoxLayout* hlayout = new QHBoxLayout(); + hlayout->setContentsMargins(0, 0, 0, 0); + hlayout->addWidget(m_shouldIndexTests); + hlayout->addStretch(); + hlayout->addWidget(filesButton); + + layout->addLayout(hlayout, row, QtProjectWizzardWindow::BACK_COL); + row++; +} + +void QtProjectWizzardContentPathSourceMaven::load() +{ + std::shared_ptr javaSettings = std::dynamic_pointer_cast(m_settings); + if (javaSettings) + { + m_picker->setText(QString::fromStdString(javaSettings->getMavenProjectFilePath().str())); + m_shouldIndexTests->setChecked(javaSettings->getShouldIndexMavenTests()); + } +} + +void QtProjectWizzardContentPathSourceMaven::save() +{ + std::shared_ptr javaSettings = std::dynamic_pointer_cast(m_settings); + if (javaSettings) + { + javaSettings->setMavenProjectFilePath(m_picker->getText().toStdString()); + javaSettings->setShouldIndexMavenTests(m_shouldIndexTests->isChecked()); + } +} + +std::vector QtProjectWizzardContentPathSourceMaven::getFileNames() const +{ + std::shared_ptr javaSettings = std::dynamic_pointer_cast(m_settings); + + const FilePath mavenPath = ApplicationSettings::getInstance()->getMavenPath(); + const FilePath mavenProjectRoot = javaSettings->getAbsoluteMavenProjectFilePath().parentDirectory(); + + std::vector list; + + const bool success = utility::mavenGenerateSources(mavenPath, mavenProjectRoot); + if (!success) + { + const std::string dialogMessage = + "Coati was unable to locate Maven on this machine.\n" + "Please make sure to provide the correct Maven Path in the preferences."; + + MessageStatus(dialogMessage, true, false).dispatch(); + + Application::getInstance()->handleDialog(dialogMessage); + } + else + { + const std::vector sourceDirectories = utility::mavenGetAllDirectoriesFromEffectivePom( + mavenPath, + mavenProjectRoot, + javaSettings->getShouldIndexMavenTests() + ); + + FileManager fileManager; + fileManager.setPaths( + sourceDirectories, + std::vector(), // we don't need to specify header paths here + m_settings->getAbsoluteExcludePaths(), + m_settings->getSourceExtensions() + ); + + const FilePath projectPath = m_settings->getProjectFileLocation(); + + for (FilePath path: fileManager.getSourceFilePaths()) + { + if (projectPath.exists()) + { + path = path.relativeTo(projectPath); + } + + list.push_back(path.str()); + } + } + + return list; +} + +QtProjectWizzardContentPathDependenciesMaven::QtProjectWizzardContentPathDependenciesMaven( + std::shared_ptr settings, QtProjectWizzardWindow* window +) + : QtProjectWizzardContentPath(settings, window) +{ + setTitleString("Intermediate Dependencies Directory"); + setHelpString( + "This directory is used to temporarily download and store the dependencies (e.g. .jar files) of the Maven project while it is indexed.
" + "
" + "You can make use of environment variables with ${ENV_VAR}." + ); +} + +void QtProjectWizzardContentPathDependenciesMaven::load() +{ + std::shared_ptr javaSettings = std::dynamic_pointer_cast(m_settings); + if (javaSettings) + { + m_picker->setText(QString::fromStdString(javaSettings->getMavenDependenciesDirectory().str())); + } +} + +void QtProjectWizzardContentPathDependenciesMaven::save() +{ + std::shared_ptr javaSettings = std::dynamic_pointer_cast(m_settings); + if (javaSettings) + { + javaSettings->setMavenDependenciesDirectory(m_picker->getText().toStdString()); + } +} diff --git a/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentPath.h b/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentPath.h new file mode 100644 index 00000000..ba89d0a1 --- /dev/null +++ b/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentPath.h @@ -0,0 +1,69 @@ +#ifndef QT_PROJECT_WIZZARD_CONTENT_PATH_H +#define QT_PROJECT_WIZZARD_CONTENT_PATH_H + +#include "qt/window/project_wizzard/QtProjectWizzardContent.h" +#include "utility/path_detector/CombinedPathDetector.h" + +class QCheckBox; +class QComboBox; +class QPushButton; + +class QtLocationPicker; + +class QtProjectWizzardContentPath + : public QtProjectWizzardContent +{ + Q_OBJECT + +public: + QtProjectWizzardContentPath(std::shared_ptr settings, QtProjectWizzardWindow* window); + + // QtSettingsWindow implementation + virtual void populate(QGridLayout* layout, int& row) override; + + virtual bool check() override; + +protected: + void setTitleString(const QString& title); + void setHelpString(const QString& help); + + QtLocationPicker* m_picker; + + bool m_makePathRelativeToProjectFileLocation; + +private: + QString m_titleString; + QString m_helpString; +}; + +class QtProjectWizzardContentPathSourceMaven + : public QtProjectWizzardContentPath +{ +public: + QtProjectWizzardContentPathSourceMaven(std::shared_ptr settings, QtProjectWizzardWindow* window); + + // QtSettingsWindow implementation + virtual void populate(QGridLayout* layout, int& row) override; + + // QtProjectWizzardContent implementation + virtual void load() override; + virtual void save() override; + + virtual std::vector getFileNames() const override; + +private: + QCheckBox* m_shouldIndexTests; +}; + +class QtProjectWizzardContentPathDependenciesMaven + : public QtProjectWizzardContentPath +{ +public: + QtProjectWizzardContentPathDependenciesMaven(std::shared_ptr settings, QtProjectWizzardWindow* window); + + // QtProjectWizzardContent implementation + virtual void load() override; + virtual void save() override; +}; + +#endif // QT_PROJECT_WIZZARD_CONTENT_PATH_H diff --git a/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentPaths.cpp b/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentPaths.cpp index e82aa94b..0e324d6d 100644 --- a/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentPaths.cpp +++ b/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentPaths.cpp @@ -172,33 +172,19 @@ void QtProjectWizzardContentPathsSource::save() std::vector QtProjectWizzardContentPathsSource::getFileNames() const { - std::vector sourcePaths = m_settings->getAbsoluteSourcePaths(); - std::vector excludePaths = m_settings->getAbsoluteExcludePaths(); - std::vector extensions = m_settings->getSourceExtensions(); + FileManager fileManager; + fileManager.setPaths( + m_settings->getAbsoluteSourcePaths(), + std::vector(), // we don't need to specify header paths here + m_settings->getAbsoluteExcludePaths(), + m_settings->getSourceExtensions() + ); - std::vector fileInfos = FileSystem::getFileInfosFromPaths(sourcePaths, extensions); - FilePath projectPath = m_settings->getProjectFileLocation(); + const FilePath projectPath = m_settings->getProjectFileLocation(); std::vector list; - for (const FileInfo& info : fileInfos) + for (FilePath path: fileManager.getSourceFilePaths()) { - FilePath path = info.path; - - bool excluded = false; - for (FilePath p : excludePaths) - { - if (p == path || p.contains(path)) - { - excluded = true; - break; - } - } - - if (excluded) - { - continue; - } - if (projectPath.exists()) { path = path.relativeTo(projectPath); diff --git a/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentPaths.h b/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentPaths.h index 37b0ebf2..666bbc9b 100644 --- a/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentPaths.h +++ b/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentPaths.h @@ -143,7 +143,6 @@ public: virtual void save() override; }; - class QtProjectWizzardContentPathsClassJava : public QtProjectWizzardContentPaths { diff --git a/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentPreferences.cpp b/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentPreferences.cpp index 99ba3f25..43899476 100644 --- a/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentPreferences.cpp +++ b/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentPreferences.cpp @@ -113,25 +113,20 @@ void QtProjectWizzardContentPreferences::populate(QGridLayout* layout, int& row) // jvm library path m_javaPath = new QtLocationPicker(this); -#ifdef _WIN32 - QString filter = "JVM Library (jvm.dll)"; -#elif __APPLE__ - QString filter = "JLI or JVM Library (libjli.dylib libjvm.dylib)"; -#else - QString filter = "JVM Library (libjvm.so)"; -#endif - m_javaPath->setFileFilter(filter); if (QSysInfo::windowsVersion() != QSysInfo::WV_None) { + m_javaPath->setFileFilter("JVM Library (jvm.dll)"); m_javaPath->setPlaceholderText("/bin/client/jvm.dll"); } else if (QSysInfo::macVersion() != QSysInfo::MV_None) { + m_javaPath->setFileFilter("JLI or JVM Library (libjli.dylib libjvm.dylib)"); m_javaPath->setPlaceholderText("/Contents/Home/jre/lib/jli/libjli.dylib"); } else { + m_javaPath->setFileFilter("JVM Library (libjvm.so)"); m_javaPath->setPlaceholderText("/bin//server/libjvm.so"); } @@ -152,6 +147,7 @@ void QtProjectWizzardContentPreferences::populate(QGridLayout* layout, int& row) javaVersionString += "Java 8"; addHelpButton(( + "Only required for indexing Java projects.\n" "Provide the location of the jvm library inside the installation of your " + javaVersionString + " runtime environment (for information on how to set these take a look at " "" @@ -168,6 +164,37 @@ void QtProjectWizzardContentPreferences::populate(QGridLayout* layout, int& row) "allocated by the indexer's JVM. A value of -1 ignores this setting.", layout, row); layout->setRowMinimumHeight(row - 1, 30); + // maven path + m_mavenPath = new QtLocationPicker(this); + + if (QSysInfo::windowsVersion() != QSysInfo::WV_None) + { + m_mavenPath->setFileFilter("Maven command (mvn.cmd)"); + m_mavenPath->setPlaceholderText("/bin/mvn.cmd"); + } + else if (QSysInfo::macVersion() != QSysInfo::MV_None) + { + // todo: add filter here + // todo: add placeholder here + } + else + { + // todo: add filter here + // todo: add placeholder here + } + + addLabelAndWidget("Maven Path", m_mavenPath, layout, row); + + addHelpButton( + "Only required for indexing projects using Maven.\n" + "Provide the location of the Maven executable. You can also use the auto detection below." + , layout, row + ); + row++; + + m_mavenPathDetector = utility::getMavenExecutablePathDetector(); + addMavenPathDetection(layout, row); + addGap(layout, row); // C/C++ @@ -214,6 +241,11 @@ void QtProjectWizzardContentPreferences::load() } m_jvmMaximumMemory->setText(QString::number(appSettings->getJavaMaximumMemory())); + + if (m_mavenPath) + { + m_mavenPath->setText(QString::fromStdString(appSettings->getMavenPath())); + } } void QtProjectWizzardContentPreferences::save() @@ -253,6 +285,11 @@ void QtProjectWizzardContentPreferences::save() int jvmMaximumMemory = m_jvmMaximumMemory->text().toInt(); if (jvmMaximumMemory) appSettings->setJavaMaximumMemory(jvmMaximumMemory); + + if (m_mavenPath) + { + appSettings->setMavenPath(m_mavenPath->getText().toStdString()); + } } bool QtProjectWizzardContentPreferences::check() @@ -265,7 +302,6 @@ void QtProjectWizzardContentPreferences::colorSchemeChanged(int index) MessageSwitchColorScheme(m_colorSchemePaths[index]).dispatch(); } - void QtProjectWizzardContentPreferences::javaPathDetectionClicked() { std::vector paths = m_javaPathDetector->getPaths(m_javaPathDetectorBox->currentText().toStdString()); @@ -275,6 +311,15 @@ void QtProjectWizzardContentPreferences::javaPathDetectionClicked() } } +void QtProjectWizzardContentPreferences::mavenPathDetectionClicked() +{ + std::vector paths = m_mavenPathDetector->getPaths(m_mavenPathDetectorBox->currentText().toStdString()); + if (!paths.empty()) + { + m_mavenPath->setText(paths.front().str().c_str()); + } +} + void QtProjectWizzardContentPreferences::loggingEnabledChanged() { m_verboseIndexerLoggingEnabled->setEnabled(m_loggingEnabled->isChecked()); @@ -314,6 +359,40 @@ void QtProjectWizzardContentPreferences::addJavaPathDetection(QGridLayout* layou row++; } +void QtProjectWizzardContentPreferences::addMavenPathDetection(QGridLayout* layout, int& row) +{ + std::vector detectorNames = m_mavenPathDetector->getWorkingDetectorNames(); + if (detectorNames.empty()) + { + return; + } + + QLabel* label = new QLabel("Auto detection from:"); + + m_mavenPathDetectorBox = new QComboBox(); + + for (const std::string& detectorName: detectorNames) + { + m_mavenPathDetectorBox->addItem(detectorName.c_str()); + } + + QPushButton* button = new QPushButton("detect"); + button->setObjectName("windowButton"); + connect(button, SIGNAL(clicked()), this, SLOT(mavenPathDetectionClicked())); + + QHBoxLayout* hlayout = new QHBoxLayout(); + hlayout->setContentsMargins(0, 0, 0, 0); + hlayout->addWidget(label); + hlayout->addWidget(m_mavenPathDetectorBox); + hlayout->addWidget(button); + + QWidget* detectionWidget = new QWidget(); + detectionWidget->setLayout(hlayout); + + layout->addWidget(detectionWidget, row, QtProjectWizzardWindow::BACK_COL, Qt::AlignLeft | Qt::AlignTop); + row++; +} + void QtProjectWizzardContentPreferences::addTitle(QString title, QGridLayout* layout, int& row) { layout->addWidget(createFormTitle(title), row++, QtProjectWizzardWindow::FRONT_COL, Qt::AlignLeft); diff --git a/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentPreferences.h b/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentPreferences.h index 4ed2e945..3afcb109 100644 --- a/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentPreferences.h +++ b/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentPreferences.h @@ -29,10 +29,12 @@ public: private slots: void colorSchemeChanged(int index); void javaPathDetectionClicked(); + void mavenPathDetectionClicked(); void loggingEnabledChanged(); private: void addJavaPathDetection(QGridLayout* layout, int& row); + void addMavenPathDetection(QGridLayout* layout, int& row); void addTitle(QString title, QGridLayout* layout, int& row); void addLabelAndWidget( @@ -63,8 +65,12 @@ private: QComboBox* m_threads; std::shared_ptr m_javaPathDetector; + std::shared_ptr m_mavenPathDetector; + QComboBox* m_javaPathDetectorBox; + QComboBox* m_mavenPathDetectorBox; QtLocationPicker* m_javaPath; + QtLocationPicker* m_mavenPath; QLineEdit* m_jvmMaximumMemory; }; diff --git a/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentSelect.cpp b/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentSelect.cpp index 329176bb..3449689c 100644 --- a/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentSelect.cpp +++ b/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentSelect.cpp @@ -7,6 +7,7 @@ #include "qt/window/project_wizzard/QtProjectWizzardWindow.h" #include "utility/ResourcePaths.h" +#include "utility/utilityString.h" #include "utility/solution/SolutionParserManager.h" @@ -22,45 +23,82 @@ QtProjectWizzardContentSelect::QtProjectWizzardContentSelect( void QtProjectWizzardContentSelect::populate(QGridLayout* layout, int& row) { - QPushButton* d = new QPushButton(languageTypeToString(LANGUAGE_CPP).c_str(), this); - QPushButton* e = new QPushButton(languageTypeToString(LANGUAGE_C).c_str(), this); - QPushButton* f = new QPushButton(languageTypeToString(LANGUAGE_JAVA).c_str(), this); + struct ProjectInfo + { + ProjectInfo(ProjectType type) :type(type) {} + const ProjectType type; + }; - d->setObjectName("menuButton"); - e->setObjectName("menuButton"); - f->setObjectName("menuButton"); + // define which kind of projects are available for each language + std::map> projectInfos; + projectInfos[LANGUAGE_C].push_back(ProjectInfo(PROJECT_C_EMPTY)); + projectInfos[LANGUAGE_C].push_back(ProjectInfo(PROJECT_CXX_CDB)); + projectInfos[LANGUAGE_C].push_back(ProjectInfo(PROJECT_CXX_VS)); + projectInfos[LANGUAGE_CPP].push_back(ProjectInfo(PROJECT_CPP_EMPTY)); + projectInfos[LANGUAGE_CPP].push_back(ProjectInfo(PROJECT_CXX_CDB)); + projectInfos[LANGUAGE_CPP].push_back(ProjectInfo(PROJECT_CXX_VS)); + projectInfos[LANGUAGE_JAVA].push_back(ProjectInfo(PROJECT_JAVA_EMPTY)); + projectInfos[LANGUAGE_JAVA].push_back(ProjectInfo(PROJECT_JAVA_MAVEN)); - d->setCheckable(true); - e->setCheckable(true); - f->setCheckable(true); + // define which icons should be used for which kind of project + m_projectTypeIconName[PROJECT_C_EMPTY] = "empty_icon"; + m_projectTypeIconName[PROJECT_CPP_EMPTY] = "empty_icon"; + m_projectTypeIconName[PROJECT_CXX_CDB] = "cdb_icon"; + m_projectTypeIconName[PROJECT_CXX_VS] = "vs_icon"; + m_projectTypeIconName[PROJECT_JAVA_EMPTY] = "empty_icon"; + m_projectTypeIconName[PROJECT_JAVA_MAVEN] = "empty_icon"; - d->setChecked(true); + // define descriptions for each kind of project + m_projectTypeDescriptions[PROJECT_C_EMPTY] = "Create a new Coati project by defining which C files will be indexed."; + m_projectTypeDescriptions[PROJECT_CPP_EMPTY] = "Create a new Coati project by defining which C++ files will be indexed."; + m_projectTypeDescriptions[PROJECT_CXX_CDB] = "Create a project from an existing Compilation Database (compile_commands.json). They can be created from Make and " + "CMake projects. Have a look at the " + "documentation to find out more."; + m_projectTypeDescriptions[PROJECT_CXX_VS] = "Create a new project from an existing Visual Studio Solution file. " + "Note: Requires a running Visual Studio instance with the " + "Visual Studio plugin installed."; + m_projectTypeDescriptions[PROJECT_JAVA_EMPTY] = "Create a new Coati project by defining which Java files will be indexed."; + m_projectTypeDescriptions[PROJECT_JAVA_MAVEN] = "Create a new project from an existing Maven project."; + + QVBoxLayout* vlayout = new QVBoxLayout(); + vlayout->setContentsMargins(0, 30, 0, 0); + vlayout->setSpacing(10); m_languages = new QButtonGroup(); - m_languages->addButton(d); - m_languages->addButton(e); - m_languages->addButton(f); + for (auto it: projectInfos) + { + QPushButton* b = new QPushButton(languageTypeToString(it.first).c_str(), this); + b->setObjectName("menuButton"); + b->setCheckable(true); + b->setProperty("language_type", it.first); + m_languages->addButton(b); + vlayout->addWidget(b); + } - m_languages->setId(d, 0); - m_languages->setId(e, 1); - m_languages->setId(f, 2); + vlayout->addStretch(); + layout->addLayout(vlayout, 0, QtProjectWizzardWindow::FRONT_COL, Qt::AlignRight); - connect(m_languages, static_cast(&QButtonGroup::buttonClicked), - [this](int id) + connect(m_languages, static_cast(&QButtonGroup::buttonClicked), + [this](QAbstractButton* button) { - bool isJava = stringToLanguageType(m_languages->checkedButton()->text().toStdString()) == LANGUAGE_JAVA; - - m_buttons->setExclusive(false); - for (int i = 0; i < m_buttons->buttons().size(); i++) + LanguageType selectedLanguage = LANGUAGE_UNKNOWN; + bool ok = false; + int languageTypeInt = button->property("language_type").toInt(&ok); + if (ok) { - m_buttons->button(i)->setChecked(false); + selectedLanguage = LanguageType(languageTypeInt); + } - if (i != 0) + for (auto it: m_buttons) + { + it.second->setExclusive(false); + for (QAbstractButton* button: it.second->buttons()) { - m_buttons->button(i)->setVisible(!isJava); + button->setChecked(false); + button->setVisible(it.first == selectedLanguage); } + it.second->setExclusive(true); } - m_buttons->setExclusive(true); m_window->setNextEnabled(false); m_title->setText("Project Types - " + m_languages->checkedButton()->text()); @@ -68,94 +106,46 @@ void QtProjectWizzardContentSelect::populate(QGridLayout* layout, int& row) } ); - QVBoxLayout* vlayout = new QVBoxLayout(); - vlayout->setContentsMargins(0, 30, 0, 0); - vlayout->setSpacing(10); - - vlayout->addWidget(d); - vlayout->addWidget(e); - vlayout->addWidget(f); - - vlayout->addStretch(); - - layout->addLayout(vlayout, 0, QtProjectWizzardWindow::FRONT_COL, Qt::AlignRight); - - - QToolButton* a = createProjectButton( - "Empty Project", (ResourcePaths::getGuiPath() + "icon/empty_icon.png").c_str()); - QToolButton* c = createProjectButton( - "from Compilation\nDatabase", (ResourcePaths::getGuiPath() + "icon/cdb_icon.png").c_str()); - - m_solutionDescription.push_back("Create a new Coati project by defining what files will be indexed."); - m_solutionDescription.push_back( - "Create a project from an existing Compilation Database (compile_commands.json). They can be created from Make and " - "CMake projects. Have a look at the " - "documentation to find out more."); - - m_buttons = new QButtonGroup(this); - m_buttons->addButton(a); - m_buttons->addButton(c); - - m_buttons->setId(a, PROJECT_EMPTY); - m_buttons->setId(c, PROJECT_CDB); - QHBoxLayout* hlayout = new QHBoxLayout(); - hlayout->addWidget(a); - hlayout->addWidget(c); - - unsigned int runningId = 2; - std::shared_ptr manager = m_solutionParserManager.lock(); - if (manager != NULL) + for (auto languageIt: projectInfos) { - for (unsigned int i = 0; i < manager->getParserCount(); i++) + QButtonGroup* projectButtons = new QButtonGroup(this); + + for (auto projectIt: languageIt.second) { - std::string name = manager->getParserButtonText(i); - - QToolButton* button = createProjectButton(name.c_str(), - (ResourcePaths::getGuiPath() + manager->getIconPath(i)).c_str()); - - m_buttons->addButton(button); - - m_solutionDescription.push_back(manager->getParserDescription(i)); - - hlayout->addWidget(button); - - m_buttons->setId(button, runningId); - - runningId++; + QToolButton* b = createProjectButton( + utility::insertLineBreaksAtBlankSpaces(projectTypeToString(projectIt.type), 15).c_str(), + (ResourcePaths::getGuiPath() + "icon/" + m_projectTypeIconName[projectIt.type] + ".png").c_str() + ); + b->setProperty("project_type", int(projectIt.type)); + projectButtons->addButton(b); + hlayout->addWidget(b); } + + m_buttons[languageIt.first] = projectButtons; } - // Add vs solution button + for (auto it: m_buttons) { - std::string name = "Visual Studio"; + connect(it.second, static_cast(&QButtonGroup::buttonClicked), + [this](QAbstractButton* button) + { + ProjectType selectedProject = PROJECT_UNKNOWN; + bool ok = false; + int projectTypeInt = button->property("project_type").toInt(&ok); + if (ok) + { + selectedProject = ProjectType(projectTypeInt); + } - QToolButton* button = createProjectButton(name.c_str(), - (ResourcePaths::getGuiPath() + "icon/vs_icon.png").c_str()); + m_description->setText(m_projectTypeDescriptions[selectedProject].c_str()); - m_buttons->addButton(button); - - m_solutionDescription.push_back("Create a new project from an existing Visual Studio Solution file. " - "Note: Requires a running Visual Studio instance with the " - "Visual Studio plugin installed."); - - hlayout->addWidget(button); - - m_buttons->setId(button, runningId); - - runningId++; + m_window->setNextEnabled(true); + } + ); } - connect(m_buttons, static_cast(&QButtonGroup::buttonClicked), - [this](int id) - { - m_description->setText(m_solutionDescription[id].c_str()); - - m_window->setNextEnabled(true); - } - ); - QFrame* container = new QFrame(); container->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding); container->setObjectName("projectContainer"); @@ -169,7 +159,7 @@ void QtProjectWizzardContentSelect::populate(QGridLayout* layout, int& row) m_description->setObjectName("projectDescription"); layout->addWidget(m_description, 1, QtProjectWizzardWindow::BACK_COL); - m_title = new QLabel("Project Types - " + m_languages->checkedButton()->text()); + m_title = new QLabel("Project Types"); m_title->setObjectName("projectTitle"); layout->addWidget(m_title, 0, QtProjectWizzardWindow::BACK_COL, Qt::AlignLeft | Qt::AlignTop); @@ -179,26 +169,44 @@ void QtProjectWizzardContentSelect::populate(QGridLayout* layout, int& row) layout->setColumnStretch(QtProjectWizzardWindow::FRONT_COL, 0); layout->setColumnStretch(QtProjectWizzardWindow::BACK_COL, 1); layout->setHorizontalSpacing(0); + + m_languages->buttons().first()->click(); } void QtProjectWizzardContentSelect::save() { ProjectType type; - switch (m_buttons->checkedId()) + for (auto it: m_buttons) { - case 0: type = PROJECT_EMPTY; break; - case 1: type = PROJECT_CDB; break; - case 2: type = PROJECT_MANAGED; break; - default: type = PROJECT_MANAGED; break; + if (QAbstractButton* b = it.second->checkedButton()) + { + bool ok = false; + int projectType = b->property("project_type").toInt(&ok); + if (ok) + { + type = ProjectType(projectType); + break; + } + } } - - emit selected(stringToLanguageType(m_languages->checkedButton()->text().toStdString()), type); + emit selected(type); } bool QtProjectWizzardContentSelect::check() { - if (m_buttons->checkedId() == -1) + bool projectChosen = false; + + for (auto it: m_buttons) + { + if (it.second->checkedId() != -1) + { + projectChosen = true; + break; + } + } + + if (!projectChosen) { QMessageBox msgBox; msgBox.setText("Please choose a method of creating a new project."); diff --git a/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentSelect.h b/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentSelect.h index b5083513..65624ca7 100644 --- a/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentSelect.h +++ b/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentSelect.h @@ -12,13 +12,6 @@ class QtProjectWizzardContentSelect Q_OBJECT public: - enum ProjectType : int - { - PROJECT_EMPTY = 0, - PROJECT_CDB = 1, - PROJECT_MANAGED = 2 // use this type for all standard parser (parsers that are handled by the parser manager) - }; - QtProjectWizzardContentSelect( std::shared_ptr settings, QtProjectWizzardWindow* window, @@ -31,18 +24,17 @@ public: virtual bool check() override; signals: - void selected(LanguageType, QtProjectWizzardContentSelect::ProjectType); + void selected(ProjectType); private: QButtonGroup* m_languages; - QButtonGroup* m_buttons; + std::map m_buttons; QLabel* m_title; QLabel* m_description; - std::vector m_projectTypeNames; - std::vector m_projectTypeDescriptions; - std::vector m_projectTypeIconPaths; + std::map m_projectTypeIconName; + std::map m_projectTypeDescriptions; std::weak_ptr m_solutionParserManager; std::vector m_solutionDescription; diff --git a/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardWindow.cpp b/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardWindow.cpp index 7223595f..bdb60526 100644 --- a/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardWindow.cpp +++ b/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardWindow.cpp @@ -40,6 +40,11 @@ void QtProjectWizzardWindow::setPreferredSize(QSize size) m_preferredSize = size; } +void QtProjectWizzardWindow::saveContent() +{ + m_content->save(); +} + void QtProjectWizzardWindow::populateWindow(QWidget* widget) { QGridLayout* layout = new QGridLayout(); @@ -80,7 +85,7 @@ void QtProjectWizzardWindow::windowReady() void QtProjectWizzardWindow::handleNext() { - m_content->save(); + saveContent(); if (m_content->check()) { diff --git a/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardWindow.h b/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardWindow.h index e9c58032..109e9732 100644 --- a/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardWindow.h +++ b/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardWindow.h @@ -20,6 +20,8 @@ public: void setPreferredSize(QSize size); + void saveContent(); + static const int FRONT_COL = 0; static const int HELP_COL = 1; static const int LINE_COL = 2; diff --git a/src/lib_gui/utility/path_detector/maven_executable/MavenPathDetectorUnix.cpp b/src/lib_gui/utility/path_detector/maven_executable/MavenPathDetectorUnix.cpp new file mode 100644 index 00000000..964dfde8 --- /dev/null +++ b/src/lib_gui/utility/path_detector/maven_executable/MavenPathDetectorUnix.cpp @@ -0,0 +1,25 @@ +#include "utility/path_detector/maven_executable/MavenPathDetectorUnix.h" + +#include "utility/utilityApp.h" + +MavenPathDetectorUnix::MavenPathDetectorUnix() + : PathDetector("Maven for Unix") +{ +} + +MavenPathDetectorUnix::~MavenPathDetectorUnix() +{ +} + +std::vector MavenPathDetectorUnix::getPaths() const +{ + std::string command = "which mvn"; + FilePath mavenPath(utility::executeProcess(command.c_str())); + + std::vector paths; + if (mavenPath.exists()) + { + paths.push_back(mavenPath); + } + return paths; +} diff --git a/src/lib_gui/utility/path_detector/maven_executable/MavenPathDetectorUnix.h b/src/lib_gui/utility/path_detector/maven_executable/MavenPathDetectorUnix.h new file mode 100644 index 00000000..5528e0d0 --- /dev/null +++ b/src/lib_gui/utility/path_detector/maven_executable/MavenPathDetectorUnix.h @@ -0,0 +1,15 @@ +#ifndef MAVEN_PATH_DETECTOR_UNIX_H +#define MAVEN_PATH_DETECTOR_UNIX_H + +#include "utility/path_detector/PathDetector.h" + +class MavenPathDetectorUnix: public PathDetector +{ +public: + MavenPathDetectorUnix(); + virtual ~MavenPathDetectorUnix(); + + virtual std::vector getPaths() const; +}; + +#endif // MAVEN_PATH_DETECTOR_UNIX_H diff --git a/src/lib_gui/utility/path_detector/maven_executable/MavenPathDetectorWindows.cpp b/src/lib_gui/utility/path_detector/maven_executable/MavenPathDetectorWindows.cpp new file mode 100644 index 00000000..a704f060 --- /dev/null +++ b/src/lib_gui/utility/path_detector/maven_executable/MavenPathDetectorWindows.cpp @@ -0,0 +1,25 @@ +#include "utility/path_detector/maven_executable/MavenPathDetectorWindows.h" + +#include "utility/utilityApp.h" + +MavenPathDetectorWindows::MavenPathDetectorWindows() + : PathDetector("Maven for Windows") +{ +} + +MavenPathDetectorWindows::~MavenPathDetectorWindows() +{ +} + +std::vector MavenPathDetectorWindows::getPaths() const +{ + std::string command = "cmd /k where mvn.cmd && exit"; + FilePath mavenPath(utility::executeProcess(command.c_str())); + + std::vector paths; + if (mavenPath.exists()) + { + paths.push_back(mavenPath); + } + return paths; +} diff --git a/src/lib_gui/utility/path_detector/maven_executable/MavenPathDetectorWindows.h b/src/lib_gui/utility/path_detector/maven_executable/MavenPathDetectorWindows.h new file mode 100644 index 00000000..e71e8045 --- /dev/null +++ b/src/lib_gui/utility/path_detector/maven_executable/MavenPathDetectorWindows.h @@ -0,0 +1,15 @@ +#ifndef MAVEN_PATH_DETECTOR_WINDOWS_H +#define MAVEN_PATH_DETECTOR_WINDOWS_H + +#include "utility/path_detector/PathDetector.h" + +class MavenPathDetectorWindows: public PathDetector +{ +public: + MavenPathDetectorWindows(); + virtual ~MavenPathDetectorWindows(); + + virtual std::vector getPaths() const; +}; + +#endif // MAVEN_PATH_DETECTOR_WINDOWS_H diff --git a/src/lib_gui/utility/utilityApp.cpp b/src/lib_gui/utility/utilityApp.cpp index d1aae498..37f8265f 100644 --- a/src/lib_gui/utility/utilityApp.cpp +++ b/src/lib_gui/utility/utilityApp.cpp @@ -5,11 +5,17 @@ #include "utility/utilityString.h" -std::string utility::executeProcess(const char *cmd) +std::string utility::executeProcess(const std::string& command, const std::string& workingDirectory) { QProcess process; process.setProcessChannelMode(QProcess::MergedChannels); - process.start(cmd); + + if (!workingDirectory.empty()) + { + process.setWorkingDirectory(workingDirectory.c_str()); + } + + process.start(command.c_str()); process.waitForFinished(); std::string processoutput = process.readAll().toStdString(); process.close(); diff --git a/src/lib_gui/utility/utilityApp.h b/src/lib_gui/utility/utilityApp.h index c28865f1..c14b498e 100644 --- a/src/lib_gui/utility/utilityApp.h +++ b/src/lib_gui/utility/utilityApp.h @@ -1,17 +1,16 @@ #ifndef UTILITY_APP_H #define UTILITY_APP_H -#include +#include #include "utility/ApplicationArchitectureType.h" namespace utility { - std::string executeProcess(const char* cmd); + std::string executeProcess(const std::string& command, const std::string& workingDirectory = ""); ApplicationArchitectureType getApplicationArchitectureType(); } - #endif // UTILITY_APP_H diff --git a/src/lib_gui/utility/utilityPathDetection.cpp b/src/lib_gui/utility/utilityPathDetection.cpp index f4eee105..8a9e78f3 100644 --- a/src/lib_gui/utility/utilityPathDetection.cpp +++ b/src/lib_gui/utility/utilityPathDetection.cpp @@ -6,6 +6,9 @@ #include "utility/path_detector/java_runtime/JavaPathDetectorMac.h" #include "utility/path_detector/java_runtime/JavaPathDetectorWindows.h" +#include "utility/path_detector/maven_executable/MavenPathDetectorUnix.h" +#include "utility/path_detector/maven_executable/MavenPathDetectorWindows.h" + #include "utility/path_detector/cxx_header/CxxFrameworkPathDetector.h" #include "utility/path_detector/cxx_header/CxxHeaderPathDetector.h" #include "utility/path_detector/cxx_header/CxxVsHeaderPathDetector.h" @@ -29,6 +32,21 @@ std::shared_ptr utility::getJavaRuntimePathDetector() return combinedDetector; } +std::shared_ptr utility::getMavenExecutablePathDetector() +{ + std::shared_ptr combinedDetector = std::make_shared(); + if (QSysInfo::windowsVersion() != QSysInfo::WV_None) + { + combinedDetector->addDetector(std::make_shared()); + } + else + { + combinedDetector->addDetector(std::make_shared()); + } + + return combinedDetector; +} + std::shared_ptr utility::getCxxVsHeaderPathDetector() { std::shared_ptr combinedDetector = std::make_shared(); diff --git a/src/lib_gui/utility/utilityPathDetection.h b/src/lib_gui/utility/utilityPathDetection.h index 30111368..0030e321 100644 --- a/src/lib_gui/utility/utilityPathDetection.h +++ b/src/lib_gui/utility/utilityPathDetection.h @@ -6,6 +6,7 @@ namespace utility { std::shared_ptr getJavaRuntimePathDetector(); + std::shared_ptr getMavenExecutablePathDetector(); std::shared_ptr getCxxVsHeaderPathDetector(); std::shared_ptr getCxxHeaderPathDetector(); diff --git a/src/lib_java/CMakeLists.txt b/src/lib_java/CMakeLists.txt index 5ac11e24..492e6a8e 100644 --- a/src/lib_java/CMakeLists.txt +++ b/src/lib_java/CMakeLists.txt @@ -16,6 +16,9 @@ add_files( data/parser/java/JavaEnvironmentFactory.cpp data/parser/java/JavaEnvironmentFactory.h + utility/utilityMaven.cpp + utility/utilityMaven.h + JavaProject.cpp JavaProject.h ProjectFactoryModuleJava.cpp diff --git a/src/lib_java/JavaProject.cpp b/src/lib_java/JavaProject.cpp index 39057114..3da96312 100644 --- a/src/lib_java/JavaProject.cpp +++ b/src/lib_java/JavaProject.cpp @@ -5,14 +5,20 @@ #include "data/parser/java/JavaEnvironmentFactory.h" #include "data/parser/java/JavaEnvironment.h" #include "utility/file/FileRegister.h" -#include "utility/text/TextAccess.h" +#include "utility/file/FileSystem.h" #include "utility/messaging/type/MessageStatus.h" +#include "utility/text/TextAccess.h" #include "utility/ResourcePaths.h" +#include "utility/utilityMaven.h" #include "utility/utilityString.h" #include "Application.h" +#include "settings/ApplicationSettings.h" + +#include "utility/tracing.h" +#include "utility/ScopedFunctor.h" JavaProject::JavaProject( - std::shared_ptr projectSettings, StorageAccessProxy* storageAccessProxy, DialogView* dialogView + std::shared_ptr projectSettings, StorageAccessProxy* storageAccessProxy, std::shared_ptr dialogView ) : Project(storageAccessProxy, dialogView) , m_projectSettings(projectSettings) @@ -67,17 +73,52 @@ bool JavaProject::prepareIndexing() if (!JavaEnvironmentFactory::getInstance()) { std::string dialogMessage = - "Coati was unable to locate Java on this machine.\nPlease make sure to provide the correct Java Path in the preferences."; + "Coati was unable to locate Java on this machine.\n" + "Please make sure to provide the correct Java Path in the preferences."; if (errorString.size() > 0) { dialogMessage += "\n\nError: " + errorString; } + MessageStatus(dialogMessage, true, false).dispatch(); + Application::getInstance()->handleDialog(dialogMessage); return false; } + if (m_projectSettings->getAbsoluteMavenProjectFilePath().exists()) + { + const FilePath mavenPath = ApplicationSettings::getInstance()->getMavenPath(); + const FilePath projectRootPath = m_projectSettings->getAbsoluteMavenProjectFilePath().parentDirectory(); + + ScopedFunctor dialogHider([this](){ + getDialogView()->hideStatusDialog(); + }); + + getDialogView()->showStatusDialog("Preparing Project", "Maven\nGenerating Source Files"); + bool success = utility::mavenGenerateSources( + mavenPath, projectRootPath + ); + + if (!success) + { + const std::string dialogMessage = + "Coati was unable to locate Maven on this machine.\n" + "Please make sure to provide the correct Maven Path in the preferences."; + + MessageStatus(dialogMessage, true, false).dispatch(); + + Application::getInstance()->handleDialog(dialogMessage); + return false; + } + + getDialogView()->showStatusDialog("Preparing Project", "Maven\nExporting Dependencies"); + utility::mavenCopyDependencies( + mavenPath, projectRootPath, m_projectSettings->getAbsoluteMavenDependenciesDirectory() + ); + } + return true; } @@ -85,7 +126,7 @@ std::vector> JavaProject::getIndexerCommands() { std::vector classPath; - for (FilePath p: m_projectSettings->getAbsoluteClasspaths()) + for (const FilePath& p: m_projectSettings->getAbsoluteClasspaths()) { if (p.exists()) { @@ -93,6 +134,18 @@ std::vector> JavaProject::getIndexerCommands() } } + if (m_projectSettings->getAbsoluteMavenDependenciesDirectory().exists()) + { + const std::vector dependencies = FileSystem::getFileNamesFromDirectory( + m_projectSettings->getAbsoluteMavenDependenciesDirectory().str(), + std::vector(1, ".jar") + ); + for (const std::string& dependency: dependencies) + { + classPath.push_back(dependency); + } + } + if (!m_rootDirectories) { getDialogView()->showStatusDialog("Preparing Project", "Gathering Root\nDirectories"); @@ -135,10 +188,23 @@ std::vector> JavaProject::getIndexerCommands() return indexerCommands; } - void JavaProject::updateFileManager(FileManager& fileManager) { - std::vector sourcePaths = m_projectSettings->getAbsoluteSourcePaths(); + std::vector sourcePaths; + if (m_projectSettings->getAbsoluteMavenProjectFilePath().exists()) + { + getDialogView()->showStatusDialog("Preparing Project", "Maven\nFetching Source Directories"); + + const FilePath mavenPath(ApplicationSettings::getInstance()->getMavenPath()); + const FilePath projectRootPath = m_projectSettings->getAbsoluteMavenProjectFilePath().parentDirectory(); + sourcePaths = utility::mavenGetAllDirectoriesFromEffectivePom(mavenPath, projectRootPath, m_projectSettings->getShouldIndexMavenTests()); + + getDialogView()->hideStatusDialog(); + } + else + { + sourcePaths = m_projectSettings->getAbsoluteSourcePaths(); + } std::vector headerPaths = sourcePaths; std::vector sourceExtensions = m_projectSettings->getSourceExtensions(); std::vector excludePaths = m_projectSettings->getAbsoluteExcludePaths(); @@ -151,12 +217,7 @@ void JavaProject::fetchRootDirectories() m_rootDirectories = std::make_shared>(); FileManager fileManager; - fileManager.setPaths( - m_projectSettings->getAbsoluteSourcePaths(), - std::vector(), - m_projectSettings->getAbsoluteExcludePaths(), - m_projectSettings->getSourceExtensions() - ); + updateFileManager(fileManager); FileManager::FileSets fileSets = fileManager.fetchFilePaths(std::vector()); std::shared_ptr javaEnvironment = JavaEnvironmentFactory::getInstance()->createEnvironment(); diff --git a/src/lib_java/JavaProject.h b/src/lib_java/JavaProject.h index 8dc9cc36..f097df51 100644 --- a/src/lib_java/JavaProject.h +++ b/src/lib_java/JavaProject.h @@ -12,7 +12,7 @@ public: JavaProject( std::shared_ptr projectSettings, StorageAccessProxy* storageAccessProxy, - DialogView* dialogView + std::shared_ptr dialogView ); virtual ~JavaProject(); diff --git a/src/lib_java/ProjectFactoryModuleJava.cpp b/src/lib_java/ProjectFactoryModuleJava.cpp index dc5edcf4..5d013969 100644 --- a/src/lib_java/ProjectFactoryModuleJava.cpp +++ b/src/lib_java/ProjectFactoryModuleJava.cpp @@ -13,7 +13,7 @@ LanguageType ProjectFactoryModuleJava::getLanguage() const } std::shared_ptr ProjectFactoryModuleJava::createProject( - const FilePath& projectSettingsFile, StorageAccessProxy* storageAccessProxy, DialogView* dialogView + const FilePath& projectSettingsFile, StorageAccessProxy* storageAccessProxy, std::shared_ptr dialogView ) { return std::shared_ptr(new JavaProject( diff --git a/src/lib_java/ProjectFactoryModuleJava.h b/src/lib_java/ProjectFactoryModuleJava.h index 56f5dc22..65a12393 100644 --- a/src/lib_java/ProjectFactoryModuleJava.h +++ b/src/lib_java/ProjectFactoryModuleJava.h @@ -10,7 +10,7 @@ public: virtual LanguageType getLanguage() const; virtual std::shared_ptr createProject( - const FilePath& projectSettingsFile, StorageAccessProxy* storageAccessProxy, DialogView* dialogView + const FilePath& projectSettingsFile, StorageAccessProxy* storageAccessProxy, std::shared_ptr dialogView ); }; diff --git a/src/lib_java/utility/utilityMaven.cpp b/src/lib_java/utility/utilityMaven.cpp new file mode 100644 index 00000000..5c436d1b --- /dev/null +++ b/src/lib_java/utility/utilityMaven.cpp @@ -0,0 +1,104 @@ +#include "utility/utilityMaven.h" + +#include "utility/text/TextAccess.h" +#include "utility/utilityApp.h" +#include "utility/utilityString.h" +#include "utility/utilityXml.h" +#include "utility/utility.h" + +namespace utility +{ + bool mavenGenerateSources(const FilePath& mavenPath, const FilePath& projectDirectoryPath) + { + const std::string output = utility::executeProcess( + mavenPath.str() + " generate-sources", + projectDirectoryPath.str() + ); + return !output.empty(); + } + + bool mavenCopyDependencies(const FilePath& mavenPath, const FilePath& projectDirectoryPath, const FilePath& outputDirectoryPath) + { + const std::string output = utility::executeProcess( + mavenPath.str() + " dependency:copy-dependencies -DoutputDirectory=" + outputDirectoryPath.str(), + projectDirectoryPath.str() + ); + return !output.empty(); + } + + std::vector mavenGetAllDirectoriesFromEffectivePom(const FilePath& mavenPath, const FilePath& projectDirectoryPath, bool addTestDirectories) + { + + std::shared_ptr outputAccess = TextAccess::createFromString(utility::executeProcess( + mavenPath.str() + " help:effective-pom", + projectDirectoryPath.str() + )); + + std::string xmlContent = ""; + for (std::string line: outputAccess->getAllLines()) + { + const std::string trimmedLine = utility::trim(line); + if (!trimmedLine.empty() && trimmedLine.front() == '<') + { + xmlContent.append(line); + } + } + std::shared_ptr xmlAccess = TextAccess::createFromString(xmlContent); + + std::vector directories; + + + std::vector uncheckedDirectories; + for (std::string value: utility::getValuesOfAllXmlElementsOnPath(xmlAccess, utility::createVectorFromElements("project", "build", "sourceDirectory"))) + { + uncheckedDirectories.push_back(FilePath(value)); + } + + for (std::string value: utility::getValuesOfAllXmlElementsOnPath(xmlAccess, utility::createVectorFromElements("projects", "project", "build", "sourceDirectory"))) + { + uncheckedDirectories.push_back(FilePath(value)); + } + + for (std::string value: utility::getValuesOfAllXmlElementsOnPath(xmlAccess, utility::createVectorFromElements("project", "build", "directory"))) + { + uncheckedDirectories.push_back(FilePath(value).concat("generated-sources")); + } + + for (std::string value: utility::getValuesOfAllXmlElementsOnPath(xmlAccess, utility::createVectorFromElements("projects", "project", "build", "directory"))) + { + uncheckedDirectories.push_back(FilePath(value).concat("generated-sources")); + } + + if (addTestDirectories) + { + for (std::string value: utility::getValuesOfAllXmlElementsOnPath(xmlAccess, utility::createVectorFromElements("project", "build", "testSourceDirectory"))) + { + uncheckedDirectories.push_back(FilePath(value)); + } + for (std::string value: utility::getValuesOfAllXmlElementsOnPath(xmlAccess, utility::createVectorFromElements("projects", "project", "build", "testSourceDirectory"))) + { + uncheckedDirectories.push_back(FilePath(value)); + } + + for (std::string value: utility::getValuesOfAllXmlElementsOnPath(xmlAccess, utility::createVectorFromElements("project", "build", "directory"))) + { + uncheckedDirectories.push_back(FilePath(value).concat("generated-test-sources")); + } + + for (std::string value: utility::getValuesOfAllXmlElementsOnPath(xmlAccess, utility::createVectorFromElements("projects", "project", "build", "directory"))) + { + uncheckedDirectories.push_back(FilePath(value).concat("generated-test-sources")); + } + } + + for (const FilePath& uncheckedDirectory: uncheckedDirectories) + { + if (uncheckedDirectory.exists()) + { + directories.push_back(uncheckedDirectory); + } + } + + return directories; + } +} diff --git a/src/lib_java/utility/utilityMaven.h b/src/lib_java/utility/utilityMaven.h new file mode 100644 index 00000000..497aef06 --- /dev/null +++ b/src/lib_java/utility/utilityMaven.h @@ -0,0 +1,13 @@ +#ifndef UTILITY_MAVEN_H +#define UTILITY_MAVEN_H + +#include "utility/file/FilePath.h" + +namespace utility +{ + bool mavenGenerateSources(const FilePath& mavenPath, const FilePath& projectDirectoryPath); + bool mavenCopyDependencies(const FilePath& mavenPath, const FilePath& projectDirectoryPath, const FilePath& outputDirectoryPath); + std::vector mavenGetAllDirectoriesFromEffectivePom(const FilePath& mavenPath, const FilePath& projectDirectoryPath, bool addTestDirectories); +} + +#endif // UTILITY_MAVEN_H