ProjectManager: Centralize "File not found handling"

That's the only error that was ever checked for, in all nine
project manager. In the hypothetical case that we'll need something
else than the name of a file to identify a "project file", we'd
probably need to touch the signature anyway. Until then, remove
the duplication.

Change-Id: Iba00b8f71309a908e2d29c0a58c50b685eca0cae
Reviewed-by: Tobias Hunger <tobias.hunger@qt.io>
This commit is contained in:
hjk
2017-02-28 16:07:53 +01:00
parent 3490c5751d
commit 50d1690854
18 changed files with 24 additions and 94 deletions

View File

@@ -29,27 +29,13 @@
#include "autotoolsproject.h"
#include "autotoolsprojectconstants.h"
#include <coreplugin/icore.h>
#include <coreplugin/idocument.h>
#include <coreplugin/messagemanager.h>
#include <projectexplorer/projectexplorerconstants.h>
#include <projectexplorer/projectexplorer.h>
#include <projectexplorer/session.h>
using namespace ProjectExplorer;
namespace AutotoolsProjectManager {
namespace Internal {
Project *AutotoolsManager::openProject(const QString &fileName, QString *errorString)
Project *AutotoolsManager::openProject(const QString &fileName)
{
if (!QFileInfo(fileName).isFile()) {
if (errorString)
*errorString = tr("Failed opening project \"%1\": Project is not a file")
.arg(fileName);
return 0;
}
return new AutotoolsProject(fileName);
}

View File

@@ -44,7 +44,7 @@ class AutotoolsManager : public ProjectExplorer::IProjectManager
Q_OBJECT
public:
ProjectExplorer::Project *openProject(const QString &fileName, QString *errorString) override;
ProjectExplorer::Project *openProject(const QString &fileName) override;
QString mimeType() const override;
};

View File

@@ -156,17 +156,9 @@ void CMakeManager::rescanProject(Project *project)
cmakeProject->runCMake(); // by my experience: every rescan run requires cmake run too
}
Project *CMakeManager::openProject(const QString &fileName, QString *errorString)
Project *CMakeManager::openProject(const QString &fileName)
{
Utils::FileName file = Utils::FileName::fromString(fileName);
if (!file.toFileInfo().isFile()) {
if (errorString)
*errorString = tr("Failed opening project \"%1\": Project is not a file")
.arg(file.toUserOutput());
return 0;
}
return new CMakeProject(file);
return new CMakeProject(Utils::FileName::fromString(fileName));
}
QString CMakeManager::mimeType() const

View File

@@ -42,7 +42,7 @@ class CMakeManager : public ProjectExplorer::IProjectManager
public:
CMakeManager();
ProjectExplorer::Project *openProject(const QString &fileName, QString *errorString) override;
ProjectExplorer::Project *openProject(const QString &fileName) override;
QString mimeType() const override;
private:

View File

@@ -27,13 +27,6 @@
#include "genericprojectconstants.h"
#include "genericproject.h"
#include <coreplugin/icore.h>
#include <projectexplorer/projectexplorer.h>
#include <projectexplorer/projectexplorerconstants.h>
#include <projectexplorer/session.h>
#include <QDebug>
namespace GenericProjectManager {
namespace Internal {
@@ -42,15 +35,8 @@ QString Manager::mimeType() const
return QLatin1String(Constants::GENERICMIMETYPE);
}
ProjectExplorer::Project *Manager::openProject(const QString &fileName, QString *errorString)
ProjectExplorer::Project *Manager::openProject(const QString &fileName)
{
if (!QFileInfo(fileName).isFile()) {
if (errorString)
*errorString = tr("Failed opening project \"%1\": Project is not a file.")
.arg(fileName);
return 0;
}
return new GenericProject(fileName);
}

View File

@@ -38,7 +38,7 @@ class Manager : public ProjectExplorer::IProjectManager
public:
virtual QString mimeType() const override;
virtual ProjectExplorer::Project *openProject(const QString &fileName, QString *errorString) override;
virtual ProjectExplorer::Project *openProject(const QString &fileName) override;
void registerProject(GenericProject *project);
void unregisterProject(GenericProject *project);

View File

@@ -37,13 +37,8 @@ QString NimProjectManager::mimeType() const
return QLatin1String(Constants::C_NIM_PROJECT_MIMETYPE);
}
Project *NimProjectManager::openProject(const QString &fileName, QString *errorString)
Project *NimProjectManager::openProject(const QString &fileName)
{
if (!QFileInfo(fileName).isFile()) {
*errorString = tr("Failed opening project \"%1\": Project is not a file.").arg(fileName);
return nullptr;
}
return new NimProject(fileName);
}

View File

@@ -36,7 +36,7 @@ class NimProjectManager : public ProjectExplorer::IProjectManager
public:
QString mimeType() const override;
ProjectExplorer::Project *openProject(const QString &fileName, QString *errorString) override;
ProjectExplorer::Project *openProject(const QString &fileName) override;
};
}

View File

@@ -39,8 +39,8 @@ class PROJECTEXPLORER_EXPORT IProjectManager : public QObject
public:
virtual QString mimeType() const = 0;
// fileName is a canonical path!
virtual Project *openProject(const QString &fileName, QString *errorString) = 0;
// FileName is a canonical path of a checked-to-exist file.
virtual Project *openProject(const QString &fileName) = 0;
};
} // namespace ProjectExplorer

View File

