1 | // SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd. |
2 | // |
3 | // SPDX-License-Identifier: GPL-3.0-or-later |
4 | |
5 | #include "mavenconfigutil.h" |
6 | #include "maven/project/mavenprojectgenerator.h" |
7 | |
8 | #include "services/option/optionmanager.h" |
9 | |
10 | namespace mavenConfig { |
11 | |
12 | const QString kJrePath = "jrePath" ; |
13 | const QString kJreExecute = "jreExecute" ; |
14 | const QString kLaunchConfigPath = "launchConfigPath" ; |
15 | const QString kLaunchPackageFile = "launchPackageFile" ; |
16 | const QString kDapPackageFile = "dapPackageFile" ; |
17 | |
18 | class ConfigUtilPrivate |
19 | { |
20 | friend class ConfigUtil; |
21 | ConfigureParam configureParam; |
22 | }; |
23 | |
24 | ConfigUtil::ConfigUtil(QObject *parent) |
25 | : QObject(parent) |
26 | , d(new ConfigUtilPrivate()) |
27 | { |
28 | |
29 | } |
30 | |
31 | ConfigUtil::~ConfigUtil() |
32 | { |
33 | if (d) { |
34 | delete d; |
35 | } |
36 | } |
37 | |
38 | ConfigUtil *ConfigUtil::instance() |
39 | { |
40 | static ConfigUtil ins; |
41 | return &ins; |
42 | } |
43 | |
44 | ConfigureParam *ConfigUtil::getConfigureParamPointer() |
45 | { |
46 | return &d->configureParam; |
47 | } |
48 | |
49 | bool ConfigUtil::getProjectInfo(const ConfigureParam *param, dpfservice::ProjectInfo &info) |
50 | { |
51 | QString sourceFolder = QFileInfo(param->projectPath).path(); |
52 | info.setLanguage(param->language); |
53 | info.setKitName(MavenProjectGenerator::toolKitName()); |
54 | info.setWorkspaceFolder(sourceFolder); |
55 | info.setBuildProgram(OptionManager::getInstance()->getMavenToolPath()); |
56 | info.setDetailInformation(param->detailInfo); |
57 | info.setProperty(kJrePath, param->jreExecute); |
58 | info.setProperty(kJreExecute, param->launchConfigPath); |
59 | info.setProperty(kLaunchConfigPath, param->launchConfigPath); |
60 | info.setProperty(kLaunchPackageFile, param->launchPackageFile); |
61 | info.setProperty(kDapPackageFile, param->dapPackageFile); |
62 | |
63 | return true; |
64 | } |
65 | |
66 | QString ConfigUtil::getConfigPath(const QString &projectPath) |
67 | { |
68 | return CustomPaths::projectCachePath(projectPath) + QDir::separator() + "project.properties" ; |
69 | } |
70 | |
71 | void ConfigUtil::readConfig(const QString &filePath, ConfigureParam ¶m) |
72 | { |
73 | param.clear(); |
74 | |
75 | QFile file(filePath); |
76 | if (file.open(QIODevice::ReadOnly)) { |
77 | QDataStream stream(&file); |
78 | stream >> param; |
79 | file.close(); |
80 | } |
81 | } |
82 | |
83 | void ConfigUtil::saveConfig(const QString &filePath, const ConfigureParam ¶m) |
84 | { |
85 | QFile file(filePath); |
86 | if (file.open(QIODevice::ReadWrite)) { |
87 | QDataStream stream(&file); |
88 | stream << param; |
89 | file.close(); |
90 | } |
91 | } |
92 | |
93 | void ConfigUtil::updateProjectInfo(dpfservice::ProjectInfo &info, const ConfigureParam *cfgParams) |
94 | { |
95 | if (!cfgParams) |
96 | return; |
97 | |
98 | info.setLanguage(cfgParams->language); |
99 | info.setKitName(MavenProjectGenerator::toolKitName()); |
100 | info.setWorkspaceFolder(cfgParams->projectPath); |
101 | info.setBuildFolder(cfgParams->projectPath); |
102 | info.setBuildProgram(cfgParams->mavenVersion.path); |
103 | info.setDetailInformation(cfgParams->detailInfo); |
104 | info.setProperty(kJrePath, cfgParams->jrePath); |
105 | info.setProperty(kJreExecute, cfgParams->jreExecute); |
106 | info.setProperty(kLaunchConfigPath, cfgParams->launchConfigPath); |
107 | info.setProperty(kLaunchPackageFile, cfgParams->launchPackageFile); |
108 | info.setProperty(kDapPackageFile, cfgParams->dapPackageFile); |
109 | } |
110 | |
111 | } //namespace mavenConfig |
112 | |