1// SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd.
2//
3// SPDX-License-Identifier: GPL-3.0-or-later
4
5#include "gradleconfigutil.h"
6#include "gradle/project/gradleprojectgenerator.h"
7
8#include "services/option/optionmanager.h"
9
10namespace gradleConfig {
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(GradleProjectGenerator::toolKitName());
54 info.setWorkspaceFolder(sourceFolder);
55 info.setBuildProgram(OptionManager::getInstance()->getGradleToolPath());
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
93
94void ConfigUtil::updateProjectInfo(dpfservice::ProjectInfo &info, const ConfigureParam *cfgParams)
95{
96 if (!cfgParams)
97 return;
98
99 info.setLanguage(cfgParams->language);
100 info.setKitName(GradleProjectGenerator::toolKitName());
101 info.setWorkspaceFolder(cfgParams->projectPath);
102 info.setBuildFolder(cfgParams->projectPath);
103 info.setBuildProgram(cfgParams->gradleVersion.path);
104 info.setDetailInformation(cfgParams->detailInfo);
105 info.setProperty(kJrePath, cfgParams->jrePath);
106 info.setProperty(kJreExecute, cfgParams->jreExecute);
107 info.setProperty(kLaunchConfigPath, cfgParams->launchConfigPath);
108 info.setProperty(kLaunchPackageFile, cfgParams->launchPackageFile);
109 info.setProperty(kDapPackageFile, cfgParams->dapPackageFile);
110}
111
112} //namespace gradleConfig
113