1// SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd.
2//
3// SPDX-License-Identifier: GPL-3.0-or-later
4
5#include "mavenparser.h"
6
7#include "services/builder/task.h"
8#include "services/builder/fileutils.h"
9
10const char TASK_CATEGORY_BUILDSYSTEM[] = "Task.Category.Buildsystem";
11
12MavenParser::MavenParser()
13{
14 setObjectName(QLatin1String("MavenParser"));
15}
16
17void MavenParser::stdOutput(const QString &line, OutputPane::OutputFormat format)
18{
19 QString newContent = line;
20 QRegExp exp("\\033\\[(\\d*;*\\d*)m");
21 newContent.replace(exp, "");
22
23 if (newContent.indexOf("[ERROR]") != -1) {
24 format = OutputPane::OutputFormat::ErrorMessage;
25 stdError(newContent);
26 }
27
28 emit outputAdded(newContent, format);
29
30 IOutputParser::stdOutput(newContent, format);
31}
32
33void MavenParser::stdError(const QString &line)
34{
35 QString newContent = line;
36 QRegExp exp("/.*:\\[(\\d*),(\\d*)\\]");
37 int pos = newContent.indexOf(exp);
38 QString filePath;
39 int lineNumber = -1;
40 if (pos != -1) {
41 QStringList list = newContent.mid(pos).split(":");
42 if (list.count() > 1) {
43 filePath = list.at(0);
44 QString last = list.at(1);
45 QStringList sublist = last.split(",");
46 if (sublist.count() > 1) {
47 lineNumber = sublist[0].mid(1).toInt();
48 }
49 }
50 } else {
51 QRegExp pomExp("Non-parseable POM /.*:");
52 QString header = "Non-parseable POM ";
53 pos = newContent.indexOf(pomExp);
54 if (pos != -1) {
55 newContent = newContent.mid(pos);
56 pos = newContent.indexOf(":");
57 if (pos != -1) {
58 filePath = newContent.left(pos).mid(header.length() - 1);
59 newContent = newContent.mid(pos);
60 pos = newContent.indexOf("@ line ");
61 if (pos != -1) {
62 newContent = newContent.mid(pos);
63 pos = newContent.indexOf(",");
64 if (pos != -1) {
65 newContent = newContent.left(pos);
66 header = "@ line ";
67 lineNumber = newContent.mid(header.length() - 1).toInt();
68 }
69 }
70 }
71 }
72 }
73
74 Utils::FileName fileName;
75 if (QFileInfo(filePath).isFile()) {
76 fileName = Utils::FileName::fromUserInput(filePath);
77 } else {
78 fileName = Utils::FileName();
79 }
80
81 taskAdded(Task(Task::Error,
82 line,
83 fileName,
84 lineNumber,
85 TASK_CATEGORY_BUILDSYSTEM), 1, 0);
86}
87
88void MavenParser::taskAdded(const Task &task, int linkedLines, int skippedLines)
89{
90 emit addTask(task, linkedLines, skippedLines);
91}
92