ui: autodetect java on windows

* implemented a more generic approach to detecting filepaths
* reimplemented standard header detection using this approach
* added auto detection of JVM dynamic library on windows
* fixed java tests that were broken when updating the java_indexer project before this commit.
This commit is contained in:
malte_langkabel
2016-08-24 15:21:04 +02:00
parent 01f740276b
commit 8dfc1ea9d9
30 changed files with 508 additions and 370 deletions
@@ -10,7 +10,9 @@
#include "settings/JavaProjectSettings.h"
#include "utility/file/FileManager.h"
#include "utility/file/FileSystem.h"
#include "utility/headerSearch/StandardHeaderDetection.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"
QtProjectWizzardContentPaths::QtProjectWizzardContentPaths(std::shared_ptr<ProjectSettings> settings, QtProjectWizzardWindow* window)
@@ -45,9 +47,9 @@ void QtProjectWizzardContentPaths::populateWindow(QGridLayout* layout, int& row)
addFilesButton(m_showFilesString, layout, row);
}
if (m_detectionString.size() > 0)
if (m_pathDetector)
{
addDetection(m_detectionString, layout, row);
addDetection(layout, row);
}
row++;
@@ -76,9 +78,9 @@ void QtProjectWizzardContentPaths::populateForm(QGridLayout* layout, int& row)
row++;
}
if (m_detectionString.size() > 0)
if (m_pathDetector)
{
addDetection(m_detectionString, layout, row);
addDetection(layout, row);
row++;
}
}
@@ -140,10 +142,9 @@ void QtProjectWizzardContentPaths::setHelpString(const QString& help)
m_helpString = help;
}
void QtProjectWizzardContentPaths::addDetection(QString name, QGridLayout* layout, int row)
void QtProjectWizzardContentPaths::addDetection(QGridLayout* layout, int row)
{
StandardHeaderDetection detection;
std::vector<std::string> detectorNames = detection.getWorkingDetectorNames();
std::vector<std::string> detectorNames = m_pathDetector->getWorkingDetectorNames();
if (!detectorNames.size())
{
return;
@@ -175,18 +176,7 @@ void QtProjectWizzardContentPaths::addDetection(QString name, QGridLayout* layou
void QtProjectWizzardContentPaths::detectionClicked()
{
StandardHeaderDetection detection;
std::vector<FilePath> paths;
if (m_detectionString == "headers")
{
paths = detection.getStandardHeaderPaths(m_detectorBox->currentText().toStdString());
}
else if (m_detectionString == "frameworks")
{
paths = detection.getStandardFrameworkPaths(m_detectorBox->currentText().toStdString());
}
std::vector<FilePath> paths = m_pathDetector->getPaths(m_detectorBox->currentText().toStdString());
std::vector<FilePath> oldPaths = m_list->getList();
m_list->setList(utility::unique(utility::concat(oldPaths, paths)));
}
@@ -382,7 +372,17 @@ QtProjectWizzardContentPathsHeaderSearchGlobal::QtProjectWizzardContentPathsHead
"Include Paths defined here will be used for all projects."
);
m_detectionString = "headers";
m_pathDetector = std::make_shared<CombinedPathDetector>();
m_pathDetector->addDetector(std::make_shared<CxxHeaderPathDetector>("gcc"));
m_pathDetector->addDetector(std::make_shared<CxxHeaderPathDetector>("clang"));
m_pathDetector->addDetector(std::make_shared<CxxVsHeaderPathDetector>(9, false));
m_pathDetector->addDetector(std::make_shared<CxxVsHeaderPathDetector>(9, true));
m_pathDetector->addDetector(std::make_shared<CxxVsHeaderPathDetector>(11, false));
m_pathDetector->addDetector(std::make_shared<CxxVsHeaderPathDetector>(11, true));
m_pathDetector->addDetector(std::make_shared<CxxVsHeaderPathDetector>(12, false));
m_pathDetector->addDetector(std::make_shared<CxxVsHeaderPathDetector>(12, true));
m_pathDetector->addDetector(std::make_shared<CxxVsHeaderPathDetector>(14, false));
m_pathDetector->addDetector(std::make_shared<CxxVsHeaderPathDetector>(14, true));
}
void QtProjectWizzardContentPathsHeaderSearchGlobal::load()
@@ -448,7 +448,9 @@ QtProjectWizzardContentPathsFrameworkSearchGlobal::QtProjectWizzardContentPathsF
"Framework Search Paths defined here will be used for all projects."
);
m_detectionString = "frameworks";
m_pathDetector = std::make_shared<CombinedPathDetector>();
m_pathDetector->addDetector(std::make_shared<CxxFrameworkPathDetector>("gcc"));
m_pathDetector->addDetector(std::make_shared<CxxFrameworkPathDetector>("clang"));
}
void QtProjectWizzardContentPathsFrameworkSearchGlobal::load()
@@ -5,6 +5,7 @@
#include <QPushButton>
#include "qt/window/project_wizzard/QtProjectWizzardContent.h"
#include "utility/path_detector/CombinedPathDetector.h"
class QtDirectoryListBox;
@@ -33,12 +34,12 @@ protected:
void setDescriptionString(const QString& description);
void setHelpString(const QString& help);
void addDetection(QString name, QGridLayout* layout, int row);
void addDetection(QGridLayout* layout, int row);
QtDirectoryListBox* m_list;
QString m_showFilesString;
QString m_detectionString;
std::shared_ptr<CombinedPathDetector> m_pathDetector;
private slots:
void detectionClicked();
@@ -1,8 +1,9 @@
#include "qt/window/project_wizzard/QtProjectWizzardContentPreferences.h"
#include "settings/ApplicationSettings.h"
#include "utility/messaging/type/MessageSwitchColorScheme.h"
#include "utility/file/FileSystem.h"
#include "utility/messaging/type/MessageSwitchColorScheme.h"
#include "utility/path_detector/java_runtime/JavaPathDetectorWindows.h"
#include "utility/ResourcePaths.h"
QtProjectWizzardContentPreferences::QtProjectWizzardContentPreferences(
@@ -143,17 +144,25 @@ void QtProjectWizzardContentPreferences::populateForm(QGridLayout* layout, int&
// java path
m_javaPath = new QtLocationPicker(this);
m_javaPath->setPickDirectory(true);
m_javaPath->setPlaceholderText("<jdk_root>");
m_javaPath->setPlaceholderText("<jre_8_root>/bin/client");
layout->addWidget(createFormLabel("Java Path"), row, QtProjectWizzardWindow::FRONT_COL, Qt::AlignRight);
layout->addWidget(m_javaPath, row, QtProjectWizzardWindow::BACK_COL);
addHelpButton(
"Location of your java installation so that dynamic libraries of JVM can be found."
"Location of the folder that contains the dynamic library for your jre virtual machine."
, layout, row
);
row++;
if (QSysInfo::windowsVersion() != QSysInfo::WV_None)
{
m_javaPathDetector = std::make_shared<CombinedPathDetector>();
m_javaPathDetector->addDetector(std::make_shared<JavaPathDetectorWindows>("1.8"));
addJavaPathDetection(layout, row);
row++;
}
layout->setRowMinimumHeight(row++, 20);
// C/C++
@@ -228,3 +237,45 @@ void QtProjectWizzardContentPreferences::colorSchemeChanged(int index)
{
MessageSwitchColorScheme(m_colorSchemePaths[index]).dispatch();
}
void QtProjectWizzardContentPreferences::javaPathDetectionClicked()
{
std::vector<FilePath> paths = m_javaPathDetector->getPaths(m_javaPathDetectorBox->currentText().toStdString());
if (!paths.empty())
{
m_javaPath->setText(paths.front().str().c_str());
}
}
void QtProjectWizzardContentPreferences::addJavaPathDetection(QGridLayout* layout, int row)
{
std::vector<std::string> detectorNames = m_javaPathDetector->getWorkingDetectorNames();
if (!detectorNames.size())
{
return;
}
QLabel* label = new QLabel("Auto detection from:");
m_javaPathDetectorBox = new QComboBox();
for (const std::string& detectorName: detectorNames)
{
m_javaPathDetectorBox->addItem(detectorName.c_str());
}
QPushButton* button = new QPushButton("detect");
button->setObjectName("windowButton");
connect(button, SIGNAL(clicked()), this, SLOT(javaPathDetectionClicked()));
QHBoxLayout* hlayout = new QHBoxLayout();
hlayout->addWidget(label);
hlayout->addWidget(m_javaPathDetectorBox);
hlayout->addWidget(button);
QWidget* detectionWidget = new QWidget();
detectionWidget->setLayout(hlayout);
layout->addWidget(detectionWidget, row, QtProjectWizzardWindow::BACK_COL, Qt::AlignLeft | Qt::AlignTop);
}
@@ -7,6 +7,7 @@
#include "qt/element/QtLocationPicker.h"
#include "qt/window/project_wizzard/QtProjectWizzardContent.h"
#include "utility/path_detector/CombinedPathDetector.h"
class QtProjectWizzardContentPreferences
: public QtProjectWizzardContent
@@ -27,8 +28,11 @@ public:
private slots:
void colorSchemeChanged(int index);
void javaPathDetectionClicked();
private:
void addJavaPathDetection(QGridLayout* layout, int row);
QLineEdit* m_fontFace;
QComboBox* m_fontSize;
QComboBox* m_tabWidth;
@@ -41,6 +45,8 @@ private:
QComboBox* m_threads;
QCheckBox* m_fatalErrors;
std::shared_ptr<CombinedPathDetector> m_javaPathDetector;
QComboBox* m_javaPathDetectorBox;
QtLocationPicker* m_javaPath;
};