1// SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd.
2//
3// SPDX-License-Identifier: GPL-3.0-or-later
4
5#include "mavengenerator.h"
6#include "java/javadebug.h"
7#include "maven/mavenbuild.h"
8#include "javautil.h"
9
10#include <QRegExp>
11
12using namespace dpfservice;
13
14class MavenGeneratorPrivate
15{
16 friend class MavenGenerator;
17 QSharedPointer<JavaDebug> javaDebug;
18};
19
20MavenGenerator::MavenGenerator()
21 : d(new MavenGeneratorPrivate())
22{
23 d->javaDebug.reset(new JavaDebug());
24}
25
26MavenGenerator::~MavenGenerator()
27{
28 if (d)
29 delete d;
30}
31
32QString MavenGenerator::debugger()
33{
34 return "dap";
35}
36
37bool MavenGenerator::isNeedBuild()
38{
39 return true;
40}
41
42bool MavenGenerator::isTargetReady()
43{
44 return true;
45}
46
47bool MavenGenerator::isAnsyPrepareDebug()
48{
49 return d->javaDebug->isAnsyPrepareDebug();
50}
51
52bool MavenGenerator::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 MavenGenerator::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 MavenGenerator::isLaunchNotAttach()
65{
66 return d->javaDebug->isLaunchNotAttach();
67}
68
69dap::LaunchRequest MavenGenerator::launchDAP(const QMap<QString, QVariant> &param)
70{
71 QString workspace = param.value("workspace").toString();
72 QString mainClass = param.value("mainClass").toString();
73 QString projectName = param.value("projectName").toString();
74 QStringList classPaths = param.value("classPaths").toStringList();
75
76 return d->javaDebug->launchDAP(workspace, mainClass, projectName, classPaths);
77}
78
79bool MavenGenerator::isRestartDAPManually()
80{
81 return d->javaDebug->isRestartDAPManually();
82}
83
84bool MavenGenerator::isStopDAPManually()
85{
86 return d->javaDebug->isStopDAPManually();
87}
88
89QString MavenGenerator::build(const QString &projectPath)
90{
91 return MavenBuild::build(toolKitName(), projectPath);
92}
93
94QString MavenGenerator::getProjectFile(const QString &projectPath)
95{
96 return projectPath + QDir::separator() + "pom.xml";
97}
98
99QMap<QString, QVariant> MavenGenerator::getDebugArguments(const dpfservice::ProjectInfo &projectInfo,
100 const QString &currentFile)
101{
102 Q_UNUSED(currentFile)
103
104 QMap<QString, QVariant> param;
105 param.insert("workspace", projectInfo.workspaceFolder());
106
107 return param;
108}
109
110RunCommandInfo MavenGenerator::getRunArguments(const ProjectInfo &projectInfo, const QString &currentFile)
111{
112 Q_UNUSED(currentFile)
113
114 RunCommandInfo runCommandInfo;
115 QString packageDirName = "classes";
116
117 QString mainClassPath = JavaUtil::getMainClassPath(projectInfo.workspaceFolder());
118 runCommandInfo.program = "java";
119 runCommandInfo.arguments << JavaUtil::getMainClass(mainClassPath, packageDirName);
120 runCommandInfo.workingDir = JavaUtil::getPackageDir(mainClassPath, packageDirName);
121
122 return runCommandInfo;
123}
124