Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/qtdeclarative/src/qtdeclarative/tools/qmlcachegen/resourcefilemapper.cpp |
Source code | Switch to Preprocessed file |
Line | Source | Count | ||||||
---|---|---|---|---|---|---|---|---|
1 | /**************************************************************************** | - | ||||||
2 | ** | - | ||||||
3 | ** Copyright (C) 2016 The Qt Company Ltd. | - | ||||||
4 | ** Contact: https://www.qt.io/licensing/ | - | ||||||
5 | ** | - | ||||||
6 | ** This file is part of the QtQml module of the Qt Toolkit. | - | ||||||
7 | ** | - | ||||||
8 | ** $QT_BEGIN_LICENSE:GPL-EXCEPT$ | - | ||||||
9 | ** Commercial License Usage | - | ||||||
10 | ** Licensees holding valid commercial Qt licenses may use this file in | - | ||||||
11 | ** accordance with the commercial license agreement provided with the | - | ||||||
12 | ** Software or, alternatively, in accordance with the terms contained in | - | ||||||
13 | ** a written agreement between you and The Qt Company. For licensing terms | - | ||||||
14 | ** and conditions see https://www.qt.io/terms-conditions. For further | - | ||||||
15 | ** information use the contact form at https://www.qt.io/contact-us. | - | ||||||
16 | ** | - | ||||||
17 | ** GNU General Public License Usage | - | ||||||
18 | ** Alternatively, this file may be used under the terms of the GNU | - | ||||||
19 | ** General Public License version 3 as published by the Free Software | - | ||||||
20 | ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT | - | ||||||
21 | ** included in the packaging of this file. Please review the following | - | ||||||
22 | ** information to ensure the GNU General Public License requirements will | - | ||||||
23 | ** be met: https://www.gnu.org/licenses/gpl-3.0.html. | - | ||||||
24 | ** | - | ||||||
25 | ** $QT_END_LICENSE$ | - | ||||||
26 | ** | - | ||||||
27 | ****************************************************************************/ | - | ||||||
28 | - | |||||||
29 | #include "resourcefilemapper.h" | - | ||||||
30 | - | |||||||
31 | #include <QFileInfo> | - | ||||||
32 | #include <QDir> | - | ||||||
33 | #include <QXmlStreamReader> | - | ||||||
34 | - | |||||||
35 | ResourceFileMapper::ResourceFileMapper(const QStringList &resourceFiles) | - | ||||||
36 | { | - | ||||||
37 | for (const QString &fileName: resourceFiles) { | - | ||||||
38 | QFile f(fileName); | - | ||||||
39 | if (!f.open(QIODevice::ReadOnly))
| 0 | ||||||
40 | continue; never executed: continue; | 0 | ||||||
41 | populateFromQrcFile(f); | - | ||||||
42 | } never executed: end of block | 0 | ||||||
43 | } never executed: end of block | 0 | ||||||
44 | - | |||||||
45 | bool ResourceFileMapper::isEmpty() const | - | ||||||
46 | { | - | ||||||
47 | return qrcPathToFileSystemPath.isEmpty(); never executed: return qrcPathToFileSystemPath.isEmpty(); | 0 | ||||||
48 | } | - | ||||||
49 | - | |||||||
50 | QStringList ResourceFileMapper::resourcePaths(const QString &fileName) | - | ||||||
51 | { | - | ||||||
52 | const QString absPath = QDir::cleanPath(QDir::current().absoluteFilePath(fileName)); | - | ||||||
53 | QHashIterator<QString, QString> it(qrcPathToFileSystemPath); | - | ||||||
54 | QStringList resourcePaths; | - | ||||||
55 | while (it.hasNext()) {
| 0 | ||||||
56 | it.next(); | - | ||||||
57 | if (QFileInfo(it.value()) == QFileInfo(absPath))
| 0 | ||||||
58 | resourcePaths.append(it.key()); never executed: resourcePaths.append(it.key()); | 0 | ||||||
59 | } never executed: end of block | 0 | ||||||
60 | return resourcePaths; never executed: return resourcePaths; | 0 | ||||||
61 | } | - | ||||||
62 | - | |||||||
63 | QStringList ResourceFileMapper::qmlCompilerFiles() const | - | ||||||
64 | { | - | ||||||
65 | QStringList files; | - | ||||||
66 | for (auto it = qrcPathToFileSystemPath.constBegin(), end = qrcPathToFileSystemPath.constEnd(); | - | ||||||
67 | it != end; ++it) {
| 0 | ||||||
68 | const QString &qrcPath = it.key(); | - | ||||||
69 | const QString suffix = QFileInfo(qrcPath).suffix(); | - | ||||||
70 | if (suffix != QStringLiteral("qml") && suffix != QStringLiteral("js")) never executed: return qstring_literal_temp; | 0 | ||||||
71 | continue; never executed: continue; | 0 | ||||||
72 | files << qrcPath; dead code: files << qrcPath; | - | ||||||
73 | } | - | ||||||
74 | return files; never executed: return files; | 0 | ||||||
75 | } | - | ||||||
76 | - | |||||||
77 | void ResourceFileMapper::populateFromQrcFile(QFile &file) | - | ||||||
78 | { | - | ||||||
79 | enum State { | - | ||||||
80 | InitialState, | - | ||||||
81 | InRCC, | - | ||||||
82 | InResource, | - | ||||||
83 | InFile | - | ||||||
84 | }; | - | ||||||
85 | State state = InitialState; | - | ||||||
86 | - | |||||||
87 | QDir qrcDir = QFileInfo(file).absoluteDir(); | - | ||||||
88 | - | |||||||
89 | QString prefix; | - | ||||||
90 | QString currentFileName; | - | ||||||
91 | QXmlStreamAttributes currentFileAttributes; | - | ||||||
92 | - | |||||||
93 | QXmlStreamReader reader(&file); | - | ||||||
94 | while (!reader.atEnd()) {
| 0 | ||||||
95 | switch (reader.readNext()) { | - | ||||||
96 | case QXmlStreamReader::StartElement: never executed: case QXmlStreamReader::StartElement: | 0 | ||||||
97 | if (reader.name() == QStringLiteral("RCC")) { | - | ||||||
98 | if (state != InitialState)
| 0 | ||||||
99 | return; never executed: return; | 0 | ||||||
100 | state = InRCC; | - | ||||||
101 | continue; never executed: continue; | 0 | ||||||
102 | } else if (reader.name() == QStringLiteral("qresource")) { dead code: else dead code: if (reader.name() == ([]() noexcept | - | ||||||
103 | if (state != InRCC)
| 0 | ||||||
104 | return; never executed: return; | 0 | ||||||
105 | state = InResource; | - | ||||||
106 | QXmlStreamAttributes attributes = reader.attributes(); | - | ||||||
107 | if (attributes.hasAttribute(QStringLiteral("prefix"))) never executed: return qstring_literal_temp;
| 0 | ||||||
108 | prefix = attributes.value(QStringLiteral("prefix")).toString(); never executed: prefix = attributes.value(([]() noexcept -> QString { enum { Size = sizeof(u"" "prefix")/2 - 1 }; static const QStaticStringData<Size> qstring_literal = { { { { -1 } }, Size, 0, 0, sizeof(QStringData) }, u"" "prefix" }; QStringDataPtr holder = { qstring_literal.data_ptr() }; const QString qstring_literal_temp(holder); return qstring_literal_temp; }())).toString(); never executed: return qstring_literal_temp; | 0 | ||||||
109 | if (!prefix.startsWith(QLatin1Char('/')))
| 0 | ||||||
110 | prefix.prepend(QLatin1Char('/')); never executed: prefix.prepend(QLatin1Char('/')); | 0 | ||||||
111 | if (!prefix.endsWith(QLatin1Char('/')))
| 0 | ||||||
112 | prefix.append(QLatin1Char('/')); never executed: prefix.append(QLatin1Char('/')); | 0 | ||||||
113 | continue; never executed: continue; | 0 | ||||||
114 | } else if (reader.name() == QStringLiteral("file")) { dead code: else dead code: if (reader.name() == ([]() noexcept | - | ||||||
115 | if (state != InResource)
| 0 | ||||||
116 | return; never executed: return; | 0 | ||||||
117 | state = InFile; | - | ||||||
118 | currentFileAttributes = reader.attributes(); | - | ||||||
119 | continue; never executed: continue; | 0 | ||||||
120 | } | - | ||||||
121 | return; dead code: return; | - | ||||||
122 | - | |||||||
123 | case QXmlStreamReader::EndElement: never executed: case QXmlStreamReader::EndElement: | 0 | ||||||
124 | if (reader.name() == QStringLiteral("file")) { | - | ||||||
125 | if (state != InFile)
| 0 | ||||||
126 | return; never executed: return; | 0 | ||||||
127 | state = InResource; | - | ||||||
128 | continue; never executed: continue; | 0 | ||||||
129 | } else if (reader.name() == QStringLiteral("qresource")) { dead code: else dead code: if (reader.name() == ([]() noexcept | - | ||||||
130 | if (state != InResource)
| 0 | ||||||
131 | return; never executed: return; | 0 | ||||||
132 | state = InRCC; | - | ||||||
133 | continue; never executed: continue; | 0 | ||||||
134 | } else if (reader.name() == QStringLiteral("RCC")) { dead code: else dead code: if (reader.name() == ([]() noexcept | - | ||||||
135 | if (state != InRCC)
| 0 | ||||||
136 | return; never executed: return; | 0 | ||||||
137 | state = InitialState; | - | ||||||
138 | continue; never executed: continue; | 0 | ||||||
139 | } | - | ||||||
140 | return; dead code: return; | - | ||||||
141 | - | |||||||
142 | case QXmlStreamReader::Characters: { never executed: case QXmlStreamReader::Characters: | 0 | ||||||
143 | if (reader.isWhitespace())
| 0 | ||||||
144 | break; never executed: break; | 0 | ||||||
145 | if (state != InFile)
| 0 | ||||||
146 | return; never executed: return; | 0 | ||||||
147 | currentFileName = reader.text().toString(); | - | ||||||
148 | if (currentFileName.isEmpty())
| 0 | ||||||
149 | continue; never executed: continue; | 0 | ||||||
150 | - | |||||||
151 | const QString fsPath = QDir::cleanPath(qrcDir.absoluteFilePath(currentFileName)); | - | ||||||
152 | - | |||||||
153 | if (currentFileAttributes.hasAttribute(QStringLiteral("alias"))) never executed: return qstring_literal_temp;
| 0 | ||||||
154 | currentFileName = currentFileAttributes.value(QStringLiteral("alias")).toString(); never executed: currentFileName = currentFileAttributes.value(([]() noexcept -> QString { enum { Size = sizeof(u"" "alias")/2 - 1 }; static const QStaticStringData<Size> qstring_literal = { { { { -1 } }, Size, 0, 0, sizeof(QStringData) }, u"" "alias" }; QStringDataPtr holder = { qstring_literal.data_ptr() }; const QString qstring_literal_temp(holder); return qstring_literal_temp; }())).toString(); never executed: return qstring_literal_temp; | 0 | ||||||
155 | - | |||||||
156 | currentFileName = QDir::cleanPath(currentFileName); | - | ||||||
157 | while (currentFileName.startsWith(QLatin1String("../")))
| 0 | ||||||
158 | currentFileName.remove(0, 3); never executed: currentFileName.remove(0, 3); | 0 | ||||||
159 | - | |||||||
160 | const QString qrcPath = prefix + currentFileName; | - | ||||||
161 | if (QFile::exists(fsPath))
| 0 | ||||||
162 | qrcPathToFileSystemPath.insert(qrcPath, fsPath); never executed: qrcPathToFileSystemPath.insert(qrcPath, fsPath); | 0 | ||||||
163 | continue; never executed: continue; | 0 | ||||||
164 | } | - | ||||||
165 | - | |||||||
166 | default: break; never executed: break; never executed: default: | 0 | ||||||
167 | } | - | ||||||
168 | } | - | ||||||
169 | } never executed: end of block | 0 | ||||||
Source code | Switch to Preprocessed file |