1// SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd.
2//
3// SPDX-License-Identifier: GPL-3.0-or-later
4
5#ifndef GRADLECONFIGUTIL_H
6#define GRADLECONFIGUTIL_H
7
8#include "services/project/projectservice.h"
9
10#include <QObject>
11#include <QVector>
12#include <QMap>
13
14namespace gradleConfig {
15
16extern const QString kJrePath;
17extern const QString kJreExecute;
18extern const QString kLaunchConfigPath;
19extern const QString kLaunchPackageFile;
20extern const QString kDapPackageFile;
21
22struct ItemInfo {
23 QString name;
24 QString path;
25
26 friend QDataStream &operator<<(QDataStream &stream, const ItemInfo &data)
27 {
28 stream << data.name;
29 stream << data.path;
30
31 return stream;
32 }
33
34 friend QDataStream &operator>>(QDataStream &stream, ItemInfo &data)
35 {
36 stream >> data.name;
37 stream >> data.path;
38
39 return stream;
40 }
41
42 void clear()
43 {
44 name.clear();
45 path.clear();
46 }
47};
48
49struct ConfigureParam {
50 QString kit;
51 QString language;
52 QString projectPath;
53 ItemInfo jdkVersion;
54 ItemInfo gradleVersion;
55 QString mainClass;
56 QString jrePath;
57 QString jreExecute;
58 QString launchConfigPath;
59 QString launchPackageFile;
60 QString dapPackageFile;
61 bool detailInfo = true;
62
63 friend QDataStream &operator<<(QDataStream &stream, const ConfigureParam &data)
64 {
65 stream << data.kit;
66 stream << data.language;
67 stream << data.projectPath;
68 stream << data.jdkVersion;
69 stream << data.gradleVersion;
70 stream << data.mainClass;
71 stream << data.jrePath;
72 stream << data.jreExecute;
73 stream << data.launchConfigPath;
74 stream << data.launchPackageFile;
75 stream << data.dapPackageFile;
76 stream << data.detailInfo;
77
78 return stream;
79 }
80
81 friend QDataStream &operator>>(QDataStream &stream, ConfigureParam &data)
82 {
83 stream >> data.kit;
84 stream >> data.language;
85 stream >> data.projectPath;
86 stream >> data.jdkVersion;
87 stream >> data.gradleVersion;
88 stream >> data.mainClass;
89 stream >> data.jrePath;
90 stream >> data.jreExecute;
91 stream >> data.launchConfigPath;
92 stream >> data.launchPackageFile;
93 stream >> data.dapPackageFile;
94 stream >> data.detailInfo;
95
96 return stream;
97 }
98
99 void clear()
100 {
101 kit.clear();
102 language.clear();
103 projectPath.clear();
104 jdkVersion.clear();
105 gradleVersion.clear();
106 mainClass.clear();
107 jrePath.clear();
108 jreExecute.clear();
109 launchConfigPath.clear();
110 launchPackageFile.clear();
111 dapPackageFile.clear();
112 detailInfo = true;
113 }
114};
115
116class ConfigUtilPrivate;
117class ConfigUtil final: public QObject
118{
119 Q_OBJECT
120public:
121 static ConfigUtil *instance();
122
123 ConfigUtil(const ConfigUtil &) = delete;
124 ConfigUtil &operator=(const ConfigUtil &) = delete;
125
126 QString getConfigPath(const QString &projectPath);
127
128 ConfigureParam *getConfigureParamPointer();
129
130 bool getProjectInfo(const ConfigureParam *param, dpfservice::ProjectInfo &info);
131
132 void readConfig(const QString &filePath, ConfigureParam &param);
133 void saveConfig(const QString &filePath, const ConfigureParam &param);
134
135 void updateProjectInfo(dpfservice::ProjectInfo &info, const ConfigureParam *param);
136signals:
137
138private:
139 explicit ConfigUtil(QObject *parent = nullptr);
140 ~ConfigUtil();
141
142 ConfigUtilPrivate *const d;
143};
144
145} //namespace gradleConfig
146
147#endif // GRADLECONFIGUTIL_H
148