From ce324b8d28c51188672dc48d70d6e21a0adc8610 Mon Sep 17 00:00:00 2001
From: Tobias Hunger <tobias.hunger@digia.com>
Date: Mon, 16 Jun 2014 14:42:21 +0200
Subject: [PATCH] Qbs: Factor parsing code out of QbsProject

Change-Id: I9b86baf964252e3d155cce533c79ca7a9dc9b315
Reviewed-by: Christian Kandeler <christian.kandeler@digia.com>
---
 src/plugins/qbsprojectmanager/qbsproject.cpp  | 170 ++++-----------
 src/plugins/qbsprojectmanager/qbsproject.h    |  15 +-
 .../qbsprojectmanager/qbsprojectmanager.pro   |   2 +
 .../qbsprojectmanager/qbsprojectmanager.qbs   |   2 +
 .../qbsprojectmanager/qbsprojectparser.cpp    | 200 ++++++++++++++++++
 .../qbsprojectmanager/qbsprojectparser.h      |  86 ++++++++
 6 files changed, 336 insertions(+), 139 deletions(-)
 create mode 100644 src/plugins/qbsprojectmanager/qbsprojectparser.cpp
 create mode 100644 src/plugins/qbsprojectmanager/qbsprojectparser.h

diff --git a/src/plugins/qbsprojectmanager/qbsproject.cpp b/src/plugins/qbsprojectmanager/qbsproject.cpp
index 9016e3b881..7821fa4aaf 100644
--- a/src/plugins/qbsprojectmanager/qbsproject.cpp
+++ b/src/plugins/qbsprojectmanager/qbsproject.cpp
@@ -32,6 +32,7 @@
 #include "qbsbuildconfiguration.h"
 #include "qbslogsink.h"
 #include "qbsprojectfile.h"
+#include "qbsprojectparser.h"
 #include "qbsprojectmanagerconstants.h"
 #include "qbsnodes.h"
 
@@ -39,7 +40,6 @@
 #include <utils/qtcassert.h>
 
 #include <coreplugin/icontext.h>
-#include <coreplugin/icore.h>
 #include <coreplugin/id.h>
 #include <coreplugin/progressmanager/progressmanager.h>
 #include <coreplugin/mimedatabase.h>
@@ -98,9 +98,8 @@ QbsProject::QbsProject(QbsManager *manager, const QString &fileName) :
     m_projectName(QFileInfo(fileName).completeBaseName()),
     m_fileName(fileName),
     m_rootProjectNode(0),
-    m_qbsSetupProjectJob(0),
+    m_qbsProjectParser(0),
     m_qbsUpdateFutureInterface(0),