@@ -109,7 +109,6 @@ void JsonKitsPage::setupProjectFiles(const JsonWizard::GeneratorFiles &files)
foreach (const JsonWizard::GeneratorFile &f, files) {
if (f.file.attributes() & GeneratedFile::OpenProjectAttribute) {
QString errorMessage;
const QFileInfo fi(f.file.path());
const QString path = fi.absoluteFilePath();
@@ -119,7 +118,7 @@ void JsonKitsPage::setupProjectFiles(const JsonWizard::GeneratorFiles &files)
continue;
auto manager = Utils::findOrDefault(managerList, Utils::equal(&IProjectManager::mimeType, mt.name()));
project = manager ? manager->openProject(path, &errorMessage) : nullptr;
project = manager ? manager->openProject(path) : nullptr;
if (project) {
if (setupProject(project))
project->saveSettings();

View File

@@ -1707,8 +1707,10 @@ ProjectExplorerPlugin::OpenProjectResult ProjectExplorerPlugin::openProjects(con
foreach (IProjectManager *manager, projectManagers) {
if (mt.matchesName(manager->mimeType())) {
foundProjectManager = true;
QString tmp;
if (Project *pro = manager->openProject(filePath, &tmp)) {
if (!QFileInfo(filePath).isFile()) {
appendError(errorString,
tr("Failed opening project \"%1\": Project is not a file").arg(fileName));
} else if (Project *pro = manager->openProject(filePath)) {
pro->setProjectManager(manager);
QObject::connect(pro, &Project::parsingFinished, [pro]() {
emit SessionManager::instance()->projectFinishedParsing(pro);
@@ -1726,8 +1728,6 @@ ProjectExplorerPlugin::OpenProjectResult ProjectExplorerPlugin::openProjects(con
delete pro;
}
}
if (!tmp.isEmpty())
appendError(errorString, tmp);
break;
}
}

View File

@@ -94,7 +94,7 @@ class PythonProjectManager : public IProjectManager
Q_OBJECT
public:
QString mimeType() const override { return QLatin1String(PythonMimeType); }
Project *openProject(const QString &fileName, QString *errorString) override;
Project *openProject(const QString &fileName) override;
};
class PythonProject : public Project
@@ -361,15 +361,8 @@ PythonRunConfigurationWidget::PythonRunConfigurationWidget(PythonRunConfiguratio
setEnabled(runConfiguration->isEnabled());
}
Project *PythonProjectManager::openProject(const QString &fileName, QString *errorString)
Project *PythonProjectManager::openProject(const QString &fileName)
{
if (!QFileInfo(fileName).isFile()) {
if (errorString)
*errorString = tr("Failed opening project \"%1\": Project is not a file.")
.arg(fileName);
return 0;
}
return new PythonProject(fileName);
}

View File

@@ -105,15 +105,8 @@ QString QbsManager::mimeType() const
return QLatin1String(QmlJSTools::Constants::QBS_MIMETYPE);
}
ProjectExplorer::Project *QbsManager::openProject(const QString &fileName, QString *errorString)
ProjectExplorer::Project *QbsManager::openProject(const QString &fileName)
{
if (!QFileInfo(fileName).isFile()) {
if (errorString)
*errorString = tr("Failed opening project \"%1\": Project is not a file.")
.arg(fileName);
return nullptr;
}
return new QbsProject(fileName);
}

View File

@@ -60,7 +60,7 @@ public:
~QbsManager();
QString mimeType() const override;
ProjectExplorer::Project *openProject(const QString &fileName, QString *errorString) override;
ProjectExplorer::Project *openProject(const QString &fileName) override;
// QBS profiles management:
QString profileForKit(const ProjectExplorer::Kit *k);

View File

@@ -74,15 +74,8 @@ QString QmakeManager::mimeType() const
return QLatin1String(QmakeProjectManager::Constants::PROFILE_MIMETYPE);
}
ProjectExplorer::Project *QmakeManager::openProject(const QString &fileName, QString *errorString)
ProjectExplorer::Project *QmakeManager::openProject(const QString &fileName)
{
if (!QFileInfo(fileName).isFile()) {
if (errorString)
*errorString = tr("Failed opening project \"%1\": Project is not a file")
.arg(fileName);
return 0;
}
return new QmakeProject(this, fileName);
}

View File

@@ -53,7 +53,7 @@ public:
void notifyChanged(const Utils::FileName &name);
QString mimeType() const override;
ProjectExplorer::Project *openProject(const QString &fileName, QString *errorString) override;
ProjectExplorer::Project *openProject(const QString &fileName) override;
// Context information used in the slot implementations
static ProjectExplorer::Node *contextNode();

View File

@@ -43,15 +43,8 @@ Manager::Manager()
QString Manager::mimeType() const
{ return QLatin1String(Constants::QMLPROJECT_MIMETYPE); }
ProjectExplorer::Project *Manager::openProject(const QString &fileName, QString *errorString)
ProjectExplorer::Project *Manager::openProject(const QString &fileName)
{
if (!QFileInfo(fileName).isFile()) {
if (errorString)
*errorString = tr("Failed opening project \"%1\": Project is not a file.")
.arg(fileName);
return 0;
}
return new QmlProject(this, Utils::FileName::fromString(fileName));
}

View File

@@ -39,7 +39,7 @@ public:
Manager();
QString mimeType() const override;
ProjectExplorer::Project *openProject(const QString &fileName, QString *errorString) override;
ProjectExplorer::Project *openProject(const QString &fileName) override;
};
} // namespace Internal