logic: discard non-existing paths in path detectors (#930)

This prevents the automatic path detection from adding paths to the project settings or application settings that cause the "you have missing paths" dialog to pop up when saving the settings.
This commit is contained in:
Malte Langkabel
2020-02-24 19:59:21 +01:00
committed by GitHub
parent 4dd0cb7590
commit ad464fc1b1
27 changed files with 133 additions and 101 deletions
@@ -82,7 +82,7 @@ bool applicationSettingsContainVisualStudioHeaderSearchPaths()
utility::getCxxVsHeaderPathDetector();
for (const std::string& detectorName: headerPathDetector->getWorkingDetectorNames())
{
for (const FilePath& path: headerPathDetector->getPaths(detectorName))
for (const FilePath& path: headerPathDetector->getPathsForDetector(detectorName))
{
utility::append(expandedPaths, path.expandEnvironmentVariables());
}
@@ -651,7 +651,7 @@ void QtProjectWizardContentPreferences::colorSchemeChanged(int index)
void QtProjectWizardContentPreferences::javaPathDetectionClicked()
{
std::vector<FilePath> paths = m_javaPathDetector->getPaths(
std::vector<FilePath> paths = m_javaPathDetector->getPathsForDetector(
m_javaPathDetectorBox->currentText().toStdString());
if (!paths.empty())
{
@@ -661,7 +661,7 @@ void QtProjectWizardContentPreferences::javaPathDetectionClicked()
void QtProjectWizardContentPreferences::jreSystemLibraryPathsDetectionClicked()
{
std::vector<FilePath> paths = m_jreSystemLibraryPathsDetector->getPaths(
std::vector<FilePath> paths = m_jreSystemLibraryPathsDetector->getPathsForDetector(
m_jreSystemLibraryPathsDetectorBox->currentText().toStdString());
std::vector<FilePath> oldPaths = m_jreSystemLibraryPaths->getPathsAsAbsolute();
m_jreSystemLibraryPaths->setPaths(utility::unique(utility::concat(oldPaths, paths)));
@@ -669,7 +669,7 @@ void QtProjectWizardContentPreferences::jreSystemLibraryPathsDetectionClicked()
void QtProjectWizardContentPreferences::mavenPathDetectionClicked()
{
std::vector<FilePath> paths = m_mavenPathDetector->getPaths(
std::vector<FilePath> paths = m_mavenPathDetector->getPathsForDetector(
m_mavenPathDetectorBox->currentText().toStdString());
if (!paths.empty())
{
@@ -166,7 +166,8 @@ void QtProjectWizardContentPaths::addDetection(QGridLayout* layout, int row)
void QtProjectWizardContentPaths::detectionClicked()
{
std::vector<FilePath> paths = m_pathDetector->getPaths(m_detectorBox->currentText().toStdString());
std::vector<FilePath> paths = m_pathDetector->getPathsForDetector(
m_detectorBox->currentText().toStdString());
std::vector<FilePath> oldPaths = m_list->getPathsAsDisplayed();
paths = utility::unique(utility::concat(oldPaths, paths));
@@ -22,7 +22,19 @@ std::vector<std::string> CombinedPathDetector::getWorkingDetectorNames()
return names;
}
std::vector<FilePath> CombinedPathDetector::getPaths() const
std::vector<FilePath> CombinedPathDetector::getPathsForDetector(const std::string& detectorName) const
{
for (const std::shared_ptr<PathDetector>& detector: m_detectors)
{
if (detector->getName() == detectorName)
{
return detector->getPaths();
}
}
return std::vector<FilePath>();
}
std::vector<FilePath> CombinedPathDetector::doGetPaths() const
{
for (const std::shared_ptr<PathDetector>& detector: m_detectors)
{
@@ -34,15 +46,3 @@ std::vector<FilePath> CombinedPathDetector::getPaths() const
}
return std::vector<FilePath>();
}
std::vector<FilePath> CombinedPathDetector::getPaths(const std::string& detectorName) const
{
for (const std::shared_ptr<PathDetector>& detector: m_detectors)
{
if (detector->getName() == detectorName)
{
return detector->getPaths();
}
}
return std::vector<FilePath>();
}
@@ -17,10 +17,11 @@ public:
std::vector<std::string> getWorkingDetectorNames();
std::vector<FilePath> getPaths() const override;
std::vector<FilePath> getPaths(const std::string& detectorName) const;
std::vector<FilePath> getPathsForDetector(const std::string& detectorName) const;
private:
std::vector<FilePath> doGetPaths() const override;
std::vector<std::shared_ptr<PathDetector>> m_detectors;
};
@@ -9,6 +9,19 @@ std::string PathDetector::getName() const
return m_name;
}
std::vector<FilePath> PathDetector::getPaths() const
{
std::vector<FilePath> paths;
for (const FilePath& path: doGetPaths())
{
if (path.exists())
{
paths.push_back(path);
}
}
return paths;
}
bool PathDetector::isWorking() const
{
return (!getPaths().empty());
@@ -13,11 +13,14 @@ public:
virtual ~PathDetector() = default;
std::string getName() const;
std::vector<FilePath> getPaths() const;
bool isWorking() const;
virtual std::vector<FilePath> getPaths() const = 0;
protected:
const std::string m_name;
private:
virtual std::vector<FilePath> doGetPaths() const = 0;
};
#endif // PATH_DETECTOR_BASE_H
@@ -9,7 +9,7 @@ CxxFrameworkPathDetector::CxxFrameworkPathDetector(const std::string& compilerNa
{
}
std::vector<FilePath> CxxFrameworkPathDetector::getPaths() const
std::vector<FilePath> CxxFrameworkPathDetector::doGetPaths() const
{
std::vector<std::string> paths = utility::getCxxHeaderPaths(m_compilerName);
std::vector<FilePath> frameworkPaths;
@@ -7,9 +7,10 @@ class CxxFrameworkPathDetector: public PathDetector
{
public:
CxxFrameworkPathDetector(const std::string& compilerName);
std::vector<FilePath> getPaths() const override;
private:
std::vector<FilePath> doGetPaths() const override;
const std::string m_compilerName;
};
@@ -9,7 +9,7 @@ CxxHeaderPathDetector::CxxHeaderPathDetector(const std::string& compilerName)
{
}
std::vector<FilePath> CxxHeaderPathDetector::getPaths() const
std::vector<FilePath> CxxHeaderPathDetector::doGetPaths() const
{
std::vector<std::string> paths = utility::getCxxHeaderPaths(m_compilerName);
std::vector<FilePath> headerSearchPaths;
@@ -7,9 +7,10 @@ class CxxHeaderPathDetector: public PathDetector
{
public:
CxxHeaderPathDetector(const std::string& compilerName);
std::vector<FilePath> getPaths() const override;
private:
std::vector<FilePath> doGetPaths() const override;
const std::string m_compilerName;
};
@@ -21,32 +21,6 @@ CxxVs10To14HeaderPathDetector::CxxVs10To14HeaderPathDetector(
{
}
std::vector<FilePath> CxxVs10To14HeaderPathDetector::getPaths() const
{
const FilePath vsInstallPath = getVsInstallPathUsingRegistry();
// vc++ headers
std::vector<FilePath> headerSearchPaths;
if (vsInstallPath.exists())
{
for (const std::wstring& subdirectory: {L"vc/include", L"vc/atlmfc/include"})
{
FilePath headerSearchPath = vsInstallPath.getConcatenated(subdirectory);
if (headerSearchPath.exists())
{
headerSearchPaths.push_back(headerSearchPath.makeCanonical());
}
}
}
if (!headerSearchPaths.empty())
{
utility::append(headerSearchPaths, utility::getWindowsSdkHeaderSearchPaths(m_architecture));
}
return headerSearchPaths;
}
int CxxVs10To14HeaderPathDetector::visualStudioTypeToVersion(const VisualStudioType t)
{
switch (t)
@@ -80,6 +54,32 @@ std::string CxxVs10To14HeaderPathDetector::visualStudioTypeToString(const Visual
return ret;
}
std::vector<FilePath> CxxVs10To14HeaderPathDetector::doGetPaths() const
{
const FilePath vsInstallPath = getVsInstallPathUsingRegistry();
// vc++ headers
std::vector<FilePath> headerSearchPaths;
if (vsInstallPath.exists())
{
for (const std::wstring& subdirectory: {L"vc/include", L"vc/atlmfc/include"})
{
FilePath headerSearchPath = vsInstallPath.getConcatenated(subdirectory);
if (headerSearchPath.exists())
{
headerSearchPaths.push_back(headerSearchPath.makeCanonical());
}
}
}
if (!headerSearchPaths.empty())
{
utility::append(headerSearchPaths, utility::getWindowsSdkHeaderSearchPaths(m_architecture));
}
return headerSearchPaths;
}
FilePath CxxVs10To14HeaderPathDetector::getVsInstallPathUsingRegistry() const
{
QString key = "HKEY_LOCAL_MACHINE\\SOFTWARE\\";
@@ -17,12 +17,13 @@ public:
CxxVs10To14HeaderPathDetector(
VisualStudioType type, bool isExpress, ApplicationArchitectureType architecture);
std::vector<FilePath> getPaths() const override;
private:
static int visualStudioTypeToVersion(const VisualStudioType t);
static std::string visualStudioTypeToString(const VisualStudioType t);
std::vector<FilePath> doGetPaths() const override;
FilePath getVsInstallPathUsingRegistry() const;
const int m_version;
@@ -10,7 +10,7 @@
CxxVs15HeaderPathDetector::CxxVs15HeaderPathDetector(): PathDetector("Visual Studio 2017") {}
std::vector<FilePath> CxxVs15HeaderPathDetector::getPaths() const
std::vector<FilePath> CxxVs15HeaderPathDetector::doGetPaths() const
{
std::vector<FilePath> headerSearchPaths;
@@ -8,7 +8,9 @@ class CxxVs15HeaderPathDetector: public PathDetector
{
public:
CxxVs15HeaderPathDetector();
std::vector<FilePath> getPaths() const override;
private:
std::vector<FilePath> doGetPaths() const override;
};
#endif // CXX_VS_15_HEADER_PATH_DETECTOR_H
@@ -16,6 +16,42 @@ JavaPathDetectorLinux::JavaPathDetectorLinux(const std::string javaVersion)
{
}
std::vector<FilePath> JavaPathDetectorLinux::doGetPaths() const
{
std::vector<FilePath> paths;
FilePath p = getJavaInPath();
if (!p.empty())
{
paths.push_back(p);
}
p = getJavaInJavaHome();
if (!p.empty())
{
paths.push_back(p);
}
// some default paths for java
paths.push_back(FilePath(L"/etc/alternatives/java"));
paths.push_back(FilePath(L"/usr/lib/jvm/default/bin/java"));
paths.push_back(FilePath(L"/usr/lib/jvm/java-openjdk/bin/java"));
for (const FilePath& path: paths)
{
if (checkVersion(path))
{
FilePath absoluteJavaPath = readLink(path);
FilePath jvmLibrary = getFilePathRelativeToJavaExecutable(absoluteJavaPath);
if (jvmLibrary.exists())
{
std::vector<FilePath> foundPath = {jvmLibrary};
return foundPath;
}
}
}
return std::vector<FilePath>();
}
FilePath JavaPathDetectorLinux::getJavaInPath() const
{
std::string command = "which java";
@@ -84,39 +120,3 @@ bool JavaPathDetectorLinux::checkVersion(const FilePath& path) const
return output.find(m_javaVersion) != std::string::npos;
}
std::vector<FilePath> JavaPathDetectorLinux::getPaths() const
{
std::vector<FilePath> paths;
FilePath p = getJavaInPath();
if (!p.empty())
{
paths.push_back(p);
}
p = getJavaInJavaHome();
if (!p.empty())
{
paths.push_back(p);
}
// some default paths for java
paths.push_back(FilePath(L"/etc/alternatives/java"));
paths.push_back(FilePath(L"/usr/lib/jvm/default/bin/java"));
paths.push_back(FilePath(L"/usr/lib/jvm/java-openjdk/bin/java"));
for (const FilePath& path: paths)
{
if (checkVersion(path))
{
FilePath absoluteJavaPath = readLink(path);
FilePath jvmLibrary = getFilePathRelativeToJavaExecutable(absoluteJavaPath);
if (jvmLibrary.exists())
{
std::vector<FilePath> foundPath = {jvmLibrary};
return foundPath;
}
}
}
return std::vector<FilePath>();
}
@@ -7,9 +7,9 @@ class JavaPathDetectorLinux: public JavaPathDetector
{
public:
JavaPathDetectorLinux(const std::string javaVersion);
std::vector<FilePath> getPaths() const override;
private:
std::vector<FilePath> doGetPaths() const override;
FilePath getJavaInPath() const;
FilePath readLink(const FilePath& path) const;
FilePath getJavaInJavaHome() const;
@@ -9,7 +9,7 @@ JavaPathDetectorMac::JavaPathDetectorMac(const std::string javaVersion)
{
}
std::vector<FilePath> JavaPathDetectorMac::getPaths() const
std::vector<FilePath> JavaPathDetectorMac::doGetPaths() const
{
std::vector<FilePath> paths;
FilePath javaPath;
@@ -7,7 +7,9 @@ class JavaPathDetectorMac: public JavaPathDetector
{
public:
JavaPathDetectorMac(const std::string javaVersion);
virtual std::vector<FilePath> getPaths() const override;
private:
virtual std::vector<FilePath> doGetPaths() const override;
};
#endif // JAVA_PATH_DETECTOR_MAC_H
@@ -12,7 +12,7 @@ JavaPathDetectorWindows::JavaPathDetectorWindows(const std::string javaVersion)
{
}
std::vector<FilePath> JavaPathDetectorWindows::getPaths() const
std::vector<FilePath> JavaPathDetectorWindows::doGetPaths() const
{
QString key = "HKEY_LOCAL_MACHINE\\SOFTWARE\\";
@@ -7,7 +7,9 @@ class JavaPathDetectorWindows: public JavaPathDetector
{
public:
JavaPathDetectorWindows(const std::string javaVersion);
virtual std::vector<FilePath> getPaths() const override;
private:
virtual std::vector<FilePath> doGetPaths() const override;
};
#endif // JAVA_PATH_DETECTOR_WINDOWS_H
@@ -13,7 +13,7 @@ JreSystemLibraryPathDetector::JreSystemLibraryPathDetector(
{
}
std::vector<FilePath> JreSystemLibraryPathDetector::getPaths() const
std::vector<FilePath> JreSystemLibraryPathDetector::doGetPaths() const
{
std::vector<FilePath> paths;
for (const FilePath& jrePath: m_javaPathDetector->getPaths())
@@ -11,9 +11,10 @@ class JreSystemLibraryPathDetector: public PathDetector
{
public:
JreSystemLibraryPathDetector(std::shared_ptr<JavaPathDetector> javaPathDetector);
std::vector<FilePath> getPaths() const override;
private:
std::vector<FilePath> doGetPaths() const override;
std::shared_ptr<JavaPathDetector> m_javaPathDetector;
};
@@ -5,7 +5,7 @@
MavenPathDetectorUnix::MavenPathDetectorUnix(): PathDetector("Maven for Unix") {}
std::vector<FilePath> MavenPathDetectorUnix::getPaths() const
std::vector<FilePath> MavenPathDetectorUnix::doGetPaths() const
{
std::string command = "which mvn";
FilePath mavenPath(utility::executeProcess(command.c_str()).second);
@@ -7,7 +7,9 @@ class MavenPathDetectorUnix: public PathDetector
{
public:
MavenPathDetectorUnix();
std::vector<FilePath> getPaths() const override;
private:
std::vector<FilePath> doGetPaths() const override;
};
#endif // MAVEN_PATH_DETECTOR_UNIX_H
@@ -5,7 +5,7 @@
MavenPathDetectorWindows::MavenPathDetectorWindows(): PathDetector("Maven for Windows") {}
std::vector<FilePath> MavenPathDetectorWindows::getPaths() const
std::vector<FilePath> MavenPathDetectorWindows::doGetPaths() const
{
std::string command = "cmd /c where mvn.cmd && exit";
FilePath mavenPath(utility::executeProcess(command.c_str()).second);
@@ -7,7 +7,9 @@ class MavenPathDetectorWindows: public PathDetector
{
public:
MavenPathDetectorWindows();
std::vector<FilePath> getPaths() const override;
private:
std::vector<FilePath> doGetPaths() const override;
};
#endif // MAVEN_PATH_DETECTOR_WINDOWS_H