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
10namespace mavenConfig {
11
12const QString kJrePath = "jrePath";
13const QString kJreExecute = "jreExecute";
14const QString kLaunchConfigPath = "launchConfigPath";
15const QString kLaunchPackageFile = "launchPackageFile";
16const QString kDapPackageFile = "dapPackageFile";
17
18class ConfigUtilPrivate
19{
20 friend class ConfigUtil;
21 ConfigureParam configureParam;
22};
23
24ConfigUtil::ConfigUtil(QObject *parent)
25 : QObject(parent)
26 , d(new ConfigUtilPrivate())
27{
28
29}
30
31ConfigUtil::~ConfigUtil()
32{
33 if (d) {
34 delete d;
35 }
36}
37
38ConfigUtil *ConfigUtil::instance()
39{
40 static ConfigUtil ins;
41 return &ins;
42}
43
44ConfigureParam *ConfigUtil::getConfigureParamPointer()
45{
46 return &d->configureParam;
47}
48
49bool 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
66QString ConfigUtil::getConfigPath(const QString &projectPath)
67{
68 return CustomPaths::projectCachePath(projectPath) + QDir::separator() + "project.properties";
69}
70
71void ConfigUtil::readConfig(const QString &filePath, ConfigureParam &param)
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
83void ConfigUtil::saveConfig(const QString &filePath, const ConfigureParam &param)
84{
85 QFile file(filePath);
86 if (file.open(QIODevice::ReadWrite)) {
87 QDataStream stream(&file);
88 stream << param;
89 file.close();
90 }
91}
92
93void 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