-    m_currentProgressBase(0),
     m_forceParsing(false),
     m_currentBc(0)
 {
@@ -127,11 +126,7 @@ QbsProject::QbsProject(QbsManager *manager, const QString &fileName) :
 QbsProject::~QbsProject()
 {
     m_codeModelFuture.cancel();
-    if (m_qbsSetupProjectJob) {
-        m_qbsSetupProjectJob->disconnect(this);
-        m_qbsSetupProjectJob->cancel();
-        delete m_qbsSetupProjectJob;
-    }
+    delete m_qbsProjectParser;
 
     // Deleting the root node triggers a few things, make sure rootProjectNode
     // returns 0 already
@@ -279,22 +274,22 @@ bool QbsProject::needsSpecialDeployment() const
 
 void QbsProject::handleQbsParsingDone(bool success)
 {
-    QTC_ASSERT(m_qbsSetupProjectJob, return);
-    QTC_ASSERT(m_qbsUpdateFutureInterface, return);
+    QTC_ASSERT(m_qbsProjectParser, return);
 
     qbs::Project project;
-    if (success) {
-        project = m_qbsSetupProjectJob->project();
-    } else {
-        generateErrors(m_qbsSetupProjectJob->error());
-        m_qbsUpdateFutureInterface->reportCanceled();
-    }
-    m_qbsSetupProjectJob->deleteLater();
-    m_qbsSetupProjectJob = 0;
+    if (success)
+        project = m_qbsProjectParser->qbsProject();
 
-    m_qbsUpdateFutureInterface->reportFinished();
-    delete m_qbsUpdateFutureInterface;
-    m_qbsUpdateFutureInterface = 0;
+    generateErrors(m_qbsProjectParser->error());
+
+    m_qbsProjectParser->deleteLater();
+    m_qbsProjectParser = 0;
+
+    if (m_qbsUpdateFutureInterface) {
+        m_qbsUpdateFutureInterface->reportFinished();
+        delete m_qbsUpdateFutureInterface;
+        m_qbsUpdateFutureInterface = 0;
+    }
 
     if (project.isValid()) {
         // Do not throw away data when parsing errors were introduced. That frightens users:-)
@@ -315,21 +310,6 @@ void QbsProject::handleQbsParsingDone(bool success)
     emit projectParsingDone(success);
 }
 
-void QbsProject::handleQbsParsingProgress(int progress)
-{
-    if (m_qbsUpdateFutureInterface)
-        m_qbsUpdateFutureInterface->setProgressValue(m_currentProgressBase + progress);
-}
-
-void QbsProject::handleQbsParsingTaskSetup(const QString &description, int maximumProgressValue)
-{
-    Q_UNUSED(description);
-    if (m_qbsUpdateFutureInterface) {
-        m_currentProgressBase = m_qbsUpdateFutureInterface->progressValue();
-        m_qbsUpdateFutureInterface->setProgressRange(0, m_currentProgressBase + maximumProgressValue);
-    }
-}
-
 void QbsProject::targetWasAdded(Target *t)
 {
     connect(t, SIGNAL(activeBuildConfigurationChanged(ProjectExplorer::BuildConfiguration*)),
@@ -383,8 +363,6 @@ void QbsProject::delayForcedParsing()
 
 void QbsProject::parseCurrentBuildConfiguration(bool force)
 {
-    m_parsingDelay.stop();
-
     if (!m_forceParsing)
         m_forceParsing = force;
 
@@ -396,6 +374,25 @@ void QbsProject::parseCurrentBuildConfiguration(bool force)
     parse(bc->qbsConfiguration(), bc->environment(), bc->buildDirectory().toString());
 }
 
+void QbsProject::registerQbsProjectParser(QbsProjectParser *p)
+{
+    m_parsingDelay.stop();
+
+    if (m_qbsProjectParser) {
+        m_qbsProjectParser->disconnect(this);
+        m_qbsProjectParser->deleteLater();
+    }
+
+    m_qbsProjectParser = p;
+
+    if (p) {
+        p->setForced(m_forceParsing);
+        connect(m_qbsProjectParser, SIGNAL(done(bool)), this, SLOT(handleQbsParsingDone(bool)));
+    }
+
+    m_forceParsing = false;
+}
+
 bool QbsProject::fromMap(const QVariantMap &map)
 {
     if (!Project::fromMap(map))
@@ -425,75 +422,17 @@ void QbsProject::generateErrors(const qbs::ErrorInfo &e)
 
 void QbsProject::parse(const QVariantMap &config, const Environment &env, const QString &dir)
 {
-    QTC_ASSERT(!dir.isNull(), return);
-
-    qbs::SetupProjectParameters params;
-    QVariantMap baseConfig;
-    QVariantMap userConfig = config;
-    QString specialKey = QLatin1String(Constants::QBS_CONFIG_PROFILE_KEY);
-    const QString profileName = userConfig.take(specialKey).toString();
-    baseConfig.insert(specialKey, profileName);
-    specialKey = QLatin1String(Constants::QBS_CONFIG_VARIANT_KEY);
-    baseConfig.insert(specialKey, userConfig.take(specialKey));
-    params.setBuildConfiguration(baseConfig);
-    params.setOverriddenValues(userConfig);
-    qbs::ErrorInfo err = params.expandBuildConfiguration(QbsManager::settings());
-    if (err.hasError()) {
-        generateErrors(err);
-        return;
-    }
-
-    // Avoid useless reparsing:
-    const qbs::Project &currentProject = qbsProject();
-    if (!m_forceParsing
-            && currentProject.isValid()
-            && currentProject.projectConfiguration() == params.finalBuildConfigurationTree()) {
-        QHash<QString, QString> usedEnv = currentProject.usedEnvironment();
-        bool canSkip = true;
-        for (QHash<QString, QString>::const_iterator i = usedEnv.constBegin();
-             i != usedEnv.constEnd(); ++i) {
-            if (env.value(i.key()) != i.value()) {
-                canSkip = false;
-                break;
-            }
-        }
-        if (canSkip)
-            return;
-    }
-
-    // Some people don't like it when files are created as a side effect of opening a project,
-    // so do not store the build graph if the build directory does not exist yet.
-    params.setDryRun(!QFileInfo(dir).exists());
-
-    params.setBuildRoot(dir);
-    params.setProjectFilePath(m_fileName);
-    params.setIgnoreDifferentProjectFilePath(false);
-    params.setEnvironment(env.toProcessEnvironment());
-    const qbs::Preferences prefs(QbsManager::settings(), profileName);
-    params.setSearchPaths(prefs.searchPaths(resourcesBaseDirectory()));
-    params.setPluginPaths(prefs.pluginPaths(pluginsBaseDirectory()));
-
-    // Do the parsing:
     prepareForParsing();
-    QTC_ASSERT(!m_qbsSetupProjectJob, return);
-
-    m_qbsSetupProjectJob
-            = qbs::Project::setupProject(params, QbsManager::logSink(), 0);
+    QTC_ASSERT(!m_qbsProjectParser, return);
 
-    connect(m_qbsSetupProjectJob, SIGNAL(finished(bool,qbs::AbstractJob*)),
-            this, SLOT(handleQbsParsingDone(bool)));
-    connect(m_qbsSetupProjectJob, SIGNAL(taskStarted(QString,int,qbs::AbstractJob*)),
-            this, SLOT(handleQbsParsingTaskSetup(QString,int)));
-    connect(m_qbsSetupProjectJob, SIGNAL(taskProgress(int,qbs::AbstractJob*)),
-            this, SLOT(handleQbsParsingProgress(int)));
+    registerQbsProjectParser(new QbsProjectParser(this, m_qbsUpdateFutureInterface));
 
-    emit projectParsingStarted();
+    if (m_qbsProjectParser->parse(config, env, dir))
+        emit projectParsingStarted();
 }
 
 void QbsProject::prepareForParsing()
 {
-    m_forceParsing = false;
-
     TaskHub::clearTasks(ProjectExplorer::Constants::TASK_CATEGORY_BUILDSYSTEM);
     if (m_qbsUpdateFutureInterface) {
         m_qbsUpdateFutureInterface->reportCanceled();
@@ -502,15 +441,7 @@ void QbsProject::prepareForParsing()
     delete m_qbsUpdateFutureInterface;
     m_qbsUpdateFutureInterface = 0;
 
-    if (m_qbsSetupProjectJob) {
-        m_qbsSetupProjectJob->disconnect(this);
-        m_qbsSetupProjectJob->cancel();
-        m_qbsSetupProjectJob->deleteLater();
-        m_qbsSetupProjectJob = 0;
-    }
-
-    m_currentProgressBase = 0;
-    m_qbsUpdateFutureInterface = new QFutureInterface<void>();
+    m_qbsUpdateFutureInterface = new QFutureInterface<bool>();
     m_qbsUpdateFutureInterface->setProgressRange(0, 0);
     ProgressManager::addTask(m_qbsUpdateFutureInterface->future(),
         tr("Reading Project \"%1\"").arg(displayName()), "Qbs.QbsEvaluate");
@@ -712,26 +643,5 @@ void QbsProject::updateDeploymentInfo(const qbs::Project &project)
     activeTarget()->setDeploymentData(deploymentData);
 }
 
-QString QbsProject::resourcesBaseDirectory() const
-{
-    const QString qbsInstallDir = QLatin1String(QBS_INSTALL_DIR);
-    if (!qbsInstallDir.isEmpty())
-        return qbsInstallDir;
-    return ICore::resourcePath() + QLatin1String("/qbs");
-}
-
-QString QbsProject::pluginsBaseDirectory() const
-{
-    const QString qbsInstallDir = QLatin1String(QBS_INSTALL_DIR);
-    if (!qbsInstallDir.isEmpty())
-        return qbsInstallDir + QLatin1String("/lib/");
-    if (Utils::HostOsInfo::isMacHost())
-        return QDir::cleanPath(QCoreApplication::applicationDirPath()
-                               + QLatin1String("/../PlugIns"));
-    else
-        return QDir::cleanPath(QCoreApplication::applicationDirPath()
-                               + QLatin1String("/../" IDE_LIBRARY_BASENAME "/qtcreator"));
-}
-
 } // namespace Internal
 } // namespace QbsProjectManager
diff --git a/src/plugins/qbsprojectmanager/qbsproject.h b/src/plugins/qbsprojectmanager/qbsproject.h
index 00fc85f003..45cee112e8 100644
--- a/src/plugins/qbsprojectmanager/qbsproject.h
+++ b/src/plugins/qbsprojectmanager/qbsproject.h
@@ -47,7 +47,6 @@ class BuildJob;
 class CleanJob;
 class Error;
 class ProjectData;
-class SetupProjectJob;
 class CleanOptions;
 class InstallJob;
 class InstallOptions;
@@ -63,6 +62,7 @@ namespace QbsProjectManager {
 namespace Internal {
 
 class QbsProjectNode;
+class QbsProjectParser;
 class QbsBuildConfiguration;
 
 class QbsProject : public ProjectExplorer::Project
@@ -92,6 +92,8 @@ public:
     bool hasParseResult() const;
     void parseCurrentBuildConfiguration(bool force);
 
+    void registerQbsProjectParser(QbsProjectParser *p);
+
     static Utils::FileName defaultBuildDirectory(const QString &projectFilePath,
                                                  const ProjectExplorer::Kit *k,
                                                  const QString &bcName);
@@ -100,6 +102,7 @@ public:
     const qbs::ProjectData qbsProjectData() const;
 
     bool needsSpecialDeployment() const;
+    void generateErrors(const qbs::ErrorInfo &e);
 
 public slots:
     void invalidate();
@@ -112,8 +115,6 @@ signals:
 
 private slots:
     void handleQbsParsingDone(bool success);
-    void handleQbsParsingProgress(int progress);
-    void handleQbsParsingTaskSetup(const QString &description, int maximumProgressValue);
 
     void targetWasAdded(ProjectExplorer::Target *t);
     void changeActiveTarget(ProjectExplorer::Target *t);
@@ -125,15 +126,12 @@ private:
 
     void parse(const QVariantMap &config, const Utils::Environment &env, const QString &dir);
 
-    void generateErrors(const qbs::ErrorInfo &e);
     void prepareForParsing();
     void updateDocuments(const QSet<QString> &files);
     void updateCppCodeModel(const qbs::ProjectData &prj);
     void updateQmlJsCodeModel(const qbs::ProjectData &prj);
     void updateApplicationTargets(const qbs::ProjectData &projectData);
     void updateDeploymentInfo(const qbs::Project &project);
-    QString resourcesBaseDirectory() const;
-    QString pluginsBaseDirectory() const;
 
     QbsManager *const m_manager;
     const QString m_projectName;
@@ -141,10 +139,9 @@ private:
     QSet<Core::IDocument *> m_qbsDocuments;
     QbsProjectNode *m_rootProjectNode;
 
-    qbs::SetupProjectJob *m_qbsSetupProjectJob;
+    QbsProjectParser *m_qbsProjectParser;
 
-    QFutureInterface<void> *m_qbsUpdateFutureInterface;
-    int m_currentProgressBase;
+    QFutureInterface<bool> *m_qbsUpdateFutureInterface;
     bool m_forceParsing;
 
     QFuture<void> m_codeModelFuture;
diff --git a/src/plugins/qbsprojectmanager/qbsprojectmanager.pro b/src/plugins/qbsprojectmanager/qbsprojectmanager.pro
index 6b50595ed2..3497587550 100644
--- a/src/plugins/qbsprojectmanager/qbsprojectmanager.pro
+++ b/src/plugins/qbsprojectmanager/qbsprojectmanager.pro
@@ -36,6 +36,7 @@ HEADERS = \
     qbsprojectmanager_global.h \
     qbsprojectmanagerconstants.h \
     qbsprojectmanagerplugin.h \
+    qbsprojectparser.h \
     qbspropertylineedit.h \
     qbsrunconfiguration.h \
     qbsconstants.h
@@ -55,6 +56,7 @@ SOURCES = \
     qbsprojectfile.cpp \
     qbsprojectmanager.cpp \
     qbsprojectmanagerplugin.cpp \
+    qbsprojectparser.cpp \
     qbspropertylineedit.cpp \
     qbsrunconfiguration.cpp
 
diff --git a/src/plugins/qbsprojectmanager/qbsprojectmanager.qbs b/src/plugins/qbsprojectmanager/qbsprojectmanager.qbs
index 4ef8fee1fb..2fa3855e2a 100644
--- a/src/plugins/qbsprojectmanager/qbsprojectmanager.qbs
+++ b/src/plugins/qbsprojectmanager/qbsprojectmanager.qbs
@@ -101,6 +101,8 @@ QtcPlugin {
         "qbsprojectmanagerconstants.h",
         "qbsprojectmanagerplugin.cpp",
         "qbsprojectmanagerplugin.h",
+        "qbsprojectparser.cpp",
+        "qbsprojectparser.h",
         "qbspropertylineedit.cpp",
         "qbspropertylineedit.h",
         "qbsrunconfiguration.cpp",
diff --git a/src/plugins/qbsprojectmanager/qbsprojectparser.cpp b/src/plugins/qbsprojectmanager/qbsprojectparser.cpp
new file mode 100644
index 0000000000..f0b37fc6fc
--- /dev/null
+++ b/src/plugins/qbsprojectmanager/qbsprojectparser.cpp
@@ -0,0 +1,200 @@
+/****************************************************************************
+**
+** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of Qt Creator.
+**
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Digia.  For licensing terms and
+** conditions see http://qt.digia.com/licensing.  For further information
+** use the contact form at http://qt.digia.com/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file.  Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Digia gives you certain additional
+** rights.  These rights are described in the Digia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+****************************************************************************/
+
+#include "qbsprojectparser.h"
+
+#include "qbslogsink.h"
+#include "qbsproject.h"
+#include "qbsprojectmanagerconstants.h"
+
+#include <coreplugin/icore.h>
+#include <utils/qtcassert.h>
+
+#include <qbs.h>
+
+#include <QCoreApplication>
+#include <QDir>
+#include <QFileInfo>
+
+using namespace Utils;
+
+namespace QbsProjectManager {
+namespace Internal {
+
+// --------------------------------------------------------------------
+// QbsProjectParser:
+// --------------------------------------------------------------------
+
+QbsProjectParser::QbsProjectParser(QbsProject *project, QFutureInterface<bool> *fi) :
+    m_qbsSetupProjectJob(0),
+    m_fi(fi),
+    m_currentProgressBase(0)
+{
+    m_project = project->qbsProject();
+    m_projectFilePath = project->projectFilePath().toString();
+}
+
+QbsProjectParser::~QbsProjectParser()
+{
+    if (m_qbsSetupProjectJob) {
+        m_qbsSetupProjectJob->disconnect(this);
+        m_qbsSetupProjectJob->cancel();
+        m_qbsSetupProjectJob->deleteLater();
+        m_qbsSetupProjectJob = 0;
+    }
+    m_fi = 0; // we do not own m_fi, do not delete
+}
+
+void QbsProjectParser::setForced(bool f)
+{
+    m_wasForced = f;
+}
+
+bool QbsProjectParser::parse(const QVariantMap &config, const Environment &env, const QString &dir)
+{
+    QTC_ASSERT(!m_qbsSetupProjectJob, return false);
+    QTC_ASSERT(!dir.isNull(), return false);
+
+    m_currentProgressBase = 0;
+
+    qbs::SetupProjectParameters params;
+    QVariantMap baseConfig;
+    QVariantMap userConfig = config;
+    QString specialKey = QLatin1String(Constants::QBS_CONFIG_PROFILE_KEY);
+    const QString profileName = userConfig.take(specialKey).toString();
+    baseConfig.insert(specialKey, profileName);
+    specialKey = QLatin1String(Constants::QBS_CONFIG_VARIANT_KEY);
+    baseConfig.insert(specialKey, userConfig.take(specialKey));
+    params.setBuildConfiguration(baseConfig);
+    params.setOverriddenValues(userConfig);
+    m_error = params.expandBuildConfiguration(QbsManager::settings());
+    if (m_error.hasError()) {
+        emit done(false);
+        return false;
+    }
+
+    // Avoid useless reparsing:
+    if (!m_wasForced
+            && m_project.isValid()
+            && m_project.projectConfiguration() == params.finalBuildConfigurationTree()) {
+        QHash<QString, QString> usedEnv = m_project.usedEnvironment();
+        for (QHash<QString, QString>::const_iterator i = usedEnv.constBegin();
+             i != usedEnv.constEnd(); ++i) {
+            if (env.value(i.key()) != i.value()) {
+                emit done(true);
+                return true;
+            }
+        }
+    }
+
+    // Some people don't like it when files are created as a side effect of opening a project,
+    // so do not store the build graph if the build directory does not exist yet.
+    params.setDryRun(!QFileInfo(dir).exists());
+
+    params.setBuildRoot(dir);
+    params.setProjectFilePath(m_projectFilePath);
+    params.setIgnoreDifferentProjectFilePath(false);
+    params.setEnvironment(env.toProcessEnvironment());
+    const qbs::Preferences prefs(QbsManager::settings(), profileName);
+    params.setSearchPaths(prefs.searchPaths(resourcesBaseDirectory()));
+    params.setPluginPaths(prefs.pluginPaths(pluginsBaseDirectory()));
+
+    m_qbsSetupProjectJob = qbs::Project::setupProject(params, QbsManager::logSink(), 0);
+
+    connect(m_qbsSetupProjectJob, SIGNAL(finished(bool,qbs::AbstractJob*)),
+            this, SLOT(handleQbsParsingDone(bool)));
+    connect(m_qbsSetupProjectJob, SIGNAL(taskStarted(QString,int,qbs::AbstractJob*)),
+            this, SIGNAL(taskChanged(QString,int)));
+    connect(m_qbsSetupProjectJob, SIGNAL(taskProgress(int,qbs::AbstractJob*)),
+            this, SIGNAL(progress(int)));
+
+    return true;
+}
+
+qbs::Project QbsProjectParser::qbsProject() const
+{
+    return m_project;
+}
+
+qbs::ErrorInfo QbsProjectParser::error()
+{
+    return m_error;
+}
+
+void QbsProjectParser::handleQbsParsingDone(bool success)
+{
+    QTC_ASSERT(m_qbsSetupProjectJob, return);
+
+    m_project = m_qbsSetupProjectJob->project();
+    m_error = m_qbsSetupProjectJob->error();
+
+    if (!success)
+        m_fi->reportCanceled();
+
+    emit done(success);
+}
+
+void QbsProjectParser::handleQbsParsingProgress(int progress)
+{
+    if (m_fi)
+        m_fi->setProgressValue(m_currentProgressBase + progress);
+}
+
+void QbsProjectParser::handleQbsParsingTaskSetup(const QString &description, int maximumProgressValue)
+{
+    Q_UNUSED(description);
+    if (m_fi) {
+        m_currentProgressBase = m_fi->progressValue();
+        m_fi->setProgressRange(0, m_currentProgressBase + maximumProgressValue);
+    }
+}
+
+QString QbsProjectParser::resourcesBaseDirectory() const
+{
+    const QString qbsInstallDir = QLatin1String(QBS_INSTALL_DIR);
+    if (!qbsInstallDir.isEmpty())
+        return qbsInstallDir;
+    return Core::ICore::resourcePath() + QLatin1String("/qbs");
+}
+
+QString QbsProjectParser::pluginsBaseDirectory() const
+{
+    const QString qbsInstallDir = QLatin1String(QBS_INSTALL_DIR);
+    if (!qbsInstallDir.isEmpty())
+        return qbsInstallDir + QLatin1String("/lib/");
+    if (Utils::HostOsInfo::isMacHost())
+        return QDir::cleanPath(QCoreApplication::applicationDirPath()
+                               + QLatin1String("/../PlugIns"));
+    else
+        return QDir::cleanPath(QCoreApplication::applicationDirPath()
+                               + QLatin1String("/../" IDE_LIBRARY_BASENAME "/qtcreator"));
+}
+
+} // namespace Internal
+} // namespace QbsProjectManager
diff --git a/src/plugins/qbsprojectmanager/qbsprojectparser.h b/src/plugins/qbsprojectmanager/qbsprojectparser.h
new file mode 100644
index 0000000000..36ddd7ea8f
--- /dev/null
+++ b/src/plugins/qbsprojectmanager/qbsprojectparser.h
@@ -0,0 +1,86 @@
+/****************************************************************************
+**
+** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of Qt Creator.
+**
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Digia.  For licensing terms and
+** conditions see http://qt.digia.com/licensing.  For further information
+** use the contact form at http://qt.digia.com/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file.  Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Digia gives you certain additional
+** rights.  These rights are described in the Digia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+****************************************************************************/
+
+#ifndef QBSPROJECTPARSER_H
+#define QBSPROJECTPARSER_H
+
+#include <utils/environment.h>
+
+#include <QFutureInterface>
+#include <QObject>
+
+#include <qbs.h>
+
+namespace QbsProjectManager {
+namespace Internal {
+
+class QbsProject;
+
+class QbsProjectParser : public QObject
+{
+    Q_OBJECT
+
+public:
+    QbsProjectParser(QbsProjectManager::Internal::QbsProject *project,
+                     QFutureInterface<bool> *fi);
+    ~QbsProjectParser();
+
+    void setForced(bool);
+
+    bool parse(const QVariantMap &config, const Utils::Environment &env, const QString &dir);
+
+    qbs::Project qbsProject() const;
+    qbs::ErrorInfo error();
+
+signals:
+    void done(bool success);
+
+private slots:
+    void handleQbsParsingDone(bool success);
+    void handleQbsParsingProgress(int progress);
+    void handleQbsParsingTaskSetup(const QString &description, int maximumProgressValue);
+
+private:
+    QString pluginsBaseDirectory() const;
+    QString resourcesBaseDirectory() const;
+
+    bool m_wasForced;
+    QString m_projectFilePath;
+    qbs::SetupProjectJob *m_qbsSetupProjectJob;
+    qbs::ErrorInfo m_error;
+    qbs::Project m_project;
+
+    QFutureInterface<bool> *m_fi;
+    int m_currentProgressBase;
+};
+
+} // namespace Internal
+} // namespace QbsProjectManager
+
+#endif // QBSPROJECTPARSER_H
-- 
GitLab