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 | |
12 | using namespace dpfservice; |
13 | |
14 | class MavenGeneratorPrivate |
15 | { |
16 | friend class MavenGenerator; |
17 | QSharedPointer<JavaDebug> javaDebug; |
18 | }; |
19 | |
20 | MavenGenerator::MavenGenerator() |
21 | : d(new MavenGeneratorPrivate()) |
22 | { |
23 | d->javaDebug.reset(new JavaDebug()); |
24 | } |
25 | |
26 | MavenGenerator::~MavenGenerator() |
27 | { |
28 | if (d) |
29 | delete d; |
30 | } |
31 | |
32 | QString MavenGenerator::debugger() |
33 | { |
34 | return "dap" ; |
35 | } |
36 | |
37 | bool MavenGenerator::isNeedBuild() |
38 | { |
39 | return true; |
40 | } |
41 | |
42 | bool MavenGenerator::isTargetReady() |
43 | { |
44 | return true; |
45 | } |
46 | |
47 | bool MavenGenerator::isAnsyPrepareDebug() |
48 | { |
49 | return d->javaDebug->isAnsyPrepareDebug(); |
50 | } |
51 | |
52 | bool MavenGenerator::prepareDebug(const QMap<QString, QVariant> ¶m, QString &retMsg) |
53 | { |
54 | QString projectPath = param.value("workspace" ).toString(); |
55 | return d->javaDebug->prepareDebug(projectPath, retMsg); |
56 | } |
57 | |
58 | bool MavenGenerator::requestDAPPort(const QString &uuid, const QMap<QString, QVariant> ¶m, QString &retMsg) |
59 | { |
60 | QString projectPath = param.value("workspace" ).toString(); |
61 | return d->javaDebug->requestDAPPort(uuid, toolKitName(), projectPath, retMsg); |
62 | } |
63 | |
64 | bool MavenGenerator::isLaunchNotAttach() |
65 | { |
66 | return d->javaDebug->isLaunchNotAttach(); |
67 | } |
68 | |
69 | dap::LaunchRequest MavenGenerator::launchDAP(const QMap<QString, QVariant> ¶m) |
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 | |
79 | bool MavenGenerator::isRestartDAPManually() |
80 | { |
81 | return d->javaDebug->isRestartDAPManually(); |
82 | } |
83 | |
84 | bool MavenGenerator::isStopDAPManually() |
85 | { |
86 | return d->javaDebug->isStopDAPManually(); |
87 | } |
88 | |
89 | QString MavenGenerator::build(const QString &projectPath) |
90 | { |
91 | return MavenBuild::build(toolKitName(), projectPath); |
92 | } |
93 | |
94 | QString MavenGenerator::getProjectFile(const QString &projectPath) |
95 | { |
96 | return projectPath + QDir::separator() + "pom.xml" ; |
97 | } |
98 | |
99 | QMap<QString, QVariant> MavenGenerator::getDebugArguments(const dpfservice::ProjectInfo &projectInfo, |
100 | const QString ¤tFile) |
101 | { |
102 | Q_UNUSED(currentFile) |
103 | |
104 | QMap<QString, QVariant> param; |
105 | param.insert("workspace" , projectInfo.workspaceFolder()); |
106 | |
107 | return param; |
108 | } |
109 | |
110 | RunCommandInfo MavenGenerator::getRunArguments(const ProjectInfo &projectInfo, const QString ¤tFile) |
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 | |