ProjectExplorer: Split up the IOutputParser class

For symmetry with Utils::OutputFormatter.

Task-number: QTCREATORBUG-22665
Change-Id: I148fed69dba042ad3ef26e080829c31cd3f357fd
Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
Christian Kandeler
2020-04-15 14:59:51 +02:00
parent d04597f2aa
commit 6f32538c5d
76 changed files with 345 additions and 311 deletions

View File

@@ -57,7 +57,7 @@ void CMakeParser::setSourceDirectory(const QString &sourceDir)
m_sourceDirectory = QDir(sourceDir);
}
IOutputParser::Status CMakeParser::doHandleLine(const QString &line, OutputFormat type)
OutputTaskParser::Status CMakeParser::handleLine(const QString &line, OutputFormat type)
{
if (type != StdErrFormat)
return Status::NotHandled;
@@ -67,7 +67,7 @@ IOutputParser::Status CMakeParser::doHandleLine(const QString &line, OutputForma
case NONE:
if (trimmedLine.isEmpty() && !m_lastTask.isNull()) {
if (m_skippedFirstEmptyLine) {
doFlush();
flush();
return Status::InProgress;
}
m_skippedFirstEmptyLine = true;
@@ -100,7 +100,7 @@ IOutputParser::Status CMakeParser::doHandleLine(const QString &line, OutputForma
return Status::InProgress;
} else if (trimmedLine.endsWith(QLatin1String("in cmake code at"))) {
m_expectTripleLineErrorData = LINE_LOCATION;
doFlush();
flush();
const Task::TaskType type =
trimmedLine.contains(QLatin1String("Error")) ? Task::Error : Task::Warning;
m_lastTask = BuildSystemTask(type, QString());
@@ -129,7 +129,7 @@ IOutputParser::Status CMakeParser::doHandleLine(const QString &line, OutputForma
m_expectTripleLineErrorData = LINE_DESCRIPTION2;
else {
m_expectTripleLineErrorData = NONE;
doFlush();
flush();
return Status::Done;
}
return Status::InProgress;
@@ -137,13 +137,13 @@ IOutputParser::Status CMakeParser::doHandleLine(const QString &line, OutputForma
m_lastTask.description.append(QLatin1Char('\n'));
m_lastTask.description.append(trimmedLine);
m_expectTripleLineErrorData = NONE;
doFlush();
flush();
return Status::Done;
}
return Status::NotHandled;
}
void CMakeParser::doFlush()
void CMakeParser::flush()
{
if (m_lastTask.isNull())
return;

View File

@@ -36,7 +36,7 @@
namespace CMakeProjectManager {
class CMAKE_EXPORT CMakeParser : public ProjectExplorer::IOutputParser
class CMAKE_EXPORT CMakeParser : public ProjectExplorer::OutputTaskParser
{
Q_OBJECT
@@ -45,8 +45,8 @@ public:
void setSourceDirectory(const QString &sourceDir);
private:
Status doHandleLine(const QString &line, Utils::OutputFormat type) override;
void doFlush() override;
Status handleLine(const QString &line, Utils::OutputFormat type) override;
void flush() override;
enum TripleLineError { NONE, LINE_LOCATION, LINE_DESCRIPTION, LINE_DESCRIPTION2 };

View File

@@ -76,9 +76,7 @@ CMakeProcess::~CMakeProcess()
Core::Reaper::reap(m_process.release());
}
// Delete issue parser:
if (m_parser)
m_parser->flush();
m_parser.flush();
if (m_future) {
reportCanceled();
@@ -88,7 +86,7 @@ CMakeProcess::~CMakeProcess()
void CMakeProcess::run(const BuildDirParameters &parameters, const QStringList &arguments)
{
QTC_ASSERT(!m_process && !m_parser && !m_future, return);
QTC_ASSERT(!m_process && !m_future, return);
CMakeTool *cmake = parameters.cmakeTool();
QTC_ASSERT(parameters.isValid() && cmake, return);
@@ -98,10 +96,11 @@ void CMakeProcess::run(const BuildDirParameters &parameters, const QStringList &
const QString srcDir = parameters.sourceDirectory.toString();
auto parser = std::make_unique<CMakeParser>();
const auto parser = new CMakeParser;
parser->setSourceDirectory(srcDir);
m_parser.addLineParser(parser);
QDir source = QDir(srcDir);
connect(parser.get(), &IOutputParser::addTask, parser.get(),
connect(&m_parser, &IOutputParser::addTask, this,
[source](const Task &task) {
if (task.file.isEmpty() || task.file.toFileInfo().isAbsolute()) {
TaskHub::addTask(task);
@@ -155,7 +154,6 @@ void CMakeProcess::run(const BuildDirParameters &parameters, const QStringList &
process->start();
m_process = std::move(process);
m_parser = std::move(parser);
m_future = std::move(future);
}
@@ -201,7 +199,7 @@ void CMakeProcess::processStandardError()
static QString rest;
rest = lineSplit(rest, m_process->readAllStandardError(), [this](const QString &s) {
m_parser->handleStderr(s);
m_parser.handleStderr(s);
Core::MessageManager::write(s);
});
}

View File

@@ -70,7 +70,7 @@ private:
void checkForCancelled();
std::unique_ptr<Utils::QtcProcess> m_process;
std::unique_ptr<ProjectExplorer::IOutputParser> m_parser;
ProjectExplorer::IOutputParser m_parser;
std::unique_ptr<QFutureInterface<void>> m_future;
bool m_processWasCanceled = false;
QTimer m_cancelTimer;

View File

@@ -73,7 +73,9 @@ const int MAX_PROGRESS = 1400;
ServerModeReader::ServerModeReader()
{
connect(&m_parser, &CMakeParser::addTask, this, [this](const Task &t) {
m_cmakeParser = new CMakeParser;
m_parser.addLineParser(m_cmakeParser);
connect(&m_parser, &IOutputParser::addTask, this, [this](const Task &t) {
Task editable(t);
if (!editable.file.isEmpty()) {
QDir srcDir(m_parameters.sourceDirectory.toString());
@@ -94,8 +96,7 @@ void ServerModeReader::setParameters(const BuildDirParameters &p)
QTC_ASSERT(cmake, return);
m_parameters = p;
m_parser.setSourceDirectory(m_parameters.sourceDirectory.toString());
m_cmakeParser->setSourceDirectory(m_parameters.sourceDirectory.toString());
createNewServer();
}

View File

@@ -180,7 +180,8 @@ private:
QList<Target *> m_targets;
QList<FileGroup *> m_fileGroups;
CMakeParser m_parser;
CMakeParser *m_cmakeParser = nullptr;
ProjectExplorer::IOutputParser m_parser;
#if defined(WITH_TESTS)
friend class CMakeProjectPlugin;