1 | // SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd. |
---|---|
2 | // |
3 | // SPDX-License-Identifier: GPL-3.0-or-later |
4 | |
5 | #include "mavenbuildergenerator.h" |
6 | #include "maven/builder/parser/mavenparser.h" |
7 | #include "services/window/windowservice.h" |
8 | #include "services/builder/builderservice.h" |
9 | #include "services/option/optionmanager.h" |
10 | |
11 | class MavenBuilderGeneratorPrivate |
12 | { |
13 | friend class MavenBuilderGenerator; |
14 | }; |
15 | |
16 | MavenBuilderGenerator::MavenBuilderGenerator() |
17 | : d(new MavenBuilderGeneratorPrivate()) |
18 | { |
19 | |
20 | } |
21 | |
22 | MavenBuilderGenerator::~MavenBuilderGenerator() |
23 | { |
24 | if (d) |
25 | delete d; |
26 | } |
27 | |
28 | BuildCommandInfo MavenBuilderGenerator::getMenuCommand(const BuildMenuType buildMenuType, const dpfservice::ProjectInfo &projectInfo) |
29 | { |
30 | BuildCommandInfo info; |
31 | info.kitName = projectInfo.kitName(); |
32 | info.workingDir = projectInfo.workspaceFolder(); |
33 | info.program = projectInfo.buildProgram(); |
34 | if (info.program.isEmpty()) |
35 | info.program = OptionManager::getInstance()->getMavenToolPath(); |
36 | switch (buildMenuType) { |
37 | case Build: |
38 | info.arguments.append("compile"); |
39 | break; |
40 | case Clean: |
41 | info.arguments.append("clean"); |
42 | break; |
43 | } |
44 | |
45 | return info; |
46 | } |
47 | |
48 | void MavenBuilderGenerator::appendOutputParser(std::unique_ptr<IOutputParser> &outputParser) |
49 | { |
50 | if (outputParser) { |
51 | outputParser->takeOutputParserChain(); |
52 | outputParser->appendOutputParser(new MavenParser()); |
53 | } |
54 | } |
55 | |
56 | bool MavenBuilderGenerator::checkCommandValidity(const BuildCommandInfo &info, QString &retMsg) |
57 | { |
58 | if (info.program.trimmed().isEmpty()) { |
59 | retMsg = tr("The build command of %1 project is null! "\ |
60 | "please install it in console with \"sudo apt install maven\", and then restart the tool.") |
61 | .arg(info.kitName.toUpper()); |
62 | return false; |
63 | } |
64 | |
65 | if (!QFileInfo(info.workingDir.trimmed()).exists()) { |
66 | retMsg = tr("The path of \"%1\" is not exist! "\ |
67 | "please check and reopen the project.") |
68 | .arg(info.workingDir); |
69 | return false; |
70 | } |
71 | |
72 | return true; |
73 | } |
74 |