From 97b151371b39e04207d991ed681c6f227d8063e3 Mon Sep 17 00:00:00 2001 From: malte_langkabel Date: Wed, 12 Oct 2016 19:10:03 +0200 Subject: [PATCH] ui: added initial auto-detection for cpp standard headers and java runtime library * when Coati is started with no java-path or global cxx header or framework paths in the appsettings they are auto-detected using the first working detector * order in which the detectors are shown in gui now matches the order they are added to the combined detector. --- src/app/main.cpp | 69 ++++++++++++++++--- src/lib_gui/CMakeLists.txt | 2 + .../QtProjectWizzardContentPaths.cpp | 20 +----- .../QtProjectWizzardContentPreferences.cpp | 20 +----- .../path_detector/CombinedPathDetector.cpp | 25 ++++--- .../path_detector/CombinedPathDetector.h | 5 +- src/lib_gui/utility/utilityPathDetection.cpp | 54 +++++++++++++++ src/lib_gui/utility/utilityPathDetection.h | 15 ++++ 8 files changed, 151 insertions(+), 59 deletions(-) create mode 100644 src/lib_gui/utility/utilityPathDetection.cpp create mode 100644 src/lib_gui/utility/utilityPathDetection.h diff --git a/src/app/main.cpp b/src/app/main.cpp index 07ffe063..cbff2b77 100644 --- a/src/app/main.cpp +++ b/src/app/main.cpp @@ -1,10 +1,3 @@ -#include "utility/AppPath.h" -#include "utility/commandline/CommandLineParser.h" -#include "utility/ResourcePaths.h" -#include "utility/ScopedFunctor.h" -#include "utility/UserPaths.h" -#include "utility/Version.h" - #include "Application.h" #include "ProjectFactoryModuleC.h" #include "ProjectFactoryModuleCpp.h" @@ -17,8 +10,61 @@ #include "qt/utility/utilityQt.h" #include "qt/view/QtViewFactory.h" #include "qt/window/QtMainWindow.h" +#include "settings/ApplicationSettings.h" +#include "utility/AppPath.h" +#include "utility/commandline/CommandLineParser.h" +#include "utility/ResourcePaths.h" +#include "utility/ScopedFunctor.h" +#include "utility/UserPaths.h" +#include "utility/utilityPathDetection.h" +#include "utility/Version.h" #include "version.h" +void prefillJavaRuntimePath() +{ + std::shared_ptr settings = ApplicationSettings::getInstance(); + if (settings->getJavaPath().empty()) + { + std::shared_ptr javaPathDetector = utility::getJavaRuntimePathDetector(); + std::vector paths = javaPathDetector->getPaths(); + if (!paths.empty()) + { + settings->setJavaPath(paths.front().str()); + settings->save(); + } + } +} + +void prefillCxxHeaderPaths() +{ + std::shared_ptr settings = ApplicationSettings::getInstance(); + if (settings->getHeaderSearchPaths().empty()) + { + std::shared_ptr cxxHeaderDetector = utility::getCxxHeaderPathDetector(); + std::vector paths = cxxHeaderDetector->getPaths(); + if (!paths.empty()) + { + settings->setHeaderSearchPaths(paths); + settings->save(); + } + } +} + +void prefillCxxFrameworkPaths() +{ + std::shared_ptr settings = ApplicationSettings::getInstance(); + if (settings->getFrameworkSearchPaths().empty()) + { + std::shared_ptr cxxFrameworkDetector = utility::getCxxFrameworkPathDetector(); + std::vector paths = cxxFrameworkDetector->getPaths(); + if (!paths.empty()) + { + settings->setFrameworkSearchPaths(paths); + settings->save(); + } + } +} + int main(int argc, char *argv[]) { QApplication::setApplicationName("Coati"); @@ -51,6 +97,10 @@ int main(int argc, char *argv[]) Application::destroyInstance(); }); + prefillJavaRuntimePath(); + prefillCxxHeaderPaths(); + prefillCxxFrameworkPaths(); + Application::getInstance()->addProjectFactoryModule(std::make_shared()); Application::getInstance()->addProjectFactoryModule(std::make_shared()); Application::getInstance()->addProjectFactoryModule(std::make_shared()); @@ -90,6 +140,10 @@ int main(int argc, char *argv[]) Application::destroyInstance(); }); + prefillJavaRuntimePath(); + prefillCxxHeaderPaths(); + prefillCxxFrameworkPaths(); + Application::getInstance()->addProjectFactoryModule(std::make_shared()); Application::getInstance()->addProjectFactoryModule(std::make_shared()); Application::getInstance()->addProjectFactoryModule(std::make_shared()); @@ -102,4 +156,3 @@ int main(int argc, char *argv[]) return qtApp.exec(); } } - diff --git a/src/lib_gui/CMakeLists.txt b/src/lib_gui/CMakeLists.txt index da9ecf9a..ba35a2d6 100644 --- a/src/lib_gui/CMakeLists.txt +++ b/src/lib_gui/CMakeLists.txt @@ -194,4 +194,6 @@ add_files( utility/utilityApp.cpp utility/utilityApp.h + utility/utilityPathDetection.cpp + utility/utilityPathDetection.h ) diff --git a/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentPaths.cpp b/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentPaths.cpp index add299f0..fa07f35d 100644 --- a/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentPaths.cpp +++ b/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentPaths.cpp @@ -13,10 +13,8 @@ #include "utility/CompilationDatabase.h" #include "utility/file/FileManager.h" #include "utility/file/FileSystem.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" #include "utility/utility.h" +#include "utility/utilityPathDetection.h" QtProjectWizzardContentPaths::QtProjectWizzardContentPaths(std::shared_ptr settings, QtProjectWizzardWindow* window) : QtProjectWizzardContent(settings, window) @@ -364,17 +362,7 @@ QtProjectWizzardContentPathsHeaderSearchGlobal::QtProjectWizzardContentPathsHead "Finding System Header Locations or use the auto detection below)." ); - m_pathDetector = std::make_shared(); - m_pathDetector->addDetector(std::make_shared("gcc")); - m_pathDetector->addDetector(std::make_shared("clang")); - m_pathDetector->addDetector(std::make_shared(9, false)); - m_pathDetector->addDetector(std::make_shared(9, true)); - m_pathDetector->addDetector(std::make_shared(11, false)); - m_pathDetector->addDetector(std::make_shared(11, true)); - m_pathDetector->addDetector(std::make_shared(12, false)); - m_pathDetector->addDetector(std::make_shared(12, true)); - m_pathDetector->addDetector(std::make_shared(14, false)); - m_pathDetector->addDetector(std::make_shared(14, true)); + m_pathDetector = utility::getCxxHeaderPathDetector(); } void QtProjectWizzardContentPathsHeaderSearchGlobal::load() @@ -439,9 +427,7 @@ QtProjectWizzardContentPathsFrameworkSearchGlobal::QtProjectWizzardContentPathsF "Finding System Header Locations or use the auto detection below)." ); - m_pathDetector = std::make_shared(); - m_pathDetector->addDetector(std::make_shared("gcc")); - m_pathDetector->addDetector(std::make_shared("clang")); + m_pathDetector = utility::getCxxFrameworkPathDetector(); } void QtProjectWizzardContentPathsFrameworkSearchGlobal::load() diff --git a/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentPreferences.cpp b/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentPreferences.cpp index 97240e73..f9fbbdd9 100644 --- a/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentPreferences.cpp +++ b/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentPreferences.cpp @@ -3,10 +3,8 @@ #include "settings/ApplicationSettings.h" #include "utility/file/FileSystem.h" #include "utility/messaging/type/MessageSwitchColorScheme.h" -#include "utility/path_detector/java_runtime/JavaPathDetectorLinux.h" -#include "utility/path_detector/java_runtime/JavaPathDetectorMac.h" -#include "utility/path_detector/java_runtime/JavaPathDetectorWindows.h" #include "utility/ResourcePaths.h" +#include "utility/utilityPathDetection.h" QtProjectWizzardContentPreferences::QtProjectWizzardContentPreferences( std::shared_ptr settings, QtProjectWizzardWindow* window @@ -217,19 +215,7 @@ void QtProjectWizzardContentPreferences::populate(QGridLayout* layout, int& row) ); row++; - m_javaPathDetector = std::make_shared(); - if (QSysInfo::windowsVersion() != QSysInfo::WV_None) - { - m_javaPathDetector->addDetector(std::make_shared("1.8")); - } - else if (QSysInfo::macVersion() != QSysInfo::MV_None) - { - m_javaPathDetector->addDetector(std::make_shared("1.8")); - } - else - { - m_javaPathDetector->addDetector(std::make_shared("1.8")); - } + m_javaPathDetector = utility::getJavaRuntimePathDetector(); addJavaPathDetection(layout, row); layout->setRowMinimumHeight(row, 20); @@ -350,7 +336,7 @@ void QtProjectWizzardContentPreferences::javaPathDetectionClicked() void QtProjectWizzardContentPreferences::addJavaPathDetection(QGridLayout* layout, int& row) { std::vector detectorNames = m_javaPathDetector->getWorkingDetectorNames(); - if (!detectorNames.size()) + if (detectorNames.empty()) { return; } diff --git a/src/lib_gui/utility/path_detector/CombinedPathDetector.cpp b/src/lib_gui/utility/path_detector/CombinedPathDetector.cpp index 505a9ac9..037a5cc6 100644 --- a/src/lib_gui/utility/path_detector/CombinedPathDetector.cpp +++ b/src/lib_gui/utility/path_detector/CombinedPathDetector.cpp @@ -11,29 +11,27 @@ CombinedPathDetector::~CombinedPathDetector() void CombinedPathDetector::addDetector(std::shared_ptr detector) { - m_detectors[detector->getName()] = detector; + m_detectors.push_back(detector); } std::vector CombinedPathDetector::getWorkingDetectorNames() { std::vector names; - - for (DetectorPair detectorEntry: m_detectors) + for (std::shared_ptr detector: m_detectors) { - if (detectorEntry.second->isWorking()) + if (detector->isWorking()) { - names.push_back(detectorEntry.first); + names.push_back(detector->getName()); } } - return names; } std::vector CombinedPathDetector::getPaths() const { - for (DetectorPair detectorEntry: m_detectors) + for (std::shared_ptr detector: m_detectors) { - std::vector detectedPaths = detectorEntry.second->getPaths(); + std::vector detectedPaths = detector->getPaths(); if (!detectedPaths.empty()) { return detectedPaths; @@ -44,11 +42,12 @@ std::vector CombinedPathDetector::getPaths() const std::vector CombinedPathDetector::getPaths(std::string detectorName) const { - std::vector paths; - DetectorMap::const_iterator it = m_detectors.find(detectorName); - if (it != m_detectors.end()) + for (std::shared_ptr detector: m_detectors) { - paths = it->second->getPaths(); + if (detector->getName() == detectorName) + { + return detector->getPaths(); + } } - return paths; + return std::vector(); } diff --git a/src/lib_gui/utility/path_detector/CombinedPathDetector.h b/src/lib_gui/utility/path_detector/CombinedPathDetector.h index 13df23bf..ca97a521 100644 --- a/src/lib_gui/utility/path_detector/CombinedPathDetector.h +++ b/src/lib_gui/utility/path_detector/CombinedPathDetector.h @@ -22,10 +22,7 @@ public: std::vector getPaths(std::string detectorName) const; private: - typedef std::map> DetectorMap; - typedef std::pair> DetectorPair; - - DetectorMap m_detectors; + std::vector> m_detectors; }; #endif // COMBINED_PATH_DETECTOR_H diff --git a/src/lib_gui/utility/utilityPathDetection.cpp b/src/lib_gui/utility/utilityPathDetection.cpp new file mode 100644 index 00000000..89ab4757 --- /dev/null +++ b/src/lib_gui/utility/utilityPathDetection.cpp @@ -0,0 +1,54 @@ +#include "utility/utilityPathDetection.h" + +#include + +#include "utility/path_detector/java_runtime/JavaPathDetectorLinux.h" +#include "utility/path_detector/java_runtime/JavaPathDetectorMac.h" +#include "utility/path_detector/java_runtime/JavaPathDetectorWindows.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" + +std::shared_ptr utility::getJavaRuntimePathDetector() +{ + std::shared_ptr combinedDetector = std::make_shared(); + if (QSysInfo::windowsVersion() != QSysInfo::WV_None) + { + combinedDetector->addDetector(std::make_shared("1.8")); + } + else if (QSysInfo::macVersion() != QSysInfo::MV_None) + { + combinedDetector->addDetector(std::make_shared("1.8")); + } + else + { + combinedDetector->addDetector(std::make_shared("1.8")); + } + + return combinedDetector; +} + +std::shared_ptr utility::getCxxHeaderPathDetector() +{ + std::shared_ptr combinedDetector = std::make_shared(); + combinedDetector->addDetector(std::make_shared("gcc")); + combinedDetector->addDetector(std::make_shared("clang")); + combinedDetector->addDetector(std::make_shared(14, false)); + combinedDetector->addDetector(std::make_shared(14, true)); + combinedDetector->addDetector(std::make_shared(12, false)); + combinedDetector->addDetector(std::make_shared(12, true)); + combinedDetector->addDetector(std::make_shared(11, false)); + combinedDetector->addDetector(std::make_shared(11, true)); + combinedDetector->addDetector(std::make_shared(9, false)); + combinedDetector->addDetector(std::make_shared(9, true)); + return combinedDetector; +} + +std::shared_ptr utility::getCxxFrameworkPathDetector() +{ + std::shared_ptr combinedDetector = std::make_shared(); + combinedDetector->addDetector(std::make_shared("gcc")); + combinedDetector->addDetector(std::make_shared("clang")); + return combinedDetector; +} diff --git a/src/lib_gui/utility/utilityPathDetection.h b/src/lib_gui/utility/utilityPathDetection.h new file mode 100644 index 00000000..f117719e --- /dev/null +++ b/src/lib_gui/utility/utilityPathDetection.h @@ -0,0 +1,15 @@ +#ifndef UTILITY_PATH_DETECTION_H +#define UTILITY_PATH_DETECTION_H + +#include "utility/path_detector/CombinedPathDetector.h" + +namespace utility +{ + std::shared_ptr getJavaRuntimePathDetector(); + std::shared_ptr getCxxHeaderPathDetector(); + std::shared_ptr getCxxFrameworkPathDetector(); +} + + +#endif // UTILITY_PATH_DETECTION_H +