| 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 | |
| 10 | namespace gradleConfig { |
| 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(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 | |
| 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 | |
| 94 | void 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 | |