logic: add auto-detection for JRE System Library

* fixed error columns are not saved to database correctly
* implemented setting JRE System Library paths in app settings
* added detector for JRE System Library that not use Java Runtime specified in AppSettings but detects JRE on its own by reusing the JavaPathDetector.
* added option to use JRE System Library in JavaSourceGroup
This commit is contained in:
malte_langkabel
2017-07-10 18:12:52 +02:00
parent b4166be89b
commit 9bcde198a5
23 changed files with 404 additions and 99 deletions
+9
View File
@@ -239,6 +239,15 @@ add_files(
utility/path_detector/java_runtime/JavaPathDetectorWindows.cpp
utility/path_detector/java_runtime/JavaPathDetectorWindows.h
utility/path_detector/jre_system_library/JreSystemLibraryPathDetector.cpp
utility/path_detector/jre_system_library/JreSystemLibraryPathDetector.h
utility/path_detector/jre_system_library/JreSystemLibraryPathDetectorLinux.cpp
utility/path_detector/jre_system_library/JreSystemLibraryPathDetectorLinux.h
utility/path_detector/jre_system_library/JreSystemLibraryPathDetectorMac.cpp
utility/path_detector/jre_system_library/JreSystemLibraryPathDetectorMac.h
utility/path_detector/jre_system_library/JreSystemLibraryPathDetectorWindows.cpp
utility/path_detector/jre_system_library/JreSystemLibraryPathDetectorWindows.h
utility/path_detector/maven_executable/MavenPathDetectorUnix.cpp
utility/path_detector/maven_executable/MavenPathDetectorUnix.h
utility/path_detector/maven_executable/MavenPathDetectorWindows.cpp
@@ -1,9 +1,10 @@
#include "qt/window/project_wizzard/QtProjectWizzardContentPaths.h"
#include <QCheckBox>
#include <QComboBox>
#include <QLabel>
#include <QMessageBox>
#include <QVBoxLayout>
#include <QComboBox>
#include "qt/element/QtDirectoryListBox.h"
#include "qt/window/QtSelectPathsDialog.h"
@@ -221,7 +222,7 @@ QtProjectWizzardContentPathsCDBHeader::QtProjectWizzardContentPathsCDBHeader(
);
}
void QtProjectWizzardContentPathsCDBHeader::populate( QGridLayout* layout, int& row)
void QtProjectWizzardContentPathsCDBHeader::populate(QGridLayout* layout, int& row)
{
QtProjectWizzardContentPaths::populate(layout, row);
@@ -479,12 +480,26 @@ QtProjectWizzardContentPathsClassJava::QtProjectWizzardContentPathsClassJava(
);
}
void QtProjectWizzardContentPathsClassJava::populate(QGridLayout* layout, int& row)
{
QtProjectWizzardContentPaths::populate(layout, row);
QLabel* label = createFormLabel("JRE System Library");
layout->addWidget(label, row, QtProjectWizzardWindow::FRONT_COL, Qt::AlignTop);
m_useJreSystemLibraryCheckBox = new QCheckBox("Use JRE System Library", this);
layout->addWidget(m_useJreSystemLibraryCheckBox, row, QtProjectWizzardWindow::BACK_COL);
row++;
}
void QtProjectWizzardContentPathsClassJava::load()
{
std::shared_ptr<SourceGroupSettingsJava> javaSettings = std::dynamic_pointer_cast<SourceGroupSettingsJava>(m_settings);
if (javaSettings)
{
m_list->setList(javaSettings->getClasspaths());
m_list->setList(javaSettings->getClasspath());
m_useJreSystemLibraryCheckBox->setChecked(javaSettings->getUseJreSystemLibrary());
}
}
@@ -493,6 +508,7 @@ void QtProjectWizzardContentPathsClassJava::save()
std::shared_ptr<SourceGroupSettingsJava> javaSettings = std::dynamic_pointer_cast<SourceGroupSettingsJava>(m_settings);
if (javaSettings)
{
javaSettings->setClasspaths(m_list->getList());
javaSettings->setClasspath(m_list->getList());
javaSettings->setUseJreSystemLibrary(m_useJreSystemLibraryCheckBox->isChecked());
}
}
@@ -4,9 +4,10 @@
#include "qt/window/project_wizzard/QtProjectWizzardContent.h"
#include "utility/path_detector/CombinedPathDetector.h"
class QtDirectoryListBox;
class QPushButton;
class QCheckBox;
class QComboBox;
class QPushButton;
class QtDirectoryListBox;
class SourceGroupSettings;
class QtProjectWizzardContentPaths
@@ -153,8 +154,12 @@ public:
QtProjectWizzardContentPathsClassJava(std::shared_ptr<SourceGroupSettings> settings, QtProjectWizzardWindow* window);
// QtProjectWizzardContent implementation
virtual void populate(QGridLayout* layout, int& row);
virtual void load() override;
virtual void save() override;
private:
QCheckBox* m_useJreSystemLibraryCheckBox;
};
#endif // QT_PROJECT_WIZZARD_CONTENT_PATHS_H
@@ -155,90 +155,112 @@ void QtProjectWizzardContentPreferences::populate(QGridLayout* layout, int& row)
// Java
addTitle("JAVA", layout, row);
// jvm library path
m_javaPath = new QtLocationPicker(this);
if (QSysInfo::windowsVersion() != QSysInfo::WV_None)
{
m_javaPath->setFileFilter("JVM Library (jvm.dll)");
m_javaPath->setPlaceholderText("<jre_path>/bin/client/jvm.dll");
// jvm library path
m_javaPath = new QtLocationPicker(this);
if (QSysInfo::windowsVersion() != QSysInfo::WV_None)
{
m_javaPath->setFileFilter("JVM Library (jvm.dll)");
m_javaPath->setPlaceholderText("<jre_path>/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("<jre_path>/Contents/Home/jre/lib/jli/libjli.dylib");
}
else
{
m_javaPath->setFileFilter("JVM Library (libjvm.so)");
m_javaPath->setPlaceholderText("<jre_path>/bin/<arch>/server/libjvm.so");
}
addLabelAndWidget("Java Path", m_javaPath, layout, row);
std::string javaVersionString = "";
switch (utility::getApplicationArchitectureType())
{
case APPLICATION_ARCHITECTURE_X86_32:
javaVersionString = "32 Bit ";
break;
case APPLICATION_ARCHITECTURE_X86_64:
javaVersionString = "64 Bit ";
break;
default:
break;
}
javaVersionString += "Java 8";
addHelpButton((
"<p>Only required for indexing Java projects.</p>"
"<p>Provide the location of the jvm library inside the installation of your " + javaVersionString +
" runtime environment (for information on how to set this take a look at "
"<a href=\"https://sourcetrail.com/documentation/#FindingJavaRuntimeLibraryLocation\">"
"Finding Java Runtime Library Location</a> or use the auto detection below)</p>").c_str(),
layout, row
);
row++;
m_javaPathDetector = utility::getJavaRuntimePathDetector();
addJavaPathDetection(layout, row);
}
else if (QSysInfo::macVersion() != QSysInfo::MV_None)
{
m_javaPath->setFileFilter("JLI or JVM Library (libjli.dylib libjvm.dylib)");
m_javaPath->setPlaceholderText("<jre_path>/Contents/Home/jre/lib/jli/libjli.dylib");
// jvm max memory
m_jvmMaximumMemory = addLineEdit(
"JVM Maximum Memory",
"<p>Specify the maximum amount of memory that will be allocated by the indexer's JVM (values are in MB). Set "
"this value to -1 to use the JVM's default setting.</p>"
"<p><b>Warning</b>: You may experience a sudden slowdown during the course of indexing when setting this value "
"too low. This may also happen when using the JVM's default setting.</p>",
layout, row
);
layout->setRowMinimumHeight(row - 1, 30);
}
else
{
m_javaPath->setFileFilter("JVM Library (libjvm.so)");
m_javaPath->setPlaceholderText("<jre_path>/bin/<arch>/server/libjvm.so");
// JRE System Library
const QString title = "JRE System Library";
QLabel* label = createFormLabel(title);
layout->addWidget(label, row, QtProjectWizzardWindow::FRONT_COL, Qt::AlignTop);
addHelpButton(
"<p>Only required for indexing Java projects.</p>"
"<p>Add the jar files of your JRE System Library. These jars can be found inside your JRE install directory.</p>", layout, row);
m_jreSystemLibraryPaths = new QtDirectoryListBox(this, title);
layout->addWidget(m_jreSystemLibraryPaths, row, QtProjectWizzardWindow::BACK_COL);
row++;
m_jreSystemLibraryPathsDetector = utility::getJreSystemLibraryPathsDetector();
addJreSystemLibraryPathsDetection(layout, row);
}
addLabelAndWidget("Java Path", m_javaPath, layout, row);
std::string javaVersionString = "";
switch (utility::getApplicationArchitectureType())
{
case APPLICATION_ARCHITECTURE_X86_32:
javaVersionString = "32 Bit ";
break;
case APPLICATION_ARCHITECTURE_X86_64:
javaVersionString = "64 Bit ";
break;
default:
break;
// maven path
m_mavenPath = new QtLocationPicker(this);
if (QSysInfo::windowsVersion() != QSysInfo::WV_None)
{
m_mavenPath->setFileFilter("Maven command (mvn.cmd)");
m_mavenPath->setPlaceholderText("<maven_path>/bin/mvn.cmd");
}
else
{
m_mavenPath->setFileFilter("Maven command (mvn)");
m_mavenPath->setPlaceholderText("<binarypath>/mvn");
}
addLabelAndWidget("Maven Path", m_mavenPath, layout, row);
addHelpButton(
"<p>Only required for indexing projects using Maven.</p>"
"<p>Provide the location of your installed Maven executable. You can also use the auto detection below.</p>"
, layout, row
);
row++;
m_mavenPathDetector = utility::getMavenExecutablePathDetector();
addMavenPathDetection(layout, row);
}
javaVersionString += "Java 8";
addHelpButton((
"<p>Only required for indexing Java projects.</p>"
"<p>Provide the location of the jvm library inside the installation of your " + javaVersionString +
" runtime environment (for information on how to set this take a look at "
"<a href=\"https://sourcetrail.com/documentation/#FindingJavaRuntimeLibraryLocation\">"
"Finding Java Runtime Library Location</a> or use the auto detection below)</p>").c_str(),
layout, row
);
row++;
m_javaPathDetector = utility::getJavaRuntimePathDetector();
addJavaPathDetection(layout, row);
// jvm max memory
m_jvmMaximumMemory = addLineEdit(
"JVM Maximum Memory",
"<p>Specify the maximum amount of memory that will be allocated by the indexer's JVM (values are in MB). Set "
"this value to -1 to use the JVM's default setting.</p>"
"<p><b>Warning</b>: You may experience a sudden slowdown during the course of indexing when setting this value "
"too low. This may also happen when using the JVM's default setting.</p>",
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("<maven_path>/bin/mvn.cmd");
}
else
{
m_mavenPath->setFileFilter("Maven command (mvn)");
m_mavenPath->setPlaceholderText("<binarypath>/mvn");
}
addLabelAndWidget("Maven Path", m_mavenPath, layout, row);
addHelpButton(
"<p>Only required for indexing projects using Maven.</p>"
"<p>Provide the location of your installed Maven executable. You can also use the auto detection below.</p>"
, layout, row
);
row++;
m_mavenPathDetector = utility::getMavenExecutablePathDetector();
addMavenPathDetection(layout, row);
addGap(layout, row);
@@ -290,6 +312,8 @@ void QtProjectWizzardContentPreferences::load()
m_jvmMaximumMemory->setText(QString::number(appSettings->getJavaMaximumMemory()));
m_jreSystemLibraryPaths->setList(appSettings->getJreSystemLibraryPaths());
if (m_mavenPath)
{
m_mavenPath->setText(QString::fromStdString(appSettings->getMavenPath().str()));
@@ -332,6 +356,8 @@ void QtProjectWizzardContentPreferences::save()
appSettings->setJavaPath(m_javaPath->getText().toStdString());
}
appSettings->setJreSystemLibraryPaths(m_jreSystemLibraryPaths->getList());
int jvmMaximumMemory = m_jvmMaximumMemory->text().toInt();
if (jvmMaximumMemory) appSettings->setJavaMaximumMemory(jvmMaximumMemory);
@@ -363,6 +389,13 @@ void QtProjectWizzardContentPreferences::javaPathDetectionClicked()
}
}
void QtProjectWizzardContentPreferences::jreSystemLibraryPathsDetectionClicked()
{
std::vector<FilePath> paths = m_jreSystemLibraryPathsDetector->getPaths(m_jreSystemLibraryPathsDetectorBox->currentText().toStdString());
std::vector<FilePath> oldPaths = m_jreSystemLibraryPaths->getList();
m_jreSystemLibraryPaths->setList(utility::unique(utility::concat(oldPaths, paths)));
}
void QtProjectWizzardContentPreferences::mavenPathDetectionClicked()
{
std::vector<FilePath> paths = m_mavenPathDetector->getPaths(m_mavenPathDetectorBox->currentText().toStdString());
@@ -424,6 +457,40 @@ void QtProjectWizzardContentPreferences::addJavaPathDetection(QGridLayout* layou
row++;
}
void QtProjectWizzardContentPreferences::addJreSystemLibraryPathsDetection(QGridLayout* layout, int& row)
{
const std::vector<std::string> detectorNames = m_jreSystemLibraryPathsDetector->getWorkingDetectorNames();
if (detectorNames.empty())
{
return;
}
QLabel* label = new QLabel("Auto detection from:");
m_jreSystemLibraryPathsDetectorBox = new QComboBox();
for (const std::string& detectorName: detectorNames)
{
m_jreSystemLibraryPathsDetectorBox->addItem(detectorName.c_str());
}
QPushButton* button = new QPushButton("detect");
button->setObjectName("windowButton");
connect(button, SIGNAL(clicked()), this, SLOT(jreSystemLibraryPathsDetectionClicked()));
QHBoxLayout* hlayout = new QHBoxLayout();
hlayout->setContentsMargins(0, 0, 0, 0);
hlayout->addWidget(label);
hlayout->addWidget(m_jreSystemLibraryPathsDetectorBox);
hlayout->addWidget(button);
QWidget* detectionWidget = new QWidget();
detectionWidget->setLayout(hlayout);
layout->addWidget(detectionWidget, row, QtProjectWizzardWindow::BACK_COL, Qt::AlignLeft | Qt::AlignTop);
row++;
}
void QtProjectWizzardContentPreferences::addMavenPathDetection(QGridLayout* layout, int& row)
{
std::vector<std::string> detectorNames = m_mavenPathDetector->getWorkingDetectorNames();
@@ -8,6 +8,7 @@
#include "qt/element/QtFontPicker.h"
#include "qt/element/QtLocationPicker.h"
#include "qt/element/QtDirectoryListBox.h"
#include "qt/window/project_wizzard/QtProjectWizzardContent.h"
#include "utility/path_detector/CombinedPathDetector.h"
@@ -30,12 +31,14 @@ public:
private slots:
void colorSchemeChanged(int index);
void javaPathDetectionClicked();
void jreSystemLibraryPathsDetectionClicked();
void mavenPathDetectionClicked();
void loggingEnabledChanged();
void indexerThreadsChanges(int index);
private:
void addJavaPathDetection(QGridLayout* layout, int& row);
void addJreSystemLibraryPathsDetection(QGridLayout* layout, int& row);
void addMavenPathDetection(QGridLayout* layout, int& row);
void addTitle(QString title, QGridLayout* layout, int& row);
@@ -72,13 +75,16 @@ private:
QCheckBox* m_multiProcessIndexing;
std::shared_ptr<CombinedPathDetector> m_javaPathDetector;
std::shared_ptr<CombinedPathDetector> m_jreSystemLibraryPathsDetector;
std::shared_ptr<CombinedPathDetector> m_mavenPathDetector;
QComboBox* m_javaPathDetectorBox;
QComboBox* m_jreSystemLibraryPathsDetectorBox;
QComboBox* m_mavenPathDetectorBox;
QtLocationPicker* m_javaPath;
QtLocationPicker* m_mavenPath;
QtDirectoryListBox* m_jreSystemLibraryPaths;
QLineEdit* m_jvmMaximumMemory;
QtLocationPicker* m_mavenPath;
};
#endif // QT_PROJECT_WIZZARD_CONTENT_PREFERENCES_H
@@ -0,0 +1,35 @@
#include "utility/path_detector/jre_system_library/JreSystemLibraryPathDetector.h"
#include "utility/path_detector/java_runtime/JavaPathDetector.h"
#include "settings/ApplicationSettings.h"
#include "utility/file/FilePath.h"
#include "utility/file/FileSystem.h"
JreSystemLibraryPathDetector::JreSystemLibraryPathDetector(std::shared_ptr<JavaPathDetector> javaPathDetector)
: PathDetector("JRE System Library")
, m_javaPathDetector(javaPathDetector)
{
}
JreSystemLibraryPathDetector::~JreSystemLibraryPathDetector()
{
}
std::vector<FilePath> JreSystemLibraryPathDetector::getPaths() const
{
std::vector<FilePath> paths;
for (const FilePath& jrePath: m_javaPathDetector->getPaths())
{
const FilePath javaRoot = jrePath.parentDirectory().parentDirectory().parentDirectory();
for (const FilePath& jarPath : FileSystem::getFilePathsFromDirectory(javaRoot.concat(FilePath("lib")), {".jar"}))
{
paths.push_back(jarPath);
}
if (!paths.empty())
{
break;
}
}
return paths;
}
@@ -0,0 +1,22 @@
#ifndef JRE_SYSTEM_LIBRARY_PATH_DETECTOR_H
#define JRE_SYSTEM_LIBRARY_PATH_DETECTOR_H
#include <memory>
#include "utility/path_detector/PathDetector.h"
class JavaPathDetector;
class JreSystemLibraryPathDetector: public PathDetector
{
public:
JreSystemLibraryPathDetector(std::shared_ptr<JavaPathDetector> javaPathDetector);
virtual ~JreSystemLibraryPathDetector();
virtual std::vector<FilePath> getPaths() const;
private:
std::shared_ptr<JavaPathDetector> m_javaPathDetector;
};
#endif // JRE_SYSTEM_LIBRARY_PATH_DETECTOR_H
@@ -0,0 +1,12 @@
#include "utility/path_detector/jre_system_library/JreSystemLibraryPathDetectorLinux.h"
#include "utility/path_detector/java_runtime/JavaPathDetectorLinux.h"
JreSystemLibraryPathDetectorLinux::JreSystemLibraryPathDetectorLinux(const std::string javaVersion)
: JreSystemLibraryPathDetector(std::make_shared<JavaPathDetectorLinux>(javaVersion))
{
}
JreSystemLibraryPathDetectorLinux::~JreSystemLibraryPathDetectorLinux()
{
}
@@ -0,0 +1,13 @@
#ifndef JRE_SYSTEM_LIBRARY_PATH_DETECTOR_LINUX_H
#define JRE_SYSTEM_LIBRARY_PATH_DETECTOR_LINUX_H
#include "utility/path_detector/jre_system_library/JreSystemLibraryPathDetector.h"
class JreSystemLibraryPathDetectorLinux: public JreSystemLibraryPathDetector
{
public:
JreSystemLibraryPathDetectorLinux(const std::string javaVersion);
virtual ~JreSystemLibraryPathDetectorLinux();
};
#endif // JRE_SYSTEM_LIBRARY_PATH_DETECTOR_LINUX_H
@@ -0,0 +1,12 @@
#include "utility/path_detector/jre_system_library/JreSystemLibraryPathDetectorMac.h"
#include "utility/path_detector/java_runtime/JavaPathDetectorMac.h"
JreSystemLibraryPathDetectorMac::JreSystemLibraryPathDetectorMac(const std::string javaVersion)
: JreSystemLibraryPathDetector(std::make_shared<JavaPathDetectorMac>(javaVersion))
{
}
JreSystemLibraryPathDetectorMac::~JreSystemLibraryPathDetectorMac()
{
}
@@ -0,0 +1,13 @@
#ifndef JRE_SYSTEM_LIBRARY_PATH_DETECTOR_MAC_H
#define JRE_SYSTEM_LIBRARY_PATH_DETECTOR_MAC_H
#include "utility/path_detector/jre_system_library/JreSystemLibraryPathDetector.h"
class JreSystemLibraryPathDetectorMac: public JreSystemLibraryPathDetector
{
public:
JreSystemLibraryPathDetectorMac(const std::string javaVersion);
virtual ~JreSystemLibraryPathDetectorMac();
};
#endif // JRE_SYSTEM_LIBRARY_PATH_DETECTOR_MAC_H
@@ -0,0 +1,12 @@
#include "utility/path_detector/jre_system_library/JreSystemLibraryPathDetectorWindows.h"
#include "utility/path_detector/java_runtime/JavaPathDetectorWindows.h"
JreSystemLibraryPathDetectorWindows::JreSystemLibraryPathDetectorWindows(const std::string javaVersion)
: JreSystemLibraryPathDetector(std::make_shared<JavaPathDetectorWindows>(javaVersion))
{
}
JreSystemLibraryPathDetectorWindows::~JreSystemLibraryPathDetectorWindows()
{
}
@@ -0,0 +1,13 @@
#ifndef JRE_SYSTEM_LIBRARY_PATH_DETECTOR_WINDOWS_H
#define JRE_SYSTEM_LIBRARY_PATH_DETECTOR_WINDOWS_H
#include "utility/path_detector/jre_system_library/JreSystemLibraryPathDetector.h"
class JreSystemLibraryPathDetectorWindows: public JreSystemLibraryPathDetector
{
public:
JreSystemLibraryPathDetectorWindows(const std::string javaVersion);
virtual ~JreSystemLibraryPathDetectorWindows();
};
#endif // JRE_SYSTEM_LIBRARY_PATH_DETECTOR_WINDOWS_H
@@ -6,6 +6,10 @@
#include "utility/path_detector/java_runtime/JavaPathDetectorMac.h"
#include "utility/path_detector/java_runtime/JavaPathDetectorWindows.h"
#include "utility/path_detector/jre_system_library/JreSystemLibraryPathDetectorLinux.h"
#include "utility/path_detector/jre_system_library/JreSystemLibraryPathDetectorMac.h"
#include "utility/path_detector/jre_system_library/JreSystemLibraryPathDetectorWindows.h"
#include "utility/path_detector/maven_executable/MavenPathDetectorUnix.h"
#include "utility/path_detector/maven_executable/MavenPathDetectorWindows.h"
@@ -32,6 +36,25 @@ std::shared_ptr<CombinedPathDetector> utility::getJavaRuntimePathDetector()
return combinedDetector;
}
std::shared_ptr<CombinedPathDetector> utility::getJreSystemLibraryPathsDetector()
{
std::shared_ptr<CombinedPathDetector> combinedDetector = std::make_shared<CombinedPathDetector>();
if (QSysInfo::windowsVersion() != QSysInfo::WV_None)
{
combinedDetector->addDetector(std::make_shared<JreSystemLibraryPathDetectorWindows>("1.8"));
}
else if (QSysInfo::macVersion() != QSysInfo::MV_None)
{
combinedDetector->addDetector(std::make_shared<JreSystemLibraryPathDetectorMac>("1.8"));
}
else
{
combinedDetector->addDetector(std::make_shared<JreSystemLibraryPathDetectorLinux>("1.8"));
}
return combinedDetector;
}
std::shared_ptr<CombinedPathDetector> utility::getMavenExecutablePathDetector()
{
std::shared_ptr<CombinedPathDetector> combinedDetector = std::make_shared<CombinedPathDetector>();
@@ -6,6 +6,7 @@
namespace utility
{
std::shared_ptr<CombinedPathDetector> getJavaRuntimePathDetector();
std::shared_ptr<CombinedPathDetector> getJreSystemLibraryPathsDetector();
std::shared_ptr<CombinedPathDetector> getMavenExecutablePathDetector();
std::shared_ptr<CombinedPathDetector> getCxxVsHeaderPathDetector();