1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
|
/****************************************************************************
**
** Copyright (C) 2016 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** 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 The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3 as published by the Free Software
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
**
****************************************************************************/
#include "qmljsbundleprovider.h"
#include <coreplugin/icore.h>
#include <qmljs/qmljsbundle.h>
#include <qmljs/qmljsconstants.h>
#include <qtsupport/qtkitinformation.h>
#include <qtsupport/qtsupportconstants.h>
#include <QDir>
namespace QmlJSTools {
using namespace QmlJS;
/*!
\class QmlJSEditor::BasicBundleProvider
\brief The BasicBundleProvider class sets up the default bundles for Qt and
various QML states.
*/
BasicBundleProvider::BasicBundleProvider(QObject *parent) :
IBundleProvider(parent)
{ }
QmlBundle BasicBundleProvider::defaultBundle(const QString &bundleInfoName)
{
static bool wroteErrors = false;
QmlBundle res;
QString defaultBundlePath = Core::ICore::resourcePath()
+ QLatin1String("/qml-type-descriptions/")
+ bundleInfoName;
if (!QFileInfo::exists(defaultBundlePath)) {
qWarning() << "BasicBundleProvider: ERROR " << defaultBundlePath
<< " not found";
return res;
}
QStringList errors;
if (!res.readFrom(defaultBundlePath, &errors) && ! wroteErrors) {
qWarning() << "BasicBundleProvider: ERROR reading " << defaultBundlePath
<< " : " << errors;
wroteErrors = true;
}
return res;
}
QmlBundle BasicBundleProvider::defaultQt5QtQuick2Bundle()
{
return defaultBundle(QLatin1String("qt5QtQuick2-bundle.json"));
}
QmlBundle BasicBundleProvider::defaultQbsBundle()
{
return defaultBundle(QLatin1String("qbs-bundle.json"));
}
QmlBundle BasicBundleProvider::defaultQmltypesBundle()
{
return defaultBundle(QLatin1String("qmltypes-bundle.json"));
}
QmlBundle BasicBundleProvider::defaultQmlprojectBundle()
{
return defaultBundle(QLatin1String("qmlproject-bundle.json"));
}
void BasicBundleProvider::mergeBundlesForKit(ProjectExplorer::Kit *kit
, QmlLanguageBundles &bundles
, const QHash<QString,QString> &replacements)
{
QHash<QString,QString> myReplacements = replacements;
bundles.mergeBundleForLanguage(Dialect::QmlQbs, defaultQbsBundle());
bundles.mergeBundleForLanguage(Dialect::QmlTypeInfo, defaultQmltypesBundle());
bundles.mergeBundleForLanguage(Dialect::QmlProject, defaultQmlprojectBundle());
QtSupport::BaseQtVersion *qtVersion = QtSupport::QtKitAspect::qtVersion(kit);
if (!qtVersion) {
QmlBundle b2(defaultQt5QtQuick2Bundle());
bundles.mergeBundleForLanguage(Dialect::Qml, b2);
bundles.mergeBundleForLanguage(Dialect::QmlQtQuick2, b2);
bundles.mergeBundleForLanguage(Dialect::QmlQtQuick2Ui, b2);
return;
}
QString qtQmlPath = qtVersion->qmlPath().toString();
myReplacements.insert(QLatin1String("$(CURRENT_DIRECTORY)"), qtQmlPath);
QDir qtQuick2Bundles(qtQmlPath);
qtQuick2Bundles.setNameFilters(QStringList(QLatin1String("*-bundle.json")));
QmlBundle qtQuick2Bundle;
QFileInfoList list = qtQuick2Bundles.entryInfoList();
for (int i = 0; i < list.size(); ++i) {
QmlBundle bAtt;
QStringList errors;
if (!bAtt.readFrom(list.value(i).filePath(), &errors))
qWarning() << "BasicBundleProvider: ERROR reading " << list[i].filePath() << " : "
<< errors;
qtQuick2Bundle.merge(bAtt);
}
if (!qtQuick2Bundle.supportedImports().contains(QLatin1String("QtQuick 2."),
PersistentTrie::Partial)) {
qtQuick2Bundle.merge(defaultQt5QtQuick2Bundle());
}
qtQuick2Bundle.replaceVars(myReplacements);
bundles.mergeBundleForLanguage(Dialect::Qml, qtQuick2Bundle);
bundles.mergeBundleForLanguage(Dialect::QmlQtQuick2, qtQuick2Bundle);
bundles.mergeBundleForLanguage(Dialect::QmlQtQuick2Ui, qtQuick2Bundle);
}
static QList<IBundleProvider *> g_bundleProviders;
IBundleProvider::IBundleProvider(QObject *parent)
: QObject(parent)
{
g_bundleProviders.append(this);
}
IBundleProvider::~IBundleProvider()
{
g_bundleProviders.removeOne(this);
}
const QList<IBundleProvider *> IBundleProvider::allBundleProviders()
{
return g_bundleProviders;
}
} // end namespace QmlJSTools
|