1// SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd.
2//
3// SPDX-License-Identifier: GPL-3.0-or-later
4
5#include "gradlegenerator.h"
6
7#include "java/javadebug.h"
8#include "gradle/gradlebuild.h"
9#include "javautil.h"
10#include "services/project/projectservice.h"
11
12using namespace dpfservice;
13
14class GradleGeneratorPrivate
15{
16 friend class GradleGenerator;
17 QSharedPointer<JavaDebug> javaDebug;
18};
19
20GradleGenerator::GradleGenerator()
21 : d(new GradleGeneratorPrivate())
22{
23 d->javaDebug.reset(new JavaDebug());
24}
25
26GradleGenerator::~GradleGenerator()
27{
28 if (d)
29 delete d;
30}
31
32QString GradleGenerator::debugger()
33{
34 return "dap";
35}
36
37bool GradleGenerator::isNeedBuild()
38{
39 return true;
40}
41
42bool GradleGenerator::isTargetReady()
43{
44 return true;
45}
46
47bool GradleGenerator::isAnsyPrepareDebug()
48{
49 return d->javaDebug->isAnsyPrepareDebug();
50}
51
52bool GradleGenerator::prepareDebug(const QMap<QString, QVariant> &param, QString &retMsg)
53{
54 QString projectPath = param.value("workspace").toString();
55 return d->javaDebug->prepareDebug(projectPath, retMsg);
56}
57
58bool GradleGenerator::requestDAPPort(const QString &uuid, const QMap<QString, QVariant> &param, QString &retMsg)
59{
60 QString projectPath = param.value("workspace").toString();
61 return d->javaDebug->requestDAPPort(uuid, toolKitName(),projectPath, retMsg);
62}
63
64bool GradleGenerator::isLaunchNotAttach()
65{
66 return d->javaDebug->isLaunchNotAttach();
67}
68
69dap::LaunchRequest GradleGenerator::launchDAP(const QMap<QString, QVariant> &param)
70{
71 QString workspace = param.value("workspace").toString();
72 QString mainClass = param.value("mainClass").toString();
73 ProjectService *projectService = dpfGetService(ProjectService);
74 ProjectInfo projectInfo = projectService->getActiveProjectInfo();
75 QString mainClassPath = JavaUtil::getMainClassPath(projectInfo.workspaceFolder());
76 QString packageDirName = "main";
77 if (mainClass.isEmpty()) {
78 mainClass = JavaUtil::getMainClass(mainClassPath, packageDirName);
79 }
80 QString projectName = param.value("projectName").toString();
81 QStringList classPaths = param.value("classPaths").toStringList();
82 if (classPaths.isEmpty()) {
83 classPaths << JavaUtil::getPackageDir(mainClassPath, packageDirName);
84 }
85 return d->javaDebug->launchDAP(workspace, mainClass, projectName, classPaths);
86}
87
88bool GradleGenerator::isRestartDAPManually()
89{
90 return d->javaDebug->isRestartDAPManually();
91}
92
93bool GradleGenerator::isStopDAPManually()
94{
95 return d->javaDebug->isStopDAPManually();
96}
97
98QString GradleGenerator::build(const QString& projectPath)
99{
100 return GradleBuild::build(toolKitName(), projectPath);
101}
102
103QMap<QString, QVariant> GradleGenerator::getDebugArguments(const dpfservice::ProjectInfo &projectInfo,
104 const QString &currentFile)
105{
106 Q_UNUSED(currentFile)
107
108 QMap<QString, QVariant> param;
109 param.insert("workspace", projectInfo.workspaceFolder());
110
111 return param;
112}
113
114dpfservice::RunCommandInfo GradleGenerator::getRunArguments(const dpfservice::ProjectInfo &projectInfo, const QString &currentFile)
115{
116 Q_UNUSED(currentFile)
117
118 RunCommandInfo runCommandInfo;
119 QString packageDirName = "main";
120
121 QString mainClassPath = JavaUtil::getMainClassPath(projectInfo.workspaceFolder());
122 runCommandInfo.program = "java";
123 runCommandInfo.arguments << JavaUtil::getMainClass(mainClassPath, packageDirName);
124 runCommandInfo.workingDir = JavaUtil::getPackageDir(mainClassPath, packageDirName);
125
126 return runCommandInfo;
127}
128
129