1 | // SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd. |
2 | // |
3 | // SPDX-License-Identifier: GPL-3.0-or-later |
4 | |
5 | #include "optionmanager.h" |
6 | #include "optionutils.h" |
7 | #include "optiondatastruct.h" |
8 | |
9 | #include <QVariant> |
10 | |
11 | static OptionManager *m_instance = nullptr; |
12 | |
13 | class OptionManagerPrivate final |
14 | { |
15 | friend class OptionManager; |
16 | |
17 | QMap<QString, QVariant> dataMap; |
18 | }; |
19 | |
20 | OptionManager::OptionManager(QObject *parent) |
21 | : QObject(parent) |
22 | , d(new OptionManagerPrivate()) |
23 | { |
24 | updateData(); |
25 | } |
26 | |
27 | OptionManager::~OptionManager() |
28 | { |
29 | if (d) { |
30 | delete d; |
31 | } |
32 | } |
33 | |
34 | OptionManager *OptionManager::getInstance() |
35 | { |
36 | if (!m_instance) { |
37 | m_instance = new OptionManager(); |
38 | } |
39 | return m_instance; |
40 | } |
41 | |
42 | void OptionManager::updateData() |
43 | { |
44 | OptionUtils::readAll(OptionUtils::getJsonFilePath(), d->dataMap); |
45 | } |
46 | |
47 | QString OptionManager::getMavenToolPath() |
48 | { |
49 | QMap<QString, QVariant> map = d->dataMap.value(option::CATEGORY_MAVEN).toMap(); |
50 | return map.value("Maven" ).toMap().value("version" ).toMap().value("path" ).toString(); |
51 | } |
52 | |
53 | QString OptionManager::getJdkToolPath() |
54 | { |
55 | QMap<QString, QVariant> map = d->dataMap.value(option::CATEGORY_JAVA).toMap(); |
56 | return map.value("JDK" ).toMap().value("version" ).toMap().value("path" ).toString(); |
57 | } |
58 | |
59 | QString OptionManager::getGradleToolPath() |
60 | { |
61 | QMap<QString, QVariant> map = d->dataMap.value(option::CATEGORY_GRADLE).toMap(); |
62 | int useWrapper = map.value("Gradle" ).toMap().value("useWrapper" ).toInt(); |
63 | if (useWrapper) { |
64 | return "./gradlew" ; |
65 | } |
66 | |
67 | return map.value("Gradle" ).toMap().value("version" ).toMap().value("path" ).toString(); |
68 | } |
69 | |
70 | QString OptionManager::getPythonToolPath() |
71 | { |
72 | QMap<QString, QVariant> map = d->dataMap.value(option::CATEGORY_PYTHON).toMap(); |
73 | return map.value("Interpreter" ).toMap().value("version" ).toMap().value("path" ).toString(); |
74 | } |
75 | |
76 | QString OptionManager::getCMakeToolPath() |
77 | { |
78 | QMap<QString, QVariant> map = d->dataMap.value(option::CATEGORY_CMAKE).toMap(); |
79 | return map.value("Kits" ).toMap().value("cmake" ).toMap().value("path" ).toString(); |
80 | } |
81 | |
82 | QString OptionManager::getNinjaToolPath() |
83 | { |
84 | QMap<QString, QVariant> map = d->dataMap.value(option::CATEGORY_NINJA).toMap(); |
85 | return map.value("Ninja" ).toMap().value("version" ).toMap().value("path" ).toString(); |
86 | } |
87 | |
88 | QString OptionManager::getCxxDebuggerToolPath() |
89 | { |
90 | QMap<QString, QVariant> map = d->dataMap.value(option::CATEGORY_CMAKE).toMap(); |
91 | return map.value("Kits" ).toMap().value("debugger" ).toMap().value("path" ).toString(); |
92 | } |
93 | |
94 | QString OptionManager::getJSToolPath() |
95 | { |
96 | QMap<QString, QVariant> map = d->dataMap.value(option::CATEGORY_JS).toMap(); |
97 | return map.value("Interpreter" ).toMap().value("version" ).toMap().value("path" ).toString(); |
98 | } |
99 | |
100 | QString OptionManager::getToolPath(const QString &kit) |
101 | { |
102 | if (kit == option::CATEGORY_CMAKE) { |
103 | return getCMakeToolPath(); |
104 | } else if (kit == option::CATEGORY_NINJA) { |
105 | return getNinjaToolPath(); |
106 | } else if (kit == option::CATEGORY_MAVEN) { |
107 | return getMavenToolPath(); |
108 | } else if (kit == option::CATEGORY_GRADLE) { |
109 | return getGradleToolPath(); |
110 | } else if (kit == option::CATEGORY_JS) { |
111 | return getJSToolPath(); |
112 | } else if (kit == option::CATEGORY_PYTHON) { |
113 | return getPythonToolPath(); |
114 | } |
115 | return "" ; |
116 | } |
117 | |
118 | |